00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
00044 #define OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
00045
00046
00047
00048
00049 #if !defined(OM_USE_OSG)
00050 # define OM_USE_OSG 0
00051 #endif
00052
00053
00054 #include <qtimer.h>
00055 #include <string>
00056 #include <memory>
00057
00058
00059 #include <OpenMesh/Core/IO/MeshIO.hh>
00060
00061 #if OM_USE_OSG
00062 # include <OpenMesh/Tools/Kernel_OSG/TriMesh_OSGArrayKernelT.hh>
00063 # define DEFAULT_TRAITS Kernel_OSG::Traits
00064 # define TRIMESH_KERNEL Kernel_OSG::TriMesh_OSGArrayKernelT
00065 #else
00066
00067 # include <OpenMesh/Core/Mesh/Traits.hh>
00068 # include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
00069 # define DEFAULT_TRAITS DefaultTraits
00070 # define TRIMESH_KERNEL TriMesh_ArrayKernelT
00071 #endif
00072
00073 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
00074
00075 #include <OpenMesh/Tools/Decimater/DecimaterT.hh>
00076 #include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
00077 #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
00078
00079
00080
00081
00082
00083 using namespace OpenMesh;
00084
00085 struct MyTraits : public DEFAULT_TRAITS
00086 {
00087 VertexAttributes ( Attributes::Normal );
00088 FaceAttributes ( Attributes::Normal );
00089 };
00090
00091 typedef TRIMESH_KERNEL<MyTraits> mesh_t;
00092 typedef MeshViewerWidgetT<mesh_t> MeshViewerWidget;
00093
00094
00095
00096
00097 class DecimaterViewerWidget : public MeshViewerWidget
00098 {
00099 Q_OBJECT
00100
00101 public:
00102
00103 typedef MeshViewerWidget inherited_t;
00104
00105 typedef Decimater::DecimaterT<mesh_t> decimater_t;
00106 typedef Decimater::ModQuadricT< decimater_t > mod_quadric_t;
00107 typedef Decimater::ModNormalFlippingT< decimater_t > mod_nf_t;
00108
00109
00110 typedef std::auto_ptr< decimater_t > decimater_o;
00111 typedef std::auto_ptr< mod_quadric_t > mod_quadric_o;
00112 typedef std::auto_ptr< mod_nf_t > mod_nf_o;
00113
00115 DecimaterViewerWidget(QWidget* _parent=0)
00116 : MeshViewerWidget(_parent), steps_(1)
00117 {
00118 timer_ = new QTimer(this);
00119
00120 connect( timer_, SIGNAL(timeout()), SLOT(animate()) );
00121 }
00122
00124 ~DecimaterViewerWidget()
00125 {
00126 delete timer_;
00127 }
00128
00129 public:
00130
00131 bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt)
00132 {
00133 bool rc;
00134
00135 if ( (rc = inherited_t::open_mesh( _filename, _opt )) )
00136 {
00137 std::cout << "prepare decimater" << std::endl;
00138
00139
00140 {
00141 decimater_o tmp( new decimater_t ( mesh() ) );
00142 decimater_ = tmp;
00143 }
00144 {
00145 mod_quadric_o tmp( new mod_quadric_t( *decimater_ ) );
00146 mod_quadric_ = tmp;
00147 }
00148 {
00149 mod_nf_o tmp( new mod_nf_t ( *decimater_ ) );
00150 mod_nf_ = tmp;
00151 }
00152
00153 decimater_->initialize();
00154 }
00155 return rc;
00156 }
00157
00158 protected slots:
00159
00160 void animate( void );
00161
00162 protected:
00163
00164 virtual void keyPressEvent(QKeyEvent* _event);
00165
00166
00167 private:
00168
00169 bool animate_;
00170 QTimer *timer_;
00171
00172 decimater_o decimater_;
00173 mod_quadric_o mod_quadric_;
00174 mod_nf_o mod_nf_;
00175
00176 size_t steps_;
00177 };
00178
00179
00180
00181 #endif // OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH defined
00182
00183