54{
55
56 vtkInformation *outInfo = outputVector->GetInformationObject(0);
57
58
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
81
82
83
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;
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 }
162 }
163
164 if ( numPts < 1)
165 {
166 vtkDebugMacro(<<"No data to append!");
167 return 1;
168 }
169
170
171 output->Allocate(numCells);
172
173 outputPD->CopyAllocate(ptList,numPts);
174
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();
183 {
184 locator->InitPointInsertion(newPts,bounds);
185 }
186
187 vtkIdList* ptIdMap = vtkIdList::New();
188
189 vtkIdType newPtId;
190 double point[3];
191
192
193
194 tenth = (numPts + numCells)/10 + 1;
195 int inputCount = 0;
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
215 for (ptId=0; ptId < numPts && !abort; ptId++)
216 {
217 ds->GetPoint(ptId,point);
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
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
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
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
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}