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

File Contents

# User Rev Content
1 francois 1158 //####//------------------------------------------------------------
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_MCNodePolyline.cpp
15     //####//
16     //####//------------------------------------------------------------
17     //####//------------------------------------------------------------
18     //####// COPYRIGHT 2000-2024
19     //####// jeu 13 jun 2024 11:58:56 EDT
20     //####//------------------------------------------------------------
21     //####//------------------------------------------------------------
22 foucault 27
23    
24     #pragma hdrstop
25    
26     #include "gestionversion.h"
27    
28     #include "mg_geometrie.h"
29     #include "ot_algorithme_geometrique.h"
30     #include "CAD4FE_MCNode.h"
31     #include "CAD4FE_MCFace.h"
32     #include "CAD4FE_PolySurface.h"
33     #include "CAD4FE_Intersection_Plane_MG_ARETE.h"
34 foucault 569 #include "CAD4FE_Geometric_Tools.h"
35 foucault 27 #include "CAD4FE_FaceBoundaryPoint.h"
36 foucault 569 #include "ot_decalage_parametre.h"
37 foucault 27
38     #include "CAD4FE_MCNodePolyline.h"
39    
40    
41     #pragma package(smart_init)
42    
43     using namespace CAD4FE;
44    
45     MCNodePolyline::MCNodePolyline(MG_ELEMENT_TOPOLOGIQUE * __mcTopo)
46     : OT_REFERENCE(), _mcTopo(__mcTopo)
47     {
48    
49     }
50    
51     MCNodePolyline::MCNodePolyline(MG_ELEMENT_TOPOLOGIQUE * __mcTopo, const std::vector <MCNode*> & __polylineNodes, const std::vector <MG_ELEMENT_TOPOLOGIQUE*> & __polylineTopo)
52     : OT_REFERENCE(), _polylineNodes(__polylineNodes), _polylineTopo(__polylineTopo),_mcTopo(__mcTopo)
53     {
54     MCNode *xi=_polylineNodes[0],*xii=_polylineNodes[1];
55     MG_ELEMENT_TOPOLOGIQUE * topo = NULL;
56     for (unsigned i=0; i+1<_polylineNodes.size();i++)
57     {
58     topo = _polylineTopo[i];
59     xi=_polylineNodes[i];
60     xii=_polylineNodes[i+1];
61     lst_length.push_back( Distance(xi,xii,topo) );
62     }
63     for (unsigned i=0; i<_polylineNodes.size(); i++)
64     _polylineNodes[i]->incrementer();
65     }
66     MCNodePolyline::MCNodePolyline(MCNodePolyline &__pl)
67     {
68     _mcTopo = __pl._mcTopo;
69     _polylineNodes = __pl._polylineNodes;
70     _polylineTopo = __pl._polylineTopo;
71     lst_length = __pl.lst_length;
72     for (unsigned i=0; i<_polylineNodes.size(); i++)
73     _polylineNodes[i]->incrementer();
74     }
75     MCNodePolyline::~MCNodePolyline()
76     {
77     for (unsigned i=0; i<_polylineNodes.size(); i++)
78     {
79     _polylineNodes[i]->decrementer();
80     if ( _polylineNodes[i]->get_nb_reference() == 0)
81     delete _polylineNodes[i];
82     }
83     }
84     void MCNodePolyline::Add(MCNode * __mcNode, MG_ELEMENT_TOPOLOGIQUE * __topo)
85     {
86     _polylineNodes.push_back(__mcNode);
87     _polylineTopo.push_back(__topo);
88     __mcNode->incrementer();
89     if (_polylineNodes.size() > 1)
90     {
91     unsigned i = _polylineNodes.size() - 2;
92     MCNode *xi=_polylineNodes[i],*xii=_polylineNodes[i+1];
93     MG_ELEMENT_TOPOLOGIQUE *topo = _polylineTopo[i];
94     lst_length.push_back( Distance(xi,xii,topo) );
95     }
96     }
97     std::vector <MCNode *> & MCNodePolyline::GetPolylineNodes()
98     {
99     return _polylineNodes;
100     }
101     MCNode * MCNodePolyline::GetPolylineNode(unsigned __index)
102     {
103     return _polylineNodes[__index];
104     }
105     std::vector <MG_ELEMENT_TOPOLOGIQUE *> & MCNodePolyline::GetPolylineTopos()
106     {
107     return _polylineTopo;
108     }
109     MG_ELEMENT_TOPOLOGIQUE * MCNodePolyline::GetPolylineTopo(unsigned __index)
110     {
111     return _polylineTopo[__index];
112     }
113     void MCNodePolyline::Inverse(double &__t, MCNode *__mcNode)
114     {
115     double l=0;
116     for (unsigned i=0; i<_polylineNodes.size();i++)
117     {
118     MCNode * mcNode = _polylineNodes[i];
119     if (mcNode == __mcNode)
120     break;
121     l += lst_length[i];
122     }
123     __t = l;
124     }
125    
126     double MCNodePolyline::GetLength()
127     {
128     double l=0;
129     for (unsigned i=0; i<lst_length.size();i++)
130     l+=lst_length[i];
131     return l;
132     }
133    
134     double MCNodePolyline::Distance(MCNode * __a, MCNode * __b, MG_ELEMENT_TOPOLOGIQUE * __c)
135     {
136     MG_ELEMENT_TOPOLOGIQUE * topo = __c;
137     MCNode * mcNode1 = __a;
138     MCNode * mcNode2 = __b;
139    
140     double t1, t2;
141    
142     MG_FACE * face = 0;
143     double distFace=1E300;
144     MG_ARETE * edge = 0;
145     double distEdge=1E300;
146     MG_SOMMET * vertex = 0;
147     double distVertex=1E300;
148    
149     if (topo == NULL)
150     {
151     return OT_ALGORITHME_GEOMETRIQUE::VEC3_DISTANCE_VEC3(__a->get_coord(),__b->get_coord());
152     }
153    
154     switch(topo->get_dimension())
155     {
156     case 2:
157     face = (MG_FACE*)topo;
158     break;
159     case 1:
160     edge = (MG_ARETE*)topo;
161     break;
162     case 0:
163     vertex = (MG_SOMMET*)topo;
164     break;
165     }
166     double dist=1E300;
167    
168     if (face)
169     {
170     distFace = GeometricTools::Segment2dCurvilinearLength(face,mcNode2->UV(face),mcNode1->UV(face),3);
171     }
172     if (edge )
173     {
174     t1=mcNode1->GetEdgeParams(edge);
175     t2=mcNode2->GetEdgeParams(edge);
176     if (edge->get_courbe()->est_periodique())
177     {
178     if (t1 < edge->get_tmin()-1E-6*(edge->get_tmax()-edge->get_tmin()))
179     t1 += edge->get_courbe()->get_periode();
180     if (t2 < edge->get_tmin()-1E-6*(edge->get_tmax()-edge->get_tmin()))
181     t2 += edge->get_courbe()->get_periode();
182 foucault 64 if ((t2-t1)*2 > edge->get_courbe()->get_periode())
183     t1 += edge->get_courbe()->get_periode();
184     if ((t1-t2)*2 > edge->get_courbe()->get_periode())
185     t2 += edge->get_courbe()->get_periode();
186 foucault 27 }
187     if ((t2-t1)*(edge->get_tmax()-edge->get_tmin()) < 0)
188     std::swap(t1,t2);
189     if ((t2-t1) < 1E-6*(edge->get_tmax()-edge->get_tmin()) )
190     distEdge = (t2-t1)/(edge->get_tmax()-edge->get_tmin())*edge->get_longueur(edge->get_tmin(),edge->get_tmax());
191     else
192     distEdge = edge->get_longueur(t1,t2);
193     }
194     if (vertex)
195     {
196     if (mcNode1->IsInVertex(vertex) ||mcNode2->IsInVertex(vertex))
197     distVertex=OT_ALGORITHME_GEOMETRIQUE::VEC3_DISTANCE_VEC3(mcNode1->get_coord(),mcNode2->get_coord());
198     else
199     distVertex=1E300;
200     }
201    
202     dist = distFace;
203     dist = std::min(dist, distEdge);
204     dist = std::min(dist, distVertex);
205    
206     return dist;
207     }
208    
209     MCNode MCNodePolyline::Evaluate(double __s, double * tangent, double * curvature)
210     {
211     //MCNode result(_mcTopo,topo,xyz[0],xyz[1],xyz[2]);
212     MCNode result;
213     double si=0;
214     double xyz[3];
215     MCNode *xi=_polylineNodes[0],*xii=_polylineNodes[1];
216     MG_ELEMENT_TOPOLOGIQUE * topo = NULL;
217     unsigned i=0;
218    
219     double polylineLength = GetLength();
220    
221     if (polylineLength == 0)
222     return *_polylineNodes[_polylineNodes.size()-1];
223    
224     if (1 - (__s / polylineLength) < 1E-6)
225     return *_polylineNodes[_polylineNodes.size()-1];
226    
227     for (i=0; lst_length.size() && __s > si+lst_length[i] && i<lst_length.size(); i++)
228     {
229     si += lst_length[i];
230     }
231    
232     topo = _polylineTopo[i];
233     xi=_polylineNodes[i];
234     xii=_polylineNodes[i+1];
235    
236     if (xi==NULL)
237     printf("Error in MCNodePolyline::Evaluate\n");
238    
239     double L = lst_length[i];
240    
241     double coef = (L > 1E-6*fabs(si-__s) ) ? (__s-si)/L : 0;
242    
243     if (topo != NULL)
244     {
245     if (topo->get_dimension()==2)
246     {
247     MG_FACE * face = (MG_FACE*) topo;
248     MCNode::FMap F;
249    
250     OT_VECTEUR_3D xi_uv = xi->UV(face);
251     OT_VECTEUR_3D xii_uv = xii->UV(face);
252    
253     OT_DECALAGE_PARAMETRE ot_decalage(face->get_surface()->get_periode_u(),face->get_surface()->get_periode_v());
254     double decal_u=ot_decalage.calcul_decalage_parametre_u(xi_uv[0]);
255     double decal_v=ot_decalage.calcul_decalage_parametre_v(xi_uv[1]);
256     OT_VECTEUR_3D decal_xi_uv(0,0,0), decal_xii_uv(0,0,0);
257     decal_xi_uv[0]=ot_decalage.decalage_parametre_u(xi_uv[0],decal_u);
258     decal_xi_uv[1]=ot_decalage.decalage_parametre_v(xi_uv[1],decal_v);
259     decal_xii_uv[0]=ot_decalage.decalage_parametre_u(xii_uv[0],decal_u);
260     decal_xii_uv[1]=ot_decalage.decalage_parametre_v(xii_uv[1],decal_v);
261    
262     OT_VECTEUR_3D Duv = (decal_xii_uv-decal_xi_uv);
263     Duv[2]=0;
264     OT_VECTEUR_3D decal_uv = decal_xi_uv + coef*Duv;
265     OT_VECTEUR_3D uv;
266     uv[0] = ot_decalage.decalage_parametre_u(decal_uv[0],-decal_u);
267     uv[1] = ot_decalage.decalage_parametre_v(decal_uv[1],-decal_v);
268    
269     F[face]=uv;
270     face->evaluer(uv,xyz);
271     result = MCNode(_mcTopo,face,uv,xyz);
272    
273     if (tangent)
274     {
275     OT_MATRICE_3D tangentPlaneFrame = GeometricTools::TangentPlaneFrame(face,xi_uv);
276     OT_VECTEUR_3D tangentTemp = tangentPlaneFrame*Duv;
277     tangentTemp.norme();
278     for (int i=0;i<3;i++) tangent[i] = tangentTemp[i];
279     }
280     if (curvature)
281     {
282     }
283     }
284     if (topo->get_dimension()==1)
285     {
286     MG_ARETE * edge = ( MG_ARETE * ) topo;
287     double t[3];
288     t[0] = xi->T(edge);
289     t[1] = xii->T(edge);
290     if ( edge->get_courbe()->est_periodique() )
291     {
292     double period=edge->get_courbe()->get_periode();
293     for (unsigned k=0;k<2;k++)
294     if (t[k] < edge->get_tmin() - 1E-6*edge->get_courbe()->get_periode())
295     t[k] += period;
296     if (fabs(t[1]-t[0])>.5*period)
297     {
298     if (t[1] < t[0]) t[1]+=period;
299     else t[0]+=period;
300     }
301     //if ((t[1]-t[0])*(edge->get_tmax()-edge->get_tmin()) < 0)
302     // std::swap(t[0],t[1]);
303     }
304     t[2] = t[0] + (t[1]-t[0])*coef;
305     edge->evaluer(t[2],xyz);
306     result = MCNode(_mcTopo,edge,t[2],xyz);
307    
308     if (tangent)
309     {
310     OT_VECTEUR_3D tangentTemp;
311     edge->deriver(t[2],tangentTemp);
312     tangentTemp.norme();
313     for (int i=0;i<3;i++) tangent[i] = tangentTemp[i];
314     }
315     }
316     }
317     if (topo == NULL || topo->get_dimension()==0)
318     {
319     for (int i=0; i<3; i++)
320     xyz[i]=(xii->get_coord()[i]-xi->get_coord()[i])*coef+xi->get_coord()[i];
321     result = MCNode(_mcTopo,topo,xyz[0],xyz[1],xyz[2]);
322     if (tangent)
323     {
324     OT_VECTEUR_3D tangentTemp;
325     for (int i=0; i<3; i++)
326     tangentTemp[i]=(xii->get_coord()[i]-xi->get_coord()[i]);
327     if ( tangentTemp.get_longueur2() > 1E-50 )
328     tangentTemp.norme();
329     for (int i=0; i<3; i++)
330     tangent[i]=tangentTemp[i];
331     }
332     }
333    
334     return result;
335     }
336    
337     unsigned MCNodePolyline::GetPolylineNodeCount()
338     {
339     return _polylineNodes.size();
340     }