From ff82c0202d0496bb65bc4cb07e63604616db2961 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Wed, 30 Nov 2016 19:30:59 -0500 Subject: [PATCH] debug --- appli/PipelineEditor/PipelineEditor.cxx | 15 +++- appli/PipelineEditor/PipelineEditor.h | 1 + appli/PipelineEditor/PipelineEditor.ui | 23 ++++++ lib/cpInstances/Image.cxx | 9 +++ lib/cpPlugins/BaseObjects/Port.h | 2 +- lib/cpPlugins/BaseObjects/ProcessObject.cxx | 79 ++++++++++++++++----- lib/cpPlugins/BaseObjects/ProcessObject.h | 10 +-- lib/cpPlugins/Interface/Plugins.cxx | 30 +++++++- 8 files changed, 143 insertions(+), 26 deletions(-) diff --git a/appli/PipelineEditor/PipelineEditor.cxx b/appli/PipelineEditor/PipelineEditor.cxx index fec6efd..32a4546 100644 --- a/appli/PipelineEditor/PipelineEditor.cxx +++ b/appli/PipelineEditor/PipelineEditor.cxx @@ -31,6 +31,10 @@ PipelineEditor( int argc, char* argv[], QWidget* parent ) this->m_UI->Canvas->connectOutputPortSlot( this, SLOT( _slotView( const std::string&, bool ) ) ); + this->connect( + this->m_UI->actionPrintExecutionInformation, SIGNAL( triggered( bool ) ), + this, SLOT( _slotPrintExecutionInformation( bool ) ) + ); // Load command-line given workspace (if any) if( argc > 1 ) @@ -93,7 +97,8 @@ _slotView( const std::string& name, bool show ) } // fi if( dynamic_cast< QWidget* >( viewer ) != - dynamic_cast< QWidget* >( this->m_UI->Viewer ) + dynamic_cast< QWidget* >( this->m_UI->Viewer ) && + viewer != NULL ) { delete this->m_UI->Viewer; @@ -136,6 +141,14 @@ _slotView( const std::string& name, bool show ) } // fi } +// ------------------------------------------------------------------------- +void PipelineEditor:: +_slotPrintExecutionInformation( bool show ) +{ + if( this->m_Workspace.IsNotNull( ) ) + this->m_Workspace->SetPrintExecution( show ); +} + // ------------------------------------------------------------------------- #include cpBaseQtApplication_Main( PipelineEditor ); diff --git a/appli/PipelineEditor/PipelineEditor.h b/appli/PipelineEditor/PipelineEditor.h index 8c8db35..1b6674e 100644 --- a/appli/PipelineEditor/PipelineEditor.h +++ b/appli/PipelineEditor/PipelineEditor.h @@ -25,6 +25,7 @@ public: protected slots: void _slotView( const std::string& name, bool show ); + void _slotPrintExecutionInformation( bool show ); private: Ui::PipelineEditor* m_UI; diff --git a/appli/PipelineEditor/PipelineEditor.ui b/appli/PipelineEditor/PipelineEditor.ui index 45dc1fd..0e61512 100644 --- a/appli/PipelineEditor/PipelineEditor.ui +++ b/appli/PipelineEditor/PipelineEditor.ui @@ -75,6 +75,18 @@ + + + toolBar + + + TopToolBarArea + + + false + + + E&xit @@ -128,6 +140,17 @@ Ctrl+Shift+D + + + true + + + Print execution information? + + + Print execution information? + + diff --git a/lib/cpInstances/Image.cxx b/lib/cpInstances/Image.cxx index dc52b37..6cdae03 100644 --- a/lib/cpInstances/Image.cxx +++ b/lib/cpInstances/Image.cxx @@ -130,6 +130,8 @@ _ITK_2_VTK_0( _TImage* image ) const } // ------------------------------------------------------------------------- +#include + template< class _TImage > void cpInstances::Image:: _ITK_2_VTK_1( _TImage* image ) const @@ -145,6 +147,13 @@ _ITK_2_VTK_1( _TImage* image ) const f = nf.GetPointer( ); } // fi + + std::string name = ""; + if( this->m_Source != NULL ) + name = this->m_Source->GetName( ); + + std::cout << "HOLALALAL: " << name << " " << image << " " << f->GetInput( ) << std::endl; + f->SetInput( image ); f->Update( ); diff --git a/lib/cpPlugins/BaseObjects/Port.h b/lib/cpPlugins/BaseObjects/Port.h index 49ac16a..eef1616 100644 --- a/lib/cpPlugins/BaseObjects/Port.h +++ b/lib/cpPlugins/BaseObjects/Port.h @@ -29,7 +29,7 @@ namespace cpPlugins virtual void Clear( ); template< class _TType > - inline void Configure( ) { this->m_Sample = _TType::New( ); } + inline void Configure( ) { this->m_Sample = _TType::New( ); } protected: bool m_Required; diff --git a/lib/cpPlugins/BaseObjects/ProcessObject.cxx b/lib/cpPlugins/BaseObjects/ProcessObject.cxx index a367a3c..0192ea6 100644 --- a/lib/cpPlugins/BaseObjects/ProcessObject.cxx +++ b/lib/cpPlugins/BaseObjects/ProcessObject.cxx @@ -5,6 +5,41 @@ #include #include +// ------------------------------------------------------------------------- +void cpPlugins::BaseObjects::ProcessObject:: +PrintExecutionOn( ) +{ + this->SetPrintExecution( true ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::BaseObjects::ProcessObject:: +PrintExecutionOff( ) +{ + this->SetPrintExecution( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::BaseObjects::ProcessObject:: +GetPrintExecution( ) const +{ + return( this->m_PrintExecution ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::BaseObjects::ProcessObject:: +SetPrintExecution( bool v ) +{ + this->m_PrintExecution = v; +} + +// ------------------------------------------------------------------------- +void cpPlugins::BaseObjects::ProcessObject:: +SetPrintExecutionStream( std::ofstream* s ) +{ + this->m_PrintExecutionStream = s; +} + // ------------------------------------------------------------------------- cpPlugins::BaseObjects::Parameters* cpPlugins::BaseObjects::ProcessObject:: @@ -171,6 +206,7 @@ Disconnect( ) void cpPlugins::BaseObjects::ProcessObject:: Modified( ) const { + std::cout << "Modified: " << this->m_Name << std::endl; this->Superclass::Modified( ); cpPlugins::BaseObjects::Events::Modified evt; @@ -184,38 +220,41 @@ void cpPlugins::BaseObjects::ProcessObject:: Update( ) { // Force upstream updates - bool need_to_update = this->m_ExplicitExecution; - for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i ) + bool update = ( this->m_LastExecutionTime < this->GetMTime( ) ); + for( auto input : this->m_Inputs ) { - bool iv = i->second->IsValid( ); - bool ir = i->second->IsRequired( ); - if( !iv && ir ) - this->_Error( - std::string( "Required input \"" ) + i->first + - std::string( "\" is not valid." ) - ); - if( iv ) + for( unsigned int i = 0; i < input.second->Size( ); ++i ) { - unsigned int n = i->second->Size( ); - for( unsigned int j = 0; j < n; ++j ) + auto obj = input.second->Get( i ); + if( obj != NULL ) { - Self* src = i->second->Get( j )->GetSource( ); + auto src = obj->GetSource( ); if( src != NULL ) { - need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) ); src->Update( ); + update |= ( this->m_LastExecutionTime < src->GetMTime( ) ); } // fi + } + else + { + if( input.second->IsRequired( ) ) + this->_Error( + std::string( "Required input \"" ) + input.first + + std::string( "\" in filter \"" ) + + this->m_Name + + std::string( "\" is not valid." ) + ); - } // rof + } // fi - } // fi + } // rof } // rof - // Current update - if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update ) + if( update || this->m_ExplicitExecution ) { + // Show a message, if needed... if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL ) { *( this->m_PrintExecutionStream ) @@ -227,13 +266,15 @@ Update( ) } // fi + // Execute filter's algorithm and keep information about time auto t_start = cpPlugins_CHRONO; this->_GenerateData( ); auto t_end = cpPlugins_CHRONO; - this->m_LastExecutionSpan = long( t_end - t_start ); this->Modified( ); + this->m_LastExecutionSpan = long( t_end - t_start ); this->m_LastExecutionTime = this->GetMTime( ); + // End the message, if needed... if( this->m_PrintExecution && this->m_PrintExecutionStream != NULL ) { *( this->m_PrintExecutionStream ) diff --git a/lib/cpPlugins/BaseObjects/ProcessObject.h b/lib/cpPlugins/BaseObjects/ProcessObject.h index 60ee651..5dbf8b3 100644 --- a/lib/cpPlugins/BaseObjects/ProcessObject.h +++ b/lib/cpPlugins/BaseObjects/ProcessObject.h @@ -31,21 +31,23 @@ namespace cpPlugins cpPlugins_Id_Macro( ProcessObject, Object ); itkBooleanMacro( ExplicitExecution ); - itkBooleanMacro( PrintExecution ); itkGetStringMacro( Name ); itkGetStringMacro( PluginName ); itkGetConstMacro( ExplicitExecution, bool ); itkGetConstMacro( LastExecutionSpan, long ); - itkGetConstMacro( PrintExecution, bool ); itkSetStringMacro( Name ); itkSetStringMacro( PluginName ); itkSetMacro( ExplicitExecution, bool ); - itkSetMacro( PrintExecution, bool ); - itkSetObjectMacro( PrintExecutionStream, std::ofstream ); public: + void PrintExecutionOn( ); + void PrintExecutionOff( ); + bool GetPrintExecution( ) const; + bool SetPrintExecution( bool v ); + void SetPrintExecutionStream( std::ofstream* s ); + Parameters* GetParameters( ); const Parameters* GetParameters( ) const; diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx index 2f8d7ad..1543d31 100644 --- a/lib/cpPlugins/Interface/Plugins.cxx +++ b/lib/cpPlugins/Interface/Plugins.cxx @@ -123,48 +123,76 @@ cpPlugins::BaseObjects::ProcessObject::Pointer cpPlugins::Interface::Plugins:: CreateFilter( const std::string& category, const std::string& name ) { + std::cout << "1" << std::endl; typedef void* ( *_TCreator )( ); + std::cout << "2" << std::endl; typedef cpPlugins::BaseObjects::ProcessObject::Pointer _TPtr; + std::cout << "3" << std::endl; _TPtr o = NULL; + std::cout << "4" << std::endl; auto cat = this->m_Filters.find( category ); + std::cout << "5" << std::endl; if( cat != this->m_Filters.end( ) ) { + std::cout << "6" << std::endl; auto nam = cat->second.find( name ); + std::cout << "7" << std::endl; if( nam != cat->second.end( ) ) { + std::cout << "8" << std::endl; void* l_hnd = nam->second.second.first; + std::cout << "9" << std::endl; void* f_hnd = nam->second.second.second; + std::cout << "10" << std::endl; if( l_hnd == NULL ) { + std::cout << "11" << std::endl; l_hnd = cpPlugins::OS::DLLManager::LoadPlugins( nam->second.first ); + std::cout << "12" << std::endl; nam->second.second.first = l_hnd; + std::cout << "13" << std::endl; } // fi if( f_hnd == NULL ) { + std::cout << "14" << std::endl; f_hnd = cpPlugins::OS::DLLManager::LoadCreator( l_hnd, category, name ); + std::cout << "15" << std::endl; nam->second.second.second = f_hnd; + std::cout << "16" << std::endl; } // fi + std::cout << "17" << std::endl; _TCreator creator = reinterpret_cast< _TCreator >( f_hnd ); + std::cout << "18" << std::endl; if( creator != NULL ) { - o = reinterpret_cast< _TPtr* >( creator( ) )->GetPointer( ); + std::cout << "19 " << creator << " " << f_hnd << std::endl; + void* a = creator( ); + std::cout << "20" << std::endl; + std::cout << "20 " << creator << " " << a << std::endl; + std::cout << "21" << std::endl; + o = reinterpret_cast< _TPtr* >( a )->GetPointer( ); + std::cout << "22" << std::endl; o->SetName( name ); + std::cout << "23" << std::endl; o->SetPluginName( nam->second.first ); + std::cout << "24" << std::endl; } // fi } // fi } // fi + std::cout << "25" << std::endl; if( o.IsNull( ) ) throw std::runtime_error( std::string( "Could not create a valid ProcessObject of type \"" ) + category + std::string( ":" ) + name + std::string( "\"" ) ); + std::cout << "26" << std::endl; return( o ); } -- 2.47.1