128{
129 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
130 vtkInformation *outInfo = outputVector->GetInformationObject(0);
131
132 vtkPolyData *input = vtkPolyData::SafeDownCast(
133 inInfo->Get(vtkDataObject::DATA_OBJECT()));
134 vtkPolyData *output = vtkPolyData::SafeDownCast(
135 outInfo->Get(vtkDataObject::DATA_OBJECT()));
136
138 {
139 vtkErrorMacro(<<"BoundaryMetricArrayName not set.");
140 return 1;
141 }
142
144 {
145 vtkErrorMacro(<<"GroupIdsArrayName not set.");
146 return 1;
147 }
148
149 vtkDataArray* groupIdsArray = input->GetPointData()->GetArray(this->
GroupIdsArrayName);
150
151 if (!groupIdsArray)
152 {
153 vtkErrorMacro(<<"GroupIdsArray with name specified does not exist.");
154 return 1;
155 }
156
158 {
159 vtkErrorMacro(<<"Centerlines not set");
160 return 1;
161 }
162
164 {
165 vtkErrorMacro(<<"CenterlineAbscissasArrayName not set.");
166 return 1;
167 }
168
170
171 if (!centerlineAbscissasArray)
172 {
173 vtkErrorMacro(<<"CenterlineAbscissasArray with name specified does not exist.");
174 return 1;
175 }
176
178 {
179 vtkErrorMacro(<<"CenterlineRadiusArrayName not set.");
180 return 1;
181 }
182
184
185 if (!centerlineRadiusArray)
186 {
187 vtkErrorMacro(<<"CenterlineRadiusArray with name specified does not exist.");
188 return 1;
189 }
190
192 {
193 vtkErrorMacro(<<"CenterlineGroupIdsArrayName not set.");
194 return 1;
195 }
196
198
199 if (!centerlineGroupIdsArray)
200 {
201 vtkErrorMacro(<<"CenterlineGroupIdsArrayName with name specified does not exist.");
202 return 1;
203 }
204
206 {
207 vtkErrorMacro(<<"CenterlineIdsArrayName not set.");
208 return 1;
209 }
210
212
213 if (!centerlineIdsArray)
214 {
215 vtkErrorMacro(<<"CenterlineIdsArrayName with name specified does not exist.");
216 return 1;
217 }
218
220 {
221 vtkErrorMacro(<<"CenterlineTractIdsArrayName not set.");
222 return 1;
223 }
224
226
227 if (!centerlineTractIdsArray)
228 {
229 vtkErrorMacro(<<"CenterlineTractIdsArrayName with name specified does not exist.");
230 return 1;
231 }
232
234 {
235 vtkErrorMacro(<<"ReferenceSystems not set");
236 return 1;
237 }
238
240 {
241 vtkErrorMacro(<<"ReferenceSystemGroupIdsArrayName not set.");
242 return 1;
243 }
244
246
247 if (!referenceSystemGroupIdsArray)
248 {
249 vtkErrorMacro(<<"ReferenceSystemGroupIdsArrayName with name specified does not exist.");
250 return 1;
251 }
252
253 int numberOfInputPoints = input->GetNumberOfPoints();
254
255 output->DeepCopy(input);
256
257 vtkDoubleArray* boundaryMetricArray = vtkDoubleArray::New();
259 boundaryMetricArray->SetNumberOfComponents(1);
260 boundaryMetricArray->SetNumberOfTuples(numberOfInputPoints);
261 boundaryMetricArray->FillComponent(0,0.0);
262
263 output->GetPointData()->AddArray(boundaryMetricArray);
264
265
266
267 vtkIdList* groupIds = vtkIdList::New();
269 int i;
270 for (i=0; i<groupIds->GetNumberOfIds(); i++)
271 {
272 vtkIdType groupId = groupIds->GetId(i);
273 vtkPolyData* cylinder = vtkPolyData::New();
275
277 boundaryExtractor->SetInputData(cylinder);
278 boundaryExtractor->Update();
279
280 int numberOfBoundaries = boundaryExtractor->GetOutput()->GetNumberOfCells();
281
282 if (numberOfBoundaries != 2)
283 {
284 vtkErrorMacro(<<"Branch is not topologically a cylinder");
285 return 1;
286 }
287
288 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
290
296
297 double boundaryAbscissa[2];
298
299 int j;
300 for (j=0; j<numberOfBoundaries; j++)
301 {
302 vtkPolyLine* boundary = vtkPolyLine::SafeDownCast(boundaryExtractor->GetOutput()->GetCell(j));
303
304 if (boundary->GetNumberOfPoints() == 0)
305 {
306 vtkErrorMacro(<<"Zero-length boundary found");
307 return 1;
308 }
309
311
315 double abscissa = 0.0;
317
318 boundaryAbscissa[j] = abscissa;
319 }
320
321 int boundaryOrderedIds[2];
322 boundaryOrderedIds[0] = 0;
323 boundaryOrderedIds[1] = 1;
324 if (boundaryAbscissa[0] > boundaryAbscissa[1])
325 {
326 boundaryOrderedIds[0] = 1;
327 boundaryOrderedIds[1] = 0;
328 }
329
330
331
332 vtkIdList* upStreamGroupIds = vtkIdList::New();
333 vtkIdList* downStreamGroupIds = vtkIdList::New();
334
336
337 if ((upStreamGroupIds->GetNumberOfIds() > 1) || (downStreamGroupIds->GetNumberOfIds() > 1))
338 {
339 vtkErrorMacro(<<"More than one adjacent group found for current group. Not topologically a cylinder.");
340 return 1;
341 }
342
343 vtkIdType referenceSystemGroupIds[2];
344 referenceSystemGroupIds[0] = -1;
345 referenceSystemGroupIds[1] = -1;
346 vtkIdType referenceSystemPointIds[2];
347 referenceSystemPointIds[0] = -1;
348 referenceSystemPointIds[1] = -1;
349
350 if (upStreamGroupIds->GetNumberOfIds() > 0)
351 {
352 referenceSystemGroupIds[0] = upStreamGroupIds->GetId(0);
353 }
354
355 if (downStreamGroupIds->GetNumberOfIds() > 0)
356 {
357 referenceSystemGroupIds[1] = downStreamGroupIds->GetId(0);
358 }
359
360 int n;
361 for (n=0; n<2; n++)
362 {
363 if (referenceSystemGroupIds[n] == -1)
364 {
365 continue;
366 }
368 if (referenceSystemPointIds[n] == -1)
369 {
370 vtkErrorMacro(<<"Centerline group ids and reference system group ids are inconsistent.");
371 return 1;
372 }
373 }
374
375
376
377
378 double referenceSystemAbscissas[2];
379 referenceSystemAbscissas[0] = 0.0;
380 referenceSystemAbscissas[1] = 0.0;
381
382 for (n=0; n<2; n++)
383 {
384 if (referenceSystemGroupIds[n] != -1)
385 {
386
387
389
390 double weightSum = 0.0;
391
392 vtkIdList* centerlineGroupAllCellIds = vtkIdList::New();
394 for (j=0; j<centerlineGroupAllCellIds->GetNumberOfIds(); j++)
395 {
396 centerlineGroupCellIds->Initialize();
397 centerlineGroupCellIds->InsertNextId(centerlineGroupAllCellIds->GetId(j));
398
401
405
406 double radius = 0.0;
408 double weight = radius * radius;
409 double abscissa = 0.0;
411
412 referenceSystemAbscissas[n] += weight * abscissa;
413 weightSum += weight;
414 }
415 referenceSystemAbscissas[n] /= weightSum;
416 }
417 else
418 {
419
420 if (n==0)
421 {
422 referenceSystemAbscissas[n] = VTK_DOUBLE_MAX;
423
424 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
426 for (j=0; j<centerlineGroupCellIds->GetNumberOfIds(); j++)
427 {
428 vtkIdType centerlineCellId = centerlineGroupCellIds->GetId(j);
429 double abscissa = centerlineAbscissasArray->GetComponent(this->
Centerlines->GetCell(centerlineCellId)->GetPointId(0),0);
430 if (abscissa < referenceSystemAbscissas[n])
431 {
432 referenceSystemAbscissas[n] = abscissa;
433 }
434 }
435 centerlineGroupCellIds->Delete();
436 }
437 else if (n==1)
438 {
439 referenceSystemAbscissas[n] = VTK_DOUBLE_MIN;
440
441 vtkIdList* centerlineGroupCellIds = vtkIdList::New();
443 for (j=0; j<centerlineGroupCellIds->GetNumberOfIds(); j++)
444 {
445 vtkIdType centerlineCellId = centerlineGroupCellIds->GetId(j);
446
447 int numberOfCellPoints = this->
Centerlines->GetCell(centerlineCellId)->GetNumberOfPoints();
448 double abscissa = centerlineAbscissasArray->GetComponent(this->
Centerlines->GetCell(centerlineCellId)->GetPointId(numberOfCellPoints-1),0);
449 if (abscissa > referenceSystemAbscissas[n])
450 {
451 referenceSystemAbscissas[n] = abscissa;
452 }
453 }
454 }
455 }
456 }
457
458
459
460 for (n=0; n<2; n++)
461 {
462 vtkCell* boundary = boundaryExtractor->GetOutput()->GetCell(boundaryOrderedIds[n]);
463 vtkDataArray* boundaryPointIds = boundaryExtractor->GetOutput()->GetPointData()->GetScalars();
464 int numberOfBoundaryPoints = boundary->GetNumberOfPoints();
465 for (j=0; j<numberOfBoundaryPoints; j++)
466 {
467 vtkIdType boundaryPointId = static_cast<int>(boundaryPointIds->GetComponent(boundary->GetPointId(j),0));
468 boundaryMetricArray->SetComponent(boundaryPointId,0,referenceSystemAbscissas[n]);
469 }
470 }
471
472 tube->Delete();
473 centerlineGroupCellIds->Delete();
474 boundaryExtractor->Delete();
475 cylinder->Delete();
476 upStreamGroupIds->Delete();
477 downStreamGroupIds->Delete();
478 }
479
480 groupIds->Delete();
481 boundaryMetricArray->Delete();
482
483 return 1;
484}
static void GetGroupCellIds(vtkPolyData *centerlines, const char *groupIdsArrayName, vtkIdType groupId, vtkIdList *groupCellIds)
static void GetGroupUniqueCellIds(vtkPolyData *centerlines, const char *groupIdsArrayName, vtkIdType groupId, vtkIdList *groupCellIds)
static void InterpolateTuple1(vtkPolyData *centerlines, const char *arrayName, int cellId, int subId, double pcoord, double &interpolatedTuple1)
static void FindAdjacentCenterlineGroupIds(vtkPolyData *centerlines, const char *groupIdsArrayName, const char *centerlineIdsArrayName, const char *tractIdsArrayName, vtkIdType groupId, vtkIdList *upStreamGroupIds, vtkIdList *downStreamGroupIds)
virtual double GetLastPolyBallCellPCoord()
virtual void SetInput(vtkPolyData *)
virtual void SetPolyBallRadiusArrayName(const char *)
virtual void SetInputCellIds(vtkIdList *)
virtual vtkIdType GetLastPolyBallCellId()
static vtkvmtkPolyBallLine * New()
double EvaluateFunction(double x[3]) override
virtual vtkIdType GetLastPolyBallCellSubId()
virtual void UseRadiusInformationOn()
virtual void UseRadiusInformationOff()
static void ExtractGroup(vtkPolyData *surface, const char *groupIdsArrayName, vtkIdType groupId, bool cleanGroupSurface, vtkPolyData *groupSurface)
static void GetGroupsIdList(vtkPolyData *surface, const char *groupIdsArrayName, vtkIdList *groupIds)
static vtkIdType GetReferenceSystemPointId(vtkPolyData *referenceSystems, const char *groupIdsArrayName, vtkIdType groupId)