Salome HOME
041519246752d813f3b21d2985f6daaa48067738
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_2.cxx
1 // File:        NMTTools_PaveFiller_2.cxx
2 // Created:     Mon Dec  8 12:02:56 2003
3 // Author:      Peter KURNEV
4 //              <pkv@irinox>
5
6
7 #include <NMTTools_PaveFiller.ixx>
8
9 #include <Precision.hxx>
10
11 #include <gp_Pnt.hxx>
12
13 #include <Geom_Curve.hxx>
14
15 #include <TopAbs_Orientation.hxx>
16
17 #include <TopoDS.hxx>
18 #include <TopoDS_Edge.hxx>
19 #include <TopoDS_Vertex.hxx>
20
21 #include <BRep_Builder.hxx>
22 #include <BRep_Tool.hxx>
23
24 #include <BOPTools_Pave.hxx>
25 #include <BOPTools_PaveSet.hxx>
26 #include <BOPTools_CArray1OfVEInterference.hxx>
27 #include <BOPTools_VEInterference.hxx>
28
29 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
30
31 #include <NMTDS_ShapesDataStructure.hxx>
32 //
33 #include <BOPTools_IndexedMapOfCoupleOfInteger.hxx>
34 #include <BOPTools_CoupleOfInteger.hxx>
35
36 //=======================================================================
37 // function: PrepareEdges
38 // purpose: 
39 //=======================================================================
40   void NMTTools_PaveFiller::PrepareEdges() 
41 {
42   Standard_Integer  i, nV, ii, aNBSuc, ip, aNbShapesObject;
43   Standard_Real aT;
44   TopAbs_Orientation anOr;
45   TopoDS_Edge   aE;
46   TopoDS_Vertex aV;
47   //
48   aNbShapesObject=myDS->NumberOfShapesOfTheObject();
49   for (i=1; i<=myNbSources; ++i) {
50     if (myDS->GetShapeType(i)==TopAbs_EDGE) {
51       aE=TopoDS::Edge(myDS->Shape(i));
52       //
53       if (BRep_Tool::Degenerated(aE)){
54         continue;
55       }
56       //
57       BOPTools_PaveSet& aPaveSet=myPavePool(myDS->RefEdge(i));
58       //
59       // A <-
60       aNBSuc=myDS->NumberOfSuccessors(i);
61       for (ii=1; ii <=aNBSuc; ii++) {
62         nV=myDS->GetSuccessor(i, ii);
63         anOr=myDS->GetOrientation(i, ii);
64         aV=TopoDS::Vertex(myDS->Shape(nV));
65         aV.Orientation(anOr);
66         aT=BRep_Tool::Parameter(aV, aE);
67         //
68         ip=FindSDVertex(nV);
69         if (ip) {
70           aV=TopoDS::Vertex(myDS->Shape(ip));
71           aV.Orientation(anOr);// XX ? if the edge is closed it'll be amazing result 
72           nV=ip;
73         }
74         //
75         BOPTools_Pave aPave(nV, aT); 
76         aPaveSet.Append (aPave);
77       }
78     }
79   }
80 }
81 //=======================================================================
82 // function: PerformVE
83 // purpose: 
84 //=======================================================================
85   void NMTTools_PaveFiller::PerformVE() 
86 {
87   myIsDone=Standard_False;
88   //
89   Standard_Boolean bJustAddInterference;
90   Standard_Integer n1, n2, anIndexIn, aFlag, aWhat, aWith, aNbVEs, aBlockLength, iSDV, nV1;
91   Standard_Real aT;
92   TopoDS_Vertex aV1;
93   TopoDS_Edge aE2;
94   BOPTools_IndexedMapOfCoupleOfInteger aSnareMap;
95   BOPTools_CoupleOfInteger aCouple;
96   //
97   BOPTools_CArray1OfVEInterference& aVEs=myIntrPool->VEInterferences();
98   //
99   myDSIt.Initialize (TopAbs_VERTEX, TopAbs_EDGE);
100   //
101   // BlockLength correction
102   aNbVEs=ExpectedPoolLength();
103   aBlockLength=aVEs.BlockLength();
104   if (aNbVEs > aBlockLength) {
105     aVEs.SetBlockLength(aNbVEs);
106   }
107   //
108   for (; myDSIt.More(); myDSIt.Next()) {
109     myDSIt.Current(n1, n2, bJustAddInterference);
110     //
111     if (! myIntrPool->IsComputed(n1, n2)) {
112       if (! IsSuccesstorsComputed(n1, n2)) {
113         anIndexIn=0;
114         aWhat=n1; // Vertex
115         aWith=n2; // Edge
116         SortTypes(aWhat, aWith);
117         //
118         if(bJustAddInterference) {
119          myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexEdge, anIndexIn);
120          continue;
121         }
122         // Edge
123         aE2=TopoDS::Edge(myDS->Shape(aWith));
124         //
125         if (BRep_Tool::Degenerated(aE2)){
126           continue;
127         }
128         // Vertex
129         nV1=aWhat;
130         aV1=TopoDS::Vertex(myDS->Shape(aWhat));
131         //
132         iSDV=FindSDVertex(aWhat);
133         if (iSDV) {
134           nV1=iSDV;
135           aV1=TopoDS::Vertex(myDS->Shape(nV1));
136         }
137         //
138         aFlag=myContext.ComputeVE (aV1, aE2, aT);
139         //
140         if (!aFlag) {
141           //
142           // Add Interference to the Pool
143           BOPTools_VEInterference anInterf (aWhat, aWith, aT);
144           anIndexIn=aVEs.Append(anInterf);
145           //
146           // Add Pave to the Edge's myPavePool
147           aCouple.SetCouple(nV1, aWith);
148           if (!aSnareMap.Contains(aCouple)){
149             aSnareMap.Add(aCouple);
150             //
151             BOPTools_Pave aPave(nV1, aT, BooleanOperations_VertexEdge);
152             aPave.SetInterference(anIndexIn);
153             BOPTools_PaveSet& aPaveSet= myPavePool(myDS->RefEdge(aWith));
154             aPaveSet.Append(aPave);
155           }
156           //
157           // State for the Vertex in DS;
158           myDS->SetState (aWhat, BooleanOperations_ON);
159           // Insert Vertex in Interference Object
160           BOPTools_VEInterference& aVE=aVEs(anIndexIn);
161           aVE.SetNewShape(aWhat);
162         }
163         myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexEdge, anIndexIn);
164       }
165     }
166   }
167   myIsDone=Standard_True;
168 }
169
170 /*
171 // A
172 //
173       //                                                   cto900/M2
174       // Some of Edges can be [Semi] Infinite.  Such  Edges have no 
175       // vertices on correspondant INF ends.   So we  must  provide 
176       // these vertices formally (to obtain  Shrunk  Ranges for e.g). 
177       // In reality this vertex(-es) does not belong to the INF Edge.
178       // It just has reference in the DS.
179       //                            PKV Tue Apr 23 10:21:45 2002                 
180       {
181         Standard_Real aT1, aT2, aTolE;
182         Standard_Boolean bInf1, bInf2;
183         gp_Pnt aPx;
184         TopoDS_Vertex aVx; 
185         BRep_Builder aBB;
186         BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq; 
187         //
188         aTolE=BRep_Tool::Tolerance(aE);
189         Handle(Geom_Curve) aC3D=BRep_Tool::Curve (aE, aT1, aT2);
190         bInf1=Precision::IsNegativeInfinite(aT1);
191         bInf2=Precision::IsPositiveInfinite(aT2);
192
193         if (bInf1) {
194           aC3D->D0(aT1, aPx);
195           aBB.MakeVertex(aVx, aPx, aTolE);
196           myDS->InsertShapeAndAncestorsSuccessors(aVx, anASSeq);
197           nV=myDS->NumberOfInsertedShapes();
198           BOPTools_Pave aPave(nV, aT1); 
199           aPaveSet.Append (aPave);
200         }
201
202         if (bInf2) {
203           aC3D->D0(aT2, aPx);
204           aBB.MakeVertex(aVx, aPx, aTolE);
205           myDS->InsertShapeAndAncestorsSuccessors(aVx, anASSeq);
206           nV=myDS->NumberOfInsertedShapes();
207           BOPTools_Pave aPave(nV, aT2);
208           aPaveSet.Append (aPave); 
209         }
210       }
211 */