134 using namespace DGtal;
141 std::string poly = argv[ 1 ];
142 const double B = argc > 2 ? atof( argv[ 2 ] ) : 1.0;
143 const double h = argc > 3 ? atof( argv[ 3 ] ) : 1.0;
144 std::string mode = argc > 4 ? argv[ 4 ] :
"Const";
145 bool interpolated = mode ==
"Interp";
147 trace.
info() <<
"Using vertex-*Interpolated* Corrected Normal Current" << std::endl;
149 trace.
info() <<
"Using face-*Constant* Corrected Normal Current" << std::endl;
152 auto params = SH::defaultParameters() | SHG::defaultParameters();
154 params(
"surfaceTraversal",
"DepthFirst" );
155 params(
"t-ring", 3 );
156 params(
"polynomial", poly )(
"gridstep", h );
157 params(
"minAABB", -B )(
"maxAABB", B );
158 params(
"offset", 3.0 );
159 auto shape = SH::makeImplicitShape3D( params );
160 auto K = SH::getKSpace( params );
161 auto dshape = SH::makeDigitizedImplicitShape3D( shape, params );
162 auto bimage = SH::makeBinaryImage( dshape, params );
163 if ( bimage ==
nullptr )
165 trace.
error() <<
"Unable to read polynomial <"
166 << poly.c_str() <<
">" << std::endl;
169 auto sembedder = SH::getSCellEmbedder(
K );
170 auto embedder = SH::getCellEmbedder(
K );
171 auto surface = SH::makeDigitalSurface( bimage,
K, params );
172 auto surfels = SH::getSurfelRange(
surface, params );
173 trace.
info() <<
"- surface has " << surfels.size()<<
" surfels." << std::endl;
177 params(
"r-radius", 3.0 );
178 params(
"alpha", 0.33 );
179 double ii_r = 3.0 * pow( h, 0.33 );
182 std::vector< double > HII = SHG::getIIMeanCurvatures ( bimage, surfels, params );
183 std::vector< double > GII = SHG::getIIGaussianCurvatures( bimage, surfels, params );
189 std::vector< SM::Vertices > faces;
191 auto pointels = SH::getPointelRange( c2i,
surface );
192 auto vertices = SH::RealPoints( pointels.size() );
193 std::transform( pointels.cbegin(), pointels.cend(),
vertices.begin(),
194 [&] (
const SH::Cell& c) { return h * embedder( c ); } );
195 for (
auto&& surfel : surfels )
197 const auto primal_surfel_vtcs = SH::getPointelRange(
K, surfel );
199 for (
auto&& primal_vtx : primal_surfel_vtcs )
200 face.push_back( c2i[ primal_vtx ] );
201 faces.push_back( face );
204 faces.cbegin(), faces.cend() );
210 auto exp_H = SHG::getMeanCurvatures( shape,
K, surfels, params );
211 auto exp_G = SHG::getGaussianCurvatures( shape,
K, surfels, params );
221 auto face_normals = SHG::getIINormalVectors( bimage, surfels, params );
225 smesh.setFaceNormals( face_normals.cbegin(), face_normals.cend() );
228 if ( interpolated ) smesh.computeVertexNormalsFromFaceNormals();
230 auto mu0 = cnc.computeMu0();
231 auto mu1 = cnc.computeMu1();
232 auto mu2 = cnc.computeMu2();
237 double cnc_mr = 1.0 * sqrt( h );
238 trace.
info() <<
"CNC measuring radius = " << cnc_mr << std::endl;
239 std::vector< double >
H( smesh.nbFaces() );
240 std::vector< double > G( smesh.nbFaces() );
241 for (
auto f = 0; f < smesh.nbFaces(); ++f )
243 const auto b = smesh.faceCentroid( f );
244 const auto area = mu0.measure( b, cnc_mr, f );
245 H[ f ] = cnc.meanCurvature ( area, mu1.measure( b, cnc_mr, f ) );
246 G[ f ] = cnc.GaussianCurvature( area, mu2.measure( b, cnc_mr, f ) );
252 auto HII_min_max = std::minmax_element( HII.cbegin(), HII.cend() );
253 auto GII_min_max = std::minmax_element( GII.cbegin(), GII.cend() );
254 auto H_min_max = std::minmax_element(
H.cbegin(),
H.cend() );
255 auto G_min_max = std::minmax_element( G.cbegin(), G.cend() );
256 auto exp_H_min_max = std::minmax_element( exp_H.cbegin(), exp_H.cend() );
257 auto exp_G_min_max = std::minmax_element( exp_G.cbegin(), exp_G.cend() );
258 trace.
info() <<
"Expected mean curvatures:"
259 <<
" min=" << *exp_H_min_max.first <<
" max=" << *exp_H_min_max.second
261 trace.
info() <<
"Computed II mean curvatures:"
262 <<
" min=" << *HII_min_max.first <<
" max=" << *HII_min_max.second
264 trace.
info() <<
"Computed CNC mean curvatures:"
265 <<
" min=" << *H_min_max.first <<
" max=" << *H_min_max.second
267 trace.
info() <<
"Expected Gaussian curvatures:"
268 <<
" min=" << *exp_G_min_max.first <<
" max=" << *exp_G_min_max.second
270 trace.
info() <<
"Computed II Gaussian curvatures:"
271 <<
" min=" << *GII_min_max.first <<
" max=" << *GII_min_max.second
273 trace.
info() <<
"Computed CNC Gaussian curvatures:"
274 <<
" min=" << *G_min_max.first <<
" max=" << *G_min_max.second
276 const auto error_HII = SHG::getScalarsAbsoluteDifference( HII, exp_H );
277 const auto stat_error_HII = SHG::getStatistic( error_HII );
278 const auto error_HII_l2 = SHG::getScalarsNormL2( HII, exp_H );
279 trace.
info() <<
"|H-H_II|_oo = " << stat_error_HII.max() << std::endl;
280 trace.
info() <<
"|H-H_II|_2 = " << error_HII_l2 << std::endl;
281 const auto error_H = SHG::getScalarsAbsoluteDifference( H, exp_H );
282 const auto stat_error_H = SHG::getStatistic( error_H );
283 const auto error_H_l2 = SHG::getScalarsNormL2( H, exp_H );
284 trace.
info() <<
"|H-H_CNC|_oo = " << stat_error_H.max() << std::endl;
285 trace.
info() <<
"|H-H_CNC|_2 = " << error_H_l2 << std::endl;
286 const auto error_GII = SHG::getScalarsAbsoluteDifference( GII, exp_G );
287 const auto stat_error_GII = SHG::getStatistic( error_GII );
288 const auto error_GII_l2 = SHG::getScalarsNormL2( GII, exp_G );
289 trace.
info() <<
"|G-G_II|_oo = " << stat_error_GII.max() << std::endl;
290 trace.
info() <<
"|G-G_II|_2 = " << error_GII_l2 << std::endl;
291 const auto error_G = SHG::getScalarsAbsoluteDifference( G, exp_G );
292 const auto stat_error_G = SHG::getStatistic( error_G );
293 const auto error_G_l2 = SHG::getScalarsNormL2( G, exp_G );
294 trace.
info() <<
"|G-G_CNC|_oo = " << stat_error_G.max() << std::endl;
295 trace.
info() <<
"|G-G_CNC|_2 = " << error_G_l2 << std::endl;
299 std::cout <<
"# " << argv[ 0 ] << std::endl
300 <<
"# polynomial: " << poly << std::endl
301 <<
"# CNC mode: " << mode << std::endl;
303 std::cout <<
"# h nb_surfels ii_t ii_r ii_Hoo ii_H2 ii_Goo ii_G2 ";
305 std::cout <<
"cnc_tn cnc_t cnc_mr cnc_Hoo cnc_H2 cnc_Goo cnc_G2" << std::endl;
306 std::cout << h <<
" " << surfels.size() <<
" " << ii_t <<
" " << ii_r
307 <<
" " << stat_error_HII.max() <<
" " << error_HII_l2
308 <<
" " << stat_error_GII.max() <<
" " << error_GII_l2
309 <<
" " << cnc_tn <<
" " << cnc_t <<
" " << cnc_mr
310 <<
" " << stat_error_H.max() <<
" " << error_H_l2
311 <<
" " << stat_error_G.max() <<
" " << error_G_l2 << std::endl;
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
void beginBlock(const std::string &keyword="")
void usage(int argc, char *argv[])
CountedPtr< SH3::DigitalSurface > surface
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
std::pair< typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator, typename graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator > vertices(const DGtal::DigitalSurface< TDigitalSurfaceContainer > &digSurf)
Aim: Utility class to compute curvature measures induced by (1) a corrected normal current defined by...
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...