openmbvcppinterface  3.1.0
OpenMBV C++ Interface
arrow.h
1/*
2 OpenMBV - Open Multi Body Viewer.
3 Copyright (C) 2009 Markus Friedrich
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#ifndef _OPENMBV_ARROW_H_
21#define _OPENMBV_ARROW_H_
22
23#include <openmbvcppinterface/dynamiccoloredbody.h>
24#include <hdf5serie/vectorserie.h>
25#include <stdexcept>
26
27namespace OpenMBV {
28
37 class Arrow : public DynamicColoredBody {
38 friend class ObjectFactory;
39 public:
40 enum Type {
41 line,
42 fromHead,
43 toHead,
44 bothHeads,
45 fromDoubleHead,
46 toDoubleHead,
47 bothDoubleHeads
48 };
49 enum ReferencePoint {
50 toPoint,
51 fromPoint,
52 midPoint
53 };
54 protected:
55 std::string pathStr;
56 void createHDF5File() override;
57 void openHDF5File() override;
58 H5::VectorSerie<double>* data{nullptr};
59 double headDiameter{0.5};
60 double headLength{0.75};
61 double diameter{0.25};
62 double scaleLength{1};
63 Type type{toHead};
64 ReferencePoint referencePoint{toPoint};
65
66 Arrow();
67 ~Arrow() override;
68 public:
70 void setPath(bool p) { pathStr=(p)?"true":"false"; }
71
72 bool getPath() { return pathStr=="true"?true:false; }
73
75 template<typename T>
76 void append(const T& row) {
77 if(data==nullptr) throw std::runtime_error("can not append data to an environment object");
78 if(row.size()!=8) throw std::runtime_error("the dimension does not match");
79 if(!std::isnan(dynamicColor))
80 {
81 std::vector<double> tmprow(8);
82 std::copy(&row[0], &row[8], tmprow.begin());
83 tmprow[7]=dynamicColor;
84 data->append(tmprow);
85 }
86 else
87 data->append(row);
88 }
89
90 int getRows() override { return data?data->getRows():0; }
91 std::vector<double> getRow(int i) override { return data?data->getRow(i):std::vector<double>(8); }
92
94 void setArrowHead(double diameter, double length) {
95 headDiameter=diameter;
96 headLength=length;
97 }
98
100 void setHeadDiameter(double diameter) {
101 headDiameter=diameter;
102 }
103
104 double getHeadDiameter() { return headDiameter; }
105
107 void setHeadLength(double length) {
108 headLength=length;
109 }
110
111 double getHeadLength() { return headLength; }
112
114 void setDiameter(double diameter_) {
115 diameter=diameter_;
116 }
117
118 double getDiameter() { return diameter; }
119
129 void setType(Type type_) {
130 type=type_;
131 }
132
133 Type getType() { return type; }
134
141 void setReferencePoint(ReferencePoint referencePoint_) {
142 referencePoint=referencePoint_;
143 }
144
145 ReferencePoint getReferencePoint() { return referencePoint; }
146
148 void setScaleLength(double scale) {
149 scaleLength=scale;
150 }
151
152 double getScaleLength() { return scaleLength; }
153
155 void initializeUsingXML(xercesc::DOMElement *element) override;
156
157 xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent) override;
158 };
159
160}
161
162#endif
void getRow(int row, size_t size, T data[])
void append(const T data[], size_t size)
Definition: arrow.h:37
void setType(Type type_)
Definition: arrow.h:129
void setHeadDiameter(double diameter)
Definition: arrow.h:100
void setHeadLength(double length)
Definition: arrow.h:107
void setDiameter(double diameter_)
Definition: arrow.h:114
int getRows() override
Definition: arrow.h:90
std::vector< double > getRow(int i) override
Definition: arrow.h:91
void setPath(bool p)
Definition: arrow.h:70
void append(const T &row)
Definition: arrow.h:76
void setArrowHead(double diameter, double length)
Definition: arrow.h:94
void setScaleLength(double scale)
Definition: arrow.h:148
void setReferencePoint(ReferencePoint referencePoint_)
Definition: arrow.h:141
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: arrow.cc:94
Definition: dynamiccoloredbody.h:28
Definition: objectfactory.h:38