/* +---------------------------------------------------------------------------+
   |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
   |                                                                           |
   |                   http://mrpt.sourceforge.net/                            |
   |                                                                           |
   |   Copyright (C) 2005-2008  University of Malaga                           |
   |                                                                           |
   |    This software was written by the Perception and Robotics               |
   |      research group, University of Malaga (Spain).                        |
   |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
   |                                                                           |
   |  This file is part of the MRPT project.                                   |
   |                                                                           |
   |     MRPT is free software: you can redistribute it and/or modify          |
   |     it under the terms of the GNU General Public License as published by  |
   |     the Free Software Foundation, either version 3 of the License, or     |
   |     (at your option) any later version.                                   |
   |                                                                           |
   |   MRPT is distributed in the hope that it will be useful,                 |
   |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
   |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
   |     GNU General Public License for more details.                          |
   |                                                                           |
   |     You should have received a copy of the GNU General Public License     |
   |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
   |                                                                           |
   +---------------------------------------------------------------------------+ */
#ifndef COBSERVATION_H
#define COBSERVATION_H

#include <MRPT/UTILS/CSerializable.h>
#include <MRPT/UTILS/SystemUtils.h>

namespace MRML
{
	/** Used for CObservationBearingRange::TMeasurement::beaconID
	  */
	#define INVALID_LANDMARK_ID 	(-1)

	/** Used for CObservationBeaconRange
	  */
	#define INVALID_BEACON_ID  		(-1)

	class CMetricMap;
	class CObservation;
	class CPosePDF;
	class CPose2D;
	class CPose3D;

	/** Declares a class that represents any robot's observation.
	       This is a base class for many types of sensors
		     observations. Users can add a new observation type
			 creating a new class deriving from this one.<br>
		   <b>IMPORTANT</b>: Observations doesn't include any information about the
		    robot pose beliefs, just the raw observation and, where
			aplicable, information about sensor position or
			orientation respect to robotic coordinates origin.
     *
	 * \sa CSensoryFrame, CMetricMap
	 */
	class CObservation : public UTILS::CSerializable
	{
		// This must be added to any CSerializable derived class:
		DEFINE_VIRTUAL_SERIALIZABLE( CObservation )

	 public:

		 /** Constructor: It sets the initial timestamp to current time
		   */
		 CObservation();

		 /** Inserts a pure virtual method for finding the likelihood between this
		  *   and another observation, probably only of the same derived class. The operator
		  *   may be asymmetric.
		  *
		  * \param anotherObs The other observation to compute likelihood with.
		  * \param anotherObsPose If known, the belief about the robot pose when the other observation was taken can be supplied here, or NULL if it is unknown.
		  *
		  * \return Returns a likelihood measurement, in the range [0,1].
		  *	\exception std::exception On any error, as another observation being of an invalid class.
		  */
		 virtual float  likelihoodWith( const CObservation *anotherObs, const CPosePDF *anotherObsPose = NULL ) const = 0;


		 /** This method is equivalent to:
		  * \code
		  *		map->insertObservation(this, robotPose)
		  * \endcode
		  * \param theMap The map where this observation is to be inserted: the map will be updated.
		  * \param robotPose The pose of the robot base for this observation, relative to the target metric map. Set to NULL (default) to use (0,0,0deg)
		  *
		  * \return Returns true if the map has been updated, or false if this observations
		  *			has nothing to do with a metric map (for example, a sound observation).
		  *
		  * \sa CMetricMap::insertObservation
		  */
		 bool  insertObservationInto( CMetricMap *theMap, const CPose3D *robotPose = NULL ) const;

		 /** The associated time-stamp.
		  */
		UTILS::TTimeStamp	timestamp;

		/** An arbitrary label that can be used to identify the sensor.
		  */
		std::string			sensorLabel;

		/** A general method to retrieve the sensor pose on the robot.
		  *  Note that most sensors will return a full (6D) CPose3D, but see the derived classes for more details or special cases.
		  * \sa setSensorPose
		  */
		virtual void getSensorPose( CPose3D &out_sensorPose ) const = 0;

		/** A general method to change the sensor pose on the robot.
		  *  Note that most sensors will use the full (6D) CPose3D, but see the derived classes for more details or special cases.
		  * \sa getSensorPose
		  */
		virtual void setSensorPose( const CPose3D &newSensorPose ) = 0;



	}; // End of class def.

	DEFINE_SERIALIZABLE_POST( CObservation )

} // End of namespace

#endif
