DGtal 2.1.0
Loading...
Searching...
No Matches
ctopo-2-3d.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/topology/KhalimskySpaceND.h"
36#include "DGtal/topology/helpers/Surfaces.h"
37
38#include "DGtal/io/viewers/PolyscopeViewer.h"
39#include "DGtal/io/readers/VolReader.h"
40#include "DGtal/images/ImageSelector.h"
41#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
42#include "DGtal/io/Color.h"
43#include "DGtal/io/colormaps/GradientColorMap.h"
44
45#include "ConfigExamples.h"
46
48using namespace std;
49using namespace DGtal;
51
52int main()
53{
54 trace.beginBlock ( "Example ctopo-2-3d" );
55 // for 3D display with PolyscopeViewer
56
58 std::string inputFilename = examplesPath + "samples/cat10.vol";
62
63 // Construct the Khalimsky space from the image domain
64 Z3i::KSpace ks;
65 bool space_ok = ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
66
67 if (!space_ok)
68 {
69 trace.error() << "Error in the Khamisky space construction."<<std::endl;
70 return 2;
71 }
72
73 std::vector<Z3i::SCell> vectBdrySCell;
74 std::vector<Z3i::SCell> vectBdrySCell2;
75 std::set<Z3i::SCell> vectBdrySCellALL;
76 SurfelAdjacency<3> SAdj( true );
77
78
79 //Extract an initial boundary cell
81 trace.info() << "Tracking Boundary.."<<std::endl;
82 // Extracting all boundary surfels which are connected to the initial boundary Cell.
84 ks,SAdj, set3d, aCell );
85
86 // Extract the bondary contour associated to the initial surfel in its first direction
88 ks, *(ks.sDirs( aCell )), SAdj,
89 set3d, aCell );
90
91 // Extract the bondary contour associated to the initial surfel in its second direction
93 ks, *(++(ks.sDirs( aCell ))), SAdj,
94 set3d, aCell );
95
96
97 // Displaying all the surfels in transparent mode
98 typedef PolyscopeViewer <Z3i::Space,Z3i::KSpace> MyViewer;
99 MyViewer viewer(ks);
100
101 trace.info() << "Displaying the surfels.."<<std::endl;
102 for( std::set<Z3i::SCell>::iterator it=vectBdrySCellALL.begin();
103 it!= vectBdrySCellALL.end(); it++){
104 viewer<< *it;
105 }
106 trace.info()<<"done"<<std::endl;
107 // Displaying First surfels cut with gradient colors.;
108 GradientColorMap<int> cmap_grad(0, vectBdrySCell2.size());
109 cmap_grad.addColor( Color( 50, 50, 255 ) );
110 cmap_grad.addColor( Color( 255, 0, 0 ) );
111 cmap_grad.addColor( Color( 255, 255, 10 ) );
112
113 // Need to avoid surfel superposition (the surfel size in increased)
114 viewer.drawColor(Color(180, 200, 25, 255));
115
116 int d=0;
117 for( std::vector<Z3i::SCell>::iterator it=vectBdrySCell2.begin();
118 it!= vectBdrySCell2.end(); it++){
119 Color col= cmap_grad(d);
120 viewer.drawColor(Color(col.red(),col.green() ,col.blue(), 255));
121 viewer<< *it;
122 d++;
123 }
124
125 GradientColorMap<int> cmap_grad2(0, vectBdrySCell.size());
126 cmap_grad2.addColor( Color( 50, 50, 255 ) );
127 cmap_grad2.addColor( Color( 255, 0, 0 ) );
128 cmap_grad2.addColor( Color( 255, 255, 10 ) );
129
130 d=0;
131 for( std::vector<Z3i::SCell>::iterator it=vectBdrySCell.begin();
132 it!= vectBdrySCell.end(); it++){
133 Color col= cmap_grad2(d);
134 viewer.drawColor(Color(col.red(),col.green() ,col.blue(), 255));
135 viewer<< *it;
136 d++;
137 }
138
139 // On need once again to avoid superposition.
140 viewer.drawColor(Color(18, 200, 25, 255));
141 viewer << aCell ;
142
143 viewer.show();
144 return 0;
145}
146// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
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)
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
const Domain & domain() const
Definition Image.h:192
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.
DirIterator sDirs(const SCell &p) const
Given a signed cell [p], returns an iterator to iterate over each coordinate the cell spans.
static void trackBoundary(SCellSet &surface, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
static void track2DSliceBoundary(std::vector< SCell > &aSCellContour2D, const KSpace &K, const Dimension &trackDir, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
std::ostream & error()
std::ostream & info()
int main()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
ImageContainerBySTLVector< Domain, Value > Type
Aim: Define utilities to convert a digital set into an image.
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Image image(domain)
PolyscopeViewer< Space, KSpace > MyViewer