ClassNames.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @file ClassNames.h
  3. * @brief simple interface for class name confusion
  4. * @author Erik Rodner
  5. * @date 02/08/2008
  6. */
  7. #ifndef CLASSNAMESINCLUDE
  8. #define CLASSNAMESINCLUDE
  9. #include "core/image/ImageT.h"
  10. #include "core/vector/VectorT.h"
  11. #include "core/vector/MatrixT.h"
  12. #include <string>
  13. #include <map>
  14. // in future we should replace this with
  15. // unordered_map, but it is still experimental but standard c++
  16. #ifdef WIN32
  17. #ifdef NICE_USELIB_BOOST
  18. #include <boost/unordered_map.hpp>
  19. #endif
  20. #else
  21. //#include <ext/hash_map>
  22. #include <tr1/unordered_map>
  23. #endif
  24. #include "core/basics/Config.h"
  25. #include "core/basics/Persistent.h"
  26. namespace OBJREC {
  27. /** simple interface for class name confusion */
  28. class ClassNames : public NICE::Persistent
  29. {
  30. protected:
  31. std::map<std::string, std::string> tbl_code_text;
  32. std::map<std::string, std::string> tbl_text_code;
  33. std::map<int, std::string> tbl_classno_code;
  34. std::map<std::string, int> tbl_code_classno;
  35. #if defined WIN32 && defined NICE_USELIB_BOOST
  36. boost::unordered_map<long, int> tbl_color_classno;
  37. #else
  38. // __gnu_cxx::hash_map<long, int> tbl_color_classno;
  39. std::tr1::unordered_map<long, int> tbl_color_classno;
  40. #endif
  41. std::map<int, long> tbl_classno_color;
  42. int maxClassNo;
  43. public:
  44. /** simple constructor */
  45. ClassNames();
  46. /** copy constructor */
  47. ClassNames ( const ClassNames & cn );
  48. /** create sub selection */
  49. ClassNames ( const ClassNames & cn,
  50. const std::string & classselection );
  51. /** simple destructor */
  52. virtual ~ClassNames();
  53. /** get the readable class number of a class number */
  54. std::string text ( int classno ) const;
  55. /** get the class code (e.g. ascii code) of a class number */
  56. std::string code ( int classno ) const;
  57. /** get the class number corresponding to the code */
  58. int classno ( std::string code ) const;
  59. /** get the class number corresponding to the name */
  60. int classnoFromText ( std::string text ) const;
  61. /** number of classes */
  62. int numClasses () const;
  63. void getSelection ( const std::string & classselection,
  64. std::set<int> & classnos ) const;
  65. /** add new class information
  66. * @param classno class number
  67. * @param code class code (such as ascii number or just the name)
  68. * @param text class name as readable ascii representation
  69. */
  70. void addClass ( int classno, const std::string & code,
  71. const std::string & text );
  72. bool readFromConfig ( const NICE::Config & datasetconf,
  73. const std::string & classselection );
  74. /** is there any class with this class number */
  75. bool existsClassno ( int classno ) const;
  76. /** is there any class with this class code */
  77. bool existsClassCode ( const std::string & classcode ) const;
  78. int getMaxClassno () const;
  79. void getRGBColor ( int classno, int & r, int & g, int & b ) const;
  80. void getClassnoFromColor ( int & classno, int r, int g, int b ) const;
  81. /** colorize a labeled image using color information given in the class
  82. * information file */
  83. void labelToRGB ( const NICE::Image & img, NICE::ColorImage & rgb ) const;
  84. int getBackgroundClass () const;
  85. /** restore classnames in the format <classtext> <classcode> <classno> */
  86. void restore ( std::istream & is, int format = 0 );
  87. /** store classnames in the format <classtext> <classcode> <classno> */
  88. void store ( std::ostream & os, int format = 0 ) const;
  89. /** clear class information */
  90. void clear ();
  91. };
  92. } // namespace
  93. #endif