瀏覽代碼

Merge remote-tracking branch 'origin/master' into clemens-fixes

Clemens-Alexander Brust 11 年之前
父節點
當前提交
a8c03b78ac

+ 21 - 1
core/basics/Config.cpp

@@ -7,6 +7,7 @@
 #include "core/basics/Config.h"
 #include "core/basics/ossettings.h"
 #include "core/basics/StringTools.h"
+#include "core/basics/FileName.h"
 
 using namespace NICE;
   
@@ -26,6 +27,7 @@ Config::Config ( const std::string & configfn )
     read(configfn);
   }
   ioUntilEndOfFile = true;
+  m_sConfigFilename = configfn;
 }
 
 Config::Config ( int argc, 
@@ -43,6 +45,7 @@ Config::Config ( int argc,
 Config::Config ( const Config & conf ) : Persistent()
 {
   ioUntilEndOfFile = true;
+  m_sConfigFilename = conf.m_sConfigFilename;
 	confB.copyFrom ( conf.confB );
 	confD.copyFrom ( conf.confD );
 	confI.copyFrom ( conf.confI );
@@ -308,7 +311,7 @@ bool Config::keyExists ( const std::string & block, const std::string & key ) co
     return ( confS.keyExists ( block, key ) || 
              confI.keyExists ( block, key ) ||
 	     confB.keyExists ( block, key ) ||
-	     confD.keyExists ( block, key ) );
+             confD.keyExists ( block, key ) );
 }
 
 void Config::addHelp ( const std::string & block, const std::string & key,
@@ -568,3 +571,20 @@ void Config::getAllBlocks ( std::set< std::string > & list ) const
     confS.getAllBlocks ( list );
     confI.getAllBlocks ( list );
 }
+
+string Config::getAbsoluteFilenameRelativeToThisConfig(const string &p_Filename) const
+{
+    if( m_sConfigFilename.empty() )
+        return p_Filename;
+
+    NICE::FileName t_DatasetFilename( p_Filename );
+
+    if( !t_DatasetFilename.isRelative() )
+    {
+        return p_Filename;
+    }
+
+    NICE::FileName t_ConfigFilename( this->m_sConfigFilename );
+    return  t_ConfigFilename.extractPath().str() + p_Filename;
+}
+

+ 15 - 0
core/basics/Config.h

@@ -54,6 +54,8 @@ class Config : public NICE::Persistent
     /** read until end of file fore restore (default: yes)*/
     bool ioUntilEndOfFile;
 
+    /** stores filename the config was created from*/
+    std::string m_sConfigFilename;
   public:
 
       /** simplest constructor, create an empty config */
@@ -136,6 +138,19 @@ class Config : public NICE::Persistent
       */
       bool keyExists ( const std::string & block, const std::string & key ) const;
 
+      /** returns the filename the config was created by*/
+      std::string getFilename() const{ return m_sConfigFilename;}
+
+      /**
+       * @brief Returns the given filename as an absolute path relative to this config file' location
+       *
+       * If p_Filename is not a relative path, then the filepath is alread absolute and just return that!
+       *
+       * @param p_Filename filename being relative or absolute
+       * @return absolute filename
+       */
+      std::string getAbsoluteFilenameRelativeToThisConfig(const std::string &p_Filename) const;
+
       /** add a help text */
       void addHelp ( const std::string & block, const std::string & key,
 		     const std::string & helpText );

+ 8 - 1
core/basics/FileName.cpp

@@ -133,7 +133,14 @@ void FileName::createDirectory() const {
 }
 
 void FileName::deleteFile() const {
-  remove(fileName.c_str());
+    remove(fileName.c_str());
+}
+
+bool FileName::isRelative() const {
+    if(fileName.empty())
+        return false;
+
+    return  fileName.substr(0,1) != "/";
 }
 
 } // namespace

+ 4 - 0
core/basics/FileName.h

@@ -146,6 +146,10 @@ public:
    */
   void deleteFile() const;
    
+  /** returns true if the filename's path is relative which means beginning with (at least) a dot (.)
+      @return true if the filename is realtive
+  */
+  bool isRelative() const;
 private:
   //! stores the file name
   std::string fileName;

+ 37 - 0
core/basics/tests/FileNameTest.cpp

@@ -23,6 +23,10 @@ void FileNameTest::testFileName() {
   CPPUNIT_ASSERT_EQUAL(path, fileName.extractPath().str());
   CPPUNIT_ASSERT_EQUAL(name, fileName.extractFileName().str());
   CPPUNIT_ASSERT_EQUAL(ext, fileName.extractExtension().str());
+
+  CPPUNIT_ASSERT_EQUAL(false, fileName.isRelative() );
+  FileName fileNameRelative(name);
+  CPPUNIT_ASSERT_EQUAL(true, fileNameRelative.isRelative() );
 }
 
 void FileNameTest::testFileNameSlash() {
@@ -34,4 +38,37 @@ void FileNameTest::testFileNameSlash() {
   fileNameSlash.removeSlash();
   CPPUNIT_ASSERT_EQUAL(path, fileNameSlash.str());
   CPPUNIT_ASSERT_EQUAL(pathSlash, fileName.str());
+
+  CPPUNIT_ASSERT_EQUAL(false, fileName.isRelative() );
+  CPPUNIT_ASSERT_EQUAL(false, fileNameSlash.isRelative() );
+}
+
+void FileNameTest::testPathRelative() {
+  FileName fileName;
+
+  // absolute pathes
+  fileName.set("");
+  CPPUNIT_ASSERT_EQUAL(false, fileName.isRelative() );
+  fileName.set("/home/user/temporary.ext");
+  CPPUNIT_ASSERT_EQUAL(false, fileName.isRelative() );
+  fileName.set("/home/user/");
+  CPPUNIT_ASSERT_EQUAL(false, fileName.isRelative() );
+  fileName.set("/tmp/tmp.ect");
+  CPPUNIT_ASSERT_EQUAL(false, fileName.isRelative() );
+
+  // relative pathes and files
+  fileName.set("temporary.ext");
+  CPPUNIT_ASSERT_EQUAL(true, fileName.isRelative() );
+  fileName.set("./");
+  CPPUNIT_ASSERT_EQUAL(true, fileName.isRelative() );
+  fileName.set("./temporary.ext");
+  CPPUNIT_ASSERT_EQUAL(true, fileName.isRelative() );
+  fileName.set("../temporary.ext");
+  CPPUNIT_ASSERT_EQUAL(true, fileName.isRelative() );
+  fileName.set("../../temporary.ext");
+  CPPUNIT_ASSERT_EQUAL(true, fileName.isRelative() );
+  fileName.set("../../temporary.ext");
+  CPPUNIT_ASSERT_EQUAL(true, fileName.isRelative() );
+
+
 }

+ 6 - 0
core/basics/tests/FileNameTest.h

@@ -12,6 +12,7 @@ class FileNameTest : public CppUnit::TestFixture {
   CPPUNIT_TEST_SUITE( FileNameTest );
   CPPUNIT_TEST( testFileName );
   CPPUNIT_TEST( testFileNameSlash );
+  CPPUNIT_TEST( testPathRelative );
   CPPUNIT_TEST_SUITE_END();
   
  private:
@@ -30,6 +31,11 @@ class FileNameTest : public CppUnit::TestFixture {
    */
   void testFileNameSlash();
 
+  /**
+   * Test FileName for relative and absolute path recognition
+   */
+  void testPathRelative();
+
 };
 
 #endif // FILENAMETEST_H

+ 1 - 1
core/image/MultiChannelImage3DT.h

@@ -127,7 +127,7 @@ public:
    * @param channel channel
    * @return P mean value of given volume
    **/
-  P getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel);
+  P getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel) const;
 
   /** convert to ice image */
   void convertToGrey( NICE::Image & img, int z, uint channel = 0, bool normalize = true ) const;

+ 1 - 1
core/image/MultiChannelImage3DT.tcc

@@ -680,7 +680,7 @@ void MultiChannelImage3DT<P>::calcVariance( uint srcchan, uint tarchan )
 }
 
 template<class P>
-P MultiChannelImage3DT<P>::getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel)
+P MultiChannelImage3DT<P>::getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel) const
 {
   ulfx = std::max(ulfx-1, -1);
   ulfx = std::min(ulfx, xsize-1);

+ 6 - 2
core/vector/VectorT.tcc

@@ -756,10 +756,14 @@ void VectorT<ElementType>::sortDescend(VectorT<int> & permutation) {
   permutation.resize(this->size());
 
   int idxSelf ( 0 );
-  for (VectorT<ElementType>::const_iterator itSelf = (*this).begin(); itSelf != (*this).end(); itSelf++, idxSelf++)
+  for (typename VectorT<ElementType>::const_iterator itSelf = (*this).begin(); 
+       itSelf != (*this).end(); 
+       itSelf++, idxSelf++)
   {
     int idxOrig ( 0 );
-    for ( VectorT<ElementType>::const_iterator itOrig = tmp_cp.begin(); itOrig != tmp_cp.end(); itOrig++, idxOrig++)
+    for (typename VectorT<ElementType>::const_iterator itOrig = tmp_cp.begin(); 
+         itOrig != tmp_cp.end(); 
+         itOrig++, idxOrig++)
     {
       if ( *itOrig == *itSelf )
       {