[vtkusers] Picking a cell problem

Ali Habib ali.mahmoud.habib at gmail.com
Fri Aug 14 11:13:21 EDT 2009


Hi everyone

I used ur advice to pick a cell but my code just got one cell and not other

the commin is using c# but it's near to c++ if u can help me in it , and how
to select region using that

  private void button1_Click(object sender, EventArgs e)
        {
            vtkSphereSource sphere = new vtkSphereSource();
            vtkPolyDataMapper sphereMapper = new vtkPolyDataMapper();
            sphereMapper.SetInput(sphere.GetOutput());
            //sphereMapper.GlobalImmediateModeRenderingOn();
            vtkLODActor sphereActor = new vtkLODActor();
            sphereActor.SetMapper(sphereMapper);
            // create the spikes by glyphing the sphere with a cone.  Create
the mapper
            // and actor for the glyphs.
            vtkConeSource cone = new vtkConeSource();
            vtkGlyph3D glyph = new vtkGlyph3D();
            glyph.SetInput(sphere.GetOutput());
            glyph.SetSource(cone.GetOutput());
            glyph.SetVectorModeToUseNormal();
            glyph.SetScaleModeToScaleByVector();
            glyph.SetScaleFactor(0.25);
            vtkPolyDataMapper spikeMapper = new vtkPolyDataMapper();
            spikeMapper.SetInput(glyph.GetOutput());
            vtkLODActor spikeActor = new vtkLODActor();
            spikeActor.SetMapper(spikeMapper);
            // Create a text mapper and actor to display the results of
picking.
            textMapper = new vtkTextMapper();
            vtkTextProperty tprop = textMapper.GetTextProperty();
            tprop.SetFontFamilyToArial();
            tprop.SetFontSize(12);
            tprop.BoldOn();
            //    tprop->ShadowOn();
            tprop.SetColor(1, 0, 0);
            textActor = new vtkActor2D();
            textActor.VisibilityOff();
            textActor.SetMapper(textMapper);
            // Create a cell picker.
            picker = new vtkCellPicker();
            ren1 = new vtkRenderer();
            renWin = new vtkRenderWindow();
            renWin.AddRenderer(ren1);
            iren = new vtkRenderWindowInteractor();
            iren.AddObserver((uint)vtk.EventIds.LeftButtonPressEvent, new
vtk.vtkDotNetCallback(MouseRelease));
            iren.SetRenderWindow(renWin);
            //iren.SetInteractorStyle(style);
            iren.SetPicker(picker);
            picker.AddObserver((uint)vtk.EventIds.LeftButtonPressEvent, new
vtk.vtkDotNetCallback(MouseRelease));
            // Add the actors to the renderer, set the background and size
            ren1.AddActor2D(textActor);
            ren1.AddActor(sphereActor);
            ren1.AddActor(spikeActor);
            ren1.SetBackground(1, 1, 1);
            renWin.SetSize(300, 300);
            vtkCamera cam1 = ren1.GetActiveCamera();
            cam1.Zoom(1.4);
            picker.Pick(85, 126, 0, ren1); ;
            iren.Initialize();
            iren.Start();

        }
        public  void MouseRelease(vtk.vtkObject obj, uint eventId, Object
data, IntPtr clientdata)
        {
            if (picker.GetCellId() < 0)
            {
                textActor.VisibilityOff();
            }
            else
            {
                //double[] selpt = new double[3];

                double[] selpt = picker.GetSelectionPoint();
                double x = selpt[0];
                double y = selpt[1];
                // double[] pickPos = new double[3];
                double[] pickPos = picker.GetPickPosition();
                double xp = pickPos[0];
                double yp = pickPos[1];
                double zp = pickPos[2];
                string text = new string(new char[120]);
                text = string.Format("({0,5:f5},  {1,5:f5},  {2,5:f5})", xp,
yp, zp);
                textMapper.SetInput(text);
                textActor.SetPosition(x, y);
                textActor.VisibilityOn();

            }
          // renWin.Render();

        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090814/c6890e54/attachment.htm>


More information about the vtkusers mailing list