7fd59977 |
1 | // File: TopOpeBRepBuild_BlockBuilder.cxx |
2 | // Created: Thu Mar 11 12:56:30 1993 |
3 | // Author: Jean Yves LEBEY |
4 | // <jyl@sdsun2> |
5 | // Copyright: Matra Datavision |
6 | |
7 | #include <BOP_BlockBuilder.ixx> |
8 | |
9 | #include <Standard_Failure.hxx> |
10 | |
11 | //======================================================================= |
12 | //function : BOP_BlockBuilder::BOP_BlockBuilder |
13 | //purpose : |
14 | //======================================================================= |
15 | BOP_BlockBuilder::BOP_BlockBuilder() |
16 | : |
17 | myIsDone(Standard_False) |
18 | { |
19 | } |
20 | |
21 | //======================================================================= |
22 | //function : BOP_BlockBuilder::BOP_BlockBuilder |
23 | //purpose : |
24 | //======================================================================= |
25 | BOP_BlockBuilder::BOP_BlockBuilder (BOP_ShapeSet& SS) |
26 | :myIsDone(Standard_False) |
27 | { |
28 | MakeBlock(SS); |
29 | } |
30 | |
31 | //======================================================================= |
32 | //function : MakeBlock |
33 | //purpose : |
34 | //======================================================================= |
35 | void BOP_BlockBuilder::MakeBlock(BOP_ShapeSet& SS) |
36 | { |
37 | // Compute the set of connexity blocks of elements of element set SS |
38 | // |
39 | // Logic : |
40 | // - A block is a set of connex elements of SS |
41 | // - We assume that any element of SS appears in only 1 connexity block. |
42 | // |
43 | // Implementation : |
44 | // - All the elements of all the blocks are stored in map myOrientedShapeMap(M). |
45 | // - A connexity block is a segment [f,l] of element indices of M. |
46 | // - myBlocks is a sequence of integer; each integer is the index of the |
47 | // first element (in M) of a connexity block. |
48 | // - Bounds [f,l] of a connexity block are : |
49 | // f = myBlocks(i) |
50 | // l = myBlocks(i+1) - 1 |
51 | |
52 | myOrientedShapeMap.Clear(); |
53 | myOrientedShapeMapIsValid.Clear(); |
54 | myBlocks.Clear(); |
55 | myBlocksIsRegular.Clear(); |
56 | // |
57 | Standard_Boolean IsRegular, CurNei, Mextent, Eindex, |
58 | EnewinM, searchneighbours, condregu; |
59 | Standard_Integer iiregu; |
60 | // |
61 | // |
62 | SS.InitStartElements(); |
63 | for (; SS.MoreStartElements(); SS.NextStartElement()) { |
64 | const TopoDS_Shape& E = SS.StartElement(); |
65 | Mextent = myOrientedShapeMap.Extent(); |
66 | Eindex = AddElement(E); |
67 | |
68 | // E = current element of the element set SS |
69 | // Mextent = index of last element stored in map M, before E is added. |
70 | // Eindex = index of E added to M : Eindex > Mextent => E is new in M |
71 | |
72 | EnewinM = (Eindex > Mextent); |
73 | if (EnewinM) { |
74 | // |
75 | // make a new block starting at element Eindex |
76 | myBlocks.Append(Eindex); |
77 | IsRegular = Standard_True; CurNei = 0; |
78 | // put in current block all the elements connex to E : |
79 | // while an element E has been added to M |
80 | // - compute neighbours of E : N(E) |
81 | // - add each element N of N(E) to M |
82 | |
83 | Mextent = myOrientedShapeMap.Extent(); |
84 | searchneighbours = (Eindex <= Mextent); |
85 | while (searchneighbours) { |
86 | |
87 | // E = element of M on which neighbours must be searched |
88 | // first step : Eindex = index of starting element of SS |
89 | // next steps : Eindex = index of neighbours of starting element of SS |
90 | const TopoDS_Shape& anE = myOrientedShapeMap(Eindex); |
91 | CurNei = SS.MaxNumberSubShape(anE); |
92 | |
93 | condregu = (CurNei > 2) ? Standard_False : Standard_True; |
94 | |
95 | IsRegular = IsRegular && condregu; |
96 | // |
97 | // compute neighbours of E : add them to M to increase M.Extent(). |
98 | SS.InitNeighbours(anE); |
99 | |
100 | for (; SS.MoreNeighbours(); SS.NextNeighbour()) { |
101 | const TopoDS_Shape& N = SS.Neighbour(); |
102 | AddElement(N); |
103 | } |
104 | |
105 | Eindex++; |
106 | Mextent = myOrientedShapeMap.Extent(); |
107 | searchneighbours = (Eindex <= Mextent); |
108 | |
109 | } // while (searchneighbours) |
110 | |
111 | iiregu = IsRegular ? 1 : 0; |
112 | myBlocksIsRegular.Append(iiregu); |
113 | } // if (EnewinM) |
114 | } // for () |
115 | // |
116 | // To value the l bound of the last connexity block created above, |
117 | // we create an artificial block of value = myOrientedShapeMap.Extent() + 1 |
118 | // The real number of connexity blocks is myBlocks.Length() - 1 |
119 | Mextent = myOrientedShapeMap.Extent(); |
120 | myBlocks.Append(Mextent + 1); |
121 | |
122 | myIsDone = Standard_True; |
123 | } |
124 | |
125 | //======================================================================= |
126 | //function : InitBlock |
127 | //purpose : |
128 | //======================================================================= |
129 | void BOP_BlockBuilder::InitBlock() |
130 | { |
131 | myBlockIndex = 1; |
132 | } |
133 | |
134 | //======================================================================= |
135 | //function : MoreBlock |
136 | //purpose : |
137 | //======================================================================= |
138 | Standard_Boolean BOP_BlockBuilder::MoreBlock() const |
139 | { |
140 | // the length of myBlocks is 1 + number of connexity blocks |
141 | Standard_Integer l = myBlocks.Length(); |
142 | Standard_Boolean b = (myBlockIndex < l); |
143 | return b; |
144 | } |
145 | |
146 | //======================================================================= |
147 | //function : NextBlock |
148 | //purpose : |
149 | //======================================================================= |
150 | void BOP_BlockBuilder::NextBlock() |
151 | { |
152 | myBlockIndex++; |
153 | } |
154 | |
155 | //======================================================================= |
156 | //function : BlockIterator |
157 | //purpose : |
158 | //======================================================================= |
159 | BOP_BlockIterator BOP_BlockBuilder::BlockIterator() const |
160 | { |
161 | Standard_Integer lower, upper; |
162 | |
163 | lower = myBlocks(myBlockIndex); |
164 | upper = myBlocks(myBlockIndex+1)-1; |
165 | |
166 | return BOP_BlockIterator(lower,upper); |
167 | } |
168 | |
169 | //======================================================================= |
170 | //function : Element |
171 | //purpose : |
172 | //======================================================================= |
173 | const TopoDS_Shape& BOP_BlockBuilder::Element (const BOP_BlockIterator& BI) const |
174 | { |
175 | Standard_Boolean isbound = BI.More(); |
176 | if (!isbound) { |
177 | Standard_Failure::Raise("OutOfRange"); |
178 | } |
179 | |
180 | Standard_Integer index = BI.Value(); |
181 | const TopoDS_Shape& E = myOrientedShapeMap(index); |
182 | return E; |
183 | } |
184 | //======================================================================= |
185 | //function : Element |
186 | //purpose : |
187 | //======================================================================= |
188 | const TopoDS_Shape& BOP_BlockBuilder::Element (const Standard_Integer index) const |
189 | { |
190 | Standard_Boolean isbound = myOrientedShapeMapIsValid.IsBound(index); |
191 | if (!isbound) { |
192 | Standard_Failure::Raise("OutOfRange"); |
193 | } |
194 | const TopoDS_Shape& E = myOrientedShapeMap(index); |
195 | return E; |
196 | } |
197 | //======================================================================= |
198 | //function : Element |
199 | //purpose : |
200 | //======================================================================= |
201 | Standard_Integer BOP_BlockBuilder::Element (const TopoDS_Shape& E) const |
202 | { |
203 | Standard_Boolean isbound = myOrientedShapeMap.Contains(E); |
204 | if (!isbound) { |
205 | Standard_Failure::Raise("OutOfRange"); |
206 | } |
207 | |
208 | Standard_Integer I = myOrientedShapeMap.FindIndex(E); |
209 | return I; |
210 | } |
211 | |
212 | //======================================================================= |
213 | //function : ElementIsValid |
214 | //purpose : |
215 | //======================================================================= |
216 | Standard_Boolean BOP_BlockBuilder::ElementIsValid (const BOP_BlockIterator& BI) const |
217 | { |
218 | Standard_Boolean isvalid, isbound = BI.More(); |
219 | if (!isbound) { |
220 | return Standard_False; |
221 | } |
222 | Standard_Integer Sindex, isb; |
223 | |
224 | Sindex = BI.Value(); |
225 | isb = myOrientedShapeMapIsValid.Find(Sindex); |
226 | isvalid = (isb == 1)? Standard_True: Standard_False; |
227 | |
228 | return isvalid; |
229 | } |
230 | //======================================================================= |
231 | //function : ElementIsValid |
232 | //purpose : |
233 | //======================================================================= |
234 | Standard_Boolean BOP_BlockBuilder::ElementIsValid (const Standard_Integer Sindex) const |
235 | { |
236 | Standard_Boolean isvalid, isbound = myOrientedShapeMapIsValid.IsBound(Sindex); |
237 | if (!isbound) return Standard_False; |
238 | |
239 | Standard_Integer isb = myOrientedShapeMapIsValid.Find(Sindex); |
240 | isvalid = (isb == 1)? Standard_True: Standard_False; |
241 | |
242 | return isvalid; |
243 | } |
244 | |
245 | //======================================================================= |
246 | //function : AddElement |
247 | //purpose : |
248 | //======================================================================= |
249 | Standard_Integer BOP_BlockBuilder::AddElement(const TopoDS_Shape& S) |
250 | { |
251 | Standard_Integer Sindex = myOrientedShapeMap.Add(S); |
252 | myOrientedShapeMapIsValid.Bind(Sindex, 1); |
253 | |
254 | return Sindex; |
255 | } |
256 | |
257 | //======================================================================= |
258 | //function : SetValid |
259 | //purpose : |
260 | //======================================================================= |
261 | void BOP_BlockBuilder::SetValid(const BOP_BlockIterator& BI, |
262 | const Standard_Boolean isvalid) |
263 | { |
264 | Standard_Boolean isbound = BI.More(); |
265 | if (!isbound) { |
266 | return; |
267 | } |
268 | Standard_Integer Sindex, i; |
269 | Sindex = BI.Value(); |
270 | i = (isvalid) ? 1 : 0; |
271 | myOrientedShapeMapIsValid.Bind(Sindex,i); |
272 | } |
273 | //======================================================================= |
274 | //function : SetValid |
275 | //purpose : |
276 | //======================================================================= |
277 | void BOP_BlockBuilder::SetValid(const Standard_Integer Sindex, |
278 | const Standard_Boolean isvalid) |
279 | { |
280 | Standard_Boolean isbound = myOrientedShapeMapIsValid.IsBound(Sindex); |
281 | if (!isbound) { |
282 | return; |
283 | } |
284 | |
285 | Standard_Integer i = (isvalid) ? 1 : 0; |
286 | myOrientedShapeMapIsValid.Bind(Sindex,i); |
287 | } |
288 | |
289 | //======================================================================= |
290 | //function : CurrentBlockIsRegular |
291 | //purpose : |
292 | //======================================================================= |
293 | Standard_Boolean BOP_BlockBuilder::CurrentBlockIsRegular() |
294 | { |
295 | Standard_Boolean b = Standard_False; |
296 | Standard_Integer i = myBlocksIsRegular.Value(myBlockIndex); |
297 | |
298 | if(i == 1) { |
299 | b = Standard_True; |
300 | } |
301 | return b; |
302 | } |
303 | |
304 | |