DGtal  1.3.beta
topology/homotopicThinning3D.cpp

An homotopic thinning is an iterative removal of simple points from a given digital object.

See also
Simple points
Resulting 3d thinning with the 18_6 object
Resulting 3d thinning with the 6_26 object
#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"
using namespace std;
using namespace DGtal;
using namespace Z3i;
int main( int argc, char** argv )
{
trace.beginBlock ( "Example simple example of 3DViewer" );
QApplication application(argc,argv);
Viewer3D<> viewer;
viewer.setWindowTitle("simpleExample3DViewer");
viewer.show();
// Domain cretation from two bounding points.
Point c( 0, 0, 0 );
Point p1( -50, -50, -50 );
Point p2( 50, 50, 50 );
Domain domain( p1, p2 );
trace.warning() << "Constructing a ring DigitalSet ... ";
DigitalSet shape_set( domain );
for (Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it )
{
if ( ((*it - c ).norm() <= 25) && ((*it - c ).norm() >= 18)
&& ( (((*it)[0] <= 3)&& ((*it)[0] >= -3))|| (((*it)[1] <= 3)&& ((*it)[1] >= -3)))){
shape_set.insertNew( *it );
}
}
trace.warning() << " [Done]" << std::endl;
trace.beginBlock ( "Thinning" );
Object18_6 shape( dt18_6, shape_set );
int nb_simple=0;
DigitalSet::Iterator it, itE;
do
{
DigitalSet & S = shape.pointSet();
std::queue<DigitalSet::Iterator> Q;
it = S.begin();
itE = S.end();
#ifdef WITH_OPENMP
std::vector<DigitalSet::Iterator> v( S.size() );
std::vector<uint8_t> b( v.size() );
for ( size_t i = 0; it != itE; ++it, ++i )
v[ i ] = it;
#pragma omp parallel for schedule(dynamic)
for ( size_t i = 0; i < v.size(); ++i )
b[ i ] = shape.isSimple( *(v[ i ]) );
for ( size_t i = 0; i < v.size(); ++i )
if ( b[ i ] ) Q.push( v[ i ] );
#else
for ( ; it != itE; ++it )
if ( shape.isSimple( *it ) )
Q.push( it );
#endif
nb_simple = 0;
while ( ! Q.empty() )
{
DigitalSet::Iterator itt = Q.front();
Q.pop();
if ( shape.isSimple( *itt ) )
{
S.erase( *itt );
++nb_simple;
}
}
}
while ( nb_simple != 0 );
DigitalSet & S = shape.pointSet();
// Display by using two different list to manage OpenGL transparency.
viewer << SetMode3D( shape_set.className(), "Paving" );
viewer << CustomColors3D(Color(25,25,255, 255), Color(25,25,255, 255));
viewer << S ;
viewer << SetMode3D( shape_set.className(), "PavingTransp" );
viewer << CustomColors3D(Color(250, 0,0, 25), Color(250, 0,0, 5));
viewer << shape_set;
viewer<< Viewer3D<>::updateDisplay;
return application.exec();
}
// //
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Z3i::Object18_6
Object< DT18_6, DigitalSet > Object18_6
Definition: StdDefs.h:178
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
DGtal::Viewer3D
Definition: Viewer3D.h:135
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::CustomColors3D
Definition: DrawWithDisplay3DModifier.h:129
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:73
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
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::Trace::warning
std::ostream & warning()
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
Point
MyPointD Point
Definition: testClone2.cpp:383