1 // File: GEOMAlgo_GlueDetector.cxx
2 // Created: Wed Dec 15 11:08:09 2004
3 // Author: Peter KURNEV
7 #include <GEOMAlgo_GlueAnalyser.ixx>
10 #include <TopoDS_Shape.hxx>
11 #include <TopoDS_Face.hxx>
12 #include <TopoDS_Edge.hxx>
13 #include <TopoDS_Compound.hxx>
15 #include <BRep_Builder.hxx>
19 #include <TopTools_IndexedMapOfShape.hxx>
20 #include <TopTools_ListOfShape.hxx>
21 #include <TopTools_ListIteratorOfListOfShape.hxx>
22 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
23 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
25 #include <GEOMAlgo_PassKey.hxx>
26 #include <GEOMAlgo_IndexedDataMapOfPassKeyListOfShape.hxx>
27 #include <GEOMAlgo_Tools.hxx>
28 #include <GEOMAlgo_CoupleOfShapes.hxx>
30 #include <GEOMAlgo_Gluer.hxx>
31 #include <Bnd_HArray1OfBox.hxx>
32 #include <Bnd_BoundSortBox.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
35 #include <GEOMAlgo_IndexedDataMapOfShapeBox.hxx>
36 #include <Bnd_Box.hxx>
37 #include <TColStd_ListOfInteger.hxx>
38 #include <TopTools_MapOfShape.hxx>
39 #include <TColStd_ListIteratorOfListOfInteger.hxx>
40 #include <BRepBndLib.hxx>
42 //=======================================================================
45 //=======================================================================
46 GEOMAlgo_GlueAnalyser::GEOMAlgo_GlueAnalyser()
50 //=======================================================================
53 //=======================================================================
54 GEOMAlgo_GlueAnalyser::~GEOMAlgo_GlueAnalyser()
56 //=======================================================================
57 //function : HasSolidsToGlue
59 //=======================================================================
60 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsToGlue()const
62 return !mySolidsToGlue.IsEmpty();
64 //=======================================================================
65 //function : HasSolidsAlone
67 //=======================================================================
68 Standard_Boolean GEOMAlgo_GlueAnalyser::HasSolidsAlone()const
70 return !mySolidsAlone.IsEmpty();
72 //=======================================================================
73 //function : SolidsToGlue
75 //=======================================================================
76 const GEOMAlgo_ListOfCoupleOfShapes& GEOMAlgo_GlueAnalyser::SolidsToGlue()const
78 return mySolidsToGlue;
80 //=======================================================================
81 //function : SolidsAlone
83 //=======================================================================
84 const TopTools_ListOfShape& GEOMAlgo_GlueAnalyser::SolidsAlone()const
88 //=======================================================================
91 //=======================================================================
92 void GEOMAlgo_GlueAnalyser::Perform()
97 mySolidsToGlue.Clear();
98 mySolidsAlone.Clear();
130 //=======================================================================
131 //function : DetectVertices
133 //=======================================================================
134 void GEOMAlgo_GlueAnalyser::DetectVertices()
138 Standard_Integer j, i, aNbV, aIndex, aNbVSD;
139 TColStd_ListIteratorOfListOfInteger aIt;
140 Handle(Bnd_HArray1OfBox) aHAB;
141 Bnd_BoundSortBox aBSB;
142 TopoDS_Shape aSTmp, aVF;
144 TopTools_IndexedMapOfShape aMV, aMVProcessed;
145 TopTools_ListIteratorOfListOfShape aItS;
146 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
147 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
148 GEOMAlgo_IndexedDataMapOfShapeBox aMSB;
150 TopExp::MapShapes(myShape, TopAbs_VERTEX, aMV);
153 myErrorStatus=2; // no vertices in source shape
157 aHAB=new Bnd_HArray1OfBox(1, aNbV);
159 for (i=1; i<=aNbV; ++i) {
160 const TopoDS_Shape& aV=aMV(i);
164 BRepBndLib::Add(aV, aBox);
165 aHAB->SetValue(i, aBox);
170 aBSB.Initialize(aHAB);
172 for (i=1; i<=aNbV; ++i) {
173 const TopoDS_Shape& aV=aMV(i);
175 if (aMVProcessed.Contains(aV)) {
179 const Bnd_Box& aBoxV=aMSB.FindFromKey(aV);
180 const TColStd_ListOfInteger& aLI=aBSB.Compare(aBoxV);
183 myErrorStatus=3; // it must not be
188 TopTools_ListOfShape aLVSD;
191 for (j=0; aIt.More(); aIt.Next(), ++j) {
193 const TopoDS_Shape& aVx=aMIS.FindFromKey(aIndex);
198 aMVProcessed.Add(aVx);
200 myImages.Bind(aVF, aLVSD);
203 aItIm.Initialize(myImages);
204 for (; aItIm.More(); aItIm.Next()) {
205 const TopoDS_Shape& aV=aItIm.Key();
206 const TopTools_ListOfShape& aLVSD=aItIm.Value();
208 aItS.Initialize(aLVSD);
209 for (; aItS.More(); aItS.Next()) {
210 const TopoDS_Shape& aVSD=aItS.Value();
211 if (!myOrigins.IsBound(aVSD)) {
212 myOrigins.Bind(aVSD, aV);
217 //=======================================================================
218 //function : DetectFaces
220 //=======================================================================
221 void GEOMAlgo_GlueAnalyser::DetectFaces()
223 DetectShapes(TopAbs_FACE);
225 //=======================================================================
226 //function : DetectEdges
228 //=======================================================================
229 void GEOMAlgo_GlueAnalyser::DetectEdges()
231 DetectShapes(TopAbs_EDGE);
233 //=======================================================================
234 //function : DetectShapes
236 //=======================================================================
237 void GEOMAlgo_GlueAnalyser::DetectShapes(const TopAbs_ShapeEnum aType)
241 Standard_Integer i, aNbF, aNbSDF, iErr;
242 TopoDS_Shape aNewShape;
243 TopTools_IndexedMapOfShape aMF;
244 TopTools_ListIteratorOfListOfShape aItS;
245 GEOMAlgo_PassKey aPKF;
246 GEOMAlgo_IndexedDataMapOfPassKeyListOfShape aMPKLF;
248 TopExp::MapShapes(myShape, aType, aMF);
251 for (i=1; i<=aNbF; ++i) {
252 const TopoDS_Shape& aS=aMF(i);
255 if (aType==TopAbs_FACE) {
256 const TopoDS_Face& aF=TopoDS::Face(aS);
257 FacePassKey(aF, aPKF);
259 else if (aType==TopAbs_EDGE) {
260 const TopoDS_Edge& aE=TopoDS::Edge(aS);
261 EdgePassKey(aE, aPKF);
268 if (aMPKLF.Contains(aPKF)) {
269 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
273 TopTools_ListOfShape aLSDF;
276 aMPKLF.Add(aPKF, aLSDF);
279 // check geometric coincidence
280 if (myCheckGeometry) {
281 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTol, myContext); //XX
289 aNbF=aMPKLF.Extent();
290 for (i=1; i<=aNbF; ++i) {
291 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
292 aNbSDF=aLSDF.Extent();
294 myErrorStatus=4; // it must not be
297 const TopoDS_Shape& aS1=aLSDF.First();
300 myImages.Bind(aNewShape, aLSDF);
302 aItS.Initialize(aLSDF);
303 for (; aItS.More(); aItS.Next()) {
304 const TopoDS_Shape& aFSD=aItS.Value();
305 if (!myOrigins.IsBound(aFSD)) {
306 myOrigins.Bind(aFSD, aNewShape);
311 //=======================================================================
312 //function : DetectSolids
314 //=======================================================================
315 void GEOMAlgo_GlueAnalyser::DetectSolids()
319 Standard_Integer i, aNbF, aNbS, aNbC, aNbX;
320 TopoDS_Compound aCmp;
322 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
323 TopTools_IndexedMapOfShape aMx, aMS;
324 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
325 GEOMAlgo_IndexedDataMapOfPassKeyListOfShape aMPKLS;
326 GEOMAlgo_PassKey aPKSx;
327 GEOMAlgo_CoupleOfShapes aCS;
329 aBB.MakeCompound(aCmp);
331 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
333 aItIm.Initialize(myImages);
334 for (; aItIm.More(); aItIm.Next()) {
335 const TopoDS_Shape& aIm=aItIm.Key();
336 if (aIm.ShapeType()!=TopAbs_FACE) {
340 const TopTools_ListOfShape& aLF=aItIm.Value();
346 TopoDS_Shape aSx[2], aFx[2];
350 for (i=0; i<2; ++i) {
351 if (!aMFS.Contains(aFx[i])) {
352 continue;// it must not be so
355 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aFx[i]);
363 if (aSx[0].IsNull() || aSx[1].IsNull()) {
368 aPKSx.SetIds(aSx[0], aSx[1]);
370 if (!aMPKLS.Contains(aPKSx)) {
371 TopTools_ListOfShape aLSx;
376 aMPKLS.Add(aPKSx, aLSx);
380 mySolidsToGlue.Clear();
381 mySolidsAlone.Clear();
384 aNbC=aMPKLS.Extent();
389 for (i=1; i<=aNbC; ++i) {
390 const TopTools_ListOfShape& aLSx=aMPKLS(i);
391 const TopoDS_Shape& aSx1=aLSx.First();
392 const TopoDS_Shape& aSx2=aLSx.Last();
395 mySolidsToGlue.Append(aCS);
397 if (!aMx.Contains(aSx1)) {
401 if (!aMx.Contains(aSx2)) {
408 // check alone solids
409 TopExp::MapShapes(myShape, TopAbs_SOLID, aMS);
412 for (i=1; i<=aNbX; ++i) {
413 const TopoDS_Shape& aSx=aMx(i);
414 if (!aMS.Contains(aSx)) {
415 mySolidsAlone.Append(aSx);
424 aItIm.Initialize(myImages);
425 for (; aItIm.More(); aItIm.Next()) {
426 const TopoDS_Shape& aV=aItIm.Key();
428 const TopTools_ListOfShape& aLVSD=aItIm.Value();
429 MakeVertex(aLVSD, aVnew);//ZZ
430 myImages.Bind(aVnew, aLVSD);
434 for (i=1; i<=aNbV; ++i) {
435 const TopoDS_Shape& aV=aMV(i);