[vtkusers] from point cloud to PLY file ??

Michele Natrella michele.cetma at yahoo.it
Tue Dec 22 05:28:28 EST 2009


Hi David,
Many thanks for your reply. 
My point cloud comes from a sea bed therefore vtkDelaunay2D should be right. Actually I would like to perform an oversampling because I am not satisfied with the resulting mesh, it's too raw, grainy, not smooth enough.
I am able to up sample point clouds with Matlab and I wonder whether there is a way to do that using vtk (?)




________________________________
Da: David Doria <daviddoria+vtk at gmail.com>
Cc: vtkusers at vtk.org
Inviato: Lun 21 dicembre 2009, 20:35:26
Oggetto: Re: [vtkusers] from point cloud to PLY file ??

On Mon, Dec 21, 2009 at 12:42 PM, Michele Natrella
<michele.cetma at yahoo.it> wrote:
>
> Hi everybody,
> My name is (Mr) Michele, I am a beginner with VTK.
>
> I am dealing with 3D point clouds (in ascii files). My purpose is to obtain a PLY file. Could anyone give me any hints on the best way to achieve this result?
>
> So far I have been able to obtain a PLY file by using vtkPoints, vtkPolyData, vtkDelaunay2D and vtkPLYWriter. Is this a good procedure?
> If so, I would want to refine my risult by performing an oversampling of my 3D point clouds. Is this feasible with VTK?
>
> Should anyone be interested, as follows the code I wrote (for the moment I have to use the 4.2 version of VTK):
>
>
>
> #include "vtkPolyDataMapper.h"
> #include "vtkProperty.h"
> #include "vtkCamera.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkDelaunay2D.h"
> #include "vtkPolyData.h"
> #include "vtkOBJExporter.h"
> #include "vtkIVExporter.h"
> #include "vtkPLYWriter.h"
>
> #include <fstream>
> #include <string>
> #include <iostream>
> #include <vector>
> #include <sstream>
> #include <cstdlib>
>
> using namespace std;
>
> std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);
> std::vector<std::string> split(const std::string &s, char delim);
>
>
>
> int main()
> {
>     vtkPolyData* profile = vtkPolyData::New();
>     vtkPoints* points = vtkPoints::New();
>
> // -1- Apertura file in lettura
>     ifstream fileStream("C:/Documents and Settings/michele.natrella/Desktop/file.txt");
>
>     // -2- Controllo sulla correttezza dell'apertura del file
>     if( !fileStream )
>     {
>         cout << "Impossibile aprire il file " << endl;
>         return 1;
>     }
>
> // -3- Recupero linea per linea e assegnamento valori
>     string line;
>     vector<string> data;
>     float x, y, z; //Punti da inserire
>     while(getline(fileStream, line)) //Prende una nuova linea
>     {
>         if(!line.empty()) // se la linea non è vuota
>         {
>         data=split(line, ' '); //il carattere di separazione  lo spazio
>
>         //Conversione da std::string a float (se si vuole convertire in double sostituire atof con atod)
>         x=(float)atof(data[0].c_str());
>         y=(float)atof(data[1].c_str());
>         z=(float)atof(data[2].c_str());
>
>         points->InsertNextPoint(x, y, z);
>         }
>     }
>
>     profile->SetPoints(points);
>
>     // Perform a 2D Delaunay triangulation on them..
>     vtkDelaunay2D* delny = vtkDelaunay2D::New();
>     delny->SetInput(profile);
>     delny->SetTolerance(0.0001);
>     vtkPolyDataMapper* mapMesh = vtkPolyDataMapper::New();
>     mapMesh->SetInput(delny->GetOutput());
>     vtkActor* meshActor = vtkActor::New();
>     meshActor->SetMapper(mapMesh);
>     meshActor->GetProperty()->SetColor(0.8, 0.8, 0.8);
>
>     // Create the rendering window, renderer, and interactive renderer
>     vtkRenderer* ren = vtkRenderer::New();
>     vtkRenderWindow* renWin = vtkRenderWindow::New();
>     renWin->AddRenderer(ren);
>     vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
>     iren->SetRenderWindow(renWin);
>
>     // Add the actors to the renderer, set the background and size
>     ren->AddActor(meshActor);
>     ren->SetBackground(0, 0, 0);
>     renWin->SetSize(500, 500);
>
>     //write the scene into Ply format
>     vtkPLYWriter* ply = vtkPLYWriter::New();
>     ply->SetInput(delny->GetOutput());
>     ply->SetFileName ("C:/Documents and Settings/michele.natrella/Desktop/file..ply");
>     ply->SetDataByteOrderToBigEndian();
>     ply->Write();
>
>     ren->ResetCamera();
>     ren->GetActiveCamera()->Zoom(1.5);
>
>     // Interact with the data.
>     iren->Initialize();
>     renWin->Render();
>     iren->Start();
>
>     return 0;
> }
>
>
> std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
>     std::stringstream ss(s);
>     std::string item;
>     while(std::getline(ss, item, delim)) {
>         elems.push_back(item);
>     }
>     return elems;
> }
>
> std::vector<std::string> split(const std::string &s, char delim) {
>     std::vector<std::string> elems;
>     return split(s, delim, elems);
> }
>
>
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>


Hi Michele,

Welcome to VTK!

Using  is only feasible if the points are a height map -
i.e. they can be projected onto a plane without losing any
relationship information.

I'm assuming by a "ply file" you mean you want a mesh on your points?
If so, here are a couple of examples of doing that:
http://www.cmake.org/Wiki/Create_a_surface_from_Unorganized_Points
http://www.cmake.org/Wiki/Create_a_surface_from_Unorganized_Points_%28Gaussian_Splat%29

I'm curious how you plan to "up sample" your points. If you have a
reasonable idea for doing that, I'd like to turn it into a VTK filter.
Let me know how you were thinking/planning to go about that.

Thanks,

David
_______________________________________________
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

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091222/9cacb22c/attachment.htm>


More information about the vtkusers mailing list