DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ctopo-2-3d.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 
34 #include "DGtal/helpers/StdDefs.h"
35 #include <QtGui/qapplication.h>
36 #include "DGtal/topology/KhalimskySpaceND.h"
37 #include "DGtal/topology/helpers/Surfaces.h"
38 
39 #include "DGtal/io/viewers/Viewer3D.h"
40 #include "DGtal/io/readers/VolReader.h"
41 #include "DGtal/io/DrawWithDisplay3DModifier.h"
42 #include "DGtal/images/ImageSelector.h"
43 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
44 #include "DGtal/io/Color.h"
45 #include "DGtal/io/colormaps/GradientColorMap.h"
46 
47 #include "ConfigExamples.h"
48 
50 using namespace std;
51 using namespace DGtal;
53 
54 int main( int argc, char** argv )
55 {
56  trace.beginBlock ( "Example ctopo-2-3d" );
57  // for 3D display with Viewer3D
58  QApplication application(argc,argv);
59 
61  std::string inputFilename = examplesPath + "samples/cat10.vol";
62  Image image = VolReader<Image>::importVol(inputFilename);
63  Z3i::DigitalSet set3d (image.domain());
64  SetPredicate<Z3i::DigitalSet> set3dPredicate( set3d );
65  SetFromImage<Z3i::DigitalSet>::append<Image>(set3d, image, 0,255);
66  Viewer3D viewer;
67  viewer.show();
68 
69 
70  // Construct the Khalimsky space from the image domain
71  Z3i::KSpace ks;
72  bool space_ok = ks.init( image.domain().lowerBound(), image.domain().upperBound(), true );
73 
74  if (!space_ok)
75  {
76  trace.error() << "Error in the Khamisky space construction."<<std::endl;
77  return 2;
78  }
79 
80  std::vector<Z3i::SCell> vectBdrySCell;
81  std::vector<Z3i::SCell> vectBdrySCell2;
82  std::set<Z3i::SCell> vectBdrySCellALL;
83  SurfelAdjacency<3> SAdj( true );
84 
85 
86 
87  //Extract an initial boundary cell
88  Z3i::SCell aCell = Surfaces<Z3i::KSpace>::findABel(ks, set3dPredicate);
89 
90  // Extracting all boundary surfels which are connected to the initial boundary Cell.
91  Surfaces<Z3i::KSpace>::trackBoundary( vectBdrySCellALL,
92  ks,SAdj, set3dPredicate, aCell );
93 
94  // Extract the bondary contour associated to the initial surfel in its first direction
96  ks, *(ks.sDirs( aCell )), SAdj,
97  set3dPredicate, aCell );
98 
99  // Extract the bondary contour associated to the initial surfel in its second direction
101  ks, *(++(ks.sDirs( aCell ))), SAdj,
102  set3dPredicate, aCell );
103 
104 
105  // Displaying all the surfels in transparent mode
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 
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::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 
137  d=0;
138  for( std::vector<Z3i::SCell>::iterator it=vectBdrySCell.begin();
139  it!= vectBdrySCell.end(); it++){
140  Color col= cmap_grad2(d);
141  viewer.setFillColor(Color(col.red(),col.green() ,col.blue(), 255));
142  viewer<< *it;
143  d++;
144  }
145 
146  // On need once again to avoid superposition.
147  viewer << Viewer3D::shiftSurfelVisu;
148  viewer.setFillColor(Color(18, 200, 25, 255));
149  viewer << aCell ;
150  viewer << Viewer3D::updateDisplay;
151 
152  return application.exec();
153 }
154 // //