ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/CAD4FE/src/CAD4FE_VertexCriteria.cpp
Revision: 1158
Committed: Thu Jun 13 22:18:49 2024 UTC (11 months ago) by francois
File size: 13412 byte(s)
Error occurred while calculating annotation data.
Log Message:
compatibilité Ubuntu 22.04
Suppression des refeences à Windows
Ajout d'une banière

File Contents

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