Developer Documentation

PropertyVisualizer.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43
44 #ifndef PROPERTY_VISUALIZER_HH
45 #define PROPERTY_VISUALIZER_HH
46
47 #include "Utils.hh"
48
49 #include <OpenFlipper/BasePlugin/BaseInterface.hh>
50 #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
51 #include <ACG/QtWidgets/QtHistogramWidget.hh>
52 #include <ACG/Utils/IColorCoder.hh>
53 #include <ACG/Utils/SmartPointer.hh>
54
55 #include "OpenMesh/Core/Geometry/VectorT.hh"
56
57 #ifdef ENABLE_SKELETON_SUPPORT
58 #include <ObjectTypes/Skeleton/BaseSkin.hh>
59 #endif
60
61 #include <stdexcept>
62
63 class VizException : public std::logic_error {
64 public:
65 explicit VizException(const std::string &msg) : std::logic_error(msg) {}
66 };
67
68
77 class PropertyVisualizer: public QObject
78 {
79 Q_OBJECT
80
81 signals:
82 void log(Logtype _type, QString _message);
83 void log(QString _message);
84
85 public:
91 explicit PropertyVisualizer(const PropertyInfo& _propertyInfo)
92 :
93 propertyInfo(_propertyInfo),
94 widget(0)
95 {
96 }
97
99 virtual ~PropertyVisualizer(){delete widget; }
100
102 virtual void visualize(bool _setDrawMode, QWidget* _widget);
103
105 virtual void removeProperty();
106
108 virtual void duplicateProperty();
109
111 virtual void clear();
112
119 virtual QString getName() { return propertyInfo.toString(); }
120
126 virtual QWidget* getWidget() { return widget; }
127
129 const PropertyInfo& getPropertyInfo() const { return propertyInfo; }
130
136 virtual QString getPropertyText(unsigned int i) = 0;
137
138
148 virtual void setPropertyFromText(unsigned int index, QString text) = 0;
149
151 virtual int getEntityCount() = 0;
152
154 virtual QString getHeader() = 0;
155
156 static inline QString toStr(bool b) { return b ? QObject::tr("True") : QObject::tr("False"); }
157 static inline QString toStr(double d) { return QObject::tr("%1").arg(d); }
158 static inline QString toStr(int i) { return QObject::tr("%1").arg(i); }
159 static inline QString toStr(uint8_t i) { return QObject::tr("%1").arg(i); }
160 static inline QString toStr(unsigned int i) { return QObject::tr("%1").arg(i); }
161 static QString toStr(OpenMesh::Vec3d v);
162 static QString toStr(OpenMesh::Vec2d v);
163 static QString toStr(OpenMesh::Vec2f v);
164 #ifdef ENABLE_SKELETON_SUPPORT
165 static QString toStr(BaseSkin::SkinWeights sw);
166 #endif
167
168 static inline bool strToBool (QString str) { return (str.compare(QObject::tr("True"))==0); }
169 static inline double strToDouble(QString str) { return str.toDouble() ; }
170 static inline int strToInt (QString str) { return str.toInt(); }
171 static inline unsigned int strToUInt (QString str) { return str.toUInt(); }
172 static OpenMesh::Vec3d strToVec3d (QString str);
173 static OpenMesh::Vec2d strToVec2d (QString str);
174 static OpenMesh::Vec2f strToVec2f (QString str);
175
176
177 protected:
178 virtual std::unique_ptr<ACG::IColorCoder> buildColorCoder();
179
180 template<typename PropType, typename Iterable>
181 void showHistogramT(ACG::QtWidgets::QtHistogramWidget *widget,
182 Iterable data);
183
184 PropertyInfo propertyInfo;
185
186 public:
187 QWidget* widget;
188 };
189
190 template<typename PropType, typename Iterable>
191 void PropertyVisualizer::showHistogramT(
192 ACG::QtWidgets::QtHistogramWidget *widget,
193 Iterable data)
194 {
195 const size_t max_bins = 50; // TODO: expose in GUI?
196 widget->setMinimumHeight(300);
197 widget->setColorCoder(buildColorCoder());
198 widget->setHistogram(ptr::make_unique<ACG::HistogramT<PropType>>(data.begin(), data.end(), max_bins));
199 }
200
201 #endif /* PROPERTY_VISUALIZER_HH */
PropertyVisualizer::~PropertyVisualizer
virtual ~PropertyVisualizer()
Destructor.
Definition: PropertyVisualizer.hh:99
ACG::QtWidgets::QtHistogramWidget
Definition: QtHistogramWidget.hh:57
Logtype
Logtype
Log types for Message Window.
Definition: LoggingInterface.hh:92
PropertyVisualizer::getPropertyInfo
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
Definition: PropertyVisualizer.hh:129
LoggingInterface.hh
PropertyVisualizer::getName
virtual QString getName()
Returns a beautiful name.
Definition: PropertyVisualizer.hh:119
BaseInterface.hh
ACG::HistogramT
Definition: Histogram.hh:85
BaseSkin::SkinWeights
std::map< unsigned int, double > SkinWeights
Stores the joint weights per vertex.
Definition: BaseSkin.hh:94
PropertyVisualizer
This class vizualizes a property.
Definition: PropertyVisualizer.hh:77
PropertyVisualizer::getWidget
virtual QWidget * getWidget()
Returns the visualizer&#39;s widget.
Definition: PropertyVisualizer.hh:126
OpenMesh::VectorT< double, 3 >
VizException
Definition: PropertyVisualizer.hh:63
PropertyVisualizer::PropertyVisualizer
PropertyVisualizer(const PropertyInfo &_propertyInfo)
Constructor.
Definition: PropertyVisualizer.hh:91
PropertyInfo
Cellection of information about a property.
Definition: Utils.hh:109