73#include "DGtal/base/Common.h" 
   74#include "DGtal/io/viewers/PolyscopeViewer.h" 
   75#include "DGtal/io/Color.h" 
   76#include "DGtal/shapes/Shapes.h" 
   77#include "DGtal/helpers/StdDefs.h" 
   78#include "DGtal/helpers/Shortcuts.h" 
   79#include "DGtal/images/ImageContainerBySTLVector.h" 
   80#include "DGtal/geometry/volumes/NeighborhoodConvexityAnalyzer.h" 
   92template < 
typename KSpace, 
int N >
 
   97  template < 
typename ImagePtr >
 
  104    auto& 
image = *bimage;
 
  110    std::vector< Point > localCompX;
 
  113    std::cout << 
"Cfg=" << cfg << std::endl;
 
  114    for ( 
auto q : localCompX ) std::cout << q;
 
  115    std::cout << std::endl;
 
  116    geom = ( cvx ? 0x1 : 0x0 ) | ( ccvx ? 0x2 : 0x0 );
 
  117    std::cout << 
"cvx=" << cvx << 
" ccvx=" << ccvx << std::endl;
 
  118    std::cout << 
"geom=" << geom << std::endl;
 
 
  122  template < 
typename ImagePtr >
 
  125  run( 
const KSpace& aK, 
const std::vector<Point>& pts, ImagePtr bimage )
 
  129    auto& 
image = *bimage;
 
  130    std::vector<int> result;
 
  131    std::map< Point, int > computed;
 
  139        if ( i % 100 == 0 ) 
trace.progressBar( i, nb );
 
  140        auto it = computed.find( p );
 
  141        if ( it == computed.end() )
 
  146            if ( cvx  ) nb_cvx  += 1;
 
  147            if ( ccvx ) nb_ccvx += 1;
 
  148            geom = ( cvx ? 0x1 : 0x0 ) | ( ccvx ? 0x2 : 0x0 );
 
  149            computed[ p ] = geom;
 
  151        else geom = it->second;
 
  152        result.push_back( geom );
 
  155    trace.info() << 
"nb_cvx=" << nb_cvx << 
" nb_ccvx=" << nb_ccvx << std::endl;
 
 
  159  template < 
typename ImagePtr >
 
  162  run( std::vector<int> & to_update,
 
  163       const KSpace& aK, 
const std::vector<Point>& pts, ImagePtr bimage )
 
  167    auto& 
image = *bimage;
 
  168    std::map< Point, int > computed;
 
  174        if ( i % 100 == 0 ) 
trace.progressBar( i, nb );
 
  175        auto it = computed.find( p );
 
  176        if ( it == computed.end() )
 
  179            bool  cvx = ( to_update[ i ] & 0x1 )
 
  182            bool ccvx = ( to_update[ i ] & 0x2 )
 
  185            geom = ( cvx ? 0x1 : 0x0 ) | ( ccvx ? 0x2 : 0x0 );
 
  186            computed[ p ] = geom;
 
  188        else geom = it->second;
 
  189        to_update[ i++ ] = geom;
 
 
 
  194template < 
typename KSpace, 
int N >
 
  200  template < 
typename ImagePtr >
 
  202  std::vector< Geometry >
 
  204                  const std::vector<Point>& pts,
 
  209    trace.info() << 
"------- Analyzing scale " << N << 
" --------" << std::endl;
 
  210    std::vector< int > geom( prev_geometry.size() );
 
  211    for ( 
int i = 0; i < geom.size(); i++ )
 
  212      geom[ i ] = ( prev_geometry[ i ].first == N-1 ? 0x1 : 0x0 )
 
  213        |  ( prev_geometry[ i ].second == N-1 ? 0x2 : 0x0 );
 
  215    for ( 
int i = 0; i < geom.size(); i++ ) {
 
  216      prev_geometry[ i ].first  += ( geom[ i ] & 0x1 ) ? 1 : 0;
 
  217      prev_geometry[ i ].second += ( geom[ i ] & 0x2 ) ? 1 : 0;
 
  219    return prev_geometry;
 
 
 
  224template < 
typename KSpace>
 
  229  template < 
typename ImagePtr >
 
  231  std::vector< Geometry >
 
  233                  const std::vector<Point>& pts,
 
  238    return std::vector< Geometry >( pts.size(), std::make_pair( 0, 0 ) );
 
 
 
  242int main( 
int argc, 
char** argv )
 
  246      trace.info() << 
"Usage: " << argv[ 0 ] << 
" <K> <input.vol> <m> <M>" << std::endl;
 
  247      trace.info() << 
"\tAnalyze the  shape with local full convexity" << std::endl;
 
  248      trace.info() << 
"\t- 1 <= K <= 5: analysis at scale K" << std::endl;
 
  249      trace.info() << 
"\t- K == 0: multiscale analysis (using scales 1-5)" << std::endl;
 
  250      trace.info() << 
"\t- input.vol: choose your favorite shape" << std::endl;
 
  251      trace.info() << 
"\t- m [==0], M [==255]: used to threshold input vol image" << std::endl;
 
  254  int         N = atoi( argv[ 1 ] );
 
  255  std::string fn= argv[ 2 ];
 
  256  int         m = argc > 3 ? atoi( argv[ 3 ] ) : 0;
 
  257  int         M = argc > 4 ? atoi( argv[ 4 ] ) : 255;
 
  262  trace.info() << 
"Building set or importing vol ... ";
 
  264  params( 
"thresholdMin", m );
 
  265  params( 
"thresholdMax", M );
 
  268  trace.info() << 
"  [Done]" << std::endl;
 
  270  params( 
"surfaceComponents" , 
"All" );
 
  275  std::vector< Point >   points;
 
  276  std::map< SCell, int > surfel2idx;
 
  277  std::map< Point, int > point2idx;
 
  283      auto voxel  = 
K.sIncident( s, k, 
K.sDirect( s, k ) );
 
  284      Point p     = 
K.sCoords( voxel );
 
  285      auto it     = point2idx.find( p );
 
  286      if ( it == point2idx.end() )
 
  288          points.push_back( p );
 
  289          surfel2idx[ s ] = idx;
 
  290          point2idx [ p ] = idx++;
 
  293        surfel2idx[ s ] = it->second;
 
  295  trace.info() << 
"Shape has " << points.size() << 
" interior boundary points" 
  299      std::vector< int > result;
 
  300      trace.beginBlock ( 
"Single scale analysis" );
 
  309        { 
Color( 255, 0, 0, 255 ), 
Color( 0, 255, 0, 255 ),
 
  310          Color( 0, 0, 255, 255 ), 
Color( 255, 255, 255, 255 ) };
 
  313      for ( 
int i = 0; i < surfels.size(); i++ )
 
  315          const auto    j = surfel2idx[ surfels[ i ] ];
 
  316          all_colors[ i ] = colors[ result[ j ] ];
 
  323          viewer << all_colors[ i ]
 
  331      trace.beginBlock ( 
"Multiscale analysis" );
 
  335      Color colors_planar[ 6 ] =
 
  336        { 
Color( 0, 255, 255, 255),
 
  337          Color( 50, 255, 255, 255), 
Color( 100, 255, 255, 255),
 
  338          Color( 150, 255, 255, 255), 
Color( 200, 255, 255, 255 ),
 
  339          Color( 255, 255, 255, 255 ) };
 
  340      Color color_atypical( 255, 0, 0, 255 ); 
 
  341      Color colors_cvx[ 5 ] =
 
  342        { 
Color( 0, 255, 0, 255 ), 
Color( 50, 255, 50, 255 ),
 
  343          Color( 100, 255, 100, 255 ), 
Color( 150, 255, 150, 255 ),
 
  344          Color( 200, 255, 200, 255 ) };
 
  345      Color colors_ccv[ 5 ] =
 
  346        { 
Color( 0, 0, 255, 255 ), 
Color( 50, 50, 255, 255 ),
 
  347          Color( 100, 100, 255, 255 ), 
Color( 150, 150, 255, 255 ),
 
  348          Color( 200, 200, 255, 255 ) };
 
  351      for ( 
int i = 0; i < surfels.size(); i++ ) {
 
  352        const auto j = surfel2idx[ surfels[ i ] ];
 
  353        int m0 = std::min( geometry[ j ].first, geometry[ j ].second );
 
  354        int m1 = std::max( geometry[ j ].first, geometry[ j ].second );
 
  355        if ( m1 == 0 ) all_colors[ i ] = color_atypical;
 
  356        else if ( m0 == m1 ) all_colors[ i ] = colors_planar[ 5 ];
 
  357        else if ( geometry[ j ].first > geometry[ j ].second )
 
  358          all_colors[ i ] = colors_cvx[ 5 - abs( m0 - m1 ) ];
 
  360          all_colors[ i ] = colors_ccv[ 5 - abs( m0 - m1 ) ];
 
  368          viewer << all_colors[ i ]
 
 
Structure representing an RGB triple with alpha component.
const Point & lowerBound() const
Return the lower bound for digital points in this space.
PointVector< dim, Integer > Point
const Point & upperBound() const
Return the upper bound for digital points in this space.
static const constexpr Dimension dimension
bool isComplementaryFullyConvex(bool with_center)
static Configuration makeConfiguration(Configuration current, bool complement, bool with_center)
bool isFullyConvex(bool with_center)
void setCenter(Point c, const PointPredicate &X)
void getLocalCompX(std::vector< Point > &localCompX, bool with_center) const
Configuration configuration() const
void show() override
Starts the event loop and display of elements.
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
std::vector< Color > Colors
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters ¶ms=parametersDigitalSurface())
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters ¶ms=parametersDigitalSurface())
std::vector< RealVector > RealVectors
static Parameters defaultParameters()
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, const TCellEmbedder &embedder, const RealVectors &normals, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
static CountedPtr< BinaryImage > makeBinaryImage(Domain shapeDomain)
CountedPtr< SH3::DigitalSurface > surface
Z3i this namespace gathers the standard of types for 3D imagery.
KhalimskySpaceND< 3, Integer > KSpace
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
static std::vector< Point > debug_one(const KSpace &aK, Point p, ImagePtr bimage)
NeighborhoodConvexityAnalyzer< KSpace, N > NCA
static void run(std::vector< int > &to_update, const KSpace &aK, const std::vector< Point > &pts, ImagePtr bimage)
static std::vector< int > run(const KSpace &aK, const std::vector< Point > &pts, ImagePtr bimage)
std::pair< int, int > Geometry
static std::vector< Geometry > multiscale_run(const KSpace &aK, const std::vector< Point > &pts, ImagePtr bimage)
NeighborhoodConvexityAnalyzer< KSpace, N > NCA
static std::vector< Geometry > multiscale_run(const KSpace &aK, const std::vector< Point > &pts, ImagePtr bimage)
std::pair< int, int > Geometry