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
62class BaseSkin : public PerObjectData
63{
64
65public:
66
79 {
80 DefaultPose() {};
82
85 };
86
94 typedef std::map<unsigned int, double> SkinWeights;
96
97
98
99public:
100 BaseSkin(int _skeletonId) {
101 skeleton_ = _skeletonId;
102 };
103
105
106public:
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
126private:
129};
130
131
132// ----------------------------------------------------------------------------
133// support persistence for struct Weights
134// ----------------------------------------------------------------------------
135
136namespace 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 std::string type_identifier() { return "SkinWeights"; }
148
149 static size_t size_of(void)
150 {
151 return UnknownSize;
152 }
153
154 static size_t size_of(const value_type& _v)
155 {
156 if (_v.empty())
157 return sizeof(unsigned int);
158
159 value_type::const_iterator it = _v.begin();
160 unsigned int N = static_cast<unsigned int>(_v.size());
161 size_t bytes = IO::size_of(N);
162
163 for(;it!=_v.end(); ++it)
164 {
165 bytes += IO::size_of( it->first );
166 bytes += IO::size_of( it->second );
167 }
168 return bytes;
169 }
170
171 static size_t store(std::ostream& _os, const value_type& _v, bool _swap=false)
172 {
173 value_type::const_iterator it = _v.begin();
174 unsigned int N = static_cast<unsigned int>(_v.size());
175
176 size_t bytes;
177 bytes = IO::store( _os, N, _swap );
178
179 for(;it!=_v.end(); ++it)
180 {
181 bytes += IO::store( _os, it->first, _swap );
182 bytes += IO::store( _os, it->second, _swap );
183 }
184
185 return _os.good() ? bytes : 0;
186 }
187
188 static size_t restore( std::istream& _is, value_type& _v, bool _swap=false)
189 {
190 unsigned int N = static_cast<unsigned int>(_v.size());
191
192 size_t bytes;
193 bytes = IO::restore( _is, N, _swap );
194
195 for(unsigned int i=0; i < N; i++)
196 {
197 unsigned int first;
198 double second;
199
200 bytes += IO::restore( _is, first, _swap );
201 bytes += IO::restore( _is, second, _swap );
202
203 _v[first] = second;
204 }
205
206 return _is.good() ? bytes : 0;
207 }
208 };
209 }
210}
211
212
213#endif //BASESKIN_HH
A handle used to refer to an animation or to a specific frame in an animation.
Abstract base class for the skin template, wrapping all template versions of the skin.
Definition: BaseSkin.hh:63
BaseSkin(int _skeletonId)
Stores the joint weights per vertex.
Definition: BaseSkin.hh:100
int skeleton_
Holds the associated skeleton.
Definition: BaseSkin.hh:128
int skeletonId()
Holds the associated skeleton.
Definition: BaseSkin.hh:122
~BaseSkin()
Stores the joint weights per vertex.
Definition: BaseSkin.hh:104
std::map< unsigned int, double > SkinWeights
Stores the joint weights per vertex.
Definition: BaseSkin.hh:94
Object Payload.
size_t size_of(const T &_v)
Definition: StoreRestore.hh:89
Holds the skins default pose.
Definition: BaseSkin.hh:79
OpenMesh::Vec3d normal
The points normal in the default pose.
Definition: BaseSkin.hh:84
OpenMesh::Vec3d point
The points position in the default pose.
Definition: BaseSkin.hh:83
static size_t restore(std::istream &, value_type &, bool=false, bool=true)
Restore a value of T and return the number of bytes read.
Definition: SR_binary.hh:125
static const bool is_streamable
Can we store T? Set this to true in your specialization.
Definition: SR_binary.hh:101
static size_t store(std::ostream &, const value_type &, bool=false, bool=true)
Store a value of T and return the number of bytes written.
Definition: SR_binary.hh:113
static std::string type_identifier(void)
A string that identifies the type of T.
Definition: SR_binary.hh:109
static size_t size_of(void)
What's the size of T? If it depends on the actual value (e.g. for vectors) return UnknownSize.
Definition: SR_binary.hh:104