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   // -----------------------------------------------------------------------------
36   inline vtkSmartPointer<vtkCamera>
getCamera()37   getCamera () const
38   {
39     return camera_;
40   }
41 
42   inline vtkSmartPointer<vtkCameraActor>
getCameraActor()43   getCameraActor () const
44   {
45     return camera_actor_;
46   }
47 
48   inline vtkSmartPointer<vtkActor>
getHullActor()49   getHullActor () const
50   {
51     return hull_actor_;
52   }
53 
54   inline bool
getDisplay()55   getDisplay () const
56   {
57     return display_;
58   }
59 
60   void
setDisplay(bool display)61   setDisplay (bool display)
62   {
63     this->display_ = display;
64   }
65 
66   void
getFrustum(double frustum[])67   getFrustum (double frustum[])
68   {
69     for (int i = 0; i < 24; i++)
70       frustum[i] = frustum_[i];
71   }
72 
73   void
setProjectionMatrix(const Eigen::Matrix4d & projection_matrix)74   setProjectionMatrix (const Eigen::Matrix4d &projection_matrix)
75   {
76     projection_matrix_ = projection_matrix;
77   }
78 
79   Eigen::Matrix4d
getProjectionMatrix()80   getProjectionMatrix ()
81   {
82     return projection_matrix_;
83   }
84 
85   void
setModelViewMatrix(const Eigen::Matrix4d & model_view_matrix)86   setModelViewMatrix (const Eigen::Matrix4d &model_view_matrix)
87   {
88     model_view_matrix_ = model_view_matrix;
89   }
90 
91   Eigen::Matrix4d
getModelViewMatrix()92   getModelViewMatrix ()
93   {
94     return model_view_matrix_;
95   }
96 
97   Eigen::Matrix4d
getViewProjectionMatrix()98   getViewProjectionMatrix ()
99   {
100     return Eigen::Matrix4d (projection_matrix_ * model_view_matrix_);
101   }
102 
103   Eigen::Vector3d
getPosition()104   getPosition ()
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
130   computeFrustum ();
131   //computeFrustum(double aspect);
132   void
133   printFrustum ();
134 
135   // Aligned operator, because of Eigen members
136   PCL_MAKE_ALIGNED_OPERATOR_NEW
137 
138 private:
139 
140   // Members
141   // -----------------------------------------------------------------------------
142   vtkSmartPointer<vtkCamera> camera_;
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 };
156