Point Cloud Library (PCL)  1.14.0-dev
camera.h
1 #pragma once
2 
3 // C++
4 #include <iostream>
5 #include <string>
6 
7 // PCL
8 #include <pcl/outofcore/visualization/object.h>
9 #include <pcl/common/eigen.h>
10 #include <pcl/memory.h>
11 #include <pcl/pcl_macros.h>
12 
13 // VTK
14 #include <vtkActor.h>
15 #include <vtkCamera.h>
16 #include <vtkCameraActor.h>
17 #include <vtkPolyData.h>
18 #include <vtkSmartPointer.h>
19 
20 class Camera : public Object
21 {
22 public:
23 
24  // Operators
25  // -----------------------------------------------------------------------------
26  Camera (std::string name);
27  Camera (std::string name, vtkSmartPointer<vtkCamera> camera);
28 
29 private:
30 // friend std::ostream & operator<<(std::ostream &os, const Camera& camera);
31 
32 public:
33 
34  // Accessors
35  // -----------------------------------------------------------------------------
37  getCamera () const
38  {
39  return camera_;
40  }
41 
43  getCameraActor () const
44  {
45  return camera_actor_;
46  }
47 
49  getHullActor () const
50  {
51  return hull_actor_;
52  }
53 
54  inline bool
55  getDisplay () const
56  {
57  return display_;
58  }
59 
60  void
61  setDisplay (bool display)
62  {
63  this->display_ = display;
64  }
65 
66  void
67  getFrustum (double frustum[])
68  {
69  for (int i = 0; i < 24; i++)
70  frustum[i] = frustum_[i];
71  }
72 
73  void
74  setProjectionMatrix (const Eigen::Matrix4d &projection_matrix)
75  {
76  projection_matrix_ = projection_matrix;
77  }
78 
79  Eigen::Matrix4d
81  {
82  return projection_matrix_;
83  }
84 
85  void
86  setModelViewMatrix (const Eigen::Matrix4d &model_view_matrix)
87  {
88  model_view_matrix_ = model_view_matrix;
89  }
90 
91  Eigen::Matrix4d
93  {
94  return model_view_matrix_;
95  }
96 
97  Eigen::Matrix4d
99  {
100  // Disable check for braced-initialization,
101  // since the compiler complains that the constructor selected
102  // with {projection_matrix_ * model_view_matrix_} is explicit
103  // NOLINTNEXTLINE(modernize-return-braced-init-list)
104  return Eigen::Matrix4d (projection_matrix_ * model_view_matrix_);
105  }
106 
107  Eigen::Vector3d
109  {
110  //Compute eye or position from model view matrix
111  Eigen::Matrix4d inverse_model_view_matrix = model_view_matrix_.inverse ();
112  Eigen::Vector3d position;
113  for (int i = 0; i < 3; i++)
114  {
115  position (i) = inverse_model_view_matrix (i, 3);
116  }
117 
118  return position;
119  }
120 
121  inline void
122  setClippingRange (float near_value = 0.0001f, float far_value = 100000.f)
123  {
124  camera_->SetClippingRange (near_value, far_value);
125  }
126 
127  void
128  render (vtkRenderer* renderer) override;
129 
130  // Methods
131  // -----------------------------------------------------------------------------
132  //void computeFrustum(double aspect);
133  void
135  //computeFrustum(double aspect);
136  void
138 
139  // Aligned operator, because of Eigen members
141 
142 private:
143 
144  // Members
145  // -----------------------------------------------------------------------------
147  vtkSmartPointer<vtkCameraActor> camera_actor_;
148  vtkSmartPointer<vtkActor> hull_actor_;
149 
150  bool display_;
151 
152  double frustum_[24];
153  Eigen::Matrix4d projection_matrix_;
154  Eigen::Matrix4d model_view_matrix_;
155 
156  double prevUp_[3];
157  double prevFocal_[3];
158  double prevPos_[3];
159 };
Definition: camera.h:21
void getFrustum(double frustum[])
Definition: camera.h:67
Eigen::Matrix4d getModelViewMatrix()
Definition: camera.h:92
void setModelViewMatrix(const Eigen::Matrix4d &model_view_matrix)
Definition: camera.h:86
vtkSmartPointer< vtkCameraActor > getCameraActor() const
Definition: camera.h:43
void setDisplay(bool display)
Definition: camera.h:61
void computeFrustum()
Eigen::Matrix4d getViewProjectionMatrix()
Definition: camera.h:98
vtkSmartPointer< vtkCamera > getCamera() const
Definition: camera.h:37
vtkSmartPointer< vtkActor > getHullActor() const
Definition: camera.h:49
Camera(std::string name)
Camera(std::string name, vtkSmartPointer< vtkCamera > camera)
Eigen::Matrix4d getProjectionMatrix()
Definition: camera.h:80
Eigen::Vector3d getPosition()
Definition: camera.h:108
void printFrustum()
bool getDisplay() const
Definition: camera.h:55
void setProjectionMatrix(const Eigen::Matrix4d &projection_matrix)
Definition: camera.h:74
void render(vtkRenderer *renderer) override
void setClippingRange(float near_value=0.0001f, float far_value=100000.f)
Definition: camera.h:122
Definition: object.h:19
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Defines functions, macros and traits for allocating and using memory.
Defines all the PCL and non-PCL macros used.