Skip to content

Commit

Permalink
Add color, image and material classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Nov 19, 2022
1 parent 015a9eb commit 235ecf8
Show file tree
Hide file tree
Showing 15 changed files with 3,716 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tesseract_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ find_package(Boost REQUIRED COMPONENTS system filesystem serialization)
find_package(Eigen3 REQUIRED)
find_package(TinyXML2 REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(FreeImage REQUIRED)

find_package(console_bridge REQUIRED)
if(NOT TARGET console_bridge::console_bridge)
Expand Down Expand Up @@ -47,12 +48,18 @@ add_library(
src/allowed_collision_matrix.cpp
src/any_poly.cpp
src/collision_margin_data.cpp
src/color.cpp
src/joint_state.cpp
src/manipulator_info.cpp
src/material.cpp
src/kinematic_limits.cpp
src/eigen_serialization.cpp
src/image.cpp
src/utils.cpp
src/resource_locator.cpp
src/shader_param.cpp
src/shader_params.cpp
src/shader_type.cpp
src/types.cpp)
target_link_libraries(
${PROJECT_NAME}
Expand All @@ -64,6 +71,7 @@ target_link_libraries(
Boost::filesystem
Boost::serialization
console_bridge::console_bridge
${FreeImage_LIBRARIES}
yaml-cpp)
target_compile_options(${PROJECT_NAME} PUBLIC ${TESSERACT_COMPILE_OPTIONS_PUBLIC})
target_compile_definitions(${PROJECT_NAME} PUBLIC ${TESSERACT_COMPILE_DEFINITIONS})
Expand All @@ -77,6 +85,8 @@ target_code_coverage(
ENABLE ${TESSERACT_ENABLE_CODE_COVERAGE})
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC
${FreeImage_INCLUDE_DIRS})

configure_package(NAMESPACE tesseract TARGETS ${PROJECT_NAME})

Expand All @@ -91,6 +101,8 @@ install(

install(
FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/tesseract_macros.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/FindFreeImage.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/FindPkgMacros.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/FindTinyXML2.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/Findtcmalloc.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/Findtcmalloc_minimal.cmake"
Expand Down
60 changes: 60 additions & 0 deletions tesseract_common/cmake/FindFreeImage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -------------------------------------------------------------------
# This file is part of the CMake build system for OGRE (Object-oriented Graphics Rendering Engine) For the latest info,
# see http://www.ogre3d.org/
#
# The contents of this file are placed in the public domain. Feel free to make use of it in any way you like.
# -------------------------------------------------------------------

# * Try to find FreeImage Once done, this will define
#
# FreeImage_FOUND - system has FreeImage FreeImage_INCLUDE_DIRS - the FreeImage include directories FreeImage_LIBRARIES
# - link these to use FreeImage

include(FindPkgMacros)
findpkg_begin(FreeImage)

# Get path, convert backslashes as ${ENV_${var}}
getenv_path(FREEIMAGE_HOME)

# construct search paths
set(FreeImage_PREFIX_PATH ${FREEIMAGE_HOME} ${ENV_FREEIMAGE_HOME})
create_search_paths(FreeImage "")
# redo search if prefix path changed
clear_if_changed(
FreeImage_PREFIX_PATH
FreeImage_LIBRARY_FWK
FreeImage_LIBRARY_REL
FreeImage_LIBRARY_DBG
FreeImage_INCLUDE_DIR)

set(FreeImage_LIBRARY_NAMES
freeimage
freeimageLib
FreeImage
FreeImageLib)
get_debug_names(FreeImage_LIBRARY_NAMES)

use_pkgconfig(FreeImage_PKGC freeimage)

findpkg_framework(FreeImage)

find_path(FreeImage_INCLUDE_DIR NAMES FreeImage.h HINTS ${FreeImage_INC_SEARCH_PATH} ${FreeImage_PKGC_INCLUDE_DIRS})

find_library(
FreeImage_LIBRARY_REL
NAMES ${FreeImage_LIBRARY_NAMES}
HINTS ${FreeImage_LIB_SEARCH_PATH} ${FreeImage_PKGC_LIBRARY_DIRS}
PATH_SUFFIXES
""
Release
RelWithDebInfo
MinSizeRel)
find_library(
FreeImage_LIBRARY_DBG
NAMES ${FreeImage_LIBRARY_NAMES_DBG}
HINTS ${FreeImage_LIB_SEARCH_PATH} ${FreeImage_PKGC_LIBRARY_DIRS}
PATH_SUFFIXES "" Debug)

make_library_set(FreeImage_LIBRARY)

findpkg_finish(FreeImage)
193 changes: 193 additions & 0 deletions tesseract_common/cmake/FindPkgMacros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# -------------------------------------------------------------------
# This file is part of the CMake build system for OGRE (Object-oriented Graphics Rendering Engine) For the latest info,
# see http://www.ogre3d.org/
#
# The contents of this file are placed in the public domain. Feel free to make use of it in any way you like.
# -------------------------------------------------------------------

# ######################################################################################################################
# Provides some common functionality for the FindPackage modules
# ######################################################################################################################

# Begin processing of package
macro(findpkg_begin PREFIX)
if(NOT ${PREFIX}_FIND_QUIETLY)
message(STATUS "Looking for ${PREFIX}...")
endif()
endmacro(findpkg_begin)

# Display a status message unless FIND_QUIETLY is set
macro(pkg_message PREFIX)
if(NOT ${PREFIX}_FIND_QUIETLY)
message(STATUS ${ARGN})
endif()
endmacro(pkg_message)

# Get environment variable, define it as ENV_$var and make sure backslashes are converted to forward slashes
macro(getenv_path VAR)
set(ENV_${VAR} $ENV{${VAR}})
# replace won't work if var is blank
if(ENV_${VAR})
string(
REGEX
REPLACE "\\\\"
"/"
ENV_${VAR}
${ENV_${VAR}})
endif()
endmacro(getenv_path)

# Construct search paths for includes and libraries from a PREFIX_PATH
macro(create_search_paths PREFIX PATH_SUFFIX)
foreach(dir ${${PREFIX}_PREFIX_PATH})
set(${PREFIX}_INC_SEARCH_PATH
${${PREFIX}_INC_SEARCH_PATH}
${dir}/include
${dir}/Include
${dir}/include/${PREFIX}${PATH_SUFFIX}
${dir}/Headers)
set(${PREFIX}_LIB_SEARCH_PATH
${${PREFIX}_LIB_SEARCH_PATH}
${dir}/lib
${dir}/Lib
${dir}/lib/${PREFIX}${PATH_SUFFIX}
${dir}/Libs)
set(${PREFIX}_BIN_SEARCH_PATH ${${PREFIX}_BIN_SEARCH_PATH} ${dir}/bin)
endforeach(dir)
if(ANDROID)
set(${PREFIX}_LIB_SEARCH_PATH ${${PREFIX}_LIB_SEARCH_PATH} ${OGRE_DEPENDENCIES_DIR}/lib/${ANDROID_ABI})
endif()
set(${PREFIX}_FRAMEWORK_SEARCH_PATH ${${PREFIX}_PREFIX_PATH})
endmacro(create_search_paths)

# clear cache variables if a certain variable changed
macro(clear_if_changed TESTVAR)
# test against internal check variable HACK: Apparently, adding a variable to the cache cleans up the list a bit. We
# need to also remove any empty strings from the list, but at the same time ensure that we are actually dealing with a
# list.
list(APPEND ${TESTVAR} "")
list(REMOVE_ITEM ${TESTVAR} "")
if(NOT
"${${TESTVAR}}"
STREQUAL
"${${TESTVAR}_INT_CHECK}")
message(STATUS "${TESTVAR} changed.")
foreach(var ${ARGN})
set(${var} "NOTFOUND" CACHE STRING "x" FORCE)
endforeach(var)
endif()
set(${TESTVAR}_INT_CHECK ${${TESTVAR}} CACHE INTERNAL "x" FORCE)
endmacro(clear_if_changed)

# Try to get some hints from pkg-config, if available
macro(use_pkgconfig PREFIX PKGNAME)
if(NOT ANDROID)
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(${PREFIX} ${PKGNAME})
endif()
endif()
endmacro(use_pkgconfig)

# Couple a set of release AND debug libraries (or frameworks)
macro(make_library_set PREFIX)
if(${PREFIX}_FWK)
set(${PREFIX} ${${PREFIX}_FWK})
elseif(${PREFIX}_REL AND ${PREFIX}_DBG)
set(${PREFIX}
optimized
${${PREFIX}_REL}
debug
${${PREFIX}_DBG})
elseif(${PREFIX}_REL)
set(${PREFIX} ${${PREFIX}_REL})
elseif(${PREFIX}_DBG)
set(${PREFIX} ${${PREFIX}_DBG})
endif()
endmacro(make_library_set)

# Generate debug names from given release names
macro(get_debug_names PREFIX)
foreach(i ${${PREFIX}})
set(${PREFIX}_DBG
${${PREFIX}_DBG}
${i}d
${i}D
${i}_d
${i}_D
${i}_debug
${i})
endforeach(i)
endmacro(get_debug_names)

# Add the parent dir from DIR to VAR
macro(add_parent_dir VAR DIR)
get_filename_component(${DIR}_TEMP "${${DIR}}/.." ABSOLUTE)
set(${VAR} ${${VAR}} ${${DIR}_TEMP})
endmacro(add_parent_dir)

# Do the final processing for the package find.
macro(findpkg_finish PREFIX)
# skip if already processed during this run
if(NOT ${PREFIX}_FOUND)
if(${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
set(${PREFIX}_FOUND TRUE)
set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
if(NOT ${PREFIX}_FIND_QUIETLY)
message(STATUS "Found ${PREFIX}: ${${PREFIX}_LIBRARIES}")
endif()
else()
if(NOT ${PREFIX}_FIND_QUIETLY)
message(STATUS "Could not locate ${PREFIX}")
endif()
if(${PREFIX}_FIND_REQUIRED)
message(
FATAL_ERROR
"Required library ${PREFIX} not found! Install the library (including dev packages) and try again. If the library is already installed, set the missing variables manually in cmake."
)
endif()
endif()

mark_as_advanced(
${PREFIX}_INCLUDE_DIR
${PREFIX}_LIBRARY
${PREFIX}_LIBRARY_REL
${PREFIX}_LIBRARY_DBG
${PREFIX}_LIBRARY_FWK)
endif()
endmacro(findpkg_finish)

# Slightly customised framework finder
macro(findpkg_framework fwk)
if(APPLE)
set(${fwk}_FRAMEWORK_PATH
${${fwk}_FRAMEWORK_SEARCH_PATH}
${CMAKE_FRAMEWORK_PATH}
~/Library/Frameworks
/Library/Frameworks
/System/Library/Frameworks
/Network/Library/Frameworks
${CMAKE_CURRENT_SOURCE_DIR}/lib/macosx/Release
${CMAKE_CURRENT_SOURCE_DIR}/lib/macosx/Debug)
# These could be arrays of paths, add each individually to the search paths
foreach(i ${OGRE_PREFIX_PATH})
set(${fwk}_FRAMEWORK_PATH ${${fwk}_FRAMEWORK_PATH} ${i}/lib/macosx/Release ${i}/lib/macosx/Debug)
endforeach(i)

foreach(i ${OGRE_PREFIX_BUILD})
set(${fwk}_FRAMEWORK_PATH ${${fwk}_FRAMEWORK_PATH} ${i}/lib/macosx/Release ${i}/lib/macosx/Debug)
endforeach(i)

foreach(dir ${${fwk}_FRAMEWORK_PATH})
set(fwkpath ${dir}/${fwk}.framework)
if(EXISTS ${fwkpath})
set(${fwk}_FRAMEWORK_INCLUDES ${${fwk}_FRAMEWORK_INCLUDES} ${fwkpath}/Headers ${fwkpath}/PrivateHeaders)
set(${fwk}_FRAMEWORK_PATH ${dir})
if(NOT ${fwk}_LIBRARY_FWK)
set(${fwk}_LIBRARY_FWK "-framework ${fwk}")
endif()
endif(EXISTS ${fwkpath})
endforeach(dir)
endif(APPLE)
endmacro(findpkg_framework)
Loading

0 comments on commit 235ecf8

Please sign in to comment.