DGtal 1.3.0
Loading...
Searching...
No Matches
3dKSSurfaceExtraction.cpp
Go to the documentation of this file.
1
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/DrawWithDisplay3DModifier.h"
48#include "DGtal/io/viewers/Viewer3D.h"
49#include "DGtal/io/Color.h"
50
51#include "DGtal/images/ImageSelector.h"
52#include "DGtal/helpers/StdDefs.h"
53#include "ConfigExamples.h"
54#include "DGtal/io/Color.h"
55#include "DGtal/io/colormaps/GradientColorMap.h"
56#include "DGtal/topology/KhalimskySpaceND.h"
57#include "DGtal/topology/helpers/Surfaces.h"
58
59
61
62using namespace std;
63using namespace DGtal;
64using namespace Z3i;
65
67
68int main( int argc, char** argv )
69{
70
71 Point p1( 0, 0, 0 );
72 Point p2( 20, 20, 20 );
73 Point c( 10, 10, 10 );
74 Domain domain( p1, p2);
75
76 // Generate the digital set from randam seeds and distance threshold.
77 DigitalSet diamond_set( domain );
78 //srand ( time(NULL) );
79 unsigned int nbSeeds = 35;
80 vector<Point> vCenters;
81 vector<uint> vRad;
82 for(unsigned int i=0;i<nbSeeds; i++){
83 vCenters.push_back(Point(rand()%p2[0], rand()%p2[1],
84 rand()%p2[2]));
85 vRad.push_back(rand()%7);
86 }
87 for ( Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it ){
88 for(unsigned int i=0;i<nbSeeds; i++){
89 if ( (*it - vCenters.at(i) ).norm1() <= vRad.at(i) && domain.isInside(*it) &&
90 domain.isInside(*it+Point(1,1,1)) && domain.isInside(*it-Point(1,1,1)) ){
91 diamond_set.insertNew( *it );
92 break;
93 }
94 }
95 }
96
97
98 //A KhalimskySpace is constructed from the domain boundary points.
99 KSpace K;
100 K.init(p1, p2, true);
101
102 SurfelAdjacency<3> SAdj( true );
103 vector<vector<SCell> > vectConnectedSCell;
104
105
106 //Here since the last argument is set to true, the resulting
107 //SignedKhalimskySpaceND are signed in order to indicate the direction
108 //of exterior. You can also get the SignefKhalimskySpaceND with default
109 //sign:
110
111 Surfaces<KSpace>::extractAllConnectedSCell(vectConnectedSCell,K, SAdj, diamond_set, false);
112
113
114 QApplication application(argc,argv);
115 Viewer3D<> viewer (K);
116 viewer.show();
117
118
119 // Each connected compoments are simply displayed with a specific color.
120 GradientColorMap<long> gradient(0, (const long)vectConnectedSCell.size());
121 gradient.addColor(Color::Red);
122 gradient.addColor(Color::Yellow);
123 gradient.addColor(Color::Green);
124 gradient.addColor(Color::Cyan);
125 gradient.addColor(Color::Blue);
126 gradient.addColor(Color::Magenta);
127 gradient.addColor(Color::Red);
128
129
130 for(unsigned int i=0; i< vectConnectedSCell.size();i++){
131 DGtal::Color col= gradient(i);
132 viewer << CustomColors3D(Color(250, 0,0), Color(col.red(),
133 col.green(),
134 col.blue()));
135
136 for(unsigned int j=0; j< vectConnectedSCell.at(i).size();j++){
137 viewer << vectConnectedSCell.at(i).at(j);
138 }
139 }
140
141
142 viewer << CustomColors3D(Color(250, 0,0),Color(250, 200,200, 200));
143 viewer << diamond_set;
144 //viewer << ClippingPlane(0,1,0.0,-2);
145 viewer << Viewer3D<>::updateDisplay;
146 return application.exec();
147}
148// //
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
static const Color Yellow
Definition: Color.h:422
static const Color Cyan
Definition: Color.h:420
void green(const unsigned char aGreenValue)
static const Color Green
Definition: Color.h:417
void red(const unsigned char aRedValue)
static const Color Red
Definition: Color.h:416
static const Color Blue
Definition: Color.h:419
void blue(const unsigned char aBlueValue)
static const Color Magenta
Definition: Color.h:421
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
Iterator for HyperRectDomain.
bool isInside(const Point &p) const
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
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...
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Space::Point Point
Definition: StdDefs.h:168
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