Developer Documentation
SkeletonNodeT.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 
51 #ifndef ACG_SKELETONNODET_HH
52 #define ACG_SKELETONNODET_HH
53 
54 
55 //== INCLUDES =================================================================
56 
57 #include <ACG/Scenegraph/MaterialNode.hh>
58 #include <ACG/Scenegraph/DrawModes.hh>
59 #include <ACG/GL/GLPrimitives.hh>
60 #include <ACG/GL/globjects.hh>
61 #include "JointT.hh"
62 
63 //== FORWARDDECLARATIONS ======================================================
64 
65 //== NAMESPACES ===============================================================
66 
67 namespace ACG {
68 namespace SceneGraph {
69 
70 //== CLASS DEFINITION =========================================================
71 
72 
73 
74 
82 template <class SkeletonType>
83 class SkeletonNodeT : public BaseNode
84 {
85 public:
86  // static name of this class
87  ACG_CLASSNAME(SkeletonNodeT);
88 
89  typedef typename SkeletonType::Point Point;
91  typedef typename SkeletonType::Pose Pose;
92  typedef typename SkeletonType::Matrix Matrix;
93 
94 public:
95 
97  SkeletonNodeT(SkeletonType &_skeleton, BaseNode *_parent=0, std::string _name="<SkeletonNode>");
98 
100  ~SkeletonNodeT();
101 
102 public:
104  SkeletonType& skeleton();
105 
109  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
111  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
113  void pick(GLState& _state, PickTarget _target);
114 
116  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
117 
119  void setActivePose(const AnimationHandle &_hAni);
122 
124  void showCoordFrames(bool _bVisible = true);
125 
126  bool coordFramesVisible();
127 
129  double frameSize();
130 
131 private:
133  void pick_vertices( GLState& _state );
135  void pick_edges(GLState& _state);
136 
138  void draw_bone(GLState &_state, DrawModes::DrawMode _drawMode, const Point& _parent, const Point& _axis);
139 
141  void addBoneToRenderer(IRenderer* _renderer, RenderObject& _base, const Point& _parent, const Point& _axis);
142 
144  void computeConeMatrices(const GLMatrixf& _modelView, const Point& _parent, const Point& _axis,
145  GLMatrixf* _outCone0, GLMatrixf* _outCone1);
146 
148  void NormalizeCoordinateFrame(Matrix &_mat);
149 
151  void getJointColor( const Vec4f& _baseColor, Vec4f& _result );
152 
154  void HSVtoRGB(const Vec4f& _HSV, Vec4f& _RGB);
156  void RGBtoHSV(const Vec4f& _RGB, Vec4f& _HSV);
157 
158 
160  double unprojectPointSize(double _pointSize, const Vec3d& _point, GLState& _state);
161 
162 
163 private:
167  SkeletonType& skeleton_;
170 
172  double fFrameSize_;
173 
174  int slices_;
175  int stacks_;
176 
177  ACG::GLSphere* sphere_;
178  ACG::GLCone* cone_;
179  ACG::GLCylinder* cylinder_;
180 
181 
182  // instanced rendering with render objects:
183  // store modelview and color of instances in a separate vbo
184 
186  GeometryBuffer pointInstanceData_;
187  VertexDeclaration pointInstanceDecl_;
188 
190  GeometryBuffer boneInstanceData_;
191  VertexDeclaration boneInstanceDecl_;
192 };
193 
194 
195 //=============================================================================
196 } // namespace SceneGraph
197 } // namespace ACG
198 //=============================================================================
199 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_SKELETONNODET_C)
200 #define ACG_SKELETONNODET_TEMPLATES
201 #include "SkeletonNodeT.cc"
202 #endif
203 //=============================================================================
204 #endif // ACG_SKELETONNODET_HH defined
205 //=============================================================================
206 
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
Returns the bounding box of this node.
SkeletonType & skeleton_
The skeleton nodes skeleton.
DrawModes::DrawMode availableDrawModes() const
Returns available draw modes.
GeometryBuffer boneInstanceData_
per instance data of bones
void getJointColor(const Vec4f &_baseColor, Vec4f &_result)
get a joint color suitable to the baseColor
Represents a single joint in the skeleton.
Definition: JointT.hh:66
bool bCoordFramesVisible_
Coordinate frames are visible if this is true, not visible if false.
Class to define the vertex input layout.
void addBoneToRenderer(IRenderer *_renderer, RenderObject &_base, const Point &_parent, const Point &_axis)
Helper function to create a renderobject for bones.
void pick_edges(GLState &_state)
Pick method for edges.
void RGBtoHSV(const Vec4f &_RGB, Vec4f &_HSV)
Convert RGB color to HSV.
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
void draw_bone(GLState &_state, DrawModes::DrawMode _drawMode, const Point &_parent, const Point &_axis)
Helper function to draw the bones.
A handle used to refer to an animation or to a specific frame in an animation.
AnimationHandle activePose()
Get the pose that is used for rendering.
void HSVtoRGB(const Vec4f &_HSV, Vec4f &_RGB)
Convert HSV color to RGB.
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
Adds renderobjects to renderer for flexible shader pipeline.
SkeletonType & skeleton()
Returns a pointer to the skeleton.
double fFrameSize_
size for the coord-frame
double unprojectPointSize(double _pointSize, const Vec3d &_point, GLState &_state)
Simulate glPointSize(12) with a sphere.
GeometryBuffer pointInstanceData_
per instance data of joint spheres
void pick(GLState &_state, PickTarget _target)
Renders the node in picking mode, restricted to the node components given by _target.
double frameSize()
returns the size of the rendered coordinate system
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void pick_vertices(GLState &_state)
Pick method for vertices.
void computeConeMatrices(const GLMatrixf &_modelView, const Point &_parent, const Point &_axis, GLMatrixf *_outCone0, GLMatrixf *_outCone1)
Helper function to compute modelview matrices for the two cones composing a bone. ...
void setActivePose(const AnimationHandle &_hAni)
Set the pose which should be rendered.
SkeletonNodeT(SkeletonType &_skeleton, BaseNode *_parent=0, std::string _name="<SkeletonNode>")
Constructor.
Interface class between scenegraph and renderer.
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
Renders the nodes contents using the given render state and draw mode.
AnimationHandle hAni_
The active pose, this one is going to be rendered.
void NormalizeCoordinateFrame(Matrix &_mat)
Normalizes a coordinate frame defined by the given matrix.
void showCoordFrames(bool _bVisible=true)
Toggle visibility of coordinate frames for all joints.