DGtal  1.3.beta
geometry/volumes/fullConvexityThinning3D.cpp

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 DGtal;
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);
Viewer3D<> viewer;
viewer.setWindowTitle("fullConvexityThinning3D");
viewer.show();
auto params = SH3::defaultParameters();
// Domain creation from two bounding points.
trace.info() << "Building set or importing vol ... ";
Point c( 0, 0, 0 );
Point p1( -50, -50, -50 );
Point p2( 50, 50, 50 );
Domain domain( p1, p2 );
std::set< Point > shape_set;
if ( fn == "" )
{
K.init( p1, p2, true );
for (Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
{
Point p = *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 );
p1 = K.lowerBound();
p2 = K.upperBound();
domain = Domain( p1, p2 );
for ( auto p : domain )
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 );
bool ok = 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 ( auto it = to_process.begin(), itE = to_process.end(); it != itE; ++it )
{
Point p = *it;
if ( ! image( p ) ) continue; // already removed
nca.setCenter( p, image );
if ( full_cvx
{
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" );
}
// Display by using two different list to manage OpenGL transparency.
DigitalSet origin( domain );
DigitalSet output( domain );
for ( auto p : origin_set ) origin.insert( p );
for ( auto p : shape_set ) output.insert( p );
viewer << SetMode3D( output.className(), "Paving" );
viewer << CustomColors3D(Color(25,25,255, 255), Color(25,25,255, 255));
viewer << output;
viewer << SetMode3D( origin.className(), "PavingTransp" );
viewer << CustomColors3D(Color(250, 0,0, 25), Color(250, 0,0, 5));
viewer << origin;
viewer<< Viewer3D<>::updateDisplay;
return application.exec();
}
// //
image
Image image(domain)
DGtal::KhalimskySpaceND::upperBound
const Point & upperBound() const
Return the upper bound for digital points in this space.
DGtal::HyperRectDomain< Space >
DGtal::NeighborhoodConvexityAnalyzer::isFullyConvexCollapsible
bool isFullyConvexCollapsible()
Definition: NeighborhoodConvexityAnalyzer.h:243
DGtal::Trace::endBlock
double endBlock()
SH3
Shortcuts< KSpace > SH3
Definition: testArithmeticalDSSComputerOnSurfels.cpp:49
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::DigitalSetByAssociativeContainer::className
std::string className() const
DGtal::trace
Trace trace
Definition: Common.h:154
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Shortcuts::makeDigitalSurface
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1209
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::ImageContainerBySTLVector::setValue
void setValue(const Point &aPoint, const Value &aValue)
DGtal::KhalimskySpaceND::lowerBound
const Point & lowerBound() const
Return the lower bound for digital points in this space.
DGtal::Shortcuts
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:104
DGtal::Trace::info
std::ostream & info()
DGtal::Viewer3D
Definition: Viewer3D.h:135
DGtal::Shortcuts::defaultParameters
static Parameters defaultParameters()
Definition: Shortcuts.h:203
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Domain
HyperRectDomain< Space > Domain
Definition: testSimpleRandomAccessRangeFromPoint.cpp:44
DGtal::NeighborhoodConvexityAnalyzer::setCenter
void setCenter(Point c, const PointPredicate &X)
DGtal::DigitalSetByAssociativeContainer::insert
void insert(const Point &p)
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
DGtal::CountedPtr
Aim: Smart pointer based on reference counts.
Definition: CountedPtr.h:79
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:73
DGtal::NeighborhoodConvexityAnalyzer
Aim: A class that models a neighborhood and that provides services to analyse the convexity properti...
Definition: NeighborhoodConvexityAnalyzer.h:94
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Shortcuts::getKSpace
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:332
DGtal::NeighborhoodConvexityAnalyzer::getLocalX
void getLocalX(std::vector< Point > &localX, bool with_center) const
DGtal::HyperRectDomain_Iterator
Iterator for HyperRectDomain.
Definition: HyperRectDomain_Iterator.h:142
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::Viewer3D::show
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DGtal::Shortcuts::saveOBJ
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, const TCellEmbedder &embedder, const RealVectors &normals, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
Definition: Shortcuts.h:1739
DGtal::Shortcuts::makeBinaryImage
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
Definition: Shortcuts.h:561
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::NeighborhoodConvexityAnalyzer::is0ConvexCollapsible
bool is0ConvexCollapsible()
Definition: NeighborhoodConvexityAnalyzer.h:271
NCA
NeighborhoodConvexityAnalyzer< KSpace, 1 > NCA
Definition: fullConvexityThinning3D.cpp:60
DGtal::DigitalSetByAssociativeContainer
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Definition: DigitalSetByAssociativeContainer.h:89
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64