| OpenMesh

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ArrayKernelT.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42 /*===========================================================================*\
43 * *
44 * $Revision: 1258 $ *
45 * $Date: 2015-04-28 15:07:46 +0200 (Di, 28 Apr 2015) $ *
46 * *
47 \*===========================================================================*/
48
49
50 //=============================================================================
51 //
52 // CLASS OSGArrayKernelT
53 //
54 //=============================================================================
55
56
57 #ifndef OPENMESH_KERNELOSG_ARRAY_KERNEL_HH
58 #define OPENMEHS_KERNELOSG_ARRAY_KERNEL_HH
59
60
61 //== INCLUDES =================================================================
62
63 #include <vector>
64 // --------------------
65 #include <OpenMesh/Core/System/config.h>
66 #include <OpenMesh/Core/Utils/GenProg.hh>
67 #include <OpenMesh/Core/Mesh/ArrayKernel.hh>
68 // --------------------
69 #include <OpenMesh/Tools/Kernel_OSG/AttribKernelT.hh>
70
71
72
73 //== NAMESPACES ===============================================================
74
75
76 namespace OpenMesh {
77 namespace Kernel_OSG {
78
79 //== CLASS DEFINITION =========================================================
80
81
92 // \see OpenMesh::ArrayHandleT
93 // \see \ref mesh_type
94
95
96 template <class AttribKernel, class FinalMeshItems>
97 class ArrayKernelT
98 : public OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems>
99 {
100 public:
101
102 typedef ArrayKernelT<AttribKernel, FinalMeshItems> This;
103 typedef OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems> Base;
104
105 // attributes
106 // typedef typename Base::HasVertexNormals HasVertexNormals;
107 // typedef typename Base::HasVertexColors HasVertexColors;
108 // typedef typename Base::HasVertexTexCoords HasVertexTexCoords;
109 // typedef typename Base::HasVertexStatus HasVertexStatus;
110 typedef typename Base::HasPrevHalfedge HasPrevHalfedge;
111 // typedef typename Base::HasEdgeStatus HasEdgeStatus;
112 // typedef typename Base::HasFaceNormals HasFaceNormals;
113 // typedef typename Base::HasFaceColors HasFaceColors;
114 // typedef typename Base::HasFaceStatus HasFaceStatus;
115
116 // item types
117 typedef typename FinalMeshItems::Vertex Vertex;
118 typedef typename FinalMeshItems::Halfedge Halfedge;
119 typedef typename FinalMeshItems::Edge Edge;
120 typedef typename FinalMeshItems::Face Face;
121 typedef typename FinalMeshItems::Point Point;
122 typedef typename FinalMeshItems::Normal Normal;
123 typedef typename FinalMeshItems::Color Color;
124 typedef typename FinalMeshItems::TexCoord TexCoord;
125 typedef typename FinalMeshItems::Scalar Scalar;
126
127 // // handles
128 // typedef typename OpenMesh::VertexHandle VertexHandle;
129 // typedef typename FinalMeshItems::HalfedgeHandle HalfedgeHandle;
130 // typedef typename FinalMeshItems::EdgeHandle EdgeHandle;
131 // typedef typename FinalMeshItems::FaceHandle FaceHandle;
132
133 // iterators
134 typedef std::vector<Vertex> VertexContainer;
135 typedef std::vector<Edge> EdgeContainer;
136 typedef std::vector<Face> FaceContainer;
137 typedef typename VertexContainer::iterator KernelVertexIter;
138 typedef typename VertexContainer::const_iterator KernelConstVertexIter;
139 typedef typename EdgeContainer::iterator KernelEdgeIter;
140 typedef typename EdgeContainer::const_iterator KernelConstEdgeIter;
141 typedef typename FaceContainer::iterator KernelFaceIter;
142 typedef typename FaceContainer::const_iterator KernelConstFaceIter;
143
144 public:
145
146 ArrayKernelT() : Base()
147 { }
148
149 virtual ~ArrayKernelT()
150 { }
151
152 public: // replacements
153
154 void set_halfedge_handle(VertexHandle _vh, HalfedgeHandle _heh) {
155 Base::set_halfedge_handle( _vh, _heh );
156 }
157
158 void set_halfedge_handle(FaceHandle _fh, HalfedgeHandle _heh) {
159 Base::set_halfedge_handle( _fh, _heh );
160 osg_sync( _fh );
161 }
162
163 void set_next_halfedge_handle(HalfedgeHandle _heh, HalfedgeHandle _nheh) {
164 Base::set_next_halfedge_handle( _heh, _nheh );
165 osg_sync( face_handle( _heh ) ); // ##Changed
166 }
167
168 void garbage_collection(bool _v=true, bool _e=true, bool _f=true);
169
170 protected:
171
172 bool osg_sync( FaceHandle _fh )
173 {
174 return _fh.is_valid()
175 ? osg_sync( _fh, typename Face::IsTriangle() )
176 : false;
177 }
178
179 private:
180
181 bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<true> )
182 {
183 HalfedgeHandle hh( halfedge_handle(_fh) );
184 if ( !hh.is_valid() ) return false;
185 FaceHandle f1( _fh.idx() * 3 );
186 set_face_indices( f1, to_vertex_handle(hh).idx() );
187
188 hh = next_halfedge_handle(hh);
189 if ( !hh.is_valid() ) return false;
190 FaceHandle f2( f1.idx()+1 );
191 set_face_indices( f2, to_vertex_handle(hh).idx() );
192
193 hh = next_halfedge_handle(hh);
194 if ( !hh.is_valid() ) return false;
195 FaceHandle f3( f1.idx()+2 );
196 set_face_indices( f3, to_vertex_handle(hh).idx() );
197
198 set_face_types ( _fh, GL_TRIANGLES );
199 set_face_lengths( _fh, 3 );
200
201 return true;
202 }
203
204 bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<false> )
205 {
206 return false;
207 }
208
209 };
210
211
212 template <class AttribKernel, class FinalMeshItems>
213 void
214 ArrayKernelT<AttribKernel, FinalMeshItems>::
215 garbage_collection(bool _v, bool _e, bool _f)
216 {
217 Base::garbage_collection(_v, _e, _f);
218 for (size_t fidx=0; fidx < n_faces(); ++fidx)
219 osg_sync( FaceHandle(fidx) );
220 }
221
222 //=============================================================================
223 } // namespace Kernel_OSG
224 } // namespace OpenMesh
225 //=============================================================================
226 #endif // OPENMESH_ARRAY_KERNEL_HH defined
227 //=============================================================================
OpenMesh::BaseHandle::is_valid
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
OpenMesh::BaseHandle::idx
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
OpenMesh::FaceHandle
Handle for a face entity.
Definition: Handles.hh:142
OpenMesh::HalfedgeHandle
Handle for a halfedge entity.
Definition: Handles.hh:128
OpenMesh::Attributes::Color
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:88
OpenMesh::Attributes::Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
OpenMesh::Kernel_OSG::ArrayKernelT
Mesh kernel using arrays for mesh item storage.
Definition: ArrayKernelT.hh:97
OpenMesh::VertexHandle
Handle for a vertex entity.
Definition: Handles.hh:121