1 |
foucault |
27 |
//---------------------------------------------------------------------------
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
#pragma hdrstop
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
//---------------------------------------------------------------------------
|
8 |
foucault |
176 |
|
9 |
|
|
#include "gestionversion.h"
|
10 |
|
|
#include <vector>
|
11 |
|
|
using namespace std; |
12 |
foucault |
27 |
|
13 |
foucault |
176 |
#include "CAD4FE_EdgeCollapseCriteria.h"
|
14 |
foucault |
27 |
#include "CAD4FE_MCBody.h" |
15 |
|
|
#include "CAD4FE_MCAA.h" |
16 |
|
|
#include "CAD4FE_MCEdge.h" |
17 |
|
|
#include "CAD4FE_MCVertex.h" |
18 |
|
|
#include "CAD4FE_mg_utils.h" |
19 |
|
|
#include "ot_algorithme_geometrique.h" |
20 |
|
|
#include "CAD4FE_Criteria.h" |
21 |
|
|
#include "CAD4FE_ColorMap.h" |
22 |
|
|
#include "CAD4FE_VertexCriteria.h" |
23 |
|
|
#include "CAD4FE_PolyCurve.h" |
24 |
|
|
#include "CAD4FE_GlobalEdgeCriteria.h" |
25 |
foucault |
569 |
#include "CAD4FE_CoVertexCriteria.h"
|
26 |
|
|
#include "CAD4FE_Geometric_Tools.h"
|
27 |
foucault |
27 |
|
28 |
|
|
#pragma package(smart_init)
|
29 |
|
|
|
30 |
|
|
using namespace CAD4FE;
|
31 |
|
|
|
32 |
|
|
EdgeCollapseCriteria::EdgeCollapseCriteria(MCEdge * __mcEdge, MCVertex * __deleteVertex, MCAA * __mcaa)
|
33 |
|
|
: _mcaa(__mcaa), _mcEdge(__mcEdge) |
34 |
|
|
{ |
35 |
|
|
MCVertex *v1, *v2; |
36 |
|
|
v1 = (MCVertex*) _mcEdge->get_cosommet1()->get_sommet(); |
37 |
|
|
v2 = (MCVertex*) _mcEdge->get_cosommet2()->get_sommet(); |
38 |
|
|
|
39 |
|
|
if (__deleteVertex == v1) |
40 |
|
|
{ |
41 |
|
|
_deleteVertex = v1; |
42 |
|
|
_targetVertex = v2; |
43 |
|
|
} |
44 |
|
|
else if (__deleteVertex == v2) |
45 |
|
|
{ |
46 |
|
|
_deleteVertex = v2; |
47 |
|
|
_targetVertex = v1; |
48 |
|
|
} |
49 |
|
|
else // problem |
50 |
|
|
{ |
51 |
|
|
_deleteVertex = _targetVertex = NULL; |
52 |
foucault |
569 |
printf(" EdgeCollapseCriteria : vertex %lu is not adjacent to edge %lu !\n", __deleteVertex->get_id(), __mcEdge->get_id()); |
53 |
foucault |
27 |
} |
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
double EdgeCollapseCriteria::GetScore() |
57 |
|
|
{ |
58 |
foucault |
569 |
if (_mcaa->GetMCBody()->G21()->GetArc(_mcEdge->get_id())->Rank() != 2) |
59 |
|
|
return 0; |
60 |
|
|
|
61 |
foucault |
27 |
if (_deleteVertex == _targetVertex) // the collapse edge is a cycle |
62 |
|
|
return 0; |
63 |
|
|
|
64 |
|
|
// don't use edge collapse when you can use vertex deletion |
65 |
|
|
if (_mcaa->GetMCBody()->G10()->GetArc(_deleteVertex->get_id())->Rank() < 3) |
66 |
|
|
return 0; |
67 |
|
|
|
68 |
|
|
return EdgeLength(); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
double EdgeCollapseCriteria::EdgeLength() |
72 |
|
|
{ |
73 |
|
|
double deleteVertex_xyz[3]; |
74 |
|
|
double LMin, minEdgeLength; |
75 |
|
|
int extendEdgeCount; |
76 |
|
|
|
77 |
|
|
_deleteVertex->get_point()->evaluer(deleteVertex_xyz); |
78 |
|
|
LMin = _mcaa->GetMinSize(deleteVertex_xyz); |
79 |
|
|
|
80 |
|
|
double collapseEdgeLength = _mcEdge->GetPolyCurve()->get_longueur(); |
81 |
|
|
if (collapseEdgeLength >= LMin) |
82 |
|
|
return 0; |
83 |
|
|
|
84 |
|
|
std::vector<MCEdge *> adjEdges; |
85 |
|
|
_mcaa->GetMCBody()->Vertex_GetAdjacentEdges(_deleteVertex, adjEdges); |
86 |
|
|
|
87 |
foucault |
569 |
// Verify that adjacent edges have the same color as the deleted edge |
88 |
|
|
{ |
89 |
|
|
unsigned char rgba1[4];
|
90 |
|
|
int is_colored1 = CAD4FE::GeometricTools::MG_TOPO_GetColor(_mcEdge, rgba1); |
91 |
|
|
for (std::vector<MCEdge*>::iterator itEdge = adjEdges.begin(); |
92 |
|
|
itEdge != adjEdges.end(); itEdge++) |
93 |
|
|
{ |
94 |
|
|
MCEdge * edge = *itEdge; |
95 |
|
|
unsigned char rgba2[4];
|
96 |
|
|
int is_colored2 = CAD4FE::GeometricTools::MG_TOPO_GetColor(edge, rgba2); |
97 |
|
|
|
98 |
|
|
if (is_colored2 != is_colored1)
|
99 |
|
|
return 0;
|
100 |
|
|
else if ( rgba1[0] != rgba2[0] || rgba1[1] != rgba2[1] || rgba1[2] != rgba2[2] || rgba1[3] != rgba2[3])
|
101 |
|
|
return 0; |
102 |
|
|
} |
103 |
|
|
} |
104 |
|
|
|
105 |
foucault |
27 |
minEdgeLength = 1E100; |
106 |
|
|
extendEdgeCount = 0; |
107 |
|
|
for (std::vector<MCEdge*>::iterator itEdge = adjEdges.begin(); |
108 |
|
|
itEdge != adjEdges.end(); itEdge++) |
109 |
|
|
{ |
110 |
|
|
MCEdge * edge = *itEdge; |
111 |
|
|
if (edge == _mcEdge) |
112 |
|
|
continue; |
113 |
|
|
|
114 |
|
|
double edgeLength = edge->GetPolyCurve()->get_longueur(); |
115 |
|
|
|
116 |
|
|
minEdgeLength = std::min(minEdgeLength,edgeLength); |
117 |
|
|
extendEdgeCount++; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
|
121 |
|
|
if (minEdgeLength < LMin) |
122 |
|
|
{ |
123 |
|
|
return 0; |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
return 1-collapseEdgeLength/LMin; |
127 |
|
|
} |