OpenMesh
OpenMesh/Apps/VDProgMesh/Synthesizer/VDPMSynthesizerViewerWidget.hh
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 496 $                                                         *
00038  *   $Date: 2012-01-16 10:31:24 +0100 (Mo, 16 Jan 2012) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00042 //=============================================================================
00043 //
00044 //  CLASS newClass
00045 //
00046 //=============================================================================
00047 
00048 
00049 #ifndef OPENMESH_VDPROGMESH_VDPMSYNTHESIZERVIEWERWIDGET_HH
00050 #define OPENMESH_VDPROGMESH_VDPMSYNTHESIZERVIEWERWIDGET_HH
00051 
00052 
00053 //== INCLUDES =================================================================
00054 
00055 #include <string>
00056 #include <QTimer>
00057 
00058 #include <OpenMesh/Core/IO/MeshIO.hh>
00059 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
00060 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
00061 
00062 #include <OpenMesh/Tools/VDPM/MeshTraits.hh>
00063 #include <OpenMesh/Tools/VDPM/StreamingDef.hh>
00064 #include <OpenMesh/Tools/VDPM/ViewingParameters.hh>
00065 #include <OpenMesh/Tools/VDPM/VHierarchy.hh>
00066 #include <OpenMesh/Tools/VDPM/VFront.hh>
00067 
00068 
00069 //== FORWARDDECLARATIONS ======================================================
00070 
00071 
00072 //== NAMESPACES ===============================================================
00073 
00074 namespace OpenMesh {
00075 
00076 
00077 //== CLASS DEFINITION =========================================================
00078 
00079               
00089 typedef TriMesh_ArrayKernelT<VDPM::MeshTraits>  VDPMMesh;
00090 typedef MeshViewerWidgetT<VDPMMesh>             MeshViewerWidget;
00091 
00092 
00093   // using view dependent progressive mesh 
00094 
00095   using VDPM::Plane3d;
00096   using VDPM::VFront;
00097   using VDPM::VHierarchy;
00098   using VDPM::VHierarchyNode;
00099   using VDPM::VHierarchyNodeIndex;
00100   using VDPM::VHierarchyNodeHandle;
00101   using VDPM::VHierarchyNodeHandleContainer;
00102   using VDPM::ViewingParameters;
00103 
00104 
00105 //== CLASS DEFINITION =========================================================
00106 
00107 
00108 class VDPMSynthesizerViewerWidget : public MeshViewerWidget
00109 {
00110 public:
00111 
00112   typedef MeshViewerWidget Base;
00113 
00114 public:
00115 
00116   VDPMSynthesizerViewerWidget(QWidget* _parent=0, const char* _name=0);
00117 
00118   ~VDPMSynthesizerViewerWidget();
00119 
00121   void open_vd_prog_mesh(const char* _filename);
00122 
00123 
00124 private:
00125 
00126   QString             qFilename_;
00127   VHierarchy          vhierarchy_;
00128   VFront              vfront_;
00129   ViewingParameters   viewing_parameters_;
00130   float               kappa_square_;
00131   bool                adaptive_mode_;
00132 
00133   unsigned int        n_base_vertices_;
00134   unsigned int        n_base_edges_;
00135   unsigned int        n_base_faces_;
00136   unsigned int        n_details_;
00137 
00138     
00139 private:
00140 
00141   bool outside_view_frustum(const OpenMesh::Vec3f &pos, float radius);
00142 
00143   bool oriented_away(float sin_square, 
00144                      float distance_square, 
00145                      float product_value);
00146 
00147   bool screen_space_error(float mue_square, 
00148                           float sigma_square, 
00149                           float distance_square, 
00150                           float product_value);
00151 
00152   void update_viewing_parameters();
00153 
00154   virtual void keyPressEvent(QKeyEvent* _event);
00155 
00156 protected:
00157 
00159   virtual void draw_scene(const std::string& _draw_mode);
00160 
00161 public:
00162 
00163   void adaptive_refinement();   
00164 
00165   bool qrefine(VHierarchyNodeHandle _node_handle);              
00166 
00167   void force_vsplit(VHierarchyNodeHandle _node_handle);
00168 
00169   bool ecol_legal(VHierarchyNodeHandle _parent_handle, 
00170                   VDPMMesh::HalfedgeHandle& v0v1);
00171 
00172   void get_active_cuts(VHierarchyNodeHandle _node_handle, 
00173                        VDPMMesh::VertexHandle &vl, VDPMMesh::VertexHandle &vr);
00174 
00175   void vsplit(VHierarchyNodeHandle _node_handle, 
00176               VDPMMesh::VertexHandle vl, VDPMMesh::VertexHandle vr);
00177 
00178   void ecol(VHierarchyNodeHandle _parent_handle, 
00179             const VDPMMesh::HalfedgeHandle& v0v1);
00180 
00181   void init_vfront();
00182  
00183 };
00184 
00185 
00186 //=============================================================================
00187 } // namespace OpenMesh
00188 //=============================================================================
00189 #endif // OPENMESHAPPS_VDPMSYNTHESIZERVIEWERWIDGET_HH defined
00190 //=============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines