00001 #include "PlannerObstacles.h"
00002
00003
00004
00005
00006
00007 #include "DualCoding/ShapeBlob.h"
00008 #include "DualCoding/ShapeBrick.h"
00009 #include "DualCoding/ShapeCross.h"
00010 #include "DualCoding/ShapeDomino.h"
00011 #include "DualCoding/ShapeCylinder.h"
00012 #include "DualCoding/ShapeEllipse.h"
00013 #include "DualCoding/ShapeLine.h"
00014 #include "DualCoding/ShapeNaught.h"
00015 #include "DualCoding/ShapePoint.h"
00016 #include "DualCoding/ShapePolygon.h"
00017 #include "DualCoding/ShapeSphere.h"
00018
00019
00020 using namespace DualCoding;
00021
00022 template <>
00023 void PlannerObstacle2D::convertShapeToPlannerObstacle
00024 (const DualCoding::ShapeRoot &shape, float inflation, std::vector<PlannerObstacle2D*> &obstacles) {
00025 switch ( shape->getType() ) {
00026
00027 case pointDataType: {
00028 const Shape<PointData> &p = ShapeRootTypeConst(shape,PointData);
00029 float pointWidth = 1;
00030 CircularObstacle *circ =
00031 new CircularObstacle(p->getCentroid().coordX(),
00032 p->getCentroid().coordY(),
00033 pointWidth+inflation);
00034 std::ostringstream nameStream;
00035 nameStream << p->getName() << "-" << p->getId();
00036 circ->name = nameStream.str();
00037 circ->shapeId = p->getId();
00038 obstacles.push_back(circ);
00039 } break;
00040
00041 case aprilTagDataType:
00042
00043 break;
00044
00045 case lineDataType: {
00046 const Shape<LineData> &line = ShapeRootTypeConst(shape,LineData);
00047 const fmat::SubVector<2, const fmat::fmatReal> p1(line->end1Pt().coords);
00048 const fmat::SubVector<2, const fmat::fmatReal> p2(line->end2Pt().coords);
00049 const fmat::Column<2> axis = p2 - p1;
00050 float const lineWidth = 1;
00051 RectangularObstacle *rect =
00052 new RectangularObstacle((p1 + p2)/2,
00053 fmat::pack(axis.norm()/2+inflation, lineWidth+inflation),
00054 line->getOrientation());
00055 std::ostringstream nameStream;
00056 nameStream << line->getName() << "-" << line->getId();
00057 rect->name = nameStream.str();
00058 rect->shapeId = line->getId();
00059 obstacles.push_back(rect);
00060 } break;
00061
00062 case polygonDataType: {
00063 const Shape<PolygonData>& poly = ShapeRootTypeConst(shape,PolygonData);
00064 std::vector<LineData> lines = poly->getEdges();
00065 for (unsigned int i = 0; i < lines.size(); i++) {
00066 const fmat::SubVector<2, const fmat::fmatReal> p1(lines[i].end1Pt().coords);
00067 const fmat::SubVector<2, const fmat::fmatReal> p2(lines[i].end2Pt().coords);
00068 const fmat::Column<2> axis = p2 - p1;
00069 float const lineWidth = 1;
00070 RectangularObstacle *rect =
00071 new RectangularObstacle((p1 + p2)/2, fmat::pack(axis.norm()/2+inflation, lineWidth+inflation),
00072 lines[i].getOrientation());
00073 std::ostringstream nameStream;
00074 nameStream << poly->getName() << "-" << poly->getId() << ":" << i;
00075 rect->name = nameStream.str();
00076 rect->shapeId = poly->getId();
00077 obstacles.push_back(rect);
00078 }
00079 break;
00080 }
00081
00082 case ellipseDataType: {
00083 const Shape<EllipseData> &e = ShapeRootTypeConst(shape,EllipseData);
00084 EllipticalObstacle* ellipse =
00085 new EllipticalObstacle(fmat::Column<2>(e->getCentroid().coords),
00086 e->getSemimajor()+inflation,
00087 e->getSemiminor()+inflation,
00088 e->getOrientation());
00089 std::ostringstream nameStream;
00090 nameStream << e->getName() << "-" << e->getId();
00091 ellipse->name = nameStream.str();
00092 ellipse->shapeId = e->getId();
00093 obstacles.push_back(ellipse);
00094 } break;
00095
00096 case sphereDataType: {
00097 const Shape<SphereData> &sph = ShapeRootTypeConst(shape,SphereData);
00098 CircularObstacle *circ =
00099 new CircularObstacle(sph->getCentroid().coordX(),
00100 sph->getCentroid().coordY(),
00101 sph->getRadius()+inflation);
00102 std::ostringstream nameStream;
00103 nameStream << sph->getName() << "-" << sph->getId();
00104 circ->name = nameStream.str();
00105 circ->shapeId = sph->getId();
00106 obstacles.push_back(circ);
00107 } break;
00108
00109 case cylinderDataType: {
00110 const Shape<CylinderData>& c = ShapeRootTypeConst(shape,CylinderData);
00111 CircularObstacle *circ =
00112 new CircularObstacle(c->getCentroid().coordX(), c->getCentroid().coordY(), c->getRadius()+inflation);
00113 std::ostringstream nameStream;
00114 nameStream << c->getName() << "-" << c->getId();
00115 circ->name = nameStream.str();
00116 circ->shapeId = c->getId();
00117 obstacles.push_back(circ);
00118 } break;
00119
00120 case blobDataType: {
00121 const Shape<BlobData> &b = ShapeRootTypeConst(shape,BlobData);
00122 RectangularObstacle *rect =
00123 new RectangularObstacle(fmat::Column<2>(b->getCentroid().coords), b->getBoundingBox().getDimensions()+inflation, 0);
00124 std::ostringstream nameStream;
00125 nameStream << b->getName() << "-" << b->getId();
00126 rect->name = nameStream.str();
00127 rect->shapeId = b->getId();
00128 obstacles.push_back(rect);
00129 } break;
00130
00131 case brickDataType:{
00132 const Shape<BrickData> &brick = ShapeRootTypeConst(shape,BrickData);
00133 RectangularObstacle *rect =
00134 new RectangularObstacle(fmat::Column<2>(brick->getCentroid().coords), fmat::pack(
00135 (brick->getBoundingBox().getDimension(0))/2 +inflation,
00136 (brick->getBoundingBox().getDimension(1))/2 +inflation), 0);
00137
00138 std::ostringstream nameStream;
00139 nameStream << brick->getName() << "-" << brick->getId();
00140 rect->name = nameStream.str();
00141 rect->shapeId = brick->getId();
00142 obstacles.push_back(rect);
00143 } break;
00144
00145 case dominoDataType: {
00146 const Shape<DominoData> &domino = ShapeRootTypeConst(shape,DominoData);
00147 EllipticalObstacle *ell = new EllipticalObstacle(fmat::Column<2>(domino->getCentroid().coords),
00148 domino->getLength()/2+inflation, domino->getWidth()/2+inflation,
00149 domino->getOrientation().angle());
00150 std::ostringstream nameStream;
00151 nameStream << domino->getName() << "-" << domino->getId();
00152 ell->name = nameStream.str();
00153 ell->shapeId = domino->getId();
00154 obstacles.push_back(ell);
00155 } break;
00156
00157 case crossDataType: {
00158 const Shape<CrossData>& c = ShapeRootTypeConst(shape,CrossData);
00159 CircularObstacle *circ =
00160 new CircularObstacle(c->getCentroid().coordX(), c->getCentroid().coordY(), c->getArmSemiLength()+inflation);
00161 std::ostringstream nameStream;
00162 nameStream << c->getName() << "-" << c->getId();
00163 circ->name = nameStream.str();
00164 circ->shapeId = c->getId();
00165 obstacles.push_back(circ);
00166 } break;
00167
00168 case naughtDataType: {
00169 const Shape<NaughtData>& naught = ShapeRootTypeConst(shape,NaughtData);
00170 CircularObstacle *circ =
00171 new CircularObstacle(naught->getCentroid().coordX(), naught->getCentroid().coordY(), naught->getRadius()+inflation);
00172 std::ostringstream nameStream;
00173 nameStream << naught->getName() << "-" << naught->getId();
00174 circ->name = nameStream.str();
00175 circ->shapeId = naught->getId();
00176 obstacles.push_back(circ);
00177 } break;
00178
00179 default:
00180 std::cout << std::endl << std::endl
00181 <<"Planner error: conversion of '" << shape->getName() << "' "
00182 << " to PlannerObstacle2D not yet implemented." << std::endl << std::endl;
00183 }
00184 }
00185
00186 template <>
00187 void PlannerObstacle3D::convertShapeToPlannerObstacle
00188 (const DualCoding::ShapeRoot &shape, float inflation, std::vector<PlannerObstacle3D*> &obstacles) {
00189 switch ( shape->getType() ) {
00190
00191 case pointDataType: {
00192 const Shape<PointData> &p = ShapeRootTypeConst(shape,PointData);
00193 float pointWidth = 1;
00194 SphericalObstacle *sphere =
00195 new SphericalObstacle(p->getCentroid().coordX(),
00196 p->getCentroid().coordY(),
00197 p->getCentroid().coordZ(),
00198 pointWidth+inflation);
00199 std::ostringstream nameStream;
00200 nameStream << p->getName() << "-" << p->getId();
00201 sphere->name = nameStream.str();
00202 sphere->shapeId = p->getId();
00203 obstacles.push_back(sphere);
00204 } break;
00205
00206 case sphereDataType: {
00207 const Shape<SphereData> &sph = ShapeRootTypeConst(shape,SphereData);
00208 SphericalObstacle *so =
00209 new SphericalObstacle(sph->getCentroid().coordX(),
00210 sph->getCentroid().coordY(),
00211 sph->getCentroid().coordZ(),
00212 sph->getRadius()+inflation);
00213 std::ostringstream nameStream;
00214 nameStream << sph->getName() << "-" << sph->getId();
00215 so->name = nameStream.str();
00216 so->shapeId = sph->getId();
00217 obstacles.push_back(so);
00218 } break;
00219
00220 case cylinderDataType: {
00221 const Shape<CylinderData>& c = ShapeRootTypeConst(shape,CylinderData);
00222 CylindricalObstacle *cyl =
00223 new CylindricalObstacle(fmat::pack(c->getCentroid().coordX(),
00224 c->getCentroid().coordY(),
00225 c->getCentroid().coordZ()),
00226 fmat::Matrix<3,3>::identity(),
00227 c->getRadius(),
00228 c->getHeight()/2);
00229 std::ostringstream nameStream;
00230 nameStream << c->getName() << "-" << c->getId();
00231 cyl->name = nameStream.str();
00232 cyl->shapeId = c->getId();
00233 obstacles.push_back(cyl);
00234 } break;
00235
00236 case brickDataType:
00237 case dominoDataType: {
00238 const Shape<BrickData> &br = ShapeRootTypeConst(shape,BrickData);
00239
00240 const fmat::Column<3> centroid = br->getCentroid().coords;
00241
00242 fmat::Column<3> extents = br->getTFR().coords - centroid;
00243
00244 fmat::Matrix<3,3> o;
00245 o.column(0) = (br->getTFR() - br->getTFL()).coords; o.column(0) /= o.column(0).norm();
00246 o.column(1) = (br->getTFR() - br->getTBR()).coords; o.column(1) /= o.column(1).norm();
00247 o.column(2) = (br->getTFR() - br->getGFR()).coords; o.column(2) /= o.column(2).norm();
00248 BoxObstacle *box = new BoxObstacle(centroid, o.transpose() * extents, o);
00249 std::ostringstream nameStream;
00250 nameStream << br->getName() << "-" << br->getId();
00251 box->name = nameStream.str();
00252 box->shapeId = br->getId();
00253 obstacles.push_back(box);
00254 } break;
00255
00256 default:
00257 std::cout << std::endl << std::endl
00258 <<"Planner error: conversion of '" << shape->getName() << "' "
00259 << " to PlannerObstacle3D not yet implemented." << std::endl << std::endl;
00260 }
00261 }