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 <vector>
30 #include <Eigen/Core>
32 
33 namespace open3d {
34 namespace visualization {
35 
36 namespace glsl {
37 
38 class NormalShader : public ShaderWrapper {
39 public:
40  ~NormalShader() override { Release(); }
41 
42 protected:
43  NormalShader(const std::string &name) : ShaderWrapper(name) { Compile(); }
44 
45 protected:
46  bool Compile() final;
47  void Release() final;
48  bool BindGeometry(const geometry::Geometry &geometry,
49  const RenderOption &option,
50  const ViewControl &view) final;
51  bool RenderGeometry(const geometry::Geometry &geometry,
52  const RenderOption &option,
53  const ViewControl &view) final;
54  void UnbindGeometry() final;
55 
56 protected:
57  virtual bool PrepareRendering(const geometry::Geometry &geometry,
58  const RenderOption &option,
59  const ViewControl &view) = 0;
60  virtual bool PrepareBinding(const geometry::Geometry &geometry,
61  const RenderOption &option,
62  const ViewControl &view,
63  std::vector<Eigen::Vector3f> &points,
64  std::vector<Eigen::Vector3f> &normals) = 0;
65 
66 protected:
71  GLuint MVP_;
72  GLuint V_;
73  GLuint M_;
74 };
75 
77 public:
78  NormalShaderForPointCloud() : NormalShader("NormalShaderForPointCloud") {}
79 
80 protected:
81  bool PrepareRendering(const geometry::Geometry &geometry,
82  const RenderOption &option,
83  const ViewControl &view) final;
84  bool PrepareBinding(const geometry::Geometry &geometry,
85  const RenderOption &option,
86  const ViewControl &view,
87  std::vector<Eigen::Vector3f> &points,
88  std::vector<Eigen::Vector3f> &normals) final;
89 };
90 
92 public:
94  : NormalShader("NormalShaderForTriangleMesh") {}
95 
96 protected:
97  bool PrepareRendering(const geometry::Geometry &geometry,
98  const RenderOption &option,
99  const ViewControl &view) final;
100  bool PrepareBinding(const geometry::Geometry &geometry,
101  const RenderOption &option,
102  const ViewControl &view,
103  std::vector<Eigen::Vector3f> &points,
104  std::vector<Eigen::Vector3f> &normals) final;
105 };
106 
107 } // namespace glsl
108 
109 } // namespace visualization
110 } // namespace open3d
Definition: Geometry.h:32
GLuint vertex_normal_
Definition: NormalShader.h:69
GLuint vertex_position_
Definition: NormalShader.h:67
bool BindGeometry(const geometry::Geometry &geometry, const RenderOption &option, const ViewControl &view) final
Definition: NormalShader.cpp:57
Definition: ViewControl.h:38
NormalShaderForPointCloud()
Definition: NormalShader.h:78
GLuint vertex_position_buffer_
Definition: NormalShader.h:68
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:38
GLuint vertex_normal_buffer_
Definition: NormalShader.h:70
NormalShaderForTriangleMesh()
Definition: NormalShader.h:93
Definition: RenderOption.h:36
void UnbindGeometry() final
Definition: NormalShader.cpp:112
int points
Definition: FilePCD.cpp:69
Definition: PinholeCameraIntrinsic.cpp:33
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:54
Definition: ShaderWrapper.h:40
NormalShader(const std::string &name)
Definition: NormalShader.h:43
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:71
GLuint M_
Definition: NormalShader.h:73
~NormalShader() override
Definition: NormalShader.h:40
GLuint V_
Definition: NormalShader.h:72