00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef POLYGONPOINT_H
00021 #define POLYGONPOINT_H
00022
00023 #include <vector>
00024 #include <fstream>
00025 #include <iostream>
00026 #include <mbxmlutilstinyxml/tinyxml.h>
00027 #include "openmbvcppinterface/body.h"
00028 #include <stdexcept>
00029
00030 namespace OpenMBV {
00031
00038 class PolygonPoint {
00039 public:
00041 PolygonPoint(double x_, double y_, int b_) : x(x_), y(y_), b(b_) {}
00042
00043
00044 double getXComponent() { return x; }
00045 double getYComponent() { return y; }
00046 int getBorderValue() { return b; }
00047
00048
00049
00051 static void serializePolygonPointContour(MBXMLUtils::TiXmlElement *parent, const std::vector<PolygonPoint*> *cont) {
00052 std::string str;
00053 str="[ ";
00054 for(std::vector<PolygonPoint*>::const_iterator j=cont->begin(); j!=cont->end(); j++) {
00055 str+=Object::numtostr((*j)->getXComponent())+", "+Object::numtostr((*j)->getYComponent())+", "+Object::numtostr((*j)->getBorderValue());
00056 if(j+1!=cont->end()) str+="; "; else str+=" ]";
00057 }
00058 Object::addElementText(parent, OPENMBVNS"contour", str);
00059 }
00060
00061 static std::vector<PolygonPoint*>* initializeUsingXML(MBXMLUtils::TiXmlElement *element) {
00062 MatrixParameter matParam=Body::getMat(element);
00063 if(matParam.getParamStr()!="") throw std::runtime_error("only numeric values are allowd for contours (vector<PolygonPoint*>)");
00064 std::vector<std::vector<double> > mat=matParam.getValue();
00065 std::vector<PolygonPoint*> *contour=new std::vector<PolygonPoint*>;
00066 for(size_t r=0; r<mat.size(); r++) {
00067 PolygonPoint *pp=new PolygonPoint(mat[r][0], mat[r][1], (int)(mat[r][2]));
00068 contour->push_back(pp);
00069 }
00070 return contour;
00071 }
00072
00073 private:
00074 double x, y;
00075 int b;
00076 };
00077
00078 }
00079
00080 #endif
00081