Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tools ExtractAccoOrigins and fix duplicated accumulations values #30

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ SET(CDCVAM_BIN
centerLineGeodesicGraph
compAccFromMesh
displayAccuMesh
compAccFromNormals)
compAccFromNormals
extractAccOrigins)

if ( WITH_VISU3D_QGLVIEWER )
SET(CDCVAM_BIN ${CDCVAM_BIN} illustrationGraphAllSteps)
Expand Down
106 changes: 106 additions & 0 deletions bin/extractAccOrigins.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>


#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include <DGtal/io/readers/GenericReader.h>
#include <DGtal/io/writers/GenericWriter.h>
#include <DGtal/io/writers/VolWriter.h>
#include <DGtal/io/writers/LongvolWriter.h>

#include <DGtal/io/readers/MeshReader.h>
#include <DGtal/io/writers/MeshWriter.h>

#include <DGtal/images/ImageContainerBySTLVector.h>

#include "CLI11.hpp"

#include "NormalAccumulator.h"


using namespace std;
using namespace DGtal;

typedef ImageContainerBySTLVector<Z3i::Domain, DGtal::uint64_t> Image3D;
typedef ImageContainerBySTLVector<Z3i::Domain, double> 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<Z3i::RealPoint> 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;
}

16 changes: 14 additions & 2 deletions src/NormalAccumulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}




Expand Down Expand Up @@ -399,8 +409,10 @@ NormalAccumulator::computeConfidence(bool updateVertexAsso, unsigned int minAcc

while((currentPoint - centerPoint).norm()<myRadius){
DGtal::Z3i::Point currentPointI = DGtal::Z3i::Point(currentPoint,DGtal::functors::Round<>());

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;
Expand Down
21 changes: 19 additions & 2 deletions src/NormalAccumulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int> PointIndexContainer;
typedef std::vector<Point> PointContainer;
typedef std::vector<Vector> VectorContainer;
typedef std::vector<Vector> VectorContainer;

// types of image containers:
typedef DGtal::ImageContainerBySTLVector<DGtal::Z3i::Domain, DGtal::uint64_t> Image3D;
typedef DGtal::ImageContainerBySTLVector<DGtal::Z3i::Domain, double> Image3DDouble;
// to recover the origin point which has contributed to a particular voxel.
typedef DGtal::ImageContainerBySTLVector<DGtal::Z3i::Domain, std::vector<unsigned int> > ImagePointAssociation;
typedef DGtal::ImageContainerBySTLVector<DGtal::Z3i::Domain, PointIndexContainer > ImagePointAssociation;



Expand Down Expand Up @@ -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.
Expand Down
Loading