From ab4c744a681aadd4255aa44d819d8ac52432afe8 Mon Sep 17 00:00:00 2001 From: Bertrand Kerautret Date: Fri, 6 Oct 2023 16:37:33 +0200 Subject: [PATCH 1/2] base tools to extract acc origins --- bin/CMakeLists.txt | 3 +- bin/extractAccOrigins.cpp | 106 ++++++++++++++++++++++++++++++++++++++ src/NormalAccumulator.cpp | 10 ++++ src/NormalAccumulator.h | 21 +++++++- 4 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 bin/extractAccOrigins.cpp diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index 7cb6e49..df8a44b 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -2,7 +2,8 @@ SET(CDCVAM_BIN centerLineGeodesicGraph compAccFromMesh displayAccuMesh - compAccFromNormals) + compAccFromNormals + extractAccOrigins) if ( WITH_VISU3D_QGLVIEWER ) SET(CDCVAM_BIN ${CDCVAM_BIN} illustrationGraphAllSteps) diff --git a/bin/extractAccOrigins.cpp b/bin/extractAccOrigins.cpp new file mode 100644 index 0000000..fbb7dfc --- /dev/null +++ b/bin/extractAccOrigins.cpp @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include + + +#include "DGtal/helpers/StdDefs.h" +#include "DGtal/base/Common.h" +#include +#include +#include +#include + +#include +#include + +#include + +#include "CLI11.hpp" + +#include "NormalAccumulator.h" + + +using namespace std; +using namespace DGtal; + +typedef ImageContainerBySTLVector Image3D; +typedef ImageContainerBySTLVector ImageDouble; + +typedef Z3i::Domain::Predicate DomainPredicate; + + + + +/** + * @brief main function call + * + */ +int main(int argc, char *const *argv) +{ + string inputFile; + string outputAccOrigins {"exportedAcc.dat"}; + unsigned int thAcc {50}; + double thConf {0.75}; + double radius {5.0}; + bool invertNormal {false}; + + + // parse command line using CLI ---------------------------------------------- + CLI::App app; + app.description("Compute the accumulation origins from a mesh and export in dat format : X Y Z NbAcc NbAccM Id1 Id2 ... IdNbAccM ... NbAcc " + "of all faces participating to the accumulation" ); + app.add_option("-i,--input,1", inputFile, "input mesh." ) + ->required() + ->check(CLI::ExistingFile); + app.add_option("--output,-o,2",outputAccOrigins,"output accumulation origins.", true); + + app.add_option("--radius,-r", radius, "radius of accumulation analysis.", true); + app.add_flag("--invertNormal", invertNormal, "export the accumulation vectors."); + app.add_option("--maxThAccVectors", thAcc, "threshold the value of accumulations used to decide to export the accumulations vectors (used with outputAccVectors) .", true); + app.add_option("--maxThConfVectors",thConf, "threshold the value of confidence to export the accumulations vectors (used with outputConfVectors) .", true); + + app.get_formatter()->column_width(40); + CLI11_PARSE(app, argc, argv); + // END parse command line using CLI ---------------------------------------------- + + + // 1) Reading input mesh + Mesh aMesh(true); + aMesh << inputFile; + + // 2) Init an NormalAccumulator + NormalAccumulator normAcc(radius, "mean"); + normAcc.initFromMesh(aMesh, invertNormal); + + // 3) Generate accumulation image + normAcc.computeAccumulation(); + NormalAccumulator::Image3D &imageAccumulation = normAcc.getAccumulationImage(); + + if(outputAccOrigins != "") + { + ofstream fout; fout.open(outputAccOrigins.c_str(), ofstream::binary|ofstream::out); + for(const auto &p: imageAccumulation.domain()) + { + if(imageAccumulation(p)>thAcc) + { + NormalAccumulator::PointIndexContainer setIndexPt = normAcc.getAssociatedIndexPoints(p); + if(setIndexPt.size()!=0){ + fout << p[0] << " " << p[1] << " " << p[2] << " " << imageAccumulation(p) << " " ; + for(const auto &i: setIndexPt) + { + fout << i << " "; + } + fout << std::endl; + } + } + } + fout.close(); + } + + + + return 0; +} + diff --git a/src/NormalAccumulator.cpp b/src/NormalAccumulator.cpp index 1d4fca3..eb83b78 100644 --- a/src/NormalAccumulator.cpp +++ b/src/NormalAccumulator.cpp @@ -371,6 +371,16 @@ NormalAccumulator::getAssociatedPoints(const DGtal::Z3i::Point &aVoxel) return result; } +NormalAccumulator::PointIndexContainer +NormalAccumulator::getAssociatedIndexPoints(const DGtal::Z3i::Point &aVoxel) +{ + PointIndexContainer result; + for(unsigned int ptId :myAssociationImage(aVoxel)){ + result.push_back(ptId); + } + return result; +} + diff --git a/src/NormalAccumulator.h b/src/NormalAccumulator.h index ac440af..99ba878 100644 --- a/src/NormalAccumulator.h +++ b/src/NormalAccumulator.h @@ -41,14 +41,15 @@ class NormalAccumulator{ typedef typename DGtal::Z3i::Domain Domain; typedef typename DGtal::Z3i::RealPoint Point; typedef typename DGtal::Z3i::RealPoint Vector; + typedef std::vector PointIndexContainer; typedef std::vector PointContainer; - typedef std::vector VectorContainer; + typedef std::vector VectorContainer; // types of image containers: typedef DGtal::ImageContainerBySTLVector Image3D; typedef DGtal::ImageContainerBySTLVector Image3DDouble; // to recover the origin point which has contributed to a particular voxel. - typedef DGtal::ImageContainerBySTLVector > ImagePointAssociation; + typedef DGtal::ImageContainerBySTLVector ImagePointAssociation; @@ -189,6 +190,22 @@ class NormalAccumulator{ PointContainer getAssociatedPoints(const DGtal::Z3i::Point &aVoxel); + + /** + * Get the associated input index points associated to a voxel. It can be + * all the points with normal contributing to the accumulation or + * the confidence (if the point association is updated whe when + * calling computeConfidence and passing true on argument + * updateVertexAsso). + * The index can be useful to process mesh by recovering the index of the + * face voting for the particular voxel. + * + * + * @param aVoxel the input voxel + * @return the container with all point contributing to the condidence. + **/ + + PointIndexContainer getAssociatedIndexPoints(const DGtal::Z3i::Point &aVoxel); /** * return the maximum accumulation value. From a3337c60423a3d98fd107841e72166b7de1aa000 Mon Sep 17 00:00:00 2001 From: Bertrand Kerautret Date: Sat, 7 Oct 2023 11:31:07 +0200 Subject: [PATCH 2/2] fix duoplicated points accumulation from rounding to interger previous point --- src/NormalAccumulator.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/NormalAccumulator.cpp b/src/NormalAccumulator.cpp index eb83b78..03f2d21 100644 --- a/src/NormalAccumulator.cpp +++ b/src/NormalAccumulator.cpp @@ -409,8 +409,10 @@ NormalAccumulator::computeConfidence(bool updateVertexAsso, unsigned int minAcc while((currentPoint - centerPoint).norm()()); - - if(myDomain.isInside(currentPointI) && previousPoint != currentPoint){ + DGtal::Z3i::Point previousPointI = DGtal::Z3i::Point(previousPoint, + DGtal::functors::Round<>()); + + if(myDomain.isInside(currentPointI) && previousPointI != currentPointI){ unsigned int valAcc = myAccumulationImage(currentPointI); if( valAcc > aMaxAcc){ aMaxAcc = valAcc;