OMPropertyVisualizerBooleanT.cc 9.89 KB
Newer Older
1 2 3 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 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
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
*                           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/>.                                       *
*                                                                            *
\*===========================================================================*/

#define OM_PROPERTY_VISUALIZER_BOOLEAN_CC

#include "OMPropertyVisualizerBoolean.hh"

template <typename MeshT>
OMPropertyVisualizerBoolean<MeshT>::OMPropertyVisualizerBoolean(MeshT* _mesh, PropertyInfo _propertyInfo)
    : OMPropertyVisualizer<MeshT>(_mesh, _propertyInfo)
{
    if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
    BooleanWidget* w = new BooleanWidget();
    w->paramBool->setTitle(QString("Boolean Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
    PropertyVisualizer::widget = w;
}

template <typename MeshT>
QString OMPropertyVisualizerBoolean<MeshT>::getPropertyText(unsigned int index)
{
    return OMPropertyVisualizer<MeshT>::template getPropertyText_<bool>(index);
}

template <typename MeshT>
void OMPropertyVisualizerBoolean<MeshT>::visualizeFaceProp()
{
    BooleanWidget* booleanWidget = static_cast<BooleanWidget*>(PropertyVisualizer::widget);
    MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
    typename MeshT::Color colorTrue, colorFalse;

    colorTrue  = OMPropertyVisualizer<MeshT>::convertColor(booleanWidget->colorTrue->color());
    colorFalse = OMPropertyVisualizer<MeshT>::convertColor(booleanWidget->colorFalse->color());

    OpenMesh::FPropHandleT< bool > prop;

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

    if ( !mesh->has_face_colors() )
        OMPropertyVisualizer<MeshT>::mesh->request_face_colors();

    for (typename MeshT::FaceIter f_it = mesh->faces_begin() ; f_it != mesh->faces_end() ; ++f_it)
        if ( mesh->property(prop, f_it) )
            mesh->set_color(f_it, colorTrue);
        else
            mesh->set_color(f_it, colorFalse);

    PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED);

}

template <typename MeshT>
void OMPropertyVisualizerBoolean<MeshT>::visualizeEdgeProp()
{
    BooleanWidget* booleanWidget = static_cast<BooleanWidget*>(PropertyVisualizer::widget);
    MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
    typename MeshT::Color colorTrue, colorFalse;

    colorTrue  = OMPropertyVisualizer<MeshT>::convertColor(booleanWidget->colorTrue->color());
    colorFalse = OMPropertyVisualizer<MeshT>::convertColor(booleanWidget->colorFalse->color());

    OpenMesh::EPropHandleT< bool > prop;

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

    if ( !mesh->has_edge_colors() )
        mesh->request_edge_colors();

    for (typename MeshT::EdgeIter e_it = mesh->edges_begin() ; e_it != mesh->edges_end() ; ++e_it)
        if ( mesh->property(prop, e_it) )
            mesh->set_color(e_it, colorTrue);
        else
            mesh->set_color(e_it, colorFalse);

    PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::EDGES_COLORED);
}

template <typename MeshT>
void OMPropertyVisualizerBoolean<MeshT>::visualizeHalfedgeProp()
{
    BooleanWidget* booleanWidget = static_cast<BooleanWidget*>(PropertyVisualizer::widget);
    MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
    typename MeshT::Color colorTrue, colorFalse;

    colorTrue  = OMPropertyVisualizer<MeshT>::convertColor(booleanWidget->colorTrue->color());
    colorFalse = OMPropertyVisualizer<MeshT>::convertColor(booleanWidget->colorFalse->color());

    OpenMesh::HPropHandleT< bool > prop;

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

    if ( ! mesh->has_halfedge_colors() )
        mesh->request_halfedge_colors();

    for (typename MeshT::HalfedgeIter he_it = mesh->halfedges_begin() ; he_it != mesh->halfedges_end() ; ++he_it)
        if ( mesh->property(prop, he_it) )
            mesh->set_color(he_it, colorTrue);
        else
            mesh->set_color(he_it, colorFalse);

    PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::HALFEDGES_COLORED);

}

template <typename MeshT>
void OMPropertyVisualizerBoolean<MeshT>::visualizeVertexProp()
{
    BooleanWidget* booleanWidget = static_cast<BooleanWidget*>(PropertyVisualizer::widget);
    MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
    typename MeshT::Color colorTrue, colorFalse;

    colorTrue  = OMPropertyVisualizer<MeshT>::convertColor(booleanWidget->colorTrue->color());
    colorFalse = OMPropertyVisualizer<MeshT>::convertColor(booleanWidget->colorFalse->color());

    OpenMesh::VPropHandleT< bool > prop;

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

    if ( ! mesh->has_vertex_colors() )
        mesh->request_vertex_colors();

    for (typename MeshT::VertexIter v_it = mesh->vertices_begin() ; v_it != mesh->vertices_end() ; ++v_it)
        if ( mesh->property(prop, v_it) )
            mesh->set_color(v_it, colorTrue);
        else
            mesh->set_color(v_it, colorFalse);

    PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_POINTS_COLORED);

}

template <typename MeshT>
void OMPropertyVisualizerBoolean<MeshT>::setFacePropertyFromText(unsigned int index, QString text)
{
    OpenMesh::FPropHandleT< bool > prop;
    MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;

    if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
Mike Kremer's avatar
Mike Kremer committed
173
        std::cerr << "Error: No property with name " <<  PropertyVisualizer::propertyInfo.propName().c_str() << std::endl;
174 175 176 177 178 179 180 181 182 183 184 185 186 187


    typename MeshT::FaceHandle fh = mesh->face_handle(index);

    mesh->property(prop, fh) = this->strToBool(text);
}

template <typename MeshT>
void OMPropertyVisualizerBoolean<MeshT>::setEdgePropertyFromText(unsigned int index, QString text)
{
    OpenMesh::EPropHandleT< bool > prop;
    MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;

    if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
Mike Kremer's avatar
Mike Kremer committed
188
        std::cerr << "Error: No property with name " <<  PropertyVisualizer::propertyInfo.propName().c_str() << std::endl;
189 190 191 192 193 194 195 196 197 198 199 200 201 202


    typename MeshT::EdgeHandle eh = mesh->edge_handle(index);

    mesh->property(prop, eh) = this->strToBool(text);
}

template <typename MeshT>
void OMPropertyVisualizerBoolean<MeshT>::setHalfedgePropertyFromText(unsigned int index, QString text)
{
    OpenMesh::HPropHandleT< bool > prop;
    MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;

    if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
Mike Kremer's avatar
Mike Kremer committed
203
        std::cerr << "Error: No property with name " <<  PropertyVisualizer::propertyInfo.propName().c_str() << std::endl;
204 205 206 207 208 209 210 211 212 213 214 215 216 217


    typename MeshT::HalfedgeHandle heh = mesh->halfedge_handle(index);

    mesh->property(prop, heh) = this->strToBool(text);
}

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

    if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
Mike Kremer's avatar
Mike Kremer committed
218
        std::cerr << "Error: No property with name " <<  PropertyVisualizer::propertyInfo.propName().c_str() << std::endl;
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236


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

    mesh->property(prop, vh) = this->strToBool(text);
}

template<typename MeshT>
void OMPropertyVisualizerBoolean<MeshT>::removeProperty()
{
    OMPropertyVisualizer<MeshT>::template removeProperty_stage1<bool>();
}

template<typename MeshT>
void OMPropertyVisualizerBoolean<MeshT>::duplicateProperty()
{
    OMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<bool>();
}