28 #ifndef LIGHTWEIGHT_GEOM_DATA_H
29 #define LIGHTWEIGHT_GEOM_DATA_H
47 namespace utils {
class CStream; }
52 using namespace mrpt::utils;
100 template <
class DERIVEDCLASS>
111 inline TPoint2D(
double xx,
double yy):x(xx),y(yy) {}
191 void fromString(
const std::string &s);
192 static size_t size() {
return 2; }
235 inline TPose2D(
double xx,
double yy,
double pphi):x(xx),y(yy),phi(pphi) {}
257 v[0]=x; v[1]=y; v[2]=phi;
269 void fromString(
const std::string &s);
270 static size_t size() {
return 3; }
283 inline TPoint3Df(
const float xx,
const float yy,
const float zz) : x(xx), y(yy),z(zz) { }
298 inline TPoint3D(
double xx,
double yy,
double zz):x(xx),y(yy),z(zz) {}
370 v[0]=x; v[1]=y; v[2]=z;
423 void fromString(
const std::string &s);
424 static size_t size() {
return 3; }
479 TPose3D(
double _x,
double _y,
double _z,
double _yaw,
double _pitch,
double _roll):x(_x),y(_y),z(_z),yaw(_yaw),pitch(_pitch),roll(_roll) {}
507 v[0]=x; v[1]=y; v[2]=z; v[3]=yaw; v[4]=pitch; v[5]=roll;
519 void fromString(
const std::string &s);
520 static size_t size() {
return 6; }
536 inline TPose3DQuat(
double _x,
double _y,
double _z,
double _qr,
double _qx,
double _qy,
double _qz):x(_x),y(_y),z(_z),qr(_qr),qx(_qx),qy(_qy),qz(_qz) { }
557 for (
size_t i=0;i<7;i++) v[i]=(*
this)[i];
569 void fromString(
const std::string &s);
570 static size_t size() {
return 7; }
592 return (p1.
x==p2.
x)&&(p1.
y==p2.
y);
598 return (p1.
x!=p2.
x)||(p1.
y!=p2.
y);
604 return (p1.
x==p2.
x)&&(p1.
y==p2.
y)&&(p1.
z==p2.
z);
610 return (p1.
x!=p2.
x)||(p1.
y!=p2.
y)||(p1.
z!=p2.
z);
661 double length()
const;
669 double signedDistance(
const TPoint2D &point)
const;
673 bool contains(
const TPoint2D &point)
const;
694 p.
x=(point1.x+point2.x)/2;
695 p.
y=(point1.y+point2.y)/2;
729 double length()
const;
737 bool contains(
const TPoint3D &point)
const;
760 p.
x=(point1.x+point2.x)/2;
761 p.
y=(point1.y+point2.y)/2;
762 p.
z=(point1.z+point2.z)/2;
810 double evaluatePoint(
const TPoint2D &point)
const;
814 bool contains(
const TPoint2D &point)
const;
822 double signedDistance(
const TPoint2D &point)
const;
826 void getNormalVector(
double (&vector)[2])
const;
836 getNormalVector(vector);
841 void getDirectorVector(
double (&vector)[2])
const;
847 getDirectorVector(vector);
852 void generate3DObject(
TLine3D &l)
const;
909 bool contains(
const TPoint3D &point)
const;
922 for (
size_t i=0;i<3;i++) vector[i]=director[i];
929 getDirectorVector(vector);
970 double evaluatePoint(
const TPoint3D &point)
const;
974 bool contains(
const TPoint3D &point)
const;
979 return contains(segment.
point1)&&contains(segment.
point2);
984 bool contains(
const TLine3D &line)
const;
996 void getNormalVector(
double (&vec)[3])
const;
1006 getNormalVector(vec);
1054 inline TPlane(
double A,
double B,
double C,
double D) {
1064 for (
size_t i=0;i<4;i++) coefs[i]=vec[i];
1083 bool contains(
const TPoint2D &point)
const;
1087 void getAsSegmentList(std::vector<TSegment2D> &v)
const;
1099 bool isConvex()
const;
1104 void removeRepeatedVertices();
1109 void removeRedundantVertices();
1114 void getPlotData(std::vector<double> &x,std::vector<double> &y)
const;
1135 static void createRegularPolygon(
size_t numEdges,
double radius,
TPolygon2D &poly);
1156 bool contains(
const TPoint3D &point)
const;
1160 void getAsSegmentList(std::vector<TSegment3D> &v)
const;
1164 bool getPlane(
TPlane &p)
const;
1169 void getBestFittingPlane(
TPlane &p)
const;
1185 bool isSkew()
const;
1189 void removeRepeatedVertices();
1193 void removeRedundantVertices();
1214 static void createRegularPolygon(
size_t numEdges,
double radius,
TPolygon3D &poly);
1257 #ifdef TOBJECTS_USE_UNIONS
1282 delete data.segment;
1288 delete data.polygon;
1331 inline bool isPoint()
const {
1337 inline bool isSegment()
const {
1343 inline bool isLine()
const {
1349 inline bool isPolygon()
const {
1355 inline unsigned char getType()
const {
1361 inline bool getPoint(
TPoint2D &p)
const {
1365 }
else return false;
1370 inline bool getSegment(
TSegment2D &s)
const {
1374 }
else return false;
1379 inline bool getLine(
TLine2D &r)
const {
1383 }
else return false;
1388 inline bool getPolygon(
TPolygon2D &p)
const {
1392 }
else return false;
1398 if (
this==&obj)
return;
1400 switch (type=obj.
type) {
1418 inline void operator=(
const TPoint2D &p) {
1434 inline void operator=(
const TLine2D &l) {
1450 void generate3DObject(
TObject3D &obj)
const;
1460 static void getPoints(
const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts);
1464 static void getSegments(
const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms);
1468 static void getLines(
const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins);
1472 static void getPolygons(
const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys);
1476 static void getPoints(
const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts,std::vector<TObject2D> &remainder);
1480 static void getSegments(
const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms,std::vector<TObject2D> &remainder);
1484 static void getLines(
const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins,std::vector<TObject2D> &remainder);
1488 static void getPolygons(
const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys,std::vector<TObject2D> &remainder);
1519 delete data.segment;
1525 delete data.polygon;
1542 data.point=
new TPoint3D(p);
1566 data.plane=
new TPlane(p);
1581 inline bool isPoint()
const {
1587 inline bool isSegment()
const {
1593 inline bool isLine()
const {
1599 inline bool isPolygon()
const {
1605 inline bool isPlane()
const {
1611 inline unsigned char getType()
const {
1617 inline bool getPoint(TPoint3D &p)
const {
1621 }
else return false;
1626 inline bool getSegment(
TSegment3D &s)
const {
1630 }
else return false;
1635 inline bool getLine(
TLine3D &r)
const {
1639 }
else return false;
1644 inline bool getPolygon(
TPolygon3D &p)
const {
1648 }
else return false;
1653 inline bool getPlane(TPlane &p)
const {
1657 }
else return false;
1663 if (
this==&obj)
return;
1665 switch (type=obj.type) {
1667 data.point=
new TPoint3D(*(obj.data.point));
1670 data.segment=
new TSegment3D(*(obj.data.segment));
1673 data.line=
new TLine3D(*(obj.data.line));
1676 data.polygon=
new TPolygon3D(*(obj.data.polygon));
1679 data.plane=
new TPlane(*(obj.data.plane));
1690 inline void operator=(
const TPoint3D &p) {
1693 data.point=
new TPoint3D(p);
1706 inline void operator=(
const TLine3D &l) {
1722 inline void operator=(
const TPlane &p) {
1725 data.plane=
new TPlane(p);
1731 inline void generate2DObject(TObject2D &obj)
const {
1734 obj=TPoint2D(*(data.point));
1737 obj=TSegment2D(*(data.segment));
1740 obj=TLine2D(*(data.line));
1743 obj=TPolygon2D(*(data.polygon));
1746 throw std::logic_error(
"Too many dimensions");
1761 static void getPoints(
const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts);
1765 static void getSegments(
const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms);
1769 static void getLines(
const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins);
1773 static void getPlanes(
const std::vector<TObject3D> &objs,std::vector<TPlane> &plns);
1777 static void getPolygons(
const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys);
1781 static void getPoints(
const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts,std::vector<TObject3D> &remainder);
1785 static void getSegments(
const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms,std::vector<TObject3D> &remainder);
1789 static void getLines(
const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins,std::vector<TObject3D> &remainder);
1793 static void getPlanes(
const std::vector<TObject3D> &objs,std::vector<TPlane> &plns,std::vector<TObject3D> &remainder);
1797 static void getPolygons(
const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys,std::vector<TObject3D> &remainder);
1894 }
else return false;
1903 }
else return false;
1912 }
else return false;
1921 }
else return false;
1927 if (
this==&obj)
return;
1929 switch (type=obj.
type) {
1979 void generate3DObject(
TObject3D &obj)
const;
1989 static void getPoints(
const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts);
1993 static void getSegments(
const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms);
1997 static void getLines(
const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins);
2001 static void getPolygons(
const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys);
2005 static void getPoints(
const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts,std::vector<TObject2D> &remainder);
2009 static void getSegments(
const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms,std::vector<TObject2D> &remainder);
2013 static void getLines(
const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins,std::vector<TObject2D> &remainder);
2017 static void getPolygons(
const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys,std::vector<TObject2D> &remainder);
2130 }
else return false;
2139 }
else return false;
2148 }
else return false;
2157 }
else return false;
2166 }
else return false;
2172 if (
this==&obj)
return;
2174 switch (type=obj.
type) {
2255 throw std::logic_error(
"Too many dimensions");
2270 static void getPoints(
const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts);
2274 static void getSegments(
const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms);
2278 static void getLines(
const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins);
2282 static void getPlanes(
const std::vector<TObject3D> &objs,std::vector<TPlane> &plns);
2286 static void getPolygons(
const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys);
2290 static void getPoints(
const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts,std::vector<TObject3D> &remainder);
2294 static void getSegments(
const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms,std::vector<TObject3D> &remainder);
2298 static void getLines(
const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins,std::vector<TObject3D> &remainder);
2302 static void getPlanes(
const std::vector<TObject3D> &objs,std::vector<TPlane> &plns,std::vector<TObject3D> &remainder);
2306 static void getPolygons(
const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys,std::vector<TObject3D> &remainder);
2439 using namespace ::mrpt::math;