OVMPropertyVisualizer.hh 11.5 KB
Newer Older
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
39 40 41
*                                                                            *
\*===========================================================================*/

42 43 44 45 46 47 48 49
/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/

50 51 52 53 54 55 56 57 58 59 60
#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT

#ifndef OVM_PROPERTY_VISUALIZER_HH
#define OVM_PROPERTY_VISUALIZER_HH

#include "../PropertyVisualizer.hh"

#include <ObjectTypes/VolumeMeshObject/VolumeMeshObject.hh>

#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>

61 62
#include <ObjectTypes/VolumeMeshObject/VolumeMeshDrawModesContainer.hh>

63 64
#include <ACG/QtWidgets/QtHistogramWidget.hh>

65 66 67 68 69 70 71 72 73
#include <iostream>

template <typename MeshT>
class OVMPropertyVisualizer: public PropertyVisualizer{

public:
    OVMPropertyVisualizer(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo)
        : PropertyVisualizer(_propertyInfo),
          mesh(_mesh),
74 75
          mObjectID(objectID),
          drawModes()
76 77
    {}

78
    virtual ~OVMPropertyVisualizer(){ clear(); }
79 80

    /// Visualizes a property.
81
    virtual void visualize(bool _setDrawMode, QWidget* _widget);
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

    /**
     * @brief Should remove the property.
     *
     * Removing properties is not yet supported by OpenVolumeMesh. Therefor this method only informs the user of this fact via
     * a log message.
     */
    virtual void removeProperty(){ emit log("Removing properties not yet implemented for OpenVolumeMeshs."); }

    /// Duplicates a property.
    virtual void duplicateProperty(){ /*implemented by subclass*/}

    /// Clears a property.
    virtual void clear();

97
    virtual QString getPropertyText(unsigned int index)=0;
98 99 100 101

    /// Returns the ID of the closest primitive.
    unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint);

102 103 104 105
protected slots:
    template <typename Type>
    void showHistogram(ACG::QtWidgets::QtHistogramWidget *histogramWidget);

106 107 108
protected:
    MeshT* mesh;

109 110 111 112 113 114
    virtual void visualizeFaceProp(bool _setDrawMode = true);
    virtual void visualizeEdgeProp(bool _setDrawMode = true);
    virtual void visualizeHalfedgeProp(bool _setDrawMode = true);
    virtual void visualizeVertexProp(bool _setDrawMode = true);
    virtual void visualizeCellProp(bool _setDrawMode = true);
    virtual void visualizeHalffaceProp(bool _setDrawMode = true);
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

    template<typename PropType>
    void duplicateProperty_stage1();

    template <typename InnerType>
    QString getPropertyText_(unsigned int index);

    virtual void setCellPropertyFromText(unsigned int index, QString text);
    virtual void setFacePropertyFromText(unsigned int index, QString text);
    virtual void setHalffacePropertyFromText(unsigned int index, QString text);
    virtual void setEdgePropertyFromText(unsigned int index, QString text);
    virtual void setHalfedgePropertyFromText(unsigned int index, QString text);
    virtual void setVertexPropertyFromText(unsigned int index, QString text);

    virtual void setPropertyFromText(unsigned int index, QString text);

    virtual int getEntityCount();

    virtual QString getHeader();

    unsigned int getClosestCellId(unsigned int _face, ACG::Vec3d& _hitPoint);
    unsigned int getClosestFaceId(unsigned int _face, ACG::Vec3d& _hitPoint);
    unsigned int getClosestHalffaceId(unsigned int _face, ACG::Vec3d& _hitPoint);
    unsigned int getClosestEdgeId(unsigned int _face, ACG::Vec3d& _hitPoint);
    unsigned int getClosestHalfedgeId(unsigned int _face, ACG::Vec3d& _hitPoint);
    unsigned int getClosestVertexId(unsigned int _face, ACG::Vec3d& _hitPoint);

    int mObjectID;

144 145
    VolumeMeshDrawModesContainer drawModes;

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
private:

    template<typename Property>
    class CopyProperty
    {
        public:
            CopyProperty(Property& p1, const Property& p2, MeshT*& mesh) :
                p1(p1), p2(p2), mesh(mesh) {}

            template<typename PrimitiveHandleT>
            inline void operator() (const PrimitiveHandleT &pr) {
                p1[pr] = p2[pr];
            }

        private:
            Property &p1;
            const Property &p2;
            MeshT*& mesh;
    };
};

167
#define CALLS_TO_VISUALIZE_PROP(Classname, Template, PropType) \
168
template <Template> \
169
void Classname::visualizeCellProp(bool _setDrawMode) \
170
{\
171
    OpenVolumeMesh::CellPropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_cell_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
172
    visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->cells_begin(), OVMPropertyVisualizer<MeshT>::mesh->cells_end());\
173 174 175 176 177 178
    if (_setDrawMode)\
    {\
        VolumeMeshObject<MeshT>* object;\
        PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
        object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.cellsColoredPerCell);\
    }\
179 180
}\
template <Template>\
181
void Classname::visualizeFaceProp(bool _setDrawMode)\
182
{\
183
    OpenVolumeMesh::FacePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_face_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
184
    visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->faces_begin(), OVMPropertyVisualizer<MeshT>::mesh->faces_end());\
185 186 187 188 189 190
    if (_setDrawMode)\
    {\
        VolumeMeshObject<MeshT>* object;\
        PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
        object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.facesColoredPerFace);\
    }\
191 192
}\
template <Template>\
193
void Classname::visualizeHalffaceProp(bool _setDrawMode)\
194
{\
195
    OpenVolumeMesh::HalfFacePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfface_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
196
    visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->halffaces_begin(), OVMPropertyVisualizer<MeshT>::mesh->halffaces_end());\
197 198 199 200 201 202
    if (_setDrawMode)\
    {\
        VolumeMeshObject<MeshT>* object;\
        PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
        object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halffacesColoredPerHalfface);\
    }\
203 204
}\
template <Template>\
205
void Classname::visualizeEdgeProp(bool _setDrawMode)\
206
{\
207
    OpenVolumeMesh::EdgePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_edge_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
208
    visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->edges_begin(), OVMPropertyVisualizer<MeshT>::mesh->edges_end());\
209 210 211 212 213 214
    if (_setDrawMode)\
    {\
        VolumeMeshObject<MeshT>* object;\
        PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
        object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.edgesColoredPerEdge);\
    }\
215 216
}\
template <Template>\
217
void Classname::visualizeHalfedgeProp(bool _setDrawMode)\
218
{\
219
    OpenVolumeMesh::HalfEdgePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfedge_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
220
    visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->halfedges_begin(), OVMPropertyVisualizer<MeshT>::mesh->halfedges_end());\
221 222 223 224 225 226
    if (_setDrawMode)\
    {\
        VolumeMeshObject<MeshT>* object;\
        PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
        object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halfedgesColoredPerHalfedge);\
    }\
227 228
}\
template <Template>\
229
void Classname::visualizeVertexProp(bool _setDrawMode)\
230
{\
231
    OpenVolumeMesh::VertexPropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_vertex_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
232
    visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->vertices_begin(), OVMPropertyVisualizer<MeshT>::mesh->vertices_end());\
233 234 235 236 237 238
    if (_setDrawMode)\
    {\
        VolumeMeshObject<MeshT>* object;\
        PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
        object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.verticesColored);\
    }\
239 240 241 242 243 244 245 246 247 248
}\


#if defined(INCLUDE_TEMPLATES) && !defined(OVM_PROPERTY_VISUALIZER_CC)
#include "OVMPropertyVisualizerT.cc"
#endif

#endif /* OVM_PROPERTY_VISUALIZER_HH */

#endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */
249