48int main(
int argc,
char** argv )
53 typedef SH3::Cell
Cell;
55 const double alpha_at = 0.1;
56 const double lambda_at = 0.01;
57 const double e1 = 2.0;
58 const double e2 = 0.25;
59 const double er = 2.0;
61 const string volfile = argc > 1 ? argv[ 1 ] : examplesPath +
"samples/Al.100.vol";
62 const double threshold = argc > 2 ? atof( argv[ 2 ] ) : 0.5;
63 trace.
beginBlock (
"Load vol file -> build digital surface -> estimate II normals." );
65 auto params = SH3::defaultParameters() | SHG3::defaultParameters();
66 auto bimage = SH3::makeBinaryImage( volfile, params );
67 auto K = SH3::getKSpace( bimage, params );
68 auto surface = SH3::makeDigitalSurface( bimage,
K, params );
69 auto surfels = SH3::getSurfelRange(
surface, params );
70 auto linels = SH3::getCellRange(
surface, 1 );
71 auto ii_normals= SHG3::getIINormalVectors( bimage, surfels, params );
72 auto uembedder = SH3::getCellEmbedder(
K );
73 auto embedder = SH3::getSCellEmbedder(
K );
80 const auto calculus = CalculusFactory::createFromNSCells<2>( surfels.begin(), surfels.end() );
85 at_solver.
setUp( alpha_at, lambda_at );
92 auto at_normals = ii_normals;
95 SH3::RealPoints positions( surfels.size() );
96 std::transform( surfels.cbegin(), surfels.cend(), positions.begin(),
97 [&] (
const SH3::SCell& c) { return embedder( c ); } );
98 SH3::Colors colors( surfels.size() );
99 for (
size_t i = 0; i < surfels.size(); i++ )
100 colors[ i ] = SH3::Color( (
unsigned char) 255.0*fabs( at_normals[ i ][ 0 ] ),
101 (
unsigned char) 255.0*fabs( at_normals[ i ][ 1 ] ),
102 (
unsigned char) 255.0*fabs( at_normals[ i ][ 2 ] ) );
103 std::transform( surfels.cbegin(), surfels.cend(), positions.begin(),
104 [&] (
const SH3::SCell& c) { return embedder( c ); } );
106 bool ok1 = SH3::saveOBJ(
surface, at_normals, SH3::Colors(),
107 "output-surface.obj" );
108 bool ok2 = SH3::saveOBJ(
surface, at_normals, colors,
109 "output-surface-at-normals.obj" );
110 bool ok3 = SH3::saveVectorFieldOBJ( positions, at_normals, 0.05, SH3::Colors(),
111 "output-vf-at-normals.obj",
112 SH3::Color( 0, 0, 0 ), SH3::Color::Red );
114 ASSERT(ok1 && ok2 && ok3);
116 SH3::Scalars features( linels.size() );
122 for (
size_t i = 0; i < linels.size(); i++ )
124 if ( features[ i ] < threshold )
126 const Cell linel = linels[ i ];
130 f0.push_back( uembedder( p0 ) );
131 f1.push_back( uembedder( p1 ) - uembedder( p0 ) );
134 bool ok4 = SH3::saveVectorFieldOBJ( f0, f1, 0.1, SH3::Colors(),
135 "output-features.obj",
136 SH3::Color( 0, 0, 0 ), SH3::Color::Red );