DGtal  1.3.beta
topology/ctopo-2-3d.cpp

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);
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
MyViewer viewer(ks);
viewer.show();
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;
}
trace.info()<<"done"<<std::endl;
// 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;
d++;
}
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;
d=0;
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;
d++;
}
// On need once again to avoid superposition.
viewer.setFillColor(Color(18, 200, 25, 255));
viewer << aCell ;
return application.exec();
}
// //
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::SetFromImage
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::SurfelAdjacency
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Definition: SurfelAdjacency.h:65
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::trace
Trace trace
Definition: Common.h:154
DGtal::Display3D::updateDisplay
@ updateDisplay
Definition: Display3D.h:249
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::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::Display3D::shiftSurfelVisu
@ shiftSurfelVisu
Definition: Display3D.h:249
DGtal::Color::red
void red(const unsigned char aRedValue)
DGtal::Trace::info
std::ostream & info()
DGtal::Viewer3D
Definition: Viewer3D.h:135
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::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::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::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119
DGtal::DigitalSetByAssociativeContainer
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Definition: DigitalSetByAssociativeContainer.h:89
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64