Skip to content
Snippets Groups Projects
Commit d65dab6e authored by Fabian Reister's avatar Fabian Reister
Browse files

aron converter: common converter + vector converter; cmake aliases and interface library

parent 8f34a0ac
No related branches found
No related tags found
1 merge request!137Armem/dev
Showing
with 208 additions and 9 deletions
add_subdirectory(common)
add_subdirectory(ivt)
add_subdirectory(pcl)
add_subdirectory(eigen)
add_subdirectory(opencv)
add_library(AronConverter INTERFACE)
target_link_libraries(AronConverter
INTERFACE
RobotAPI::aron::converter::common
RobotAPI::aron::converter::ivt
RobotAPI::aron::converter::pcl
RobotAPI::aron::converter::eigen
RobotAPI::aron::converter::opencv
)
add_library(RobotAPI::aron::converter ALIAS AronConverter)
set(LIB_NAME aroncommonconverter)
armarx_component_set_name("${LIB_NAME}")
armarx_set_target("Library: ${LIB_NAME}")
set(LIBS
aron
)
set(LIB_FILES
Converter.cpp
VectorConverter.cpp
)
set(LIB_HEADERS
Converter.h
VectorConverter.h
)
armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}")
add_library(RobotAPI::aron::converter::common ALIAS aroncommonconverter)
#include "Converter.h"
\ No newline at end of file
/*
* 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/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <algorithm>
#include <vector>
namespace armarx::aron
{
/**
* @brief Converter function for vector of aron elements to plain cpp type
*
* You have to provide a converter function for the element with the signature
*
* PlainCppType fromAron(const AronType&)
*
* @tparam T the aron vector element
* @param v the vector of elements
* @return the vector of aron elements
*/
template <typename T>
auto fromAron(const std::vector<T>& v) -> std::vector<decltype(fromAron(T()))>
{
std::vector<decltype(fromAron(T()))> r;
r.reserve(v.size());
std::transform(v.begin(), v.end(), std::back_inserter(r),
[](const T & t)
{
return fromAron(t);
});
return r;
}
template <typename T> auto toAron(const std::vector<T>& v)
{
std::vector<decltype(toAron(T()))> r;
r.reserve(v.size());
std::transform(v.begin(), v.end(), std::back_inserter(r),
[](const T & t)
{
return toAron(t);
});
return r;
}
} // namespace armarx::aron
#include "VectorConverter.h"
\ No newline at end of file
/*
* 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/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
// STD/STL
#include <memory>
#include <string>
#include <numeric>
// ArmarX
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
#include <RobotAPI/interface/aron.h>
#include <RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h>
namespace armarx::aron::converter
{
class AronVectorConverter
{
public:
AronVectorConverter() = delete;
template<typename T>
static std::vector<T> ConvertToVector(const datanavigator::NDArrayNavigatorPtr& nav)
{
ARMARX_CHECK_NOT_NULL(nav);
const auto& dims = nav->getDimensions();
if(dims.size() != 2)
{
throw error::AronException("AronVectorConverter", "ConvertToVector", "The NDArray must have two dimensions.", nav->getPath());
}
if(dims.at(1) != sizeof(T))
{
throw error::AronException("AronVectorConverter", "ConvertToVector", "Dimension 1 of the array has to match the element size.", nav->getPath());
}
const int size = std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<>());
std::vector<T> v(dims.at(0));
memcpy(v.data(), nav->getData(), size);
return v;
}
};
} // namespace armarx::aron::converter
......@@ -8,6 +8,7 @@ armarx_build_if(Eigen3_FOUND "Eigen3 not available")
set(LIBS
aron
Eigen3::Eigen
)
set(LIB_FILES
......@@ -20,6 +21,4 @@ set(LIB_HEADERS
armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}")
if(Eigen3_FOUND)
include_directories(${Eigen3_INCLUDE_DIR})
endif()
add_library(RobotAPI::aron::converter::eigen ALIAS aroneigenconverter)
......@@ -7,7 +7,9 @@ find_package(IVT COMPONENTS ivt ivtopencv QUIET)
armarx_build_if(IVT_FOUND "IVT not available")
set(LIBS
aron ivt ivtopencv
aron
ivt
ivtopencv
)
set(LIB_FILES
......@@ -21,5 +23,10 @@ set(LIB_HEADERS
armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}")
if(IVT_FOUND)
include_directories(${IVT_INCLUDE_DIRS})
target_include_directories(aronivtconverter
SYSTEM PUBLIC
${IVT_INCLUDE_DIRS}
)
endif()
add_library(RobotAPI::aron::converter::ivt ALIAS aronivtconverter)
......@@ -7,7 +7,8 @@ find_package(OpenCV QUIET)
armarx_build_if(OpenCV_FOUND "OpenCV not available")
set(LIBS
aron ${OpenCV_LIBRARIES}
aron
${OpenCV_LIBRARIES}
)
set(LIB_FILES
......@@ -21,5 +22,11 @@ set(LIB_HEADERS
armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}")
if(OpenCV_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS})
target_include_directories(aronopencvconverter
SYSTEM PUBLIC
${OpenCV_INCLUDE_DIRS}
)
endif()
add_library(RobotAPI::aron::converter::opencv ALIAS aronopencvconverter)
......@@ -7,7 +7,8 @@ find_package(PCL QUIET)
armarx_build_if(PCL_FOUND "PCL not available")
set(LIBS
aron ${PCL_COMMON_LIBRARIES}
aron
${PCL_COMMON_LIBRARIES}
)
set(LIB_FILES
......@@ -21,5 +22,10 @@ set(LIB_HEADERS
armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}")
if(PCL_FOUND)
include_directories(${PCL_INCLUDE_DIRS})
target_include_directories(aronpclconverter
SYSTEM PUBLIC
${PCL_INCLUDE_DIRS}
)
endif()
add_library(RobotAPI::aron::converter::pcl ALIAS aronpclconverter)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment