perspective_camera_equipped_entity.cpp
Go to the documentation of this file.
2 #include <argos3/core/simulator/space/space.h>
3 #include <argos3/core/simulator/entity/composable_entity.h>
4 
5 namespace argos {
6 
7  /****************************************/
8  /****************************************/
9 
11  CEntity(pc_parent),
12  m_fFocalLength(0.0f),
13  m_fRange(0.0f),
14  m_nImagePxWidth(0),
15  m_nImagePxHeight(0),
16  m_psAnchor(nullptr) {
17  Disable();
18  }
19 
20  /****************************************/
21  /****************************************/
22 
24  const std::string& str_id,
25  const CRadians& c_aperture,
26  Real f_focal_length,
27  Real f_range,
28  SInt32 n_width,
29  SInt32 n_height,
30  SAnchor& s_anchor) :
31  CEntity(pc_parent, str_id),
32  m_cAperture(c_aperture),
33  m_fFocalLength(f_focal_length),
34  m_fRange(f_range),
35  m_psAnchor(&s_anchor) {
36  SetImagePxSize(n_width, n_height);
37  Disable();
38  }
39 
40  /****************************************/
41  /****************************************/
42 
44  try {
45  CEntity::Init(t_tree);
46  CDegrees cApertureDeg;
47  GetNodeAttribute(t_tree, "aperture", cApertureDeg);
48  m_cAperture = ToRadians(cApertureDeg);
49  GetNodeAttribute(t_tree, "focal_length", m_fFocalLength);
50  GetNodeAttribute(t_tree, "range", m_fRange);
51  GetNodeAttribute(t_tree, "width", m_nImagePxWidth);
52  GetNodeAttribute(t_tree, "height", m_nImagePxHeight);
53  SetImagePxSize(m_nImagePxWidth, m_nImagePxHeight);
54  std::string strAnchorId;
55  GetNodeAttribute(t_tree, "anchor", strAnchorId);
56  /*
57  * NOTE: here we get a reference to the embodied entity
58  * This line works under the assumption that:
59  * 1. the PerspectiveCameraEquippedEntity has a parent;
60  * 2. the parent has a child whose id is "body"
61  * 3. the "body" is an embodied entity
62  * If any of the above is false, this line will bomb out.
63  */
64  auto& cBody = GetParent().GetComponent<CEmbodiedEntity>("body");
65  m_psAnchor = &cBody.GetAnchor(strAnchorId);
66  }
67  catch(CARGoSException& ex) {
68  THROW_ARGOSEXCEPTION_NESTED("Error initializing the perspective camera equipped entity \"" << GetId() << "\"", ex);
69  }
70  }
71 
72  /****************************************/
73  /****************************************/
74 
76  if (m_psAnchor) {
77  m_psAnchor->Enable();
78  }
79  }
80 
81  /****************************************/
82  /****************************************/
83 
85  if (m_psAnchor) {
86  m_psAnchor->Disable();
87  }
88  }
89 
90  /****************************************/
91  /****************************************/
92 
94 
95  /****************************************/
96  /****************************************/
97 
98 }
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
signed int SInt32
32-bit signed integer.
Definition: datatypes.h:93
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
CRadians ToRadians(const CDegrees &c_degrees)
Converts CDegrees to CRadians.
Definition: angles.h:498
REGISTER_STANDARD_SPACE_OPERATIONS_ON_ENTITY(CEntity)
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
Basic class for an entity that contains other entities.
CEntity & GetComponent(const std::string &str_component)
Returns the component with the passed string label.
This entity is a link to a body in the physics engine.
The basic entity type.
Definition: entity.h:90
const std::string & GetId() const
Returns the id of this entity.
Definition: entity.h:157
CComposableEntity & GetParent()
Returns this entity's parent.
Definition: entity.cpp:91
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
Definition: entity.cpp:40
An anchor related to the body of an entity.
Definition: physics_model.h:38
void Disable()
Disables this anchor.
void Enable()
Enables this anchor.
The exception that wraps all errors in ARGoS.
It defines the basic type CRadians, used to store an angle value in radians.
Definition: angles.h:42
It defines the basic type CDegrees, used to store an angle value in degrees.
Definition: angles.h:288
void SetImagePxSize(SInt32 n_width, SInt32 n_height)
Sets the image size in pixel.
CPerspectiveCameraEquippedEntity(CComposableEntity *pc_parent)
Class constructor.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.