<div dir="ltr">Dear Jim,<div><br></div><div>I made sure that the observers I used work and the algorithm use them </div><div><br></div><div>but the shape not be affected </div><div><br></div><div>Best regards<br><br><div class="gmail_quote">
On Sat, Aug 21, 2010 at 5:17 PM, Jim Peterson <span dir="ltr">&lt;<a href="mailto:jimcp@cox.net">jimcp@cox.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Ali,<br>
Are you sure your interaction events are being invoked? I would put a System.out.Println(&quot;.....&quot;); 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:<br>

<br>
     iren.AddObserver(&quot;UserEvent&quot;,this,&quot;updmeth&quot;);<br>
     ren1.AddObserver(&quot;StartEvent&quot;,this,&quot;startRender&quot;);<br>
     iren.AddObserver(&quot;StartPickEvent&quot;,this,&quot;startPick&quot;);<br>
     iren.AddObserver(&quot;EndPickEvent&quot;,this,&quot;endPick&quot;);<br>
<br>
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.<br>
<br>
I perform the .Modified() call for all of the affected elements of the pipeline. Points, Scalars, and PolyData objects.<div class="im"><br>
<br>
Hope that helps,<br>
Jim<br>
Ali Habib wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Dear Jim<br>
<br>
it didn&#39;t affect , do u have any suggestion or a way to reach my goal <br>
Best regards <br></div><div><div></div><div class="h5">
On Sat, Aug 21, 2010 at 4:44 PM, Jim Peterson &lt;<a href="mailto:jimcp@cox.net" target="_blank">jimcp@cox.net</a> &lt;mailto:<a href="mailto:jimcp@cox.net" target="_blank">jimcp@cox.net</a>&gt;&gt; wrote:<br>
<br>
    Ali,<br>
    I think you need to invoke apd.Modified() before apd.Update() to<br>
    get the changes incorporated in the pipeline.<br>
<br>
    Hope that helps,<br>
    Jim.<br>
<br>
    Ali Habib wrote:<br>
<br>
        I select part of vtkpolydata using vtkboxwidget and<br>
        vtkclippolydata , then I want to change (do displacement) to<br>
        the points be selected  so I search for the points in the<br>
        source polydata and change its position<br>
<br>
        my goal is to for example deform vtkpolydata by stretch<br>
        certain part , the problem is that the shape doesn&#39;t change<br>
        below is the code any suggestion please<br>
               static vtkLODActor selectActor;<br>
               static vtkLODActor maceActor;<br>
               static vtkPlanes planes;<br>
               static vtkClipPolyData clipper;<br>
               static vtkAppendPolyData apd;<br>
<br>
              static double[] center_Before =new double[3];<br>
               static double[] center_After = new double[3];<br>
                 static void Main(string[] args)<br>
               {<br>
                          ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
                          //////////////////////////////////////////////////////// the<br>
        core of cutting tool<br>
        /////////////////////////////////////////////////////////////<br>
                          ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
                   // Create a mace out of filters.<br>
                   vtkSphereSource sphere = new vtkSphereSource();<br>
                   vtkConeSource cone = new vtkConeSource();<br>
                   vtkGlyph3D glyph = new vtkGlyph3D();<br>
                   glyph.SetInput(sphere.GetOutput());<br>
                   glyph.SetSource(cone.GetOutput());<br>
                   glyph.SetVectorModeToUseNormal();<br>
                   glyph.SetScaleModeToScaleByVector();<br>
                   glyph.SetScaleFactor(0.25);<br>
<br>
                   // The sphere and spikes are appended into a single<br>
        polydata. This just<br>
                   // makes things simpler to manage.<br>
                     apd = new vtkAppendPolyData();<br>
                   apd.AddInput(glyph.GetOutput());<br>
                   apd.AddInput(sphere.GetOutput());<br>
<br>
                   vtkPolyDataMapper maceMapper = new vtkPolyDataMapper();<br>
                   maceMapper.SetInput(apd.GetOutput());<br>
                   maceActor = new vtkLODActor();<br>
                   maceActor.SetMapper(maceMapper);<br>
                   maceActor.GetProperty().SetColor(1, 0, 0);<br>
                   maceActor.VisibilityOn();<br>
<br>
                   // This portion of the code clips the mace with the<br>
        vtkPlanes implicit<br>
                   // function.  The clipped region is colored green.<br>
                   planes = new vtkPlanes();<br>
                     clipper = new vtkClipPolyData();<br>
                   clipper.SetInput(apd.GetOutput());<br>
                   clipper.SetClipFunction(planes);<br>
                   clipper.InsideOutOff();<br>
<br>
                   vtkPolyDataMapper selectMapper = new<br>
        vtkPolyDataMapper();<br>
                   selectMapper.SetInput(clipper.GetOutput());<br>
                   selectActor = new vtkLODActor();<br>
                   selectActor.SetMapper(selectMapper);<br>
                   selectActor.GetProperty().SetColor(0, 1, 0);<br>
                   selectActor.VisibilityOff();<br>
                   selectActor.SetScale(1.01, 1.01, 1.01);<br>
<br>
                   // Create the RenderWindow, Renderer and both Actors<br>
                   vtkRenderer ren = new vtkRenderer();<br>
                   vtkRenderWindow renWin = new vtkRenderWindow();<br>
                   renWin.AddRenderer(ren);<br>
<br>
                   vtkRenderWindowInteractor iren = new<br>
        vtkRenderWindowInteractor();<br>
                   iren.SetRenderWindow(renWin);<br>
<br>
                   //The SetInteractor method is how 3D widgets are<br>
        associated with the<br>
                   //render window interactor.  Internally,<br>
        SetInteractor sets up a bunch<br>
                   //of callbacks using the Command/Observer mechanism<br>
        (AddObserver()).<br>
                   vtkBoxWidget boxWidget = new vtkBoxWidget();<br>
                   boxWidget.SetInteractor(iren);<br>
                   boxWidget.SetPlaceFactor(1.25);<br>
                   boxWidget.TranslationEnabledOn();<br>
                   ren.AddActor(maceActor);<br>
                   ren.AddActor(selectActor);<br>
<br>
                   //Add the actors to the renderer, set the<br>
        background and size<br>
                   ren.SetBackground(0.1, 0.2, 0.4);<br>
                   // renWin.SetSize(300, 300);<br>
<br>
                   // Place the interactor initially. The input to a<br>
        3D widget is used to<br>
                   // initially position and scale the widget. The<br>
        &quot;EndInteractionEvent&quot; is<br>
                   // observed which invokes the SelectPolygons callback.<br>
                   boxWidget.SetInput(glyph.GetOutput());<br>
                   boxWidget.PlaceWidget();<br>
                          boxWidget.AddObserver((uint)vtk.EventIds.InteractionEvent,<br>
        new vtk.vtkDotNetCallback(InteractionEvent));<br>
                          boxWidget.AddObserver((uint)vtk.EventIds.EndInteractionEvent,<br>
        new vtk.vtkDotNetCallback(EndInteractionEvent));<br>
<br>
                   boxWidget.On();<br>
                   iren.Initialize();<br>
                   renWin.Render();<br>
                   iren.Start();<br>
                               }<br>
               public static void InteractionEvent(vtk.vtkObject obj,<br>
        uint eventId, Object data, IntPtr clientdata)<br>
               {<br>
                   vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);<br>
                   widget.GetPlanes(planes);<br>
                   selectActor.VisibilityOn();<br>
<br>
<br>
                   vtkPolyData before = new vtkPolyData();<br>
                   widget.GetPolyData(before);<br>
                   center_Before = GetBoundsCenter(before.GetBounds());<br>
<br>
                   //maceActor.VisibilityOff();<br>
                   ///////////// Test writting<br>
        /////////////////////////////////////////////<br>
                   //Write the file<br>
<br>
                   /*vtkXMLPolyDataWriter writer = new<br>
        vtkXMLPolyDataWriter ();<br>
                   writer.SetInputConnection(clipper.GetOutputPort());<br>
                  writer.SetFileName(&quot;disk.vtp&quot;);<br>
                  writer.Write();*/<br>
<br>
<br>
               }<br>
               public static void EndInteractionEvent(vtk.vtkObject<br>
        obj, uint eventId, Object data, IntPtr clientdata)<br>
               {<br>
                   vtkBoxWidget widget = vtkBoxWidget.SafeDownCast(obj);<br>
                    vtkPolyData after = new vtkPolyData();<br>
                    widget.GetPolyData(after);<br>
                    center_After = GetBoundsCenter(after.GetBounds());<br>
<br>
                    ModifyData();<br>
<br>
<br>
               }<br>
<br>
               private static double[] GetBoundsCenter(double[] bounds)<br>
               {<br>
                   double[] center = new double[3];<br>
<br>
                   center[0] = (bounds[0] + bounds[1]) / 2.0;<br>
                   center[1] = (bounds[2] + bounds[3]) / 2.0;<br>
                   center[2] = (bounds[4] + bounds[5]) / 2.0;<br>
<br>
                   return center;<br>
               }<br>
<br>
               private static void ModifyData()<br>
               {<br>
                   double[] Displacement = { center_After[0] -<br>
        center_Before[0], center_After[1] - center_Before[1],<br>
        center_After[2] - center_Before[2] };<br>
<br>
                   int NoOfPoints =<br>
        clipper.GetOutput().GetNumberOfPoints();<br>
<br>
                   for (int i = 0; i &lt; NoOfPoints;i++ )<br>
                   {<br>
                              /////////////////////////////////////////////////////////////////////////////////////<br>
                              apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[0]<br>
        =<br>
                                  apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[0]<br>
        + Displacement[0];<br>
<br>
                              apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[1]<br>
        =<br>
                  apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[1]<br>
        + Displacement[1];<br>
<br>
                              apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[2]<br>
        =<br>
                  apd.GetOutput().GetPoints().GetPoint(apd.GetOutput().FindPoint(clipper.GetOutput().GetPoints().GetPoint(i)))[2]<br>
        + Displacement[2];<br>
<br>
                       apd.Update();<br>
<br>
                   }<br>
                                               }<br>
        ------------------------------------------------------------------------<br>
<br>
        _______________________________________________<br></div></div>
        Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a> &lt;<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>&gt;<div class="im"><br>
<br>
        Visit other Kitware open-source projects at<br>
        <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
        Please keep messages on-topic and check the VTK FAQ at:<br>
        <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
        Follow this link to subscribe/unsubscribe:<br>
        <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
         <br>
<br>
<br>
</div></blockquote>
<br>
</blockquote></div><br></div></div>