Point Cloud Library (PCL)  1.12.1-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  return Eigen::Matrix4d (projection_matrix_ * model_view_matrix_);
101  }
102 
103  Eigen::Vector3d
105  {
106  //Compute eye or position from model view matrix
107  Eigen::Matrix4d inverse_model_view_matrix = model_view_matrix_.inverse ();
108  Eigen::Vector3d position;
109  for (int i = 0; i < 3; i++)
110  {
111  position (i) = inverse_model_view_matrix (i, 3);
112  }
113 
114  return position;
115  }
116 
117  inline void
118  setClippingRange (float near_value = 0.0001f, float far_value = 100000.f)
119  {
120  camera_->SetClippingRange (near_value, far_value);
121  }
122 
123  void
124  render (vtkRenderer* renderer) override;
125 
126  // Methods
127  // -----------------------------------------------------------------------------
128  //void computeFrustum(double aspect);
129  void
131  //computeFrustum(double aspect);
132  void
134 
135  // Aligned operator, because of Eigen members
137 
138 private:
139 
140  // Members
141  // -----------------------------------------------------------------------------
143  vtkSmartPointer<vtkCameraActor> camera_actor_;
144  vtkSmartPointer<vtkActor> hull_actor_;
145 
146  bool display_;
147 
148  double frustum_[24];
149  Eigen::Matrix4d projection_matrix_;
150  Eigen::Matrix4d model_view_matrix_;
151 
152  double prevUp_[3];
153  double prevFocal_[3];
154  double prevPos_[3];
155 };
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:104
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:118
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.