Salome HOME
PAL12607: Static objects in Geometry GUI libraries.
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_FinderShapeOn1.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        GEOMAlgo_FinderShapeOn1.cxx
21 // Created:     Fri Mar  4 10:31:06 2005
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <GEOMAlgo_FinderShapeOn1.ixx>
27 #include <math.h>
28
29
30 #include <Precision.hxx>
31 #include <TColStd_Array1OfInteger.hxx>
32 #include <TColStd_MapOfInteger.hxx>
33
34 #include <gp_Trsf.hxx>
35 #include <gp_Cylinder.hxx>
36 #include <gp_Pnt.hxx>
37
38 #include <TColgp_Array1OfPnt.hxx>
39
40 #include <Poly_Array1OfTriangle.hxx>
41 #include <Poly_Triangle.hxx>
42 #include <Poly_PolygonOnTriangulation.hxx>
43 #include <Poly_Triangulation.hxx>
44
45 #include <Geom_Curve.hxx>
46 #include <Geom_Surface.hxx>
47 #include <GeomAdaptor_Surface.hxx>
48 #include <GeomAbs_SurfaceType.hxx>
49 #include <GeomAdaptor_Curve.hxx>
50 #include <GeomAbs_CurveType.hxx>
51
52 #include <TopAbs_State.hxx>
53
54 #include <TopLoc_Location.hxx>
55 #include <TopoDS.hxx>
56 #include <TopoDS_Shape.hxx>
57 #include <TopoDS_Vertex.hxx>
58 #include <TopoDS_Face.hxx>
59 #include <TopoDS_Edge.hxx>
60
61 #include <TopExp.hxx>
62 #include <TopExp_Explorer.hxx>
63
64 #include <TopTools_IndexedMapOfShape.hxx>
65
66 #include <BRep_Tool.hxx>
67 #include <BRepLib_MakeEdge.hxx>
68
69 #include <GEOMAlgo_ListIteratorOfListOfPnt.hxx>
70 #include <GEOMAlgo_PassKey.hxx>
71 #include <GEOMAlgo_DataMapOfPassKeyInteger.hxx>
72 #include <GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger.hxx>
73 #include <GEOMAlgo_SurfaceTools.hxx>
74 #include <GEOMAlgo_StateCollector.hxx>
75
76
77 //=======================================================================
78 //function : GEOMAlgo_FinderShapeOn1
79 //purpose  : 
80 //=======================================================================
81 GEOMAlgo_FinderShapeOn1::GEOMAlgo_FinderShapeOn1()
82 :
83   GEOMAlgo_ShapeAlgo()
84 {
85   myTolerance=0.0001;
86   myShapeType=TopAbs_VERTEX;
87   myState=GEOMAlgo_ST_UNKNOWN;
88   myNbPntsMin=3;
89   myNbPntsMax=0;
90 }
91 //=======================================================================
92 //function : ~
93 //purpose  : 
94 //=======================================================================
95 GEOMAlgo_FinderShapeOn1::~GEOMAlgo_FinderShapeOn1()
96 {
97 }
98 //=======================================================================
99 //function : SetSurface
100 //purpose  : 
101 //=======================================================================
102 void GEOMAlgo_FinderShapeOn1::SetSurface(const Handle(Geom_Surface)& aS)
103 {
104   mySurface=aS;
105 }
106 //=======================================================================
107 //function : Surface
108 //purpose  : 
109 //=======================================================================
110 const Handle(Geom_Surface)& GEOMAlgo_FinderShapeOn1::Surface() const
111 {
112   return mySurface;
113 }
114 //=======================================================================
115 //function : SetShapeType
116 //purpose  : 
117 //=======================================================================
118 void GEOMAlgo_FinderShapeOn1::SetShapeType(const TopAbs_ShapeEnum aType)
119 {
120   myShapeType=aType;
121 }
122 //=======================================================================
123 //function : ShapeType
124 //purpose  : 
125 //=======================================================================
126 TopAbs_ShapeEnum GEOMAlgo_FinderShapeOn1::ShapeType()const
127 {
128   return myShapeType;
129 }
130 //=======================================================================
131 //function : SetState
132 //purpose  : 
133 //=======================================================================
134 void GEOMAlgo_FinderShapeOn1::SetState(const GEOMAlgo_State aState)
135 {
136   myState=aState;
137 }
138 //=======================================================================
139 //function : State
140 //purpose  : 
141 //=======================================================================
142 GEOMAlgo_State GEOMAlgo_FinderShapeOn1::State() const
143 {
144   return myState;
145 }
146 //=======================================================================
147 //function : SetNbPntsMin
148 //purpose  : 
149 //=======================================================================
150 void GEOMAlgo_FinderShapeOn1::SetNbPntsMin(const Standard_Integer aNb)
151 {
152   myNbPntsMin=aNb;
153 }
154 //=======================================================================
155 //function : NbPntsMin
156 //purpose  : 
157 //=======================================================================
158 Standard_Integer GEOMAlgo_FinderShapeOn1::NbPntsMin()const
159 {
160   return myNbPntsMin;
161 }
162 //=======================================================================
163 //function : SetNbPntsMax
164 //purpose  : 
165 //=======================================================================
166 void GEOMAlgo_FinderShapeOn1::SetNbPntsMax(const Standard_Integer aNb)
167 {
168   myNbPntsMax=aNb;
169 }
170 //=======================================================================
171 //function : NbPntsMax
172 //purpose  : 
173 //=======================================================================
174 Standard_Integer GEOMAlgo_FinderShapeOn1::NbPntsMax()const
175 {
176   return myNbPntsMax;
177 }
178 //=======================================================================
179 // function: MSS
180 // purpose: 
181 //=======================================================================
182 const GEOMAlgo_IndexedDataMapOfShapeState& GEOMAlgo_FinderShapeOn1::MSS() const
183 {
184   return myMSS;
185 }
186 //=======================================================================
187 // function: Shapes
188 // purpose: 
189 //=======================================================================
190 const TopTools_ListOfShape& GEOMAlgo_FinderShapeOn1::Shapes() const
191 {
192   Standard_Integer i, aNb;
193   TopTools_ListOfShape* pL;
194   //
195   pL=(TopTools_ListOfShape*) &myLS;
196   pL->Clear();
197   //
198   aNb=myMSS.Extent();
199   for (i=1; i<=aNb; ++i) {
200     const TopoDS_Shape& aS=myMSS.FindKey(i);
201     if (aS.ShapeType()==myShapeType) {
202       pL->Append(aS);
203     }
204   }
205   return myLS;
206 }
207 //=======================================================================
208 //function : Perform
209 //purpose  : 
210 //=======================================================================
211 void GEOMAlgo_FinderShapeOn1::Perform()
212 {
213   myErrorStatus=0;
214   myWarningStatus=0;
215   myLS.Clear();
216   myMSS.Clear();
217   //
218   CheckData();
219   if(myErrorStatus) {
220     return;
221   }
222   //
223   // 1
224   ProcessVertices();
225   if(myErrorStatus) {
226     return;
227   }
228   if (myShapeType==TopAbs_VERTEX) {
229     return;
230   }
231   //
232   // 2
233   ProcessEdges();
234   if(myErrorStatus) {
235     return;
236   }
237   if (myShapeType==TopAbs_EDGE) {
238     return;
239   }
240   //
241   // 3
242   ProcessFaces();
243   if(myErrorStatus) {
244     return;
245   }
246   if (myShapeType==TopAbs_FACE) {
247     return;
248   }
249   //
250   // 4
251   ProcessSolids(); 
252   //
253 }
254 //=======================================================================
255 //function : ProcessVertices
256 //purpose  : 
257 //=======================================================================
258 void GEOMAlgo_FinderShapeOn1::ProcessVertices()
259 {
260   myErrorStatus=0;
261   //
262   Standard_Boolean bIsConformState;
263   Standard_Integer i, aNb;
264   gp_Pnt aP;
265   TopTools_IndexedMapOfShape aM;
266   TopAbs_State aSt;
267   //
268   TopExp::MapShapes(myShape, TopAbs_VERTEX, aM);
269   aNb=aM.Extent();
270   for (i=1; i<=aNb; ++i) {
271     const TopoDS_Vertex& aV=TopoDS::Vertex(aM(i));
272     aP=BRep_Tool::Pnt(aV);
273     //
274     aSt = GetPointState( aP );
275     bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
276     //
277     if (myShapeType==TopAbs_VERTEX){
278       if (bIsConformState) {
279         myMSS.Add(aV, aSt);
280       }
281     }
282     else if (bIsConformState || aSt==TopAbs_ON) {
283       myMSS.Add(aV, aSt);
284     }
285   }
286 }
287 //=======================================================================
288 //function : ProcessEdges
289 //purpose  : 
290 //=======================================================================
291 void GEOMAlgo_FinderShapeOn1::ProcessEdges()
292 {
293   myErrorStatus=0;
294   //
295   Standard_Boolean bIsConformState, bIsToBreak;
296   Standard_Integer i, aNb, iCnt;
297   TopAbs_State aSt;
298   TopTools_IndexedMapOfShape aM;
299   TopExp_Explorer aExp;
300   GEOMAlgo_ListIteratorOfListOfPnt aIt;
301   GeomAbs_SurfaceType aType1;
302   //
303   aType1=myGAS.GetType();
304   //
305   TopExp::MapShapes(myShape, TopAbs_EDGE, aM);
306   aNb=aM.Extent();
307   for (i=1; i<=aNb; ++i) {
308     GEOMAlgo_ListOfPnt aLP;
309     GEOMAlgo_StateCollector aSC;
310     //
311     const TopoDS_Edge& aE=TopoDS::Edge(aM(i));
312     //
313     aExp.Init(aE, TopAbs_VERTEX);
314     for (; aExp.More(); aExp.Next()) {
315       const TopoDS_Shape& aV=aExp.Current();
316       //
317       bIsConformState=myMSS.Contains(aV);
318       if (!bIsConformState) {
319         break;// vertex has non-conformed state
320       }
321       else {
322         aSt=myMSS.FindFromKey(aV);
323         aSC.AppendState(aSt);
324       }
325     }
326     //
327     if (!bIsConformState) {
328       continue; // vertex has non-conformed state,skip edge
329     }
330     //
331     if (BRep_Tool::Degenerated(aE)) {
332       myMSS.Add(aE, aSt); 
333       continue;
334     }
335     //
336     if (myState==GEOMAlgo_ST_ON && aType1==GeomAbs_Sphere) {
337       Standard_Real aT1, aT2;
338       Handle(Geom_Curve) aC; 
339       GeomAdaptor_Curve aGAC;
340       GeomAbs_CurveType aType2;
341       //
342       aC=BRep_Tool::Curve(aE, aT1, aT2);
343       aGAC.Load(aC);
344       //
345       aType2=aGAC.GetType();
346       if (aType2==GeomAbs_Line) {
347         continue;
348       }
349     }
350     //
351     InnerPoints(aE, aLP);
352     if (myErrorStatus) {
353       return;  
354     }
355     //
356     bIsConformState=Standard_True;
357     aIt.Initialize(aLP);
358     for (iCnt=0; aIt.More(); aIt.Next(), ++iCnt) {
359       if (myNbPntsMax) {
360         if (iCnt > myNbPntsMax) {
361           break;
362         }
363       }
364       //
365       const gp_Pnt& aP=aIt.Value();
366       aSt = GetPointState( aP );
367       bIsToBreak=aSC.AppendState(aSt);
368       if (bIsToBreak) {
369         break;
370       }
371     }
372     //
373     aSt=aSC.State();    
374     //
375     bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
376     if (myShapeType==TopAbs_EDGE) {
377       if (bIsConformState) {
378         myMSS.Add(aE, aSt);
379       }
380     }
381     else if (bIsConformState || aSt==TopAbs_ON) {
382       myMSS.Add(aE, aSt);
383     }
384   } //  for (i=1; i<=aNb; ++i) next edge 
385 }
386 //=======================================================================
387 //function : ProcessFaces
388 //purpose  : 
389 //=======================================================================
390 void GEOMAlgo_FinderShapeOn1::ProcessFaces()
391 {
392   myErrorStatus=0;
393   //
394   Standard_Boolean bIsConformState, bIsToBreak;
395   Standard_Integer i, aNbF, iCnt;
396   TopAbs_State aSt;
397   TopTools_IndexedMapOfShape aM;
398   TopExp_Explorer aExp;
399   GEOMAlgo_ListIteratorOfListOfPnt aIt;
400   GeomAbs_SurfaceType aType1, aType2;
401   //
402   aType1=myGAS.GetType();
403   //
404   TopExp::MapShapes(myShape, TopAbs_FACE, aM);
405   aNbF=aM.Extent();
406   for (i=1; i<=aNbF; ++i) {
407     GEOMAlgo_StateCollector aSC;
408     GEOMAlgo_ListOfPnt aLP;
409     //
410     const TopoDS_Face& aF=TopoDS::Face(aM(i));
411     //
412     if (myState==GEOMAlgo_ST_ON) {
413       Handle(Geom_Surface) aS;
414       GeomAdaptor_Surface aGAS;
415       //
416       aS=BRep_Tool::Surface(aF);
417       aGAS.Load(aS);
418       aType2=aGAS.GetType();
419       if (aType2!=aType1) {
420         continue;
421       }
422     }
423     //
424     aExp.Init(aF, TopAbs_EDGE);
425     for (; aExp.More(); aExp.Next()) {
426       const TopoDS_Shape& aE=aExp.Current();
427       bIsConformState=myMSS.Contains(aE);
428       if (!bIsConformState) {
429         break;// edge has non-conformed state
430       }
431       else {
432         aSt=myMSS.FindFromKey(aE);
433         aSC.AppendState(aSt);
434       }
435     }
436     //
437     if (!bIsConformState) {
438       continue; // edge has non-conformed state,skip face
439     }
440     //
441     InnerPoints(aF, aLP);
442     if (myErrorStatus) {
443       return;
444     }
445     //
446     bIsConformState=Standard_True;
447     aIt.Initialize(aLP);
448     for (iCnt=0; aIt.More(); aIt.Next(), ++iCnt) {
449       if (myNbPntsMax) {
450         if (iCnt > myNbPntsMax) {
451           break;
452         }
453       }
454       //
455       const gp_Pnt& aP=aIt.Value();
456       aSt = GetPointState( aP );
457       bIsToBreak=aSC.AppendState(aSt);
458       if (bIsToBreak) {
459         break;
460       }
461     }
462     //
463     aSt=aSC.State();    
464     //
465     bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
466     if (myShapeType==TopAbs_FACE) {
467       if (bIsConformState) {
468         myMSS.Add(aF, aSt);
469       }
470     }
471     else if (bIsConformState || aSt==TopAbs_ON) {
472       myMSS.Add(aF, aSt);
473     }
474   }//  for (i=1; i<=aNb; ++i) next face 
475 }
476 //=======================================================================
477 //function : ProcessSolids
478 //purpose  : 
479 //=======================================================================
480 void GEOMAlgo_FinderShapeOn1::ProcessSolids()
481 {
482   myErrorStatus=0;
483   //
484   Standard_Boolean bIsConformState;
485   Standard_Integer i, aNbS, j, aNbF;
486   TopTools_IndexedMapOfShape aM, aMF;
487   TopAbs_State aSt;
488   //
489   TopExp::MapShapes(myShape, TopAbs_SOLID, aM);
490   aNbS=aM.Extent();
491   for (i=1; i<=aNbS; ++i) {
492     GEOMAlgo_StateCollector aSC;
493     //
494     const TopoDS_Shape& aSd=aM(i);
495     aMF.Clear();
496     TopExp::MapShapes(aSd, TopAbs_FACE, aMF);
497     aNbF=aMF.Extent();
498     for (j=1; j<=aNbF; ++j) {
499       const TopoDS_Shape& aF=aMF(j);
500       bIsConformState=myMSS.Contains(aF);
501       if (!bIsConformState) {
502         break;// face has non-conformed state
503       }
504       else {
505         aSt=myMSS.FindFromKey(aF);
506         aSC.AppendState(aSt);
507       }
508     }
509     //
510     if (!bIsConformState) {
511       continue; // face has non-conformed state,skip solid
512     }
513     //
514     aSt=aSC.State();    
515     //
516     bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
517     if (bIsConformState) {
518       myMSS.Add(aSd, aSt);
519     }
520   }
521 }
522 //
523 //=======================================================================
524 //function : InnerPoints
525 //purpose  : 
526 //=======================================================================
527 void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
528                                           GEOMAlgo_ListOfPnt& aLP)
529 {
530   myErrorStatus=0;
531   //
532   Standard_Integer j, j1, j2, k, n[4], aNbLinks, aNx, aNbMax, aNb;
533   Standard_Integer iCnt, *pIds;
534   TopLoc_Location aLoc;
535   Handle(Poly_Triangulation) aTRF;
536   TColStd_MapOfInteger aMBN;
537   GEOMAlgo_DataMapOfPassKeyInteger aMPKI;
538   GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger aIt;
539   gp_Pnt aP, aP1, aP2;
540   //
541   aLP.Clear();
542   //
543   aTRF=BRep_Tool::Triangulation(aF, aLoc);
544   if (aTRF.IsNull()) {
545     myErrorStatus=20; // no triangulation found
546     return;  
547   }
548   //
549   const gp_Trsf& aTrsf=aLoc.Transformation();
550   const Poly_Array1OfTriangle& aTrs=aTRF->Triangles();
551   const TColgp_Array1OfPnt& aNodes=aTRF->Nodes();
552   //
553   // map link/nbtriangles
554   j1=aTrs.Lower();
555   j2=aTrs.Upper();
556   for (j=j1; j<=j2; ++j) {
557     const Poly_Triangle& aTr=aTrs(j);
558     aTr.Get(n[0], n[1], n[2]);
559     n[3]=n[0];
560     for (k=0; k<3; ++k) {
561       GEOMAlgo_PassKey aPK;
562       //
563       aPK.SetIds(n[k], n[k+1]);
564       if (aMPKI.IsBound(aPK)) {
565         Standard_Integer& iCntX=aMPKI.ChangeFind(aPK);
566         ++iCntX;
567       }
568       else {
569         aMPKI.Bind(aPK, 1);
570       }
571     }
572   }
573   //
574   // boundary nodes aMBN
575   aNbLinks=aMPKI.Extent();
576   aIt.Initialize(aMPKI);
577   for (; aIt.More(); aIt.Next()) {
578     iCnt=aIt.Value();
579     if (iCnt==1) {
580       const GEOMAlgo_PassKey& aPK=aIt.Key();
581       aNbMax=aPK.NbMax();
582       pIds=(Standard_Integer*)aPK.Key();
583       for (k=1; k<3; ++k) {
584         aNx=*(pIds+aNbMax-k);
585         aMBN.Add(aNx);
586       }
587     }
588   }
589   //
590   // inner nodes=all_nodes - boundary_nodes 
591   j1=aNodes.Lower();
592   j2=aNodes.Upper();
593   for (j=j1; j<=j2; ++j) {
594     if (!aMBN.Contains(j)) {
595       aP=aNodes(j).Transformed(aTrsf);
596       aLP.Append(aP);
597     }
598   }
599   //
600   aNb=aLP.Extent();
601   //
602   if (!aNb && myNbPntsMin) { 
603     // try to fill it yourself
604     Standard_Boolean bIsDone;
605     Standard_Integer aN1, aN2;
606     Handle(Geom_Surface) aS;
607     GeomAdaptor_Surface aGAS;
608     GeomAbs_SurfaceType aType;
609     //
610     aS=BRep_Tool::Surface(aF);
611     aGAS.Load(aS);
612     aType=aGAS.GetType();
613     if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder) {
614       // inner links
615       aNbLinks=aMPKI.Extent();
616       aIt.Initialize(aMPKI);
617       for (; aIt.More(); aIt.Next()) {
618         iCnt=aIt.Value();
619         if (iCnt>1) {
620           // take the first having occured inner link
621           // and discretize it
622           const GEOMAlgo_PassKey& aPK=aIt.Key();
623           aNbMax=aPK.NbMax();
624           pIds=(Standard_Integer*)aPK.Key();
625           aN1=*(pIds+aNbMax-1);
626           aN2=*(pIds+aNbMax-2);
627           aP1=aNodes(aN1).Transformed(aTrsf);
628           aP2=aNodes(aN2).Transformed(aTrsf);
629           //
630           if (aType==GeomAbs_Cylinder) {
631             Standard_Real aTolSM;
632             gp_Cylinder aCyl;
633             //
634             aTolSM=1.523e-6;//~1.-cos(0.1 deg)
635             aCyl=aGAS.Cylinder();
636             if (!GEOMAlgo_SurfaceTools::IsCoaxial(aP1, aP2, aCyl, aTolSM)) {
637               continue;
638             }
639           }
640           //
641           BRepLib_MakeEdge aBME(aP1, aP2);
642           bIsDone=aBME.IsDone();
643           if (!bIsDone) {
644             myErrorStatus=30; //can not obtain the line fron the link
645             return;
646           }
647           //
648           const TopoDS_Shape& aSx=aBME.Shape();
649           const TopoDS_Edge& aE=TopoDS::Edge(aSx);
650           //
651           InnerPoints(aE, myNbPntsMin, aLP);
652           break;
653         }// if (iCnt>1)
654       }// for (; aIt.More(); aIt.Next())
655     }// if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder) 
656   }// if (!aNb && myNbPntsMin) { 
657 }
658 //=======================================================================
659 //function : InnerPoints
660 //purpose  : 
661 //=======================================================================
662 void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
663                                           GEOMAlgo_ListOfPnt& aLP)
664 {
665   myErrorStatus=0;
666   //
667   Standard_Integer j, aNbNodes, aIndex, aNb;
668   Handle(Poly_PolygonOnTriangulation) aPTE;
669   Handle(Poly_Triangulation) aTRE;
670   TopLoc_Location aLoc;
671   gp_Pnt aP;
672   //
673   aLP.Clear();
674   BRep_Tool::PolygonOnTriangulation(aE, aPTE, aTRE, aLoc);
675   if (aTRE.IsNull() || aPTE.IsNull()) {
676     myErrorStatus=20; // no triangulation found
677     return;  
678   }
679   //
680   const gp_Trsf& aTrsf=aLoc.Transformation();
681   const TColgp_Array1OfPnt& aNodes=aTRE->Nodes();
682   //
683   aNbNodes=aPTE->NbNodes();
684   const TColStd_Array1OfInteger& aInds=aPTE->Nodes();
685   for (j=2; j<aNbNodes; ++j) {
686     aIndex=aInds(j);
687     aP=aNodes(aIndex).Transformed(aTrsf);
688     aLP.Append(aP);
689   }
690   //
691   aNb=aLP.Extent();
692   if (!aNb && myNbPntsMin) { 
693     // try to fill it yourself
694     InnerPoints(aE, myNbPntsMin, aLP);
695     aNb=aLP.Extent();
696     
697   }
698 }
699 //=======================================================================
700 //function : InnerPoints
701 //purpose  : 
702 //=======================================================================
703 void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
704                                           const Standard_Integer aNbPntsMin,
705                                           GEOMAlgo_ListOfPnt& aLP)
706 {
707   // try to fill it yourself
708   Standard_Boolean bInf1, bInf2;
709   Standard_Integer j, aNbT;
710   Standard_Real dT, aT, aT1, aT2;
711   gp_Pnt aP;
712   Handle(Geom_Curve) aC3D;
713   //
714   aC3D=BRep_Tool::Curve(aE, aT1, aT2);
715   if (aC3D.IsNull()) {
716     return;
717   }
718   //
719   bInf1=Precision::IsNegativeInfinite(aT1);
720   bInf2=Precision::IsPositiveInfinite(aT2);
721   if (bInf1 || bInf2) {
722     return;
723   }
724   //
725   aNbT=myNbPntsMin+1;
726   dT=(aT2-aT1)/aNbT;
727   for (j=1; j<=aNbPntsMin; ++j) {
728     aT=aT1+j*dT;
729     aC3D->D0(aT, aP);
730     aLP.Append(aP);
731   }
732 }
733
734 //=======================================================================
735 //function : CheckData
736 //purpose  : 
737 //=======================================================================
738 void GEOMAlgo_FinderShapeOn1::CheckData()
739 {
740   myErrorStatus=0;
741   //
742   if(mySurface.IsNull()) {
743     myErrorStatus=10; // mySurface=NULL
744     return;
745   }
746   //
747   if (myShape.IsNull()) {
748     myErrorStatus=11; // myShape=NULL
749     return;
750   }
751   //
752   if (!(myShapeType==TopAbs_VERTEX ||
753         myShapeType==TopAbs_EDGE ||
754         myShapeType==TopAbs_FACE ||
755         myShapeType==TopAbs_SOLID)) {
756     myErrorStatus=12; // unallowed subshape type
757     return;
758   }
759   //
760   if (myState==GEOMAlgo_ST_UNKNOWN || 
761       myState==GEOMAlgo_ST_INOUT) {
762     myErrorStatus=13; // unallowed state type
763     return;
764   }
765   //
766   GeomAbs_SurfaceType aType;
767   //
768   myGAS.Load(mySurface);
769   aType=myGAS.GetType();
770   if (!(aType==GeomAbs_Plane || 
771         aType==GeomAbs_Cylinder ||
772         aType==GeomAbs_Sphere)) {
773     myErrorStatus=14; // unallowed surface type
774   }
775 }
776
777 //=======================================================================
778 //function : GetPointState
779 //purpose  : 
780 //=======================================================================
781
782 TopAbs_State GEOMAlgo_FinderShapeOn1::GetPointState(const gp_Pnt& aP) 
783 {
784   TopAbs_State aSt;
785   GEOMAlgo_SurfaceTools::GetState(aP, myGAS, myTolerance, aSt);
786   return aSt;
787 }
788
789
790 //
791 // myErrorStatus :
792 //
793 // 10 -mySurface=NULL
794 // 11 -myShape=NULL
795 // 12 -unallowed type of subshapes 
796 // 13 -unallowed state  
797 // 14 -unallowed surface type
798 // 15 -unallowed surface type
799 // 20- no triangulation found
800 // 30- can not obtain the line from the link
801
802
803 /*
804 // Chronometer
805 #include <OSD_Chronometer.hxx>
806 #include <Standard_Static.hxx>
807
808 Standard_STATIC(OSD_Chronometer, x_S_Chrono);
809 static void x_StartChrono();
810 static void x_StopChrono(); 
811 static Standard_Boolean x_IsToShow(); 
812 //
813 //=======================================================================
814 //function : x_StartChrono
815 //purpose  : 
816 //=======================================================================
817 void x_StartChrono() 
818 {
819   if (x_IsToShow()){
820     x_S_Chrono().Reset();
821     x_S_Chrono().Start();
822   }
823 }
824 //=======================================================================
825 //function : x_StopChrono
826 //purpose  : 
827 //=======================================================================
828 void x_StopChrono() 
829
830   if (x_IsToShow()){
831     Standard_Real Chrono;
832     x_S_Chrono().Stop();
833     x_S_Chrono().Show(Chrono);
834     printf(" Tps: %lf\n", Chrono);
835     //cout << "Tps: " << Chrono << endl;
836   }
837 }
838 //=======================================================================
839 //function : x_IsToShow
840 //purpose  : 
841 //=======================================================================
842 Standard_Boolean x_IsToShow() 
843
844   Standard_Boolean bFlag=Standard_False;
845   //
846   char *xr=getenv ("STDCHRONO");
847   if (xr!=NULL){
848     if (!strcmp (xr, "yes")) {
849       bFlag=!bFlag;
850     }
851   }
852   return bFlag;
853 }
854 */