[vtkusers] why the vtkpolydata can't be updated

Jim Peterson jimcp at cox.net
Sat Aug 21 10:17:32 EDT 2010


Ali,
Are you sure your interaction events are being invoked? I would put a 
System.out.Println("....."); message in the callback routines to be sure 
you are going through there first. I am a relative Vtk rookie myself, 
but I do use java callbacks to animate vtk objects from Java tabular 
data. I use the callbacks from the renderer and interaction window 
respectivelym iren is an instance of vtkRenderWindowInteractor and ren1 
is an instance of vtkRenderer:

      iren.AddObserver("UserEvent",this,"updmeth");
      ren1.AddObserver("StartEvent",this,"startRender");
      iren.AddObserver("StartPickEvent",this,"startPick");
      iren.AddObserver("EndPickEvent",this,"endPick");

The UserEvent responds to the U key interaction and allows me to toggle 
the animation on and off, the StartEvent of the renderer is where I  
modify my pipeline elements.

I perform the .Modified() call for all of the affected elements of the 
pipeline. Points, Scalars, and PolyData objects.

Hope that helps,
Jim
Ali Habib wrote:
> Dear Jim
>
> it didn't affect , do u have any suggestion or a way to reach my goal 
>
> Best regards 
>
> On Sat, Aug 21, 2010 at 4:44 PM, Jim Peterson <jimcp at cox.net 
> <mailto:jimcp at cox.net>> wrote:
>
>     Ali,
>     I think you need to invoke apd.Modified() before apd.Update() to
>     get the changes incorporated in the pipeline.
>
>     Hope that helps,
>     Jim.
>
>     Ali Habib wrote:
>
>         I select part of vtkpolydata using vtkboxwidget and
>         vtkclippolydata , then I want to change (do displacement) to
>         the points be selected  so I search for the points in the
>         source polydata and change its position
>
>         my goal is to for example deform vtkpolydata by stretch
>         certain part , the problem is that the shape doesn't change
>         below is the code any suggestion please
>                static vtkLODActor selectActor;
>                static vtkLODActor maceActor;
>                static vtkPlanes planes;
>                static vtkClipPolyData clipper;
>                static vtkAppendPolyData apd;
>
>               static double[] center_Before =new double[3];
>                static double[] center_After = new double[3];
>                  static void Main(string[] args)
>                {
>                  
>          ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>                  
>          //////////////////////////////////////////////////////// the
>         core of cutting tool
>         /////////////////////////////////////////////////////////////
>                  
>          ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>                    // Create a mace out of filters.
>                    vtkSphereSource sphere = new vtkSphereSource();
>                    vtkConeSource cone = new vtkConeSource();
>                    vtkGlyph3D glyph = new vtkGlyph3D();
>                    glyph.SetInput(sphere.GetOutput());
>                    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.
>                      apd = new vtkAppendPolyData();
>                    apd.AddInput(glyph.GetOutput());
>                    apd.AddInput(sphere.GetOutput());
>
>                    vtkPolyDataMapper maceMapper = new vtkPolyDataMapper();
>                    maceMapper.SetInput(apd.GetOutput());
>                    maceActor = new vtkLODActor();
>                    maceActor.SetMapper(maceMapper);
>                    maceActor.GetProperty().SetColor(1, 0, 0);
>                    maceActor.VisibilityOn();
>
>                    // This portion of the code clips the mace with the
>         vtkPlanes implicit
>                    // function.  The clipped region is colored green.
>                    planes = new vtkPlanes();
>                      clipper = new vtkClipPolyData();
>                    clipper.SetInput(apd.GetOutput());
>                    clipper.SetClipFunction(planes);
>                    clipper.InsideOutOff();
>
>                    vtkPolyDataMapper selectMapper = new
>         vtkPolyDataMapper();
>                    selectMapper.SetInput(clipper.GetOutput());
>                    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 ren = new vtkRenderer();
>                    vtkRenderWindow renWin = new vtkRenderWindow();
>                    renWin.AddRenderer(ren);
>
>                    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()).
>                    vtkBoxWidget boxWidget = new vtkBoxWidget();
>                    boxWidget.SetInteractor(iren);
>                    boxWidget.SetPlaceFactor(1.25);
>                    boxWidget.TranslationEnabledOn();
>                    ren.AddActor(maceActor);
>                    ren.AddActor(selectActor);
>
>                    //Add the actors to the renderer, set the
>         background and size
>                    ren.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();
>                  
>          boxWidget.AddObserver((uint)vtk.EventIds.InteractionEvent,
>         new vtk.vtkDotNetCallback(InteractionEvent));
>                  
>          boxWidget.AddObserver((uint)vtk.EventIds.EndInteractionEvent,
>         new vtk.vtkDotNetCallback(EndInteractionEvent));
>
>                    boxWidget.On();
>                    iren.Initialize();
>                    renWin.Render();
>                    iren.Start();
>                                }
>                public static void InteractionEvent(vtk.vtkObject obj,
>         uint eventId, Object data, IntPtr clientdata)
>                {
>                    vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);
>                    widget.GetPlanes(planes);
>                    selectActor.VisibilityOn();
>
>
>                    vtkPolyData before = new vtkPolyData();
>                    widget.GetPolyData(before);
>                    center_Before = GetBoundsCenter(before.GetBounds());
>
>                    //maceActor.VisibilityOff();
>                    ///////////// Test writting
>         /////////////////////////////////////////////
>                    //Write the file
>
>                    /*vtkXMLPolyDataWriter writer = new
>         vtkXMLPolyDataWriter ();
>                    writer.SetInputConnection(clipper.GetOutputPort());
>                   writer.SetFileName("disk.vtp");
>                   writer.Write();*/
>
>
>                }
>                public static void EndInteractionEvent(vtk.vtkObject
>         obj, uint eventId, Object data, IntPtr clientdata)
>                {
>                    vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);
>                     vtkPolyData after = new vtkPolyData();
>                     widget.GetPolyData(after);
>                     center_After = GetBoundsCenter(after.GetBounds());
>
>                     ModifyData();
>
>
>                }
>
>                private static double[] GetBoundsCenter(double[] bounds)
>                {
>                    double[] center = new double[3];
>
>                    center[0] = (bounds[0] + bounds[1]) / 2.0;
>                    center[1] = (bounds[2] + bounds[3]) / 2.0;
>                    center[2] = (bounds[4] + bounds[5]) / 2.0;
>
>                    return center;
>                }
>
>                private static void ModifyData()
>                {
>                    double[] Displacement = { center_After[0] -
>         center_Before[0], center_After[1] - center_Before[1],
>         center_After[2] - center_Before[2] };
>
>                    int NoOfPoints =
>         clipper.GetOutput().GetNumberOfPoints();
>
>                    for (int i = 0; i < NoOfPoints;i++ )
>                    {
>                      
>          /////////////////////////////////////////////////////////////////////////////////////
>                      
>          apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[0]
>         =
>                          
>          apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[0]
>         + Displacement[0];
>
>                      
>          apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[1]
>         =
>          
>          apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[1]
>         + Displacement[1];
>
>                      
>          apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[2]
>         =
>          
>          apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[2]
>         + Displacement[2];
>
>                        apd.Update();
>
>                    }
>                                                }
>         ------------------------------------------------------------------------
>
>         _______________________________________________
>         Powered by www.kitware.com <http://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
>          
>
>
>




More information about the vtkusers mailing list