DGtal  1.5.beta
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/Viewer3D.h"
39 #include "DGtal/io/readers/VolReader.h"
40 #include "DGtal/io/DrawWithDisplay3DModifier.h"
41 #include "DGtal/images/ImageSelector.h"
42 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
43 #include "DGtal/io/Color.h"
44 #include "DGtal/io/colormaps/GradientColorMap.h"
45 
46 #include "ConfigExamples.h"
47 
49 using namespace std;
50 using namespace DGtal;
52 
53 int main( int argc, char** argv )
54 {
55  trace.beginBlock ( "Example ctopo-2-3d" );
56  // for 3D display with Viewer3D
57  QApplication application(argc,argv);
58 
60  std::string inputFilename = examplesPath + "samples/cat10.vol";
61  Image image = VolReader<Image>::importVol(inputFilename);
62  Z3i::DigitalSet set3d (image.domain());
64 
65  // Construct the Khalimsky space from the image domain
66  Z3i::KSpace ks;
67  bool space_ok = ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
68 
69  if (!space_ok)
70  {
71  trace.error() << "Error in the Khamisky space construction."<<std::endl;
72  return 2;
73  }
74 
75  std::vector<Z3i::SCell> vectBdrySCell;
76  std::vector<Z3i::SCell> vectBdrySCell2;
77  std::set<Z3i::SCell> vectBdrySCellALL;
78  SurfelAdjacency<3> SAdj( true );
79 
80 
81 
82  //Extract an initial boundary cell
84  trace.info() << "Tracking Boundary.."<<std::endl;
85  // Extracting all boundary surfels which are connected to the initial boundary Cell.
86  Surfaces<Z3i::KSpace>::trackBoundary( vectBdrySCellALL,
87  ks,SAdj, set3d, aCell );
88 
89  // Extract the bondary contour associated to the initial surfel in its first direction
91  ks, *(ks.sDirs( aCell )), SAdj,
92  set3d, aCell );
93 
94  // Extract the bondary contour associated to the initial surfel in its second direction
96  ks, *(++(ks.sDirs( aCell ))), SAdj,
97  set3d, aCell );
98 
99 
100  // Displaying all the surfels in transparent mode
102  MyViewer viewer(ks);
103  viewer.show();
104 
105  trace.info() << "Displaying the surfels.."<<std::endl;
106  viewer << SetMode3D((*(vectBdrySCellALL.begin())).className(), "Transparent");
107  for( std::set<Z3i::SCell>::iterator it=vectBdrySCellALL.begin();
108  it!= vectBdrySCellALL.end(); it++){
109  viewer<< *it;
110  }
111  trace.info()<<"done"<<std::endl;
112  // Displaying First surfels cut with gradient colors.;
113  GradientColorMap<int> cmap_grad(0, (const int)vectBdrySCell2.size());
114  cmap_grad.addColor( Color( 50, 50, 255 ) );
115  cmap_grad.addColor( Color( 255, 0, 0 ) );
116  cmap_grad.addColor( Color( 255, 255, 10 ) );
117 
118  // Need to avoid surfel superposition (the surfel size in increased)
119  viewer << Viewer3D<Z3i::Space,Z3i::KSpace>::shiftSurfelVisu;
120  viewer << SetMode3D((*(vectBdrySCell2.begin())).className(), "");
121  viewer.setFillColor(Color(180, 200, 25, 255));
122 
123  int d=0;
124  for( std::vector<Z3i::SCell>::iterator it=vectBdrySCell2.begin();
125  it!= vectBdrySCell2.end(); it++){
126  Color col= cmap_grad(d);
127  viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
128  viewer<< *it;
129  d++;
130  }
131 
132  GradientColorMap<int> cmap_grad2(0, (const int)vectBdrySCell.size());
133  cmap_grad2.addColor( Color( 50, 50, 255 ) );
134  cmap_grad2.addColor( Color( 255, 0, 0 ) );
135  cmap_grad2.addColor( Color( 255, 255, 10 ) );
136  viewer << Viewer3D<>::shiftSurfelVisu;
137 
138  d=0;
139  for( std::vector<Z3i::SCell>::iterator it=vectBdrySCell.begin();
140  it!= vectBdrySCell.end(); it++){
141  Color col= cmap_grad2(d);
142  viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
143  viewer<< *it;
144  d++;
145  }
146 
147  // On need once again to avoid superposition.
148  viewer << MyViewer::shiftSurfelVisu;
149  viewer.setFillColor(Color(18, 200, 25, 255));
150  viewer << aCell ;
151  viewer << MyViewer::updateDisplay;
152 
153  return application.exec();
154 }
155 // //
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
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...
virtual void setFillColor(DGtal::Color aColor)
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
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.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & info()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
int main(int argc, char **argv)
Definition: ctopo-2-3d.cpp:53
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
ImageContainerBySTLVector< Domain, Value > Image