-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuilding.hpp
95 lines (81 loc) · 2.96 KB
/
Building.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef BLDG_HPP
#define BLDG_HPP
#include <gdal/ogrsf_frmts.h>
class Building
{
public:
Building():_footprint(0) {}
Building(OGRPolygon* ply,double h,int idLot=-1):_footprint((OGRPolygon*)(ply->clone())),_h(h),_idLot(idLot) {}
Building(const Building& o){
_footprint = (OGRPolygon*)(o._footprint->clone());
_h = o._h;
_idLot = o._idLot;
}
~Building(){if(_footprint) _footprint->empty();}
inline OGRPolygon* footprint() const{return _footprint;}
inline double height() const{return _h;}
inline int idLot() const{return _idLot;}
inline OGRMultiPolygon* extrude() const
{
OGRMultiPolygon* block = new OGRMultiPolygon;
//extrude roof
OGRPolygon roof;
{
roof.addRing(_footprint->getExteriorRing());
OGRLinearRing* ring = roof.getExteriorRing();
for(int i=0; i<ring->getNumPoints(); i++)
ring->setPoint(i,ring->getX(i),ring->getY(i),_h);
}
if(int n = _footprint->getNumInteriorRings())
{
for (int j=0; j<n; j++)
{
roof.addRing(_footprint->getInteriorRing(j));
OGRLinearRing* ring = roof.getInteriorRing(j);
for(int i=0; i<ring->getNumPoints(); i++)
ring->setPoint(i,ring->getX(i),ring->getY(i),_h);
}
}
block->addGeometry(&roof);
//extrude exter walls
OGRLinearRing* ringEx = _footprint->getExteriorRing();
for(int i=0; i<ringEx->getNumPoints()-1; i++)
{
OGRPolygon wall;
OGRLinearRing ring;
ring.addPoint(ringEx->getX(i),ringEx->getY(i),0);
ring.addPoint(ringEx->getX(i+1),ringEx->getY(i+1),0);
ring.addPoint(ringEx->getX(i+1),ringEx->getY(i+1),_h);
ring.addPoint(ringEx->getX(i),ringEx->getY(i),_h);
ring.addPoint(ringEx->getX(i),ringEx->getY(i),0);
wall.addRing(&ring);
block->addGeometry(&wall);
}
//extrude inner walls if exist
if(int n = _footprint->getNumInteriorRings())
{
for (int i=0; i<n; i++)
{
OGRLinearRing* ringIn = _footprint->getInteriorRing(i);
for(int j=0; j<ringIn->getNumPoints()-1; j++)
{
OGRPolygon wall;
OGRLinearRing ring;
ring.addPoint(ringIn->getX(j),ringIn->getY(j),0);
ring.addPoint(ringIn->getX(j+1),ringIn->getY(j+1),0);
ring.addPoint(ringIn->getX(j+1),ringIn->getY(j+1),_h);
ring.addPoint(ringIn->getX(j),ringIn->getY(j),_h);
ring.addPoint(ringIn->getX(j),ringIn->getY(j),0);
wall.addRing(&ring);
block->addGeometry(&wall);
}
}
}
return block;
}
private:
OGRPolygon* _footprint;
double _h;
int _idLot;
};
#endif