]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/Parameters.hxx
Machete filter visualization finished.
[cpPlugins.git] / lib / cpPlugins / Interface / Parameters.hxx
index 4b4e3424f699f8b167aa9b0fe6a7d394affb33f0..b633f879f5e33b70b0a3064e259ca0c754849b4d 100644 (file)
@@ -31,6 +31,21 @@ ConfigureAsPoint( const TString& name, const TUint& dim, const P& v )
   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( );
+}
+
 // -------------------------------------------------------------------------
 template< class I >
 I cpPlugins::Interface::Parameters::
@@ -79,7 +94,41 @@ GetPoint( const TString& name, const TUint& dim ) const
       unsigned int d = 0;
       while( std::getline( str, token, ';' ) && d < dim )
       {
-        v[ d ] = std::atof( token.c_str( ) );
+        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
@@ -156,7 +205,44 @@ GetPointList(
     P v;
     while( std::getline( str2, token2, ';' ) && d < dim )
     {
-      v[ d ] = std::atof( token.c_str( ) );
+      std::istringstream tok_str( token );
+      tok_str >> v[ d ];
+      d++;
+
+    } // elihw
+    lst.push_back( v );
+
+  } // 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 )
+    {
+      std::istringstream tok_str( token );
+      tok_str >> v[ d ];
       d++;
 
     } // elihw
@@ -203,6 +289,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::
@@ -247,6 +352,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$