Developer Documentation
PropertyKernel.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$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
49 #ifndef OPENMESH_KERNEL_OSG_PROPERTYKERNEL_HH
50 #define OPENMESH_KENREL_OSG_PROPERTYKERNEL_HH
51 
52 
53 //== INCLUDES =================================================================
54 
55 #include <OpenMesh/Core/Utils/Property.hh>
56 #include <OpenMesh/Core/Mesh/BaseKernel.hh>
57 // --------------------
58 #include <OpenMesh/Tools/Kernel_OSG/PropertyT.hh>
59 
60 //== NAMESPACES ===============================================================
61 
62 namespace OpenMesh {
63 namespace Kernel_OSG {
64 
65 //== CLASS DEFINITION =========================================================
66 
72 template < typename IsTriMesh >
74 {
75 public:
76 
77  // --------------------------------------------------------------- item types
78 
82 
86 
87  // ------------------------------------------------- constructor / destructor
88 
89  PropertyKernel() {}
90  virtual ~PropertyKernel() { }
91 
92 
93 protected: // ---------------------------------------------- add osg properties
94 
95  // -------------------- vertex properties
96 
97  template < typename T >
98  VPropHandleT<T> add_vpositions( const T& _t, const std::string& _n )
99  { return VPropHandleT<T>(_add_vprop( new typename _t2vp<T>::prop(_n))); }
100 
101  template < typename T >
102  VPropHandleT<T> add_vnormals( const T& _t, const std::string& _n )
103  { return VPropHandleT<T>(_add_vprop( new typename _t2vn<T>::prop(_n) )); }
104 
105  template < typename T >
106  VPropHandleT<T> add_vcolors( const T& _t, const std::string& _n )
107  { return VPropHandleT<T>(_add_vprop( new typename _t2vc<T>::prop(_n) )); }
108 
109  template < typename T >
110  VPropHandleT<T> add_vtexcoords( const T& _t, const std::string& _n )
111  { return VPropHandleT<T>(_add_vprop( new typename _t2vtc<T>::prop(_n) )); }
112 
113 
114  // -------------------- face properties
115 
116  FPTypesHandle add_fptypes( )
117  { return FPTypesHandle(_add_fprop(new GeoPTypes)); }
118 
119  FPLengthsHandle add_fplengths( )
120  { return FPLengthsHandle(_add_fprop(new GeoPLengths)); }
121 
122  FIndicesHandle add_findices( FPTypesHandle _pht, FPLengthsHandle _phl )
123  {
124  GeoIndices *bp = new GeoIndices( fptypes(_pht), fplengths(_phl ) );
125  return FIndicesHandle(_add_fprop( bp ) );
126  }
127 
128 protected: // ------------------------------------------- access osg properties
129 
130  template < typename T >
131  typename _t2vp<T>::prop& vpositions( VPropHandleT<T> _ph )
132  { return static_cast<typename _t2vp<T>::prop&>( _vprop( _ph ) ); }
133 
134  template < typename T >
135  const typename _t2vp<T>::prop& vpositions( VPropHandleT<T> _ph) const
136  { return static_cast<const typename _t2vp<T>::prop&>( _vprop( _ph ) ); }
137 
138 
139  template < typename T >
140  typename _t2vn<T>::prop& vnormals( VPropHandleT<T> _ph )
141  { return static_cast<typename _t2vn<T>::prop&>( _vprop( _ph ) ); }
142 
143  template < typename T >
144  const typename _t2vn<T>::prop& vnormals( VPropHandleT<T> _ph) const
145  { return static_cast<const typename _t2vn<T>::prop&>( _vprop( _ph ) ); }
146 
147 
148  template < typename T >
149  typename _t2vc<T>::prop& vcolors( VPropHandleT<T> _ph )
150  { return static_cast<typename _t2vc<T>::prop&>( _vprop( _ph ) ); }
151 
152  template < typename T >
153  const typename _t2vc<T>::prop& vcolors( VPropHandleT<T> _ph ) const
154  { return static_cast<const typename _t2vc<T>::prop&>( _vprop( _ph ) ); }
155 
156 
157  template < typename T >
158  typename _t2vtc<T>::prop& vtexcoords( VPropHandleT<T> _ph )
159  { return static_cast<typename _t2vtc<T>::prop&>( _vprop( _ph ) ); }
160 
161  template < typename T >
162  const typename _t2vtc<T>::prop& vtexcoords( VPropHandleT<T> _ph ) const
163  { return static_cast<const typename _t2vtc<T>::prop&>( _vprop( _ph ) ); }
164 
165 
166  //
167  GeoPTypes& fptypes( FPTypesHandle _ph )
168  { return static_cast<GeoPTypes&>( _fprop(_ph) ); }
169 
170  const GeoPTypes& fptypes( FPTypesHandle _ph ) const
171  { return static_cast<const GeoPTypes&>( _fprop(_ph) ); }
172 
173 
174  GeoPLengths& fplengths( FPLengthsHandle _ph )
175  { return static_cast<GeoPLengths&>( _fprop(_ph) ); }
176 
177  const GeoPLengths& fplengths( FPLengthsHandle _ph ) const
178  { return static_cast<const GeoPLengths&>( _fprop(_ph) ); }
179 
180 
181  GeoIndices& findices( FIndicesHandle _ph )
182  { return static_cast<GeoIndices&>( _fprop(_ph) ); }
183 
184  const GeoIndices& findices( FIndicesHandle _ph ) const
185  { return static_cast<const GeoIndices&>( _fprop(_ph) ); }
186 
187 
188 protected: // ------------------------------------ access osg property elements
189 
190  template <typename T>
191  T& vpositions( VPropHandleT<T> _ph, VertexHandle _vh )
192  { return vpositions(_ph)[_vh.idx()]; }
193 
194  template <class T>
195  const T& vpositions( VPropHandleT<T> _ph, VertexHandle _vh ) const
196  { return vpositions(_ph)[_vh.idx()]; }
197 
198 
199  template < typename T>
200  T& vnormals( VPropHandleT<T> _ph, VertexHandle _vh )
201  { return vnormals(_ph)[_vh.idx()]; }
202 
203  template <class T>
204  const T& vnormals( VPropHandleT<T> _ph, VertexHandle _vh ) const
205  { return vnormals(_ph)[_vh.idx()]; }
206 
207 
208  template < typename T>
209  T& vcolors( VPropHandleT<T> _ph, VertexHandle _vh )
210  { return vcolors(_ph)[_vh.idx()]; }
211 
212  template <class T>
213  const T& vcolors( VPropHandleT<T> _ph, VertexHandle _vh ) const
214  { return vcolors(_ph)[_vh.idx()]; }
215 
216 
217  template < typename T>
218  T& vtexcoords( VPropHandleT<T> _ph, VertexHandle _vh )
219  { return vtexcoords(_ph)[_vh.idx()]; }
220 
221  template <class T>
222  const T& vtexcoords( VPropHandleT<T> _ph, VertexHandle _vh ) const
223  { return vtexcoords(_ph)[_vh.idx()]; }
224 
225 
226  // -------------------- access face property elements
227 
228  FPTypesHandle::value_type&
229  fptypes( FPTypesHandle _ph, FaceHandle _fh )
230  { return fptypes( _ph )[ _fh.idx()]; }
231 
232  const FPTypesHandle::value_type&
233  fptypes( FPTypesHandle _ph, FaceHandle _fh ) const
234  { return fptypes( _ph )[ _fh.idx()]; }
235 
236 
237  FPLengthsHandle::value_type&
238  fplengths( FPLengthsHandle _ph, FaceHandle _fh )
239  { return fplengths( _ph )[ _fh.idx()]; }
240 
241  const FPLengthsHandle::value_type&
242  fplengths( FPLengthsHandle _ph, FaceHandle _fh ) const
243  { return fplengths( _ph )[ _fh.idx()]; }
244 
245 
246  FIndicesHandle::value_type&
247  findices( FIndicesHandle _ph, FaceHandle _fh )
248  { return findices( _ph )[ _fh.idx()]; }
249 
250  const FIndicesHandle::value_type&
251  findices( FIndicesHandle _ph, FaceHandle _fh ) const
252  { return findices( _ph )[ _fh.idx()]; }
253 
254 public:
255 
256  void stats(void)
257  {
258  std::cout << "#V : " << n_vertices() << std::endl;
259  std::cout << "#E : " << n_edges() << std::endl;
260  std::cout << "#F : " << n_faces() << std::endl;
261  property_stats();
262  }
263 };
264 
265 
266 //=============================================================================
267 } // namespace Kernel_OSG
268 } // namespace OpenMesh
269 //=============================================================================
270 #endif // OPENMESH_KERNEL_OSG_PROPERTYKERNEL_HH defined
271 //=============================================================================
272 
Adaptor for osg::GeoIndicesUI32.
Definition: PropertyT.hh:293
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
Handle for a vertex entity.
Definition: Handles.hh:125
Handle for a face entity.
Definition: Handles.hh:146