Skip to content

Commit

Permalink
Save the mesh in ply and vtk file formats
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.pointclouds.org/pcl/trunk@8616 a9d63959-f2ad-4865-b262-bf0e56cfafb6
  • Loading branch information
Martin Sälzle committed Jan 26, 2013
1 parent 7e8fdc2 commit be03130
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ namespace pcl
void
reset ();

/** \brief Saves the model mesh as ply file. */
void
savePly (const std::string& file);

/** \brief Saves the model mesh as vtk file. */
void
saveVtk (const std::string& file);

/** \see http://doc.qt.digia.com/qt/qwidget.html#keyPressEvent */
void
keyPressEvent (QKeyEvent* event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ namespace pcl

public slots:

// Help
void showHelp ();
void saveAs ();

// In hand scanner
void runningModeChanged (const RunningMode mode);
Expand Down
33 changes: 33 additions & 0 deletions apps/in_hand_scanner/src/in_hand_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
#include <pcl/common/time.h>
#include <pcl/common/transforms.h>
#include <pcl/io/openni_grabber.h>
#include <pcl/io/ply_io.h>
#include <pcl/io/vtk_io.h>
#include <pcl/geometry/get_boundary.h>
#include <pcl/geometry/mesh_conversion.h>
#include <pcl/apps/in_hand_scanner/icp.h>
#include <pcl/apps/in_hand_scanner/input_data_processing.h>
#include <pcl/apps/in_hand_scanner/integration.h>
Expand Down Expand Up @@ -234,6 +237,36 @@ pcl::ihs::InHandScanner::reset ()

////////////////////////////////////////////////////////////////////////////////

void
pcl::ihs::InHandScanner::savePly (const std::string& file)
{
boost::mutex::scoped_lock lock (mutex_);
if (destructor_called_) return;

pcl::PolygonMesh pm;
pcl::geometry::MeshConversion converter;
converter.toFaceVertexMesh (*mesh_model_, pm);

pcl::io::savePLYFile (file, pm);
}

////////////////////////////////////////////////////////////////////////////////

void
pcl::ihs::InHandScanner::saveVtk (const std::string& file)
{
boost::mutex::scoped_lock lock (mutex_);
if (destructor_called_) return;

pcl::PolygonMesh pm;
pcl::geometry::MeshConversion converter;
converter.toFaceVertexMesh (*mesh_model_, pm);

pcl::io::saveVTKFile (file, pm);
}

////////////////////////////////////////////////////////////////////////////////

void
pcl::ihs::InHandScanner::keyPressEvent (QKeyEvent* event)
{
Expand Down
20 changes: 18 additions & 2 deletions apps/in_hand_scanner/src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@

#include <limits>

#include <QHBoxLayout>
#include <QDoubleValidator>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QString>
#include <QTimer>
#include <QMessageBox>

#include <pcl/apps/in_hand_scanner/help_window.h>
#include <pcl/apps/in_hand_scanner/in_hand_scanner.h>
Expand Down Expand Up @@ -90,6 +91,8 @@ pcl::ihs::MainWindow::MainWindow (QWidget* parent)
connect (ui_->actionToggle_coloring, SIGNAL (triggered ()), ihs_, SLOT (toggleColoring ()));
connect (ui_->actionMesh_representation, SIGNAL (triggered ()), ihs_, SLOT (toggleMeshRepresentation ()));

connect (ui_->actionSaveAs, SIGNAL (triggered ()), this, SLOT (saveAs ()));

connect (ihs_, SIGNAL (runningModeChanged (RunningMode)), this, SLOT (runningModeChanged (RunningMode)));

// Input data processing
Expand Down Expand Up @@ -156,6 +159,19 @@ pcl::ihs::MainWindow::showHelp ()

////////////////////////////////////////////////////////////////////////////////

void
pcl::ihs::MainWindow::saveAs ()
{
QString filename = QFileDialog::getSaveFileName (this, "Save the model mesh.", "", "Polygon File Format (*.ply);;VTK File Format (*.vtk)");

if (filename.isEmpty ()) return;

if (filename.endsWith ("ply", Qt::CaseInsensitive)) ihs_->savePly (filename.toStdString ());
else if (filename.endsWith ("vtk", Qt::CaseInsensitive)) ihs_->saveVtk (filename.toStdString ());
}

////////////////////////////////////////////////////////////////////////////////

void
pcl::ihs::MainWindow::runningModeChanged (const RunningMode mode)
{
Expand Down
31 changes: 28 additions & 3 deletions apps/in_hand_scanner/src/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
<x>0</x>
<y>0</y>
<width>300</width>
<height>423</height>
<height>408</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -580,7 +580,7 @@
<x>0</x>
<y>0</y>
<width>300</width>
<height>423</height>
<height>401</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -720,7 +720,7 @@
<x>0</x>
<y>0</y>
<width>300</width>
<height>423</height>
<height>401</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -838,6 +838,23 @@
<addaction name="actionMesh_representation"/>
<addaction name="actionHelp"/>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1008</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionSaveAs"/>
</widget>
<addaction name="menuFile"/>
</widget>
<action name="actionHelp">
<property name="text">
<string>Help</string>
Expand Down Expand Up @@ -867,6 +884,14 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Toggle the display of the mesh (Shortcut: s):&lt;/p&gt;&lt;p&gt;- Points&lt;/p&gt;&lt;p&gt;- Wireframe&lt;/p&gt;&lt;p&gt;- Closed surface&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</action>
<action name="actionSaveAs">
<property name="text">
<string>Save As ...</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
Expand Down
2 changes: 1 addition & 1 deletion geometry/include/pcl/geometry/mesh_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace pcl
toFaceVertexMesh (const HalfEdgeMeshT& half_edge_mesh, pcl::PolygonMesh& face_vertex_mesh)
{
typedef HalfEdgeMeshT HalfEdgeMesh;
typedef typename HalfEdgeMeshT::VertexAroundFaceCirculator VAFC;
typedef typename HalfEdgeMesh::VertexAroundFaceCirculator VAFC;
typedef typename HalfEdgeMesh::FaceIndex FaceIndex;

pcl::Vertices polygon;
Expand Down

0 comments on commit be03130

Please sign in to comment.