DGtal  1.0.0
Functions
shortcuts.cpp File Reference
#include <iostream>
#include "ConfigExamples.h"
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/helpers/Shortcuts.h"
Include dependency graph for shortcuts.cpp:

Go to the source code of this file.

Functions

int main (int, char **)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2018/06/26

An example file named shortcuts.

This file is part of the DGtal library.

Definition in file shortcuts.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

[dgtal_shortcuts_ssec2_1_1s]

[dgtal_shortcuts_ssec2_1_1s]

[dgtal_shortcuts_ssec2_1_2s]

[dgtal_shortcuts_ssec2_1_2s]

[dgtal_shortcuts_ssec2_1_3s]

[dgtal_shortcuts_ssec2_1_3s]

[dgtal_shortcuts_ssec2_1_4s]

[dgtal_shortcuts_ssec2_1_4s]

[dgtal_shortcuts_ssec2_1_5s]

[dgtal_shortcuts_ssec2_1_5s]

[dgtal_shortcuts_ssec2_2_1s]

[dgtal_shortcuts_ssec2_2_1s]

[dgtal_shortcuts_ssec2_2_2s]

[dgtal_shortcuts_ssec2_2_2s]

[dgtal_shortcuts_ssec2_2_3s]

[dgtal_shortcuts_ssec2_2_3s]

[dgtal_shortcuts_ssec2_2_4s]

[dgtal_shortcuts_ssec2_2_4s]

Definition at line 43 of file shortcuts.cpp.

44 {
45  unsigned int nb = 0, nbok = 0;
46  // Using standard 3D digital space.
47  typedef Shortcuts<Z3i::KSpace> SH3;
48 
49  // 3d tests
50  trace.beginBlock ( "Load vol file -> noisify -> save as vol file." );
51  {
52  auto params = SH3::defaultParameters();
54  // load and noisify image directly.
55  auto al_capone = SH3::makeBinaryImage( examplesPath + "samples/Al.100.vol",
56  params( "noise", 0.3 ) );
57  auto ok = SH3::saveBinaryImage( al_capone, "noisy-Al.vol" );
59  ++nb; nbok += ok ? 1 : 0;
60  }
61  trace.endBlock();
62  trace.beginBlock ( "Load vol file -> build main connected digital surface." );
63  {
64  auto params = SH3::defaultParameters();
66  auto al_capone = SH3::makeBinaryImage( examplesPath + "samples/Al.100.vol", params );
67  auto K = SH3::getKSpace( al_capone );
68  auto surface = SH3::makeLightDigitalSurface( al_capone, K, params );
69  trace.info() << "#surfels=" << surface->size() << std::endl;
71  ++nb; nbok += surface->size() == 21239 ? 1 : 0;
72  }
73  trace.endBlock();
74 
75  trace.beginBlock ( "Load vol file -> extract 2 isosurfaces -> build mesh" );
76  {
77  auto params = SH3::defaultParameters();
79  params( "faceSubdivision", "Centroid" )( "surfelAdjacency", 1);
80  auto gimage = SH3::makeGrayScaleImage( examplesPath + "samples/lobster.vol" );
81  auto trisurf150= SH3::makeTriangulatedSurface( gimage, params( "thresholdMin", 150 ) );
82  auto trisurf40 = SH3::makeTriangulatedSurface( gimage, params( "thresholdMin", 40 ) );
83  auto mesh150 = SH3::makeMesh( trisurf150 );
84  auto mesh40 = SH3::makeMesh( trisurf40 );
85  trace.info() << "#mesh150=" << mesh150->nbVertex()
86  << " #mesh40=" << mesh40->nbVertex() << std::endl;
88  ++nb; nbok += ( mesh150->nbVertex() < mesh40->nbVertex() )
89  && ( mesh40->nbVertex() == 273182 ) ? 1 : 0;
90  }
91  trace.endBlock();
92 
93  trace.beginBlock ( "Load vol file -> extract 2 triangulated isosurfaces -> save as OBJ." );
94  {
95  auto params = SH3::defaultParameters();
97  params( "faceSubdivision", "Centroid" )( "surfelAdjacency", 1);
98  auto gimage = SH3::makeGrayScaleImage( examplesPath + "samples/lobster.vol" );
99  auto trisurf150= SH3::makeTriangulatedSurface( gimage, params( "thresholdMin", 150 ) );
100  auto trisurf40 = SH3::makeTriangulatedSurface( gimage, params( "thresholdMin", 40 ) );
101  auto ok40 = SH3::saveOBJ( trisurf40, SH3::RealVectors(), SH3::Colors(),
102  "lobster-40.obj", // semi-transparent red diffuse color
103  SH3::Color( 30,30,30 ), SH3::Color( 255,0,0,100 ) );
104  auto ok150 = SH3::saveOBJ( trisurf150, SH3::RealVectors(), SH3::Colors(),
105  "lobster-150.obj", // opaque blue diffuse color
106  SH3::Color( 30,30,30 ), SH3::Color( 0,0,255,255 ) );
108  ++nb; nbok += ok40 ? 1 : 0;
109  ++nb; nbok += ok150 ? 1 : 0;
110  }
111  trace.endBlock();
112 
113  trace.beginBlock ( "Load vol file -> build main digital surface -> breadth first traversal -> save OBJ with colored distance." );
114  {
115  auto params = SH3::defaultParameters();
117  params( "surfaceTraversal", "BreadthFirst" ) // specifies breadth-first traversal
118  ( "colormap", "Jet" ); // specifies the colormap
119  auto al_capone = SH3::makeBinaryImage( examplesPath + "samples/Al.100.vol", params );
120  auto K = SH3::getKSpace( al_capone );
121  auto surface = SH3::makeLightDigitalSurface( al_capone, K, params );
122  auto surfels = SH3::getSurfelRange( surface, params );
123  auto cmap = SH3::getColorMap( 0, surfels.size(), params );
124  SH3::Colors colors( surfels.size() );
125  for ( unsigned int i = 0; i < surfels.size(); ++i ) colors[ i ] = cmap( i );
126  bool ok = SH3::saveOBJ( surface, SH3::RealVectors(), colors, "al-primal-bft.obj" );
128  ++nb; nbok += ok ? 1 : 0;
129  }
130  trace.endBlock();
131 
132  trace.beginBlock ( "Build polynomial shape -> digitize -> noisify -> save as vol file." );
133  {
134  auto params = SH3::defaultParameters();
136  params( "polynomial", "3*x^2+2*y^2+z^2-90" )( "gridstep", 0.25 )
137  ( "noise", 0.3 );
138  auto implicit_shape = SH3::makeImplicitShape3D( params );
139  auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
140  auto noisy_shape = SH3::makeBinaryImage ( digitized_shape, params );
141  auto ok = SH3::saveBinaryImage ( noisy_shape, "noisy-ellipsoid.vol" );
143  ++nb; nbok += ok ? 1 : 0;
144  }
145  trace.endBlock();
146 
147  trace.beginBlock ( "Build polynomial shape -> digitize -> build digital surface -> save primal surface as obj." );
148  {
149  auto params = SH3::defaultParameters();
151  params( "polynomial", "goursat" )( "gridstep", 0.25 );
152  auto implicit_shape = SH3::makeImplicitShape3D ( params );
153  auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
154  auto K = SH3::getKSpace( params );
155  auto binary_image = SH3::makeBinaryImage( digitized_shape, params );
156  auto surface = SH3::makeDigitalSurface( binary_image, K, params );
157  bool ok = SH3::saveOBJ( surface, "goursat-primal.obj" );
159  ++nb; nbok += ok ? 1 : 0;
160  }
161  trace.endBlock();
162 
163  trace.beginBlock ( "Build polynomial shape -> digitize -> build indexed surface on a subpart." );
164  {
165  auto params = SH3::defaultParameters();
167  params( "polynomial", "leopold" )( "gridstep", 0.25 )
168  ( "minAABB", -12.0 )( "maxAABB", 12.0 )
169  ( "surfaceComponents", "All" );
170  auto implicit_shape = SH3::makeImplicitShape3D ( params );
171  auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
172  auto Kwhole = SH3::getKSpace( params );
173  auto K = SH3::getKSpace( SH3::Point::zero, Kwhole.upperBound(), params );
174  auto binary_image = SH3::makeBinaryImage( digitized_shape,
176  params );
177  auto surface = SH3::makeIdxDigitalSurface( binary_image, K, params );
178  trace.info() << "#surfels=" << surface->size() << std::endl;
180  ++nb; nbok += surface->size() > 1000 ? 1 : 0;
181  }
182  trace.endBlock();
183 
184  trace.beginBlock ( "Build polynomial shape -> digitize -> noisify -> count components -> save OBJ with different colors." );
185  {
186  auto params = SH3::defaultParameters();
188  params( "polynomial", "leopold" )( "gridstep", 0.25 )
189  ( "minAABB", -12.0 )( "maxAABB", 12.0 )
190  ( "surfaceComponents", "All" )( "noise", 0.5 );
191  auto implicit_shape = SH3::makeImplicitShape3D ( params );
192  auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
193  auto K = SH3::getKSpace( params );
194  auto binary_image = SH3::makeBinaryImage(digitized_shape,
196  params );
197  // Extracts the whole surface (with all components)
198  auto surface = SH3::makeDigitalSurface( binary_image, K, params );
199  // Extracts a vector of connected surfaces.
200  auto vec_surfs = SH3::makeLightDigitalSurfaces( binary_image, K, params );
201  trace.info() << "#connected components = " << vec_surfs.size() << std::endl;
202  std::map< SH3::Surfel, unsigned int> label;
203  unsigned int n = 0;
204  for ( auto&& surf : vec_surfs ) {
205  auto surfels = SH3::getSurfelRange( surf, params );
206  for ( auto&& s : surfels ) label[ s ] = n;
207  n += 1;
208  }
209  auto cmap = SH3::getColorMap( 0, vec_surfs.size(), params );
210  auto all_surfels = SH3::getSurfelRange( surface, params );
211  SH3::Colors colors( all_surfels.size() );
212  for ( unsigned int i = 0; i < all_surfels.size(); ++i )
213  colors[ i ] = cmap( label[ all_surfels[ i ] ] );
214  bool ok = SH3::saveOBJ( surface, SH3::RealVectors(), colors, "leopold-primal-cc.obj" );
216  ++nb; nbok += ok ? 1 : 0;
217  }
218  trace.endBlock();
219 
220  trace.info() << nbok << "/" << nb << " passed tests." << std::endl;
221 
222  return 0;
223 }
void beginBlock(const std::string &keyword="")
HyperRectDomain< Space > Domain
Trace trace
Definition: Common.h:144
const Point & upperBound() const
Return the upper bound for digital points in this space.
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:101
double endBlock()
const Point & lowerBound() const
Return the lower bound for digital points in this space.
std::ostream & info()
KSpace K

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), K, DGtal::KhalimskySpaceND< dim, TInteger >::lowerBound(), DGtal::trace, and DGtal::KhalimskySpaceND< dim, TInteger >::upperBound().