Changed SMState interface (how the ownership of the image is transferred)

git-svn-id: http://rtabmap.googlecode.com/svn/branches/0.3/rtabmap@70 f169173b-cf89-36c8-b27e-44dbe73f0c83
This commit is contained in:
matlabbe
2011-06-07 19:15:27 +00:00
parent 4ceeb78c8b
commit a0576be506
6 changed files with 36 additions and 36 deletions

View File

@@ -417,11 +417,13 @@ int main(int argc, char * argv[])
v[0] = 2; v[0] = 2;
v[1] = 0; v[1] = 0;
teleopActions.push_back(v); teleopActions.push_back(v);
smState = new SMState(image, teleopActions); smState = new SMState(std::list<std::vector<float> >(), teleopActions);
smState->setImage(image);
} }
else else
{ {
smState = new SMState(image, actions); smState = new SMState(std::list<std::vector<float> >(), actions);
smState->setImage(image);
} }
rtabmap->process(smState); rtabmap->process(smState);
loopClosureId = rtabmap->getLoopClosureId(); loopClosureId = rtabmap->getLoopClosureId();

View File

@@ -47,7 +47,7 @@ public:
this->parseParameters(parameters); this->parseParameters(parameters);
} }
virtual ~CamPostTreatment() {} virtual ~CamPostTreatment() {}
virtual SMState * process(IplImage * image); virtual SMState * process(const IplImage * image) const;
virtual void parseParameters(const ParametersMap & parameters) {} virtual void parseParameters(const ParametersMap & parameters) {}
}; };
@@ -68,7 +68,7 @@ public:
this->parseParameters(parameters); this->parseParameters(parameters);
} }
virtual ~CamKeypointTreatment(); virtual ~CamKeypointTreatment();
virtual SMState * process(IplImage * image); virtual SMState * process(const IplImage * image) const;
virtual void parseParameters(const ParametersMap & parameters); virtual void parseParameters(const ParametersMap & parameters);
DetectorStrategy detectorStrategy() const; DetectorStrategy detectorStrategy() const;
private: private:

View File

@@ -75,6 +75,7 @@ public:
Rtabmap(); Rtabmap();
virtual ~Rtabmap(); virtual ~Rtabmap();
// ownership is transferred
void process(SMState * data); void process(SMState * data);
void dumpData(); void dumpData();
@@ -110,7 +111,7 @@ private:
virtual void killCleanup(); virtual void killCleanup();
virtual void startInit(); virtual void startInit();
void process(); void process();
void addSMState(SMState * data); void addSMState(SMState * data); // ownership is transferred
SMState * getSMState(); SMState * getSMState();
void setupLogFiles(); void setupLogFiles();
void releaseAllStrategies(); void releaseAllStrategies();

View File

@@ -34,22 +34,20 @@ namespace rtabmap {
class SMState class SMState
{ {
public: public:
// Constructor 0 : ownership is transferred
SMState(IplImage * image = 0) :
_image(image)
{}
// Constructor 1 // Constructor 1
// image and/or keypoints can be passed for debugging (rtabmap will not re-extract keypoints/descriptors from the image if not null, only for debug/visualization) SMState(const std::list<std::vector<float> > & sensors, const std::list<std::vector<float> > & actuators) :
// take image ownership
SMState(const std::list<std::vector<float> > & sensors, const std::list<std::vector<float> > & actuators, IplImage * image = 0, const std::list<cv::KeyPoint> & keypoints = std::list<cv::KeyPoint>()) :
_sensors(sensors), _sensors(sensors),
_actuators(actuators), _actuators(actuators),
_image(image), _image(0)
_keypoints(keypoints)
{} {}
// Constructor 2 : for convenience with ROS conversion... // Constructor 2 : for convenience with ROS conversion...
// Sensors and actuators vectors will be split into a list with smaller vectors of length sensorStep and actuatorStep respectively. // Sensors and actuators vectors will be split into a list with smaller vectors of length sensorStep and actuatorStep respectively.
// image and/or keypoints can be passed for debugging (rtabmap will not re-extract keypoints/descriptors from the image if not null, only for debug/visualization) SMState(const std::vector<float> & sensors, int sensorStep, const std::vector<float> & actuators, int actuatorStep) :
// take image ownership _image(0)
SMState(const std::vector<float> & sensors, int sensorStep, const std::vector<float> & actuators, int actuatorStep, IplImage * image = 0, const std::list<cv::KeyPoint> & keypoints = std::list<cv::KeyPoint>()) :
_image(image),
_keypoints(keypoints)
{ {
if(sensorStep && sensors.size() % sensorStep != 0) if(sensorStep && sensors.size() % sensorStep != 0)
{ {
@@ -68,19 +66,6 @@ public:
_actuators.push_back(std::vector<float>(actuators.data()+i, actuators.data()+i+actuatorStep)); _actuators.push_back(std::vector<float>(actuators.data()+i, actuators.data()+i+actuatorStep));
} }
} }
// Constructor 3 :
// rtabmap will automatically extract keypoints and descriptors from the image...
// take image ownership
SMState(IplImage * image) :
_image(image)
{}
// Constructor 4 :
// rtabmap will automatically extract keypoints and descriptors from the image...
// take image ownership
SMState(IplImage * image, const std::list<std::vector<float> > & actuators) :
_actuators(actuators),
_image(image)
{}
virtual ~SMState() virtual ~SMState()
{ {
@@ -96,6 +81,17 @@ public:
const std::list<std::vector<float> > & getActuators() const {return _actuators;} const std::list<std::vector<float> > & getActuators() const {return _actuators;}
void setSensors(const std::list<std::vector<float> > & sensors) {_sensors=sensors;} void setSensors(const std::list<std::vector<float> > & sensors) {_sensors=sensors;}
void setActuators(const std::list<std::vector<float> > & actuators) {_actuators=actuators;} void setActuators(const std::list<std::vector<float> > & actuators) {_actuators=actuators;}
void setKeypoints(const std::list<cv::KeyPoint> & keypoints) {_keypoints = keypoints;}
//ownership is transferred
void setImage(IplImage * image)
{
if(_image)
{
cvReleaseImage(&_image);
}
_image = image;
}
void getSensorsMerged(std::vector<float> & sensors, int & step) const void getSensorsMerged(std::vector<float> & sensors, int & step) const
{ {

View File

@@ -36,13 +36,10 @@
namespace rtabmap namespace rtabmap
{ {
SMState * CamPostTreatment::process(IplImage * image) SMState * CamPostTreatment::process(const IplImage * image) const
{ {
if(image) //no threatment...
{ return new SMState();
return new SMState(image);
}
return 0;
} }
CamKeypointTreatment::~CamKeypointTreatment() CamKeypointTreatment::~CamKeypointTreatment()
@@ -56,13 +53,14 @@ CamKeypointTreatment::~CamKeypointTreatment()
delete _keypointDescriptor; delete _keypointDescriptor;
} }
} }
SMState * CamKeypointTreatment::process(IplImage * image) SMState * CamKeypointTreatment::process(const IplImage * image) const
{ {
if(image) if(image)
{ {
std::list<cv::KeyPoint> keypoints = _keypointDetector->generateKeypoints(image); std::list<cv::KeyPoint> keypoints = _keypointDetector->generateKeypoints(image);
std::list<std::vector<float> > descriptors = _keypointDescriptor->generateDescriptors(image, keypoints); std::list<std::vector<float> > descriptors = _keypointDescriptor->generateDescriptors(image, keypoints);
SMState * smState = new SMState(descriptors, std::list<std::vector<float> >(), image, keypoints); SMState * smState = new SMState(descriptors, std::list<std::vector<float> >());
smState->setKeypoints(keypoints);
return smState; return smState;
} }
return 0; return 0;
@@ -292,6 +290,7 @@ void Camera::process()
SMState * smState = _postThreatement->process(image); SMState * smState = _postThreatement->process(image);
if(smState) if(smState)
{ {
smState->setImage(image);
this->post(new SMStateEvent(smState)); this->post(new SMStateEvent(smState));
} }
double elapsed = timer.ticks(); double elapsed = timer.ticks();

View File

@@ -1243,6 +1243,7 @@ void Rtabmap::process()
delete smState; delete smState;
} }
// ownership is transferred
void Rtabmap::addSMState(SMState * data) void Rtabmap::addSMState(SMState * data)
{ {
ULOGGER_DEBUG(""); ULOGGER_DEBUG("");
@@ -1361,6 +1362,7 @@ void Rtabmap::setWorkingDirectory(std::string path)
} }
} }
// ownership is transferred
void Rtabmap::process(SMState * data) void Rtabmap::process(SMState * data)
{ {
if(!this->isRunning()) if(!this->isRunning())