DART  6.10.1
OpenGLRenderInterface.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, 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>
38 #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 } // namespace dynamics
49 
50 namespace gui {
52 {
53 
54 public:
56  : mViewportX(0.0),
57  mViewportY(0.0),
58  mViewportWidth(0.0),
59  mViewportHeight(0.0)
60  {
61  }
63  {
64  }
65 
66  void initialize() override;
67  void destroy() override;
68 
69  void setViewport(int _x, int _y, int _width, int _height) override;
70  void getViewport(int& _x, int& _y, int& _width, int& _height) const override;
71 
72  void clear(const Eigen::Vector3d& _color) override;
73 
74  void setMaterial(
75  const Eigen::Vector3d& _diffuse,
76  const Eigen::Vector3d& _specular,
77  double _cosinePow) override;
78  void getMaterial(
79  Eigen::Vector3d& _diffuse,
80  Eigen::Vector3d& _specular,
81  double& _cosinePow) const override;
82  void setDefaultMaterial() override;
83 
84  void pushMatrix() override;
85  void popMatrix() override;
86  void pushName(int _id) override;
87  void popName() override;
88 
89  void translate(const Eigen::Vector3d& _offset) override; // glTranslate
90  void rotate(const Eigen::Vector3d& _axis, double _rad) override; // glRotate
91  void transform(const Eigen::Isometry3d& _transform) override; // glMultMatrix
92  void scale(const Eigen::Vector3d& _scale) override; // glScale
93 
94  void compileList(dynamics::Skeleton* _skel);
95  void compileList(dynamics::BodyNode* _node);
96  void compileList(dynamics::Shape* _shape);
97  GLuint compileList(const Eigen::Vector3d& _scale, const aiScene* _mesh);
98 
99  void drawSphere(double radius, int slices = 16, int stacks = 16) override;
100  void drawMultiSphere(
101  const std::vector<std::pair<double, Eigen::Vector3d>>& spheres,
102  int slices = 16,
103  int stacks = 16) override;
104  void drawEllipsoid(const Eigen::Vector3d& _diameters) override;
105  void drawCube(const Eigen::Vector3d& _size) override;
106  void drawOpenCylinder(
107  double baseRadius,
108  double topRadius,
109  double height,
110  int slices = 16,
111  int stacks = 16) override;
112  void drawCylinder(
113  double _radius,
114  double _height,
115  int slices = 16,
116  int stacks = 16) override;
117  void drawCapsule(double radius, double height) override;
118  void drawCone(double radius, double height) override;
119  void drawPyramid(double baseWidth, double baseDepth, double height) override;
120  void drawMesh(const Eigen::Vector3d& _scale, const aiScene* _mesh) override;
121  void drawSoftMesh(const aiMesh* mesh) override;
122  void drawList(GLuint index) override;
123  void drawLineSegments(
124  const std::vector<Eigen::Vector3d>& _vertices,
125  const common::aligned_vector<Eigen::Vector2i>& _connections) override;
126 
127  void setPenColor(const Eigen::Vector4d& _col) override;
128  void setPenColor(const Eigen::Vector3d& _col) override;
129 
130  void setLineWidth(float _width) override;
131 
132  void saveToImage(
133  const char* _filename, DecoBufferType _buffType = BT_Back) override;
134  void readFrameBuffer(
135  DecoBufferType _buffType, DecoColorChannel _ch, void* _pixels) override;
136 
137 private:
138  void color4_to_float4(const aiColor4D* c, float f[4]);
139  void set_float4(float f[4], float a, float b, float c, float d);
140  void applyMaterial(const struct aiMaterial* mtl);
141  void recursiveRender(const struct aiScene* sc, const struct aiNode* nd);
142 
144 
145 public:
146  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
147 };
148 
149 } // namespace gui
150 } // namespace dart
151 
152 #endif // #ifndef DART_GUI_OPENGLRENDERINTERFACE_HPP_
std::size_t index
Definition: SkelParser.cpp:1672
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:79
Definition: Shape.hpp:54
class Skeleton
Definition: Skeleton.hpp:59
Definition: OpenGLRenderInterface.hpp:52
void scale(const Eigen::Vector3d &_scale) override
Definition: OpenGLRenderInterface.cpp:165
void transform(const Eigen::Isometry3d &_transform) override
Definition: OpenGLRenderInterface.cpp:160
void drawCapsule(double radius, double height) override
Definition: OpenGLRenderInterface.cpp:424
void drawEllipsoid(const Eigen::Vector3d &_diameters) override
Definition: OpenGLRenderInterface.cpp:260
void drawList(GLuint index) override
Definition: OpenGLRenderInterface.cpp:744
void compileList(dynamics::Skeleton *_skel)
Definition: OpenGLRenderInterface.cpp:765
void drawCube(const Eigen::Vector3d &_size) override
Definition: OpenGLRenderInterface.cpp:267
void translate(const Eigen::Vector3d &_offset) override
Definition: OpenGLRenderInterface.cpp:150
void clear(const Eigen::Vector3d &_color) override
Definition: OpenGLRenderInterface.cpp:106
void rotate(const Eigen::Vector3d &_axis, double _rad) override
Definition: OpenGLRenderInterface.cpp:155
void popName() override
Definition: OpenGLRenderInterface.cpp:145
void destroy() override
Definition: OpenGLRenderInterface.cpp:84
int mViewportX
Definition: OpenGLRenderInterface.hpp:143
OpenGLRenderInterface()
Definition: OpenGLRenderInterface.hpp:55
virtual ~OpenGLRenderInterface()
Definition: OpenGLRenderInterface.hpp:62
void getMaterial(Eigen::Vector3d &_diffuse, Eigen::Vector3d &_specular, double &_cosinePow) const override
Definition: OpenGLRenderInterface.cpp:119
void saveToImage(const char *_filename, DecoBufferType _buffType=BT_Back) override
Definition: OpenGLRenderInterface.cpp:853
void setDefaultMaterial() override
Definition: OpenGLRenderInterface.cpp:126
void set_float4(float f[4], float a, float b, float c, float d)
Definition: OpenGLRenderInterface.cpp:540
void drawSoftMesh(const aiMesh *mesh) override
Definition: OpenGLRenderInterface.cpp:720
void popMatrix() override
Definition: OpenGLRenderInterface.cpp:135
void getViewport(int &_x, int &_y, int &_width, int &_height) const override
Definition: OpenGLRenderInterface.cpp:97
void readFrameBuffer(DecoBufferType _buffType, DecoColorChannel _ch, void *_pixels) override
Definition: OpenGLRenderInterface.cpp:848
int mViewportY
Definition: OpenGLRenderInterface.hpp:143
int mViewportWidth
Definition: OpenGLRenderInterface.hpp:143
void applyMaterial(const struct aiMaterial *mtl)
Definition: OpenGLRenderInterface.cpp:550
void drawOpenCylinder(double baseRadius, double topRadius, double height, int slices=16, int stacks=16) override
Definition: OpenGLRenderInterface.cpp:309
int mViewportHeight
Definition: OpenGLRenderInterface.hpp:143
void initialize() override
Definition: OpenGLRenderInterface.cpp:70
void setPenColor(const Eigen::Vector4d &_col) override
Definition: OpenGLRenderInterface.cpp:833
void setMaterial(const Eigen::Vector3d &_diffuse, const Eigen::Vector3d &_specular, double _cosinePow) override
Definition: OpenGLRenderInterface.cpp:112
void drawMultiSphere(const std::vector< std::pair< double, Eigen::Vector3d >> &spheres, int slices=16, int stacks=16) override
Definition: OpenGLRenderInterface.cpp:225
void setLineWidth(float _width) override
Definition: OpenGLRenderInterface.cpp:843
void drawCylinder(double _radius, double _height, int slices=16, int stacks=16) override
Definition: OpenGLRenderInterface.cpp:331
void drawSphere(double radius, int slices=16, int stacks=16) override
Definition: OpenGLRenderInterface.cpp:170
void drawLineSegments(const std::vector< Eigen::Vector3d > &_vertices, const common::aligned_vector< Eigen::Vector2i > &_connections) override
Definition: OpenGLRenderInterface.cpp:749
void drawMesh(const Eigen::Vector3d &_scale, const aiScene *_mesh) override
Definition: OpenGLRenderInterface.cpp:705
void color4_to_float4(const aiColor4D *c, float f[4])
Definition: OpenGLRenderInterface.cpp:532
void recursiveRender(const struct aiScene *sc, const struct aiNode *nd)
Definition: OpenGLRenderInterface.cpp:625
void drawPyramid(double baseWidth, double baseDepth, double height) override
Definition: OpenGLRenderInterface.cpp:486
void setViewport(int _x, int _y, int _width, int _height) override
Definition: OpenGLRenderInterface.cpp:88
void drawCone(double radius, double height) override
Definition: OpenGLRenderInterface.cpp:457
void pushMatrix() override
Definition: OpenGLRenderInterface.cpp:130
void pushName(int _id) override
Definition: OpenGLRenderInterface.cpp:140
Definition: RenderInterface.hpp:71
std::vector< _Tp, Eigen::aligned_allocator< _Tp > > aligned_vector
Definition: Memory.hpp:71
DecoBufferType
Definition: RenderInterface.hpp:46
@ BT_Back
Definition: RenderInterface.hpp:48
DecoColorChannel
Definition: RenderInterface.hpp:52
Definition: BulletCollisionDetector.cpp:65