OMPropertyModelT.cc 29 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
#define OM_PROPERTY_MODEL_CC

#include "OMPropertyModel.hh"

#include "OMPropertyVisualizerBoolean.hh"
#include "OMPropertyVisualizerDouble.hh"
#include "OMPropertyVisualizerInteger.hh"
#include "OMPropertyVisualizerVector.hh"
58
#include "OMPropertyVisualizerVector2.hh"
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "OMPropertyVisualizerVectorFieldDifference.hh"

#ifdef ENABLE_SKELETON_SUPPORT
#include "OMPropertyVisualizerSkinWeights.hh"
#endif

#include "../Utils.hh"

#include <vector>

#define PROP_VIS "PropertyVisualization"

template<typename MeshT>
OMPropertyModel<MeshT>::OMPropertyModel(MeshT* mesh, int objectID, QObject *parent)
    : OMPropertyModelSubclass(parent),
      mesh_(mesh),
      objectID_(objectID),
      mCombineProperty1(0),
      mCombineProperty2(0),
78
      pickModeActive(false)
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{
    gatherProperties();
    bCombine.setText(tr("Combine"));
    bCombine.hide();
    connect(&bCombine, SIGNAL(clicked()),
            this,      SLOT(slotCombine()));
    widgets->layout()->addWidget(&bCombine);
    widgets->layout()->addWidget(&mLoadSaveWidget);

    connect(mLoadSaveWidget.save_property , SIGNAL(clicked()),
            this,                           SLOT(slotSaveProperty()));

    connect(mLoadSaveWidget.load_property , SIGNAL(clicked()),
            this,                           SLOT(slotLoadProperty()));

    widgets->layout()->addWidget(&mPickWidget);
    connect(mPickWidget.pickButton, SIGNAL(clicked()),
            this,                   SLOT(slotPickProperty()));
    mPickWidget.hide();
    QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
    mPickWidget.pickButton->setIcon( QIcon(iconPath + "color-picker.png") );


    lastPickMode   = PluginFunctions::pickMode();
    lastActionMode = PluginFunctions::actionMode();
104

Max Lyon's avatar
Max Lyon committed
105
    initializeSupportedPropertyTypes();
106
107
108
109
110
111

}

template<typename MeshT>
void OMPropertyModel<MeshT>::updateWidget(const QModelIndexList& selectedIndices)
{
112
    SingleObjectPropertyModel::updateWidget(selectedIndices);
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

    if (selectedIndices.size() == 2)
    {
        if (combinable(propertyVisualizers[selectedIndices[0].row()], propertyVisualizers[selectedIndices[1].row()]))
        {

            bCombine.show();
            mCombineProperty1 = &propertyVisualizers[selectedIndices[0].row()]->getPropertyInfo();
            mCombineProperty2 = &propertyVisualizers[selectedIndices[1].row()]->getPropertyInfo();
        }
        else
            bCombine.hide();
    }
    else
        bCombine.hide();

    if (selectedIndices.size() == 1)
        mPickWidget.show();
    else
    {
        mPickWidget.hide();
134
135
136
        //reset Picking, just if picking was enabled
        if (mPickWidget.pickButton->isChecked())
          resetPicking();
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
    }
}

template<typename MeshT>
QString OMPropertyModel<MeshT>::getLoadFilenameFilter()
{
    QString filter;
    filter =       tr("Vertex Property (*.vprop)");
    filter += tr(";; HalfEdge Property (*.hprop)");
    filter +=     tr(";; Edge Property (*.eprop)");
    filter +=     tr(";; Face Property (*.fprop)");
    filter +=         tr(";; All Files (*)");
    return filter;
}

template<typename MeshT>
QString OMPropertyModel<MeshT>::getSaveFilenameFilter(unsigned int propId)
{
    PropertyVisualizer* propViz = propertyVisualizers[propId];

    QString filter;

    if (propViz->getPropertyInfo().isVertexProp())
        filter = tr("Vertex Property (*.vprop)");
    else if (propViz->getPropertyInfo().isHalfedgeProp())
        filter = tr("HalfEdge Property (*.hprop)");
    else if (propViz->getPropertyInfo().isEdgeProp())
        filter = tr("Edge Property (*.eprop)");
    else if (propViz->getPropertyInfo().isFaceProp())
        filter = tr("Face Property (*.fprop)");

    filter += tr(";; All Files (*)");

    return filter;
}

/**
 * @brief Combines two properties.
 *
 * If the user selects two properties which are both of a vector type (Vec3f or Vec3d)
 * they can be combined. This method will create a new PropertyVisualizer (an
 * OMPropertyVisualizerVectorFieldDifference<MeshT> to be exact) but not an additional
 * property.
 */
template<typename MeshT>
void OMPropertyModel<MeshT>::combine()
{
    beginResetModel();
    if (isVectorType(mCombineProperty1->typeinfo()))
186
        propertyVisualizers.push_back(new OMPropertyVisualizerVectorFieldDifference<MeshT>(mesh_, objectID_, *mCombineProperty1, *mCombineProperty2));
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
    endResetModel();
}

/**
 * @brief Checks if two properties are combinable.
 *
 * @param propertyVisualizer1 First PropertyVisualizer for combination.
 * @param propertyVisualizer2 Second PropertyVisualizer for combination.
 *
 * @return True if the two properties are combinable, False if not.
 *
 * If the user selects two properties which are both of a vector type (Vec3f or Vec3d)
 * they can be combined. This method will check if the two provided PropertyVisualizers can
 * be comined. Currently PropertyVisualizers can only be combined if both visualize a
 * property with a vector type and the same entity type.
 */
template<typename MeshT>
bool OMPropertyModel<MeshT>::combinable(PropertyVisualizer* propertyVisualizer1, PropertyVisualizer* propertyVisualizer2)
{
    const PropertyInfo& propInfo1 = propertyVisualizer1->getPropertyInfo();
    const PropertyInfo& propInfo2 = propertyVisualizer2->getPropertyInfo();
    TypeInfoWrapper typeInfo1 = propInfo1.typeinfo();
    TypeInfoWrapper typeInfo2 = propInfo2.typeinfo();

    return (isVectorType(typeInfo1) && isVectorType(typeInfo2)) && (propInfo1.entityType() == propInfo2.entityType());
}

template<typename MeshT>
void OMPropertyModel<MeshT>::saveProperty()
{
217
    for (QModelIndexList::const_iterator it = currentlySelectedIndices.begin(), it_end = currentlySelectedIndices.end();
218
                it != it_end; ++it) {
219
        SingleObjectPropertyModel::saveProperty(it->row());
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    }
}

template<typename MeshT>
bool OMPropertyModel<MeshT>::parseHeader(QString header, PropertyVisualizer*& propVis, unsigned int &n)
{
    QStringList headerParts = header.split(tr(", "), QString::SkipEmptyParts );
    int headerVersion = headerParts[0].toUInt();
    if (headerVersion == 1)
    {
        n = headerParts[1].toUInt();
        unsigned int nExpected = 0;

        PropertyInfo::ENTITY_FILTER filter = (PropertyInfo::ENTITY_FILTER)headerParts[2].toInt();
        switch (filter)
        {
            case PropertyInfo::EF_FACE:
                nExpected = mesh_->n_faces();
                break;
            case PropertyInfo::EF_EDGE:
                nExpected = mesh_->n_edges();
                break;
            case PropertyInfo::EF_HALFEDGE:
                nExpected = mesh_->n_halfedges();
                break;
            case PropertyInfo::EF_VERTEX:
                nExpected = mesh_->n_vertices();
                break;
            default:
                nExpected = -1;
                break;
        }

        if (n != nExpected)
        {
            emit log(LOGERR, "Could not load property: unexpected number of entities");
            return false;
        }

        QString friendlyName = headerParts[3];

        if (!isSupported(friendlyName))
        {
            emit log(LOGERR, tr("Could not load property: unsupported property type %1").arg(friendlyName));
            return false;
        }

        TypeInfoWrapper typeInfo = getSupportedTypeInfoWrapper(friendlyName);

        QString propName = QInputDialog::getText(0, "Property Name", "Please enter name.",QLineEdit::Normal,headerParts[4]);
        if (propName == "") return false;

        bool replace = false;
        if (!(isPropertyFree(propName, filter, typeInfo) || replace))
        {
            NewNameMessageBox* msgBox = new NewNameMessageBox(propName);
            msgBox->exec();

            if (msgBox->rename)
                propName = QInputDialog::getText(0, "New Property Name", "Please enter new name.");
            else if (msgBox->cancel)
                return false;
            else if (msgBox->replace)
                replace = true;

            delete msgBox;
        }

        if (!replace)
        {
            addProperty(propName, friendlyName, filter);
            gatherProperties();
        }

        propVis = getPropertyVisualizer(propName, filter, typeInfo);

        return true;

    }
    else
    {
        emit log(LOGERR, "Could not load property: unsupported header format");
        return false;
    }
}


template<typename MeshT>
308
void OMPropertyModel<MeshT>::setPropertyFromFile(QTextStream& file_stream, unsigned int n, PropertyVisualizer* propVis)
309
310
311
312
313
314
315
316
{
#ifdef ENABLE_SKELETON_SUPPORT
    if (propVis->getPropertyInfo().typeinfo() == proptype_SkinWeights)
    {
        for (unsigned int i = 0; i < n; ++i)
        {
            QString propertyText = "";
            QString tmp;
317
            while ((tmp = file_stream.readLine()) != "")
318
319
320
321
322
323
324
                propertyText = propertyText + tmp;
            propVis->setPropertyFromText(i, propertyText);
        }
    }
    else
#endif
    {
325
        SingleObjectPropertyModel::setPropertyFromFile(file_stream, n, propVis);
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
    }
}

template<typename MeshT>
void OMPropertyModel<MeshT>:: resetPicking()
{
    PluginFunctions::pickMode(lastPickMode);
    PluginFunctions::actionMode(lastActionMode);
}


/**
 * @brief Toggle picking on and off.
 *
 * This method will start and stop the picking.
 */
template<typename MeshT>
void OMPropertyModel<MeshT>::pickProperty()
{
    if ( mPickWidget.pickButton->isChecked() ){

      lastPickMode   = PluginFunctions::pickMode();
      lastActionMode = PluginFunctions::actionMode();

      PluginFunctions::pickMode(PROP_VIS);
      PluginFunctions::actionMode(Viewer::PickingMode);

    } else {
        resetPicking();
    }
}


template<typename MeshT>
void OMPropertyModel<MeshT>::pickModeChanged(const std::string& _mode)
{
    pickModeActive = (_mode == PROP_VIS);

    if (!pickModeActive)
    {
        lastPickMode = _mode;
    }

    mPickWidget.pickButton->setChecked(pickModeActive);
}

/**
 * @brief Handles mouse events for picking.
 *
 * If picking mode is active this method will find the picked entity and display
 * its handle and value in the PickWidget.
 */
template<typename MeshT>
void OMPropertyModel<MeshT>::mouseEvent(QMouseEvent* _event)
{
    if (!pickModeActive) return;

    if (_event->type() == QEvent::MouseButtonPress)
    {
385
386
387
388
389
390
391
      size_t         node_idx, face_idx;
      ACG::Vec3d     hit_point;

      if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE, _event->pos(),node_idx, face_idx, &hit_point)) {
        BaseObjectData* object;
        PluginFunctions::getPickedObject(node_idx, object);

392
        if (object->id() == objectID_ && !currentlySelectedIndices.empty())
393
394
395
396
397
        {
          OMPropertyVisualizer<MeshT>* viz = dynamic_cast<OMPropertyVisualizer<MeshT>*>(propertyVisualizers[currentlySelectedIndices.first().row()] );
          unsigned int primitiveId = viz->getClosestPrimitiveId(face_idx, hit_point);
          mPickWidget.pickedHandle->setText(tr("%1").arg(primitiveId));
          mPickWidget.pickedValue->setText(viz->getPropertyText(primitiveId));
398
        }
399
      }
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
    }
}

template<typename MeshT>
bool OMPropertyModel<MeshT>::isVectorType(const TypeInfoWrapper& typeInfo) const
{
    return (typeInfo == proptype_Vec3f) || (typeInfo == proptype_Vec3d);
}

template<typename MeshT>
void OMPropertyModel<MeshT>::gatherProperties( MeshT* mesh,
                       typename MeshT::prop_iterator props_first,
                       typename MeshT::prop_iterator props_last,
                       PropertyInfo::ENTITY_FILTER filter)
{
    for (typename MeshT::prop_iterator pit = props_first; pit != props_last; ++pit) {
         OpenMesh::BaseProperty*const baseProp = *pit;
        if (baseProp && isSupported(baseProp) && isNew(baseProp, filter))
            addPropertyVisualizer(baseProp, mesh, filter);
    }
}

template<typename MeshT>
void OMPropertyModel<MeshT>::gatherProperties()
{
    beginResetModel();
    if (mesh_) {
        gatherProperties(mesh_, mesh_->fprops_begin(), mesh_->fprops_end(), PropertyInfo::EF_FACE);
        gatherProperties(mesh_, mesh_->eprops_begin(), mesh_->eprops_end(), PropertyInfo::EF_EDGE);
        gatherProperties(mesh_, mesh_->hprops_begin(), mesh_->hprops_end(), PropertyInfo::EF_HALFEDGE);
        gatherProperties(mesh_, mesh_->vprops_begin(), mesh_->vprops_end(), PropertyInfo::EF_VERTEX);
    }
    endResetModel();
}


/**
 * @brief Checks if visualizing this property is supported.
 *
 * @param baseProp A pointer to the property that we want to visualize.
 *
 * @return True if the property can be visualized, False if not.
 */
template<typename MeshT>
bool OMPropertyModel<MeshT>::isSupported(OpenMesh::BaseProperty* const baseProp) const
{
    TypeInfoWrapper bp_type = typeid(*baseProp);
    TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
    return propIt != supportedPropertyTypes.end();
}

/**
 * @brief Checks if visualizing this property is supported.
 *
 * @param friendlyName The type we want to visualize in text form.
 *
 * @return True if the property type can be visualized, False if not.
 *
 * Currently supported are the types "bool", "int", "unsigned int", "double", "Vec3d",
 * "Vec3f" and "SkinWeights"
 */
template<typename MeshT>
bool OMPropertyModel<MeshT>::isSupported(QString friendlyName) const
{
    for (TypeInfoWrapperSet::const_iterator it =  supportedPropertyTypes.begin();
                                            it != supportedPropertyTypes.end();
                                          ++it )
    {
        if (friendlyName.toStdString().compare(it->getName()) == 0)
            return true;
    }
    return false;
}

/**
 * @brief Checks if we already created a PropertyVisualizer for this property.
 *
 * @param baseProp A pointer to the property.
 * @param filter The entity type.
 *
 * @return True if we do not have PropertyVisualizer yet for that property, False if we do
 */
template<typename MeshT>
bool OMPropertyModel<MeshT>::isNew(OpenMesh::BaseProperty* const baseProp, PropertyInfo::ENTITY_FILTER filter)
{
    for (unsigned int i = 0; i < propertyVisualizers.size(); ++i)
    {
        const PropertyInfo& propInfo =  propertyVisualizers[i]->getPropertyInfo();
        if (propInfo == PropertyInfo(baseProp->name(), getSupportedTypeInfoWrapper(baseProp) , filter))
            return false;
    }
    return true;
}

/**
 * @brief Returns the TypeInfoWrapper for the property if it is supported.
 *
 * @param baseProp A pointer to the property.
 *
 * @return A TypeInfoWrapper containing all the type information for the provided property.
 */
template<typename MeshT>
TypeInfoWrapper OMPropertyModel<MeshT>::getSupportedTypeInfoWrapper(OpenMesh::BaseProperty* const baseProp)
{
    TypeInfoWrapper bp_type = typeid(*baseProp);
    TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
    return *propIt;
}

/**
 * @brief Returns the TypeInfoWrapper for the type of property if it is supported.
 *
 * @param friendlyName The type we want to visualize in text form.
 *
 * @return A TypeInfoWrapper containing all the type information for the property type.
 */
template<typename MeshT>
TypeInfoWrapper OMPropertyModel<MeshT>::getSupportedTypeInfoWrapper(QString friendlyName)
{
    for (TypeInfoWrapperSet::const_iterator it =  supportedPropertyTypes.begin();
                                            it != supportedPropertyTypes.end();
                                          ++it )
    {
        if (friendlyName.toStdString().compare(it->getName()) == 0)
            return *it;
    }
    throw std::exception();
}


/**
 * @brief Adds a new PropertyVisualizer.
 *
 * @param baseProp A pointer to the property that should be visualized.
 * @param mesh A pointer to the mesh whose properties should be visualized.
 * @param filter The entity type that should be visualized.
 *
 * This method creates a new PropertyVisualizer depending on the provieded parameters and adds it to the list
 * of PropertyVisualizers.
 */
template<typename MeshT>
void OMPropertyModel<MeshT>::addPropertyVisualizer(OpenMesh::BaseProperty* const baseProp, MeshT* mesh, PropertyInfo::ENTITY_FILTER filter)
{
    PropertyInfo propInfo = PropertyInfo(baseProp->name(), getSupportedTypeInfoWrapper(baseProp) , filter);
    if (propInfo.typeinfo() == proptype_bool)
545
        propertyVisualizers.push_back(new OMPropertyVisualizerBoolean<MeshT>(mesh, objectID_, propInfo));
546
    else if (propInfo.typeinfo() == proptype_int)
547
        propertyVisualizers.push_back(new OMPropertyVisualizerInteger<MeshT, int>(mesh, objectID_, propInfo, false));
548
    else if (propInfo.typeinfo() == proptype_uint)
549
        propertyVisualizers.push_back(new OMPropertyVisualizerInteger<MeshT, unsigned int>(mesh, objectID_, propInfo, true));
550
    else if (propInfo.typeinfo() == proptype_uint8_t)
551
        propertyVisualizers.push_back(new OMPropertyVisualizerInteger<MeshT, uint8_t>(mesh, objectID_, propInfo, true));
552
    else if (propInfo.typeinfo() == proptype_double)
553
        propertyVisualizers.push_back(new OMPropertyVisualizerDouble<MeshT>(mesh, objectID_, propInfo));
554
    else if ((propInfo.typeinfo() == proptype_Vec3d) || (propInfo.typeinfo() == proptype_Vec3f))
555
        propertyVisualizers.push_back(new OMPropertyVisualizerVector<MeshT>(mesh, objectID_, propInfo));
556
    else if ((propInfo.typeinfo() == proptype_Vec2d))
557
        propertyVisualizers.push_back(new OMPropertyVisualizerVector2<MeshT, ACG::Vec2d>(mesh, objectID_, propInfo));
558
    else if ((propInfo.typeinfo() == proptype_Vec2f))
559
        propertyVisualizers.push_back(new OMPropertyVisualizerVector2<MeshT, ACG::Vec2f>(mesh, objectID_, propInfo));
560
561
#ifdef ENABLE_SKELETON_SUPPORT
    else if (propInfo.typeinfo() == proptype_SkinWeights)
562
        propertyVisualizers.push_back(new OMPropertyVisualizerSkinWeights<MeshT>(mesh, objectID_, propInfo));
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
#endif
    connectLogs(propertyVisualizers.back());
}

/**
 * @brief Adds a new property to the mesh.
 *
 * @param propName The name of the property that should be added.
 * @param friendlyTypeName The type of the property.
 * @param filter The entity type of the property.
 *
 * This method adds a new property to the mesh. The types "Vec3d", "Vec3d", "double", "unsigned int",
 * "int" and "bool" can be added for every entity type. "SkinWeights" can only be added for vertices.
 */
template<typename MeshT>
void OMPropertyModel<MeshT>:: addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
{

    QString dtype = friendlyTypeName;
    QString pname = propName;

    MeshT* mesh = mesh_;

    if ( filter == PropertyInfo::EF_VERTEX )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenMesh::VPropHandleT< TriMesh::Point > prop;
591
            mesh->add_property(prop, pname.toStdString());
592
        }
593
594
595
596
597
598
599
600
601
602
        else if (dtype == tr("Vec2d"))
        {
            OpenMesh::VPropHandleT< ACG::Vec2d > prop;
            mesh->add_property(prop, pname.toStdString());
        }
        else if (dtype == tr("Vec2f"))
        {
            OpenMesh::VPropHandleT< ACG::Vec2f > prop;
            mesh->add_property(prop, pname.toStdString());
        }
603
604
605
        else if ( dtype == tr("double") )
        {
            OpenMesh::VPropHandleT< double > prop;
606
            mesh->add_property(prop, pname.toStdString());
607
608
609
610
        }
        else if ( dtype == tr("unsigned int") )
        {
            OpenMesh::VPropHandleT< unsigned int > prop;
611
            mesh->add_property(prop, pname.toStdString());
612
        }
613
614
615
616
617
        else if ( dtype == tr("uint8_t") )
        {
            OpenMesh::VPropHandleT< uint8_t > prop;
            mesh->add_property(prop, pname.toStdString());
        }
618
619
620
        else if ( dtype == tr("int") )
        {
            OpenMesh::VPropHandleT< int > prop;
621
            mesh->add_property(prop, pname.toStdString());
622
623
624
625
        }
        else if ( dtype == tr("bool") )
        {
            OpenMesh::VPropHandleT< bool > prop;
626
            mesh->add_property(prop, pname.toStdString());
627
628
629
630
631
632
633
        }
        //please update the doc if you write "skin weights"-property support

#ifdef ENABLE_SKELETON_SUPPORT
        else if ( dtype == tr("SkinWeights") )
        {
            OpenMesh::VPropHandleT< BaseSkin::SkinWeights > prop;
634
            mesh->add_property(prop, pname.toStdString());
635
636
637
638
639
640
641
642
        }
#endif
    }
    else if ( filter == PropertyInfo::EF_EDGE )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenMesh::EPropHandleT< TriMesh::Point > prop;
643
            mesh->add_property(prop, pname.toStdString());
644
        }
645
646
647
648
649
650
651
652
653
654
        else if ( dtype == tr("Vec2d") )
        {
            OpenMesh::EPropHandleT< ACG::Vec2d > prop;
            mesh->add_property(prop, pname.toStdString());
        }
        else if ( dtype == tr("Vec2f") )
        {
            OpenMesh::EPropHandleT< ACG::Vec2f > prop;
            mesh->add_property(prop, pname.toStdString());
        }
655
656
657
        else if ( dtype == tr("double") )
        {
            OpenMesh::EPropHandleT< double > prop;
658
            mesh->add_property(prop, pname.toStdString());
659
660
661
662
        }
        else if ( dtype == tr("unsgined int") )
        {
            OpenMesh::EPropHandleT< unsigned int > prop;
663
            mesh->add_property(prop, pname.toStdString());
664
        }
665
666
667
668
669
        else if ( dtype == tr("uint8_t") )
        {
            OpenMesh::EPropHandleT< uint8_t > prop;
            mesh->add_property(prop, pname.toStdString());
        }
670
671
672
        else if ( dtype == tr("int") )
        {
            OpenMesh::EPropHandleT< int > prop;
673
            mesh->add_property(prop, pname.toStdString());
674
675
676
677
        }
        else if ( dtype == tr("bool") )
        {
            OpenMesh::EPropHandleT< bool > prop;
678
            mesh->add_property(prop, pname.toStdString());
679
680
681
682
683
684
685
        }
    }
    else if ( filter == PropertyInfo::EF_FACE )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenMesh::FPropHandleT< TriMesh::Point > prop;
686
            mesh->add_property(prop, pname.toStdString());
687
        }
688
689
690
691
692
693
694
695
696
697
        else if ( dtype == tr("Vec2d") )
        {
            OpenMesh::FPropHandleT< ACG::Vec2d > prop;
            mesh->add_property(prop, pname.toStdString());
        }
        else if ( dtype == tr("Vec2f") )
        {
            OpenMesh::FPropHandleT< ACG::Vec2f > prop;
            mesh->add_property(prop, pname.toStdString());
        }
698
699
700
        else if ( dtype == tr("double") )
        {
            OpenMesh::FPropHandleT< double > prop;
701
            mesh->add_property(prop, pname.toStdString());
702
703
704
705
        }
        else if ( dtype == tr("unsigned int") )
        {
            OpenMesh::FPropHandleT< unsigned int > prop;
706
            mesh->add_property(prop, pname.toStdString());
707
        }
708
709
710
711
712
        else if ( dtype == tr("uint8_t") )
        {
            OpenMesh::FPropHandleT< uint8_t > prop;
            mesh->add_property(prop, pname.toStdString());
        }
713
714
715
        else if ( dtype == tr("int") )
        {
            OpenMesh::FPropHandleT< int > prop;
716
            mesh->add_property(prop, pname.toStdString());
717
718
719
720
        }
        else if ( dtype == tr("bool") )
        {
            OpenMesh::FPropHandleT< bool > prop;
721
            mesh->add_property(prop, pname.toStdString());
722
723
724
725
726
727
728
        }
    }
    else if ( filter == PropertyInfo::EF_HALFEDGE )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenMesh::HPropHandleT< TriMesh::Point > prop;
729
            mesh->add_property(prop, pname.toStdString());
730
731
732
733
        }
        else if ( dtype == tr("double") )
        {
            OpenMesh::HPropHandleT< double > prop;
734
            mesh->add_property(prop, pname.toStdString());
735
736
737
738
        }
        else if ( dtype == tr("unsigned int") )
        {
            OpenMesh::HPropHandleT< unsigned int > prop;
739
            mesh->add_property(prop, pname.toStdString());
740
        }
741
742
743
744
745
        else if ( dtype == tr("uint8_t") )
        {
            OpenMesh::HPropHandleT< uint8_t > prop;
            mesh->add_property(prop, pname.toStdString());
        }
746
747
748
        else if ( dtype == tr("int") )
        {
            OpenMesh::HPropHandleT< int > prop;
749
            mesh->add_property(prop, pname.toStdString());
750
751
752
753
        }
        else if ( dtype == tr("bool") )
        {
            OpenMesh::HPropHandleT< bool > prop;
754
            mesh->add_property(prop, pname.toStdString());
755
756
757
758
759
760
        }
    }

}


Max Lyon's avatar
Max Lyon committed
761
762
763
template<typename MeshT>
void OMPropertyModel<MeshT>::initializeSupportedPropertyTypes()
{
764
765


Max Lyon's avatar
Max Lyon committed
766
767
768
    supportedPropertyTypes.insert(proptype_bool);
    supportedPropertyTypes.insert(proptype_int);
    supportedPropertyTypes.insert(proptype_uint);
769
    supportedPropertyTypes.insert(proptype_uint8_t);
Max Lyon's avatar
Max Lyon committed
770
771
772
    supportedPropertyTypes.insert(proptype_double);
    supportedPropertyTypes.insert(proptype_Vec3d);
    supportedPropertyTypes.insert(proptype_Vec3f);
773
774
    supportedPropertyTypes.insert(proptype_Vec2d);
    supportedPropertyTypes.insert(proptype_Vec2f);
775

776
#ifdef ENABLE_SKELETON_SUPPORT
Max Lyon's avatar
Max Lyon committed
777
    supportedPropertyTypes.insert(proptype_SkinWeights);
778
#endif
779

Max Lyon's avatar
Max Lyon committed
780
781
782
783
784
785
786
787
788
789
//#ifdef ENABLE_SKELETON_SUPPORT
//    //template <typename MeshT>
//    //const typename OMPropertyModel<MeshT>::TypeInfoWrapperSet OMPropertyModel<MeshT>::supportedPropertyTypes =
//    //        (OpenFlipper::Options::nogui() ? typename OMPropertyModel<MeshT>::TypeInfoWrapperSet() : typename OMPropertyModel<MeshT>::TypeInfoWrapperSet(propertyTypes, propertyTypes + 7));
//    supportedPropertyTypes = typename OMPropertyModel<MeshT>::TypeInfoWrapperSet();
//#else
//    //const typename OMPropertyModel<MeshT>::TypeInfoWrapperSet OMPropertyModel<MeshT>::supportedPropertyTypes =
//    //        (OpenFlipper::Options::nogui() ? typename OMPropertyModel<MeshT>::TypeInfoWrapperSet() : typename OMPropertyModel<MeshT>::TypeInfoWrapperSet(propertyTypes, propertyTypes + 6));
//    supportedPropertyTypes = typename OMPropertyModel<MeshT>::TypeInfoWrapperSet();
//#endif
790

791
}