14 #include <yarp/sig/SegmentationModuleInterface.h>
16 #include <yarp/os/idl/WireTypes.h>
21 class SegmentationModuleInterface_set_sigma_helper :
22 public yarp::os::Portable
25 explicit SegmentationModuleInterface_set_sigma_helper(
const double newValue);
26 bool write(yarp::os::ConnectionWriter& connection)
const override;
27 bool read(yarp::os::ConnectionReader& connection)
override;
32 SegmentationModuleInterface_set_sigma_helper::SegmentationModuleInterface_set_sigma_helper(
const double newValue) :
37 bool SegmentationModuleInterface_set_sigma_helper::write(yarp::os::ConnectionWriter& connection)
const
39 yarp::os::idl::WireWriter writer(connection);
40 if (!writer.writeListHeader(3)) {
43 if (!writer.writeTag(
"set_sigma", 1, 2)) {
46 if (!writer.writeFloat64(m_newValue)) {
52 bool SegmentationModuleInterface_set_sigma_helper::read(yarp::os::ConnectionReader& connection)
54 yarp::os::idl::WireReader reader(connection);
55 if (!reader.readListReturn()) {
61 class SegmentationModuleInterface_set_k_helper :
62 public yarp::os::Portable
65 explicit SegmentationModuleInterface_set_k_helper(
const double newValue);
66 bool write(yarp::os::ConnectionWriter& connection)
const override;
67 bool read(yarp::os::ConnectionReader& connection)
override;
72 SegmentationModuleInterface_set_k_helper::SegmentationModuleInterface_set_k_helper(
const double newValue) :
77 bool SegmentationModuleInterface_set_k_helper::write(yarp::os::ConnectionWriter& connection)
const
79 yarp::os::idl::WireWriter writer(connection);
80 if (!writer.writeListHeader(3)) {
83 if (!writer.writeTag(
"set_k", 1, 2)) {
86 if (!writer.writeFloat64(m_newValue)) {
92 bool SegmentationModuleInterface_set_k_helper::read(yarp::os::ConnectionReader& connection)
94 yarp::os::idl::WireReader reader(connection);
95 if (!reader.readListReturn()) {
101 class SegmentationModuleInterface_set_minRegion_helper :
102 public yarp::os::Portable
105 explicit SegmentationModuleInterface_set_minRegion_helper(
const double newValue);
106 bool write(yarp::os::ConnectionWriter& connection)
const override;
107 bool read(yarp::os::ConnectionReader& connection)
override;
112 SegmentationModuleInterface_set_minRegion_helper::SegmentationModuleInterface_set_minRegion_helper(
const double newValue) :
117 bool SegmentationModuleInterface_set_minRegion_helper::write(yarp::os::ConnectionWriter& connection)
const
119 yarp::os::idl::WireWriter writer(connection);
120 if (!writer.writeListHeader(3)) {
123 if (!writer.writeTag(
"set_minRegion", 1, 2)) {
126 if (!writer.writeFloat64(m_newValue)) {
132 bool SegmentationModuleInterface_set_minRegion_helper::read(yarp::os::ConnectionReader& connection)
134 yarp::os::idl::WireReader reader(connection);
135 if (!reader.readListReturn()) {
141 class SegmentationModuleInterface_get_sigma_helper :
142 public yarp::os::Portable
145 explicit SegmentationModuleInterface_get_sigma_helper();
146 bool write(yarp::os::ConnectionWriter& connection)
const override;
147 bool read(yarp::os::ConnectionReader& connection)
override;
149 thread_local
static double s_return_helper;
152 thread_local
double SegmentationModuleInterface_get_sigma_helper::s_return_helper = {};
154 SegmentationModuleInterface_get_sigma_helper::SegmentationModuleInterface_get_sigma_helper()
156 s_return_helper = {};
159 bool SegmentationModuleInterface_get_sigma_helper::write(yarp::os::ConnectionWriter& connection)
const
161 yarp::os::idl::WireWriter writer(connection);
162 if (!writer.writeListHeader(2)) {
165 if (!writer.writeTag(
"get_sigma", 1, 2)) {
171 bool SegmentationModuleInterface_get_sigma_helper::read(yarp::os::ConnectionReader& connection)
173 yarp::os::idl::WireReader reader(connection);
174 if (!reader.readListReturn()) {
177 if (!reader.readFloat64(s_return_helper)) {
184 class SegmentationModuleInterface_get_k_helper :
185 public yarp::os::Portable
188 explicit SegmentationModuleInterface_get_k_helper();
189 bool write(yarp::os::ConnectionWriter& connection)
const override;
190 bool read(yarp::os::ConnectionReader& connection)
override;
192 thread_local
static double s_return_helper;
195 thread_local
double SegmentationModuleInterface_get_k_helper::s_return_helper = {};
197 SegmentationModuleInterface_get_k_helper::SegmentationModuleInterface_get_k_helper()
199 s_return_helper = {};
202 bool SegmentationModuleInterface_get_k_helper::write(yarp::os::ConnectionWriter& connection)
const
204 yarp::os::idl::WireWriter writer(connection);
205 if (!writer.writeListHeader(2)) {
208 if (!writer.writeTag(
"get_k", 1, 2)) {
214 bool SegmentationModuleInterface_get_k_helper::read(yarp::os::ConnectionReader& connection)
216 yarp::os::idl::WireReader reader(connection);
217 if (!reader.readListReturn()) {
220 if (!reader.readFloat64(s_return_helper)) {
227 class SegmentationModuleInterface_get_minRegion_helper :
228 public yarp::os::Portable
231 explicit SegmentationModuleInterface_get_minRegion_helper();
232 bool write(yarp::os::ConnectionWriter& connection)
const override;
233 bool read(yarp::os::ConnectionReader& connection)
override;
235 thread_local
static double s_return_helper;
238 thread_local
double SegmentationModuleInterface_get_minRegion_helper::s_return_helper = {};
240 SegmentationModuleInterface_get_minRegion_helper::SegmentationModuleInterface_get_minRegion_helper()
242 s_return_helper = {};
245 bool SegmentationModuleInterface_get_minRegion_helper::write(yarp::os::ConnectionWriter& connection)
const
247 yarp::os::idl::WireWriter writer(connection);
248 if (!writer.writeListHeader(2)) {
251 if (!writer.writeTag(
"get_minRegion", 1, 2)) {
257 bool SegmentationModuleInterface_get_minRegion_helper::read(yarp::os::ConnectionReader& connection)
259 yarp::os::idl::WireReader reader(connection);
260 if (!reader.readListReturn()) {
263 if (!reader.readFloat64(s_return_helper)) {
270 class SegmentationModuleInterface_get_num_components_helper :
271 public yarp::os::Portable
274 explicit SegmentationModuleInterface_get_num_components_helper();
275 bool write(yarp::os::ConnectionWriter& connection)
const override;
276 bool read(yarp::os::ConnectionReader& connection)
override;
278 thread_local
static std::int32_t s_return_helper;
281 thread_local std::int32_t SegmentationModuleInterface_get_num_components_helper::s_return_helper = {};
283 SegmentationModuleInterface_get_num_components_helper::SegmentationModuleInterface_get_num_components_helper()
285 s_return_helper = {};
288 bool SegmentationModuleInterface_get_num_components_helper::write(yarp::os::ConnectionWriter& connection)
const
290 yarp::os::idl::WireWriter writer(connection);
291 if (!writer.writeListHeader(3)) {
294 if (!writer.writeTag(
"get_num_components", 1, 3)) {
300 bool SegmentationModuleInterface_get_num_components_helper::read(yarp::os::ConnectionReader& connection)
302 yarp::os::idl::WireReader reader(connection);
303 if (!reader.readListReturn()) {
306 if (!reader.readI32(s_return_helper)) {
313 class SegmentationModuleInterface_get_component_around_helper :
314 public yarp::os::Portable
317 explicit SegmentationModuleInterface_get_component_around_helper(
const Pixel& objCenter);
318 bool write(yarp::os::ConnectionWriter& connection)
const override;
319 bool read(yarp::os::ConnectionReader& connection)
override;
323 thread_local
static std::vector<Pixel> s_return_helper;
326 thread_local std::vector<Pixel> SegmentationModuleInterface_get_component_around_helper::s_return_helper = {};
328 SegmentationModuleInterface_get_component_around_helper::SegmentationModuleInterface_get_component_around_helper(
const Pixel& objCenter) :
329 m_objCenter{objCenter}
333 bool SegmentationModuleInterface_get_component_around_helper::write(yarp::os::ConnectionWriter& connection)
const
335 yarp::os::idl::WireWriter writer(connection);
336 if (!writer.writeListHeader(5)) {
339 if (!writer.writeTag(
"get_component_around", 1, 3)) {
342 if (!writer.write(m_objCenter)) {
348 bool SegmentationModuleInterface_get_component_around_helper::read(yarp::os::ConnectionReader& connection)
350 yarp::os::idl::WireReader reader(connection);
351 if (!reader.readListReturn()) {
354 s_return_helper.clear();
356 yarp::os::idl::WireState _etype3;
357 reader.readListBegin(_etype3, _size0);
358 s_return_helper.resize(_size0);
359 for (
size_t _i4 = 0; _i4 < _size0; ++_i4) {
360 if (!reader.readNested(s_return_helper[_i4])) {
365 reader.readListEnd();
370 SegmentationModuleInterface::SegmentationModuleInterface()
372 yarp().setOwner(*
this);
375 void SegmentationModuleInterface::set_sigma(
const double newValue)
377 SegmentationModuleInterface_set_sigma_helper helper{newValue};
378 if (!yarp().canWrite()) {
379 yError(
"Missing server method '%s'?",
"void SegmentationModuleInterface::set_sigma(const double newValue)");
381 yarp().write(helper, helper);
384 void SegmentationModuleInterface::set_k(
const double newValue)
386 SegmentationModuleInterface_set_k_helper helper{newValue};
387 if (!yarp().canWrite()) {
388 yError(
"Missing server method '%s'?",
"void SegmentationModuleInterface::set_k(const double newValue)");
390 yarp().write(helper, helper);
393 void SegmentationModuleInterface::set_minRegion(
const double newValue)
395 SegmentationModuleInterface_set_minRegion_helper helper{newValue};
396 if (!yarp().canWrite()) {
397 yError(
"Missing server method '%s'?",
"void SegmentationModuleInterface::set_minRegion(const double newValue)");
399 yarp().write(helper, helper);
402 double SegmentationModuleInterface::get_sigma()
404 SegmentationModuleInterface_get_sigma_helper helper{};
405 if (!yarp().canWrite()) {
406 yError(
"Missing server method '%s'?",
"double SegmentationModuleInterface::get_sigma()");
408 bool ok = yarp().write(helper, helper);
409 return ok ? SegmentationModuleInterface_get_sigma_helper::s_return_helper :
double{};
412 double SegmentationModuleInterface::get_k()
414 SegmentationModuleInterface_get_k_helper helper{};
415 if (!yarp().canWrite()) {
416 yError(
"Missing server method '%s'?",
"double SegmentationModuleInterface::get_k()");
418 bool ok = yarp().write(helper, helper);
419 return ok ? SegmentationModuleInterface_get_k_helper::s_return_helper :
double{};
422 double SegmentationModuleInterface::get_minRegion()
424 SegmentationModuleInterface_get_minRegion_helper helper{};
425 if (!yarp().canWrite()) {
426 yError(
"Missing server method '%s'?",
"double SegmentationModuleInterface::get_minRegion()");
428 bool ok = yarp().write(helper, helper);
429 return ok ? SegmentationModuleInterface_get_minRegion_helper::s_return_helper :
double{};
432 std::int32_t SegmentationModuleInterface::get_num_components()
434 SegmentationModuleInterface_get_num_components_helper helper{};
435 if (!yarp().canWrite()) {
436 yError(
"Missing server method '%s'?",
"std::int32_t SegmentationModuleInterface::get_num_components()");
438 bool ok = yarp().write(helper, helper);
439 return ok ? SegmentationModuleInterface_get_num_components_helper::s_return_helper : std::int32_t{};
442 std::vector<Pixel> SegmentationModuleInterface::get_component_around(
const Pixel& objCenter)
444 SegmentationModuleInterface_get_component_around_helper helper{objCenter};
445 if (!yarp().canWrite()) {
446 yError(
"Missing server method '%s'?",
"std::vector<Pixel> SegmentationModuleInterface::get_component_around(const Pixel& objCenter)");
448 bool ok = yarp().write(helper, helper);
449 return ok ? SegmentationModuleInterface_get_component_around_helper::s_return_helper : std::vector<Pixel>{};
453 std::vector<std::string> SegmentationModuleInterface::help(
const std::string& functionName)
455 bool showAll = (functionName ==
"--all");
456 std::vector<std::string> helpString;
458 helpString.emplace_back(
"*** Available commands:");
459 helpString.emplace_back(
"set_sigma");
460 helpString.emplace_back(
"set_k");
461 helpString.emplace_back(
"set_minRegion");
462 helpString.emplace_back(
"get_sigma");
463 helpString.emplace_back(
"get_k");
464 helpString.emplace_back(
"get_minRegion");
465 helpString.emplace_back(
"get_num_components");
466 helpString.emplace_back(
"get_component_around");
467 helpString.emplace_back(
"help");
469 if (functionName ==
"set_sigma") {
470 helpString.emplace_back(
"void set_sigma(const double newValue) ");
471 helpString.emplace_back(
"Set sigma (smoothing) parameter for the algorithm ");
472 helpString.emplace_back(
"@param newValue new value for sigma parameter ");
474 if (functionName ==
"set_k") {
475 helpString.emplace_back(
"void set_k(const double newValue) ");
476 helpString.emplace_back(
"Set k (scale factor for boundary-detection threshold function) parameter for the algorithm ");
477 helpString.emplace_back(
"@param newValue new value for k parameter ");
479 if (functionName ==
"set_minRegion") {
480 helpString.emplace_back(
"void set_minRegion(const double newValue) ");
481 helpString.emplace_back(
"Set minRegion parameter for the algorithm, i.e., the minimum size of any segmented component ");
482 helpString.emplace_back(
"@param newValue new value for minRegion parameter ");
484 if (functionName ==
"get_sigma") {
485 helpString.emplace_back(
"double get_sigma() ");
486 helpString.emplace_back(
"Get sigma (smoothing) parameter for the algorithm ");
487 helpString.emplace_back(
"@return current value for sigma parameter ");
489 if (functionName ==
"get_k") {
490 helpString.emplace_back(
"double get_k() ");
491 helpString.emplace_back(
"Get k (scale factor for boundary-detection threshold function) parameter for the algorithm ");
492 helpString.emplace_back(
"@return current value for k parameter ");
494 if (functionName ==
"get_minRegion") {
495 helpString.emplace_back(
"double get_minRegion() ");
496 helpString.emplace_back(
"Get minRegion parameter for the algorithm, i.e., the minimum size of any segmented component ");
497 helpString.emplace_back(
"@return current value for minRegion parameter ");
499 if (functionName ==
"get_num_components") {
500 helpString.emplace_back(
"std::int32_t get_num_components() ");
501 helpString.emplace_back(
"Get the number of segmented components that have been detected in the last provided image ");
502 helpString.emplace_back(
"@return number of segmented components ");
504 if (functionName ==
"get_component_around") {
505 helpString.emplace_back(
"std::vector<Pixel> get_component_around(const Pixel& objCenter) ");
506 helpString.emplace_back(
"Get the list of pixels corresponding to the component to which a given pixel belongs ");
507 helpString.emplace_back(
"@param objCenter a pixel belonging to the region of interest ");
508 helpString.emplace_back(
"@return list of pixels belonging to the same component as the input pixels ");
510 if (functionName ==
"help") {
511 helpString.emplace_back(
"std::vector<std::string> help(const std::string& functionName = \"--all\")");
512 helpString.emplace_back(
"Return list of available commands, or help message for a specific function");
513 helpString.emplace_back(
"@param functionName name of command for which to get a detailed description. If none or '--all' is provided, print list of available commands");
514 helpString.emplace_back(
"@return list of strings (one string per line)");
517 if (helpString.empty()) {
518 helpString.emplace_back(
"Command not found");
524 bool SegmentationModuleInterface::read(yarp::os::ConnectionReader& connection)
526 yarp::os::idl::WireReader reader(connection);
527 reader.expectAccept();
528 if (!reader.readListHeader()) {
533 std::string tag = reader.readTag();
534 bool direct = (tag ==
"__direct__");
536 tag = reader.readTag();
538 while (!reader.isError()) {
539 if (tag ==
"set_sigma") {
541 if (!reader.readFloat64(newValue)) {
546 yarp::os::idl::WireWriter writer(reader);
547 if (!writer.isNull()) {
548 if (!writer.writeListHeader(0)) {
555 if (tag ==
"set_k") {
557 if (!reader.readFloat64(newValue)) {
562 yarp::os::idl::WireWriter writer(reader);
563 if (!writer.isNull()) {
564 if (!writer.writeListHeader(0)) {
571 if (tag ==
"set_minRegion") {
573 if (!reader.readFloat64(newValue)) {
577 set_minRegion(newValue);
578 yarp::os::idl::WireWriter writer(reader);
579 if (!writer.isNull()) {
580 if (!writer.writeListHeader(0)) {
587 if (tag ==
"get_sigma") {
588 SegmentationModuleInterface_get_sigma_helper::s_return_helper = get_sigma();
589 yarp::os::idl::WireWriter writer(reader);
590 if (!writer.isNull()) {
591 if (!writer.writeListHeader(1)) {
594 if (!writer.writeFloat64(SegmentationModuleInterface_get_sigma_helper::s_return_helper)) {
601 if (tag ==
"get_k") {
602 SegmentationModuleInterface_get_k_helper::s_return_helper = get_k();
603 yarp::os::idl::WireWriter writer(reader);
604 if (!writer.isNull()) {
605 if (!writer.writeListHeader(1)) {
608 if (!writer.writeFloat64(SegmentationModuleInterface_get_k_helper::s_return_helper)) {
615 if (tag ==
"get_minRegion") {
616 SegmentationModuleInterface_get_minRegion_helper::s_return_helper = get_minRegion();
617 yarp::os::idl::WireWriter writer(reader);
618 if (!writer.isNull()) {
619 if (!writer.writeListHeader(1)) {
622 if (!writer.writeFloat64(SegmentationModuleInterface_get_minRegion_helper::s_return_helper)) {
629 if (tag ==
"get_num_components") {
630 SegmentationModuleInterface_get_num_components_helper::s_return_helper = get_num_components();
631 yarp::os::idl::WireWriter writer(reader);
632 if (!writer.isNull()) {
633 if (!writer.writeListHeader(1)) {
636 if (!writer.writeI32(SegmentationModuleInterface_get_num_components_helper::s_return_helper)) {
643 if (tag ==
"get_component_around") {
645 if (!reader.read(objCenter)) {
649 SegmentationModuleInterface_get_component_around_helper::s_return_helper = get_component_around(objCenter);
650 yarp::os::idl::WireWriter writer(reader);
651 if (!writer.isNull()) {
652 if (!writer.writeListHeader(1)) {
655 if (!writer.writeListBegin(BOTTLE_TAG_LIST,
static_cast<uint32_t
>(SegmentationModuleInterface_get_component_around_helper::s_return_helper.size()))) {
658 for (
const auto& _item5 : SegmentationModuleInterface_get_component_around_helper::s_return_helper) {
659 if (!writer.writeNested(_item5)) {
663 if (!writer.writeListEnd()) {
671 std::string functionName;
672 if (!reader.readString(functionName)) {
673 functionName =
"--all";
675 auto help_strings = help(functionName);
676 yarp::os::idl::WireWriter writer(reader);
677 if (!writer.isNull()) {
678 if (!writer.writeListHeader(2)) {
681 if (!writer.writeTag(
"many", 1, 0)) {
684 if (!writer.writeListBegin(BOTTLE_TAG_INT32,
static_cast<uint32_t
>(help_strings.size()))) {
687 for (
const auto& help_string : help_strings) {
688 if (!writer.writeString(help_string)) {
692 if (!writer.writeListEnd()) {
699 if (reader.noMore()) {
703 std::string next_tag = reader.readTag();
704 if (next_tag ==
"") {
707 tag.append(
"_").append(next_tag);
Pixel position in the image frame.