Go to the documentation of this file.00001
00002 #include <iostream>
00003 #include <string>
00004
00005
00006 #include <pcl/visualization/common/common.h>
00007
00008
00009 #include <pcl/outofcore/visualization/camera.h>
00010 #include <pcl/outofcore/visualization/object.h>
00011
00012
00013 #include <vtkActor.h>
00014 #include <vtkCamera.h>
00015 #include <vtkCameraActor.h>
00016 #include <vtkHull.h>
00017 #include <vtkPlanes.h>
00018 #include <vtkPolyData.h>
00019 #include <vtkPolyDataMapper.h>
00020 #include <vtkProperty.h>
00021 #include <vtkSmartPointer.h>
00022
00023
00024
00025 Camera::Camera (std::string name) :
00026 Object (name), display_ (false)
00027 {
00028 camera_ = vtkSmartPointer<vtkCamera>::New ();
00029 camera_->SetClippingRange(0.0001, 100000);
00030
00031 camera_actor_ = vtkSmartPointer<vtkCameraActor>::New ();
00032 camera_actor_->SetCamera (camera_);
00033 camera_actor_->GetProperty ()->SetLighting (0);
00034 camera_actor_->GetProperty ()->SetLineStipplePattern (1010101010);
00035
00036 for (int i = 0; i < 24; i++)
00037 frustum_[i] = 0;
00038
00039 hull_actor_ = vtkSmartPointer<vtkActor>::New ();
00040 vtkSmartPointer<vtkPolyDataMapper> hull_mapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
00041
00042 hull_actor_->SetMapper (hull_mapper);
00043 hull_actor_->GetProperty ()->SetLighting (0);
00044 hull_actor_->GetProperty ()->SetColor (1.0, 0.0, 0.0);
00045 hull_actor_->GetProperty ()->SetOpacity (0.25);
00046 }
00047
00048 Camera::Camera (std::string name, vtkSmartPointer<vtkCamera> camera) :
00049 Object (name), display_ (false)
00050 {
00051 camera_ = camera;
00052 camera_->SetClippingRange(0.0001, 100000);
00053
00054 camera_actor_ = vtkSmartPointer<vtkCameraActor>::New ();
00055 camera_actor_->SetCamera (camera_);
00056 camera_actor_->GetProperty ()->SetLighting (0);
00057
00058 for (int i = 0; i < 24; i++)
00059 frustum_[i] = 0;
00060
00061 hull_actor_ = vtkSmartPointer<vtkActor>::New ();
00062 vtkSmartPointer<vtkPolyDataMapper> hull_mapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
00063
00064 hull_actor_->SetMapper (hull_mapper);
00065 hull_actor_->GetProperty ()->SetLighting (0);
00066 hull_actor_->GetProperty ()->SetColor (1.0, 0.0, 0.0);
00067 hull_actor_->GetProperty ()->SetOpacity (0.25);
00068
00069 prevUp_[0] = prevUp_[1] = prevUp_[2] = 0;
00070 prevFocal_[0] = prevFocal_[1] = prevFocal_[2] = 0;
00071 prevPos_[0] = prevPos_[1] = prevPos_[2] = 0;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081 void
00082
00083 Camera::computeFrustum ()
00084 {
00085
00086
00087
00088
00089 pcl::visualization::getViewFrustum (getViewProjectionMatrix (), frustum_);
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 }
00109
00110 void
00111 Camera::printFrustum ()
00112 {
00113 for (int i = 0; i < 6; i++)
00114 {
00115 std::cout << frustum_[(i * 4)] << "x + " << frustum_[(i * 4) + 1] << "y + " << frustum_[(i * 4) + 2] << "z + "
00116 << frustum_[(i * 4) + 3] << std::endl;
00117 }
00118 }
00119
00120 void
00121 Camera::render (vtkRenderer* renderer)
00122 {
00123 vtkSmartPointer<vtkCamera> active_camera = renderer->GetActiveCamera ();
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 setClippingRange();
00142
00143 double *up = active_camera->GetViewUp ();
00144 double *focal = active_camera->GetFocalPoint ();
00145 double *pos = active_camera->GetPosition ();
00146
00147 bool viewpointChanged = false;
00148
00149
00150 if (up[0] != prevUp_[0] || up[1] != prevUp_[1] || up[2] != prevUp_[2])
00151 viewpointChanged = true;
00152
00153
00154 if (focal[0] != prevFocal_[0] || focal[1] != prevFocal_[1] || focal[2] != prevFocal_[2])
00155 viewpointChanged = true;
00156
00157
00158 if (pos[0] != prevPos_[0] || pos[1] != prevPos_[1] || pos[2] != prevPos_[2])
00159 viewpointChanged = true;
00160
00161
00162 if (viewpointChanged)
00163 {
00164 prevUp_[0] = up[0];
00165 prevUp_[1] = up[1];
00166 prevUp_[2] = up[2];
00167 prevFocal_[0] = focal[0];
00168 prevFocal_[1] = focal[1];
00169 prevFocal_[2] = focal[2];
00170 prevPos_[0] = pos[0];
00171 prevPos_[1] = pos[1];
00172 prevPos_[2] = pos[2];
00173
00174
00175
00176
00177
00178
00179 {
00180 renderer->ComputeAspect ();
00181 double *aspect = renderer->GetAspect ();
00182
00183 projection_matrix_ = pcl::visualization::vtkToEigen (active_camera->GetProjectionTransformMatrix (aspect[0] / aspect[1], 0.0, 1.0));
00184 model_view_matrix_ = pcl::visualization::vtkToEigen (active_camera->GetModelViewTransformMatrix ());
00185
00186
00187 computeFrustum ();
00188 }
00189 }
00190
00191 Object::render(renderer);
00192 }