Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
3dKSSurfaceExtraction.cpp
Go to the documentation of this file.
1
16
29
39
40
42#include <iostream>
43#include "DGtal/base/Common.h"
44
45#include "DGtal/base/Common.h"
46#include "DGtal/io/readers/VolReader.h"
47#include "DGtal/io/viewers/PolyscopeViewer.h"
48#include "DGtal/io/Color.h"
49
50#include "DGtal/images/ImageSelector.h"
51#include "DGtal/helpers/StdDefs.h"
52#include "ConfigExamples.h"
53#include "DGtal/io/Color.h"
54#include "DGtal/io/colormaps/GradientColorMap.h"
55#include "DGtal/topology/KhalimskySpaceND.h"
56#include "DGtal/topology/helpers/Surfaces.h"
57
58
60
61using namespace std;
62using namespace DGtal;
63using namespace Z3i;
64
66
67int main( int argc, char** argv )
68{
69
70 Point p1( 0, 0, 0 );
71 Point p2( 20, 20, 20 );
72 Point c( 10, 10, 10 );
73 Domain domain( p1, p2);
74
75 // Generate the digital set from randam seeds and distance threshold.
76 DigitalSet diamond_set( domain );
77 //srand ( time(NULL) );
78 unsigned int nbSeeds = 35;
79 vector<Point> vCenters;
80 vector<uint> vRad;
81 for(unsigned int i=0;i<nbSeeds; i++){
82 vCenters.push_back(Point(rand()%p2[0], rand()%p2[1],
83 rand()%p2[2]));
84 vRad.push_back(rand()%7);
85 }
86 for ( Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it ){
87 for(unsigned int i=0;i<nbSeeds; i++){
88 if ( (*it - vCenters.at(i) ).norm1() <= vRad.at(i) && domain.isInside(*it) &&
89 domain.isInside(*it+Point(1,1,1)) && domain.isInside(*it-Point(1,1,1)) ){
90 diamond_set.insertNew( *it );
91 break;
92 }
93 }
94 }
95
96
97 //A KhalimskySpace is constructed from the domain boundary points.
98 KSpace K;
99 K.init(p1, p2, true);
100
101 SurfelAdjacency<3> SAdj( true );
102 vector<vector<SCell> > vectConnectedSCell;
103
104
105 //Here since the last argument is set to true, the resulting
106 //SignedKhalimskySpaceND are signed in order to indicate the direction
107 //of exterior. You can also get the SignefKhalimskySpaceND with default
108 //sign:
109
110 Surfaces<KSpace>::extractAllConnectedSCell(vectConnectedSCell,K, SAdj, diamond_set, false);
111
112
113 PolyscopeViewer<> viewer (K);
114
115
116 // Each connected compoments are simply displayed with a specific color.
117 GradientColorMap<long> gradient(0, (const long)vectConnectedSCell.size());
118 gradient.addColor(Color::Red);
119 gradient.addColor(Color::Yellow);
120 gradient.addColor(Color::Green);
121 gradient.addColor(Color::Cyan);
122 gradient.addColor(Color::Blue);
123 gradient.addColor(Color::Magenta);
124 gradient.addColor(Color::Red);
125
126
127 for(unsigned int i=0; i< vectConnectedSCell.size();i++){
128 DGtal::Color col= gradient(i);
129 viewer << col;
130 for(unsigned int j=0; j< vectConnectedSCell.at(i).size();j++){
131 viewer << vectConnectedSCell.at(i).at(j);
132 }
133 }
134
135
136 viewer << Color(250, 200,200, 200);
137 viewer << diamond_set;
138 //viewer << ClippingPlane(0,1,0.0,-2);
139 viewer.show();
140 return 0;
141}
142// //
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.
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
Space::Point Point
Definition StdDefs.h:168
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition StdDefs.h:173
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
int main()
Definition testBits.cpp:56
KSpace K
Domain domain