/*===========================================================================*\ * * * OpenFlipper * * 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. * * * \*===========================================================================*/ /*===========================================================================*\ * * * $Revision$ * * $LastChangedBy$ * * $Date$ * * * \*===========================================================================*/ #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT #define OVM_PROPERTY_VISUALIZER_VECTOR_CC #include #include "OVMPropertyVisualizerVector.hh" template OVMPropertyVisualizerVector::OVMPropertyVisualizerVector(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo) : OVMPropertyVisualizer(_mesh, objectID, _propertyInfo) { if (PropertyVisualizer::widget) delete PropertyVisualizer::widget; VectorWidget* w = new VectorWidget(); w->paramVector->setTitle(QString("3D Vector Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str())); PropertyVisualizer::widget = w; lineNode = new ACG::SceneGraph::LineNode( ACG::SceneGraph::LineNode::LineSegmentsMode, dynamic_cast < ACG::SceneGraph::SeparatorNode* >( PluginFunctions::getRootNode() ) ); w->vectors_edges_rb->hide(); } template void OVMPropertyVisualizerVector::clear() { lineNode->clear(); OVMPropertyVisualizer::clear(); } template void OVMPropertyVisualizerVector::duplicateProperty() { OVMPropertyVisualizer::template duplicateProperty_stage1(); } template template void OVMPropertyVisualizerVector::visualizeVectorAsColorForEntity(PropType prop, EntityIterator e_begin, EntityIterator e_end) { if (!prop) throw VizException("Getting PropHandle from mesh for selected property failed."); VolumeMeshObject* object; PluginFunctions::getObject(OVMPropertyVisualizer::mObjectID, object); for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it) { ACG::Vec3d v = prop[*e_it].normalized() * .5 + ACG::Vec3d(.5, .5, .5); object->colors()[*e_it] = ACG::Vec4f(v[0], v[1], v[2], 1.0); } } template void OVMPropertyVisualizerVector::visualizeCellProp(bool _setDrawMode) { VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget; if (w->vectors_colors_rb->isChecked()) { OpenVolumeMesh::CellPropertyT prop = OVMPropertyVisualizer::mesh->template request_cell_property(OVMPropertyVisualizer::propertyInfo.propName()); visualizeVectorAsColorForEntity(prop, OVMPropertyVisualizer::mesh->cells_begin(), OVMPropertyVisualizer::mesh->cells_end()); if (_setDrawMode) { VolumeMeshObject* object; PluginFunctions::getObject(OVMPropertyVisualizer::mObjectID, object); object->setObjectDrawMode(OVMPropertyVisualizer::drawModes.cellsColoredPerCell); } } else visualizeCellPropAsStrokes(); } template void OVMPropertyVisualizerVector::visualizeFaceProp(bool _setDrawMode) { VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget; if (w->vectors_colors_rb->isChecked()) { OpenVolumeMesh::FacePropertyT prop = OVMPropertyVisualizer::mesh->template request_face_property(OVMPropertyVisualizer::propertyInfo.propName()); visualizeVectorAsColorForEntity(prop, OVMPropertyVisualizer::mesh->faces_begin(), OVMPropertyVisualizer::mesh->faces_end()); if (_setDrawMode) { VolumeMeshObject* object; PluginFunctions::getObject(OVMPropertyVisualizer::mObjectID, object); object->setObjectDrawMode(OVMPropertyVisualizer::drawModes.facesColoredPerFace); } } else visualizeFacePropAsStrokes(); } template void OVMPropertyVisualizerVector::visualizeHalffaceProp(bool _setDrawMode) { VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget; if (w->vectors_colors_rb->isChecked()) { OpenVolumeMesh::HalfFacePropertyT prop = OVMPropertyVisualizer::mesh->template request_halfface_property(OVMPropertyVisualizer::propertyInfo.propName()); visualizeVectorAsColorForEntity(prop, OVMPropertyVisualizer::mesh->halffaces_begin(), OVMPropertyVisualizer::mesh->halffaces_end()); if (_setDrawMode) { VolumeMeshObject* object; PluginFunctions::getObject(OVMPropertyVisualizer::mObjectID, object); object->setObjectDrawMode(OVMPropertyVisualizer::drawModes.halffacesColoredPerHalfface); } } else visualizeHalffacePropAsStrokes(); } template void OVMPropertyVisualizerVector::visualizeEdgeProp(bool _setDrawMode) { VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget; if (w->vectors_colors_rb->isChecked()) { OpenVolumeMesh::EdgePropertyT prop = OVMPropertyVisualizer::mesh->template request_edge_property(OVMPropertyVisualizer::propertyInfo.propName()); visualizeVectorAsColorForEntity(prop, OVMPropertyVisualizer::mesh->edges_begin(), OVMPropertyVisualizer::mesh->edges_end()); if (_setDrawMode) { VolumeMeshObject* object; PluginFunctions::getObject(OVMPropertyVisualizer::mObjectID, object); object->setObjectDrawMode(OVMPropertyVisualizer::drawModes.edgesColoredPerEdge); } } else visualizeEdgePropAsStrokes(); } template void OVMPropertyVisualizerVector::visualizeHalfedgeProp(bool _setDrawMode) { VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget; if (w->vectors_colors_rb->isChecked()) { OpenVolumeMesh::HalfEdgePropertyT prop = OVMPropertyVisualizer::mesh->template request_halfedge_property(OVMPropertyVisualizer::propertyInfo.propName()); visualizeVectorAsColorForEntity(prop, OVMPropertyVisualizer::mesh->halfedges_begin(), OVMPropertyVisualizer::mesh->halfedges_end()); if (_setDrawMode) { VolumeMeshObject* object; PluginFunctions::getObject(OVMPropertyVisualizer::mObjectID, object); object->setObjectDrawMode(OVMPropertyVisualizer::drawModes.halfedgesColoredPerHalfedge); } } else visualizeHalfedgePropAsStrokes(); } template void OVMPropertyVisualizerVector::visualizeVertexProp(bool _setDrawMode) { VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget; if (w->vectors_colors_rb->isChecked()) { OpenVolumeMesh::VertexPropertyT prop = OVMPropertyVisualizer::mesh->template request_vertex_property(OVMPropertyVisualizer::propertyInfo.propName()); visualizeVectorAsColorForEntity(prop, OVMPropertyVisualizer::mesh->vertices_begin(), OVMPropertyVisualizer::mesh->vertices_end()); if (_setDrawMode) { VolumeMeshObject* object; PluginFunctions::getObject(OVMPropertyVisualizer::mObjectID, object); object->setObjectDrawMode(OVMPropertyVisualizer::drawModes.verticesColored); } } else visualizeVertexPropAsStrokes(); } template void OVMPropertyVisualizerVector::visualizeFacePropAsStrokes() { VectorWidget* vectorWidget = static_cast(PropertyVisualizer::widget); lineNode->clear(); ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color()); OpenVolumeMesh::FacePropertyT prop = OVMPropertyVisualizer::mesh->template request_face_property(PropertyVisualizer::propertyInfo.propName()); if ( !prop ) return; OpenVolumeMesh::FaceIter f_begin(OVMPropertyVisualizer::mesh->faces_begin()), f_end(OVMPropertyVisualizer::mesh->faces_end()); for (OpenVolumeMesh::FaceIter f_it = f_begin; f_it != f_end; ++f_it){ ACG::Vec3d center(0.0, 0.0, 0.0); int vCount = 0; OpenVolumeMesh::HalfFaceHandle hfh = OVMPropertyVisualizer::mesh->halfface_handle(*f_it, 0); for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = OVMPropertyVisualizer::mesh->hfv_iter(hfh); hfv_it; ++hfv_it){ vCount++; center += OVMPropertyVisualizer::mesh->vertex(*hfv_it); } center /= vCount; ACG::Vec3d v = prop[*f_it]; if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12) v.normalize(); if(vectorWidget->scale->isChecked()) v *= vectorWidget->scaleBox->value(); lineNode->add_line( center, (center+v) ); lineNode->add_color(color); } } template void OVMPropertyVisualizerVector::visualizeEdgePropAsStrokes() { VectorWidget* vectorWidget = static_cast(PropertyVisualizer::widget); lineNode->clear(); ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color()); OpenVolumeMesh::EdgePropertyT prop = OVMPropertyVisualizer::mesh->template request_edge_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) return; OpenVolumeMesh::EdgeIter e_begin(OVMPropertyVisualizer::mesh->edges_begin()), e_end(OVMPropertyVisualizer::mesh->edges_end()); for (OpenVolumeMesh::EdgeIter e_it = e_begin; e_it != e_end; ++e_it){ OpenVolumeMesh::OpenVolumeMeshEdge edge = OVMPropertyVisualizer::mesh->edge(*e_it); ACG::Vec3d v1 = OVMPropertyVisualizer::mesh->vertex(edge.from_vertex()); ACG::Vec3d v2 = OVMPropertyVisualizer::mesh->vertex(edge.to_vertex()); ACG::Vec3d start = 0.5*(v1+v2); ACG::Vec3d v = prop[*e_it]; if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12) v.normalize(); if(vectorWidget->scale->isChecked()) v *= vectorWidget->scaleBox->value(); lineNode->add_line( start, (start+v) ); lineNode->add_color(color); } } template void OVMPropertyVisualizerVector::visualizeHalfedgePropAsStrokes() { VectorWidget* vectorWidget = static_cast(PropertyVisualizer::widget); lineNode->clear(); ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color()); OpenVolumeMesh::HalfEdgePropertyT prop = OVMPropertyVisualizer::mesh->template request_halfedge_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) return; OpenVolumeMesh::HalfEdgeIter he_begin(OVMPropertyVisualizer::mesh->halfedges_begin()), he_end(OVMPropertyVisualizer::mesh->halfedges_end()); for (OpenVolumeMesh::HalfEdgeIter he_it = he_begin; he_it != he_end; ++he_it){ OpenVolumeMesh::OpenVolumeMeshEdge edge = OVMPropertyVisualizer::mesh->halfedge(*he_it); ACG::Vec3d v1 = OVMPropertyVisualizer::mesh->vertex(edge.from_vertex()); ACG::Vec3d v2 = OVMPropertyVisualizer::mesh->vertex(edge.to_vertex()); ACG::Vec3d start = (2.0*v1+v2)/3.0; ACG::Vec3d v = prop[*he_it]; if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12) v.normalize(); if(vectorWidget->scale->isChecked()) v *= vectorWidget->scaleBox->value(); lineNode->add_line( start, (start+v) ); lineNode->add_color(color); } } template void OVMPropertyVisualizerVector::visualizeVertexPropAsStrokes() { VectorWidget* vectorWidget = static_cast(PropertyVisualizer::widget); lineNode->clear(); ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color()); OpenVolumeMesh::VertexPropertyT prop = OVMPropertyVisualizer::mesh->template request_vertex_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) return; OpenVolumeMesh::VertexIter v_begin(OVMPropertyVisualizer::mesh->vertices_begin()), v_end(OVMPropertyVisualizer::mesh->vertices_end()); for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it != v_end; ++v_it){ ACG::Vec3d start = OVMPropertyVisualizer::mesh->vertex(*v_it); ACG::Vec3d v = prop[*v_it]; if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12) v.normalize(); if(vectorWidget->scale->isChecked()) v *= vectorWidget->scaleBox->value(); lineNode->add_line( start, (start+v) ); lineNode->add_color(color); } } template void OVMPropertyVisualizerVector::visualizeCellPropAsStrokes() { VectorWidget* vectorWidget = static_cast(PropertyVisualizer::widget); lineNode->clear(); ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color()); OpenVolumeMesh::CellPropertyT prop = OVMPropertyVisualizer::mesh->template request_cell_property(PropertyVisualizer::propertyInfo.propName()); if ( !prop ) return; OpenVolumeMesh::CellIter c_begin(OVMPropertyVisualizer::mesh->cells_begin()), c_end(OVMPropertyVisualizer::mesh->cells_end()); for (OpenVolumeMesh::CellIter c_it = c_begin; c_it != c_end; ++c_it){ // Compute cell's center ACG::Vec3d center(0.0, 0.0, 0.0); unsigned int vCount = OVMPropertyVisualizer::mesh->n_vertices_in_cell(*c_it); for(OpenVolumeMesh::CellVertexIter cv_it = OVMPropertyVisualizer::mesh->cv_iter(*c_it); cv_it.valid(); ++cv_it) { center += OVMPropertyVisualizer::mesh->vertex(*cv_it) / (double)vCount; } ACG::Vec3d v = prop[*c_it]; if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12) v.normalize(); if(vectorWidget->scale->isChecked()) v *= vectorWidget->scaleBox->value(); lineNode->add_line( center, (center+v) ); lineNode->add_color(color); } } template void OVMPropertyVisualizerVector::visualizeHalffacePropAsStrokes() { VectorWidget* vectorWidget = static_cast(PropertyVisualizer::widget); lineNode->clear(); ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color()); OpenVolumeMesh::HalfFacePropertyT prop = OVMPropertyVisualizer::mesh->template request_halfface_property(PropertyVisualizer::propertyInfo.propName()); if ( !prop ) return; OpenVolumeMesh::HalfFaceIter hf_begin(OVMPropertyVisualizer::mesh->halffaces_begin()), hf_end(OVMPropertyVisualizer::mesh->halffaces_end()); for (OpenVolumeMesh::HalfFaceIter hf_it = hf_begin; hf_it != hf_end; ++hf_it){ ACG::Vec3d center(0.0, 0.0, 0.0); int vCount = 0; for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = OVMPropertyVisualizer::mesh->hfv_iter(*hf_it); hfv_it; ++hfv_it){ vCount++; center += OVMPropertyVisualizer::mesh->vertex(*hfv_it); } center /= vCount; ACG::Vec3d v = prop[*hf_it]; if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12) v.normalize(); if(vectorWidget->scale->isChecked()) v *= vectorWidget->scaleBox->value(); lineNode->add_line( center, (center+v) ); lineNode->add_color(color); } } template QString OVMPropertyVisualizerVector::getPropertyText(unsigned int index) { return OVMPropertyVisualizer::template getPropertyText_(index); } template void OVMPropertyVisualizerVector::setCellPropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::CellPropertyT prop = mesh->template request_cell_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::CellHandle ch(index); prop[ch] = this->strToVec3d(text); } template void OVMPropertyVisualizerVector::setFacePropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::FacePropertyT prop = mesh->template request_face_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::FaceHandle fh(index); prop[fh] = this->strToVec3d(text); } template void OVMPropertyVisualizerVector::setHalffacePropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::HalfFacePropertyT prop = mesh->template request_halfface_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::HalfFaceHandle hfh(index); prop[hfh] = this->strToVec3d(text); } template void OVMPropertyVisualizerVector::setEdgePropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::EdgePropertyT prop = mesh->template request_edge_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::EdgeHandle eh(index); prop[eh] = this->strToVec3d(text); } template void OVMPropertyVisualizerVector::setHalfedgePropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::HalfEdgePropertyT prop = mesh->template request_halfedge_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::HalfEdgeHandle heh(index); prop[heh] = this->strToVec3d(text); } template void OVMPropertyVisualizerVector::setVertexPropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::VertexPropertyT prop = mesh->template request_vertex_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::VertexHandle vh(index); prop[vh] = this->strToVec3d(text); } #endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */