Selaa lähdekoodia

Merge branch 'master' of dbv.inf-cv.uni-jena.de:nice/nice-core

Sven Sickert 9 vuotta sitten
vanhempi
commit
83dc4be54c

+ 38 - 4
cmake/NiceModules.cmake

@@ -165,7 +165,7 @@ macro(nice_get_source_files)
     
 
     #message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
-    file(GLOB_RECURSE list_tmp1 RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.cpp *.tcc *.c)
+    file(GLOB_RECURSE list_tmp1 RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.cpp *.tcc *.c *.C)
     #message(STATUS "list_tmp1: ${list_tmp1}")
     foreach( t_SrcFile ${list_tmp1})
       get_filename_component(t_SrcPath ${t_SrcFile} PATH)
@@ -205,9 +205,43 @@ macro(nice_get_source_files)
     #message(STATUS "globallyrecusive_tests: ${nice_${the_library}_TESTFILES_SRC}")
     #message(STATUS "globallyrecusive_progs: ${nice_${the_library}_PROGFILES_SRC}")
 
-    ### Get all header files recursively
-    file(GLOB_RECURSE nice_${the_library}_HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h)
-    
+    ### Get all header files recursively...
+    # ... but filter the headers according to their "type", meaning whether they are part of a unit test, a prog, or a mex.
+    # That means for example, that if you DO NOT WANT to build all progs in ./progs/ directories, all header files inside ./progs/ direcories 
+    # should be excluded and not be consided in the build. The same example applies to unit tests (./tests/) and mex filex.
+    # The reason is: The filter mechanism described above was also appied to source code files. So, we need to take care to have 
+    # the source and header files synchronized, so that we avoid using only the header file of a class, but not its source code implementation file
+    # which might lead to "undefined references" error. Especially in case of header file class definitions using Qt and an Q_OBJECT
+    # definition, a header file is moc'ed but but will generate "undefined references" if the source code file is not available.
+    file(GLOB_RECURSE list_tmp2 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h)
+    set(nice_${the_library}_HDR "")
+    foreach( t_HdrFile ${list_tmp2})
+      get_filename_component(t_HdrPath ${t_HdrFile} PATH)
+      set(t_HdrPath ${the_library}/${t_HdrPath})
+      string(REGEX REPLACE "(.*)/+$" "\\1" t_HdrPath ${t_HdrPath})
+      #list(FIND internal_deps ${t_HdrPath} dep_index)
+      if( NOT t_HdrFile MATCHES "moc_" )
+        if( t_HdrFile MATCHES "tests/" )
+          if(BUILD_UNITTESTS)
+            LIST(APPEND nice_${the_library}_HDR ${t_HdrFile})
+          endif()
+        elseif( t_HdrFile MATCHES "progs/" )
+          if(BUILD_PROGRAMS)
+            #message(STATUS "prog: ${t_HdrFile}")
+            LIST(APPEND nice_${the_library}_HDR ${t_HdrFile})
+          endif()
+        elseif( t_HdrFile MATCHES "Mex[.]" )
+          if(WITH_MEX)
+            #message(STATUS "mex: ${t_HdrFile}")
+            LIST(APPEND nice_${the_library}_HDR ${t_HdrFile})
+          endif()
+        else()
+           LIST(APPEND nice_${the_library}_HDR ${t_HdrFile})
+        endif()
+      endif()
+    endforeach()
+    #message(STATUS "header files found: ${nice_${the_library}_HDR}")
+
   else()
     message(STATUS "Using source files from file lists (*.cmake)")
     #define variable nice_<libname>_HDR and nice_<libname>_SRC for library header and source files (don't include progs and test source files here)

+ 19 - 2
core/image/MultiChannelImage3DT.h

@@ -28,7 +28,8 @@ protected:
   typedef unsigned int uint;
 
   /** image data, use carefully !!! data[channel][pixel_offset] */
-  P **data;
+  std::vector<P*> data;
+//    P **data;
   
   /** image width */
   int xsize;
@@ -73,6 +74,17 @@ public:
   /** free all memory */
   void freeData();
 
+  /**
+   * @brief free only the pointer to the actual data, but leaves the actual data in the memory.
+   *
+   * Usefull for when the underlying data (e.g data[0] ptrs are passed to an other multi channel
+   * image for further use and memcopy should be avoided.
+   * Detail: Only frees variable 'data', not the memory data[0:numChannels] is pointing to
+   * @author Johannes Ruehle
+   * @date 2014-07-18
+   */
+  void freeShallowData();
+
   /** reinit */
   void reInit( int xsize, int ysize, int zsize, int numChannels = 1);
 
@@ -89,12 +101,17 @@ public:
   
   template<class SrcP>
   void addChannel(const NICE::MultiChannelImage3DT<SrcP> &newImg);
+
+  /** add channels only as references (no deep memory copy) */
+  template<class SrcP>
+  void addChannelReferences(const NICE::MultiChannelImage3DT<SrcP> &newImg);
   
   /** get value */
   P get( int x, int y, int z, uint channel = 0 ) const;
   
   /** get data pointer */
-  P** getDataPointer();
+  std::vector<P*> getDataPointer() const;
+  //P** getDataPointer();
 
   /** set value */
   void set( int x, int y, int z, P val, uint channel = 0 );

+ 91 - 56
core/image/MultiChannelImage3DT.tcc

@@ -7,7 +7,7 @@ namespace NICE {
 template<class P>
 MultiChannelImage3DT<P>::MultiChannelImage3DT( int _xsize, int _ysize, int _zsize, uint _numChannels)
 {
-  data = NULL;
+//  data = NULL;
   numChannels = 0;
   xsize = 0;
   ysize = 0;
@@ -22,7 +22,7 @@ MultiChannelImage3DT<P>::MultiChannelImage3DT()
   ysize = 0;
   zsize = 0;
   numChannels = 0;
-  data = NULL;
+//  data = NULL;
 }
 
 template<class P>
@@ -52,40 +52,32 @@ MultiChannelImageT<P> MultiChannelImage3DT<P>::operator[] (uint z)
 template<class P>
 MultiChannelImage3DT<P>& MultiChannelImage3DT<P>::operator=(const MultiChannelImage3DT<P>& orig) 
 {
-  if(!(xsize == orig.xsize && ysize == orig.ysize && zsize == orig.zsize && numChannels == orig.numChannels))
+  if(  xsize == orig.xsize
+     && ysize == orig.ysize
+     && zsize == orig.zsize
+     && numChannels == orig.numChannels)
+  {
+      int iMemSize = xsize*ysize*zsize;
+      for(int c=0; c < numChannels; ++c)
+      {
+          std::copy(orig.data[c], orig.data[c]+iMemSize, data[c]);
+      }
+  }
+  else
   {
     freeData();
     xsize = orig.xsize;
     ysize = orig.ysize;
     zsize = orig.zsize;
     numChannels = orig.numChannels;
-    if(orig.data != NULL)
-    {
-      data = new P *[numChannels];
-      for ( int c = 0; c < ( int )numChannels; c++ )
-      {
-        if ( orig.data[c] == NULL )
-        {
-          data[c] = NULL;
-        }
-        else
-        {
-          data[c] = new P [xsize*ysize*zsize];
-        }
-      }
-    }
-    else
-      data = NULL;
-  }
 
-  for ( int c = 0; c < ( int )numChannels; c++ )
-  {
-    if ( orig.data[c] != NULL )
+    int iMemSize = xsize*ysize*zsize;
+
+    for(int c = 0; c < numChannels; ++c)
     {
-      for ( int x = 0; x < xsize*ysize*zsize; x++ )
-      {
-        data[c][x] = orig.data[c][x];
-      }
+        P *t_newData = new P [iMemSize];
+        std::copy(orig.data[c], orig.data[c]+iMemSize, t_newData);
+        data.push_back( t_newData );
     }
   }
   
@@ -95,13 +87,21 @@ MultiChannelImage3DT<P>& MultiChannelImage3DT<P>::operator=(const MultiChannelIm
 template<class P>
 MultiChannelImage3DT<P>::MultiChannelImage3DT( const MultiChannelImage3DT<P>& p )
 {
-  data = NULL;
   xsize = p.xsize;
   ysize = p.ysize;
   zsize = p.zsize;
   numChannels = p.numChannels;
-   
-  if(p.data != NULL)
+
+  int iMemSize = xsize*ysize*zsize;
+
+  for(int c=0; c < numChannels; ++c)
+  {
+      P *t_newData = new P [iMemSize];
+      std::copy(p.data[c], p.data[c]+iMemSize, t_newData);
+      data.push_back( t_newData );
+  }
+
+/*  if(p.data != NULL)
     data = new P *[numChannels];
   else
     data = NULL;
@@ -121,13 +121,25 @@ MultiChannelImage3DT<P>::MultiChannelImage3DT( const MultiChannelImage3DT<P>& p
       }
     }
   }
+*/
 }
 
 
 template<class P>
 void MultiChannelImage3DT<P>::addChannel( int newChans )
 {
-  P **tmpData = new P *[numChannels+newChans];
+    assert(xsize > 0);
+    assert(ysize > 0);
+    assert(zsize > 0);
+
+    for (int i = 0; i < newChans; i++ )
+    {
+        this->data.push_back( new P [xsize*ysize*zsize] );
+    }
+
+    numChannels = this->data.size();
+/* old and ugly:
+   P **tmpData = new P *[numChannels+newChans];
 
   bool allocMem = false;
   int i = 0;
@@ -160,6 +172,7 @@ void MultiChannelImage3DT<P>::addChannel( int newChans )
   }
 
   delete [] tmpData;
+  */
 }
 
 template<class P>
@@ -224,6 +237,37 @@ void MultiChannelImage3DT<P>::addChannel(const NICE::MultiChannelImage3DT<SrcP>
   }
 }
 
+template<class P>
+template<class SrcP>
+void MultiChannelImage3DT<P>::addChannelReferences(const NICE::MultiChannelImage3DT<SrcP> &newImg)
+{
+    if(numChannels == 0)
+    {
+        xsize = newImg.width();
+        ysize = newImg.height();
+        zsize = newImg.depth();
+    }
+    else
+    {
+        if( !(       newImg.width() == this->width()
+                     && newImg.height() == this->height()
+                     && newImg.depth() == this->depth() ) )
+        {
+            throw( " channelwise dimensions don't fit! Abort this crazy mixing of channels" );
+            return;
+        }
+    }
+
+    // add channel deep data references
+    // -> wrap this MultiChannelImage3D around the other data
+    const std::vector< P* > vecDataChannelPtrs = newImg.getDataPointer();
+    for( int c=0; c < vecDataChannelPtrs.size() ; ++c)
+        data.push_back( vecDataChannelPtrs[c] );
+
+    numChannels = data.size();
+
+}
+
 template<class P>
 MultiChannelImage3DT<P>::~MultiChannelImage3DT()
 {
@@ -233,16 +277,20 @@ MultiChannelImage3DT<P>::~MultiChannelImage3DT()
 template<class P>
 void MultiChannelImage3DT<P>::freeData()
 {
-  if ( data != NULL )
-  {
-    for ( uint i = 0 ; i < numChannels ; i++ )
-      if ( data[i] != NULL )
-        delete [] data[i];
+    if ( !data.empty())
+    {
+        for ( int i = 0 ; i < (int)data.size() ; i++ )
+            if ( data[i] != NULL )
+                delete [] data[i];
 
-    delete [] data;
+        data.clear();
+    }
+}
 
-    data = NULL;
-  }
+template<class P>
+void MultiChannelImage3DT<P>::freeShallowData()
+{
+    this->data.clear();
 }
 
 template<class P>
@@ -253,27 +301,14 @@ void MultiChannelImage3DT<P>::reInit( int _xsize, int _ysize, int _zsize, int _n
   ysize = _ysize;
   zsize = _zsize;
   numChannels = _numChannels;
-  data = new P *[numChannels];
-
-  for ( uint i = 0 ; i < numChannels; i++ )
-    data[i] = new P [xsize*ysize*zsize];
+  this->addChannel(numChannels);
 }
 
 template<class P>
 template<class SrcP>
 void MultiChannelImage3DT<P>::reInitFrom( const MultiChannelImage3DT<SrcP> & src )
 {
-  freeData();
-
-  xsize = src.width();
-  ysize = src.height();
-  zsize = src.depth();
-  numChannels = src.channels();
-
-  data = new P *[numChannels];
-
-  for ( uint i = 0 ; i < numChannels; i++ )
-    data[i] = new P [xsize*ysize*zsize];
+    this->reInit(src.width(),src.height(), src.depth(), src.channels() );
 }
 
 template<class P>
@@ -289,7 +324,7 @@ P MultiChannelImage3DT<P>::get( int x, int y, int z, uint channel ) const
 }
 
 template<class P>
-P ** MultiChannelImage3DT<P>::getDataPointer()
+std::vector<P*> MultiChannelImage3DT<P>::getDataPointer() const
 {
   return data;
 }

+ 48 - 30
core/vector/SparseVectorT.h

@@ -32,7 +32,7 @@ class SparseVectorT : public std::map<I, V>, public Persistent
 
   protected:
     //! dimension of the SparseVector, not properly implemented! FIXME
-    int dim;
+    uint dim;
     
 
   public:
@@ -42,26 +42,30 @@ class SparseVectorT : public std::map<I, V>, public Persistent
      * @param k position of the value
      * @param v value
      */
-    SparseVectorT ( I k, V v );
-    SparseVectorT ( const std::map<I, V> & mymap );
+    SparseVectorT ( I _k, 
+                    V _v
+                  );
+    SparseVectorT ( const std::map<I, V> & _mymap );
 
     /**
      * simple constructor -> does nothing
      */
-    SparseVectorT ():dim(-1) {}
+    SparseVectorT ():dim(0) {}
 
     /**
      * Constructor with the dimension
      * @param _dim dimension of the SparseVector
      */
-    SparseVectorT ( int _dim );
+    SparseVectorT ( uint _dim );
 
     /**
      * converts a ICE::Vector to a SparseVector with a tolerance factor
      * @param v input ICE::Vector
      * @param tolerance tolerance value
      */
-    SparseVectorT ( const NICE::Vector &v, double tolerance = 1e-15 );
+    SparseVectorT ( const NICE::Vector & _v, 
+                    double _tolerance = 1e-15
+                  );
 
     /**
      * simple destructor
@@ -72,44 +76,56 @@ class SparseVectorT : public std::map<I, V>, public Persistent
      * add the elements of a SparseVector to this SparseVector
      * @param v input SparseVector
      */
-    void add ( const SparseVectorT<I,V> & v );
+    void add ( const SparseVectorT<I,V> & _v );
 
     /**
      * add the elements of a SparseVector to this NICE::Vector and multiply each element with a constant lambda
      * @param v
      * @param lambda
      */
-    void add ( const SparseVectorT<I,V> & v, double lambda );
+    void add ( const SparseVectorT<I,V> & _v, 
+               double _lambda 
+             );
     
     /**
      * add to each element a constant
      * @param value
      */
-    void add ( V value );
+    void add ( V _value );
     
     /**
      * sub the elements of a SparseVector from this SparseVector
      * @param v input SparseVector
      */
-    void sub ( const SparseVectorT<I,V> & v );
+    void sub ( const SparseVectorT<I,V> & _v );
 
     /** add a sparse vector given as a STL map with integer values multiplied with a scalar to the current vector */
-    void addMap ( const std::map<int, int> & v, double lambda = 1.0 );
+    void addMap ( const std::map<uint, int> & _v, 
+                  double _lambda = 1.0
+                );
 
     /** add a sparse vector given as a STL map with double values multiplied with a scalar to the current vector */
-    void addMap ( const std::map<int, double> & v, double lambda = 1.0 );
+    void addMap ( const std::map<uint, double> & _v, 
+                  double _lambda = 1.0 
+                );
 
     /** normalize, such that all elements sum to one */
     void normalize ();
     
     /** normalize in given interval between maxv and minv */
-    void normalize (V minv, V maxv);
+    void normalize (V _minv, 
+                    V _maxv
+                   );
 
     /** read from a stream */
-    void restore ( std::istream & is, int format = 0 );
+    void restore ( std::istream & _is, 
+                   int _format = 0 
+                 );
 
     /** write to a stream */
-    void store ( std::ostream & os, int format = 0 ) const;
+    void store ( std::ostream & _os,
+                 int _format = 0 
+               ) const;
 
     /** clear the data of the vector */
     void clear ();
@@ -121,32 +137,32 @@ class SparseVectorT : public std::map<I, V>, public Persistent
      * each element of the SparseVector is multiplied by the elements of the input SparseVector
      * @param v input SparseVector
      */
-    void multiply ( const SparseVectorT<I,V> & v );
+    void multiply ( const SparseVectorT<I,V> & _v );
 
     /**
      * each element of the SparseVector is multiplied by a constant value
      * @param val factor
      */
-    void multiply ( V val );
+    void multiply ( V _val );
 
     /**
      * each element of the SparseVector is divided by the elements of the input SparseVector
      * @param v input SparseVector
      */
-    void divide ( const SparseVectorT<I,V> & v );
+    void divide ( const SparseVectorT<I,V> & _v );
 
     /**
      * each element of the SparseVector is divided by a constant value
      * @param v divisor
      */
-    void divide ( V v );
+    void divide ( V _v );
 
     /**
      * computes the inner product of two SparseVectors
      * @param v the second sparse vector
      * @return inner product
      */
-    double innerProduct ( const SparseVectorT<I,V> & v ) const;
+    double innerProduct ( const SparseVectorT<I,V> & _v ) const;
 
     /** get the sum of all elements */
     V sum () const;
@@ -164,25 +180,27 @@ class SparseVectorT : public std::map<I, V>, public Persistent
     I maxElementExclusive ( I key ) const;
 
     /** get all indices of elements with non-zero values as a sorted STL vector */
-    void getSortedIndices ( std::vector<I> & indizes ) const;
+    void getSortedIndices ( std::vector<I> & _indizes ) const;
 
     /** get an element */
-    V get ( I i ) const;
+    V get ( I _i ) const;
 
     /** set an element */
-    bool set ( I i , V newValue );
+    bool set ( I _i , 
+               V _newValue 
+             );
 
     /**
      * set the dimension of the SparseVector
      * @param _dim
      */
-    void setDim ( int _dim );
+    void setDim ( uint _dim );
 
     /**
      * returns the dimension of the SparseVector
      * @return dimension
      */
-    int getDim() const;
+    uint getDim() const;
     
     /**
     * @brief calculate the value of the minimum kernel
@@ -190,7 +208,7 @@ class SparseVectorT : public std::map<I, V>, public Persistent
     * @param b 2nd argument of the minimum kernel, which is symmetric
     * @return resulting value of the minimum kernel
     */
-    double minimumKernel ( const SparseVectorT<I,V> & b ) const;
+    double minimumKernel ( const SparseVectorT<I,V> & _b ) const;
 
     /** pick a random index by interpreting the elements of the vector as
         an unnormalized multinomial distribution */
@@ -200,12 +218,12 @@ class SparseVectorT : public std::map<I, V>, public Persistent
      * @brief computes a full NICE::VectorT from the current SparseVectorT object. the dimension has to be set properly for this method!
      * @param v resulting NICE::VectorT
      */
-    void convertToVectorT(NICE::VectorT<V> & v ) const ;     
+    void convertToVectorT(NICE::VectorT<V> & _v ) const ;     
 };
 
-typedef SparseVectorT<long, double> SparseVectorLong;
-typedef SparseVectorT<int, double> SparseVectorInt;
-typedef SparseVectorT<short, double> SparseVector;
+typedef SparseVectorT<unsigned long, double> SparseVectorLong;
+typedef SparseVectorT<unsigned int, double> SparseVectorInt;
+typedef SparseVectorT<unsigned short, double> SparseVector;
 
 } // namespace
 

+ 31 - 27
core/vector/SparseVectorT.tcc

@@ -27,20 +27,20 @@ SparseVectorT<I,V>::SparseVectorT ( const std::map<I, V> & mymap ):std::map<I, V
 template<typename I, typename V>
 SparseVectorT<I,V>::SparseVectorT ( I k, V v )
 {
-  this->insert ( std::pair<short, double> ( k, v ) );
-  dim = k;
+  this->insert ( std::pair<I, V> ( k, v ) );
+  this->dim = k;
 }
 
 template<typename I, typename V>
-SparseVectorT<I,V>::SparseVectorT ( int _dim ) : dim ( _dim )
+SparseVectorT<I,V>::SparseVectorT ( uint _dim ) : dim ( _dim )
 {
 }
 
 template<typename I, typename V>
 SparseVectorT<I,V>::SparseVectorT ( const NICE::Vector &v, double tolerance )
 {
-  dim = (int)v.size();
-  for ( int i = 0; i < dim; i++ )
+  this->dim = v.size();
+  for ( uint i = 0; i < dim; i++ )
   {
     if ( fabs ( v[i] ) > tolerance )
       this->insert ( std::pair<I, V> ( i, v[i] ) );
@@ -57,7 +57,7 @@ void SparseVectorT<I,V>::sub ( const SparseVectorT<I,V> & v )
 template<typename I, typename V>
 void SparseVectorT<I,V>::add ( const SparseVectorT<I,V> & v )
 {
-  add ( v, 1.0 );
+  this->add ( v, 1.0 );
 }
 
 template<typename I, typename V>
@@ -326,16 +326,16 @@ void SparseVectorT<I,V>::normalize ( V minv, V maxv )
 }
 
 template<typename I, typename V>
-void SparseVectorT<I,V>::addMap ( const std::map<int, int> & v, double lambda )
+void SparseVectorT<I,V>::addMap ( const std::map<uint, int> & v, double lambda )
 {
-  for ( std::map<int, int>::const_iterator v_it = v.begin(); v_it != v.end(); v_it++ )
+  for ( std::map<uint, int>::const_iterator v_it = v.begin(); v_it != v.end(); v_it++ )
     ( *this ) [(I)v_it->first] += (V)v_it->second * lambda;
 }
 
 template<typename I, typename V>
-void SparseVectorT<I,V>::addMap ( const std::map<int, double> & v, double lambda )
+void SparseVectorT<I,V>::addMap ( const std::map<uint, double> & v, double lambda )
 {
-  for ( std::map<int, double>::const_iterator v_it = v.begin(); v_it != v.end(); v_it++ )
+  for ( std::map<uint, double>::const_iterator v_it = v.begin(); v_it != v.end(); v_it++ )
     ( *this ) [(I)v_it->first] += (V)v_it->second * lambda;
 }
 
@@ -456,15 +456,15 @@ bool SparseVectorT<I,V>::set ( I i , V newValue )
 }
 
 template<typename I, typename V>
-void SparseVectorT<I,V>::setDim ( int _dim )
+void SparseVectorT<I,V>::setDim ( uint _dim )
 {
-  dim = _dim;
+  this->dim = _dim;
 }
 
 template<typename I, typename V>
-int SparseVectorT<I,V>::getDim() const
+uint SparseVectorT<I,V>::getDim() const
 {
-  return dim;
+  return this->dim;
 }
 
 template<typename I, typename V>
@@ -530,19 +530,23 @@ I SparseVectorT<I,V>::pickRandomSample() const
 template<typename I, typename V>
 void SparseVectorT<I,V>::convertToVectorT(NICE::VectorT<V> & v ) const
 {
-  int dimension (this->getDim());
-  //dimension flag was not set properly
-  if (dimension < 0)
+  uint dimension ( this->getDim() );
+
+  if ( dimension == 0 )
   {
-    typename SparseVectorT<I,V>::const_iterator i = this->end(); i--;
-    int dist (distance(this->begin(), this->end()) );
-    if (dist > 0)
-      dimension = i->first+1; //plus one, since this is the index, but we need the resulting size
+    // if dimension is zero, it could either be the case that the sparse vector is empty, or that the dimension flag was not set properly. 
+    // thus, let's check out the largest dimension
+    // could be removed later... only needed for backwards compatibility
+    typename SparseVectorT<I,V>::const_iterator svIt = this->end(); 
+    svIt--;
+    uint dist (distance(this->begin(), this->end()) );
+    if ( dist > 0 )
+      dimension = svIt->first+1; //plus one, since this is the index, but we need the resulting size
     //we're not allowed here to set the dimension flag, since we want to have this method to be a const one
   }
 
-  //our sparse vector is empty
-  if (dimension <= 0)
+  // is our sparse vector empty?
+  if ( dimension == 0 )
   {
     v.clear();
     v.resize(0);
@@ -556,12 +560,12 @@ void SparseVectorT<I,V>::convertToVectorT(NICE::VectorT<V> & v ) const
   v.set( (V) 0.0);
 
   //add the actual content
-  typename SparseVectorT<I,V>::const_iterator i = this->begin();
-  for ( ; i != this->end(); i++ )
+  typename SparseVectorT<I,V>::const_iterator svIt = this->begin();
+  for ( ; svIt != this->end(); svIt++ )
   {
     //just to be sure that we do not get some errors due to badly set dimension flags
-    if (i->first < dimension)
-      v[i->first] = i->second;
+    if (svIt->first < dimension)
+      v[svIt->first] = svIt->second;
   }
 }
 

+ 31 - 0
core/vector/tests/TestSparseVector.cpp

@@ -19,6 +19,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( TestSparseVector );
 using namespace NICE;
 using namespace std;
 
+const bool b_verbose = false;
+
 void TestSparseVector::testProducts()
 {
   SparseVector v1;
@@ -41,7 +43,13 @@ void TestSparseVector::testProducts()
   SparseVector v3;
   v3.restore ( iss );
   
+  if ( b_verbose )
+    std::cerr << "TestSparseVector::testProducts -- check1 v3 == v1 " << std::endl;
+  
   CPPUNIT_ASSERT ( v3 == v1 );
+  
+  if ( b_verbose )
+    std::cerr << "TestSparseVector::testProducts -- check1 v3 == v1 passed" << std::endl;
 
   //cerr << "Testing SparseVector::FORMAT_INDEX_LINE" << endl;
   stringstream ss;
@@ -50,8 +58,14 @@ void TestSparseVector::testProducts()
   v3.clear();
   v3.restore ( ss, SparseVector::FORMAT_INDEX_LINE );
 
+  if ( b_verbose )
+    std::cerr << "TestSparseVector::testProducts -- check2 v3 == v1 " << std::endl;
+  
   CPPUNIT_ASSERT ( v3 == v1 );
   
+  if ( b_verbose )
+    std::cerr << "TestSparseVector::testProducts -- check2 v3 == v1 passed" << std::endl;
+  
   //cerr << "Testing SparseVector::FORMAT_INDEX" << endl;
   stringstream ss2;
   v1.store( ss2, SparseVector::FORMAT_INDEX );
@@ -59,7 +73,13 @@ void TestSparseVector::testProducts()
   v3.clear();
   v3.restore ( ss2, SparseVector::FORMAT_INDEX );
 
+  if ( b_verbose )
+    std::cerr << "TestSparseVector::testProducts -- check3 v3 == v1" << std::endl;
+  
   CPPUNIT_ASSERT ( v3 == v1 );
+  
+  if ( b_verbose )
+    std::cerr << "TestSparseVector::testProducts -- check3 v3 == v1 passed" << std::endl;
 
 }
 
@@ -77,7 +97,18 @@ void TestSparseVector::testConversionToVectorT()
   NICE::Vector vGT(5);
   vGT[0] = 0.5;vGT[1] = 1.0;vGT[2] = 0.0;vGT[3] = 0.1;vGT[4] = 2.0;
    
+  if ( b_verbose )
+  {
+    std::cerr << "TestSparseVector::testConversionToVectorT -- v == vGT" << std::endl;
+  
+    std::cerr << v << std::endl;
+    std::cerr << vGT << std::endl;
+  }
+  
   CPPUNIT_ASSERT ( v == vGT );
+  
+  if ( b_verbose )
+    std::cerr << "TestSparseVector::testConversionToVectorT -- v == vGT passed" << std::endl;
 }
 
 #endif