[vtkusers] How to change radius in vtkTubeFilter using parametric spline?

reaper84 sankowski at gmail.com
Thu Jan 17 08:22:00 EST 2013


Hi VTK users!

I'm trying to make a tube with vary radius like in this example
http://www.itk.org/Wiki/VTK/Examples/Cxx/VisualizationAlgorithms/TubesWithVaryingRadiusAndColors
<http://www.itk.org/Wiki/VTK/Examples/Cxx/VisualizationAlgorithms/TubesWithVaryingRadiusAndColors>
but using parametric spline. This is my code so far:

#include <vtkSmartPointer.h>
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkDoubleArray.h>
#include <vtkPoints.h>
#include <vtkParametricSpline.h>
#include <vtkTubeFilter.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkParametricFunctionSource.h>

int main(int, char *[])
{
  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();

  points->InsertPoint(1,1,0,0);
  points->InsertPoint(2,2,0,0);
  points->InsertPoint(3,3,1,0);
  points->InsertPoint(4,4,1,0);
  points->InsertPoint(5,5,0,0);
  points->InsertPoint(6,6,0,0);

  vtkSmartPointer<vtkDoubleArray> tubeRadius =
vtkSmartPointer<vtkDoubleArray>::New();
  tubeRadius->SetName("TubeRadius");
  tubeRadius->SetNumberOfTuples(7);
  tubeRadius->SetTuple1(1,2);
  tubeRadius->SetTuple1(2,2);
  tubeRadius->SetTuple1(3,2);
  tubeRadius->SetTuple1(4,1);
  tubeRadius->SetTuple1(5,1);
  tubeRadius->SetTuple1(6,1);

  vtkSmartPointer<vtkParametricSpline> spline =
vtkSmartPointer<vtkParametricSpline>::New();
  spline->SetPoints(points);

  vtkSmartPointer<vtkParametricFunctionSource> functionSource =
vtkSmartPointer<vtkParametricFunctionSource>::New();
  functionSource->SetParametricFunction(spline);
  functionSource->Update();

  //--------------
  vtkSmartPointer<vtkPolyData> polyData =
vtkSmartPointer<vtkPolyData>::New();
  polyData = functionSource->GetOutput();
//  polyData->SetPoints(points);
//  polyData->GetPointData()->AddArray(tubeRadius);   <-this part don't work
//  polyData->GetPointData()->SetActiveScalars("TubeRadius");

  //--------------

  vtkTubeFilter* tuber = vtkTubeFilter::New();
  tuber->SetInput(polyData);
  tuber->SetNumberOfSides(30);
  tuber->SetVaryRadiusToVaryRadiusByAbsoluteScalar();
  // Setup actor and mapper
  vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(functionSource->GetOutputPort());
  vtkSmartPointer<vtkPolyDataMapper> mapper2 =
vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper2->SetInputConnection(tuber->GetOutputPort());

  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  vtkSmartPointer<vtkActor> actor2 = vtkSmartPointer<vtkActor>::New();
  actor2->SetMapper(mapper2);

  // Setup render window, renderer, and interactor
  vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);
  renderer->AddActor(actor);
  renderer->AddActor(actor2);
  renderWindow->Render();
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

Tube works, but i can't attach array with information about desired radius.
Probably I'm trying the wrong way. I'm hoping someone will be able to help
me. I really need a changing tube radius.



--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-change-radius-in-vtkTubeFilter-using-parametric-spline-tp5717990.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list