-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzone.cpp
More file actions
248 lines (219 loc) · 7.87 KB
/
Copy pathzone.cpp
File metadata and controls
248 lines (219 loc) · 7.87 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*************************************************************************
Zone - description
-------------------
authors : Laurent Francioli
copyright : Institut universitaire romand de Sante au Travail
University of Geneva (UniGe)
*************************************************************************/
#include "zone.h"
//----------------------------------------------------------------- PUBLIC
//--------------------------------------------------------- Public Methods
void Zone::addZoneIP(int IP){
zoneIP+=IP;
if(subZones){
vector<Zone*>::iterator subzoneIter;
for(subzoneIter=subZones->begin();subzoneIter!=subZones->end();++subzoneIter){
(*subzoneIter)->addZoneIP(IP);
}
}
if(zoneVertices){
}
}
void Zone::setZoneIP(int IP){
zoneIP=IP;
if(subZones){
vector<Zone*>::iterator subzoneIter;
for(subzoneIter=subZones->begin();subzoneIter!=subZones->end();++subzoneIter){
(*subzoneIter)->setZoneIP(IP);
}
}
}
void Zone::resetZoneIP(){
zoneIP=1;
if(subZones){
vector<Zone*>::iterator subzoneIter;
for(subzoneIter=subZones->begin();subzoneIter!=subZones->end();++subzoneIter){
(*subzoneIter)->resetZoneIP();
}
}
}
void Zone::addSubZone(Zone *subZone){
if(!subZones){
subZones = new vector<Zone*>;
}
subZones->push_back(subZone);
}
void Zone::mergeZoneIntensity(EvaluatedIntensity* intensity){
if(!intensity->intensityList || !zoneEvaluatedIntensity->intensityList || intensity->intensityList->size() != zoneEvaluatedIntensity->intensityList->size()){
return;
}
//Merge dates
if((*intensity->beginDate) < (*zoneEvaluatedIntensity->beginDate)){
delete zoneEvaluatedIntensity->beginDate;
zoneEvaluatedIntensity->beginDate = new Date(*intensity->beginDate);
}
if((*intensity->endDate) > (*zoneEvaluatedIntensity->endDate)){
delete zoneEvaluatedIntensity->endDate;
zoneEvaluatedIntensity->endDate = new Date(*intensity->endDate);
}
//Merge Intensities
IntensityList::iterator intIter;
IntensityList::iterator zoneIntIter = zoneEvaluatedIntensity->intensityList->begin();
for(intIter = intensity->intensityList->begin(); intIter != intensity->intensityList->end(); ++intIter){
(*zoneIntIter) += (*intIter);
++zoneIntIter;
}
}
void Zone::multiplyZoneIntensities(float factor){
//Multiply the zone intensity
IntensityList::iterator zoneIntIter;
for(zoneIntIter = zoneEvaluatedIntensity->intensityList->begin(); zoneIntIter != zoneEvaluatedIntensity->intensityList->end(); ++zoneIntIter){
(*zoneIntIter) *= factor;
}
//Multiply the subzones intensites
if(subZones){
vector<Zone*>::iterator subZoneIter;
for(subZoneIter = subZones->begin(); subZoneIter != subZones->end(); ++subZoneIter){
(*subZoneIter)->multiplyZoneIntensities(factor);
}
}
}
//FACE INTENSITIES -- NOT CURRENTLY USED
/*void Zone::addZoneFace(CFaceO *face){
if(!zoneFaces){
zoneFaces = new map<CFaceO*,int>;
}
(*zoneFaces)[face] += 1;
}*/
void Zone::evaluateIntensity(VertexIntensities *vertexIntensities, const Date &beginDate, const Date &endDate){
//Create Intensity container and intiate its values
Intensity intensity;
intensity.direct = 0;
intensity.diffused = 0;
intensity.reflected = 0;
//First evaluate the subzones -if any - recursively and get their values back
if(subZones){
vector<Zone*>::iterator zoneIter;
float vertSurface;
for(zoneIter = subZones->begin(); zoneIter!=subZones->end(); zoneIter++){
(*zoneIter)->evaluateIntensity(vertexIntensities,beginDate,endDate);
vertSurface = (*zoneIter)->getSurface();
//Note that the intensities need to be multiplied by the vertex surface in order to ponder them.
//The full zone intensity will be divided by the full zone surface later
intensity.direct += vertSurface*((*zoneIter)->getEvaluatedIntensity()->intensityList->back().direct);
intensity.diffused += vertSurface*((*zoneIter)->getEvaluatedIntensity()->intensityList->back().diffused);
intensity.reflected += vertSurface*((*zoneIter)->getEvaluatedIntensity()->intensityList->back().reflected);
zoneSurface += vertSurface;
}
}
//If the zone contains vertices, evaluate the intensity received
//by the zone (depends on vertex intensity and zone surface)
if(zoneVertices){
vector<CVertexO*>::iterator vertIter;
for(vertIter=zoneVertices->begin();vertIter!=zoneVertices->end();vertIter++){
//Get the area of all the faces around hte vertex
vcg::face::VFIterator<CFaceO> vfi(*vertIter);
float vertSurface = 0;
for(;!vfi.End();++vfi)
{
vertSurface += vcg::DoubleArea<CFaceO>(*(vfi.F())) / 2.0;
}
//Add the vertex intensity and area to the zone intensity and area
//Note that each vertex is multiplied by its surface for ponderation
//TODO: THIS SHOULD BE DONE INDEPENDANTLY OF THE ZONE EVALUATION!!!
(*vertexIntensities)[(*vertIter)]->setIP(zoneIP);
//END OF IMPORTANT TODO
intensity.direct += (vertSurface*((*vertexIntensities)[(*vertIter)]->direct));
intensity.diffused += (vertSurface*((*vertexIntensities)[(*vertIter)]->diffused));
intensity.reflected += (vertSurface*((*vertexIntensities)[(*vertIter)]->reflected));
zoneSurface += vertSurface;
}
}
//After all the subzones and vertices intensities and the zone
//area has been calculated, save all the data
if(zoneSurface == 0)
{
intensity.direct = 0;
intensity.diffused = 0;
intensity.reflected = 0;
}
else
{
intensity.direct = intensity.direct / zoneSurface;
intensity.diffused = intensity.diffused / zoneSurface;
intensity.reflected = intensity.reflected / zoneSurface;
}
zoneEvaluatedIntensity->beginDate = new Date(beginDate);
zoneEvaluatedIntensity->endDate = new Date(endDate);
zoneEvaluatedIntensity->intensityList = new vector<Intensity>;
zoneEvaluatedIntensity->intensityList->push_back(intensity);
}
void Zone::clearEvaluatedIntensities()
{
zoneSurface = 0;
if(zoneEvaluatedIntensity)
{
if(zoneEvaluatedIntensity->intensityList)
{
zoneEvaluatedIntensity->intensityList->clear();
delete zoneEvaluatedIntensity->intensityList;
zoneEvaluatedIntensity->intensityList = 0;
}
if(zoneEvaluatedIntensity->beginDate)
{
delete zoneEvaluatedIntensity->beginDate;
zoneEvaluatedIntensity->beginDate = 0;
}
if(zoneEvaluatedIntensity->endDate)
{
delete zoneEvaluatedIntensity->endDate;
zoneEvaluatedIntensity->endDate = 0;
}
}
if(subZones){
for(auto subzoneIter=subZones->begin();subzoneIter!=subZones->end();++subzoneIter)
(*subzoneIter)->clearEvaluatedIntensities();
}
}
//--------------------------------------------------- Operator Overloading
//---------------------------------------------- Constructors - destructor
Zone::Zone(std::string name, bool active, vcg::Color4b *color):zoneName(name),zoneActive(active), zoneColor(color){
subZones = 0;
zoneVertices = 0;
zoneSurface = 0;
zoneEvaluatedIntensity = new EvaluatedIntensity;
zoneIP = 1;
//FACE INTENSITIES -- NOT CURRENTLY USED
//zoneFaces = 0;
}
Zone::~Zone(){
if(zoneEvaluatedIntensity)
{
if(zoneEvaluatedIntensity->intensityList)
{
zoneEvaluatedIntensity->intensityList->clear();
delete zoneEvaluatedIntensity->intensityList;
}
delete zoneEvaluatedIntensity->beginDate;
delete zoneEvaluatedIntensity->endDate;
delete zoneEvaluatedIntensity;
}
if (zoneColor) delete zoneColor;
if (subZones){
while(!subZones->empty()){
delete subZones->back();
subZones->pop_back();
}
delete subZones;
}
if(zoneVertices){
delete zoneVertices;
}
//FACE INTENSITIES -- NOT CURRENTLY USED
/*if (zoneFaces){
zoneFaces->clear();
delete zoneFaces;
}*/
}
//---------------------------------------------------------------- PRIVATE
//------------------------------------------------------ Protected Methods