[vtkusers] Change color of displayed mesh in visu of ICP registration

agatte agatakrason at gmail.com
Sat Jul 27 17:16:51 EDT 2013


Hi,


I have a problem to chanhe display color of mesh in visu of result
registration icp.
I followed one of examples from vtk - wiki. 
I was trying to change in :
sourceActor->GetProperty->SetColor(1,2,3); // 
But it didn't work ;/ It didn't change.
I need to have different color of meshes to see a difference after applying
transform.

Could anyone help me please ?

I would appreciate for any help please.

Here I attached a little changed code of this example :

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

	vtkSmartPointer<vtkPolyData> source = 
		vtkSmartPointer<vtkPolyData>::New();
	vtkSmartPointer<vtkPolyData> target =
		vtkSmartPointer<vtkPolyData>::New();


	std::cout<<" Reading data ..."<<std::endl;
	std::string strSource = &quot;outputMeshXML.vtp&quot;;
	std::string strTarget = &quot;outputMeshXML2.vtp&quot;;

	vtkSmartPointer&lt;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->GetLandmarkTransform()->SetModeToAffine();
  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 by the ICP solution
  vtkSmartPointer&lt;vtkTransformPolyDataFilter> icpTransformFilter = 
	  vtkSmartPointer<vtkTransformPolyDataFilter>::New();

#if VTK_MAJOR_VERSION <= 5
  icpTransformFilter->SetInput(source);
#else
   icpTranformFilter->SetInputData(source);
#endif
  icpTransformFilter->SetTransform(icp);
  icpTransformFilter->Update();

  // 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,1,1);
 sourceActor->GetProperty()->SetPointSize(3);

 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(2,1,2);
 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.4,0.4,0.4);
 solutionActor->GetProperty()->SetPointSize(3);

 // Create a render, 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);

 sourceActor->GetProperty()->SetColor(1.0, 1.0, 1.0);
 
 // Add the actor to the scene
 renderer->AddActor(sourceActor);
 renderer->AddActor(targetActor);
 renderer->AddActor(solutionActor);

 renderer->SetBackground(.3, .6, .3);

 // Render and interact
 renderWindow->Render();
 renderWindowInteractor->Start();

 return EXIT_SUCCESS;



}


agatte

I attached photo.

Skin_mesh_surface.png
<http://vtk.1045678.n5.nabble.com/file/n5722285/Skin_mesh_surface.png>  

 



--
View this message in context: http://vtk.1045678.n5.nabble.com/Change-color-of-displayed-mesh-in-visu-of-ICP-registration-tp5722285.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list