DGtal 1.3.0
No Matches

A simple example illustrating the extraction of the sequence of surfels boudary. This program outputs this image.

See also
Tracking a 3D boundary to build a surface.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/DrawWithDisplay3DModifier.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;
int main( int argc, char** argv )
trace.beginBlock ( "Example ctopo-2-3d" );
// for 3D display with Viewer3D
QApplication application(argc,argv);
typedef ImageSelector < Z3i::Domain, int>::Type Image;
std::string inputFilename = examplesPath + "samples/cat10.vol";
Image image = VolReader<Image>::importVol(inputFilename);
Z3i::DigitalSet set3d (image.domain());
// 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;
std::vector<Z3i::SCell> vectBdrySCell;
std::vector<Z3i::SCell> vectBdrySCell2;
std::set<Z3i::SCell> vectBdrySCellALL;
SurfelAdjacency<3> SAdj( true );
//Extract an initial boundary cell
trace.info() << "Tracking Boundary.."<<std::endl;
// Extracting all boundary surfels which are connected to the initial boundary Cell.
ks,SAdj, set3d, aCell );
// Extract the bondary contour associated to the initial surfel in its first direction
ks, *(ks.sDirs( aCell )), SAdj,
set3d, aCell );
// Extract the bondary contour associated to the initial surfel in its second direction
ks, *(++(ks.sDirs( aCell ))), SAdj,
set3d, aCell );
// Displaying all the surfels in transparent mode
typedef Viewer3D <Z3i::Space,Z3i::KSpace> MyViewer;
MyViewer viewer(ks);
trace.info() << "Displaying the surfels.."<<std::endl;
viewer << SetMode3D((*(vectBdrySCellALL.begin())).className(), "Transparent");
for( std::set<Z3i::SCell>::iterator it=vectBdrySCellALL.begin();
it!= vectBdrySCellALL.end(); it++){
viewer<< *it;
// Displaying First surfels cut with gradient colors.;
GradientColorMap<int> cmap_grad(0, (const int)vectBdrySCell2.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<Z3i::Space,Z3i::KSpace>::shiftSurfelVisu;
viewer << SetMode3D((*(vectBdrySCell2.begin())).className(), "");
viewer.setFillColor(Color(180, 200, 25, 255));
int d=0;
for( std::vector<Z3i::SCell>::iterator it=vectBdrySCell2.begin();
it!= vectBdrySCell2.end(); it++){
Color col= cmap_grad(d);
viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
viewer<< *it;
GradientColorMap<int> cmap_grad2(0, (const int)vectBdrySCell.size());
cmap_grad2.addColor( Color( 50, 50, 255 ) );
cmap_grad2.addColor( Color( 255, 0, 0 ) );
cmap_grad2.addColor( Color( 255, 255, 10 ) );
viewer << Viewer3D<>::shiftSurfelVisu;
for( std::vector<Z3i::SCell>::iterator it=vectBdrySCell.begin();
it!= vectBdrySCell.end(); it++){
Color col= cmap_grad2(d);
viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
viewer<< *it;
// On need once again to avoid superposition.
viewer << MyViewer::shiftSurfelVisu;
viewer.setFillColor(Color(18, 200, 25, 255));
viewer << aCell ;
viewer << MyViewer::updateDisplay;
return application.exec();
// //
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DirIterator sDirs(const SCell &p) const
Given a signed cell [p], returns an iterator to iterate over each coordinate the cell spans.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
std::ostream & error()
std::ostream & info()
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
int main()
Definition: testBits.cpp:56
ImageContainerBySTLVector< Domain, Value > Image