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