1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| #include <vtkPoints.h> #include <vtkSmartPointer.h> #include <vtkLandmarkTransform.h> #include <vtkMatrix4x4.h> #include <vtkPolyDataMapper.h> #include <vtkActor.h> #include <vtkRenderWindow.h> #include <vtkRenderer.h> #include <vtkRenderWindowInteractor.h> #include <vtkProperty.h> #include <vtkTransformPolyDataFilter.h> #include <vtkVertexGlyphFilter.h>
int main(int, char *[]) {
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.02, 0.0}; targetPoints->InsertNextPoint(targetPoint2); double targetPoint3[3] = {-1.11, 0.0, 0.0}; targetPoints->InsertNextPoint(targetPoint3); vtkSmartPointer<vtkLandmarkTransform> landmarkTransform = vtkSmartPointer<vtkLandmarkTransform>::New(); landmarkTransform->SetSourceLandmarks(sourcePoints); landmarkTransform->SetTargetLandmarks(targetPoints); landmarkTransform->SetModeToRigidBody(); landmarkTransform->Update();
vtkSmartPointer<vtkPolyData> source = vtkSmartPointer<vtkPolyData>::New(); source->SetPoints(sourcePoints); vtkSmartPointer<vtkPolyData> target = vtkSmartPointer<vtkPolyData>::New(); target->SetPoints(targetPoints); vtkSmartPointer<vtkVertexGlyphFilter> sourceGlyphFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New(); sourceGlyphFilter->SetInputData(source); sourceGlyphFilter->Update(); vtkSmartPointer<vtkVertexGlyphFilter> targetGlyphFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New(); targetGlyphFilter->SetInputData(target); targetGlyphFilter->Update(); vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); transformFilter->SetInputConnection(sourceGlyphFilter->GetOutputPort()); transformFilter->SetTransform(landmarkTransform); transformFilter->Update(); vtkMatrix4x4* mat = landmarkTransform->GetMatrix(); std::cout << "Matrix: " << *mat << std::endl;
vtkSmartPointer<vtkPolyDataMapper> sourceMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); sourceMapper->SetInputConnection(sourceGlyphFilter->GetOutputPort());
vtkSmartPointer<vtkActor> sourceActor = vtkSmartPointer<vtkActor>::New(); sourceActor->SetMapper(sourceMapper); sourceActor->GetProperty()->SetColor(0,1,0); sourceActor->GetProperty()->SetPointSize(4);
vtkSmartPointer<vtkPolyDataMapper> targetMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); targetMapper->SetInputConnection(targetGlyphFilter->GetOutputPort());
vtkSmartPointer<vtkActor> targetActor = vtkSmartPointer<vtkActor>::New(); targetActor->SetMapper(targetMapper); targetActor->GetProperty()->SetColor(1,0,0); targetActor->GetProperty()->SetPointSize(4); vtkSmartPointer<vtkPolyDataMapper> solutionMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); solutionMapper->SetInputConnection(transformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> solutionActor = vtkSmartPointer<vtkActor>::New(); solutionActor->SetMapper(solutionMapper); solutionActor->GetProperty()->SetColor(0,0,1); solutionActor->GetProperty()->SetPointSize(3); vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(sourceActor); renderer->AddActor(targetActor); renderer->AddActor(solutionActor); renderer->SetBackground(.3, .6, .3);
renderWindow->Render(); renderWindowInteractor->Start(); return EXIT_SUCCESS; }
|