]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/Parameters.hxx
Machete filter visualization finished.
[cpPlugins.git] / lib / cpPlugins / Interface / Parameters.hxx
index ac30bc9648e8c4344cbbda8aefb2c960dd7a95d8..b633f879f5e33b70b0a3064e259ca0c754849b4d 100644 (file)
 #ifndef __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
 #define __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
 
-#include <sstream>
-
 // -------------------------------------------------------------------------
 template< class I >
 void cpPlugins::Interface::Parameters::
-SetValueAsStringList( const std::string& name, const I& b, const I& e )
+ConfigureAsIndex( const TString& name, const TUint& dim, const I& v )
 {
-  TParameters::iterator pIt = this->m_Parameters.find( name );
-  if( pIt == this->m_Parameters.end( ) )
-    return;
-  if( pIt->second.first != Self::StringList )
-    return;
+  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::Index, TValues( s, s ) );
+  this->Modified( );
+}
 
-  std::stringstream ss;
-  for( I i = b; i != e; ++i )
-    ss << *i << ":";
-  pIt->second = ss.str( );
+// -------------------------------------------------------------------------
+template< class P >
+void cpPlugins::Interface::Parameters::
+ConfigureAsPoint( const TString& name, const TUint& dim, const P& 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::Point, TValues( s, s ) );
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
-template< class I >
+template< class V >
 void cpPlugins::Interface::Parameters::
-SetValueAsIntList( const std::string& name, const I& b, const I& e )
+ConfigureAsVector( const TString& name, const TUint& dim, const V& v )
 {
-  TParameters::iterator pIt = this->m_Parameters.find( name );
-  if( pIt == this->m_Parameters.end( ) )
-    return;
-  if( pIt->second.first != Self::IntList )
-    return;
+  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( );
+}
+
+// -------------------------------------------------------------------------
+template< class I >
+I cpPlugins::Interface::Parameters::
+GetIndex( const TString& name, const TUint& dim ) const
+{
+  I v;
+  TParameters::const_iterator i = this->m_Parameters.find( name );
+  if( i != this->m_Parameters.end( ) )
+  {
+    if( i->second.first == Self::Index )
+    {
+      std::istringstream str( i->second.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
 
-  std::stringstream ss;
-  for( I i = b; i != e; ++i )
-    ss << *i << ":";
-  pIt->second = ss.str( );
+  } // fi
+
+  // If parameter not found
+  for( unsigned int d = 0; d < dim; ++d )
+    v[ d ] = 0;
+  return( v );
+}
+
+// -------------------------------------------------------------------------
+template< class P >
+P cpPlugins::Interface::Parameters::
+GetPoint( const TString& name, const TUint& dim ) const
+{
+  P v;
+  TParameters::const_iterator i = this->m_Parameters.find( name );
+  if( i != this->m_Parameters.end( ) )
+  {
+    if( i->second.first == Self::Point )
+    {
+      std::istringstream str( i->second.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 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 )
+      {
+        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::
-SetValueAsUintList( const std::string& name, const I& b, const I& e )
+GetIndexList(
+  std::vector< I >& lst, const TString& name, const TUint& dim
+  ) const
 {
-  TParameters::iterator pIt = this->m_Parameters.find( name );
-  if( pIt == this->m_Parameters.end( ) )
+  lst.clear( );
+
+  TParameters::const_iterator i = this->m_Parameters.find( name );
+  if( i == this->m_Parameters.end( ) )
     return;
-  if( pIt->second.first != Self::UintList )
+  if( i->second.first == Self::IndexList )
     return;
 
-  std::stringstream ss;
-  for( I i = b; i != e; ++i )
-    ss << *i << ":";
-  pIt->second = ss.str( );
+  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;
+    I v;
+    while( std::getline( str2, token2, ';' ) && d < dim )
+    {
+      v[ d ] = std::atoi( token.c_str( ) );
+      d++;
+
+    } // elihw
+    lst.push_back( v );
+
+  } // elihw
 }
 
 // -------------------------------------------------------------------------
-template< class I >
+template< class P >
 void cpPlugins::Interface::Parameters::
-SetValueAsRealList( const std::string& name, const I& b, const I& e )
+GetPointList(
+  std::vector< P >& lst, const TString& name, const TUint& dim
+  ) const
 {
-  TParameters::iterator pIt = this->m_Parameters.find( name );
-  if( pIt == this->m_Parameters.end( ) )
+  lst.clear( );
+
+  TParameters::const_iterator i = this->m_Parameters.find( name );
+  if( i == this->m_Parameters.end( ) )
     return;
-  if( pIt->second.first != Self::RealList )
+  if( i->second.first == Self::PointList )
     return;
 
-  std::stringstream ss;
-  for( I i = b; i != e; ++i )
-    ss << *i << ":";
-  pIt->second = ss.str( );
+  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;
+    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
 }
 
 // -------------------------------------------------------------------------
-template< class I >
+template< class V >
 void cpPlugins::Interface::Parameters::
-SetValueAsIndexList( const std::string& name, const I& b, const I& e )
+GetVectorList(
+  std::vector< V >& lst, const TString& name, const TUint& dim
+  ) const
 {
-  // TODO
+  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 )
+    {
+      std::istringstream tok_str( token );
+      tok_str >> v[ d ];
+      d++;
+
+    } // elihw
+    lst.push_back( v );
+
+  } // elihw
 }
 
 // -------------------------------------------------------------------------
 template< class I >
 void cpPlugins::Interface::Parameters::
-SetValueAsPointList( const std::string& name, const I& b, const I& e )
+SetIndex( const TString& name, const TUint& dim, const I& v )
 {
-  // TODO
+  TParameters::iterator i = this->m_Parameters.find( name );
+  if( i == this->m_Parameters.end( ) )
+    return;
+  if( i->second.first != Self::Index )
+    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 >
-I cpPlugins::Interface::Parameters::
-GetValueAsIndex( const std::string& name ) const
+template< class P >
+void cpPlugins::Interface::Parameters::
+SetPoint( const TString& name, const TUint& dim, const P& v )
 {
-  TParameters::iterator pIt = this->m_Parameters.find( name );
-  if( pIt == this->m_Parameters.end( ) )
-    return( I( ) );
-  if( pIt->second.first != Self::Index )
-    return( I( ) );
-
-  // TODO:
-  return( I( ) );
+  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.second = str.str( );
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
-template< class P >
-P cpPlugins::Interface::Parameters::
-GetValueAsPoint( const std::string& name ) const
+template< class V >
+void cpPlugins::Interface::Parameters::
+SetVector( const TString& name, const TUint& dim, const V& v )
 {
-  TParameters::iterator pIt = this->m_Parameters.find( name );
-  if( pIt == this->m_Parameters.end( ) )
-    return( P( ) );
-  if( pIt->second.first != Self::Point )
-    return( P( ) );
-
-  // TODO:
-  return( P( ) );
+  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::
-GetValueAsIndexList( std::vector< I >& lst, const std::string& name ) const
+AddToIndexList( const TString& name, const TUint& dim, const I& v )
 {
-  lst.clear( );
-  TParameters::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::IndexList )
     return;
 
-  // TODO:
+  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( );
 }
 
 // -------------------------------------------------------------------------
 template< class P >
 void cpPlugins::Interface::Parameters::
-GetValueAsPointList( std::vector< P >& lst, const std::string& name ) const
+AddToPointList( const TString& name, const TUint& dim, const P& v )
 {
-  lst.clear( );
-  TParameters::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( i->second.first != Self::PointList )
+    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( );
+}
+
+// -------------------------------------------------------------------------
+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( pIt->second.first != Self::PointList )
+  if( i->second.first != Self::VectorList )
     return;
 
-  // TODO:
+  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__