1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
5 #include <cpPlugins/ProcessObject.h>
6 #include <cpPlugins/DataObject.h>
7 #include <cpPlugins/Pipeline.h>
8 #include <boost/property_tree/ptree.hpp>
10 // -------------------------------------------------------------------------
11 const std::string& cpPlugins::ProcessObject::
14 return( this->m_Name );
17 // -------------------------------------------------------------------------
18 void cpPlugins::ProcessObject::
19 SetName( const std::string& name )
21 if( this->m_Name != name )
28 // -------------------------------------------------------------------------
29 void cpPlugins::ProcessObject::
30 Print( std::ostream& o ) const
32 this->Superclass::Print( o );
33 this->TParameters::Print( o );
36 // -------------------------------------------------------------------------
37 void cpPlugins::ProcessObject::
38 SetPipeline( cpPlugins::Pipeline* p )
41 this->m_Pipeline = p->CastWeakPtr< cpPlugins::Pipeline >( );
43 this->m_Pipeline.reset( );
46 // -------------------------------------------------------------------------
47 void cpPlugins::ProcessObject::
48 SetInput( const std::string& name, cpPlugins::DataObject* data )
50 TInputs::iterator i = this->m_Inputs.find( name );
51 if( i != this->m_Inputs.end( ) )
53 if( !( i->second.Set( data ) ) )
55 this, << "Input \"" << name << "\" does not match to input data."
60 this, << "Input \"" << name << "\" does not belong to this filter."
64 // -------------------------------------------------------------------------
65 cpPlugins::DataObject* cpPlugins::ProcessObject::
66 GetInput( const std::string& name, const unsigned int id )
68 TInputs::iterator i = this->m_Inputs.find( name );
69 if( i != this->m_Inputs.end( ) )
71 if( id < i->second.Count( ) )
72 return( i->second.Get( id ) );
75 this, << "Input \"" << name << "\" does have enough inputs."
80 this, << "Input \"" << name << "\" does not belong to this filter."
84 // -------------------------------------------------------------------------
85 const cpPlugins::DataObject* cpPlugins::ProcessObject::
86 GetInput( const std::string& name, const unsigned int id ) const
88 TInputs::const_iterator i = this->m_Inputs.find( name );
89 if( i != this->m_Inputs.end( ) )
91 if( id < i->second.Count( ) )
92 return( i->second.Get( id ) );
95 this, << "Input \"" << name << "\" does have enough inputs."
100 this, << "Input \"" << name << "\" does not belong to this filter."
104 // -------------------------------------------------------------------------
105 bool cpPlugins::ProcessObject::
106 HasInput( const std::string& name ) const
108 TInputs::const_iterator i = this->m_Inputs.find( name );
109 return( i != this->m_Inputs.end( ) );
112 // -------------------------------------------------------------------------
113 std::set< std::string > cpPlugins::ProcessObject::
114 GetInputsNames( ) const
116 std::set< std::string > n;
117 TInputs::const_iterator i = this->m_Inputs.begin( );
118 for( ; i != this->m_Inputs.end( ); ++i )
119 n.insert( i->first );
123 // -------------------------------------------------------------------------
124 unsigned int cpPlugins::ProcessObject::
125 GetNumberOfInputs( ) const
127 return( this->m_Inputs.size( ) );
130 // -------------------------------------------------------------------------
131 unsigned int cpPlugins::ProcessObject::
132 GetNumberOfInputs( const std::string& name ) const
134 TInputs::const_iterator i = this->m_Inputs.find( name );
135 if( i != this->m_Inputs.end( ) )
136 return( i->second.Count( ) );
141 // -------------------------------------------------------------------------
142 std::set< std::string > cpPlugins::ProcessObject::
143 GetAllInputsNames( ) const
145 std::set< std::string > r = this->GetInputsNames( );
146 std::set< std::string > iScalar = this->GetInValueNames( );
147 std::set< std::string > iSet = this->GetInSetNames( );
148 std::set< std::string > iSequence = this->GetInSequenceNames( );
149 for( const std::string& s: iScalar )
151 for( const std::string& s: iSet )
153 for( const std::string& s: iSequence )
159 // -------------------------------------------------------------------------
160 std::set< std::string > cpPlugins::ProcessObject::
161 GetAllOutputsNames( ) const
163 std::set< std::string > r = this->GetOutValueNames( );
164 std::set< std::string > oSet = this->GetOutSetNames( );
165 std::set< std::string > oSequence = this->GetOutSequenceNames( );
166 for( const std::string& s: oSet )
168 for( const std::string& s: oSequence )
174 // -------------------------------------------------------------------------
175 bool cpPlugins::ProcessObject::
176 GetExecutionDebug( ) const
178 return( this->m_ExecutionDebug );
181 // -------------------------------------------------------------------------
182 void cpPlugins::ProcessObject::
183 SetExecutionDebug( bool d )
185 this->m_ExecutionDebug = d;
188 // -------------------------------------------------------------------------
189 void cpPlugins::ProcessObject::
192 this->SetExecutionDebug( true );
195 // -------------------------------------------------------------------------
196 void cpPlugins::ProcessObject::
199 this->SetExecutionDebug( false );
202 // -------------------------------------------------------------------------
203 const double& cpPlugins::ProcessObject::
204 GetLastDuration( ) const
206 return( this->m_LastDuration );
209 // -------------------------------------------------------------------------
210 bool cpPlugins::ProcessObject::
211 IsUpdated( const TTimeStamp& d ) const
213 bool ok = this->Superclass::IsUpdated( d );
216 for( const TInputs::value_type& i: this->m_Inputs )
218 for( unsigned long j = 0; j < i.second.Count( ); ++j )
220 const cpPlugins::DataObject* dObj = i.second.Get( j );
222 ok &= dObj->IsUpdated( d );
230 // -------------------------------------------------------------------------
231 void cpPlugins::ProcessObject::
234 this->m_LastDuration = -1;
235 this->Superclass::Modified( );
238 // -------------------------------------------------------------------------
239 void cpPlugins::ProcessObject::
240 ModifiedInValue( const std::string& name )
242 // WARNING: Synch parameters in cpPlugins::Pipeline
246 // -------------------------------------------------------------------------
247 void cpPlugins::ProcessObject::
248 ModifiedInSet( const std::string& name )
250 // WARNING: Synch parameters in cpPlugins::Pipeline
254 // -------------------------------------------------------------------------
255 void cpPlugins::ProcessObject::
256 ModifiedInSequence( const std::string& name )
258 // WARNING: Synch parameters in cpPlugins::Pipeline
262 // -------------------------------------------------------------------------
263 void cpPlugins::ProcessObject::
264 ModifiedOutValue( const std::string& name )
266 // WARNING: Synch parameters in cpPlugins::Pipeline
270 // -------------------------------------------------------------------------
271 void cpPlugins::ProcessObject::
272 ModifiedOutSet( const std::string& name )
274 // WARNING: Synch parameters in cpPlugins::Pipeline
278 // -------------------------------------------------------------------------
279 void cpPlugins::ProcessObject::
280 ModifiedOutSequence( const std::string& name )
282 // WARNING: Synch parameters in cpPlugins::Pipeline
286 // -------------------------------------------------------------------------
287 void cpPlugins::ProcessObject::
288 ModifiedChoice( const std::string& name )
290 // WARNING: Synch parameters in cpPlugins::Pipeline
294 // -------------------------------------------------------------------------
295 void cpPlugins::ProcessObject::
298 bool is_updated = this->IsUpdated( );
299 is_updated &= this->TParameters::Update( );
302 for( TInputs::value_type i: this->m_Inputs )
304 if( i.second.IsValid( ) )
306 for( unsigned long j = 0; j < i.second.Count( ); ++j )
308 cpPlugins::DataObject* dObj = i.second.Get( j );
311 if( !( dObj->IsUpdated( ) ) )
322 // Allow some updates in particular cases (i.e. Functors)
323 is_updated &= this->_BeforeUpdate( );
328 if( this->m_ExecutionDebug )
330 *( this->m_OutStream )
331 << "Executing node \"" << this->GetName( ) << "\"... "
333 this->m_OutStream->flush( );
335 std::chrono::steady_clock::time_point start =
336 std::chrono::steady_clock::now( );
337 this->_GenerateData( );
338 std::chrono::steady_clock::time_point end =
339 std::chrono::steady_clock::now( );
340 this->m_LastDuration =
342 std::chrono::duration_cast< std::chrono::microseconds >(
346 if( this->m_ExecutionDebug )
348 *( this->m_OutStream )
350 << this->m_LastDuration << " s"
352 this->m_OutStream->flush( );
358 // -------------------------------------------------------------------------
360 void cpPlugins::ProcessObject::
361 SaveXML( boost::property_tree::ptree* node ) const
363 boost::property_tree::ptree xml;
364 xml.put( "<xmlattr>.name", this->GetName( ) );
365 xml.put( "<xmlattr>.class", this->GetClassName( ) );
366 this->TParameters::SaveXML( &xml );
367 node->add_child( "pipeline.node", xml );
370 // -------------------------------------------------------------------------
371 cpPlugins::ProcessObject::
375 m_OutStream( &std::cout ),
376 m_ExecutionDebug( false ),
381 // -------------------------------------------------------------------------
382 cpPlugins::ProcessObject::
387 // -------------------------------------------------------------------------
388 bool cpPlugins::ProcessObject::