OVMPropertyModelT_impl.hh 36 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 47 48 49 50 51
#define OVM_PROPERTY_MODEL_CC

template <typename MeshT>
OVMPropertyModel<MeshT>::OVMPropertyModel(MeshT* mesh, int objectID, QObject *parent)
    : OVMPropertyModelSubclass(parent),
      mesh_(mesh),
      objectID_(objectID),
      mCombineProperty1(0),
52
      mCombineProperty2(0)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
{
    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") );
Max Lyon's avatar
Max Lyon committed
75

76 77 78
    lastPickMode   = PluginFunctions::pickMode();
    lastActionMode = PluginFunctions::actionMode();

Max Lyon's avatar
Max Lyon committed
79
    initializeSupportedPropertyTypes();
80 81
}

Max Lyon's avatar
Max Lyon committed
82 83
#undef INITIALIZE_PROPTYPES

84 85 86
template <typename MeshT>
void OVMPropertyModel<MeshT>::updateWidget(const QModelIndexList& selectedIndices)
{
87
    SingleObjectPropertyModel::updateWidget(selectedIndices);
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

    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();
111 112 113
        //reset Picking, just if picking was enabled
        if (mPickWidget.pickButton->isChecked())
          resetPicking();
114 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 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
    }

}

template <typename MeshT>
void OVMPropertyModel<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 OVMPropertyModel<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 OVMPropertyModel<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 OVMPropertyModel<MeshT>::mouseEvent(QMouseEvent* _event)
{
    if (!pickModeActive) return;
170
    if (currentlySelectedIndices.size() < 1) return;
171 172 173

    if (_event->type() == QEvent::MouseButtonPress)
    {
174
        size_t         node_idx;
175 176 177
        ACG::Vec3d     hit_point;


178
        OVMPropertyVisualizer<MeshT>* viz = dynamic_cast<OVMPropertyVisualizer<MeshT>*>(propertyVisualizers[currentlySelectedIndices.first().row()]);
179
        size_t entityId = 0;
180 181 182 183 184 185 186 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 217 218 219 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

        ACG::SceneGraph::PickTarget pickTarget;
        if (viz->getPropertyInfo().isCellProp())
            pickTarget = ACG::SceneGraph::PICK_CELL;
        if (viz->getPropertyInfo().isFaceProp())
            pickTarget = ACG::SceneGraph::PICK_FACE;
        if (viz->getPropertyInfo().isHalffaceProp())
            pickTarget = ACG::SceneGraph::PICK_FACE;
        if (viz->getPropertyInfo().isEdgeProp())
            pickTarget = ACG::SceneGraph::PICK_EDGE;
        if (viz->getPropertyInfo().isHalfedgeProp())
            pickTarget = ACG::SceneGraph::PICK_FACE;
        if (viz->getPropertyInfo().isVertexProp())
            pickTarget = ACG::SceneGraph::PICK_VERTEX;

        if (PluginFunctions::scenegraphPick(pickTarget, _event->pos(),node_idx, entityId, &hit_point)) {
            BaseObjectData* object;
            PluginFunctions::getPickedObject(node_idx, object);

            if (object->id() == objectID_)
            {
                if (viz->getPropertyInfo().isHalfedgeProp() || viz->getPropertyInfo().isHalffaceProp())   //cant be picked directly
                    entityId = viz->getClosestPrimitiveId(entityId, hit_point);

                mPickWidget.pickedHandle->setText(tr("%1").arg(entityId));
                mPickWidget.pickedValue->setText(viz->getPropertyText(entityId));
            }
        }

    }
}

template <typename MeshT>
bool OVMPropertyModel<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_CELL:
                nExpected = mesh_->n_cells();
                break;
            case PropertyInfo::EF_FACE:
                nExpected = mesh_->n_faces();
                break;
            case PropertyInfo::EF_HALFFACE:
                nExpected = mesh_->n_halffaces();
                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)
        {
            std::cerr << "unexpected number of entities" << std::endl;
            return false;
        }

        QString friendlyName = headerParts[3];

        if (!isSupported(friendlyName))
        {
            std::cerr << "unsupported property type " << friendlyName.toStdString() << std::endl;
            return false;
        }


263
        TypeInfoWrapper typeInfo = getSupportedTypeInfoWrapper(friendlyName, filter);
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 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 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

        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
    {
        std::cerr << "unsupported header format" << std::endl;
        return false;
    }
}


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

template<typename MeshT>
QString OVMPropertyModel<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 Checks if a property name is still available for an entity type and a property type.
 *
 * @param propName The name of the property.
 * @param filter The entity type of the property.
 * @param typeInfo The type of the property.
 *
 * @return True if the name is still available, False if already in use.
 */
template<typename MeshT>
bool OVMPropertyModel<MeshT>::isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
{
    return getPropertyVisualizer(propName, filter, typeInfo) == 0;
}

/**
 * @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
 * OVMPropertyVisualizerVectorFieldDifference<MeshT> to be exact) but not an additional
 * property.
 */
template<typename MeshT>
void OVMPropertyModel<MeshT>::combine()
{
    beginResetModel();
    propertyVisualizers.push_back(new OVMPropertyVisualizerVectorFieldDifference<MeshT>(mesh_, objectID_, *mCombineProperty1, *mCombineProperty2));
    endResetModel();
}

template<typename MeshT>
void OVMPropertyModel<MeshT>::saveProperty()
{
373
    for (QModelIndexList::const_iterator it = currentlySelectedIndices.begin(), it_end = currentlySelectedIndices.end();
374
                it != it_end; ++it) {
375
        SingleObjectPropertyModel::saveProperty(it->row());
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 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
    }
}

/**
 * @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 OVMPropertyModel<MeshT>::combinable(PropertyVisualizer* propertyVisualizer1, PropertyVisualizer* propertyVisualizer2) const
{
    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 OVMPropertyModel<MeshT>::gatherProperties( MeshT* mesh,
                       typename MeshT::Properties::const_iterator props_first,
                       typename MeshT::Properties::const_iterator props_last,
                       PropertyInfo::ENTITY_FILTER filter)
{
    for (typename MeshT::Properties::const_iterator pit = props_first; pit != props_last; ++pit) {
         OpenVolumeMesh::BaseProperty*const baseProp = *pit;
         if (baseProp && isSupported(baseProp) && isNew(baseProp, filter))
            addPropertyVisualizer(baseProp, mesh, filter);
    }
}


template<typename MeshT>
void OVMPropertyModel<MeshT>::gatherProperties()
{
    beginResetModel();
    if (mesh_) {
        gatherProperties(mesh_, mesh_->face_props_begin(), mesh_->face_props_end(), PropertyInfo::EF_FACE);
        gatherProperties(mesh_, mesh_->edge_props_begin(), mesh_->edge_props_end(), PropertyInfo::EF_EDGE);
        gatherProperties(mesh_, mesh_->halfedge_props_begin(), mesh_->halfedge_props_end(), PropertyInfo::EF_HALFEDGE);
        gatherProperties(mesh_, mesh_->vertex_props_begin(), mesh_->vertex_props_end(), PropertyInfo::EF_VERTEX);
        gatherProperties(mesh_, mesh_->halfface_props_begin(), mesh_->halfface_props_end(), PropertyInfo::EF_HALFFACE);
        gatherProperties(mesh_, mesh_->cell_props_begin(), mesh_->cell_props_end(), PropertyInfo::EF_CELL);
    }
    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 OVMPropertyModel<MeshT>::isSupported(OpenVolumeMesh::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"
 * and "Vec3f"
 */
template<typename MeshT>
bool OVMPropertyModel<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 OVMPropertyModel<MeshT>::isNew(OpenVolumeMesh::BaseProperty* const baseProp, PropertyInfo::ENTITY_FILTER filter) const
{
    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 OVMPropertyModel<MeshT>::getSupportedTypeInfoWrapper(OpenVolumeMesh::BaseProperty* const baseProp) const
{
    TypeInfoWrapper bp_type = typeid(*baseProp);
    TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
    if (propIt != supportedPropertyTypes.end())
        return *propIt;
    else
    {
        std::cerr << "error" << std::endl;
        return *propIt;
    }
}

/**
514
 * @brief Returns the TypeInfoWrapper for the type of property and entity if it is supported.
515 516
 *
 * @param friendlyName The type we want to visualize in text form.
517
 * @param filter The type of the entity
518 519 520 521
 *
 * @return A TypeInfoWrapper containing all the type information for the property type.
 */
template<typename MeshT>
522
TypeInfoWrapper OVMPropertyModel<MeshT>::getSupportedTypeInfoWrapper(QString friendlyName, PropertyInfo::ENTITY_FILTER filter) const
523 524 525 526 527 528
{

    for (TypeInfoWrapperSet::const_iterator it =  supportedPropertyTypes.begin();
                                            it != supportedPropertyTypes.end();
                                          ++it )
    {
529
        if ((friendlyName.toStdString().compare(it->getName()) == 0) && isEntityType(*it, filter))
530 531 532 533 534 535
            return *it;
    }
    throw std::exception();
}

template<typename MeshT>
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
bool OVMPropertyModel<MeshT>::isBoolType(const PropertyInfo& propInfo)
{
    return isBoolType(propInfo.typeinfo());
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isBoolType(const TypeInfoWrapper& typeInfo)
{
    return typeInfo == proptype_Cell_bool ||
           typeInfo == proptype_Face_bool ||
           typeInfo == proptype_HalfFace_bool ||
           typeInfo == proptype_Edge_bool ||
           typeInfo == proptype_HalfEdge_bool ||
           typeInfo == proptype_Vertex_bool;
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isIntType(const PropertyInfo& propInfo)
{
    return isIntType(propInfo.typeinfo());
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isIntType(const TypeInfoWrapper& typeInfo)
560
{
561 562 563 564 565 566
    return typeInfo == proptype_Cell_int ||
           typeInfo == proptype_Face_int ||
           typeInfo == proptype_HalfFace_int ||
           typeInfo == proptype_Edge_int ||
           typeInfo == proptype_HalfEdge_int ||
           typeInfo == proptype_Vertex_int;
567 568 569
}

template<typename MeshT>
570
bool OVMPropertyModel<MeshT>::isDoubleType(const PropertyInfo& propInfo)
571
{
572
    return isDoubleType(propInfo.typeinfo());
573 574 575
}

template<typename MeshT>
576
bool OVMPropertyModel<MeshT>::isDoubleType(const TypeInfoWrapper& typeInfo)
577
{
578 579 580 581 582 583
    return typeInfo == proptype_Cell_double ||
           typeInfo == proptype_Face_double ||
           typeInfo == proptype_HalfFace_double ||
           typeInfo == proptype_Edge_double ||
           typeInfo == proptype_HalfEdge_double ||
           typeInfo == proptype_Vertex_double;
584 585 586
}

template<typename MeshT>
587
bool OVMPropertyModel<MeshT>::isUnsignedIntType(const PropertyInfo& propInfo)
588
{
589
    return isUnsignedIntType(propInfo.typeinfo());
590 591 592
}

template<typename MeshT>
593
bool OVMPropertyModel<MeshT>::isUnsignedIntType(const TypeInfoWrapper& typeInfo)
594
{
595 596 597 598 599 600
    return typeInfo == proptype_Cell_uint ||
           typeInfo == proptype_Face_uint ||
           typeInfo == proptype_HalfFace_uint ||
           typeInfo == proptype_Edge_uint ||
           typeInfo == proptype_HalfEdge_uint ||
           typeInfo == proptype_Vertex_uint;
601 602 603
}

template<typename MeshT>
604
bool OVMPropertyModel<MeshT>::isVec3dType(const PropertyInfo& propInfo)
605
{
606
    return isVec3dType(propInfo.typeinfo());
607 608 609
}

template<typename MeshT>
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
bool OVMPropertyModel<MeshT>::isVec3dType(const TypeInfoWrapper& typeInfo)
{
    return typeInfo == proptype_Cell_Vec3d ||
           typeInfo == proptype_Face_Vec3d ||
           typeInfo == proptype_HalfFace_Vec3d ||
           typeInfo == proptype_Edge_Vec3d ||
           typeInfo == proptype_HalfEdge_Vec3d ||
           typeInfo == proptype_Vertex_Vec3d;
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isVec3fType(const PropertyInfo& propInfo)
{
    return isVec3fType(propInfo.typeinfo());
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isVec3fType(const TypeInfoWrapper& typeInfo)
{
    return typeInfo == proptype_Cell_Vec3f ||
           typeInfo == proptype_Face_Vec3f ||
           typeInfo == proptype_HalfFace_Vec3f ||
           typeInfo == proptype_Edge_Vec3f ||
           typeInfo == proptype_HalfEdge_Vec3f ||
           typeInfo == proptype_Vertex_Vec3f;
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isVectorType(const PropertyInfo& propInfo)
639 640 641 642
{
    return isVec3fType(propInfo) || isVec3dType(propInfo);
}

643 644 645 646 647 648
template<typename MeshT>
bool OVMPropertyModel<MeshT>::isVectorType(const TypeInfoWrapper& typeInfo)
{
    return isVec3fType(typeInfo) || isVec3dType(typeInfo);
}

649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
template<typename MeshT>
bool OVMPropertyModel<MeshT>::isMatrix3x3Type(const PropertyInfo& propInfo)
{
    return isMatrix3x3Type(propInfo.typeinfo());
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isMatrix3x3Type(const TypeInfoWrapper& typeInfo)
{
    return typeInfo == proptype_Cell_Matrix3x3d ||
           typeInfo == proptype_Face_Matrix3x3d ||
           typeInfo == proptype_HalfFace_Matrix3x3d ||
           typeInfo == proptype_Edge_Matrix3x3d ||
           typeInfo == proptype_HalfEdge_Matrix3x3d ||
           typeInfo == proptype_Vertex_Matrix3x3d;
}

666 667 668 669 670 671 672 673 674 675 676
template<typename MeshT>
bool OVMPropertyModel<MeshT>::isEntityType(const TypeInfoWrapper& typeInfo, PropertyInfo::ENTITY_FILTER entity_type) const
{
    bool result = false;
    if (entity_type & PropertyInfo::EF_CELL)
    {
        result |=    (typeInfo == proptype_Cell_bool)
                  || (typeInfo == proptype_Cell_int)
                  || (typeInfo == proptype_Cell_double)
                  || (typeInfo == proptype_Cell_uint)
                  || (typeInfo == proptype_Cell_Vec3d)
677
                  || (typeInfo == proptype_Cell_Vec3f);
678 679 680 681 682 683 684 685
    }
    if (entity_type & PropertyInfo::EF_FACE)
    {
        result |=    (typeInfo == proptype_Face_bool)
                  || (typeInfo == proptype_Face_int)
                  || (typeInfo == proptype_Face_double)
                  || (typeInfo == proptype_Face_uint)
                  || (typeInfo == proptype_Face_Vec3d)
686
                  || (typeInfo == proptype_Face_Vec3f);
687 688 689 690 691 692 693 694
    }
    if (entity_type & PropertyInfo::EF_HALFFACE)
    {
        result |=    (typeInfo == proptype_HalfFace_bool)
                  || (typeInfo == proptype_HalfFace_int)
                  || (typeInfo == proptype_HalfFace_double)
                  || (typeInfo == proptype_HalfFace_uint)
                  || (typeInfo == proptype_HalfFace_Vec3d)
695
                  || (typeInfo == proptype_HalfFace_Vec3f);
696 697 698 699 700 701 702 703
    }
    if (entity_type & PropertyInfo::EF_EDGE)
    {
        result |=    (typeInfo == proptype_Edge_bool)
                  || (typeInfo == proptype_Edge_int)
                  || (typeInfo == proptype_Edge_double)
                  || (typeInfo == proptype_Edge_uint)
                  || (typeInfo == proptype_Edge_Vec3d)
704
                  || (typeInfo == proptype_Edge_Vec3f);
705 706 707 708 709 710 711 712
    }
    if (entity_type & PropertyInfo::EF_HALFEDGE)
    {
        result |=    (typeInfo == proptype_HalfEdge_bool)
                  || (typeInfo == proptype_HalfEdge_int)
                  || (typeInfo == proptype_HalfEdge_double)
                  || (typeInfo == proptype_HalfEdge_uint)
                  || (typeInfo == proptype_HalfEdge_Vec3d)
713
                  || (typeInfo == proptype_HalfEdge_Vec3f);
714 715 716 717 718 719 720 721
    }
    if (entity_type & PropertyInfo::EF_VERTEX)
    {
        result |=    (typeInfo == proptype_Vertex_bool)
                  || (typeInfo == proptype_Vertex_int)
                  || (typeInfo == proptype_Vertex_double)
                  || (typeInfo == proptype_Vertex_uint)
                  || (typeInfo == proptype_Vertex_Vec3d)
722
                  || (typeInfo == proptype_Vertex_Vec3f);
723 724 725 726 727
    }
    return result;
}


728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
/**
 * @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 OVMPropertyModel<MeshT>::addPropertyVisualizer(OpenVolumeMesh::BaseProperty* const baseProp, MeshT* mesh, PropertyInfo::ENTITY_FILTER filter)
{
    PropertyInfo propInfo = PropertyInfo(baseProp->name(), getSupportedTypeInfoWrapper(baseProp) , filter);
    if (isBoolType(propInfo))
        propertyVisualizers.push_back(new OVMPropertyVisualizerBoolean<MeshT>(mesh, objectID_, propInfo));
    else if (isIntType(propInfo))
        propertyVisualizers.push_back(new OVMPropertyVisualizerInteger<MeshT, int>(mesh, objectID_, propInfo, false));
    else if (isUnsignedIntType(propInfo))
        propertyVisualizers.push_back(new OVMPropertyVisualizerInteger<MeshT, unsigned int>(mesh, objectID_, propInfo, true));
    else if (isDoubleType(propInfo))
        propertyVisualizers.push_back(new OVMPropertyVisualizerDouble<MeshT>(mesh, objectID_, propInfo));
    else if (isVectorType(propInfo))
        propertyVisualizers.push_back(new OVMPropertyVisualizerVector<MeshT>(mesh, objectID_, propInfo));
752 753
    else if (isMatrix3x3Type(propInfo))
        propertyVisualizers.push_back(new OVMPropertyVisualizerMatrix3x3<MeshT>(mesh, objectID_, propInfo));
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
    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.
 */
template<typename MeshT>
void OVMPropertyModel<MeshT>::addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
{

    QString dtype = friendlyTypeName;
    std::string pname = propName.toStdString();

    MeshT* mesh = mesh_;

    if ( filter == PropertyInfo::EF_VERTEX )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenVolumeMesh::VertexPropertyT< ACG::Vec3d > prop = mesh->template request_vertex_property< ACG::Vec3d >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("double") )
        {
            OpenVolumeMesh::VertexPropertyT< double > prop = mesh->template request_vertex_property< double >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("unsigned int") )
        {
            OpenVolumeMesh::VertexPropertyT< unsigned int > prop = mesh->template request_vertex_property< unsigned int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("int") )
        {
            OpenVolumeMesh::VertexPropertyT< int > prop = mesh->template request_vertex_property< int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("bool") )
        {
            OpenVolumeMesh::VertexPropertyT< bool > prop = mesh->template request_vertex_property< bool >(pname);
            mesh->set_persistent(prop, true);
        }
    }
    else if ( filter == PropertyInfo::EF_EDGE )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenVolumeMesh::EdgePropertyT< ACG::Vec3d > prop = mesh->template request_edge_property< ACG::Vec3d >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("double") )
        {
            OpenVolumeMesh::EdgePropertyT< double > prop = mesh->template request_edge_property< double >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("unsgined int") )
        {
            OpenVolumeMesh::EdgePropertyT< unsigned int > prop = mesh->template request_edge_property< unsigned int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("int") )
        {
            OpenVolumeMesh::EdgePropertyT< int > prop = mesh->template request_edge_property< int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("bool") )
        {
            OpenVolumeMesh::EdgePropertyT< bool > prop = mesh->template request_edge_property< bool >(pname);
            mesh->set_persistent(prop, true);
        }
    }
    else if ( filter == PropertyInfo::EF_FACE )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenVolumeMesh::FacePropertyT< ACG::Vec3d > prop = mesh->template request_face_property< ACG::Vec3d >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("double") )
        {
            OpenVolumeMesh::FacePropertyT< double > prop = mesh->template request_face_property< double >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("unsigned int") )
        {
            OpenVolumeMesh::FacePropertyT< unsigned int > prop = mesh->template request_face_property< unsigned int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("int") )
        {
            OpenVolumeMesh::FacePropertyT< int > prop = mesh->template request_face_property< int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("bool") )
        {
            OpenVolumeMesh::FacePropertyT< bool > prop = mesh->template request_face_property< bool >(pname);
            mesh->set_persistent(prop, true);
        }
    }
    else if ( filter == PropertyInfo::EF_HALFEDGE )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenVolumeMesh::HalfEdgePropertyT< ACG::Vec3d > prop = mesh->template request_halfedge_property< ACG::Vec3d >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("double") )
        {
            OpenVolumeMesh::HalfEdgePropertyT< double > prop = mesh->template request_halfedge_property< double >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("unsigned int") )
        {
            OpenVolumeMesh::HalfEdgePropertyT< unsigned int > prop = mesh->template request_halfedge_property< unsigned int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("int") )
        {
            OpenVolumeMesh::HalfEdgePropertyT< int > prop = mesh->template request_halfedge_property< int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("bool") )
        {
            OpenVolumeMesh::HalfEdgePropertyT< bool > prop = mesh->template request_halfedge_property< bool >(pname);
            mesh->set_persistent(prop, true);
        }
    }
    else if ( filter == PropertyInfo::EF_HALFFACE )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenVolumeMesh::HalfFacePropertyT< ACG::Vec3d > prop = mesh->template request_halfface_property< ACG::Vec3d >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("double") )
        {
            OpenVolumeMesh::HalfFacePropertyT< double > prop = mesh->template request_halfface_property< double >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("unsigned int") )
        {
            OpenVolumeMesh::HalfFacePropertyT< unsigned int > prop = mesh->template request_halfface_property< unsigned int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("int") )
        {
            OpenVolumeMesh::HalfFacePropertyT< int > prop = mesh->template request_halfface_property< int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("bool") )
        {
            OpenVolumeMesh::HalfFacePropertyT< bool > prop = mesh->template request_halfface_property< bool >(pname);
            mesh->set_persistent(prop, true);
        }
    }
    else if ( filter == PropertyInfo::EF_CELL )
    {
        if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
        {
            OpenVolumeMesh::CellPropertyT< ACG::Vec3d > prop = mesh->template request_cell_property< ACG::Vec3d >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("double") )
        {
            OpenVolumeMesh::CellPropertyT< double > prop = mesh->template request_cell_property< double >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("unsigned int") )
        {
            OpenVolumeMesh::CellPropertyT< unsigned int > prop = mesh->template request_cell_property< unsigned int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("int") )
        {
            OpenVolumeMesh::CellPropertyT< int > prop = mesh->template request_cell_property< int >(pname);
            mesh->set_persistent(prop, true);
        }
        else if ( dtype == tr("bool") )
        {
            OpenVolumeMesh::CellPropertyT< bool > prop = mesh->template request_cell_property< bool >(pname);
            mesh->set_persistent(prop, true);
        }
    }

Max Lyon's avatar
Max Lyon committed
945 946 947 948 949
}

template <typename MeshT>
void OVMPropertyModel<MeshT>::initializeSupportedPropertyTypes()
{
950

Max Lyon's avatar
Max Lyon committed
951 952 953 954 955 956 957
#define INSERT_PROPTYPES(primitive) \
supportedPropertyTypes.insert(proptype_##primitive##_bool);   \
supportedPropertyTypes.insert(proptype_##primitive##_int);    \
supportedPropertyTypes.insert(proptype_##primitive##_uint);   \
supportedPropertyTypes.insert(proptype_##primitive##_double); \
supportedPropertyTypes.insert(proptype_##primitive##_Vec3d);  \
supportedPropertyTypes.insert(proptype_##primitive##_Vec3f);  \
958
supportedPropertyTypes.insert(proptype_##primitive##_Matrix3x3d);  \
Max Lyon's avatar
Max Lyon committed
959 960 961 962 963 964 965 966 967 968

    INSERT_PROPTYPES(Cell)
    INSERT_PROPTYPES(Face)
    INSERT_PROPTYPES(HalfFace)
    INSERT_PROPTYPES(Edge)
    INSERT_PROPTYPES(HalfEdge)
    INSERT_PROPTYPES(Vertex)

#undef INITIALIZE_PROPTYPES

969 970


971 972
}