X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FParameters.hxx;h=0bb20c7e46ff65bbb9ff472f931822ebc364bc3c;hb=00b54bc0344d74f31df8b93f7c28a07cfc8d6873;hp=791d526263ad5584ab0b0bfe73010e7403d7ba6a;hpb=2eaf38cfdcbd2cfb0cc323dad6ded6bbeb436edf;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Parameters.hxx b/lib/cpPlugins/Interface/Parameters.hxx index 791d526..0bb20c7 100644 --- a/lib/cpPlugins/Interface/Parameters.hxx +++ b/lib/cpPlugins/Interface/Parameters.hxx @@ -11,7 +11,8 @@ ConfigureAsIndex( const TString& name, const TUint& dim, const I& v ) for( unsigned int d = 1; d < dim; ++d ) str << ";" << v[ d ]; std::string s = str.str( ); - this->m_Parameters[ name ] = TParameter( Self::Index, TValues( s, s ) ); + this->m_Parameters[ name ] = + TParameter( Self::Index, TValues( s, s ) ); this->Modified( ); } @@ -25,7 +26,23 @@ ConfigureAsPoint( const TString& name, const TUint& dim, const P& v ) for( unsigned int d = 1; d < dim; ++d ) str << ";" << v[ d ]; std::string s = str.str( ); - this->m_Parameters[ name ] = TParameter( Self::Point, TValues( s, s ) ); + this->m_Parameters[ name ] = + TParameter( Self::Point, TValues( s, s ) ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class V > +void cpPlugins::Interface::Parameters:: +ConfigureAsVector( const TString& name, const TUint& dim, const V& v ) +{ + std::stringstream str; + str << v[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + str << ";" << v[ d ]; + std::string s = str.str( ); + this->m_Parameters[ name ] = + TParameter( Self::Vector, TValues( s, s ) ); this->Modified( ); } @@ -93,6 +110,38 @@ GetPoint( const TString& name, const TUint& dim ) const return( v ); } +// ------------------------------------------------------------------------- +template< class V > +V cpPlugins::Interface::Parameters:: +GetVector( const TString& name, const TUint& dim ) const +{ + V v; + TParameters::const_iterator i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == Self::Vector ) + { + std::istringstream str( i->second.second.second ); + std::string token; + unsigned int d = 0; + while( std::getline( str, token, ';' ) && d < dim ) + { + v[ d ] = std::atof( token.c_str( ) ); + 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:: @@ -163,6 +212,41 @@ GetPointList( } // elihw } +// ------------------------------------------------------------------------- +template< class V > +void cpPlugins::Interface::Parameters:: +GetVectorList( + std::vector< V >& lst, const TString& name, const TUint& dim + ) const +{ + lst.clear( ); + + TParameters::const_iterator i = this->m_Parameters.find( name ); + if( i == this->m_Parameters.end( ) ) + return; + if( i->second.first == Self::VectorList ) + return; + + std::istringstream str( i->second.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 ) + { + v[ d ] = std::atof( token.c_str( ) ); + d++; + + } // elihw + lst.push_back( v ); + + } // elihw +} + // ------------------------------------------------------------------------- template< class I > void cpPlugins::Interface::Parameters:: @@ -201,6 +285,25 @@ SetPoint( const TString& name, const TUint& dim, const P& v ) this->Modified( ); } +// ------------------------------------------------------------------------- +template< class V > +void cpPlugins::Interface::Parameters:: +SetVector( const TString& name, const TUint& 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.second = str.str( ); + this->Modified( ); +} + // ------------------------------------------------------------------------- template< class I > void cpPlugins::Interface::Parameters:: @@ -245,6 +348,28 @@ AddToPointList( const TString& name, const TUint& dim, const P& v ) this->Modified( ); } +// ------------------------------------------------------------------------- +template< class V > +void cpPlugins::Interface::Parameters:: +AddToVectorList( const TString& name, const TUint& 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.second == "" ) + str << v[ 0 ]; + else + str << "#" << v[ 0 ]; + for( unsigned int d = 1; d < dim; ++d ) + str << ";" << v[ d ]; + i->second.second.second += str.str( ); + this->Modified( ); +} + #endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__ // eof - $RCSfile$