Просмотр исходного кода

Merge branch 'master', remote branch 'origin/master'

Alexander Luetz 13 лет назад
Родитель
Сommit
5925e819a8
5 измененных файлов с 523 добавлено и 521 удалено
  1. 16 16
      baselib/Globals.h
  2. 340 338
      cbaselib/ClassNames.cpp
  3. 80 80
      cbaselib/ClassNames.h
  4. 47 47
      features/fpfeatures/HaarFeature.cpp
  5. 40 40
      features/fpfeatures/HaarFeature.h

+ 16 - 16
baselib/Globals.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file Globals.h
 * @brief some routines which provide access to global variables
 * @author Erik Rodner
@@ -14,22 +14,22 @@ namespace OBJREC {
 
 /** @brief some routines which provide access to global variables */
 class Globals {
-    
-    private:
+
+  private:
 
     /** image filename which is currently processed */
     static std::string currentImgFN;
 
-    public:
+  public:
 
-	/** cache mode: none "none" (<root>/<imgfn>), categories "cat" (<root>/<last-dir-part>/<imgfn>),
-	    categories_secondpart "cat2" (<root>/<second-last-dir-part>/<imgfn>) */
+    /** cache mode: none "none" (<root>/<imgfn>), categories "cat" (<root>/<last-dir-part>/<imgfn>),
+        categories_secondpart "cat2" (<root>/<second-last-dir-part>/<imgfn>) */
     enum {
-		SORT_NONE = 0,
-		SORT_CATEGORIES,
-		SORT_CATEGORIES_SECONDPART
+      SORT_NONE = 0,
+      SORT_CATEGORIES,
+      SORT_CATEGORIES_SECONDPART
     };
-   
+
     /** set filename of the image which is currently processed */
     static void setCurrentImgFN ( const std::string & imgfn );
 
@@ -37,15 +37,15 @@ class Globals {
     static std::string getCurrentImgFN ();
 
     /** get a filename which can be used for caching
-	@param root root directory of the global cache
-	@param cache_mode mode of the caching
-	@return cache filename
+    @param root root directory of the global cache
+    @param cache_mode mode of the caching
+    @return cache filename
     */
     static std::string getCacheFilename ( const std::string & root, int cache_mode );
-    
+
     /** get cache mode
-	@param desc description of the cache
-	@return determined cache mode
+    @param desc description of the cache
+    @return determined cache mode
     */
     static int getCacheMode ( const std::string & desc );
 

+ 340 - 338
cbaselib/ClassNames.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file ClassNames.cpp
 * @brief simple interface for class name confusion
 * @author Erik Rodner
@@ -27,454 +27,456 @@ using namespace NICE;
 
 ClassNames::ClassNames()
 {
-	maxClassNo = 0;
+  maxClassNo = 0;
 }
 
-ClassNames::ClassNames ( const ClassNames & cn, 
-			 const std::string & classselection )
+ClassNames::ClassNames ( const ClassNames & cn,
+                         const std::string & classselection )
 {
-	std::set<int> selection;
-	cn.getSelection ( classselection, selection );
-	maxClassNo = 0;
-
-	store ( cerr );
-
-	for ( map<string, string>::const_iterator i  = cn.tbl_code_text.begin();
-						  i != cn.tbl_code_text.end();
-						  i++ )
-	{
-		const std::string & classname = i->second;
-		std::string code = i->first;
-
-		if ( cn.tbl_code_classno.find(code) == cn.tbl_code_classno.end() )
-		{
-			fprintf (stderr, "class %s excluded in base classnames\n", code.c_str() );
-			continue;
-		}
-
-		int classno = cn.classno(code);
-		if ( selection.find(classno) != selection.end() )
-		{
-			addClass( classno, code, classname );
-			if ( classno > maxClassNo ) maxClassNo = classno;
+  std::set<int> selection;
+  cn.getSelection ( classselection, selection );
+  maxClassNo = 0;
+
+  store ( cerr );
+
+  for ( map<string, string>::const_iterator i  = cn.tbl_code_text.begin();
+        i != cn.tbl_code_text.end();
+        i++ )
+  {
+    const std::string & classname = i->second;
+    std::string code = i->first;
+
+    if ( cn.tbl_code_classno.find ( code ) == cn.tbl_code_classno.end() )
+    {
+      fprintf ( stderr, "class %s excluded in base classnames\n", code.c_str() );
+      continue;
+    }
+
+    int classno = cn.classno ( code );
+    if ( selection.find ( classno ) != selection.end() )
+    {
+      addClass ( classno, code, classname );
+      if ( classno > maxClassNo ) maxClassNo = classno;
 #ifdef DEBUG_ClassNames
-			fprintf (stderr, "class %s (%d) inherited\n", code.c_str(), classno );
+      fprintf ( stderr, "class %s (%d) inherited\n", code.c_str(), classno );
 #endif
-		} else {
+    } else {
 #ifdef DEBUG_ClassNames
-			fprintf (stderr, "class %s (%d) excluded in selection\n", code.c_str(), classno );
+      fprintf ( stderr, "class %s (%d) excluded in selection\n", code.c_str(), classno );
 #endif
-		}
-	}
+    }
+  }
 }
 
 ClassNames::ClassNames ( const ClassNames & cn )
-	: tbl_code_text(cn.tbl_code_text), tbl_text_code(cn.tbl_text_code),
-	  tbl_classno_code(cn.tbl_classno_code), tbl_code_classno(cn.tbl_code_classno),
-	  tbl_color_classno(tbl_color_classno), tbl_classno_color(cn.tbl_classno_color), maxClassNo(cn.maxClassNo)
+    : tbl_code_text ( cn.tbl_code_text ), tbl_text_code ( cn.tbl_text_code ),
+    tbl_classno_code ( cn.tbl_classno_code ), tbl_code_classno ( cn.tbl_code_classno ),
+    tbl_color_classno ( tbl_color_classno ), tbl_classno_color ( cn.tbl_classno_color ), maxClassNo ( cn.maxClassNo )
 {
 }
 
 ClassNames::~ClassNames()
 {
 }
-	
+
 
 int ClassNames::classnoFromText ( std::string text ) const
 {
-	map<string, string>::const_iterator j = tbl_text_code.find(text);
-	if ( j == tbl_text_code.end() ) return -1;
+  map<string, string>::const_iterator j = tbl_text_code.find ( text );
+  if ( j == tbl_text_code.end() ) return -1;
 
-	map<string, int>::const_iterator jj = tbl_code_classno.find(j->second);
-	if ( jj == tbl_code_classno.end() ) return -1;
+  map<string, int>::const_iterator jj = tbl_code_classno.find ( j->second );
+  if ( jj == tbl_code_classno.end() ) return -1;
 
-	return jj->second;
+  return jj->second;
 }
 
 void ClassNames::getSelection ( const std::string & classselection,
-				std::set<int> & classnos ) const
+                                std::set<int> & classnos ) const
 {
-	if ( classselection.size() <= 0 ) return;
-
-	std::vector<string> classlist;
-	StringTools::split ( classselection, ',', classlist );
-
-	if ( classlist.size() <= 0 )
-	{
-	fprintf (stderr, "FATAL ERROR: wrong format for classselection\n");
-	exit(-1);
-	} else if ( classlist[0] == "*" )
-	{
-	map<string, bool> forbidden_classes;
-	for ( size_t k = 1 ; k < classlist.size() ; k++ )
-		if ( classlist[k].substr(0,1) == "-" )
-		{
-			std::string f_class = classlist[k].substr(1);
+  if ( classselection.size() <= 0 ) return;
+
+  std::vector<string> classlist;
+  StringTools::split ( classselection, ',', classlist );
+
+  if ( classlist.size() <= 0 )
+  {
+    fprintf ( stderr, "FATAL ERROR: wrong format for classselection\n" );
+    exit ( -1 );
+  } else if ( classlist[0] == "*" )
+  {
+    map<string, bool> forbidden_classes;
+    for ( size_t k = 1 ; k < classlist.size() ; k++ )
+      if ( classlist[k].substr ( 0, 1 ) == "-" )
+      {
+        std::string f_class = classlist[k].substr ( 1 );
 #if defined DEBUG_ClassNames
-			fprintf (stderr, "ClassNames: class %s excluded !\n", f_class.c_str() );
+        fprintf ( stderr, "ClassNames: class %s excluded !\n", f_class.c_str() );
 #endif
-			forbidden_classes[ f_class ] = true;
-		} else {
-			fprintf (stderr, "FATAL ERROR: wrong format for classselection: *,-class0,class1,...\n");
-			exit(-1);
-		}
-   
-	for ( map<int, string>::const_iterator i  = tbl_classno_code.begin();
-						  i != tbl_classno_code.end();
-						  i++ )
-	{
-		int myclassno = i->first;
-		const std::string & classname = text(myclassno);
-		if ( forbidden_classes.find(classname) != forbidden_classes.end() )
-		continue;
-		
-		classnos.insert ( myclassno );
-	}
-	} else {
-		for ( vector<string>::const_iterator i  = classlist.begin();
-							i != classlist.end();
-							i++ )
-		{
-			const std::string & classname = *i;
-			map<string, string>::const_iterator j = tbl_text_code.find(classname);
-	
-			if ( j == tbl_text_code.end() )
-			{
-				fprintf (stderr, "ClassNames: FATAL ERROR This is not a selection of a subset: %s [%s]\n",
-					classname.c_str(), classselection.c_str());
-				exit(-1);
-			}
-	
-			const std::string & code = j->second;
-			int myclassno = classno (code);
-	
-			if ( myclassno < 0 ) {
-				fprintf (stderr, "ClassNames: FATAL ERROR This is not a selection of a subset\n");
-				exit(-1);
-			}
-			classnos.insert ( myclassno );
-		}
-	}
+        forbidden_classes[ f_class ] = true;
+      } else {
+        fprintf ( stderr, "FATAL ERROR: wrong format for classselection: *,-class0,class1,...\n" );
+        exit ( -1 );
+      }
+
+    for ( map<int, string>::const_iterator i  = tbl_classno_code.begin();
+          i != tbl_classno_code.end();
+          i++ )
+    {
+      int myclassno = i->first;
+      const std::string & classname = text ( myclassno );
+      if ( forbidden_classes.find ( classname ) != forbidden_classes.end() )
+        continue;
+
+      classnos.insert ( myclassno );
+    }
+  } else {
+    for ( vector<string>::const_iterator i  = classlist.begin();
+          i != classlist.end();
+          i++ )
+    {
+      const std::string & classname = *i;
+      map<string, string>::const_iterator j = tbl_text_code.find ( classname );
+
+      if ( j == tbl_text_code.end() )
+      {
+        fprintf ( stderr, "ClassNames: FATAL ERROR This is not a selection of a subset: %s [%s]\n",
+                  classname.c_str(), classselection.c_str() );
+        exit ( -1 );
+      }
+
+      const std::string & code = j->second;
+      int myclassno = classno ( code );
+
+      if ( myclassno < 0 ) {
+        fprintf ( stderr, "ClassNames: FATAL ERROR This is not a selection of a subset\n" );
+        exit ( -1 );
+      }
+      classnos.insert ( myclassno );
+    }
+  }
 
 }
 
 std::string ClassNames::text ( int classno ) const
-{  
-	map<string, string>::const_iterator i = 
-		tbl_code_text.find ( code(classno) );
-
-	if ( i == tbl_code_text.end() )
-	{
-		fprintf (stderr, "ClassNames: no name found for classno %d\n", classno );
-		return "unknown";
-	} else {
-		return i->second;
-	}
+{
+  map<string, string>::const_iterator i =
+    tbl_code_text.find ( code ( classno ) );
+
+  if ( i == tbl_code_text.end() )
+  {
+    fprintf ( stderr, "ClassNames: no name found for classno %d\n", classno );
+    return "unknown";
+  } else {
+    return i->second;
+  }
 
 }
 
 std::string ClassNames::code ( int classno ) const
 {
-	map<int, string>::const_iterator i = 
-		tbl_classno_code.find ( classno );
+  map<int, string>::const_iterator i =
+    tbl_classno_code.find ( classno );
 
-	if ( i == tbl_classno_code.end() )
-	{
-		fprintf (stderr, "ClassNames: no code found for classno %d\n", classno );
-		return "unknown";
-	} else {
-		return i->second;
-	}
+  if ( i == tbl_classno_code.end() )
+  {
+    fprintf ( stderr, "ClassNames: no code found for classno %d\n", classno );
+    return "unknown";
+  } else {
+    return i->second;
+  }
 
 }
 
 int ClassNames::classno ( std::string code ) const
 {
-	map<string, int>::const_iterator i = 
-		tbl_code_classno.find ( code );
-
-	if ( i == tbl_code_classno.end() )
-	{
-		fthrow(Exception, "no classno found for code <" << code << ">" );
-	} else {
-		return i->second;
-	}
+  map<string, int>::const_iterator i =
+    tbl_code_classno.find ( code );
+
+  if ( i == tbl_code_classno.end() )
+  {
+    fthrow ( Exception, "no classno found for code <" << code << ">" );
+  } else {
+    return i->second;
+  }
 }
 
 int ClassNames::numClasses () const
 {
-	return tbl_classno_code.size();
+  return tbl_classno_code.size();
 }
 
 
-void ClassNames::addClass ( int classno, const std::string & code, 
-	const std::string & text )
+void ClassNames::addClass ( int classno, const std::string & code,
+                            const std::string & text )
 {
-	tbl_classno_code[classno] = code;
-	tbl_text_code[text]	   = code;
-	tbl_code_text[code]	   = text;
-	tbl_code_classno[code]	= classno;
+  tbl_classno_code[classno] = code;
+  tbl_text_code[text]    = code;
+  tbl_code_text[code]    = text;
+  tbl_code_classno[code] = classno;
 
-	if ( classno > maxClassNo ) maxClassNo = classno;
+  if ( classno > maxClassNo ) maxClassNo = classno;
 }
-	
+
 bool ClassNames::existsClassno ( int classno ) const
 {
-	return (tbl_classno_code.find(classno) != tbl_classno_code.end());
+  return ( tbl_classno_code.find ( classno ) != tbl_classno_code.end() );
 }
 
 // refactor-nice.pl: check this substitution
 // old: bool ClassNames::existsClassCode ( const string & classcode ) const
 bool ClassNames::existsClassCode ( const std::string & classcode ) const
 {
-	return (tbl_code_classno.find(classcode) != tbl_code_classno.end());
+  return ( tbl_code_classno.find ( classcode ) != tbl_code_classno.end() );
 }
 
-bool ClassNames::readFromConfig ( const Config & datasetconf, 
-			// refactor-nice.pl: check this substitution
-			// old: const string & classselection )
-			const std::string & classselection )
+bool ClassNames::readFromConfig ( const Config & datasetconf,
+                                  // refactor-nice.pl: check this substitution
+                                  // old: const string & classselection )
+                                  const std::string & classselection )
 {
 
-	datasetconf.getAllS ( "classnames", tbl_code_text );
+  datasetconf.getAllS ( "classnames", tbl_code_text );
 
-	if ( tbl_code_text.size() <= 0 ) {
-		fprintf (stderr, "ClassNames: no classnames specified\n");
-		return false;
-	}
+  if ( tbl_code_text.size() <= 0 ) {
+    fprintf ( stderr, "ClassNames: no classnames specified\n" );
+    return false;
+  }
 
-	// reverse map and lower case
-	for ( map<string, string>::const_iterator i  = tbl_code_text.begin();
-									   i != tbl_code_text.end(); i++ )
-		tbl_text_code [ i->second ] = i->first;	
+  // reverse map and lower case
+  for ( map<string, string>::const_iterator i  = tbl_code_text.begin();
+        i != tbl_code_text.end(); i++ )
+    tbl_text_code [ i->second ] = i->first;
 
 #if defined DEBUG_ClassNames
-	cerr << "ClassNames::read: selection = " << classselection << endl;
+  cerr << "ClassNames::read: selection = " << classselection << endl;
 #endif
 
-	std::vector<string> classlist;
-	StringTools::split ( classselection, ',', classlist );
-
-	if ( classlist.size() <= 0 )
-	{
-	fprintf (stderr, "FATAL ERROR: wrong format for classselection\n");
-	exit(-1);
-	} else if ( classlist[0] == "*" )
-	{
-	map<string, bool> forbidden_classes;
-	for ( size_t k = 1 ; k < classlist.size() ; k++ )
-		if ( classlist[k].substr(0,1) == "-" )
-		{
-		// refactor-nice.pl: check this substitution
-		// old: string f_class = classlist[k].substr(1);
-		std::string f_class = classlist[k].substr(1);
+  std::vector<string> classlist;
+  StringTools::split ( classselection, ',', classlist );
+
+  if ( classlist.size() <= 0 )
+  {
+    fprintf ( stderr, "FATAL ERROR: wrong format for classselection\n" );
+    exit ( -1 );
+  } else if ( classlist[0] == "*" )
+  {
+    map<string, bool> forbidden_classes;
+    for ( size_t k = 1 ; k < classlist.size() ; k++ )
+      if ( classlist[k].substr ( 0, 1 ) == "-" )
+      {
+        // refactor-nice.pl: check this substitution
+        // old: string f_class = classlist[k].substr(1);
+        std::string f_class = classlist[k].substr ( 1 );
 #if defined DEBUG_ClassNames
-		fprintf (stderr, "ClassNames: class %s excluded !\n", f_class.c_str() );
+        fprintf ( stderr, "ClassNames: class %s excluded !\n", f_class.c_str() );
 #endif
-		forbidden_classes[ f_class ] = true;
-		} else {
-		fprintf (stderr, "FATAL ERROR: wrong format for classselection: *,-class0,class1,...\n");
-		exit(-1);
-		}
-
-	int classno_seq = 0;
-	for ( map<string, string>::const_iterator i  = tbl_code_text.begin();
-						  i != tbl_code_text.end();
-						  i++,classno_seq++ )
-	{
-		const std::string & classname = i->second;
-		if ( forbidden_classes.find(classname) != forbidden_classes.end() )
-			continue;
-
-		// refactor-nice.pl: check this substitution
-		// old: string code = tbl_text_code [ i->second ];
-		std::string code = tbl_text_code [ i->second ];
-		int classno;
-		classno = classno_seq;
-		tbl_classno_code[classno] = code;
-		tbl_code_classno[code] = classno;
-		if ( classno > maxClassNo ) maxClassNo = classno;
+        forbidden_classes[ f_class ] = true;
+      } else {
+        fprintf ( stderr, "FATAL ERROR: wrong format for classselection: *,-class0,class1,...\n" );
+        exit ( -1 );
+      }
+
+    int classno_seq = 0;
+    for ( map<string, string>::const_iterator i  = tbl_code_text.begin();
+          i != tbl_code_text.end();
+          i++, classno_seq++ )
+    {
+      const std::string & classname = i->second;
+      if ( forbidden_classes.find ( classname ) != forbidden_classes.end() )
+        continue;
+
+      // refactor-nice.pl: check this substitution
+      // old: string code = tbl_text_code [ i->second ];
+      std::string code = tbl_text_code [ i->second ];
+      int classno;
+      classno = classno_seq;
+      tbl_classno_code[classno] = code;
+      tbl_code_classno[code] = classno;
+      if ( classno > maxClassNo ) maxClassNo = classno;
 
 #if defined DEBUG_ClassNames
-		fprintf (stderr, "classno %d class code %s class text %s\n", classno, code.c_str(), classname.c_str() );
+      fprintf ( stderr, "classno %d class code %s class text %s\n", classno, code.c_str(), classname.c_str() );
 #endif
-	}
-	} else {
+    }
+  } else {
 
 #if defined DEBUG_ClassNames
-	cerr << "list : " << classlist.size() << endl;
+    cerr << "list : " << classlist.size() << endl;
 #endif
-	for ( size_t classno_seq = 0 ; classno_seq < classlist.size() ; classno_seq++ )
-	{
-		std::string classname = classlist[classno_seq];
-
-		if ( tbl_text_code.find ( classname ) != tbl_text_code.end() )
-		{
-			std::string code = tbl_text_code [ classname ];
-			int classno;
-			classno = classno_seq;
-			tbl_classno_code[classno] = code;
-			tbl_code_classno[code] = classno;
-			if ( classno > maxClassNo ) maxClassNo = classno;
+    for ( size_t classno_seq = 0 ; classno_seq < classlist.size() ; classno_seq++ )
+    {
+      std::string classname = classlist[classno_seq];
+
+      if ( tbl_text_code.find ( classname ) != tbl_text_code.end() )
+      {
+        std::string code = tbl_text_code [ classname ];
+        int classno;
+        classno = classno_seq;
+        tbl_classno_code[classno] = code;
+        tbl_code_classno[code] = classno;
+        if ( classno > maxClassNo ) maxClassNo = classno;
 
 #if defined DEBUG_ClassNames
-			fprintf (stderr, "classno %d class code %s class text %s\n", (int)classno, code.c_str(), classname.c_str() );
+        fprintf ( stderr, "classno %d class code %s class text %s\n", ( int ) classno, code.c_str(), classname.c_str() );
 #endif
-		} else {
-			fprintf (stderr, "ClassNames::ClassNames: FATAL ERROR class >%s< not found in data set\n", classname.c_str() );
-			exit(-1);
-		}
-	}
-	}
-
-	/****** after all, try to read color coding *******/
-	map<string, string> list;
-	datasetconf.getAllS ( "colors", list );
-
-	if ( list.size() > 0 ) {
-		for ( map<string,string>::const_iterator i = list.begin();
-			i != list.end();
-			i++ )
-		{
-			std::string value = i->second;
-			std::string classname = i->first;
-			int _classno = classno(classname);
-			vector<string> submatches;
-			if ( StringTools::regexMatch ( value, "^ *([[:digit:]]+) *: *([[:digit:]]+) *: *([[:digit:]]+) *$", submatches ) 
-				&& ( submatches.size() == 4 ) )
-			{
-				int r = StringTools::convert<int> ( submatches[1] );
-				int g = StringTools::convert<int> ( submatches[2] );
-				int b = StringTools::convert<int> ( submatches[3] );
-				long index = 256*(256*r + g) + b;
-				tbl_color_classno[index] = _classno;
-				tbl_classno_color[_classno] = index;
-			} else {
-				fprintf (stderr, "LabeledFileList: parse error colors >%s<\n", value.c_str() );
-				exit(-1);
-			}
-		}
-	}
-
-	return true;
+      } else {
+        fprintf ( stderr, "ClassNames::ClassNames: FATAL ERROR class >%s< not found in data set\n", classname.c_str() );
+        exit ( -1 );
+      }
+    }
+  }
+
+  /****** after all, try to read color coding *******/
+  map<string, string> list;
+  datasetconf.getAllS ( "colors", list );
+
+  if ( list.size() > 0 ) {
+    for ( map<string, string>::const_iterator i = list.begin();
+          i != list.end();
+          i++ )
+    {
+      std::string value = i->second;
+      std::string classname = i->first;
+      int _classno = classno ( classname );
+      vector<string> submatches;
+      if ( StringTools::regexMatch ( value, "^ *([[:digit:]]+) *: *([[:digit:]]+) *: *([[:digit:]]+) *$", submatches )
+           && ( submatches.size() == 4 ) )
+      {
+        int r = StringTools::convert<int> ( submatches[1] );
+        int g = StringTools::convert<int> ( submatches[2] );
+        int b = StringTools::convert<int> ( submatches[3] );
+        long index = 256 * ( 256 * r + g ) + b;
+        tbl_color_classno[index] = _classno;
+        tbl_classno_color[_classno] = index;
+      } else {
+        fprintf ( stderr, "LabeledFileList: parse error colors >%s<\n", value.c_str() );
+        exit ( -1 );
+      }
+    }
+  }
+
+  return true;
 }
-	
+
 int ClassNames::getMaxClassno () const
 {
-	return maxClassNo;
+  return maxClassNo;
 }
-	
+
 void ClassNames::getRGBColor ( int classno, int & r, int & g, int & b ) const
 {
-	map<int, long>::const_iterator i = tbl_classno_color.find(classno);
-
-	if ( i == tbl_classno_color.end() )
-	{
-		fprintf (stderr, "ClassNames: no color setting found for class %d\n", classno );
-		getchar();
-		double x = classno / (double)numClasses();
-		double rd, gd, bd;
-		ICETools::toColor ( x, rd, gd, bd );
-		r = (int)(255*rd);
-		g = (int)(255*gd);
-		b = (int)(255*bd);
-	} else {
-		long color = i->second;
-		b = color % 256;
-		color /= 256;
-		g = color % 256;
-		color /= 256;
-		r = color % 256;
-	}
+  map<int, long>::const_iterator i = tbl_classno_color.find ( classno );
+
+  if ( i == tbl_classno_color.end() )
+  {
+    fprintf ( stderr, "ClassNames: no color setting found for class %d\n", classno );
+    getchar();
+    double x = classno / ( double ) numClasses();
+    double rd, gd, bd;
+    ICETools::toColor ( x, rd, gd, bd );
+    r = ( int ) ( 255 * rd );
+    g = ( int ) ( 255 * gd );
+    b = ( int ) ( 255 * bd );
+  } else {
+    long color = i->second;
+    b = color % 256;
+    color /= 256;
+    g = color % 256;
+    color /= 256;
+    r = color % 256;
+  }
 }
 
 void ClassNames::getClassnoFromColor ( int & classno, int r, int g, int b ) const
 {
-	long color = 256*(256*r+g) + b;
-	map<long, int>::const_iterator i = tbl_color_classno.find(color);
-
-	if ( i == tbl_color_classno.end() )
-	{
-		classno = -1;
-	} else {
-		classno = i->second;
-	}
+  long color = 256 * ( 256 * r + g ) + b;
+  map<long, int>::const_iterator i = tbl_color_classno.find ( color );
+
+  if ( i == tbl_color_classno.end() )
+  {
+    classno = -1;
+  } else {
+    classno = i->second;
+  }
 }
 
 void ClassNames::labelToRGB ( const NICE::Image & img, NICE::ColorImage & rgb ) const
 {
-	int red, green, blue;
+  int red, green, blue;
 
-	rgb.resize(img.width(), img.height());
+  rgb.resize ( img.width(), img.height() );
 
-	for ( int y = 0 ; y < img.height(); y++ )
-	for ( int x = 0 ; x < img.width(); x++ )
-	{
-		int label = img.getPixel(x,y);
-		getRGBColor ( label, red, green, blue );
-		rgb.setPixel(x,y,0,red);
-		rgb.setPixel(x,y,1,green);
-		rgb.setPixel(x,y,2,blue);
-	}
+  for ( int y = 0 ; y < img.height(); y++ )
+    for ( int x = 0 ; x < img.width(); x++ )
+    {
+      int label = img.getPixel ( x, y );
+      getRGBColor ( label, red, green, blue );
+      rgb.setPixel ( x, y, 0, red );
+      rgb.setPixel ( x, y, 1, green );
+      rgb.setPixel ( x, y, 2, blue );
+    }
 
 }
 
 int ClassNames::getBackgroundClass () const
 {
-	if ( existsClassCode ("various" ) )
-		return classno("various");
-	else if ( existsClassCode ("background" ) )
-		return classno("background");
-	else if ( existsClassCode ("clutter" ) )
-		return classno("clutter");
-	else
-		return 0;
+  if ( existsClassCode ( "various" ) )
+    return classno ( "various" );
+  else if ( existsClassCode ( "background" ) )
+    return classno ( "background" );
+  else if ( existsClassCode ( "clutter" ) )
+    return classno ( "clutter" );
+  else
+    return 0;
 }
 
-void ClassNames::restore (istream & is, int format)
+void ClassNames::restore ( istream & is, int format )
 {
-	maxClassNo = -1;
-	while ( ! is.eof() )
-	{
-		std::string mytext;
-		std::string mycode;
-		int myclassno;
-
-		if ( !(is >> mytext) ) break;
-		if ( !(is >> mycode) ) break;
-		if ( !(is >> myclassno) ) break;
-
-		tbl_code_text.insert ( pair<string, string> ( mycode, mytext ) );
-		tbl_text_code.insert ( pair<string, string> ( mytext, mycode ) );
-		tbl_classno_code.insert ( pair<int, string> ( myclassno, mycode ) );
-		tbl_code_classno.insert ( pair<string, int> ( mycode, myclassno ) );
-
-		if ( myclassno > maxClassNo ) maxClassNo = myclassno;
-	}
+  maxClassNo = -1;
+  while ( ! is.eof() )
+  {
+    std::string mytext;
+    std::string mycode;
+    int myclassno;
+
+    if ( ! ( is >> mytext ) ) break;
+    if ( mytext == "end" ) break;
+    if ( ! ( is >> mycode ) ) break;
+    if ( ! ( is >> myclassno ) ) break;
+
+    tbl_code_text.insert ( pair<string, string> ( mycode, mytext ) );
+    tbl_text_code.insert ( pair<string, string> ( mytext, mycode ) );
+    tbl_classno_code.insert ( pair<int, string> ( myclassno, mycode ) );
+    tbl_code_classno.insert ( pair<string, int> ( mycode, myclassno ) );
+
+    if ( myclassno > maxClassNo ) maxClassNo = myclassno;
+  }
 }
 
-void ClassNames::store (ostream & os, int format) const
+void ClassNames::store ( ostream & os, int format ) const
 {
-	assert ( tbl_classno_code.size() == tbl_code_classno.size() );
-	for ( map<int, string>::const_iterator i  = tbl_classno_code.begin() ;
-						  i != tbl_classno_code.end();
-						  i++ )
-	{
-		int myclassno = i->first;
-		std::string mycode = i->second;
-		std::string mytext = text(myclassno);
-
-		os << mytext << "\t" << mycode << "\t" << myclassno << endl;
-	}	
+  assert ( tbl_classno_code.size() == tbl_code_classno.size() );
+  for ( map<int, string>::const_iterator i  = tbl_classno_code.begin() ;
+        i != tbl_classno_code.end();
+        i++ )
+  {
+    int myclassno = i->first;
+    std::string mycode = i->second;
+    std::string mytext = text ( myclassno );
+
+    os << mytext << "\t" << mycode << "\t" << myclassno << endl;
+  }
+  os << "end" << endl;
 }
 
 void ClassNames::clear ()
 {
-	tbl_code_text.clear();
-	tbl_text_code.clear();
-	tbl_classno_code.clear();
-	tbl_code_classno.clear();
-	tbl_color_classno.clear();
-	tbl_classno_color.clear();
+  tbl_code_text.clear();
+  tbl_text_code.clear();
+  tbl_classno_code.clear();
+  tbl_code_classno.clear();
+  tbl_color_classno.clear();
+  tbl_classno_color.clear();
 }
 

+ 80 - 80
cbaselib/ClassNames.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file ClassNames.h
 * @brief simple interface for class name confusion
 * @author Erik Rodner
@@ -11,7 +11,7 @@
 #include "core/image/ImageT.h"
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
- 
+
 #include <string>
 #include <map>
 
@@ -25,84 +25,84 @@ namespace OBJREC {
 class ClassNames : public NICE::Persistent
 {
 
-    protected:
-
-		std::map<std::string, std::string> tbl_code_text;
-		std::map<std::string, std::string> tbl_text_code;
-		std::map<int, std::string> tbl_classno_code;
-		std::map<std::string, int> tbl_code_classno;
-		std::map<long, int> tbl_color_classno;
-		std::map<int, long> tbl_classno_color;
-
-		int maxClassNo;
-
-    public:
-  
-	/** simple constructor */
-	ClassNames();
-    
-	/** copy constructor */
-	ClassNames ( const ClassNames & cn );
-  
-	/** create sub selection */
-	ClassNames ( const ClassNames & cn, 
-		     const std::string & classselection );
-
-	/** simple destructor */
-	virtual ~ClassNames();
-    
-	/** get the readable class number of a class number */
-	std::string text ( int classno ) const;
-
-	/** get the class code (e.g. ascii code) of a class number */
-	std::string code ( int classno ) const;
-
-	/** get the class number corresponding to the code */
-	int classno ( std::string code ) const;
-	
-	/** get the class number corresponding to the name */
-	int classnoFromText ( std::string text ) const;
-
-	/** number of classes */
-	int numClasses () const;
-	void getSelection ( const std::string & classselection,
-			    std::set<int> & classnos ) const;
-
-	/** add new class information 
-	 * @param classno class number
-	 * @param code class code (such as ascii number or just the name)
-	 * @param text class name as readable ascii representation
-	 */
-	void addClass ( int classno, const std::string & code, 
-	    const std::string & text );
-
-	bool readFromConfig ( const NICE::Config & datasetconf, 
-		    const std::string & classselection );
-
-	/** is there any class with this class number */
-	bool existsClassno ( int classno ) const;
-	/** is there any class with this class code */
-	bool existsClassCode ( const std::string & classcode ) const;
-
-	int getMaxClassno () const;
-
-	void getRGBColor ( int classno, int & r, int & g, int & b ) const;
-	
-	void getClassnoFromColor ( int & classno, int r, int g, int b ) const;
-
-	/** colorize a labeled image using color information given in the class 
-	 *  information file */
-	void labelToRGB ( const NICE::Image & img, NICE::ColorImage & rgb ) const;
-
-	int getBackgroundClass () const;
-
-	/** restore classnames in the format <classtext> <classcode> <classno> */ 
-	void restore (std::istream & is, int format = 0);
-
-	/** store classnames in the format <classtext> <classcode> <classno> */ 
-	void store (std::ostream & os, int format = 0) const;
-
-	/** clear class information */
+  protected:
+
+    std::map<std::string, std::string> tbl_code_text;
+    std::map<std::string, std::string> tbl_text_code;
+    std::map<int, std::string> tbl_classno_code;
+    std::map<std::string, int> tbl_code_classno;
+    std::map<long, int> tbl_color_classno;
+    std::map<int, long> tbl_classno_color;
+
+    int maxClassNo;
+
+  public:
+
+    /** simple constructor */
+    ClassNames();
+
+    /** copy constructor */
+    ClassNames ( const ClassNames & cn );
+
+    /** create sub selection */
+    ClassNames ( const ClassNames & cn,
+                 const std::string & classselection );
+
+    /** simple destructor */
+    virtual ~ClassNames();
+
+    /** get the readable class number of a class number */
+    std::string text ( int classno ) const;
+
+    /** get the class code (e.g. ascii code) of a class number */
+    std::string code ( int classno ) const;
+
+    /** get the class number corresponding to the code */
+    int classno ( std::string code ) const;
+
+    /** get the class number corresponding to the name */
+    int classnoFromText ( std::string text ) const;
+
+    /** number of classes */
+    int numClasses () const;
+    void getSelection ( const std::string & classselection,
+                        std::set<int> & classnos ) const;
+
+    /** add new class information
+     * @param classno class number
+     * @param code class code (such as ascii number or just the name)
+     * @param text class name as readable ascii representation
+     */
+    void addClass ( int classno, const std::string & code,
+                    const std::string & text );
+
+    bool readFromConfig ( const NICE::Config & datasetconf,
+                          const std::string & classselection );
+
+    /** is there any class with this class number */
+    bool existsClassno ( int classno ) const;
+    /** is there any class with this class code */
+    bool existsClassCode ( const std::string & classcode ) const;
+
+    int getMaxClassno () const;
+
+    void getRGBColor ( int classno, int & r, int & g, int & b ) const;
+
+    void getClassnoFromColor ( int & classno, int r, int g, int b ) const;
+
+    /** colorize a labeled image using color information given in the class
+     *  information file */
+    void labelToRGB ( const NICE::Image & img, NICE::ColorImage & rgb ) const;
+
+    int getBackgroundClass () const;
+
+    /** restore classnames in the format <classtext> <classcode> <classno> */
+    void restore ( std::istream & is, int format = 0 );
+
+    /** store classnames in the format <classtext> <classcode> <classno> */
+    void store ( std::ostream & os, int format = 0 ) const;
+
+    /** clear class information */
     void clear ();
 };
 

+ 47 - 47
features/fpfeatures/HaarFeature.cpp

@@ -16,61 +16,61 @@ using namespace std;
 using namespace NICE;
 
 
-void HaarFeature::explode( FeaturePool & featurePool, bool variableWindow ) const
+void HaarFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
 {
-  HaarFeature *hf = new HaarFeature( *this );
+  HaarFeature *hf = new HaarFeature ( *this );
 
   hf->pos1 = 0;
   hf->pos2 = 0;
   hf->type = HAARTYPE_HORIZONTAL;
   for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_y - 1 ; hf->pos1 += hf->step_y )
-    featurePool.addFeature( hf->clone(), hf->step_y / ( double )( HAARTYPE_NUMTYPES * hf->window_size_y ) );
+    featurePool.addFeature ( hf->clone(), hf->step_y / ( double ) ( HAARTYPE_NUMTYPES * hf->window_size_y ) );
 
   hf->pos1 = 0;
   hf->pos2 = 0;
   hf->type = HAARTYPE_VERTICAL;
   for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_x - 1; hf->pos1 += hf->step_x )
-    featurePool.addFeature( hf->clone(), hf->step_x / ( double )( HAARTYPE_NUMTYPES * hf->window_size_x ) );
+    featurePool.addFeature ( hf->clone(), hf->step_x / ( double ) ( HAARTYPE_NUMTYPES * hf->window_size_x ) );
 
   hf->type = HAARTYPE_DIAGONAL;
   hf->pos1 = 0;
   hf->pos2 = 0;
   for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_x - 1; hf->pos1 += hf->step_x )
     for ( hf->pos2 = 0 ; hf->pos2 < hf->window_size_y - 1 ; hf->pos2 += hf->step_y )
-      featurePool.addFeature( hf->clone(),
-                              hf->step_x * hf->step_y / ( double )( HAARTYPE_NUMTYPES * hf->window_size_x * hf->window_size_y ) );
+      featurePool.addFeature ( hf->clone(),
+                               hf->step_x * hf->step_y / ( double ) ( HAARTYPE_NUMTYPES * hf->window_size_x * hf->window_size_y ) );
 
   hf->pos1 = 0;
   hf->pos2 = 0;
   hf->type = HAARTYPE_3BLOCKS;
   for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_x - 2*hf->step_x ; hf->pos1 += hf->step_x )
     for ( hf->pos2 = hf->pos1 + hf->step_x; hf->pos2 < hf->window_size_x - hf->step_x ; hf->pos2 += hf->step_x )
-      featurePool.addFeature( hf->clone(),
-                              ( 2.0 * hf->step_x ) / ( HAARTYPE_NUMTYPES * ( hf->window_size_x - hf->step_x ) ) );
+      featurePool.addFeature ( hf->clone(),
+                               ( 2.0 * hf->step_x ) / ( HAARTYPE_NUMTYPES * ( hf->window_size_x - hf->step_x ) ) );
 
   delete hf;
 }
 
 Feature *HaarFeature::clone() const
 {
-  HaarFeature *fp =  new HaarFeature( *this );
+  HaarFeature *fp =  new HaarFeature ( *this );
   return fp;
 }
 
 
 /************* HaarFeature **************/
-HaarFeature::HaarFeature( const Config *conf )
+HaarFeature::HaarFeature ( const Config *conf )
 {
-  window_size_x = conf->gI( "HaarFeature", "window_size_x", 24 );
-  window_size_y = conf->gI( "HaarFeature", "window_size_y", 24 );
-  step_x = conf->gI( "HaarFeature", "step_x", 1 );
-  step_y = conf->gI( "HaarFeature", "step_y", 1 );
+  window_size_x = conf->gI ( "HaarFeature", "window_size_x", 24 );
+  window_size_y = conf->gI ( "HaarFeature", "window_size_y", 24 );
+  step_x = conf->gI ( "HaarFeature", "step_x", 1 );
+  step_y = conf->gI ( "HaarFeature", "step_y", 1 );
 }
 
-HaarFeature::HaarFeature( int _window_size_x,
-                          int _window_size_y,
-                          int _step_x,
-                          int _step_y )
+HaarFeature::HaarFeature ( int _window_size_x,
+                           int _window_size_y,
+                           int _step_x,
+                           int _step_y )
 {
   window_size_x = _window_size_x;
   window_size_y = _window_size_y;
@@ -85,9 +85,9 @@ HaarFeature::~HaarFeature()
 {
 }
 
-double HaarFeature::val( const Example *example ) const
+double HaarFeature::val ( const Example *example ) const
 {
-  const NICE::MultiChannelImageT<long> & img = example->ce->getLChannel( CachedExample::L_INTEGRALIMAGE );
+  const NICE::MultiChannelImageT<long> & img = example->ce->getLChannel ( CachedExample::L_INTEGRALIMAGE );
 
   const long *integralImage = img.data[0];
   int xsize = img.xsize;
@@ -112,28 +112,28 @@ double HaarFeature::val( const Example *example ) const
     br = bl + ( window_size_x - 1 );
   }
 
-  assert( tl < xsize*ysize );
-  assert( tr < xsize*ysize );
+  assert ( tl < xsize*ysize );
+  assert ( tr < xsize*ysize );
   if ( br >= xsize*ysize )
   {
-    fprintf( stderr, "xsize=%d, ysize=%d, x=%d, y=%d, wsy=%d, wsx=%d\n",
-             xsize, ysize, x, y, window_size_x, window_size_y );
-    fprintf( stderr, "example: %d x %d\n",
-             example->width, example->height );
+    fprintf ( stderr, "xsize=%d, ysize=%d, x=%d, y=%d, wsy=%d, wsx=%d\n",
+              xsize, ysize, x, y, window_size_x, window_size_y );
+    fprintf ( stderr, "example: %d x %d\n",
+              example->width, example->height );
 
   }
-  assert( bl < xsize*ysize );
-  assert( br < xsize*ysize );
-  assert( pos1 >= 0 );
-  assert( pos2 >= 0 );
+  assert ( bl < xsize*ysize );
+  assert ( br < xsize*ysize );
+  assert ( pos1 >= 0 );
+  assert ( pos2 >= 0 );
 
   double value;
   if ( type == HaarFeature::HAARTYPE_HORIZONTAL )
   {
     long ml = tl + xsize * pos1;
     long mr = tr + xsize * pos1;
-    assert(( ml >= 0 ) && ( ml < xsize*ysize ) );
-    assert(( mr >= 0 ) && ( mr < xsize*ysize ) );
+    assert ( ( ml >= 0 ) && ( ml < xsize*ysize ) );
+    assert ( ( mr >= 0 ) && ( mr < xsize*ysize ) );
     value = 2 * integralImage[mr];
     value -= 2 * integralImage[ml];
     value +=   integralImage[tl];
@@ -143,8 +143,8 @@ double HaarFeature::val( const Example *example ) const
   } else if ( type == HaarFeature::HAARTYPE_VERTICAL ) {
     long mt = tl + pos1;
     long mb = bl + pos1;
-    assert(( mt >= 0 ) && ( mt < xsize*ysize ) );
-    assert(( mb >= 0 ) && ( mb < xsize*ysize ) );
+    assert ( ( mt >= 0 ) && ( mt < xsize*ysize ) );
+    assert ( ( mb >= 0 ) && ( mb < xsize*ysize ) );
 
     value = 2 * integralImage[mb];
     value -= 2 * integralImage[mt];
@@ -154,12 +154,12 @@ double HaarFeature::val( const Example *example ) const
     value -=   integralImage[br];
   } else if ( type == HaarFeature::HAARTYPE_DIAGONAL ) {
     int p2o = pos2 * xsize;
-    assert(( p2o >= 0 ) && ( p2o < xsize*ysize ) );
-    assert(( tl + pos1 >= 0 ) && ( tl + pos1 < xsize*ysize ) );
-    assert(( tl + p2o >= 0 ) && ( tl + p2o < xsize*ysize ) );
-    assert(( bl + pos1 >= 0 ) && ( bl + pos1 < xsize*ysize ) );
-    assert(( tr + p2o >= 0 ) && ( tr + p2o < xsize*ysize ) );
-    assert(( tl + pos1 + p2o >= 0 ) && ( tl + pos1 + p2o < xsize*ysize ) );
+    assert ( ( p2o >= 0 ) && ( p2o < xsize*ysize ) );
+    assert ( ( tl + pos1 >= 0 ) && ( tl + pos1 < xsize*ysize ) );
+    assert ( ( tl + p2o >= 0 ) && ( tl + p2o < xsize*ysize ) );
+    assert ( ( bl + pos1 >= 0 ) && ( bl + pos1 < xsize*ysize ) );
+    assert ( ( tr + p2o >= 0 ) && ( tr + p2o < xsize*ysize ) );
+    assert ( ( tl + pos1 + p2o >= 0 ) && ( tl + pos1 + p2o < xsize*ysize ) );
 
     value = integralImage[tl];
     value += integralImage[bl];
@@ -174,10 +174,10 @@ double HaarFeature::val( const Example *example ) const
     value += 4 * integralImage[tl + pos1 + p2o];
 
   } else if ( type == HaarFeature::HAARTYPE_3BLOCKS ) {
-    assert(( tl + pos1 >= 0 ) && ( tl + pos1 < xsize*ysize ) );
-    assert(( bl + pos2 >= 0 ) && ( bl + pos2 < xsize*ysize ) );
-    assert(( tl + pos2 >= 0 ) && ( tl + pos2 < xsize*ysize ) );
-    assert(( bl + pos1 >= 0 ) && ( bl + pos1 < xsize*ysize ) );
+    assert ( ( tl + pos1 >= 0 ) && ( tl + pos1 < xsize*ysize ) );
+    assert ( ( bl + pos2 >= 0 ) && ( bl + pos2 < xsize*ysize ) );
+    assert ( ( tl + pos2 >= 0 ) && ( tl + pos2 < xsize*ysize ) );
+    assert ( ( bl + pos1 >= 0 ) && ( bl + pos1 < xsize*ysize ) );
     value = integralImage[tl];
     value +=  integralImage[br];
     value -=  integralImage[bl];
@@ -192,12 +192,12 @@ double HaarFeature::val( const Example *example ) const
     return -1;
   }
 
-  assert( finite( value ) );
+  assert ( finite ( value ) );
 
   return value;
 }
 
-void HaarFeature::restore( istream & is, int format )
+void HaarFeature::restore ( istream & is, int format )
 {
   is >> type;
   is >> window_size_x;
@@ -206,7 +206,7 @@ void HaarFeature::restore( istream & is, int format )
   is >> pos2;
 }
 
-void HaarFeature::store( ostream & os, int format ) const
+void HaarFeature::store ( ostream & os, int format ) const
 {
   os << "HAARFEATURE" << " " << type << " "
   << window_size_x << " " << window_size_y

+ 40 - 40
features/fpfeatures/HaarFeature.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file HaarFeature.h
 * @brief simple haar like feature
 * @author Erik Rodner
@@ -22,45 +22,45 @@ namespace OBJREC {
 class HaarFeature : public Feature
 {
 
-    protected:
-	enum {
-	    HAARTYPE_HORIZONTAL = 0,
-	    HAARTYPE_VERTICAL,
-	    HAARTYPE_DIAGONAL,
-	    HAARTYPE_3BLOCKS,
-	    HAARTYPE_NUMTYPES
-	};
-
-	int type;
-	int pos1;
-	int pos2;
-	int step_x;
-	int step_y;
-	int window_size_x;
-	int window_size_y;
-
-    public:
-  
-	/** simple constructor */
-	HaarFeature( const NICE::Config *conf );
-      
-	/** without memory wasting config */
-	HaarFeature ( int window_size_x,	
-		      int window_size_y,
-		      int step_x,
-		      int step_y );
-
-	/** simple destructor */
-	virtual ~HaarFeature();
-     
-	virtual double val( const Example *example ) const;
-
-	void explode ( FeaturePool & featurePool, bool variableWindow ) const;
-	Feature *clone() const;
-	
-	void restore (std::istream & is, int format = 0);
-	void store (std::ostream & os, int format = 0) const;
-	void clear ();
+  protected:
+    enum {
+      HAARTYPE_HORIZONTAL = 0,
+      HAARTYPE_VERTICAL,
+      HAARTYPE_DIAGONAL,
+      HAARTYPE_3BLOCKS,
+      HAARTYPE_NUMTYPES
+    };
+
+    int type;
+    int pos1;
+    int pos2;
+    int step_x;
+    int step_y;
+    int window_size_x;
+    int window_size_y;
+
+  public:
+
+    /** simple constructor */
+    HaarFeature ( const NICE::Config *conf );
+
+    /** without memory wasting config */
+    HaarFeature ( int window_size_x,
+                  int window_size_y,
+                  int step_x,
+                  int step_y );
+
+    /** simple destructor */
+    virtual ~HaarFeature();
+
+    virtual double val ( const Example *example ) const;
+
+    void explode ( FeaturePool & featurePool, bool variableWindow ) const;
+    Feature *clone() const;
+
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
 
 };