OVMPropertyVisualizerVectorT_impl.hh 23.9 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
*                                                                            *
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
42

43

44
45
46

#define OVM_PROPERTY_VISUALIZER_VECTOR_CC

47
#include <ACG/Utils/ColorConversion.hh>
48
49
50
#include "OVMPropertyVisualizerVector.hh"


David Bommes's avatar
David Bommes committed
51
52
template <typename MeshT, typename VectorT>
OVMPropertyVisualizerVector<MeshT,VectorT>::OVMPropertyVisualizerVector(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo)
53
54
55
56
57
58
59
    : OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo)
{
    if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
    VectorWidget* w = new VectorWidget();
    w->paramVector->setTitle(QString("3D Vector Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
    PropertyVisualizer::widget = w;

60
61
    BaseObjectData *bod;
    PluginFunctions::getObject(objectID, bod);
62
    lineNode = new ACG::SceneGraph::LineNode(ACG::SceneGraph::LineNode::LineSegmentsMode, bod->manipulatorNode());
63
    w->vectors_edges_rb->hide();
64
    this->connect(w->lineWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
65
                  [this](double value) {lineNode->set_line_width(value);});
66
67
}

David Bommes's avatar
David Bommes committed
68
69
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::clear()
70
71
72
73
74
{
    lineNode->clear();
    OVMPropertyVisualizer<MeshT>::clear();
}

David Bommes's avatar
David Bommes committed
75
76
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::duplicateProperty()
77
{
David Bommes's avatar
David Bommes committed
78
    OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<VectorT>();
79
80
}

David Bommes's avatar
David Bommes committed
81
template<typename MeshT, typename VectorT>
82
template<typename PropType, typename EntityIterator>
David Bommes's avatar
David Bommes committed
83
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeVectorAsColorForEntity(PropType prop, EntityIterator e_begin, EntityIterator e_end, bool normalized) {
84
85
86
87
88
    if (!prop)
        throw VizException("Getting PropHandle from mesh for selected property failed.");
    VolumeMeshObject<MeshT>* object;
    PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
    for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it) {
David Bommes's avatar
David Bommes committed
89
        ACG::Vec3d v = convert_to_acg(prop[*e_it]);
90
        if (normalized)
91
            v = v.normalized() * 0.5 + ACG::Vec3d(0.5);
92
        else
93
            v = v.min(ACG::Vec3d(1, 1, 1)).max(ACG::Vec3d(0, 0, 0));
94
95
96
97
        object->colors()[*e_it] = ACG::Vec4f(v[0], v[1], v[2], 1.0);
    }
}

David Bommes's avatar
David Bommes committed
98
99
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeCellProp(bool _setDrawMode)
100
101
102
103
{
    VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
    if (w->vectors_colors_rb->isChecked())
    {
David Bommes's avatar
David Bommes committed
104
        OpenVolumeMesh::CellPropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_cell_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
105
106
        visualizeVectorAsColorForEntity(prop,
                                        OVMPropertyVisualizer<MeshT>::mesh->cells_begin(),
107
108
                                        OVMPropertyVisualizer<MeshT>::mesh->cells_end(),
                                        w->normalize_colors->isChecked());
109
110
111
112
113
114
        if (_setDrawMode)
        {
            VolumeMeshObject<MeshT>* object;
            PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
            object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.cellsColoredPerCell);
        }
115
116
117
118
    }
    else visualizeCellPropAsStrokes();
}

David Bommes's avatar
David Bommes committed
119
120
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeFaceProp(bool _setDrawMode)
121
122
123
124
{
    VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
    if (w->vectors_colors_rb->isChecked())
    {
David Bommes's avatar
David Bommes committed
125
        OpenVolumeMesh::FacePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_face_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
126
127
        visualizeVectorAsColorForEntity(prop,
                                        OVMPropertyVisualizer<MeshT>::mesh->faces_begin(),
128
129
                                        OVMPropertyVisualizer<MeshT>::mesh->faces_end(),
                                        w->normalize_colors->isChecked());
130
131
132
133
134
135
        if (_setDrawMode)
        {
            VolumeMeshObject<MeshT>* object;
            PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
            object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.facesColoredPerFace);
        }
136
137
138
139
140
    }
    else visualizeFacePropAsStrokes();
}


David Bommes's avatar
David Bommes committed
141
142
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeHalffaceProp(bool _setDrawMode)
143
144
145
146
{
    VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
    if (w->vectors_colors_rb->isChecked())
    {
David Bommes's avatar
David Bommes committed
147
        OpenVolumeMesh::HalfFacePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfface_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
148
149
        visualizeVectorAsColorForEntity(prop,
                                        OVMPropertyVisualizer<MeshT>::mesh->halffaces_begin(),
150
151
                                        OVMPropertyVisualizer<MeshT>::mesh->halffaces_end(),
                                        w->normalize_colors->isChecked());
152
153
154
155
156
157
        if (_setDrawMode)
        {
            VolumeMeshObject<MeshT>* object;
            PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
            object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halffacesColoredPerHalfface);
        }
158
    }
159
    else visualizeHalffacePropAsStrokes();
160
161
}

David Bommes's avatar
David Bommes committed
162
163
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeEdgeProp(bool _setDrawMode)
164
165
166
167
{
    VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
    if (w->vectors_colors_rb->isChecked())
    {
David Bommes's avatar
David Bommes committed
168
        OpenVolumeMesh::EdgePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_edge_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
169
170
        visualizeVectorAsColorForEntity(prop,
                                        OVMPropertyVisualizer<MeshT>::mesh->edges_begin(),
171
172
                                        OVMPropertyVisualizer<MeshT>::mesh->edges_end(),
                                        w->normalize_colors->isChecked());
173
174
175
176
177
178
        if (_setDrawMode)
        {
            VolumeMeshObject<MeshT>* object;
            PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
            object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.edgesColoredPerEdge);
        }
179
180
181
182
    }
    else visualizeEdgePropAsStrokes();
}

David Bommes's avatar
David Bommes committed
183
184
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeHalfedgeProp(bool _setDrawMode)
185
186
187
188
{
    VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
    if (w->vectors_colors_rb->isChecked())
    {
David Bommes's avatar
David Bommes committed
189
        OpenVolumeMesh::HalfEdgePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfedge_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
190
191
        visualizeVectorAsColorForEntity(prop,
                                        OVMPropertyVisualizer<MeshT>::mesh->halfedges_begin(),
192
193
                                        OVMPropertyVisualizer<MeshT>::mesh->halfedges_end(),
                                        w->normalize_colors->isChecked());
194
195
196
197
198
199
        if (_setDrawMode)
        {
            VolumeMeshObject<MeshT>* object;
            PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
            object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halfedgesColoredPerHalfedge);
        }
200
201
202
203
    }
    else visualizeHalfedgePropAsStrokes();
}

David Bommes's avatar
David Bommes committed
204
205
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeVertexProp(bool _setDrawMode)
206
207
208
209
{
    VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
    if (w->vectors_colors_rb->isChecked())
    {
David Bommes's avatar
David Bommes committed
210
        OpenVolumeMesh::VertexPropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_vertex_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
211
212
        visualizeVectorAsColorForEntity(prop,
                                        OVMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
213
214
                                        OVMPropertyVisualizer<MeshT>::mesh->vertices_end(),
                                        w->normalize_colors->isChecked());
215
216
217
218
219
220
        if (_setDrawMode)
        {
            VolumeMeshObject<MeshT>* object;
            PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
            object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.verticesColored);
        }
221
222
223
224
    }
    else visualizeVertexPropAsStrokes();
}

David Bommes's avatar
David Bommes committed
225
226
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeFacePropAsStrokes()
227
228
229
230
231
{
    VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);

    lineNode->clear();

232
    ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
233

David Bommes's avatar
David Bommes committed
234
    OpenVolumeMesh::FacePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_face_property<VectorT>(PropertyVisualizer::propertyInfo.propName());
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

    if ( !prop )
        return;

    OpenVolumeMesh::FaceIter f_begin(OVMPropertyVisualizer<MeshT>::mesh->faces_begin()), f_end(OVMPropertyVisualizer<MeshT>::mesh->faces_end());
    for (OpenVolumeMesh::FaceIter f_it = f_begin; f_it != f_end; ++f_it){

        ACG::Vec3d center(0.0, 0.0, 0.0);
        int vCount = 0;

        OpenVolumeMesh::HalfFaceHandle hfh = OVMPropertyVisualizer<MeshT>::mesh->halfface_handle(*f_it, 0);
        for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = OVMPropertyVisualizer<MeshT>::mesh->hfv_iter(hfh); hfv_it; ++hfv_it){
            vCount++;
            center += OVMPropertyVisualizer<MeshT>::mesh->vertex(*hfv_it);
        }

        center /= vCount;

David Bommes's avatar
David Bommes committed
253
        ACG::Vec3d v  = convert_to_acg(prop[*f_it]);
254
255
256
257
258
259
260
261
262
263
264
265

        if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
            v.normalize();

        if(vectorWidget->scale->isChecked())
            v *= vectorWidget->scaleBox->value();

        lineNode->add_line( center, (center+v) );
        lineNode->add_color(color);
    }
}

David Bommes's avatar
David Bommes committed
266
267
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeEdgePropAsStrokes()
268
269
270
271
272
{
    VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);

    lineNode->clear();

273
    ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
274

David Bommes's avatar
David Bommes committed
275
    OpenVolumeMesh::EdgePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_edge_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
276
277
278
279
280
281
282
283
284
285
286
    if ( !prop )
        return;

    OpenVolumeMesh::EdgeIter e_begin(OVMPropertyVisualizer<MeshT>::mesh->edges_begin()), e_end(OVMPropertyVisualizer<MeshT>::mesh->edges_end());
    for (OpenVolumeMesh::EdgeIter e_it = e_begin; e_it != e_end; ++e_it){

        OpenVolumeMesh::OpenVolumeMeshEdge edge = OVMPropertyVisualizer<MeshT>::mesh->edge(*e_it);
        ACG::Vec3d v1 = OVMPropertyVisualizer<MeshT>::mesh->vertex(edge.from_vertex());
        ACG::Vec3d v2 = OVMPropertyVisualizer<MeshT>::mesh->vertex(edge.to_vertex());
        ACG::Vec3d start = 0.5*(v1+v2);

David Bommes's avatar
David Bommes committed
287
        ACG::Vec3d v  = convert_to_acg(prop[*e_it]);
288
289
290
291
292
293
294
295
296
297
298
299
300
301

        if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
            v.normalize();



        if(vectorWidget->scale->isChecked())
        v *= vectorWidget->scaleBox->value();

        lineNode->add_line( start, (start+v) );
        lineNode->add_color(color);
    }
}

David Bommes's avatar
David Bommes committed
302
303
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeHalfedgePropAsStrokes()
304
305
306
307
308
{
    VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);

    lineNode->clear();

309
    ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
310

David Bommes's avatar
David Bommes committed
311
    OpenVolumeMesh::HalfEdgePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfedge_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
312
313
314
315
316
317
318
319
320
321
322
323
    if ( !prop )
        return;

    OpenVolumeMesh::HalfEdgeIter he_begin(OVMPropertyVisualizer<MeshT>::mesh->halfedges_begin()), he_end(OVMPropertyVisualizer<MeshT>::mesh->halfedges_end());
    for (OpenVolumeMesh::HalfEdgeIter he_it = he_begin; he_it != he_end; ++he_it){

        OpenVolumeMesh::OpenVolumeMeshEdge edge = OVMPropertyVisualizer<MeshT>::mesh->halfedge(*he_it);

        ACG::Vec3d v1 = OVMPropertyVisualizer<MeshT>::mesh->vertex(edge.from_vertex());
        ACG::Vec3d v2 = OVMPropertyVisualizer<MeshT>::mesh->vertex(edge.to_vertex());
        ACG::Vec3d start = (2.0*v1+v2)/3.0;

David Bommes's avatar
David Bommes committed
324
        ACG::Vec3d v  = convert_to_acg(prop[*he_it]);
325
326
327
328
329
330
331
332
333
334
335
336

        if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
            v.normalize();

        if(vectorWidget->scale->isChecked())
        v *= vectorWidget->scaleBox->value();

        lineNode->add_line( start, (start+v) );
        lineNode->add_color(color);
    }
}

David Bommes's avatar
David Bommes committed
337
338
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeVertexPropAsStrokes()
339
340
341
342
343
{
    VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);

    lineNode->clear();

344
    ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
345

David Bommes's avatar
David Bommes committed
346
    OpenVolumeMesh::VertexPropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_vertex_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
347
348
349
350
351
352
353
354
    if ( !prop )
        return;

    OpenVolumeMesh::VertexIter v_begin(OVMPropertyVisualizer<MeshT>::mesh->vertices_begin()), v_end(OVMPropertyVisualizer<MeshT>::mesh->vertices_end());
    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it != v_end; ++v_it){

        ACG::Vec3d start = OVMPropertyVisualizer<MeshT>::mesh->vertex(*v_it);

David Bommes's avatar
David Bommes committed
355
        ACG::Vec3d v  = convert_to_acg(prop[*v_it]);
356
357
358
359
360
361
362
363
364
365
366
367

        if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
            v.normalize();

        if(vectorWidget->scale->isChecked())
        v *= vectorWidget->scaleBox->value();

        lineNode->add_line( start, (start+v) );
        lineNode->add_color(color);
    }
}

David Bommes's avatar
David Bommes committed
368
369
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeCellPropAsStrokes()
370
371
372
373
374
{
    VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);

    lineNode->clear();

375
    ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
376

David Bommes's avatar
David Bommes committed
377
    OpenVolumeMesh::CellPropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_cell_property<VectorT>(PropertyVisualizer::propertyInfo.propName());
378
379
380
381
382
383
384
385
386
387
388
389
390
391

    if ( !prop )
        return;

    OpenVolumeMesh::CellIter c_begin(OVMPropertyVisualizer<MeshT>::mesh->cells_begin()), c_end(OVMPropertyVisualizer<MeshT>::mesh->cells_end());
    for (OpenVolumeMesh::CellIter c_it = c_begin; c_it != c_end; ++c_it){

        // Compute cell's center
        ACG::Vec3d center(0.0, 0.0, 0.0);
        unsigned int vCount = OVMPropertyVisualizer<MeshT>::mesh->n_vertices_in_cell(*c_it);
        for(OpenVolumeMesh::CellVertexIter cv_it = OVMPropertyVisualizer<MeshT>::mesh->cv_iter(*c_it); cv_it.valid(); ++cv_it) {
            center += OVMPropertyVisualizer<MeshT>::mesh->vertex(*cv_it) / (double)vCount;
        }

David Bommes's avatar
David Bommes committed
392
        ACG::Vec3d v  = convert_to_acg(prop[*c_it]);
393
394
395
396
397
398
399
400
401
402
403
404

        if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
            v.normalize();

        if(vectorWidget->scale->isChecked())
            v *= vectorWidget->scaleBox->value();

        lineNode->add_line( center, (center+v) );
        lineNode->add_color(color);
    }
}

David Bommes's avatar
David Bommes committed
405
406
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeHalffacePropAsStrokes()
407
408
409
410
411
{
    VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);

    lineNode->clear();

412
    ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
413

David Bommes's avatar
David Bommes committed
414
    OpenVolumeMesh::HalfFacePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfface_property<VectorT>(PropertyVisualizer::propertyInfo.propName());
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431

    if ( !prop )
        return;

    OpenVolumeMesh::HalfFaceIter hf_begin(OVMPropertyVisualizer<MeshT>::mesh->halffaces_begin()), hf_end(OVMPropertyVisualizer<MeshT>::mesh->halffaces_end());
    for (OpenVolumeMesh::HalfFaceIter hf_it = hf_begin; hf_it != hf_end; ++hf_it){

        ACG::Vec3d center(0.0, 0.0, 0.0);
        int vCount = 0;

        for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = OVMPropertyVisualizer<MeshT>::mesh->hfv_iter(*hf_it); hfv_it; ++hfv_it){
            vCount++;
            center += OVMPropertyVisualizer<MeshT>::mesh->vertex(*hfv_it);
        }

        center /= vCount;

David Bommes's avatar
David Bommes committed
432
        ACG::Vec3d v  = convert_to_acg(prop[*hf_it]);
433
434
435
436
437
438
439
440
441
442
443
444

        if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
            v.normalize();

        if(vectorWidget->scale->isChecked())
            v *= vectorWidget->scaleBox->value();

        lineNode->add_line( center, (center+v) );
        lineNode->add_color(color);
    }
}

David Bommes's avatar
David Bommes committed
445
446
template <typename MeshT, typename VectorT>
QString OVMPropertyVisualizerVector<MeshT,VectorT>::getPropertyText(unsigned int index)
447
{
David Bommes's avatar
David Bommes committed
448
    return OVMPropertyVisualizer<MeshT>::template getPropertyText_<VectorT>(index);
449
450
}

451

David Bommes's avatar
David Bommes committed
452
453
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::setCellPropertyFromText(unsigned int index, QString text)
454
455
456
{
    MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;

David Bommes's avatar
David Bommes committed
457
    OpenVolumeMesh::CellPropertyT<VectorT> prop = mesh->template request_cell_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
458
459
460
461
462
463
464
465
    if ( !prop )
    {
        emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
        return;
    }

    OpenVolumeMesh::CellHandle ch(index);

David Bommes's avatar
David Bommes committed
466
    prop[ch] = this->template strToVec3<VectorT>(text);
467
468
}

David Bommes's avatar
David Bommes committed
469
470
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::setFacePropertyFromText(unsigned int index, QString text)
471
472
473
{
    MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;

David Bommes's avatar
David Bommes committed
474
    OpenVolumeMesh::FacePropertyT<VectorT> prop = mesh->template request_face_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
475
476
477
478
479
480
481
482
    if ( !prop )
    {
        emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
        return;
    }

    OpenVolumeMesh::FaceHandle fh(index);

David Bommes's avatar
David Bommes committed
483
    prop[fh] = this->template strToVec3<VectorT>(text);
484
485
}

David Bommes's avatar
David Bommes committed
486
487
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::setHalffacePropertyFromText(unsigned int index, QString text)
488
489
490
{
    MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;

David Bommes's avatar
David Bommes committed
491
    OpenVolumeMesh::HalfFacePropertyT<VectorT> prop = mesh->template request_halfface_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
492
493
494
495
496
497
498
499
    if ( !prop )
    {
        emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
        return;
    }

    OpenVolumeMesh::HalfFaceHandle hfh(index);

David Bommes's avatar
David Bommes committed
500
    prop[hfh] = this->template strToVec3<VectorT>(text);
501
502
}

David Bommes's avatar
David Bommes committed
503
504
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::setEdgePropertyFromText(unsigned int index, QString text)
505
506
507
{
    MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;

David Bommes's avatar
David Bommes committed
508
    OpenVolumeMesh::EdgePropertyT<VectorT> prop = mesh->template request_edge_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
509
510
511
512
513
514
515
516
    if ( !prop )
    {
        emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
        return;
    }

    OpenVolumeMesh::EdgeHandle eh(index);

David Bommes's avatar
David Bommes committed
517
    prop[eh] = this->template strToVec3<VectorT>(text);
518
519
}

David Bommes's avatar
David Bommes committed
520
521
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::setHalfedgePropertyFromText(unsigned int index, QString text)
522
523
524
{
    MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;

David Bommes's avatar
David Bommes committed
525
    OpenVolumeMesh::HalfEdgePropertyT<VectorT> prop = mesh->template request_halfedge_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
526
527
528
529
530
531
532
533
    if ( !prop )
    {
        emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
        return;
    }

    OpenVolumeMesh::HalfEdgeHandle heh(index);

David Bommes's avatar
David Bommes committed
534
    prop[heh] = this->template strToVec3<VectorT>(text);
535
536
}

David Bommes's avatar
David Bommes committed
537
538
template <typename MeshT, typename VectorT>
void OVMPropertyVisualizerVector<MeshT,VectorT>::setVertexPropertyFromText(unsigned int index, QString text)
539
540
541
{
    MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;

David Bommes's avatar
David Bommes committed
542
    OpenVolumeMesh::VertexPropertyT<VectorT> prop = mesh->template request_vertex_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
543
544
545
546
547
548
549
550
    if ( !prop )
    {
        emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
        return;
    }

    OpenVolumeMesh::VertexHandle vh(index);

David Bommes's avatar
David Bommes committed
551
    prop[vh] = this->template strToVec3<VectorT>(text);
552
553
}