1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: GEOMAlgo_GlueDetector.cxx
21 // Created: Wed Dec 15 11:08:09 2004
22 // Author: Peter KURNEV
26 #include <GEOMAlgo_GlueAnalyser.ixx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <TopoDS_Compound.hxx>
34 #include <BRep_Builder.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
44 #include <GEOMAlgo_PassKeyShape.hxx>
45 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
46 #include <GEOMAlgo_Tools.hxx>
47 #include <GEOMAlgo_CoupleOfShapes.hxx>
49 #include <GEOMAlgo_Gluer.hxx>
50 #include <Bnd_HArray1OfBox.hxx>
51 #include <Bnd_BoundSortBox.hxx>
52 #include <TopoDS_Vertex.hxx>
53 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
54 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
55 #include <Bnd_Box.hxx>
56 #include <TColStd_ListOfInteger.hxx>
57 #include <TopTools_MapOfShape.hxx>
58 #include <TColStd_ListIteratorOfListOfInteger.hxx>
59 #include <BRepBndLib.hxx>
61 //=======================================================================
64 //=======================================================================
65 GEOMAlgo_GlueAnalyser::GEOMAlgo_GlueAnalyser()
69 //=======================================================================
72 //=======================================================================
73 GEOMAlgo_GlueAnalyser::~GEOMAlgo_GlueAnalyser()
75 //=======================================================================
76 //function : HasSolidsToGlue
78 //=======================================================================
79 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsToGlue()const
81 return !mySolidsToGlue.IsEmpty();
83 //=======================================================================
84 //function : HasSolidsAlone
86 //=======================================================================
87 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsAlone()const
89 return !mySolidsAlone.IsEmpty();
91 //=======================================================================
92 //function : SolidsToGlue
94 //=======================================================================
95 const GEOMAlgo_ListOfCoupleOfShapes& GEOMAlgo_GlueAnalyser::SolidsToGlue()const
97 return mySolidsToGlue;
99 //=======================================================================
100 //function : SolidsAlone
102 //=======================================================================
103 const TopTools_ListOfShape& GEOMAlgo_GlueAnalyser::SolidsAlone()const
105 return mySolidsAlone;
107 //=======================================================================
110 //=======================================================================
111 void GEOMAlgo_GlueAnalyser::Perform()
116 mySolidsToGlue.Clear();
117 mySolidsAlone.Clear();
149 //=======================================================================
150 //function : DetectVertices
152 //=======================================================================
153 void GEOMAlgo_GlueAnalyser::DetectVertices()
157 Standard_Integer j, i, aNbV, aIndex, aNbVSD;
158 TColStd_ListIteratorOfListOfInteger aIt;
159 Handle(Bnd_HArray1OfBox) aHAB;
160 Bnd_BoundSortBox aBSB;
161 TopoDS_Shape aSTmp, aVF;
163 TopTools_IndexedMapOfShape aMV, aMVProcessed;
164 TopTools_ListIteratorOfListOfShape aItS;
165 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
166 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
167 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
169 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
172 myErrorStatus=2; // no vertices in source shape
176 aHAB=new Bnd_HArray1OfBox(1, aNbV);
178 for (i=1; i<=aNbV; ++i) {
179 const TopoDS_Shape& aV=aMV(i);
183 BRepBndLib::Add(aV, aBox);
184 aHAB->SetValue(i, aBox);
189 aBSB.Initialize(aHAB);
191 for (i=1; i<=aNbV; ++i) {
192 const TopoDS_Shape& aV=aMV(i);
194 if (aMVProcessed.Contains(aV)) {
198 const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
199 const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
202 myErrorStatus=3; // it must not be
207 TopTools_ListOfShape aLVSD;
210 for (j=0; aIt.More(); aIt.Next(), ++j) {
212 const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
217 aMVProcessed.Add(aVx);
219 myImages.Bind(aVF, aLVSD);
222 aItIm.Initialize(myImages);
223 for (; aItIm.More(); aItIm.Next()) {
224 const TopoDS_Shape& aV=aItIm.Key();
225 const TopTools_ListOfShape& aLVSD=aItIm.Value();
227 aItS.Initialize(aLVSD);
228 for (; aItS.More(); aItS.Next()) {
229 const TopoDS_Shape& aVSD=aItS.Value();
230 if (!myOrigins.IsBound(aVSD)) {
231 myOrigins.Bind(aVSD, aV);
236 //=======================================================================
237 //function : DetectFaces
239 //=======================================================================
240 void GEOMAlgo_GlueAnalyser::DetectFaces()
242 DetectShapes(TopAbs_FACE);
244 //=======================================================================
245 //function : DetectEdges
247 //=======================================================================
248 void GEOMAlgo_GlueAnalyser::DetectEdges()
250 DetectShapes(TopAbs_EDGE);
252 //=======================================================================
253 //function : DetectShapes
255 //=======================================================================
256 void GEOMAlgo_GlueAnalyser::DetectShapes(const TopAbs_ShapeEnum aType)
260 Standard_Integer i, aNbF, aNbSDF, iErr;
261 TopoDS_Shape aNewShape;
262 TopTools_IndexedMapOfShape aMF;
263 TopTools_ListIteratorOfListOfShape aItS;
264 GEOMAlgo_PassKeyShape aPKF;
265 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
267 TopExp::MapShapes(myShape, aType, aMF);
270 for (i=1; i<=aNbF; ++i) {
271 const TopoDS_Shape& aS=aMF(i);
274 if (aType==TopAbs_FACE) {
275 const TopoDS_Face& aF=TopoDS::Face(aS);
276 FacePassKey(aF, aPKF);
278 else if (aType==TopAbs_EDGE) {
279 const TopoDS_Edge& aE=TopoDS::Edge(aS);
280 EdgePassKey(aE, aPKF);
287 if (aMPKLF.Contains(aPKF)) {
288 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
292 TopTools_ListOfShape aLSDF;
295 aMPKLF.Add(aPKF, aLSDF);
298 // check geometric coincidence
299 if (myCheckGeometry) {
300 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext); //XX
308 aNbF=aMPKLF.Extent();
309 for (i=1; i<=aNbF; ++i) {
310 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
311 aNbSDF=aLSDF.Extent();
313 myErrorStatus=4; // it must not be
316 const TopoDS_Shape& aS1=aLSDF.First();
319 myImages.Bind(aNewShape, aLSDF);
321 aItS.Initialize(aLSDF);
322 for (; aItS.More(); aItS.Next()) {
323 const TopoDS_Shape& aFSD=aItS.Value();
324 if (!myOrigins.IsBound(aFSD)) {
325 myOrigins.Bind(aFSD, aNewShape);
330 //=======================================================================
331 //function : DetectSolids
333 //=======================================================================
334 void GEOMAlgo_GlueAnalyser::DetectSolids()
338 Standard_Integer i, aNbF, aNbS, aNbC, aNbX;
339 TopoDS_Compound aCmp;
341 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
342 TopTools_IndexedMapOfShape aMx, aMS;
343 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
344 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLS;
345 GEOMAlgo_PassKeyShape aPKSx;
346 GEOMAlgo_CoupleOfShapes aCS;
348 aBB.MakeCompound(aCmp);
350 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
352 aItIm.Initialize(myImages);
353 for (; aItIm.More(); aItIm.Next()) {
354 const TopoDS_Shape& aIm=aItIm.Key();
355 if (aIm.ShapeType()!=TopAbs_FACE) {
359 const TopTools_ListOfShape& aLF=aItIm.Value();
365 TopoDS_Shape aSx[2], aFx[2];
369 for (i=0; i<2; ++i) {
370 if (!aMFS.Contains(aFx[i])) {
371 continue;// it must not be so
374 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aFx[i]);
382 if (aSx[0].IsNull() || aSx[1].IsNull()) {
387 aPKSx.SetIds(aSx[0], aSx[1]);
389 if (!aMPKLS.Contains(aPKSx)) {
390 TopTools_ListOfShape aLSx;
395 aMPKLS.Add(aPKSx, aLSx);
399 mySolidsToGlue.Clear();
400 mySolidsAlone.Clear();
403 aNbC=aMPKLS.Extent();
408 for (i=1; i<=aNbC; ++i) {
409 const TopTools_ListOfShape& aLSx=aMPKLS(i);
410 const TopoDS_Shape& aSx1=aLSx.First();
411 const TopoDS_Shape& aSx2=aLSx.Last();
414 mySolidsToGlue.Append(aCS);
416 if (!aMx.Contains(aSx1)) {
420 if (!aMx.Contains(aSx2)) {
427 // check alone solids
428 TopExp::MapShapes(myShape, TopAbs_SOLID, aMS);
431 for (i=1; i<=aNbX; ++i) {
432 const TopoDS_Shape& aSx=aMx(i);
433 if (!aMS.Contains(aSx)) {
434 mySolidsAlone.Append(aSx);
443 aItIm.Initialize(myImages);
444 for (; aItIm.More(); aItIm.Next()) {
445 const TopoDS_Shape& aV=aItIm.Key();
447 const TopTools_ListOfShape& aLVSD=aItIm.Value();
448 MakeVertex(aLVSD, aVnew);//ZZ
449 myImages.Bind(aVnew, aLVSD);
453 for (i=1; i<=aNbV; ++i) {
454 const TopoDS_Shape& aV=aMV(i);