OVMPropertyModelT.cc 36.2 KB
Newer Older
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen       *
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
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
\*===========================================================================*/

35 36 37 38 39 40 41 42
/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/

43 44 45 46 47 48
#ifdef ENABLE_OPENVOLUMEMESH_SUPPORT

#define OVM_PROPERTY_MODEL_CC

#include "OVMPropertyModel.hh"

Max Lyon's avatar
Max Lyon committed
49 50 51 52 53 54 55 56 57
#define INITIALIZE_PROPTYPES(primitive)                                                                                       \
    proptype_##primitive##_bool(TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<bool>), "bool")),                 \
    proptype_##primitive##_int(TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<int>), "int")),                     \
    proptype_##primitive##_uint(TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<unsigned int>), "unsigned int")),   \
    proptype_##primitive##_double(TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<double>), "double")),             \
    proptype_##primitive##_Vec3d(TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3d>), "Vec3d")),           \
    proptype_##primitive##_Vec3f(TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3f>), "Vec3f"))


58 59 60 61 62 63
template <typename MeshT>
OVMPropertyModel<MeshT>::OVMPropertyModel(MeshT* mesh, int objectID, QObject *parent)
    : OVMPropertyModelSubclass(parent),
      mesh_(mesh),
      objectID_(objectID),
      mCombineProperty1(0),
Max Lyon's avatar
Max Lyon committed
64 65 66 67 68 69 70
      mCombineProperty2(0),
      INITIALIZE_PROPTYPES(Cell),
      INITIALIZE_PROPTYPES(Face),
      INITIALIZE_PROPTYPES(HalfFace),
      INITIALIZE_PROPTYPES(Edge),
      INITIALIZE_PROPTYPES(HalfEdge),
      INITIALIZE_PROPTYPES(Vertex)
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
{
    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
93 94

    initializeSupportedPropertyTypes();
95 96
}

Max Lyon's avatar
Max Lyon committed
97 98
#undef INITIALIZE_PROPTYPES

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 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 170 171 172 173 174 175 176 177 178 179 180 181 182
template <typename MeshT>
void OVMPropertyModel<MeshT>::updateWidget(const QModelIndexList& selectedIndices)
{
    PropertyModel::updateWidget(selectedIndices);

    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();
        resetPicking();
    }

}

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;
183
    if (currentlySelectedIndices.size() < 1) return;
184 185 186 187 188 189 190

    if (_event->type() == QEvent::MouseButtonPress)
    {
        unsigned int   node_idx;
        ACG::Vec3d     hit_point;


191
        OVMPropertyVisualizer<MeshT>* viz = dynamic_cast<OVMPropertyVisualizer<MeshT>*>(propertyVisualizers[currentlySelectedIndices.first().row()]);
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 263 264 265 266 267 268 269 270 271 272 273 274 275
        unsigned int entityId = 0;

        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;
        }


276
        TypeInfoWrapper typeInfo = getSupportedTypeInfoWrapper(friendlyName, filter);
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 373 374 375 376 377 378 379 380 381 382 383 384 385

        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()
{
386
    for (QModelIndexList::const_iterator it = currentlySelectedIndices.begin(), it_end = currentlySelectedIndices.end();
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 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
                it != it_end; ++it) {
        PropertyModel::saveProperty(it->row());
    }
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isVectorType(const TypeInfoWrapper& typeInfo) const
{
    return     (typeInfo == proptype_Cell_Vec3f)     || (typeInfo == proptype_Cell_Vec3d)
            || (typeInfo == proptype_Face_Vec3f)     || (typeInfo == proptype_Face_Vec3d)
            || (typeInfo == proptype_HalfFace_Vec3f) || (typeInfo == proptype_HalfFace_Vec3d)
            || (typeInfo == proptype_Edge_Vec3f)     || (typeInfo == proptype_Edge_Vec3d)
            || (typeInfo == proptype_HalfEdge_Vec3f) || (typeInfo == proptype_HalfEdge_Vec3d)
            || (typeInfo == proptype_Vertex_Vec3f)   || (typeInfo == proptype_Vertex_Vec3d);
}

/**
 * @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;
    }
}

/**
538
 * @brief Returns the TypeInfoWrapper for the type of property and entity if it is supported.
539 540
 *
 * @param friendlyName The type we want to visualize in text form.
541
 * @param filter The type of the entity
542 543 544 545
 *
 * @return A TypeInfoWrapper containing all the type information for the property type.
 */
template<typename MeshT>
546
TypeInfoWrapper OVMPropertyModel<MeshT>::getSupportedTypeInfoWrapper(QString friendlyName, PropertyInfo::ENTITY_FILTER filter) const
547 548 549 550 551 552
{

    for (TypeInfoWrapperSet::const_iterator it =  supportedPropertyTypes.begin();
                                            it != supportedPropertyTypes.end();
                                          ++it )
    {
553
        if ((friendlyName.toStdString().compare(it->getName()) == 0) && isEntityType(*it, filter))
554 555 556 557 558 559 560 561 562 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 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
            return *it;
    }
    throw std::exception();
}

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

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isIntType(const PropertyInfo& propInfo) const
{
    return propInfo.typeinfo() == proptype_Cell_int ||
           propInfo.typeinfo() == proptype_Face_int ||
           propInfo.typeinfo() == proptype_HalfFace_int ||
           propInfo.typeinfo() == proptype_Edge_int ||
           propInfo.typeinfo() == proptype_HalfEdge_int ||
           propInfo.typeinfo() == proptype_Vertex_int;
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isDoubleType(const PropertyInfo& propInfo) const
{
    return propInfo.typeinfo() == proptype_Cell_double ||
           propInfo.typeinfo() == proptype_Face_double ||
           propInfo.typeinfo() == proptype_HalfFace_double ||
           propInfo.typeinfo() == proptype_Edge_double ||
           propInfo.typeinfo() == proptype_HalfEdge_double ||
           propInfo.typeinfo() == proptype_Vertex_double;
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isUnsignedIntType(const PropertyInfo& propInfo) const
{
    return propInfo.typeinfo() == proptype_Cell_uint ||
           propInfo.typeinfo() == proptype_Face_uint ||
           propInfo.typeinfo() == proptype_HalfFace_uint ||
           propInfo.typeinfo() == proptype_Edge_uint ||
           propInfo.typeinfo() == proptype_HalfEdge_uint ||
           propInfo.typeinfo() == proptype_Vertex_uint;
}

template<typename MeshT>
bool OVMPropertyModel<MeshT>::isVec3dType(const PropertyInfo& propInfo) const
{
    return propInfo.typeinfo() == proptype_Cell_Vec3d ||
           propInfo.typeinfo() == proptype_Face_Vec3d ||
           propInfo.typeinfo() == proptype_HalfFace_Vec3d ||
           propInfo.typeinfo() == proptype_Edge_Vec3d ||
           propInfo.typeinfo() == proptype_HalfEdge_Vec3d ||
           propInfo.typeinfo() == proptype_Vertex_Vec3d;
}

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

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

631 632 633 634 635 636 637 638 639 640 641
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)
642
                  || (typeInfo == proptype_Cell_Vec3f);
643 644 645 646 647 648 649 650
    }
    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)
651
                  || (typeInfo == proptype_Face_Vec3f);
652 653 654 655 656 657 658 659
    }
    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)
660
                  || (typeInfo == proptype_HalfFace_Vec3f);
661 662 663 664 665 666 667 668
    }
    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)
669
                  || (typeInfo == proptype_Edge_Vec3f);
670 671 672 673 674 675 676 677
    }
    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)
678
                  || (typeInfo == proptype_HalfEdge_Vec3f);
679 680 681 682 683 684 685 686
    }
    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)
687
                  || (typeInfo == proptype_Vertex_Vec3f);
688 689 690 691 692
    }
    return result;
}


693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 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
/**
 * @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));
    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
908 909 910 911 912
}

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

Max Lyon's avatar
Max Lyon committed
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
#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);  \

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

#undef INITIALIZE_PROPTYPES

931 932


933 934 935
}

#endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */