OVMPropertyVisualizerMatrix3x3_impl.hh 8.48 KB
Newer Older
1
2
3
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
39
40
41
42
43
44
45
46
47
48
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
 *           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.              *
*                                                                            *
\*===========================================================================*/




#define OVM_PROPERTY_VISUALIZER_MAT3X3_CC

#include <ACG/Utils/ColorConversion.hh>
#include "OVMPropertyVisualizerMatrix3x3.hh"
49
#include "ACG/Scenegraph/DrawModes.hh"
50
#include "EntityPosition.hh"
51

52
53
54
55
56
57
58
using Color4f = ACG::SceneGraph::LineNode::Color4f;
static std::array<Color4f, 3> dim_color {
    Color4f{1.f,0.f,0.f,1.f},
    Color4f{0.f,1.f,0.f,1.f},
    Color4f{0.f,0.f,1.f,1.f}
};

59
60
61
62
63
64
65
66
67
68
template <typename MeshT>
OVMPropertyVisualizerMatrix3x3<MeshT>::OVMPropertyVisualizerMatrix3x3(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo)
    : OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo)
{
    if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
    Matrix3x3Widget* w = new Matrix3x3Widget();
    PropertyVisualizer::widget = w;

    BaseObjectData *bod;
    PluginFunctions::getObject(objectID, bod);
69
70
71
72

    boxesNode = new ACG::SceneGraph::BoxesNode(bod->manipulatorNode());

    lineNode = new ACG::SceneGraph::LineNode(ACG::SceneGraph::LineNode::LineSegmentsMode, bod->manipulatorNode());
73
74
75
76
77
78
79
80
    this->connect(w->lineWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
                  [this](double value) {lineNode->set_line_width(value);});
}

template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::clear()
{
    lineNode->clear();
81
    boxesNode->clear();
82
83
84
85
86
87
88
89
90
    OVMPropertyVisualizer<MeshT>::clear();
}

template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::duplicateProperty()
{
    OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<ACG::Matrix3x3d>();
}

91
template<typename MeshT>
92
template<typename EntityTag, typename Property, typename EntityIterator>
93
void OVMPropertyVisualizerMatrix3x3<MeshT>::
94
visualizeAsCrossesForEntity(Property prop, EntityIterator e_begin, EntityIterator e_end)
95
96
97
98
{
    using ACG::Vec3d;
    using ACG::Matrix3x3d;

99
    MeshT &m = *OVMPropertyVisualizer<MeshT>::mesh;
100
101
102
    EntityPosition<MeshT> ep{m};


103
    double scaleFactor = getMatWidget()->getScaleFactor();
104

105
106
107
108
    for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it) {
        Matrix3x3d mat = prop[*e_it];
        Vec3d center_pos = ep(*e_it);
        for (unsigned char dim = 0; dim < 3; ++dim) {
109
            ACG::Vec3d v = mat.getCol(dim) * scaleFactor;
110
111
112
113
114
115
116
            lineNode->add_line(center_pos - v, center_pos + v);
            lineNode->add_color(dim_color[dim]);
        }
    }
}

template<typename MeshT>
117
template<typename EntityTag, typename Property, typename EntityIterator>
118
void OVMPropertyVisualizerMatrix3x3<MeshT>::
119
visualizeAsBoxesForEntity(Property prop, EntityIterator e_begin, EntityIterator e_end)
120
{
121
122
123
124
125
    using ACG::Vec3d;
    using ACG::Matrix3x3d;
    MeshT &m = *OVMPropertyVisualizer<MeshT>::mesh;
    EntityPosition<MeshT> ep{m};

126

127
128
129
    for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it) {
        const Matrix3x3d &mat = prop[*e_it];
        Vec3d center_pos = ep(*e_it);
130
        boxesNode->push_back({mat, center_pos});
131
    }
132
    boxesNode->setScaleFactor(getMatWidget()->getScaleFactor());
133
134
135
136
137
138
139
}

template<typename MeshT>
template<typename EntityTag, typename EntityIterator>
void OVMPropertyVisualizerMatrix3x3<MeshT>::
visualizeForEntity(EntityIterator e_begin, EntityIterator e_end)
{
140
141
142
143
144
145
    clear();
    MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
    auto prop = m.template request_property<ACG::Matrix3x3d, EntityTag>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
    if (!prop)
        throw VizException("Getting PropHandle from mesh for selected property failed.");

146
    if (getMatWidget()->as_crosses->isChecked()) {
147
        visualizeAsCrossesForEntity<EntityTag>(prop, e_begin, e_end);
148
    } else if (getMatWidget()->as_boxes->isChecked()) {
149
        visualizeAsBoxesForEntity<EntityTag>(prop, e_begin, e_end);
150
151
152
    }
}

153
template <typename MeshT>
154
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeCellProp(bool /*_setDrawMode*/)
155
{
156
157
    MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
    visualizeForEntity<OpenVolumeMesh::Entity::Cell>(m.cells_begin(), m.cells_end());
158
159
160
}

template <typename MeshT>
161
162
163
164
165
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeFaceProp(bool /*_setDrawMode*/)
{
    MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
    visualizeForEntity<OpenVolumeMesh::Entity::Face>(m.faces_begin(), m.faces_end());
}
166
167
168


template <typename MeshT>
169
170
171
172
173
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeHalffaceProp(bool /*_setDrawMode*/)
{
    MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
    visualizeForEntity<OpenVolumeMesh::Entity::HalfFace>(m.halffaces_begin(), m.halffaces_end());
}
174
175

template <typename MeshT>
176
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeEdgeProp(bool /*_setDrawMode*/)
177
{
178
179
    MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
    visualizeForEntity<OpenVolumeMesh::Entity::Edge>(m.edges_begin(), m.edges_end());
180
181
182
}

template <typename MeshT>
183
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeHalfedgeProp(bool /*_setDrawMode*/)
184
{
185
186
    MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
    visualizeForEntity<OpenVolumeMesh::Entity::HalfEdge>(m.halfedges_begin(), m.halfedges_end());
187
188
189
}

template <typename MeshT>
190
191
192
193
194
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeVertexProp(bool /*_setDrawMode*/)
{
    MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
    visualizeForEntity<OpenVolumeMesh::Entity::Vertex>(m.vertices_begin(), m.vertices_end());
}
195
196
197
198
199
200
201

template <typename MeshT>
QString OVMPropertyVisualizerMatrix3x3<MeshT>::getPropertyText(unsigned int index)
{
    return OVMPropertyVisualizer<MeshT>::template getPropertyText_<ACG::Matrix3x3d>(index);
}