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     public:
00040       enum Type {
00041         line,
00042         fromHead,
00043         toHead,
00044         bothHeads,
00045         fromDoubleHead,
00046         toDoubleHead,
00047         bothDoubleHeads
00048       };
00049       enum ReferencePoint {
00050         toPoint,
00051         fromPoint,
00052         midPoint
00053       };
00054     protected:
00055       std::string pathStr;
00056       void createHDF5File();
00057       void openHDF5File();
00058       H5::VectorSerie<double>* data;
00059       double headDiameter, headLength, diameter, scaleLength;
00060       Type type;
00061       ReferencePoint referencePoint;
00062 
00064       virtual ~Arrow();
00065     public:
00067       Arrow();
00068 
00070       std::string getClassName() { return "Arrow"; }
00071 
00073       void setPath(bool p) { pathStr=(p==true)?"true":"false"; }
00074 
00075       bool getPath() { return pathStr=="true"?true:false; }
00076       
00078       void append(const std::vector<double>& row) {
00079         if(data==0) throw std::runtime_error("can not append data to an environment object");
00080         if(row.size()!=8) throw std::runtime_error("the dimension does not match");
00081         if(!std::isnan(dynamicColor))
00082         {
00083           std::vector<double> tmprow(row);
00084           tmprow[7]=dynamicColor;
00085           data->append(tmprow);
00086         }
00087         else
00088           data->append(row);
00089       }
00090 
00091       int getRows() { return data?data->getRows():-1; }
00092       std::vector<double> getRow(int i) { return data?data->getRow(i):std::vector<double>(8); }
00093 
00095       void setArrowHead(double diameter, double length) {
00096         headDiameter=diameter;
00097         headLength=length;
00098       }
00099 
00101       void setHeadDiameter(double diameter) {
00102         headDiameter=diameter;
00103       }
00104 
00105       double getHeadDiameter() { return headDiameter; }
00106 
00108       void setHeadLength(double length) {
00109         headLength=length;
00110       }
00111 
00112       double getHeadLength() { return headLength; }
00113 
00115       void setDiameter(double diameter_) {
00116         diameter=diameter_;
00117       }
00118 
00119       double getDiameter() { return diameter; }
00120       
00130       void setType(Type type_) {
00131         type=type_;
00132       }
00133       
00134       Type getType() { return type; }
00135       
00142       void setReferencePoint(ReferencePoint referencePoint_) {
00143         referencePoint=referencePoint_;
00144       }
00145       
00146       ReferencePoint getReferencePoint() { return referencePoint; }
00147 
00149       void setScaleLength(double scale) {
00150         scaleLength=scale;
00151       }
00152 
00153       double getScaleLength() { return scaleLength; }
00154 
00156       virtual void initializeUsingXML(xercesc::DOMElement *element);
00157 
00158       xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent);
00159   };
00160 
00161 }
00162 
00163 #endif