[vtkusers] On vtkSelectVisiblePoints

Petru Pau ppau at risc.uni-linz.ac.at
Thu Jun 3 08:22:50 EDT 2004


All right, good people, the time has come for me to post some code.
A couple of weeks ago I asked some questions about vtkSelectVisiblePoints.
As I got no answer, I started playing around with this filter. It is
really interesting...

Anyway, here's my question: why are there only three points selected as
visible, in the following example?

The example creates a cube, rotates it, selects (well...) the visible 
points,
and puts small spheres in these visible points, just for fun. Please don't
bother about the syntax - I wrote it in C#, and I reckon translating it
to TCL, which I do not master, should be immediate. Basically, 70%
of the code is the rendering stuff - but I have to put it here because the
renderer of the initial model must be given to the point selection filter.

I attach an image with the two render windows - with the rotated cube and
with the points detected as visible.

Maybe this time somebody can figure out why it works this way.

Petru

---
           vtkPolyData model = createCube(); // create a cube
            model = Geometry.transform(0,0,0, 
(float)Math.PI/3,(float)-Math.PI/4, model); // rotate
            
            // show initial model
            vtkPolyDataMapper mapper1 = vtkPolyDataMapper.New();
            vtkPolyDataMapper.GlobalImmediateModeRenderingOn();
            vtkActor actor1 = vtkActor.New();
            vtkRenderer renderer1 = vtkRenderer.New();
            vtkRenderWindow renWin1 = vtkRenderWindow.New();
            vtkRenderWindowInteractor iren1 = 
vtkRenderWindowInteractor.New();

            mapper1.SetInput(model);               
actor1.SetMapper(mapper1);
            renderer1.AddActor(actor1);          
renWin1.AddRenderer(renderer1);
            renWin1.SetSize(300, 300);           
 iren1.SetRenderWindow(renWin1);
            renWin1.Render();

            // extract visible points
            vtkIdFilter ids = vtkIdFilter.New();
            ids.SetInput(model);
            ids.PointIdsOn();     ids.CellIdsOn();    ids.FieldDataOn();
                
            vtkSelectVisiblePoints visPtsSel = vtkSelectVisiblePoints.New();
            visPtsSel.SetInput(ids.GetOutput());
            visPtsSel.SetRenderer(renderer1);

            vtkPolyData visPoints = visPtsSel.GetOutput();
            visPoints.Update();

            // put a small sphere in each visible point
            // createSphere is a local function with prototype
            //      createSphere(float[] centerPoint, float radius)
            int nrPoints = visPoints.GetNumberOfPoints();
            vtkAppendPolyData apd = vtkAppendPolyData.New();
            for (int i=0; i<nrPoints; i++)
                apd.AddInput(createSphere(visPoints.GetPoint(i), 0.1F));

            // show visible points
            vtkPolyDataMapper mapper2 = vtkPolyDataMapper.New();
            vtkPolyDataMapper.GlobalImmediateModeRenderingOn();
            vtkActor actor2 = vtkActor.New();
            vtkRenderer renderer2 = vtkRenderer.New();
            vtkRenderWindow renWin2 = vtkRenderWindow.New();
            vtkRenderWindowInteractor iren2 = 
vtkRenderWindowInteractor.New();

            mapper2.SetInput(apd.GetOutput());    actor2.SetMapper(mapper2);
            renderer2.AddActor(actor2);           
 renWin2.AddRenderer(renderer2);
            renWin2.SetSize(300, 300);           
 iren2.SetRenderWindow(renWin2);
            renWin2.Render();
---
-------------- next part --------------
A non-text attachment was scrubbed...
Name: visCube.jpg
Type: image/jpeg
Size: 22735 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040603/877b12df/attachment.jpg>


More information about the vtkusers mailing list