diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h index 863332144f55d05c4594e81e1a5f0869e4f77f62..c6fefc5b18133bc7aa36797156687d2a75384f3e 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityBase.h @@ -119,7 +119,7 @@ namespace armarx::armem::base /** * @brief Indicates whether a history entry for the given time exists. */ - bool hasSnapshot(Time time) const + virtual bool hasSnapshot(Time time) const { return this->_container.count(time) > 0; } @@ -136,7 +136,7 @@ namespace armarx::armem::base /** * @brief Get all timestamps in the history. */ - std::vector<Time> getTimestamps() const + virtual std::vector<Time> getTimestamps() const { return simox::alg::get_keys(this->_container); } @@ -155,7 +155,7 @@ namespace armarx::armem::base return const_cast<EntitySnapshotT&>(const_cast<const EntityBase*>(this)->getSnapshot(time)); } - const EntitySnapshotT& getSnapshot(Time time) const + virtual const EntitySnapshotT& getSnapshot(Time time) const { auto it = this->_container.find(time); if (it != this->_container.end()) @@ -269,7 +269,7 @@ namespace armarx::armem::base } - private: + protected: /// If maximum size is set, ensure `history`'s is not higher. void truncateHistoryToSize() @@ -297,7 +297,7 @@ namespace armarx::armem::base * @return The latest snapshot. * @throw `armem::error::EntityHistoryEmpty` If the history is empty. */ - const typename std::map<Time, EntitySnapshotT>::value_type& getLatestItem() const + virtual const typename std::map<Time, EntitySnapshotT>::value_type& getLatestItem() const { if (this->_container.empty()) { diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h index 0dfe62f51c92011cf8587c0bdb06655948b3c378..54e004f4875242a30b538864695d13fe1f553582 100644 --- a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h +++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h @@ -38,6 +38,11 @@ namespace armarx::armem::ltm using Base::EntityBase; using Base::operator=; + Entity() + { + // the history of snapshots is just a cache of frequently used elements + setMaxHistorySize(20); + } // Conversion wm::Entity convert(const MongoDBConnectionManager::MongoDBSettings&) const; @@ -46,6 +51,50 @@ namespace armarx::armem::ltm void reload(const MongoDBConnectionManager::MongoDBSettings&); void append(const wm::Entity&, const MongoDBConnectionManager::MongoDBSettings&); + // virtual overrides for LTM storage + /*virtual bool hasSnapshot(Time time) const override + { + // check cache + if (Base::hasSnapshot(time)) + { + return true; + } + // check mongodb + return false; + // TODO + } + virtual std::vector<Time> getTimestamps() const override + { + // get from cache + std::vector<Time> ret = Base::getTimestamps(); + // get missing from mongodb + // TODO + return ret; + } + virtual const EntitySnapshotT& getSnapshot(Time time) const override + { + try + { + return Base::getSnapshot(time); + } + catch (const error::MissingEntry& _) + { + // if not in cache then get from mongo db + // TODO + return Base::getSnapshot(time); + } + } + + protected: + // virtual overrides for LTM storage + virtual const typename std::map<Time, EntitySnapshotT>::value_type& getLatestItem() const override + { + // Directly query mongodb (cache cant know whether it is the latest or not) + // TODO + return Base::getLatestItem(); + }*/ + + private: static const constexpr char* MONGO_DB_COLLECTION_PREFIX = "Entity__"; }; diff --git a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp index f6271553eddfe787162841ba7c428f7f74aa1626..24c0a22203aae81bfc52802a9f48fbb9755c9c5f 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp @@ -114,7 +114,7 @@ namespace ArMemLTMTest for (unsigned int j = 0; j < numInstances; ++j) { - aron::datanavigator::DictNavigatorPtr m = aron::datanavigator::DictNavigator::DynamicCastAndCheck(r.generateAronDataFromType(t)); + aron::datanavigator::DictNavigatorPtr m = aron::datanavigator::DictNavigator::DynamicCastAndCheck(r.generateEmptyAronDataFromType(t)); r.initializeRandomly(m, t); q.push_back(m); } diff --git a/source/RobotAPI/libraries/armem_robot_state/server/localization/Segment.cpp b/source/RobotAPI/libraries/armem_robot_state/server/localization/Segment.cpp index 2c2b0ae63c221f5f8d041357314cc2032bb9b0d6..e0dcf6c2bcd9d86012d98cf5aded6fee585ed866 100644 --- a/source/RobotAPI/libraries/armem_robot_state/server/localization/Segment.cpp +++ b/source/RobotAPI/libraries/armem_robot_state/server/localization/Segment.cpp @@ -157,7 +157,7 @@ namespace armarx::armem::server::robot_state::localization coreSegment->id().withProviderSegmentName(transform.header.agent); if (not coreSegment->hasProviderSegment(providerID.providerSegmentName)) { - coreSegment->addProviderSegment(providerID.providerSegmentName, arondto::Transform::toInitialAronType()); + coreSegment->addProviderSegment(providerID.providerSegmentName, arondto::Transform::toAronType()); } Commit commit; diff --git a/source/RobotAPI/libraries/aron/core/CMakeLists.txt b/source/RobotAPI/libraries/aron/core/CMakeLists.txt index 2c069c1807cfe66c6538c834f3b4674eac9f9ff4..af2caf05737aec188ccae47c5554f7776a27defd 100644 --- a/source/RobotAPI/libraries/aron/core/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/core/CMakeLists.txt @@ -3,16 +3,9 @@ set(LIB_NAME aron) armarx_component_set_name("${LIB_NAME}") armarx_set_target("Library: ${LIB_NAME}") -find_package(Eigen3 QUIET) -armarx_build_if(Eigen3_FOUND "Eigen3 not available") - find_package(Simox QUIET) armarx_build_if(Simox_FOUND "Simox not available") -find_package(PCL QUIET COMPONENTS io common) -armarx_build_if(PCL_FOUND "PCL not available") - - set(LIBS ArmarXCoreInterfaces ArmarXCore @@ -277,16 +270,18 @@ set(LIB_HEADERS ) -armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") - - -if(PCL_FOUND) -target_include_directories("${LIB_NAME}" - SYSTEM PUBLIC - "${PCL_INCLUDE_DIRS}" +armarx_add_library( + LIB_NAME + "${LIB_NAME}" + SOURCES + "${LIB_FILES}" + HEADERS + "${LIB_HEADERS}" + LIBS + "${LIBS}" ) -endif() +add_library(RobotAPI::aron ALIAS "${LIB_NAME}") # add unit tests add_subdirectory(test) diff --git a/source/RobotAPI/libraries/aron/core/Descriptor.h b/source/RobotAPI/libraries/aron/core/Descriptor.h index 10833d329cfec0d594375a1c12d9f83b28c46570..bcf2d0c3173dfc12493d0e5dac0155da81217c57 100644 --- a/source/RobotAPI/libraries/aron/core/Descriptor.h +++ b/source/RobotAPI/libraries/aron/core/Descriptor.h @@ -36,6 +36,15 @@ namespace armarx::aron::type { + const std::vector<type::Maybe> ALL_MAYBE_TYPES = + { + type::Maybe::eNone, + type::Maybe::eOptional, + type::Maybe::eRawPointer, + type::Maybe::eSharedPointer, + type::Maybe::eUniquePointer + }; + enum class Descriptor { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ @@ -46,6 +55,16 @@ namespace armarx::aron::type eUnknown = -1 }; + const std::vector<type::Descriptor> ALL_ARON_TYPES = + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + type::Descriptor::e##upperType, + + HANDLE_ALL_ARON_TYPES +#undef RUN_ARON_MACRO + Descriptor::eUnknown + }; + const std::map<type::Descriptor, std::string> _descriptor2string = { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ @@ -95,6 +114,11 @@ namespace armarx::aron::type { return type::_string2descriptor.at(s); } + + inline type::Descriptor DESCRIPTOR_FROM_STRING(const std::string& s) + { + return STRING_TO_DESCRIPTOR(s); + } } namespace armarx::aron::data @@ -109,6 +133,16 @@ namespace armarx::aron::data eUnknown = -1 }; + const std::vector<data::Descriptor> ALL_ARON_DATA = + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + data::Descriptor::e##upperType, + + HANDLE_ALL_ARON_DATA +#undef RUN_ARON_MACRO + Descriptor::eUnknown + }; + const std::map<data::Descriptor, std::string> _descriptor2string = { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ @@ -144,4 +178,9 @@ namespace armarx::aron::data { return data::_string2descriptor.at(s); } + + inline data::Descriptor DESCRIPTOR_FROM_STRING(const std::string& s) + { + return STRING_TO_DESCRIPTOR(s); + } } diff --git a/source/RobotAPI/libraries/aron/core/Randomizer.h b/source/RobotAPI/libraries/aron/core/Randomizer.h index bdc272383357c6300f9d60d2f4e027319385f845..bdc05099f108f0abaecb8db68cc58f47b8688a6c 100644 --- a/source/RobotAPI/libraries/aron/core/Randomizer.h +++ b/source/RobotAPI/libraries/aron/core/Randomizer.h @@ -39,38 +39,33 @@ namespace armarx::aron public: Randomizer() { - initialize_random(); + initializeSelf(); }; - typenavigator::NavigatorPtr generateRandomType(bool mustBeObject = false) const + typenavigator::NavigatorPtr generateRandomType(bool allowMaybeType = false, bool firstObject = false) const { type::Descriptor nextType = type::Descriptor::eObject; - if (!mustBeObject) + if (!firstObject) { - std::vector<type::Descriptor> descriptors = - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - type::Descriptor::e##upperType, - - HANDLE_ALL_ARON_TYPES -#undef RUN_ARON_MACRO - }; + nextType = getRandomElement(type::ALL_ARON_TYPES); + } - int randomType = generateRandom(descriptors.size(), 0); - nextType = descriptors[randomType]; + type::Maybe nextMaybeType = type::Maybe::eNone; + if (allowMaybeType && !firstObject) + { + nextMaybeType = getRandomElement(type::ALL_MAYBE_TYPES); } switch (nextType) { case type::Descriptor::eObject: { - typenavigator::ObjectNavigatorPtr t = typenavigator::ObjectNavigatorPtr(new typenavigator::ObjectNavigator(Path())); + auto t = std::make_shared<typenavigator::ObjectNavigator>(); std::string objectName = generateRandomWord(); t->setObjectName(objectName); - std::vector<std::string> usedNames({objectName}); int members = generateRandom(4, 2); - std::set<std::string> usedKeys; + std::set<std::string> usedKeys = {objectName}; for (int i = 0; i < members; ++i) { std::string key = generateRandomWord(usedKeys); @@ -81,9 +76,25 @@ namespace armarx::aron } return t; } + case type::Descriptor::eIntEnum: + { + auto t = std::make_shared<typenavigator::IntEnumNavigator>(); + std::string intEnumName = generateRandomWord(); + t->setEnumName(intEnumName); + + std::set<std::string> usedKeys = {intEnumName}; + for (int i = 0; i < generateRandom(5, 2); ++i) + { + std::string key = generateRandomWord(usedKeys); + usedKeys.insert(key); + + t->addAcceptedValue(key, i); + } + return t; + } case type::Descriptor::eDict: { - typenavigator::DictNavigatorPtr t = typenavigator::DictNavigatorPtr(new typenavigator::DictNavigator()); + auto t = std::make_shared<typenavigator::DictNavigator>(); typenavigator::NavigatorPtr a = generateRandomType(false); t->setAcceptedType(a); @@ -91,7 +102,7 @@ namespace armarx::aron } case type::Descriptor::eTuple: { - typenavigator::TupleNavigatorPtr t = typenavigator::TupleNavigatorPtr(new typenavigator::TupleNavigator()); + auto t = std::make_shared<typenavigator::TupleNavigator>(); int members = generateRandom(4, 2); for (int i = 0; i < members; ++i) @@ -103,7 +114,7 @@ namespace armarx::aron } case type::Descriptor::eList: { - typenavigator::ListNavigatorPtr t = typenavigator::ListNavigatorPtr(new typenavigator::ListNavigator()); + auto t = std::make_shared<typenavigator::ListNavigator>(); typenavigator::NavigatorPtr a = generateRandomType(false); t->setAcceptedType(a); @@ -111,7 +122,7 @@ namespace armarx::aron } case type::Descriptor::ePair: { - typenavigator::PairNavigatorPtr t = typenavigator::PairNavigatorPtr(new typenavigator::PairNavigator()); + auto t = std::make_shared<typenavigator::PairNavigator>(); typenavigator::NavigatorPtr a = generateRandomType(false); typenavigator::NavigatorPtr b = generateRandomType(false); @@ -119,15 +130,61 @@ namespace armarx::aron t->setSecondAcceptedType(b); return t; } - case type::Descriptor::eEigenMatrix: // TODO (fabian.peller) + case type::Descriptor::eNDArray: + { + // TODO (fabian.peller) + // fall through EigenMatrix + } + case type::Descriptor::eEigenMatrix: + { + auto t = std::make_shared<typenavigator::EigenMatrixNavigator>(); + auto type = getRandomKey(t->ACCEPTED_TYPES); + t->setTypename(type); + t->setRows(generateRandom(10, 1)); + t->setRows(generateRandom(10, 1)); + return t; + } case type::Descriptor::eEigenQuaternion: + { + auto t = std::make_shared<typenavigator::EigenQuaternionNavigator>(); + auto type = getRandomKey(t->ACCEPTED_TYPES); + t->setTypename(type); + return t; + } case type::Descriptor::eIVTCByteImage: + { + auto t = std::make_shared<typenavigator::IVTCByteImageNavigator>(); + auto type = getRandomKey(t->ACCEPTED_TYPES); + return t; + } case type::Descriptor::eOpenCVMat: + { + auto t = std::make_shared<typenavigator::OpenCVMatNavigator>(); + auto type = getRandomKey(t->ACCEPTED_TYPES); + return t; + } case type::Descriptor::ePCLPointCloud: + { + auto t = std::make_shared<typenavigator::PCLPointCloudNavigator>(); + auto type = getRandomKey(t->ACCEPTED_TYPES); + t->setTypename(type); + return t; + } case type::Descriptor::ePosition: + { + auto t = std::make_shared<typenavigator::PositionNavigator>(); + return t; + } case type::Descriptor::eOrientation: + { + auto t = std::make_shared<typenavigator::PositionNavigator>(); + return t; + } case type::Descriptor::ePose: - + { + auto t = std::make_shared<typenavigator::PositionNavigator>(); + return t; + } case type::Descriptor::eInt: { auto t = std::make_shared<typenavigator::IntNavigator>(); @@ -163,14 +220,14 @@ namespace armarx::aron auto t = std::make_shared<typenavigator::TimeNavigator>(); return t; } - default: + case type::Descriptor::eUnknown: { throw error::DescriptorNotValidException("Randomizer", "generateRandomType", "No valid type found!", nextType); } } } - datanavigator::NavigatorPtr generateAronDataFromType(const typenavigator::NavigatorPtr& type, bool ignore_maybe = false) const + datanavigator::NavigatorPtr generateEmptyAronDataFromType(const typenavigator::NavigatorPtr& type, bool ignore_maybe = false) const { if (type->getMaybe() != type::Maybe::eNone && !ignore_maybe) { @@ -187,25 +244,32 @@ namespace armarx::aron case type::Descriptor::eObject: { typenavigator::ObjectNavigatorPtr t = typenavigator::ObjectNavigator::DynamicCastAndCheck(type); - datanavigator::DictNavigatorPtr d = datanavigator::DictNavigatorPtr(new datanavigator::DictNavigator()); + auto d = std::make_shared<datanavigator::DictNavigator>(); for (const auto& [k, tt] : t->getMemberTypes()) { - d->addElement(k, generateAronDataFromType(tt)); + d->addElement(k, generateEmptyAronDataFromType(tt)); } return d; } + case type::Descriptor::eIntEnum: + { + auto t = typenavigator::IntEnumNavigator::DynamicCastAndCheck(type); + auto d = std::make_shared<datanavigator::IntNavigator>(); + return d; + } + // here all totally random case type::Descriptor::eDict: { - typenavigator::DictNavigatorPtr t = typenavigator::DictNavigator::DynamicCastAndCheck(type); + auto t = typenavigator::DictNavigator::DynamicCastAndCheck(type); return datanavigator::NavigatorPtr(new datanavigator::DictNavigator()); } #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ case type::Descriptor::e##upperType: \ { \ - typenavigator::upperType##NavigatorPtr t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ + auto t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ return datanavigator::NavigatorPtr(new datanavigator::ListNavigator()); \ } @@ -215,9 +279,8 @@ case type::Descriptor::e##upperType: \ #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ case type::Descriptor::e##upperType: \ { \ - typenavigator::upperType##NavigatorPtr t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ - datanavigator::NDArrayNavigatorPtr ndarray = datanavigator::NDArrayNavigatorPtr(new datanavigator::NDArrayNavigator()); \ - return ndarray; \ + auto t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ + return datanavigator::NDArrayNavigatorPtr(new datanavigator::NDArrayNavigator()); \ } HANDLE_NDARRAY_TYPES @@ -226,36 +289,31 @@ case type::Descriptor::e##upperType: \ #define RUN_ARON_MACRO(upperType, lowerType, capsType, upperData, lowerData, capsData) \ case type::Descriptor::e##upperType: \ { \ - typenavigator::upperType##NavigatorPtr t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ + auto t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ return datanavigator::NavigatorPtr(new datanavigator::upperData##Navigator()); \ } HANDLE_PRIMITIVE_CORRESPONDING #undef RUN_ARON_MACRO - default: + case type::Descriptor::eUnknown: { throw error::DescriptorNotValidException("Randomizer", "generateAronDataFromType", "No valid type found!", desc); } } + // end of non void....... dont know why + return nullptr; } void initializeRandomly(datanavigator::NavigatorPtr& data, const typenavigator::NavigatorPtr& type) const { + data = generateEmptyAronDataFromType(type); if (!data) { - if (!type->getMaybe() != type::Maybe::eNone) + if (type->getMaybe() == type::Maybe::eNone) { throw error::AronException("Randomizer", "initializeRandomly", "The data is null but the type is not a maybe type. This is not valid."); } - - if (fiftyPercentChance()) // 50% chance - { - data = generateAronDataFromType(type, true); - } - else - { - return; - } + return; } // Containers @@ -275,37 +333,62 @@ case type::Descriptor::e##upperType: \ HANDLE_ALL_CORRESPONDING #undef RUN_ARON_MACRO - default: + case type::Descriptor::eUnknown: { throw error::DescriptorNotValidException("Randomizer", "initializeRandomly", "No valid type found!", desc); } } } + // generate i in [min, max) int generateRandom(int max, int min) const { - max += 1; + if (max < min) + { + throw error::IndexNotValidException("AronRandomizer", "generateRandom", "The max value is lower than the min value", max, min); + } int random = (std::rand() % (max - min)) + min; return random; } + template <class T> + T getRandomElement(const std::vector<T>& vec) const + { + int i = generateRandom(vec.size(), 0); + return vec.at(i); + } + + template <class T> + std::string getRandomKey(const std::map<std::string, T>& m) const + { + std::vector<std::string> keys; + for (const auto [k, _] : m) + { + keys.push_back(k); + } + return getRandomElement(keys); + } bool fiftyPercentChance() const { - return generateRandom(2, 1) == 1; + return generateRandom(2, 0); } std::string generateRandomWord(const std::set<std::string>& usedKeys = {}) const { + // https://randomwordgenerator.com/ + // script to convert random words into string: + // jQuery("#result li i").remove(); var str = ""; jQuery("#result li").each(function() {str += jQuery(this).html() + ", " }); console.log(str); std::vector<string> words = { - "Lorem", "ipsum", "dolor", "sit", "amet", "consetetur", "sadipscing", "elitr" - "sed", "diam", "nonumy", "eirmod", "tempor", "invidunt", "ut", "labore", "et" - "dolore", "magna", "aliquyam", "eratsed" + "jaw", "river", "bow", "profession", "heat", "interference", "slave", "population", "deport", "redeem", "digress", "penny", "cousin", "beef", "Bible", "fuss", + "urgency", "tasty", "innovation", "upset", "gold", "day", "remunerate", "strain", "district", "panel", "choke", "rack", "parameter", "despair", "extort", "country", + "hesitate", "record", "brand", "confusion", "discreet", "accept", "lifestyle", "option", "corn", "charity", "miss", "viable", "glance", "norm", "meet", "bird", + "ribbon", "guideline" }; - int i = generateRandom(words.size() - 1, 0); - std::string key = words[i]; + int i = generateRandom(words.size(), 0); + std::string key = words.at(i); while (usedKeys.count(key) > 0) { @@ -320,18 +403,11 @@ case type::Descriptor::e##upperType: \ std::vector<unsigned char> new_blob(size, 0); for (unsigned int i = 0; i < size; ++i) { - new_blob[i] = (generateRandom(127, 0)); + new_blob[i] = (generateRandom(128, 0)); } return new_blob; } - private: - void initialize_random() const - { - std::srand(std::time(nullptr)); - } - - public: void initializeRandomly(datanavigator::DictNavigatorPtr& data, const typenavigator::ObjectNavigatorPtr& type) const { for (auto& [key, nextData] : data->getElements()) @@ -349,7 +425,7 @@ case type::Descriptor::e##upperType: \ { std::string key = generateRandomWord(usedKeys); usedKeys.insert(key); - datanavigator::NavigatorPtr newData = generateAronDataFromType(type->getAcceptedType()); + datanavigator::NavigatorPtr newData = generateEmptyAronDataFromType(type->getAcceptedType()); initializeRandomly(newData, type->getAcceptedType()); data->addElement(key, newData); } @@ -378,7 +454,7 @@ case type::Descriptor::e##upperType: \ int numElements = generateRandom(5, 1); for (int i = 0; i < numElements; ++i) { - datanavigator::NavigatorPtr newData = generateAronDataFromType(type->getAcceptedType()); + datanavigator::NavigatorPtr newData = generateEmptyAronDataFromType(type->getAcceptedType()); initializeRandomly(newData, type->getAcceptedType()); data->addElement(newData); } @@ -414,12 +490,18 @@ case type::Descriptor::e##upperType: \ void initializeRandomly(datanavigator::BoolNavigatorPtr& data, const typenavigator::NavigatorPtr& type) const { - data->setValue(generateRandom(1, 0)); + data->setValue(fiftyPercentChance()); } void initializeRandomly(datanavigator::StringNavigatorPtr& data, const typenavigator::NavigatorPtr& type) const { data->setValue(generateRandomWord()); } + + private: + void initializeSelf() const + { + std::srand(std::time(nullptr)); + } }; } diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.cpp index 771063a4a0ced90ceaf58b3088bf9a7c30b2ea46..6998d81b564e532f5f174c8c07db8b4b79b1f703 100644 --- a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.cpp +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.cpp @@ -170,7 +170,7 @@ namespace armarx::aron::cppserializer::serializer CppMethodPtr m = CppMethodPtr(new CppMethod(getFullCppTypename() + "& operator=(const " + getFullCppTypename() + "& c)", doc.str())); CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("value = c.value;"); - b->addLine("return *this"); + b->addLine("return *this;"); m->setBlock(b); return m; } @@ -184,7 +184,7 @@ namespace armarx::aron::cppserializer::serializer CppMethodPtr m = CppMethodPtr(new CppMethod(getFullCppTypename() + "& operator=(" + std::string(IMPL_ENUM) + " v)", doc.str())); CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("value = v;"); - b->addLine("return *this"); + b->addLine("return *this;"); m->setBlock(b); return m; } @@ -205,7 +205,7 @@ namespace armarx::aron::cppserializer::serializer CppBlockPtr b3 = std::make_shared<CppBlock>(); b3->addLine("value = it->second;"); b->addBlock(b3); - b->addLine("return *this"); + b->addLine("return *this;"); m->setBlock(b); return m; } diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.cpp index c21af9e90f4f7bc3425a01e8db24ed40607bc619..eb1a486374c836d8156d8055e543379de9840a47 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.cpp @@ -78,6 +78,14 @@ namespace armarx::aron::datanavigator } return true; } + bool NDArrayNavigator::operator==(const NDArrayNavigatorPtr& other) const + { + if (!other) + { + return false; + } + return *this == *other; + } // static methods NDArrayNavigatorPtr NDArrayNavigator::FromAronNDArrayPtr(const data::AronNDArrayPtr& aron) diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h b/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h index fb7461791974325a1a73304cbfd1ee0f92ca62fe..e41fbdb6518bc3e7f5f57999fc3fd3de2f14fa13 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h @@ -63,6 +63,7 @@ namespace armarx::aron::datanavigator // operators virtual bool operator==(const NDArrayNavigator&) const override; + bool operator==(const NDArrayNavigatorPtr&) const override; // static methods static PointerType FromAronNDArrayPtr(const data::AronNDArrayPtr& aron); diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.cpp index ad9de5450ac39606eaf0f026100469e709b54aac..a4f0f8be1532830e63bb49fe585160dbed493776 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.cpp @@ -67,21 +67,29 @@ namespace armarx::aron::datanavigator { for (const auto& [key, nav] : childrenNavigators) { - if (!nav) - { - return (bool) other.getElement(key); - } if (not(other.hasElement(key))) { return false; } - if (not(*nav == other.getElement(key))) + if (!nav) + { + return !((bool) other.getElement(key)); + } + if (not(*nav == *other.getElement(key))) { return false; } } return true; } + bool DictNavigator::operator==(const DictNavigatorPtr& other) const + { + if (!other) + { + return false; + } + return *this == *other; + } // static methods DictNavigatorPtr DictNavigator::FromAronDictPtr(const data::AronDictPtr& aron) diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.h b/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.h index 82aafaba03cbf7b5cf1547d24147931f5e9b097e..88e434f3edd552261ef43559151785d41d194778 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.h @@ -50,6 +50,7 @@ namespace armarx::aron::datanavigator // operators virtual bool operator==(const DictNavigator&) const override; + bool operator==(const DictNavigatorPtr&) const override; static PointerType FromAronDictPtr(const data::AronDictPtr& aron); static data::AronDictPtr ToAronDictPtr(const PointerType& navigator); diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/container/List.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/container/List.cpp index eb4c74fd6d4899ffa8bf2b917bd0668be0186a20..44f5c61eca8325e2175edbd0245085005dbfdb50 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/container/List.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/container/List.cpp @@ -70,6 +70,10 @@ namespace armarx::aron::datanavigator unsigned int i = 0; for (const auto& nav : childrenNavigators) { + if (!other.hasElement(i)) + { + return false; + } if (!nav) { if (!other.getElement(i)) @@ -77,10 +81,6 @@ namespace armarx::aron::datanavigator return false; } } - if (!other.hasElement(i)) - { - return false; - } if (!(*nav == other.getElement(i))) { return false; @@ -89,6 +89,14 @@ namespace armarx::aron::datanavigator } return true; } + bool ListNavigator::operator==(const ListNavigatorPtr& other) const + { + if (!other) + { + return false; + } + return *this == *other; + } // static methods ListNavigatorPtr ListNavigator::FromAronListPtr(const data::AronListPtr& aron) diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/container/List.h b/source/RobotAPI/libraries/aron/core/navigator/data/container/List.h index d46607c13eb0ceff3012cd12d4b158b595b56d28..8df55ff032ba6a48b9651b011718f713484c26b2 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/container/List.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/container/List.h @@ -50,6 +50,7 @@ namespace armarx::aron::datanavigator // operators virtual bool operator==(const ListNavigator&) const override; + bool operator==(const ListNavigatorPtr&) const override; // static methods static PointerType FromAronListPtr(const data::AronListPtr& aron); diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/detail/NavigatorBase.h b/source/RobotAPI/libraries/aron/core/navigator/data/detail/NavigatorBase.h index 1ec24d777730a0c36a8047c077e25193b0c79d0b..0c455a3eec808c7b995cb5a611e81139aa7008cc 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/detail/NavigatorBase.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/detail/NavigatorBase.h @@ -76,14 +76,7 @@ namespace armarx::aron::datanavigator::detail } virtual bool operator==(const DerivedT&) const = 0; - bool operator==(const PointerType& other) const - { - if (other) - { - return *this == *other; - } - return false; - } + virtual bool operator==(const PointerType& other) const = 0; // virtual implementations virtual data::AronDataPtr toAronPtr() const override diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Bool.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Bool.cpp index ffe4f83bbfabf059c0106590fdac52842734a640..091343a774a134a760ab9c579aefa2edc6304113 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Bool.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Bool.cpp @@ -46,10 +46,20 @@ namespace armarx::aron::datanavigator bool BoolNavigator::operator==(const BoolNavigator& other) const { const auto& otherAron = other.toAronBoolPtr(); - if(aron->value != otherAron->value) + if (aron->value != otherAron->value) + { return false; + } return true; } + bool BoolNavigator::operator==(const BoolNavigatorPtr& other) const + { + if (!other) + { + return false; + } + return *this == *other; + } /* static methods */ diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Bool.h b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Bool.h index e23d168376bd32f23cb6cd26dc33c5080b8fc4bb..b95f1a86e3b84d517807b4b0d25edd7438c6ed12 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Bool.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Bool.h @@ -42,8 +42,6 @@ namespace armarx::aron::datanavigator virtual public detail::PrimitiveNavigatorBase<data::AronBool, bool, BoolNavigator> { public: - using PointerType = BoolNavigatorPtr; - /* constructors */ BoolNavigator(const Path& = Path()); BoolNavigator(const data::AronBoolPtr&, const Path& = Path()); @@ -51,6 +49,7 @@ namespace armarx::aron::datanavigator // operators bool operator==(const BoolNavigator& other) const override; + bool operator==(const BoolNavigatorPtr&) const override; // static methods static BoolNavigatorPtr FromAronBoolPtr(const data::AronBoolPtr& aron); diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Double.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Double.cpp index 3f61bde7b79f7d9d080007f5ecea1e724ed32d1d..352e7abb14aef60126cb82ff7781afd8f427f72c 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Double.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Double.cpp @@ -50,11 +50,20 @@ namespace armarx::aron::datanavigator bool DoubleNavigator::operator==(const DoubleNavigator& other) const { const auto& otherAron = other.toAronDoublePtr(); - if(this->aron->value != otherAron->value) + if (this->aron->value != otherAron->value) + { return false; + } return true; } - + bool DoubleNavigator::operator==(const DoubleNavigatorPtr& other) const + { + if (!other) + { + return false; + } + return *this == *other; + } /* static methods */ DoubleNavigatorPtr DoubleNavigator::FromAronDoublePtr(const data::AronDoublePtr& aron) diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Double.h b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Double.h index 59cb01d0a222027e5b8ee8d0e982cceff5cb2f1d..4996bc46bd479fe4318c9bb6bcf8228c453c65fc 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Double.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Double.h @@ -42,8 +42,6 @@ namespace armarx::aron::datanavigator virtual public detail::PrimitiveNavigatorBase<data::AronDouble, double, DoubleNavigator> { public: - using PointerType = DoubleNavigatorPtr; - /* constructors */ DoubleNavigator(const Path& = Path()); DoubleNavigator(const data::AronDoublePtr&, const Path& = Path()); @@ -51,6 +49,7 @@ namespace armarx::aron::datanavigator /* operators */ bool operator==(const DoubleNavigator&) const override; + bool operator==(const DoubleNavigatorPtr&) const override; /* static methods */ static DoubleNavigatorPtr FromAronDoublePtr(const data::AronDoublePtr& aron); diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Float.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Float.cpp index 64ed78465202f2ccc4c19281c11c359406a0d663..145e96f9d2baa2292354556eac3fc67a2c54a192 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Float.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Float.cpp @@ -46,10 +46,20 @@ namespace armarx::aron::datanavigator bool FloatNavigator::operator==(const FloatNavigator& other) const { const auto& otherAron = other.toAronFloatPtr(); - if(this->aron->value != otherAron->value) + if (this->aron->value != otherAron->value) + { return false; + } return true; } + bool FloatNavigator::operator==(const FloatNavigatorPtr& other) const + { + if (!other) + { + return false; + } + return *this == *other; + } /* static methods */ diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Float.h b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Float.h index 8c873ae51098c6b05ab094d395cf9c5c30257095..b060f82d9606c14baf63c539450fc2beed1a6a89 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Float.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Float.h @@ -42,8 +42,6 @@ namespace armarx::aron::datanavigator virtual public detail::PrimitiveNavigatorBase<data::AronFloat, float, FloatNavigator> { public: - using PointerType = FloatNavigatorPtr; - /* constructors */ FloatNavigator(const Path& = Path()); FloatNavigator(const data::AronFloatPtr&, const Path& = Path()); @@ -51,6 +49,7 @@ namespace armarx::aron::datanavigator /* operators */ bool operator==(const FloatNavigator&) const override; + bool operator==(const FloatNavigatorPtr&) const override; /* static methods */ static FloatNavigatorPtr FromAronFloatPtr(const data::AronFloatPtr& aron); diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Int.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Int.cpp index b986847685146debfcc957b5db90f4731d5aa121..29c706c12774e2aef91d962a66260db4dc5d7d21 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Int.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Int.cpp @@ -49,10 +49,20 @@ namespace armarx::aron::datanavigator bool IntNavigator::operator==(const IntNavigator& other) const { const auto& otherAron = other.toAronIntPtr(); - if(this->aron->value != otherAron->value) + if (this->aron->value != otherAron->value) + { return false; + } return true; } + bool IntNavigator::operator==(const IntNavigatorPtr& other) const + { + if (!other) + { + return false; + } + return *this == *other; + } /* static methods */ diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Int.h b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Int.h index 61b190f9f1c4aa63cf89dfc708c11d544f90ef01..317650e847695cde2700867757c0407b1fc7d8a0 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Int.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Int.h @@ -42,8 +42,6 @@ namespace armarx::aron::datanavigator virtual public detail::PrimitiveNavigatorBase<data::AronInt, int, IntNavigator> { public: - using PointerType = IntNavigatorPtr; - /* constructors */ IntNavigator(const Path& = Path()); IntNavigator(const data::AronIntPtr&, const Path& = Path()); @@ -51,6 +49,7 @@ namespace armarx::aron::datanavigator /* operators */ bool operator==(const IntNavigator&) const override; + bool operator==(const IntNavigatorPtr&) const override; /* static methods */ static IntNavigatorPtr FromAronIntPtr(const data::AronIntPtr& aron); diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Long.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Long.cpp index 35d27c60202430568f0b04092ffc168c0219ea3a..73676a1d51c21f9f7f37b2d3b92eaf429f20afe2 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Long.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Long.cpp @@ -50,10 +50,20 @@ namespace armarx::aron::datanavigator bool LongNavigator::operator==(const LongNavigator& other) const { const auto& otherAron = other.toAronLongPtr(); - if(this->aron->value != otherAron->value) + if (this->aron->value != otherAron->value) + { return false; + } return true; } + bool LongNavigator::operator==(const LongNavigatorPtr& other) const + { + if (!other) + { + return false; + } + return *this == *other; + } /* static methods */ diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Long.h b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Long.h index fe02823d88b7779bbae2be3375de7825417b9821..f9593ec4059b9676dd56df76196418c82465f17c 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Long.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Long.h @@ -42,8 +42,6 @@ namespace armarx::aron::datanavigator virtual public detail::PrimitiveNavigatorBase<data::AronLong, long, LongNavigator> { public: - using PointerType = LongNavigatorPtr; - /* constructors */ LongNavigator(const Path& = Path()); LongNavigator(const data::AronLongPtr&, const Path& = Path()); @@ -51,6 +49,7 @@ namespace armarx::aron::datanavigator /* operators */ bool operator==(const LongNavigator&) const override; + bool operator==(const LongNavigatorPtr&) const override; /* static methods */ static LongNavigatorPtr FromAronLongPtr(const data::AronLongPtr& aron); diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/String.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/String.cpp index c2014114e68a64b143de02b856c9cc43969c6164..11477863e1062e53575bfa5482f5e767a57ad2c6 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/String.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/String.cpp @@ -46,10 +46,20 @@ namespace armarx::aron::datanavigator bool StringNavigator::operator==(const StringNavigator& other) const { const auto& otherAron = other.toAronStringPtr(); - if(this->aron->value != otherAron->value) + if (this->aron->value != otherAron->value) + { return false; + } return true; } + bool StringNavigator::operator==(const StringNavigatorPtr& other) const + { + if (!other) + { + return false; + } + return *this == *other; + } /* static methods */ diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/String.h b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/String.h index cbf82862998ace407bd1e415362c72351889c8a7..915334a9d8794245cb3c44c755ac5d3e39a7ddb5 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/String.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/String.h @@ -42,8 +42,6 @@ namespace armarx::aron::datanavigator virtual public detail::PrimitiveNavigatorBase<data::AronString, std::string, StringNavigator> { public: - using PointerType = StringNavigatorPtr; - /* constructors */ StringNavigator(const Path& = Path()); StringNavigator(const data::AronStringPtr&, const Path& = Path()); @@ -51,6 +49,7 @@ namespace armarx::aron::datanavigator /* operators */ bool operator==(const StringNavigator&) const override; + bool operator==(const StringNavigatorPtr&) const override; /* static methods */ static StringNavigatorPtr FromAronStringPtr(const data::AronStringPtr& aron); diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.cpp index b224cbac92ee7c984aff34370b871b4e46511baf..0e3f0594bb085b991fda4a66acf3877b5590a550 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.cpp @@ -48,11 +48,31 @@ namespace armarx::aron::typenavigator return getEnumName() == other.getEnumName(); } - std::map<std::string, int> IntEnumNavigator::getAcceptedValues() const + std::map<std::string, int> IntEnumNavigator::getAcceptedValueMap() const { return this->aron->acceptedValues; } + std::vector<std::string> IntEnumNavigator::getAcceptedValueNames() const + { + std::vector<std::string> names; + for (const auto& [k, _] : aron->acceptedValues) + { + names.push_back(k); + } + return names; + } + + std::vector<int> IntEnumNavigator::getAcceptedValues() const + { + std::vector<int> vals; + for (const auto& [_, i] : aron->acceptedValues) + { + vals.push_back(i); + } + return vals; + } + std::string IntEnumNavigator::getValueName(int i) const { for (const auto& [k, v] : this->aron->acceptedValues) diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h b/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h index d32af558270a3520d2618e51499850e376443ee7..31ccdab0ddecf016b9eaf67a5af5941e65d6a272 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h @@ -47,7 +47,10 @@ namespace armarx::aron::typenavigator virtual bool operator==(const IntEnumNavigator&) const override; // public member functions - std::map<std::string, int> getAcceptedValues() const; + std::map<std::string, int> getAcceptedValueMap() const; + std::vector<std::string> getAcceptedValueNames() const; + std::vector<int> getAcceptedValues() const; + std::string getValueName(int) const; int getValue(const std::string&) const; std::string getEnumName() const; diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.h index accb32e55d68548e98fb47c7b776a5565077dda9..5112f7f21b2017f4c84982520983a49a9eafa20f 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.h @@ -40,8 +40,7 @@ namespace armarx::aron::typenavigator { public: // constructors - EigenQuaternionNavigator() = delete; - EigenQuaternionNavigator(const Path& path); + EigenQuaternionNavigator(const Path& path = Path()); EigenQuaternionNavigator(const type::AronEigenQuaternionPtr&, const Path& path); // operators diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.h index f39a3752bb347c7fe44ed7982f98b9c3e894210f..83927a86d1baf61b98d443086539fb32f638d2fe 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.h @@ -40,8 +40,7 @@ namespace armarx::aron::typenavigator { public: // constructors - IVTCByteImageNavigator() = delete; - IVTCByteImageNavigator(const Path& path); + IVTCByteImageNavigator(const Path& path = Path()); IVTCByteImageNavigator(const type::AronIVTCByteImagePtr&, const Path& path); // operators diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.h index 37af2896aedaf042edf1cc6a8a53f0b6f0f82045..74e4e285540a66823409c8272b707d825e78ba40 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.h @@ -40,8 +40,7 @@ namespace armarx::aron::typenavigator { public: // constructors - OpenCVMatNavigator() = delete; - OpenCVMatNavigator(const Path& path); + OpenCVMatNavigator(const Path& path = Path()); OpenCVMatNavigator(const type::AronOpenCVMatPtr&, const Path& path); // operators diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.h index 0d0647d35f561c4abad956236d537e9e144eb05a..6b2df5228b77f93395fd2c653718c2c64637266a 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.h @@ -40,8 +40,7 @@ namespace armarx::aron::typenavigator { public: // constructors - OrientationNavigator() = delete; - OrientationNavigator(const Path& path); + OrientationNavigator(const Path& path = Path()); OrientationNavigator(const type::AronOrientationPtr&, const Path& path); // operators diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.h index 6751542ebbe5f19a8129250b835f500246f64582..45cd8b8680af13101403820fe6d62447ed78b522 100644 --- a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.h @@ -40,8 +40,7 @@ namespace armarx::aron::typenavigator { public: // constructors - PCLPointCloudNavigator() = delete; - PCLPointCloudNavigator(const Path& path); + PCLPointCloudNavigator(const Path& path = Path()); PCLPointCloudNavigator(const type::AronPCLPointCloudPtr&, const Path& path); // operators diff --git a/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt b/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt index d491c12363d7c088250599c7ff88dd6f62f25506..59892d744e814a6c0ece1b32cf208b6ba9e064a5 100644 --- a/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt @@ -1,44 +1,71 @@ -SET(TEST_NAME aronTest) - +###################### +# ARON OPERATOR TEST # +###################### +find_package(Simox QUIET) +armarx_build_if(Simox_FOUND "Simox not available") -find_package(Eigen3 QUIET) -armarx_build_if(Eigen3_FOUND "Eigen3 not available") -if(Eigen3_FOUND) - include_directories(${Eigen3_INCLUDE_DIR}) -endif() +armarx_add_test( + TEST_NAME + aronOperatorTest + TEST_FILE + aronOperatorTest.cpp + LIBS + Simox::SimoxUtility + ArmarXCore + RobotAPI::aron + INCLUDE_DIRECTORIES + ${Simox_INCLUDE_DIR} +) +###################### +# ARON NAVIGATE TEST # +###################### find_package(Simox QUIET) armarx_build_if(Simox_FOUND "Simox not available") -if(Simox_FOUND) - include_directories(${Simox_INCLUDE_DIR}) -endif() + +armarx_add_test( + TEST_NAME + aronNavigateTest + TEST_FILE + aronNavigateTest.cpp + LIBS + Simox::SimoxUtility + ArmarXCore + RobotAPI::aron + ARON_FILES + xmls/NaturalIKTest.xml + INCLUDE_DIRECTORIES + ${Simox_INCLUDE_DIR} +) + + +######################## +# ARON RANDOMIZED TEST # +######################## +find_package(Eigen3 QUIET) +armarx_build_if(Eigen3_FOUND "Eigen3 not available") find_package(IVT COMPONENTS ivt ivtopencv QUIET) armarx_build_if(IVT_FOUND "IVT not available") -if(IVT_FOUND) - include_directories(${IVT_INCLUDE_DIRS}) -endif() find_package(OpenCV QUIET) armarx_build_if(OpenCV_FOUND "OpenCV not available") -if(OpenCV_FOUND) - include_directories(${OpenCV_INCLUDE_DIRS}) -endif() find_package(PCL QUIET) armarx_build_if(PCL_FOUND "PCL not available") -if(PCL_FOUND) - include_directories(${PCL_INCLUDE_DIRS}) -endif() - -# Libs required for the tests -SET(LIBS ${LIBS} ArmarXCore aron ivt ivtopencv ${PCL_COMMON_LIBRARIES}) - -armarx_add_test(${TEST_NAME} aronTest.cpp "${LIBS}") -armarx_enable_aron_file_generation_for_target( - TARGET_NAME - ${TEST_NAME} +armarx_add_test( + TEST_NAME + aronRandomizedTest + TEST_FILE + aronRandomizedTest.cpp + LIBS + Simox::SimoxUtility + ArmarXCore + RobotAPI::aron + ivt + ivtopencv + ${PCL_COMMON_LIBRARIES} ARON_FILES # xmls/BaseClass.xml # xmls/DerivedClassTest.xml @@ -58,5 +85,10 @@ armarx_enable_aron_file_generation_for_target( xmls/PositionTest.xml xmls/PrimitiveTest.xml xmls/OptionalTest.xml - #ENABLE_DEBUG_INFO + INCLUDE_DIRECTORIES + ${Simox_INCLUDE_DIR} + ${Eigen3_INCLUDE_DIR} + ${IVT_INCLUDE_DIRS} + ${OpenCV_INCLUDE_DIRS} + ${PCL_INCLUDE_DIRS} ) diff --git a/source/RobotAPI/libraries/aron/core/test/aronDataWithoutCodeGeneration.h b/source/RobotAPI/libraries/aron/core/test/aronDataWithoutCodeGeneration.h deleted file mode 100644 index db9969bbbafe82d38c146453d7f1449bf1bd24d9..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/core/test/aronDataWithoutCodeGeneration.h +++ /dev/null @@ -1,335 +0,0 @@ -#pragma once - -#include <vector> - -#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> -#include <RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h> - -#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> -#include <RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h> - -#include <RobotAPI/libraries/aron/core/io/typeIO/writer/Writer.h> -#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h> - -namespace armarx -{ - - class AronTrivialDataWithoutCodeGeneration - { - public: - float f = 1; - int i = 42; - - bool operator==(const AronTrivialDataWithoutCodeGeneration& x) const - { - return x.f == f && x.i == i; - } - - void write(armarx::aron::io::AronDataWriter& w) const - { - w.writeStartDict(); - w.writeKey("f"); - w.writePrimitive(f); - w.writeKey("i"); - w.writePrimitive(i); - w.writeEndDict(); - } - - void writeType(armarx::aron::io::Writer& w) const - { - w.writeStartObjectType(); - w.writeObjectName("AronTrivialDataWithoutCodeGeneration"); - w.writeKey("f"); - w.writeFloatType(); - w.writeKey("i"); - w.writeIntType(); - w.writeEndObjectType(); - } - - void read(armarx::aron::io::AronDataReader& w) - { - f = 0; - i = 0; - - w.readStartDict(); - w.readKey("f"); - w.readPrimitive(f); - w.readKey("i"); - w.readPrimitive(i); - w.readEndDict(); - } - - armarx::aron::datanavigator::DictNavigatorPtr toAron() const - { - armarx::aron::io::NavigatorWriter writer; - this->write(writer); - return armarx::aron::datanavigator::DictNavigator::DynamicCast(writer.getResult()); - } - - void fromAron(const armarx::aron::datanavigator::DictNavigatorPtr& input) - { - armarx::aron::io::NavigatorReader reader(input); - //this->read(reader); - } - - armarx::aron::typenavigator::ObjectNavigatorPtr toAronType() const - { - armarx::aron::io::NavigatorWriter writer; - this->writeType(writer); - return armarx::aron::typenavigator::ObjectNavigator::DynamicCast(writer.getResult()); - } - }; - - class AronSimpleDataWithoutCodeGeneration - { - public: - std::string str = "stringy"; - std::vector<int> vec_i = {37, 38, 39}; - - bool operator==(const AronSimpleDataWithoutCodeGeneration& i) const - { - return i.str == str && i.vec_i == vec_i; - } - - void write(armarx::aron::io::AronDataWriter& w) const - { - w.writeStartDict(); - - w.writeKey("str"); - w.writePrimitive(str); - - w.writeKey("vec_i"); - w.writeStartList(); - for (const auto& e : vec_i) - { - w.writePrimitive(e); - } - w.writeEndList(); - - w.writeEndDict(); - } - - void writeType(armarx::aron::io::Writer& w) const - { - w.writeStartObjectType(); - w.writeObjectName("AronSimpleDataWithoutCodeGeneration"); - w.writeKey("str"); - w.writeStringType(); - w.writeKey("vec_i"); - w.writeStartListType(); - w.writeIntType(); - w.writeEndListType(); - w.writeEndObjectType(); - } - - void read(armarx::aron::io::AronDataReader& w) - { - str = ""; - vec_i.clear(); - - w.readStartDict(); - - w.readKey("str"); - w.readPrimitive(str); - - w.readKey("vec_i"); - w.readStartList(); - while (!w.readEndList()) - { - int e; - w.readPrimitive(e); - vec_i.push_back(e); - } - w.readEndDict(); - } - - - armarx::aron::datanavigator::DictNavigatorPtr toAron() const - { - armarx::aron::io::NavigatorWriter writer; - this->write(writer); - return armarx::aron::datanavigator::DictNavigator::DynamicCast(writer.getResult()); - } - - void fromAron(const armarx::aron::datanavigator::DictNavigatorPtr& input) - { - //armarx::aron::io::NavigatorReader reader(input); - //this->read(reader); - } - - armarx::aron::typenavigator::ObjectNavigatorPtr toAronType() const - { - armarx::aron::io::NavigatorWriter writer; - this->writeType(writer); - return armarx::aron::typenavigator::ObjectNavigator::DynamicCast(writer.getResult()); - } - }; - - class AronNestedDataWithoutCodeGeneration - { - public: - AronTrivialDataWithoutCodeGeneration tri; - std::vector<AronTrivialDataWithoutCodeGeneration> vec_tri{{}, {}, {}}; - AronSimpleDataWithoutCodeGeneration simp; - std::vector<AronSimpleDataWithoutCodeGeneration> vec_simp{{}, {}}; - - bool operator==(const AronNestedDataWithoutCodeGeneration& i) const - { - return i.tri == tri && - i.vec_tri == vec_tri && - simp == i.simp && - i.vec_simp == vec_simp; - } - - void write(armarx::aron::io::AronDataWriter& w) const - { - w.writeStartDict(); - - w.writeKey("tri"); - tri.write(w); - - w.writeKey("vec_tri"); - w.writeStartList(); - for (auto& e : vec_tri) - { - e.write(w); - } - w.writeEndList(); - - w.writeKey("simp"); - simp.write(w); - w.writeKey("vec_simp"); - w.writeStartList(); - for (auto& e : vec_simp) - { - e.write(w); - } - w.writeEndList(); - w.writeEndDict(); - } - - void writeType(armarx::aron::io::Writer& w) const - { - w.writeStartObjectType(); - w.writeObjectName("AronNestedDataWithoutCodeGeneration"); - w.writeKey("tri"); - tri.writeType(w); - - w.writeKey("vec_tri"); - w.writeStartListType(); - tri.writeType(w); // hack here - w.writeEndListType(); - - w.writeKey("simp"); - simp.writeType(w); - - w.writeKey("vec_simp"); - w.writeStartListType(); - simp.writeType(w); // hack here - w.writeEndListType(); - - w.writeEndObjectType(); - } - - void read(armarx::aron::io::AronDataReader& w) - { - // dont forget to reset! - tri = AronTrivialDataWithoutCodeGeneration(); - vec_tri.clear(); - simp = AronSimpleDataWithoutCodeGeneration(); - vec_simp.clear(); - - w.readStartDict(); - - w.readKey("tri"); - tri.read(w); - - w.readKey("vec_tri"); - w.readStartList(); - while (!w.readEndList()) - { - AronTrivialDataWithoutCodeGeneration e; - e.read(w); - vec_tri.push_back(e); - } - - w.readKey("simp"); - simp.read(w); - - w.readKey("vec_simp"); - w.readStartList(); - while (!w.readEndList()) - { - AronSimpleDataWithoutCodeGeneration e; - e.read(w); - vec_simp.push_back(e); - } - w.readEndDict(); - } - - armarx::aron::datanavigator::DictNavigatorPtr toAron() const - { - armarx::aron::io::NavigatorWriter writer; - this->write(writer); - return armarx::aron::datanavigator::DictNavigator::DynamicCast(writer.getResult()); - } - - void fromAron(const armarx::aron::datanavigator::DictNavigatorPtr& input) - { - armarx::aron::io::NavigatorReader reader(input); - //this->read(reader); - } - - armarx::aron::typenavigator::ObjectNavigatorPtr toAronType() const - { - armarx::aron::io::NavigatorWriter writer; - this->writeType(writer); - return armarx::aron::typenavigator::ObjectNavigator::DynamicCast(writer.getResult()); - } - - }; - - /*template<class T> - void test(const auto& name) - { - std::cout << "############################\n" << name << '\n'; - T orig; - T round; - std::string orig_j; - std::string round_j; - - { - armarx::aron::io::AronDataJSONWriter jwrt_o; - write(orig, jwrt_o); - orig_j = jwrt_o.getResult(); - std::cout << "orig\n" << orig_j << '\n'; - } - - { - armarx::aron::io::NavigatorWriter wrt; - write(orig, wrt); - armarx::aron::io::NavigatorReader rdr(wrt.getResult()); - read(round, rdr); - } - - { - armarx::aron::io::AronDataJSONWriter jwrt_r; - write(round, jwrt_r); - round_j = jwrt_r.getResult(); - std::cout << "round\n" << round_j << '\n'; - } - - std::cout << "equal? " << (orig_j == round_j) << '\n'; - }*/ - - //#include <iostream> - //int main() - //{ - // test<trivial>("trivial"); - // test<simple >("simple"); - // test<nested >("nested"); - // - // return 0; - //} - -} diff --git a/source/RobotAPI/libraries/aron/core/test/aronNavigateTest.cpp b/source/RobotAPI/libraries/aron/core/test/aronNavigateTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..233814ffd7c60a09fa9588093c7d1e2f726e282e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/aronNavigateTest.cpp @@ -0,0 +1,98 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::aron + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2019 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXLibraries::aron + +#define ARMARX_BOOST_TEST + +// STD/STL +#include <iostream> +#include <cstdlib> +#include <ctime> +#include <numeric> + +// Boost +#include <boost/algorithm/string.hpp> + +// Test +#include <RobotAPI/Test.h> + +// ArmarX +#include <ArmarXCore/libraries/cppgen/CppMethod.h> +#include <ArmarXCore/libraries/cppgen/CppClass.h> +#include <RobotAPI/libraries/aron/core/Exception.h> + +// Aron +#include <RobotAPI/libraries/aron/core/Debug.h> +#include <RobotAPI/libraries/aron/core/Randomizer.h> + +// Generated File +#include <RobotAPI/libraries/aron/core/test/aron/NaturalIKTest.aron.generated.h> + +using namespace armarx; +using namespace aron; + +BOOST_AUTO_TEST_CASE(AronNavigateTest) +{ + std::cout << "Running navigate test" << std::endl; + NaturalIKResult k; + NaturalIKResult k2; + + // test Path + datanavigator::DictNavigatorPtr aron = k.toAron(); + Path path = aron->getPath(); // should be empty since aron is top level object + Path memberReached(path, "reached"); + Path memberJointValues(path, "jointValues"); + Path indexJointValues0(memberJointValues, "0"); + Path indexJointValues1(memberJointValues, "1"); + + BOOST_CHECK_EQUAL(path.toString(), "\\"); + BOOST_CHECK_EQUAL(path.size(), 0); + + BOOST_CHECK_EQUAL(memberReached.toString(), "\\->reached"); + BOOST_CHECK_EQUAL(memberReached.size(), 1); + + BOOST_CHECK_EQUAL(memberJointValues.toString(), "\\->jointValues"); + BOOST_CHECK_EQUAL(memberJointValues.size(), 1); + + BOOST_CHECK_EQUAL(indexJointValues0.toString(), "\\->jointValues->0"); + BOOST_CHECK_EQUAL(indexJointValues0.size(), 2); + + BOOST_CHECK_EQUAL(indexJointValues1.toString(), "\\->jointValues->1"); + BOOST_CHECK_EQUAL(indexJointValues1.size(), 2); + + datanavigator::BoolNavigatorPtr reached = datanavigator::BoolNavigator::DynamicCastAndCheck(aron->navigateAbsolute(memberReached)); + datanavigator::ListNavigatorPtr jointValues = datanavigator::ListNavigator::DynamicCastAndCheck(aron->navigateAbsolute(memberJointValues)); + + if (jointValues->childrenSize() > 0) + { + datanavigator::FloatNavigatorPtr el = datanavigator::FloatNavigator::DynamicCastAndCheck(aron->navigateAbsolute(indexJointValues0)); + } + if (jointValues->childrenSize() > 1) + { + datanavigator::FloatNavigatorPtr el = datanavigator::FloatNavigator::DynamicCastAndCheck(aron->navigateAbsolute(indexJointValues1)); + } + + Path diff = indexJointValues1.getWithoutPrefix(indexJointValues0); + BOOST_CHECK_EQUAL(diff.toString(), "\\->1"); + BOOST_CHECK_EQUAL(diff.size(), 1); +} diff --git a/source/RobotAPI/libraries/aron/core/test/aronOperatorTest.cpp b/source/RobotAPI/libraries/aron/core/test/aronOperatorTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..539b6fb0449f1ba3e7258c502e28602a07a5b796 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/aronOperatorTest.cpp @@ -0,0 +1,94 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::aron + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2019 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXLibraries::aron + +#define ARMARX_BOOST_TEST + +// STD/STL +#include <iostream> +#include <cstdlib> +#include <ctime> +#include <numeric> + +// Boost +#include <boost/algorithm/string.hpp> + +// Test +#include <RobotAPI/Test.h> + +// ArmarX +#include <ArmarXCore/libraries/cppgen/CppMethod.h> +#include <ArmarXCore/libraries/cppgen/CppClass.h> +#include <RobotAPI/libraries/aron/core/Exception.h> + +// Aron +#include <RobotAPI/libraries/aron/core/Debug.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> + +using namespace armarx; +using namespace aron; + +BOOST_AUTO_TEST_CASE(AronAssignmentTest) +{ + std::cout << "Aron assignment test" << std::endl; + float f = 5.0; + double d = 42.0; + int i = 666; + long l = 123; + std::string s = "Hello World"; + bool b = true; + + aron::datanavigator::FloatNavigator fn = f; + aron::datanavigator::DoubleNavigator dn = d; + aron::datanavigator::IntNavigator in = i; + aron::datanavigator::LongNavigator ln = l; + aron::datanavigator::StringNavigator sn = s; + aron::datanavigator::BoolNavigator bn = b; + + BOOST_CHECK_EQUAL((float) fn == f, true); + BOOST_CHECK_EQUAL((double) dn == d, true); + BOOST_CHECK_EQUAL((int) in == i, true); + BOOST_CHECK_EQUAL((long) ln == l, true); + BOOST_CHECK_EQUAL((std::string) sn == s, true); + BOOST_CHECK_EQUAL((bool) bn == b, true); +} + +BOOST_AUTO_TEST_CASE(AronEqualsTest) +{ + std::cout << "Aron equals test" << std::endl; + aron::datanavigator::FloatNavigator fn = 5.0; + aron::datanavigator::FloatNavigator fn_equals = 5.0; + aron::datanavigator::FloatNavigator fn_unequals = 6.0; + + BOOST_CHECK_EQUAL(fn == fn_equals, true); + BOOST_CHECK_EQUAL(fn == fn_unequals, false); + + auto fn_ptr_equals = std::make_shared<aron::datanavigator::FloatNavigator>(5.0); + auto fn_ptr_unequals = std::make_shared<aron::datanavigator::FloatNavigator>(42.0); + + BOOST_CHECK_EQUAL(fn == fn_ptr_equals, true); + BOOST_CHECK_EQUAL(fn == fn_ptr_unequals, false); +} + +// TODO more tests (fabian.peller) + diff --git a/source/RobotAPI/libraries/aron/core/test/aronRandomizedTest.cpp b/source/RobotAPI/libraries/aron/core/test/aronRandomizedTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d579f3a6dab0e0a432b8a383f47be4496dcca137 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/aronRandomizedTest.cpp @@ -0,0 +1,375 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::aron + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2019 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXLibraries::aron + +#define ARMARX_BOOST_TEST + +// STD/STL +#include <iostream> +#include <cstdlib> +#include <ctime> +#include <numeric> + +// IVT +#include <Image/ByteImage.h> + +// Eigen +#include <Eigen/Core> + +// OpenCV +#include <opencv2/core/core.hpp> + +// PCL +#include <pcl/point_cloud.h> +#include <pcl/point_types.h> + +// Boost +#include <boost/algorithm/string.hpp> + +// Test +#include <RobotAPI/Test.h> + +// ArmarX +#include <ArmarXCore/libraries/cppgen/CppMethod.h> +#include <ArmarXCore/libraries/cppgen/CppClass.h> +#include <RobotAPI/libraries/aron/core/Exception.h> + +// Aron +#include <RobotAPI/libraries/aron/core/Debug.h> +#include <RobotAPI/libraries/aron/core/Randomizer.h> + +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.h> + +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h> + +#include <RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReader.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.h> + +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h> + +// Files without code generation +//#include "aronDataWithoutCodeGeneration.h" + +// Generated File +#include <RobotAPI/libraries/aron/core/test/aron/ListTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/DictTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/PrimitiveTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/ObjectTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/IVTCByteImageTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/EigenMatrixTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/EigenQuaternionTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/OpenCVMatTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/PCLPointCloudTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/PositionTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/OrientationTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/PoseTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/EnumTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/OptionalTest.aron.generated.h> + +using namespace armarx; +using namespace aron; + +template <typename T> +void runTestWithInstances(T& k1, T& k2) +{ + // assumes not nullptrs as k1 and k2. If you have a maybe type then make sure that it is set properly + + int echo_debug_lv = 1; + + Randomizer r; + + { + if (echo_debug_lv) + { + std::cout << "\t getting type 1" << std::endl; + } + typenavigator::ObjectNavigatorPtr k1_type_nav = k1.toAronType(); + type::AronObjectPtr k1_type = k1_type_nav->toAronObjectPtr(); + BOOST_CHECK_EQUAL((bool) k1_type, true); + + armarx::aron::typeIO::writer::NlohmannJSONWriter json_writer_k1; + k1.writeType(json_writer_k1); + nlohmann::json k1_type_json = json_writer_k1.getResult(); + BOOST_CHECK_EQUAL(k1_type_json.is_object(), true); + + if (echo_debug_lv) + { + std::cout << "\t getting type 2" << std::endl; + } + typenavigator::ObjectNavigatorPtr k2_type_nav = k2.toAronType(); + type::AronObjectPtr k2_type = k2_type_nav->toAronObjectPtr(); + BOOST_CHECK_EQUAL((bool) k2_type, true); + + armarx::aron::typeIO::writer::NlohmannJSONWriter json_writer_k2; + k2.writeType(json_writer_k2); + nlohmann::json k2_type_json = json_writer_k2.getResult(); + BOOST_CHECK_EQUAL(k2_type_json.is_object(), true); + BOOST_CHECK_EQUAL(k1_type_json.dump(2), k2_type_json.dump(2)); + } + + { + typenavigator::ObjectNavigatorPtr k1_type_nav = k1.toAronType(); + datanavigator::DictNavigatorPtr k1_aron_nav = k1.toAron(); + + if (echo_debug_lv) + { + std::cout << "\t initialize aron 1 randomly" << std::endl; + } + r.initializeRandomly(k1_aron_nav, k1_type_nav); + + if (echo_debug_lv) + { + std::cout << "\t getting aron 1" << std::endl; + } + data::AronDictPtr k1_aron = k1_aron_nav->toAronDictPtr(); + BOOST_CHECK_EQUAL((bool) k1_aron, true); + + if (echo_debug_lv >= 2) + { + std::cout << "K1 Aron:" << std::endl; + std::cout << armarx::aron::Debug::AronDataPtrToString(k1_aron) << std::endl; + std::cout << "K2 Aron:" << std::endl; + std::cout << armarx::aron::Debug::AronDataPtrToString(k2.toAron()->toAronDictPtr()) << std::endl; + } + + if (echo_debug_lv) + { + std::cout << "\t setting aron 2 from aron 1" << std::endl; + } + k2.fromAron(k1_aron); + + if (echo_debug_lv) + { + std::cout << "\t getting aron 2" << std::endl; + } + datanavigator::DictNavigatorPtr k2_aron_nav = k2.toAron(); + BOOST_CHECK_EQUAL((*k1_aron_nav == *k2_aron_nav), true); + + data::AronDictPtr k2_aron = k2_aron_nav->toAronDictPtr(); + BOOST_CHECK_EQUAL((bool) k2_aron, true); + + if (echo_debug_lv) + { + std::cout << "\t setting aron 1 from aron 2 and check for equality" << std::endl; + } + k1.fromAron(k2_aron_nav); + + if (echo_debug_lv >= 2) + { + std::cout << "K1 Aron:" << std::endl; + std::cout << armarx::aron::Debug::AronDataPtrToString(k1.toAron()->toAronDictPtr()) << std::endl; + std::cout << "K2 Aron:" << std::endl; + std::cout << armarx::aron::Debug::AronDataPtrToString(k2.toAron()->toAronDictPtr()) << std::endl; + } + BOOST_CHECK_EQUAL((k1 == k2), true); + + datanavigator::DictNavigatorPtr k1_aron_nav_again = k1.toAron(); + BOOST_CHECK_EQUAL((*k1_aron_nav == *k1_aron_nav_again), true); + } + + { + typenavigator::ObjectNavigatorPtr k1_type_nav = k1.toAronType(); + datanavigator::DictNavigatorPtr k1_aron_nav = k1.toAron(); + + r.initializeRandomly(k1_aron_nav, k1_type_nav); + + data::AronDictPtr k1_aron = k1_aron_nav->toAronDictPtr(); + k1.fromAron(k1_aron); + + if (echo_debug_lv) + { + std::cout << "\t check JSON export of k and k2 for equality" << std::endl; + } + armarx::aron::dataIO::writer::NlohmannJSONWriter json_writer_for_k1; + armarx::aron::dataIO::writer::NlohmannJSONWriter json_writer_for_k2; + + k1.write(json_writer_for_k1); + nlohmann::json k1_aron_json = json_writer_for_k1.getResult(); + std::string k1_aron_json_str = k1_aron_json.dump(4); + + armarx::aron::dataIO::writer::NlohmannJSONWriter direct_json_writer_for_k1; + armarx::aron::dataIO::Visitor::VisitAndSetup(direct_json_writer_for_k1, k1_aron); + nlohmann::json direct_k1_aron_json = direct_json_writer_for_k1.getResult(); + std::string direct_k1_aron_json_str = direct_k1_aron_json.dump(4); + + if (echo_debug_lv >= 2) + { + std::cout << "\t K1 as json: " << std::endl << k1_aron_json_str << std::endl; + std::cout << "\t K1 as direct json: " << std::endl << direct_k1_aron_json_str << std::endl; + } + BOOST_CHECK_EQUAL((k1_aron_json_str == direct_k1_aron_json_str), true); + + armarx::aron::dataIO::reader::NlohmannJSONReader json_reader_for_k2(k1_aron_json); + + k2.read(json_reader_for_k2); + k2.write(json_writer_for_k2); + + nlohmann::json k2_aron_json = json_writer_for_k2.getResult(); + std::string k2_aron_json_str = k2_aron_json.dump(4); + + if (echo_debug_lv >= 2) + { + std::cout << "\t K1 as json: " << std::endl << k1_aron_json_str << std::endl; + std::cout << "\t K2 as json: " << std::endl << k2_aron_json_str << std::endl; + } + BOOST_CHECK_EQUAL((k1_aron_json_str == k2_aron_json_str), true); + } +} + +BOOST_AUTO_TEST_CASE(AronListTest) +{ + std::cout << "Running List test" << std::endl; + ListTest l; + ListTest l2; + runTestWithInstances<ListTest>(l, l2); +} + +BOOST_AUTO_TEST_CASE(AronDictTest) +{ + std::cout << "Running Dict test" << std::endl; + DictTest d; + DictTest d2; + runTestWithInstances<DictTest>(d, d2); +} + +BOOST_AUTO_TEST_CASE(AronPrimitiveTest) +{ + std::cout << "Running Primitive test" << std::endl; + PrimitiveTest p; + PrimitiveTest p2; + runTestWithInstances<PrimitiveTest>(p, p2); +} + +BOOST_AUTO_TEST_CASE(AronObjectTest) +{ + std::cout << "Running Object test" << std::endl; + ObjectTest1 o1; + ObjectTest1 o12; + runTestWithInstances<ObjectTest1>(o1, o12); + + ObjectTest2 o2; + ObjectTest2 o22; + runTestWithInstances<ObjectTest2>(o2, o22); +} + +BOOST_AUTO_TEST_CASE(AronImageTest) +{ + std::cout << "Running Image test" << std::endl; + IVTCByteImageTest ii; + IVTCByteImageTest ii2; + + ii.the_grayscale_image = std::make_shared<CByteImage>(); + ii2.the_grayscale_image = std::make_shared<CByteImage>(); + + ii.the_rgb_image = std::make_shared<CByteImage>(); + ii2.the_rgb_image = std::make_shared<CByteImage>(); + + ii.the_grayscale_image->Set(5, 5, CByteImage::eGrayScale); + ii2.the_grayscale_image->Set(7, 7, CByteImage::eGrayScale); + + ii.the_rgb_image->Set(5, 5, CByteImage::eRGB24); + ii2.the_rgb_image->Set(7, 7, CByteImage::eRGB24); + + runTestWithInstances<IVTCByteImageTest>(ii, ii2); +} + +BOOST_AUTO_TEST_CASE(AronEigenMatrixTest) +{ + // Eigen may cause problems with dimensions > 145 + std::cout << "Running EigenMatrix test" << std::endl; + EigenMatrixTest em; + EigenMatrixTest em2; + runTestWithInstances<EigenMatrixTest>(em, em2); +} + +BOOST_AUTO_TEST_CASE(AronOpenCVTest) +{ + std::cout << "Running OpenCVMat test" << std::endl; + OpenCVMatTest ocv; + OpenCVMatTest ocv2; + + ocv.the_2d_opencv_matrix = cv::Mat(2, 2, CV_64F); + ocv.the_3d_opencv_matrix = cv::Mat(std::vector<int>({2, 2, 2}), CV_32F); + ocv.the_4d_opencv_matrix = cv::Mat(std::vector<int>({2, 2, 2, 2}), CV_16S); + ocv.the_5d_opencv_matrix = cv::Mat(std::vector<int>({2, 2, 2, 2, 2}), CV_8U); + + runTestWithInstances<OpenCVMatTest>(ocv, ocv2); +} + +BOOST_AUTO_TEST_CASE(AronPCLPointCloudTest) +{ + std::cout << "Running PCLPointCloud test" << std::endl; + PointCloudTest pc; + PointCloudTest pc2; + + pc.the_xyzrgb_pcl_pointcloud = pcl::PointCloud<pcl::PointXYZRGB>(5, 5); + pc.the_xyzrgba_pcl_pointcloud = pcl::PointCloud<pcl::PointXYZRGBA>(7, 7); + + pc2.the_xyzrgb_pcl_pointcloud = pcl::PointCloud<pcl::PointXYZRGB>(4, 4); + pc2.the_xyzrgba_pcl_pointcloud = pcl::PointCloud<pcl::PointXYZRGBA>(3, 3); + + runTestWithInstances<PointCloudTest>(pc, pc2); +} + +BOOST_AUTO_TEST_CASE(AronEigenQuaternionTest) +{ + std::cout << "Running EigenQuaternion test" << std::endl; + EigenQuaternionTest eq; + EigenQuaternionTest eq2; + runTestWithInstances<EigenQuaternionTest>(eq, eq2); +} + +BOOST_AUTO_TEST_CASE(AronPositionTest) +{ + std::cout << "Running Position test" << std::endl; + PositionTest pc; + PositionTest pc2; + runTestWithInstances<PositionTest>(pc, pc2); +} + +BOOST_AUTO_TEST_CASE(AronOrientationTest) +{ + std::cout << "Running Orientation test" << std::endl; + OrientationTest pc; + OrientationTest pc2; + runTestWithInstances<OrientationTest>(pc, pc2); +} + +BOOST_AUTO_TEST_CASE(AronPoseTest) +{ + std::cout << "Running Pose test" << std::endl; + PoseTest pc; + PoseTest pc2; + runTestWithInstances<PoseTest>(pc, pc2); +} + +BOOST_AUTO_TEST_CASE(AronOptionalTest) +{ + std::cout << "Running Optional test" << std::endl; + OptionalTest pc; + OptionalTest pc2; + runTestWithInstances<OptionalTest>(pc, pc2); +} diff --git a/source/RobotAPI/libraries/aron/core/test/aronTest.cpp b/source/RobotAPI/libraries/aron/core/test/aronTest.cpp deleted file mode 100644 index 92efc6508c634ae3d411b75092bbf5572f78be96..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/core/test/aronTest.cpp +++ /dev/null @@ -1,458 +0,0 @@ -/* - * This file is part of ArmarX. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX 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 this program. If not, see <http://www.gnu.org/licenses/>. - * - * @package RobotAPI::ArmarXObjects::aron - * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) - * @date 2019 - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#define BOOST_TEST_MODULE RobotAPI::ArmarXLibraries::aron - -#define ARMARX_BOOST_TEST - -// STD/STL -#include <iostream> -#include <cstdlib> -#include <ctime> -#include <numeric> - -// IVT -#include <Image/ByteImage.h> - -// Eigen -#include <Eigen/Core> - -// OpenCV -#include <opencv2/core/core.hpp> - -// PCL -#include <pcl/point_cloud.h> -#include <pcl/point_types.h> - -// Boost -#include <boost/algorithm/string.hpp> - -// Test -#include <RobotAPI/Test.h> - -// ArmarX -#include <ArmarXCore/libraries/cppgen/CppMethod.h> -#include <ArmarXCore/libraries/cppgen/CppClass.h> -#include <RobotAPI/libraries/aron/core/Exception.h> - -// Aron -#include <RobotAPI/libraries/aron/core/Debug.h> -#include <RobotAPI/libraries/aron/core/Randomizer.h> - -#include <RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h> -#include <RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.h> - -#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> -#include <RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h> - -// Files without code generation -//#include "aronDataWithoutCodeGeneration.h" - -// Generated File -#include <RobotAPI/libraries/aron/core/test/aron/NaturalIKTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/ListTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/DictTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/PrimitiveTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/ObjectTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/IVTCByteImageTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/EigenMatrixTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/EigenQuaternionTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/OpenCVMatTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/PCLPointCloudTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/PositionTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/OrientationTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/PoseTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/EnumTest.aron.generated.h> -#include <RobotAPI/libraries/aron/core/test/aron/OptionalTest.aron.generated.h> - -using namespace armarx; -using namespace aron; - -template <typename T> -void runTestWithInstances(T& k1, T& k2) -{ - bool echo = false; - - Randomizer r; - - if (echo) - { - std::cout << "\t getting type 1" << std::endl; - } - typenavigator::ObjectNavigatorPtr k1_type_nav = k1.toAronType(); - type::AronObjectPtr k1_type = k1_type_nav->toAronObjectPtr(); - BOOST_CHECK_EQUAL((bool) k1_type, true); - - if (echo) - { - std::cout << "\t getting type 2" << std::endl; - } - typenavigator::ObjectNavigatorPtr k2_type_nav = k2.toAronType(); - type::AronObjectPtr k2_type = k2_type_nav->toAronObjectPtr(); - BOOST_CHECK_EQUAL((bool) k2_type, true); - - datanavigator::DictNavigatorPtr k1_aron_nav = k1.toAron(); - - if (echo) - { - std::cout << "\t initialize aron 1 randomly" << std::endl; - } - r.initializeRandomly(k1_aron_nav, k1_type_nav); - - if (echo) - { - std::cout << "\t getting aron 1" << std::endl; - } - data::AronDictPtr k1_aron = k1_aron_nav->toAronDictPtr(); - BOOST_CHECK_EQUAL((bool) k1_aron, true); - - if (echo) - { - std::cout << "K1 Aron:" << std::endl; - } - if (echo) - { - std::cout << armarx::aron::Debug::AronDataPtrToString(k1_aron) << std::endl; - } - - if (echo) - { - std::cout << "K2 Aron:" << std::endl; - } - if (echo) - { - std::cout << armarx::aron::Debug::AronDataPtrToString(k2.toAron()->toAronDictPtr()) << std::endl; - } - - if (echo) - { - std::cout << "\t setting aron 2 from aron 1" << std::endl; - } - k2.fromAron(k1_aron); - - if (echo) - { - std::cout << "\t getting aron 2" << std::endl; - } - datanavigator::DictNavigatorPtr k2_aron_nav = k2.toAron(); - data::AronDictPtr k2_aron = k2_aron_nav->toAronDictPtr(); - BOOST_CHECK_EQUAL((bool) k2_aron, true); - - //if (echo) std::cout << "K2 Aron:" << std::endl; - //if (echo) std::cout << armarx::aron::Debug::AronDataPtrToString(k2_aron) << std::endl; - - if (echo) - { - std::cout << "\t setting aron 1 from aron 2 and check for equality" << std::endl; - } - - k1.fromAron(k2_aron_nav); - - if (echo) - { - std::cout << "K1 Aron:" << std::endl; - } - if (echo) - { - std::cout << armarx::aron::Debug::AronDataPtrToString(k1.toAron()->toAronDictPtr()) << std::endl; - } - - if (echo) - { - std::cout << "K2 Aron:" << std::endl; - } - if (echo) - { - std::cout << armarx::aron::Debug::AronDataPtrToString(k2.toAron()->toAronDictPtr()) << std::endl; - } - - BOOST_CHECK_EQUAL((k1 == k2), true); - - - //std::cout << "\t getting current type 1" << std::endl; - //typenavigator::NavigatorPtr k1_current_type_nav = k1.toCurrentAronType(); - //type::AronTypePtr k1_current_type = k1_current_type_nav->getResult(); - //BOOST_CHECK_NE(k1_current_type.get(), nullptr); - - //std::cout << "\t getting type 2" << std::endl; - //typenavigator::NavigatorPtr k2_current_type_nav = k2.toCurrentAronType(); - //type::AronTypePtr k2_current_type = k2_current_type_nav->getResult(); - //BOOST_CHECK_NE(k2_current_type.get(), nullptr); - - r.initializeRandomly(k1_aron_nav, k1_type_nav); - - k1.fromAron(k1_aron); - - if (echo) - { - std::cout << "\t check JSON export of k and k2 for equality" << std::endl; - } - armarx::aron::dataIO::writer::NlohmannJSONWriter json_writer_for_k1; - armarx::aron::dataIO::writer::NlohmannJSONWriter json_writer_for_k2; - - k1.write(json_writer_for_k1); - nlohmann::json k1_aron_json = json_writer_for_k1.getResult(); - std::string k1_aron_json_str = k1_aron_json.dump(4); - - armarx::aron::dataIO::writer::NlohmannJSONWriter direct_json_writer_for_k1; - armarx::aron::dataIO::Visitor::VisitAndSetup(direct_json_writer_for_k1, k1_aron); - nlohmann::json direct_k1_aron_json = direct_json_writer_for_k1.getResult(); - std::string direct_k1_aron_json_str = direct_k1_aron_json.dump(4); - - if (echo) - { - std::cout << "\t K1 as json: " << std::endl << k1_aron_json_str << std::endl; - } - if (echo) - { - std::cout << "\t K1 as direct json: " << std::endl << direct_k1_aron_json_str << std::endl; - } - BOOST_CHECK_EQUAL((k1_aron_json_str == direct_k1_aron_json_str), true); - - armarx::aron::dataIO::reader::NlohmannJSONReader json_reader_for_k2(k1_aron_json); - - k2.read(json_reader_for_k2); - k2.write(json_writer_for_k2); - - nlohmann::json k2_aron_json = json_writer_for_k2.getResult(); - std::string k2_aron_json_str = k2_aron_json.dump(4); - - if (echo) - { - std::cout << "\t K1 as json: " << std::endl << k1_aron_json_str << std::endl; - } - if (echo) - { - std::cout << "\t K2 as json: " << std::endl << k2_aron_json_str << std::endl; - } - BOOST_CHECK_EQUAL((k1_aron_json_str == k2_aron_json_str), true); -} - -BOOST_AUTO_TEST_CASE(AssignmentTest) -{ - std::cout << "Aron Assignment test" << std::endl; - float f = 5.0; - double d = 42.0; - int i = 666; - long l = 123; - std::string s = "Hello World"; - bool b = true; - - aron::datanavigator::FloatNavigator fn = f; - aron::datanavigator::DoubleNavigator dn = d; - aron::datanavigator::IntNavigator in = i; - aron::datanavigator::LongNavigator ln = l; - aron::datanavigator::StringNavigator sn = s; - aron::datanavigator::BoolNavigator bn = b; - - BOOST_CHECK_EQUAL((float) fn == f, true); - BOOST_CHECK_EQUAL((double) dn == d, true); - BOOST_CHECK_EQUAL((int) in == i, true); - BOOST_CHECK_EQUAL((long) ln == l, true); - BOOST_CHECK_EQUAL((std::string) sn == s, true); - BOOST_CHECK_EQUAL((bool) bn == b, true); - - -} - - -BOOST_AUTO_TEST_CASE(AronNaturalIKTest) -{ - std::cout << "Running NaturalIK test" << std::endl; - NaturalIKResult k; - NaturalIKResult k2; - runTestWithInstances<NaturalIKResult>(k, k2); - - // also test Path - datanavigator::DictNavigatorPtr aron = k.toAron(); - Path path = aron->getPath(); // should be empty since aron is top level object - Path memberReached(path, "reached"); - Path memberJointValues(path, "jointValues"); - Path indexJointValues0(memberJointValues, "0"); - Path indexJointValues1(memberJointValues, "1"); - - BOOST_CHECK_EQUAL(path.toString(), "\\"); - BOOST_CHECK_EQUAL(path.size(), 0); - - BOOST_CHECK_EQUAL(memberReached.toString(), "\\->reached"); - BOOST_CHECK_EQUAL(memberReached.size(), 1); - - BOOST_CHECK_EQUAL(memberJointValues.toString(), "\\->jointValues"); - BOOST_CHECK_EQUAL(memberJointValues.size(), 1); - - BOOST_CHECK_EQUAL(indexJointValues0.toString(), "\\->jointValues->0"); - BOOST_CHECK_EQUAL(indexJointValues0.size(), 2); - - BOOST_CHECK_EQUAL(indexJointValues1.toString(), "\\->jointValues->1"); - BOOST_CHECK_EQUAL(indexJointValues1.size(), 2); - - datanavigator::BoolNavigatorPtr reached = datanavigator::BoolNavigator::DynamicCastAndCheck(aron->navigateAbsolute(memberReached)); - datanavigator::ListNavigatorPtr jointValues = datanavigator::ListNavigator::DynamicCastAndCheck(aron->navigateAbsolute(memberJointValues)); - - if (jointValues->childrenSize() > 0) - { - datanavigator::FloatNavigatorPtr el = datanavigator::FloatNavigator::DynamicCastAndCheck(aron->navigateAbsolute(indexJointValues0)); - } - if (jointValues->childrenSize() > 1) - { - datanavigator::FloatNavigatorPtr el = datanavigator::FloatNavigator::DynamicCastAndCheck(aron->navigateAbsolute(indexJointValues1)); - } - - Path diff = indexJointValues1.getWithoutPrefix(indexJointValues0); - BOOST_CHECK_EQUAL(diff.toString(), "\\->1"); - BOOST_CHECK_EQUAL(diff.size(), 1); -} - - -BOOST_AUTO_TEST_CASE(AronListTest) -{ - std::cout << "Running List test" << std::endl; - ListTest l; - ListTest l2; - runTestWithInstances<ListTest>(l, l2); -} - -BOOST_AUTO_TEST_CASE(AronDictTest) -{ - std::cout << "Running Dict test" << std::endl; - DictTest d; - DictTest d2; - runTestWithInstances<DictTest>(d, d2); -} - -BOOST_AUTO_TEST_CASE(AronPrimitiveTest) -{ - std::cout << "Running Primitive test" << std::endl; - PrimitiveTest p; - PrimitiveTest p2; - runTestWithInstances<PrimitiveTest>(p, p2); -} - -BOOST_AUTO_TEST_CASE(AronObjectTest) -{ - std::cout << "Running Object test" << std::endl; - ObjectTest1 o1; - ObjectTest1 o12; - runTestWithInstances<ObjectTest1>(o1, o12); - - ObjectTest2 o2; - ObjectTest2 o22; - runTestWithInstances<ObjectTest2>(o2, o22); -} - -BOOST_AUTO_TEST_CASE(AronImageTest) -{ - std::cout << "Running Image test" << std::endl; - IVTCByteImageTest ii; - IVTCByteImageTest ii2; - - ii.the_grayscale_image = std::make_shared<CByteImage>(); - ii2.the_grayscale_image = std::make_shared<CByteImage>(); - - ii.the_rgb_image = std::make_shared<CByteImage>(); - ii2.the_rgb_image = std::make_shared<CByteImage>(); - - ii.the_grayscale_image->Set(5, 5, CByteImage::eGrayScale); - ii2.the_grayscale_image->Set(7, 7, CByteImage::eGrayScale); - - ii.the_rgb_image->Set(5, 5, CByteImage::eRGB24); - ii2.the_rgb_image->Set(7, 7, CByteImage::eRGB24); - - runTestWithInstances<IVTCByteImageTest>(ii, ii2); -} - -BOOST_AUTO_TEST_CASE(AronEigenMatrixTest) -{ - std::cout << "Running EigenMatrix test" << std::endl; - EigenMatrixTest em; - EigenMatrixTest em2; - runTestWithInstances<EigenMatrixTest>(em, em2); -} - -BOOST_AUTO_TEST_CASE(AronOpenCVTest) -{ - std::cout << "Running OpenCVMat test" << std::endl; - OpenCVMatTest ocv; - OpenCVMatTest ocv2; - - ocv.the_2d_opencv_matrix = cv::Mat(2, 2, CV_64F); - ocv.the_3d_opencv_matrix = cv::Mat(std::vector<int>({2, 2, 2}), CV_32F); - ocv.the_4d_opencv_matrix = cv::Mat(std::vector<int>({2, 2, 2, 2}), CV_16S); - ocv.the_5d_opencv_matrix = cv::Mat(std::vector<int>({2, 2, 2, 2, 2}), CV_8U); - - runTestWithInstances<OpenCVMatTest>(ocv, ocv2); -} - -BOOST_AUTO_TEST_CASE(AronPCLPointCloudTest) -{ - std::cout << "Running PCLPointCloud test" << std::endl; - PointCloudTest pc; - PointCloudTest pc2; - - pc.the_xyzrgb_pcl_pointcloud = pcl::PointCloud<pcl::PointXYZRGB>(5, 5); - pc.the_xyzrgba_pcl_pointcloud = pcl::PointCloud<pcl::PointXYZRGBA>(7, 7); - - pc2.the_xyzrgb_pcl_pointcloud = pcl::PointCloud<pcl::PointXYZRGB>(4, 4); - pc2.the_xyzrgba_pcl_pointcloud = pcl::PointCloud<pcl::PointXYZRGBA>(3, 3); - - runTestWithInstances<PointCloudTest>(pc, pc2); -} - -BOOST_AUTO_TEST_CASE(AronEigenQuaternionTest) -{ - std::cout << "Running EigenQuaternion test" << std::endl; - EigenQuaternionTest eq; - EigenQuaternionTest eq2; - runTestWithInstances<EigenQuaternionTest>(eq, eq2); -} - -BOOST_AUTO_TEST_CASE(AronPositionTest) -{ - std::cout << "Running Position test" << std::endl; - PositionTest pc; - PositionTest pc2; - runTestWithInstances<PositionTest>(pc, pc2); -} - -BOOST_AUTO_TEST_CASE(AronOrientationTest) -{ - std::cout << "Running Orientation test" << std::endl; - OrientationTest pc; - OrientationTest pc2; - runTestWithInstances<OrientationTest>(pc, pc2); -} - -BOOST_AUTO_TEST_CASE(AronPoseTest) -{ - std::cout << "Running Pose test" << std::endl; - PoseTest pc; - PoseTest pc2; - runTestWithInstances<PoseTest>(pc, pc2); -} - -BOOST_AUTO_TEST_CASE(AronOptionalTest) -{ - std::cout << "Running Optional test" << std::endl; - OptionalTest pc; - OptionalTest pc2; - runTestWithInstances<OptionalTest>(pc, pc2); -} diff --git a/source/RobotAPI/libraries/aron/core/test/xmls/EigenMatrixTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/EigenMatrixTest.xml index b3f5f6447c6fc6f3d3a8851e00578156ad4560b3..59e994015fda4f1359f74c6cc6ac401cbb4f66fd 100644 --- a/source/RobotAPI/libraries/aron/core/test/xmls/EigenMatrixTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/EigenMatrixTest.xml @@ -9,19 +9,19 @@ <GenerateTypes> <Object name='armarx::EigenMatrixTest'> <ObjectChild key='the_short_eigen_matrix'> - <EigenMatrix rows="10" cols="25" type="short" /> + <EigenMatrix rows="5" cols="7" type="short" /> </ObjectChild> <ObjectChild key='the_int_eigen_matrix'> - <EigenMatrix rows="25" cols="25" type="int" /> + <EigenMatrix rows="7" cols="7" type="int" /> </ObjectChild> <ObjectChild key='the_long_eigen_matrix'> - <EigenMatrix rows="25" cols="10" type="long" /> + <EigenMatrix rows="7" cols="5" type="long" /> </ObjectChild> <ObjectChild key='the_float_eigen_matrix'> - <EigenMatrix rows="1" cols="200" type="float" /> + <EigenMatrix rows="1" cols="9" type="float" /> </ObjectChild> <ObjectChild key='the_double_eigen_matrix'> - <EigenMatrix rows="200" cols="1" type="double" /> + <EigenMatrix rows="25" cols="1" type="double" /> </ObjectChild> </Object> </GenerateTypes> diff --git a/source/RobotAPI/libraries/aron/core/test/xmls/OptionalTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/OptionalTest.xml index 7b402cb38e4b904723c31ce7097ebc7623c296ba..8e27d3c0263af6decff1d945acb40cc1d3081df4 100644 --- a/source/RobotAPI/libraries/aron/core/test/xmls/OptionalTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/OptionalTest.xml @@ -15,7 +15,7 @@ <Float optional="1"/> </ObjectChild> - <ObjectChild key='some_string'> + <!--<ObjectChild key='some_string'> <String optional="true"/> </ObjectChild> @@ -57,7 +57,7 @@ <Float optional="ja" /> </List> </List> - </ObjectChild> + </ObjectChild>-->