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 
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  static QString toStr(const ACG::Matrix3x3d &v);
165 #ifdef ENABLE_SKELETON_SUPPORT
166  static QString toStr(BaseSkin::SkinWeights sw);
167 #endif
168 
169  static inline bool strToBool (QString str) { return (str.compare(QObject::tr("True"))==0); }
170  static inline double strToDouble(QString str) { return str.toDouble() ; }
171  static inline int strToInt (QString str) { return str.toInt(); }
172  static inline unsigned int strToUInt (QString str) { return str.toUInt(); }
173  static OpenMesh::Vec3d strToVec3d (QString str);
174  static OpenMesh::Vec2d strToVec2d (QString str);
175  static OpenMesh::Vec2f strToVec2f (QString str);
176 
177 
178 protected:
179  virtual std::unique_ptr<ACG::IColorCoder> buildColorCoder();
180 
181  template<typename PropType, typename Iterable>
182  void showHistogramT(ACG::QtWidgets::QtHistogramWidget *widget,
183  Iterable data);
184 
185  PropertyInfo propertyInfo;
186 
187 public:
188  QWidget* widget;
189 };
190 
191 template<typename PropType, typename Iterable>
192 void PropertyVisualizer::showHistogramT(
194  Iterable data)
195 {
196  const size_t max_bins = 50; // TODO: expose in GUI?
197  widget->setMinimumHeight(300);
198  widget->setColorCoder(buildColorCoder());
199  widget->setHistogram(ptr::make_unique<ACG::HistogramT<PropType>>(data.begin(), data.end(), max_bins));
200 }
201 
202 #endif /* PROPERTY_VISUALIZER_HH */
PropertyVisualizer(const PropertyInfo &_propertyInfo)
Constructor.
virtual QWidget * getWidget()
Returns the visualizer&#39;s widget.
virtual ~PropertyVisualizer()
Destructor.
Logtype
Log types for Message Window.
std::map< unsigned int, double > SkinWeights
Stores the joint weights per vertex.
Definition: BaseSkin.hh:94
virtual QString getName()
Returns a beautiful name.
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
Cellection of information about a property.
Definition: Utils.hh:109
This class vizualizes a property.