From: Leonardo Florez Valencia Date: Tue, 15 Mar 2016 21:39:09 +0000 (-0500) Subject: Now it compiles again on Windows. X-Git-Tag: v0.1~226 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=8d7780dd6a0a8f010d705e957e1eae793b7948cc;p=cpPlugins.git Now it compiles again on Windows. --- diff --git a/appli/bash/cpPlugins_HostCreator.cxx b/appli/bash/cpPlugins_HostCreator.cxx index ee11adf..445302f 100644 --- a/appli/bash/cpPlugins_HostCreator.cxx +++ b/appli/bash/cpPlugins_HostCreator.cxx @@ -100,33 +100,34 @@ int main( int argc, char* argv[] ) std::ofstream out_stream( argv[ 1 ] ); // Write include section - out_stream - << "#include " << std::endl - << "#include " << std::endl; for( int i = 2; i < argc; ++i ) out_stream << "#include \"" << argv[ i ] << "\"" < > " + << 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 @@ -135,14 +136,12 @@ int main( int argc, char* argv[] ) 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; diff --git a/appli/examples/example_LoadPluginsFile.cxx b/appli/examples/example_LoadPluginsFile.cxx index ddef170..b9a2817 100644 --- a/appli/examples/example_LoadPluginsFile.cxx +++ b/appli/examples/example_LoadPluginsFile.cxx @@ -19,7 +19,7 @@ int main( int argc, char* argv[] ) catch( std::exception& err ) { std::cerr - << "Error caught:" + << "Error caught: " << err.what( ) << std::endl; return( 1 ); diff --git a/lib/cpPlugins/CMakeLists.txt b/lib/cpPlugins/CMakeLists.txt index 565c9c1..c35c81d 100644 --- a/lib/cpPlugins/CMakeLists.txt +++ b/lib/cpPlugins/CMakeLists.txt @@ -83,6 +83,7 @@ SET( SET( target_LIBRARIES + cpPlugins_tinyxml2 cpPlugins_ITKInstances_Base cpPlugins_ITKInstances_Image cpPlugins_ITKInstances_ImageIterators @@ -93,7 +94,6 @@ IF(NOT WIN32) SET( target_LIBRARIES ${target_LIBRARIES} - cpPlugins_tinyxml2 dl ) ENDIF(NOT WIN32) diff --git a/lib/cpPlugins/Config.h.in b/lib/cpPlugins/Config.h.in index 75ae331..54f0af4 100644 --- a/lib/cpPlugins/Config.h.in +++ b/lib/cpPlugins/Config.h.in @@ -43,9 +43,9 @@ # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifndef NOMINMAX -# define NOMINMAX -# endif +# define NOMINMAX +# include +# include #elif defined( linux ) || defined( __linux ) # define cpPlugins_SYS_LINUX # define cpPlugins_PLUGIN_PREFIX "lib" diff --git a/lib/cpPlugins/Interface.cxx b/lib/cpPlugins/Interface.cxx index 2592882..611143e 100644 --- a/lib/cpPlugins/Interface.cxx +++ b/lib/cpPlugins/Interface.cxx @@ -64,6 +64,7 @@ SaveConfiguration( const std::string& filename ) const for( ; dIt != this->m_DynLibraries.end( ); ++dIt ) out << dIt->first << std::endl; out.close( ); + return( true ); } // ------------------------------------------------------------------------- @@ -104,7 +105,7 @@ LoadPluginFile( const std::string& filename ) 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 ] = @@ -146,13 +147,16 @@ UnloadAll( ) 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 ); @@ -177,29 +181,40 @@ cpPlugins::Interface:: 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 ); } @@ -213,16 +228,16 @@ _DLGetCreator( 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 ); } diff --git a/lib/cpPlugins/Interface.h b/lib/cpPlugins/Interface.h index 5dcd843..e2f5b0c 100644 --- a/lib/cpPlugins/Interface.h +++ b/lib/cpPlugins/Interface.h @@ -16,7 +16,7 @@ namespace cpPlugins 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; diff --git a/lib/cpPlugins_ITKInstances/ImageIterators_explicit_description.txt b/lib/cpPlugins_ITKInstances/ImageIterators_explicit_description.txt index 68e90fd..7221e67 100644 --- a/lib/cpPlugins_ITKInstances/ImageIterators_explicit_description.txt +++ b/lib/cpPlugins_ITKInstances/ImageIterators_explicit_description.txt @@ -43,6 +43,7 @@ c itk::ImageScanlineIterator< itk::Image< #1 , #2 > > 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 > > > diff --git a/lib/cpPlugins_ITKInstances/Image_explicit_description.txt b/lib/cpPlugins_ITKInstances/Image_explicit_description.txt index dcad0a2..210e7bb 100644 --- a/lib/cpPlugins_ITKInstances/Image_explicit_description.txt +++ b/lib/cpPlugins_ITKInstances/Image_explicit_description.txt @@ -9,6 +9,7 @@ c itk::Neighborhood< #1 , #2 , itk::NeighborhoodAllocator< #1 > > 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 > diff --git a/lib/third_party/tinyxml/CMakeLists.txt b/lib/third_party/tinyxml/CMakeLists.txt index a66769f..6579b71 100644 --- a/lib/third_party/tinyxml/CMakeLists.txt +++ b/lib/third_party/tinyxml/CMakeLists.txt @@ -1,4 +1,5 @@ SET(lib_NAME cpPlugins_tinyxml2) +SET(lib_DIR third_party/tinyxml) IF(MSVC) ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) @@ -10,7 +11,13 @@ SET_TARGET_PROPERTIES( VERSION "${prj_VER}" SOVERSION "${prj_sVER}" ) - +GENERATE_EXPORT_HEADER( + ${lib_NAME} + BASE_NAME ${lib_NAME} + EXPORT_MACRO_NAME ${lib_NAME}_EXPORT + EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/lib/${lib_DIR}/${lib_NAME}_Export.h + STATIC_DEFINE ${lib_NAME}_BUILT_AS_STATIC + ) INSTALL( TARGETS ${lib_NAME} RUNTIME DESTINATION bin diff --git a/lib/third_party/tinyxml/tinyxml2.h b/lib/third_party/tinyxml/tinyxml2.h index fb7464a..599669e 100644 --- a/lib/third_party/tinyxml/tinyxml2.h +++ b/lib/third_party/tinyxml/tinyxml2.h @@ -96,6 +96,10 @@ static const int TIXML2_MAJOR_VERSION = 3; static const int TIXML2_MINOR_VERSION = 0; static const int TIXML2_PATCH_VERSION = 0; +#include +#undef TINYXML2_LIB +#define TINYXML2_LIB cpPlugins_tinyxml2_EXPORT + namespace tinyxml2 { class XMLDocument; diff --git a/plugins/cpPluginsImageFilters/BinaryThresholdImageFilter.cxx b/plugins/cpPluginsImageFilters/BinaryThresholdImageFilter.cxx index 6545d56..37342a5 100644 --- a/plugins/cpPluginsImageFilters/BinaryThresholdImageFilter.cxx +++ b/plugins/cpPluginsImageFilters/BinaryThresholdImageFilter.cxx @@ -101,13 +101,12 @@ _GD1( _TImage* image ) 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 >( ); diff --git a/plugins/cpPluginsImageFilters/HistogramThresholdImageFilter.cxx b/plugins/cpPluginsImageFilters/HistogramThresholdImageFilter.cxx index f3addf4..6d6608b 100644 --- a/plugins/cpPluginsImageFilters/HistogramThresholdImageFilter.cxx +++ b/plugins/cpPluginsImageFilters/HistogramThresholdImageFilter.cxx @@ -69,7 +69,6 @@ _GD1( _TImage* image ) { typedef itk::HistogramThresholdImageFilter< _TImage, _TBinaryImage > _F; typedef typename _TImage::PixelType _TP; - typedef typename _TBinaryImage::PixelType _UP; // Get parameters diff --git a/plugins/cpPluginsImageFilters/OtsuThresholdImageFilter.cxx b/plugins/cpPluginsImageFilters/OtsuThresholdImageFilter.cxx index 177d464..b5dff63 100644 --- a/plugins/cpPluginsImageFilters/OtsuThresholdImageFilter.cxx +++ b/plugins/cpPluginsImageFilters/OtsuThresholdImageFilter.cxx @@ -54,28 +54,26 @@ std::string cpPluginsImageFilters::OtsuThresholdImageFilter:: _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 diff --git a/plugins/cpPluginsImageFilters/OtsuThresholdImageFilter.h b/plugins/cpPluginsImageFilters/OtsuThresholdImageFilter.h index a583ad5..1eecbf3 100644 --- a/plugins/cpPluginsImageFilters/OtsuThresholdImageFilter.h +++ b/plugins/cpPluginsImageFilters/OtsuThresholdImageFilter.h @@ -31,7 +31,7 @@ namespace cpPluginsImageFilters 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: