From fd8b7a6ada7f4e15d9ae1e98ab6da10d4db63b9a Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Thu, 21 Jan 2021 11:07:27 +0100 Subject: [PATCH] filter measure returns points, matrices and vectors --- .../interfaces/filter_plugin_interface.h | 9 ++ src/common/interfaces/plugin_interface.h | 10 ++ .../filter_measure/filter_measure.cpp | 131 +++++++++--------- 3 files changed, 88 insertions(+), 62 deletions(-) diff --git a/src/common/interfaces/filter_plugin_interface.h b/src/common/interfaces/filter_plugin_interface.h index 6b064ce47..6eb818ba8 100644 --- a/src/common/interfaces/filter_plugin_interface.h +++ b/src/common/interfaces/filter_plugin_interface.h @@ -27,6 +27,15 @@ #include "plugin_interface.h" #include "../ml_document/mesh_document.h" +//declaring types to be used as QVariants + +Q_DECLARE_METATYPE(Point2m) +Q_DECLARE_METATYPE(Point3m) +Q_DECLARE_METATYPE(Box3m) +Q_DECLARE_METATYPE(Matrix33m) +Q_DECLARE_METATYPE(Matrix44m) +Q_DECLARE_METATYPE(Eigen::VectorXd) + /** *\brief The FilterPluginInterface class provide the interface of the filter plugins. * diff --git a/src/common/interfaces/plugin_interface.h b/src/common/interfaces/plugin_interface.h index ecaed63e3..a7cf9c23c 100644 --- a/src/common/interfaces/plugin_interface.h +++ b/src/common/interfaces/plugin_interface.h @@ -67,6 +67,8 @@ public: // NEVER EVER use a msgbox to say something to the user. template void log(const char* f, Ts&&... ts); + template + void log(const std::string& s, Ts&&... ts); void log(const char* s); void log(const std::string& s); @@ -99,6 +101,14 @@ void PluginInterface::log(const char* f, Ts&&... ts) } } +template +void PluginInterface::log(const std::string& s, Ts&&... ts) +{ + if(logstream != nullptr) { + logstream->Logf(GLLogStream::FILTER, s.c_str(), std::forward(ts)...); + } +} + template void PluginInterface::log(GLLogStream::Levels Level, const char* f, Ts&&... ts) { diff --git a/src/meshlabplugins/filter_measure/filter_measure.cpp b/src/meshlabplugins/filter_measure/filter_measure.cpp index 839df0e53..8a4bd35a8 100644 --- a/src/meshlabplugins/filter_measure/filter_measure.cpp +++ b/src/meshlabplugins/filter_measure/filter_measure.cpp @@ -39,6 +39,8 @@ using namespace std; using namespace vcg; +typedef Histogram Histogramm; + FilterMeasurePlugin::FilterMeasurePlugin() { typeList << COMPUTE_TOPOLOGICAL_MEASURES @@ -385,6 +387,8 @@ bool FilterMeasurePlugin::computeGeometricMeasures(MeshDocument& md, std::map::ComputeCloudBarycenter(m, false); log("Pointcloud (vertex) barycenter %9.6f %9.6f %9.6f", bc[0], bc[1], bc[2]); + outputValues["barycenter"] = QVariant::fromValue(bc); // if there is vertex quality, also provide weighted barycenter if (tri::HasPerVertexQuality(m)) @@ -401,6 +406,7 @@ bool FilterMeasurePlugin::computeGeometricMeasures(MeshDocument& md, std::map::ComputeCloudBarycenter(m, true); log("Pointcloud (vertex) barycenter, weighted by verytex quality:"); log(" %9.6f %9.6f %9.6f", bc[0], bc[1], bc[2]); + outputValues["vertex_quality_weighted_barycenter"] = QVariant::fromValue(bc); } // principal axis @@ -410,6 +416,7 @@ bool FilterMeasurePlugin::computeGeometricMeasures(MeshDocument& md, std::map::ComputeShellBarycenter(m); log("Thin shell (faces) barycenter: %9.6f %9.6f %9.6f", bc[0], bc[1], bc[2]); + outputValues["shell_barycenter"] = QVariant::fromValue(bc); // cloud barycenter bc = tri::Stat::ComputeCloudBarycenter(m, false); log("Vertices barycenter %9.6f %9.6f %9.6f", bc[0], bc[1], bc[2]); + outputValues["barycenter"] = QVariant::fromValue(bc); // is watertight? int edgeNum = 0, edgeBorderNum = 0, edgeNonManifNum = 0; @@ -450,6 +459,7 @@ bool FilterMeasurePlugin::computeGeometricMeasures(MeshDocument& md, std::map&) +bool FilterMeasurePlugin::perVertexQualityHistogram( + MeshDocument& md, + Scalarm RangeMin, + Scalarm RangeMax, + int binNum, + bool areaFlag, + std::map& outputValues) { CMeshO &m = md.mm()->cm; tri::Allocator::CompactEveryVector(m); - Histogramf H; + Histogramm H; H.SetRange(RangeMin, RangeMax, binNum); vector aVec(m.vn, 1.0); if (areaFlag) @@ -595,46 +615,42 @@ bool FilterMeasurePlugin::perVertexQualityHistogram(MeshDocument& md, Scalarm Ra for (int i = 0; i(m.vn, 1.0); - if (areaFlag) - tri::MeshToMatrix::PerVertexArea(m, aVec); + log("( -inf..%15.7f) : " + formatter, RangeMin, H.BinCountInd(0)); + rmin(0) = std::numeric_limits::min(); + rmax(0) = RangeMin; + count(0) = H.BinCountInd(0); + for (int i = 1; i <= binNum; ++i){ + log("[%15.7f..%15.7f) : " + formatter, H.BinLowerBound(i), H.BinUpperBound(i), H.BinCountInd(i)); + rmin(i) = H.BinLowerBound(i); + rmax(i) = H.BinUpperBound(i); + count(i) = H.BinCountInd(i); + } + log("[%15.7f.. +inf) : " + formatter, RangeMax, H.BinCountInd(binNum + 1)); + rmin(binNum+1) = RangeMax; + rmax(binNum+1) = std::numeric_limits::max(); + count(binNum+1) = H.BinCountInd(binNum+1); + outputValues["hist_bin_min"] = QVariant::fromValue(rmin); + outputValues["hist_bin_max"] = QVariant::fromValue(rmax); + outputValues["hist_count"] = QVariant::fromValue(count); - for (int i = 0; i&) +bool FilterMeasurePlugin::perFaceQualityHostogram( + MeshDocument& md, + Scalarm RangeMin, + Scalarm RangeMax, + int binNum, + bool areaFlag, + std::map& outputValues) { CMeshO &m = md.mm()->cm; tri::Allocator::CompactEveryVector(m); - Histogramf H; + Histogramm H; H.SetRange(RangeMin, RangeMax, binNum); vector aVec(m.fn, 1.0); @@ -643,37 +659,28 @@ bool FilterMeasurePlugin::perFaceQualityHostogram(MeshDocument& md, Scalarm Rang for (int i = 0; i(m.fn, 1.0); - if (areaFlag) - tri::MeshToMatrix::PerFaceArea(m, aVec); + log("( -inf..%15.7f) : " + formatter, RangeMin, H.BinCountInd(0)); + rmin(0) = std::numeric_limits::min(); + rmax(0) = RangeMin; + count(0) = H.BinCountInd(0); + for (int i = 1; i <= binNum; ++i) { + log("[%15.7f..%15.7f) : " + formatter, H.BinLowerBound(i), H.BinUpperBound(i), H.BinCountInd(i)); + rmin(i) = H.BinLowerBound(i); + rmax(i) = H.BinUpperBound(i); + count(i) = H.BinCountInd(i); + } + log("[%15.7f.. +inf) : " + formatter, RangeMax, H.BinCountInd(binNum + 1)); + rmin(binNum+1) = RangeMax; + rmax(binNum+1) = std::numeric_limits::max(); + count(binNum+1) = H.BinCountInd(binNum+1); + outputValues["hist_bin_min"] = QVariant::fromValue(rmin); + outputValues["hist_bin_max"] = QVariant::fromValue(rmax); + outputValues["hist_count"] = QVariant::fromValue(count); - for (int i = 0; i