40 throw std::out_of_range(
"Invalid pointer: absolute pose of primary scene object.");
47 unsigned int& pMarkerId,
48 const Eigen::Vector3d& pMean,
49 const Eigen::Matrix3d& pCovariance)
53 throw std::invalid_argument(
"Empty ros::publisher cannot be used to publish marker messages.");
56 visualization_msgs::MarkerArray modelMarkers;
65 std_msgs::ColorRGBA pEllipseColor;
66 pEllipseColor.r = pEllipseColor.g = pEllipseColor.b = 0.45;
67 pEllipseColor.a = 0.33;
70 modelMarkers.markers.push_back(
generateCovarianceEllipsoidMarker(pMarkerId++, visualization_msgs::Marker::SPHERE, std::vector<std::vector<float> >(), pEllipseColor, pMean, pCovariance));
72 catch(std::exception& exception) {
73 std::cerr << exception.what() << std::endl;
81 std::vector<std::vector<std::vector<int> > > integerWireFrame;
84 std::vector<std::vector<std::vector<int> > >::iterator wireIterator;
87 std::vector<std::vector<int> >::iterator pointInterator;
90 std::vector<int>::iterator coordinatesIterator;
93 std::vector<int> ellipsoidHalfAxes;
96 ellipsoidHalfAxes.push_back(static_cast<int>((0.5
f * modelMarkers.markers[0].scale.x * 1000.0f) /
mSigmaMultiplicator));
97 ellipsoidHalfAxes.push_back(static_cast<int>((0.5
f * modelMarkers.markers[0].scale.y * 1000.0f) /
mSigmaMultiplicator));
98 ellipsoidHalfAxes.push_back(static_cast<int>((0.5
f * modelMarkers.markers[0].scale.z * 1000.0f) /
mSigmaMultiplicator));
104 std::vector<std::vector<std::vector<float> > > floatWireFrame;
107 for(wireIterator = integerWireFrame.begin(); wireIterator != integerWireFrame.end(); wireIterator++)
110 std::vector<std::vector<float> > pointSequence;
113 for(pointInterator = wireIterator->begin(); pointInterator != wireIterator->end(); pointInterator++)
116 std::vector<float> point;
119 for(coordinatesIterator = pointInterator->begin();coordinatesIterator != pointInterator->end(); coordinatesIterator++)
122 point.push_back(static_cast<float>(*coordinatesIterator) / 1000.0
f);
126 pointSequence.push_back(point);
130 floatWireFrame.push_back(pointSequence);
136 std_msgs::ColorRGBA pRingColor;
137 pRingColor.r =
getColor(0).r * factor;
138 pRingColor.g =
getColor(0).g * factor;
139 pRingColor.b =
getColor(0).b * factor;
143 for(
unsigned int i = 0; i < floatWireFrame.size(); i++)
146 visualization_msgs::Marker marker =
generateCovarianceEllipsoidMarker(pMarkerId++, visualization_msgs::Marker::LINE_LIST, floatWireFrame[i], pRingColor, pMean, pCovariance);
149 modelMarkers.markers.push_back(marker);
151 }
catch(std::exception& exception) {
152 std::cerr << exception.what() << std::endl;
174 pPublisher->publish(modelMarkers);
178 const int pDiscretizationResolution,
179 std::vector<std::vector<std::vector<int> > >& pEllipsePolygons)
182 if(pEllipsoidHalfAxes.size() != 3)
183 throw std::length_error(
"Only supporting three dimensional ellipsoids at the moment, not " + boost::lexical_cast<std::string>(pEllipsoidHalfAxes.size()) +
"D.");
186 pEllipsePolygons.clear();
189 std::vector<cv::Point> coordinatePlaneHalfAxisIndices;
192 coordinatePlaneHalfAxisIndices.push_back(cv::Point(1, 2));
195 coordinatePlaneHalfAxisIndices.push_back(cv::Point(0, 2));
198 coordinatePlaneHalfAxisIndices.push_back(cv::Point(0, 1));
201 for(
unsigned int i = 0; i < coordinatePlaneHalfAxisIndices.size(); i++)
204 std::vector<std::vector<int> > threeDEllipsePolygon;
207 std::vector<cv::Point> twoDEllipsePolygon;
210 cv::Size ellipseHalfAxes(static_cast<float>(pEllipsoidHalfAxes.at(coordinatePlaneHalfAxisIndices.at(i).x)) *
mSigmaMultiplicator,
static_cast<float>(pEllipsoidHalfAxes.at(coordinatePlaneHalfAxisIndices.at(i).y)) *
mSigmaMultiplicator);
213 cv::ellipse2Poly(cv::Point(0, 0), ellipseHalfAxes, 0, 0, 360, pDiscretizationResolution, twoDEllipsePolygon);
216 for(
unsigned int j = 0; j < twoDEllipsePolygon.size(); j++) {
219 std::vector<int> threeDPolygonPoint(3, 0);
222 threeDPolygonPoint.at(coordinatePlaneHalfAxisIndices.at(i).x) = twoDEllipsePolygon.at(j).x;
225 threeDPolygonPoint.at(coordinatePlaneHalfAxisIndices.at(i).y) = twoDEllipsePolygon.at(j).y;
228 threeDEllipsePolygon.push_back(threeDPolygonPoint);
232 pEllipsePolygons.push_back(threeDEllipsePolygon);
237 const int pMarkerShape,
const std::vector<std::vector<float> >& pWireFramePolygons,
238 const std_msgs::ColorRGBA& pColor,
239 const Eigen::Vector3d& pMean,
240 const Eigen::Matrix3d& pCovariance)
242 if(pMarkerShape != visualization_msgs::Marker::SPHERE && pMarkerShape != visualization_msgs::Marker::LINE_LIST)
243 throw std::invalid_argument(
"Chosen marker shape is not supported to visualize.");
246 visualization_msgs::Marker msg;
262 msg.type = pMarkerShape;
265 msg.action = visualization_msgs::Marker::ADD;
268 Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> es(pCovariance);
271 Eigen::Matrix3d rotationFromParentToWorld =
mParentPose->quat->getEigen().toRotationMatrix();
274 Eigen::Vector3d baseX = rotationFromParentToWorld * es.eigenvectors().col(0);
275 Eigen::Vector3d baseY = rotationFromParentToWorld * es.eigenvectors().col(1);
276 Eigen::Vector3d baseZ = rotationFromParentToWorld * es.eigenvectors().col(2);
279 Eigen::Vector3d positionInParentFrame = rotationFromParentToWorld * pMean;
282 Eigen::Vector3d position =
mParentPose->point->getEigen();
283 tf::Vector3 tfEllipsoidPosition(position[0] + positionInParentFrame[0],
284 position[1] + positionInParentFrame[1],
285 position[2] + positionInParentFrame[2]);
288 Eigen::Vector3d
cross = baseY.cross(baseX);
294 Eigen::Vector3d squaredEllipsoidLengths;
300 if(std::signbit(cross[0]) != std::signbit(baseZ[0]) ||
301 std::signbit(cross[1]) != std::signbit(baseZ[1]) ||
302 std::signbit(cross[2]) != std::signbit(baseZ[2]))
304 tfRotationMatrixOrientation =
tf::Matrix3x3(baseX[0], -baseZ[0], baseY[0],
305 baseX[1], -baseZ[1], baseY[1],
306 baseX[2], -baseZ[2], baseY[2]);
308 squaredEllipsoidLengths = Eigen::Vector3d(es.eigenvalues()[0], es.eigenvalues()[2], es.eigenvalues()[1]);
311 tfRotationMatrixOrientation =
tf::Matrix3x3(baseX[0], baseY[0], -baseZ[0],
312 baseX[1], baseY[1], -baseZ[1],
313 baseX[2], baseY[2], -baseZ[2]);
315 squaredEllipsoidLengths = es.eigenvalues();
319 tf::Transform tfEllipsoidPose(tfRotationMatrixOrientation, tfEllipsoidPosition);
333 if(pMarkerShape == visualization_msgs::Marker::SPHERE)
342 std::vector<std::vector<float> >::const_iterator polygonPointIterator = pWireFramePolygons.begin();
345 geometry_msgs::Point rosPolygonPoint;
351 msg.points.push_back(rosPolygonPoint);
354 for(polygonPointIterator++; polygonPointIterator != pWireFramePolygons.end(); polygonPointIterator++)
358 msg.points.push_back(rosPolygonPoint);
361 msg.points.push_back(rosPolygonPoint);
366 msg.points.push_back(rosPolygonPoint);
379 const unsigned int pAxis,
380 const Eigen::Vector3d& pMean,
381 const Eigen::Matrix3d& pCovariance)
383 visualization_msgs::Marker msg;
386 Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> es(pCovariance);
395 unsigned int axisForRightHandFrame = pAxis;
398 Eigen::Vector3d firstAxis = es.eigenvectors().col(0) * std::sqrt(es.eigenvalues()[0]);
399 Eigen::Vector3d secondAxis = es.eigenvectors().col(1) * std::sqrt(es.eigenvalues()[1]);
400 Eigen::Vector3d thirdAxis = es.eigenvectors().col(2) * std::sqrt(es.eigenvalues()[2]);
403 Eigen::Vector3d
cross = secondAxis.cross(firstAxis);
406 if(std::signbit(cross[0]) != std::signbit(thirdAxis[0]) ||
407 std::signbit(cross[1]) != std::signbit(thirdAxis[1]) ||
408 std::signbit(cross[2]) != std::signbit(thirdAxis[2]))
410 if(pAxis == 1) axisForRightHandFrame = 2;
411 if(pAxis == 2) axisForRightHandFrame = 1;
432 msg.type = visualization_msgs::Marker::ARROW;
435 msg.action = visualization_msgs::Marker::ADD;
438 msg.scale.x = msg.scale.y = 0.005;
441 Eigen::Matrix3d rotationFromParentToWorld =
mParentPose->quat->getEigen().toRotationMatrix();
445 Eigen::Vector3d axis = rotationFromParentToWorld * (es.eigenvectors().col(axisForRightHandFrame) * std::sqrt(es.eigenvalues()[axisForRightHandFrame]));
448 Eigen::Vector3d positionInParentFrame = rotationFromParentToWorld * pMean;
451 Eigen::Vector3d position =
mParentPose->point->getEigen();
454 geometry_msgs::Point start;
455 start.x = (position[0] + positionInParentFrame[0]) *
getScaleFactor();
456 start.y = (position[1] + positionInParentFrame[1]) *
getScaleFactor();
457 start.z = (position[2] + positionInParentFrame[2]) *
getScaleFactor();
458 msg.points.push_back(start);
461 geometry_msgs::Point stop;
463 stop.y = ((position[1] + positionInParentFrame[1]) + (axis[1] * mSigmaMultiplicator)) *
getScaleFactor();
464 stop.z = ((position[2] + positionInParentFrame[2]) + (axis[2] * mSigmaMultiplicator)) *
getScaleFactor();
465 msg.points.push_back(stop);
469 msg.color.b = (pAxis == 0) ? 1.0 : 0.0;
470 msg.color.g = (pAxis - 1 == 0) ? 1.0 : 0.0;
471 msg.color.r = (pAxis - 2 == 0) ? 1.0 : 0.0;
481 visualization_msgs::MarkerArray msgArray;
482 visualization_msgs::Marker msg;
495 msg.type = visualization_msgs::Marker::SPHERE_LIST;
498 msg.action = visualization_msgs::Marker::ADD;
503 geometry_msgs::Point point;
507 msg.points.push_back(point);
511 Eigen::Vector3d position =
mParentPose->point->getEigen();
516 Eigen::Quaternion<double> orientation =
mParentPose->quat->getEigen();
517 msg.pose.orientation.w = orientation.w();
518 msg.pose.orientation.x = orientation.x();
519 msg.pose.orientation.y = orientation.y();
520 msg.pose.orientation.z = orientation.z();
523 msg.scale.x = msg.scale.y = msg.scale.z = 0.0025 *
getScaleFactor();
532 msgArray.markers.push_back(msg);
540 visualization_msgs::Marker msg;
547 msg.scale.x = msg.scale.y = msg.scale.z = 0.01;
550 msg.type = visualization_msgs::Marker::SPHERE;
556 msg.id = pMarkerId++;
559 msg.action = visualization_msgs::Marker::ADD;
562 msg.pose.position.x = pPos[0];
563 msg.pose.position.y = pPos[1];
564 msg.pose.position.z = pPos[2];
565 msg.pose.orientation.x = 0.0;
566 msg.pose.orientation.y = 0.0;
567 msg.pose.orientation.z = 0.0;
568 msg.pose.orientation.w = 1.0;
572 msg.color.r =
getColor(0).r * factor;
573 msg.color.g =
getColor(0).g * factor;
574 msg.color.b =
getColor(0).b * factor;
583 visualization_msgs::Marker msg;
598 msg.type = visualization_msgs::Marker::ARROW;
604 msg.id = pMarkerId++;
607 msg.action = visualization_msgs::Marker::ADD;
610 geometry_msgs::Point start;
614 msg.points.push_back(start);
617 geometry_msgs::Point stop;
621 msg.points.push_back(stop);
625 msg.color.r =
getColor(0).r * factor;
626 msg.color.g =
getColor(0).g * factor;
627 msg.color.b =
getColor(0).b * factor;
637 if(pPositionVector.size() != 3)
638 throw std::invalid_argument(
"pPositionVector is not a position in terms of dimensionality.");
641 pROSPositionMsg.x = pPositionVector.at(0);
642 pROSPositionMsg.y = pPositionVector.at(1);
643 pROSPositionMsg.z = pPositionVector.at(2);
float mSigmaMultiplicator
std::string getNamespace()
void calculateCoordinatePlaneEllipses(const std::vector< int > &pEllipsoidHalfAxes, const int pDiscretizationResolution, std::vector< std::vector< std::vector< int > > > &pEllipsePolygons)
visualization_msgs::Marker generateArrowMessage(unsigned int &pMarkerId, Eigen::Vector3d pFrom, Eigen::Vector3d pTo)
void setSigmaMultiplicator(const float pSigmaMultiplicator)
TFSIMD_FORCE_INLINE Vector3 cross(const Vector3 &v) const
void setParentPose(boost::shared_ptr< ISM::Pose > pPose)
GaussianKernelVisualizer()
~GaussianKernelVisualizer()
const std_msgs::ColorRGBA getColor(unsigned int pNumber)
static void poseTFToMsg(const Pose &bt, geometry_msgs::Pose &msg)
visualization_msgs::MarkerArray generateSamplesMarker(const unsigned int pMarkerId, const std::vector< boost::shared_ptr< Eigen::Quaternion< double > > > &pSamples)
boost::shared_ptr< ISM::Pose > mParentPose
visualization_msgs::Marker generateSphereMessage(unsigned int &pMarkerId, Eigen::Vector3d pPos)
void publishKernel(boost::shared_ptr< ros::Publisher > pPublisher, unsigned int &pMarkerId, const Eigen::Vector3d &pMean, const Eigen::Matrix3d &pCovariance)
visualization_msgs::Marker generateAxis(const unsigned int pMarkerId, const unsigned int pAxis, const Eigen::Vector3d &pMean, const Eigen::Matrix3d &pCovariance)
visualization_msgs::Marker generateCovarianceEllipsoidMarker(const unsigned int pMarkerId, const int pMarkerShape, const std::vector< std::vector< float > > &pWireFramePolygons, const std_msgs::ColorRGBA &pColor, const Eigen::Vector3d &pMean, const Eigen::Matrix3d &pCovariance)
void stlVectorToPointMsg(const std::vector< T > pPositionVector, geometry_msgs::Point &pROSPositionMsg)