Commit 16bc12e0 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'feature-mat3x3-clean' into 'master'

Feature: Visualize 3x3 matrices on OVM meshes

See merge request !14
parents d08962e7 1ed0bbec
......@@ -7,8 +7,8 @@ if(APPLE)
add_definitions(-DOVM_FORCE_STATIC_CAST)
endif()
openflipper_plugin (INSTALLDATA Icons
DIRS OpenMesh OpenVolumeMesh Widgets ScriptObjects Toolbars Models PropertyVisualizer
openflipper_plugin (INSTALLDATA Icons Shaders
DIRS OpenMesh OpenVolumeMesh Widgets ScriptObjects Toolbars Models Nodes PropertyVisualizer
DEPS OpenMesh
OPTDEPS OpenVolumeMesh
OPT_TYPES SKELETON BSPLINECURVE POLYHEDRALMESH HEXAHEDRALMESH TETRAHEDRALMESH
......
......@@ -45,6 +45,7 @@
#include <OpenMesh/Core/Utils/Property.hh>
#include <ACG/Math/VectorT.hh>
#include <ACG/Math/Matrix3x3T.hh>
#include <iostream>
......@@ -64,6 +65,8 @@ const PropertyNameListModel::TypeInfoWrapper PropertyNameListModel::proptype_Vec
PropertyNameListModel::TypeInfoWrapper(typeid(OpenMesh::PropertyT<ACG::Vec2d>), "Vec2d");
const PropertyNameListModel::TypeInfoWrapper PropertyNameListModel::proptype_Vec2f =
PropertyNameListModel::TypeInfoWrapper(typeid(OpenMesh::PropertyT<ACG::Vec2f>), "Vec2f");
const PropertyNameListModel::TypeInfoWrapper PropertyNameListModel::proptype_Matrix3x3d =
PropertyNameListModel::TypeInfoWrapper(typeid(OpenMesh::PropertyT<ACG::Matrix3x3d>), "Matrix3x3d");
#ifdef ENABLE_SKELETON_SUPPORT
#include <ObjectTypes/Skeleton/BaseSkin.hh>
......
......@@ -66,7 +66,7 @@ class PropertyNameListModel: public QAbstractListModel {
class TypeInfoWrapper {
public:
TypeInfoWrapper(const std::type_info & ti, const char *friendlyName) : ti(&ti), friendlyName(friendlyName) {}
TypeInfoWrapper(const std::type_info & ti) : ti(&ti),friendlyName("") {}
explicit TypeInfoWrapper(const std::type_info & ti) : ti(&ti),friendlyName("") {}
operator const std::type_info *() const { return ti; }
operator const std::type_info &() const { return *ti; }
......@@ -191,7 +191,7 @@ class PropertyNameListModel: public QAbstractListModel {
OpenMesh::BaseProperty * const baseProp = *pit;
if (!baseProp) continue;
TypeInfoWrapper bp_type = typeid(*baseProp);
TypeInfoWrapper bp_type {typeid(*baseProp)};
TYPE_INFO_SET::const_iterator sane_prop_it = sane_prop_types.find(bp_type);
if ((typeIdFilter == 0 || TypeInfoWrapper(*typeIdFilter) == bp_type) && sane_prop_it != sane_prop_types.end()) {
*oit++ = PROP_INFO(baseProp->name(), *sane_prop_it, entity);
......@@ -215,6 +215,7 @@ class PropertyNameListModel: public QAbstractListModel {
static const TypeInfoWrapper proptype_Vec3f;
static const TypeInfoWrapper proptype_Vec2d;
static const TypeInfoWrapper proptype_Vec2f;
static const TypeInfoWrapper proptype_Matrix3x3d;
static const TypeInfoWrapper proptype_SkinWeights;
private:
......
/*===========================================================================*\
* *
* 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. *
* *
\*===========================================================================*/
#include <ACG/GL/acg_glew.hh>
#include "BoxesNode.hh"
#include <ACG/GL/IRenderer.hh>
namespace ACG {
namespace SceneGraph {
BoxesNode::BoxesNode(BaseNode* _parent,
std::string _name) :
MaterialNode(_parent, _name),
updateVBO_(true)
{
const std::array<Vec4f,3> dim_color = {
Vec4f{1.f,0.f,0.f,1.f},
Vec4f{0.f,1.f,0.f,1.f},
Vec4f{0.f,0.f,1.f,1.f}
};
const std::array<Vec3f, 8> vertices = {
Vec3f( 1.f, -1.f, -1.f),
Vec3f( 1.f, 1.f, -1.f),
Vec3f( 1.f, 1.f, 1.f),
Vec3f( 1.f, -1.f, 1.f),
Vec3f(-1.f, -1.f, -1.f),
Vec3f(-1.f, 1.f, -1.f),
Vec3f(-1.f, 1.f, 1.f),
Vec3f(-1.f, -1.f, 1.f)};
auto add_triangle = [this, &vertices, &dim_color]
(size_t v0, size_t v1, size_t v2, size_t dim)
{
triangles_.push_back({vertices[v0], vertices[v1], vertices[v2]});
triangle_colors_.push_back(dim_color[dim]);
};
triangles_.reserve(6*2);
triangle_colors_.reserve(6*2);
add_triangle(0, 1, 2, 0);
add_triangle(0, 2, 3, 0);
add_triangle(4, 6, 5, 0);
add_triangle(4, 7, 6, 0);
add_triangle(1, 5, 6, 1);
add_triangle(1, 6, 2, 1);
add_triangle(0, 3, 7, 1);
add_triangle(0, 7, 4, 1);
add_triangle(2, 7, 3, 2);
add_triangle(2, 6, 7, 2);
add_triangle(0, 4, 1, 2);
add_triangle(1, 4, 5, 2);
}
void
BoxesNode::
boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
{
// FIXME: this assumes matrices to only consist of vectors up to unit length
for (const auto &be: elem_) {
_bbMax.maximize(be.pos + Vec3d(scaleFactor_,scaleFactor_,scaleFactor_));
_bbMin.minimize(be.pos + Vec3d(-scaleFactor_, -scaleFactor_, -scaleFactor_));
}
}
void BoxesNode::createVBO()
{
if (!updateVBO_)
return;
// generate if needed:
geometry_vbo_.bind();
instance_vbo_.bind();
vertexDecl_.clear();
vertexDecl_.addElement(GL_FLOAT, 3, VERTEX_USAGE_POSITION, nullptr, nullptr, 0, geometry_vbo_.id());
vertexDecl_.addElement(GL_FLOAT, 4, VERTEX_USAGE_COLOR, nullptr, nullptr, 0, geometry_vbo_.id());
std::vector<float> geom_vbo_data; geom_vbo_data.reserve(3 * (3+4) * triangles_.size());
vertexDecl_.addElement(GL_FLOAT, 3, VERTEX_USAGE_SHADER_INPUT, nullptr, "inst_v0", 1, instance_vbo_.id());
vertexDecl_.addElement(GL_FLOAT, 3, VERTEX_USAGE_SHADER_INPUT, nullptr, "inst_v1", 1, instance_vbo_.id());
vertexDecl_.addElement(GL_FLOAT, 3, VERTEX_USAGE_SHADER_INPUT, nullptr, "inst_v2", 1, instance_vbo_.id());
vertexDecl_.addElement(GL_FLOAT, 3, VERTEX_USAGE_SHADER_INPUT, nullptr, "inst_pos", 1, instance_vbo_.id());
std::vector<float> instance_vbo_data; instance_vbo_data.reserve(3 * 4 * elem_.size());
assert(triangles_.size() == triangle_colors_.size());
for (size_t i = 0; i < triangles_.size(); ++i)
{
auto &tri = triangles_[i];
auto &color = triangle_colors_[i];
for (const auto &point: tri) {
std::copy(point.begin(), point.end(), std::back_inserter(geom_vbo_data));
std::copy(color.begin(), color.end(), std::back_inserter(geom_vbo_data));
}
}
for (const auto &be: elem_) {
for (const auto &point: {
be.transform.getRow(0),
be.transform.getRow(1),
be.transform.getRow(2),
be.pos})
{
std::copy(point.begin(), point.end(), std::back_inserter(instance_vbo_data));
}
}
geometry_vbo_.upload(
static_cast<GLsizeiptr>(geom_vbo_data.size()*sizeof(float)),
geom_vbo_data.data(),
GL_STATIC_DRAW_ARB);
instance_vbo_.upload(
static_cast<GLsizeiptr>(instance_vbo_data.size()*sizeof(float)),
instance_vbo_data.data(),
GL_STATIC_DRAW_ARB);
// Update done.
updateVBO_ = false;
}
void
BoxesNode::
getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& /* _drawMode */, const ACG::SceneGraph::Material* _mat)
{
if (elem_.empty())
return;
RenderObject ro;
ro.initFromState(&_state);
ro.setMaterial(_mat);
boxesNodeName_ = std::string("BoxesNode: ")+name();
ro.debugName = boxesNodeName_;
ro.depthTest = true;
ro.depthWrite = true;
ro.blending = true;
ro.blendSrc = GL_SRC_ALPHA;
ro.blendDest = GL_ONE_MINUS_SRC_ALPHA;
ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;
ro.shaderDesc.vertexColors = true;
ro.shaderDesc.vertexTemplateFile = "BoxesNode/vert.glsl";
ro.setUniform("scale", scaleFactor_);
createVBO();
ro.vertexBuffer = geometry_vbo_.id();
ro.vertexDecl = &vertexDecl_;
ro.glDrawInstancedArrays(GL_TRIANGLES, 0,
static_cast<GLsizei>(3 * triangles_.size()),
static_cast<GLsizei>(elem_.size()));
_renderer->addRenderObject(&ro);
}
} // namespace SceneGraph
} // namespace ACG
#pragma once
/*===========================================================================*\
* *
* 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. *
* *
\*===========================================================================*/
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/globjects.hh>
#include <ACG/Math/Matrix3x3T.hh>
#include <vector>
#include <limits>
namespace ACG {
namespace SceneGraph {
struct BoxElement {
Matrix3x3d transform;
Vec3d pos;
};
class BoxesNode : public MaterialNode
{
public:
ACG_CLASSNAME(BoxesNode)
BoxesNode(BaseNode* _parent=nullptr,
std::string _name="<BoxesNode>" );
~BoxesNode() = default;
DrawModes::DrawMode availableDrawModes() const {
return DrawModes::SOLID_FACES_COLORED_FLAT_SHADED;
}
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
void clear() { elem_.clear(); updateVBO_ = true; }
void reserve(size_t _n) { elem_.reserve(_n); }
/// STL conformance
void push_back(const BoxElement& _v) { elem_.push_back(_v); updateVBO_ = true; }
typedef BoxElement value_type;
typedef BoxElement& reference;
typedef const BoxElement& const_reference;
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const ACG::SceneGraph::Material* _mat);
void setScaleFactor(float _val) { scaleFactor_ = _val;}
protected:
/// creates the vbo only if update was requested
void createVBO();
std::vector<BoxElement> elem_;
float scaleFactor_ = 1.0f;
// geometry of a single box
std::vector<std::array<Vec3f,3>> triangles_;
std::vector<Vec4f> triangle_colors_;
GeometryBuffer geometry_vbo_;
GeometryBuffer instance_vbo_;
// True if points changed and the vbo has to be updated
bool updateVBO_;
ACG::VertexDeclaration vertexDecl_;
std::string boxesNodeName_;
};
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
#pragma once
#include <ACG/Math/VectorT.hh>
#include <OpenVolumeMesh/Core/Entities.hh>
#include <OpenVolumeMesh/Core/GeometryKernel.hh>
template<class MeshT>
class EntityPosition
{
public:
EntityPosition(MeshT &mesh) : mesh_(mesh) {}
ACG::Vec3d operator()(OpenVolumeMesh::VertexHandle vh)
{
return mesh_.vertex(vh);
}
ACG::Vec3d operator()(OpenVolumeMesh::EdgeHandle eh)
{
auto edge = mesh_.edge(eh);
return 0.5 * (mesh_.vertex(edge.from_vertex()) + mesh_.vertex(edge.to_vertex()));
}
ACG::Vec3d operator()(OpenVolumeMesh::HalfEdgeHandle heh)
{
auto edge = mesh_.halfedge(heh);
return (1./3.) * (2 * mesh_.vertex(edge.from_vertex()) + mesh_.vertex(edge.to_vertex()));
}
ACG::Vec3d operator()(OpenVolumeMesh::CellHandle ch)
{
int count = 0;
ACG::Vec3d sum{0.,0.,0.};
for (auto vh: mesh_.cell_vertices(ch)) {
sum += mesh_.vertex(vh);
++count;
}
return sum / count;
}
ACG::Vec3d operator()(OpenVolumeMesh::FaceHandle fh)
{
return (*this)(mesh_.halfface_handle(fh, 0));
}
ACG::Vec3d operator()(OpenVolumeMesh::HalfFaceHandle hfh)
{
// TODO: maybe offset this slightly from the face barycenter?
int count = 0;
ACG::Vec3d sum{0.,0.,0.};
for (auto vh: mesh_.halfface_vertices(hfh)) {
sum += mesh_.vertex(vh);
++count;
}
return sum / count;
}
private:
MeshT &mesh_;
};
......@@ -48,6 +48,7 @@
#include "OVMPropertyVisualizerBoolean.hh"
#include "OVMPropertyVisualizerDouble.hh"
#include "OVMPropertyVisualizerInteger.hh"
#include "OVMPropertyVisualizerMatrix3x3.hh"
#include "OVMPropertyVisualizerVector.hh"
#include "OVMPropertyVisualizerVectorFieldDifference.hh"
......@@ -104,6 +105,8 @@ public:
static bool isVec3fType(const TypeInfoWrapper& typeInfo);
static bool isVectorType(const PropertyInfo& propInfo);
static bool isVectorType(const TypeInfoWrapper& typeInfo);
static bool isMatrix3x3Type(const PropertyInfo& propInfo);
static bool isMatrix3x3Type(const TypeInfoWrapper& typeInfo);
#define DECLARE_PROPTYPES(primitive) \
static const TypeInfoWrapper proptype_##primitive##_bool; \
......@@ -111,7 +114,8 @@ public:
static const TypeInfoWrapper proptype_##primitive##_uint; \
static const TypeInfoWrapper proptype_##primitive##_double; \
static const TypeInfoWrapper proptype_##primitive##_Vec3d; \
static const TypeInfoWrapper proptype_##primitive##_Vec3f;
static const TypeInfoWrapper proptype_##primitive##_Vec3f; \
static const TypeInfoWrapper proptype_##primitive##_Matrix3x3d;
DECLARE_PROPTYPES(Cell)
DECLARE_PROPTYPES(Face)
......@@ -206,7 +210,9 @@ template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##prim
template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Vec3d \
= TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3d>), "Vec3d"); \
template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Vec3f \
= TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3f>), "Vec3f");
= TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Vec3f>), "Vec3f"); \
template <typename T> const TypeInfoWrapper OVMPropertyModel<T>::proptype_##primitive##_Matrix3x3d \
= TypeInfoWrapper(typeid(OpenVolumeMesh::primitive##PropertyT<ACG::Matrix3x3d>), "Matrix3x3d");
INITIALIZE_PROPTYPES(Cell)
INITIALIZE_PROPTYPES(Face)
......
......@@ -646,6 +646,23 @@ bool OVMPropertyModel<MeshT>::isVectorType(const TypeInfoWrapper& typeInfo)
return isVec3fType(typeInfo) || isVec3dType(typeInfo);
}
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;
}
template<typename MeshT>
bool OVMPropertyModel<MeshT>::isEntityType(const TypeInfoWrapper& typeInfo, PropertyInfo::ENTITY_FILTER entity_type) const
{
......@@ -732,6 +749,8 @@ void OVMPropertyModel<MeshT>::addPropertyVisualizer(OpenVolumeMesh::BaseProperty
propertyVisualizers.push_back(new OVMPropertyVisualizerDouble<MeshT>(mesh, objectID_, propInfo));
else if (isVectorType(propInfo))
propertyVisualizers.push_back(new OVMPropertyVisualizerVector<MeshT>(mesh, objectID_, propInfo));
else if (isMatrix3x3Type(propInfo))
propertyVisualizers.push_back(new OVMPropertyVisualizerMatrix3x3<MeshT>(mesh, objectID_, propInfo));
connectLogs(propertyVisualizers.back());
}
......@@ -936,6 +955,7 @@ supportedPropertyTypes.insert(proptype_##primitive##_uint); \
supportedPropertyTypes.insert(proptype_##primitive##_double); \
supportedPropertyTypes.insert(proptype_##primitive##_Vec3d); \
supportedPropertyTypes.insert(proptype_##primitive##_Vec3f); \
supportedPropertyTypes.insert(proptype_##primitive##_Matrix3x3d); \
INSERT_PROPTYPES(Cell)
INSERT_PROPTYPES(Face)
......
/*===========================================================================*\
* *
* 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. *
* *
\*===========================================================================*/
#pragma once
#include "OVMPropertyVisualizer.hh"
#include <ACG/Scenegraph/LineNode.hh>
#include <ACG/Scenegraph/MeshNode2T.hh>
#include "Nodes/BoxesNode.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenVolumeMesh/Core/BaseEntities.hh>
#include <OpenVolumeMesh/Core/BaseProperty.hh>
#include "Widgets/Matrix3x3Widget.hh"
#include <iostream>
template <typename MeshT>
class OVMPropertyVisualizerMatrix3x3: public OVMPropertyVisualizer<MeshT>{
public:
OVMPropertyVisualizerMatrix3x3(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo);
virtual ~OVMPropertyVisualizerMatrix3x3(){ clear(); }
void clear() override;
protected:
void duplicateProperty() override;
void visualizeFaceProp(bool _setDrawMode = true) override;
void visualizeEdgeProp(bool _setDrawMode = true) override;
void visualizeHalfedgeProp(bool _setDrawMode = true) override;
void visualizeVertexProp(bool _setDrawMode = true) override;
void visualizeCellProp(bool _setDrawMode = true) override;
void visualizeHalffaceProp(bool _setDrawMode = true) override;
QString getPropertyText(unsigned int index) override;
ACG::SceneGraph::LineNode* lineNode;
ACG::SceneGraph::BoxesNode* boxesNode;
private:
template<typename EntityTag, typename Property, typename EntityIterator>
void visualizeAsCrossesForEntity(Property prop, EntityIterator e_begin, EntityIterator e_end);
template<typename EntityTag, typename Property, typename EntityIterator>
void visualizeAsBoxesForEntity(Property prop, EntityIterator e_begin, EntityIterator e_end);
template<typename EntityTag, typename EntityIterator>
void visualizeForEntity(EntityIterator e_begin, EntityIterator e_end);
Matrix3x3Widget* getMatWidget() {return static_cast<Matrix3x3Widget*>(PropertyVisualizer::widget);}
};
#if defined(INCLUDE_TEMPLATES) && !defined(OVM_PROPERTY_VISUALIZER_MAT3X3_CC)
#include "OVMPropertyVisualizerMatrix3x3_impl.hh"
#endif
/*===========================================================================*\
* *
* 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. *
* *
\*===========================================================================*/
#define OVM_PROPERTY_VISUALIZER_MAT3X3_CC
#include <ACG/Utils/ColorConversion.hh>
#include "OVMPropertyVisualizerMatrix3x3.hh"
#include "ACG/Scenegraph/DrawModes.hh"
#include "EntityPosition.hh"
using Color4f = ACG::SceneGraph::LineNode::Color4f;
static std::array<Color4f, 3> dim_color {
Color4f{1.f,0.f,0.f,1.f},
Color4f{0.f,1.f,0.f,1.f},
Color4f{0.f,0.f,1.f,1.f}
};
template <typename MeshT>
OVMPropertyVisualizerMatrix3x3<MeshT>::OVMPropertyVisualizerMatrix3x3(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo)
: OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo)
{
if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
Matrix3x3Widget* w = new Matrix3x3Widget();
PropertyVisualizer::widget = w;
BaseObjectData *bod;
PluginFunctions::getObject(objectID, bod);
boxesNode = new ACG::SceneGraph::BoxesNode(bod->manipulatorNode());
lineNode = new ACG::SceneGraph::LineNode(ACG::SceneGraph::LineNode::LineSegmentsMode, bod->manipulatorNode());
this->connect(w->lineWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this](double value) {lineNode->set_line_width(value);});
}
template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::clear()
{
lineNode->clear();
boxesNode->clear();
OVMPropertyVisualizer<MeshT>::clear();
}
template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::duplicateProperty()
{
OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<ACG::Matrix3x3d>();
}
template<typename MeshT>
template<typename EntityTag, typename Property, typename EntityIterator>
void OVMPropertyVisualizerMatrix3x3<MeshT>::
visualizeAsCrossesForEntity(Property prop, EntityIterator e_begin, EntityIterator e_end)
{
using ACG::Vec3d;
using ACG::Matrix3x3d;
MeshT &m = *OVMPropertyVisualizer<MeshT>::mesh;
EntityPosition<MeshT> ep{m};
double scaleFactor = getMatWidget()->getScaleFactor();