Commit 97f51598 authored by Jan Möbius's avatar Jan Möbius

First checkin for OpenMesh 2.0



git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@2 fdac6126-5c0c-442c-9429-916003d36597
parent c3321ebd
#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
//=============================================================================
//
// 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);
}
//=============================================================================
//=============================================================================
//
// 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
//=============================================================================
################################################################################
#
################################################################################
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)
################################################################################
<?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="..\..\..;&quot;$(QTDIR)/include&quot;"
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="..\..\..;&quot;$(QTDIR)/include&quot;"
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"
/>
&