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

Bill Lorensen bill.lorensen at gmail.com
Thu Jan 17 11:20:07 EST 2013


Several problems with this code:

1) VTK uses 0-index in arrays. This code uses 1-index
2) The number of scalars must match the number of points. Once
interpolated, your polydata have many more points than the initial 6.

Attached, find a working example. I'll probably add it to the wiki. It
uses TupleInterpolator to populated the scalars with the same number
of tuples as there are number of points to the polydata.

Let me know if this is what you had in mind.

Bill


On Thu, Jan 17, 2013 at 8:22 AM, reaper84 <sankowski at gmail.com> wrote:
> 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.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



-- 
Unpaid intern in BillsBasement at noware dot com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TubesFromSplines.cxx
Type: application/octet-stream
Size: 3942 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130117/53008028/attachment.obj>


More information about the vtkusers mailing list