// =========================================================================
#include <fstream>
+#include <random>
#include <streambuf>
#include <tclap/CmdLine.h>
this->m_StrArgs[ "fastrw_points" ] = TStrArg( "", "B", false );
this->m_StrArgs[ "slicerw_points" ] = TStrArg( "", "C", false );
this->m_StrArgs[ "andrw_points" ] = TStrArg( "", "D", false );
+ this->m_StrArgs[ "points" ] = TStrArg( "", "E", false );
this->m_StrArgs[ "seed_file" ] = TStrArg( "", "P", false );
this->m_StrArgs[ "seed" ] = TStrArg( "", "S", false );
this->m_StrArgs[ "seed_type" ] = TStrArg( "point", "T", false );
TString bname = std::get< 0 >( this->m_StrArgs[ "input" ] );
bname = bname.substr( 0, bname.find_last_of( "." ) );
const unsigned int N = 6;
- const unsigned int M = 6;
+ const unsigned int M = 7;
TString names[ N + M ] =
{
"vesselness",
"andrw_skeleton",
"fastrw_points",
"slicerw_points",
- "andrw_points"
+ "andrw_points",
+ "points"
};
for( unsigned int i = 0; i < N; ++i )
if( std::get< 0 >( this->m_StrArgs[ names[ i ] ] ) == "" )
);
this->_AndImages( this->m_FastRW, this->m_SliceRW, this->m_AndRW );
this->_Skeleton(
- this->m_SliceRW, this->m_SliceRWSkeleton,
- std::get< 0 >( this->m_StrArgs[ "slicerw_skeleton" ] ),
- std::get< 0 >( this->m_StrArgs[ "slicerw_points" ] )
+ this->m_FastRW, this->m_FastRWSkeleton, this->m_FastRWPoints, 2,
+ std::get< 0 >( this->m_StrArgs[ "fastrw_skeleton" ] )
);
this->_Skeleton(
- this->m_AndRW, this->m_AndRWSkeleton,
- std::get< 0 >( this->m_StrArgs[ "andrw_skeleton" ] ),
- std::get< 0 >( this->m_StrArgs[ "andrw_points" ] )
+ this->m_SliceRW, this->m_SliceRWSkeleton, this->m_SliceRWPoints, 1,
+ std::get< 0 >( this->m_StrArgs[ "slicerw_skeleton" ] )
);
this->_Skeleton(
- this->m_FastRW, this->m_FastRWSkeleton,
- std::get< 0 >( this->m_StrArgs[ "fastrw_skeleton" ] ),
- std::get< 0 >( this->m_StrArgs[ "fastrw_points" ] )
+ this->m_AndRW, this->m_AndRWSkeleton, this->m_AndRWPoints, 0,
+ std::get< 0 >( this->m_StrArgs[ "andrw_skeleton" ] )
);
+
+ TEndPoints eval_points;
+ this->_Points(
+ this->m_FastRWPoints, 3,
+ this->m_SliceRWPoints, 3,
+ this->m_AndRWPoints, 4,
+ eval_points
+ );
+
+ if( eval_points.size( ) > 0 )
+ {
+ std::stringstream ePointsStr;
+ for( TEndPoint ep: eval_points )
+ {
+ for( unsigned int d = 0; d < Self::Dim; ++d )
+ ePointsStr << ep.first[ d ] << " ";
+ ePointsStr << ep.second << std::endl;
+
+ } // rof
+
+ std::string pname = std::get< 0 >( this->m_StrArgs[ "points" ] );
+ std::ofstream ePointsF( pname.c_str( ), std::ofstream::binary );
+ if( !ePointsF )
+ throw std::runtime_error(
+ TString( "Unable to write skeleton to \"" ) + pname + "\""
+ );
+ ePointsF.write( ePointsStr.str( ).c_str( ), ePointsStr.str( ).size( ) );
+
+ } // fi
}
// -------------------------------------------------------------------------
}
// -------------------------------------------------------------------------
-template< class _TInput, class _TSkeleton >
+template< class _TInput, class _TSkeleton, class _TIndices >
void CTBronchi::Process::
_Skeleton(
_TInput& a, _TSkeleton& s,
- const TString& fname,
- const TString& pname
+ _TIndices& e, unsigned int id,
+ const TString& fname
)
{
double t = s.Load( fname );
std::cout << "\"" << fname << "\" saved in " << t1 << " s." << std::endl;
// End points
- std::stringstream ePointsStr;
- std::vector< typename _TInput::TImage::IndexType > ePoints =
- filter.Get( )->GetEndPoints( );
- for( typename _TInput::TImage::IndexType i: ePoints )
- {
- for( unsigned int d = 0; d < _TInput::VDim; ++d )
- ePointsStr << i[ d ] << " ";
- ePointsStr << std::endl;
-
- } // rof
-
- std::ofstream ePointsF( pname.c_str( ), std::ofstream::binary );
- if( !ePointsF )
- throw std::runtime_error(
- TString( "Unable to write skeleton to \"" ) + pname + "\""
- );
- ePointsF.write( ePointsStr.str( ).c_str( ), ePointsStr.str( ).size( ) );
+ std::vector< TIndex > ePoints = filter.Get( )->GetEndPoints( );
+ e.clear( );
+ for( TIndex p: ePoints )
+ e.insert( TEndPoint( p, id ) );
} // fi
std::cout << "Skeleton computed in " << t << " s." << std::endl;
}
+// -------------------------------------------------------------------------
+template< class _TIndices >
+void CTBronchi::Process::
+_Points(
+ _TIndices& a, unsigned int ca,
+ _TIndices& b, unsigned int cb,
+ _TIndices& c, unsigned int cc,
+ _TIndices& d
+ )
+{
+ std::random_device rd;
+ std::mt19937 gen( rd( ) );
+ d.clear( );
+ while( d.size( ) < ca )
+ {
+ std::uniform_int_distribution< > dis( 0, a.size( ) - 1 );
+ unsigned int N = dis( gen );
+ typename _TIndices::const_iterator it = a.begin( );
+ for( unsigned int i = 0; i < N; ++i, ++it );
+ d.insert( *it );
+
+ } // fi
+ while( d.size( ) < ca + cb )
+ {
+ std::uniform_int_distribution< > dis( 0, b.size( ) - 1 );
+ unsigned int N = dis( gen );
+ typename _TIndices::const_iterator it = b.begin( );
+ for( unsigned int i = 0; i < N; ++i, ++it );
+ d.insert( *it );
+
+ } // fi
+ while( d.size( ) < ca + cb + cc )
+ {
+ std::uniform_int_distribution< > dis( 0, c.size( ) - 1 );
+ unsigned int N = dis( gen );
+ typename _TIndices::const_iterator it = c.begin( );
+ for( unsigned int i = 0; i < N; ++i, ++it );
+ d.insert( *it );
+
+ } // fi
+}
+
// eof - $RCSfile$
#define __CTBronchi__Process__h__
#include <map>
+#include <set>
#include <tuple>
#include <fpa_ctbronchi_export.h>
#include "Image.h"
class FPA_CTBRONCHI_EXPORT Process
{
public:
+ typedef Process Self;
+
// Some types and values
static const unsigned int Dim = 3;
typedef short TPixel;
typedef CTBronchi::Skeleton< Dim > TSkeleton;
// Seed
- typedef TPixelImage::TImage::PointType TPoint;
- typedef TPixelImage::TImage::IndexType TIndex;
- typedef std::pair< TIndex, TPoint > TSeed;
+ typedef TPixelImage::TImage::PointType TPoint;
+ typedef TPixelImage::TImage::IndexType TIndex;
+ typedef std::pair< TIndex, TPoint > TSeed;
+ typedef std::pair< TIndex, unsigned int > TEndPoint;
+ struct TEndPointCompare
+ {
+ bool operator()( const TEndPoint& a, const TEndPoint& b ) const
+ {
+ return( cmp( a.first, b.first ) );
+ }
+ TIndex::LexicographicCompare cmp;
+ };
+ typedef std::set< TEndPoint, TEndPointCompare > TEndPoints;
public:
Process( );
template< class _TInput >
void _AndImages( _TInput& a, _TInput& b, _TInput& c );
- template< class _TInput, class _TSkeleton >
+ template< class _TInput, class _TSkeleton, class _TIndices >
void _Skeleton(
_TInput& a, _TSkeleton& s,
- const TString& fname,
- const TString& pname
+ _TIndices& e, unsigned int id,
+ const TString& fname
+ );
+
+ template< class _TIndices >
+ void _Points(
+ _TIndices& a, unsigned int ca,
+ _TIndices& b, unsigned int cb,
+ _TIndices& c, unsigned int cc,
+ _TIndices& d
);
protected:
TSkeleton m_FastRWSkeleton;
TSkeleton m_SliceRWSkeleton;
TSkeleton m_AndRWSkeleton;
+
+ TEndPoints m_FastRWPoints;
+ TEndPoints m_SliceRWPoints;
+ TEndPoints m_AndRWPoints;
};
} // ecapseman