[vtkusers] Several point clouds alignment using ICP

nuno.jf nunofernandes7 at gmail.com
Tue Feb 22 06:53:03 EST 2011


Hi there,

Currently, I need to align and display a set of 58 point clouds (in .wrl
file format) using ICP.
The code I have right now, is the "common" one, which receives two point
clouds and aligns them. 
What I have to do (but don't know how ={ ) is a cycle for ICP to read each
point cloud and align all of them. 
In the end, a volume file of the aligned point clouds must be created.
Can anyone please help me?

Please find attached three wrl files I need to align in a zipped folder
http://vtk.1045678.n5.nabble.com/file/n3395391/hand_teste1_15_12_2010_01_001.wrl
hand_teste1_15_12_2010_01_001.wrl 
http://vtk.1045678.n5.nabble.com/file/n3395391/wrl_files.zip wrl_files.zip
(of the total 58 files).


Thank you very much!

Nuno


----------------ICP CODE I currently have -------------------
// icp

// Iterative Closest Point (VTK)

#include "vtkVRMLImporter.h"
#include "vtkIterativeClosestPointTransform.h"

#include "vtkTransform.h"
#include "vtkTransformPolyDataFilter.h"
#include "vtkLandmarkTransform.h"

#include "vtkPolyDataReader.h" 
#include "vtkPolyDataWriter.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataNormals.h"
#include "vtkSmoothPolyDataFilter.h"
#include "vtkDecimatePro.h"

#include "vtkGaussianSplatter.h"
#include "vtkContourFilter.h"

#include "vtkAxes.h"
#include "vtkTubeFilter.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"

// main function

int main( int argc, char *argv[] )
{

	// Point Cloud 1
	//---------------------------------------------------------
	vtkVRMLImporter *imp1 = vtkVRMLImporter::New();
	imp1 -> SetFileName(
"C:/Users/Nuno/Documents/Faculdade/LIGHTSCAN/bin/ICP/Debug/hand_teste1_15_12_2010_01_001.wrl"
);
	imp1 -> Read();
	imp1 -> Update();
	
	vtkDataSet *pDataset1;
	vtkActorCollection *actors1 = imp1 -> GetRenderer()->GetActors();
	actors1 -> InitTraversal();
	pDataset1 = actors1 -> GetNextActor()->GetMapper()->GetInput();
	
	vtkPolyData *polyData1 = vtkPolyData::SafeDownCast( pDataset1 );
	polyData1 -> Update();

	// Point Cloud 2
	//---------------------------------------------------------
	vtkVRMLImporter *imp2 = vtkVRMLImporter::New();
	imp2 -> SetFileName(
"C:/Users/Nuno/Documents/Faculdade/LIGHTSCAN/bin/ICP/Debug/hand_teste1_15_12_2010_01_003.wrl"
);
	imp2 -> Read();
	imp2 -> Update();
	
	vtkDataSet *pDataset2;
	vtkActorCollection *actors2 = imp2 -> GetRenderer()->GetActors();
	actors2 -> InitTraversal();
	pDataset2 = actors2 -> GetNextActor()->GetMapper()->GetInput();
	
	vtkPolyData *polyData2 = vtkPolyData::SafeDownCast( pDataset2 );
	polyData2 -> Update();

	std::cout << "Number of points in cloud 1 = " << polyData1 ->
GetNumberOfPoints() << std::endl;
	std::cout << "Number of points in cloud 2 = " << polyData2 ->
GetNumberOfPoints() << std::endl;
	
	// ==============================================================
	//
	// ICP - VTK
	//
	// ==============================================================
	
	vtkIterativeClosestPointTransform * icp =
vtkIterativeClosestPointTransform::New();

	// Set SOURCE and TARGET points
	//---------------------------------------------------------
	//icp -> SetTarget( reader_PolyData1 -> GetOutput() );
	//icp -> SetSource( reader_PolyData2 -> GetOutput() );
	icp -> SetTarget( polyData1 );
	icp -> SetSource( polyData2 ); // 
	
	// Configure ICP transform
	//---------------------------------------------------------		
	//icp -> SetStartByMatchingCentroids(1);
	icp -> StartByMatchingCentroidsOff();
	icp -> GetLandmarkTransform()->SetModeToRigidBody();
	//icp -> GetLandmarkTransform()->SetModeToAffine();
	//icp -> SetCheckMeanDistance(1);
	//icp -> SetMeanDistanceModeToAbsoluteValue();
	icp -> SetMeanDistanceModeToRMS();
	icp -> SetMaximumNumberOfLandmarks(2000);
	icp -> SetMaximumNumberOfIterations(250);
	icp -> SetMaximumMeanDistance(0.00001);
	icp -> Update();

	std::cout << "ICP Mean Distance RMS = " << icp -> GetMeanDistance() <<
std::endl;

	// transform SOURCE to obtain TARGET
	//---------------------------------------------------------
	vtkTransformPolyDataFilter * transform = vtkTransformPolyDataFilter::New();
	
	transform -> SetTransform( icp );
	transform -> SetInput( polyData2 );
	transform -> Update();
	
	//transform -> PrintSelf( std::cout, 0);
	std::cout << "ICP transform done." << std::endl;


	// ==============================================================
	//
	// VTK  RENDERING
	//
	// ==============================================================
	vtkRenderer                    *ren = vtkRenderer::New();
	vtkRenderWindow             *renWin = vtkRenderWindow::New();
	vtkRenderWindowInteractor     *iren = vtkRenderWindowInteractor::New();
	renWin  -> AddRenderer(ren);
	iren    -> SetRenderWindow(renWin);
	ren     -> SetBackground(1, 1, 1);
	renWin  -> SetSize(800, 600);

	// axes
	//---------------------------------------------------------
	double axis_scale_factor = 100.0;	// mm
	int num_sides = 6;
	vtkAxes					*axes = vtkAxes::New();
	vtkTubeFilter	   *axesTubes = vtkTubeFilter::New();
	vtkPolyDataMapper *axesMapper = vtkPolyDataMapper::New();
	vtkActor		   *axesActor = vtkActor::New();
	axes		-> SetOrigin( 0.0, 0.0, 0.0 );
	axes		-> SetScaleFactor( axis_scale_factor );
	axesTubes	-> SetInput( axes -> GetOutput());
	axesTubes	-> SetRadius( axes -> GetScaleFactor()/axis_scale_factor );
	axesTubes	-> SetNumberOfSides( num_sides );
	axesMapper	-> SetInput( axesTubes -> GetOutput() );
	axesActor	-> SetMapper( axesMapper );
			
	//ren -> AddActor( axesActor );
	axesMapper -> Delete();
	axesTubes -> Delete();
	axes -> Delete();


	// TARGET - PolyData1 - Points Red
	//---------------------------------------------------------
	vtkPolyDataMapper * rawpointsMapper1 = vtkPolyDataMapper::New();
	vtkActor		   * rawpointsActor1 = vtkActor::New();
	//rawpointsMapper1 -> SetInput( reader_PolyData1 -> GetOutput() );
	rawpointsMapper1 -> SetInput( polyData1 );
	rawpointsMapper1 -> ScalarVisibilityOff(); 
	rawpointsActor1  -> SetMapper( rawpointsMapper1 );
	rawpointsActor1  -> GetProperty() -> SetColor(1, 0, 0); 
	
	ren -> AddActor( rawpointsActor1 );
	rawpointsMapper1 -> Delete();
	

	// SOURCE - PolyData2 - Points Green
	//---------------------------------------------------------
	vtkPolyDataMapper * rawpointsMapper2 = vtkPolyDataMapper::New();
	vtkActor		   * rawpointsActor2 = vtkActor::New();
	
	rawpointsMapper2 -> SetInput( polyData2 );
	rawpointsMapper2 -> ScalarVisibilityOff();
	rawpointsActor2  -> SetMapper( rawpointsMapper2 );
	rawpointsActor2  -> GetProperty() -> SetColor(0, 1, 0); 

	ren -> AddActor( rawpointsActor2 );
	rawpointsMapper2 -> Delete();
	

	// ICP - PolyData2 TRANSFORMED - Points Blue
	//---------------------------------------------------------
	vtkPolyDataMapper * rawpointsMapper3 = vtkPolyDataMapper::New();
	vtkActor		   * rawpointsActor3 = vtkActor::New();
	
	rawpointsMapper3 -> SetInput( transform -> GetOutput() );
	//rawpointsMapper3 -> SetInput( TF -> GetOutput() );
	rawpointsMapper3 -> ScalarVisibilityOff();
	rawpointsActor3  -> SetMapper( rawpointsMapper3 );
	rawpointsActor3  -> GetProperty() -> SetColor(0, 0, 1); 
	
	ren -> AddActor( rawpointsActor3 );
	rawpointsMapper3  -> Delete();
	
	// Surface Rendering

	renWin -> Render();
	iren -> Start();			

	// Delete VTK objects

	ren -> RemoveActor( axesActor );
	ren -> RemoveActor( rawpointsActor1 );
	ren -> RemoveActor( rawpointsActor2 );
	ren -> RemoveActor( rawpointsActor3 );
	
	rawpointsActor1 -> Delete();
	rawpointsActor2 -> Delete();
	rawpointsActor3 -> Delete();

	ren -> Delete();
	iren -> Delete();
	renWin -> Delete();

	/* ============================================================ */
	return 0;

}

-- 
View this message in context: http://vtk.1045678.n5.nabble.com/Several-point-clouds-alignment-using-ICP-tp3395391p3395391.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list