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