X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FParameters.hxx;h=eecb2b6b08ebb74d201324a7cd79ec6039e685a1;hb=e992c2468610352a34187d9180e2e8f3fd3a6e68;hp=e47b799c7616e2c85ea7148bb4eb4fe2956e22a4;hpb=1c9f0e4788ee1b1f924f369ddadb7be7c8921f8c;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Parameters.hxx b/lib/cpPlugins/Interface/Parameters.hxx index e47b799..eecb2b6 100644 --- a/lib/cpPlugins/Interface/Parameters.hxx +++ b/lib/cpPlugins/Interface/Parameters.hxx @@ -1,100 +1,337 @@ #ifndef __CPPLUGINS__INTERFACE__PARAMETERS__HXX__ #define __CPPLUGINS__INTERFACE__PARAMETERS__HXX__ -#include -#include -#include +// ------------------------------------------------------------------------- +template< class I > +I cpPlugins::Interface::Parameters:: +GetIndex( const std::string& name, const unsigned int& dim ) const +{ + I v; + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == Self::Index ) + { + std::istringstream str( i->second.second ); + std::string token; + unsigned int d = 0; + while( std::getline( str, token, ';' ) && d < dim ) + { + v[ d ] = std::atoi( token.c_str( ) ); + d++; + + } // elihw + return( v ); + + } // fi + + } // fi + + // If parameter not found + for( unsigned int d = 0; d < dim; ++d ) + v[ d ] = 0; + return( v ); +} // ------------------------------------------------------------------------- -#define cpPlugins_Interface_Parameters_SetIndexOrPointMacro( NAME, TYPE ) \ - template< class T > \ - T cpPlugins::Interface::Parameters:: \ - GetValueAs##NAME( const TString& name ) const \ - { \ - T val; \ - TParameters::const_iterator pIt = this->m_Parameters.find( name ); \ - if( pIt != this->m_Parameters.end( ) ) \ - { \ - if( pIt->second.first == Self::NAME ) \ - { \ - std::istringstream ss( pIt->second.second ); \ - std::string token; \ - unsigned int i = 0; \ - while( std::getline( ss, token, ',' ) ) \ - { \ - if( token != "" ) \ - val[ i++ ] = TYPE( std::atof( token.c_str( ) ) ); \ - } \ - } \ - } \ - return( val ); \ - } - -cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Index, long ); -cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Point, double ); +template< class P > +P cpPlugins::Interface::Parameters:: +GetPoint( const std::string& name, const unsigned int& dim ) const +{ + P v; + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == Self::Point ) + { + std::istringstream str( i->second.second ); + std::string token; + unsigned int d = 0; + while( std::getline( str, token, ';' ) && d < dim ) + { + std::istringstream tok_str( token ); + tok_str >> v[ d ]; + d++; + + } // elihw + return( v ); + + } // fi + + } // fi + + // If parameter not found + for( unsigned int d = 0; d < dim; ++d ) + v[ d ] = float( 0 ); + return( v ); +} + +// ------------------------------------------------------------------------- +template< class V > +V cpPlugins::Interface::Parameters:: +GetVector( const std::string& name, const unsigned int& dim ) const +{ + V v; + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == Self::Vector ) + { + std::istringstream str( i->second.second ); + std::string token; + unsigned int d = 0; + while( std::getline( str, token, ';' ) && d < dim ) + { + std::istringstream tok_str( token ); + tok_str >> v[ d ]; + d++; + + } // elihw + return( v ); + + } // fi + + } // fi + + // If parameter not found + for( unsigned int d = 0; d < dim; ++d ) + v[ d ] = float( 0 ); + return( v ); +} // ------------------------------------------------------------------------- template< class I > void cpPlugins::Interface::Parameters:: -GetValueAsIndexList( std::vector< I >& lst, const TString& name ) const +SetIndex( const std::string& name, const unsigned int& dim, const I& v ) { - lst.clear( ); - TParameters::const_iterator pIt = this->m_Parameters.find( name ); - if( pIt == this->m_Parameters.end( ) ) + TParameters::iterator i = this->m_Parameters.find( name ); + if( i == this->m_Parameters.end( ) ) return; - if( pIt->second.first != Self::IndexList ) + if( i->second.first != Self::Index ) return; - std::istringstream ss( pIt->second.second ); - std::string token; - while( std::getline( ss, token, ':' ) ) + std::stringstream str; + str << v[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + str << ";" << v[ d ]; + i->second.second = str.str( ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class P > +void cpPlugins::Interface::Parameters:: +SetPoint( const std::string& name, const unsigned int& dim, const P& v ) +{ + TParameters::iterator i = this->m_Parameters.find( name ); + if( i == this->m_Parameters.end( ) ) + return; + if( i->second.first != Self::Point ) + return; + + std::stringstream str; + str << v[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + str << ";" << v[ d ]; + i->second.second = str.str( ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class V > +void cpPlugins::Interface::Parameters:: +SetVector( const std::string& name, const unsigned int& dim, const V& v ) +{ + TParameters::iterator i = this->m_Parameters.find( name ); + if( i == this->m_Parameters.end( ) ) + return; + if( i->second.first != Self::Vector ) + return; + + std::stringstream str; + str << v[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + str << ";" << v[ d ]; + i->second.second = str.str( ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class I > +std::vector< I > cpPlugins::Interface::Parameters:: +GetIndexList( const std::string& name, const unsigned int& dim ) const +{ + std::vector< I > lst; + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) { - if( token != "" ) + if( i->second.first == Self::IndexList ) { - std::istringstream ts( token ); - std::string text; - unsigned int i = 0; - I idx; - while( std::getline( ts, text, ',' ) ) - if( text != "" ) - idx[ i++ ] = std::atoi( text.c_str( ) ); - lst.push_back( idx ); + std::istringstream str( i->second.second ); + std::string token; + unsigned int d = 0; + while( std::getline( str, token, '#' ) ) + { + std::istringstream str2( token ); + std::string token2; + unsigned int d = 0; + I v; + while( std::getline( str2, token2, ';' ) && d < dim ) + { + v[ d ] = std::atoi( token.c_str( ) ); + d++; + + } // elihw + lst.push_back( v ); + + } // elihw } // fi - } // elihw + } // fi + return( lst ); } // ------------------------------------------------------------------------- template< class P > -void cpPlugins::Interface::Parameters:: -GetValueAsPointList( std::vector< P >& lst, const TString& name ) const +std::vector< P > cpPlugins::Interface::Parameters:: +GetPointList( const std::string& name, const unsigned int& dim ) const { - lst.clear( ); - TParameters::const_iterator pIt = this->m_Parameters.find( name ); - if( pIt == this->m_Parameters.end( ) ) - return; - if( pIt->second.first != Self::PointList ) - return; + std::vector< P > lst; - std::istringstream ss( pIt->second.second ); - std::string token; - while( std::getline( ss, token, ':' ) ) + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) { - if( token != "" ) + if( i->second.first == Self::PointList ) { - std::istringstream ts( token ); - std::string text; - unsigned int i = 0; - P pnt; - while( std::getline( ts, text, ',' ) ) - if( text != "" ) - pnt[ i++ ] = std::atof( text.c_str( ) ); - lst.push_back( pnt ); + std::istringstream str( i->second.second ); + std::string token; + unsigned int d = 0; + while( std::getline( str, token, '#' ) ) + { + std::istringstream str2( token ); + std::string token2; + unsigned int d = 0; + P v; + while( std::getline( str2, token2, ';' ) && d < dim ) + { + std::istringstream tok_str( token ); + tok_str >> v[ d ]; + d++; + + } // elihw + lst.push_back( v ); + + } // elihw } // fi - } // elihw + } // fi + return( lst ); +} + +// ------------------------------------------------------------------------- +template< class V > +std::vector< V > cpPlugins::Interface::Parameters:: +GetVectorList( const std::string& name, const unsigned int& dim ) const +{ + std::vector< V > lst; + + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == Self::VectorList ) + { + std::istringstream str( i->second.second ); + std::string token; + unsigned int d = 0; + while( std::getline( str, token, '#' ) ) + { + std::istringstream str2( token ); + std::string token2; + unsigned int d = 0; + V v; + while( std::getline( str2, token2, ';' ) && d < dim ) + { + std::istringstream tok_str( token ); + tok_str >> v[ d ]; + d++; + + } // elihw + lst.push_back( v ); + + } // elihw + + } // fi + + } // fi + return( lst ); +} + +// ------------------------------------------------------------------------- +template< class I > +void cpPlugins::Interface::Parameters:: +AddToIndexList( const std::string& name, const unsigned int& dim, const I& v ) +{ + TParameters::iterator i = this->m_Parameters.find( name ); + if( i == this->m_Parameters.end( ) ) + return; + if( i->second.first != Self::IndexList ) + return; + + std::stringstream str; + if( i->second.second == "" ) + str << v[ 0 ]; + else + str << "#" << v[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + str << ";" << v[ d ]; + i->second.second += str.str( ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class P > +void cpPlugins::Interface::Parameters:: +AddToPointList( const std::string& name, const unsigned int& dim, const P& v ) +{ + TParameters::iterator i = this->m_Parameters.find( name ); + if( i == this->m_Parameters.end( ) ) + return; + if( i->second.first != Self::PointList ) + return; + + std::stringstream str; + if( i->second.second == "" ) + str << v[ 0 ]; + else + str << "#" << v[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + str << ";" << v[ d ]; + i->second.second += str.str( ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class V > +void cpPlugins::Interface::Parameters:: +AddToVectorList( const std::string& name, const unsigned int& dim, const V& v ) +{ + TParameters::iterator i = this->m_Parameters.find( name ); + if( i == this->m_Parameters.end( ) ) + return; + if( i->second.first != Self::VectorList ) + return; + + std::stringstream str; + if( i->second.second == "" ) + str << v[ 0 ]; + else + str << "#" << v[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + str << ";" << v[ d ]; + i->second.second += str.str( ); + this->Modified( ); } #endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__