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 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT
169  static QString toStr(OpenVolumeMesh::Vec3d v);
170 #endif
171 
172  static inline bool strToBool (QString str) { return (str.compare(QObject::tr("True"))==0); }
173  static inline double strToDouble(QString str) { return str.toDouble() ; }
174  static inline int strToInt (QString str) { return str.toInt(); }
175  static inline unsigned int strToUInt (QString str) { return str.toUInt(); }
176  static OpenMesh::Vec3d strToVec3d (QString str);
177  static OpenMesh::Vec2d strToVec2d (QString str);
178  static OpenMesh::Vec2f strToVec2f (QString str);
179 
180  template <typename Vec3T> static Vec3T strToVec3 (QString str);
181 
182 protected:
183  virtual std::unique_ptr<ACG::IColorCoder> buildColorCoder();
184 
185  template<typename PropType, typename Iterable>
186  void showHistogramT(ACG::QtWidgets::QtHistogramWidget *widget,
187  Iterable data);
188 
189  PropertyInfo propertyInfo;
190 
191 public:
192  QWidget* widget;
193 };
194 
195 template<typename PropType, typename Iterable>
196 void PropertyVisualizer::showHistogramT(
198  Iterable data)
199 {
200  widget->setMinimumHeight(300);
201  widget->setColorCoder(buildColorCoder());
202  widget->setHistogram(ACG::create_histogram_auto(data));
203 }
204 
205 template <typename Vec3T>
206 Vec3T PropertyVisualizer::strToVec3 (QString str)
207 {
208  QString s = str;
209  s.remove(0,2);
210  s.truncate(s.lastIndexOf(")"));
211  QStringList strList = s.split(QObject::tr(", "));
212  return Vec3T(strList[0].toDouble(),strList[1].toDouble(),strList[2].toDouble());
213 }
214 
215 #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.