Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
BaseSkin.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
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 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef BASESKIN_HH
51 #define BASESKIN_HH
52 
53 #include <map>
54 
56 
57 #include <ObjectTypes/Skeleton/SkeletonT.hh>
58 #include <OpenMesh/Core/IO/MeshIO.hh>
59 
60 #define OBJECTDATA_SKIN "Skin Object-Data"
61 #define SKIN_WEIGHTS_PROP "skin-weights"
62 #define DEFAULTPOSE_PROP "Default pose"
63 
67 class BaseSkin : public PerObjectData
68 {
69 
70 public:
71 
83  struct DefaultPose
84  {
85  DefaultPose() {};
86  DefaultPose(OpenMesh::Vec3d point, OpenMesh::Vec3d normal) : point(point), normal(normal) {};
87 
90  };
91 
99  typedef std::map<unsigned int, double> SkinWeights;
101 
109  enum Method
110  {
111  M_LBS = 0,
112  M_DBS = 1
113  };
114 
115 public:
116  BaseSkin(int _skeletonId) {
117  skeleton_ = _skeletonId;
118  };
119 
120  ~BaseSkin() {};
121 
122 public:
128  virtual void attachSkin() = 0;
129  virtual void deformSkin() = 0;
130  virtual void deformSkin(const AnimationHandle &_hAni, Method _method = M_LBS) = 0;
131  virtual void releaseSkin() = 0;
133 
138  int skeletonId() {return skeleton_;};
139 
141 
142 private:
144  int skeleton_;
145 };
146 
147 
148 // ----------------------------------------------------------------------------
149 // support persistence for struct Weights
150 // ----------------------------------------------------------------------------
151 
152 namespace OpenMesh {
153  namespace IO {
154 
155  template <> struct binary<BaseSkin::SkinWeights>
156  {
157  typedef BaseSkin::SkinWeights value_type;
158 
159  static const bool is_streamable = true;
160 
161  // return binary size of the value
162 
163  static size_t size_of(void)
164  {
165  return UnknownSize;
166  }
167 
168  static size_t size_of(const value_type& _v)
169  {
170  if (_v.empty())
171  return sizeof(unsigned int);
172 
173  value_type::const_iterator it = _v.begin();
174  unsigned int N = static_cast<unsigned int>(_v.size());
175  size_t bytes = IO::size_of(N);
176 
177  for(;it!=_v.end(); ++it)
178  {
179  bytes += IO::size_of( it->first );
180  bytes += IO::size_of( it->second );
181  }
182  return bytes;
183  }
184 
185  static size_t store(std::ostream& _os, const value_type& _v, bool _swap=false)
186  {
187  value_type::const_iterator it = _v.begin();
188  unsigned int N = static_cast<unsigned int>(_v.size());
189 
190  size_t bytes;
191  bytes = IO::store( _os, N, _swap );
192 
193  for(;it!=_v.end(); ++it)
194  {
195  bytes += IO::store( _os, it->first, _swap );
196  bytes += IO::store( _os, it->second, _swap );
197  }
198 
199  return _os.good() ? bytes : 0;
200  }
201 
202  static size_t restore( std::istream& _is, value_type& _v, bool _swap=false)
203  {
204  unsigned int N = static_cast<unsigned int>(_v.size());
205 
206  size_t bytes;
207  bytes = IO::restore( _is, N, _swap );
208 
209  for(unsigned int i=0; i < N; i++)
210  {
211  unsigned int first;
212  double second;
213 
214  bytes += IO::restore( _is, first, _swap );
215  bytes += IO::restore( _is, second, _swap );
216 
217  _v[first] = second;
218  }
219 
220  return _is.good() ? bytes : 0;
221  }
222  };
223  }
224 }
225 
226 
227 #endif //BASESKIN_HH
Method
Possible deformation methods.
Definition: BaseSkin.hh:109
OpenMesh::Vec3d normal
The points normal in the default pose.
Definition: BaseSkin.hh:89
Abstract base class for the skin template, wrapping all template versions of the skin.
Definition: BaseSkin.hh:67
int skeleton_
Holds the associated skeleton.
Definition: BaseSkin.hh:138
OpenMesh::Vec3d point
The points position in the default pose.
Definition: BaseSkin.hh:86
Holds the skins default pose.
Definition: BaseSkin.hh:83
size_t size_of(const T &_v)
Definition: StoreRestore.hh:94
std::map< unsigned int, double > SkinWeights
Stores the joint weights per vertex.
Definition: BaseSkin.hh:99
A handle used to refer to an animation or to a specific frame in an animation.
Object Payload.