openmbvcppinterface  3.1.0
OpenMBV C++ Interface
ivscreenannotation.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_IVSCREENANNOTATION_H_
21#define _OPENMBV_IVSCREENANNOTATION_H_
22
23#include "body.h"
24#include <hdf5serie/vectorserie.h>
25
26namespace OpenMBV {
27
61 class IvScreenAnnotation : public Body {
62 friend class ObjectFactory;
63 public:
64 void initializeUsingXML(xercesc::DOMElement *element) override;
65 xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent) override;
66 void setScale1To1(bool scale1To1_);
67 bool getScale1To1();
68
77 void setScale1To1At(const std::vector<double> &scale1To1Center_);
78
79 std::vector<double> getScale1To1At();
80
82 void setIvFileName(std::string ivFileName_) { ivContent=""; ivFileName=std::move(ivFileName_); }
83 std::string getIvFileName() { return ivFileName; }
84
85 void setIvContent(std::string ivContent_) { ivFileName=""; ivContent=std::move(ivContent_); }
86 const std::string& getIvContent() { return ivContent; }
87
88 void setColumnLabels(const std::vector<std::string> &columnLabels_);
89 void addColumnLabel(const std::string &columnLabel_);
90 const std::vector<std::string>& getColumnLabels() const;
91 void setColumnIntLabels(const std::vector<std::string> &columnIntLabels_);
92 void addColumnIntLabel(const std::string &columnIntLabel_);
93 const std::vector<std::string>& getColumnIntLabels() const;
94 void setColumnStrLabels(const std::vector<std::string> &columnStrLabels_);
95 void addColumnStrLabel(const std::string &columnStrLabel_);
96 const std::vector<std::string>& getColumnStrLabels() const;
97 void setFixedStrSize(int fss) { fixedStrSize = fss; }
98 int getFixedStrSize() { return fixedStrSize; }
99
100 void createHDF5File() override;
101 void openHDF5File() override;
102
103 template<typename T>
104 void append(const T& row) {
105 if(data==nullptr) throw std::runtime_error("IvScreenAnnotation: Cannot append data to an environment object");
106 if(row.size()!=1+columnLabels.size()) throw std::runtime_error("IvScreenAnnotation: The dimension does not match (append: "+
107 std::to_string(row.size())+", columns: "+std::to_string(1+columnLabels.size())+")");
108 data->append(&row[0], row.size());
109 }
110
111 template<typename T>
112 void appendInt(const T& row) {
113 if(dataInt==nullptr) throw std::runtime_error("IvScreenAnnotation: Cannot append dataInt to an environment object");
114 if(row.size()!=columnIntLabels.size()) throw std::runtime_error("IvScreenAnnotation: The dimension does not match (appendInt: "+
115 std::to_string(row.size())+", columns: "+std::to_string(columnIntLabels.size())+")");
116 dataInt->append(&row[0], row.size());
117 }
118
119 template<typename T>
120 void appendStr(const T& row) {
121 if(dataStr==nullptr) throw std::runtime_error("IvScreenAnnotation: Cannot append dataStr to an environment object");
122 if(row.size()!=columnStrLabels.size()) throw std::runtime_error("IvScreenAnnotation: The dimension does not match (append: "+
123 std::to_string(row.size())+", columns: "+std::to_string(columnStrLabels.size())+")");
124 dataStr->append(&row[0], row.size());
125 }
126
127 int getRows() override { return data?data->getRows():0; }
128 std::vector<Float> getRow(int i) override {
129 if(!data)
130 return std::vector<Float>(1+columnLabels.size());
131
132 auto row = data->getRow(i);
133
134 // handle legacy data (no "time" column as first column)
135 if(columnLabels.size() == row.size()) {
136 std::vector<Float> ret(1+row.size());
137 ret[0] = 0; // use 0 for time column
138 for(size_t i = 0; i < row.size(); ++i)
139 ret[i+1] = row[i];
140 return ret;
141 }
142
143 return row;
144 }
145
146 std::vector<int> getRowInt(int i) {
147 if(!dataInt)
148 return std::vector<int>(columnIntLabels.size());
149 return dataInt->getRow(i);
150 }
151
152 std::vector<std::string> getRowStr(int i) {
153 if(!dataStr)
154 return std::vector<std::string>(columnStrLabels.size());
155 return dataStr->getRow(i);
156 }
157 protected:
158 IvScreenAnnotation();
159 ~IvScreenAnnotation() override = default;
160 bool scale1To1 { false };
161 std::vector<double> scale1To1Center;
162 std::string ivFileName;
163 std::string ivContent;
164 int fixedStrSize { -1 };
165 std::vector<std::string> columnLabels;
166 std::vector<std::string> columnIntLabels;
167 std::vector<std::string> columnStrLabels;
168 H5::VectorSerie<Float>* data{nullptr};
169 H5::VectorSerie<int>* dataInt{nullptr};
170 H5::VectorSerie<std::string>* dataStr{nullptr};
171 };
172
173}
174
175#endif
void getRow(int row, size_t size, T data[])
void append(const T data[], size_t size)
Definition: body.h:32
Definition: ivscreenannotation.h:61
void setScale1To1At(const std::vector< double > &scale1To1Center_)
Definition: ivscreenannotation.cc:122
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: ivscreenannotation.cc:60
void setIvFileName(std::string ivFileName_)
Definition: ivscreenannotation.h:82
int getRows() override
Definition: ivscreenannotation.h:127
std::vector< Float > getRow(int i) override
Definition: ivscreenannotation.h:128
Definition: objectfactory.h:38