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