Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef PROPERTY_VISUALIZER_HH
51 #define PROPERTY_VISUALIZER_HH
52 
53 #include "Utils.hh"
54 
57 #include <ACG/QtWidgets/QtHistogramWidget.hh>
58 #include <ACG/Utils/IColorCoder.hh>
59 #include <ACG/Utils/SmartPointer.hh>
60 
61 #include "OpenMesh/Core/Geometry/VectorT.hh"
62 
63 #ifdef ENABLE_SKELETON_SUPPORT
64  #include <ObjectTypes/Skeleton/BaseSkin.hh>
65 #endif
66 
67 #include <stdexcept>
68 
69 class VizException : public std::logic_error {
70  public:
71  VizException(const std::string &msg) : std::logic_error(msg) {}
72 };
73 
74 
83 class PropertyVisualizer: public QObject
84 {
85  Q_OBJECT
86 
87 signals:
88  void log(Logtype _type, QString _message);
89  void log(QString _message);
90 
91 public:
98  :
99  propertyInfo(_propertyInfo),
100  widget(0)
101  {
102  }
103 
105  virtual ~PropertyVisualizer(){delete widget; }
106 
108  virtual void visualize(bool _setDrawMode, QWidget* _widget);
109 
111  virtual void removeProperty();
112 
114  virtual void duplicateProperty();
115 
117  virtual void clear();
118 
125  virtual QString getName() { return propertyInfo.toString(); }
126 
132  virtual QWidget* getWidget() { return widget; }
133 
135  const PropertyInfo& getPropertyInfo() const { return propertyInfo; }
136 
142  virtual QString getPropertyText(unsigned int i) = 0;
143 
144 
154  virtual void setPropertyFromText(unsigned int index, QString text) = 0;
155 
157  virtual int getEntityCount() = 0;
158 
160  virtual QString getHeader() = 0;
161 
162  static inline QString toStr(bool b) { return b ? QObject::tr("True") : QObject::tr("False"); }
163  static inline QString toStr(double d) { return QObject::tr("%1").arg(d); }
164  static inline QString toStr(int i) { return QObject::tr("%1").arg(i); }
165  static inline QString toStr(uint8_t i) { return QObject::tr("%1").arg(i); }
166  static inline QString toStr(unsigned int i) { return QObject::tr("%1").arg(i); }
167  static QString toStr(OpenMesh::Vec3d v);
168  static QString toStr(OpenMesh::Vec2d v);
169  static QString toStr(OpenMesh::Vec2f v);
170 #ifdef ENABLE_SKELETON_SUPPORT
171  static QString toStr(BaseSkin::SkinWeights sw);
172 #endif
173 
174  static inline bool strToBool (QString str) { return (str.compare(QObject::tr("True"))==0); }
175  static inline double strToDouble(QString str) { return str.toDouble() ; }
176  static inline int strToInt (QString str) { return str.toInt(); }
177  static inline unsigned int strToUInt (QString str) { return str.toUInt(); }
178  static OpenMesh::Vec3d strToVec3d (QString str);
179  static OpenMesh::Vec2d strToVec2d (QString str);
180  static OpenMesh::Vec2f strToVec2f (QString str);
181 
182 
183 protected:
184  virtual std::unique_ptr<ACG::IColorCoder> buildColorCoder();
185 
186  template<typename PropType, typename Iterable>
187  void showHistogramT(ACG::QtWidgets::QtHistogramWidget *widget,
188  Iterable data);
189 
190  PropertyInfo propertyInfo;
191 
192 public:
193  QWidget* widget;
194 };
195 
196 template<typename PropType, typename Iterable>
197 void PropertyVisualizer::showHistogramT(
199  Iterable data)
200 {
201  const size_t max_bins = 50; // TODO: expose in GUI?
202  widget->setMinimumHeight(300);
203  widget->setColorCoder(buildColorCoder());
204  widget->setHistogram(ptr::make_unique<ACG::HistogramT<PropType>>(data.begin(), data.end(), max_bins));
205 }
206 
207 #endif /* PROPERTY_VISUALIZER_HH */
virtual void clear()
Clears the property visualization.
virtual void removeProperty()
Removes the property.
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
virtual QString getName()
Returns a beautiful name.
virtual int getEntityCount()=0
Returns the number of entities.
virtual void setPropertyFromText(unsigned int index, QString text)=0
Returns the value of a property in text form.
Logtype
Log types for Message Window.
virtual QWidget * getWidget()
Returns the visualizer's widget.
virtual QString getHeader()=0
Returns the header for saving.
virtual QString getPropertyText(unsigned int i)=0
Returns the value of a property in text form.
virtual void duplicateProperty()
Duplicates the property.
This class vizualizes a property.
PropertyVisualizer(PropertyInfo _propertyInfo)
Constructor.
virtual ~PropertyVisualizer()
Destructor.
std::map< unsigned int, double > SkinWeights
Stores the joint weights per vertex.
Definition: BaseSkin.hh:99
virtual void visualize(bool _setDrawMode, QWidget *_widget)
Visualizes the property.
Cellection of information about a property.
Definition: Utils.hh:115