Developer Documentation

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
45 //=============================================================================
46 //
47 // CLASS OSGArrayKernelT
48 //
49 //=============================================================================
50
51
52 #ifndef OPENMESH_KERNELOSG_ARRAY_KERNEL_HH
53 #define OPENMEHS_KERNELOSG_ARRAY_KERNEL_HH
54
55
56 //== INCLUDES =================================================================
57
58 #include <vector>
59 // --------------------
60 #include <OpenMesh/Core/System/config.h>
61 #include <OpenMesh/Core/Utils/GenProg.hh>
62 #include <OpenMesh/Core/Mesh/ArrayKernel.hh>
63 // --------------------
64 #include <OpenMesh/Tools/Kernel_OSG/AttribKernelT.hh>
65
66
67
68 //== NAMESPACES ===============================================================
69
70
71 namespace OpenMesh {
72 namespace Kernel_OSG {
73
74 //== CLASS DEFINITION =========================================================
75
76
87 // \see OpenMesh::ArrayHandleT
88 // \see \ref mesh_type
89
90
91 template <class AttribKernel, class FinalMeshItems>
92 class ArrayKernelT
93 : public OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems>
94 {
95 public:
96
97 typedef ArrayKernelT<AttribKernel, FinalMeshItems> This;
98 typedef OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems> Base;
99
100 // attributes
101 // typedef typename Base::HasVertexNormals HasVertexNormals;
102 // typedef typename Base::HasVertexColors HasVertexColors;
103 // typedef typename Base::HasVertexTexCoords HasVertexTexCoords;
104 // typedef typename Base::HasVertexStatus HasVertexStatus;
105 typedef typename Base::HasPrevHalfedge HasPrevHalfedge;
106 // typedef typename Base::HasEdgeStatus HasEdgeStatus;
107 // typedef typename Base::HasFaceNormals HasFaceNormals;
108 // typedef typename Base::HasFaceColors HasFaceColors;
109 // typedef typename Base::HasFaceStatus HasFaceStatus;
110
111 // item types
112 typedef typename FinalMeshItems::Vertex Vertex;
113 typedef typename FinalMeshItems::Halfedge Halfedge;
114 typedef typename FinalMeshItems::Edge Edge;
115 typedef typename FinalMeshItems::Face Face;
116 typedef typename FinalMeshItems::Point Point;
117 typedef typename FinalMeshItems::Normal Normal;
118 typedef typename FinalMeshItems::Color Color;
119 typedef typename FinalMeshItems::TexCoord TexCoord;
120 typedef typename FinalMeshItems::Scalar Scalar;
121
122 // // handles
123 // typedef typename OpenMesh::VertexHandle VertexHandle;
124 // typedef typename FinalMeshItems::HalfedgeHandle HalfedgeHandle;
125 // typedef typename FinalMeshItems::EdgeHandle EdgeHandle;
126 // typedef typename FinalMeshItems::FaceHandle FaceHandle;
127
128 // iterators
129 typedef std::vector<Vertex> VertexContainer;
130 typedef std::vector<Edge> EdgeContainer;
131 typedef std::vector<Face> FaceContainer;
132 typedef typename VertexContainer::iterator KernelVertexIter;
133 typedef typename VertexContainer::const_iterator KernelConstVertexIter;
134 typedef typename EdgeContainer::iterator KernelEdgeIter;
135 typedef typename EdgeContainer::const_iterator KernelConstEdgeIter;
136 typedef typename FaceContainer::iterator KernelFaceIter;
137 typedef typename FaceContainer::const_iterator KernelConstFaceIter;
138
139 public:
140
141 ArrayKernelT() : Base()
142 { }
143
144 virtual ~ArrayKernelT()
145 { }
146
147 public: // replacements
148
149 void set_halfedge_handle(VertexHandle _vh, HalfedgeHandle _heh) {
150 Base::set_halfedge_handle( _vh, _heh );
151 }
152
153 void set_halfedge_handle(FaceHandle _fh, HalfedgeHandle _heh) {
154 Base::set_halfedge_handle( _fh, _heh );
155 osg_sync( _fh );
156 }
157
158 void set_next_halfedge_handle(HalfedgeHandle _heh, HalfedgeHandle _nheh) {
159 Base::set_next_halfedge_handle( _heh, _nheh );
160 osg_sync( face_handle( _heh ) ); // ##Changed
161 }
162
163 void garbage_collection(bool _v=true, bool _e=true, bool _f=true);
164
165 protected:
166
167 bool osg_sync( FaceHandle _fh )
168 {
169 return _fh.is_valid()
170 ? osg_sync( _fh, typename Face::IsTriangle() )
171 : false;
172 }
173
174 private:
175
176 bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<true> )
177 {
178 HalfedgeHandle hh( halfedge_handle(_fh) );
179 if ( !hh.is_valid() ) return false;
180 FaceHandle f1( _fh.idx() * 3 );
181 set_face_indices( f1, to_vertex_handle(hh).idx() );
182
183 hh = next_halfedge_handle(hh);
184 if ( !hh.is_valid() ) return false;
185 FaceHandle f2( f1.idx()+1 );
186 set_face_indices( f2, to_vertex_handle(hh).idx() );
187
188 hh = next_halfedge_handle(hh);
189 if ( !hh.is_valid() ) return false;
190 FaceHandle f3( f1.idx()+2 );
191 set_face_indices( f3, to_vertex_handle(hh).idx() );
192
193 set_face_types ( _fh, GL_TRIANGLES );
194 set_face_lengths( _fh, 3 );
195
196 return true;
197 }
198
199 bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<false> )
200 {
201 return false;
202 }
203
204 };
205
206
207 template <class AttribKernel, class FinalMeshItems>
208 void
209 ArrayKernelT<AttribKernel, FinalMeshItems>::
210 garbage_collection(bool _v, bool _e, bool _f)
211 {
212 Base::garbage_collection(_v, _e, _f);
213 for (size_t fidx=0; fidx < n_faces(); ++fidx)
214 osg_sync( FaceHandle(fidx) );
215 }
216
217 //=============================================================================
218 } // namespace Kernel_OSG
219 } // namespace OpenMesh
220 //=============================================================================
221 #endif // OPENMESH_ARRAY_KERNEL_HH defined
222 //=============================================================================
OpenMesh::FaceHandle
Handle for a face entity.
Definition: Handles.hh:141
OpenMesh::Kernel_OSG::ArrayKernelT
Definition: ArrayKernelT.hh:92
OpenMesh::HalfedgeHandle
Handle for a halfedge entity.
Definition: Handles.hh:127
OpenMesh::BaseHandle::idx
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:69
config.h
OpenMesh::VertexHandle
Handle for a vertex entity.
Definition: Handles.hh:120
OpenMesh::BaseHandle::is_valid
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72
OpenMesh::Attributes::Color
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:83
OpenMesh
Definition: MeshItems.hh:59