File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
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/viewers/PolyscopeViewer.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);
PolyscopeViewer<> viewer (K);
// 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::Cyan);
gradient.addColor(Color::Blue);
gradient.addColor(Color::Red);
for(unsigned int i=0; i< vectConnectedSCell.size();i++){
DGtal::Color col= gradient(i);
viewer << col;
for(unsigned int j=0; j< vectConnectedSCell.at(i).size();j++){
viewer << vectConnectedSCell.at(i).at(j);
}
}
viewer << Color(250, 200,200, 200);
viewer << diamond_set;
//viewer << ClippingPlane(0,1,0.0,-2);
viewer.show();
return 0;
}
// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
static const Color Red
Definition Color.h:425
static const Color Blue
Definition Color.h:428
static const Color Yellow
Definition Color.h:431
static const Color Cyan
Definition Color.h:429
static const Color Green
Definition Color.h:426
static const Color Magenta
Definition Color.h:430
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
void show() override
Starts the event loop and display of elements.
static void extractAllConnectedSCell(std::vector< std::vector< SCell > > &aVectConnectedSCell, const KSpace &aKSpace, const SurfelAdjacency< KSpace::dimension > &aSurfelAdj, const PointPredicate &pp, bool forceOrientCellExterior=false)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
int main()
Definition testBits.cpp:56
MyPointD Point
KSpace K
Domain domain
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet