瀏覽代碼

making LocalFeature persistent

Alexander Freytag 11 年之前
父節點
當前提交
f89fce3ff7

+ 59 - 14
features/localfeatures/LocalFeature.h

@@ -8,31 +8,51 @@
 #ifndef LOCALFEATUREINCLUDE
 #define LOCALFEATUREINCLUDE
 
-#include "core/vector/VectorT.h"
-#include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-
-#include "core/vector/VVector.h"
+// nice-core includes
+#include <core/basics/Config.h>
+#include <core/basics/Persistent.h>
+// 
+#include <core/image/ImageT.h>
+// 
+#include <core/vector/MatrixT.h>
+#include <core/vector/VectorT.h>
+#include <core/vector/VVector.h>
   
 
 namespace OBJREC {
 
-    /** @class LocalFeature
-  * @brief Abstract class for Local Features ( ONLY DESCRIPTORS, NO DETECTORS )
-  *
-  */
-  class LocalFeature
-  {
+/** @class LocalFeature
+* @brief Abstract class for Local Features ( ONLY DESCRIPTORS, NO DETECTORS )
+*
+*/
+class LocalFeature : public NICE::Persistent
+{
 
-      protected:
+  protected:
 
-      public:
+  public:
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////      
     
     /** simple constructor */
     LocalFeature();
         
     /** simple destructor */
     virtual ~LocalFeature();
+    
+    /** 
+     * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mm-yyyy )
+     */    
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LocalFeature") = 0;     
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                      FEATURE STUFF
+    ///////////////////// ///////////////////// //////////////////
+    
 
     virtual int getDescSize() const = 0;
 
@@ -43,8 +63,33 @@ namespace OBJREC {
     virtual void visualizeFeatures ( NICE::Image & mark,
           const NICE::VVector & positions,
           size_t color ) const;
+          
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+
+    /**
+    * @brief Load object from external file (stream)
+    * @author Alexander Freytag
+    * @date 09-02-2014 ( dd-mm-yyyy )
+    */
+    void restore ( std::istream & is, int format = 0 ) = 0;
+
+    /**
+    * @brief Save object to external file (stream)
+    * @author Alexander Freytag
+    * @date 09-02-2014 ( dd-mm-yyyy )
+    */
+    void store ( std::ostream & os, int format = 0 ) const = 0;
+
+    /**
+    * @brief Clear object
+    * @author Alexander Freytag
+    * @date 09-02-2014 ( dd-mm-yyyy )
+    */
+    void clear () = 0;           
       
-  };
+};
 
 
 } // namespace

+ 97 - 18
features/localfeatures/LocalFeatureCentrist.cpp

@@ -176,35 +176,34 @@ void LocalFeatureCentrist::computeDesc( const NICE::ColorImage & img, NICE::VVec
 
 /* public methods*/
 
-/**
- * @brief Default constructor
- * @author Alexander Freytag
- * @date 12/06/2011
- */
-LocalFeatureCentrist::LocalFeatureCentrist()
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+LocalFeatureCentrist::LocalFeatureCentrist() : LocalFeature () 
 {
   this->i_sizeNeighborhood = 16;
 }
 
-/**
- * @brief Recommended constructor
- * @author Alexander Freytag
- * @date 12/06/2011
- */
-LocalFeatureCentrist::LocalFeatureCentrist( const Config *conf, const std::string & section )
+
+LocalFeatureCentrist::LocalFeatureCentrist( const NICE::Config * _conf )
 {
-  this->i_sizeNeighborhood = conf->gI(section, "i_sizeNeighborhood", 16);
+  this->initFromConfig( _conf );
 }
 
-/**
- * @brief Default destructor
- * @author Alexander Freytag
- * @date 12/06/2011
- */
 LocalFeatureCentrist::~LocalFeatureCentrist()
 {
 }
 
+void OBJREC::LocalFeatureCentrist::initFromConfig( const NICE::Config* _conf, const std::string& _confSection )
+{
+  this->i_sizeNeighborhood = _conf->gI(_confSection, "i_sizeNeighborhood", 16);
+}
+
+///////////////////// ///////////////////// /////////////////////
+//                      FEATURE STUFF
+///////////////////// ///////////////////// ////////////////// 
+
 int LocalFeatureCentrist::getDescSize() const
 {
   // we have 8 neighbors, so the size is always 256 with the given implementation (without spatial levels, ...)
@@ -245,3 +244,83 @@ void LocalFeatureCentrist::visualizeFeatures ( NICE::Image & mark,
   throw NICE::Exception ( "LocalFeatureCentrist::visualizeFeatures -- currently not implemented." );
 }
 
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
+
+void LocalFeatureCentrist::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "LocalFeatureCentrist" ) )
+    {
+      std::cerr << " WARNING - attempt to restore LocalFeatureCentrist, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "LocalFeatureCentrist" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );    
+      
+      if ( tmp.compare("i_sizeNeighborhood") == 0 )
+      {
+        is >> this->i_sizeNeighborhood;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }      
+      else
+      {
+      std::cerr << "WARNING -- unexpected LocalFeatureCentrist object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "LocalFeatureCentrist::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void LocalFeatureCentrist::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "LocalFeatureCentrist" ) << std::endl;    
+    
+    os << this->createStartTag( "i_sizeNeighborhood" ) << std::endl;
+    os << this->i_sizeNeighborhood << std::endl;
+    os << this->createEndTag( "i_sizeNeighborhood" ) << std::endl;     
+    
+    // done
+    os << this->createEndTag( "LocalFeatureCentrist" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void LocalFeatureCentrist::clear ()
+{
+}
+

+ 91 - 26
features/localfeatures/LocalFeatureCentrist.h

@@ -8,6 +8,7 @@
 #ifndef CENTRISTINCLUDE
 #define CENTRISTINCLUDE
 
+// nice-core includes
 #include <core/basics/Config.h>
 // 
 #include <core/image/ImageT.h>
@@ -27,38 +28,102 @@ namespace OBJREC {
 class LocalFeatureCentrist : public LocalFeature
 {
 
-    protected:
-      int i_sizeNeighborhood;
+  protected:
       
-      int CensusTransform(const NICE::Image & img, const int & x, const int & y) const;
-      int CensusTransform(const NICE::ColorImage & img, const int & x, const int & y, const int & channel) const;
+    /////////////////////////
+    /////////////////////////
+    // PROTECTED VARIABLES //
+    /////////////////////////
+    /////////////////////////  
       
-      void GenerateHistForOneRect(const NICE::Image & img, const int & xi, const int & xa, const int & yi, const int & ya, NICE::Vector & feature) const;
-      void GenerateHistForOneRect(const NICE::ColorImage & img, const int & xi, const int & xa, const int & yi, const int & ya, NICE::Vector & feature) const;
+    int i_sizeNeighborhood;
       
-      void computeDesc( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
-      void computeDesc( const NICE::ColorImage & img, NICE::VVector & positions, NICE::VVector & descriptors )  const;
+    /////////////////////////
+    /////////////////////////
+    //  PROTECTED METHODS  //
+    /////////////////////////
+    /////////////////////////         
+      
+    int CensusTransform(const NICE::Image & img, const int & x, const int & y) const;
+    int CensusTransform(const NICE::ColorImage & img, const int & x, const int & y, const int & channel) const;
+    
+    void GenerateHistForOneRect(const NICE::Image & img, const int & xi, const int & xa, const int & yi, const int & ya, NICE::Vector & feature) const;
+    void GenerateHistForOneRect(const NICE::ColorImage & img, const int & xi, const int & xa, const int & yi, const int & ya, NICE::Vector & feature) const;
+    
+    void computeDesc( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
+    void computeDesc( const NICE::ColorImage & img, NICE::VVector & positions, NICE::VVector & descriptors )  const;
 
-    public:
-  
-      /** simple constructor */
-      LocalFeatureCentrist();
-      /** default constructor */
-      LocalFeatureCentrist(const NICE::Config *conf, const std::string & section="CENTRIST");
-          
-      /** simple destructor */
-      virtual ~LocalFeatureCentrist();
+  public:
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////     
+    
+    /** 
+     * @brief default constructor
+     * @date 09-02-2014 (dd-mm-yyyy )
+     * @author Alexander Freytag
+     */
+    LocalFeatureCentrist ( );    
+    
+    /**
+     * @brief recommended constructor, calls initFromConfig
+     * @date 09-02-2014 (dd-mm-yyyy )
+     * @author Alexander Freytag
+     */
+    LocalFeatureCentrist ( const NICE::Config * _conf );
 
-      /** Beware: multiply this number by the number of channels you use in your color image*/
-      virtual int getDescSize() const;
+    /**
+     * @brief simple destructor
+     */
+    virtual ~LocalFeatureCentrist();
+    
+    /** 
+     * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mm-yyyy )
+     */    
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "CENTRIST");    
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                      FEATURE STUFF
+    ///////////////////// ///////////////////// //////////////////       
 
-      virtual int getDescriptors ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors) const;
-      
-      virtual int getDescriptors ( const NICE::ColorImage & img, NICE::VVector & positions, NICE::VVector & descriptors) const;
-      
-      virtual void visualizeFeatures ( NICE::Image & mark,
-            const NICE::VVector & positions,
-            size_t color ) const;
+    /** Beware: multiply this number by the number of channels you use in your color image*/
+    virtual int getDescSize() const;
+
+    virtual int getDescriptors ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors) const;
+    
+    virtual int getDescriptors ( const NICE::ColorImage & img, NICE::VVector & positions, NICE::VVector & descriptors) const;
+    
+    virtual void visualizeFeatures ( NICE::Image & mark,
+          const NICE::VVector & positions,
+          size_t color ) const;
+          
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */     
+    virtual void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */       
+    virtual void store( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear  object
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */    
+    virtual void clear ();            
     
 };
 

+ 9 - 2
features/localfeatures/LocalFeatureColorWeijer.cpp

@@ -32,7 +32,11 @@ const int colors[11][3] =
   {255, 255,   0}, // yellow
 };
 
-OBJREC::LocalFeatureColorWeijer::LocalFeatureColorWeijer()
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+OBJREC::LocalFeatureColorWeijer::LocalFeatureColorWeijer() : LocalFeature () 
 {
   this->tfile = "";
 }
@@ -70,6 +74,10 @@ void LocalFeatureColorWeijer::initFromConfig ( const NICE::Config * _conf, const
   this->restoreLUT();  
 }
 
+///////////////////// ///////////////////// /////////////////////
+//                      FEATURE STUFF
+///////////////////// ///////////////////// ////////////////// 
+
 int LocalFeatureColorWeijer::getDescSize() const
 {
   return LASTCOLOR;
@@ -367,5 +375,4 @@ void LocalFeatureColorWeijer::store ( std::ostream & os, int format ) const
 
 void LocalFeatureColorWeijer::clear ()
 {
- //TODO
 }

+ 10 - 3
features/localfeatures/LocalFeatureColorWeijer.h

@@ -9,7 +9,6 @@
 
 // nice-core includes
 #include <core/basics/Config.h>
-#include <core/basics/Persistent.h>
 // 
 #include <core/image/ImageT.h>
 #include <core/image/MultiChannelImageT.h>
@@ -26,7 +25,7 @@
 namespace OBJREC {
 
 /** interface to ColorSande implementation */
-class LocalFeatureColorWeijer : public LocalFeature, public NICE::Persistent //TODO move Persistent inheritence to LocalFeature
+class LocalFeatureColorWeijer : public LocalFeature
 {
 
   protected:
@@ -55,6 +54,10 @@ class LocalFeatureColorWeijer : public LocalFeature, public NICE::Persistent //T
     
   public:
 
+
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////   
     
     /** 
      * @brief default constructor 
@@ -80,8 +83,12 @@ class LocalFeatureColorWeijer : public LocalFeature, public NICE::Persistent //T
      * @author Alexander Freytag
      * @date 06-02-2014 ( dd-mm-yyyy )
      */    
-    void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LocalFeatureColorWeijer");
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LocalFeatureColorWeijer");
 
+    ///////////////////// ///////////////////// /////////////////////
+    //                      FEATURE STUFF
+    ///////////////////// ///////////////////// //////////////////    
+    
     /**
      * get the size of the descriptor
      * @return size of descriptor

+ 115 - 5
features/localfeatures/LocalFeatureLFInterface.cpp

@@ -1,23 +1,46 @@
 #include <iostream>
-
 #include <assert.h>
 
-#include "vislearning/features/localfeatures/LocalFeatureLFInterface.h"
+#include "LocalFeatureLFInterface.h"
 
 using namespace OBJREC;
 using namespace std;
 using namespace NICE;
 
-LocalFeatureLFInterface::LocalFeatureLFInterface( const Config *conf, LocalFeatureRepresentation *_lfpres )
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+LocalFeatureLFInterface::LocalFeatureLFInterface() : LocalFeature () 
 {
-  lfpres = _lfpres;
+  this->lfpres = NULL;
+}
+
+LocalFeatureLFInterface::LocalFeatureLFInterface( const NICE::Config * _conf, LocalFeatureRepresentation *_lfpres )
+{
+  this->initFromConfig( _conf );
+
+  //TODO check for null pointers? where will deletion be performed? what about restoring those objects?  
+  this->lfpres = _lfpres;
 }
 
 LocalFeatureLFInterface::~LocalFeatureLFInterface()
 {
-  delete lfpres;
+  if ( this->lfpres != NULL )
+    delete lfpres;
+  this->lfpres = NULL;
+}
+
+void LocalFeatureLFInterface::initFromConfig( const NICE::Config* _conf, const std::string& _confSection )
+{
+  //nothing to do here
+  //NOTE how to handle lfrep object? - separate set method?
 }
 
+///////////////////// ///////////////////// /////////////////////
+//                      FEATURE STUFF
+///////////////////// ///////////////////// ////////////////// 
+
 
 int LocalFeatureLFInterface::getDescriptors ( const NICE::Image & img, VVector & positions, VVector & descriptors ) const
 {
@@ -43,3 +66,90 @@ void LocalFeatureLFInterface::visualizeFeatures ( NICE::Image & mark,
   lfpres->visualizeFeatures(mark, positions, color);
 }
 
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
+
+void LocalFeatureLFInterface::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "LocalFeatureLFInterface" ) )
+    {
+      std::cerr << " WARNING - attempt to restore LocalFeatureLFInterface, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "LocalFeatureLFInterface" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );    
+      
+      ///////////////////////////////
+      //       PARENT OBJECT       //
+      ///////////////////////////////
+      if ( tmp.compare("lfpres") == 0 )
+      {
+        // restore parent object
+        //TODO this->lfpres->restore ( is );
+      }      
+      else
+      {
+      std::cerr << "WARNING -- unexpected LocalFeatureOpponnentSift object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "LocalFeatureOpponnentSift::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void LocalFeatureLFInterface::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "LocalFeatureLFInterface" ) << std::endl;    
+        
+    ///////////////////////////////
+    //       PARENT OBJECT       //
+    ///////////////////////////////
+    os << this->createStartTag( "lfpres" ) << std::endl;
+    //TODO this->lfpres->store(os);  
+    os << this->createStartTag( "lfpres" ) << std::endl;   
+    
+    // done
+    os << this->createEndTag( "LocalFeatureLFInterface" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void LocalFeatureLFInterface::clear ()
+{
+  if ( this->lfpres != NULL )
+    delete lfpres;
+  this->lfpres = NULL;  
+}

+ 75 - 18
features/localfeatures/LocalFeatureLFInterface.h

@@ -1,18 +1,22 @@
 /** 
 * @file LocalFeatureLFInterface.h
 * @brief Interface to use a LocalFeature (Descriptor only) with routines of LocalFeatureRepresentations (Detector + Descriptor)
-* @author Björn Fröhlich
+* @author Björn Fröhlich, Alexander Freytag
 * @date 09/07/2010
 
 */
 #ifndef LocalFeatureLFInterfaceINCLUDE
 #define LocalFeatureLFInterfaceINCLUDE
 
-#include "core/vector/VectorT.h"
-#include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
+// nice-core includes
+#include <core/basics/Config.h>
+// 
+#include <core/image/ImageT.h>
+// 
+#include <core/vector/VectorT.h>
+#include <core/vector/MatrixT.h>
 
-#include "core/basics/Config.h"
+// nice-vislearning includes
 #include "LocalFeature.h"
 #include "LocalFeatureRepresentation.h"
 
@@ -20,25 +24,53 @@
 namespace OBJREC {
 
 
-  /** @class LocalFeatureLFInterface
-  * @brief Interface to use a LocalFeature (Descriptor only) with routines of LocalFeatureRepresentations (Detector + Descriptor)
-  *
-  */  
-  class LocalFeatureLFInterface : public LocalFeature
-  {
+/** @class LocalFeatureLFInterface
+* @brief Interface to use a LocalFeature (Descriptor only) with routines of LocalFeatureRepresentations (Detector + Descriptor)
+*
+*/  
+class LocalFeatureLFInterface : public LocalFeature
+{
 
-      protected:
-      LocalFeatureRepresentation *lfpres;
+    protected:
+    LocalFeatureRepresentation *lfpres;
+
+    public:
 
-      public:
-    
-    /** simple constructor */
-      LocalFeatureLFInterface ( const NICE::Config *conf, LocalFeatureRepresentation *_lfpres );
         
-    /** simple destructor */
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////   
+    
+    /** 
+     * @brief default constructor 
+     * @author Alexander Freytag
+     * @date 06-02-2014 ( dd-mm-yyyy )
+     */
+    LocalFeatureLFInterface ( );
+    
+    /** 
+     * @brief recommended constructor, calls initFromConfig
+     * @author Alexander Freytag
+     * @date 06-02-2014 ( dd-mm-yyyy )
+     */
+    LocalFeatureLFInterface ( const NICE::Config * _conf, LocalFeatureRepresentation *_lfpres );
 
+    /** 
+     * @brief simple destructor
+     */
     virtual ~LocalFeatureLFInterface();
     
+    /** 
+     * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
+     * @author Alexander Freytag
+     * @date 06-02-2014 ( dd-mm-yyyy )
+     */    
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LocalFeatureLFInterface");
+
+    ///////////////////// ///////////////////// /////////////////////
+    //                      FEATURE STUFF
+    ///////////////////// ///////////////////// //////////////////        
+    
     /**
     * @brief returns the size of each the SIFT-Feature
     */
@@ -63,6 +95,31 @@ namespace OBJREC {
     int getDescriptors ( const NICE::ColorImage & img, NICE::VVector & positions, NICE::VVector & descriptors) const;
               
     void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
+    
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */     
+    virtual void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */       
+    virtual void store( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear  object
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */    
+    virtual void clear ();     
 
       
   };

+ 107 - 1
features/localfeatures/LocalFeatureOpponnentSift.cpp

@@ -7,14 +7,33 @@ using namespace OBJREC;
 using namespace std;
 using namespace NICE;
 
-LocalFeatureOpponnentSift::LocalFeatureOpponnentSift ( const Config *conf ) : LocalFeatureRGBSift ( conf )
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+LocalFeatureOpponnentSift::LocalFeatureOpponnentSift() : LocalFeatureRGBSift () 
+{
+}
+
+LocalFeatureOpponnentSift::LocalFeatureOpponnentSift ( const NICE::Config * _conf )
 {
+  this->initFromConfig( _conf );  
 }
 
 LocalFeatureOpponnentSift::~LocalFeatureOpponnentSift()
 {
 }
 
+void LocalFeatureOpponnentSift::initFromConfig( const NICE::Config* _conf, const std::string& _confSection )
+{
+  //first of all, call method of parent object
+  LocalFeatureRGBSift::initFromConfig( _conf );
+}
+
+///////////////////// ///////////////////// /////////////////////
+//                      FEATURE STUFF
+///////////////////// ///////////////////// ////////////////// 
+
 int LocalFeatureOpponnentSift::getDescriptors ( const NICE::ColorImage & cimg,
     VVector & positions,
     VVector & descriptors ) const
@@ -41,3 +60,90 @@ int LocalFeatureOpponnentSift::getDescriptors ( const NICE::ColorImage & cimg,
 
   return LocalFeatureRGBSift::getDescriptors ( opimg, positions, descriptors );
 }
+
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
+
+void LocalFeatureOpponnentSift::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "LocalFeatureOpponnentSift" ) )
+    {
+      std::cerr << " WARNING - attempt to restore LocalFeatureOpponnentSift, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "LocalFeatureOpponnentSift" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );    
+      
+      ///////////////////////////////
+      //       PARENT OBJECT       //
+      ///////////////////////////////
+      if ( tmp.compare("LocalFeatureRGBSift--Parent") == 0 )
+      {
+        // restore parent object
+        LocalFeatureRGBSift::restore(is);
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );        
+      }      
+      else
+      {
+      std::cerr << "WARNING -- unexpected LocalFeatureOpponnentSift object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "LocalFeatureOpponnentSift::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void LocalFeatureOpponnentSift::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "LocalFeatureOpponnentSift" ) << std::endl;    
+        
+    ///////////////////////////////
+    //       PARENT OBJECT       //
+    ///////////////////////////////
+    os << this->createStartTag( "LocalFeatureRGBSift--Parent" ) << std::endl;
+    LocalFeatureRGBSift::store(os);  
+    os << this->createStartTag( "LocalFeatureRGBSift--Parent" ) << std::endl;   
+    
+    // done
+    os << this->createEndTag( "LocalFeatureOpponnentSift" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void LocalFeatureOpponnentSift::clear ()
+{
+}

+ 89 - 16
features/localfeatures/LocalFeatureOpponnentSift.h

@@ -1,20 +1,27 @@
 /**
  * @file LocalFeatureOpponnentSift.h
  * @brief local feature with color sift
- * @author Björn Fröhlich
+ * @author Björn Fröhlich, Alexander Freytag
  * @date 03/08/2010
 
  */
 #ifndef LocalFeatureOpponnentSiftINCLUDE
 #define LocalFeatureOpponnentSiftINCLUDE
 
-#include "core/vector/VectorT.h"
-#include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
+// nice-core includes
+#include <core/basics/Config.h>
+// 
+#include <core/image/ImageT.h>
+// 
+#include <core/imagedisplay/ImageDisplay.h>
+// 
+#include <core/vector/VectorT.h>
+#include <core/vector/MatrixT.h>
 
-#include "core/basics/Config.h"
-#include "vislearning/features/localfeatures/LocalFeatureRGBSift.h"
+
+
+// nice-vislearning includes
+#include "LocalFeatureRGBSift.h"
 
 
 namespace OBJREC
@@ -25,20 +32,60 @@ class LocalFeatureOpponnentSift : public LocalFeatureRGBSift
 {
 
   protected:
-    int octaves;
-    int levels;
-    bool normalizeFeature;
-    int first_octave;
-    double magnif;
+    
+    /////////////////////////
+    /////////////////////////
+    // PROTECTED VARIABLES //
+    /////////////////////////
+    /////////////////////////     
+    
+//TODO check why those member variables have been declared here originally. In the source code, they're not used at all...    
+//     int octaves;
+//     
+//     int levels;
+//     
+//     bool normalizeFeature;
+//     
+//     int first_octave;
+//     
+//     double magnif;
 
   public:
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////   
 
-    /** simple constructor */
-    LocalFeatureOpponnentSift ( const NICE::Config *conf );
-
-    /** simple destructor */
+    /** 
+     * @brief default constructor
+     * @date 09-02-2014 (dd-mm-yyyy )
+     * @author Alexander Freytag
+     */
+    LocalFeatureOpponnentSift ( );    
+    
+    /**
+     * @brief recommended constructor, calls initFromConfig
+     * @date 09-02-2014 (dd-mm-yyyy )
+     * @author Alexander Freytag
+     */
+    LocalFeatureOpponnentSift ( const NICE::Config * _conf );
 
+    /**
+     * @brief simple destructor
+     */
     virtual ~LocalFeatureOpponnentSift();
+    
+    /** 
+     * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mm-yyyy )
+     */    
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LocalFeatureOpponnentSift");     
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                      FEATURE STUFF
+    ///////////////////// ///////////////////// //////////////////     
+
 
     /**
      * get the descriptor
@@ -48,6 +95,32 @@ class LocalFeatureOpponnentSift : public LocalFeatureRGBSift
      * @return 0
      */
     int getDescriptors ( const NICE::ColorImage & cimg, NICE::VVector & positions, NICE::VVector & descriptors ) const;
+    
+                                 
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */     
+    virtual void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */       
+    virtual void store( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear  object
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */    
+    virtual void clear ();      
 };
 
 

+ 130 - 14
features/localfeatures/LocalFeatureRGBSift.cpp

@@ -12,20 +12,42 @@ using namespace std;
 using namespace NICE;
 
 
-LocalFeatureRGBSift::LocalFeatureRGBSift ( const Config *conf ) : LocalFeatureSift ( conf )
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+LocalFeatureRGBSift::LocalFeatureRGBSift() : LocalFeatureSift () 
+{
+  //set deletemode variable of partent object
+  this->deletemode = false;
+}
+
+LocalFeatureRGBSift::LocalFeatureRGBSift ( const NICE::Config * _conf )
 {
-  deletemode = false;
+  this->initFromConfig( _conf );  
 }
 
 LocalFeatureRGBSift::~LocalFeatureRGBSift()
 {
+}
 
+void LocalFeatureRGBSift::initFromConfig( const NICE::Config* _conf, const std::string& _confSection )
+{
+  //first of all, call method of parent object
+  LocalFeatureSift::initFromConfig( _conf );
+  
+  //set deletemode variable of partent object
+  this->deletemode = false;  
 }
 
+///////////////////// ///////////////////// /////////////////////
+//                      FEATURE STUFF
+///////////////////// ///////////////////// ////////////////// 
+
 int
 LocalFeatureRGBSift::getDescriptors ( const NICE::ColorImage & img, VVector & positions, VVector & descriptors ) const
 {
-  sortPositions ( positions );
+  this->sortPositions ( positions );
   descriptors.clear();
   for ( int i = 0; i < ( int ) positions.size(); i++ )
   {
@@ -33,13 +55,13 @@ LocalFeatureRGBSift::getDescriptors ( const NICE::ColorImage & img, VVector & po
     descriptors.push_back ( v );
   }
 
-  vector<VVector> desc ( 3 );
+  std::vector< NICE::VVector > desc ( 3 );
 
 #ifdef NICE_USELIB_OPENMP
   // check whether siftGPU should be used
   int numberOfCPU = omp_get_num_procs();
   int numberOfThreads = 0;
-  if ( isGpuUsed() )
+  if ( this->isGpuUsed() )
   {
     // in case of siftGPU it is possible to use one device
     numberOfThreads = 1;
@@ -54,30 +76,37 @@ LocalFeatureRGBSift::getDescriptors ( const NICE::ColorImage & img, VVector & po
 #endif
 
 #pragma omp parallel for num_threads(numberOfThreads)
-  for ( int i = 0; i < 3; i++ ) {
+  for ( int i = 0; i < 3; i++ )
+  {
     NICE::Image tmp ( img.width(), img.height() );
 
-    for ( int y = 0; y < img.height(); y++ ) {
-      for ( int x = 0; x < img.width(); x++ ) {
+    for ( int y = 0; y < img.height(); y++ )
+    {
+      for ( int x = 0; x < img.width(); x++ )
+      {
         tmp.setPixel ( x, y, img.getPixel ( x, y, i ) );
       }
     }
-    VVector pos = positions;
-    computeDesc ( tmp, pos, desc[i] );
+    NICE::VVector pos = positions;
+    this->computeDesc ( tmp, pos, desc[i] );
   }
 
-  for ( int i = 0; i < 3; i++ ) {
+  for ( int i = 0; i < 3; i++ )
+  {
     assert ( desc[i].size() == descriptors.size() );
 
     if ( i == 0 ) {
 #pragma omp parallel for num_threads( numberOfCPU )
-      for ( int j = 0; j < ( int ) desc[i].size(); j++ ) {
+      for ( int j = 0; j < ( int ) desc[i].size(); j++ )
+      {
         descriptors[j] = desc[i][j];
       }
     }
-    else {
+    else 
+    {
 #pragma omp parallel for num_threads( numberOfCPU )
-      for ( int j = 0; j < ( int ) desc[i].size(); j++ ) {
+      for ( int j = 0; j < ( int ) desc[i].size(); j++ )
+      {
         descriptors[j].append ( desc[i][j] );
       }
     }
@@ -85,3 +114,90 @@ LocalFeatureRGBSift::getDescriptors ( const NICE::ColorImage & img, VVector & po
 
   return positions.size();
 }
+
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
+
+void LocalFeatureRGBSift::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "LocalFeatureRGBSift" ) )
+    {
+      std::cerr << " WARNING - attempt to restore LocalFeatureRGBSift, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "LocalFeatureRGBSift" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );    
+      
+      ///////////////////////////////
+      //       PARENT OBJECT       //
+      ///////////////////////////////
+      if ( tmp.compare("LocalFeatureSift--Parent") == 0 )
+      {
+        // restore parent object
+        LocalFeatureSift::restore(is);
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );        
+      }      
+      else
+      {
+      std::cerr << "WARNING -- unexpected LocalFeatureRGBSift object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "LocalFeatureRGBSift::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void LocalFeatureRGBSift::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "LocalFeatureRGBSift" ) << std::endl;    
+        
+    ///////////////////////////////
+    //       PARENT OBJECT       //
+    ///////////////////////////////
+    os << this->createStartTag( "LocalFeatureSift--Parent" ) << std::endl;
+    LocalFeatureSift::store(os);  
+    os << this->createStartTag( "LocalFeatureSift--Parent" ) << std::endl;   
+    
+    // done
+    os << this->createEndTag( "LocalFeatureRGBSift" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void LocalFeatureRGBSift::clear ()
+{
+}

+ 85 - 15
features/localfeatures/LocalFeatureRGBSift.h

@@ -1,19 +1,24 @@
 /**
 * @file LocalFeatureRGBSift.h
 * @brief local feature with color sift
-* @author Björn Fröhlich
+* @author Björn Fröhlich, Alexander Freytag
 * @date 03/10/2012 (Eric Bach)
 */
 
 #ifndef LocalFeatureRGBSiftINCLUDE
 #define LocalFeatureRGBSiftINCLUDE
 
-#include "core/vector/VectorT.h"
-#include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
+// nice-core includes
+#include <core/basics/Config.h>
+// 
+#include <core/image/ImageT.h>
+// 
+#include <core/vector/VectorT.h>
+#include <core/vector/MatrixT.h>
 
-#include "core/basics/Config.h"
-#include "vislearning/features/localfeatures/LocalFeatureSift.h"
+
+// nice-vislearning includes
+#include "LocalFeatureSift.h"
 
 namespace OBJREC {
 
@@ -22,20 +27,60 @@ class LocalFeatureRGBSift : public LocalFeatureSift
 {
 
   protected:
-    int octaves;
-    int levels;
-    bool normalizeFeature;
-    int first_octave;
-    double magnif;
+    
+    /////////////////////////
+    /////////////////////////
+    // PROTECTED VARIABLES //
+    /////////////////////////
+    /////////////////////////  
+    
+    //TODO check why those member variables have been declared here originally. In the source code, they're not used at all...
+//     int octaves;
+//     
+//     int levels;
+//     
+//     bool normalizeFeature;
+//     
+//     int first_octave;
+//     
+//     double magnif;
 
   public:
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////   
 
-    /** simple constructor */
-    LocalFeatureRGBSift ( const NICE::Config *conf );
-
-    /** simple destructor */
+    /** 
+     * @brief default constructor
+     * @date 09-02-2014 (dd-mm-yyyy )
+     * @author Alexander Freytag
+     */
+    LocalFeatureRGBSift ( );    
+    
+    /**
+     * @brief recommended constructor, calls initFromConfig
+     * @date 09-02-2014 (dd-mm-yyyy )
+     * @author Alexander Freytag
+     */
+    LocalFeatureRGBSift ( const NICE::Config * _conf );
 
+    /**
+     * @brief simple destructor
+     */
     virtual ~LocalFeatureRGBSift();
+    
+    /** 
+     * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mm-yyyy )
+     */    
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LocalFeatureRGBSift");     
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                      FEATURE STUFF
+    ///////////////////// ///////////////////// //////////////////     
+
 
     /**
      * returns the size of each the SIFT-Feature
@@ -55,6 +100,31 @@ class LocalFeatureRGBSift : public LocalFeatureSift
     virtual int getDescriptors ( const NICE::ColorImage & cimg,
                                  NICE::VVector & positions,
                                  NICE::VVector & descriptors ) const;
+                                 
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */     
+    virtual void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */       
+    virtual void store( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear  object
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */    
+    virtual void clear ();                                   
 };
 
 

+ 189 - 15
features/localfeatures/LocalFeatureSift.cpp

@@ -1,7 +1,7 @@
 /**
 * @file LocalFeatureSift.cpp
 * @brief local feature with sift
-* @author Erik Rodner
+* @author Erik Rodner, Alexander Freytag
 * @date 03/10/2012
 */
 #include <iostream>
@@ -14,28 +14,52 @@ using namespace OBJREC;
 using namespace std;
 using namespace NICE;
 
-LocalFeatureSift::LocalFeatureSift( const Config *conf )
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+LocalFeatureSift::LocalFeatureSift() : LocalFeature () 
+{
+  this->octaves          = 6;
+  this->levels           = 3;
+  this->first_octave     = -1;
+  this->normalizeFeature = true;
+  this->magnif           = 3;
+  this->deletemode       = true;
+  this->integerValues    = true;
+  this->usegpu           = false;
+}
+
+LocalFeatureSift::LocalFeatureSift( const NICE::Config * _conf )
+{
+  this->initFromConfig( _conf );
+}
+
+LocalFeatureSift::~LocalFeatureSift()
 {
-    this->conf = conf;
+}
 
-    octaves          = conf->gI("LFSiftPP", "octaves", 			6);
-    levels           = conf->gI("LFSiftPP", "levels", 			3);
-    first_octave     = conf->gI("LFSiftPP", "first_octave", 	-1);
-    normalizeFeature = conf->gB("LFSiftPP", "normalize_feature", true );
-    magnif 	         = conf->gD("LFSiftPP", "magnif", 			3 );
-    deletemode       = conf->gB("LFSiftPP", "deletemode", 		true );
-    integerValues    = conf->gB("LFSiftPP", "integer_values", 	true );
+void OBJREC::LocalFeatureSift::initFromConfig( const NICE::Config* _conf, const std::string& _confSection )
+{
+  //NOTE previous confSection defaultet to LFSiftPP!
+  this->octaves          = _conf->gI(_confSection, "octaves",           6);
+  this->levels           = _conf->gI(_confSection, "levels",            3);
+  this->first_octave     = _conf->gI(_confSection, "first_octave",      -1);
+  this->normalizeFeature = _conf->gB(_confSection, "normalize_feature", true );
+  this->magnif           = _conf->gD(_confSection, "magnif",            3 );
+  this->deletemode       = _conf->gB(_confSection, "deletemode",        true );
+  this->integerValues    = _conf->gB(_confSection, "integer_values",    true );
 
 #ifdef NICE_USELIB_CUDASIFT
-    usegpu 	     	 = conf->gB("LFSiftPP", "use_siftgpu",		false );
+  this->usegpu           = _conf->gB(_confSection, "use_siftgpu",       false );
 #else
-	usegpu = false;
+  this->usegpu = false;
 #endif
 }
 
-LocalFeatureSift::~LocalFeatureSift()
-{
-}
+///////////////////// ///////////////////// /////////////////////
+//                      FEATURE STUFF
+///////////////////// ///////////////////// ////////////////// 
 
 void LocalFeatureSift::sortPositions(VVector & positions) const
 {
@@ -297,3 +321,153 @@ void LocalFeatureSift::withGPU(const NICE::Image& img, VVector& positions, VVect
     }
 }
 #endif
+  
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
+
+void LocalFeatureSift::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "LocalFeatureSift" ) )
+    {
+      std::cerr << " WARNING - attempt to restore LocalFeatureSift, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "LocalFeatureSift" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );    
+      
+      if ( tmp.compare("octaves") == 0 )
+      {
+        is >> this->octaves;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("levels") == 0 )
+      {
+        is >> this->levels;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }      
+      else if ( tmp.compare("first_octave") == 0 )
+      {
+        is >> this->first_octave;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("normalizeFeature") == 0 )
+      {
+        is >> this->normalizeFeature;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }      
+      else if ( tmp.compare("magnif") == 0 )
+      {
+        is >> this->magnif;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("deletemode") == 0 )
+      {
+        is >> this->deletemode;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }      
+      else if ( tmp.compare("integerValues") == 0 )
+      {
+        is >> this->integerValues;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("usegpu") == 0 )
+      {
+        is >> this->usegpu;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }      
+      else
+      {
+      std::cerr << "WARNING -- unexpected LocalFeatureSift object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "LocalFeatureSift::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void LocalFeatureSift::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "LocalFeatureSift" ) << std::endl;    
+    
+    os << this->createStartTag( "octaves" ) << std::endl;
+    os << this->octaves << std::endl;
+    os << this->createEndTag( "octaves" ) << std::endl;  
+
+    os << this->createStartTag( "levels" ) << std::endl;
+    os << this->levels << std::endl;
+    os << this->createEndTag( "levels" ) << std::endl;
+    
+    os << this->createStartTag( "first_octave" ) << std::endl;
+    os << this->first_octave << std::endl;
+    os << this->createEndTag( "first_octave" ) << std::endl;  
+
+    os << this->createStartTag( "normalizeFeature" ) << std::endl;
+    os << this->normalizeFeature << std::endl;
+    os << this->createEndTag( "normalizeFeature" ) << std::endl; 
+    
+    os << this->createStartTag( "magnif" ) << std::endl;
+    os << this->magnif << std::endl;
+    os << this->createEndTag( "magnif" ) << std::endl;
+    
+    os << this->createStartTag( "deletemode" ) << std::endl;
+    os << this->deletemode << std::endl;
+    os << this->createEndTag( "deletemode" ) << std::endl;  
+
+    os << this->createStartTag( "integerValues" ) << std::endl;
+    os << this->integerValues << std::endl;
+    os << this->createEndTag( "integerValues" ) << std::endl;     
+    
+    os << this->createStartTag( "usegpu" ) << std::endl;
+    os << this->usegpu << std::endl;
+    os << this->createEndTag( "usegpu" ) << std::endl;     
+    
+    // done
+    os << this->createEndTag( "LocalFeatureSift" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void LocalFeatureSift::clear ()
+{
+}

+ 96 - 22
features/localfeatures/LocalFeatureSift.h

@@ -1,7 +1,7 @@
 /**
 * @file LocalFeatureSift.h
 * @brief local feature with sift
-* @author Erik Rodner
+* @author Erik Rodner, Alexander Freytag
 * @date 03/10/2012 (Eric Bach)
 * @note some notes to the use of siftGPU (added by Eric Bach)
 *  - install cudaSift & siftGPU (see Makefile.config)
@@ -15,21 +15,27 @@
 #ifndef LOCALFEATURESIFTINCLUDE
 #define LOCALFEATURESIFTINCLUDE
 
-// NICE includes
-#include "core/vector/VectorT.h"
-#include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
-#include "core/basics/Config.h"
-#include "core/basics/StringTools.h"
-#include "LocalFeature.h"
-
-// std includes
+// STL includes
 #include <iostream>
 #include <string>
 #include <stdexcept>
 
+// nice-core includes
+#include <core/basics/Config.h>
+#include <core/basics/StringTools.h>
+// 
+#include <core/image/ImageT.h>
+#include <core/imagedisplay/ImageDisplay.h>
+// 
+#include <core/vector/VectorT.h>
+#include <core/vector/MatrixT.h>
+
+// nice-vislearning includes
+#include "LocalFeature.h"
+
+
+
 // SiftGPU & GL
 #ifdef NICE_USELIB_CUDASIFT
 #include <src/SiftGPU.h>
@@ -42,23 +48,41 @@ namespace OBJREC {
 /** local feature with sift */
 class LocalFeatureSift : public LocalFeature
 {
-  private:
-    const NICE::Config* conf;
 
   protected:
+    
+    /////////////////////////
+    /////////////////////////
+    // PROTECTED VARIABLES //
+    /////////////////////////
+    /////////////////////////    
+    
     int octaves;
+    
     int levels;
+    
     bool normalizeFeature;
+    
     int first_octave;
+    
     double magnif;
+    
     bool deletemode;
+    
     bool integerValues;
 
     // for SiftGPU
     bool usegpu;
 
     float threshold;
+    
     float edgeThreshold;
+    
+    /////////////////////////
+    /////////////////////////
+    //  PROTECTED METHODS  //
+    /////////////////////////
+    /////////////////////////      
 
     void withPP ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
 #ifdef NICE_USELIB_CUDASIFT
@@ -66,13 +90,40 @@ class LocalFeatureSift : public LocalFeature
 #endif
 
   public:
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////       
+
+    /** 
+     * @brief default constructor
+     * @date 09-02-2014 (dd-mm-yyyy )
+     * @author Alexander Freytag
+     */
+    LocalFeatureSift ( );    
+    
+    /**
+     * @brief recommended constructor, calls initFromConfig
+     * @date 09-02-2014 (dd-mm-yyyy )
+     * @author Alexander Freytag
+     */
+    LocalFeatureSift ( const NICE::Config * _conf );
 
-    /** simple constructor */
-    LocalFeatureSift ( const NICE::Config *conf );
-
-    /** simple destructor */
-
+    /**
+     * @brief simple destructor
+     */
     virtual ~LocalFeatureSift();
+    
+    /** 
+     * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mm-yyyy )
+     */    
+    void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LocalFeatureSift");    
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                      FEATURE STUFF
+    ///////////////////// ///////////////////// //////////////////        
 
     /**
      * returns the size of each the SIFT-Feature
@@ -117,10 +168,33 @@ class LocalFeatureSift : public LocalFeature
      */
     void sortPositions ( NICE::VVector & positions ) const;
 
-    void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
-
-
-
+    virtual void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
+
+
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */     
+    virtual void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */       
+    virtual void store( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear  object
+     * @author Alexander Freytag
+     * @date 09-02-2014 ( dd-mmyyyy)
+     */    
+    virtual void clear ();  
 
 };