[vtkusers] ICP and parametric surface

raimi87 amich.randa at gmail.com
Tue Aug 9 09:54:48 EDT 2011


hi make this little code but i have some problem after 
build suuceed but debug start working and then "nuage.exe" stopped working 



#include <stdio.h>
#include "vtkActor.h"
#include "vtkCellArray.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkIntArray.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPointSet.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkDelaunay3D.h"
#include "vtkDataSetMapper.h"
#include "vtkOutlineFilter.h"
#include "vtkProperty.h"
#include "vtkIterativeClosestPointTransform.h"
#include "vtkLandmarkTransform.h"
#include "vtkTransformPolyDataFilter.h"
#include "vtkMaskPoints.h"

using namespace std;
int main(int/*argc*/, char ** /*argv*/)

{
	// Read some 3d points.
	FILE *datei = fopen("bs000_N_N_1mesh1remaillage.obj","r");
	vtkDelaunay3D* del_1    = vtkDelaunay3D::New();
	vtkPolyData *polydata_1 = vtkPolyData::New();
	vtkPoints *points = vtkPoints::New();
	vtkDelaunay3D* del_2    = vtkDelaunay3D::New();
	vtkPolyData *polydata_2 = vtkPolyData::New();
	vtkPoints *points_2 = vtkPoints::New();
	
	int iCounter = 0;
	while (!feof(datei))
	{
		fprintf(stdout,"reading points: %i\r", iCounter);
		char a ;
		float x, y, z;
		fscanf(datei,"%c %f %f %f \n",&a , &x, &y, &z);
		if (a == 'v')
		points->InsertPoint(iCounter++, x, y, z);
		//cout<<"x=    "<&lt;x&lt;&lt;&quot;y=    &quot;&lt;&lt;y&lt;&lt;&quot;z=   
&quot;&lt;&lt;z&lt;&lt;endl;
	}
	polydata_1-&gt;SetPoints(points);
	fclose(datei);
	fprintf(stdout,"\n\n");

	
	int num_of_points_1 = polydata_1->GetPoints()->GetNumberOfPoints();
	cout << "in all, num of points in cloud 1 is " << num_of_points_1 << endl;
	del_1->SetInput((vtkPointSet*)polydata_1);
	del_1->SetTolerance(0.01);
	del_1->Update();
	del_1->SetAlpha(0);
	FILE *datei2 = fopen("bs015_N_N_0mesh1.obj","r");
int iCounter2 = 0;

	while (!feof(datei2))
	{
		fprintf(stdout,"reading points: %i\r", iCounter);
		char a ;
		float x, y, z;
		fscanf(datei,"%c %f %f %f \n",&a , &x, &y, &z);
		if (a == 'v')
		points_2->InsertPoint(iCounter2++, x, y, z);
		//cout<<"x=    "<&lt;x&lt;&lt;&quot;y=    &quot;&lt;&lt;y&lt;&lt;&quot;z=   
&quot;&lt;&lt;z&lt;&lt;endl;
	}
	polydata_2-&gt;SetPoints(points_2);
	fclose(datei2);
	fprintf(stdout,"\n\n");
	
	int num_of_points_2 = polydata_1->GetPoints()->GetNumberOfPoints();
	cout << "in all, num of points in cloud 1 is " << num_of_points_2 << endl;
	del_2->SetInput((vtkPointSet*)polydata_2);
	del_2->SetTolerance(0.01);
	del_2->Update();
	del_2->SetAlpha(0);
	

	
	vtkIterativeClosestPointTransform *_icpt =
vtkIterativeClosestPointTransform::New();
	_icpt->GetLandmarkTransform()->SetModeToRigidBody();
	_icpt->StartByMatchingCentroidsOn();
	_icpt->SetMaximumNumberOfIterations(10.);
	
	vtkMaskPoints *maskPoints1 = vtkMaskPoints::New();
 	maskPoints1->SetInput(polydata_1);
 	maskPoints1->SetMaximumNumberOfPoints(402);
 	maskPoints1->GenerateVerticesOn();
	_icpt->SetSource((vtkPolyData *)maskPoints1);
	cout << "Calling icpt" << endl;
	
	vtkMaskPoints *maskPoints2 = vtkMaskPoints::New();
 	maskPoints2->SetInput(polydata_2);
 	maskPoints2->SetMaximumNumberOfPoints(6034);
 	maskPoints2->GenerateVerticesOn();
	_icpt->SetSource((vtkPolyData *)maskPoints2);
	cout << "Calling icpt" << endl;
  	_icpt->SetTarget((vtkPolyData *)maskPoints2);
  	_icpt->SetMeanDistanceModeToAbsoluteValue(); 
	_icpt->Update();
	
	cout << " Mean distance is " << _icpt->GetMeanDistance() << endl;
    cout << "done icpt" << endl;
	vtkTransformPolyDataFilter* transformer =
vtkTransformPolyDataFilter::New();
	transformer->SetTransform(_icpt);
	transformer->SetInput((vtkPolyData*)maskPoints1);
	transformer->Update();
	
	
	//transformer->PrintSelf(std::cout,0);  
	vtkDataSetMapper *surface_mapper_1 = vtkDataSetMapper::New();
	surface_mapper_1->SetInput((vtkDataSet*)maskPoints1->GetOutput());
	
	
	vtkActor* actor_1 = vtkActor::New();
	actor_1->SetMapper(surface_mapper_1);
	actor_1->GetProperty()->SetRepresentationToPoints();
	actor_1->GetProperty()->SetColor(1,1,1);
	
	vtkRenderer* ren = vtkRenderer::New();
	 ren->AddActor(actor_1);
	
	vtkRenderWindow* renWin = vtkRenderWindow::New();
	 renWin->AddRenderer(ren);
	vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
 	 iren->SetRenderWindow(renWin);
  	iren->Initialize();
 	iren->Start();
	
 return 0;



	
	
	
	}


what's wrong with my project 


--
View this message in context: http://vtk.1045678.n5.nabble.com/ICP-and-parametric-surface-tp4681918p4682104.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list