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