]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx
Salome HOME
Refactoring QuadraticPlanar precision tuning. Fixes intersector bugs.
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DComposedEdge.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "InterpKernelGeo2DComposedEdge.hxx"
22 #include "InterpKernelGeo2DElementaryEdge.hxx"
23 #include "InterpKernelGeo2DEdgeArcCircle.hxx"
24 #include "InterpKernelGeo2DEdgeInfLin.hxx"
25 #include "InterpKernelException.hxx"
26
27 #include <algorithm>
28 #include <memory>
29 #include <iterator>
30 #include <set>
31
32 using namespace INTERP_KERNEL;
33
34 ComposedEdge::ComposedEdge(const ComposedEdge& other)
35 {
36   for(std::list<ElementaryEdge *>::const_iterator iter=other._sub_edges.begin();iter!=other._sub_edges.end();iter++)
37     _sub_edges.push_back((*iter)->clone());
38 }
39
40 ComposedEdge::~ComposedEdge()
41 {
42   clearAll(_sub_edges.begin());
43 }
44
45 void ComposedEdge::setValueAt(int i, Edge *e, bool direction)
46 {
47   std::list<ElementaryEdge*>::iterator it=_sub_edges.begin();
48   for(int j=0;j<i;j++)
49     it++;
50   delete *it;
51   *it=new ElementaryEdge(e,direction);
52 }
53
54 /*! \cond HIDDEN_ITEMS */
55 struct AbsEdgeCmp
56 {
57   AbsEdgeCmp(ElementaryEdge *b):_b1(b) { }
58   bool operator()(ElementaryEdge *a) { return a->getPtr()==_b1->getPtr();}
59
60   ElementaryEdge *_b1;
61 };
62 /*! \endcond */
63
64 double ComposedEdge::getCommonLengthWith(const ComposedEdge& other) const
65 {
66   double ret=0.;
67   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
68     {
69       if(find_if(other._sub_edges.begin(),other._sub_edges.end(),AbsEdgeCmp(*iter))!=other._sub_edges.end())
70         {
71           const ElementaryEdge *tmp=static_cast<const ElementaryEdge *>(*iter);
72           ret+=tmp->getCurveLength();
73         }
74     }
75   return ret;
76 }
77
78 void ComposedEdge::clear()
79 {
80   clearAll(_sub_edges.begin());
81   _sub_edges.clear();
82 }
83
84 void ComposedEdge::pushBack(Edge *edge, bool direction)
85 {
86   _sub_edges.push_back(new ElementaryEdge(edge,direction));
87 }
88
89 void ComposedEdge::pushBack(ElementaryEdge *elem)
90 {
91   _sub_edges.push_back(elem);
92 }
93
94 void ComposedEdge::pushBack(ComposedEdge *elem)
95 {
96   std::list<ElementaryEdge *> *elemsOfElem=elem->getListBehind();
97   _sub_edges.insert(_sub_edges.end(),elemsOfElem->begin(),elemsOfElem->end());
98 }
99
100 ElementaryEdge *ComposedEdge::operator[](int i) const
101 {
102   std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();
103   for(int ii=0;ii<i;ii++)
104     iter++;
105   return *iter;
106 }
107
108 void ComposedEdge::reverse()
109 {
110   _sub_edges.reverse();
111   for(std::list<ElementaryEdge *>::iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
112     (*iter)->reverse();
113 }
114
115 bool ComposedEdge::presenceOfOn() const
116 {
117   bool ret=false;
118   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end() && !ret;iter++)
119     ret=((*iter)->getLoc()==FULL_ON_1);
120   return ret;
121 }
122
123 bool ComposedEdge::presenceOfQuadraticEdge() const
124 {
125   bool ret=false;
126   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end() && !ret;iter++)
127     {
128       Edge *e=(*iter)->getPtr();
129       if(e)
130         ret=dynamic_cast<EdgeArcCircle*>(e)!=0;
131     }
132   return ret;
133 }
134
135 void ComposedEdge::initLocations() const
136 {
137   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
138     (*iter)->initLocations();
139 }
140
141 /**
142  * Reset the status of all edges (OUT, IN, ON) because they were potentially assigned
143  * by the previous candidate processing.
144  */
145 void ComposedEdge::InitLocationsWithOther(const ComposedEdge& first, const ComposedEdge& other)
146 {
147   std::set<Edge *> s1,s2;
148   for(std::list<ElementaryEdge *>::const_iterator it1=first._sub_edges.begin();it1!=first._sub_edges.end();it1++)
149     s1.insert((*it1)->getPtr());
150   for(std::list<ElementaryEdge *>::const_iterator it2=other._sub_edges.begin();it2!=other._sub_edges.end();it2++)
151     s2.insert((*it2)->getPtr());
152   first.initLocations();
153   other.initLocations();
154   std::vector<Edge *> s3;
155   std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector<Edge *> >(s3));
156   for(std::vector<Edge *>::const_iterator it3=s3.begin();it3!=s3.end();it3++)
157     (*it3)->declareOn();
158 }
159
160 ComposedEdge *ComposedEdge::clone() const
161 {
162   return new ComposedEdge(*this);
163 }
164
165 bool ComposedEdge::isNodeIn(Node *n) const
166 {
167   bool ret=false;
168   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end() && !ret;iter++)
169     ret=(*iter)->isNodeIn(n);
170   return ret;
171 }
172
173 /*!
174  * This method computes the area of 'this'.
175  * By definition :
176  * \f[
177  * Area=\int_{Polygon} dS
178  * \f]
179  * Thanks to Green's theorem we have.
180  * \f[
181  * \int_{Polygon} x \cdot dS=\sum_{0 \leq i < nb of edges} -\int_{Edge_{i}}ydx=\sum_{0 \leq i < nb of edges} AreaOfZone_{Edge_{i}}
182  * \f]
183  * Where \f$ AreaOfZone_{i} \f$ is computed virtually by INTERP_KERNEL::Edge::getAreaOfZone with following formula :
184  * \f[
185  * AreaOfZone_{i}=\int_{Edge_{i}} -ydx
186  * \f]
187  */
188 double ComposedEdge::getArea() const
189 {
190   double ret=0.;
191   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
192     ret+=(*iter)->getAreaOfZone();
193   return ret;
194 }
195
196 double ComposedEdge::getPerimeter() const
197 {
198   double ret=0.;
199   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
200     ret+=(*iter)->getCurveLength();
201   return ret;
202 }
203
204 double ComposedEdge::getHydraulicDiameter() const
205 {
206   return 4*fabs(getArea())/getPerimeter();
207 }
208
209 /*!
210  * This method computes barycenter of 'this' by returning xG in bary[0] and yG in bary[1].
211  * By definition :
212  * \f[
213  * Area \cdot x_{G}=\int_{Polygon} x \cdot dS
214  * \f]
215  * \f[
216  * Area \cdot y_{G}=\int_{Polygon} y \cdot dS
217  * \f]
218  * Thanks to Green's theorem we have.
219  * \f[
220  * \int_{Polygon} x \cdot dS=\sum_{0 \leq i < nb of edges} -\int_{Edge_{i}}yxdx
221  * \f]
222  * \f[
223  * \int_{Polygon} y \cdot dS=\sum_{0 \leq i < nb of edges} -\int_{Edge_{i}}\frac{y^{2}}{2}dx
224  * \f]
225  * Area is computed using the same principle than described in INTERP_KERNEL::ComposedEdge::getArea method.
226  * \f$ -\int_{Edge_{i}}yxdx \f$ and \f$ -\int_{Edge_{i}}\frac{y^{2}}{2}dx \f$ are computed virtually with INTERP_KERNEL::Edge::getBarycenterOfZone.
227  */
228 void ComposedEdge::getBarycenter(double *bary) const
229 {
230   bary[0]=0.;
231   bary[1]=0.;
232   double area=0.;
233   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
234     {
235       (*iter)->getBarycenterOfZone(bary);
236       area+=(*iter)->getAreaOfZone();
237     }
238   bary[0]/=area;
239   bary[1]/=area;
240 }
241
242 /*!
243  * Idem ComposedEdge::getBarycenter except that the special case where _sub_edges==1 is dealt here.
244  */
245 void ComposedEdge::getBarycenterGeneral(double *bary) const
246 {
247   if(_sub_edges.empty())
248     throw INTERP_KERNEL::Exception("ComposedEdge::getBarycenterGeneral called on an empty polygon !");
249   if(_sub_edges.size()>2)
250     return getBarycenter(bary);
251   double w;
252   _sub_edges.back()->getBarycenter(bary,w);
253 }
254
255 double ComposedEdge::normalizeMe(double& xBary, double& yBary)
256 {
257   Bounds b;
258   b.prepareForAggregation();
259   fillBounds(b);
260   double dimChar=b.getCaracteristicDim();
261   b.getBarycenter(xBary,yBary);
262   applyGlobalSimilarity(xBary,yBary,dimChar);
263   return dimChar;
264 }
265
266 double ComposedEdge::normalize(ComposedEdge *other, double& xBary, double& yBary)
267 {
268   Bounds b;
269   b.prepareForAggregation();
270   fillBounds(b); 
271   other->fillBounds(b);
272   double dimChar=b.getCaracteristicDim();
273   b.getBarycenter(xBary,yBary);
274   applyGlobalSimilarity(xBary,yBary,dimChar);
275   other->applyGlobalSimilarity(xBary,yBary,dimChar);
276   return dimChar;
277 }
278
279 /*!
280  * This method operates the opposite operation than ComposedEdge::applyGlobalSimilarity.
281  */
282 void ComposedEdge::unApplyGlobalSimilarityExt(ComposedEdge& other, double xBary, double yBary, double fact)
283 {
284   initNodeHitStatus();
285   other.initNodeHitStatus();
286   unApplySimilarityOnMyNodes(xBary,yBary,fact);
287   other.unApplySimilarityOnMyNodesIfNotAlreadyHit(xBary,yBary,fact);
288   initEdgeHitStatus();
289   other.initEdgeHitStatus();
290   unApplySimilarityOnMyEdges(xBary,yBary,fact);
291   other.unApplySimilarityOnMyEdgesIfNotAlreadyHit(xBary,yBary,fact);
292 }
293
294 double ComposedEdge::normalizeExt(ComposedEdge *other, double& xBary, double& yBary)
295 {
296   Bounds b;
297   b.prepareForAggregation();
298   fillBounds(b); 
299   other->fillBounds(b);
300   double dimChar=b.getCaracteristicDim();
301   b.getBarycenter(xBary,yBary);
302   applyGlobalSimilarity2(other,xBary,yBary,dimChar);
303   return dimChar;
304 }
305
306 void ComposedEdge::dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const
307 {
308   stream.precision(10);
309   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
310     (*iter)->dumpInXfigFile(stream,resolution,box);
311 }
312
313 Node *ComposedEdge::getEndNode() const
314 {
315   return _sub_edges.back()->getEndNode();
316 }
317
318 Node *ComposedEdge::getStartNode() const
319 {
320   return _sub_edges.front()->getStartNode();
321 }
322
323 bool ComposedEdge::changeEndNodeWith(Node *node) const
324 {
325   return _sub_edges.back()->changeEndNodeWith(node);
326 }
327
328 bool ComposedEdge::changeStartNodeWith(Node *node) const
329 {
330   return _sub_edges.front()->changeStartNodeWith(node);
331 }
332
333 void ComposedEdge::fillBounds(Bounds& output) const
334 {
335   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
336     (*iter)->fillBounds(output);
337 }
338
339 /*!
340  * \b WARNING : applies similarity \b ONLY on edges without any change on Nodes. To perform a global similarity call applyGlobalSimilarity.
341  */
342 void ComposedEdge::applySimilarity(double xBary, double yBary, double dimChar)
343 {
344   for(std::list<ElementaryEdge *>::iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
345     (*iter)->applySimilarity(xBary,yBary,dimChar);
346 }
347
348 /*!
349  * Perform Similarity transformation on all elements of this Nodes and Edges.
350  */
351 void ComposedEdge::applyGlobalSimilarity(double xBary, double yBary, double dimChar)
352 {
353   std::set<Node *> allNodes;
354   getAllNodes(allNodes);
355   for(std::set<Node *>::iterator iter=allNodes.begin();iter!=allNodes.end();iter++)
356     (*iter)->applySimilarity(xBary,yBary,dimChar);
357   for(std::list<ElementaryEdge *>::iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
358     (*iter)->applySimilarity(xBary,yBary,dimChar);
359 }
360
361 /*!
362  * Perform Similarity transformation on all elements of this Nodes and Edges on 'this' and 'other'.
363  * Nodes can be shared between 'this' and 'other'.
364  */
365 void ComposedEdge::applyGlobalSimilarity2(ComposedEdge *other, double xBary, double yBary, double dimChar)
366 {
367   initNodeHitStatus();
368   other->initNodeHitStatus();
369   applySimilarityOnMyNodes(xBary,yBary,dimChar);
370   other->applySimilarityOnMyNodesIfNotAlreadyHit(xBary,yBary,dimChar);
371   initEdgeHitStatus();
372   other->initEdgeHitStatus();
373   applySimilarityOnMyEdges(xBary,yBary,dimChar);
374   other->applySimilarityOnMyEdgesIfNotAlreadyHit(xBary,yBary,dimChar);
375 }
376
377 /*!
378  * This method append to param 'partConsidered' the part of length of subedges IN or ON.
379  * @param partConsidered INOUT param.
380  */
381 void ComposedEdge::dispatchPerimeter(double& partConsidered) const
382 {
383   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
384     {
385       TypeOfEdgeLocInPolygon loc=(*iter)->getLoc();
386       if(loc==FULL_IN_1 || loc==FULL_ON_1)
387         partConsidered+=(*iter)->getCurveLength();
388     }
389 }
390
391 /*!
392  * Idem dispatchPerimeterExcl except that when a subedge is declared as ON this subedge is counted in commonPart.
393  */
394 void ComposedEdge::dispatchPerimeterExcl(double& partConsidered, double& commonPart) const
395 {
396   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
397     {
398       TypeOfEdgeLocInPolygon loc=(*iter)->getLoc();
399       if(loc==FULL_IN_1)
400         partConsidered+=(*iter)->getCurveLength();
401       if(loc==FULL_ON_1)
402         commonPart+=(*iter)->getCurveLength();
403     }
404 }
405
406 void ComposedEdge::getAllNodes(std::set<Node *>& output) const
407 {
408   std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();
409   for(;iter!=_sub_edges.end();iter++)
410     (*iter)->getAllNodes(output);
411 }
412
413 void ComposedEdge::initNodeHitStatus() const
414 {
415   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
416     {
417       (*iter)->getStartNode()->initHitStatus();
418       (*iter)->getEndNode()->initHitStatus();
419     }
420 }
421
422 void ComposedEdge::applySimilarityOnMyNodes(double xBary, double yBary, double dimChar) const
423 {
424   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
425     {
426       (*iter)->getStartNode()->hitMeAlone(xBary,yBary,dimChar);
427       (*iter)->getEndNode()->hitMeAlone(xBary,yBary,dimChar);
428     }
429 }
430
431 void ComposedEdge::unApplySimilarityOnMyNodes(double xBary, double yBary, double dimChar) const
432 {
433   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
434     {
435       (*iter)->getStartNode()->unHitMeAlone(xBary,yBary,dimChar);
436       (*iter)->getEndNode()->unHitMeAlone(xBary,yBary,dimChar);
437     }
438 }
439
440 void ComposedEdge::applySimilarityOnMyNodesIfNotAlreadyHit(double xBary, double yBary, double dimChar) const
441 {
442   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
443     {
444       (*iter)->getStartNode()->hitMeAfter(xBary,yBary,dimChar);
445       (*iter)->getEndNode()->hitMeAfter(xBary,yBary,dimChar);
446     }
447 }
448
449 void ComposedEdge::unApplySimilarityOnMyNodesIfNotAlreadyHit(double xBary, double yBary, double dimChar) const
450 {
451   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
452     {
453       (*iter)->getStartNode()->unHitMeAfter(xBary,yBary,dimChar);
454       (*iter)->getEndNode()->unHitMeAfter(xBary,yBary,dimChar);
455     }
456 }
457
458 void ComposedEdge::initEdgeHitStatus() const
459 {
460   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
461     (*iter)->getPtr()->initHitStatus();
462 }
463
464 void ComposedEdge::applySimilarityOnMyEdges(double xBary, double yBary, double dimChar) const
465 {
466   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
467     (*iter)->getPtr()->hitMeAlone(xBary,yBary,dimChar);
468 }
469
470 void ComposedEdge::unApplySimilarityOnMyEdges(double xBary, double yBary, double dimChar) const
471 {
472   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
473     (*iter)->getPtr()->unHitMeAlone(xBary,yBary,dimChar);
474 }
475
476 void ComposedEdge::applySimilarityOnMyEdgesIfNotAlreadyHit(double xBary, double yBary, double dimChar) const
477 {
478   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
479     (*iter)->getPtr()->hitMeAfter(xBary,yBary,dimChar);
480 }
481
482 void ComposedEdge::unApplySimilarityOnMyEdgesIfNotAlreadyHit(double xBary, double yBary, double dimChar) const
483 {
484   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
485     (*iter)->getPtr()->unHitMeAfter(xBary,yBary,dimChar);
486 }
487
488 void ComposedEdge::getBarycenter(double *bary, double& weigh) const
489 {
490   weigh=0.; bary[0]=0.; bary[1]=0.;
491   double tmp1,tmp2[2];
492   for(std::list<ElementaryEdge *>::const_iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++)
493     {
494       (*iter)->getBarycenter(tmp2,tmp1);
495       weigh+=tmp1;
496       bary[0]+=tmp1*tmp2[0];
497       bary[1]+=tmp1*tmp2[1];
498     }
499   bary[0]/=weigh;
500   bary[1]/=weigh;
501 }
502
503 /*!
504  * This method makes the hypothesis that \a nodeToTest can be either IN or OUT.
505  * 
506  * \sa ComposedEdge::isInOrOut2
507  */
508 bool ComposedEdge::isInOrOut(Node *nodeToTest) const
509 {
510   Bounds b; b.prepareForAggregation();
511   fillBounds(b);
512   if(b.nearlyWhere((*nodeToTest)[0],(*nodeToTest)[1])==OUT)
513     return false;
514   std::set< IntersectElement > inOutSwitch;
515   std::set<Node *> nodes;
516   getAllNodes(nodes);
517   double ref(isInOrOutAlg(nodeToTest,nodes,inOutSwitch));
518   bool ret(false);
519   for(std::set< IntersectElement >::iterator iter4=inOutSwitch.begin();iter4!=inOutSwitch.end();iter4++)
520     {
521       if((*iter4).getVal1()<ref)
522         {
523           if((*iter4).getNodeOnly()->getLoc()==ON_1)
524             ret=!ret;
525         }
526       else
527         break;
528     }
529   return ret;
530 }
531
532 /*!
533  * This method is close to ComposedEdge::isInOrOut behaviour except that here EPSILON is taken into account to detect if it is IN or OUT.
534  * If \a nodeToTest is close to an edge in \a this, true will be returned even if it is outside informatically from \a this.
535  *
536  * \sa ComposedEdge::isInOrOut
537  */
538 bool ComposedEdge::isInOrOut2(Node *nodeToTest) const
539 {
540   std::set< IntersectElement > inOutSwitch;
541   std::set<Node *> nodes;
542   getAllNodes(nodes);
543   for(std::set<Node *>::const_iterator iter=nodes.begin();iter!=nodes.end();iter++)
544     if(sqrt((*iter)->distanceWithSq(*nodeToTest))<QuadraticPlanarPrecision::getPrecision())
545       return true;
546   double ref(isInOrOutAlg(nodeToTest,nodes,inOutSwitch));
547   bool ret(false);
548   for(std::set< IntersectElement >::iterator iter4=inOutSwitch.begin();iter4!=inOutSwitch.end();iter4++)
549     {
550       double val((*iter4).getVal1());
551       if(fabs(val-ref)>=QuadraticPlanarPrecision::getPrecision())
552         {
553           if(val<ref)
554             {
555               if((*iter4).getNodeOnly()->getLoc()==ON_1)
556                 ret=!ret;
557             }
558           else
559             break;
560         }
561       else
562         return true;
563     }
564   return ret;
565 }
566
567 double ComposedEdge::isInOrOutAlg(Node *nodeToTest, const std::set<Node*>& nodes, std::set< IntersectElement >& inOutSwitch) const
568 {
569   // searching for e1
570   std::set<double> radialDistributionOfNodes;
571   std::set<Node *>::const_iterator iter;
572   for(iter=nodes.begin();iter!=nodes.end();iter++)
573     radialDistributionOfNodes.insert(nodeToTest->getSlope(*(*iter)));
574   std::vector<double> radialDistrib(radialDistributionOfNodes.begin(),radialDistributionOfNodes.end());
575   radialDistributionOfNodes.clear();
576   std::vector<double> radialDistrib2(radialDistrib.size());
577   copy(radialDistrib.begin()+1,radialDistrib.end(),radialDistrib2.begin());
578   radialDistrib2.back()=M_PI+radialDistrib.front();
579   std::vector<double> radialDistrib3(radialDistrib.size());
580   std::transform(radialDistrib2.begin(),radialDistrib2.end(),radialDistrib.begin(),radialDistrib3.begin(),std::minus<double>());
581   std::vector<double>::iterator iter3=max_element(radialDistrib3.begin(),radialDistrib3.end());
582   int i=iter3-radialDistrib3.begin();
583   // ok for e1 - Let's go.
584   EdgeInfLin *e1=new EdgeInfLin(nodeToTest,radialDistrib[i]+radialDistrib3[i]/2.);
585   double ref=e1->getCharactValue(*nodeToTest);
586   for(std::list<ElementaryEdge *>::const_iterator iter4=_sub_edges.begin();iter4!=_sub_edges.end();iter4++)
587     {
588       ElementaryEdge *val=(*iter4);
589       if(val)
590         {
591           Edge *e=val->getPtr();
592           std::auto_ptr<EdgeIntersector> intersc(Edge::BuildIntersectorWith(e1,e));
593           bool obviousNoIntersection,areOverlapped;
594           intersc->areOverlappedOrOnlyColinears(0,obviousNoIntersection,areOverlapped);  // first parameter never used
595           if(obviousNoIntersection)
596             {
597               continue;
598             }
599           if(!areOverlapped)
600             {
601               std::list< IntersectElement > listOfIntesc=intersc->getIntersectionsCharacteristicVal();
602               for(std::list< IntersectElement >::iterator iter2=listOfIntesc.begin();iter2!=listOfIntesc.end();iter2++)
603                 if((*iter2).isIncludedByBoth())
604                   inOutSwitch.insert(*iter2);
605             }
606           //if overlapped we can forget
607         }
608       else
609         throw Exception("Invalid use of ComposedEdge::isInOrOutAlg : only one level supported !");
610     }
611   e1->decrRef();
612   return ref;
613 }
614
615 bool ComposedEdge::getDirection() const
616 {
617   throw Exception("ComposedEdge::getDirection : no sense");
618 }
619
620 bool ComposedEdge::intresincEqCoarse(const Edge *other) const
621 {
622   if(_sub_edges.size()!=1)
623     return false;
624   return _sub_edges.front()->intresincEqCoarse(other);
625 }
626
627 void ComposedEdge::clearAll(std::list<ElementaryEdge *>::iterator startToDel)
628 {
629   for(std::list<ElementaryEdge *>::iterator iter=startToDel;iter!=_sub_edges.end();iter++)
630     delete (*iter);
631 }