Quantcast

vtk3ddelaunay save in .ply, .stl, .obj or .wrl

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

vtk3ddelaunay save in .ply, .stl, .obj or .wrl

mozendi
Dear VTK users,

I am using VTK to generate a 3D Delaunay triangulation from a list of input points that are obtained using terrestrial laser scanner. So far, I successfully generated some 3D triangulations and saved them in vtk or vtu file formats. However, I need to save them as one of the popular formats such as .ply, .stl, .obj or .wrl. Could you please tell me how can I save 3d triangulation in one of these formats? My other question is about setAlpha and setTolerance parameters, could you please explain me these parameters in detail?
Thanks in advance

int main( int argc, char* argv[] )
{
        //load the point cloud
        vtkSmartPointer<vtkSimplePointsReader> reader = vtkSmartPointer<vtkSimplePointsReader>::New();
        reader->SetFileName("kucuk50k.xyz");
        reader->Update();
        vtkPolyData* polydata = reader->GetOutput();
        std::cout << "The point cloud is loaded" << std::endl;
        //end of point cloud loading
        std::cout << "----------------------------------------------" << std::endl;
        // Generate a mesh from the input points. If Alpha is non-zero, then
        // tetrahedra, triangles, edges and vertices that lie within the
        // alpha radius are output.
        std::cout << "Start delaunay 3d triangulation" << std::endl;
        vtkSmartPointer<vtkDelaunay3D> delaunay3DAlpha = vtkSmartPointer<vtkDelaunay3D>::New();
        delaunay3DAlpha->SetInputConnection(reader->GetOutputPort());
        delaunay3DAlpha->SetAlpha(0.01);
        std::cout << "3d Delaunay computed" << std::endl;
        std::cout << "----------------------------------------------" << std::endl;
        std::cout << "Start writing the triangulation" << std::endl;
        vtkSmartPointer<vtkXMLUnstructuredGridWriter> ugWriter = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
        ugWriter->SetInputConnection(delaunay3DAlpha->GetOutputPort());
        ugWriter->SetFileName("delaunayy_50k.vtk");
        ugWriter->Write();
        std::cout << "VTK file created" << std::endl;
        return EXIT_SUCCESS;
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtk3ddelaunay save in .ply, .stl, .obj or .wrl

chiranjibsur
Hi,
You can use vtkPLYWriter / vtkSTLWriter to convert you file in the desired format.
Here is a page with examples:

Thanks,
Chiranjib

On Wed, May 3, 2017 at 1:30 AM, mozendi <[hidden email]> wrote:
Dear VTK users,

I am using VTK to generate a 3D Delaunay triangulation from a list of input
points that are obtained using terrestrial laser scanner. So far, I
successfully generated some 3D triangulations and saved them in vtk or vtu
file formats. However, I need to save them as one of the popular formats
such as .ply, .stl, .obj or .wrl. Could you please tell me how can I save 3d
triangulation in one of these formats? My other question is about setAlpha
and setTolerance parameters, could you please explain me these parameters in
detail?
Thanks in advance

int main( int argc, char* argv[] )
{
        //load the point cloud
        vtkSmartPointer<vtkSimplePointsReader> reader =
vtkSmartPointer<vtkSimplePointsReader>::New();
        reader->SetFileName("kucuk50k.xyz");
        reader->Update();
        vtkPolyData* polydata = reader->GetOutput();
        std::cout << "The point cloud is loaded" << std::endl;
        //end of point cloud loading
        std::cout << "----------------------------------------------" << std::endl;
        // Generate a mesh from the input points. If Alpha is non-zero, then
        // tetrahedra, triangles, edges and vertices that lie within the
        // alpha radius are output.
        std::cout << "Start delaunay 3d triangulation" << std::endl;
        vtkSmartPointer<vtkDelaunay3D> delaunay3DAlpha =
vtkSmartPointer<vtkDelaunay3D>::New();
        delaunay3DAlpha->SetInputConnection(reader->GetOutputPort());
        delaunay3DAlpha->SetAlpha(0.01);
        std::cout << "3d Delaunay computed" << std::endl;
        std::cout << "----------------------------------------------" << std::endl;
        std::cout << "Start writing the triangulation" << std::endl;
        vtkSmartPointer<vtkXMLUnstructuredGridWriter> ugWriter =
vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
        ugWriter->SetInputConnection(delaunay3DAlpha->GetOutputPort());
        ugWriter->SetFileName("delaunayy_50k.vtk");
        ugWriter->Write();
        std::cout << "VTK file created" << std::endl;
        return EXIT_SUCCESS;
}



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtk3ddelaunay-save-in-ply-stl-obj-or-wrl-tp5743046.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtk3ddelaunay save in .ply, .stl, .obj or .wrl

mozendi
Dear Chiranjib,

Thank you for your help. After creating the 3D delaunay, this is the way how I save my 3D delaunay tirangulation in .ply format:

//surface filter
        vtkSmartPointer<vtkDataSetSurfaceFilter> surfaceFilter = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
        surfaceFilter->SetInputConnection(delaunay3DAlpha->GetOutputPort());
        surfaceFilter->Update();
        std::cout << "surface filter OK" << std::endl;
        std::cout << "------------------------------" << std::endl;
        std::cout << "Start writing the triangulation" << std::endl;
       
        std::string filename = "kucuk2.ply";
        vtkSmartPointer<vtkPLYWriter> plyWriter = vtkSmartPointer<vtkPLYWriter>::New();
        plyWriter->SetInputConnection(surfaceFilter->GetOutputPort());
        plyWriter->SetFileName(filename.c_str());
        plyWriter->Write();

It works fine but the resulting triangulation consists of many overlapping triangles as in the following figure:



However, the resulting triangulation should be similar to the image below which is generated using Geomagic software:



Do you have any idea about this issue?

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtk3ddelaunay save in .ply, .stl, .obj or .wrl

chiranjibsur
vtkCleanPolydata filter might come handy for you.


Hope that helps!

On Sun, May 7, 2017 at 5:45 PM, mozendi <[hidden email]> wrote:
Dear Chiranjib,

Thank you for your help. After creating the 3D delaunay, this is the way how
I save my 3D delaunay tirangulation in .ply format:

//surface filter
        vtkSmartPointer<vtkDataSetSurfaceFilter> surfaceFilter =
vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
        surfaceFilter->SetInputConnection(delaunay3DAlpha->GetOutputPort());
        surfaceFilter->Update();
        std::cout << "surface filter OK" << std::endl;
        std::cout << "------------------------------" << std::endl;
        std::cout << "Start writing the triangulation" << std::endl;

        std::string filename = "kucuk2.ply";
        vtkSmartPointer<vtkPLYWriter> plyWriter =
vtkSmartPointer<vtkPLYWriter>::New();
        plyWriter->SetInputConnection(surfaceFilter->GetOutputPort());
        plyWriter->SetFileName(filename.c_str());
        plyWriter->Write();

It works fine but the resulting triangulation consists of many overlapping
triangles as in the following figure:

<http://vtk.1045678.n5.nabble.com/file/n5743107/vtk_triangulation.png>

However, the resulting triangulation should be similar to the image below
which is generated using Geomagic software:

<http://vtk.1045678.n5.nabble.com/file/n5743107/geom_triangles.png>

Do you have any idea about this issue?

Thanks




--
View this message in context: http://vtk.1045678.n5.nabble.com/vtk3ddelaunay-save-in-ply-stl-obj-or-wrl-tp5743046p5743107.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtk3ddelaunay save in .ply, .stl, .obj or .wrl

mozendi
Thanks for helps. I think I will try CGAL and see the results.
Loading...