37 #ifndef AIMS_CONNECTIVITY_COMPONENT_D_H 
   38 #define AIMS_CONNECTIVITY_COMPONENT_D_H 
   52   template<
typename T, 
typename O>
 
   53   void ConnectedComponentEngine<carto::VolumeRef<T>,
 
   57     std::map<O, size_t>& valids,
 
   61     int x = 0, y = 0, z = 0;
 
   64       std::cout << 
"filtering...\n";
 
   68     typename std::map<O, size_t>::iterator  is, es = valids.end();
 
   77     for( ; !it.
ended(); ++it, ++oit )
 
   84         is = valids.find( (O) *p );
 
   92   template<
typename T, 
typename O>
 
   98     std::multimap<size_t, O>& compSizes,
 
  104     int x = 0, y = 0, z = 0, n = 0;
 
  105     std::vector<int> dims = data->
getSize();
 
  128     for( ; !bit.
ended(); ++bit, ++it )
 
  143     std::queue<Point3dl> que;
 
  150     for ( z = 0; z < dimZ; ++z )
 
  153         std::cout << 
"\rz: " << z << std::flush;
 
  155       for ( y = 0; y < dimY; ++y )
 
  156         for ( x = 0; x < dimX; ++x )
 
  157           if( !flag( x, y, z ) )
 
  159             val = data( x, y, z, t );
 
  161             flag( x, y, z ) = 
true;
 
  163             while ( !que.empty() )
 
  175                 if ( newpos[0] >= 0   &&
 
  183                         && ( bin || data( newpos[0], newpos[1], newpos[2], t ) == val ) )
 
  185                     flag( newpos ) = 
true;
 
  193             compSizes.insert( std::pair<size_t, O>( sz, label ) );
 
  200       std::cout << std::endl;
 
  201       std::cout << label << 
" components" << std::endl;
 
  206   template<
typename T, 
typename O>
 
  212     std::map<O, size_t>& valids,
 
  213     const T & backg, 
bool bin, 
 
  214     size_t minSize, 
size_t maxSize,
 
  215     size_t numMax, 
bool verbose )
 
  217     std::multimap<size_t, size_t> compSizes;
 
  224     for( t = 0 ; t < dimT ; ++t )
 
  231         ::connectedInFrame( data, 
 
  241       std::multimap<size_t, size_t>::reverse_iterator 
 
  242         im, em = compSizes.rend();
 
  246       for( im = compSizes.rbegin(); 
 
  247            im != em && ( numMax == 0 || 
static_cast<size_t>(label) <= numMax ); ++im )
 
  252             std::cout << 
"component " << std::setw( 4 ) << im->second 
 
  253                         << 
" : " << std::setw( 8 ) << im->first 
 
  254                         << 
" points" << std::endl;
 
  255             valids[ im->second ] = 
static_cast<size_t>( label++ );
 
  260         ::filterInFrame( cc, out, valids, t, 
verbose );
 
  263         std::cout << 
"after filtering: " << valids.size() << 
" components\n";
 
  268   template <
typename T> 
 
  272                                const T & backgrnd, 
bool bin, 
 
  273                                size_t minsize, 
size_t maxsize,
 
  274                                size_t maxcomp, 
bool verbose )
 
  277     std::unique_ptr<AimsBucket<Void> >  abk;
 
  278     if( minsize == 0 && maxsize == 0 && maxcomp == 0 )
 
  288     int x=0, y=0, z=0, t=0, n=0;
 
  300     for( t = 0 ; t < dimT ; ++t )
 
  312       for( ; !bit.
ended(); ++bit, ++it )
 
  327       std::queue< AimsBucketItem< Void > >      que;
 
  334       for ( z = 0; z < dimZ; ++z )
 
  337           std::cout << 
"\rz: " << z << std::flush;
 
  338         for ( y = 0; y < dimY; ++y )
 
  339           for ( x = 0; x < dimX; ++x )
 
  341               if( !flag( x, y, z ) )
 
  344                   val = data( x, y, z );
 
  347                   flag( x, y, z ) = 
true;
 
  348                   std::list<AimsBucketItem<Void> > & bk = component[ label ];
 
  349                   while ( !que.empty() )
 
  351                       item.
location() = que.front().location();
 
  353                       bk.push_back( item );
 
  365                             if ( flag( newItem.
location() ) == 
false  
  366                                  && ( bin || data( newItem.
location() ) 
 
  379         std::cout << std::endl;
 
  382       if( minsize == 0 && maxsize == 0 && maxcomp == 0 )
 
  386       std::multimap<unsigned, std::list<AimsBucketItem<Void> > *>       comps;
 
  387       for( i=component.begin(); i!=e; ++i )
 
  388         if(( minsize == 0 || i->second.size() >= minsize ) && ( maxsize == 0 || i->second.size() <= maxsize ))
 
  390                       ( i->second.size(),&i->second ) );
 
  391       std::multimap<unsigned, 
 
  392         std::list<AimsBucketItem<Void> > *>::reverse_iterator 
 
  393         im, em = comps.rend();
 
  395       for( im=comps.rbegin(); im!=em && label < maxcomp; ++im )
 
  396         components[ label++ ] = *im->second;
 
  403     template <
typename T> 
inline  
  418   template <
typename T>
 
  422                                const T & backg, 
bool bin, 
 
  423                                size_t minsize, 
size_t maxsize,
 
  424                                size_t maxcomp, 
bool )
 
  427     std::unique_ptr<AimsBucket<Void> >  abk;
 
  428     if( minsize == 0 && maxsize == 0 && maxcomp == 0 )
 
  448     for( ib=b.begin(); ib!=eb; ++ib )
 
  456     std::queue< AimsBucketItem< Void > >        que;
 
  462     for( ib=b.begin(); ib!=eb; ++ib )
 
  464         ifl = flag.find( ib->first );
 
  472             std::list<AimsBucketItem<Void> >    & bk = component[ label ];
 
  473             while ( !que.empty() )
 
  475                 item.
location() = que.front().location();
 
  477                 bk.push_back( item );
 
  481                     ifl = flag.find( newItem.
location() );
 
  482                     if( ifl != efl && ifl->second == 
false  
  484                              || b.find( newItem.
location() )->second == val ) )
 
  497     if( minsize == 0 && maxcomp == 0 )
 
  501     std::multimap<unsigned, std::list<AimsBucketItem<Void> > *> comps;
 
  502     for( i=component.begin(); i!=e; ++i )
 
  503       if(( minsize == 0 || i->second.size() >= minsize ) && ( maxsize == 0 || i->second.size() <= maxsize ))
 
  505                       ( i->second.size(),&i->second ) );
 
  506     std::multimap<unsigned, 
 
  507       std::list<AimsBucketItem<Void> > *>::reverse_iterator 
 
  508       im, em = comps.rend();
 
  510     for( im=comps.rbegin(); im!=em && label<maxcomp; ++im )
 
  511       components[ label++ ] = *im->second;
 
  515   template <
typename T>
 
  518                                const T & backgrnd, 
bool bin,
 
  519                                size_t minsize, 
size_t maxsize,
 
  527     std::list<AimsBucketItem<Void> >::iterator  ic, ec;
 
  532     for( ib=data.begin(); ib!=eb; ++ib )
 
  533       for( ibb=ib->second.begin(), ebb=ib->second.end(); ibb!=ebb; ++ibb )
 
  537     for( i=comps.begin(); i!=e; ++i )
 
  538       for( ic=i->second.begin(), ec=i->second.end(); ic!=ec; ++ic )
 
  539         bk[ ic->location() ] = i->first + 1;
 
  543   template <
typename T> 
 
  548     const T & backgrnd, 
bool bin,
 
  549     size_t minsize, 
size_t maxsize,
 
  550     size_t maxcomp, 
bool verbose )
 
  556     labelImage->
fill( 0 );
 
  557     std::unique_ptr<AimsBucket<Void> >  abk;
 
  558     if( minsize == 0 && maxsize == 0 && maxcomp == 0 )
 
  568     int x=0, y=0, z=0, t=0, n=0;
 
  579     for( t = 0 ; t < dimT ; ++t )
 
  590       for( ; !bit.
ended(); ++it, ++bit )
 
  606       std::queue< AimsBucketItem< Void > >  que;
 
  612       for ( z = 0; z < dimZ; ++z )
 
  615           std::cout << 
"\rz: " << z << std::flush;
 
  616         for ( y = 0; y < dimY; ++y )
 
  617           for ( x = 0; x < dimX; ++x )
 
  620           if( !flag( x, y, z ) )
 
  623             val = data( x, y, z );
 
  626             labelImage (x, y, z) = label;
 
  628             flag( x, y, z ) = 
true;
 
  631             std::list<AimsBucketItem<Void> > & bk = component[ label ];
 
  632             while ( !que.empty() )
 
  634               item.
location() = que.front().location();
 
  636               bk.push_back( item );
 
  637               labelImage (item.
location()) =label;
 
  649                   if ( flag( newItem.
location() ) == 
false  
  650                        && ( bin || data( newItem.
location() ) 
 
  655                   labelImage (newItem.
location()) = label;
 
  665         std::cout << std::endl;
 
  668       if( minsize == 0 && maxsize == 0 && maxcomp == 0 )
 
  672       std::multimap<unsigned, std::list<AimsBucketItem<Void> > *> comps;
 
  673       for( i=component.begin(); i!=e; ++i )
 
  674         if(( minsize == 0 || i->second.size() >= minsize ) && (maxsize == 0 || i->second.size() <= maxsize ))
 
  676               ( i->second.size(),&i->second ) );
 
  678       std::multimap<unsigned, 
 
  679       std::list<AimsBucketItem<Void> > *>::reverse_iterator 
 
  680           im, em = comps.rend();
 
  683       for( im=comps.rbegin(); im!=em && (label < maxcomp || maxcomp == 0); ++im ){
 
  684           std::list<AimsBucketItem<Void> > bucket = *im->second;
 
  685           std::list<AimsBucketItem<Void> >::iterator ite, iteend = bucket.
end();
 
  686           for (ite = bucket.begin(); ite != iteend ; ite ++ ) {
 
  687               labelImage ((*ite).location()) = label;
 
  689         components[ label++ ] = *im->second;
 
The template base class for all types of bucket items.
const AimsVector< short, 3 > & location() const
Get a const reference to the location of the bucket item.
The bucket base class to manage packages of points associated to their value during time.
std::map< int, std::list< AimsBucketItem< T > > >::iterator iterator
const T & item(int d) const
An alternate, ordered, representation for buckets (voxels lists).
std::map< int, Bucket >::iterator iterator
std::map< Point3d, T, BucketMapLess > Bucket
Topology of a data container.
const Point3d & xyzOffset(int n) const
Get the X/Y/Z offsets of the nth element.
int nbNeighbors() const
Get the number of neighbors for that connectivity.
Type
The different kinds of connectivity.
std::vector< int > getSize() const
std::vector< int > getSize() const
const T & at(long x, long y=0, long z=0, long t=0) const
void fill(const T &value)
std::vector< size_t > getStrides() const
std::vector< size_t > getStrides() const
void fill(const T &value)
const T & at(long x, long y=0, long z=0, long t=0) const
void inc_line_ptr(const T *&p) const
void inc_line_ptr(T *&p) const
bool _nulltesttemplate_iseq(const T &x, const T &val)
The class for EcatSino data write operation.
carto::VolumeRef< int16_t > AimsLabeledConnectedComponent(AimsBucket< Void > &component, const carto::VolumeRef< T > &data, aims::Connectivity::Type connectivity, const T &backgrnd=0, bool bin=true, size_t minsize=0, size_t maxSize=0, size_t maxcomp=0, bool verbose=true)
void AimsConnectedComponent(carto::VolumeRef< T > data, aims::Connectivity::Type connectivity, std::map< T, size_t > &valids, const T &backgrnd=0, bool bin=true, size_t minSize=0, size_t maxSize=0, size_t numMax=0, bool verbose=true)
std::vector< int > minSize(const std::vector< int > &s1, const std::vector< int > &s2)
std::vector< int > maxSize(const std::vector< int > &s1, const std::vector< int > &s2)