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/DrawWithDisplay3DModifier.h"
#include "DGtal/io/viewers/Viewer3D.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"
using namespace std;
using namespace Z3i;
int main(
int argc,
char** argv )
{
QApplication application(argc,argv);
typedef ImageSelector < Domain, int>::Type
Image;
std::string inputFilename = examplesPath + "samples/Al.100.vol";
Image image = VolReader<Image>::importVol(inputFilename);
SetFromImage<DigitalSet>::append<Image>(set3d, image,
0, 1 );
Viewer3D<> viewer;
viewer.show();
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;
}
typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
MySurfelAdjacency surfAdj( true );
typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
MySetOfSurfels theSetOfSurfels( ks, surfAdj );
Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
ks, set3d,
image.domain().lowerBound(),
image.domain().upperBound() );
trace.
info() <<
"Digital surface has " << digSurf.size() <<
" surfels."
<< std::endl;
typedef MyDigitalSurface::DigitalSurfaceTracker MyTracker;
typedef DigitalSurface2DSlice< MyTracker > My2DSlice;
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()) );
viewer << SetMode3D( surf.className(), "Transparent");
it_end = theSetOfSurfels.end(); it != it_end; ++it )
viewer<< *it;
GradientColorMap<int> cmap_grad( 0, slice1.size() );
cmap_grad.addColor( Color( 50, 50, 255 ) );
cmap_grad.addColor( Color( 255, 0, 0 ) );
cmap_grad.addColor( Color( 255, 255, 10 ) );
viewer << Viewer3D<>::shiftSurfelVisu;
viewer << SetMode3D( surf.className(), "");
viewer.setFillColor(Color(180, 200, 25, 255));
int d=0;
it_end = slice1.end(); it != it_end; ++it )
{
Color col= cmap_grad(d);
viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
viewer<< *it;
d++;
}
GradientColorMap<int> cmap_grad2( 0, slice2.size() );
cmap_grad2.addColor( Color( 50, 50, 255 ) );
cmap_grad2.addColor( Color( 255, 0, 0 ) );
cmap_grad2.addColor( Color( 255, 255, 10 ) );
d=0;
it_end = slice2.end(); it != it_end; ++it )
{
Color col= cmap_grad2(d);
viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
viewer<< *it;
d++;
}
viewer << Viewer3D<>::shiftSurfelVisu;
viewer.setFillColor(Color(18, 200, 25, 255));
viewer << surf ;
viewer << Viewer3D<>::updateDisplay;
return application.exec();
}
void beginBlock(const std::string &keyword="")
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::ConstIterator ConstIterator
MyDigitalSurface::SurfelSet SurfelSet
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
ImageContainerBySTLVector< Domain, Value > Image
Z2i::DigitalSet DigitalSet