Hosted by: BerliOS Developer Logo

OpenMBV C++ Interface

BerliOS Project Page
/home/user/MBSimWindows/openmbv/openmbvcppinterface/openmbvcppinterface/path.h
00001 /*
00002     OpenMBV - Open Multi Body Viewer.
00003     Copyright (C) 2009 Markus Friedrich
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #ifndef _OPENMBV_PATH_H_
00021 #define _OPENMBV_PATH_H_
00022 
00023 #include <openmbvcppinterface/body.h>
00024 #include <openmbvcppinterface/simpleparameter.h>
00025 #include <hdf5serie/vectorserie.h>
00026 #include <vector>
00027 #include <stdexcept>
00028 
00029 namespace OpenMBV {
00030 
00037   class Path : public Body {
00038     protected:
00039       void createHDF5File();
00040       void openHDF5File();
00041       H5::VectorSerie<double>* data;
00042       VectorParameter color;
00043       
00045       virtual ~Path();
00046     public:
00048       Path();
00049 
00051       std::string getClassName() { return "Path"; }
00052 
00054       void append(const std::vector<double>& row) {
00055         if(data==0) throw std::runtime_error("can not append data to an environment object");
00056         if(row.size()!=4) throw std::runtime_error("the dimension does not match");
00057         data->append(row);
00058       }
00059 
00060       int getRows() { return data?data->getRows():-1; }
00061       std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(4); }
00062 
00064       void setColor(const VectorParameter& hsv) {
00065         if(hsv.getParamStr()=="" && hsv.getValue().size()!=3) throw std::runtime_error("the dimension does not match");
00066         set(color,hsv);
00067       }
00068 
00070       void setColor(const std::vector<double>& hsv) {
00071         if(hsv.size()!=3) throw std::runtime_error("the dimension does not match");
00072         set(color,hsv);
00073       }
00074 
00075       std::vector<double> getColor() { return get(color); }
00076 
00078       void setColor(double h, double s, double v) {
00079         std::vector<double> hsv;
00080         hsv.push_back(h);
00081         hsv.push_back(s);
00082         hsv.push_back(v);
00083         color=hsv;
00084       }
00085 
00087       virtual void initializeUsingXML(MBXMLUtils::TiXmlElement *element);
00088 
00089       MBXMLUtils::TiXmlElement* writeXMLFile(MBXMLUtils::TiXmlNode *parent);
00090   };
00091 
00092 }
00093 
00094 #endif