1 // Created on: 1993-03-11
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <BOP_BlockBuilder.ixx>
24 #include <Standard_Failure.hxx>
26 //=======================================================================
27 //function : BOP_BlockBuilder::BOP_BlockBuilder
29 //=======================================================================
30 BOP_BlockBuilder::BOP_BlockBuilder()
32 myIsDone(Standard_False)
36 //=======================================================================
37 //function : BOP_BlockBuilder::BOP_BlockBuilder
39 //=======================================================================
40 BOP_BlockBuilder::BOP_BlockBuilder (BOP_ShapeSet& SS)
41 :myIsDone(Standard_False)
46 //=======================================================================
47 //function : MakeBlock
49 //=======================================================================
50 void BOP_BlockBuilder::MakeBlock(BOP_ShapeSet& SS)
52 // Compute the set of connexity blocks of elements of element set SS
55 // - A block is a set of connex elements of SS
56 // - We assume that any element of SS appears in only 1 connexity block.
59 // - All the elements of all the blocks are stored in map myOrientedShapeMap(M).
60 // - A connexity block is a segment [f,l] of element indices of M.
61 // - myBlocks is a sequence of integer; each integer is the index of the
62 // first element (in M) of a connexity block.
63 // - Bounds [f,l] of a connexity block are :
65 // l = myBlocks(i+1) - 1
67 myOrientedShapeMap.Clear();
68 myOrientedShapeMapIsValid.Clear();
70 myBlocksIsRegular.Clear();
72 Standard_Boolean IsRegular, CurNei, Mextent, Eindex,
73 EnewinM, searchneighbours, condregu;
74 Standard_Integer iiregu;
77 SS.InitStartElements();
78 for (; SS.MoreStartElements(); SS.NextStartElement()) {
79 const TopoDS_Shape& E = SS.StartElement();
80 Mextent = myOrientedShapeMap.Extent();
81 Eindex = AddElement(E);
83 // E = current element of the element set SS
84 // Mextent = index of last element stored in map M, before E is added.
85 // Eindex = index of E added to M : Eindex > Mextent => E is new in M
87 EnewinM = (Eindex > Mextent);
90 // make a new block starting at element Eindex
91 myBlocks.Append(Eindex);
92 IsRegular = Standard_True; CurNei = 0;
93 // put in current block all the elements connex to E :
94 // while an element E has been added to M
95 // - compute neighbours of E : N(E)
96 // - add each element N of N(E) to M
98 Mextent = myOrientedShapeMap.Extent();
99 searchneighbours = (Eindex <= Mextent);
100 while (searchneighbours) {
102 // E = element of M on which neighbours must be searched
103 // first step : Eindex = index of starting element of SS
104 // next steps : Eindex = index of neighbours of starting element of SS
105 const TopoDS_Shape& anE = myOrientedShapeMap(Eindex);
106 CurNei = SS.MaxNumberSubShape(anE);
108 condregu = (CurNei > 2) ? Standard_False : Standard_True;
110 IsRegular = IsRegular && condregu;
112 // compute neighbours of E : add them to M to increase M.Extent().
113 SS.InitNeighbours(anE);
115 for (; SS.MoreNeighbours(); SS.NextNeighbour()) {
116 const TopoDS_Shape& N = SS.Neighbour();
121 Mextent = myOrientedShapeMap.Extent();
122 searchneighbours = (Eindex <= Mextent);
124 } // while (searchneighbours)
126 iiregu = IsRegular ? 1 : 0;
127 myBlocksIsRegular.Append(iiregu);
131 // To value the l bound of the last connexity block created above,
132 // we create an artificial block of value = myOrientedShapeMap.Extent() + 1
133 // The real number of connexity blocks is myBlocks.Length() - 1
134 Mextent = myOrientedShapeMap.Extent();
135 myBlocks.Append(Mextent + 1);
137 myIsDone = Standard_True;
140 //=======================================================================
141 //function : InitBlock
143 //=======================================================================
144 void BOP_BlockBuilder::InitBlock()
149 //=======================================================================
150 //function : MoreBlock
152 //=======================================================================
153 Standard_Boolean BOP_BlockBuilder::MoreBlock() const
155 // the length of myBlocks is 1 + number of connexity blocks
156 Standard_Integer l = myBlocks.Length();
157 Standard_Boolean b = (myBlockIndex < l);
161 //=======================================================================
162 //function : NextBlock
164 //=======================================================================
165 void BOP_BlockBuilder::NextBlock()
170 //=======================================================================
171 //function : BlockIterator
173 //=======================================================================
174 BOP_BlockIterator BOP_BlockBuilder::BlockIterator() const
176 Standard_Integer lower, upper;
178 lower = myBlocks(myBlockIndex);
179 upper = myBlocks(myBlockIndex+1)-1;
181 return BOP_BlockIterator(lower,upper);
184 //=======================================================================
187 //=======================================================================
188 const TopoDS_Shape& BOP_BlockBuilder::Element (const BOP_BlockIterator& BI) const
190 Standard_Boolean isbound = BI.More();
192 Standard_Failure::Raise("OutOfRange");
195 Standard_Integer index = BI.Value();
196 const TopoDS_Shape& E = myOrientedShapeMap(index);
199 //=======================================================================
202 //=======================================================================
203 const TopoDS_Shape& BOP_BlockBuilder::Element (const Standard_Integer index) const
205 Standard_Boolean isbound = myOrientedShapeMapIsValid.IsBound(index);
207 Standard_Failure::Raise("OutOfRange");
209 const TopoDS_Shape& E = myOrientedShapeMap(index);
212 //=======================================================================
215 //=======================================================================
216 Standard_Integer BOP_BlockBuilder::Element (const TopoDS_Shape& E) const
218 Standard_Boolean isbound = myOrientedShapeMap.Contains(E);
220 Standard_Failure::Raise("OutOfRange");
223 Standard_Integer I = myOrientedShapeMap.FindIndex(E);
227 //=======================================================================
228 //function : ElementIsValid
230 //=======================================================================
231 Standard_Boolean BOP_BlockBuilder::ElementIsValid (const BOP_BlockIterator& BI) const
233 Standard_Boolean isvalid, isbound = BI.More();
235 return Standard_False;
237 Standard_Integer Sindex, isb;
240 isb = myOrientedShapeMapIsValid.Find(Sindex);
241 isvalid = (isb == 1)? Standard_True: Standard_False;
245 //=======================================================================
246 //function : ElementIsValid
248 //=======================================================================
249 Standard_Boolean BOP_BlockBuilder::ElementIsValid (const Standard_Integer Sindex) const
251 Standard_Boolean isvalid, isbound = myOrientedShapeMapIsValid.IsBound(Sindex);
252 if (!isbound) return Standard_False;
254 Standard_Integer isb = myOrientedShapeMapIsValid.Find(Sindex);
255 isvalid = (isb == 1)? Standard_True: Standard_False;
260 //=======================================================================
261 //function : AddElement
263 //=======================================================================
264 Standard_Integer BOP_BlockBuilder::AddElement(const TopoDS_Shape& S)
266 Standard_Integer Sindex = myOrientedShapeMap.Add(S);
267 myOrientedShapeMapIsValid.Bind(Sindex, 1);
272 //=======================================================================
273 //function : SetValid
275 //=======================================================================
276 void BOP_BlockBuilder::SetValid(const BOP_BlockIterator& BI,
277 const Standard_Boolean isvalid)
279 Standard_Boolean isbound = BI.More();
283 Standard_Integer Sindex, i;
285 i = (isvalid) ? 1 : 0;
286 myOrientedShapeMapIsValid.Bind(Sindex,i);
288 //=======================================================================
289 //function : SetValid
291 //=======================================================================
292 void BOP_BlockBuilder::SetValid(const Standard_Integer Sindex,
293 const Standard_Boolean isvalid)
295 Standard_Boolean isbound = myOrientedShapeMapIsValid.IsBound(Sindex);
300 Standard_Integer i = (isvalid) ? 1 : 0;
301 myOrientedShapeMapIsValid.Bind(Sindex,i);
304 //=======================================================================
305 //function : CurrentBlockIsRegular
307 //=======================================================================
308 Standard_Boolean BOP_BlockBuilder::CurrentBlockIsRegular()
310 Standard_Boolean b = Standard_False;
311 Standard_Integer i = myBlocksIsRegular.Value(myBlockIndex);