[vtkusers] Iterative closest point transform for point clouds - need some help
Sylvain Jaume
sylvain.jaume at kitware.com
Tue Nov 8 17:34:29 EST 2005
Hi Vikas,
You could define one vertex for every point in your input polydata.
You may as well use the attached code.
Cheers,
Sylvain
Vikas Singh wrote:
>Hi Sylvain:
>
>I am sorry but your suggestions are not helping me solve the problem.
>I just started on VTK yesterday, maybe I do not know VTK well enough
>to understand what you're trying to tell me :-)
>
>For instance, your suggestion
>vtkMaskPoints *maskPoints1 = vtkMaskPoints::New();
>maskPoints1->SetInput(polyData1);
>maskPoints1->SetMaximumNumberOfPoints(500);
>maskPoints1->GenerateVerticesOn();
>
>_icpt->SetSource(maskPoints1);
>
>does not compile. When I replace the last line by typecasting
>maskPoints1 it gives me a seg-fault same as before. I am attaching the
>code - its only about 50-60 lines. See if you can help me here.
>
>regards,
>
>Vikas.
>
>On 11/7/05, Sylvain Jaume <sylvain.jaume at kitware.com> wrote:
>
>
>>Hi Vikas,
>>
>>You could try to create vertices with vtkMaskPoints before the ICP filter:
>>
>>vtkMaskPoints *maskPoints = vtkMaskPoints::New();
>>maskPoints->SetInput(polyData1);
>>maskPoints->SetMaximumNumberOfPoints(numPoints);
>>maskPoints->GenerateVerticesOn();
>>
>>You don't need to cast polyData1. Use vtkPolyDataMaper instead of
>>vtkDataSetMapper.
>>
>>Cheers,
>>Sylvain
>>
>>Vikas Singh wrote:
>>
>>
>>
>>>Hi Sylvain:
>>>
>>>Unfortunately, that doesnt work. I mentioned that in my email
>>>(attached below) that if I do not do a delaunay triangulation and call
>>>icpt directly as
>>>
>>>_icpt->SetSource(polydata_1);
>>>_icpt->SetTarget(polydata_2);
>>>
>>>it gives me a segmentation fault and the following error message:
>>>ERROR: In /usr/local/VTK/Filtering/vtkCellLocator.cxx, line 1190
>>>vtkCellLocator (0x8093b88): No cells to subdivide.
>>>
>>>Same error message even if I typecast it.
>>>
>>>But If I do a Delaunay, I avoid the error message and seg fault.
>>>However, after applying the transformation on the source cloud set, I
>>>cannot see the point set when it renders it.
>>>See partial code below:
>>>
>>>// Iterative Closest Point Transform
>>> vtkIterativeClosestPointTransform *_icpt =
>>>vtkIterativeClosestPointTransform::New();
>>> _icpt->GetLandmarkTransform()->SetModeToRigidBody();
>>> _icpt->StartByMatchingCentroidsOn();
>>> _icpt->SetMaximumNumberOfIterations(100.);
>>>
>>>// del_1 and del_2 are the delaunay triangulations for first and
>>>second point clouds.
>>> _icpt->SetSource((vtkDataSet *)del_1->GetOutput());
>>> cout << "Calling icpt" << endl;
>>> _icpt->SetTarget((vtkDataSet *)del_2->GetOutput());
>>>
>>> _icpt->Update();
>>>
>>> cout << "done icpt" << endl;
>>>
>>> // Now lets tranform the data
>>> vtkTransformPolyDataFilter* transformer = vtkTransformPolyDataFilter::New();
>>> transformer->SetTransform(_icpt);
>>>
>>> transformer->SetInput((vtkPolyData*)polydata_1);
>>> transformer->Update();
>>> transformer->PrintSelf(std::cout,0);
>>>
>>> // map for displaying
>>>
>>> vtkDataSetMapper *surface_mapper_1 = vtkDataSetMapper::New();
>>>
>>> //surface_mapper_1->SetInput((vtkDataSet*)del_1->GetOutput());
>>> // if i do this ^^^^^^^^^^^^^ it shows the untransformed first point cloud
>>> // and the one below does not show anything (I want it to show the
>>> // the transformed (aligned) point cloud
>>> surface_mapper_1->SetInput(transformer->GetOutput());
>>>
>>> vtkDataSetMapper *surface_mapper_2 = vtkDataSetMapper::New();
>>> surface_mapper_2->SetInput((vtkDataSet*)_icpt->GetTarget());
>>>
>>> // Create an actor for cloud 1.
>>> vtkActor* actor_1 = vtkActor::New();
>>> actor_1->SetMapper(surface_mapper_1);
>>> actor_1->GetProperty()->SetRepresentationToPoints();
>>> actor_1->GetProperty()->SetColor(1,1,1);
>>>
>>> // create an actor for cloud 2
>>> vtkActor* actor_2 = vtkActor::New();
>>> actor_2->SetMapper(surface_mapper_2);
>>> actor_2->GetProperty()->SetRepresentationToPoints();
>>> actor_2->GetProperty()->SetColor(0,1,1);
>>>
>>>......and then the rendering part.
>>>
>>>
>>>Any suggestions ?
>>>
>>>--Vikas
>>>
>>>
>>>On 11/7/05, Sylvain Jaume <sylvain.jaume at kitware.com> wrote:
>>>
>>>
>>>
>>>
>>>>Hi Vikas,
>>>>
>>>>vtkIterativeClosestPointTransform gives a transform. You need to apply
>>>>the resulting transform to your input dataset using
>>>>vtkTransformPolyDataFilter. You don't need to use vtkDelaunay3D, nor to
>>>>type cast your datasets.
>>>>
>>>>Cheers,
>>>>Sylvain
>>>>
>>>>Vikas Singh wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>Hello!
>>>>>
>>>>>I am a newbie to VTK and need some help with ICPT. Been trying all
>>>>>sorts of things since today morning including the VTK User's guide and
>>>>>the online documentation but nothing has worked so far. Seems to me
>>>>>that the problem is simple for someone who knows VTK well.
>>>>>
>>>>>I am trying to randomly generate point clouds and align them (as a start).
>>>>>
>>>>>vtkPolyData* polydata_1 = vtkPolyData::New();
>>>>>vtkDelaunay3D* del_1 = vtkDelaunay3D::New();
>>>>>vtkPoints* cloud_1 = vtkPoints::New();
>>>>>
>>>>>static float mypoint_1[3];
>>>>>
>>>>>for (int i = 0; i < 50; i++)
>>>>> {
>>>>> mypoint_1[0] = drand48()*50;
>>>>> mypoint_1[1] = drand48()*50;
>>>>> mypoint_1[2] = drand48()*50;
>>>>>
>>>>> cloud_1->InsertNextPoint(mypoint_1);
>>>>> }
>>>>>
>>>>>polydata_1->SetPoints(cloud_1);
>>>>>
>>>>>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->PrintSelf(std::cout,0);
>>>>>
>>>>>I repeat the same for cloud 2 - variable names end with "_2".
>>>>>
>>>>>
>>>>>Then I call ICPT as follows:
>>>>>
>>>>>vtkIterativeClosestPointTransform *_icpt =
>>>>>vtkIterativeClosestPointTransform::New();
>>>>>_icpt->GetLandmarkTransform()->SetModeToRigidBody();
>>>>>_icpt->StartByMatchingCentroidsOn();
>>>>>_icpt->SetMaximumNumberOfIterations(10);
>>>>>
>>>>>_icpt->SetSource((vtkDataSet *)del_1->GetOutput());
>>>>>cout << "Calling icpt" << endl;
>>>>>_icpt->SetTarget((vtkDataSet *)del_2->GetOutput());
>>>>>
>>>>>_icpt->Update();
>>>>>
>>>>>
>>>>>To this it gives me an error
>>>>>
>>>>>ERROR: In /usr/local/VTK/Hybrid/vtkIterativeClosestPointTransform.cxx, line 274
>>>>>vtkIterativeClosestPointTransform (0x80650e0): Can't execute with NULL or empty
>>>>>input
>>>>>
>>>>>I think that up until the delaunay triangulation, it is working ok - I
>>>>>rendered it and it is alright. If I do not do a delaunay triangulation
>>>>>and typecast cloud_1 and cloud_2 directly it never returns from ICPT.
>>>>>
>>>>>any pointers, please?
>>>>>
>>>>>VS.
>>>>>_______________________________________________
>>>>>This is the private VTK discussion list.
>>>>>Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>>>Follow this link to subscribe/unsubscribe:
>>>>>http://www.vtk.org/mailman/listinfo/vtkusers
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>_______________________________________________
>>>This is the private VTK discussion list.
>>>Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>Follow this link to subscribe/unsubscribe:
>>>http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>>
>>>
>>>
>>>
>>------------------------------------------------------------------------
>>
>>// This example demonstrate the use of VTK data arrays as attribute
>>// data as well as field data. It creates geometry (vtkPolyData) as
>>// well as attribute data explicitly.
>>
>>// first include the required header files for the vtk classes we are using
>>#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[] )
>>{
>> srand48(time(NULL));
>> cout << "Program Starting" << endl;
>>
>> // Create the dataset. In this case, we create a vtkPolyData for first point cloud
>> vtkPolyData* polydata_1 = vtkPolyData::New();
>> vtkDelaunay3D* del_1 = vtkDelaunay3D::New();
>> vtkPoints* cloud_1 = vtkPoints::New();
>>
>> static float mypoint_1[3];
>>
>> for (int i = 0; i < 500; i++)
>> {
>> mypoint_1[0] = drand48()*50;
>> mypoint_1[1] = drand48()*50;
>> mypoint_1[2] = drand48()*50;
>>
>> cloud_1->InsertNextPoint(mypoint_1);
>> }
>>
>> polydata_1->SetPoints(cloud_1);
>>
>> 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);
>> //del_1->BoundingTriangulationOn();
>> //del_1->PrintSelf(std::cout,0);
>>
>> // finished dealing with the first point cloud
>>
>>
>> // Create the dataset. In this case, we create a vtkPolyData for second point cloud
>> vtkPolyData* polydata_2 = vtkPolyData::New();
>> vtkDelaunay3D* del_2 = vtkDelaunay3D::New();
>> vtkPoints* cloud_2 = vtkPoints::New();
>>
>> static float mypoint_2[3];
>>
>> for (int i = 0; i < 500; i++)
>> {
>> mypoint_2[0] = drand48()*50;
>> mypoint_2[1] = drand48()*50;
>> mypoint_2[2] = drand48()*50;
>>
>> cloud_2->InsertNextPoint(mypoint_2);
>> }
>>
>> polydata_2->SetPoints(cloud_2);
>>
>> int num_of_points_2 = polydata_2->GetPoints()->GetNumberOfPoints();
>> cout << "in all, num of points in cloud 2 is " << num_of_points_2 << endl;
>>
>> del_2->SetInput(polydata_2);
>> del_2->SetTolerance(0.01);
>> del_2->Update();
>> del_2->SetAlpha(0);
>> //del_1->BoundingTriangulationOn();
>> //del_2->PrintSelf(std::cout,0);
>>
>> // finished dealing with the second point cloud
>>
>>
>> // Iterative Closest Point Transform
>> vtkIterativeClosestPointTransform *_icpt = vtkIterativeClosestPointTransform::New();
>> _icpt->GetLandmarkTransform()->SetModeToRigidBody();
>> _icpt->StartByMatchingCentroidsOn();
>> //_icpt->SetMaximumMeanDistance(atof(MaxMeanDist->Text.c_str()));
>> _icpt->SetMaximumNumberOfIterations(10.);
>> //_icpt->SetMaximumNumberOfLandmarks(atof(MaxNLandmarks->Text.c_str()));
>>
>> vtkMaskPoints *maskPoints1 = vtkMaskPoints::New();
>> maskPoints1->SetInput(polydata_1);
>> maskPoints1->SetMaximumNumberOfPoints(500);
>> maskPoints1->GenerateVerticesOn();
>>
>> vtkMaskPoints *maskPoints2 = vtkMaskPoints::New();
>> maskPoints2->SetInput(polydata_2);
>> maskPoints2->SetMaximumNumberOfPoints(500);
>> maskPoints2->GenerateVerticesOn();
>>
>> //_icpt->SetSource((vtkDataSet *)del_1->GetOutput());
>> _icpt->SetSource((vtkPolyData *)maskPoints1);
>> cout << "Calling icpt" << endl;
>> //_icpt->SetTarget((vtkDataSet *)del_2->GetOutput());
>> _icpt->SetTarget((vtkPolyData *)maskPoints2);
>>
>> _icpt->SetMeanDistanceModeToAbsoluteValue();
>> //_icpt->PrintSelf(std::cout, 0);
>> _icpt->Update();
>>
>> cout << " Mean distance is " << _icpt->GetMeanDistance() << endl;
>> cout << "done icpt" << endl;
>>
>> // Now lets tranform the data
>> vtkTransformPolyDataFilter* transformer = vtkTransformPolyDataFilter::New();
>> transformer->SetTransform(_icpt);
>>
>> //transformer->SetInput((vtkPolyData*)polydata_1);
>> transformer->SetInput((vtkPolyData*)maskPoints1);
>> transformer->Update();
>> transformer->PrintSelf(std::cout,0);
>>
>>
>> // map for displaying
>>
>> vtkDataSetMapper *surface_mapper_1 = vtkDataSetMapper::New();
>> //surface_mapper_1->SetInput((vtkDataSet*)del_1->GetOutput());
>>
>> surface_mapper_1->SetInput((vtkDataSet*)_icpt->GetSource());
>> //surface_mapper_1->SetInput(transformer->GetOutput());
>> //surface_mapper_1->PrintSelf(std::cout,0);
>>
>> vtkDataSetMapper *surface_mapper_2 = vtkDataSetMapper::New();
>> surface_mapper_2->SetInput((vtkDataSet*)_icpt->GetTarget());
>> //surface_mapper_2->PrintSelf(std::cout,0);
>>
>>
>> //cout << (_icpt->GetSource())->GetCenter() << endl;
>>
>> // Create an actor for cloud 1.
>> vtkActor* actor_1 = vtkActor::New();
>> actor_1->SetMapper(surface_mapper_1);
>> //actor->GetProperty()->SetRepresentationToWireframe();
>> actor_1->GetProperty()->SetRepresentationToPoints();
>> actor_1->GetProperty()->SetColor(1,1,1);
>>
>> // create an actor for cloud 2
>> vtkActor* actor_2 = vtkActor::New();
>> actor_2->SetMapper(surface_mapper_2);
>> //actor->GetProperty()->SetRepresentationToWireframe();
>> actor_2->GetProperty()->SetRepresentationToPoints();
>> actor_2->GetProperty()->SetColor(0,1,1);
>>
>> // Create the rendering objects.
>> vtkRenderer* ren = vtkRenderer::New();
>> ren->AddActor(actor_1);
>> ren->AddActor(actor_2);
>>
>> vtkRenderWindow* renWin = vtkRenderWindow::New();
>> renWin->AddRenderer(ren);
>>
>> vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
>> iren->SetRenderWindow(renWin);
>> iren->Initialize();
>> iren->Start();
>>
>> // pcoords->Delete();
>> // points->Delete();
>> // strips->Delete();
>> // temperature->Delete();
>> // vorticity->Delete();
>> // polydata->Delete();
>> // mapper->Delete();
>> actor_1->Delete();
>> actor_2->Delete();
>> ren->Delete();
>> renWin->Delete();
>> iren->Delete();
>>
>> polydata_1->Delete();
>> del_1->Delete();
>> cloud_1->Delete();
>>
>> return 0;
>>}
>>
>>
>>
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VikasTest.cxx
Type: text/x-c++src
Size: 4128 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051108/4f889e85/attachment.cxx>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkIterativeClosestPointTransform2.cxx
Type: text/x-c++src
Size: 13615 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051108/4f889e85/attachment-0001.cxx>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: vtkIterativeClosestPointTransform2.h
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051108/4f889e85/attachment.txt>
More information about the vtkusers
mailing list