Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <pcl/visualization/common/common.h>
00039 #include <stdlib.h>
00040
00042 void
00043 pcl::visualization::getRandomColors (double &r, double &g, double &b, double min, double max)
00044 {
00045 double sum;
00046 static unsigned stepRGBA = 100;
00047 do
00048 {
00049 sum = 0;
00050 r = (rand () % stepRGBA) / static_cast<double> (stepRGBA);
00051 while ((g = (rand () % stepRGBA) / static_cast<double> (stepRGBA)) == r) {}
00052 while (((b = (rand () % stepRGBA) / static_cast<double> (stepRGBA)) == r) && (b == g)) {}
00053 sum = r + g + b;
00054 }
00055 while (sum <= min || sum >= max);
00056 }
00057
00059
00060 void
00061 pcl::visualization::Camera::computeViewMatrix(Eigen::Matrix4d& view_mat) const
00062 {
00063
00064
00065 Eigen::Vector3d focal_point (focal[0], focal[1], focal[2]);
00066 Eigen::Vector3d posv (pos[0] , pos[1] , pos[2]);
00067 Eigen::Vector3d up (view[0] , view[1] , view[2]);
00068
00069 Eigen::Vector3d zAxis = (focal_point - posv).normalized();
00070 Eigen::Vector3d xAxis = zAxis.cross(up).normalized();
00071
00072 Eigen::Vector3d yAxis = xAxis.cross (zAxis);
00073
00074 view_mat.block <1, 3> (0, 0) = xAxis;
00075 view_mat.block <1, 3> (1, 0) = yAxis;
00076 view_mat.block <1, 3> (2, 0) = -zAxis;
00077 view_mat.row (3) << 0, 0, 0, 1;
00078
00079 view_mat.block <3, 1> (0, 3) = view_mat.topLeftCorner<3, 3> () * (-posv);
00080 }
00081
00083 void
00084 pcl::visualization::Camera::computeProjectionMatrix (Eigen::Matrix4d& proj) const
00085 {
00086 float top = static_cast<float> (clip[0]) * tanf (0.5f * static_cast<float> (fovy));
00087 float left = -top * static_cast<float> (window_size[0] / window_size[1]);
00088 float right = -left;
00089 float bottom = -top;
00090
00091 float temp1, temp2, temp3, temp4;
00092 temp1 = 2.0f * static_cast<float> (clip[0]);
00093 temp2 = 1.0f / (right - left);
00094 temp3 = 1.0f / (top - bottom);
00095 temp4 = 1.0f / static_cast<float> (clip[1] - clip[0]);
00096
00097 proj.setZero ();
00098
00099 proj(0,0) = temp1 * temp2;
00100 proj(1,1) = temp1 * temp3;
00101 proj(0,2) = (right + left) * temp2;
00102 proj(1,2) = (top + bottom) * temp3;
00103 proj(2,2) = (-clip[1] - clip[0]) * temp4;
00104 proj(3,2) = -1.0;
00105 proj(2,3) = (-temp1 * clip[1]) * temp4;
00106 }