OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArrayKernelT.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08. Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
42
43 //=============================================================================
44 //
45 // CLASS OSGArrayKernelT
46 //
47 //=============================================================================
48
49
50 #ifndef OPENMESH_KERNELOSG_ARRAY_KERNEL_HH
51 #define OPENMEHS_KERNELOSG_ARRAY_KERNEL_HH
52
53
54 //== INCLUDES =================================================================
55
56 #include <vector>
57 // --------------------
58 #include <OpenMesh/Core/System/config.h>
59 #include <OpenMesh/Core/Utils/GenProg.hh>
60 #include <OpenMesh/Core/Mesh/ArrayKernel.hh>
61 // --------------------
62 #include <OpenMesh/Tools/Kernel_OSG/AttribKernelT.hh>
63
64
65
66 //== NAMESPACES ===============================================================
67
68
69 namespace OpenMesh {
70 namespace Kernel_OSG {
71
72 //== CLASS DEFINITION =========================================================
73
74
85 // \see OpenMesh::ArrayHandleT
86 // \see \ref mesh_type
87
88
89 template <class AttribKernel, class FinalMeshItems>
90 class ArrayKernelT
91 : public OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems>
92 {
93 public:
94
95 typedef ArrayKernelT<AttribKernel, FinalMeshItems> This;
96 typedef OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems> Base;
97
98 // attributes
99 // typedef typename Base::HasVertexNormals HasVertexNormals;
100 // typedef typename Base::HasVertexColors HasVertexColors;
101 // typedef typename Base::HasVertexTexCoords HasVertexTexCoords;
102 // typedef typename Base::HasVertexStatus HasVertexStatus;
103 typedef typename Base::HasPrevHalfedge HasPrevHalfedge;
104 // typedef typename Base::HasEdgeStatus HasEdgeStatus;
105 // typedef typename Base::HasFaceNormals HasFaceNormals;
106 // typedef typename Base::HasFaceColors HasFaceColors;
107 // typedef typename Base::HasFaceStatus HasFaceStatus;
108
109 // item types
110 typedef typename FinalMeshItems::Vertex Vertex;
111 typedef typename FinalMeshItems::Halfedge Halfedge;
112 typedef typename FinalMeshItems::Edge Edge;
113 typedef typename FinalMeshItems::Face Face;
114 typedef typename FinalMeshItems::Point Point;
115 typedef typename FinalMeshItems::Normal Normal;
116 typedef typename FinalMeshItems::Color Color;
117 typedef typename FinalMeshItems::TexCoord TexCoord;
118 typedef typename FinalMeshItems::Scalar Scalar;
119
120 // // handles
121 // typedef typename OpenMesh::VertexHandle VertexHandle;
122 // typedef typename FinalMeshItems::HalfedgeHandle HalfedgeHandle;
123 // typedef typename FinalMeshItems::EdgeHandle EdgeHandle;
124 // typedef typename FinalMeshItems::FaceHandle FaceHandle;
125
126 // iterators
127 typedef std::vector<Vertex> VertexContainer;
128 typedef std::vector<Edge> EdgeContainer;
129 typedef std::vector<Face> FaceContainer;
130 typedef typename VertexContainer::iterator KernelVertexIter;
131 typedef typename VertexContainer::const_iterator KernelConstVertexIter;
132 typedef typename EdgeContainer::iterator KernelEdgeIter;
133 typedef typename EdgeContainer::const_iterator KernelConstEdgeIter;
134 typedef typename FaceContainer::iterator KernelFaceIter;
135 typedef typename FaceContainer::const_iterator KernelConstFaceIter;
136
137 public:
138
139 ArrayKernelT() : Base()
140 { }
141
142 virtual ~ArrayKernelT()
143 { }
144
145 public: // replacements
146
147 void set_halfedge_handle(VertexHandle _vh, HalfedgeHandle _heh) {
148 Base::set_halfedge_handle( _vh, _heh );
149 }
150
151 void set_halfedge_handle(FaceHandle _fh, HalfedgeHandle _heh) {
152 Base::set_halfedge_handle( _fh, _heh );
153 osg_sync( _fh );
154 }
155
156 void set_next_halfedge_handle(HalfedgeHandle _heh, HalfedgeHandle _nheh) {
157 Base::set_next_halfedge_handle( _heh, _nheh );
158 osg_sync( face_handle( _heh ) ); // ##Changed
159 }
160
161 void garbage_collection(bool _v=true, bool _e=true, bool _f=true);
162
163 protected:
164
165 bool osg_sync( FaceHandle _fh )
166 {
167 return _fh.is_valid()
168 ? osg_sync( _fh, typename Face::IsTriangle() )
169 : false;
170 }
171
172 private:
173
174 bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<true> )
175 {
176 HalfedgeHandle hh( halfedge_handle(_fh) );
177 if ( !hh.is_valid() ) return false;
178 FaceHandle f1( _fh.idx() * 3 );
179 set_face_indices( f1, to_vertex_handle(hh).idx() );
180
181 hh = next_halfedge_handle(hh);
182 if ( !hh.is_valid() ) return false;
183 FaceHandle f2( f1.idx()+1 );
184 set_face_indices( f2, to_vertex_handle(hh).idx() );
185
186 hh = next_halfedge_handle(hh);
187 if ( !hh.is_valid() ) return false;
188 FaceHandle f3( f1.idx()+2 );
189 set_face_indices( f3, to_vertex_handle(hh).idx() );
190
191 set_face_types ( _fh, GL_TRIANGLES );
192 set_face_lengths( _fh, 3 );
193
194 return true;
195 }
196
197 bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<false> )
198 {
199 return false;
200 }
201
202 };
203
204
205 template <class AttribKernel, class FinalMeshItems>
206 void
207 ArrayKernelT<AttribKernel, FinalMeshItems>::
208 garbage_collection(bool _v, bool _e, bool _f)
209 {
210 Base::garbage_collection(_v, _e, _f);
211 for (size_t fidx=0; fidx < n_faces(); ++fidx)
212 osg_sync( FaceHandle(fidx) );
213 }
214
215 //=============================================================================
216 } // namespace Kernel_OSG
217 } // namespace OpenMesh
218 //=============================================================================
219 #endif // OPENMESH_ARRAY_KERNEL_HH defined
220 //=============================================================================