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