SingleCameraModelFilter.cpp
Go to the documentation of this file.
1 
24 
25 namespace next_best_view {
26  SingleCameraModelFilter::SingleCameraModelFilter(const SimpleVector3 pivotPointOffset) : CameraModelFilter(), mPivotPointOffset(pivotPointOffset), mFrustumCullingPtr(new FrustumCulling()) {
27  }
28 
30 
32  indicesPtr = IndicesPtr(new Indices());
33 
34  // get the settings of the pivot point
35  SimpleVector3 pivotPointPosition = this->getPivotPointPosition();
36  SimpleQuaternion pivotPointOrientation = this->getOrientation();
37 
38  // calculate the real position of the camera
39  SimpleVector3 cameraPosition = pivotPointPosition + pivotPointOrientation.toRotationMatrix() * mPivotPointOffset;
40 
41  // set the settings
42  mFrustumCullingPtr->setHorizontalFOV(this->getVerticalFOV());
43  mFrustumCullingPtr->setVerticalFOV(this->getHorizontalFOV());
44  mFrustumCullingPtr->setNearPlaneDistance(this->getNearClippingPlane());
45  mFrustumCullingPtr->setFarPlaneDistance(this->getFarClippingPlane());
46 
47  // orientation and position
48  mFrustumCullingPtr->setCameraPose(getCameraPoseMatrix(cameraPosition, pivotPointOrientation));
49  mFrustumCullingPtr->setIndices(this->getIndices());
50  mFrustumCullingPtr->setInputCloud(this->getInputCloud());
51 
52  // start filtering.
53  mFrustumCullingPtr->filter(*indicesPtr);
54  }
55 
57  mPivotPointOffset = pivotPointOffset;
58  }
59 
61  return mPivotPointOffset;
62  }
63 
64  viz::MarkerArrayPtr SingleCameraModelFilter::getVisualizationMarkerArray(uint32_t &sequence, double lifetime) {
65  viz::MarkerArrayPtr markerArrayPtr(new viz::MarkerArray());
66  ros::Duration lifetimeDur = lifetime > 0 ? ros::Duration(lifetime) : ros::Duration();
67 
68  // get the position of the pivot point.
69  SimpleVector3 pivotPointPosition = this->getPivotPointPosition();
70  // the orientation
71  SimpleQuaternion orientation = this->getOrientation();
72  SimpleMatrix3 rotationMatrix = orientation.toRotationMatrix();
73 
74  // get the camera position
75  SimpleVector3 cameraPosition = pivotPointPosition + rotationMatrix * this->getPivotPointOffset();
76 
77  // setting the camera params
78  double fovx = MathHelper::degToRad(this->getHorizontalFOV());
79  double fovy = MathHelper::degToRad(this->getVerticalFOV());
80  double ncp = this->getNearClippingPlane();
81  double fcp = this->getFarClippingPlane();
82 
83  // Mark Frustum
84  viz::Marker axisX = MarkerHelper::getArrowMarker(sequence++, cameraPosition, cameraPosition + rotationMatrix.block<3,1>(0, 0) * fcp);
85  MarkerHelper::getRainbowColor(axisX, 1.0 / 6.0, 0.8);
86  axisX.lifetime = lifetimeDur;
87  markerArrayPtr->markers.push_back(axisX);
88 
89 // viz::Marker axisY = MarkerHelper::getArrowMarker(sequence++, cameraPosition, cameraPosition + rotationMatrix.block<3,1>(0, 1));
90 // MarkerHelper::getRainbowColor(axisY, 2.0 / 6.0, 0.8);
91 // axisY.lifetime = lifetimeDur;
92 // markerArrayPtr->markers.push_back(axisY);
93 //
94 // viz::Marker axisZ = MarkerHelper::getArrowMarker(sequence++, cameraPosition, cameraPosition + rotationMatrix.block<3,1>(0, 2));
95 // MarkerHelper::getRainbowColor(axisZ, 4.0 / 6.0, 0.8);
96 // axisZ.lifetime = lifetimeDur;
97 // markerArrayPtr->markers.push_back(axisZ);
98 
99  Eigen::Matrix<Precision, 3, 4> frustumMatrix;
100  frustumMatrix << 1, 1, 1, 1,
101  tan(fovx / 2.0), -tan(fovx / 2.0), -tan(fovx / 2.0), tan(fovx / 2.0),
102  tan(fovy / 2.0), tan(fovy / 2.0), -tan(fovy / 2.0), -tan(fovy / 2.0);
103 
104  Eigen::Matrix<Precision, 3, 4> frustumCornerMatrix = rotationMatrix * frustumMatrix;
105 
106  Eigen::Matrix<Precision, 3, 8> completeFrustumCornerMatrix;
107  completeFrustumCornerMatrix.block<3, 4>(0, 0) = ncp * frustumCornerMatrix;
108  completeFrustumCornerMatrix.block<3, 4>(0, 4) = fcp * frustumCornerMatrix;
109 
110  // Create the frustum
111  int indicesList[] = {0,1,2, 0,2,3, 0,4,7, 0,3,7 ,0,4,5, 0,1,5, 2,6,7, 2,3,7, 2,5,6, 1,2,5, 4,5,7, 5,6,7};
112  std::size_t sz = sizeof(indicesList) / sizeof(int);
113  std::vector<int> triangleList(indicesList, indicesList + sz);
114 
115  viz::Marker triangleListMarker = MarkerHelper::getBasicMarker(sequence++);
116  triangleListMarker.type = viz::Marker::TRIANGLE_LIST;
117  triangleListMarker.lifetime = lifetimeDur;
118  triangleListMarker.scale.x = triangleListMarker.scale.y = triangleListMarker.scale.z = 1.0;
119  triangleListMarker.pose.position = TypeHelper::getPointMSG(cameraPosition);
120  MarkerHelper::getRainbowColor(triangleListMarker, 1.0 / 6.0, 0.2);
121 
122  BOOST_FOREACH(int index, triangleList) {
123  SimpleVector3 frustumPoint = completeFrustumCornerMatrix.block<3, 1>(0, index);
124  geometry_msgs::Point pt = TypeHelper::getPointMSG(frustumPoint);
125  triangleListMarker.points.push_back(pt);
126  }
127  markerArrayPtr->markers.push_back(triangleListMarker);
128 
129  // create the line list
130  int lineIndicesList[] = {0,1, 0,3, 0,4, 1,2, 1,5, 2,3, 2,6, 3,7, 4,5, 4,7, 5,6, 6,7};
131  sz = sizeof(lineIndicesList) / sizeof(int);
132  std::vector<int> lineList(lineIndicesList, lineIndicesList + sz);
133 
134  viz::Marker lineListMarker = MarkerHelper::getBasicMarker(sequence++);
135  lineListMarker.type = viz::Marker::LINE_LIST;
136  lineListMarker.lifetime = lifetimeDur;
137  lineListMarker.scale.x = 0.01;
138  lineListMarker.pose.position = TypeHelper::getPointMSG(cameraPosition);
139  MarkerHelper::getRainbowColor(lineListMarker, 1.0 / 6.0, 0.2);
140 
141  BOOST_FOREACH(int index, lineList) {
142  SimpleVector3 frustumPoint = completeFrustumCornerMatrix.block<3, 1>(0, index);
143  geometry_msgs::Point pt = TypeHelper::getPointMSG(frustumPoint);
144  lineListMarker.points.push_back(pt);
145  }
146  markerArrayPtr->markers.push_back(lineListMarker);
147 
148  if (pivotPointPosition != cameraPosition) {
149  viz::Marker offsetArrow = MarkerHelper::getArrowMarker(sequence++, pivotPointPosition, cameraPosition);
150  offsetArrow.lifetime = lifetimeDur;
151  MarkerHelper::getRainbowColor(offsetArrow, 1.0 / 6.0, 1.0);
152  markerArrayPtr->markers.push_back(offsetArrow);
153  }
154 
155  return markerArrayPtr;
156  }
157 }
158 
SingleCameraModelFilter(const SimpleVector3 pivotPointOffset=SimpleVector3())
constructs a new camera model filter object.
pcl::FrustumCulling< ObjectPoint > FrustumCulling
Definition: typedef.hpp:101
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
Definition: typedef.hpp:53
static geometry_msgs::Point getPointMSG(const SimpleVector3 &vector)
Definition: TypeHelper.cpp:23
virtual ObjectPointCloudPtr & getInputCloud()
Definition: CommonClass.cpp:31
static SimpleMatrix4 getCameraPoseMatrix(const SimpleVector3 &position, const SimpleQuaternion &orientation)
convenience function to get a camera pose matrix.
std::vector< int > Indices
Definition: typedef.hpp:117
this namespace contains all generally usable classes.
viz::MarkerArrayPtr getVisualizationMarkerArray(uint32_t &sequence, double lifetime=30.0)
returns a array of markers containing the visualization of the camera frustum.
SimpleVector3 mPivotPointOffset
the offset to the pivot point.
virtual ~SingleCameraModelFilter()
destructs the single camera model filter object.
boost::shared_ptr< Indices > IndicesPtr
Definition: typedef.hpp:118
CameraModelFilter class was built to generalize the filtering for different camera models...
static visualization_msgs::Marker getBasicMarker(int id, std::string ns="my_namespace")
returns a marker with basic settings
virtual IndicesPtr & getIndices()
Definition: CommonClass.cpp:39
static double degToRad(double input)
Definition: MathHelper.cpp:172
FrustumCullingPtr mFrustumCullingPtr
shared pointer to the frustum culling object.
static visualization_msgs::Marker getArrowMarker(int id, SimpleVector3 startPoint, SimpleVector3 endPoint, SimpleVector3 scale=SimpleVector3(0.025, 0.05, 0.05), SimpleVector4 color=SimpleVector4(1.0, 0.0, 0.0, 1.0), std::string ns="my_namespace")
returns an arrow marker with the given settings
static void getRainbowColor(visualization_msgs::Marker &marker, double x, double alpha=1.0)
void setPivotPointOffset(const SimpleVector3 &pivotPointOffset)
sets the offset between the pivot point and the actual camera position.
void doFiltering(IndicesPtr &indicesPtr)
Does the filtering on the indices.
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:67
Eigen::Matrix< Precision, 3, 3 > SimpleMatrix3
Definition: typedef.hpp:40


asr_next_best_view
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Thu Jan 9 2020 07:20:18