Open3D (C++ API)
SimpleShader.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <Eigen/Core>
30 #include <vector>
31 
33 
34 namespace open3d {
35 namespace visualization {
36 
37 namespace glsl {
38 
39 class SimpleShader : public ShaderWrapper {
40 public:
41  ~SimpleShader() override { Release(); }
42 
43 protected:
44  SimpleShader(const std::string &name) : ShaderWrapper(name) { Compile(); }
45 
46 protected:
47  bool Compile() final;
48  void Release() final;
49  bool BindGeometry(const geometry::Geometry &geometry,
50  const RenderOption &option,
51  const ViewControl &view) final;
52  bool RenderGeometry(const geometry::Geometry &geometry,
53  const RenderOption &option,
54  const ViewControl &view) final;
55  void UnbindGeometry() final;
56 
57 protected:
58  virtual bool PrepareRendering(const geometry::Geometry &geometry,
59  const RenderOption &option,
60  const ViewControl &view) = 0;
61  virtual bool PrepareBinding(const geometry::Geometry &geometry,
62  const RenderOption &option,
63  const ViewControl &view,
64  std::vector<Eigen::Vector3f> &points,
65  std::vector<Eigen::Vector3f> &colors) = 0;
66 
67 protected:
70  GLuint vertex_color_;
72  GLuint MVP_;
73 };
74 
76 public:
77  SimpleShaderForPointCloud() : SimpleShader("SimpleShaderForPointCloud") {}
78 
79 protected:
80  bool PrepareRendering(const geometry::Geometry &geometry,
81  const RenderOption &option,
82  const ViewControl &view) final;
83  bool PrepareBinding(const geometry::Geometry &geometry,
84  const RenderOption &option,
85  const ViewControl &view,
86  std::vector<Eigen::Vector3f> &points,
87  std::vector<Eigen::Vector3f> &colors) final;
88 };
89 
91 public:
92  SimpleShaderForLineSet() : SimpleShader("SimpleShaderForLineSet") {}
93 
94 protected:
95  bool PrepareRendering(const geometry::Geometry &geometry,
96  const RenderOption &option,
97  const ViewControl &view) final;
98  bool PrepareBinding(const geometry::Geometry &geometry,
99  const RenderOption &option,
100  const ViewControl &view,
101  std::vector<Eigen::Vector3f> &points,
102  std::vector<Eigen::Vector3f> &colors) final;
103 };
104 
106 public:
107  SimpleShaderForTetraMesh() : SimpleShader("SimpleShaderForTetraMesh") {}
108 
109 protected:
110  bool PrepareRendering(const geometry::Geometry &geometry,
111  const RenderOption &option,
112  const ViewControl &view) final;
113  bool PrepareBinding(const geometry::Geometry &geometry,
114  const RenderOption &option,
115  const ViewControl &view,
116  std::vector<Eigen::Vector3f> &points,
117  std::vector<Eigen::Vector3f> &colors) final;
118 };
119 
121 public:
123  : SimpleShader("SimpleShaderForOrientedBoundingBox") {}
124 
125 protected:
126  bool PrepareRendering(const geometry::Geometry &geometry,
127  const RenderOption &option,
128  const ViewControl &view) final;
129  bool PrepareBinding(const geometry::Geometry &geometry,
130  const RenderOption &option,
131  const ViewControl &view,
132  std::vector<Eigen::Vector3f> &points,
133  std::vector<Eigen::Vector3f> &colors) final;
134 };
135 
137 public:
139  : SimpleShader("SimpleShaderForAxisAlignedBoundingBox") {}
140 
141 protected:
142  bool PrepareRendering(const geometry::Geometry &geometry,
143  const RenderOption &option,
144  const ViewControl &view) final;
145  bool PrepareBinding(const geometry::Geometry &geometry,
146  const RenderOption &option,
147  const ViewControl &view,
148  std::vector<Eigen::Vector3f> &points,
149  std::vector<Eigen::Vector3f> &colors) final;
150 };
151 
153 public:
155  : SimpleShader("SimpleShaderForTriangleMesh") {}
156 
157 protected:
158  bool PrepareRendering(const geometry::Geometry &geometry,
159  const RenderOption &option,
160  const ViewControl &view) final;
161  bool PrepareBinding(const geometry::Geometry &geometry,
162  const RenderOption &option,
163  const ViewControl &view,
164  std::vector<Eigen::Vector3f> &points,
165  std::vector<Eigen::Vector3f> &colors) final;
166 };
167 
169 public:
171  : SimpleShader("SimpleShaderForVoxelGridLine") {}
172 
173 protected:
174  bool PrepareRendering(const geometry::Geometry &geometry,
175  const RenderOption &option,
176  const ViewControl &view) final;
177  bool PrepareBinding(const geometry::Geometry &geometry,
178  const RenderOption &option,
179  const ViewControl &view,
180  std::vector<Eigen::Vector3f> &points,
181  std::vector<Eigen::Vector3f> &colors) final;
182 };
183 
185 public:
187  : SimpleShader("SimpleShaderForVoxelGridFace") {}
188 
189 protected:
190  bool PrepareRendering(const geometry::Geometry &geometry,
191  const RenderOption &option,
192  const ViewControl &view) final;
193  bool PrepareBinding(const geometry::Geometry &geometry,
194  const RenderOption &option,
195  const ViewControl &view,
196  std::vector<Eigen::Vector3f> &points,
197  std::vector<Eigen::Vector3f> &colors) final;
198 };
199 
201 public:
202  SimpleShaderForOctreeLine() : SimpleShader("SimpleShaderForOctreeLine") {}
203 
204 protected:
205  bool PrepareRendering(const geometry::Geometry &geometry,
206  const RenderOption &option,
207  const ViewControl &view) final;
208  bool PrepareBinding(const geometry::Geometry &geometry,
209  const RenderOption &option,
210  const ViewControl &view,
211  std::vector<Eigen::Vector3f> &points,
212  std::vector<Eigen::Vector3f> &colors) final;
213 };
214 
216 public:
217  SimpleShaderForOctreeFace() : SimpleShader("SimpleShaderForOctreeFace") {}
218 
219 protected:
220  bool PrepareRendering(const geometry::Geometry &geometry,
221  const RenderOption &option,
222  const ViewControl &view) final;
223  bool PrepareBinding(const geometry::Geometry &geometry,
224  const RenderOption &option,
225  const ViewControl &view,
226  std::vector<Eigen::Vector3f> &points,
227  std::vector<Eigen::Vector3f> &colors) final;
228 };
229 
230 } // namespace glsl
231 
232 } // namespace visualization
233 } // namespace open3d
GLuint vertex_position_buffer_
Definition: SimpleShader.h:69
The base geometry class.
Definition: Geometry.h:37
bool Compile() final
Definition: SimpleShader.cpp:69
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: SimpleShader.cpp:118
GLuint vertex_color_buffer_
Definition: SimpleShader.h:71
SimpleShaderForLineSet()
Definition: SimpleShader.h:92
SimpleShaderForVoxelGridLine()
Definition: SimpleShader.h:170
View controller for visualizer.
Definition: ViewControl.h:41
GLuint vertex_color_
Definition: SimpleShader.h:70
void UnbindGeometry() final
Definition: SimpleShader.cpp:139
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: SimpleShader.cpp:86
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
SimpleShaderForTriangleMesh()
Definition: SimpleShader.h:154
GLuint vertex_position_
Definition: SimpleShader.h:68
SimpleShaderForOrientedBoundingBox()
Definition: SimpleShader.h:122
Definition: SimpleShader.h:39
void Release() final
Definition: SimpleShader.cpp:81
Defines rendering options for visualizer.
Definition: RenderOption.h:39
SimpleShaderForTetraMesh()
Definition: SimpleShader.h:107
SimpleShaderForOctreeFace()
Definition: SimpleShader.h:217
~SimpleShader() override
Definition: SimpleShader.h:41
virtual bool PrepareBinding(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view, std::vector< Eigen::Vector3f > &points, std::vector< Eigen::Vector3f > &colors)=0
SimpleShader(const std::string &name)
Definition: SimpleShader.h:44
int points
Definition: FilePCD.cpp:71
Definition: Open3DViewer.h:29
std::string name
Definition: FilePCD.cpp:56
Definition: ShaderWrapper.h:40
SimpleShaderForPointCloud()
Definition: SimpleShader.h:77
SimpleShaderForOctreeLine()
Definition: SimpleShader.h:202
SimpleShaderForVoxelGridFace()
Definition: SimpleShader.h:186
GLuint MVP_
Definition: SimpleShader.h:72