[vtkusers] conversion vtkPolydata(triangle ) to vtkPoints
agatte
agatakrason at gmail.com
Sat May 12 06:01:22 EDT 2012
Hi All ;)
I am fresh user of vtk. I have already created mesh and saved in vtk file
(vtkPolydata)
Now, I want to make IterativeClosestPointsTransform example.
I have impression that I need convert my data to vtkPoint / vtkXMLPolydata ?
Here my data :
# vtk DataFile Version 3.0
vtk output
ASCII
DATASET POLYDATA
POINTS 361359 float
-2.3387 -167.527 -400.25 -1.47737 -167.527 -400.25 -0.616043 -167.527
-400.25
0.245285 -167.527 -400.25 1.10661 -167.527 -400.25 1.96794 -167.527 -400.25
2.82927 -167.527 -400.25 3.6906 -167.527 -400.25 4.55192 -167.527 -400.25
5.41325 -167.527 -400.25 6.27458 -167.527 -400.25 7.13591 -167.527 -400.25
7.99724 -167.527 -400.25 8.85856 -167.527 -400.25 9.71989 -167.527 -400.25
10.5812 -167.527 -400.25 11.4425 -167.527 -400.25 12.3039 -167.527 -400.25
................
I want to do this example :
int main(int argc, char *argv[])
{
vtkSmartPointer<vtkPolyData> source =
vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPolyData> target =
vtkSmartPointer<vtkPolyData>::New();
if(argc == 3)
{
std::cout << "Reading data..." << std::endl;
std::string strSource = argv[1];
std::string strTarget = argv[2];
argv[1]="mesh1.vtk";
argv[2]="mesh2.vtk";
vtkSmartPointer<vtkXMLPolyDataReader> sourceReader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
sourceReader->SetFileName(strSource.c_str());
sourceReader->Update();
source->ShallowCopy(sourceReader->GetOutput());
vtkSmartPointer<vtkXMLPolyDataReader> targetReader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
targetReader->SetFileName(strTarget.c_str());
targetReader->Update();
target->ShallowCopy(targetReader->GetOutput());
}
// Setup ICP transform
vtkSmartPointer<vtkIterativeClosestPointTransform> icp =
vtkSmartPointer<vtkIterativeClosestPointTransform>::New();
icp->SetSource(source);
icp->SetTarget(target);
icp->GetLandmarkTransform()->SetModeToRigidBody();
icp->SetMaximumNumberOfIterations(20);
//icp->StartByMatchingCentroidsOn();
icp->Modified();
icp->Update();
// Get the resulting transformation matrix (this matrix takes the source
points to the target points)
vtkSmartPointer<vtkMatrix4x4> m = icp->GetMatrix();
std::cout << "The resulting matrix is: " << *m << std::endl;
// Transform the source points by the ICP solution
vtkSmartPointer<vtkTransformPolyDataFilter> icpTransformFilter =
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
#if VTK_MAJOR_VERSION <= 5
icpTransformFilter->SetInput(source);
#else
icpTransformFilter->SetInputData(source);
#endif
icpTransformFilter->SetTransform(icp);
icpTransformFilter->Update();
/*
// If you need to take the target points to the source points, the matrix
is:
icp->Inverse();
vtkSmartPointer<vtkMatrix4x4> minv = icp->GetMatrix();
std::cout << "The resulting inverse matrix is: " << *minv << std::cout;
*/
// Visualize
vtkSmartPointer<vtkPolyDataMapper> sourceMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
sourceMapper->SetInputConnection(source->GetProducerPort());
#else
sourceMapper->SetInputData(source);
#endif
vtkSmartPointer<vtkActor> sourceActor =
vtkSmartPointer<vtkActor>::New();
sourceActor->SetMapper(sourceMapper);
sourceActor->GetProperty()->SetColor(1,0,0);
sourceActor->GetProperty()->SetPointSize(4);
vtkSmartPointer<vtkPolyDataMapper> targetMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
targetMapper->SetInputConnection(target->GetProducerPort());
#else
targetMapper->SetInputData(target);
#endif
vtkSmartPointer<vtkActor> targetActor =
vtkSmartPointer<vtkActor>::New();
targetActor->SetMapper(targetMapper);
targetActor->GetProperty()->SetColor(0,1,0);
targetActor->GetProperty()->SetPointSize(4);
vtkSmartPointer<vtkPolyDataMapper> solutionMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
solutionMapper->SetInputConnection(icpTransformFilter->GetOutputPort());
vtkSmartPointer<vtkActor> solutionActor =
vtkSmartPointer<vtkActor>::New();
solutionActor->SetMapper(solutionMapper);
solutionActor->GetProperty()->SetColor(0,0,1);
solutionActor->GetProperty()->SetPointSize(3);
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actor to the scene
renderer->AddActor(sourceActor);
renderer->AddActor(targetActor);
renderer->AddActor(solutionActor);
renderer->SetBackground(.3, .6, .3); // Background color green
// Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
I would appreciate for any help please ;)
--
View this message in context: http://vtk.1045678.n5.nabble.com/conversion-vtkPolydata-triangle-to-vtkPoints-tp5706915.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list