std::ofstream out_stream( argv[ 1 ] );
// Write include section
- out_stream
- << "#include <map>" << std::endl
- << "#include <set>" << std::endl;
for( int i = 2; i < argc; ++i )
out_stream << "#include \"" << argv[ i ] << "\"" <<std::endl;
// Write init/finish section
- out_stream
- << std::endl
- << "void __attribute__ ((constructor)) _initialize( )" << std::endl
- << "{" << std::endl << "}" << std::endl << std::endl
- << "void __attribute__ ((destructor)) _finalize( )" << std::endl
- << "{" << std::endl << "}" << std::endl << std::endl;
+ /* TODO:
+ out_stream
+ << std::endl
+ << "void __attribute__ ((constructor)) _initialize( )" << std::endl
+ << "{" << std::endl << "}" << std::endl << std::endl
+ << "void __attribute__ ((destructor)) _finalize( )" << std::endl
+ << "{" << std::endl << "}" << std::endl;
+ */
// Write access function
out_stream
- << "extern \"C\" std::map< std::string, std::set< std::string > > "
+ << std::endl
+ << "extern \"C\" __declspec(dllexport) const char* "
<< "cpPlugins_LoadedFilters( )" << std::endl << "{" << std::endl
- << " std::map< std::string, std::set< std::string > > classes;"
- << std::endl;
+ << " static std::string classes;"
+ << std::endl
+ << " classes = \"\";" << std::endl;
for( auto iIt = info.begin( ); iIt != info.end( ); ++iIt )
for( auto jIt = iIt->second.begin( ); jIt != iIt->second.end( ); ++jIt )
out_stream
- << " classes[ \"" << iIt->first
- << "\" ].insert( \"" << jIt->first << "\" );" << std::endl;
+ << " classes += std::string( \"" << iIt->first
+ << ":" << jIt->first << ";\" );" << std::endl;
out_stream
- << " return( classes );" << std::endl
+ << " return( classes.c_str( ) );" << std::endl
<< "}" << std::endl << std::endl;
// Write creators
for( auto jIt = iIt->second.begin( ); jIt != iIt->second.end( ); ++jIt )
{
out_stream
- << "extern \"C\" cpPlugins::ProcessObject::Pointer "
+ << "extern \"C\" __declspec(dllexport) void* "
<< iIt->first << "_" << jIt->first
<< "( )" << std::endl << "{" << std::endl
- << std::endl
- << " cpPlugins::ProcessObject::Pointer p;" << std::endl
- << " " << jIt->second << "::" << jIt->first << "::Pointer f = "
- << jIt->second << "::" << jIt->first << "::New( );" << std::endl
- << " p = f.GetPointer( );" << std::endl << " return( p );"
+ << " static " << jIt->second << "::" << jIt->first << "::Pointer f;" << std::endl
+ << " f = " << jIt->second << "::" << jIt->first << "::New( );" << std::endl
+ << " return( &f );"
<< std::endl;
out_stream
<< "}" << std::endl << std::endl;
catch( std::exception& err )
{
std::cerr
- << "Error caught:"
+ << "Error caught: "
<< err.what( )
<< std::endl;
return( 1 );
SET(
target_LIBRARIES
+ cpPlugins_tinyxml2
cpPlugins_ITKInstances_Base
cpPlugins_ITKInstances_Image
cpPlugins_ITKInstances_ImageIterators
SET(
target_LIBRARIES
${target_LIBRARIES}
- cpPlugins_tinyxml2
dl
)
ENDIF(NOT WIN32)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
-# ifndef NOMINMAX
-# define NOMINMAX
-# endif
+# define NOMINMAX
+# include <windows.h>
+# include <tchar.h>
#elif defined( linux ) || defined( __linux )
# define cpPlugins_SYS_LINUX
# define cpPlugins_PLUGIN_PREFIX "lib"
for( ; dIt != this->m_DynLibraries.end( ); ++dIt )
out << dIt->first << std::endl;
out.close( );
+ return( true );
}
// -------------------------------------------------------------------------
if( new_filter )
{
// Update filters container
- TCreator creator = Self::_DLGetCreator( hnd, catIt->first, *clsIt );
+ auto creator = Self::_DLGetCreator( hnd, catIt->first, *clsIt );
if( creator != NULL )
{
this->m_DynFilters[ catIt->first][ *clsIt ] =
cpPlugins::ProcessObject::Pointer cpPlugins::Interface::
Create( const std::string& category, const std::string& name )
{
- cpPlugins::ProcessObject::Pointer filter = NULL;
+ typedef cpPlugins::ProcessObject::Pointer _TPointer;
+ _TPointer filter = NULL;
auto catIt = this->m_DynFilters.find( category );
if( catIt != this->m_DynFilters.end( ) )
{
auto clsIt = catIt->second.find( name );
if( clsIt != catIt->second.end( ) )
- filter = clsIt->second.second( );
+ filter =
+ ( reinterpret_cast< _TPointer* >( clsIt->second.second( ) ) )->
+ GetPointer( );
} // fi
return( filter );
TFilters cpPlugins::Interface::
_DLGetFilters( void* hnd )
{
- typedef const TFilters ( *f_t )( );
-
- TFilters filters;
+ // Get descriptors
+ typedef const char* ( *f_t )( );
+ f_t f = NULL;
#ifdef cpPlugins_SYS_WINDOWS
- auto f = ( f_t )(
- ::GetProcAddress( ( HMODULE )hnd, "cpPlugins_LoadedFilters" )
- );
- std::cout << f << std::endl;
+ f = ( f_t )( ::GetProcAddress( ( HMODULE )hnd, "cpPlugins_LoadedFilters" ) );
#else // cpPlugins_SYS_WINDOWS
- auto f = ( f_t ) dlsym( hnd, "cpPlugins_LoadedFilters" );
- const char* err = dlerror( );
- if( err != NULL )
+ f = ( f_t )( dlsym( hnd, "cpPlugins_LoadedFilters" ) );
+#endif // cpPlugins_SYS_WINDOWS
+ if( f == NULL )
{
- dlclose( hnd );
+ Self::_DLClose( hnd );
throw std::runtime_error(
- std::string(
- "cpPlugins::Interface: Library not recognized as a cpPlugins library: "
- ) + std::string( err )
+ "cpPlugins::Interface: Library not recognized as a cpPlugins library: "
);
} // fi
-#endif // cpPlugins_SYS_WINDOWS
- filters = f( );
+ std::string descriptors = f( );
+
+ // Demangle descriptors
+ TFilters filters;
+ std::replace( descriptors.begin( ), descriptors.end( ), ';', ' ' );
+ std::istringstream str( descriptors );
+ while( str )
+ {
+ std::string value, category, name;
+ str >> value;
+ if( value == "" )
+ continue;
+ std::replace( value.begin( ), value.end( ), ':', ' ' );
+ std::istringstream value_str( value );
+ value_str >> category >> name;
+ filters[ category ].insert( name );
+
+ } // elihw
return( filters );
}
TCreator c = NULL;
std::string func_name = category + "_" + name;
#ifdef cpPlugins_SYS_WINDOWS
- // TODO:
+ c = ( TCreator )( ::GetProcAddress( ( HMODULE )hnd, func_name.c_str( ) ) );
#else // cpPlugins_SYS_WINDOWS
- c = ( TCreator )dlsym( hnd, func_name.c_str( ) );
+ c = ( TCreator )( dlsym( hnd, func_name.c_str( ) ) );
+#endif // cpPlugins_SYS_WINDOWS
if( c == NULL )
throw std::runtime_error(
std::string( "cpPlugins::Interface: Class \"" ) +
category + std::string( ":" ) + name +
std::string( "\" does not have a valid creator function." )
);
-#endif // cpPlugins_SYS_WINDOWS
return( c );
}
public:
typedef Interface Self;
- typedef cpPlugins::ProcessObject::Pointer ( *TCreator )( );
+ typedef void* ( *TCreator )( );
typedef std::pair< std::string, TCreator > TDynFunc;
typedef std::map< std::string, TDynFunc > TDynFilter;
typedef std::map< std::string, TDynFilter > TDynFilters;
c itk::ImageScanlineIterator< itk::Image< std::complex< #3 > , #2 > >
c itk::ImageScanlineIterator< itk::Image< itk::RGBPixel< #1 > , #2 > >
c itk::ImageScanlineIterator< itk::Image< itk::RGBAPixel< #1 > , #2 > >
+c #4 < itk::Image< #1 , #2 >, itk::Image< #1 , #2 > >
c itk::ConstNeighborhoodIterator< itk::Image< #1 , #2 >, #4 < itk::Image< #1 , #2 >, itk::Image< #1 , #2 > > >
c itk::NeighborhoodIterator< itk::Image< #1 , #2 >, #4 < itk::Image< #1 , #2 >, itk::Image< #1 , #2 > > >
c itk::ConstShapedNeighborhoodIterator< itk::Image< #1 , #2 >, #4 < itk::Image< #1 , #2 >, itk::Image< #1 , #2 > > >
c itk::Neighborhood< #5 , #2 , itk::NeighborhoodAllocator< #5 > >
c itk::Statistics::Histogram< #1 >
c itk::HistogramAlgorithmBase< itk::Statistics::Histogram< #1 > >
+c itk::ImageRegion< #2 >
c itk::Image< #1 , #2 >
c itk::Image< std::complex< #4 > , #2 >
c itk::Image< itk::RGBPixel< #1 > , #2 >
SET(lib_NAME cpPlugins_tinyxml2)\r
+SET(lib_DIR third_party/tinyxml)\r
\r
IF(MSVC)\r
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)\r
VERSION "${prj_VER}"\r
SOVERSION "${prj_sVER}"\r
)\r
-\r
+GENERATE_EXPORT_HEADER(\r
+ ${lib_NAME}\r
+ BASE_NAME ${lib_NAME}\r
+ EXPORT_MACRO_NAME ${lib_NAME}_EXPORT\r
+ EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/${lib_DIR}/${lib_NAME}_Export.h\r
+ STATIC_DEFINE ${lib_NAME}_BUILT_AS_STATIC\r
+ )\r
INSTALL(\r
TARGETS ${lib_NAME}\r
RUNTIME DESTINATION bin\r
static const int TIXML2_MINOR_VERSION = 0;\r
static const int TIXML2_PATCH_VERSION = 0;\r
\r
+#include <tinyxml/cpPlugins_tinyxml2_Export.h>\r
+#undef TINYXML2_LIB\r
+#define TINYXML2_LIB cpPlugins_tinyxml2_EXPORT\r
+\r
namespace tinyxml2\r
{\r
class XMLDocument;\r
typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage;
typedef itk::BinaryThresholdImageFilter< _TImage, _TBinaryImage > _F;
typedef typename _TImage::PixelType _TP;
- typedef typename _TBinaryImage::PixelType _UP;
// Get parameters
_TP lower_val = _TP( this->m_Parameters.GetReal( "LowerThresholdValue" ) );
_TP upper_val = _TP( this->m_Parameters.GetReal( "UpperThresholdValue" ) );
- _UP in_val = _UP( this->m_Parameters.GetReal( "InsideValue" ) );
- _UP out_val = _UP( this->m_Parameters.GetReal( "OutsideValue" ) );
+ _TBinaryPixel in_val = _TBinaryPixel( this->m_Parameters.GetReal( "InsideValue" ) );
+ _TBinaryPixel out_val = _TBinaryPixel( this->m_Parameters.GetReal( "OutsideValue" ) );
// Configure filter
_F* filter = this->_CreateITK< _F >( );
{
typedef itk::HistogramThresholdImageFilter< _TImage, _TBinaryImage > _F;
typedef typename _TImage::PixelType _TP;
- typedef typename _TBinaryImage::PixelType _UP;
// Get parameters
_GD0( _TImage* image )
{
if( image != NULL )
- return(
- this->_GD1< _TImage, itk::Image< unsigned char, _TImage::ImageDimension > >( image )
- );
+ return( this->_GD1< _TImage, unsigned char >( image ) );
else
return( "ImageFilters::OtsuThresholdImageFilter: No valid input image." );
}
// -------------------------------------------------------------------------
-template< class _TImage, class _TBinaryImage >
+template< class _TImage, class _TBinaryPixel >
std::string cpPluginsImageFilters::OtsuThresholdImageFilter::
_GD1( _TImage* image )
{
- typedef itk::OtsuThresholdImageFilter< _TImage, _TBinaryImage > _F;
- typedef typename _TBinaryImage::PixelType _UP;
+ typedef itk::Image< _TBinaryPixel, _TImage::ImageDimension > _TBinaryImage;
+ typedef itk::OtsuThresholdImageFilter< _TImage, _TBinaryImage > _TFilter;
// Get parameters
unsigned int bins = this->m_Parameters.GetUint( "NumberOfHistogramBins" );
- _UP in_val = _UP( this->m_Parameters.GetUint( "InsideValue" ) );
- _UP out_val = _UP( this->m_Parameters.GetUint( "OutsideValue" ) );
+ _TBinaryPixel in_val = _TBinaryPixel( this->m_Parameters.GetUint( "InsideValue" ) );
+ _TBinaryPixel out_val = _TBinaryPixel( this->m_Parameters.GetUint( "OutsideValue" ) );
// Configure filter
- _F* filter = this->_CreateITK< _F >( );
+ _TFilter* filter = this->_CreateITK< _TFilter >( );
filter->SetInput( image );
filter->SetNumberOfHistogramBins( bins );
filter->SetInsideValue( out_val ); // WARNING: these are inverted
template< class _TImage >
inline std::string _GD0( _TImage* image );
- template< class _TImage, class _TBinaryImage >
+ template< class _TImage, class _TBinaryPixel >
inline std::string _GD1( _TImage* image );
private: