<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 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 <span style="font-weight: bold;">vtkPoints</span>, <span style="font-weight: bold;">vtkPolyData</span><span style="font-weight: bold;"></span>, <span style="font-weight: bold;">vtkDelaunay2D </span>and <span style="font-weight: bold;">vtkPLYWriter</span>. 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></div>
<!-- cg16.c41.mail.ird.yahoo.com compressed Mon Dec 21 09:02:36 PST 2009 -->
</div><br>
</body></html>