Open3D (C++ API)
NormalShader.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 NormalShader : public ShaderWrapper {
40 public:
41  ~NormalShader() override { Release(); }
42 
43 protected:
44  NormalShader(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> &normals) = 0;
66 
67 protected:
72  GLuint MVP_;
73  GLuint V_;
74  GLuint M_;
75 };
76 
78 public:
79  NormalShaderForPointCloud() : NormalShader("NormalShaderForPointCloud") {}
80 
81 protected:
82  bool PrepareRendering(const geometry::Geometry &geometry,
83  const RenderOption &option,
84  const ViewControl &view) final;
85  bool PrepareBinding(const geometry::Geometry &geometry,
86  const RenderOption &option,
87  const ViewControl &view,
88  std::vector<Eigen::Vector3f> &points,
89  std::vector<Eigen::Vector3f> &normals) final;
90 };
91 
93 public:
95  : NormalShader("NormalShaderForTriangleMesh") {}
96 
97 protected:
98  bool PrepareRendering(const geometry::Geometry &geometry,
99  const RenderOption &option,
100  const ViewControl &view) final;
101  bool PrepareBinding(const geometry::Geometry &geometry,
102  const RenderOption &option,
103  const ViewControl &view,
104  std::vector<Eigen::Vector3f> &points,
105  std::vector<Eigen::Vector3f> &normals) final;
106 };
107 
108 } // namespace glsl
109 
110 } // namespace visualization
111 } // namespace open3d
The base geometry class.
Definition: Geometry.h:37
GLuint vertex_normal_
Definition: NormalShader.h:70
GLuint vertex_position_
Definition: NormalShader.h:68
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: NormalShader.cpp:57
View controller for visualizer.
Definition: ViewControl.h:41
NormalShaderForPointCloud()
Definition: NormalShader.h:79
GLuint vertex_position_buffer_
Definition: NormalShader.h:69
virtual bool PrepareBinding(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view, std::vector< Eigen::Vector3f > &points, std::vector< Eigen::Vector3f > &normals)=0
Definition: NormalShader.h:39
GLuint vertex_normal_buffer_
Definition: NormalShader.h:71
NormalShaderForTriangleMesh()
Definition: NormalShader.h:94
Defines rendering options for visualizer.
Definition: RenderOption.h:39
void UnbindGeometry() final
Definition: NormalShader.cpp:112
int points
Definition: FilePCD.cpp:71
Definition: Open3DViewer.h:29
virtual bool PrepareRendering(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view)=0
bool Compile() final
Definition: NormalShader.cpp:38
std::string name
Definition: FilePCD.cpp:56
Definition: ShaderWrapper.h:40
NormalShader(const std::string &name)
Definition: NormalShader.h:44
void Release() final
Definition: NormalShader.cpp:52
bool RenderGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: NormalShader.cpp:89
GLuint MVP_
Definition: NormalShader.h:72
GLuint M_
Definition: NormalShader.h:74
~NormalShader() override
Definition: NormalShader.h:41
GLuint V_
Definition: NormalShader.h:73