[vtkusers] rotation of vtkActor through a matrix

Gomez Herrero, Alberto alberto.gomez-herrero at philips.com
Fri Aug 14 14:35:10 EDT 2009


Hi all,

I solved my problem. I don't know what was wrong, but I just rewrote it simpler. I put both rotations and translations in the reslice axes matrix and it works fine. Here is the code:

transformResliceMatrix->DeepCopy(identityElements);
    
          transformReslice->SetMatrix(transformResliceMatrix);

       resliceAxes->DeepCopy(identityElements);
       
         resliceAxes->SetElement(0,0,normalVector[0]);
         resliceAxes->SetElement(1,0,normalVector[1]);
         resliceAxes->SetElement(2,0,normalVector[2]);

         resliceAxes->SetElement(0,1,tangentVector1[0]);
         resliceAxes->SetElement(1,1,tangentVector1[1]);
         resliceAxes->SetElement(2,1,tangentVector1[2]);

         resliceAxes->SetElement(0,2,tangentVector2[0]);
         resliceAxes->SetElement(1,2,tangentVector2[1]);
         resliceAxes->SetElement(2,2,tangentVector2[2]);

       
          resliceAxes->SetElement(0, 3, initialPointCoordinates[0]);
          resliceAxes->SetElement(1, 3, initialPointCoordinates[1]);
          resliceAxes->SetElement(2, 3, initialPointCoordinates[2]);
-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of Gomez Herrero, Alberto
Sent: Freitag, 14. August 2009 19:33
To: VTK users group
Subject: Re: [vtkusers] rotation of vtkActor through a matrix

Hi,

Just one more thing: if I set the initial point to (0,0,0), It seems to work also for a different set of vectors.

-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of Gomez Herrero, Alberto
Sent: Freitag, 14. August 2009 19:32
To: VTK users group
Subject: Re: [vtkusers] rotation of vtkActor through a matrix

Thanks for your reply,

I tried that method, now I have the correct matrix, but my problem is still there. Let me explain a bit more the full thing.

I want to extract an slice of a volume (vtkImageData). The slice I want to extract is defined by a plane, which is defined by a point (selected by the user with a vtkPointPicker) called initialPoint, and a the normal vector to the plane. At each "pickable" point, I have three vectors, normalVector, tangentVector1 and tangentVector2 (orthogonal to each other), and I want tangentVector2 to be the vector normal to the plane. These are the important pieces of code:

	volumeSlicer = vtkImageReslice::New();
      volumeSlicer->SetInput(volume);

	//Reslice parameters
       volumeSlicer->SetInterpolationModeToLinear();
       volumeSlicer->SetOutputSpacing(spacing[0], spacing[1], spacing[2]);
       volumeSlicer->GetOutput()->UpdateInformation();
       volumeSlicer->TransformInputSamplingOff();
       volumeSlicer->SetOutputDimensionality(2);// extract a slice

	  //The following matrix is initialized as a eye matrix
	  transformResliceMatrix->SetElement(0,0,normalVector[0]);
        transformResliceMatrix->SetElement(1,0,normalVector[1]);
        transformResliceMatrix->SetElement(2,0,normalVector[2]);

        transformResliceMatrix->SetElement(0,1,tangentVector1[0]);
        transformResliceMatrix->SetElement(1,1,tangentVector1[1]);
        transformResliceMatrix->SetElement(2,1,tangentVector1[2]);

        transformResliceMatrix->SetElement(0,2,tangentVector2[0]);
        transformResliceMatrix->SetElement(1,2,tangentVector2[1]);
        transformResliceMatrix->SetElement(2,2,tangentVector2[2]);

	  //The following matrix is initialized as a eye matrix
	    resliceAxes->SetElement(0, 3, initialPointCoordinates[0]);
          resliceAxes->SetElement(1, 3, initialPointCoordinates[1]);
          resliceAxes->SetElement(2, 3, initialPointCoordinates[2]);

	 transformReslice->SetMatrix(transformResliceMatrix);

	   volumeSlicer->SetResliceTransform(transformReslice);

        volumeSlicer->SetResliceAxes(resliceAxes);

	// Set the output origin
		double inputOrigin[4];
          inputOrigin[0]=volume->GetOrigin()[0];
          inputOrigin[1]=volume->GetOrigin()[1];
          inputOrigin[2]=volume->GetOrigin()[2];
          inputOrigin[3]=1;

        double outputOrigin[4]={0,0,0,0};
            vtkMatrix4x4 *tmp = vtkMatrix4x4::New();
            tmp->DeepCopy(volumeSlicer->GetResliceAxes());
            tmp->Invert();
            tmp->MultiplyPoint(inputOrigin,outputOrigin);

		//... The image actor pipeline is correctly set up
	   sliceActorMatrix->DeepCopy(transformResliceMatrix);
          sliceActorMatrix->SetElement(0,3,initialPointCoordinates[0]);
          sliceActorMatrix->SetElement(1,3,initialPointCoordinates[1]);
          sliceActorMatrix->SetElement(2,3,initialPointCoordinates[2]);

     	     imageActor->SetUserMatrix(sliceActorMatrix);
          imageActor->SetOrigin(initialPointCoordinates);


If my normalVector, tangentVector1 and tangentVector2 are the canonical base (100,010, 001) everything works fine, but if I choose a different set of orthogonal vectors, the slice is not right. I superpose it to a mesh to visualize the results. The slice orientation is ok (i.e. it is parallel to the axes I defined) but I seems like it is translated with respect to the volume. Any idea of what is wrong?

-----Original Message-----
From: Miguel Angel Rodriguez Florido [mailto:marf at itccanarias.org] 
Sent: Freitag, 14. August 2009 16:59
To: Gomez Herrero, Alberto
Cc: VTK users group
Subject: Re: [vtkusers] rotation of vtkActor through a matrix

	Hi,

	Have you tried the vtkActor's methods SetUserTransform or SetUserMatrix?

	Hth.

Gomez Herrero, Alberto wrote:
> Hi all,
> 
> is there any way of applying a transformation to a vtkActor using a 4x4 matrix? The pokeMatrix() method does not work as I expected. If I do
> 
> actor->pokeMatrix(transformationMatrix)
> 
> and nothing else, the position is set to (0,0,0). If I do
> 
> actor->pokeMatrix(transformationMatrix)
> actor->SetPosition(position)
> 
> and then I print the matrix with
> 
> std::cout << *(actor->GetMatrix()) << std::endl;
> 
> then the 4th column of the matrix, which is supposed to be the position given with SetPosition, is not that.
> 
> If there is not any method for appliying a matrix, could anyone give me some light on how to pass from a matrix to angles around x, y and z so I can use the RotateX, RotateY and RotateZ methods?
> 
> Thank you very much,
> 
> Alberto
> 
> The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
> _______________________________________________
> 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

-- 
Miguel Angel Rodríguez Florido
Departamento de Ingeniería del Software
División de Investigación y Desarrollo Tecnológico
INSTITUTO TECNOLOGICO DE CANARIAS, S.A. - GOBIERNO DE CANARIAS
www.itccanarias.org t: +34 928 727548/457462, f: +34 928 727517

--------------------------------------------------------------------------
AVISO LEGAL:
Este mensaje y los ficheros adjuntos si los hubiere, se dirigen 
exclusivamente a su destinatario y puede contener información 
privilegiada o confidencial. La transmisión errónea del presente mensaje 
en ningún momento supone renuncia a su confidencialidad. Si no es vd. el 
destinatario indicado, queda notificado de que la utilización, 
divulgación y/o copia sin autorización está prohibida en virtud de la 
legislación vigente. Si ha recibido este mensaje por error, le rogamos 
que nos lo comunique inmediatamente por esta misma vía y proceda a su 
destrucción.

LEGAL WARNING:
This message and the files attached if there were any, are intended 
exclusively for its addressee and may contain information that is 
CONFIDENTIAL and protected by professional privilege. A wrong 
transmission to this message don't suppose we relinquished to It's 
confidential. If you are not the intended recipient you are hereby 
notified that any dissemination, copy or disclosure of this 
communication is strictly prohibited by law. If this message has been 
received in error, please immediately notify us via e-mail and delete it.




_______________________________________________
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
_______________________________________________
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