[vtkusers] vtkIterativeClosestPointTransform Hello World

維均 innocentfox at gmail.com
Tue Apr 24 23:21:10 EDT 2007


Hi all,

I've looked into the archive but still can't get
vtkIterativeClosestPointTransform working. I only wish to align two point
clouds, and print out the 6-degree-of-freedom result in any form. Would
anyone come up with a hello-world level solution (in c++), or correct my
code?

Thanks and Thanks and Thanks!

Arnie

My testing program follows.....

////////////////////////////////////
#include <vtk/vtkPoints.h>
#include <vtk/vtkPolyData.h>
#include <vtk/vtkDataSet.h>
#include <vtk/vtkLandmarkTransform.h>
#include <vtk/vtkIterativeClosestPointTransform.h>

using namespace std;
//make_icp by Benedikt
vtkIterativeClosestPointTransform * make_icp(vtkDataSet * source, vtkDataSet
*
target, int iter)
{
        vtkIterativeClosestPointTransform * icp =
                vtkIterativeClosestPointTransform::New();
        icp->SetSource(source);
        icp->SetTarget(target);
        //      icp->DebugOn();
        icp->SetMaximumNumberOfIterations(iter);
        icp->SetMaximumNumberOfLandmarks(source->GetNumberOfPoints());
        icp->SetCheckMeanDistance(1);
        icp->SetMaximumMeanDistance(0.0000001);
        icp->GetLandmarkTransform()->SetModeToRigidBody();
        icp->Modified();
        icp->Update();
        return icp;
};

int main(){
  float x[8][3]={{0,0,0}, {1,0,0}, {1,1,0}, {0,1,0},
                        {0,0,1}, {1,0,1}, {1,1,1}, {0,1,1}};
  vtkPoints *points1 = vtkPoints::New();
  vtkPolyData *cube1 = vtkPolyData::New();
  vtkPoints *points2 = vtkPoints::New();
  vtkPolyData *cube2 = vtkPolyData::New();
  for (int i=0; i<8; i++) points1->InsertPoint(i,x[i]);
  for (int i=0; i<8; i++) points2->InsertPoint(i,x[i]);
  cube1->SetPoints(points1);
  cube2->SetPoints(points2);

  vtkIterativeClosestPointTransform *icp = make_icp( cube1, cube2, 100 );
  icp ->PrintSelf(std::cout,0);

  points1->Delete();
  points2->Delete();
}

//////////END OF CODE///////////
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070425/e2e711ea/attachment.htm>


More information about the vtkusers mailing list