Hosted by: BerliOS Developer Logo

OpenMBV C++ Interface

BerliOS Project Page
/home/user/MBSimWindows/openmbv/openmbvcppinterface/openmbvcppinterface/arrow.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_ARROW_H_
00021 #define _OPENMBV_ARROW_H_
00022 
00023 #include <openmbvcppinterface/dynamiccoloredbody.h>
00024 #include <hdf5serie/vectorserie.h>
00025 #include <cmath>
00026 #include <stdexcept>
00027 
00028 namespace OpenMBV {
00029 
00038   class Arrow : public DynamicColoredBody {
00039     friend class ObjectFactory;
00040     public:
00041       enum Type {
00042         line,
00043         fromHead,
00044         toHead,
00045         bothHeads,
00046         fromDoubleHead,
00047         toDoubleHead,
00048         bothDoubleHeads
00049       };
00050       enum ReferencePoint {
00051         toPoint,
00052         fromPoint,
00053         midPoint
00054       };
00055     protected:
00056       std::string pathStr;
00057       void createHDF5File();
00058       void openHDF5File();
00059       H5::VectorSerie<double>* data;
00060       double headDiameter, headLength, diameter, scaleLength;
00061       Type type;
00062       ReferencePoint referencePoint;
00063 
00064       Arrow();
00065       virtual ~Arrow();
00066     public:
00068       std::string getClassName() { return "Arrow"; }
00069 
00071       void setPath(bool p) { pathStr=(p==true)?"true":"false"; }
00072 
00073       bool getPath() { return pathStr=="true"?true:false; }
00074       
00076       void append(const std::vector<double>& row) {
00077         if(data==0) throw std::runtime_error("can not append data to an environment object");
00078         if(row.size()!=8) throw std::runtime_error("the dimension does not match");
00079         if(!std::isnan(dynamicColor))
00080         {
00081           std::vector<double> tmprow(row);
00082           tmprow[7]=dynamicColor;
00083           data->append(tmprow);
00084         }
00085         else
00086           data->append(row);
00087       }
00088 
00089       int getRows() { return data?data->getRows():-1; }
00090       std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
00091 
00093       void setArrowHead(double diameter, double length) {
00094         headDiameter=diameter;
00095         headLength=length;
00096       }
00097 
00099       void setHeadDiameter(double diameter) {
00100         headDiameter=diameter;
00101       }
00102 
00103       double getHeadDiameter() { return headDiameter; }
00104 
00106       void setHeadLength(double length) {
00107         headLength=length;
00108       }
00109 
00110       double getHeadLength() { return headLength; }
00111 
00113       void setDiameter(double diameter_) {
00114         diameter=diameter_;
00115       }
00116 
00117       double getDiameter() { return diameter; }
00118       
00128       void setType(Type type_) {
00129         type=type_;
00130       }
00131       
00132       Type getType() { return type; }
00133       
00140       void setReferencePoint(ReferencePoint referencePoint_) {
00141         referencePoint=referencePoint_;
00142       }
00143       
00144       ReferencePoint getReferencePoint() { return referencePoint; }
00145 
00147       void setScaleLength(double scale) {
00148         scaleLength=scale;
00149       }
00150 
00151       double getScaleLength() { return scaleLength; }
00152 
00154       virtual void initializeUsingXML(xercesc::DOMElement *element);
00155 
00156       xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent);
00157   };
00158 
00159 }
00160 
00161 #endif