#include <iostream>
#include <queue>
#include "DGtal/base/Common.h"
#include "DGtal/io/viewers/PolyscopeViewer.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"
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" );
PolyscopeViewer<> viewer;
auto params = SH3::defaultParameters();
trace.info() <<
"Building set or importing vol ... ";
Point p1( -50, -50, -50 );
std::set< Point > shape_set;
if ( fn == "" )
{
for (Domain::ConstIterator it =
domain.begin(); it !=
domain.end(); ++it )
{
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 );
bimage->setValue( p, true );
}
else
bimage->setValue( p, false );
}
}
else
{
params( "thresholdMin", m );
params( "thresholdMax", M );
bimage = SH3::makeBinaryImage( fn, params );
K = SH3::getKSpace( bimage );
if ( (*bimage)( p ) ) shape_set.insert( p );
}
std::set< Point > origin_set( shape_set );
trace.info() <<
" [Done]" << std::endl;
{
params( "surfaceComponents" , "All" );
auto surface = SH3::makeDigitalSurface( bimage,
K, params );
SH3::saveOBJ(
surface,
"source.obj" );
}
trace.beginBlock (
"Thinning" );
SH3::BinaryImage&
image = *bimage;
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 ( it = to_process.begin(), itE = to_process.end(); it != itE; ++it )
{
if ( !
image( p ) )
continue;
nca.setCenter( p,
image );
if ( full_cvx
? nca.isFullyConvexCollapsible()
: nca.is0ConvexCollapsible() )
{
std::vector< Point > neighbors;
nca.getLocalX( neighbors, false );
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" );
auto surface = SH3::makeDigitalSurface( bimage,
K, params );
SH3::saveOBJ(
surface,
"geom-thinned.obj" );
}
for ( auto p : origin_set ) origin.insert( p );
for ( auto p : shape_set ) output.insert( p );
viewer <<
Color(25,25,255, 255);
viewer << output;
viewer <<
Color(250, 0,0, 25);
viewer << origin;
return 0;
}
Structure representing an RGB triple with alpha component.
Aim: Smart pointer based on reference counts.
void show() override
Starts the event loop and display of elements.
CountedPtr< SH3::DigitalSurface > surface
NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet