Commit 51d944e8 authored by Martin Heistermann's avatar Martin Heistermann

mat3x3 vis: implement cross visualisation

parent 0dfe7085
#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_;
};
......@@ -66,6 +66,7 @@ public:
protected:
void duplicateProperty() override;
void visualizeFaceProp(bool _setDrawMode = true) override;
void visualizeEdgeProp(bool _setDrawMode = true) override;
void visualizeHalfedgeProp(bool _setDrawMode = true) override;
......@@ -77,9 +78,18 @@ protected:
ACG::SceneGraph::LineNode* lineNode;
private:
template<typename EntityTag, typename EntityIterator>
void visualizeAsCrossForEntity(EntityIterator e_begin, EntityIterator e_end);
template<typename EntityTag, typename EntityIterator>
void visualizeAsBoxesForEntity(EntityIterator e_begin, EntityIterator e_end);
template<typename EntityTag, typename EntityIterator>
void visualizeForEntity(EntityIterator e_begin, EntityIterator e_end);
Matrix3x3Widget* getWidget() {return static_cast<Matrix3x3Widget*>(PropertyVisualizer::widget);}
};
#if defined(INCLUDE_TEMPLATES) && !defined(OVM_PROPERTY_VISUALIZER_MAT3X3_CC)
#include "OVMPropertyVisualizerMatrix3x3T.cc"
#include "OVMPropertyVisualizerMatrix3x3_impl.hh"
#endif
......@@ -46,7 +46,7 @@
#include <ACG/Utils/ColorConversion.hh>
#include "OVMPropertyVisualizerMatrix3x3.hh"
#include "EntityPosition.hh"
template <typename MeshT>
OVMPropertyVisualizerMatrix3x3<MeshT>::OVMPropertyVisualizerMatrix3x3(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo)
......@@ -76,34 +76,106 @@ void OVMPropertyVisualizerMatrix3x3<MeshT>::duplicateProperty()
OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<ACG::Matrix3x3d>();
}
template<typename MeshT>
template<typename EntityTag, typename EntityIterator>
void OVMPropertyVisualizerMatrix3x3<MeshT>::
visualizeAsCrossForEntity(EntityIterator e_begin, EntityIterator e_end)
{
using ACG::Vec3d;
using ACG::Matrix3x3d;
using Color4f = ACG::SceneGraph::LineNode::Color4f;
MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
EntityPosition<MeshT> ep{m};
auto prop = m.template request_property<ACG::Matrix3x3d, EntityTag>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
if (!prop)
throw VizException("Getting PropHandle from mesh for selected property failed.");
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}
};
lineNode->clear();
bool normalized = getWidget()->normalize_colors->isChecked();
double scaleFactor = getWidget()->scale->isChecked() ? getWidget()->scaleBox->value() : 1.0;
for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it) {
Matrix3x3d mat = prop[*e_it];
Vec3d center_pos = ep(*e_it);
for (unsigned char dim = 0; dim < 3; ++dim) {
ACG::Vec3d v = mat.getCol(dim);
v *= (normalized ? (scaleFactor / v.norm()) : scaleFactor);
lineNode->add_line(center_pos - v, center_pos + v);
lineNode->add_color(dim_color[dim]);
}
}
}
template<typename MeshT>
template<typename EntityTag, typename EntityIterator>
void OVMPropertyVisualizerMatrix3x3<MeshT>::
visualizeAsBoxesForEntity(EntityIterator e_begin, EntityIterator e_end)
{
}
template<typename MeshT>
template<typename EntityTag, typename EntityIterator>
void OVMPropertyVisualizerMatrix3x3<MeshT>::
visualizeForEntity(EntityIterator e_begin, EntityIterator e_end)
{
if (getWidget()->as_crosses->isChecked()) {
visualizeAsCrossForEntity<EntityTag>(e_begin, e_end);
} else if (getWidget()->as_boxes->isChecked()) {
visualizeAsBoxesForEntity<EntityTag>(e_begin, e_end);
}
}
template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeCellProp(bool _setDrawMode)
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeCellProp(bool /*_setDrawMode*/)
{
MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
visualizeForEntity<OpenVolumeMesh::Entity::Cell>(m.cells_begin(), m.cells_end());
}
template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeFaceProp(bool _setDrawMode)
{}
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeFaceProp(bool /*_setDrawMode*/)
{
MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
visualizeForEntity<OpenVolumeMesh::Entity::Face>(m.faces_begin(), m.faces_end());
}
template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeHalffaceProp(bool _setDrawMode)
{}
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeHalffaceProp(bool /*_setDrawMode*/)
{
MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
visualizeForEntity<OpenVolumeMesh::Entity::HalfFace>(m.halffaces_begin(), m.halffaces_end());
}
template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeEdgeProp(bool _setDrawMode)
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeEdgeProp(bool /*_setDrawMode*/)
{
MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
visualizeForEntity<OpenVolumeMesh::Entity::Edge>(m.edges_begin(), m.edges_end());
}
template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeHalfedgeProp(bool _setDrawMode)
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeHalfedgeProp(bool /*_setDrawMode*/)
{
MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
visualizeForEntity<OpenVolumeMesh::Entity::HalfEdge>(m.halfedges_begin(), m.halfedges_end());
}
template <typename MeshT>
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeVertexProp(bool _setDrawMode)
{}
void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeVertexProp(bool /*_setDrawMode*/)
{
MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
visualizeForEntity<OpenVolumeMesh::Entity::Vertex>(m.vertices_begin(), m.vertices_end());
}
template <typename MeshT>
QString OVMPropertyVisualizerMatrix3x3<MeshT>::getPropertyText(unsigned int index)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment