1780f1f186a58222b306c734ebefd46b5796ddf3
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_1.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 //                         EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 //
7 // This file is part of Open CASCADE Technology software library.
8 //
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
14 //
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
17
18
19 #include <Bnd_Box.hxx>
20 #include <BOPAlgo_PaveFiller.hxx>
21 #include <BOPAlgo_SectionAttribute.hxx>
22 #include <BOPAlgo_Tools.hxx>
23 #include <BOPCol_DataMapOfIntegerInteger.hxx>
24 #include <BOPCol_DataMapOfIntegerListOfInteger.hxx>
25 #include <BOPCol_ListOfShape.hxx>
26 #include <BOPCol_MapOfInteger.hxx>
27 #include <BOPDS_Curve.hxx>
28 #include <BOPDS_DS.hxx>
29 #include <BOPDS_Iterator.hxx>
30 #include <BOPDS_PaveBlock.hxx>
31 #include <BOPDS_ShapeInfo.hxx>
32 #include <BOPDS_VectorOfInterfVV.hxx>
33 #include <BOPTools_AlgoTools.hxx>
34 #include <BRepBndLib.hxx>
35 #include <BRep_TVertex.hxx>
36 #include <BRep_Tool.hxx>
37 #include <gp_Pnt.hxx>
38 #include <IntTools_Context.hxx>
39 #include <NCollection_BaseAllocator.hxx>
40 #include <Precision.hxx>
41 #include <TopoDS.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Vertex.hxx>
44
45 //=======================================================================
46 // function: PerformVV
47 // purpose: 
48 //=======================================================================
49 void BOPAlgo_PaveFiller::PerformVV() 
50 {
51   Standard_Boolean bWithSubShape;
52   Standard_Integer n1, n2, iFlag, aSize, k, aNbBlocks;
53   Handle(NCollection_BaseAllocator) aAllocator;
54   //
55   myErrorStatus=0;
56   //
57   myIterator->Initialize(TopAbs_VERTEX, TopAbs_VERTEX);
58   aSize=myIterator->ExpectedLength();
59   if (!aSize) {
60     return; 
61   }
62   //
63   BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
64   aVVs.SetIncrement(aSize);
65   //
66   //-----------------------------------------------------scope f
67   aAllocator=
68     NCollection_BaseAllocator::CommonBaseAllocator();
69   BOPCol_IndexedDataMapOfIntegerListOfInteger aMILI(100, aAllocator);
70   BOPCol_DataMapOfIntegerListOfInteger aMBlocks(100, aAllocator);
71   //
72   // 1. Map V/LV
73   for (; myIterator->More(); myIterator->Next()) {
74     myIterator->Value(n1, n2, bWithSubShape);
75     //
76     const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(n1))); 
77     const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(n2))); 
78     //
79     iFlag=BOPTools_AlgoTools::ComputeVV(aV1, aV2);
80     if (!iFlag) {
81       BOPAlgo_Tools::FillMap(n1, n2, aMILI, aAllocator);
82     }
83   } 
84   //
85   // 2. Make blocks
86   BOPAlgo_Tools::MakeBlocksCnx(aMILI, aMBlocks, aAllocator);
87   //
88   // 3. Make vertices
89   aNbBlocks=aMBlocks.Extent();
90   for (k=0; k<aNbBlocks; ++k) {
91     const BOPCol_ListOfInteger& aLI=aMBlocks.Find(k);
92     //
93     MakeSDVertices(aLI);
94   }
95   //
96   BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aItDMII;
97   //
98   BOPCol_DataMapOfIntegerInteger& aDMII=myDS->ShapesSD();
99   aItDMII.Initialize(aDMII);
100   for (; aItDMII.More(); aItDMII.Next()) {
101     n1=aItDMII.Key();
102     myDS->InitPaveBlocksForVertex(n1);
103   }
104   //
105   //-----------------------------------------------------scope t
106   aMBlocks.Clear();
107   aMILI.Clear();
108 }
109
110 //=======================================================================
111 // function: PerformVV
112 // purpose: 
113 //=======================================================================
114 void BOPAlgo_PaveFiller::MakeSDVertices(const BOPCol_ListOfInteger& theVertIndices)
115 {
116   TopoDS_Vertex aVSD, aVn;
117   BOPCol_ListIteratorOfListOfInteger aItLI(theVertIndices);
118   BOPCol_ListOfShape aLV;
119   for (; aItLI.More(); aItLI.Next()) {
120     Standard_Integer nX = aItLI.Value();
121     Standard_Integer nSD;
122     if (myDS->HasShapeSD(nX, nSD)) {
123       aVSD = TopoDS::Vertex(myDS->Shape(nSD));
124     }
125     const TopoDS_Shape& aV = myDS->Shape(nX);
126     aLV.Append(aV);
127   }
128   BOPTools_AlgoTools::MakeVertex(aLV, aVn);
129   if (!aVSD.IsNull()) {
130     // update old SD vertex with new value
131     Handle(BRep_TVertex)& aTVertex =
132       reinterpret_cast<Handle(BRep_TVertex)&>(const_cast<Handle(TopoDS_TShape)&>(aVSD.TShape()));
133     aTVertex->Pnt(BRep_Tool::Pnt(aVn));
134     aTVertex->Tolerance(BRep_Tool::Tolerance(aVn));
135   }
136   //
137   // Append new vertex to the DS
138   BOPDS_ShapeInfo aSIn;
139   aSIn.SetShapeType(TopAbs_VERTEX);
140   aSIn.SetShape(aVn);
141   Standard_Integer n = myDS->Append(aSIn);
142   //
143   BOPDS_ShapeInfo& aSIDS = myDS->ChangeShapeInfo(n);
144   Bnd_Box& aBox = aSIDS.ChangeBox();
145   BRepBndLib::Add(aVn, aBox);
146   aBox.SetGap(aBox.GetGap() + Precision::Confusion());
147   //
148   // Fill ShapesSD
149   BOPDS_VectorOfInterfVV& aVVs = myDS->InterfVV();
150   aVVs.SetIncrement(theVertIndices.Extent());
151   //
152   aItLI.Initialize(theVertIndices);
153   for (; aItLI.More(); aItLI.Next()) {
154     Standard_Integer n1 = aItLI.Value();
155     myDS->AddShapeSD(n1, n);
156     //
157     BOPCol_ListIteratorOfListOfInteger aItLI2 = aItLI;
158     aItLI2.Next();
159     for (; aItLI2.More(); aItLI2.Next()) {
160       Standard_Integer n2 = aItLI2.Value();
161       //
162       myDS->AddInterf(n1, n2);
163       BOPDS_InterfVV& aVV = aVVs.Append1();
164       //
165       aVV.SetIndices(n1, n2);
166       aVV.SetIndexNew(n);
167     }
168   }
169 }