0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / TopOpeBRep / TopOpeBRep_FaceEdgeFiller.cxx
1 // Created on: 1995-06-14
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <gp_Pnt2d.hxx>
19 #include <TopoDS.hxx>
20 #include <TopoDS_Edge.hxx>
21 #include <TopoDS_Face.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TopOpeBRep_FaceEdgeFiller.hxx>
24 #include <TopOpeBRep_FaceEdgeIntersector.hxx>
25 #include <TopOpeBRep_PointGeomTool.hxx>
26 #include <TopOpeBRepDS_CurvePointInterference.hxx>
27 #include <TopOpeBRepDS_DataStructure.hxx>
28 #include <TopOpeBRepDS_HDataStructure.hxx>
29 #include <TopOpeBRepDS_Interference.hxx>
30 #include <TopOpeBRepDS_InterferenceTool.hxx>
31 #include <TopOpeBRepDS_Point.hxx>
32
33 #ifdef OCCT_DEBUG
34 extern void FEINT_DUMPPOINTS(TopOpeBRep_FaceEdgeIntersector& FEINT,
35                              const TopOpeBRepDS_DataStructure& BDS);
36 #endif
37
38 //=======================================================================
39 //function : TopOpeBRep_FaceEdgeFiller
40 //purpose  : 
41 //=======================================================================
42
43 TopOpeBRep_FaceEdgeFiller::TopOpeBRep_FaceEdgeFiller() 
44 {
45 }
46
47
48 //=======================================================================
49 //function : Insert
50 //purpose  : 
51 //=======================================================================
52
53 void TopOpeBRep_FaceEdgeFiller::Insert
54 (const TopoDS_Shape& F,
55  const TopoDS_Shape& E,
56  TopOpeBRep_FaceEdgeIntersector& FEINT,
57  const Handle(TopOpeBRepDS_HDataStructure)& HDS)
58 {
59   const TopoDS_Face& FF = TopoDS::Face(F);
60   const TopoDS_Edge& EE = TopoDS::Edge(E);
61
62   // exit if no point.
63   FEINT.InitPoint(); 
64   if ( ! FEINT.MorePoint() ) return;
65
66   TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
67
68   TopAbs_Orientation FFori = FF.Orientation();
69
70   // --- Add <FF,EE> in BDS
71   Standard_Integer FFindex = BDS.AddShape(FF,1);
72                              BDS.AddShape(EE,2);
73
74   // --- get list of interferences connected to edges <FF>,<EE>
75   TopOpeBRepDS_ListOfInterference& EIL1 = BDS.ChangeShapeInterferences(FF);
76   TopOpeBRepDS_ListOfInterference& EIL2 = BDS.ChangeShapeInterferences(EE);
77
78   Handle(TopOpeBRepDS_Interference) EPI;  //edge/point interference
79   Handle(TopOpeBRepDS_Interference) EVI;  //edge/vertex interference
80
81   for (; FEINT.MorePoint(); FEINT.NextPoint() ) {
82     gp_Pnt2d      pUV; FEINT.UVPoint(pUV);
83     Standard_Real parE = FEINT.Parameter();
84
85 #ifdef OCCT_DEBUG
86     TopAbs_Orientation EEori = EE.Orientation();
87     TopOpeBRepDS_Transition TFF = FEINT.Transition(1,EEori); (void)TFF;
88 #endif
89     TopOpeBRepDS_Transition TEE = FEINT.Transition(2,FFori);
90     TEE.Index(FFindex);
91     
92     TopoDS_Vertex V1;
93     Standard_Boolean isvertexF = FEINT.IsVertex(1,V1);
94     TopoDS_Vertex V2;
95     Standard_Boolean isvertexE = FEINT.IsVertex(2,V2);
96     Standard_Boolean isvertex = isvertexF || isvertexE;
97
98     Standard_Integer DSPindex;
99     Standard_Boolean EPIfound;
100
101     if ( ! isvertex ) {
102       // create a new geometry in DS ( and get its index <DSPindex> )
103       // or get the index <DSPindex> of an equal geometry
104       // among those of Edge/Point interferences connected to <FF> (or <EE>).
105
106       TopOpeBRepDS_ListIteratorOfListOfInterference itEIL1(EIL1);
107       EPIfound = GetGeometry(itEIL1,FEINT,DSPindex,BDS);
108       if ( ! EPIfound ) DSPindex = MakeGeometry(FEINT,BDS);
109
110       // sur FF
111       // NYI : FacePointInterference : on ajoute un point INTERNAL a F
112 //      FPI = new TopOpeBRepDS_FacePointInterference(TopAbs_INTERNAL,
113 //                                             TopOpeBRepDS_FACE,FFindex,
114 //                                             TopOpeBRepDS_POINT,DSPindex,
115 //                                             pUV);
116 //      StoreInterference(FPI,EIL1,BDS);
117
118       // sur EE
119       EPI = TopOpeBRepDS_InterferenceTool::MakeCurveInterference
120         (TEE,TopOpeBRepDS_FACE,FFindex,TopOpeBRepDS_POINT,DSPindex,parE);
121       StoreInterference(EPI,EIL2,BDS);
122     }
123
124     else if ( isvertexF ) {
125       // si aussi vertex de E, in privilegie le vertex de la face
126       Standard_Integer Vindex = BDS.AddShape(V1,1);
127
128       // sur FF
129       // NYI pour toute arete de F qui accede V , une EVI
130 //      EVI = new TopOpeBRepDS_EdgeVertexInterference(Transition ?? <-> TFF,
131 //                                                  TopOpeBRepDS_EDGE,E de F,
132 //                                                  TopOpeBRepDS_VERTEX,Vindex,
133 //                                                  param de V sur E de F);
134 //      StoreInterference(EVI,EIL1,BDS);
135
136       // sur EE
137       EPI = new TopOpeBRepDS_CurvePointInterference(TEE,
138                                                     TopOpeBRepDS_FACE,FFindex,
139                                                     TopOpeBRepDS_VERTEX,Vindex,
140                                                     parE);
141       StoreInterference(EPI,EIL2,BDS);
142     }
143
144     else if ( isvertexE ) {
145       Standard_Integer Vindex = BDS.AddShape(V2,2);
146
147       // sur FF
148       // NYI : FaceVertexInterference : on ajoute un vertex INTERNAL a F
149 //      FVI = new TopOpeBRepDS_FaceVertexInterference(TopAbs_INTERNAL,
150 //                                             TopOpeBRepDS_FACE,FFindex,
151 //                                             TopOpeBRepDS_VERTEX,Vindex,
152 //                                             pUV);
153 //      StoreInterference(FPI,EIL1,BDS);
154       
155       // sur EE
156       EPI = new TopOpeBRepDS_CurvePointInterference(TEE,
157                                                     TopOpeBRepDS_FACE,FFindex,
158                                                     TopOpeBRepDS_VERTEX,Vindex,
159                                                     parE);
160       StoreInterference(EPI,EIL2,BDS);
161     }
162   }
163 }
164
165
166
167 // ===============
168 // private methods
169 // ===============
170
171 //-----------------------------------------------------------------------
172 // Search, among a list of interferences accessed by the iterator <IT>,
173 // a geometry whose 3D point is identical yo the 3D point of a DS point <DSP>.
174 // TheDSPointGeomTool is a tool able to access the 3D point of the DS point 
175 // DSP,and to test identity (according to tolerance connected to DSP) of the
176 // DS points.
177 // return True if such an interference has been found, False else.
178 // if True, iterator <IT> points (by the Value() method) on the first 
179 // interference accessing an identical 3D point.
180 //-----------------------------------------------------------------------
181 //=======================================================================
182 //function : ScanInterfList
183 //purpose  : private
184 //=======================================================================
185
186 Standard_Boolean TopOpeBRep_FaceEdgeFiller::ScanInterfList
187    (TopOpeBRepDS_ListIteratorOfListOfInterference& IT,
188     const TopOpeBRepDS_Point& DSP,
189     const TopOpeBRepDS_DataStructure& BDS) const
190 {
191   for ( ; IT.More(); IT.Next() ) {
192     Standard_Integer DSPG = IT.Value()->Geometry();
193     const TopOpeBRepDS_Point& otherDSP = BDS.Point(DSPG);
194     if (TopOpeBRep_PointGeomTool::IsEqual(DSP,otherDSP)) return Standard_True;
195   }
196   return Standard_False;
197 }
198
199
200 //=======================================================================
201 //function : GetGeometry
202 //purpose  : private
203 //=======================================================================
204
205 Standard_Boolean TopOpeBRep_FaceEdgeFiller::GetGeometry
206     (TopOpeBRepDS_ListIteratorOfListOfInterference& IT,
207      const TopOpeBRep_FaceEdgeIntersector& FEINT,
208      Standard_Integer& G,
209      const TopOpeBRepDS_DataStructure& BDS) const
210 {
211   TopOpeBRepDS_Point DSP = TopOpeBRep_PointGeomTool::MakePoint(FEINT);
212   Standard_Boolean found = ScanInterfList(IT,DSP,BDS);
213   if (found) G = IT.Value()->Geometry();
214   return found;
215 }
216
217
218 //=======================================================================
219 //function : GetGeometry
220 //purpose  : private
221 //=======================================================================
222
223 Standard_Boolean TopOpeBRep_FaceEdgeFiller::GetGeometry
224     (const TopOpeBRepDS_ListOfInterference& L,
225      const TopOpeBRepDS_Point& DSP,
226      Standard_Integer& G,
227      TopOpeBRepDS_DataStructure& BDS) const
228 {
229   TopOpeBRepDS_ListIteratorOfListOfInterference itI(L);
230   Standard_Boolean Ifound = ScanInterfList(itI,DSP,BDS);
231   if (Ifound) G = itI.Value()->Geometry();
232   else        G = BDS.AddPoint(DSP);
233   return Ifound;   // interference found or not
234 }
235
236
237 //-----------------------------------------------------------------------
238 // StoreInterference : Append an interference I to a list of interference LI
239 //                   : Append I to the interf. list connected to I Geometry()
240 //-----------------------------------------------------------------------
241 //=======================================================================
242 //function : StoreInterference
243 //purpose  : private
244 //=======================================================================
245
246 void TopOpeBRep_FaceEdgeFiller::StoreInterference
247 (const Handle(TopOpeBRepDS_Interference)& I,
248  TopOpeBRepDS_ListOfInterference& LI,
249  TopOpeBRepDS_DataStructure& BDS) const
250 {
251   // append I to list LI
252   LI.Append(I);
253
254   Standard_Integer G = I->Geometry();
255
256   // append I to list of interference connected to G = I->Geometry()
257   switch (I->GeometryType()) {
258
259   case TopOpeBRepDS_SOLID : case TopOpeBRepDS_FACE : 
260   case TopOpeBRepDS_EDGE : case TopOpeBRepDS_VERTEX :
261 //    appendtoG = Standard_True;
262 //    BDS.ChangeShapeInterferences(G).Append(I);
263     break;
264     
265   case TopOpeBRepDS_SURFACE :
266     BDS.ChangeSurfaceInterferences(G).Append(I);
267     break;
268     
269   case TopOpeBRepDS_CURVE :
270     BDS.ChangeCurveInterferences(G).Append(I);
271     break;
272     
273   case TopOpeBRepDS_POINT :
274 //    appendtoG = Standard_True;
275 //    BDS.ChangePointInterferences(G).Append(I);
276     break;
277   default:
278     break;
279   }
280 }
281
282 //=======================================================================
283 //function : MakeGeometry
284 //purpose  : 
285 //=======================================================================
286
287 Standard_Integer TopOpeBRep_FaceEdgeFiller::MakeGeometry
288     (TopOpeBRep_FaceEdgeIntersector& FEINT,
289      TopOpeBRepDS_DataStructure& BDS) const
290 {
291   Standard_Integer G=0;
292
293   TopoDS_Vertex V1;
294   Standard_Boolean isvertexF = FEINT.IsVertex(1,V1);
295   TopoDS_Vertex V2;
296   Standard_Boolean isvertexE = FEINT.IsVertex(2,V2);
297   Standard_Boolean isvertex = isvertexF || isvertexE;
298
299   if ( isvertex ) {
300     if      ( isvertexF ) G = BDS.AddShape(V1,1);
301     else if ( isvertexE ) G = BDS.AddShape(V2,2);
302   }
303   else 
304     G = BDS.AddPoint(TopOpeBRep_PointGeomTool::MakePoint(FEINT));
305   return G;
306 }