Open3D (C++ API)  0.18.0+252c867
SimpleShader.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <vector>
12 
14 
15 namespace open3d {
16 namespace visualization {
17 
18 namespace glsl {
19 
20 class SimpleShader : public ShaderWrapper {
21 public:
22  ~SimpleShader() override { Release(); }
23 
24 protected:
25  SimpleShader(const std::string &name) : ShaderWrapper(name) { Compile(); }
26 
27 protected:
28  bool Compile() final;
29  void Release() final;
30  bool BindGeometry(const geometry::Geometry &geometry,
31  const RenderOption &option,
32  const ViewControl &view) final;
33  bool RenderGeometry(const geometry::Geometry &geometry,
34  const RenderOption &option,
35  const ViewControl &view) final;
36  void UnbindGeometry() final;
37 
38 protected:
39  virtual bool PrepareRendering(const geometry::Geometry &geometry,
40  const RenderOption &option,
41  const ViewControl &view) = 0;
42  virtual bool PrepareBinding(const geometry::Geometry &geometry,
43  const RenderOption &option,
44  const ViewControl &view,
45  std::vector<Eigen::Vector3f> &points,
46  std::vector<Eigen::Vector3f> &colors) = 0;
47 
48 protected:
51  GLuint vertex_color_;
53  GLuint MVP_;
54 };
55 
57 public:
58  SimpleShaderForPointCloud() : SimpleShader("SimpleShaderForPointCloud") {}
59 
60 protected:
61  bool PrepareRendering(const geometry::Geometry &geometry,
62  const RenderOption &option,
63  const ViewControl &view) final;
64  bool PrepareBinding(const geometry::Geometry &geometry,
65  const RenderOption &option,
66  const ViewControl &view,
67  std::vector<Eigen::Vector3f> &points,
68  std::vector<Eigen::Vector3f> &colors) final;
69 };
70 
72 public:
73  SimpleShaderForLineSet() : SimpleShader("SimpleShaderForLineSet") {}
74 
75 protected:
76  bool PrepareRendering(const geometry::Geometry &geometry,
77  const RenderOption &option,
78  const ViewControl &view) final;
79  bool PrepareBinding(const geometry::Geometry &geometry,
80  const RenderOption &option,
81  const ViewControl &view,
82  std::vector<Eigen::Vector3f> &points,
83  std::vector<Eigen::Vector3f> &colors) final;
84 };
85 
87 public:
88  SimpleShaderForTetraMesh() : SimpleShader("SimpleShaderForTetraMesh") {}
89 
90 protected:
91  bool PrepareRendering(const geometry::Geometry &geometry,
92  const RenderOption &option,
93  const ViewControl &view) final;
94  bool PrepareBinding(const geometry::Geometry &geometry,
95  const RenderOption &option,
96  const ViewControl &view,
97  std::vector<Eigen::Vector3f> &points,
98  std::vector<Eigen::Vector3f> &colors) final;
99 };
100 
102 public:
104  : SimpleShader("SimpleShaderForOrientedBoundingBox") {}
105 
106 protected:
107  bool PrepareRendering(const geometry::Geometry &geometry,
108  const RenderOption &option,
109  const ViewControl &view) final;
110  bool PrepareBinding(const geometry::Geometry &geometry,
111  const RenderOption &option,
112  const ViewControl &view,
113  std::vector<Eigen::Vector3f> &points,
114  std::vector<Eigen::Vector3f> &colors) final;
115 };
116 
118 public:
120  : SimpleShader("SimpleShaderForAxisAlignedBoundingBox") {}
121 
122 protected:
123  bool PrepareRendering(const geometry::Geometry &geometry,
124  const RenderOption &option,
125  const ViewControl &view) final;
126  bool PrepareBinding(const geometry::Geometry &geometry,
127  const RenderOption &option,
128  const ViewControl &view,
129  std::vector<Eigen::Vector3f> &points,
130  std::vector<Eigen::Vector3f> &colors) final;
131 };
132 
134 public:
136  : SimpleShader("SimpleShaderForTriangleMesh") {}
137 
138 protected:
139  bool PrepareRendering(const geometry::Geometry &geometry,
140  const RenderOption &option,
141  const ViewControl &view) final;
142  bool PrepareBinding(const geometry::Geometry &geometry,
143  const RenderOption &option,
144  const ViewControl &view,
145  std::vector<Eigen::Vector3f> &points,
146  std::vector<Eigen::Vector3f> &colors) final;
147 };
148 
150 public:
152  : SimpleShader("SimpleShaderForVoxelGridLine") {}
153 
154 protected:
155  bool PrepareRendering(const geometry::Geometry &geometry,
156  const RenderOption &option,
157  const ViewControl &view) final;
158  bool PrepareBinding(const geometry::Geometry &geometry,
159  const RenderOption &option,
160  const ViewControl &view,
161  std::vector<Eigen::Vector3f> &points,
162  std::vector<Eigen::Vector3f> &colors) final;
163 };
164 
166 public:
168  : SimpleShader("SimpleShaderForVoxelGridFace") {}
169 
170 protected:
171  bool PrepareRendering(const geometry::Geometry &geometry,
172  const RenderOption &option,
173  const ViewControl &view) final;
174  bool PrepareBinding(const geometry::Geometry &geometry,
175  const RenderOption &option,
176  const ViewControl &view,
177  std::vector<Eigen::Vector3f> &points,
178  std::vector<Eigen::Vector3f> &colors) final;
179 };
180 
182 public:
183  SimpleShaderForOctreeLine() : SimpleShader("SimpleShaderForOctreeLine") {}
184 
185 protected:
186  bool PrepareRendering(const geometry::Geometry &geometry,
187  const RenderOption &option,
188  const ViewControl &view) final;
189  bool PrepareBinding(const geometry::Geometry &geometry,
190  const RenderOption &option,
191  const ViewControl &view,
192  std::vector<Eigen::Vector3f> &points,
193  std::vector<Eigen::Vector3f> &colors) final;
194 };
195 
197 public:
198  SimpleShaderForOctreeFace() : SimpleShader("SimpleShaderForOctreeFace") {}
199 
200 protected:
201  bool PrepareRendering(const geometry::Geometry &geometry,
202  const RenderOption &option,
203  const ViewControl &view) final;
204  bool PrepareBinding(const geometry::Geometry &geometry,
205  const RenderOption &option,
206  const ViewControl &view,
207  std::vector<Eigen::Vector3f> &points,
208  std::vector<Eigen::Vector3f> &colors) final;
209 };
210 
211 } // namespace glsl
212 
213 } // namespace visualization
214 } // namespace open3d
The base geometry class.
Definition: Geometry.h:18
Defines rendering options for visualizer.
Definition: RenderOption.h:20
View controller for visualizer.
Definition: ViewControl.h:23
Definition: ShaderWrapper.h:21
SimpleShaderForLineSet()
Definition: SimpleShader.h:73
SimpleShaderForOctreeFace()
Definition: SimpleShader.h:198
SimpleShaderForOctreeLine()
Definition: SimpleShader.h:183
SimpleShaderForOrientedBoundingBox()
Definition: SimpleShader.h:103
SimpleShaderForPointCloud()
Definition: SimpleShader.h:58
SimpleShaderForTetraMesh()
Definition: SimpleShader.h:88
SimpleShaderForTriangleMesh()
Definition: SimpleShader.h:135
SimpleShaderForVoxelGridFace()
Definition: SimpleShader.h:167
SimpleShaderForVoxelGridLine()
Definition: SimpleShader.h:151
Definition: SimpleShader.h:20
GLuint vertex_position_
Definition: SimpleShader.h:49
GLuint MVP_
Definition: SimpleShader.h:53
GLuint vertex_color_buffer_
Definition: SimpleShader.h:52
GLuint vertex_position_buffer_
Definition: SimpleShader.h:50
~SimpleShader() override
Definition: SimpleShader.h:22
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
void UnbindGeometry() final
Definition: SimpleShader.cpp:119
virtual bool PrepareBinding(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view, std::vector< Eigen::Vector3f > &points, std::vector< Eigen::Vector3f > &colors)=0
void Release() final
Definition: SimpleShader.cpp:61
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: SimpleShader.cpp:98
bool Compile() final
Definition: SimpleShader.cpp:50
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: SimpleShader.cpp:66
SimpleShader(const std::string &name)
Definition: SimpleShader.h:25
GLuint vertex_color_
Definition: SimpleShader.h:51
std::string name
Definition: FilePCD.cpp:39
int points
Definition: FilePCD.cpp:54
Definition: NonRigidOptimizer.cpp:22
Definition: PinholeCameraIntrinsic.cpp:16
Definition: Device.h:107