1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: GEOMAlgo_GlueDetector.cxx
23 // Author: Peter KURNEV
25 #include <GEOMAlgo_GlueDetector.hxx>
27 #include <GEOMAlgo_IndexedDataMapOfIntegerShape.hxx>
28 #include <GEOMAlgo_PassKeyShape.hxx>
29 #include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
30 #include <GEOMAlgo_Tools.hxx>
32 #include <NMTDS_BndSphereTree.hxx>
33 #include <NMTDS_BndSphere.hxx>
34 #include <NMTDS_IndexedDataMapOfShapeBndSphere.hxx>
36 #include <Basics_OCCTVersion.hxx>
38 #include <NCollection_UBTreeFiller.hxx>
40 #include <TColStd_ListOfInteger.hxx>
41 #include <TColStd_ListIteratorOfListOfInteger.hxx>
42 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopoDS_Face.hxx>
46 #include <TopoDS_Edge.hxx>
47 #include <TopoDS_Compound.hxx>
48 #include <TopoDS_Vertex.hxx>
49 #include <TopoDS_Iterator.hxx>
50 #include <TopoDS_Compound.hxx>
52 #include <TopTools_IndexedMapOfShape.hxx>
53 #include <TopTools_ListOfShape.hxx>
54 #include <TopTools_ListIteratorOfListOfShape.hxx>
55 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
56 #include <TopTools_MapOfShape.hxx>
57 #include <TopTools_MapIteratorOfMapOfShape.hxx>
61 #include <BRep_Tool.hxx>
62 #include <BRep_Builder.hxx>
63 #include <BRepBndLib.hxx>
65 #include <Bnd_Box.hxx>
67 //=======================================================================
70 //=======================================================================
71 GEOMAlgo_GlueDetector::GEOMAlgo_GlueDetector()
72 : GEOMAlgo_GluerAlgo(),
75 //=======================================================================
78 //=======================================================================
79 GEOMAlgo_GlueDetector::~GEOMAlgo_GlueDetector()
81 //=======================================================================
84 //=======================================================================
85 void GEOMAlgo_GlueDetector::Perform()
95 #if OCC_VERSION_LARGE > 0x06050200
96 // Initialize the context
97 GEOMAlgo_GluerAlgo::Perform();
115 //=======================================================================
116 //function : DetectVertices
118 //=======================================================================
119 void GEOMAlgo_GlueDetector::DetectVertices()
121 Standard_Integer j, i, aNbV, aNbVSD;
124 TColStd_ListIteratorOfListOfInteger aIt;
126 TopTools_IndexedMapOfShape aMV;
127 TopTools_MapOfShape aMVProcessed;
128 TopTools_ListIteratorOfListOfShape aItS;
129 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItIm;
130 TopTools_DataMapOfShapeListOfShape aMVV;
131 GEOMAlgo_IndexedDataMapOfIntegerShape aMIS;
132 NMTDS_IndexedDataMapOfShapeBndSphere aMSB;
134 NMTDS_BndSphereTreeSelector aSelector;
135 NMTDS_BndSphereTree aBBTree;
136 NCollection_UBTreeFiller <Standard_Integer, NMTDS_BndSphere> aTreeFiller(aBBTree);
140 TopExp::MapShapes(myArgument, TopAbs_VERTEX, aMV);
143 myErrorStatus=2; // no vertices in source shape
147 for (i=1; i<=aNbV; ++i) {
148 NMTDS_BndSphere aBox;
150 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&aMV(i));
151 aPV=BRep_Tool::Pnt(aV);
152 aTolV=BRep_Tool::Tolerance(aV);
154 aBox.SetGap(myTolerance);
156 aBox.SetRadius(aTolV);
158 aTreeFiller.Add(i, aBox);
166 //---------------------------------------------------
168 for (i=1; i<=aNbV; ++i) {
169 const TopoDS_Shape& aV=aMV(i);
171 if (aMVProcessed.Contains(aV)) {
175 Standard_Integer aNbIP, aIP, aNbIP1, aIP1;
176 TopTools_ListOfShape aLVSD;
177 TColStd_MapOfInteger aMIP, aMIP1, aMIPC;
178 TColStd_MapIteratorOfMapOfInteger aIt1;
183 aIt1.Initialize(aMIP);
184 for(; aIt1.More(); aIt1.Next()) {
186 if (aMIPC.Contains(aIP)) {
190 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
191 const NMTDS_BndSphere& aBoxVP=aMSB.FindFromKey(aVP);
194 aSelector.SetBox(aBoxVP);
196 aNbVSD=aBBTree.Select(aSelector);
198 continue; // it shoild not be so [at least IP itself]
201 const TColStd_ListOfInteger& aLI=aSelector.Indices();
203 for (; aIt.More(); aIt.Next()) {
205 if (aMIP.Contains(aIP1)) {
209 } //for (; aIt.More(); aIt.Next()) {
210 }//for(; aIt1.More(); aIt1.Next()) {
212 aNbIP1=aMIP1.Extent();
217 aIt1.Initialize(aMIP);
218 for(; aIt1.More(); aIt1.Next()) {
224 aIt1.Initialize(aMIP1);
225 for(; aIt1.More(); aIt1.Next()) {
233 aNbIP=aMIPC.Extent();
235 if (!aNbIP) {// no SD vertices is found
236 aMVProcessed.Add(aV);
239 //else { // SD vertices founded [ aMIPC ]
240 aIt1.Initialize(aMIPC);
241 for(j=0; aIt1.More(); aIt1.Next(), ++j) {
243 const TopoDS_Shape& aVP=aMIS.FindFromKey(aIP);
248 aMVProcessed.Add(aVP);
251 myImages.Bind(aVF, aLVSD);
252 }// for (i=1; i<=aNbV; ++i) {
253 //------------------------------
255 aItIm.Initialize(myImages);
256 for (; aItIm.More(); aItIm.Next()) {
257 const TopoDS_Shape& aV=aItIm.Key();
258 const TopTools_ListOfShape& aLVSD=aItIm.Value();
259 aItS.Initialize(aLVSD);
260 for (; aItS.More(); aItS.Next()) {
261 const TopoDS_Shape& aVSD=aItS.Value();
262 if (!myOrigins.IsBound(aVSD)) {
263 myOrigins.Bind(aVSD, aV);
268 //=======================================================================
269 //function : DetectFaces
271 //=======================================================================
272 void GEOMAlgo_GlueDetector::DetectFaces()
274 DetectShapes(TopAbs_FACE);
276 //=======================================================================
277 //function : DetectEdges
279 //=======================================================================
280 void GEOMAlgo_GlueDetector::DetectEdges()
282 DetectShapes(TopAbs_EDGE);
284 //=======================================================================
285 //function : DetectShapes
287 //=======================================================================
288 void GEOMAlgo_GlueDetector::DetectShapes(const TopAbs_ShapeEnum aType)
290 Standard_Boolean bDegenerated;
291 Standard_Integer i, aNbF, aNbSDF, iErr;
292 TopTools_IndexedMapOfShape aMF;
293 TopTools_ListIteratorOfListOfShape aItLS;
294 GEOMAlgo_PassKeyShape aPKF;
295 GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape aMPKLF;
299 TopExp::MapShapes(myArgument, aType, aMF);
302 for (i=1; i<=aNbF; ++i) {
303 const TopoDS_Shape& aS=aMF(i);
305 if (aType==TopAbs_FACE) {
306 const TopoDS_Face& aF=*((TopoDS_Face*)&aS);
307 FacePassKey(aF, aPKF);
309 else if (aType==TopAbs_EDGE) {
310 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aS);
311 EdgePassKey(aE, aPKF);
318 if (aMPKLF.Contains(aPKF)) {
319 TopTools_ListOfShape& aLSDF=aMPKLF.ChangeFromKey(aPKF);
323 TopTools_ListOfShape aLSDF;
326 aMPKLF.Add(aPKF, aLSDF);
329 // check geometric coincidence
330 if (myCheckGeometry) {
331 iErr=GEOMAlgo_Tools::RefineSDShapes(aMPKLF, myTolerance, myContext);
339 aNbF=aMPKLF.Extent();
340 for (i=1; i<=aNbF; ++i) {
341 const TopTools_ListOfShape& aLSDF=aMPKLF(i);
342 aNbSDF=aLSDF.Extent();
344 myErrorStatus=4; // it must not be
351 const TopoDS_Shape& aS1=aLSDF.First();
353 if (aType==TopAbs_EDGE) {
354 const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aS1);
355 bDegenerated=BRep_Tool::Degenerated(aE1);
361 myImages.Bind(aS1, aLSDF);
363 aItLS.Initialize(aLSDF);
364 for (; aItLS.More(); aItLS.Next()) {
365 const TopoDS_Shape& aFSD=aItLS.Value();
366 if (!myOrigins.IsBound(aFSD)) {
367 myOrigins.Bind(aFSD, aS1);
370 }// for (i=1; i<=aNbF; ++i)
372 //=======================================================================
373 //function : FacePassKey
375 //=======================================================================
376 void GEOMAlgo_GlueDetector::FacePassKey(const TopoDS_Face& aF,
377 GEOMAlgo_PassKeyShape& aPK)
379 Standard_Integer i, aNbE;
381 TopTools_ListOfShape aLE;
382 TopTools_IndexedMapOfShape aME;
384 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
387 for (i=1; i<=aNbE; ++i) {
388 const TopoDS_Shape& aE=aME(i);
390 const TopoDS_Edge& aEE=*((TopoDS_Edge*)&aE);
391 if (BRep_Tool::Degenerated(aEE)) {
395 if (myOrigins.IsBound(aE)) {
396 aER=myOrigins.Find(aE);
405 //=======================================================================
406 //function : EdgePassKey
408 //=======================================================================
409 void GEOMAlgo_GlueDetector::EdgePassKey(const TopoDS_Edge& aE,
410 GEOMAlgo_PassKeyShape& aPK)
412 TopAbs_Orientation aOr;
415 TopTools_ListOfShape aLV;
418 for (; aIt.More(); aIt.Next()) {
419 const TopoDS_Shape& aV=aIt.Value();
420 aOr=aV.Orientation();
421 if (aOr==TopAbs_FORWARD || aOr==TopAbs_REVERSED) {
422 if (myOrigins.IsBound(aV)) {
423 aVR=myOrigins.Find(aV);