Эх сурвалжийг харах

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

Sven Sickert 11 жил өмнө
parent
commit
cef999f2a4

+ 18 - 1
core/basics/Config.cpp

@@ -2,6 +2,9 @@
 #include <assert.h>
 #include <fstream>
 
+#include <unistd.h> //for getpwd() under linux
+#include <sys/param.h> //for MAXPATHLEN - the maximal path length
+
 // nice-core includes
 #include "core/basics/Exception.h"
 #include "core/basics/Config.h"
@@ -35,7 +38,21 @@ Config::Config ( int argc,
 {
   readFromArguments ( argc, argv );
   std::string configfile = gS("main", "config", "" );
-  
+
+  NICE::FileName t_ConfigFilename( configfile );
+
+  // check for relative path correction:
+  // if dataset is a relative path, then make it absolute using the
+  // currend working directory
+  if( t_ConfigFilename.isRelative() )
+  {
+      char sCWDPath[MAXPATHLEN];
+      getcwd(sCWDPath, MAXPATHLEN);
+      t_ConfigFilename.set( string(sCWDPath) + "/" + configfile );
+      t_ConfigFilename.convertToRealPath();
+      configfile = t_ConfigFilename.str();
+  }
+  m_sConfigFilename = configfile;
   std::cerr << "configfile: " << configfile << std::endl;
   ioUntilEndOfFile = gB("main", "ioUntilEndOfFile", true );
   if ( configfile.size() > 0 )

+ 15 - 0
core/basics/FileName.cpp

@@ -3,6 +3,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+#include <sys/param.h> //for MAXPATHLEN - the maximal path length
+
 
 using namespace std;
 
@@ -143,4 +145,17 @@ bool FileName::isRelative() const {
     return  fileName.substr(0,1) != "/";
 }
 
+bool FileName::convertToRealPath()
+{
+    char actualpath [MAXPATHLEN];
+    char *pRet = realpath( fileName.c_str(), actualpath);
+
+    //TODO: how to treat the return value???
+//    if( pRet == NULL)
+//        return false;
+
+    this->fileName = string( actualpath);
+    return true;
+}
+
 } // namespace

+ 9 - 0
core/basics/FileName.h

@@ -150,6 +150,15 @@ public:
       @return true if the filename is realtive
   */
   bool isRelative() const;
+
+  /** Converts the path into a real path with all relative path elements being resolved.
+   * Example:
+   *    path before: "/home/user/experiment/../config/conf.conf
+   *    path after : "/home/user/config/conf.conf
+   * @return true if resolution was successfull
+   */
+  bool convertToRealPath();
+
 private:
   //! stores the file name
   std::string fileName;

+ 4 - 1
core/image/MultiChannelImage3DT.h

@@ -141,9 +141,12 @@ public:
 	/** return image for visualization */
   ImageT<P> getChannelT( int z, uint channel = 0 ) const;
 
-  /** return rgb image for visualization */
+  /** return rgb image (reading channels 0, 1, 2) for visualization */
   ColorImage getColor(int z) const;
 
+  /** return rgb image (reading arbitrary three channels) for visualization */
+  ColorImage getColorImageFromChannels(int z, int channel0, int channel1, int channel2) const;
+
   /** calculate image statistics */
   void statistics( P & min, P & max, uint channel = 0 ) const;
 

+ 24 - 0
core/image/MultiChannelImage3DT.tcc

@@ -538,6 +538,30 @@ ColorImage MultiChannelImage3DT<P>::getColor(int z) const
   return img;
 }
 
+template<class P>
+ColorImage MultiChannelImage3DT<P>::getColorImageFromChannels(int z, int channel0, int channel1, int channel2) const
+{
+  assert( z < zsize );
+  assert( numChannels >= std::max( std::max(channel0,channel1),channel2 ) );
+
+  NICE::ColorImage img( xsize, ysize );
+
+  long k = 0;
+
+  for ( int y = 0 ; y < ysize; y++ )
+  {
+    for ( int x = 0 ; x < xsize ; x++, k++ )
+    {
+      img.setPixel( x, y, 0, ( int )( data[channel0][z*xsize*ysize + k] ) );
+      img.setPixel( x, y, 1, ( int )( data[channel1][z*xsize*ysize + k] ) );
+      img.setPixel( x, y, 2, ( int )( data[channel2][z*xsize*ysize + k] ) );
+    }
+  }
+  //showImage(img);
+  //getchar();
+  return img;
+}
+
 template<class P>
 void MultiChannelImage3DT<P>::calcIntegral( uint channel )
 {