DGtal  1.3.beta
topology/3dKSSurfaceExtraction.cpp

A simple example illustrating the extraction of 3d connected set of KhalimskyCell. This program outputs these images:

See also
Extracting surface of connected components
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/Color.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/topology/helpers/Surfaces.h"
using namespace std;
using namespace DGtal;
using namespace Z3i;
int main( int argc, char** argv )
{
Point p1( 0, 0, 0 );
Point p2( 20, 20, 20 );
Point c( 10, 10, 10 );
Domain domain( p1, p2);
// Generate the digital set from randam seeds and distance threshold.
DigitalSet diamond_set( domain );
//srand ( time(NULL) );
unsigned int nbSeeds = 35;
vector<Point> vCenters;
vector<uint> vRad;
for(unsigned int i=0;i<nbSeeds; i++){
vCenters.push_back(Point(rand()%p2[0], rand()%p2[1],
rand()%p2[2]));
vRad.push_back(rand()%7);
}
for ( Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it ){
for(unsigned int i=0;i<nbSeeds; i++){
if ( (*it - vCenters.at(i) ).norm1() <= vRad.at(i) && domain.isInside(*it) &&
domain.isInside(*it+Point(1,1,1)) && domain.isInside(*it-Point(1,1,1)) ){
diamond_set.insertNew( *it );
break;
}
}
}
//A KhalimskySpace is constructed from the domain boundary points.
K.init(p1, p2, true);
SurfelAdjacency<3> SAdj( true );
vector<vector<SCell> > vectConnectedSCell;
//Here since the last argument is set to true, the resulting
//SignedKhalimskySpaceND are signed in order to indicate the direction
//of exterior. You can also get the SignefKhalimskySpaceND with default
//sign:
Surfaces<KSpace>::extractAllConnectedSCell(vectConnectedSCell,K, SAdj, diamond_set, false);
QApplication application(argc,argv);
Viewer3D<> viewer (K);
viewer.show();
// Each connected compoments are simply displayed with a specific color.
GradientColorMap<long> gradient(0, (const long)vectConnectedSCell.size());
gradient.addColor(Color::Red);
gradient.addColor(Color::Yellow);
gradient.addColor(Color::Green);
gradient.addColor(Color::Cyan);
gradient.addColor(Color::Blue);
gradient.addColor(Color::Magenta);
gradient.addColor(Color::Red);
for(unsigned int i=0; i< vectConnectedSCell.size();i++){
DGtal::Color col= gradient(i);
viewer << CustomColors3D(Color(250, 0,0), Color(col.red(),
col.green(),
col.blue()));
for(unsigned int j=0; j< vectConnectedSCell.at(i).size();j++){
viewer << vectConnectedSCell.at(i).at(j);
}
}
viewer << CustomColors3D(Color(250, 0,0),Color(250, 200,200, 200));
viewer << diamond_set;
//viewer << ClippingPlane(0,1,0.0,-2);
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
DGtal::HyperRectDomain< Space >
DGtal::HyperRectDomain::isInside
bool isInside(const Point &p) const
DGtal::SurfelAdjacency
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Definition: SurfelAdjacency.h:65
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.
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Color::red
void red(const unsigned char aRedValue)
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
DGtal::Viewer3D
Definition: Viewer3D.h:135
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::CustomColors3D
Definition: DrawWithDisplay3DModifier.h:129
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Color::green
void green(const unsigned char aGreenValue)
DGtal::Color::blue
void blue(const unsigned char aBlueValue)
DGtal::HyperRectDomain_Iterator
Iterator for HyperRectDomain.
Definition: HyperRectDomain_Iterator.h:142
DGtal::GradientColorMap::addColor
void addColor(const Color &color)
domain
Domain domain
Definition: testProjection.cpp:88
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::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
Point
MyPointD Point
Definition: testClone2.cpp:383
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::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64