This example shows a greedy segmentation into naive planes of the surface at threshold 0 within volume Al.100.vol.
Colors for each plane are chosen randomly. Surfels in the same plane have the same color.
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/Display3D.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/DigitalSetBoundary.h"
#include "DGtal/graph/BreadthFirstVisitor.h"
#include "DGtal/geometry/surfaces/COBANaivePlaneComputer.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
using namespace Z3i;
typedef MyDigitalSurface::Vertex
Vertex;
typedef MyDigitalSurface::SurfelSet
SurfelSet;
struct SegmentedPlane {
};
int main(
int argc,
char** argv )
{
trace.
info() <<
"Segments the surface at given threshold within given volume into digital planes of rational width num/den." << std::endl;
string inputFilename = examplesPath + "samples/Al.100.vol" ;
trace.
info() <<
"input file used " << inputFilename << std::endl;
unsigned int threshold = 0;
trace.
info() <<
"the value that defines the isosurface in the image (an integer between 0 and 255)= " << threshold<< std::endl;
unsigned int widthNum = 1;
trace.
info() <<
"the numerator of the rational width (a non-null integer) =" << widthNum<< std::endl;
unsigned int widthDen = 1;
trace.
info() <<
"the denominator of the rational width (a non-null integer)= " << widthDen<< std::endl;
QApplication application(argc,argv);
typedef ImageSelector < Domain, int>::Type
Image;
bool ok = ks.init( set3d.domain().lowerBound(),
set3d.domain().upperBound(), true );
if ( ! ok ) std::cerr << "[KSpace.init] Failed." << std::endl;
std::set<Vertex> processedVertices;
std::vector<SegmentedPlane*> segmentedPlanes;
std::map<Vertex,SegmentedPlane*> v2plane;
unsigned int j = 0;
unsigned int nb = digSurf.size();
for (
ConstIterator it = digSurf.begin(), itE= digSurf.end(); it != itE; ++it )
{
if ( ( (++j) % 50 == 0 ) || ( j == nb ) ) trace.
progressBar( j, nb );
if ( processedVertices.find( v ) != processedVertices.end() )
continue;
SegmentedPlane* ptrSegment = new SegmentedPlane;
segmentedPlanes.push_back( ptrSegment );
axis = ks.sOrthDir( v );
ptrSegment->plane.init( axis, 500, widthNum, widthDen );
while ( ! visitor.finished() )
{
Visitor::Node node = visitor.current();
v = node.first;
if ( processedVertices.find( v ) == processedVertices.end() )
{
axis = ks.sOrthDir( v );
p = ks.sCoords( ks.sDirectIncident( v, axis ) );
bool isExtended = ptrSegment->plane.extend( p );
if ( isExtended )
{
processedVertices.insert( v );
v2plane[ v ] = ptrSegment;
visitor.expand();
}
else
visitor.ignore();
}
else
visitor.ignore();
}
ptrSegment->color =
Color( rand() % 256, rand() % 256, rand() % 256, 255 );
}
viewer.show();
for ( std::map<Vertex,SegmentedPlane*>::const_iterator
it = v2plane.begin(), itE = v2plane.end();
it != itE; ++it )
{
viewer << ks.unsigns( it->first );
}
viewer << Viewer3D<>::updateDisplay;
for ( std::vector<SegmentedPlane*>::iterator
it = segmentedPlanes.begin(), itE = segmentedPlanes.end();
it != itE; ++it )
delete *it;
segmentedPlanes.clear();
v2plane.clear();
return application.exec();
}
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
Aim: A class that contains the COBA algorithm (Emilie Charrier, Lilian Buzer, DGCI2008) for recognizi...
Structure representing an RGB triple with alpha component.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of a given...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
void progressBar(const double currentValue, const double maximalValue)
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
SurfelSet::iterator SurfelSetIterator
COBANaivePlaneComputer< Z3, InternalInteger > NaivePlaneComputer
MyDigitalSurface::ConstIterator ConstIterator
MyDigitalSurface::SurfelSet SurfelSet
BreadthFirstVisitor< MyDigitalSurface > Visitor
DigitalSetBoundary< KSpace, DigitalSet > MyDigitalSurfaceContainer
DGtal::int64_t InternalInteger
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
DGtal::uint32_t Dimension
Aim: Define utilities to convert a digital set into an image.
Aim: implements methods to read a "Vol" file format.
ImageContainerBySTLVector< Domain, Value > Image
Z2i::DigitalSet DigitalSet