[vtkusers] what's wrong in my code

Ali Habib ali.mahmoud.habib at gmail.com
Sat Jun 26 10:57:12 EDT 2010


this is the complete code

        static vtkBoxWidget boxWidget;

        static vtkPlanes planes;

       static  vtkLODActor selectActor;

        static void Main(string[] args)
        {
            //Create a mace out of filters.

            vtkSphereSource sphere = new vtkSphereSource();
            vtkConeSource cone = new vtkConeSource();
            vtkGlyph3D glyph = new vtkGlyph3D();
            glyph.SetInputConnection(sphere.GetOutputPort());
            glyph.SetSource(cone.GetOutput());
            glyph.SetVectorModeToUseNormal();
            glyph.SetScaleModeToScaleByVector();
            glyph.SetScaleFactor(0.25);

            //The sphere and spikes are appended into a single polydata.
This just makes things
            //simpler to manage.
            vtkAppendPolyData apd = new vtkAppendPolyData();
            apd.AddInput(glyph.GetOutput());
            apd.AddInput(sphere.GetOutput());
            vtkPolyDataMapper maceMapper = new vtkPolyDataMapper();
            maceMapper.SetInputConnection(apd.GetOutputPort());
            vtkLODActor maceActor = new vtkLODActor();
            maceActor.SetMapper(maceMapper);
            maceActor.VisibilityOn();


            //This portion of the code clips the mace with the vtkPlanes
implicit function.
            //The clipped region is colored green.
             planes = new vtkPlanes();
            vtkClipPolyData clipper = new vtkClipPolyData();
            clipper.SetInputConnection(apd.GetOutputPort());
            clipper.SetClipFunction(planes);
            clipper.InsideOutOn();
            vtkPolyDataMapper selectMapper = new vtkPolyDataMapper();
            selectMapper.SetInputConnection(clipper.GetOutputPort());
             selectActor = new vtkLODActor();
            selectActor.SetMapper(selectMapper);
            selectActor.GetProperty().SetColor(0, 1, 0);
            selectActor.VisibilityOff();
            selectActor.SetScale(1.01, 1.01, 1.01);

            //Create the RenderWindow, Renderer and both Actors

            vtkRenderer ren1 = new vtkRenderer();
            vtkRenderWindow renWin = new vtkRenderWindow();
            renWin.AddRenderer(ren1);

            vtkRenderWindowInteractor iren = new
vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);

            //The SetInteractor method is how 3D widgets are associated with
the render
            //window interactor. Internally, SetInteractor sets up a bunch
of callbacks
            //using the Command/Observer mechanism (AddObserver()).
            boxWidget = new vtkBoxWidget();
            boxWidget.SetInteractor(iren);
            boxWidget.SetPlaceFactor(1.25);

            ren1.AddActor(maceActor);
            ren1.AddActor(selectActor);

            //Add the actors to the renderer, set the background and size

            ren1.SetBackground(0.1, 0.2, 0.4);
            renWin.SetSize(300, 300);





            //Place the interactor initially. The input to a 3D widget is
used to
            //initially position and scale the widget. The
EndInteractionEvent is
            //observed which invokes the SelectPolygons callback.
            boxWidget.SetInput(glyph.GetOutput());
            boxWidget.PlaceWidget();
            iren.AddObserver((uint)vtk.EventIds.EndInteractionEvent, new
vtk.vtkDotNetCallback(SelectPolygons));
            iren.Initialize();







        }
        public static void SelectPolygons(vtk.vtkObject obj, uint eventId,
Object data, IntPtr clientdata)
        {
               boxWidget.GetPlanes( planes);
               selectActor.VisibilityOn();
        }

Best regards

On Sat, Jun 26, 2010 at 1:21 PM, Ali Habib <ali.mahmoud.habib at gmail.com>wrote:

> I wante to cut part using vtk box widget , but the pipeline always fail any
> suggestion please
>
> the code is
>
>         static vtkBoxWidget boxWidget;
>
>         static vtkPlanes planes;
>
>        static  vtkLODActor selectActor;
>
>         static void Main(string[] args)
>         {
>             //Create a mace out of filters.
>
>             vtkSphereSource sphere = new vtkSphereSource();
>             vtkConeSource cone = new vtkConeSource();
>             vtkGlyph3D glyph = new vtkGlyph3D();
>             glyph.SetInputConnection(sphere.GetOutputPort());
>             glyph.SetSource(cone.GetOutput());
>             glyph.SetVectorModeToUseNormal();
>             glyph.SetScaleModeToScaleByVector();
>             glyph.SetScaleFactor(0.25);
>
>             //The sphere and spikes are appended into a single polydata.
> This just makes things
>             //simpler to manage.
>             vtkAppendPolyData apd = new vtkAppendPolyData();
>             apd.AddInput(glyph.GetOutput());
>             apd.AddInput(sphere.GetOutput());
>             vtkPolyDataMapper maceMapper = new vtkPolyDataMapper();
>             maceMapper.SetInputConnection(apd.GetOutputPort());
>             vtkLODActor maceActor = new vtkLODActor();
>             maceActor.SetMapper(maceMapper);
>             maceActor.VisibilityOn();
>
>
>             //This portion of the code clips the mace with the vtkPlanes
> implicit function.
>             //The clipped region is colored green.
>
>
>             //Create the RenderWindow, Renderer and both Actors
>
>             vtkRenderer ren1 = new vtkRenderer();
>             vtkRenderWindow renWin = new vtkRenderWindow();
>             renWin.AddRenderer(ren1);
>
>             vtkRenderWindowInteractor iren = new
> vtkRenderWindowInteractor();
>             iren.SetRenderWindow(renWin);
>
>             //The SetInteractor method is how 3D widgets are associated
> with the render
>             //window interactor. Internally, SetInteractor sets up a bunch
> of callbacks
>             //using the Command/Observer mechanism (AddObserver()).
>             boxWidget = new vtkBoxWidget();
>             boxWidget.SetInteractor(iren);
>             boxWidget.SetPlaceFactor(1.25);
>
>             ren1.AddActor(maceActor);
>             ren1.AddActor(selectActor);
>
>             //Add the actors to the renderer, set the background and size
>
>             ren1.SetBackground(0.1, 0.2, 0.4);
>             renWin.SetSize(300, 300);
>
>
>
>
>
>             //Place the interactor initially. The input to a 3D widget is
> used to
>             //initially position and scale the widget. The
> EndInteractionEvent is
>             //observed which invokes the SelectPolygons callback.
>             boxWidget.SetInput(glyph.GetOutput());
>             boxWidget.PlaceWidget();
>             iren.AddObserver((uint)vtk.EventIds.EndInteractionEvent, new
> vtk.vtkDotNetCallback(SelectPolygons));
>             iren.Initialize();
>
>
>
>
>
>
>
>         }
>         public static void SelectPolygons(vtk.vtkObject obj, uint eventId,
> Object data, IntPtr clientdata)
>         {
>                boxWidget.GetPlanes( planes);
>                selectActor.VisibilityOn();
>         }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100626/dd49a976/attachment.htm>


More information about the vtkusers mailing list