123 vtkInformation *vtkNotUsed(request),
124 vtkInformationVector **inputVector,
125 vtkInformationVector *outputVector)
127 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
128 vtkInformation *outInfo = outputVector->GetInformationObject(0);
130 vtkPolyData *input = vtkPolyData::SafeDownCast(
131 inInfo->Get(vtkDataObject::DATA_OBJECT()));
132 vtkPolyData *output = vtkPolyData::SafeDownCast(
133 outInfo->Get(vtkDataObject::DATA_OBJECT()));
137 vtkErrorMacro(<<
"OffsetAbscissasArrayName not specified");
143 vtkErrorMacro(<<
"OffsetNormalsArrayName not specified");
149 vtkErrorMacro(<<
"AbscissasArrayName not specified");
153 vtkDataArray* abscissasArray = input->GetPointData()->GetArray(this->
AbscissasArrayName);
157 vtkErrorMacro(<<
"AbscissasArray with name specified does not exist");
163 vtkErrorMacro(<<
"NormalsArrayName not specified");
167 vtkDataArray* normalsArray = input->GetPointData()->GetArray(this->
NormalsArrayName);
171 vtkErrorMacro(<<
"NormalsArray with name specified does not exist");
177 vtkErrorMacro(<<
"GroupIdsArrayName not specified");
181 vtkDataArray* groupIdsArray = input->GetCellData()->GetArray(this->
GroupIdsArrayName);
185 vtkErrorMacro(<<
"GroupIdsArray with name specified does not exist");
191 vtkErrorMacro(<<
"CenterlineIdsArrayName not specified");
197 if (!centerlineIdsArray)
199 vtkErrorMacro(<<
"CenterlineIdsArray with name specified does not exist");
205 vtkErrorMacro(<<
"ReferenceSystems not specified");
211 vtkErrorMacro(<<
"ReferenceSystems empty");
217 vtkErrorMacro(<<
"ReferenceSystemsNormalArrayName not specified");
223 if (!referenceSystemsNormalArray)
225 vtkErrorMacro(<<
"ReferenceSystemNormalsArray with name specified does not exist");
231 vtkErrorMacro(<<
"ReferenceSystemsGroupIdsArrayName not specified");
237 if (!referenceSystemsGroupIdsArray)
239 vtkErrorMacro(<<
"ReferenceSystemsGroupIdsArray with name specified does not exist");
243 output->DeepCopy(input);
245 vtkDoubleArray* offsetAbscissasArray = vtkDoubleArray::New();
247 offsetAbscissasArray->SetNumberOfComponents(1);
248 offsetAbscissasArray->SetNumberOfTuples(input->GetNumberOfPoints());
250 vtkDoubleArray* offsetNormalsArray = vtkDoubleArray::New();
252 offsetNormalsArray->SetNumberOfComponents(3);
253 offsetNormalsArray->SetNumberOfTuples(input->GetNumberOfPoints());
263 vtkIdList* tubeInputCellIds = vtkIdList::New();
265 double referenceSystemOrigin[3], referenceSystemNormal[3];
269 this->
ReferenceGroupId =
static_cast<int>(referenceSystemsGroupIdsArray->GetComponent(0,0));
274 if (referenceSystemPointId == -1)
276 vtkErrorMacro(<<
"Invalid ReferenceGroupId");
280 this->
ReferenceSystems->GetPoint(referenceSystemPointId,referenceSystemOrigin);
281 referenceSystemsNormalArray->GetTuple(referenceSystemPointId,referenceSystemNormal);
283 vtkIdList* groupCellIds = vtkIdList::New();
285 for (
int i=0; i<groupCellIds->GetNumberOfIds(); i++)
287 vtkIdType currentCellId = groupCellIds->GetId(i);
289 vtkIdType centerlineId =
static_cast<int>(centerlineIdsArray->GetComponent(currentCellId,0));
290 tubeInputCellIds->Initialize();
291 tubeInputCellIds->InsertNextId(currentCellId);
300 double abscissa = 0.0;
302 double abscissaOffset = - abscissa;
306 vtkMath::Normalize(normal);
308 double point0[3], point1[3], tangent[3];
309 input->GetCell(cellId)->GetPoints()->GetPoint(subId,point0);
310 input->GetCell(cellId)->GetPoints()->GetPoint(subId+1,point1);
311 tangent[0] = point1[0] - point0[0];
312 tangent[1] = point1[1] - point0[1];
313 tangent[2] = point1[2] - point0[2];
314 double normalDot = vtkMath::Dot(tangent,normal);
315 tangent[0] -= normalDot * normal[0];
316 tangent[1] -= normalDot * normal[1];
317 tangent[2] -= normalDot * normal[2];
318 vtkMath::Normalize(tangent);
320 double dot = vtkMath::Dot(tangent,referenceSystemNormal);
321 double projectedReferenceSystemNormal[3];
322 projectedReferenceSystemNormal[0] = referenceSystemNormal[0] - dot * tangent[0];
323 projectedReferenceSystemNormal[1] = referenceSystemNormal[1] - dot * tangent[1];
324 projectedReferenceSystemNormal[2] = referenceSystemNormal[2] - dot * tangent[2];
325 vtkMath::Normalize(projectedReferenceSystemNormal);
330 vtkMath::Cross(projectedReferenceSystemNormal,normal,cross);
331 double tangentDot = vtkMath::Dot(tangent,cross);
333 if (tangentDot < 0.0)
338 double angleOffset = -angle;
340 vtkIdList* centerlineCellIds = vtkIdList::New();
342 for (
int j=0; j<centerlineCellIds->GetNumberOfIds(); j++)
344 vtkCell* branchCell = input->GetCell(centerlineCellIds->GetId(j));
345 int numberOfBranchPoints = branchCell->GetNumberOfPoints();
346 for (
int k=0; k<numberOfBranchPoints; k++)
348 vtkIdType branchPointId = branchCell->GetPointId(k);
349 double branchPointAbscissa = abscissasArray->GetComponent(branchPointId,0);
350 double offsetBranchPointAbscissa = branchPointAbscissa + abscissaOffset;
351 offsetAbscissasArray->SetComponent(branchPointId,0,offsetBranchPointAbscissa);
353 double branchPointNormal[3];
354 normalsArray->GetTuple(branchPointId,branchPointNormal);
355 double branchPoint[3];
356 branchCell->GetPoints()->GetPoint(k,branchPoint);
357 double branchTangent[3];
358 branchTangent[0] = branchTangent[1] = branchTangent[2] = 0.0;
361 double branchPoint0[3];
362 branchCell->GetPoints()->GetPoint(k-1,branchPoint0);
363 branchTangent[0] += branchPoint[0] - branchPoint0[0];
364 branchTangent[1] += branchPoint[1] - branchPoint0[1];
365 branchTangent[2] += branchPoint[2] - branchPoint0[2];
367 if (k < numberOfBranchPoints-1)
369 double branchPoint1[3];
370 branchCell->GetPoints()->GetPoint(k+1,branchPoint1);
371 branchTangent[0] += branchPoint1[0] - branchPoint[0];
372 branchTangent[1] += branchPoint1[1] - branchPoint[1];
373 branchTangent[2] += branchPoint1[2] - branchPoint[2];
375 double branchNormalDot = vtkMath::Dot(branchTangent,branchPointNormal);
376 branchTangent[0] -= branchNormalDot * branchPointNormal[0];
377 branchTangent[1] -= branchNormalDot * branchPointNormal[1];
378 branchTangent[2] -= branchNormalDot * branchPointNormal[2];
379 vtkMath::Normalize(branchTangent);
381 vtkTransform* transform = vtkTransform::New();
382 transform->RotateWXYZ(angleOffset/vtkMath::Pi()*180.0,branchTangent);
384 double offsetBranchPointNormal[3];
385 transform->TransformNormal(branchPointNormal,offsetBranchPointNormal);
386 offsetNormalsArray->SetTuple(branchPointId,offsetBranchPointNormal);
391 centerlineCellIds->Delete();
394 groupCellIds->Delete();
396 output->GetPointData()->AddArray(offsetAbscissasArray);
397 output->GetPointData()->AddArray(offsetNormalsArray);
399 offsetAbscissasArray->Delete();
400 offsetNormalsArray->Delete();
402 tubeInputCellIds->Delete();