VTK/Examples/LandmarkTransform
From KitwarePublic
< VTK | Examples(Redirected from Landmark Transform)
This example creates two point sets which it assumes are known, ordered correspondences. It then transforms Source to Target and displays the matrix used in the transformation.
Fix: Add CMakeLists.txt
LandmarkTransform.cxx
#include <vtkPoints.h> #include <vtkSmartPointer.h> #include <vtkLandmarkTransform.h> #include <vtkMatrix4x4.h> int main(int argc, char *argv[]) { /* This demo creates a coordinate frame (+x, +y, +z) of vectors and a rotated, peturbed frame (+z, +y, -x) and aligns the rotated frame to the original as best as possible. */ vtkSmartPointer<vtkPoints> sourcePoints = vtkSmartPointer<vtkPoints>::New(); double sourcePoint1[3] = {1.0, 0.0, 0.0}; sourcePoints->InsertNextPoint(sourcePoint1); double sourcePoint2[3] = {0.0, 1.0, 0.0}; sourcePoints->InsertNextPoint(sourcePoint2); double sourcePoint3[3] = {0.0, 0.0, 1.0}; sourcePoints->InsertNextPoint(sourcePoint3); vtkSmartPointer<vtkPoints> targetPoints = vtkSmartPointer<vtkPoints>::New(); double targetPoint1[3] = {0.0, 0.0, 1.1}; targetPoints->InsertNextPoint(targetPoint1); double targetPoint2[3] = {0.0, 1.0, 0.0}; targetPoints->InsertNextPoint(targetPoint2); double targetPoint3[3] = {-1.11, 0.0, 0.0}; targetPoints->InsertNextPoint(targetPoint3); //setup the transform vtkSmartPointer<vtkLandmarkTransform> landmarkTransform = vtkSmartPointer<vtkLandmarkTransform>::New(); landmarkTransform->SetSourceLandmarks(sourcePoints); landmarkTransform->SetTargetLandmarks(targetPoints); landmarkTransform->SetModeToRigidBody(); //display the transformation matrix that was computed vtkMatrix4x4* mat = landmarkTransform->GetMatrix(); vtkstd::cout << "Matrix: " << *mat << vtkstd::endl; vtkSmartPointer<vtkPoints> transformedSourcePoints = vtkSmartPointer<vtkPoints>::New(); landmarkTransform->TransformPoints(sourcePoints, transformedSourcePoints); for(unsigned int i = 0; i < 3; i++) { double origpoint[3]; sourcePoints->GetPoint(i, origpoint); vtkstd::cout << "Original point: (" << origpoint[0] << ", " << origpoint[1] << ", " << origpoint[2] << ")" << vtkst::endl; double transpoint[3]; transformedSourcePoints->GetPoint(i, transpoint); vtkstd::cout << "Transformed point: (" << transpoint[0] << ", " << transpoint[1] << ", " << transpoint[2] << ")" << vtkstd::endl; } return 0; }

