VMTK
Loading...
Searching...
No Matches
vtkvmtkAppendFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkAppendFilter.cxx,v $
5Language: C++
6Date: $Date: 2005/03/31 15:49:05 $
7Version: $Revision: 1.3 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
22#include "vtkvmtkAppendFilter.h"
23
24#include "vtkCell.h"
25#include "vtkCellData.h"
26#include "vtkDataSetAttributes.h"
27#include "vtkDataSetCollection.h"
28#include "vtkExecutive.h"
29#include "vtkInformation.h"
30#include "vtkInformationVector.h"
31#include "vtkObjectFactory.h"
32#include "vtkPointData.h"
33#include "vtkUnstructuredGrid.h"
34
35#include "vtkMath.h"
36#include "vtkMergePoints.h"
37
38
40
45
49
51 vtkInformation *vtkNotUsed(request),
52 vtkInformationVector **inputVector,
53 vtkInformationVector *outputVector)
54{
55 // get the output info object
56 vtkInformation *outInfo = outputVector->GetInformationObject(0);
57
58 // get the output
59 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
60 outInfo->Get(vtkDataObject::DATA_OBJECT()));
61
62 vtkIdType numPts, numCells;
63 int tenth, count, abort=0;
64 float decimal;
65 vtkPoints *newPts;
66 vtkPointData *pd;
67 vtkCellData *cd;
68 vtkIdList *ptIds, *newPtIds;
69 int i, idx;
70 vtkDataSet *ds;
71 vtkIdType ptId, cellId, newCellId;
72 vtkPointData *outputPD = output->GetPointData();
73 vtkCellData *outputCD = output->GetCellData();
74
75 vtkDebugMacro(<<"Appending data together");
76
77 double bounds[6], inputBounds[6];
78 vtkMath::UninitializeBounds(bounds);
79
80 // Loop over all data sets, checking to see what data is common to
81 // all inputs. Note that data is common if 1) it is the same attribute
82 // type (scalar, vector, etc.), 2) it is the same native type (int,
83 // float, etc.), and 3) if a data array in a field, if it has the same name.
84 count = 0;
85 decimal = 0.0;
86
87 numPts = 0;
88 numCells = 0;
89
90 int numInputs = inputVector[0]->GetNumberOfInformationObjects();
91 vtkDataSetAttributes::FieldList ptList(numInputs);
92 vtkDataSetAttributes::FieldList cellList(numInputs);
93 int firstPD=1;
94 int firstCD=1;
95 vtkInformation *inInfo = 0;
96 for (idx = 0; idx < numInputs; ++idx)
97 {
98 inInfo = inputVector[0]->GetInformationObject(idx);
99 ds = 0;
100 if (inInfo)
101 {
102 ds = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
103 }
104 if (ds != NULL)
105 {
106 if ( ds->GetNumberOfPoints() <= 0 && ds->GetNumberOfCells() <= 0 )
107 {
108 continue; //no input, just skip
109 }
110
111 numPts += ds->GetNumberOfPoints();
112 numCells += ds->GetNumberOfCells();
113
114 ds->GetBounds(inputBounds);
115 if (vtkMath::AreBoundsInitialized(bounds))
116 {
117 int j;
118 for (j=0; j<6; j+=2)
119 {
120 if (inputBounds[j] < bounds[j])
121 {
122 bounds[j] = inputBounds[j];
123 }
124 if (inputBounds[j+1] > bounds[j+1])
125 {
126 bounds[j+1] = inputBounds[j+1];
127 }
128 }
129 }
130 else
131 {
132 int j;
133 for (j=0; j<6; j+=2)
134 {
135 bounds[j] = inputBounds[j];
136 bounds[j+1] = inputBounds[j+1];
137 }
138 }
139
140 pd = ds->GetPointData();
141 if ( firstPD )
142 {
143 ptList.InitializeFieldList(pd);
144 firstPD = 0;
145 }
146 else
147 {
148 ptList.IntersectFieldList(pd);
149 }
150
151 cd = ds->GetCellData();
152 if ( firstCD )
153 {
154 cellList.InitializeFieldList(cd);
155 firstCD = 0;
156 }
157 else
158 {
159 cellList.IntersectFieldList(cd);
160 }
161 }//if non-empty dataset
162 }//for all inputs
163
164 if ( numPts < 1)
165 {
166 vtkDebugMacro(<<"No data to append!");
167 return 1;
168 }
169
170 // Now can allocate memory
171 output->Allocate(numCells); //allocate storage for geometry/topology
172// outputPD->CopyGlobalIdsOn();
173 outputPD->CopyAllocate(ptList,numPts);
174// outputCD->CopyGlobalIdsOn();
175 outputCD->CopyAllocate(cellList,numCells);
176
177 newPts = vtkPoints::New();
178 ptIds = vtkIdList::New(); ptIds->Allocate(VTK_CELL_SIZE);
179 newPtIds = vtkIdList::New(); newPtIds->Allocate(VTK_CELL_SIZE);
180
181 vtkMergePoints* locator = vtkMergePoints::New();
182 if (this->MergeDuplicatePoints)
183 {
184 locator->InitPointInsertion(newPts,bounds);
185 }
186
187 vtkIdList* ptIdMap = vtkIdList::New();
188
189 vtkIdType newPtId;
190 double point[3];
191
192 // Append each input dataset together
193 //
194 tenth = (numPts + numCells)/10 + 1;
195 int inputCount = 0; // Since empty inputs are not in the list.
196 for (idx = 0; idx < numInputs && !abort; ++idx)
197 {
198 inInfo = inputVector[0]->GetInformationObject(idx);
199 ds = 0;
200 if (inInfo)
201 {
202 ds = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
203 }
204 if ( ds != NULL &&
205 (ds->GetNumberOfPoints() > 0 || ds->GetNumberOfCells() > 0) )
206 {
207 numPts = ds->GetNumberOfPoints();
208 numCells = ds->GetNumberOfCells();
209 pd = ds->GetPointData();
210
211 ptIdMap->Initialize();
212 ptIdMap->SetNumberOfIds(numPts);
213
214 // copy points and point data
215 for (ptId=0; ptId < numPts && !abort; ptId++)
216 {
217 ds->GetPoint(ptId,point);
218 if (this->MergeDuplicatePoints)
219 {
220 if (locator->InsertUniquePoint(point,newPtId))
221 {
222 outputPD->CopyData(ptList,pd,inputCount,ptId,newPtId);
223 }
224 }
225 else
226 {
227 newPtId = newPts->InsertNextPoint(point);
228 outputPD->CopyData(ptList,pd,inputCount,ptId,newPtId);
229 }
230 ptIdMap->SetId(ptId,newPtId);
231
232 // Update progress
233 count++;
234 if (!(count % tenth))
235 {
236 decimal += 0.1;
237 this->UpdateProgress(decimal);
238 abort = this->GetAbortExecute();
239 }
240 }
241
242 cd = ds->GetCellData();
243 // copy cell and cell data
244 for (cellId=0; cellId<numCells && !abort; cellId++)
245 {
246 ds->GetCellPoints(cellId, ptIds);
247 newPtIds->Reset();
248 for (i=0; i<ptIds->GetNumberOfIds(); i++)
249 {
250 newPtIds->InsertId(i,ptIdMap->GetId(ptIds->GetId(i)));
251 }
252 newCellId = output->InsertNextCell(ds->GetCellType(cellId),newPtIds);
253 outputCD->CopyData(cellList,cd,inputCount,cellId,newCellId);
254
255 // Update progress
256 count++;
257 if (!(count % tenth))
258 {
259 decimal += 0.1;
260 this->UpdateProgress(decimal);
261 abort = this->GetAbortExecute();
262 }
263 }
264 ++inputCount;
265 }
266 }
267
268 // Update ourselves and release memory
269 //
270 output->SetPoints(newPts);
271 newPts->Delete();
272 ptIds->Delete();
273 newPtIds->Delete();
274 ptIdMap->Delete();
275 locator->Delete();
276
277 return 1;
278}
279
280void vtkvmtkAppendFilter::PrintSelf(std::ostream& os, vtkIndent indent)
281{
282 this->Superclass::PrintSelf(os,indent);
283}
Merges points, point data, and cell data.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkStandardNewMacro(vtkvmtkAppendFilter)