Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
StructArray.h
1 //
2 // StructArray.h
3 //
4 // Copyright (c) 2001-2008 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef STRUCTARRAYH
9 #define STRUCTARRAYH
10 
11 #include "MathTypes.h"
12 #include "Projections.h"
13 #include "Building.h"
14 #include "HeightField.h"
15 #include <stdio.h>
16 
17 
21 {
22 public:
23  vtStructureType type;
24  DRECT rect;
25  bool bInsideOnly;
26  bool bBuildFoundations;
27  bool bUse25DForElevation;
28 
31 
32  // If height is read from a field, name of that field.
33  vtString m_strFieldNameHeight;
34  enum HeightType { STORIES, METERS, FEET, METERSNOSTORIES, FEETNOSTORIES } m_HeightType;
35 
38 
42  RoofType m_eRoofType;
43  int m_iSlope; // default: -1
44 
45  vtHeightField *pHeightField;
46 
47  bool m_bFixedColor;
48  RGBi m_BuildingColor; // default: -1 -1 -1
49  RGBi m_RoofColor; // default: -1 -1 -1
50 };
51 
52 // Well known import schemas
53 
54 typedef enum
55 {
56  SCHEMA_OSGB_TOPO_AREA,
57  SCHEMA_OSGB_TOPO_POINT,
58  SCHEMA_OSGB_TOPO_LINE,
59  SCHEMA_MAPINFO_OSGB_TOPO_AREA,
60  SCHEMA_MAPINFO_OSGB_TOPO_POINT,
61  SCHEMA_UI
62 } SchemaType;
63 
70 class vtStructureArray : public vtArray<vtStructure*>
71 {
72 public:
74  virtual ~vtStructureArray() { Empty(); free(m_Data); m_Data = NULL; m_MaxSize = 0; }
75  virtual void DestructItems(uint first, uint last);
76 
77  void SetFilename(const vtString &str) { m_strFilename = str; }
78  vtString GetFilename() { return m_strFilename; }
79 
80  int GetFirstSelected();
81  int GetNextSelected();
82  int DeleteSelected();
83  virtual void DestroyStructure(int i) {}
84 
85  bool ReadSHP(const char *pathname, StructImportOptions &opt,
86  bool progress_callback(int) = NULL);
87  void AddElementsFromOGR(class OGRDataSource *datasource,
88  StructImportOptions &opt, bool progress_callback(int) = NULL);
89 
90  void AddElementsFromOGR_SDTS(class OGRDataSource *datasource,
91  bool progress_callback(int) = NULL);
92  void AddElementsFromOGR_RAW(class OGRDataSource *datasource,
93  StructImportOptions &opt, bool progress_callback(int) = NULL);
94 
95  void AddBuildingsFromOGR(class OGRLayer *pLayer,
96  StructImportOptions &opt, bool progress_callback(int) = NULL);
97  void AddLinearsFromOGR(class OGRLayer *pLayer,
98  StructImportOptions &opt, bool progress_callback(int) = NULL);
99  void AddInstancesFromOGR(class OGRLayer *pLayer,
100  StructImportOptions &opt, bool progress_callback(int) = NULL);
101 
102  bool ReadBCF(const char *pathname); // read a .bcf file
103  bool ReadBCF_Old(FILE *fp); // support obsolete format
104  bool ReadXML(const char *pathname, bool progress_callback(int) = NULL);
105 
106  bool WriteXML(const char *pathname, bool bGZip = false) const;
107  bool WriteFootprintsToSHP(const char *pathname);
108  bool WriteFootprintsToCanoma3DV(const char *pathname, const DRECT *area,
109  const vtHeightField *pHF);
110 
111  bool FindClosestBuildingCorner(const DPoint2 &point, double epsilon,
112  int &building, int &corner, double &distance);
113  bool FindClosestBuildingCenter(const DPoint2 &point, double epsilon,
114  int &building, double &distance);
115  bool FindClosestLinearCorner(const DPoint2 &point, double epsilon,
116  int &structure, int &corner, double &distance);
117 
118  bool FindClosestStructure(const DPoint2 &point, double epsilon,
119  int &structure, double &distance, float fMaxInstRadius = 1E9f,
120  float fLinearWidthBuffer = 0.0f);
121  bool FindClosestBuilding(const DPoint2 &point, double epsilon,
122  int &structure, double &closest);
123 
124  bool IsEmpty() { return (GetSize() == 0); }
125  void GetExtents(DRECT &ext) const;
126  void Offset(const DPoint2 &delta);
127 
128  int AddFoundations(vtHeightField *pHF, bool progress_callback(int) = NULL);
129  void RemoveFoundations();
130 
131  // selection
132  int NumSelected();
133  void DeselectAll();
134 
135  // override these 'Factory' methods so that the vtStructureArray base
136  // methods can be capable of handling subclasses of vtBuilding
137  virtual vtBuilding *NewBuilding();
138  virtual vtFence *NewFence();
139  virtual vtStructInstance *NewInstance();
140 
141  // convenience methods that create, add, and return a new structure
142  vtBuilding *AddNewBuilding();
143  vtFence *AddNewFence();
144  vtStructInstance *AddNewInstance();
145 
146  vtBuilding *AddBuildingFromLineString(class OGRLineString *pLineString);
147 
148  // override to catch edit hightlighting
149  virtual void SetEditedEdge(vtBuilding *bld, int lev, int edge);
150 
151  vtProjection m_proj;
152 
153 protected:
154  vtString m_strFilename;
155 
156  // used to indicate which edge should be hightlighted during editing
157  vtBuilding *m_pEditBuilding;
158  int m_iEditLevel;
159  int m_iEditEdge;
160  int m_iLastSelected;
161 };
162 
163 extern vtStructureArray g_DefaultStructures;
164 
165 // Helpers
166 int GetSHPType(const char *filename);
167 
168 bool SetupDefaultStructures(const vtString &fname);
169 vtBuilding *GetClosestDefault(vtBuilding *pBld);
170 vtFence *GetClosestDefault(vtFence *pFence);
171 vtStructInstance *GetClosestDefault(vtStructInstance *pInstance);
172 
173 #endif // STRUCTARRAYH
174