OpenMesh
|
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: 362 $ * 00038 * $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $ * 00039 * * 00040 \*===========================================================================*/ 00041 00042 00043 //============================================================================= 00044 // 00045 // CLASS OSGArrayKernelT 00046 // 00047 //============================================================================= 00048 00049 00050 #ifndef OPENMESH_KERNELOSG_ARRAY_KERNEL_HH 00051 #define OPENMEHS_KERNELOSG_ARRAY_KERNEL_HH 00052 00053 00054 //== INCLUDES ================================================================= 00055 00056 #include <vector> 00057 // -------------------- 00058 #include <OpenMesh/Core/System/config.h> 00059 #include <OpenMesh/Core/Utils/GenProg.hh> 00060 #include <OpenMesh/Core/Mesh/ArrayKernel.hh> 00061 // -------------------- 00062 #include <OpenMesh/Tools/Kernel_OSG/AttribKernelT.hh> 00063 00064 00065 00066 //== NAMESPACES =============================================================== 00067 00068 00069 namespace OpenMesh { 00070 namespace Kernel_OSG { 00071 00072 //== CLASS DEFINITION ========================================================= 00073 00074 00085 // \see OpenMesh::ArrayHandleT 00086 // \see \ref mesh_type 00087 00088 00089 template <class AttribKernel, class FinalMeshItems> 00090 class ArrayKernelT 00091 : public OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems> 00092 { 00093 public: 00094 00095 typedef ArrayKernelT<AttribKernel, FinalMeshItems> This; 00096 typedef OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems> Base; 00097 00098 // attributes 00099 // typedef typename Base::HasVertexNormals HasVertexNormals; 00100 // typedef typename Base::HasVertexColors HasVertexColors; 00101 // typedef typename Base::HasVertexTexCoords HasVertexTexCoords; 00102 // typedef typename Base::HasVertexStatus HasVertexStatus; 00103 typedef typename Base::HasPrevHalfedge HasPrevHalfedge; 00104 // typedef typename Base::HasEdgeStatus HasEdgeStatus; 00105 // typedef typename Base::HasFaceNormals HasFaceNormals; 00106 // typedef typename Base::HasFaceColors HasFaceColors; 00107 // typedef typename Base::HasFaceStatus HasFaceStatus; 00108 00109 // item types 00110 typedef typename FinalMeshItems::Vertex Vertex; 00111 typedef typename FinalMeshItems::Halfedge Halfedge; 00112 typedef typename FinalMeshItems::Edge Edge; 00113 typedef typename FinalMeshItems::Face Face; 00114 typedef typename FinalMeshItems::Point Point; 00115 typedef typename FinalMeshItems::Normal Normal; 00116 typedef typename FinalMeshItems::Color Color; 00117 typedef typename FinalMeshItems::TexCoord TexCoord; 00118 typedef typename FinalMeshItems::Scalar Scalar; 00119 00120 // // handles 00121 // typedef typename OpenMesh::VertexHandle VertexHandle; 00122 // typedef typename FinalMeshItems::HalfedgeHandle HalfedgeHandle; 00123 // typedef typename FinalMeshItems::EdgeHandle EdgeHandle; 00124 // typedef typename FinalMeshItems::FaceHandle FaceHandle; 00125 00126 // iterators 00127 typedef std::vector<Vertex> VertexContainer; 00128 typedef std::vector<Edge> EdgeContainer; 00129 typedef std::vector<Face> FaceContainer; 00130 typedef typename VertexContainer::iterator KernelVertexIter; 00131 typedef typename VertexContainer::const_iterator KernelConstVertexIter; 00132 typedef typename EdgeContainer::iterator KernelEdgeIter; 00133 typedef typename EdgeContainer::const_iterator KernelConstEdgeIter; 00134 typedef typename FaceContainer::iterator KernelFaceIter; 00135 typedef typename FaceContainer::const_iterator KernelConstFaceIter; 00136 00137 public: 00138 00139 ArrayKernelT() : Base() 00140 { } 00141 00142 virtual ~ArrayKernelT() 00143 { } 00144 00145 public: // replacements 00146 00147 void set_halfedge_handle(VertexHandle _vh, HalfedgeHandle _heh) { 00148 Base::set_halfedge_handle( _vh, _heh ); 00149 } 00150 00151 void set_halfedge_handle(FaceHandle _fh, HalfedgeHandle _heh) { 00152 Base::set_halfedge_handle( _fh, _heh ); 00153 osg_sync( _fh ); 00154 } 00155 00156 void set_next_halfedge_handle(HalfedgeHandle _heh, HalfedgeHandle _nheh) { 00157 Base::set_next_halfedge_handle( _heh, _nheh ); 00158 osg_sync( face_handle( _heh ) ); // ##Changed 00159 } 00160 00161 void garbage_collection(bool _v=true, bool _e=true, bool _f=true); 00162 00163 protected: 00164 00165 bool osg_sync( FaceHandle _fh ) 00166 { 00167 return _fh.is_valid() 00168 ? osg_sync( _fh, typename Face::IsTriangle() ) 00169 : false; 00170 } 00171 00172 private: 00173 00174 bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<true> ) 00175 { 00176 HalfedgeHandle hh( halfedge_handle(_fh) ); 00177 if ( !hh.is_valid() ) return false; 00178 FaceHandle f1( _fh.idx() * 3 ); 00179 set_face_indices( f1, to_vertex_handle(hh).idx() ); 00180 00181 hh = next_halfedge_handle(hh); 00182 if ( !hh.is_valid() ) return false; 00183 FaceHandle f2( f1.idx()+1 ); 00184 set_face_indices( f2, to_vertex_handle(hh).idx() ); 00185 00186 hh = next_halfedge_handle(hh); 00187 if ( !hh.is_valid() ) return false; 00188 FaceHandle f3( f1.idx()+2 ); 00189 set_face_indices( f3, to_vertex_handle(hh).idx() ); 00190 00191 set_face_types ( _fh, GL_TRIANGLES ); 00192 set_face_lengths( _fh, 3 ); 00193 00194 return true; 00195 } 00196 00197 bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<false> ) 00198 { 00199 return false; 00200 } 00201 00202 }; 00203 00204 00205 template <class AttribKernel, class FinalMeshItems> 00206 void 00207 ArrayKernelT<AttribKernel, FinalMeshItems>:: 00208 garbage_collection(bool _v, bool _e, bool _f) 00209 { 00210 Base::garbage_collection(_v, _e, _f); 00211 for (size_t fidx=0; fidx < n_faces(); ++fidx) 00212 osg_sync( FaceHandle(fidx) ); 00213 } 00214 00215 //============================================================================= 00216 } // namespace Kernel_OSG 00217 } // namespace OpenMesh 00218 //============================================================================= 00219 #endif // OPENMESH_ARRAY_KERNEL_HH defined 00220 //=============================================================================