Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Building.h
1 //
2 // Building.h
3 //
4 // Implements the vtBuilding class which represents a single built structure.
5 //
6 // Copyright (c) 2001-2008 Virtual Terrain Project
7 // Free for all uses, see license.txt for details.
8 //
9 
10 #ifndef BUILDINGH
11 #define BUILDINGH
12 
13 #include <stdio.h>
14 #include "MathTypes.h"
15 #include "LocalConversion.h"
16 #include "Structure.h"
17 #include "ogrsf_frmts.h"
18 
19 class vtHeightField;
20 class vtStructureArray;
21 
23 
24 #define MINIMUM_BASEMENT_SIZE 0.5 // Mininum size of an automatically generated basement layer in a building
25 
26 #define DEFAULT_BUILDING_SIZE 10.0 // Default size for buildings imported from points
27 
28 enum RoofType
29 {
30  ROOF_FLAT, ROOF_SHED, ROOF_GABLE, ROOF_HIP, ROOF_UNKNOWN, NUM_ROOFTYPES
31 };
32 
33 enum BldColor
34 {
35  BLD_BASIC,
36  BLD_ROOF,
37 };
38 
39 // Edge feature codes
40 #define WFC_WALL 1
41 #define WFC_GAP 2
42 #define WFC_POST 3
43 #define WFC_WINDOW 4
44 #define WFC_DOOR 5
45 
47 {
48 public:
49  vtEdgeFeature();
50  vtEdgeFeature(int code, float width = -1.0f, float vf1 = 0.0f, float vf2 = 1.0f);
51 
52  void SetDefaults();
53 
54  // classification code - door, window, wall etc.
55  int m_code;
56 
57  // style (to classify window/door/post style)
58  // TODO
59 
60  // overall color of this feature, or "-1 -1 -1" for default color
61  RGBi m_color;
62 
63  // width: positive values mean meters,
64  // negative values mean proportional scaling factors
65  float m_width;
66 
67  // vertical factors: from base, start/end of feature, normalized (0-1)
68  float m_vf1;
69  float m_vf2;
70 };
71 
80 class vtEdge
81 {
82 public:
83  vtEdge();
84  vtEdge(const vtEdge &lhs);
85  ~vtEdge();
86 
87  void Set(int doors, int windows, const char *material);
88  void AddFeature(int code, float width = -1.0f, float vf1 = 0.0f, float vf2 = 1.0f);
89  size_t NumFeatures() const { return m_Features.size(); }
90  int NumFeaturesOfCode(int code);
91  float FixedFeaturesWidth();
92  float ProportionTotal();
93 
94  // color
95  RGBi m_Color; // overall edge color
96 
97  // slope in degrees: 90 is vertical, 0 is horizontal
98  int m_iSlope;
99 
100  // eave_length
101  float m_fEaveLength;
102 
103  // members
104  const vtString *m_pMaterial;
105  std::vector<vtEdgeFeature> m_Features;
106  vtString m_Facade;
107 };
108 
109 #define MAX_WALLS 360 // the largest number of walls
110  // (largest number of points in a poly-shaped building)
111 
127 class vtLevel
128 {
129  friend class vtBuilding;
130 public:
131  vtLevel();
132  vtLevel(const vtLevel &from) { *this = from; }
133  ~vtLevel();
134 
135  // assignment operator
136  vtLevel &operator=(const vtLevel &v);
137 
138  void DeleteEdge(int iEdge);
139  bool AddEdge(const int iEdge, const DPoint2 &Point);
140  int NumEdges() const { return m_Edges.GetSize(); }
141  vtEdge *GetEdge(uint i) const;
142  float GetEdgeLength(uint i) const;
143  const vtString GetOverallEdgeMaterial();
144  bool GetOverallEdgeColor(RGBi &color);
145  RoofType GuessRoofType();
146  void FlipFootprintDirection();
147 
148  bool HasSlopedEdges() const;
149  bool IsHorizontal() const;
150  bool IsEdgeConvex(int i);
151  bool IsCornerConvex(int i);
152  bool IsUniform() const;
153 
154  void SetEdgeMaterial(const char *matname);
155  void SetEdgeColor(RGBi color);
156  void SetRoofType(RoofType rt, int iSlopeDegrees);
157  void SetEaveLength(float fMeters);
158 
159  uint m_iStories;
160  float m_fStoryHeight;
161 
162  void SetFootprint(const DLine2 &dl);
163  void SetFootprint(const DPolygon2 &poly);
164  void ResizeEdgesToMatchFootprint();
165 
166  DPolygon2 &GetFootprint() { return m_Foot; }
167  const DPolygon2 &GetFootprint() const { return m_Foot; }
168 
169  // outer ring
170  DLine2 &GetOuterFootprint() { return m_Foot[0]; }
171  const DLine2 &GetOuterFootprint() const { return m_Foot[0]; }
172 
173  void DetermineLocalFootprint(float fHeight);
174  const FPolygon3 &GetLocalFootprint() const { return m_LocalFootprint; }
175 
176 private:
177  void RebuildEdges(uint n);
178  void GetEdgePlane(uint i, FPlane &plane);
179  bool DetermineHeightFromSlopes();
180  void DeleteEdges();
181 
182  vtArray<vtEdge *> m_Edges;
183 
184  // footprint of the stories in this level
185  DPolygon2 m_Foot;
186 
187  // footprint in the local CS of this building
188  FPolygon3 m_LocalFootprint;
189 };
190 
201 class vtBuilding : public vtStructure
202 {
203 public:
204  vtBuilding();
205  ~vtBuilding();
206 
207  // copy
208  vtBuilding &operator=(const vtBuilding &v);
209 
210  // footprint methods
211  void SetFootprint(int i, const DLine2 &dl);
212  void SetFootprint(int i, const DPolygon2 &poly);
213 
214  const DPolygon2 &GetFootprint(int i) const { return m_Levels[i]->GetFootprint(); }
215  const DLine2 &GetOuterFootprint(int i) const { return m_Levels[i]->GetOuterFootprint(); }
216  bool GetBaseLevelCenter(DPoint2 &p) const;
217 
218  void SetRectangle(const DPoint2 &center, float fWidth, float fDepth,
219  float fRotation = 0.0f);
220  void SetCircle(const DPoint2 &center, float fRad);
221 
222  void FlipFootprintDirection();
223  float CalculateBaseElevation(vtHeightField *pHeightField);
224  void TransformCoords(OCT *trans);
225 
226  // roof methods
227  void SetRoofType(RoofType rt, int iSlope = -1, int iLev = -1);
228  RoofType GetRoofType();
229 
230  void SetColor(BldColor which, RGBi col);
231  RGBi GetColor(BldColor which) const;
232 
233  void SetStories(int i);
234  int GetStories() const;
235  float GetTotalHeight() const;
236 
237  uint GetNumLevels() const { return m_Levels.GetSize(); }
238  vtLevel *GetLevel(int i) { return (i < (int)m_Levels.GetSize()) ? m_Levels[i] : NULL; }
239  const vtLevel *GetLevel(int i) const { return (i < (int)m_Levels.GetSize()) ? m_Levels[i] : NULL; }
240  vtLevel *CreateLevel(const DPolygon2 &footprint);
241  vtLevel *CreateLevel();
242  void InsertLevel(int iLev, vtLevel *pLev);
243  void DeleteLevel(int iLev);
244 
245  bool GetExtents(DRECT &rect) const;
246  void Offset(const DPoint2 &delta);
247  double GetDistanceToInterior(const DPoint2 &point) const;
248 
249  void WriteXML(GZOutput &out, bool bDegrees) const;
250  void AddDefaultDetails();
251  void DetermineLocalFootprints();
252  const FPolygon3 &GetLocalFootprint(int i) const { return m_Levels[i]->GetLocalFootprint(); }
253 
254  static vtLocalConversion s_Conv;
255  static const char *GetEdgeFeatureString(int edgetype);
256  static int GetEdgeFeatureValue(const char *value);
257 
258  bool IsContainedBy(const DRECT &rect) const;
259  void SwapLevels(int lev1, int lev2);
260  void CopyFromDefault(vtBuilding *pDefBld, bool bDoHeight);
261 
262 protected:
263  // information about each story
264  vtArray<vtLevel *> m_Levels;
265 
266 private:
267  void DeleteLevels();
268 };
269 
270 typedef vtBuilding *vtBuildingPtr;
271 
273 
274 #endif // BUILDINGH
275