[vtkusers] triangulating a cylinder

Obada Mahdi omahdi at gmx.de
Fri Dec 8 09:25:24 EST 2006


Hi Debbie!

On Thu, 7 Dec 2006, debbie larson wrote:
> I am now using vtkCylinderSource to build the cylinder. The problem is that I 
> want to build several cylinders with different radii and located at different 
> positions. Do I assign one actor for each cylinder? How exactly I specify the 
> center of each cylinder? (The code below doesnt seem to work)
> Here it is my current code (which is not working; it only displays one 
> cylinder)

Yes, in the example you are providing you would need to use one actor,
one mapper and one cylinder source per object.  Repeatedly setting up
pipeline connections for a certain input just results in the previous
connection to be removed, which is why you only see one cylinder.

Also, if you need to have different radii, repeatedly changing the
radius of a source object via vtkCylinderSource::SetRadius() does not
work, because it would affect every filter that uses this particular
instance as input.  This can be resolved by either creating different
sources for different radii, or by applying some sort of scaling filter
to stretch the geometry appropriately (which is probably not what you
want, as larger radii might require different resolution, i.e. number of
facets, for a smooth look).

There is more than one way to position a cylinder; the one you are
using, via vtkCylinder::SetCenter(), should work just fine, given that
the corresponding actor is located at (0,0,0) (which is the default).
Note, however, that by default the center of rotation for a given actor
is also at (0,0,0).  If you want the cylinder to rotate around its
center, you need to specify its origin of rotation using
vtkActor::SetOrigin() as well.

If you actually just want to set up the position in world coordinates
where a cylinder is to be rendered, is is easier to just leave
vtkCylinder::SetCenter() and vtkActor::SetOrigin() alone, i.e., use the
defaults of (0,0,0), and change the actor's position using
vtkActor::SetPosition().


If you are looking for different options:

In certain cases, e.g. where there is no need to interact with each
object individually and each polygonal object can be derived from a
(fixed) set of source geometry, it might be worth to consider the use of
vtkGlyph3D, which is described here:

http://www.vtk.org/doc/nightly/html/classvtkGlyph3D.html

There are also some examples in the VTK source tree at

Examples/Annotation/{Python,Tcl}/annotatePick.{py,tcl}
Examples/VisualizationAlgorithms/{Python,Tcl}/spikeF.{py,tcl}

I am not sure, however, whether it is applicable for your task, because
each of your cylinders seems to be made from a unique source, which kind
of defies the purpose of a glyphing filter.  To make the confusion
perfect, there is also vtkTubeFilter, described at

http://www.vtk.org/doc/nightly/html/classvtkTubeFilter.html

which might also be an interesting option for automatically generating
cylinder-like objects based on parameters specified by input polydata.

It takes a bit of tinkering sometimes to find the appropriate set of
classes to do a certain job in VTK :-)


Hope this helps (and does not cause too much confusion),

Obada


> Thanks
>
> deb
> -----------------------------------------------------------------------------
> vtkCylinderSource* cylinder=vtkCylinderSource::New();
>
> vtkPolyDataMapper *icylinderMapper = vtkPolyDataMapper::New();
>
> vtkActor *icylinderActor = vtkActor::New();
>
> icylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);//RGB color
>  icylinderActor->RotateX(30.0);
>  icylinderActor->RotateY(-45.0);
>  vtkRenderer *ren1 = vtkRenderer::New();
>  vtkRenderWindow *renWin = vtkRenderWindow::New();
>  renWin->AddRenderer(ren1);
>  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>  iren->SetRenderWindow(renWin);
>
>  ren1->SetBackground(0.1, 0.2, 0.4);
>  renWin->SetSize(500, 500);
>
>  for (int i=0;i<num_cylinders;i++)
>    {
>      float oradius=tdplane.getradius(i);
>      //Get the position of the center of the cylinder
>      float position[2]=tdplane.getposition();
>      float center_positionx=position[0];
>      float center_positiony=position[1];
>
>
>      cylinder->SetHeight(cylinder_height);
>      cylinder->SetRadius(iradius);
>      cylinder->SetCenter(center_positionx,0,center_positiony);
>      cylinder->CappingOff();
>      cylinder->SetResolution(8);
>
>
>     icylinderMapper->SetInputConnection(cylinder->GetOutputPort());
>
>     icylinderActor->SetMapper(icylinderMapper);
>
>
>      //Add the actors to the renderer
>      ren1->AddActor(icylinderActor);
>
>   }
>
>
>  ren1->ResetCamera();
>  ren1->GetActiveCamera()->Zoom(1.0);
>  renWin->Render();
>
> iren->Start();
>
> cylinder->Delete();
>
> icylinderMapper->Delete();
>
> icylinderActor->Delete();
>
>  ren1->Delete();
>  renWin->Delete();
>  iren->Delete();
> }



More information about the vtkusers mailing list