Developer Documentation
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 #ifndef BASESKIN_HH
44 #define BASESKIN_HH
45 
46 #include <map>
47 
49 
50 #include <ObjectTypes/Skeleton/SkeletonT.hh>
51 #include <OpenMesh/Core/IO/MeshIO.hh>
52 
53 #include "BlendingMethod.hh"
54 
55 #define OBJECTDATA_SKIN "Skin Object-Data"
56 #define SKIN_WEIGHTS_PROP "skin-weights"
57 #define DEFAULTPOSE_PROP "Default pose"
58 
62 class BaseSkin : public PerObjectData
63 {
64 
65 public:
66 
78  struct DefaultPose
79  {
80  DefaultPose() {};
81  DefaultPose(OpenMesh::Vec3d point, OpenMesh::Vec3d normal) : point(point), normal(normal) {};
82 
85  };
86 
94  typedef std::map<unsigned int, double> SkinWeights;
96 
97 
98 
99 public:
100  BaseSkin(int _skeletonId) {
101  skeleton_ = _skeletonId;
102  };
103 
104  ~BaseSkin() {};
105 
106 public:
112  virtual void attachSkin() = 0;
113  virtual void deformSkin() = 0;
114  virtual void deformSkin(const AnimationHandle &_hAni, Blending::Method _method = Blending::M_LBS) = 0;
115  virtual void releaseSkin() = 0;
117 
122  int skeletonId() {return skeleton_;};
123 
125 
126 private:
128  int skeleton_;
129 };
130 
131 
132 // ----------------------------------------------------------------------------
133 // support persistence for struct Weights
134 // ----------------------------------------------------------------------------
135 
136 namespace OpenMesh {
137  namespace IO {
138 
139  template <> struct binary<BaseSkin::SkinWeights>
140  {
141  typedef BaseSkin::SkinWeights value_type;
142 
143  static const bool is_streamable = true;
144 
145  // return binary size of the value
146 
147  static size_t size_of(void)
148  {
149  return UnknownSize;
150  }
151 
152  static size_t size_of(const value_type& _v)
153  {
154  if (_v.empty())
155  return sizeof(unsigned int);
156 
157  value_type::const_iterator it = _v.begin();
158  unsigned int N = static_cast<unsigned int>(_v.size());
159  size_t bytes = IO::size_of(N);
160 
161  for(;it!=_v.end(); ++it)
162  {
163  bytes += IO::size_of( it->first );
164  bytes += IO::size_of( it->second );
165  }
166  return bytes;
167  }
168 
169  static size_t store(std::ostream& _os, const value_type& _v, bool _swap=false)
170  {
171  value_type::const_iterator it = _v.begin();
172  unsigned int N = static_cast<unsigned int>(_v.size());
173 
174  size_t bytes;
175  bytes = IO::store( _os, N, _swap );
176 
177  for(;it!=_v.end(); ++it)
178  {
179  bytes += IO::store( _os, it->first, _swap );
180  bytes += IO::store( _os, it->second, _swap );
181  }
182 
183  return _os.good() ? bytes : 0;
184  }
185 
186  static size_t restore( std::istream& _is, value_type& _v, bool _swap=false)
187  {
188  unsigned int N = static_cast<unsigned int>(_v.size());
189 
190  size_t bytes;
191  bytes = IO::restore( _is, N, _swap );
192 
193  for(unsigned int i=0; i < N; i++)
194  {
195  unsigned int first;
196  double second;
197 
198  bytes += IO::restore( _is, first, _swap );
199  bytes += IO::restore( _is, second, _swap );
200 
201  _v[first] = second;
202  }
203 
204  return _is.good() ? bytes : 0;
205  }
206  };
207  }
208 }
209 
210 
211 #endif //BASESKIN_HH
Holds the skins default pose.
Definition: BaseSkin.hh:78
Abstract base class for the skin template, wrapping all template versions of the skin.
Definition: BaseSkin.hh:62
OpenMesh::Vec3d normal
The points normal in the default pose.
Definition: BaseSkin.hh:84
size_t size_of(const T &_v)
Definition: StoreRestore.hh:89
Object Payload.
OpenMesh::Vec3d point
The points position in the default pose.
Definition: BaseSkin.hh:81
std::map< unsigned int, double > SkinWeights
Stores the joint weights per vertex.
Definition: BaseSkin.hh:94
int skeleton_
Holds the associated skeleton.
Definition: BaseSkin.hh:122
A handle used to refer to an animation or to a specific frame in an animation.
bool is_streamable(void)
Definition: StoreRestore.hh:81