DGtal  1.3.beta
topology/digitalSurfaceSlice.cpp

Extracting 3D surface slice with DigitalSurfaceTracker.

See also
Tracking a 3D boundary to build a surface.
Extraction of 2 surface slice associated to one surfel.
#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 DGtal;
using namespace Z3i;
int main( int argc, char** argv )
{
// for 3D display with Viewer3D
QApplication application(argc,argv);
trace.beginBlock( "Reading vol file into an image." );
std::string inputFilename = examplesPath + "samples/Al.100.vol";
Image image = VolReader<Image>::importVol(inputFilename);
DigitalSet set3d (image.domain());
0, 1 );
Viewer3D<> viewer;
viewer.show();
trace.beginBlock( "Construct the Khalimsky space from the image domain." );
KSpace ks;
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 ); // interior in all directions.
trace.beginBlock( "Extracting boundary by scanning the space. " );
typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
MySetOfSurfels theSetOfSurfels( ks, surfAdj );
Surfaces<KSpace>::sMakeBoundary( theSetOfSurfels.surfelSet(),
ks, set3d,
image.domain().lowerBound(),
image.domain().upperBound() );
MyDigitalSurface digSurf( theSetOfSurfels );
trace.info() << "Digital surface has " << digSurf.size() << " surfels."
<< std::endl;
trace.beginBlock( "Extract slices." );
//Extract an initial boundary cell
Surfel surf = *digSurf.begin();
MyTracker* tracker1 = digSurf.container().newTracker( surf );
MyTracker* tracker2 = digSurf.container().newTracker( surf );
// Extract the bondary contour associated to the initial surfel in
// its first direction
My2DSlice slice1( tracker1, *(ks.sDirs( surf )) );
// Extract the bondary contour associated to the initial surfel in
// its second direction
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 QGLViewer." );
// Displaying all the surfels in transparent mode
viewer << SetMode3D( surf.className(), "Transparent");
for( MyDigitalSurface::ConstIterator it = theSetOfSurfels.begin(),
it_end = theSetOfSurfels.end(); it != it_end; ++it )
viewer<< *it;
// Displaying First surfels cut with gradient colors.;
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 ) );
// Need to avoid surfel superposition (the surfel size in increased)
viewer << Viewer3D<>::shiftSurfelVisu;
viewer << SetMode3D( surf.className(), "");
viewer.setFillColor(Color(180, 200, 25, 255));
int d=0;
for ( My2DSlice::ConstIterator it = slice1.begin(),
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;
for ( My2DSlice::ConstIterator it = slice2.begin(),
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++;
}
// One need once again to avoid superposition.
viewer << Viewer3D<>::shiftSurfelVisu;
viewer.setFillColor(Color(18, 200, 25, 255));
viewer << surf ;
viewer << Viewer3D<>::updateDisplay;
return application.exec();
}
// //
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::DigitalSurface::ConstIterator
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Definition: DigitalSurface.h:163
DGtal::SetFromImage
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
DGtal::Trace::endBlock
double endBlock()
DGtal::KhalimskySpaceND::SurfelSet
std::set< SCell > SurfelSet
Preferred type for defining a set of surfels (always signed cells).
Definition: KhalimskySpaceND.h:450
DGtal::DigitalSurface::DigitalSurfaceTracker
DigitalSurfaceContainer::DigitalSurfaceTracker DigitalSurfaceTracker
Definition: DigitalSurface.h:164
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::Trace::error
std::ostream & error()
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
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::DigitalSurface::size
Size size() const
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::KhalimskySpaceND::sDirs
DirIterator sDirs(const SCell &p) const
Given a signed cell [p], returns an iterator to iterate over each coordinate the cell spans.
DGtal::KhalimskySpaceND::lowerBound
const Point & lowerBound() const
Return the lower bound for digital points in this space.
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::Color::red
void red(const unsigned char aRedValue)
DGtal::Trace::info
std::ostream & info()
Surfel
KSpace::SCell Surfel
Definition: testArithmeticalDSSComputerOnSurfels.cpp:50
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
DGtal::SignedKhalimskyCell::className
std::string className() const
Return the style name used for drawing this object.
DGtal::Viewer3D
Definition: Viewer3D.h:135
DGtal::DigitalSurface::begin
ConstIterator begin() const
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
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::Color::green
void green(const unsigned char aGreenValue)
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::Display3D< SpaceND< 3 >, KhalimskySpaceND< 3 > >::setFillColor
virtual void setFillColor(DGtal::Color aColor)
DGtal::Color::blue
void blue(const unsigned char aBlueValue)
DGtal::GradientColorMap::addColor
void addColor(const Color &color)
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal::DigitalSurface2DSlice
Aim: Represents a 2-dimensional slice in a DigitalSurface. In a sense, it is a 4-connected contour,...
Definition: DigitalSurface2DSlice.h:93
DGtal::SetOfSurfels
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: SetOfSurfels.h:73
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::DigitalSurface::container
const DigitalSurfaceContainer & container() const
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119
MyDigitalSurface
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Definition: greedy-plane-segmentation-ex2.cpp:92
SurfelSet
MyDigitalSurface::SurfelSet SurfelSet
Definition: greedy-plane-segmentation-ex2.cpp:95
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64