First checkin for OpenMesh 2.0
git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@2 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
56
Apps/Decimating/CmdOption.hh
Normal file
56
Apps/Decimating/CmdOption.hh
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef CMDOPTION
|
||||
#define CMDOPTION
|
||||
|
||||
template <typename T>
|
||||
class CmdOption
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T value_type;
|
||||
|
||||
CmdOption(const T& _val) : val_(_val), valid_(true) { }
|
||||
CmdOption() : valid_(false), enabled_(false) { }
|
||||
|
||||
// has been set and has a value
|
||||
bool is_valid(void) const { return valid_; }
|
||||
bool has_value(void) const { return is_valid(); }
|
||||
|
||||
// has been set and may have an value (check with is_valid())
|
||||
bool is_enabled() const { return enabled_; }
|
||||
|
||||
void enable() { enabled_ = true; }
|
||||
|
||||
CmdOption& operator = ( const T& _val )
|
||||
{
|
||||
val_ = _val;
|
||||
valid_=true;
|
||||
enable();
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T () { return val_; }
|
||||
// operator const T& () const { return val_; }
|
||||
|
||||
operator T* () { return is_valid() ? &val_ : NULL; }
|
||||
|
||||
private:
|
||||
|
||||
T val_;
|
||||
bool valid_;
|
||||
bool enabled_;
|
||||
|
||||
private: // non-copyable
|
||||
|
||||
CmdOption(const CmdOption&);
|
||||
CmdOption& operator = ( const CmdOption& );
|
||||
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
std::ostream& operator << ( std::ostream& _os, CmdOption<T>& _opt )
|
||||
{
|
||||
_os << (T&)_opt;
|
||||
return _os;
|
||||
}
|
||||
|
||||
#endif
|
||||
111
Apps/Decimating/DecimaterViewerWidget.cc
Normal file
111
Apps/Decimating/DecimaterViewerWidget.cc
Normal file
@@ -0,0 +1,111 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Revision: 1.2 $
|
||||
// $Date: 2007-05-18 15:17:21 $
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(disable: 4267 4311)
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qdatetime.h>
|
||||
|
||||
#include <OpenMesh/Core/IO/BinaryHelper.hh>
|
||||
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||
|
||||
#include <OpenMesh/Apps/Decimating/DecimaterViewerWidget.hh>
|
||||
|
||||
|
||||
//== IMPLEMENTATION ==========================================================
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void DecimaterViewerWidget::keyPressEvent(QKeyEvent* _event)
|
||||
{
|
||||
switch (_event->key())
|
||||
{
|
||||
case Key_D:
|
||||
{
|
||||
int rc;
|
||||
if ( (rc=decimater_->decimate(steps_)) )
|
||||
{
|
||||
decimater_->mesh().garbage_collection();
|
||||
std::cout << rc << " vertices removed!\n";
|
||||
updateGL();
|
||||
}
|
||||
else
|
||||
std::cout << "Decimation failed\n";
|
||||
break;
|
||||
}
|
||||
|
||||
case Key_Plus:
|
||||
steps_ = std::min( ++steps_, (size_t)(mesh_.n_vertices() * 0.1) );
|
||||
updateGL();
|
||||
std::cout << "# decimating steps increased to " << steps_ << std::endl;
|
||||
break;
|
||||
|
||||
case Key_Minus:
|
||||
steps_ = std::max( --steps_, size_t(1) );
|
||||
updateGL();
|
||||
std::cout << "# decimating steps increased to " << steps_ << std::endl;
|
||||
break;
|
||||
|
||||
case Key_S:
|
||||
{
|
||||
OpenMesh::IO::Options opt;
|
||||
|
||||
opt += OpenMesh::IO::Options::Binary;
|
||||
|
||||
if (OpenMesh::IO::write_mesh( mesh(), "result.off", opt ))
|
||||
std::cout << "mesh saved in 'result.off'\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case Key_Q:
|
||||
case Key_Escape:
|
||||
qApp->quit();
|
||||
|
||||
default:
|
||||
this->inherited_t::keyPressEvent(_event);
|
||||
}
|
||||
}
|
||||
|
||||
void DecimaterViewerWidget::animate( void )
|
||||
{
|
||||
// updateGL();
|
||||
// timer_->start(300, true);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
172
Apps/Decimating/DecimaterViewerWidget.hh
Normal file
172
Apps/Decimating/DecimaterViewerWidget.hh
Normal file
@@ -0,0 +1,172 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Revision: 1.3 $
|
||||
// $Date: 2008-03-11 09:18:01 $
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#ifndef OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
|
||||
#define OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
#if !defined(OM_USE_OSG)
|
||||
# define OM_USE_OSG 0
|
||||
#endif
|
||||
|
||||
|
||||
#include <qtimer.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
//--------------------
|
||||
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||
//--------------------
|
||||
#if OM_USE_OSG
|
||||
# include <OpenMesh/Tools/Kernel_OSG/TriMesh_OSGArrayKernelT.hh>
|
||||
# define DEFAULT_TRAITS Kernel_OSG::Traits
|
||||
# define TRIMESH_KERNEL Kernel_OSG::TriMesh_OSGArrayKernelT
|
||||
#else
|
||||
//--------------------
|
||||
# include <OpenMesh/Core/Mesh/Traits.hh>
|
||||
# include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
|
||||
# define DEFAULT_TRAITS DefaultTraits
|
||||
# define TRIMESH_KERNEL TriMesh_ArrayKernelT
|
||||
#endif
|
||||
|
||||
#include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
|
||||
|
||||
#include <OpenMesh/Tools/Decimater/DecimaterT.hh>
|
||||
#include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
|
||||
#include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
|
||||
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
|
||||
using namespace OpenMesh;
|
||||
|
||||
struct MyTraits : public DEFAULT_TRAITS
|
||||
{
|
||||
VertexAttributes ( Attributes::Normal );
|
||||
FaceAttributes ( Attributes::Normal );
|
||||
};
|
||||
|
||||
typedef TRIMESH_KERNEL<MyTraits> mesh_t;
|
||||
typedef MeshViewerWidgetT<mesh_t> MeshViewerWidget;
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
|
||||
class DecimaterViewerWidget : public MeshViewerWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
typedef MeshViewerWidget inherited_t;
|
||||
|
||||
typedef Decimater::DecimaterT<mesh_t> decimater_t;
|
||||
typedef Decimater::ModQuadricT< decimater_t > mod_quadric_t;
|
||||
typedef Decimater::ModNormalFlippingT< decimater_t > mod_nf_t;
|
||||
|
||||
// object types
|
||||
typedef std::auto_ptr< decimater_t > decimater_o;
|
||||
typedef std::auto_ptr< mod_quadric_t > mod_quadric_o;
|
||||
typedef std::auto_ptr< mod_nf_t > mod_nf_o;
|
||||
|
||||
/// default constructor
|
||||
DecimaterViewerWidget(QWidget* _parent=0, const char* _name=0)
|
||||
: MeshViewerWidget(_parent), steps_(1)
|
||||
{
|
||||
timer_ = new QTimer(this);
|
||||
|
||||
connect( timer_, SIGNAL(timeout()), SLOT(animate()) );
|
||||
}
|
||||
|
||||
/// destructor
|
||||
~DecimaterViewerWidget()
|
||||
{
|
||||
delete timer_;
|
||||
}
|
||||
|
||||
public: // inherited
|
||||
|
||||
bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt)
|
||||
{
|
||||
bool rc;
|
||||
|
||||
if ( (rc = inherited_t::open_mesh( _filename, _opt )) )
|
||||
{
|
||||
std::cout << "prepare decimater" << std::endl;
|
||||
|
||||
// to be compatible with gcc 2.95.3
|
||||
{
|
||||
decimater_o tmp( new decimater_t ( mesh() ) );
|
||||
decimater_ = tmp;
|
||||
}
|
||||
{
|
||||
mod_quadric_o tmp( new mod_quadric_t( *decimater_ ) );
|
||||
mod_quadric_ = tmp;
|
||||
}
|
||||
{
|
||||
mod_nf_o tmp( new mod_nf_t ( *decimater_ ) );
|
||||
mod_nf_ = tmp;
|
||||
}
|
||||
|
||||
decimater_->initialize();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
protected slots:
|
||||
|
||||
void animate( void );
|
||||
|
||||
protected:
|
||||
|
||||
virtual void keyPressEvent(QKeyEvent* _event);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool animate_;
|
||||
QTimer *timer_;
|
||||
|
||||
decimater_o decimater_;
|
||||
mod_quadric_o mod_quadric_;
|
||||
mod_nf_o mod_nf_;
|
||||
|
||||
size_t steps_;
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
#endif // OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH defined
|
||||
//=============================================================================
|
||||
|
||||
25
Apps/Decimating/Decimating.pro
Normal file
25
Apps/Decimating/Decimating.pro
Normal file
@@ -0,0 +1,25 @@
|
||||
################################################################################
|
||||
#
|
||||
################################################################################
|
||||
|
||||
contains( OPENFLIPPER , OpenFlipper ){
|
||||
include( $$TOPDIR/qmake/all.include )
|
||||
} else {
|
||||
include( $$TOPDIR/OpenMesh/qmake/all.include )
|
||||
}
|
||||
|
||||
INCLUDEPATH += ../../..
|
||||
|
||||
Application()
|
||||
glew()
|
||||
glut()
|
||||
openmesh()
|
||||
|
||||
DIRECTORIES = . ../QtViewer
|
||||
|
||||
# Input
|
||||
HEADERS += $$getFilesFromDir($$DIRECTORIES,*.hh)
|
||||
SOURCES += $$getFilesFromDir($$DIRECTORIES,*.cc)
|
||||
FORMS += $$getFilesFromDir($$DIRECTORIES,*.ui)
|
||||
|
||||
################################################################################
|
||||
199
Apps/Decimating/OpenMesh_Apps_Decimating.vcproj
Normal file
199
Apps/Decimating/OpenMesh_Apps_Decimating.vcproj
Normal file
@@ -0,0 +1,199 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
Name="OpenMesh_Apps_Decimating"
|
||||
ProjectGUID="{2F3AB3BA-D857-4328-9CBC-C2A27F8B2CF8}"
|
||||
RootNamespace="OpenMesh_Apps_Decimating"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\..;"$(QTDIR)/include""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_USE_MATH_DEFINES"
|
||||
MinimalRebuild="false"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
DisableLanguageExtensions="false"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
ProgramDataBaseFileName="$(IntDir)/vc70.pdb"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="..\..\bin\decimater_dbg.exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(OutDir)\$(TargetName).pdb"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="1"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\..\..;"$(QTDIR)/include""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_USE_MATH_DEFINES"
|
||||
RuntimeLibrary="2"
|
||||
DisableLanguageExtensions="false"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="..\..\bin\decimater.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<File
|
||||
RelativePath=".\CmdOption.hh"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\decimater.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\test1.cpp"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
499
Apps/Decimating/decimater.cc
Normal file
499
Apps/Decimating/decimater.cc
Normal file
@@ -0,0 +1,499 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Revision: 1.2 $
|
||||
// $Date: 2007-05-18 15:17:22 $
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#if !defined(OM_USE_OSG)
|
||||
# define OM_USE_OSG 0
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
//--------------------
|
||||
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||
//--------------------
|
||||
#if OM_USE_OSG
|
||||
# include <OpenMesh/Tools/Kernel_OSG/TriMesh_OSGArrayKernelT.hh>
|
||||
#else
|
||||
# include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
|
||||
#endif
|
||||
#include <OpenMesh/Core/Utils/vector_cast.hh>
|
||||
//--------------------
|
||||
#include <OpenMesh/Tools/Utils/getopt.h>
|
||||
#include <OpenMesh/Tools/Utils/Timer.hh>
|
||||
#include <OpenMesh/Tools/Decimater/DecimaterT.hh>
|
||||
#include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
|
||||
#include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
|
||||
#include <OpenMesh/Tools/Decimater/ModProgMeshT.hh>
|
||||
#include <OpenMesh/Tools/Decimater/ModIndependentSetsT.hh>
|
||||
#include <OpenMesh/Tools/Decimater/ModRoundnessT.hh>
|
||||
|
||||
//----------------------------------------------------------------- traits ----
|
||||
|
||||
#if OM_USE_OSG
|
||||
typedef OpenMesh::Kernel_OSG::Traits MyTraits;
|
||||
#else
|
||||
typedef OpenMesh::DefaultTraits MyTraits;
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------- mesh ----
|
||||
|
||||
#if OM_USE_OSG
|
||||
typedef OpenMesh::Kernel_OSG::TriMesh_OSGArrayKernelT<MyTraits> ArrayTriMesh;
|
||||
#else
|
||||
typedef OpenMesh::TriMesh_ArrayKernelT<MyTraits> ArrayTriMesh;
|
||||
#endif
|
||||
|
||||
|
||||
//-------------------------------------------------------------- decimator ----
|
||||
|
||||
typedef OpenMesh::Decimater::DecimaterT<ArrayTriMesh> Decimater;
|
||||
|
||||
|
||||
//---------------------------------------------------------------- globals ----
|
||||
|
||||
int gverbose = 0;
|
||||
int gdebug = 0;
|
||||
|
||||
|
||||
//--------------------------------------------------------------- forwards ----
|
||||
|
||||
void usage_and_exit(int xcode);
|
||||
|
||||
|
||||
//--------------------------------------------------- decimater arguments ----
|
||||
|
||||
#include "CmdOption.hh"
|
||||
|
||||
|
||||
struct DecOptions
|
||||
{
|
||||
DecOptions()
|
||||
: n_collapses(0)
|
||||
{ }
|
||||
|
||||
CmdOption<bool> decorate_name;
|
||||
CmdOption<float> n_collapses;
|
||||
CmdOption<float> Q; // Quadrics
|
||||
CmdOption<float> NF; // Normal Flipping
|
||||
CmdOption<bool> IS; // Independent Sets
|
||||
CmdOption<std::string> PM; // Progressive Mesh
|
||||
CmdOption<float> R; // Roundness
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool init( CmdOption<T>& _o, const std::string& _val )
|
||||
{
|
||||
if ( _val.empty() )
|
||||
_o.enable();
|
||||
else
|
||||
{
|
||||
std::istringstream istr( _val );
|
||||
|
||||
T v;
|
||||
|
||||
if ( (istr >> v).fail() )
|
||||
return false;
|
||||
|
||||
_o = v;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool parse_argument( const std::string& arg )
|
||||
{
|
||||
std::string::size_type pos = arg.find(':');
|
||||
|
||||
std::string name;
|
||||
std::string value;
|
||||
|
||||
if (pos == std::string::npos)
|
||||
name = arg;
|
||||
else
|
||||
{
|
||||
name = arg.substr(0, pos);
|
||||
value = arg.substr(pos+1, arg.size());
|
||||
}
|
||||
strip(name);
|
||||
strip(value);
|
||||
|
||||
if (name == "Q") return init(Q, value);
|
||||
if (name == "NF") return init(NF, value);
|
||||
if (name == "PM") return init(PM, value);
|
||||
if (name == "IS") return init(IS, value);
|
||||
if (name == "R") return init(R, value);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::string& strip(std::string & line)
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
|
||||
pos = line.find_last_not_of(" \t");
|
||||
|
||||
if ( pos!=0 && pos!=std::string::npos )
|
||||
{
|
||||
++pos;
|
||||
line.erase( pos, line.length()-pos );
|
||||
}
|
||||
|
||||
pos = line.find_first_not_of(" \t");
|
||||
if ( pos!=0 && pos!=std::string::npos )
|
||||
{
|
||||
line.erase(0,pos);
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//----------------------------------------------------- decimater wrapper ----
|
||||
//
|
||||
template <typename Mesh, typename Decimater>
|
||||
bool
|
||||
decimate(const std::string &_ifname,
|
||||
const std::string &_ofname,
|
||||
DecOptions &_opt)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
Mesh mesh;
|
||||
OpenMesh::IO::Options opt;
|
||||
OpenMesh::Utils::Timer timer;
|
||||
|
||||
// ---------------------------------------- read source mesh
|
||||
{
|
||||
if (gverbose)
|
||||
clog << "source mesh: ";
|
||||
bool rc;
|
||||
|
||||
if (gverbose)
|
||||
clog << _ifname << endl;
|
||||
if ( !(rc = OpenMesh::IO::read_mesh(mesh, _ifname, opt)) )
|
||||
{
|
||||
cerr << " ERROR: read failed!" << endl;
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------- do some decimation
|
||||
{
|
||||
// ---- 0 - For module NormalFlipping one needs face normals
|
||||
|
||||
if ( !opt.check( OpenMesh::IO::Options::FaceNormal ) )
|
||||
{
|
||||
if ( !mesh.has_face_normals() )
|
||||
mesh.request_face_normals();
|
||||
|
||||
if (gverbose)
|
||||
clog << " updating face normals" << endl;
|
||||
mesh.update_face_normals();
|
||||
}
|
||||
|
||||
// ---- 1 - create decimater instance
|
||||
Decimater decimater( mesh );
|
||||
|
||||
// ---- 2 - registrate modules
|
||||
if (gverbose)
|
||||
clog << " registrate modules" << endl;
|
||||
|
||||
|
||||
typename OpenMesh::Decimater::ModQuadricT<Decimater>::Handle modQ;
|
||||
|
||||
if (_opt.Q.is_enabled())
|
||||
{
|
||||
decimater.add(modQ);
|
||||
if (_opt.Q.has_value())
|
||||
decimater.module( modQ ).set_max_err( _opt.Q );
|
||||
}
|
||||
|
||||
typename OpenMesh::Decimater::ModNormalFlippingT<Decimater>::Handle modNF;
|
||||
|
||||
if (_opt.NF.is_enabled())
|
||||
{
|
||||
decimater.add(modNF);
|
||||
if (_opt.NF.has_value())
|
||||
decimater.module( modNF ).set_normal_deviation( _opt.NF );
|
||||
}
|
||||
|
||||
typename OpenMesh::Decimater::ModProgMeshT<Decimater>::Handle modPM;
|
||||
|
||||
if ( _opt.PM.is_enabled() )
|
||||
decimater.add(modPM);
|
||||
|
||||
|
||||
typename OpenMesh::Decimater::ModIndependentSetsT<Decimater>::Handle modIS;
|
||||
|
||||
if ( _opt.IS.is_enabled() )
|
||||
decimater.add(modIS);
|
||||
|
||||
|
||||
typename OpenMesh::Decimater::ModRoundnessT<Decimater>::Handle modR;
|
||||
|
||||
if ( _opt.R.is_enabled() )
|
||||
{
|
||||
decimater.add( modR );
|
||||
if ( _opt.R.has_value() )
|
||||
decimater.module( modR ).set_min_angle( _opt.R,
|
||||
!modQ.is_valid() ||
|
||||
!decimater.module(modQ).is_binary());
|
||||
}
|
||||
|
||||
// ---- 3 - initialize decimater
|
||||
|
||||
if (gverbose)
|
||||
clog << "initializing mesh" << endl;
|
||||
|
||||
{
|
||||
bool rc;
|
||||
timer.start();
|
||||
rc = decimater.initialize();
|
||||
timer.stop();
|
||||
if (!rc)
|
||||
{
|
||||
std::cerr << " initializing failed!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (gverbose)
|
||||
std::clog << " Elapsed time: " << timer.as_string() << std::endl;
|
||||
|
||||
if (gverbose)
|
||||
decimater.info( clog );
|
||||
|
||||
// ---- 4 - do it
|
||||
|
||||
if (gverbose)
|
||||
{
|
||||
std::clog << "decimating" << std::endl;
|
||||
std::clog << " # vertices: " << mesh.n_vertices() << std::endl;
|
||||
}
|
||||
|
||||
float nv_before = float(mesh.n_vertices());
|
||||
|
||||
timer.start();
|
||||
int rc = 0;
|
||||
if (_opt.n_collapses < 0.0)
|
||||
rc = decimater.decimate_to( size_t(-_opt.n_collapses) );
|
||||
else if (_opt.n_collapses >= 1.0 || _opt.n_collapses == 0.0)
|
||||
rc = decimater.decimate( size_t(_opt.n_collapses) );
|
||||
else if (_opt.n_collapses > 0.0f)
|
||||
rc = decimater.decimate_to(size_t(mesh.n_vertices()*_opt.n_collapses));
|
||||
timer.stop();
|
||||
|
||||
// ---- 5 - write progmesh file for progviewer (before garbage collection!)
|
||||
|
||||
if ( _opt.PM.has_value() )
|
||||
decimater.module(modPM).write( _opt.PM );
|
||||
|
||||
// ---- 6 - throw away all tagged edges
|
||||
|
||||
mesh.garbage_collection();
|
||||
|
||||
if (gverbose)
|
||||
{
|
||||
std::clog << " # executed collapses: " << rc << std::endl;
|
||||
std::clog << " # vertices: " << mesh.n_vertices() << ", "
|
||||
<< ( 100.0*mesh.n_vertices()/nv_before ) << "%\n";
|
||||
std::clog << " Elapsed time: " << timer.as_string() << std::endl;
|
||||
std::clog << " collapses/s : " << rc/timer.seconds() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// write resulting mesh
|
||||
if ( ! _ofname.empty() )
|
||||
{
|
||||
std::string ofname(_ofname);
|
||||
|
||||
std::string::size_type pos = ofname.rfind('.');
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
ofname += ".off";
|
||||
pos = ofname.rfind('.');
|
||||
}
|
||||
|
||||
if ( _opt.decorate_name.is_enabled() )
|
||||
{
|
||||
std::stringstream s; s << mesh.n_vertices();
|
||||
std::string n; s >> n;
|
||||
ofname.insert( pos, "-");
|
||||
ofname.insert(++pos, n );
|
||||
}
|
||||
|
||||
OpenMesh::IO::Options opt;
|
||||
|
||||
//opt += OpenMesh::IO::Options::Binary;
|
||||
|
||||
if ( !OpenMesh::IO::write_mesh(mesh, ofname, opt ) )
|
||||
{
|
||||
std::cerr << " Cannot write decimated mesh to file '"
|
||||
<< ofname << "'\n";
|
||||
return false;
|
||||
}
|
||||
std::clog << " Exported decimated mesh to file '" << ofname << "'\n";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------ main -----
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::string ifname, ofname;
|
||||
|
||||
DecOptions opt;
|
||||
|
||||
//
|
||||
#if OM_USE_OSG
|
||||
osg::osgInit( argc, argv );
|
||||
#endif
|
||||
|
||||
//---------------------------------------- parse command line
|
||||
{
|
||||
int c;
|
||||
|
||||
while ( (c=getopt( argc, argv, "dDhi:M:n:o:v")) != -1 )
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'D': opt.decorate_name = true; break;
|
||||
case 'd': gdebug = true; break;
|
||||
case 'h': usage_and_exit(0);
|
||||
case 'i': ifname = optarg; break;
|
||||
case 'M': opt.parse_argument( optarg ); break;
|
||||
case 'n': opt.n_collapses = float(atof(optarg)); break;
|
||||
case 'o': ofname = optarg; break;
|
||||
case 'v': gverbose = true; break;
|
||||
case '?':
|
||||
default:
|
||||
std::cerr << "FATAL: cannot process command line option!"
|
||||
<< std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
if ( (-1.0f < opt.n_collapses) && (opt.n_collapses < 0.0f) )
|
||||
{
|
||||
std::cerr << "Error: Option -n: invalid value argument!" << std::endl;
|
||||
usage_and_exit(2);
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
if (gverbose)
|
||||
{
|
||||
std::clog << " Input file: " << ifname << std::endl;
|
||||
std::clog << " Output file: " << ofname << std::endl;
|
||||
std::clog << " #collapses: " << opt.n_collapses << std::endl;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
|
||||
|
||||
if (gverbose)
|
||||
{
|
||||
std::clog << "Begin decimation" << std::endl;
|
||||
}
|
||||
|
||||
bool rc = decimate<ArrayTriMesh, Decimater>( ifname, ofname, opt );
|
||||
|
||||
if (gverbose)
|
||||
{
|
||||
if (!rc)
|
||||
std::clog << "Decimation failed!" << std::endl;
|
||||
else
|
||||
std::clog << "Decimation done." << std::endl;
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void usage_and_exit(int xcode)
|
||||
{
|
||||
std::string errmsg;
|
||||
|
||||
switch(xcode)
|
||||
{
|
||||
case 1: errmsg = "Option not supported!"; break;
|
||||
case 2: errmsg = "Invalid output file format!"; break;
|
||||
}
|
||||
|
||||
std::cerr << std::endl;
|
||||
if (xcode)
|
||||
{
|
||||
std::cerr << "Error " << xcode << ": " << errmsg << std::endl << std::endl;
|
||||
}
|
||||
std::cerr << "Usage: decimator [Options] -i input-file -o output-file\n"
|
||||
<< " Decimating a mesh using quadrics and normal flipping.\n"
|
||||
<< std::endl;
|
||||
std::cerr << "Options\n"
|
||||
<< std::endl;
|
||||
std::cerr << " -M \"{Module-Name}[:Value]}\"\n"
|
||||
<< " Use named module with eventually given parameterization\n"
|
||||
<< std::endl;
|
||||
std::cerr << " -n <N>\n"
|
||||
<< " N >= 1: do N halfedge collapses.\n"
|
||||
<< " N <=-1: decimate down to |N| vertices.\n"
|
||||
<< " 0 < N < 1: decimate down to N%.\n"
|
||||
<< std::endl;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Modules:\n\n";
|
||||
std::cerr << " IS - ModIndependentSets\n";
|
||||
std::cerr << " NF[:angle] - ModNormalFlipping\n";
|
||||
std::cerr << " PM[:file name] - ModProgMesh\n";
|
||||
std::cerr << " Q[:error] - ModQuadric\n";
|
||||
std::cerr << " R[:angle] - ModRoundness\n";
|
||||
std::cerr << " 0 < angle < 60\n";
|
||||
|
||||
exit( xcode );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// end of file
|
||||
//=============================================================================
|
||||
126
Apps/Decimating/decimaterviewer.cc
Normal file
126
Apps/Decimating/decimaterviewer.cc
Normal file
@@ -0,0 +1,126 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Revision: 1.3 $
|
||||
// $Date: 2008-03-11 09:18:01 $
|
||||
//
|
||||
//=============================================================================
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(disable: 4267 4311)
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <getopt.h>
|
||||
#include <qapplication.h>
|
||||
#include <qmessagebox.h>
|
||||
|
||||
#include "DecimaterViewerWidget.hh"
|
||||
|
||||
#include <GL/glut.h>
|
||||
|
||||
|
||||
void usage_and_exit(int xcode);
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if defined(OM_USE_OSG) && OM_USE_OSG
|
||||
osg::osgInit(argc, argv);
|
||||
#endif
|
||||
|
||||
// OpenGL check
|
||||
QApplication::setColorSpec( QApplication::CustomColor );
|
||||
QApplication app(argc,argv);
|
||||
|
||||
glutInit(&argc,argv);
|
||||
|
||||
if ( !QGLFormat::hasOpenGL() ) {
|
||||
QString msg = "System has no OpenGL support!";
|
||||
QMessageBox::critical( NULL, "OpenGL", msg + argv[1] );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int c;
|
||||
OpenMesh::IO::Options opt;
|
||||
|
||||
while ( (c=getopt(argc,argv,"s"))!=-1 )
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case 's': opt += OpenMesh::IO::Options::Swap; break;
|
||||
case 'h':
|
||||
usage_and_exit(0);
|
||||
default:
|
||||
usage_and_exit(1);
|
||||
}
|
||||
}
|
||||
// create widget
|
||||
DecimaterViewerWidget w(0, "Viewer");
|
||||
// app.setMainWidget(&w);
|
||||
|
||||
w.resize(400, 400);
|
||||
w.show();
|
||||
|
||||
// load scene
|
||||
if ( optind < argc )
|
||||
{
|
||||
if ( ! w.open_mesh(argv[optind], opt) )
|
||||
{
|
||||
QString msg = "Cannot read mesh from file:\n '";
|
||||
msg += argv[optind];
|
||||
msg += "'";
|
||||
QMessageBox::critical( NULL, w.windowTitle(), msg );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ++optind < argc )
|
||||
{
|
||||
if ( ! w.open_texture( argv[optind] ) )
|
||||
{
|
||||
QString msg = "Cannot load texture image from file:\n '";
|
||||
msg += argv[optind];
|
||||
msg += "'\n\nPossible reasons:\n";
|
||||
msg += "- Mesh file didn't provide texture coordinates\n";
|
||||
msg += "- Texture file does not exist\n";
|
||||
msg += "- Texture file is not accessible.\n";
|
||||
QMessageBox::warning( NULL, w.windowTitle(), msg );
|
||||
}
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
void usage_and_exit(int xcode)
|
||||
{
|
||||
std::cout << "Usage: decimaterviewer [-s] [mesh] [texture]\n" << std::endl;
|
||||
std::cout << "Options:\n"
|
||||
<< " -s\n"
|
||||
<< " Reverse byte order, when reading binary files.\n"
|
||||
<< std::endl;
|
||||
exit(xcode);
|
||||
}
|
||||
Reference in New Issue
Block a user