DART  6.7.3
OpenGLRenderInterface.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2019, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_GUI_OPENGLRENDERINTERFACE_HPP_
34 #define DART_GUI_OPENGLRENDERINTERFACE_HPP_
35 
36 #include <list>
37 #include <vector>
39 #include "dart/gui/LoadOpengl.hpp"
40 
41 namespace dart {
42 
43 namespace dynamics {
44 class Skeleton;
45 class BodyNode;
46 class Shape;
47 class ShapeFrame;
48 }
49 
50 namespace gui {
52 
53 public:
56 
57  void initialize() override;
58  void destroy() override;
59 
60  void setViewport(int _x,int _y,int _width,int _height) override;
61  void getViewport(int& _x, int& _y, int& _width, int& _height) const override;
62 
63  void clear(const Eigen::Vector3d& _color) override;
64 
65  void setMaterial(const Eigen::Vector3d& _diffuse, const Eigen::Vector3d& _specular, double _cosinePow) override;
66  void getMaterial(Eigen::Vector3d& _diffuse, Eigen::Vector3d& _specular, double& _cosinePow) const override;
67  void setDefaultMaterial() override;
68 
69  void pushMatrix() override;
70  void popMatrix() override;
71  void pushName(int _id) override;
72  void popName() override;
73 
74  void translate(const Eigen::Vector3d& _offset) override; //glTranslate
75  void rotate(const Eigen::Vector3d& _axis, double _rad) override; //glRotate
76  void transform(const Eigen::Isometry3d& _transform) override; //glMultMatrix
77  void scale(const Eigen::Vector3d& _scale) override; //glScale
78 
79  void compileList(dynamics::Skeleton* _skel);
80  void compileList(dynamics::BodyNode* _node);
81  void compileList(dynamics::Shape* _shape);
82  GLuint compileList(const Eigen::Vector3d& _scale, const aiScene* _mesh);
83 
84  void drawSphere(double radius, int slices = 16, int stacks = 16) override;
85  void drawMultiSphere(const std::vector<std::pair<double, Eigen::Vector3d>>& spheres, int slices = 16, int stacks = 16) override;
86  void drawEllipsoid(const Eigen::Vector3d& _diameters) override;
87  void drawCube(const Eigen::Vector3d& _size) override;
88  void drawOpenCylinder(double baseRadius, double topRadius, double height, int slices = 16, int stacks = 16) override;
89  void drawCylinder(double _radius, double _height, int slices = 16, int stacks = 16) override;
90  void drawCapsule(double radius, double height) override;
91  void drawCone(double radius, double height) override;
92  void drawMesh(const Eigen::Vector3d& _scale, const aiScene* _mesh) override;
93  void drawSoftMesh(const aiMesh* mesh) override;
94  void drawList(GLuint index) override;
95  void drawLineSegments(const std::vector<Eigen::Vector3d>& _vertices,
96  const common::aligned_vector<Eigen::Vector2i>& _connections) override;
97 
98  void setPenColor(const Eigen::Vector4d& _col) override;
99  void setPenColor(const Eigen::Vector3d& _col) override;
100 
101  void setLineWidth(float _width) override;
102 
103  void saveToImage(const char* _filename, DecoBufferType _buffType = BT_Back) override;
104  void readFrameBuffer(DecoBufferType _buffType, DecoColorChannel _ch, void* _pixels) override;
105 
106 private:
107  void color4_to_float4(const aiColor4D *c, float f[4]);
108  void set_float4(float f[4], float a, float b, float c, float d);
109  void applyMaterial(const struct aiMaterial *mtl);
110  void recursiveRender(const struct aiScene *sc, const struct aiNode* nd);
111 
113 
114 public:
115  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
116 };
117 
118 } // namespace gui
119 } // namespace dart
120 
121 #endif // #ifndef DART_GUI_OPENGLRENDERINTERFACE_HPP_
std::size_t index
Definition: SkelParser.cpp:1617
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:78
Definition: Shape.hpp:53
class Skeleton
Definition: Skeleton.hpp:59
Definition: OpenGLRenderInterface.hpp:51
void scale(const Eigen::Vector3d &_scale) override
Definition: OpenGLRenderInterface.cpp:143
void transform(const Eigen::Isometry3d &_transform) override
Definition: OpenGLRenderInterface.cpp:139
void drawCapsule(double radius, double height) override
Definition: OpenGLRenderInterface.cpp:399
void drawEllipsoid(const Eigen::Vector3d &_diameters) override
Definition: OpenGLRenderInterface.cpp:232
void drawList(GLuint index) override
Definition: OpenGLRenderInterface.cpp:627
void compileList(dynamics::Skeleton *_skel)
Definition: OpenGLRenderInterface.cpp:647
void drawCube(const Eigen::Vector3d &_size) override
Definition: OpenGLRenderInterface.cpp:238
void translate(const Eigen::Vector3d &_offset) override
Definition: OpenGLRenderInterface.cpp:131
void clear(const Eigen::Vector3d &_color) override
Definition: OpenGLRenderInterface.cpp:98
void rotate(const Eigen::Vector3d &_axis, double _rad) override
Definition: OpenGLRenderInterface.cpp:135
void popName() override
Definition: OpenGLRenderInterface.cpp:127
void destroy() override
Definition: OpenGLRenderInterface.cpp:79
int mViewportX
Definition: OpenGLRenderInterface.hpp:112
OpenGLRenderInterface()
Definition: OpenGLRenderInterface.hpp:54
virtual ~OpenGLRenderInterface()
Definition: OpenGLRenderInterface.hpp:55
void getMaterial(Eigen::Vector3d &_diffuse, Eigen::Vector3d &_specular, double &_cosinePow) const override
Definition: OpenGLRenderInterface.cpp:107
void saveToImage(const char *_filename, DecoBufferType _buffType=BT_Back) override
Definition: OpenGLRenderInterface.cpp:728
void setDefaultMaterial() override
Definition: OpenGLRenderInterface.cpp:111
void set_float4(float f[4], float a, float b, float c, float d)
Definition: OpenGLRenderInterface.cpp:452
void drawSoftMesh(const aiMesh *mesh) override
Definition: OpenGLRenderInterface.cpp:603
void popMatrix() override
Definition: OpenGLRenderInterface.cpp:119
void getViewport(int &_x, int &_y, int &_width, int &_height) const override
Definition: OpenGLRenderInterface.cpp:91
void readFrameBuffer(DecoBufferType _buffType, DecoColorChannel _ch, void *_pixels) override
Definition: OpenGLRenderInterface.cpp:724
int mViewportY
Definition: OpenGLRenderInterface.hpp:112
int mViewportWidth
Definition: OpenGLRenderInterface.hpp:112
void applyMaterial(const struct aiMaterial *mtl)
Definition: OpenGLRenderInterface.cpp:461
void drawOpenCylinder(double baseRadius, double topRadius, double height, int slices=16, int stacks=16) override
Definition: OpenGLRenderInterface.cpp:284
int mViewportHeight
Definition: OpenGLRenderInterface.hpp:112
void initialize() override
Definition: OpenGLRenderInterface.cpp:66
void setPenColor(const Eigen::Vector4d &_col) override
Definition: OpenGLRenderInterface.cpp:712
void setMaterial(const Eigen::Vector3d &_diffuse, const Eigen::Vector3d &_specular, double _cosinePow) override
Definition: OpenGLRenderInterface.cpp:103
void drawMultiSphere(const std::vector< std::pair< double, Eigen::Vector3d >> &spheres, int slices=16, int stacks=16) override
Definition: OpenGLRenderInterface.cpp:198
void setLineWidth(float _width) override
Definition: OpenGLRenderInterface.cpp:720
void drawCylinder(double _radius, double _height, int slices=16, int stacks=16) override
Definition: OpenGLRenderInterface.cpp:306
void drawSphere(double radius, int slices=16, int stacks=16) override
Definition: OpenGLRenderInterface.cpp:147
void drawLineSegments(const std::vector< Eigen::Vector3d > &_vertices, const common::aligned_vector< Eigen::Vector2i > &_connections) override
Definition: OpenGLRenderInterface.cpp:631
void drawMesh(const Eigen::Vector3d &_scale, const aiScene *_mesh) override
Definition: OpenGLRenderInterface.cpp:588
void color4_to_float4(const aiColor4D *c, float f[4])
Definition: OpenGLRenderInterface.cpp:444
void recursiveRender(const struct aiScene *sc, const struct aiNode *nd)
Definition: OpenGLRenderInterface.cpp:528
void setViewport(int _x, int _y, int _width, int _height) override
Definition: OpenGLRenderInterface.cpp:83
void drawCone(double radius, double height) override
Definition: OpenGLRenderInterface.cpp:426
void pushMatrix() override
Definition: OpenGLRenderInterface.cpp:115
void pushName(int _id) override
Definition: OpenGLRenderInterface.cpp:123
Definition: RenderInterface.hpp:67
std::vector< _Tp, Eigen::aligned_allocator< _Tp > > aligned_vector
Definition: Memory.hpp:66
DecoBufferType
Definition: RenderInterface.hpp:45
@ BT_Back
Definition: RenderInterface.hpp:47
DecoColorChannel
Definition: RenderInterface.hpp:50
Definition: BulletCollisionDetector.cpp:63