void computeEstimation ( const po::variables_map& vm, //< command-line parameters const KSpace& K, //< cellular grid space const ImplicitShape& shape, //< implicit shape "ground truth" const Surface& surface, //< digital surface approximating shape TrueEstimator& true_estimator, //< "ground truth" estimator Estimator& estimator ) //< an initialized estimator { typedef typename Surface::ConstIterator ConstIterator; typedef typename Surface::Surfel Surfel; typedef typename Estimator::Quantity Quantity; typedef double Scalar; typedef DepthFirstVisitor< Surface > Visitor; typedef GraphVisitorRange< Visitor > VisitorRange; typedef typename VisitorRange::ConstIterator VisitorConstIterator; std::string fname = vm[ "output" ].as<std::string>(); string nameEstimator = vm[ "estimator" ].as<string>(); trace.beginBlock( "Computing " + nameEstimator + "estimations." ); CountedPtr<VisitorRange> range( new VisitorRange( new Visitor( surface, *(surface.begin()) )) ); std::vector<Quantity> n_estimations; estimator.eval( range->begin(), range->end(), std::back_inserter( n_estimations ) ); trace.info() << "- nb estimations = " << n_estimations.size() << std::endl; trace.endBlock(); trace.beginBlock( "Computing ground truth." ); range = CountedPtr<VisitorRange>( new VisitorRange( new Visitor( surface, *(surface.begin()) )) ); std::vector<Quantity> n_true_estimations; true_estimator.eval( range->begin(), range->end(), std::back_inserter( n_true_estimations ) ); trace.info() << "- nb estimations = " << n_true_estimations.size() << std::endl; trace.endBlock(); trace.beginBlock( "Correcting orientations." ); ASSERT( n_estimations.size() == n_true_estimations.size() ); for ( unsigned int i = 0; i < n_estimations.size(); ++i ) if ( n_estimations[ i ].dot( n_true_estimations[ i ] ) < 0 ) n_estimations[ i ] = -n_estimations[ i ]; trace.endBlock(); DGtal::GradientColorMap<double> grad( 0.0, 40.0 ); // 0 metallic blue, 5 light cyan, 10 light green, 15 light // yellow, 20 yellow, 25 orange, 30 red, 35, dark red, 40- grey grad.addColor( DGtal::Color( 128, 128, 255 ) ); // 0 grad.addColor( DGtal::Color( 128, 255, 255 ) ); // 5 grad.addColor( DGtal::Color( 128, 255, 128 ) ); // 10 grad.addColor( DGtal::Color( 255, 255, 128 ) ); // 15 grad.addColor( DGtal::Color( 255, 255, 0 ) ); // 20 grad.addColor( DGtal::Color( 255, 128, 0 ) ); // 25 grad.addColor( DGtal::Color( 255, 0, 0 ) ); // 30 grad.addColor( DGtal::Color( 128, 0, 0 ) ); // 35 grad.addColor( DGtal::Color( 128, 128, 128 ) ); // 40 if ( vm.count( "angle-deviation-stats" ) ) { trace.beginBlock( "Computing angle deviation error stats." ); std::ostringstream adev_sstr; adev_sstr << fname << "-" << nameEstimator << "-angle-deviation-" << estimator.h() << ".txt"; DGtal::Statistic<Scalar> adev_stat; unsigned int i = 0; range = CountedPtr<VisitorRange>( new VisitorRange( new Visitor( surface, *(surface.begin()) )) ); for ( VisitorConstIterator it = range->begin(), itE = range->end(); it != itE; ++it, ++i ) { Quantity n_est = n_estimations[ i ]; Quantity n_true_est = n_true_estimations[ i ]; Scalar angle_error = acos( n_est.dot( n_true_est ) ); adev_stat.addValue( angle_error ); } adev_stat.terminate(); std::ofstream adev_output( adev_sstr.str().c_str() ); adev_output << "# Average error X of the absolute angle between two vector estimations." << std::endl; adev_output << "# h L1 L2 Loo E[X] Var[X] Min[X] Max[X] Nb[X]" << std::endl; adev_output << estimator.h() << " " << adev_stat.mean() // L1 << " " << sqrt( adev_stat.unbiasedVariance() + adev_stat.mean()*adev_stat.mean() ) // L2 << " " << adev_stat.max() // Loo << " " << adev_stat.mean() // E[X] (=L1) << " " << adev_stat.unbiasedVariance() // Var[X] << " " << adev_stat.min() // Min[X] << " " << adev_stat.max() // Max[X] << " " << adev_stat.samples() // Nb[X] << std::endl; adev_output.close(); trace.endBlock(); } if ( vm[ "export" ].as<string>() != "None" ) { trace.beginBlock( "Exporting cell geometry." ); std::ostringstream export_sstr; export_sstr << fname << "-" << nameEstimator << "-cells-" << estimator.h() << ".txt"; std::ofstream export_output( export_sstr.str().c_str() ); export_output << "# ImaGene viewer (viewSetOfSurfels) file format for displaying cells." << std::endl; bool adev = vm[ "export" ].as<string>() == "AngleDeviation"; unsigned int i = 0; range = CountedPtr<VisitorRange>( new VisitorRange( new Visitor( surface, *(surface.begin()) )) ); for ( VisitorConstIterator it = range->begin(), itE = range->end(); it != itE; ++it, ++i ) { Quantity n_est = n_estimations[ i ]; Quantity n_true_est = n_true_estimations[ i ]; Scalar angle_error = acos( n_est.dot( n_true_est ) )*180.0 / 3.14159625; Surfel s = *it; export_output << "CellN" << " " << min( 1023, max( 512+K.sKCoord( s, 0 ), 0 ) ) << " " << min( 1023, max( 512+K.sKCoord( s, 1 ), 0 ) ) << " " << min( 1023, max( 512+K.sKCoord( s, 2 ), 0 ) ) << " " << K.sSign( s ); Color c = grad( 0 ); if ( adev ) c = grad( max( 0.0, min( angle_error, 40.0 ) ) ); export_output << " " << ((double) c.red() / 255.0 ) << " " << ((double) c.green() / 255.0 ) << " " << ((double) c.blue() / 255.0 ); export_output << " " << n_est[ 0 ] << " " << n_est[ 1 ] << " " << n_est[ 2 ] << std::endl; } export_output.close(); trace.endBlock(); } if ( vm.count( "normals" ) ) { trace.beginBlock( "Exporting cells normals." ); std::ostringstream export_sstr; export_sstr << fname << "-" << nameEstimator << "-normals-" << estimator.h() << ".txt"; std::ofstream export_output( export_sstr.str().c_str() ); export_output << "# kx ky kz sign n_est[0] n_est[1] n_est[2] n_true[0] n_true[1] n_true[2]" << std::endl; unsigned int i = 0; range = CountedPtr<VisitorRange>( new VisitorRange( new Visitor( surface, *(surface.begin()) )) ); for ( VisitorConstIterator it = range->begin(), itE = range->end(); it != itE; ++it, ++i ) { Quantity n_est = n_estimations[ i ]; Quantity n_true_est = n_true_estimations[ i ]; Surfel s = *it; export_output << K.sKCoord( s, 0 ) << " " << K.sKCoord( s, 1 ) << " " << K.sKCoord( s, 2 ) << " " << K.sSign( s ) << " " << n_est[ 0 ] << " " << n_est[ 1 ] << " " << n_est[ 2 ] << " " << n_true_est[ 0 ] << " " << n_true_est[ 1 ] << " " << n_true_est[ 2 ] << std::endl; } export_output.close(); trace.endBlock(); } if ( vm.count( "noff" ) ) { trace.beginBlock( "Exporting NOFF file." ); std::ostringstream export_sstr; export_sstr << fname << "-" << nameEstimator << "-noff-" << estimator.h() << ".off"; std::ofstream export_output( export_sstr.str().c_str() ); std::map<Surfel,Quantity> normals; unsigned int i = 0; range = CountedPtr<VisitorRange>( new VisitorRange( new Visitor( surface, *(surface.begin()) )) ); for ( VisitorConstIterator it = range->begin(), itE = range->end(); it != itE; ++it, ++i ) { Quantity n_est = n_estimations[ i ]; normals[ *it ] = n_est; } CanonicSCellEmbedder<KSpace> surfelEmbedder( K ); typedef SCellEmbedderWithNormal< CanonicSCellEmbedder<KSpace> > Embedder; Embedder embedder( surfelEmbedder, normals ); surface.exportAs3DNOFF( export_output, embedder ); export_output.close(); trace.endBlock(); } #ifdef WITH_VISU3D_QGLVIEWER if ( vm[ "view" ].as<string>() != "None" ) { typedef typename KSpace::Space Space; typedef Viewer3D<Space,KSpace> MyViewever3D; typedef Display3DFactory<Space,KSpace> MyDisplay3DFactory; int argc = 1; char name[] = "Viewer"; char* argv[ 1 ]; argv[ 0 ] = name; Surfel s; QApplication application( argc, argv ); MyViewever3D viewer( K ); viewer.show(); viewer << SetMode3D( s.className(), "Basic" ); trace.beginBlock( "Viewing surface." ); bool adev = vm[ "view" ].as<string>() == "AngleDeviation"; unsigned int i = 0; range = CountedPtr<VisitorRange>( new VisitorRange( new Visitor( surface, *(surface.begin()) )) ); for ( VisitorConstIterator it = range->begin(), itE = range->end(); it != itE; ++it, ++i ) { Quantity n_est = n_estimations[ i ]; Quantity n_true_est = n_true_estimations[ i ]; Scalar angle_error = acos( n_est.dot( n_true_est ) )*180.0 / 3.14159625; s = *it; Color c = grad( 0 ); if ( adev ) c = grad( max( 0.0, min( angle_error, 40.0 ) ) ); viewer.setFillColor( c ); MyDisplay3DFactory::drawOrientedSurfelWithNormal( viewer, s, n_est, false ); } trace.endBlock(); viewer << MyViewever3D::updateDisplay; application.exec(); } #endif }