LocalFeatureLFInterface.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include <iostream>
  2. #include <assert.h>
  3. #include "LocalFeatureLFInterface.h"
  4. using namespace OBJREC;
  5. using namespace std;
  6. using namespace NICE;
  7. ///////////////////// ///////////////////// /////////////////////
  8. // CONSTRUCTORS / DESTRUCTORS
  9. ///////////////////// ///////////////////// /////////////////////
  10. LocalFeatureLFInterface::LocalFeatureLFInterface() : LocalFeature ()
  11. {
  12. this->lfpres = NULL;
  13. }
  14. LocalFeatureLFInterface::LocalFeatureLFInterface( const NICE::Config * _conf, LocalFeatureRepresentation *_lfpres )
  15. {
  16. this->initFromConfig( _conf );
  17. //TODO check for null pointers? where will deletion be performed? what about restoring those objects?
  18. this->lfpres = _lfpres;
  19. }
  20. LocalFeatureLFInterface::~LocalFeatureLFInterface()
  21. {
  22. if ( this->lfpres != NULL )
  23. delete lfpres;
  24. this->lfpres = NULL;
  25. }
  26. void LocalFeatureLFInterface::initFromConfig( const NICE::Config* _conf, const std::string& _confSection )
  27. {
  28. //nothing to do here
  29. //NOTE how to handle lfrep object? - separate set method?
  30. }
  31. ///////////////////// ///////////////////// /////////////////////
  32. // FEATURE STUFF
  33. ///////////////////// ///////////////////// //////////////////
  34. int LocalFeatureLFInterface::getDescriptors ( const NICE::Image & img, VVector & positions, VVector & descriptors ) const
  35. {
  36. //TODO do we want to ignore the positions of lfrep and use the given ones, or do we indeed want to compute positions on our own? If so, why do we use the Interface to LocalFeature, and not directly LocalFeatureRepresentation?
  37. lfpres->extractFeatures(img, descriptors, positions);
  38. assert(descriptors.size() == positions.size());
  39. return 0;
  40. }
  41. int LocalFeatureLFInterface::getDescriptors ( const NICE::ColorImage & img, VVector & positions, VVector & descriptors) const
  42. {
  43. //TODO do we want to ignore the positions of lfrep and use the given ones, or do we indeed want to compute positions on our own? If so, why do we use the Interface to LocalFeature, and not directly LocalFeatureRepresentation?
  44. lfpres->extractFeatures(img, descriptors, positions);
  45. assert(descriptors.size() == positions.size());
  46. return 0;
  47. }
  48. void LocalFeatureLFInterface::visualizeFeatures ( NICE::Image & mark,
  49. const VVector & positions,
  50. size_t color ) const
  51. {
  52. //cerr << "LocalFeatureLFInterface::visualizeFeatures(...) not yet implemented" << endl;
  53. lfpres->visualizeFeatures(mark, positions, color);
  54. }
  55. ///////////////////// INTERFACE PERSISTENT /////////////////////
  56. // interface specific methods for store and restore
  57. ///////////////////// INTERFACE PERSISTENT /////////////////////
  58. void LocalFeatureLFInterface::restore ( std::istream & is, int format )
  59. {
  60. //delete everything we knew so far...
  61. this->clear();
  62. if ( is.good() )
  63. {
  64. std::string tmp;
  65. is >> tmp; //class name
  66. if ( ! this->isStartTag( tmp, "LocalFeatureLFInterface" ) )
  67. {
  68. std::cerr << " WARNING - attempt to restore LocalFeatureLFInterface, but start flag " << tmp << " does not match! Aborting... " << std::endl;
  69. throw;
  70. }
  71. bool b_endOfBlock ( false ) ;
  72. while ( !b_endOfBlock )
  73. {
  74. is >> tmp; // start of block
  75. if ( this->isEndTag( tmp, "LocalFeatureLFInterface" ) )
  76. {
  77. b_endOfBlock = true;
  78. continue;
  79. }
  80. tmp = this->removeStartTag ( tmp );
  81. ///////////////////////////////
  82. // PARENT OBJECT //
  83. ///////////////////////////////
  84. if ( tmp.compare("lfpres") == 0 )
  85. {
  86. // restore parent object
  87. //TODO this->lfpres->restore ( is );
  88. }
  89. else
  90. {
  91. std::cerr << "WARNING -- unexpected LocalFeatureOpponnentSift object -- " << tmp << " -- for restoration... aborting" << std::endl;
  92. throw;
  93. }
  94. }
  95. }
  96. else
  97. {
  98. std::cerr << "LocalFeatureOpponnentSift::restore -- InStream not initialized - restoring not possible!" << std::endl;
  99. throw;
  100. }
  101. }
  102. void LocalFeatureLFInterface::store ( std::ostream & os, int format ) const
  103. {
  104. if (os.good())
  105. {
  106. // show starting point
  107. os << this->createStartTag( "LocalFeatureLFInterface" ) << std::endl;
  108. ///////////////////////////////
  109. // PARENT OBJECT //
  110. ///////////////////////////////
  111. os << this->createStartTag( "lfpres" ) << std::endl;
  112. //TODO this->lfpres->store(os);
  113. os << this->createStartTag( "lfpres" ) << std::endl;
  114. // done
  115. os << this->createEndTag( "LocalFeatureLFInterface" ) << std::endl;
  116. }
  117. else
  118. {
  119. std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
  120. }
  121. }
  122. void LocalFeatureLFInterface::clear ()
  123. {
  124. if ( this->lfpres != NULL )
  125. delete lfpres;
  126. this->lfpres = NULL;
  127. }