Extracting 3D surface slice with DigitalSurfaceTracker.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/topology/SurfelAdjacency.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/SetOfSurfels.h"
#include "DGtal/topology/DigitalSurface2DSlice.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "ConfigExamples.h"
int main(
int argc,
char** argv )
{
trace.beginBlock(
"Reading vol file into an image." );
typedef ImageSelector < Domain, int>::Type
Image;
std::string inputFilename = examplesPath + "samples/Al.100.vol";
0, 1 );
PolyscopeViewer<> viewer;
trace.beginBlock(
"Construct the Khalimsky space from the image domain." );
bool space_ok = ks.init(
image.domain().lowerBound(),
image.domain().upperBound(),
true );
if (!space_ok)
{
trace.error() <<
"Error in the Khamisky space construction."<<std::endl;
return 2;
}
MySurfelAdjacency surfAdj( true );
trace.beginBlock(
"Extracting boundary by scanning the space. " );
typedef KSpace::Surfel
Surfel;
MySetOfSurfels theSetOfSurfels( ks, surfAdj );
ks, set3d,
image.domain().lowerBound(),
image.domain().upperBound() );
trace.info() <<
"Digital surface has " << digSurf.size() <<
" surfels."
<< std::endl;
trace.beginBlock(
"Extract slices." );
typedef MyDigitalSurface::DigitalSurfaceTracker MyTracker;
Surfel surf = *digSurf.begin();
MyTracker* tracker1 = digSurf.container().newTracker( surf );
MyTracker* tracker2 = digSurf.container().newTracker( surf );
My2DSlice slice1( tracker1, *(ks.sDirs( surf )) );
My2DSlice slice2( tracker2, *++(ks.sDirs( surf )) );
delete tracker1;
delete tracker2;
ASSERT( slice1.start() == slice1.begin() );
ASSERT( slice1.cstart() == slice1.c() );
ASSERT( *slice1.begin() == surf );
ASSERT( *slice1.c() == surf );
ASSERT( *slice1.start() == surf );
ASSERT( *slice1.cstart() == surf );
ASSERT( *slice1.rcstart() == surf );
ASSERT( slice1.rcstart() == slice1.rc() );
ASSERT( *slice1.rc() == surf );
ASSERT( *(slice1.c()+1) == *(slice1.begin()+1) );
ASSERT( *(slice1.rc()+1) == *(slice1.rbegin()) );
trace.beginBlock(
"Display all with Viewer." );
for( MyDigitalSurface::ConstIterator it = theSetOfSurfels.begin(),
it_end = theSetOfSurfels.end(); it != it_end; ++it )
viewer<< *it;
int d=0;
for ( My2DSlice::ConstIterator it = slice1.begin(),
it_end = slice1.end(); it != it_end; ++it )
{
viewer<< *it;
d++;
}
d=0;
for ( My2DSlice::ConstIterator it = slice2.begin(),
it_end = slice2.end(); it != it_end; ++it )
{
Color col= cmap_grad2(d);
viewer<< *it;
d++;
}
viewer << surf ;
return 0;
}
Structure representing an RGB triple with alpha component.
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
Aim: Represents a 2-dimensional slice in a DigitalSurface. In a sense, it is a 4-connected contour,...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
void drawColor(const DGtal::Color &color)
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
void show() override
Starts the event loop and display of elements.
static void sMakeBoundary(SCellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::SurfelSet SurfelSet
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
static void append(Set &aSet, const ForegroundPredicate &isForeground, typename Image::Domain::ConstIterator itBegin, typename Image::Domain::ConstIterator itEnd)
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
ImageContainerBySTLVector< Domain, Value > Image
Z2i::DigitalSet DigitalSet