MAGiC  V5.0
Mailleurs Automatiques de Géometries intégrés à la Cao
CAD4FE_VertexCriteria.cpp
Aller à la documentation de ce fichier.
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"
36 #include "CAD4FE_Criteria.h"
37 #include "CAD4FE_ColorMap.h"
38 #include "CAD4FE_VertexCriteria.h"
39 #include "CAD4FE_PolyCurve.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 
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 {
97 
98  Update();
99 }
100 
102 {
103  for (unsigned i=0; i<_covertexProps.size(); i++)
104  {
105  CovertexCriteria * covp = _covertexProps[i];
106  delete covp;
107  }
108 }
109 
110 void
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 */
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
132 {
133  std::vector <CovertexCriteria *>::iterator it;
134 
136 
137  std::vector<MCEdge *> 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; *
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]);
230  if ( deviationAngle > _deviationAngle )
231  _deviationAngle = deviationAngle;
232 /* double epsilon = Dist3D_Point_Segment
233 ( points [0], points [1], _point);
234  if (epsilon > _epsilon)
235  _epsilon = epsilon;*/
236  }
237  }
238 
239 
241  return _score;
242 }
243 
245 {
246  return _deviationAngle;
247 }
248 
249 
251 {
252  double criterionAngle;
253 
254  if (_deviationAngle < _mcaa->GetLimitAngle())
255  criterionAngle = 1 - _deviationAngle / _mcaa->GetLimitAngle();
256  else
257  criterionAngle = .1*(1 - _deviationAngle / _mcaa->GetLimitAngle());
258 
259  return criterionAngle;
260 }
261 
263 {
264  double criterionEdgeLen;
265  double limitEdgeLen = _meshSize / _mcaa->GetMaxOverdensity();
266  criterionEdgeLen = 1 - std::min(limitEdgeLen, _edgeLen) / limitEdgeLen;
267  return criterionEdgeLen;
268 }
269 
271 {
272  // Vertex having boundary conditions
273  if (_mcVertex->get_nb_ccf())
274  return -1;
275 
276  Graph::Arc * arc = _mcaa->GetMCBody()->G10()->GetArc(_mcVertex->get_id());
277  int iVertexRank = arc->Rank();
278  bool bIsLoop = arc->IsLoop();
279 
280 
281  if (iVertexRank == 0)
282  { /* vertex isolated in the domain of a face */
283  _score = 1; // UpdateDiscreteCurvatureCriterion();
284  }
285  else if ( iVertexRank == 2
286  && ! bIsLoop )
287  {
288  /* vertex bounding 2 edges */
289 
291 
292  std::vector<MCEdge *> edges2;
294 
295  // keep vertices that bouond two edges having different ccf
296  {
297  if (MG_TOPO_ccf_identique(edges2[0], edges2[1]) == 0)
298  {
299  return -1;
300  }
301  }
302 
303  // keep vertices that bound two edges with different colors
304  {
305 
306  unsigned char rgba1[4];
307  int is_colored1 = CAD4FE::GeometricTools::MG_TOPO_GetColor(edges2[0], rgba1);
308  unsigned char rgba2[4];
309  int is_colored2 = CAD4FE::GeometricTools::MG_TOPO_GetColor(edges2[1], rgba2);
310 
311  if (is_colored2 != is_colored1)
312  return -1;
313  else if ( rgba1[0] != rgba2[0] || rgba1[1] != rgba2[1] || rgba1[2] != rgba2[2] || rgba1[3] != rgba2[3])
314  return -1;
315  }
316 
317  // keep vertices that bound two edges with different deletion scores
319  _score = 0;
320 
321  // merge small edges
322  std::vector<MCEdge *> edges;
324 
325  if (edges.size() != 2)
326  return -1;
327 
328  for (int i=0; i<2; i++)
329  {
330  MCEdge * e = edges[i];
331 
332  double limitLength = _meshSize / _mcaa->GetMaxOverdensity();
333  double edgeLength = e->GetPolyCurve()->get_longueur();
334 
335  if (edgeLength<limitLength)
336  _score = 1;
337  }
338 
339  }
340  // vertex interior to an edge or bounding more than 2 edges !
341  else
342  {
343  _score = -1;
344  }
345 
346  return _score;
347 }
348 
350 {
351  return _edgeLen;
352 }
353 
355 {
356  return _mcVertex;
357 }
358 
360 {
361  std::ostringstream out;
362 
363  unsigned char rgb[3];
364  ColorMap::jetColorMap(rgb, 1-GetScore(), 0, 1);
365 
366 
367  std::vector <CovertexCriteria *>::iterator it;
368  double * point;
369  point = _point;
370 
371  out << "\nSeparator { #sep1 \n";
372  out << "\n Coordinate3 {\n point [ \n";
373  out << point[0] << " " << point[1] << " " << point[2] << " \n";
374  out << "\n]\n}\n";
375  out << "PolygonOffset { \n";
376  out << "styles POINTS \n";
377  out << "factor 5.0 \n";
378  out << "units 1.0 \n";
379  out << "} \n";
380  out << "DrawStyle {\npointSize 6\n}\n";
381  out << "BaseColor { \n rgb "<<((double)rgb[0])/255<< " " <<((double)rgb[1])/255<<" "<<((double)rgb[2])/255<< "\n }\n";
382  out << "PointSet {\nstartIndex "<<0<<"\nnumPoints "<<1<<"\n}\n";
383  out << "} # end Sep1 \n";
384 
385  /* rgb[0]=0;rgb[1]=255;rgb[2]=0;
386  for (it = _covertexProps.begin();
387  it != _covertexProps.end();
388  it++)
389  {
390  CovertexCriteria * cov = *it;
391 
392  double * point;
393  point = cov->GetPoint();
394 
395  out << "\nSeparator { #sep1 \n";
396  out << "\n Coordinate3 {\n point [ \n";
397  out << point[0] << " " << point[1] << " " << point[2] << " \n";
398  out << "\n]\n}\n";
399  out << "PolygonOffset { \n";
400  out << "styles POINTS \n";
401  out << "factor 5.0 \n";
402  out << "units 1.0 \n";
403  out << "} \n";
404  out << "DrawStyle {\npointSize 6\n}\n";
405  out << "BaseColor { \n rgb "<<((double)rgb[0])/255<< " " <<((double)rgb[1])/255<<" "<<((double)rgb[2])/255<< "\n }\n";
406  out << "PointSet {\nstartIndex "<<0<<"\nnumPoints "<<1<<"\n}\n";
407  out << "} # end Sep1 \n";
408 
409  } */
410 
411 
412  return out.str();
413 }
MG_TOPO_ccf_identique
int MG_TOPO_ccf_identique(MG_ELEMENT_TOPOLOGIQUE *__A, MG_ELEMENT_TOPOLOGIQUE *__B)
Definition: CAD4FE_VertexCriteria.cpp:50
MG_ARETE::get_cosommet2
virtual class MG_COSOMMET * get_cosommet2(void)
Definition: mg_arete.cpp:85
HypergraphLib::Arc::IsLoop
bool IsLoop()
Definition: hypergraphlib_arc.cpp:120
CAD4FE::PolyCurve::get_longueur
double get_longueur(double __s_min=-1, double __s_max=-1, double precision=1E-6)
Definition: CAD4FE_PolyCurve.cpp:669
CAD4FE::VertexCriteria::_meshSize
double _meshSize
Definition: CAD4FE_VertexCriteria.h:62
CAD4FE_MCBody.h
CAD4FE::CovertexCriteria::GetLength
double GetLength() const
Definition: CAD4FE_CoVertexCriteria.cpp:87
CAD4FE::VertexCriteria::_score
double _score
Definition: CAD4FE_VertexCriteria.h:65
CAD4FE::MCAA::GetSize
double GetSize(double xyz[3])
Definition: CAD4FE_MCAA.cpp:923
MG_IDENTIFICATEUR::get_id
unsigned long get_id()
Definition: mg_identificateur.cpp:53
CAD4FE::VertexCriteria::GetVertex
MCVertex * GetVertex()
Definition: CAD4FE_VertexCriteria.cpp:354
MG_COSOMMET
Definition: mg_cosommet.h:31
CAD4FE::VertexCriteria::~VertexCriteria
~VertexCriteria()
Definition: CAD4FE_VertexCriteria.cpp:101
CAD4FE::MCAA
Definition: CAD4FE_MCAA.h:73
CAD4FE::VertexCriteria::_mcVertex
MCVertex * _mcVertex
Definition: CAD4FE_VertexCriteria.h:59
HypergraphLib::Graph::GetArc
Arc * GetArc(int) const
Definition: hypergraphlib_graph.cpp:188
HypergraphLib::Arc
Definition: hypergraphlib_arc.h:37
CAD4FE::VertexCriteria::UpdateShapeCriteria
double UpdateShapeCriteria()
Definition: CAD4FE_VertexCriteria.cpp:131
CAD4FE::VertexCriteria::_covertexProps
std::vector< CovertexCriteria * > _covertexProps
Definition: CAD4FE_VertexCriteria.h:57
CAD4FE::VertexCriteria::GetEdgeLength
double GetEdgeLength()
Definition: CAD4FE_VertexCriteria.cpp:349
CAD4FE_Criteria.h
OT_ALGORITHME_GEOMETRIQUE::Angle3D_Segment_Segment
static double Angle3D_Segment_Segment(double __v0[3], double __v1[3], double __v2[3])
Definition: ot_algorithme_geometrique.cpp:458
MG_ELEMENT_TOPOLOGIQUE::get_type_ccf
virtual void get_type_ccf(int num, char *nom)
Definition: mg_element_topologique.cpp:95
MG_ELEMENT_TOPOLOGIQUE
Definition: mg_element_topologique.h:51
CAD4FE::MCBody::G10
Graph::Graph * G10() const
Definition: CAD4FE_MCBody.cpp:292
CAD4FE::VertexCriteria::GetDeviationAngle
double GetDeviationAngle()
Definition: CAD4FE_VertexCriteria.cpp:244
f
double f(double x, long nb, double *xfonc, double *fonc, double eng, double eni, double lambda, double nor, double *fonc2)
Definition: fct_generateur_calibrage.cpp:96
CAD4FE::VertexCriteria::GetEdgeLengthScore
double GetEdgeLengthScore()
Definition: CAD4FE_VertexCriteria.cpp:262
MG_ELEMENT_TOPOLOGIQUE::get_nb_ccf
virtual int get_nb_ccf(void)
Definition: mg_element_topologique.cpp:154
CAD4FE::MCAA::GetMaxOverdensity
double GetMaxOverdensity()
Definition: CAD4FE_MCAA.cpp:224
CAD4FE::MCVertex
Definition: CAD4FE_MCVertex.h:35
CAD4FE_MCVertex.h
CAD4FE::VertexCriteria::InventorText
std::string InventorText()
Definition: CAD4FE_VertexCriteria.cpp:359
CAD4FE::MCBody::Edge_GetAdjacentFaces
std::set< MCFace * > Edge_GetAdjacentFaces(MCEdge *__mcEdge)
Definition: CAD4FE_MCBody.cpp:1240
CAD4FE::VertexCriteria::_edgeLen
double _edgeLen
Definition: CAD4FE_VertexCriteria.h:65
CAD4FE::VertexCriteria::_point
OT_VECTEUR_3D _point
Definition: CAD4FE_VertexCriteria.h:58
CAD4FE::CovertexCriteria
Definition: CAD4FE_CoVertexCriteria.h:37
MG_SOMMET::get_point
virtual MG_POINT * get_point(void)
Definition: mg_sommet.cpp:52
CAD4FE_MCAA.h
HypergraphLib::Arc::Rank
int Rank() const
Definition: hypergraphlib_arc.cpp:87
MG_COSOMMET::get_sommet
virtual MG_SOMMET * get_sommet(void)
Definition: mg_cosommet.cpp:83
CAD4FE_MCEdge.h
CAD4FE_ColorMap.h
CAD4FE_VertexCriteria.h
OT_VECTEUR_3D
Definition: ot_mathematique.h:94
CAD4FE::MCAA::GetMCBody
MCBody * GetMCBody() const
Definition: CAD4FE_MCAA.cpp:622
CAD4FE_CoVertexCriteria.h
CAD4FE::MCEdge
Definition: CAD4FE_MCEdge.h:48
CAD4FE_Geometric_Tools.h
CAD4FE_PolyCurve.h
ot_algorithme_geometrique.h
CAD4FE::MCAA::GetLimitAngle
double GetLimitAngle()
Definition: CAD4FE_MCAA.cpp:149
CAD4FE::VertexCriteria::GetScore
double GetScore()
Definition: CAD4FE_VertexCriteria.cpp:270
CAD4FE::GeometricTools::MG_TOPO_GetColor
static int MG_TOPO_GetColor(MG_ELEMENT_TOPOLOGIQUE *ele, double &)
Definition: CAD4FE_Geometric_Tools.cpp:687
CAD4FE::VertexCriteria::Update
void Update()
Definition: CAD4FE_VertexCriteria.cpp:111
CAD4FE
Definition: CAD4FE_ClosestPoint_Segment_MG_ARETE.h:34
CAD4FE::VertexCriteria::GetDeviationAngleScore
double GetDeviationAngleScore()
Definition: CAD4FE_VertexCriteria.cpp:250
CAD4FE::GlobalEdgeCriteria::SplitScore
double SplitScore(double __splitPoint[3])
Definition: CAD4FE_GlobalEdgeCriteria.cpp:352
CAD4FE::MCEdge::GetPolyCurve
PolyCurve * GetPolyCurve()
Definition: CAD4FE_MCEdge.cpp:98
CAD4FE::VertexCriteria::_deviationAngle
double _deviationAngle
Definition: CAD4FE_VertexCriteria.h:65
CAD4FE::MCFace
Definition: CAD4FE_MCFace.h:50
MG_ELEMENT_TOPOLOGIQUE::get_valeur_ccf
virtual bool get_valeur_ccf(char *nom, double &val)
Definition: mg_element_topologique.cpp:310
MG_ARETE::get_cosommet1
virtual class MG_COSOMMET * get_cosommet1(void)
Definition: mg_arete.cpp:81
CAD4FE::ColorMap::jetColorMap
static void jetColorMap(unsigned char *rgb, double value, double min, double max)
Definition: CAD4FE_ColorMap.cpp:102
CAD4FE_GlobalEdgeCriteria.h
CAD4FE::MCBody::Vertex_GetAdjacentEdges
void Vertex_GetAdjacentEdges(MCVertex *__mcVertex, std::vector< MCEdge * > &__list)
Definition: CAD4FE_MCBody.cpp:1393
CAD4FE::VertexCriteria::_mcaa
MCAA * _mcaa
Definition: CAD4FE_VertexCriteria.h:67
MG_POINT::evaluer
virtual void evaluer(double *xyz)=0
CAD4FE_mg_utils.h