32 #include "ConfigExamples.h"
33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/helpers/Shortcuts.h"
39 using namespace DGtal;
45 unsigned int nb = 0, nbok = 0;
52 auto params = SH3::defaultParameters();
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;
62 trace.
beginBlock (
"Load vol file -> build main connected digital surface." );
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 );
71 ++nb; nbok +=
surface->size() == 21239 ? 1 : 0;
75 trace.
beginBlock (
"Load vol file -> extract 2 isosurfaces -> build mesh" );
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;
93 trace.
beginBlock (
"Load vol file -> extract 2 triangulated isosurfaces -> save as OBJ." );
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 ) );
108 ++nb; nbok += ok40 ? 1 : 0;
109 ++nb; nbok += ok150 ? 1 : 0;
113 trace.
beginBlock (
"Load vol file -> build main digital surface -> breadth first traversal -> save OBJ with colored distance." );
115 auto params = SH3::defaultParameters();
117 params(
"surfaceTraversal",
"BreadthFirst" )
118 (
"colormap",
"Jet" );
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 );
125 for (
unsigned int i = 0; i < surfels.size(); ++i ) colors[ i ] = cmap( i );
128 ++nb; nbok += ok ? 1 : 0;
132 trace.
beginBlock (
"Build polynomial shape -> digitize -> noisify -> save as vol file." );
134 auto params = SH3::defaultParameters();
136 params(
"polynomial",
"3*x^2+2*y^2+z^2-90" )(
"gridstep", 0.25 )
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;
147 trace.
beginBlock (
"Build polynomial shape -> digitize -> build digital surface -> save primal surface as obj." );
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 );
157 bool ok = SH3::saveOBJ(
surface,
"goursat-primal.obj" );
159 ++nb; nbok += ok ? 1 : 0;
163 trace.
beginBlock (
"Build polynomial shape -> digitize -> build indexed surface on a subpart." );
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 );
174 auto binary_image = SH3::makeBinaryImage( digitized_shape,
180 ++nb; nbok +=
surface->size() > 1000 ? 1 : 0;
184 trace.
beginBlock (
"Build polynomial shape -> digitize -> noisify -> count components -> save OBJ with different colors." );
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,
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;
204 for (
auto&& surf : vec_surfs ) {
205 auto surfels = SH3::getSurfelRange( surf, params );
206 for (
auto&& s : surfels ) label[ s ] = n;
209 auto cmap = SH3::getColorMap( 0, vec_surfs.size(), params );
210 auto all_surfels = SH3::getSurfelRange(
surface, params );
212 for (
unsigned int i = 0; i < all_surfels.size(); ++i )
213 colors[ i ] = cmap( label[ all_surfels[ i ] ] );
216 ++nb; nbok += ok ? 1 : 0;
220 trace.
info() << nbok <<
"/" << nb <<
" passed tests." << std::endl;
Structure representing an RGB triple with alpha component.
const Point & lowerBound() const
Return the lower bound for digital points in this space.
const Point & upperBound() const
Return the upper bound for digital points in this space.
static Self zero
Static const for zero PointVector.
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
std::vector< Color > Colors
std::vector< RealVector > RealVectors
void beginBlock(const std::string &keyword="")
CountedPtr< SH3::DigitalSurface > surface
CountedPtr< SH3::BinaryImage > binary_image
DGtal is the top-level namespace which contains all DGtal functions and types.