LabeledSetFactory.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef LABELEDSETFACTORY_H
  2. #define LABELEDSETFACTORY_H
  3. #include <string>
  4. #include <map>
  5. #include "vislearning/cbaselib/LabeledSet.h"
  6. #include "LabeledSetCreatorInterface.h"
  7. namespace OBJREC
  8. {
  9. /**
  10. * @brief Factory providing xml loading classes according to their document type.
  11. *
  12. * In order to extract ground truth information or - in general - structured data into a MultiDataset, xml files can be used as
  13. * containers of file and label information. This factory is used to choose the right loading function for different xml file formats
  14. * according to the stated document type in the xml file (e.g. < !DOCTYPE DaimlerStereoPedRecXml > ). This enables a flexible program design
  15. * that can handle loading different xml files at runtime.
  16. *
  17. * When initializing this factory, you map a given document type to the appropriate loading class, which implements the interface given by LabeledSetCreatorInterface.
  18. * For example, using the document type "DaimlerStereoPedRecXml" from above, by calling ::addCreator() this string is mapped to the xml load LabeledSetCreatorDaimlerXml,
  19. * which exactly knows how to handle the internal xml structure and create a LabeledSet out of it.
  20. *
  21. * \date 2012/05/18
  22. * \author Johannes Ruehle
  23. */
  24. class LabeledSetFactory
  25. {
  26. public:
  27. LabeledSetFactory();
  28. /**
  29. * @brief Fill a LabeledSet with data loaded from a xml file using the right loading object specified by the xml document type.
  30. *
  31. * Reads the document type of a xml file containing training / test data and calls the appropriate xml extraction class accordingly.
  32. * As a result, the xml loaded extract label information and stores them into a LabeledSet
  33. *
  34. * Note: An appropriate class derived from LabeledSetCreatorInterface had to be added in advance, by LabeledSetFactory::addCreator().
  35. *
  36. * @param sXmlFilename name of the config file (xml) containing a specific structure stated by the document type
  37. * according to which the appropriate LabeledSetCreatorInferface implementation is called for xml loading
  38. * @param p_conf Global config structure
  39. * @param p_classnames Structure containing all classnames of the ground truth
  40. * @param p_LabelSet labeled set of data to be created. All loaded data is appended to this structure.
  41. */
  42. void createLabeledSetFromXml(std::string sXmlFilename,
  43. const NICE::Config & p_conf,
  44. const ClassNames & p_classnames,
  45. LabeledSet &p_LabelSet);
  46. /**
  47. * @brief Create mapping from a xml document type to the appropriate loading function for a xml file.
  48. *
  49. * @param sCreatorName xml document type stating a specific xml format and its contents
  50. * @param pCreator object reference that knows how to load / parse the specific xml file and create a LabeledData set of it.
  51. */
  52. void addCreator(std::string sCreatorName, LabeledSetCreatorInterface *pCreator);
  53. protected:
  54. /// Mapping from xml document type to loader implementation.
  55. std::map<std::string, LabeledSetCreatorInterface*> m_MapLSCreators;
  56. };
  57. } //namespace
  58. #endif // LABELEDSETFACTORY_H