[vtkusers] interact with polydata

Miro Drahos mdrahos at robodoc.com
Fri Aug 2 17:30:54 EDT 2013


Actually, it works just fine. I had an error when applying the 
transformation pipeline :-\
Thanks anyways, and for completeness and perhaps to help someone else, I 
add the relevant code:

myIrenStyle is derived from vtkInteractorStyle, and methods taken from 
vtkInteractorStyleTrackballActor.

//this method is called from Rotate() and Spin()
void myInteractorStyleActing::Prop3DTransform(vtkProp3D *prop3D,
                        double *boxCenter,
                        int numRotation,
                        double **rotate,
                        double *scale)
{
   //==== this is verbatim from vtkInteractorStyleTrackballActor:
   vtkMatrix4x4 *oldMatrix = vtkMatrix4x4::New();
   prop3D->GetMatrix(oldMatrix);

   double orig[3];
   prop3D->GetOrigin(orig);

   vtkTransform *newTransform = vtkTransform::New();
   newTransform->PostMultiply();
   if (prop3D->GetUserMatrix() != NULL)
newTransform->SetMatrix(prop3D->GetUserMatrix());
   else
     newTransform->SetMatrix(oldMatrix);

   newTransform->Translate(-(boxCenter[0]), -(boxCenter[1]), 
-(boxCenter[2]));

   for (int i = 0; i < numRotation; i++)
     newTransform->RotateWXYZ(rotate[i][0], rotate[i][1],
                              rotate[i][2], rotate[i][3]);

   if ((scale[0] * scale[1] * scale[2]) != 0.0)
     newTransform->Scale(scale[0], scale[1], scale[2]);

   newTransform->Translate(boxCenter[0], boxCenter[1], boxCenter[2]);

   // now try to get the composit of translate, rotate, and scale
   newTransform->Translate(-(orig[0]), -(orig[1]), -(orig[2]));
   newTransform->PreMultiply();
   newTransform->Translate(orig[0], orig[1], orig[2]);
//====== end verbatim ====


   if (prop3D->GetUserMatrix() != NULL)
newTransform->GetMatrix(prop3D->GetUserMatrix());
   else
     {
       //I don't want to modify the actor, but the poly itself:
       // prop3D->SetPosition(newTransform->GetPosition());
       // prop3D->SetScale(newTransform->GetScale());
       // prop3D->SetOrientation(newTransform->GetOrientation());

       //get a handle to the polydata:
       vtkActor *actorHandle = vtkActor::SafeDownCast(prop3D);
       vtkPolyData *origPoly = 
vtkPolyData::SafeDownCast(actorHandle->GetMapper()->GetInput());

       //setup transform filter pipeline, and apply
       VTK_CREATE(vtkTransformPolyDataFilter, polyTransformFilter);
       polyTransformFilter->SetTransform(newTransform);
       polyTransformFilter->SetInput(origPoly);
       polyTransformFilter->Update();

       //update the orig poly:
origPoly->DeepCopy(polyTransformFilter->GetOutput());
   }

   oldMatrix->Delete();
   newTransform->Delete();
}

Similarly for Pan() method.
Cheers,
Miro



On 08/02/2013 01:55 PM, Miro Drahos wrote:
> Hi all,
> I am trying to setup interaction with the scene just like using 
> vtkInteractorStyleTrackBallActor, but would like to update the 
> polydata itself, not just the view. In other words, I would like to 
> translate or rotate the polydata points according to the mouse 
> interaction.
> I couldn't find any interactor style that would modify the data 
> position, so I derived my own, and tried to use the transform from 
> vtkInteractorStyleTrackballActor::Prop3DTransform(...) using the 
> newTransform object and applying it (via vtkPolyDataTransformFilter) 
> to the polydata. But this doesn't seem to work as I'd like.
> Can anyone point me in the right direction?
> Thank you very much,
> Miro
>
>
> _______________________________________________
> Powered by 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