Commit 868e1469 authored by Isaak Lim's avatar Isaak Lim

added multiple object property visualization support for OVM (thanks to Alexander Dielen)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@21171 383ad7c9-94d9-4d36-a494-682f7c89f535
parent d51a34d8
......@@ -5,8 +5,10 @@
#include "OpenVolumeMesh/OVMPropertyModel.hh"
#include "OpenVolumeMesh/Mesh/HexahedralMesh.hh"
#include "Utils.hh"
MultiObjectPropertyModel::MultiObjectPropertyModel(const QStringList& res, QObject *parent) :
PropertyModel(parent), restriction(res), widget(0)
PropertyModel(parent), restriction(res), datatypes(supportedDataTypes()), widget(0)
{
QVBoxLayout* layout = new QVBoxLayout();
widget = new QWidget();
......@@ -46,7 +48,7 @@ void MultiObjectPropertyModel::objectUpdated()
{
using namespace PluginFunctions;
for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it)
for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it)
{
// get the property model and call objectUpdated
PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id());
......@@ -62,7 +64,7 @@ void MultiObjectPropertyModel::visualize(QModelIndexList selectedIndices, QWidge
// return if nothing is selected
if (selectedIndices.size() < 1) return;
for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it)
for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it)
{
// get the property model and update it
PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id());
......@@ -97,7 +99,7 @@ void MultiObjectPropertyModel::removeProperty(QModelIndexList selectedIndices)
// return if nothing is selected
if (selectedIndices.size() < 1) return;
for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it)
for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it)
{
PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id());
if (model == 0) continue;
......@@ -130,7 +132,7 @@ void MultiObjectPropertyModel::duplicateProperty(QModelIndexList selectedIndices
// return if nothing is selected
if (selectedIndices.size() < 1) return;
for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it)
for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it)
{
PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id());
if (model == 0) continue;
......@@ -170,7 +172,7 @@ void MultiObjectPropertyModel::gatherProperties()
propWidgets.clear();
endResetModel();
for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it)
for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it)
{
PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id());
if (model == 0) continue;
......@@ -203,7 +205,7 @@ void MultiObjectPropertyModel::clear(QModelIndexList selectedIndices)
// return if nothing is selected
if (selectedIndices.size() < 1) return;
for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it)
for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it)
{
PropertyModel* model = PropertyModelFactory::Instance().getModel(o_it->id());
if (model == 0) continue;
......@@ -318,7 +320,7 @@ QWidget* MultiObjectPropertyModel::createWidgetForType(const TypeInfoWrapper& in
}
template <typename ItemHandle, typename PropHandle, typename T>
void range2(const OpenMesh::BaseKernel* mesh, unsigned int n, const std::string& name, T& min, T& max)
void range3_om(const OpenMesh::BaseKernel* mesh, unsigned int n, const std::string& name, T& min, T& max)
{
PropHandle ph;
mesh->get_property_handle(ph, name);
......@@ -332,43 +334,111 @@ void range2(const OpenMesh::BaseKernel* mesh, unsigned int n, const std::string&
}
}
template <typename T>
void range1(const BaseObject* obj, const PropertyInfo& info, T& min, T& max)
template <typename ItemHandle, typename Property, typename T>
void range3_ovm(Property& prop, unsigned int n, T& min, T& max)
{
using namespace PluginFunctions;
OpenMesh::BaseKernel* mesh = 0;
if (obj->dataType(DATA_TRIANGLE_MESH))
mesh = triMesh(obj->id());
if (obj->dataType(DATA_POLY_MESH))
mesh = polyMesh(obj->id());
for (unsigned int i = 0; i < n; ++i)
{
const ItemHandle ih(i);
min = std::min(min, prop[ih]);
max = std::max(max, prop[ih]);
}
}
template <typename Mesh, typename T>
void range2_om(const Mesh* mesh, const PropertyInfo& info, T& min, T&max)
{
if (mesh == 0) return;
if (info.isVertexProp())
range2<OpenMesh::VertexHandle, OpenMesh::VPropHandleT<T>, T>
range3_om<OpenMesh::VertexHandle, OpenMesh::VPropHandleT<T>, T>
(mesh, mesh->n_vertices(), info.propName(), min, max);
if (info.isHalfedgeProp())
range2<OpenMesh::HalfedgeHandle, OpenMesh::HPropHandleT<T>, T>
range3_om<OpenMesh::HalfedgeHandle, OpenMesh::HPropHandleT<T>, T>
(mesh, mesh->n_halfedges(), info.propName(), min, max);
if (info.isEdgeProp())
range2<OpenMesh::EdgeHandle, OpenMesh::EPropHandleT<T>, T>
range3_om<OpenMesh::EdgeHandle, OpenMesh::EPropHandleT<T>, T>
(mesh, mesh->n_edges(), info.propName(), min, max);
if (info.isFaceProp())
range2<OpenMesh::FaceHandle, OpenMesh::FPropHandleT<T>, T>
range3_om<OpenMesh::FaceHandle, OpenMesh::FPropHandleT<T>, T>
(mesh, mesh->n_faces(), info.propName(), min, max);
}
template <typename Mesh, typename T>
void range2_ovm(Mesh* mesh, const PropertyInfo& info, T& min, T&max)
{
if (mesh == 0) return;
if (info.isCellProp() && mesh->template cell_property_exists<T>(info.propName())) {
OpenVolumeMesh::CellPropertyT<T> prop = mesh->template request_cell_property<T>(info.propName());
range3_ovm<OpenVolumeMesh::CellHandle, OpenVolumeMesh::CellPropertyT<T>, T>
(prop, mesh->n_cells(), min, max);
}
if (info.isEdgeProp() && mesh->template edge_property_exists<T>(info.propName())) {
OpenVolumeMesh::EdgePropertyT<T> prop = mesh->template request_edge_property<T>(info.propName());
range3_ovm<OpenVolumeMesh::EdgeHandle, OpenVolumeMesh::EdgePropertyT<T>, T>
(prop, mesh->n_edges(), min, max);
}
if (info.isFaceProp() && mesh->template face_property_exists<T>(info.propName())) {
OpenVolumeMesh::FacePropertyT<T> prop = mesh->template request_face_property<T>(info.propName());
range3_ovm<OpenVolumeMesh::FaceHandle, OpenVolumeMesh::FacePropertyT<T>, T>
(prop, mesh->n_faces(), min, max);
}
if (info.isHalfedgeProp() && mesh->template halfedge_property_exists<T>(info.propName())) {
OpenVolumeMesh::HalfEdgePropertyT<T> prop = mesh->template request_halfedge_property<T>(info.propName());
range3_ovm<OpenVolumeMesh::HalfEdgeHandle, OpenVolumeMesh::HalfEdgePropertyT<T>, T>
(prop, mesh->n_halfedges(), min, max);
}
if (info.isHalffaceProp() && mesh->template halfface_property_exists<T>(info.propName())) {
OpenVolumeMesh::HalfFacePropertyT<T> prop = mesh->template request_halfface_property<T>(info.propName());
range3_ovm<OpenVolumeMesh::HalfFaceHandle, OpenVolumeMesh::HalfFacePropertyT<T>, T>
(prop, mesh->n_halffaces(), min, max);
}
if (info.isVertexProp() && mesh->template vertex_property_exists<T>(info.propName())) {
OpenVolumeMesh::VertexPropertyT<T> prop = mesh->template request_vertex_property<T>(info.propName());
range3_ovm<OpenVolumeMesh::VertexHandle, OpenVolumeMesh::VertexPropertyT<T>, T>
(prop, mesh->n_vertices(), min, max);
}
}
template <typename T>
void range1(const BaseObject* obj, const PropertyInfo& info, T& min, T& max)
{
using namespace PluginFunctions;
if (obj->dataType(DATA_TRIANGLE_MESH))
range2_om(triMesh(obj->id()), info, min, max);
if (obj->dataType(DATA_POLY_MESH))
range2_om(polyMesh(obj->id()), info, min, max);
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
if (obj->dataType(DATA_POLYHEDRAL_MESH))
range2_ovm(polyhedralMesh(obj->id()), info, min, max);
#endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
if (obj->dataType(DATA_HEXAHEDRAL_MESH))
range2_ovm(hexahedralMesh(obj->id()), info, min, max);
#endif
}
void MultiObjectPropertyModel::setRange(const PropertyInfo& info, QWidget* widget) const
{
using namespace PluginFunctions;
if (info.typeinfo() == OMPropertyModel<TriMesh>::proptype_double)
bool isDoubleType = info.typeinfo() == OMPropertyModel<TriMesh>::proptype_double;
isDoubleType |= OVMPropertyModel<HexahedralMesh>::isDoubleType(info.typeinfo());
bool isIntType = info.typeinfo() == OMPropertyModel<TriMesh>::proptype_int;
isIntType |= OVMPropertyModel<HexahedralMesh>::isIntType(info.typeinfo());
if (isDoubleType)
{
double min = +DBL_MAX;
double max = -DBL_MAX;
for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it)
for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it)
{
range1<double>(*o_it, info, min, max);
}
......@@ -379,12 +449,12 @@ void MultiObjectPropertyModel::setRange(const PropertyInfo& info, QWidget* widge
w->doubleFixedRangeMax->setValue(max);
}
if (info.typeinfo() == OMPropertyModel<TriMesh>::proptype_int)
if (isIntType)
{
int min = +INT_MAX;
int max = -INT_MAX;
for (ObjectIterator o_it(restriction, DATA_TRIANGLE_MESH | DATA_POLY_MESH); o_it != objectsEnd(); ++o_it)
for (ObjectIterator o_it(restriction, datatypes); o_it != objectsEnd(); ++o_it)
{
range1<int>(*o_it, info, min, max);
}
......
......@@ -2,6 +2,7 @@
#define MULTI_OBJECT_PROPERTY_MODEL_H
#include "PropertyModel.hh"
#include "OpenFlipper/common/DataTypes.hh"
class PropertyVisualizer;
......@@ -56,6 +57,7 @@ private:
private:
const QStringList restriction;
const DataType datatypes;
std::vector<QString> propNames;
std::vector<PropertyInfo> propInfos;
std::vector<QWidget*> propWidgets;
......
......@@ -280,7 +280,7 @@ void PropertyVisPlugin::slotVisualize()
}
else
{
ObjectIterator o_it(ALL_OBJECTS, DATA_TRIANGLE_MESH | DATA_POLY_MESH);
ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
while (o_it != objectsEnd())
{
emit updatedObject( o_it->id(), UPDATE_COLOR );
......@@ -317,7 +317,7 @@ void PropertyVisPlugin::slotDuplicateProperty()
}
else
{
ObjectIterator o_it(ALL_OBJECTS, DATA_TRIANGLE_MESH | DATA_POLY_MESH);
ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
while (o_it != objectsEnd())
{
emit updatedObject( o_it->id(), UPDATE_ALL );
......@@ -345,7 +345,7 @@ void PropertyVisPlugin::slotRemoveProperty()
}
else
{
ObjectIterator o_it(ALL_OBJECTS, DATA_TRIANGLE_MESH | DATA_POLY_MESH);
ObjectIterator o_it(ALL_OBJECTS, supportedDataTypes());
while (o_it != objectsEnd())
{
emit updatedObject( o_it->id(), UPDATE_ALL );
......
......@@ -56,9 +56,12 @@
#include <typeinfo>
#include <QObject>
#include <QMessageBox>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
/*! \class TypeInfoWrapper
* \brief Wraps the information of a type.
......@@ -192,4 +195,19 @@ public:
};
static DataType supportedDataTypes()
{
DataType res = DATA_TRIANGLE_MESH | DATA_POLY_MESH;
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
res |= DATA_POLYHEDRAL_MESH;
#endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
res |= DATA_HEXAHEDRAL_MESH;
#endif
return res;
}
#endif /* UTILS_H */
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