<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>Hi David,<br>Many thanks for your reply. <br>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.<br>I am able to up sample point clouds with Matlab and I wonder whether there is a way to do that using vtk (?)<br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 13px;"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">Da:</span></b> David Doria <daviddoria+vtk@gmail.com><br><b><span style="font-weight: bold;">Cc:</span></b> vtkusers@vtk.org<br><b><span style="font-weight:
bold;">Inviato:</span></b> Lun 21 dicembre 2009, 20:35:26<br><b><span style="font-weight: bold;">Oggetto:</span></b> Re: [vtkusers] from point cloud to PLY file ??<br></font><br>On Mon, Dec 21, 2009 at 12:42 PM, Michele Natrella<br><<a ymailto="mailto:michele.cetma@yahoo.it" href="mailto:michele.cetma@yahoo.it">michele.cetma@yahoo.it</a>> wrote:<br>><br>> Hi everybody,<br>> My name is (Mr) Michele, I am a beginner with VTK.<br>><br>> 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?<br>><br>> So far I have been able to obtain a PLY file by using vtkPoints, vtkPolyData, vtkDelaunay2D and vtkPLYWriter. Is this a good procedure?<br>> If so, I would want to refine my risult by performing an oversampling of my 3D point clouds. Is this feasible with VTK?<br>><br>> Should anyone be interested, as follows the code I
wrote (for the moment I have to use the 4.2 version of VTK):<br>><br>><br>><br>> #include "vtkPolyDataMapper.h"<br>> #include "vtkProperty.h"<br>> #include "vtkCamera.h"<br>> #include "vtkRenderer.h"<br>> #include "vtkRenderWindow.h"<br>> #include "vtkRenderWindowInteractor.h"<br>> #include "vtkDelaunay2D.h"<br>> #include "vtkPolyData.h"<br>> #include "vtkOBJExporter.h"<br>> #include "vtkIVExporter.h"<br>> #include "vtkPLYWriter.h"<br>><br>> #include <fstream><br>> #include <string><br>> #include <iostream><br>> #include <vector><br>> #include <sstream><br>> #include <cstdlib><br>><br>> using namespace std;<br>><br>> std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);<br>> std::vector<std::string> split(const std::string &s, char
delim);<br>><br>><br>><br>> int main()<br>> {<br>> vtkPolyData* profile = vtkPolyData::New();<br>> vtkPoints* points = vtkPoints::New();<br>><br>> // -1- Apertura file in lettura<br>> ifstream fileStream("C:/Documents and Settings/michele.natrella/Desktop/file.txt");<br>><br>> // -2- Controllo sulla correttezza dell'apertura del file<br>> if( !fileStream )<br>> {<br>> cout << "Impossibile aprire il file " << endl;<br>> return 1;<br>> }<br>><br>> // -3- Recupero linea per linea e assegnamento valori<br>> string line;<br>> vector<string> data;<br>> float x, y, z; //Punti da inserire<br>>
while(getline(fileStream, line)) //Prende una nuova linea<br>> {<br>> if(!line.empty()) // se la linea non è vuota<br>> {<br>> data=split(line, ' '); //il carattere di separazione lo spazio<br>><br>> //Conversione da std::string a float (se si vuole convertire in double sostituire atof con atod)<br>> x=(float)atof(data[0].c_str());<br>> y=(float)atof(data[1].c_str());<br>> z=(float)atof(data[2].c_str());<br>><br>> points->InsertNextPoint(x, y, z);<br>> }<br>> }<br>><br>>
profile->SetPoints(points);<br>><br>> // Perform a 2D Delaunay triangulation on them..<br>> vtkDelaunay2D* delny = vtkDelaunay2D::New();<br>> delny->SetInput(profile);<br>> delny->SetTolerance(0.0001);<br>> vtkPolyDataMapper* mapMesh = vtkPolyDataMapper::New();<br>> mapMesh->SetInput(delny->GetOutput());<br>> vtkActor* meshActor = vtkActor::New();<br>> meshActor->SetMapper(mapMesh);<br>> meshActor->GetProperty()->SetColor(0.8, 0.8, 0.8);<br>><br>> // Create the rendering window, renderer, and interactive renderer<br>> vtkRenderer* ren = vtkRenderer::New();<br>> vtkRenderWindow* renWin = vtkRenderWindow::New();<br>>
renWin->AddRenderer(ren);<br>> vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();<br>> iren->SetRenderWindow(renWin);<br>><br>> // Add the actors to the renderer, set the background and size<br>> ren->AddActor(meshActor);<br>> ren->SetBackground(0, 0, 0);<br>> renWin->SetSize(500, 500);<br>><br>> //write the scene into Ply format<br>> vtkPLYWriter* ply = vtkPLYWriter::New();<br>> ply->SetInput(delny->GetOutput());<br>> ply->SetFileName ("C:/Documents and Settings/michele.natrella/Desktop/file.ply");<br>> ply->SetDataByteOrderToBigEndian();<br>> ply->Write();<br>><br>> ren->ResetCamera();<br>>
ren->GetActiveCamera()->Zoom(1.5);<br>><br>> // Interact with the data.<br>> iren->Initialize();<br>> renWin->Render();<br>> iren->Start();<br>><br>> return 0;<br>> }<br>><br>><br>> std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {<br>> std::stringstream ss(s);<br>> std::string item;<br>> while(std::getline(ss, item, delim)) {<br>> elems.push_back(item);<br>> }<br>> return elems;<br>> }<br>><br>> std::vector<std::string> split(const std::string &s, char delim) {<br>> std::vector<std::string> elems;<br>> return split(s,
delim, elems);<br>> }<br>><br>><br>> _______________________________________________<br><span>> Powered by <a target="_blank" href="http://www.kitware.com">www.kitware.com</a></span><br>><br>> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>><br>> Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>><br>> Follow this link to subscribe/unsubscribe:<br>> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>><br><br><br>Hi Michele,<br><br>Welcome to VTK!<br><br>Using is only feasible if the points are a height map -<br>i.e. they can be projected onto a plane without losing any<br>relationship information.<br><br>I'm
assuming by a "ply file" you mean you want a mesh on your points?<br>If so, here are a couple of examples of doing that:<br><a href="http://www.cmake.org/Wiki/Create_a_surface_from_Unorganized_Points" target="_blank">http://www.cmake.org/Wiki/Create_a_surface_from_Unorganized_Points</a><br><a href="http://www.cmake.org/Wiki/Create_a_surface_from_Unorganized_Points_%28Gaussian_Splat%29" target="_blank">http://www.cmake.org/Wiki/Create_a_surface_from_Unorganized_Points_%28Gaussian_Splat%29</a><br><br>I'm curious how you plan to "up sample" your points. If you have a<br>reasonable idea for doing that, I'd like to turn it into a VTK filter.<br>Let me know how you were thinking/planning to go about that.<br><br>Thanks,<br><br>David<br>_______________________________________________<br><span>Powered by <a target="_blank" href="http://www.kitware.com">www.kitware.com</a></span><br><br>Visit other Kitware open-source projects at <a
href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br></div></div>
<!-- cg16.c41.mail.ird.yahoo.com compressed Mon Dec 21 09:02:36 PST 2009 -->
</div><br>
</body></html>