OMPropertyVisualizerSkinWeightsT_impl.hh 7.81 KB
Newer Older
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
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

#ifdef ENABLE_SKELETON_SUPPORT

#define OM_PROPERTY_VISUALIZER_SKIN_WEIGHTS_CC

#include "OMPropertyVisualizerSkinWeights.hh"

template <typename MeshT>
52
OMPropertyVisualizerSkinWeights<MeshT>::OMPropertyVisualizerSkinWeights(MeshT* _mesh, int _objectID, const PropertyInfo& _propertyInfo)
53
    : OMPropertyVisualizer<MeshT>(_mesh, _objectID, _propertyInfo)
54 55 56 57 58 59 60 61 62 63 64 65 66 67
{
    if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
    SkinWeightsWidget* w = new SkinWeightsWidget();
    w->paramSkinWeights->setTitle(QString("SkinWeights Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
    PropertyVisualizer::widget = w;
}

template <typename MeshT>
QString OMPropertyVisualizerSkinWeights<MeshT>::getPropertyText(unsigned int index)
{
    return OMPropertyVisualizer<MeshT>::template getPropertyText_<BaseSkin::SkinWeights>(index);
}

template <typename MeshT>
68
void OMPropertyVisualizerSkinWeights<MeshT>::visualizeFaceProp(bool /*_setDrawMode*/)
69 70 71 72 73
{
    OMPropertyVisualizer<MeshT>::log("Visualizing SkinWeights for faces not supported.");
}

template <typename MeshT>
74
void OMPropertyVisualizerSkinWeights<MeshT>::visualizeEdgeProp(bool /*_setDrawMode*/)
75 76 77 78 79
{
    OMPropertyVisualizer<MeshT>::log("Visualizing SkinWeights for edges not supported.");
}

template <typename MeshT>
80
void OMPropertyVisualizerSkinWeights<MeshT>::visualizeHalfedgeProp(bool /*_setDrawMode*/)
81 82 83 84 85
{
    OMPropertyVisualizer<MeshT>::log("Visualizing SkinWeights for halfedges not supported.");
}

template <typename MeshT>
86
void OMPropertyVisualizerSkinWeights<MeshT>::visualizeVertexProp(bool _setDrawMode)
87 88 89 90 91 92 93 94 95 96 97 98 99 100
{
    SkinWeightsWidget* skinWeightsWidget = static_cast<SkinWeightsWidget*>(PropertyVisualizer::widget);

    OpenMesh::VPropHandleT< BaseSkin::SkinWeights  > prop;

    if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
        return;

    // Request vertex colors if required
    if ( !OMPropertyVisualizer<MeshT>::mesh->has_vertex_colors() )
        OMPropertyVisualizer<MeshT>::mesh->request_vertex_colors();

    for (typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){

Matthias Möller's avatar
Matthias Möller committed
101
        BaseSkin::SkinWeights weight = OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it);
102 103 104 105 106 107 108 109 110 111

        double value = 0.0;
        if ( weight.find( skinWeightsWidget->boneId->value() ) != weight.end() ) {
            value = weight[skinWeightsWidget->boneId->value()];
        }


        typename MeshT::Color color(value,1.0-value,0.0,1.0);

        // set color
Matthias Möller's avatar
Matthias Möller committed
112
        OMPropertyVisualizer<MeshT>::mesh->set_color(*v_it, color);
113 114
    }

115 116
    if (_setDrawMode)
        PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_POINTS_COLORED);
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
}

template<typename MeshT>
void OMPropertyVisualizerSkinWeights<MeshT>::removeProperty()
{
    OMPropertyVisualizer<MeshT>::template removeProperty_stage1<BaseSkin::SkinWeights>();
}


template<typename MeshT>
void OMPropertyVisualizerSkinWeights<MeshT>::duplicateProperty()
{
    OMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<BaseSkin::SkinWeights>();
}

template<typename MeshT>
void OMPropertyVisualizerSkinWeights<MeshT>::setFacePropertyFromText(unsigned int index, QString text)
{
    OMPropertyVisualizer<MeshT>::log("Setting SkinWeights for faces not supported.");
}

template<typename MeshT>
void OMPropertyVisualizerSkinWeights<MeshT>::setEdgePropertyFromText(unsigned int index, QString text)
{
    OMPropertyVisualizer<MeshT>::log("Setting SkinWeights for edges not supported.");
}

template<typename MeshT>
void OMPropertyVisualizerSkinWeights<MeshT>::setHalfedgePropertyFromText(unsigned int index, QString text)
{
    OMPropertyVisualizer<MeshT>::log("Setting SkinWeights for halfedges not supported.");
}

template<typename MeshT>
void OMPropertyVisualizerSkinWeights<MeshT>::setVertexPropertyFromText(unsigned int index, QString text)
{
    OpenMesh::VPropHandleT< BaseSkin::SkinWeights > prop;
    MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;

    if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
157
        emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
158 159 160 161 162 163 164 165 166 167

    typename MeshT::VertexHandle vh = mesh->vertex_handle(index);

    BaseSkin::SkinWeights sw;

    text.remove(0,1);
    text.remove(text.length()-1, 1);

    QStringList slAll = text.split(")(");

Jan Möbius's avatar
Jan Möbius committed
168
    for (QStringList::iterator it = slAll.begin(); it != slAll.end(); ++it)
169 170 171 172 173 174 175 176 177
    {
        QStringList slCurrent = it->split(",");
        sw.insert(std::pair<int, double>(slCurrent.at(0).toInt(), slCurrent.at(1).toDouble()));
    }

    mesh->property(prop, vh) = sw;
}

#endif /* ENABLE_SKELETON_SUPPORT */