LinearCamera Class Reference

An helper class for linear camera sensors of various robots. More...

Inheritance diagram for LinearCamera:

Public Member Functions

 LinearCamera (WObject *obj, wMatrix mtr, double aperture, unsigned int numReceptors, double maxDistance, QColor backgroundColor)
 Constructor. More...
 
 LinearCamera (WObject *obj, wMatrix mtr, QVector< SimpleInterval > receptorsRanges, double maxDistance, QColor backgroundColor)
 Constructor. More...
 
virtual ~LinearCamera ()
 Destructor. More...
 
const QColor & colorForReceptor (int i) const
 Returns the color perceived by the i-th receptor. More...
 
void drawCamera (bool d)
 Sets whether to draw the linear camera or not. More...
 
QColor getBackgroundColor () const
 Returns the background color. More...
 
unsigned int getNumReceptors () const
 Returns the number of receptors. More...
 
void ignoreWalls (bool ignore)
 Sets whether walls are ignored or not. More...
 
void setBackgroundColor (QColor color)
 Sets the background color. More...
 
void update ()
 Updates the sensor reading. More...
 
bool wallsIgnored () const
 Whether walls are ignored or not. More...
 
- Public Member Functions inherited from ConcurrentResourcesUser
void addUsableResource (QString resource)
 
void addUsableResources (QStringList resources)
 
void declareResource (QString name, T *resource, QString lockBuddy="")
 
void deleteResource (QString name)
 
T * getResource (QString name, bool *resourceExists=NULL)
 
bool hasResource (QString name) const
 
void removeAllUsableResources ()
 
void removeUsableResource (QString resource)
 
void removeUsableResources (QStringList resources)
 
virtual void shareResourcesWith (ResourcesUser *buddy)
 
void usableResources (QStringList resources)
 
bool usedResourcesExist (QStringList *nonExistingResources=NULL) const
 

Additional Inherited Members

- Public Types inherited from ResourcesUser
typedef Resource::ResourceChangeType ResourceChangeType
 
- Public Types inherited from Resource
enum  ResourceChangeType
 
- Protected Member Functions inherited from ConcurrentResourcesUser
T * getResource ()
 
- Protected Member Functions inherited from ResourcesUser
 ResourcesUser (const ResourcesUser &other)
 
virtual void notifyResourceChange (ResourceHandler *resource, ResourceChangeType changeType)=0
 
ResourcesUseroperator= (const ResourcesUser &other)
 
- Protected Attributes inherited from ResourcesUser
ResourceCollectionHolder m_resources
 

Detailed Description

An helper class for linear camera sensors of various robots.

This class has all that is needed to implement a linear camera sensor. It is fully parametrized, so to implement an actual sensor one just needs to instantiate it with the correct set of parameters. The camera is attached to an object and its transformation matrix is relative to the object to which it is attached. The up vector is the local Z axis, the camera points towards X and is on the XY plane. The camera only takes into account the objects in the "2dobjects" resource (a list of PhyObject2DWrapper objects). The number of receptors, their position and their aperture can be specified in two ways. The easiest one is to set the aperture and the number of receptors: all receptors will have the same range and will be placed symmetrically with respect to the X axis. The more general way is to supply a list of SimpleIntervals, where each interval represents a single receptor. This way you can have receptors of different sizes, overlapping receptors, blind spots and receptors with a custom order (the order of receptors is the same as in the list of intervals). Moreover the sensor takes into account visual occlusion. To work, this class need to access the arena object, so a resource named "arena" which points to the instance of the arena should be present.

Note
The current implementation of the camera doesn't work well with occluding objects. In fact the occlusion is only computed on the basis of the distance between the object center and the camera. If however you have e.g. a cylinder in front of big wall, the cylinder can be more distant than the wall and so being considered behind the wall. For this reason it is possible to ignore all walls using the ignoreWalls() function (this is usefult if e.g. you have only perimetral walls of the same color as the background)
When more than one object of different colors hits a single receptor, here we take the average of the colors (weighted by the percentage of the receptor occupied by each object). This is not physically correct, so please be careful when using big receptors with a lot of objects of different colors.

Definition at line 487 of file sensors.h.

Constructor & Destructor Documentation

LinearCamera ( WObject obj,
wMatrix  mtr,
double  aperture,
unsigned int  numReceptors,
double  maxDistance,
QColor  backgroundColor 
)

Constructor.

Use this constructor to have receptors that have the same aperture and are symmetrical with respect to the X axis

Parameters
objthe object to which the sensor is attached. This cannot be NULL
mtrthe transformation matrix relative to the object to which the sensor is attached. The up vector is the local Z axis, the camera points towards X and is on the XY plane.
aperturethe aperture of the sensor in radiants
numReceptorsthe number of receptors
maxDistancethe distance above which objects are not seen anymore
backgroundColorthe background color (used when no object is perceived by a given receptor)

Definition at line 1005 of file sensors.cpp.

References ConcurrentResourcesUser::addUsableResource().

LinearCamera ( WObject obj,
wMatrix  mtr,
QVector< SimpleInterval receptorsRanges,
double  maxDistance,
QColor  backgroundColor 
)

Constructor.

Use this contructor to be able to directly specify the list of receptors

Parameters
objthe object to which the sensor is attached. This cannot be NULL
mtrthe transformation matrix relative to the object to which the sensor is attached. The up vector is the local Z axis, the camera points towards X and is on the XY plane.
receptorsRangesthe list of ranges for receptors. Angles are in radiants
maxDistancethe distance above which objects are not seen anymore
backgroundColorthe background color (used when no object is perceived by a given receptor)

Definition at line 1023 of file sensors.cpp.

References ConcurrentResourcesUser::addUsableResource().

~LinearCamera ( )
virtual

Destructor.

Definition at line 1041 of file sensors.cpp.

Member Function Documentation

const QColor& colorForReceptor ( int  i) const
inline

Returns the color perceived by the i-th receptor.

Parameters
ithe index of the photoreceptor to return
Returns
the color perceived by the receptor

Definition at line 544 of file sensors.h.

Referenced by MarXbotLinearCameraSensorNew::update().

void drawCamera ( bool  d)

Sets whether to draw the linear camera or not.

Parameters
dif true the camera is drawn, if false it is not

Definition at line 1237 of file sensors.cpp.

QColor getBackgroundColor ( ) const
inline

Returns the background color.

Returns
the background color (i.e. the color used when no object is perceived by a given receptor)

Definition at line 565 of file sensors.h.

unsigned int getNumReceptors ( ) const
inline

Returns the number of receptors.

Returns
the number of receptors

Definition at line 554 of file sensors.h.

Referenced by LinearCamera::update().

void ignoreWalls ( bool  ignore)
inline

Sets whether walls are ignored or not.

See the note in the class description

Parameters
ignorewhether to ignore walls or not

Definition at line 594 of file sensors.h.

void setBackgroundColor ( QColor  color)
inline

Sets the background color.

Parameters
colorthe background color (i.e. the color used when no object is perceived by a given receptor)

Definition at line 576 of file sensors.h.

bool wallsIgnored ( ) const
inline

Whether walls are ignored or not.

See the note in the class description

Returns
true if walls are ignored, false otherwise

Definition at line 605 of file sensors.h.


The documentation for this class was generated from the following files: