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