]> Creatis software - cpPlugins.git/commitdiff
Bug smashed like a boss
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 7 Jun 2016 00:05:05 +0000 (19:05 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 7 Jun 2016 00:05:05 +0000 (19:05 -0500)
28 files changed:
CMakeLists.txt
appli/examples/plugins/CMakeLists.txt
appli/examples/plugins/QT/example_ActorProperties/CMakeLists.txt [new file with mode: 0644]
appli/examples/plugins/QT/example_ActorProperties/example_ActorProperties.cxx [new file with mode: 0644]
appli/examples/plugins/QT/example_ActorProperties/example_ActorProperties.h [new file with mode: 0644]
appli/examples/plugins/QT/example_ActorProperties/example_ActorProperties.ui [new file with mode: 0644]
appli/examples/plugins/QT/example_ActorProperties/main.cxx [new file with mode: 0644]
appli/examples/plugins/example_LoadPlugins.cxx
appli/examples/plugins/example_LoadPluginsDirectory.cxx
appli/examples/plugins/example_LoadPluginsFile.cxx
appli/examples/plugins/example_ShowSphere.cxx [new file with mode: 0644]
lib/cpPlugins/CMakeLists.txt
lib/cpPlugins/Interface.cxx
lib/cpPlugins/Interface.h
lib/cpPlugins/cpPlugins_DynLibs.h.in [new file with mode: 0644]
lib/cpPlugins_Instances/CMakeLists.txt
plugins/CMakeLists.txt
plugins/cpPluginsGenericFilters/CMakeLists.txt
plugins/cpPluginsIO/CMakeLists.txt
plugins/cpPluginsImageFilters/CMakeLists.txt
plugins/cpPluginsImageMeshFilters/CMakeLists.txt
plugins/cpPluginsMeshFilters/CMakeLists.txt
plugins/cpPluginsMeshSources/CMakeLists.txt [new file with mode: 0644]
plugins/cpPluginsMeshSources/CylinderSource.cxx [new file with mode: 0644]
plugins/cpPluginsMeshSources/CylinderSource.h [new file with mode: 0644]
plugins/cpPluginsMeshSources/SphereSource.cxx [new file with mode: 0644]
plugins/cpPluginsMeshSources/SphereSource.h [new file with mode: 0644]
plugins/cpPluginsWidgets/CMakeLists.txt

index 89eb42a73d848eff1b6ac046547269a04ba41447..93b62fd5d75099dc56840625f40a6a25c1c00e0a 100644 (file)
@@ -27,6 +27,20 @@ INCLUDE(cmake/cpPlugins_Options.cmake)
 INCLUDE(cmake/cpPlugins_KitwareTools.cmake)
 INCLUDE(cmake/cpPlugins_Qt4Tools.cmake)
 
+## ===================================
+## == Libraries to dynamically load ==
+## ===================================
+
+SET(cpPlugins_DynLibs)
+FOREACH(i ${VTK_LIBRARIES})
+  GET_TARGET_PROPERTY(lib_${i} ${i} LOCATION)
+  LIST(APPEND cpPlugins_DynLibs ${lib_${i}})
+ENDFOREACH(i)
+FOREACH(i ${ITK_LIBRARIES})
+  GET_TARGET_PROPERTY(lib_${i} ${i} LOCATION)
+  LIST(APPEND cpPlugins_DynLibs ${lib_${i}})
+ENDFOREACH(i)
+
 ## =========================
 ## == Include directories ==
 ## =========================
index 0712ef1061e81baeedaf498ae615649756f1689c..12c8cd362dd7d85a4225352b1df1fbdf50dc13aa 100644 (file)
@@ -7,11 +7,12 @@ SET(
   example_ReadWriteImage
   example_ReadWriteImageWithWorkspace
   example_ShowImage
+  example_ShowSphere
   )
 
 FOREACH(example ${examples_SOURCES})
   ADD_EXECUTABLE(${example} ${example}.cxx)
-  TARGET_LINK_LIBRARIES(${example} cpExtensions cpPlugins)
+  TARGET_LINK_LIBRARIES(${example} cpPlugins)
 ENDFOREACH(example)
 
 IF(USE_QT4)
diff --git a/appli/examples/plugins/QT/example_ActorProperties/CMakeLists.txt b/appli/examples/plugins/QT/example_ActorProperties/CMakeLists.txt
new file mode 100644 (file)
index 0000000..63b05a0
--- /dev/null
@@ -0,0 +1,58 @@
+SET(app_NAME "example_ActorProperties")
+
+INCLUDE_DIRECTORIES(
+  ${CMAKE_CURRENT_SOURCE_DIR}
+  ${CMAKE_CURRENT_BINARY_DIR}
+  )
+
+## ====================================================
+## = Source code, user interafaces and resources here =
+## ====================================================
+
+SET(
+  app_SOURCES
+  ${CMAKE_CURRENT_SOURCE_DIR}/example_ActorProperties.cxx
+  ${CMAKE_CURRENT_SOURCE_DIR}/main.cxx
+  )
+
+SET(
+  app_HEADERS
+  ${CMAKE_CURRENT_SOURCE_DIR}/example_ActorProperties.h
+  )
+
+SET(
+  app_UI
+  ${CMAKE_CURRENT_SOURCE_DIR}/example_ActorProperties.ui
+  )
+
+## =====================
+## = Compilation rules =
+## =====================
+
+QT4_WRAP_UI(app_UI_HEADERS ${app_UI})
+QT4_WRAP_CPP(app_MOC_SOURCES ${app_HEADERS})
+
+SET(GUI_TYPE "")
+IF(WIN32)
+  SET(GUI_TYPE WIN32)
+ENDIF(WIN32)
+IF(APPLE)
+  SET(GUI_TYPE MACOSX_BUNDLE)
+ENDIF(APPLE)
+
+ADD_EXECUTABLE(
+  ${app_NAME}
+  ${GUI_TYPE}
+  ${app_HEADERS}
+  ${app_UI_HEADERS}
+  ${app_SOURCES}
+  ${app_MOC_SOURCES}
+  )
+
+TARGET_LINK_LIBRARIES(
+  ${app_NAME}
+  cpExtensions
+  cpPlugins
+  )
+
+## eof - $RCSfile$
diff --git a/appli/examples/plugins/QT/example_ActorProperties/example_ActorProperties.cxx b/appli/examples/plugins/QT/example_ActorProperties/example_ActorProperties.cxx
new file mode 100644 (file)
index 0000000..159b506
--- /dev/null
@@ -0,0 +1,104 @@
+#include "example_ActorProperties.h"
+#include "ui_example_ActorProperties.h"
+
+#include <vtkActor.h>
+#include <vtkSphereSource.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkRenderWindow.h>
+#include <vtkGenericOpenGLRenderWindow.h>
+#include <QMessageBox>
+
+// -------------------------------------------------------------------------
+example_ActorProperties::
+example_ActorProperties( int argc, char* argv[], QWidget* parent )
+  : Superclass( parent ),
+    m_UI( new Ui::example_ActorProperties )
+{
+  this->m_UI->setupUi( this );
+  this->m_Interface.GuessAccesiblePlugins( );
+
+  this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( );
+  this->m_UI->Viewer->GetRenderWindow( )->AddRenderer( this->m_Renderer );
+
+
+  vtkSmartPointer< vtkSphereSource > sphere =
+    vtkSmartPointer< vtkSphereSource >::New( );
+  vtkSmartPointer< vtkPolyDataMapper > mapper =
+    vtkSmartPointer< vtkPolyDataMapper >::New( );
+  mapper->SetInputConnection( sphere->GetOutputPort( ) );
+  vtkSmartPointer< vtkActor > actor =
+    vtkSmartPointer< vtkActor >::New( );
+  actor->SetMapper( mapper );
+
+  this->m_Renderer->AddActor( actor );
+
+  //this->m_Renderer->ResetCamera( );
+  //this->m_Renderer->Render( );
+  // this->m_UI->Viewer->GetRenderWindow( )->Render( );
+
+  // Create reader
+  /*
+    try
+    {
+  */
+  /* TODO
+     auto cylinder = this->m_Interface.Create( "MeshSources", "CylinderSource" );
+     cylinder->Update( );
+  */
+
+  /* TODO
+     this->m_Reader = this->m_Interface.Create( "IO", "ImageReader" );
+     if( this->m_Reader.IsNull( ) )
+     {
+     QMessageBox::critical(
+     this,
+     QMessageBox::tr( "Error" ),
+     QMessageBox::tr( "\"IO::ImageReader\" creation failed." )
+     );
+     std::exit( 1 );
+
+     } // fi
+
+       // Configure filters
+       auto reader_params = this->m_Reader->GetParameters( );
+       for( int i = 1; i < argc; ++i )
+       reader_params->AddToOpenFileNameList( "FileNames", argv[ i ] );
+       this->m_Reader->Update( );
+  */
+  /*
+    }
+    catch( itk::ExceptionObject& err1 )
+    {
+    QMessageBox::critical(
+    this,
+    QMessageBox::tr( "Error" ),
+    QMessageBox::tr( err1.GetDescription( ) )
+    );
+    std::exit( 1 );
+    }
+    catch( std::exception& err2 )
+    {
+    QMessageBox::critical(
+    this,
+    QMessageBox::tr( "Error" ),
+    QMessageBox::tr( err2.what( ) )
+    );
+    std::exit( 1 );
+
+    } // yrt
+  */
+  /* TODO
+     this->m_UI->Viewer->SetMainImage(
+     this->m_Reader->GetOutputData< vtkImageData >( "Output" ),
+     "MainImage"
+     );
+  */
+}
+
+// -------------------------------------------------------------------------
+example_ActorProperties::
+~example_ActorProperties( )
+{
+}
+
+// eof - $RCSfile$
diff --git a/appli/examples/plugins/QT/example_ActorProperties/example_ActorProperties.h b/appli/examples/plugins/QT/example_ActorProperties/example_ActorProperties.h
new file mode 100644 (file)
index 0000000..4f8b5b9
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef __EXAMPLE_ACTORPROPERTIES__H__
+#define __EXAMPLE_ACTORPROPERTIES__H__
+
+#include <QMainWindow>
+#include <cpPlugins/Interface.h>
+#include <vtkRenderer.h> 
+#include <vtkSmartPointer.h> 
+
+// -------------------------------------------------------------------------
+namespace Ui
+{
+  class example_ActorProperties;
+}
+
+// -------------------------------------------------------------------------
+/**
+ */
+class example_ActorProperties
+  : public QMainWindow
+{
+  Q_OBJECT;
+
+public:
+  typedef example_ActorProperties Self;
+  typedef QMainWindow       Superclass;
+
+public:
+  explicit example_ActorProperties(
+    int argc, char* argv[],
+    QWidget* parent = NULL
+    );
+  virtual ~example_ActorProperties( );
+
+private:
+  Ui::example_ActorProperties* m_UI;
+  vtkSmartPointer< vtkRenderer > m_Renderer;
+  cpPlugins::Interface m_Interface;
+};
+
+#endif // __CPEXAMPLE_ACTORPROPERTIES__H__
+
+// eof - $RCSfile$
diff --git a/appli/examples/plugins/QT/example_ActorProperties/example_ActorProperties.ui b/appli/examples/plugins/QT/example_ActorProperties/example_ActorProperties.ui
new file mode 100644 (file)
index 0000000..b5378d1
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>example_ActorProperties</class>
+ <widget class="QMainWindow" name="example_ActorProperties">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="minimumSize">
+   <size>
+    <width>800</width>
+    <height>600</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="MainWidget">
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="0">
+     <widget class="QVTKWidget" name="Viewer" native="true">
+      <property name="minimumSize">
+       <size>
+        <width>0</width>
+        <height>200</height>
+       </size>
+      </property>
+     </widget>
+    </item>
+   </layout>
+  </widget>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>QVTKWidget</class>
+   <extends>QWidget</extends>
+   <header>QVTKWidget.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/appli/examples/plugins/QT/example_ActorProperties/main.cxx b/appli/examples/plugins/QT/example_ActorProperties/main.cxx
new file mode 100644 (file)
index 0000000..5850dd6
--- /dev/null
@@ -0,0 +1,80 @@
+#include "example_ActorProperties.h"
+#include <cstdlib>
+#include <QApplication>
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  QApplication a( argc, argv );
+  example_ActorProperties w( argc, argv );
+  w.show( );
+  return( a.exec( ) );
+}
+
+// -------------------------------------------------------------------------
+#ifdef _WIN32
+
+#include <memory>
+#include <vector>
+#include <windows.h>
+#include <shellapi.h>
+
+/**
+ */
+class Win32CommandLineConverter
+{
+private:
+  std::unique_ptr< char*[ ] > argv_;
+  std::vector< std::unique_ptr< char[ ] > > storage_;
+
+public:
+  Win32CommandLineConverter( )
+    {
+      LPWSTR cmd_line = GetCommandLineW( );
+      int argc;
+      LPWSTR* w_argv = CommandLineToArgvW( cmd_line, &argc );
+      argv_ = std::unique_ptr< char*[ ] >( new char*[ argc ] );
+      storage_.reserve( argc );
+      for( int i = 0; i < argc; ++i )
+      {
+        storage_.push_back( ConvertWArg( w_argv[ i ] ) );
+        argv_[ i ] = storage_.back( ).get( );
+
+      } // rof
+      LocalFree( w_argv );
+    }
+  int argc( ) const
+    {
+      return( static_cast< int >(storage_.size( ) ) );
+    }
+  char** argv( ) const
+    {
+      return( argv_.get( ) );
+    }
+  static std::unique_ptr< char[ ] > ConvertWArg( LPWSTR w_arg )
+    {
+      int size = WideCharToMultiByte(
+        CP_UTF8, 0, w_arg, -1, nullptr, 0, nullptr, nullptr
+        );
+      std::unique_ptr< char[ ] > ret( new char[ size ] );
+      WideCharToMultiByte(
+        CP_UTF8, 0, w_arg, -1, ret.get( ), size, nullptr, nullptr
+        );
+      return( ret );
+    }
+};
+
+int CALLBACK WinMain(
+  HINSTANCE hInstance,
+  HINSTANCE hPrevInstance,
+  LPSTR lpCmdLine,
+  int nCmdShow
+  )
+{
+  Win32CommandLineConverter cmd_line;
+  return( main( cmd_line.argc( ), cmd_line.argv( ) ) );
+}
+
+#endif
+
+// eof - $RCSfile$
index 21c61c043079041819842f64a8d9762c9268c6af..3ed8fdba4ff6e5bf7c5466f8c90c145dba40acd8 100644 (file)
@@ -11,13 +11,16 @@ int main( int argc, char* argv[] )
   } // fi
 
   // Load interface
-  cpPlugins::Interface interface;
+  cpPlugins::Interface* interface = NULL;
   try
   {
-    interface.LoadPlugin( argv[ 1 ] );
+    interface = new cpPlugins::Interface( );
+    interface->LoadPlugin( argv[ 1 ] );
   }
   catch( std::exception& err )
   {
+    if( interface != NULL )
+      delete interface;
     std::cerr
       << "Error caught: "
       << err.what( )
@@ -27,13 +30,13 @@ int main( int argc, char* argv[] )
   } // yrt
 
   // Show loaded plugins
-  auto plugins = interface.GetPlugins( );
+  auto plugins = interface->GetPlugins( );
   for( auto pIt = plugins.begin( ); pIt != plugins.end( ); ++pIt )
     std::cout << "Plugin: " << *pIt << std::endl;
   std::cout << std::endl;
 
   // Show loaded filters
-  auto filters = interface.GetFilters( );
+  auto filters = interface->GetFilters( );
   for( auto cIt = filters.begin( ); cIt != filters.end( ); ++cIt )
   {
     std::cout << "Category: " << cIt->first << std::endl;
@@ -43,6 +46,9 @@ int main( int argc, char* argv[] )
         << std::endl;
 
   } // rof
+
+  // Free all and finish
+  delete interface;
   return( 0 );
 }
 
index 803d3909b89c2ad7b66a6a8a55c734e0ca7f6b4a..99f4b62a4c553eaf0a533eca4c3567042acc3018 100644 (file)
@@ -5,32 +5,39 @@ int main( int argc, char* argv[] )
 {
   if( argc < 2 )
   {
-    std::cerr << "Usage: " << argv[ 0 ] << " plugins_libraries_dir" << std::endl;
+    std::cerr
+      << "Usage: " << argv[ 0 ] << " plugins_libraries_dir" << std::endl;
     return( 1 );
 
   } // fi
 
   // Load interface
-  cpPlugins::Interface interface;
+  cpPlugins::Interface* interface = NULL;
   try
   {
-    interface.LoadPluginDir( argv[ 1 ] );
+    interface = new cpPlugins::Interface( );
+    interface->LoadPluginDir( argv[ 1 ] );
   }
   catch( std::exception& err )
   {
-    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    if( interface != NULL )
+      delete interface;
+    std::cerr
+      << "Error caught: "
+      << err.what( )
+      << std::endl;
     return( 1 );
 
   } // yrt
 
   // Show loaded plugins
-  auto plugins = interface.GetPlugins( );
+  auto plugins = interface->GetPlugins( );
   for( auto pIt = plugins.begin( ); pIt != plugins.end( ); ++pIt )
     std::cout << "Plugin: " << *pIt << std::endl;
   std::cout << std::endl;
 
   // Show loaded filters
-  auto filters = interface.GetFilters( );
+  auto filters = interface->GetFilters( );
   for( auto cIt = filters.begin( ); cIt != filters.end( ); ++cIt )
   {
     std::cout << "Category: " << cIt->first << std::endl;
@@ -40,6 +47,9 @@ int main( int argc, char* argv[] )
         << std::endl;
 
   } // rof
+
+  // Free all and finish
+  delete interface;
   return( 0 );
 }
 
index 929a48cf0cd6b21acda4dec63e15259231c5bdaa..52af772a7dc20436eea02295454ae857a35d0e4f 100644 (file)
@@ -11,13 +11,16 @@ int main( int argc, char* argv[] )
   } // fi
 
   // Load interface
-  cpPlugins::Interface interface;
+  cpPlugins::Interface* interface = NULL;
   try
   {
-    interface.LoadPluginFile( argv[ 1 ] );
+    interface = new cpPlugins::Interface( );
+    interface->LoadPluginFile( argv[ 1 ] );
   }
   catch( std::exception& err )
   {
+    if( interface != NULL )
+      delete interface;
     std::cerr
       << "Error caught: "
       << err.what( )
@@ -27,13 +30,13 @@ int main( int argc, char* argv[] )
   } // yrt
 
   // Show loaded plugins
-  auto plugins = interface.GetPlugins( );
+  auto plugins = interface->GetPlugins( );
   for( auto pIt = plugins.begin( ); pIt != plugins.end( ); ++pIt )
     std::cout << "Plugin: " << *pIt << std::endl;
   std::cout << std::endl;
 
   // Show loaded filters
-  auto filters = interface.GetFilters( );
+  auto filters = interface->GetFilters( );
   for( auto cIt = filters.begin( ); cIt != filters.end( ); ++cIt )
   {
     std::cout << "Category: " << cIt->first << std::endl;
@@ -43,6 +46,9 @@ int main( int argc, char* argv[] )
         << std::endl;
 
   } // rof
+
+  // Free all and finish
+  delete interface;
   return( 0 );
 }
 
diff --git a/appli/examples/plugins/example_ShowSphere.cxx b/appli/examples/plugins/example_ShowSphere.cxx
new file mode 100644 (file)
index 0000000..9c64f8d
--- /dev/null
@@ -0,0 +1,84 @@
+#include <iostream>
+#include <cpPlugins/Interface.h>
+
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkSmartPointer.h>
+
+int main( int argc, char* argv[] )
+{
+  // Load interface
+  cpPlugins::Interface* interface = NULL;
+  try
+  {
+    interface = new cpPlugins::Interface( );
+    interface->GuessAccesiblePlugins( );
+  }
+  catch( std::exception& err )
+  {
+    if( interface != NULL )
+      delete interface;
+    std::cerr
+      << "Error caught: "
+      << err.what( )
+      << std::endl;
+    return( 1 );
+
+  } // yrt
+
+  // Create filters
+  cpPlugins::ProcessObject::Pointer sphere;
+  int ret = 0;
+  try
+  {
+    sphere = interface->Create( "MeshSources", "SphereSource" );
+    if( sphere.IsNull( ) )
+    {
+      std::cerr
+        << "\"MeshSources::SphereSource\" creation failed."
+        << std::endl;
+      ret = 1;
+
+    } // fi
+  }
+  catch( std::exception& err )
+  {
+    std::cerr
+      << "Filter creation failed: "
+      << err.what( )
+      << std::endl;
+    ret = 1;
+
+  } // yrt
+  sphere->GetParameters( )->SetReal( "Radius", 5 );
+  sphere->GetParameters( )->SetUint( "ThetaResolution", 100 );
+  sphere->GetParameters( )->SetUint( "PhiResolution", 100 );
+  sphere->Update( );
+
+  // Prepare scene
+  vtkSmartPointer< vtkRenderer > ren =
+    vtkSmartPointer< vtkRenderer >::New( );
+  ren->SetBackground( 0, 0, 0 );
+  ren->AddActor( sphere->GetOutput( "Output" )->GetVTKActor( ) );
+
+  vtkSmartPointer< vtkRenderWindow > win =
+    vtkSmartPointer< vtkRenderWindow >::New( );
+  win->AddRenderer( ren );
+  win->SetSize( 500, 500 );
+
+  vtkSmartPointer< vtkRenderWindowInteractor > iren =
+    vtkSmartPointer< vtkRenderWindowInteractor >::New( );
+  iren->SetRenderWindow( win );
+
+  iren->Initialize( );
+  ren->Render( );
+  ren->ResetCamera( );
+  iren->Start( );
+
+  // Ok finish
+  delete interface;
+  return( ret );
+}
+
+// eof - $RCSfile$
index 7817df1e7a9fcf49673be79da35b725cb51de73b..2e09b0f23981da554ba93cdda521a40a0fa6b9aa 100644 (file)
@@ -14,6 +14,11 @@ CONFIGURE_FILE(
   ${PROJECT_BINARY_DIR}/lib/${lib_DIR}/Config.h
   @ONLY
   )
+CONFIGURE_FILE(
+  cpPlugins_DynLibs.h.in
+  ${PROJECT_BINARY_DIR}/lib/${lib_DIR}/cpPlugins_DynLibs.h
+  @ONLY
+  )
 
 ## ===============
 ## = Source code =
@@ -85,8 +90,11 @@ SET(
 
 SET(
   target_LIBRARIES
-  ${cpPlugins_LIBRARIES}
+  ${ITK_LIBRARIES}
+  ${VTK_LIBRARIES}
+  cpExtensions
   cpPlugins_tinyxml2
+  ${cpPlugins_LIBRARIES}
   )
 IF(NOT WIN32)
   SET(
index 8b5e106e5791c29d697ab123f414c56359248818..6ffc0fe462ae5b033b3cf64f7fe1ba900b27399f 100644 (file)
@@ -6,13 +6,42 @@
 #  include <dlfcn.h>
 #endif // cpPlugins_SYS_WINDOWS
 #include <cpPlugins_dirent.h>
+#include <cpPlugins/cpPlugins_DynLibs.h>
 #include <algorithm>
 
+// -------------------------------------------------------------------------
+unsigned int cpPlugins::Interface::InterfacesCount = 0;
+
 // -------------------------------------------------------------------------
 cpPlugins::Interface::
 Interface( )
 {
   this->UpdatePaths( );
+
+  // Explicitly load all ITK and VTK
+  if( Self::InterfacesCount == 0 )
+  {
+    std::vector< std::string > libs;
+    cpPlugins::TokenizeString( libs, cpPlugins_DynLibs, ";" );
+    this->_AddInstancesLib( libs, cpPlugins_CompilationDir );
+    this->_AddInstancesLib( libs, cpPlugins_InstallationDir );
+
+    for( auto l = libs.begin( ); l != libs.end( ); ++l )
+    {
+      std::string error = "";
+      void* hnd = Self::_DLOpen( *l, error );
+      if( hnd == NULL || error != "" )
+        throw std::runtime_error(
+          std::string( "cpPlugins::Interface: Could not load library \"" ) +
+          *l +
+          std::string( "\": " ) +
+          error
+          );
+
+    } // rof
+
+  } // fi
+  Self::InterfacesCount++;
 }
 
 // -------------------------------------------------------------------------
@@ -20,6 +49,12 @@ cpPlugins::Interface::
 ~Interface( )
 {
   this->UnloadAll( );
+  Self::InterfacesCount--;
+  if( Self::InterfacesCount == 0 )
+  {
+    // TODO: unload vtk and itk
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
@@ -126,12 +161,14 @@ LoadPluginFile( const std::string& filename )
       );
 
   // Try to load the library
-  void* hnd = Self::_DLOpen( canonical );
-  if( hnd == NULL )
+  std::string error;
+  void* hnd = Self::_DLOpen( canonical, error );
+  if( hnd == NULL || error != "" )
     throw std::runtime_error(
       std::string( "cpPlugins::Interface: Could not load library \"" ) +
       filename +
-      std::string( "\"" )
+      std::string( "\": " ) +
+      error
       );
 
   // Get plugin name
@@ -264,16 +301,40 @@ GetPlugins( ) const
   return( res );
 }
 
+// -------------------------------------------------------------------------
+template< class _TList >
+void cpPlugins::Interface::
+_AddInstancesLib( _TList& libs, const std::string& path )
+{
+  DIR* dir;
+  struct dirent* ent;
+  if( ( dir = opendir( path.c_str( ) ) ) != NULL )
+  {
+    while( ( ent = readdir( dir ) ) != NULL )
+    {
+      std::string fname = path + std::string( "/" ) + ent->d_name;
+      if( fname.find( "cpPlugins_Instances_" ) != std::string::npos )
+        libs.push_back( fname );
+
+    } // elihw
+    closedir( dir );
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 void* cpPlugins::Interface::
-_DLOpen( const std::string& fname )
+_DLOpen( const std::string& fname, std::string& error )
 {
   void* hnd = NULL;
 #ifdef cpPlugins_SYS_WINDOWS
   hnd = ::LoadLibraryA( fname.c_str( ) );
 #else // cpPlugins_SYS_WINDOWS
   hnd = dlopen( fname.c_str( ), RTLD_NOW | RTLD_GLOBAL );
-  dlerror( );
+  if( hnd == NULL )
+    error = dlerror( );
+  else
+    dlerror( );
 #endif // cpPlugins_SYS_WINDOWS
   return( hnd );
 }
index 0a31e63eb6e810ab408063e76398054628fe2c0f..4c7d5e65e56142a172d24daa64500542412568e6 100644 (file)
@@ -47,7 +47,9 @@ namespace cpPlugins
     std::set< std::string > GetPlugins( ) const;
 
   protected:
-    static void* _DLOpen( const std::string& fname );
+    template< class _TList >
+      inline void _AddInstancesLib( _TList& libs, const std::string& path );
+    static void* _DLOpen( const std::string& fname, std::string& error );
     static const char* _DLGetName( void* hnd );
     static TFilters _DLGetFilters( void* hnd );
     static TCreator _DLGetCreator(
@@ -60,6 +62,8 @@ namespace cpPlugins
     TDynLibraries m_DynLibraries;
     TDynFilters   m_DynFilters;
     TFilters      m_Filters;
+
+    static unsigned int InterfacesCount;
   };
 
 } // ecapseman
diff --git a/lib/cpPlugins/cpPlugins_DynLibs.h.in b/lib/cpPlugins/cpPlugins_DynLibs.h.in
new file mode 100644 (file)
index 0000000..1014047
--- /dev/null
@@ -0,0 +1,6 @@
+
+#define cpPlugins_CompilationDir "@PROJECT_BINARY_DIR@"
+#define cpPlugins_InstallationDir "@CMAKE_INSTALL_PREFIX@/lib"
+#define cpPlugins_DynLibs "@cpPlugins_DynLibs@"
+
+// eof - $RCSfile$
index 79eef7e0a102aa6c037d052f74339d9e03efc10d..7437b20b44b2475825ec7fbc3a9e6465c89d0788 100644 (file)
@@ -5,18 +5,18 @@
 SET(pfx "cpPlugins_Instances_")
 SET(arg ${pfx} ${prj_VER} ${prj_sVER})
 
-cpPlugins_WrapInstances(BaseObjects ${arg} ${ITK_LIBRARIES})
-cpPlugins_WrapInstances(Decorators ${arg} ${ITK_LIBRARIES})
+cpPlugins_WrapInstances(BaseObjects ${arg}) #${ITK_LIBRARIES})
+cpPlugins_WrapInstances(Decorators ${arg}) #${ITK_LIBRARIES})
 cpPlugins_WrapInstances(Mesh ${arg} ${pfx}BaseObjects)
 cpPlugins_WrapInstances(Transforms ${arg} ${pfx}BaseObjects)
 cpPlugins_WrapInstances(ColorPixels ${arg} ${pfx}BaseObjects)
 cpPlugins_WrapInstances(ScalarImages ${arg} ${pfx}BaseObjects)
 cpPlugins_WrapInstances(ColorImages ${arg} ${pfx}ColorPixels ${pfx}ScalarImages)
 cpPlugins_WrapInstances(VectorImages ${arg} ${pfx}ScalarImages)
-cpPlugins_WrapInstances(Paths ${arg} ${pfx}ScalarImages ${VTK_LIBRARIES})
+cpPlugins_WrapInstances(Paths ${arg} ${pfx}ScalarImages) # ${VTK_LIBRARIES})
 cpPlugins_WrapInstances(NeighborhoodIterators ${arg} ${pfx}ScalarImages)
 cpPlugins_WrapInstances(
-  ImageITK2VTK ${arg} ${pfx}ScalarImages ${pfx}ColorImages ${pfx}VectorImages ${VTK_LIBRARIES}
+  ImageITK2VTK ${arg} ${pfx}ScalarImages ${pfx}ColorImages ${pfx}VectorImages ${VTK_LIBRARIES}
   )
 cpPlugins_WrapInstances(
   ImagesIO ${arg} ${pfx}ScalarImages ${pfx}ColorImages ${pfx}VectorImages ${pfx}Decorators
index a9950954bbd7ffa36be6d2d10275cfbcd99626c2..9d51a6ad35e6a09647ea608e7969ba7dbcb02ed1 100644 (file)
@@ -2,6 +2,7 @@ SUBDIRS(
   cpPluginsGenericFilters
   cpPluginsIO
   cpPluginsImageFilters
+  cpPluginsMeshSources
   cpPluginsMeshFilters
   cpPluginsImageMeshFilters
   cpPluginsWidgets
index 1d759cc23d8d6edceee91c368b68c5f10f75129a..1c6e00901e60418433d8772f95c1340816a7d589 100644 (file)
@@ -10,7 +10,6 @@ cpPlugins_WrapPlugins(
   "${lib_SOURCES}"
   "${lib_OTHER_SOURCES}"
   "${lib_QT4_HEADERS}"
-  cpPlugins ${cpPlugins_LIBRARIES}
   )
 
 ## ========================
index cf0ac1c0f2418da534ec55bcc2974e515fa53237..aa7b3779ebe16bfd3a3a14dd26a576daa7e94061 100644 (file)
@@ -10,7 +10,6 @@ cpPlugins_WrapPlugins(
   "${lib_SOURCES}"
   "${lib_OTHER_SOURCES}"
   "${lib_QT4_HEADERS}"
-  cpPlugins ${cpPlugins_LIBRARIES}
   )
 
 ## ========================
index fa550da30d8f83547f5b20c4b719ddb5c711442b..ed6fdecca65a8822ca4a6f7cf90b1c9a3cfc2841 100644 (file)
@@ -10,7 +10,6 @@ cpPlugins_WrapPlugins(
   "${lib_SOURCES}"
   "${lib_OTHER_SOURCES}"
   "${lib_QT4_HEADERS}"
-  cpPlugins ${cpPlugins_LIBRARIES}
   )
 
 ## ========================
index 9ad287ae87280ac0065e41871aba9ae85995fb8c..01d5725c6913a588eac6f07c2e487842629eeb53 100644 (file)
@@ -10,7 +10,6 @@ cpPlugins_WrapPlugins(
   "${lib_SOURCES}"
   "${lib_OTHER_SOURCES}"
   "${lib_QT4_HEADERS}"
-  cpPlugins ${cpPlugins_LIBRARIES}
   )
 
 ## ========================
index fc68d30c73b1c5b082a0b0c80484f3539efb1845..5eceecdc45fd494ce1007a4eb693a257adf158cd 100644 (file)
@@ -10,7 +10,6 @@ cpPlugins_WrapPlugins(
   "${lib_SOURCES}"
   "${lib_OTHER_SOURCES}"
   "${lib_QT4_HEADERS}"
-  cpPlugins ${cpPlugins_LIBRARIES}
   )
 
 ## ========================
diff --git a/plugins/cpPluginsMeshSources/CMakeLists.txt b/plugins/cpPluginsMeshSources/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9fe09da
--- /dev/null
@@ -0,0 +1,26 @@
+SET(lib_NAME cpPluginsMeshSources)
+FILE(GLOB lib_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+FILE(GLOB lib_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cxx")
+SET(lib_OTHER_SOURCES "")
+SET(lib_QT4_HEADERS "")
+
+cpPlugins_WrapPlugins(
+  ${lib_NAME} ${prj_VER} ${prj_sVER}
+  "${lib_HEADERS}"
+  "${lib_SOURCES}"
+  "${lib_OTHER_SOURCES}"
+  "${lib_QT4_HEADERS}"
+  )
+
+## ========================
+## -- Installation rules --
+## ========================
+
+#INSTALL(
+#  TARGETS ${lib_NAME}
+#  RUNTIME DESTINATION bin
+#  LIBRARY DESTINATION lib
+#  ARCHIVE DESTINATION lib/static
+#  )
+
+## eof - $RCSfile$
diff --git a/plugins/cpPluginsMeshSources/CylinderSource.cxx b/plugins/cpPluginsMeshSources/CylinderSource.cxx
new file mode 100644 (file)
index 0000000..ba233f6
--- /dev/null
@@ -0,0 +1,37 @@
+#include <cpPluginsMeshSources/CylinderSource.h>
+#include <cpPlugins/Mesh.h>
+
+#include <vtkCylinderSource.h>
+
+// -------------------------------------------------------------------------
+cpPluginsMeshSources::CylinderSource::
+CylinderSource( )
+  : Superclass( )
+{
+  this->_AddOutput< cpPlugins::Mesh >( "Output" );
+  this->m_Parameters.ConfigureAsReal( "Height" );
+  this->m_Parameters.ConfigureAsReal( "Radius" );
+  this->m_Parameters.ConfigureAsUint( "Resolution" );
+  this->m_Parameters.SetReal( "Radius", 1 );
+  this->m_Parameters.SetUint( "Resolution", 8 );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsMeshSources::CylinderSource::
+~CylinderSource( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsMeshSources::CylinderSource::
+_GenerateData( )
+{
+  auto src = this->_CreateVTK< vtkCylinderSource >( );
+  src->SetHeight( this->m_Parameters.GetReal( "Height" ) );
+  src->SetRadius( this->m_Parameters.GetReal( "Radius" ) );
+  src->SetResolution( this->m_Parameters.GetUint( "Resolution" ) );
+  src->Update( );
+  this->GetOutput( "Output" )->SetVTK( src->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/cpPluginsMeshSources/CylinderSource.h b/plugins/cpPluginsMeshSources/CylinderSource.h
new file mode 100644 (file)
index 0000000..0e8d0b2
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef __CPPLUGINSMESHSOURCES__CYLINDERSOURCE__H__
+#define __CPPLUGINSMESHSOURCES__CYLINDERSOURCE__H__
+
+#include <plugins/cpPluginsMeshSources/cpPluginsMeshSources_Export.h>
+#include <cpPlugins/ProcessObject.h>
+
+namespace cpPluginsMeshSources
+{
+  /**
+   */
+  class cpPluginsMeshSources_EXPORT CylinderSource
+    : public cpPlugins::ProcessObject
+  {
+  public:
+    typedef CylinderSource                    Self;
+    typedef cpPlugins::ProcessObject        Superclass;
+    typedef itk::SmartPointer< Self >       Pointer;
+    typedef itk::SmartPointer< const Self > ConstPointer;
+
+  public:
+    itkNewMacro( Self );
+    itkTypeMacro( CylinderSource, cpPlugins::ProcessObject );
+    cpPlugins_Id_Macro( CylinderSource, MeshSources );
+
+  protected:
+    CylinderSource( );
+    virtual ~CylinderSource( );
+
+    virtual void _GenerateData( ) ITK_OVERRIDE;
+
+  private:
+    // Purposely not implemented
+    CylinderSource( const Self& );
+    Self& operator=( const Self& );
+  };
+
+} // ecapseman
+
+#endif // __CPPLUGINSMESHSOURCES__CYLINDERSOURCE__H__
+
+// eof - $RCSfile$
diff --git a/plugins/cpPluginsMeshSources/SphereSource.cxx b/plugins/cpPluginsMeshSources/SphereSource.cxx
new file mode 100644 (file)
index 0000000..96d7677
--- /dev/null
@@ -0,0 +1,38 @@
+#include <cpPluginsMeshSources/SphereSource.h>
+#include <cpPlugins/Mesh.h>
+
+#include <vtkSphereSource.h>
+
+// -------------------------------------------------------------------------
+cpPluginsMeshSources::SphereSource::
+SphereSource( )
+  : Superclass( )
+{
+  this->_AddOutput< cpPlugins::Mesh >( "Output" );
+  this->m_Parameters.ConfigureAsReal( "Radius" );
+  this->m_Parameters.ConfigureAsUint( "PhiResolution" );
+  this->m_Parameters.ConfigureAsUint( "ThetaResolution" );
+  this->m_Parameters.SetReal( "Radius", 1 );
+  this->m_Parameters.SetUint( "PhiResolution", 8 );
+  this->m_Parameters.SetUint( "ThetaResolution", 8 );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsMeshSources::SphereSource::
+~SphereSource( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsMeshSources::SphereSource::
+_GenerateData( )
+{
+  auto src = this->_CreateVTK< vtkSphereSource >( );
+  src->SetRadius( this->m_Parameters.GetReal( "Radius" ) );
+  src->SetPhiResolution( this->m_Parameters.GetUint( "PhiResolution" ) );
+  src->SetThetaResolution( this->m_Parameters.GetUint( "ThetaResolution" ) );
+  src->Update( );
+  this->GetOutput( "Output" )->SetVTK( src->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/cpPluginsMeshSources/SphereSource.h b/plugins/cpPluginsMeshSources/SphereSource.h
new file mode 100644 (file)
index 0000000..624b27e
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef __CPPLUGINSMESHSOURCES__SPHERESOURCE__H__
+#define __CPPLUGINSMESHSOURCES__SPHERESOURCE__H__
+
+#include <plugins/cpPluginsMeshSources/cpPluginsMeshSources_Export.h>
+#include <cpPlugins/ProcessObject.h>
+
+namespace cpPluginsMeshSources
+{
+  /**
+   */
+  class cpPluginsMeshSources_EXPORT SphereSource
+    : public cpPlugins::ProcessObject
+  {
+  public:
+    typedef SphereSource                    Self;
+    typedef cpPlugins::ProcessObject        Superclass;
+    typedef itk::SmartPointer< Self >       Pointer;
+    typedef itk::SmartPointer< const Self > ConstPointer;
+
+  public:
+    itkNewMacro( Self );
+    itkTypeMacro( SphereSource, cpPlugins::ProcessObject );
+    cpPlugins_Id_Macro( SphereSource, MeshSources );
+
+  protected:
+    SphereSource( );
+    virtual ~SphereSource( );
+
+    virtual void _GenerateData( ) ITK_OVERRIDE;
+
+  private:
+    // Purposely not implemented
+    SphereSource( const Self& );
+    Self& operator=( const Self& );
+  };
+
+} // ecapseman
+
+#endif // __CPPLUGINSMESHSOURCES__SPHERESOURCE__H__
+
+// eof - $RCSfile$
index 934de3d61a15b18548d6a16a88477822c5603927..081f67f636c2d0069d558b14940dfff3a6a9c66f 100644 (file)
@@ -10,7 +10,6 @@ cpPlugins_WrapPlugins(
   "${lib_SOURCES}"
   "${lib_OTHER_SOURCES}"
   "${lib_QT4_HEADERS}"
-  cpExtensions cpPlugins ${cpPlugins_LIBRARIES}
   )
 
 ## ========================