1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkBridgeCellIterator.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkBridgeCellIterator - Implementation of vtkGenericCellIterator.
16 // It is just an example that show how to implement the Generic. It is also
17 // used for testing and evaluating the Generic.
18 // .SECTION See Also
19 // vtkGenericCellIterator, vtkBridgeDataSet
20 
21 #include "vtkBridgeCellIterator.h"
22 
23 #include <cassert>
24 
25 #include "vtkObjectFactory.h"
26 #include "vtkBridgeCell.h"
27 #include "vtkBridgeDataSet.h"
28 #include "vtkDataSet.h"
29 #include "vtkIdList.h"
30 
31 #include "vtkBridgeCellIteratorOnDataSet.h"
32 #include "vtkBridgeCellIteratorOne.h"
33 #include "vtkBridgeCellIteratorOnCellBoundaries.h"
34 #include "vtkBridgeCellIteratorOnCellList.h"
35 
36 vtkStandardNewMacro(vtkBridgeCellIterator);
37 
38 //-----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)39 void vtkBridgeCellIterator::PrintSelf(ostream& os, vtkIndent indent)
40 {
41   this->Superclass::PrintSelf(os,indent);
42 }
43 
44 //-----------------------------------------------------------------------------
vtkBridgeCellIterator()45 vtkBridgeCellIterator::vtkBridgeCellIterator()
46 {
47 //  this->DebugOn();
48   this->CurrentIterator=0;
49   this->IteratorOnDataSet=vtkBridgeCellIteratorOnDataSet::New();
50   this->IteratorOneCell=vtkBridgeCellIteratorOne::New();
51   this->IteratorOnCellBoundaries=vtkBridgeCellIteratorOnCellBoundaries::New();
52   this->IteratorOnCellList=vtkBridgeCellIteratorOnCellList::New();
53 }
54 
55 //-----------------------------------------------------------------------------
~vtkBridgeCellIterator()56 vtkBridgeCellIterator::~vtkBridgeCellIterator()
57 {
58   this->IteratorOnDataSet->Delete();
59   this->IteratorOneCell->Delete();
60   this->IteratorOnCellBoundaries->Delete();
61   this->IteratorOnCellList->Delete();
62 }
63 
64 //-----------------------------------------------------------------------------
65 // Description:
66 // Move iterator to first position if any (loop initialization).
Begin()67 void vtkBridgeCellIterator::Begin()
68 {
69   if(this->CurrentIterator!=0)
70     {
71     this->CurrentIterator->Begin();
72     }
73 }
74 
75 //-----------------------------------------------------------------------------
76 // Description:
77 // Is there no cell at iterator position? (exit condition).
IsAtEnd()78 int vtkBridgeCellIterator::IsAtEnd()
79 {
80   int result=1;
81 
82   if(this->CurrentIterator!=0)
83     {
84     result=this->CurrentIterator->IsAtEnd();
85     }
86   return result;
87 }
88 
89 //-----------------------------------------------------------------------------
90 // Description:
91 // Create an empty cell.
92 // \post result_exists: result!=0
NewCell()93 vtkGenericAdaptorCell *vtkBridgeCellIterator::NewCell()
94 {
95   vtkGenericAdaptorCell *result=vtkBridgeCell::New();
96   assert("post: result_exists" && result!=0);
97   return result;
98 }
99 
100 //-----------------------------------------------------------------------------
101 // Description:
102 // Cell at current position
103 // \pre not_at_end: !IsAtEnd()
104 // \pre c_exists: c!=0
105 // THREAD SAFE
GetCell(vtkGenericAdaptorCell * c)106 void vtkBridgeCellIterator::GetCell(vtkGenericAdaptorCell *c)
107 {
108   assert("pre: not_at_end" && !IsAtEnd());
109   assert("pre: c_exists" && c!=0);
110 
111   this->CurrentIterator->GetCell(c);
112 }
113 
114 //-----------------------------------------------------------------------------
115 // Description:
116 // Cell at current position.
117 // NOT THREAD SAFE
118 // \pre not_at_end: !IsAtEnd()
119 // \post result_exits: result!=0
GetCell()120 vtkGenericAdaptorCell *vtkBridgeCellIterator::GetCell()
121 {
122   assert("pre: not_at_end" && !IsAtEnd());
123   vtkGenericAdaptorCell *result=this->CurrentIterator->GetCell( );
124   assert("post: result_exits" && result!=0);
125   return result;
126 }
127 
128 //-----------------------------------------------------------------------------
129 // Description:
130 // Move iterator to next position. (loop progression).
131 // \pre not_at_end: !IsAtEnd()
Next()132 void vtkBridgeCellIterator::Next()
133 {
134   assert("pre: not_off" && !IsAtEnd());
135   this->CurrentIterator->Next();
136 }
137 
138 //-----------------------------------------------------------------------------
139 // Description:
140 // Used internally by vtkBridgeDataSet.
141 // Iterate over cells of `ds' of some dimension `dim'.
142 // \pre ds_exists: ds!=0
143 // \pre valid_dim_range: (dim>=-1) && (dim<=3)
InitWithDataSet(vtkBridgeDataSet * ds,int dim)144 void vtkBridgeCellIterator::InitWithDataSet(vtkBridgeDataSet *ds,
145                                             int dim)
146 {
147   assert("pre: ds_exists" && ds!=0);
148   assert("pre: valid_dim_range" && (dim>=-1) && (dim<=3));
149 
150   this->IteratorOnDataSet->InitWithDataSet(ds,dim);
151   this->CurrentIterator=this->IteratorOnDataSet;
152 }
153 
154 //-----------------------------------------------------------------------------
155 // Description:
156 // Used internally by vtkBridgeDataSet.
157 // Iterate over boundary cells of `ds' of some dimension `dim'.
158 // \pre ds_exists: ds!=0
159 // \pre valid_dim_range: (dim>=-1) && (dim<=3)
InitWithDataSetBoundaries(vtkBridgeDataSet * ds,int dim,int exterior_only)160 void vtkBridgeCellIterator::InitWithDataSetBoundaries(vtkBridgeDataSet *ds,
161                                                       int dim,
162                                                       int exterior_only)
163 {
164   assert("pre: ds_exists" && ds!=0);
165   assert("pre: valid_dim_range" && (dim>=-1) && (dim<=3));
166 
167   (void)ds;
168   (void)dim;
169   (void)exterior_only;
170 
171   assert("check: TODO" && 0);
172 }
173 
174 //-----------------------------------------------------------------------------
175 // Description:
176 // Used internally by vtkBridgeDataSet.
177 // Iterate on one cell `id' of `ds'.
178 // \pre ds_exists: ds!=0
179 // \pre valid_id: (id>=0)&&(id<=ds->GetNumberOfCells())
InitWithOneCell(vtkBridgeDataSet * ds,vtkIdType cellid)180 void vtkBridgeCellIterator::InitWithOneCell(vtkBridgeDataSet *ds,
181                                             vtkIdType cellid)
182 {
183   assert("pre: ds_exists" && ds!=0);
184   assert("pre: valid_id" && (cellid>=0)&&(cellid<=ds->GetNumberOfCells()));
185 
186   this->IteratorOneCell->InitWithOneCell(ds,cellid);
187   this->CurrentIterator=this->IteratorOneCell;
188 }
189 
190 //-----------------------------------------------------------------------------
191 // Description:
192 // Used internally by vtkBridgeCell.
193 // Iterate on one cell `c'.
194 // \pre c_exists: c!=0
InitWithOneCell(vtkBridgeCell * c)195 void vtkBridgeCellIterator::InitWithOneCell(vtkBridgeCell *c)
196 {
197   assert("pre: c_exists" && c!=0);
198   this->IteratorOneCell->InitWithOneCell(c);
199   this->CurrentIterator=this->IteratorOneCell;
200 }
201 
202 //-----------------------------------------------------------------------------
203 // Description:
204 // Used internally by vtkBridgeCell.
205 // Iterate on boundary cells of a cell.
206 // \pre cell_exists: cell!=0
207 // \pre valid_dim_range: (dim==-1) || ((dim>=0)&&(dim<cell->GetDimension()))
InitWithCellBoundaries(vtkBridgeCell * cell,int dim)208 void vtkBridgeCellIterator::InitWithCellBoundaries(vtkBridgeCell *cell,
209                                                    int dim)
210 {
211   assert("pre: cell_exists" && cell!=0);
212   assert("pre: valid_dim_range" && ((dim==-1) || ((dim>=0)&&(dim<cell->GetDimension()))));
213   this->IteratorOnCellBoundaries->InitWithCellBoundaries(cell,dim);
214   this->CurrentIterator=this->IteratorOnCellBoundaries;
215 }
216 
217 //-----------------------------------------------------------------------------
218 // Description:
219 // Used internally by vtkBridgeCell.
220 // Iterate on neighbors defined by `cells' over the dataset `ds'.
221 // \pre cells_exist: cells!=0
222 // \pre ds_exists: ds!=0
InitWithCells(vtkIdList * cells,vtkBridgeDataSet * ds)223 void vtkBridgeCellIterator::InitWithCells(vtkIdList *cells,
224                                           vtkBridgeDataSet *ds)
225 {
226   assert("pre: cells_exist" && cells!=0);
227   assert("pre: ds_exists" && ds!=0);
228 
229   this->IteratorOnCellList->InitWithCells(cells,ds);
230   this->CurrentIterator=this->IteratorOnCellList;
231 }
232 
233 //-----------------------------------------------------------------------------
234 // Description:
235 // Used internally by vtkBridgeCell.
236 // Iterate on a boundary cell (defined by its points `pts' with coordinates
237 // `coords', dimension `dim' and unique id `cellid') of a cell.
238 // \pre coords_exist: coords!=0
239 // \pre pts_exist: pts!=0
240 // \pre valid_dim: dim>=0 && dim<=2
241 // \pre valid_points: pts->GetNumberOfIds()>dim
InitWithPoints(vtkPoints * coords,vtkIdList * pts,int dim,vtkIdType cellid)242 void vtkBridgeCellIterator::InitWithPoints(vtkPoints *coords,
243                                            vtkIdList *pts,
244                                            int dim,
245                                            vtkIdType cellid)
246 {
247   assert("pre: coords_exist" && coords!=0);
248   assert("pre: pts_exist" && pts!=0);
249   assert("pre: valid_dim" && dim>=0 && dim<=2);
250   assert("pre: valid_points" && pts->GetNumberOfIds()>dim);
251 
252   this->IteratorOneCell->InitWithPoints(coords,pts,dim,cellid);
253   this->CurrentIterator=this->IteratorOneCell;
254 }
255