ClassNames.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #endif
  23. #include "core/basics/Config.h"
  24. #include "core/basics/Persistent.h"
  25. namespace OBJREC {
  26. /** simple interface for class name confusion */
  27. class ClassNames : public NICE::Persistent
  28. {
  29. protected:
  30. std::map<std::string, std::string> tbl_code_text;
  31. std::map<std::string, std::string> tbl_text_code;
  32. std::map<int, std::string> tbl_classno_code;
  33. std::map<std::string, int> tbl_code_classno;
  34. #if defined WIN32 && defined NICE_USELIB_BOOST
  35. boost::unordered_map<long, int> tbl_color_classno;
  36. #else
  37. __gnu_cxx::hash_map<long, int> tbl_color_classno;
  38. #endif
  39. std::map<int, long> tbl_classno_color;
  40. int maxClassNo;
  41. public:
  42. /** simple constructor */
  43. ClassNames();
  44. /** copy constructor */
  45. ClassNames ( const ClassNames & cn );
  46. /** create sub selection */
  47. ClassNames ( const ClassNames & cn,
  48. const std::string & classselection );
  49. /** simple destructor */
  50. virtual ~ClassNames();
  51. /** get the readable class number of a class number */
  52. std::string text ( int classno ) const;
  53. /** get the class code (e.g. ascii code) of a class number */
  54. std::string code ( int classno ) const;
  55. /** get the class number corresponding to the code */
  56. int classno ( std::string code ) const;
  57. /** get the class number corresponding to the name */
  58. int classnoFromText ( std::string text ) const;
  59. /** number of classes */
  60. int numClasses () const;
  61. void getSelection ( const std::string & classselection,
  62. std::set<int> & classnos ) const;
  63. /** add new class information
  64. * @param classno class number
  65. * @param code class code (such as ascii number or just the name)
  66. * @param text class name as readable ascii representation
  67. */
  68. void addClass ( int classno, const std::string & code,
  69. const std::string & text );
  70. bool readFromConfig ( const NICE::Config & datasetconf,
  71. const std::string & classselection );
  72. /** is there any class with this class number */
  73. bool existsClassno ( int classno ) const;
  74. /** is there any class with this class code */
  75. bool existsClassCode ( const std::string & classcode ) const;
  76. int getMaxClassno () const;
  77. void getRGBColor ( int classno, int & r, int & g, int & b ) const;
  78. void getClassnoFromColor ( int & classno, int r, int g, int b ) const;
  79. /** colorize a labeled image using color information given in the class
  80. * information file */
  81. void labelToRGB ( const NICE::Image & img, NICE::ColorImage & rgb ) const;
  82. int getBackgroundClass () const;
  83. /** restore classnames in the format <classtext> <classcode> <classno> */
  84. void restore ( std::istream & is, int format = 0 );
  85. /** store classnames in the format <classtext> <classcode> <classno> */
  86. void store ( std::ostream & os, int format = 0 ) const;
  87. /** clear class information */
  88. void clear ();
  89. };
  90. } // namespace
  91. #endif