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 |
#include "CAD4FE_Geometric_Tools.h" |
23 |
|
24 |
//--------------------------------------------------------------------------- |
25 |
|
26 |
#pragma package(smart_init) |
27 |
|
28 |
using namespace CAD4FE; |
29 |
|
30 |
|
31 |
int MG_TOPO_ccf_identique( MG_ELEMENT_TOPOLOGIQUE *__A, MG_ELEMENT_TOPOLOGIQUE * __B) |
32 |
{ |
33 |
if (__A->get_nb_ccf() < __B->get_nb_ccf()) |
34 |
{ |
35 |
MG_ELEMENT_TOPOLOGIQUE *tmp = __A; |
36 |
__A = __B; |
37 |
__B = tmp; |
38 |
} |
39 |
for (int i=0; i<__A->get_nb_ccf(); i++) |
40 |
{ |
41 |
char nom_A [3]; |
42 |
__A->get_type_ccf(i, nom_A); |
43 |
double val_A = __A->get_valeur_ccf(i); |
44 |
|
45 |
int found = 0; |
46 |
int same = 0; |
47 |
|
48 |
for (int j=0; j<__B->get_nb_ccf(); j++) |
49 |
{ |
50 |
|
51 |
char nom_B [3]; |
52 |
__B->get_type_ccf(j, nom_B); |
53 |
double val_B = __B->get_valeur_ccf(j); |
54 |
|
55 |
if (strcmp(nom_A, nom_B) == 0) |
56 |
{ |
57 |
found = 1; |
58 |
if (val_A == val_B) |
59 |
{ |
60 |
same = 1; |
61 |
} |
62 |
break; |
63 |
} |
64 |
} |
65 |
|
66 |
if (found == 0 || same == 0) |
67 |
{ |
68 |
return 0; |
69 |
} |
70 |
} |
71 |
return 1; |
72 |
} |
73 |
|
74 |
VertexCriteria::VertexCriteria (MCVertex * __mcVertex, MCAA * __mcaa) |
75 |
: _mcaa(__mcaa), _mcVertex(__mcVertex) |
76 |
{ |
77 |
_mcVertex->get_point()->evaluer(_point); |
78 |
|
79 |
Update(); |
80 |
} |
81 |
|
82 |
VertexCriteria::~VertexCriteria() |
83 |
{ |
84 |
for (unsigned i=0; i<_covertexProps.size(); i++) |
85 |
{ |
86 |
CovertexCriteria * covp = _covertexProps[i]; |
87 |
delete covp; |
88 |
} |
89 |
} |
90 |
|
91 |
void |
92 |
VertexCriteria::Update() |
93 |
{ |
94 |
if (_mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id())->Rank() == 0) |
95 |
{ /* vertex isolated in the domain of a face */ |
96 |
_score = 1; // UpdateDiscreteCurvatureCriterion(); |
97 |
} |
98 |
else if ( _mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id())->Rank() == 2 |
99 |
&& ! _mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id())->IsLoop() ) |
100 |
{ |
101 |
/* vertex bounding 2 edges */ |
102 |
_score = UpdateShapeCriteria(); |
103 |
} |
104 |
// vertex interior to an edge |
105 |
else if ( _mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id())->IsLoop() ) |
106 |
{ |
107 |
_score = -1; |
108 |
} |
109 |
} |
110 |
|
111 |
double |
112 |
VertexCriteria::UpdateShapeCriteria() |
113 |
{ |
114 |
std::vector <CovertexCriteria *>::iterator it; |
115 |
|
116 |
_meshSize = _mcaa->GetSize(_point); |
117 |
|
118 |
std::vector<MCEdge *> adjEdges; |
119 |
_mcaa->GetMCBody()->Vertex_GetAdjacentEdges(_mcVertex, adjEdges); |
120 |
|
121 |
for (it = _covertexProps.begin(); |
122 |
it != _covertexProps.end(); |
123 |
it++) |
124 |
{ |
125 |
delete *it; |
126 |
_covertexProps.erase(it); |
127 |
} |
128 |
|
129 |
for (std::vector<MCEdge*>::iterator itEdge = adjEdges.begin(); |
130 |
itEdge != adjEdges.end(); itEdge++) |
131 |
{ |
132 |
MCEdge * edge = *itEdge; |
133 |
MG_COSOMMET * cov; |
134 |
if (edge->get_cosommet1()->get_sommet() == _mcVertex) |
135 |
cov = edge->get_cosommet1(); |
136 |
else |
137 |
cov = edge->get_cosommet2(); |
138 |
|
139 |
CovertexCriteria * covc = new CovertexCriteria(cov, _meshSize); |
140 |
_covertexProps.push_back(covc); |
141 |
} |
142 |
|
143 |
//_edgeLen, _epsilon, _deviationAngle, _score; * |
144 |
_edgeLen = _meshSize; |
145 |
for (it = _covertexProps.begin(); |
146 |
it != _covertexProps.end(); |
147 |
it++) |
148 |
{ |
149 |
CovertexCriteria * covc = (*it); |
150 |
double covertexLength = covc->GetLength(); |
151 |
if (covertexLength < _edgeLen) |
152 |
_edgeLen = covertexLength; |
153 |
} |
154 |
|
155 |
std::map < MCFace * , std::set<MCEdge *> > subset_face_edges; |
156 |
for (std::vector<MCEdge*>::iterator itEdge = adjEdges.begin(); |
157 |
itEdge != adjEdges.end(); itEdge++) |
158 |
{ |
159 |
std::set < MCFace * > adjfaces = _mcaa->GetMCBody()->Edge_GetAdjacentFaces(*itEdge); |
160 |
|
161 |
for ( std::set < MCFace * >::iterator itF = adjfaces.begin(); |
162 |
itF != adjfaces.end(); |
163 |
itF++) |
164 |
{ |
165 |
MCFace * f = *itF; |
166 |
/*if (subset_face_edges.find(f) == subset_face_edges.end()) |
167 |
{ |
168 |
std::set<MCEdge *> new_edgeSet; |
169 |
subset_face_edges.insert(std::make_pair(f, new_edgeSet)); |
170 |
} */ |
171 |
subset_face_edges[f].insert( *itEdge ); |
172 |
} |
173 |
} |
174 |
|
175 |
_deviationAngle = 0; |
176 |
|
177 |
for (std::map < MCFace * , std::set<MCEdge *> >::iterator itFSE = subset_face_edges.begin(); |
178 |
itFSE != subset_face_edges.end(); |
179 |
itFSE++) |
180 |
{ |
181 |
std::vector<OT_VECTEUR_3D> points; |
182 |
for (std::set<MCEdge *>::iterator itE = (itFSE->second).begin(); |
183 |
itE != (itFSE->second).end(); |
184 |
itE++) |
185 |
{ |
186 |
MCEdge * edge = *itE; |
187 |
MG_COSOMMET * cov; |
188 |
if (edge->get_cosommet1()->get_sommet() == _mcVertex) |
189 |
cov = edge->get_cosommet1(); |
190 |
else |
191 |
cov = edge->get_cosommet2(); |
192 |
|
193 |
|
194 |
for (it = _covertexProps.begin(); |
195 |
it != _covertexProps.end(); |
196 |
it++) |
197 |
{ |
198 |
if ((*it)->GetCovertex() == cov) |
199 |
break; |
200 |
} |
201 |
|
202 |
if (it != _covertexProps.end()) |
203 |
{ |
204 |
OT_VECTEUR_3D p = (*it)->GetPoint(); |
205 |
points.push_back(p); |
206 |
} |
207 |
} |
208 |
if (points.size() == 2) |
209 |
{ |
210 |
double deviationAngle = OT_ALGORITHME_GEOMETRIQUE::Angle3D_Segment_Segment(points[0],_point,points[1]);
if ( deviationAngle > _deviationAngle ) |
211 |
_deviationAngle = deviationAngle; |
212 |
/* double epsilon = Dist3D_Point_Segment
( points [0], points [1], _point); |
213 |
if (epsilon > _epsilon) |
214 |
_epsilon = epsilon;*/ |
215 |
} |
216 |
} |
217 |
|
218 |
|
219 |
_score = std::max(GetDeviationAngleScore(),GetEdgeLengthScore()); |
220 |
return _score; |
221 |
} |
222 |
|
223 |
double VertexCriteria::GetDeviationAngle() |
224 |
{ |
225 |
return _deviationAngle; |
226 |
} |
227 |
|
228 |
|
229 |
double VertexCriteria::GetDeviationAngleScore() |
230 |
{ |
231 |
double criterionAngle; |
232 |
|
233 |
if (_deviationAngle < _mcaa->GetLimitAngle()) |
234 |
criterionAngle = 1 - _deviationAngle / _mcaa->GetLimitAngle(); |
235 |
else |
236 |
criterionAngle = .1*(1 - _deviationAngle / _mcaa->GetLimitAngle()); |
237 |
|
238 |
return criterionAngle; |
239 |
} |
240 |
|
241 |
double VertexCriteria::GetEdgeLengthScore() |
242 |
{ |
243 |
double criterionEdgeLen; |
244 |
double limitEdgeLen = _meshSize / _mcaa->GetMaxOverdensity(); |
245 |
criterionEdgeLen = 1 - std::min(limitEdgeLen, _edgeLen) / limitEdgeLen; |
246 |
return criterionEdgeLen; |
247 |
} |
248 |
|
249 |
double VertexCriteria::GetScore() |
250 |
{ |
251 |
// Vertex having boundary conditions |
252 |
if (_mcVertex->get_nb_ccf()) |
253 |
return -1; |
254 |
|
255 |
Graph::Arc * arc = _mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id()); |
256 |
int iVertexRank = arc->Rank(); |
257 |
bool bIsLoop = arc->IsLoop(); |
258 |
|
259 |
|
260 |
if (iVertexRank == 0) |
261 |
{ /* vertex isolated in the domain of a face */ |
262 |
_score = 1; // UpdateDiscreteCurvatureCriterion(); |
263 |
} |
264 |
else if ( iVertexRank == 2 |
265 |
&& ! bIsLoop ) |
266 |
{ |
267 |
/* vertex bounding 2 edges */ |
268 |
|
269 |
_score = std::max(GetDeviationAngleScore(), GetEdgeLengthScore()); |
270 |
|
271 |
std::vector<MCEdge *> edges2; |
272 |
_mcaa->GetMCBody()->Vertex_GetAdjacentEdges(_mcVertex, edges2); |
273 |
|
274 |
// keep vertices that bouond two edges having different ccf |
275 |
{ |
276 |
if (MG_TOPO_ccf_identique(edges2[0], edges2[1]) == 0) |
277 |
{ |
278 |
return -1; |
279 |
} |
280 |
} |
281 |
|
282 |
// keep vertices that bound two edges with different colors |
283 |
{ |
284 |
|
285 |
unsigned char rgba1[4];
|
286 |
int is_colored1 = CAD4FE::GeometricTools::MG_TOPO_GetColor(edges2[0], rgba1);
|
287 |
unsigned char rgba2[4];
|
288 |
int is_colored2 = CAD4FE::GeometricTools::MG_TOPO_GetColor(edges2[1], rgba2);
|
289 |
|
290 |
if (is_colored2 != is_colored1)
|
291 |
return -1;
|
292 |
else if ( rgba1[0] != rgba2[0] || rgba1[1] != rgba2[1] || rgba1[2] != rgba2[2] || rgba1[3] != rgba2[3])
|
293 |
return -1; |
294 |
} |
295 |
|
296 |
// keep vertices that bound two edges with different deletion scores |
297 |
if (GlobalEdgeCriteria::SplitScore(_mcaa, _mcVertex)>0) |
298 |
_score = 0; |
299 |
|
300 |
// merge small edges |
301 |
std::vector<MCEdge *> edges; |
302 |
_mcaa->GetMCBody()->Vertex_GetAdjacentEdges(_mcVertex, edges); |
303 |
|
304 |
if (edges.size() != 2) |
305 |
return -1; |
306 |
|
307 |
for (int i=0; i<2; i++) |
308 |
{ |
309 |
MCEdge * e = edges[i]; |
310 |
|
311 |
double limitLength = _meshSize / _mcaa->GetMaxOverdensity(); |
312 |
double edgeLength = e->GetPolyCurve()->get_longueur(); |
313 |
|
314 |
if (edgeLength<limitLength) |
315 |
_score = 1; |
316 |
} |
317 |
|
318 |
} |
319 |
// vertex interior to an edge or bounding more than 2 edges ! |
320 |
else |
321 |
{ |
322 |
_score = -1; |
323 |
} |
324 |
|
325 |
return _score; |
326 |
} |
327 |
|
328 |
double VertexCriteria::GetEdgeLength() |
329 |
{ |
330 |
return _edgeLen; |
331 |
} |
332 |
|
333 |
MCVertex * VertexCriteria::GetVertex() |
334 |
{ |
335 |
return _mcVertex; |
336 |
} |
337 |
|
338 |
std::string VertexCriteria::InventorText() |
339 |
{ |
340 |
std::ostringstream out; |
341 |
|
342 |
unsigned char rgb[3]; |
343 |
ColorMap::jetColorMap(rgb, 1-GetScore(), 0, 1); |
344 |
|
345 |
|
346 |
std::vector <CovertexCriteria *>::iterator it; |
347 |
double * point; |
348 |
point = _point; |
349 |
|
350 |
out << "\nSeparator { #sep1 \n"; |
351 |
out << "\n Coordinate3 {\n point [ \n"; |
352 |
out << point[0] << " " << point[1] << " " << point[2] << " \n"; |
353 |
out << "\n]\n}\n"; |
354 |
out << "PolygonOffset { \n"; |
355 |
out << "styles POINTS \n"; |
356 |
out << "factor 5.0 \n"; |
357 |
out << "units 1.0 \n"; |
358 |
out << "} \n"; |
359 |
out << "DrawStyle {\npointSize 6\n}\n"; |
360 |
out << "BaseColor { \n rgb "<<((double)rgb[0])/255<< " " <<((double)rgb[1])/255<<" "<<((double)rgb[2])/255<< "\n }\n"; |
361 |
out << "PointSet {\nstartIndex "<<0<<"\nnumPoints "<<1<<"\n}\n"; |
362 |
out << "} # end Sep1 \n"; |
363 |
|
364 |
/* rgb[0]=0;rgb[1]=255;rgb[2]=0; |
365 |
for (it = _covertexProps.begin(); |
366 |
it != _covertexProps.end(); |
367 |
it++) |
368 |
{ |
369 |
CovertexCriteria * cov = *it; |
370 |
|
371 |
double * point; |
372 |
point = cov->GetPoint(); |
373 |
|
374 |
out << "\nSeparator { #sep1 \n"; |
375 |
out << "\n Coordinate3 {\n point [ \n"; |
376 |
out << point[0] << " " << point[1] << " " << point[2] << " \n"; |
377 |
out << "\n]\n}\n"; |
378 |
out << "PolygonOffset { \n"; |
379 |
out << "styles POINTS \n"; |
380 |
out << "factor 5.0 \n"; |
381 |
out << "units 1.0 \n"; |
382 |
out << "} \n"; |
383 |
out << "DrawStyle {\npointSize 6\n}\n"; |
384 |
out << "BaseColor { \n rgb "<<((double)rgb[0])/255<< " " <<((double)rgb[1])/255<<" "<<((double)rgb[2])/255<< "\n }\n"; |
385 |
out << "PointSet {\nstartIndex "<<0<<"\nnumPoints "<<1<<"\n}\n"; |
386 |
out << "} # end Sep1 \n"; |
387 |
|
388 |
} */ |
389 |
|
390 |
|
391 |
return out.str(); |
392 |
} |