1 |
//--------------------------------------------------------------------------- |
2 |
|
3 |
#include <sstream> |
4 |
|
5 |
#pragma hdrstop |
6 |
|
7 |
#include <vector> |
8 |
using namespace std; |
9 |
|
10 |
#include "CAD4FE_MCBody.h" |
11 |
#include "CAD4FE_MCAA.h" |
12 |
#include "CAD4FE_MCEdge.h" |
13 |
#include "CAD4FE_MCVertex.h" |
14 |
#include "CAD4FE_mg_utils.h" |
15 |
#include "ot_algorithme_geometrique.h" |
16 |
#include "CAD4FE_Criteria.h" |
17 |
#include "CAD4FE_ColorMap.h" |
18 |
#include "CAD4FE_VertexCriteria.h" |
19 |
#include "CAD4FE_PolyCurve.h" |
20 |
#include "CAD4FE_GlobalEdgeCriteria.h" |
21 |
#include "CAD4FE_CoVertexCriteria.h" |
22 |
|
23 |
//--------------------------------------------------------------------------- |
24 |
|
25 |
#pragma package(smart_init) |
26 |
|
27 |
using namespace CAD4FE; |
28 |
|
29 |
VertexCriteria::VertexCriteria (MCVertex * __mcVertex, MCAA * __mcaa) |
30 |
: _mcaa(__mcaa), _mcVertex(__mcVertex) |
31 |
{ |
32 |
_mcVertex->get_point()->evaluer(_point); |
33 |
|
34 |
Update(); |
35 |
} |
36 |
|
37 |
VertexCriteria::~VertexCriteria() |
38 |
{ |
39 |
for (unsigned i=0; i<_covertexProps.size(); i++) |
40 |
{ |
41 |
CovertexCriteria * covp = _covertexProps[i]; |
42 |
delete covp; |
43 |
} |
44 |
} |
45 |
|
46 |
void |
47 |
VertexCriteria::Update() |
48 |
{ |
49 |
if (_mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id())->Rank() == 0) |
50 |
{ /* vertex isolated in the domain of a face */ |
51 |
_score = 1; // UpdateDiscreteCurvatureCriterion(); |
52 |
} |
53 |
else if ( _mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id())->Rank() == 2 |
54 |
&& ! _mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id())->IsLoop() ) |
55 |
{ |
56 |
/* vertex bounding 2 edges */ |
57 |
_score = UpdateShapeCriteria(); |
58 |
} |
59 |
// vertex interior to an edge |
60 |
else if ( _mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id())->IsLoop() ) |
61 |
{ |
62 |
_score = -1; |
63 |
} |
64 |
} |
65 |
|
66 |
double |
67 |
VertexCriteria::UpdateShapeCriteria() |
68 |
{ |
69 |
std::vector <CovertexCriteria *>::iterator it; |
70 |
|
71 |
_meshSize = _mcaa->GetSize(_point); |
72 |
|
73 |
std::vector<MCEdge *> adjEdges; |
74 |
_mcaa->GetMCBody()->Vertex_GetAdjacentEdges(_mcVertex, adjEdges); |
75 |
|
76 |
for (it = _covertexProps.begin(); |
77 |
it != _covertexProps.end(); |
78 |
it++) |
79 |
{ |
80 |
delete *it; |
81 |
_covertexProps.erase(it); |
82 |
} |
83 |
|
84 |
for (std::vector<MCEdge*>::iterator itEdge = adjEdges.begin(); |
85 |
itEdge != adjEdges.end(); itEdge++) |
86 |
{ |
87 |
MCEdge * edge = *itEdge; |
88 |
MG_COSOMMET * cov; |
89 |
if (edge->get_cosommet1()->get_sommet() == _mcVertex) |
90 |
cov = edge->get_cosommet1(); |
91 |
else |
92 |
cov = edge->get_cosommet2(); |
93 |
|
94 |
CovertexCriteria * covc = new CovertexCriteria(cov, _meshSize); |
95 |
_covertexProps.push_back(covc); |
96 |
} |
97 |
|
98 |
//_edgeLen, _epsilon, _deviationAngle, _score; * |
99 |
_edgeLen = _meshSize; |
100 |
for (it = _covertexProps.begin(); |
101 |
it != _covertexProps.end(); |
102 |
it++) |
103 |
{ |
104 |
CovertexCriteria * covc = (*it); |
105 |
double covertexLength = covc->GetLength(); |
106 |
if (covertexLength < _edgeLen) |
107 |
_edgeLen = covertexLength; |
108 |
} |
109 |
|
110 |
std::map < MCFace * , std::set<MCEdge *> > subset_face_edges; |
111 |
for (std::vector<MCEdge*>::iterator itEdge = adjEdges.begin(); |
112 |
itEdge != adjEdges.end(); itEdge++) |
113 |
{ |
114 |
std::set < MCFace * > adjfaces = _mcaa->GetMCBody()->Edge_GetAdjacentFaces(*itEdge); |
115 |
|
116 |
for ( std::set < MCFace * >::iterator itF = adjfaces.begin(); |
117 |
itF != adjfaces.end(); |
118 |
itF++) |
119 |
{ |
120 |
MCFace * f = *itF; |
121 |
/*if (subset_face_edges.find(f) == subset_face_edges.end()) |
122 |
{ |
123 |
std::set<MCEdge *> new_edgeSet; |
124 |
subset_face_edges.insert(std::make_pair(f, new_edgeSet)); |
125 |
} */ |
126 |
subset_face_edges[f].insert( *itEdge ); |
127 |
} |
128 |
} |
129 |
|
130 |
_deviationAngle = 0; |
131 |
|
132 |
for (std::map < MCFace * , std::set<MCEdge *> >::iterator itFSE = subset_face_edges.begin(); |
133 |
itFSE != subset_face_edges.end(); |
134 |
itFSE++) |
135 |
{ |
136 |
std::vector<OT_VECTEUR_3D> points; |
137 |
for (std::set<MCEdge *>::iterator itE = (itFSE->second).begin(); |
138 |
itE != (itFSE->second).end(); |
139 |
itE++) |
140 |
{ |
141 |
MCEdge * edge = *itE; |
142 |
MG_COSOMMET * cov; |
143 |
if (edge->get_cosommet1()->get_sommet() == _mcVertex) |
144 |
cov = edge->get_cosommet1(); |
145 |
else |
146 |
cov = edge->get_cosommet2(); |
147 |
|
148 |
|
149 |
for (it = _covertexProps.begin(); |
150 |
it != _covertexProps.end(); |
151 |
it++) |
152 |
{ |
153 |
if ((*it)->GetCovertex() == cov) |
154 |
break; |
155 |
} |
156 |
|
157 |
if (it != _covertexProps.end()) |
158 |
{ |
159 |
OT_VECTEUR_3D p = (*it)->GetPoint(); |
160 |
points.push_back(p); |
161 |
} |
162 |
} |
163 |
if (points.size() == 2) |
164 |
{ |
165 |
double deviationAngle = OT_ALGORITHME_GEOMETRIQUE::Angle3D_Segment_Segment(points[0],_point,points[1]);
if ( deviationAngle > _deviationAngle ) |
166 |
_deviationAngle = deviationAngle; |
167 |
/* double epsilon = Dist3D_Point_Segment
( points [0], points [1], _point); |
168 |
if (epsilon > _epsilon) |
169 |
_epsilon = epsilon;*/ |
170 |
} |
171 |
} |
172 |
|
173 |
|
174 |
_score = std::max(GetDeviationAngleScore(),GetEdgeLengthScore()); |
175 |
return _score; |
176 |
} |
177 |
|
178 |
double VertexCriteria::GetDeviationAngle() |
179 |
{ |
180 |
return _deviationAngle; |
181 |
} |
182 |
|
183 |
|
184 |
double VertexCriteria::GetDeviationAngleScore() |
185 |
{ |
186 |
double criterionAngle; |
187 |
|
188 |
if (_deviationAngle < _mcaa->GetLimitAngle()) |
189 |
criterionAngle = 1 - _deviationAngle / _mcaa->GetLimitAngle(); |
190 |
else |
191 |
criterionAngle = .1*(1 - _deviationAngle / _mcaa->GetLimitAngle()); |
192 |
|
193 |
return criterionAngle; |
194 |
} |
195 |
|
196 |
double VertexCriteria::GetEdgeLengthScore() |
197 |
{ |
198 |
double criterionEdgeLen; |
199 |
double limitEdgeLen = _meshSize / _mcaa->GetMaxOverdensity(); |
200 |
criterionEdgeLen = 1 - std::min(limitEdgeLen, _edgeLen) / limitEdgeLen; |
201 |
return criterionEdgeLen; |
202 |
} |
203 |
|
204 |
double VertexCriteria::GetScore() |
205 |
{ |
206 |
// Vertex having boundary conditions |
207 |
if (_mcVertex->get_nb_ccf()) |
208 |
return -1; |
209 |
|
210 |
Graph::Arc * arc = _mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id()); |
211 |
int iVertexRank = arc->Rank(); |
212 |
bool bIsLoop = arc->IsLoop(); |
213 |
|
214 |
if (iVertexRank == 0) |
215 |
{ /* vertex isolated in the domain of a face */ |
216 |
_score = 1; // UpdateDiscreteCurvatureCriterion(); |
217 |
} |
218 |
else if ( iVertexRank == 2 |
219 |
&& ! bIsLoop ) |
220 |
{ |
221 |
/* vertex bounding 2 edges */ |
222 |
|
223 |
_score = std::max(GetDeviationAngleScore(), GetEdgeLengthScore()); |
224 |
|
225 |
// keep vertices that bound two edges with different deletion scores |
226 |
if (GlobalEdgeCriteria::SplitScore(_mcaa, _mcVertex)>0) |
227 |
_score = 0; |
228 |
|
229 |
// merge small edges |
230 |
std::vector<MCEdge *> edges; |
231 |
_mcaa->GetMCBody()->Vertex_GetAdjacentEdges(_mcVertex, edges); |
232 |
|
233 |
if (edges.size() != 2) |
234 |
return -1; |
235 |
|
236 |
for (int i=0; i<2; i++) |
237 |
{ |
238 |
MCEdge * e = edges[i]; |
239 |
|
240 |
double limitLength = _meshSize / _mcaa->GetMaxOverdensity(); |
241 |
double edgeLength = e->GetPolyCurve()->get_longueur(); |
242 |
|
243 |
if (edgeLength<limitLength) |
244 |
_score = 1; |
245 |
} |
246 |
|
247 |
} |
248 |
// vertex interior to an edge or bounding more than 2 edges ! |
249 |
else |
250 |
{ |
251 |
_score = -1; |
252 |
} |
253 |
|
254 |
return _score; |
255 |
} |
256 |
|
257 |
double VertexCriteria::GetEdgeLength() |
258 |
{ |
259 |
return _edgeLen; |
260 |
} |
261 |
|
262 |
MCVertex * VertexCriteria::GetVertex() |
263 |
{ |
264 |
return _mcVertex; |
265 |
} |
266 |
|
267 |
std::string VertexCriteria::InventorText() |
268 |
{ |
269 |
std::ostringstream out; |
270 |
|
271 |
unsigned char rgb[3]; |
272 |
ColorMap::jetColorMap(rgb, 1-_score, 0, 1); |
273 |
|
274 |
|
275 |
std::vector <CovertexCriteria *>::iterator it; |
276 |
double * point; |
277 |
point = _point; |
278 |
|
279 |
out << "\nSeparator { #sep1 \n"; |
280 |
out << "\n Coordinate3 {\n point [ \n"; |
281 |
out << point[0] << " " << point[1] << " " << point[2] << " \n"; |
282 |
out << "\n]\n}\n"; |
283 |
out << "PolygonOffset { \n"; |
284 |
out << "styles POINTS \n"; |
285 |
out << "factor 5.0 \n"; |
286 |
out << "units 1.0 \n"; |
287 |
out << "} \n"; |
288 |
out << "DrawStyle {\npointSize 6\n}\n"; |
289 |
out << "BaseColor { \n rgb "<<((double)rgb[0])/255<< " " <<((double)rgb[1])/255<<" "<<((double)rgb[2])/255<< "\n }\n"; |
290 |
out << "PointSet {\nstartIndex "<<0<<"\nnumPoints "<<1<<"\n}\n"; |
291 |
out << "} # end Sep1 \n"; |
292 |
|
293 |
/* rgb[0]=0;rgb[1]=255;rgb[2]=0; |
294 |
for (it = _covertexProps.begin(); |
295 |
it != _covertexProps.end(); |
296 |
it++) |
297 |
{ |
298 |
CovertexCriteria * cov = *it; |
299 |
|
300 |
double * point; |
301 |
point = cov->GetPoint(); |
302 |
|
303 |
out << "\nSeparator { #sep1 \n"; |
304 |
out << "\n Coordinate3 {\n point [ \n"; |
305 |
out << point[0] << " " << point[1] << " " << point[2] << " \n"; |
306 |
out << "\n]\n}\n"; |
307 |
out << "PolygonOffset { \n"; |
308 |
out << "styles POINTS \n"; |
309 |
out << "factor 5.0 \n"; |
310 |
out << "units 1.0 \n"; |
311 |
out << "} \n"; |
312 |
out << "DrawStyle {\npointSize 6\n}\n"; |
313 |
out << "BaseColor { \n rgb "<<((double)rgb[0])/255<< " " <<((double)rgb[1])/255<<" "<<((double)rgb[2])/255<< "\n }\n"; |
314 |
out << "PointSet {\nstartIndex "<<0<<"\nnumPoints "<<1<<"\n}\n"; |
315 |
out << "} # end Sep1 \n"; |
316 |
|
317 |
} */ |
318 |
|
319 |
|
320 |
return out.str(); |
321 |
} |