A full convexity thinning is an iterative removal of fully convex collapsible points from a given digital object. This is an experimental test.
#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/io/Color.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/helpers/Shortcuts.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/geometry/volumes/NeighborhoodConvexityAnalyzer.h"
using namespace std;
using namespace Z3i;
int main(
int argc,
char** argv )
{
trace.
info() <<
"Usage: " << argv[ 0 ] <<
" <thickness> <convexity> <input.vol> <m> <M>" << std::endl;
trace.
info() <<
" - convexity in {0,1}: 0=0-convexity, 1=full-convexity"<< std::endl;
int thickness = argc > 1 ? atoi( argv[ 1 ] ) : 2;
bool full_cvx = argc > 2 ? atoi( argv[ 2 ] ) == 1 : false;
std::string fn= argc > 3 ? argv[ 3 ] : "";
int m = argc > 4 ? atoi( argv[ 4 ] ) : 0;
int M = argc > 5 ? atoi( argv[ 5 ] ) : 255;
trace.
beginBlock (
"Example of 3D shape thinning with full convexity properties" );
QApplication application(argc,argv);
viewer.setWindowTitle("fullConvexityThinning3D");
trace.
info() <<
"Building set or importing vol ... ";
Point p1( -50, -50, -50 );
std::set< Point > shape_set;
if ( fn == "" )
{
{
if ( ((p - c ).norm() <= 22+thickness ) && ((p - c ).norm() >= 20-thickness)
&& ( ((p[0] <= thickness)&& (p[0] >= -thickness))
|| ((p[1] <= thickness)&& (p[1] >= -thickness))))
{
shape_set.insert( p );
}
else
}
}
else
{
params( "thresholdMin", m );
params( "thresholdMax", M );
if ( (*bimage)( p ) ) shape_set.insert( p );
}
std::set< Point > origin_set( shape_set );
{
params( "surfaceComponents" , "All" );
}
NCA nca( p1, p2, 10000 );
int nb_simple=0;
std::set< Point >::iterator it, itE;
std::set< Point > to_process( shape_set );
do
{
std::set< Point > next_to_process;
nb_simple = 0;
trace.
info() <<
"Pass #S=" << shape_set.size()
<< " #Q=" << to_process.size() << std::endl;
for ( auto it = to_process.begin(), itE = to_process.end(); it != itE; ++it )
{
if ( !
image( p ) )
continue;
if ( full_cvx
{
std::vector< Point > neighbors;
for ( auto q : neighbors ) next_to_process.insert( q );
shape_set.erase( p );
image.setValue( p, false );
++nb_simple;
}
}
trace.
info() <<
" => nb_removed=" << nb_simple<< std::endl;
if ( nb_simple != 0 )
std::swap( to_process, next_to_process );
}
while ( nb_simple != 0 );
{
params( "surfaceComponents" , "All" );
}
for (
auto p : origin_set ) origin.
insert( p );
for (
auto p : shape_set ) output.
insert( p );
viewer << output;
viewer << origin;
viewer<< Viewer3D<>::updateDisplay;
return application.exec();
}