YARP
Yet Another Robot Platform
frameGrabberCropper.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #include "frameGrabberCropper.h"
7 
8 #include <yarp/os/Log.h>
9 #include <yarp/os/LogStream.h>
10 
11 namespace {
12 YARP_LOG_COMPONENT(FRAMEGRABBERCROPPER, "yarp.device.frameGrabberCropper")
13 }
14 
16 {
17  close();
18 }
19 
20 
22 {
23  int x1;
24  if (config.check("x1", "x1") && config.find("x1").isInt32()) {
25  x1 = config.find("x1").asInt32();
26  } else {
27  yCError(FRAMEGRABBERCROPPER) << "x1 parameter not found";
28  return false;
29  }
30 
31  int y1;
32  if (config.check("y1", "y1") && config.find("y1").isInt32()) {
33  y1 = config.find("y1").asInt32();
34  } else {
35  yCError(FRAMEGRABBERCROPPER) << "y1 parameter not found";
36  return false;
37  }
38 
39  int x2;
40  if (config.check("x2", "x2") && config.find("x2").isInt32()) {
41  x2 = config.find("x2").asInt32();
42  } else {
43  yCError(FRAMEGRABBERCROPPER) << "x2 parameter not found";
44  return false;
45  }
46 
47  int y2;
48  if (config.check("y2", "y2") && config.find("y2").isInt32()) {
49  y2 = config.find("y2").asInt32();
50  } else {
51  yCError(FRAMEGRABBERCROPPER) << "y2 parameter not found";
52  return false;
53  }
54 
57 
58  if (config.check("forwardRgbVisualParams", "Forward the the IRgbVisualParams calls to the attached device")) {
59  forwardRgbVisualParams = true;
60  }
61 
62  if (config.check("subdevice")) {
64  subdevice = new yarp::dev::PolyDriver;
65  p.fromString(config.toString());
66  p.setMonitor(config.getMonitor(), "subdevice"); // pass on any monitoring
67  p.unput("device");
68  p.put("device", config.find("subdevice").asString()); // subdevice was already checked before
69 
70  // if errors occurred during open, quit here.
71  if (!subdevice->open(p) || !(subdevice->isValid())) {
72  yCError(FRAMEGRABBERCROPPER, "Could not open subdevice");
73  return false;
74  }
75 
76  if (!attach(subdevice)) {
77  yCError(FRAMEGRABBERCROPPER, "Could not attach subdevice");
78  subdevice->close();
79  return false;
80  }
81  subdeviceOwned = true;
82  }
83 
84  return true;
85 }
86 
87 
89 {
90  if (subdeviceOwned) {
91  subdevice->close();
92  delete subdevice;
93  subdevice = nullptr;
94  }
95  return true;
96 }
97 
99 {
100  if (!poly->isValid()) {
101  yCError(FRAMEGRABBERCROPPER) << "The device is not valid";
102  return false;
103  }
104 
107  poly->view(iFrameGrabberControls);
108  poly->view(iFrameGrabberControlsDC1394);
109  poly->view(iRgbVisualParams);
110  poly->view(iPreciselyTimed);
111 
113  yCError(FRAMEGRABBERCROPPER) << "The device does not implement the required interfaces";
114  return false;
115  }
116 
117  return true;
118 }
119 
121 {
124  iFrameGrabberControls = nullptr;
125  iFrameGrabberControlsDC1394 = nullptr;
126  iRgbVisualParams = nullptr;
127  iPreciselyTimed = nullptr;
128  return true;
129 }
130 
132 {
133  if (device2attach.size() != 1) {
134  yCError(FRAMEGRABBERCROPPER, "Expected only one device to be attached");
135  return false;
136  }
137 
138  return attach(device2attach[0]->poly);
139 }
140 
142 {
143  return detach();
144 }
yarp::dev::IFrameGrabberOf< yarp::sig::ImageOf< yarp::sig::PixelMono > > * iFrameGrabberOf
bool close() override
Close the DeviceDriver.
bool attachAll(const yarp::dev::PolyDriverList &device2attach) override
Attach to a list of objects.
bool detach() override
Detach the object (you must have first called attach).
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool detachAll() override
Detach the object (you must have first called attach).
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:88
A container for a device driver.
Definition: PolyDriver.h:23
bool close() override
Close the DeviceDriver.
Definition: PolyDriver.cpp:173
bool isValid() const
Check if device is valid.
Definition: PolyDriver.cpp:196
bool open(const std::string &txt)
Construct and configure a device by its common name.
Definition: PolyDriver.cpp:140
A class for storing options and configuration information.
Definition: Property.h:33
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1063
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:1015
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
Definition: Property.cpp:1046
A base class for nested structures that can be searched.
Definition: Searchable.h:63
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
virtual bool isInt32() const
Checks if value is a 32-bit integer.
Definition: Value.cpp:132
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
#define yCError(component,...)
Definition: LogComponent.h:213
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76