Merge branch 'python' of ssh://git.normalized.xyz:2222/Florent/Triskele into python
This commit is contained in:
commit
28263b7ceb
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,6 @@
|
|||||||
[Bb]uild
|
[Bb]uild
|
||||||
__pycache__
|
__pycache__
|
||||||
|
data/result.tif
|
||||||
|
tmp
|
||||||
|
result
|
||||||
|
*.egg-info/
|
||||||
|
@ -1,32 +1,59 @@
|
|||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
project(libtriskele VERSION 1.0.0 LANGUAGES C CXX)
|
||||||
|
|
||||||
project(TreeBuilder)
|
# Add custom modules like FindTBB.cmake
|
||||||
|
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
|
||||||
|
|
||||||
set(OUT_NAME "TreeBuilder")
|
##############################################
|
||||||
|
# Find dependencies
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -Wall -g") #-Wshadow")
|
find_package(Boost REQUIRED system chrono thread program_options date_time serialization filesystem unit_test_framework)
|
||||||
|
find_package(GDAL REQUIRED)
|
||||||
|
find_package(TBB REQUIRED)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
find_package(TinyXML)
|
||||||
|
|
||||||
set(TREEBUILDER_INCLUDES include)
|
##############################################
|
||||||
|
# Create triskele and set properties
|
||||||
|
|
||||||
file(GLOB_RECURSE TREEBUILDER_SOURCES src/*.cpp)
|
list(APPEND TRISKELE_SRC
|
||||||
|
"src/ArrayTree/triskeleArrayTreeBase.cpp"
|
||||||
|
"src/QuadTree/QuadTreeBuilder.cpp"
|
||||||
|
"src/IImage.cpp"
|
||||||
|
"src/Tree.cpp"
|
||||||
|
"src/triskeleBase.cpp"
|
||||||
|
"src/triskeleDebug.cpp")
|
||||||
|
|
||||||
find_package(OTB)
|
if (TinyXML_FOUND)
|
||||||
|
list(APPEND TRISKELE_SRC "src/XMLTree/XMLTreeBuilder.cpp")
|
||||||
|
message(STATUS "TinyXML found, XMLTreeBuilder will be compiled")
|
||||||
|
else()
|
||||||
|
message(WARNING "TinyXML not found, XMLTreeBuilder won't be compiled")
|
||||||
|
endif(TinyXML_FOUND)
|
||||||
|
|
||||||
find_package(OpenCV REQUIRED) # Petra
|
add_library(triskele
|
||||||
|
${TRISKELE_SRC})
|
||||||
|
|
||||||
if(OTB_FOUND)
|
target_include_directories(triskele
|
||||||
include(${OTB_USE_FILE})
|
PUBLIC
|
||||||
else(OTB_FOUND)
|
$<INSTALL_INTERFACE:include>
|
||||||
message(FATAL_ERROR
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
"Cannot build OTB project without OTB. Please set OTB_DIR.")
|
${GDAL_INCLUDE_DIR})
|
||||||
endif(OTB_FOUND)
|
|
||||||
|
|
||||||
include_directories(${OTB_INCLUDES})
|
target_link_libraries(triskele ${BOOST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${GDAL_LIBRARY} ${TBB_LIBRARIES})
|
||||||
include_directories(${TREEBUILDER_INCLUDES})
|
# ${TinyXML_LIBRARY})
|
||||||
|
|
||||||
set(TREEBUILDER_LIBS tinyxml opencv_ml opencv_core pthread boost_system boost_chrono boost_thread boost_program_options boost_date_time boost_serialization boost_filesystem boost_unit_test_framework gdal)
|
target_compile_definitions(triskele PUBLIC -DNDEBUG -DNO_OTB -DINTEL_TBB_THREAD) # -DBOOST_DISABLE_ASSERTS)
|
||||||
|
|
||||||
# Ajout de l'exec / lib
|
# Add Warnings for Unix and Windows, Optimization, MMD and debug for Unix
|
||||||
add_executable(${OUT_NAME} ${TREEBUILDER_SOURCES})
|
if(MSVC)
|
||||||
|
# Force to always compile with W4
|
||||||
target_link_libraries(${OUT_NAME} ${TREEBUILDER_LIBS} ${OpenCV_LIBS} ${OTB_LIBRARIES})
|
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||||
|
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||||
|
endif()
|
||||||
|
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
# Update if necessary
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall -MMD -pthread -g")
|
||||||
|
endif()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
## DIR #################################
|
## DIR #################################
|
||||||
SRC_DIR = .
|
SRC_DIR = .
|
||||||
|
TST_DIR = $(SRC_DIR)/test
|
||||||
CPP_DIR = $(SRC_DIR)/src
|
CPP_DIR = $(SRC_DIR)/src
|
||||||
HPP_DIR = $(SRC_DIR)/include
|
HPP_DIR = $(SRC_DIR)/include
|
||||||
BLD_DIR = build
|
BLD_DIR = build
|
||||||
@ -8,6 +9,11 @@ LIB_DIR = $(BLD_DIR)/lib
|
|||||||
OBJ_DIR = $(BLD_DIR)/obj
|
OBJ_DIR = $(BLD_DIR)/obj
|
||||||
|
|
||||||
## PRG #################################
|
## PRG #################################
|
||||||
|
|
||||||
|
TRSK_MOD = IImage triskeleArrayTreeBase Tree triskeleDebug TreeStats triskeleBase QuadTreeBuilder Option Selected
|
||||||
|
TRSK_OBJ = $(patsubst %, $(OBJ_DIR)/%.o, $(TRSK_MOD))
|
||||||
|
TRSK_OBJ_XML = $(TRSK_OBJ) $(OBJ_DIR)/XMLTreeBuilder.o
|
||||||
|
|
||||||
APG_PRG = apGenerator
|
APG_PRG = apGenerator
|
||||||
APG_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(APG_PRG))
|
APG_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(APG_PRG))
|
||||||
APG_OUT = $(patsubst %, $(OUT_DIR)/%, $(APG_PRG))
|
APG_OUT = $(patsubst %, $(OUT_DIR)/%, $(APG_PRG))
|
||||||
@ -20,64 +26,83 @@ PRF_PRG = PerfArrayTreeBuilder
|
|||||||
PRF_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(PRF_PRG))
|
PRF_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(PRF_PRG))
|
||||||
PRF_OUT = $(patsubst %, $(OUT_DIR)/%, $(PRF_PRG))
|
PRF_OUT = $(patsubst %, $(OUT_DIR)/%, $(PRF_PRG))
|
||||||
|
|
||||||
|
TTH_MOD = TestDeal
|
||||||
|
TTH_PRG = TestThread
|
||||||
|
TTH_SRC = $(patsubst %, $(TST_DIR)/%.cpp, $(TTH_PRG))
|
||||||
|
TTH_OBJ = $(patsubst %, $(OBJ_DIR)/%.o, $(TTH_MOD))
|
||||||
|
TTH_OUT = $(patsubst %, $(OUT_DIR)/%, $(TTH_PRG))
|
||||||
|
|
||||||
## FLAGS ###############################
|
## FLAGS ###############################
|
||||||
DFLAGS = -O2 -DNDEBUG -DNO_OTB -DINTEL_TBB_THREAD # -DBOOST_DISABLE_ASSERTS
|
# fast and no control
|
||||||
#DFLAGS = -g -DENABLE_LOG -DNO_OTB # -DTHREAD_DISABLE -DENABLE_SMART_LOG
|
#DFLAGS = -O2 -DNDEBUG -DNO_OTB -DINTEL_TBB_THREAD -DBOOST_DISABLE_ASSERTS
|
||||||
|
DFLAGS = -O2 -DNDEBUG -DNO_OTB -DBOOST_DISABLE_ASSERTS
|
||||||
|
# fast but control
|
||||||
|
#DFLAGS = -O2 -DNDEBUG -DNO_OTB -DINTEL_TBB_THREAD
|
||||||
|
# debug multi-threaded
|
||||||
|
#DFLAGS = -g -DENABLE_LOG -DNO_OTB
|
||||||
|
# debug one thread
|
||||||
|
#DFLAGS = -g -DENABLE_LOG -DNO_OTB -DTHREAD_DISABLE -DENABLE_SMART_LOG
|
||||||
|
|
||||||
IFLAGS = $(DFLAGS) -MMD -I$(HPP_DIR) -I/usr/include/gdal
|
IFLAGS = $(DFLAGS) -MMD -I$(HPP_DIR) -I/usr/include/gdal
|
||||||
LFLAGS = -L$(LIB_DIR) -ltriskele -lstdc++ -lpthread -lboost_system -lboost_chrono -lboost_thread -lboost_program_options -lboost_date_time -lboost_serialization -lboost_filesystem -lboost_unit_test_framework -lgdal -ltbb
|
LFLAGS = -L$(LIB_DIR) -ltriskele -lstdc++ -lpthread -lboost_system -lboost_chrono -lboost_thread -lboost_program_options -lboost_date_time -lboost_serialization -lboost_filesystem -lboost_unit_test_framework -lgdal -ltbb
|
||||||
CC = g++
|
CC = g++
|
||||||
|
|
||||||
## RULES ###############################
|
## RULES ###############################
|
||||||
$(OBJ_DIR)/%.o: $(CPP_DIR)/%.cpp
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/*/%.cpp
|
||||||
$(CC) $< $(IFLAGS) -cpp -c -o $@
|
$(CC) $< $(IFLAGS) -cpp -c -o $@
|
||||||
$(OBJ_DIR)/%.o: $(CPP_DIR)/*/%.cpp
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/*/*/%.cpp
|
||||||
$(CC) $< $(IFLAGS) -cpp -c -o $@
|
$(CC) $< $(IFLAGS) -cpp -c -o $@
|
||||||
|
|
||||||
$(OUT_DIR)/%: $(CPP_DIR)/%.cpp
|
$(OUT_DIR)/%: $(SRC_DIR)/*/%.cpp
|
||||||
$(CC) $(IFLAGS) $< -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
|
|
||||||
$(OUT_DIR)/%: $(CPP_DIR)/*/%.cpp
|
|
||||||
$(CC) $(IFLAGS) $< -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
|
$(CC) $(IFLAGS) $< -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
|
||||||
|
|
||||||
## ENTRIES #############################
|
## ENTRIES #############################
|
||||||
all: init libtriskele apGenerator test pref
|
all: init libtriskele apGenerator test perf
|
||||||
|
|
||||||
testA: all
|
test: testA testB testThread
|
||||||
|
|
||||||
|
testThread: init $(TTH_OUT)
|
||||||
|
$(TTH_OUT)
|
||||||
|
|
||||||
|
testA: init $(TST_OUT)
|
||||||
$(TST_OUT)
|
$(TST_OUT)
|
||||||
|
|
||||||
testB: all
|
testB: init $(APG_OUT)
|
||||||
$(APG_OUT) data/10m.tif data/result.tif --min-tree --max-tree --tos-tree --alpha-tree -A data/areaThresholds.txt -S data/sdThresholds.txt -M data/moiThresholds.txt # --debug
|
$(APG_OUT) data/10m.tif data/result.tif --min-tree --max-tree --tos-tree --alpha-tree -A data/areaThresholds.txt -S data/sdThresholds.txt -M data/moiThresholds.txt # --debug
|
||||||
|
|
||||||
perfA: all
|
perf: perfA
|
||||||
$(PRF_OUT) MIN 4 20 1000000
|
|
||||||
|
perfA: init $(PRF_OUT)
|
||||||
|
$(PRF_OUT) MIN 32 20 1000000
|
||||||
|
|
||||||
init:
|
init:
|
||||||
mkdir -p $(OUT_DIR) $(OBJ_DIR) $(LIB_DIR)
|
mkdir -p $(OUT_DIR) $(OBJ_DIR) $(LIB_DIR)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
find . -type f '(' -name '#*' -o -name '*~' ')' -print -exec rm -f '{}' \;
|
find . -type f '(' -name '#*' -o -name '*~' ')' -print -exec rm -f '{}' \;
|
||||||
|
|
||||||
wipe: clean
|
wipe: clean
|
||||||
rm -rf $(OBJ_DIR)
|
rm -rf $(OBJ_DIR)
|
||||||
rm -f $(APG_OUT) $(TST_OUT) $(LIB_DIR)/libtriskele.a
|
rm -f $(APG_OUT) $(TST_OUT) $(PRF_OUT) $(LIB_DIR)/libtriskele.a
|
||||||
rm -f $(OUT_DIR)/*.d
|
rm -f $(OUT_DIR)/*.d
|
||||||
|
-rmdir $(OUT_DIR) $(OBJ_DIR) $(LIB_DIR) $(BLD_DIR)
|
||||||
|
|
||||||
libtriskele: $(LIB_DIR)/libtriskele.a
|
libtriskele: $(LIB_DIR)/libtriskele.a
|
||||||
|
|
||||||
$(APG_OUT): $(APG_SRC) $(LIB_DIR)/libtriskele.a
|
$(APG_OUT): $(APG_SRC) $(LIB_DIR)/libtriskele.a
|
||||||
$(TST_OUT): $(TST_SRC) $(LIB_DIR)/libtriskele.a
|
$(TST_OUT): $(TST_SRC) $(LIB_DIR)/libtriskele.a
|
||||||
$(PRF_OUT): $(PRF_SRC) $(LIB_DIR)/libtriskele.a
|
$(PRF_OUT): $(PRF_SRC) $(LIB_DIR)/libtriskele.a
|
||||||
|
$(TTH_OUT): $(TTH_SRC) $(TTH_OBJ) $(LIB_DIR)/libtriskele.a
|
||||||
|
$(CC) $(IFLAGS) $< $(TTH_OBJ) -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
|
||||||
|
|
||||||
apGenerator: $(APG_OUT)
|
apGenerator: init $(APG_OUT)
|
||||||
test: init $(TST_OUT)
|
|
||||||
pref: init $(PRF_OUT)
|
|
||||||
|
|
||||||
|
|
||||||
## DEPENDS #############################
|
## DEPENDS #############################
|
||||||
ALL_OUT = $(APG_OUT)
|
ALL_OUT = $(APG_OUT)
|
||||||
ALL_OBJ = $(OBJ_DIR)/IImage.o $(OBJ_DIR)/triskeleArrayTreeBase.o $(OBJ_DIR)/Tree.o $(OBJ_DIR)/triskeleDebug.o $(OBJ_DIR)/TreeStats.o $(OBJ_DIR)/triskeleBase.o $(OBJ_DIR)/QuadTreeBuilder.o $(OBJ_DIR)/Option.o $(OBJ_DIR)/Selected.o
|
ALL_OBJ = $(TRSK_OBJ)
|
||||||
|
|
||||||
ALL_OBJ_XML = $(OBJ_DIR)/IImage.o $(OBJ_DIR)/triskeleArrayTreeBase.o $(OBJ_DIR)/Tree.o $(OBJ_DIR)/triskeleDebug.o $(OBJ_DIR)/TreeStats.o $(OBJ_DIR)/triskeleBase.o $(OBJ_DIR)/QuadTreeBuilder.o $(OBJ_DIR)/XMLTreeBuilder.o $(OBJ_DIR)/Option.o $(OBJ_DIR)/Selected.o
|
DEPENDS = ${ALL_OUT:=.d} ${ALL_OBJ:.o=.d} ${TTH_OBJ:.o=.d}
|
||||||
|
|
||||||
DEPENDS = ${ALL_OUT:=.d} ${ALL_OBJ:.o=.d}
|
|
||||||
-include ${DEPENDS}
|
-include ${DEPENDS}
|
||||||
|
|
||||||
$(LIB_DIR)/libtriskele.a: $(ALL_OBJ)
|
$(LIB_DIR)/libtriskele.a: $(ALL_OBJ)
|
||||||
|
303
cmake/FindTBB.cmake
Normal file
303
cmake/FindTBB.cmake
Normal file
@ -0,0 +1,303 @@
|
|||||||
|
# The MIT License (MIT)
|
||||||
|
#
|
||||||
|
# Copyright (c) 2015 Justus Calvin
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in all
|
||||||
|
# copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
# SOFTWARE.
|
||||||
|
|
||||||
|
#
|
||||||
|
# FindTBB
|
||||||
|
# -------
|
||||||
|
#
|
||||||
|
# Find TBB include directories and libraries.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
#
|
||||||
|
# find_package(TBB [major[.minor]] [EXACT]
|
||||||
|
# [QUIET] [REQUIRED]
|
||||||
|
# [[COMPONENTS] [components...]]
|
||||||
|
# [OPTIONAL_COMPONENTS components...])
|
||||||
|
#
|
||||||
|
# where the allowed components are tbbmalloc and tbb_preview. Users may modify
|
||||||
|
# the behavior of this module with the following variables:
|
||||||
|
#
|
||||||
|
# * TBB_ROOT_DIR - The base directory the of TBB installation.
|
||||||
|
# * TBB_INCLUDE_DIR - The directory that contains the TBB headers files.
|
||||||
|
# * TBB_LIBRARY - The directory that contains the TBB library files.
|
||||||
|
# * TBB_<library>_LIBRARY - The path of the TBB the corresponding TBB library.
|
||||||
|
# These libraries, if specified, override the
|
||||||
|
# corresponding library search results, where <library>
|
||||||
|
# may be tbb, tbb_debug, tbbmalloc, tbbmalloc_debug,
|
||||||
|
# tbb_preview, or tbb_preview_debug.
|
||||||
|
# * TBB_USE_DEBUG_BUILD - The debug version of tbb libraries, if present, will
|
||||||
|
# be used instead of the release version.
|
||||||
|
#
|
||||||
|
# Users may modify the behavior of this module with the following environment
|
||||||
|
# variables:
|
||||||
|
#
|
||||||
|
# * TBB_INSTALL_DIR
|
||||||
|
# * TBBROOT
|
||||||
|
# * LIBRARY_PATH
|
||||||
|
#
|
||||||
|
# This module will set the following variables:
|
||||||
|
#
|
||||||
|
# * TBB_FOUND - Set to false, or undefined, if we haven’t found, or
|
||||||
|
# don’t want to use TBB.
|
||||||
|
# * TBB_<component>_FOUND - If False, optional <component> part of TBB sytem is
|
||||||
|
# not available.
|
||||||
|
# * TBB_VERSION - The full version string
|
||||||
|
# * TBB_VERSION_MAJOR - The major version
|
||||||
|
# * TBB_VERSION_MINOR - The minor version
|
||||||
|
# * TBB_INTERFACE_VERSION - The interface version number defined in
|
||||||
|
# tbb/tbb_stddef.h.
|
||||||
|
# * TBB_<library>_LIBRARY_RELEASE - The path of the TBB release version of
|
||||||
|
# <library>, where <library> may be tbb, tbb_debug,
|
||||||
|
# tbbmalloc, tbbmalloc_debug, tbb_preview, or
|
||||||
|
# tbb_preview_debug.
|
||||||
|
# * TBB_<library>_LIBRARY_DEGUG - The path of the TBB release version of
|
||||||
|
# <library>, where <library> may be tbb, tbb_debug,
|
||||||
|
# tbbmalloc, tbbmalloc_debug, tbb_preview, or
|
||||||
|
# tbb_preview_debug.
|
||||||
|
#
|
||||||
|
# The following varibles should be used to build and link with TBB:
|
||||||
|
#
|
||||||
|
# * TBB_INCLUDE_DIRS - The include directory for TBB.
|
||||||
|
# * TBB_LIBRARIES - The libraries to link against to use TBB.
|
||||||
|
# * TBB_LIBRARIES_RELEASE - The release libraries to link against to use TBB.
|
||||||
|
# * TBB_LIBRARIES_DEBUG - The debug libraries to link against to use TBB.
|
||||||
|
# * TBB_DEFINITIONS - Definitions to use when compiling code that uses
|
||||||
|
# TBB.
|
||||||
|
# * TBB_DEFINITIONS_RELEASE - Definitions to use when compiling release code that
|
||||||
|
# uses TBB.
|
||||||
|
# * TBB_DEFINITIONS_DEBUG - Definitions to use when compiling debug code that
|
||||||
|
# uses TBB.
|
||||||
|
#
|
||||||
|
# This module will also create the "tbb" target that may be used when building
|
||||||
|
# executables and libraries.
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
if(NOT TBB_FOUND)
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Check the build type
|
||||||
|
##################################
|
||||||
|
|
||||||
|
if(NOT DEFINED TBB_USE_DEBUG_BUILD)
|
||||||
|
if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug|RelWithDebInfo|RELWITHDEBINFO|relwithdebinfo)")
|
||||||
|
set(TBB_BUILD_TYPE DEBUG)
|
||||||
|
else()
|
||||||
|
set(TBB_BUILD_TYPE RELEASE)
|
||||||
|
endif()
|
||||||
|
elseif(TBB_USE_DEBUG_BUILD)
|
||||||
|
set(TBB_BUILD_TYPE DEBUG)
|
||||||
|
else()
|
||||||
|
set(TBB_BUILD_TYPE RELEASE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Set the TBB search directories
|
||||||
|
##################################
|
||||||
|
|
||||||
|
# Define search paths based on user input and environment variables
|
||||||
|
set(TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBBROOT})
|
||||||
|
|
||||||
|
# Define the search directories based on the current platform
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
set(TBB_DEFAULT_SEARCH_DIR "C:/Program Files/Intel/TBB"
|
||||||
|
"C:/Program Files (x86)/Intel/TBB")
|
||||||
|
|
||||||
|
# Set the target architecture
|
||||||
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
|
set(TBB_ARCHITECTURE "intel64")
|
||||||
|
else()
|
||||||
|
set(TBB_ARCHITECTURE "ia32")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Set the TBB search library path search suffix based on the version of VC
|
||||||
|
if(WINDOWS_STORE)
|
||||||
|
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11_ui")
|
||||||
|
elseif(MSVC14)
|
||||||
|
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc14")
|
||||||
|
elseif(MSVC12)
|
||||||
|
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc12")
|
||||||
|
elseif(MSVC11)
|
||||||
|
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc11")
|
||||||
|
elseif(MSVC10)
|
||||||
|
set(TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc10")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add the library path search suffix for the VC independent version of TBB
|
||||||
|
list(APPEND TBB_LIB_PATH_SUFFIX "lib/${TBB_ARCHITECTURE}/vc_mt")
|
||||||
|
|
||||||
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||||
|
# OS X
|
||||||
|
set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
|
||||||
|
|
||||||
|
# TODO: Check to see which C++ library is being used by the compiler.
|
||||||
|
if(NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0)
|
||||||
|
# The default C++ library on OS X 10.9 and later is libc++
|
||||||
|
set(TBB_LIB_PATH_SUFFIX "lib/libc++" "lib")
|
||||||
|
else()
|
||||||
|
set(TBB_LIB_PATH_SUFFIX "lib")
|
||||||
|
endif()
|
||||||
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
|
# Linux
|
||||||
|
set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb")
|
||||||
|
|
||||||
|
# TODO: Check compiler version to see the suffix should be <arch>/gcc4.1 or
|
||||||
|
# <arch>/gcc4.1. For now, assume that the compiler is more recent than
|
||||||
|
# gcc 4.4.x or later.
|
||||||
|
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
|
||||||
|
set(TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4")
|
||||||
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
|
||||||
|
set(TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Find the TBB include dir
|
||||||
|
##################################
|
||||||
|
|
||||||
|
find_path(TBB_INCLUDE_DIRS tbb/tbb.h
|
||||||
|
HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR}
|
||||||
|
PATHS ${TBB_DEFAULT_SEARCH_DIR}
|
||||||
|
PATH_SUFFIXES include)
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Set version strings
|
||||||
|
##################################
|
||||||
|
|
||||||
|
if(TBB_INCLUDE_DIRS)
|
||||||
|
file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file)
|
||||||
|
string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1"
|
||||||
|
TBB_VERSION_MAJOR "${_tbb_version_file}")
|
||||||
|
string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1"
|
||||||
|
TBB_VERSION_MINOR "${_tbb_version_file}")
|
||||||
|
string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1"
|
||||||
|
TBB_INTERFACE_VERSION "${_tbb_version_file}")
|
||||||
|
set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Find TBB components
|
||||||
|
##################################
|
||||||
|
|
||||||
|
if(TBB_VERSION VERSION_LESS 4.3)
|
||||||
|
set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc tbb)
|
||||||
|
else()
|
||||||
|
set(TBB_SEARCH_COMPOMPONENTS tbb_preview tbbmalloc_proxy tbbmalloc tbb)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Find each component
|
||||||
|
foreach(_comp ${TBB_SEARCH_COMPOMPONENTS})
|
||||||
|
if(";${TBB_FIND_COMPONENTS};tbb;" MATCHES ";${_comp};")
|
||||||
|
|
||||||
|
# Search for the libraries
|
||||||
|
find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp}
|
||||||
|
HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
|
||||||
|
PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
|
||||||
|
PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX})
|
||||||
|
|
||||||
|
find_library(TBB_${_comp}_LIBRARY_DEBUG ${_comp}_debug
|
||||||
|
HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR}
|
||||||
|
PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH
|
||||||
|
PATH_SUFFIXES ${TBB_LIB_PATH_SUFFIX})
|
||||||
|
|
||||||
|
if(TBB_${_comp}_LIBRARY_DEBUG)
|
||||||
|
list(APPEND TBB_LIBRARIES_DEBUG "${TBB_${_comp}_LIBRARY_DEBUG}")
|
||||||
|
endif()
|
||||||
|
if(TBB_${_comp}_LIBRARY_RELEASE)
|
||||||
|
list(APPEND TBB_LIBRARIES_RELEASE "${TBB_${_comp}_LIBRARY_RELEASE}")
|
||||||
|
endif()
|
||||||
|
if(TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE} AND NOT TBB_${_comp}_LIBRARY)
|
||||||
|
set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_${TBB_BUILD_TYPE}}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TBB_${_comp}_LIBRARY AND EXISTS "${TBB_${_comp}_LIBRARY}")
|
||||||
|
set(TBB_${_comp}_FOUND TRUE)
|
||||||
|
else()
|
||||||
|
set(TBB_${_comp}_FOUND FALSE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Mark internal variables as advanced
|
||||||
|
mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE)
|
||||||
|
mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG)
|
||||||
|
mark_as_advanced(TBB_${_comp}_LIBRARY)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Set compile flags and libraries
|
||||||
|
##################################
|
||||||
|
|
||||||
|
set(TBB_DEFINITIONS_RELEASE "")
|
||||||
|
set(TBB_DEFINITIONS_DEBUG "-DTBB_USE_DEBUG=1")
|
||||||
|
|
||||||
|
if(TBB_LIBRARIES_${TBB_BUILD_TYPE})
|
||||||
|
set(TBB_DEFINITIONS "${TBB_DEFINITIONS_${TBB_BUILD_TYPE}}")
|
||||||
|
set(TBB_LIBRARIES "${TBB_LIBRARIES_${TBB_BUILD_TYPE}}")
|
||||||
|
elseif(TBB_LIBRARIES_RELEASE)
|
||||||
|
set(TBB_DEFINITIONS "${TBB_DEFINITIONS_RELEASE}")
|
||||||
|
set(TBB_LIBRARIES "${TBB_LIBRARIES_RELEASE}")
|
||||||
|
elseif(TBB_LIBRARIES_DEBUG)
|
||||||
|
set(TBB_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}")
|
||||||
|
set(TBB_LIBRARIES "${TBB_LIBRARIES_DEBUG}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package_handle_standard_args(TBB
|
||||||
|
REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES
|
||||||
|
HANDLE_COMPONENTS
|
||||||
|
VERSION_VAR TBB_VERSION)
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Create targets
|
||||||
|
##################################
|
||||||
|
|
||||||
|
if(NOT CMAKE_VERSION VERSION_LESS 3.0 AND TBB_FOUND)
|
||||||
|
add_library(tbb SHARED IMPORTED)
|
||||||
|
set_target_properties(tbb PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS}
|
||||||
|
IMPORTED_LOCATION ${TBB_LIBRARIES})
|
||||||
|
if(TBB_LIBRARIES_RELEASE AND TBB_LIBRARIES_DEBUG)
|
||||||
|
set_target_properties(tbb PROPERTIES
|
||||||
|
INTERFACE_COMPILE_DEFINITIONS "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:TBB_USE_DEBUG=1>"
|
||||||
|
IMPORTED_LOCATION_DEBUG ${TBB_LIBRARIES_DEBUG}
|
||||||
|
IMPORTED_LOCATION_RELWITHDEBINFO ${TBB_LIBRARIES_DEBUG}
|
||||||
|
IMPORTED_LOCATION_RELEASE ${TBB_LIBRARIES_RELEASE}
|
||||||
|
IMPORTED_LOCATION_MINSIZEREL ${TBB_LIBRARIES_RELEASE}
|
||||||
|
)
|
||||||
|
elseif(TBB_LIBRARIES_RELEASE)
|
||||||
|
set_target_properties(tbb PROPERTIES IMPORTED_LOCATION ${TBB_LIBRARIES_RELEASE})
|
||||||
|
else()
|
||||||
|
set_target_properties(tbb PROPERTIES
|
||||||
|
INTERFACE_COMPILE_DEFINITIONS "${TBB_DEFINITIONS_DEBUG}"
|
||||||
|
IMPORTED_LOCATION ${TBB_LIBRARIES_DEBUG}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES)
|
||||||
|
|
||||||
|
unset(TBB_ARCHITECTURE)
|
||||||
|
unset(TBB_BUILD_TYPE)
|
||||||
|
unset(TBB_LIB_PATH_SUFFIX)
|
||||||
|
unset(TBB_DEFAULT_SEARCH_DIR)
|
||||||
|
|
||||||
|
endif()
|
74
cmake/FindTinyXML.cmake
Normal file
74
cmake/FindTinyXML.cmake
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
##################################################################################################
|
||||||
|
#
|
||||||
|
# CMake script for finding TinyXML.
|
||||||
|
#
|
||||||
|
# Input variables:
|
||||||
|
#
|
||||||
|
# - TinyXML_ROOT_DIR (optional): When specified, header files and libraries will be searched for in
|
||||||
|
# ${TinyXML_ROOT_DIR}/include
|
||||||
|
# ${TinyXML_ROOT_DIR}/libs
|
||||||
|
# respectively, and the default CMake search order will be ignored. When unspecified, the default
|
||||||
|
# CMake search order is used.
|
||||||
|
# This variable can be specified either as a CMake or environment variable. If both are set,
|
||||||
|
# preference is given to the CMake variable.
|
||||||
|
# Use this variable for finding packages installed in a nonstandard location, or for enforcing
|
||||||
|
# that one of multiple package installations is picked up.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Cache variables (not intended to be used in CMakeLists.txt files)
|
||||||
|
#
|
||||||
|
# - TinyXML_INCLUDE_DIR: Absolute path to package headers.
|
||||||
|
# - TinyXML_LIBRARY: Absolute path to library.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Output variables:
|
||||||
|
#
|
||||||
|
# - TinyXML_FOUND: Boolean that indicates if the package was found
|
||||||
|
# - TinyXML_INCLUDE_DIRS: Paths to the necessary header files
|
||||||
|
# - TinyXML_LIBRARIES: Package libraries
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Example usage:
|
||||||
|
#
|
||||||
|
# find_package(TinyXML)
|
||||||
|
# if(NOT TinyXML_FOUND)
|
||||||
|
# # Error handling
|
||||||
|
# endif()
|
||||||
|
# ...
|
||||||
|
# include_directories(${TinyXML_INCLUDE_DIRS} ...)
|
||||||
|
# ...
|
||||||
|
# target_link_libraries(my_target ${TinyXML_LIBRARIES})
|
||||||
|
#
|
||||||
|
##################################################################################################
|
||||||
|
|
||||||
|
# Get package location hint from environment variable (if any)
|
||||||
|
if(NOT TinyXML_ROOT_DIR AND DEFINED ENV{TinyXML_ROOT_DIR})
|
||||||
|
set(TinyXML_ROOT_DIR "$ENV{TinyXML_ROOT_DIR}" CACHE PATH
|
||||||
|
"TinyXML base directory location (optional, used for nonstandard installation paths)")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Search path for nonstandard package locations
|
||||||
|
if(TinyXML_ROOT_DIR)
|
||||||
|
set(TinyXML_INCLUDE_PATH PATHS "${TinyXML_ROOT_DIR}/include" NO_DEFAULT_PATH)
|
||||||
|
set(TinyXML_LIBRARY_PATH PATHS "${TinyXML_ROOT_DIR}/lib" NO_DEFAULT_PATH)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Find headers and libraries
|
||||||
|
find_path(TinyXML_INCLUDE_DIR NAMES tinyxml.h PATH_SUFFIXES "tinyxml" ${TinyXML_INCLUDE_PATH})
|
||||||
|
find_library(TinyXML_LIBRARY NAMES tinyxml PATH_SUFFIXES "tinyxml" ${TinyXML_LIBRARY_PATH})
|
||||||
|
|
||||||
|
mark_as_advanced(TinyXML_INCLUDE_DIR
|
||||||
|
TinyXML_LIBRARY)
|
||||||
|
|
||||||
|
# Output variables generation
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(TinyXML DEFAULT_MSG TinyXML_LIBRARY
|
||||||
|
TinyXML_INCLUDE_DIR)
|
||||||
|
|
||||||
|
set(TinyXML_FOUND ${TINYXML_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
|
||||||
|
unset(TINYXML_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args
|
||||||
|
|
||||||
|
if(TinyXML_FOUND)
|
||||||
|
set(TinyXML_INCLUDE_DIRS ${TinyXML_INCLUDE_DIR})
|
||||||
|
set(TinyXML_LIBRARIES ${TinyXML_LIBRARY})
|
||||||
|
endif()
|
BIN
data/10m.tif
BIN
data/10m.tif
Binary file not shown.
0
data/areaThresholds.txt
Executable file → Normal file
0
data/areaThresholds.txt
Executable file → Normal file
8
data/levelThresholds.txt
Normal file
8
data/levelThresholds.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
0
|
||||||
|
1
|
||||||
|
5
|
||||||
|
10
|
||||||
|
25
|
||||||
|
50
|
||||||
|
100
|
||||||
|
200
|
0
data/moiThresholds.txt
Executable file → Normal file
0
data/moiThresholds.txt
Executable file → Normal file
0
data/sdThresholds.txt
Executable file → Normal file
0
data/sdThresholds.txt
Executable file → Normal file
81
documentation/GitInfos.org
Normal file
81
documentation/GitInfos.org
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
* Git de Triskele
|
||||||
|
Note aux développeurs
|
||||||
|
|
||||||
|
** La TODO list
|
||||||
|
- vérifier coupure (avec sens de la monotonie)
|
||||||
|
- faire coupures suivant (A>, W<>, SD>, MOI>)
|
||||||
|
- sort W thresholds
|
||||||
|
- faire les features-profiles (L, mean, SD, A, MOI)
|
||||||
|
- vérifier production windows
|
||||||
|
- refaire le tableau des exemples de traces (./result/BuildSteps.ods)
|
||||||
|
- vérifier min et max apla tos
|
||||||
|
- faire un omega-tree
|
||||||
|
- faire des tests de perf pour algo parallèle
|
||||||
|
|
||||||
|
** Fonctions intégré depuis la dernière version
|
||||||
|
- copier les valeurs de géolocalisation (de input vers output)
|
||||||
|
|
||||||
|
|
||||||
|
** Infos concernant le pattern de git de Triskele
|
||||||
|
|
||||||
|
Triskele suit partiellement le [[https://nvie.com/posts/a-successful-git-branching-model/][modèle gitflow]] pour son développement en conservant certaines branches :
|
||||||
|
- la master qui contient les versions stables du logiciel
|
||||||
|
- la develop qui découle de la master sur laquelle on corrige les bugs / on crée de nouvelles features
|
||||||
|
- les features, ajoutant une ou plusieurs fonctionnalités et qui découlent chacune de dévelop
|
||||||
|
|
||||||
|
** Commandes utiles
|
||||||
|
|
||||||
|
- récupération du git
|
||||||
|
$ git clone git://git.renater.fr/triskele.git
|
||||||
|
|
||||||
|
- Se déplacer sur une branche
|
||||||
|
$ git checkout nomDeBranche
|
||||||
|
|
||||||
|
- Créer une branche locale et s'y placer de suite
|
||||||
|
$ git checkout -b nomDeBranche nomDeBrancheParent
|
||||||
|
# Exemple, création d'une feature pour les oméga-tree
|
||||||
|
$ git checkout -b omega_feature develop
|
||||||
|
|
||||||
|
- Synchroniser la branche créée avec le dépot distant
|
||||||
|
$ git push orgin nomDeBranche
|
||||||
|
# Exemple avec la feature ci-dessus
|
||||||
|
$ git push origin omega_feature
|
||||||
|
|
||||||
|
- Annuler les modifications effectuées depuis la dernière synchronisation
|
||||||
|
$ git checkout -- [nomDuFichier]
|
||||||
|
|
||||||
|
- Afficher toutes les branches existantes (locales ou distantes)
|
||||||
|
$ git branch -a
|
||||||
|
|
||||||
|
- Supprimer une branche sur un dépot local / sur un dépot distant
|
||||||
|
# Pour une branche locale
|
||||||
|
$ git branch -d nomDeBranche
|
||||||
|
|
||||||
|
# Pour la supprimer sur le dépot distant
|
||||||
|
$ git push origin --delete nomDeBranch
|
||||||
|
|
||||||
|
- Fusionner les modifications
|
||||||
|
# Il faut synchroniser la branche développement
|
||||||
|
$ git pull
|
||||||
|
$ git commit -a
|
||||||
|
$ git push
|
||||||
|
# Il faut sélectionner la branche master
|
||||||
|
$ git checkout master
|
||||||
|
# Il faut fusionner
|
||||||
|
$ git merge develop
|
||||||
|
# editer les fichiers en confli
|
||||||
|
$ git commit -a
|
||||||
|
$ git push
|
||||||
|
# Puis mettre à jour la branch develop si conflit
|
||||||
|
$ git checkout develop
|
||||||
|
$ git merge master
|
||||||
|
# Il est possible d'annuler le traitement en cas de conflit
|
||||||
|
$ git merge --abort
|
||||||
|
|
||||||
|
- Etiquetage de version
|
||||||
|
# Choisir la branch master
|
||||||
|
git checkout master
|
||||||
|
# Donner un nom majeru.mineur.AAMMJJ
|
||||||
|
git tag 1.0.180610
|
||||||
|
# valider sur le serveur
|
||||||
|
git push --tags
|
@ -6,14 +6,17 @@
|
|||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
#include "triskeleBase.hpp"
|
#include "triskeleBase.hpp"
|
||||||
|
#include "ArrayTree/GraphWalker.hpp"
|
||||||
#include "IImage.hpp"
|
#include "IImage.hpp"
|
||||||
#include "Appli/Selected.hpp"
|
#include "Appli/Selected.hpp"
|
||||||
|
|
||||||
namespace otb {
|
namespace otb {
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
using namespace ::triskele;
|
using namespace ::triskele;
|
||||||
|
using namespace otb::triskele::arrayTree;
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
|
enum FeatureType { AP, MEAN, SD, AREA, MOI };
|
||||||
|
|
||||||
class Option {
|
class Option {
|
||||||
public:
|
public:
|
||||||
@ -25,11 +28,12 @@ namespace otb {
|
|||||||
Selected selectedBand;
|
Selected selectedBand;
|
||||||
size_t countingSortCeil = 2;
|
size_t countingSortCeil = 2;
|
||||||
vector<DimImg> areaThresholds;
|
vector<DimImg> areaThresholds;
|
||||||
vector<double> sdThresholds, moiThresholds;
|
vector<double> levelThresholds, sdThresholds, moiThresholds;
|
||||||
unsigned int coreCount = boost::thread::hardware_concurrency ();
|
unsigned int coreCount = boost::thread::hardware_concurrency ();
|
||||||
bool maxTreeFlag = false, minTreeFlag = false, tosTreeFlag = false, alphaTreeFlag = false;
|
bool maxTreeFlag = false, minTreeFlag = false, tosTreeFlag = false, alphaTreeFlag = false;
|
||||||
bool oneBand = false;
|
bool border = false, oneBand = false;
|
||||||
|
Connectivity connectivity = Connectivity::C4;
|
||||||
|
FeatureType featureType = FeatureType::AP;
|
||||||
Option ();
|
Option ();
|
||||||
Option (int argc, char** argv);
|
Option (int argc, char** argv);
|
||||||
|
|
||||||
|
@ -43,10 +43,10 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
|
|||||||
auto start = high_resolution_clock::now ();
|
auto start = high_resolution_clock::now ();
|
||||||
switch (treeType) {
|
switch (treeType) {
|
||||||
case MIN:
|
case MIN:
|
||||||
buildTree (tree, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
buildTree (tree, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||||
break;
|
break;
|
||||||
case MAX:
|
case MAX:
|
||||||
buildTree (tree, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
buildTree (tree, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||||
break;
|
break;
|
||||||
case TOS:
|
case TOS:
|
||||||
buildTree (tree, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker));
|
buildTree (tree, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker));
|
||||||
@ -84,10 +84,10 @@ ArrayTreeBuilder<WeightT, PixelT>::setAttributProfiles (AttributeProfiles<PixelT
|
|||||||
attributeProfiles.updateTranscient ();
|
attributeProfiles.updateTranscient ();
|
||||||
switch (treeType) {
|
switch (treeType) {
|
||||||
case MIN:
|
case MIN:
|
||||||
setAttributProfiles (attributeProfiles, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
setAttributProfiles (attributeProfiles, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||||
break;
|
break;
|
||||||
case MAX:
|
case MAX:
|
||||||
setAttributProfiles (attributeProfiles, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
setAttributProfiles (attributeProfiles, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||||
break;
|
break;
|
||||||
case TOS:
|
case TOS:
|
||||||
setAttributProfiles (attributeProfiles, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker));
|
setAttributProfiles (attributeProfiles, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker));
|
||||||
@ -143,7 +143,6 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &wei
|
|||||||
<< tree.printTree (2*leafCount-1));
|
<< tree.printTree (2*leafCount-1));
|
||||||
// merge sub-tree
|
// merge sub-tree
|
||||||
auto startMerge = high_resolution_clock::now ();
|
auto startMerge = high_resolution_clock::now ();
|
||||||
DimImg compCount = compTops [0];
|
|
||||||
DimImg *topC = NULL;
|
DimImg *topC = NULL;
|
||||||
DimImg compBase = vertexMaxBounds[tileCount];
|
DimImg compBase = vertexMaxBounds[tileCount];
|
||||||
if (boundCount) {
|
if (boundCount) {
|
||||||
@ -186,6 +185,53 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &wei
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SMART_LOG ("compWeights:" << endl
|
||||||
|
// << printMap (compWeights, size, 0) << endl << endl
|
||||||
|
// << tree.printTree (2*leafCount-1));
|
||||||
|
auto startForest = high_resolution_clock::now ();
|
||||||
|
if (graphWalker.border.exists ()) {
|
||||||
|
// merge comp forest
|
||||||
|
DimImg rootId = 0;
|
||||||
|
for (unsigned int tileId = 0; tileId < tileCount; tileId++)
|
||||||
|
if (compTops [tileId] != compBases [tileId]) {
|
||||||
|
rootId = findRoot (compTops [tileId] - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG ("merge forest: " << printComp (rootId));
|
||||||
|
for (unsigned int tileId = 0; tileId < tileCount; ++tileId)
|
||||||
|
for (DimImg compId = compBases [tileId]; compId < compTops [tileId]; ++compId)
|
||||||
|
if (compParents [compId] == DimImg_MAX) {
|
||||||
|
connectComp (compId, rootId, weightFunct);
|
||||||
|
rootId = findRoot (rootId);
|
||||||
|
LOG ("merge top: compId:" << printComp (compId) << " nr:" << printComp (rootId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge pixels forest
|
||||||
|
vector<DimImg> lonelyPixelsCount (tileCount, 0);
|
||||||
|
vector<WeightT> topsWeight (tileCount, compWeights [rootId]);
|
||||||
|
dealThreadRange (tileCount, coreCount, [this, &tiles, &rootId, &weightFunct, &lonelyPixelsCount, &topsWeight] (const DimImg &tileId) {
|
||||||
|
WeightT &topWeight (topsWeight [tileId]);
|
||||||
|
DimImg &lonelyPixelCount (lonelyPixelsCount [tileId]);
|
||||||
|
graphWalker.forEachVertexIdx (tiles [tileId], [this, &rootId, &lonelyPixelCount, &topWeight, &weightFunct] (const DimImg &leafId) {
|
||||||
|
if (leafParents [leafId] == DimImg_MAX) {
|
||||||
|
WeightT pixelWeight (weightFunct.getWeight (leafId));
|
||||||
|
leafParents [leafId] = rootId;
|
||||||
|
lonelyPixelCount++;
|
||||||
|
if (weightFunct.isWeightInf (topWeight, pixelWeight))
|
||||||
|
topWeight = pixelWeight;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
for (unsigned int tileId = 0; tileId < tileCount; ++tileId) {
|
||||||
|
childCount [rootId] += lonelyPixelsCount [tileId];
|
||||||
|
if (weightFunct.isWeightInf (compWeights [rootId], topsWeight [tileId]))
|
||||||
|
compWeights [rootId] = topsWeight [tileId];
|
||||||
|
// XXX on ne reprend pas la fraterie inférieur car plus d'appel à findMultiChildrenTop
|
||||||
|
LOG ("merge pixels: tileId:" << tileId << " lonely:" << lonelyPixelsCount [tileId] << " root:" << printComp (rootId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SMART_LOG ("compWeights:" << endl
|
SMART_LOG ("compWeights:" << endl
|
||||||
<< printMap (compWeights, size, 0) << endl << endl
|
<< printMap (compWeights, size, 0) << endl << endl
|
||||||
<< tree.printTree (2*leafCount-1));
|
<< tree.printTree (2*leafCount-1));
|
||||||
@ -196,7 +242,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &wei
|
|||||||
|
|
||||||
SMART_LOG ("reuse leaders:" << endl
|
SMART_LOG ("reuse leaders:" << endl
|
||||||
<< printMap (newCompId, size, 0) << endl << endl);
|
<< printMap (newCompId, size, 0) << endl << endl);
|
||||||
compCount = updateNewId (compBases, compTops, weightFunct);
|
DimImg maxTop = updateNewId (compBases, compTops, weightFunct);
|
||||||
|
|
||||||
SMART_LOG ("updateNewId:" << endl
|
SMART_LOG ("updateNewId:" << endl
|
||||||
<< printMap (newCompId, size, 0) << endl << endl);
|
<< printMap (newCompId, size, 0) << endl << endl);
|
||||||
@ -207,22 +253,23 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &wei
|
|||||||
<< printMap (newCompId, size, 0) << endl << endl);
|
<< printMap (newCompId, size, 0) << endl << endl);
|
||||||
leaders.free ();
|
leaders.free ();
|
||||||
|
|
||||||
while (compCount > 1 && childCount[compCount-1] == 1) {
|
while (maxTop > 1 && childCount[maxTop-1] == 1) {
|
||||||
--compCount;
|
--maxTop;
|
||||||
compParents [compCount-1] = DimImg_MAX;
|
compParents [maxTop-1] = DimImg_MAX;
|
||||||
SMART_LOG ("reduce lonely root:" << printComp (compCount) << endl);
|
SMART_LOG ("reduce lonely root:" << printComp (maxTop) << endl);
|
||||||
}
|
}
|
||||||
setNodeCount (tree, leafCount+compCount);
|
setNodeCount (tree, leafCount+maxTop);
|
||||||
LOG ("nodeCount:" << tree.getNodeCount());
|
LOG ("nodeCount:" << tree.getNodeCount());
|
||||||
// DimEdge root = compCount-1;
|
// DimEdge rootId = maxTop-1;
|
||||||
// compParents[root] = root;
|
// compParents[rootId] = rootId;
|
||||||
|
|
||||||
SMART_LOG ("compWeights:" << endl
|
SMART_LOG ("compWeights:" << endl
|
||||||
<< printMap (compWeights, size, 0) << endl << endl);
|
<< printMap (compWeights, size, 0) << endl << endl);
|
||||||
auto end = high_resolution_clock::now ();
|
auto end = high_resolution_clock::now ();
|
||||||
globalTreeStats.addTime (buildSetupStats, duration_cast<duration<double> > (startParent-start).count ());
|
globalTreeStats.addTime (buildSetupStats, duration_cast<duration<double> > (startParent-start).count ());
|
||||||
globalTreeStats.addTime (buildParentsStats, duration_cast<duration<double> > (startMerge-startParent).count ());
|
globalTreeStats.addTime (buildParentsStats, duration_cast<duration<double> > (startMerge-startParent).count ());
|
||||||
globalTreeStats.addTime (buildMergeStats, duration_cast<duration<double> > (startIndex-startMerge).count ());
|
globalTreeStats.addTime (buildMergeStats, duration_cast<duration<double> > (startForest-startMerge).count ());
|
||||||
|
globalTreeStats.addTime (buildForestStats, duration_cast<duration<double> > (startIndex-startForest).count ());
|
||||||
globalTreeStats.addTime (buildIndexStats, duration_cast<duration<double> > (startCompress-startIndex).count ());
|
globalTreeStats.addTime (buildIndexStats, duration_cast<duration<double> > (startCompress-startIndex).count ());
|
||||||
globalTreeStats.addTime (buildCompressStats, duration_cast<duration<double> > (end-startCompress).count ());
|
globalTreeStats.addTime (buildCompressStats, duration_cast<duration<double> > (end-startCompress).count ());
|
||||||
}
|
}
|
||||||
@ -275,8 +322,12 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
|||||||
SMART_LOG ("pa:" << pa << " pb:" << pb << " la:" << la << " lb:" << lb);
|
SMART_LOG ("pa:" << pa << " pb:" << pb << " la:" << la << " lb:" << lb);
|
||||||
SMART_LOG ("ra:" << printComp (ra) << " rb:" << printComp (rb));
|
SMART_LOG ("ra:" << printComp (ra) << " rb:" << printComp (rb));
|
||||||
|
|
||||||
if (la == lb)
|
if (la == lb) {
|
||||||
|
leaders.link (pa, la);
|
||||||
|
leaders.link (pb, la);
|
||||||
|
SMART_LOG ("la=lb");
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
if (ra == DimImg_MAX) {
|
if (ra == DimImg_MAX) {
|
||||||
swap (la, lb);
|
swap (la, lb);
|
||||||
swap (ra, rb);
|
swap (ra, rb);
|
||||||
@ -299,9 +350,9 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
|||||||
leader = lb;
|
leader = lb;
|
||||||
}
|
}
|
||||||
} else if (ra == rb) {
|
} else if (ra == rb) {
|
||||||
// XXX
|
SMART_LOG ("ra=rb **** XXXX ****");
|
||||||
BOOST_ASSERT (false);
|
BOOST_ASSERT (false);
|
||||||
continue;
|
leader = la;
|
||||||
} else if (compWeights[ra] == compWeights [rb]) {
|
} else if (compWeights[ra] == compWeights [rb]) {
|
||||||
// ra.weight = rb.weight // XXX ?= curEdge.weight
|
// ra.weight = rb.weight // XXX ?= curEdge.weight
|
||||||
if (childCount [ra] < childCount [rb]) {
|
if (childCount [ra] < childCount [rb]) {
|
||||||
@ -327,7 +378,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
|||||||
leaders.link (pa, leader);
|
leaders.link (pa, leader);
|
||||||
leaders.link (pb, leader);
|
leaders.link (pb, leader);
|
||||||
|
|
||||||
SMART_LOG (" leader:" << leader << " ra:" << printComp (ra) << " rb:" << printComp (rb));
|
SMART_LOG (" leader:" << leader << " ra:" << printComp (ra) << " rb:" << printComp (rb) << " nr:" << printComp (findRoot (leafParents [la])));
|
||||||
}
|
}
|
||||||
|
|
||||||
SMART_LOG ("topParent:" << topParent);
|
SMART_LOG ("topParent:" << topParent);
|
||||||
@ -368,11 +419,13 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
|||||||
SMART_LOG ("same parents for: " << a << ", " << b);
|
SMART_LOG ("same parents for: " << a << ", " << b);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (parA == DimImg_MAX) {
|
if (parB == DimImg_MAX) {
|
||||||
|
// XXX 20180776 bug fixed parA => parB
|
||||||
swap (a, b);
|
swap (a, b);
|
||||||
swap (parA, parB);
|
swap (parA, parB);
|
||||||
SMART_LOG ("swap: " << printComp (parA) << " " << printComp (parB));
|
SMART_LOG ("swap: " << printComp (parA) << " " << printComp (parB));
|
||||||
}
|
}
|
||||||
|
// XXX parB =? DimImg_MAX
|
||||||
if ((parA == DimImg_MAX || weightFunct.isWeightInf (weight, compWeights[parA])) &&
|
if ((parA == DimImg_MAX || weightFunct.isWeightInf (weight, compWeights[parA])) &&
|
||||||
weightFunct.isWeightInf (weight, compWeights[parB])) {
|
weightFunct.isWeightInf (weight, compWeights[parB])) {
|
||||||
// upW1 & upW2 : upper
|
// upW1 & upW2 : upper
|
||||||
@ -431,7 +484,7 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
|||||||
unlinkParent (parA);
|
unlinkParent (parA);
|
||||||
++childCount[parB];
|
++childCount[parB];
|
||||||
leafParents[a] = parB;
|
leafParents[a] = parB;
|
||||||
SMART_LOG ("parA: " << printComp (parA) << " parB: " << printComp (parB));
|
SMART_LOG ("link a: " << a << " parB: " << printComp (parB));
|
||||||
}
|
}
|
||||||
// eqW0 | eqW1 | eqW2
|
// eqW0 | eqW1 | eqW2
|
||||||
SMART_LOG ("eqW0 | eqW1 | eqW2: connect");
|
SMART_LOG ("eqW0 | eqW1 | eqW2: connect");
|
||||||
@ -455,8 +508,7 @@ ArrayTreeBuilder<WeightT, PixelT>::connect3Comp (DimImg newComp, DimImg topA, Di
|
|||||||
swap (topA, topB);
|
swap (topA, topB);
|
||||||
BOOST_ASSERT (findTopComp (topB, weightFunct) == topB);
|
BOOST_ASSERT (findTopComp (topB, weightFunct) == topB);
|
||||||
BOOST_ASSERT (weightFunct.isWeightInf (compWeights[newComp], compWeights[topB]));
|
BOOST_ASSERT (weightFunct.isWeightInf (compWeights[newComp], compWeights[topB]));
|
||||||
compParents[newComp] = topB;
|
addChild (topB, compParents[newComp]);
|
||||||
++childCount[topB];
|
|
||||||
SMART_LOG ("topB: " << printComp (topB));
|
SMART_LOG ("topB: " << printComp (topB));
|
||||||
connectComp (topA, topB, weightFunct);
|
connectComp (topA, topB, weightFunct);
|
||||||
}
|
}
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
#ifndef _OTB_TRISKELE_ARRAY_TREE_BORDER_HPP
|
|
||||||
#define _OTB_TRISKELE_ARRAY_TREE_BORDER_HPP
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "triskeleBase.hpp"
|
|
||||||
#include "triskeleArrayTreeBase.hpp"
|
|
||||||
|
|
||||||
namespace otb {
|
|
||||||
namespace triskele {
|
|
||||||
namespace arrayTree {
|
|
||||||
|
|
||||||
/** Border */
|
|
||||||
class Border {
|
|
||||||
public:
|
|
||||||
/*! Retourne le nombre de pixels à l'aide de la taille */
|
|
||||||
static inline DimImg getPixelsCount (const Size &size);
|
|
||||||
|
|
||||||
/*! Retourne la taille que doit faire le tableau simplifié */
|
|
||||||
static inline DimImg getMapLength (DimImg pixelsCount);
|
|
||||||
|
|
||||||
/*! Vérifie si un index est sur la map ou une bordure, en se basant sur le bit de l'index idx de la map */
|
|
||||||
inline bool isBorder (DimImg idx) const;
|
|
||||||
|
|
||||||
/*! Vérifie si un point est sur la map ou une bordure en appelant la méthode précédente après avoir converti le point en index */
|
|
||||||
inline bool isBorder (const Point &p) const;
|
|
||||||
|
|
||||||
/*! Supprime toutes les occurences de bordure à l'index idx */
|
|
||||||
inline void clearBorder (DimImg idx);
|
|
||||||
|
|
||||||
/*! Supprime toutes les occurences de bordure en appelant la méthode précédente après avoir converti le point en index */
|
|
||||||
inline void clearBorder (const Point &p);
|
|
||||||
|
|
||||||
/*! Rajoute une occurence de bordure à l'index indiqué */
|
|
||||||
inline void setBorder (DimImg idx);
|
|
||||||
|
|
||||||
/*! Rajoute une occurence de bordure en appelant la méthode précédente après avoir converti le point en index */
|
|
||||||
inline void setBorder (const Point &p);
|
|
||||||
|
|
||||||
/*! Construit par défault sans aucune bordure */
|
|
||||||
inline Border ();
|
|
||||||
|
|
||||||
/*! Construit Border, les valeurs de map dépendent de defaultVal */
|
|
||||||
inline Border (const Size &size, bool defaultVal);
|
|
||||||
inline Border (const Border &border, const Rect &tile);
|
|
||||||
inline ~Border ();
|
|
||||||
|
|
||||||
inline void reset (bool defaultVal);
|
|
||||||
|
|
||||||
inline const Size &getSize () const;
|
|
||||||
|
|
||||||
/*! Compte le nombre de pixels considérés comme de la bordure */
|
|
||||||
inline DimImg borderCount ();
|
|
||||||
|
|
||||||
private:
|
|
||||||
/*! Nombre de pixels dans l'image */
|
|
||||||
DimImg pixelsCount;
|
|
||||||
|
|
||||||
/*! Taille du tableau "simplifié" des pixels */
|
|
||||||
DimImg mapLength;
|
|
||||||
|
|
||||||
/*! Dimensions de l'image */
|
|
||||||
Size size;
|
|
||||||
|
|
||||||
/*! Tableau "simplifié" des pixels */
|
|
||||||
vector<uint8_t> map;
|
|
||||||
|
|
||||||
bool defaultVal;
|
|
||||||
|
|
||||||
inline void createMap ();
|
|
||||||
|
|
||||||
friend inline ostream &operator << (ostream &out, const Border &border);
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "Border.tpp"
|
|
||||||
|
|
||||||
} //arrayTree
|
|
||||||
} // triskele
|
|
||||||
} // otb
|
|
||||||
|
|
||||||
#endif // _OTB_TRISKELE_ARRAY_TREE_BORDER_HPP
|
|
@ -44,12 +44,13 @@ namespace otb {
|
|||||||
const DimImg &minVal, const DimImg &maxVal) const;
|
const DimImg &minVal, const DimImg &maxVal) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ========================================
|
||||||
/*! Structure intégrant la façon dont est géré un poids pour un MinTree */
|
/*! Structure intégrant la façon dont est géré un poids pour un MinTree */
|
||||||
template <typename PixelT, typename WeightT> struct MinWeight : public WeightBase<PixelT, WeightT> {
|
template <typename PixelT, typename WeightT> struct MinWeight : public WeightBase<PixelT, WeightT> {
|
||||||
typedef WeightBase<PixelT, WeightT> WB;
|
typedef WeightBase<PixelT, WeightT> WB;
|
||||||
|
|
||||||
inline bool getDecr () const;
|
inline bool getDecr () const;
|
||||||
static inline bool isWeightInf (const WeightT &a, const WeightT &b);
|
static inline bool isWeightInf (const WeightT &a, const WeightT &b);
|
||||||
static inline bool isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b);
|
static inline bool isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b);
|
||||||
static inline void sort (Edge<WeightT> *edges, DimEdge count);
|
static inline void sort (Edge<WeightT> *edges, DimEdge count);
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ namespace otb {
|
|||||||
template <typename PixelT, typename WeightT> struct MaxWeight : public WeightBase<PixelT, WeightT> {
|
template <typename PixelT, typename WeightT> struct MaxWeight : public WeightBase<PixelT, WeightT> {
|
||||||
typedef WeightBase<PixelT, WeightT> WB;
|
typedef WeightBase<PixelT, WeightT> WB;
|
||||||
|
|
||||||
inline MaxWeight ();
|
inline MaxWeight();
|
||||||
inline MaxWeight (const PixelT *pixels, const Size &size);
|
inline MaxWeight (const PixelT *pixels, const Size &size);
|
||||||
inline MaxWeight (const MaxWeight &model, const PixelT *pixels, const Size &size);
|
inline MaxWeight (const MaxWeight &model, const PixelT *pixels, const Size &size);
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ namespace otb {
|
|||||||
/* Définit le type d'arbre à construire */
|
/* Définit le type d'arbre à construire */
|
||||||
enum TreeType { MIN, MAX, TOS, ALPHA, TreeTypeCard};
|
enum TreeType { MIN, MAX, TOS, ALPHA, TreeTypeCard};
|
||||||
|
|
||||||
|
inline bool getDecrFromTreetype (TreeType treeType);
|
||||||
|
|
||||||
/*! Définit les noms des connectivités (utile pour le debug) */
|
/*! Définit les noms des connectivités (utile pour le debug) */
|
||||||
extern string connectivityName[];
|
extern string connectivityName[];
|
||||||
|
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
#ifndef _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
#ifndef _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
||||||
#define _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
#define _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
getDecrFromTreetype (TreeType treeType) {
|
||||||
|
switch (treeType) {
|
||||||
|
case MIN: return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
inline ostream &
|
inline ostream &
|
||||||
operator << (ostream &out, const Connectivity &c) {
|
operator << (ostream &out, const Connectivity &c) {
|
||||||
BOOST_ASSERT (c >= 0 && c < 4);
|
BOOST_ASSERT (c >= 0 && c < 4);
|
||||||
|
@ -16,6 +16,12 @@ namespace otb {
|
|||||||
inline PixelT *getValues ();
|
inline PixelT *getValues ();
|
||||||
inline const PixelT *getValues () const;
|
inline const PixelT *getValues () const;
|
||||||
|
|
||||||
|
template<typename WeightT>
|
||||||
|
inline void setValues (const PixelT defaultValue, const WeightT *weights);
|
||||||
|
|
||||||
|
template<typename WeightT>
|
||||||
|
inline void setValues (const PixelT *pixels, const WeightT *weights);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const Tree &tree;
|
const Tree &tree;
|
||||||
DimNodeId leafCount;
|
DimNodeId leafCount;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
#ifndef _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
||||||
#define _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
#define _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
||||||
|
|
||||||
|
// ========================================
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline
|
inline
|
||||||
AttributeProfiles<PixelT>::AttributeProfiles (const Tree &tree)
|
AttributeProfiles<PixelT>::AttributeProfiles (const Tree &tree)
|
||||||
@ -34,6 +35,38 @@ AttributeProfiles<PixelT>::getValues () const {
|
|||||||
return &values[0];
|
return &values[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
template<typename PixelT>
|
||||||
|
template<typename WeightT>
|
||||||
|
inline void
|
||||||
|
AttributeProfiles<PixelT>::setValues (const PixelT defaultValue, const WeightT *weights) {
|
||||||
|
updateTranscient ();
|
||||||
|
fill_n (&values[0], tree.getLeafCount (), defaultValue);
|
||||||
|
PixelT *compAP = &values[tree.getLeafCount ()];
|
||||||
|
dealThreadBound (tree.getCompCount (), tree.getCoreCount (), [&compAP, &weights] (const DimImg &minVal, const DimImg &maxVal) {
|
||||||
|
for (DimImg compIdx = minVal; compIdx < maxVal; ++compIdx)
|
||||||
|
compAP[compIdx] = weights[compIdx];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename PixelT>
|
||||||
|
template<typename WeightT>
|
||||||
|
inline void
|
||||||
|
AttributeProfiles<PixelT>::setValues (const PixelT *pixels, const WeightT *weights) {
|
||||||
|
updateTranscient ();
|
||||||
|
PixelT *leafAP = &values[0];
|
||||||
|
dealThreadBound (tree.getLeafCount (), tree.getCoreCount (), [&leafAP, &pixels] (const DimImg &minVal, const DimImg &maxVal) {
|
||||||
|
for (DimImg i = minVal; i < maxVal; ++i)
|
||||||
|
leafAP[i] = pixels [i];
|
||||||
|
});
|
||||||
|
PixelT *compAP = leafAP+tree.getLeafCount ();
|
||||||
|
dealThreadBound (tree.getCompCount (), tree.getCoreCount (), [&compAP, &weights] (const DimImg &minVal, const DimImg &maxVal) {
|
||||||
|
for (DimImg compIdx = minVal; compIdx < maxVal; ++compIdx)
|
||||||
|
compAP[compIdx] = weights[compIdx];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void
|
inline void
|
||||||
AttributeProfiles<PixelT>::free () {
|
AttributeProfiles<PixelT>::free () {
|
||||||
@ -58,4 +91,5 @@ AttributeProfiles<PixelT>::print (ostream &out) const {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
#endif // _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
#endif // _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
namespace otb {
|
namespace otb {
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
|
|
||||||
class AreaAttributes : public CompAttributeC<DimImg> {
|
/*! Fonction monotonne strictement croissante. */
|
||||||
|
class AreaAttributes : public CompAttribute<DimImg> {
|
||||||
public:
|
public:
|
||||||
inline AreaAttributes (const Tree &tree);
|
inline AreaAttributes (const Tree &tree);
|
||||||
inline ~AreaAttributes ();
|
inline ~AreaAttributes ();
|
||||||
|
@ -5,7 +5,7 @@ using namespace boost::chrono;
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
AreaAttributes::AreaAttributes (const Tree &tree)
|
AreaAttributes::AreaAttributes (const Tree &tree)
|
||||||
: CompAttributeC<DimImg> (tree) {
|
: CompAttribute<DimImg> (tree) {
|
||||||
compute ();
|
compute ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ inline void
|
|||||||
AreaAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
AreaAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const vector<DimImg> &thresholds) const {
|
const vector<DimImg> &thresholds) const {
|
||||||
auto start = high_resolution_clock::now ();
|
auto start = high_resolution_clock::now ();
|
||||||
CompAttributeC<DimImg>::cut (allBands, attributeProfiles, 1, thresholds);
|
CompAttribute<DimImg>::cut (allBands, attributeProfiles, 1, thresholds);
|
||||||
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,11 +11,13 @@
|
|||||||
namespace otb {
|
namespace otb {
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
|
|
||||||
class AverageAttributes : public CompAttributeC<double> {
|
/*! Fonction non monotonne. */
|
||||||
|
class AverageAttributes : public CompAttribute<double> {
|
||||||
public:
|
public:
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
|
inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
|
||||||
inline ~AverageAttributes ();
|
inline ~AverageAttributes ();
|
||||||
|
|
||||||
virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "average"); return out; }
|
virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "average"); return out; }
|
||||||
protected:
|
protected:
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
|
@ -6,7 +6,7 @@ using namespace boost::chrono;
|
|||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline
|
inline
|
||||||
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes)
|
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes)
|
||||||
: CompAttributeC<double> (tree) {
|
: CompAttribute<double> (tree) {
|
||||||
compute (raster, areaAttributes);
|
compute (raster, areaAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
namespace otb {
|
namespace otb {
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
|
|
||||||
class MoIAttributes : public CompAttributeC<double> {
|
/*! Fonction monotonne strictement croissante. */
|
||||||
|
class MoIAttributes : public CompAttribute<double> {
|
||||||
public:
|
public:
|
||||||
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
|
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
|
||||||
inline ~MoIAttributes ();
|
inline ~MoIAttributes ();
|
||||||
|
@ -5,7 +5,7 @@ using namespace boost::chrono;
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes)
|
MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes)
|
||||||
: CompAttributeC<double> (tree) {
|
: CompAttribute<double> (tree) {
|
||||||
compute (areaAttributes, xyAttributes);
|
compute (areaAttributes, xyAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,8 +23,8 @@ MoIAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<P
|
|||||||
auto start = high_resolution_clock::now ();
|
auto start = high_resolution_clock::now ();
|
||||||
double maxValue = CompAttribute<double>::getMaxValue ();
|
double maxValue = CompAttribute<double>::getMaxValue ();
|
||||||
cerr << "moi max value:" << maxValue << endl;
|
cerr << "moi max value:" << maxValue << endl;
|
||||||
CompAttributeC<double>::cut (allBands, attributeProfiles, 0,
|
CompAttribute<double>::cut (allBands, attributeProfiles, 0,
|
||||||
CompAttributeC<double>::getScaledThresholds (thresholds, maxValue));
|
CompAttribute<double>::getScaledThresholds (thresholds, maxValue));
|
||||||
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
namespace otb {
|
namespace otb {
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
|
|
||||||
class SDAttributes : public CompAttributeC<double> {
|
/*! Fonction non monotonne, globalement croissante. */
|
||||||
|
class SDAttributes : public CompAttribute<double> {
|
||||||
public:
|
public:
|
||||||
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
||||||
inline ~SDAttributes ();
|
inline ~SDAttributes ();
|
||||||
|
@ -5,7 +5,7 @@ using namespace boost::chrono;
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
SDAttributes::SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
|
SDAttributes::SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
|
||||||
: CompAttributeC<double> (tree) {
|
: CompAttribute<double> (tree) {
|
||||||
compute (areaAttributes);
|
compute (areaAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,8 +23,8 @@ SDAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<Pi
|
|||||||
auto start = high_resolution_clock::now ();
|
auto start = high_resolution_clock::now ();
|
||||||
double maxValue = CompAttribute<double>::getMaxValue ();
|
double maxValue = CompAttribute<double>::getMaxValue ();
|
||||||
cerr << "sd max value:" << maxValue << endl;
|
cerr << "sd max value:" << maxValue << endl;
|
||||||
CompAttributeC<double>::cut (allBands, attributeProfiles, 0,
|
CompAttribute<double>::cut (allBands, attributeProfiles, 0,
|
||||||
CompAttributeC<double>::getScaledThresholds (thresholds, maxValue));
|
CompAttribute<double>::getScaledThresholds (thresholds, maxValue));
|
||||||
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,19 +2,24 @@
|
|||||||
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
|
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
|
||||||
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
|
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
|
||||||
|
|
||||||
|
#include <boost/chrono.hpp>
|
||||||
|
|
||||||
#include "triskeleBase.hpp"
|
#include "triskeleBase.hpp"
|
||||||
|
|
||||||
namespace otb {
|
namespace otb {
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
|
|
||||||
/** Attribute */
|
/*! Fonction monotonne strict croissante ou décroissante en fonction de la fonction de poid. */
|
||||||
template<typename WeightT>
|
template<typename WeightT>
|
||||||
class WeightAttributes : public CompAttribute<WeightT> {
|
class WeightAttributes : public CompAttribute<WeightT> {
|
||||||
public:
|
public:
|
||||||
inline WeightAttributes (const Tree &tree);
|
inline WeightAttributes (const Tree &tree, const bool &decr);
|
||||||
inline ~WeightAttributes ();
|
inline ~WeightAttributes ();
|
||||||
|
|
||||||
inline void setWeightBounds (Tree &tree);
|
inline void setWeightBounds (Tree &tree);
|
||||||
|
template<typename PixelT>
|
||||||
|
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
const vector<WeightT> &thresholds) const;
|
||||||
|
|
||||||
virtual inline ostream &print (ostream &out) const { CompAttribute<WeightT>::print (out, "weight"); return out; }
|
virtual inline ostream &print (ostream &out) const { CompAttribute<WeightT>::print (out, "weight"); return out; }
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
|
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
|
||||||
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
|
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
|
||||||
|
|
||||||
|
using namespace boost::chrono;
|
||||||
|
|
||||||
template<typename WeightT>
|
template<typename WeightT>
|
||||||
inline
|
inline
|
||||||
WeightAttributes<WeightT>::WeightAttributes (const Tree &tree)
|
WeightAttributes<WeightT>::WeightAttributes (const Tree &tree, const bool &decr)
|
||||||
: CompAttribute<WeightT> (tree) {
|
: CompAttribute<WeightT> (tree, decr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename WeightT>
|
template<typename WeightT>
|
||||||
@ -39,4 +41,19 @@ WeightAttributes<WeightT>::setWeightBounds (Tree &tree) {
|
|||||||
weightBounds.push_back (rootId+1);
|
weightBounds.push_back (rootId+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename WeightT>
|
||||||
|
template<typename PixelT>
|
||||||
|
inline void
|
||||||
|
WeightAttributes<WeightT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
const vector<WeightT> &thresholds) const {
|
||||||
|
auto start = high_resolution_clock::now ();
|
||||||
|
vector<WeightT> orderedThresholds (thresholds);
|
||||||
|
if (CompAttribute<WeightT>::decr)
|
||||||
|
reverse (orderedThresholds.begin (), orderedThresholds.end ());
|
||||||
|
CompAttribute<WeightT>::cut (allBands, attributeProfiles, 0., orderedThresholds);
|
||||||
|
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
|
#endif // _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
|
||||||
|
@ -11,6 +11,7 @@ namespace otb {
|
|||||||
namespace triskele {
|
namespace triskele {
|
||||||
using namespace ::triskele;
|
using namespace ::triskele;
|
||||||
|
|
||||||
|
/*! Fonction non monotonne. */
|
||||||
struct AverageXY {
|
struct AverageXY {
|
||||||
double x, y;
|
double x, y;
|
||||||
inline AverageXY () : x(0), y(0) {}
|
inline AverageXY () : x(0), y(0) {}
|
||||||
@ -18,7 +19,7 @@ namespace otb {
|
|||||||
operator DimImg () const { return (DimImg) (x*y); }
|
operator DimImg () const { return (DimImg) (x*y); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class XYAttributes : public CompAttributeC<AverageXY> {
|
class XYAttributes : public CompAttribute<AverageXY> {
|
||||||
public:
|
public:
|
||||||
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
||||||
inline ~XYAttributes ();
|
inline ~XYAttributes ();
|
||||||
|
@ -5,7 +5,7 @@ using namespace boost::chrono;
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
XYAttributes::XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
|
XYAttributes::XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
|
||||||
: CompAttributeC<AverageXY> (tree) {
|
: CompAttribute<AverageXY> (tree) {
|
||||||
compute (areaAttributes);
|
compute (areaAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
80
include/Border.hpp
Normal file
80
include/Border.hpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#ifndef _OTB_TRISKELE_BORDER_HPP
|
||||||
|
#define _OTB_TRISKELE_BORDER_HPP
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "triskeleBase.hpp"
|
||||||
|
//#include "triskeleArrayTreeBase.hpp"
|
||||||
|
|
||||||
|
namespace triskele {
|
||||||
|
|
||||||
|
/** Border */
|
||||||
|
class Border {
|
||||||
|
public:
|
||||||
|
/*! Retourne le nombre de pixels à l'aide de la taille */
|
||||||
|
static inline DimImg getPixelsCount (const Size &size);
|
||||||
|
|
||||||
|
/*! Retourne la taille que doit faire le tableau simplifié */
|
||||||
|
static inline DimImg getMapLength (DimImg pixelsCount);
|
||||||
|
|
||||||
|
/*! Indique qu'une carte de borfure est présente (donc potentiellement des pixels de bordures). */
|
||||||
|
inline bool exists () const;
|
||||||
|
|
||||||
|
/*! Vérifie si un index est sur la map ou une bordure, en se basant sur le bit de l'index idx de la map */
|
||||||
|
inline bool isBorder (DimImg idx) const;
|
||||||
|
|
||||||
|
/*! Vérifie si un point est sur la map ou une bordure en appelant la méthode précédente après avoir converti le point en index */
|
||||||
|
inline bool isBorder (const Point &p) const;
|
||||||
|
|
||||||
|
/*! Supprime toutes les occurences de bordure à l'index idx */
|
||||||
|
inline void clearBorder (DimImg idx);
|
||||||
|
|
||||||
|
/*! Supprime toutes les occurences de bordure en appelant la méthode précédente après avoir converti le point en index */
|
||||||
|
inline void clearBorder (const Point &p);
|
||||||
|
|
||||||
|
/*! Rajoute une occurence de bordure à l'index indiqué */
|
||||||
|
inline void setBorder (DimImg idx);
|
||||||
|
|
||||||
|
/*! Rajoute une occurence de bordure en appelant la méthode précédente après avoir converti le point en index */
|
||||||
|
inline void setBorder (const Point &p);
|
||||||
|
|
||||||
|
/*! Construit par défault sans aucune bordure */
|
||||||
|
inline Border ();
|
||||||
|
|
||||||
|
/*! Construit Border, les valeurs de map dépendent de defaultVal */
|
||||||
|
inline Border (const Size &size, bool defaultVal);
|
||||||
|
inline Border (const Border &border, const Rect &tile);
|
||||||
|
inline ~Border ();
|
||||||
|
|
||||||
|
inline void reset (bool defaultVal);
|
||||||
|
|
||||||
|
inline const Size &getSize () const;
|
||||||
|
|
||||||
|
/*! Compte le nombre de pixels considérés comme de la bordure */
|
||||||
|
inline DimImg borderCount ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*! Nombre de pixels dans l'image */
|
||||||
|
DimImg pixelsCount;
|
||||||
|
|
||||||
|
/*! Taille du tableau "simplifié" des pixels */
|
||||||
|
DimImg mapLength;
|
||||||
|
|
||||||
|
/*! Dimensions de l'image */
|
||||||
|
Size size;
|
||||||
|
|
||||||
|
/*! Tableau "simplifié" des pixels */
|
||||||
|
vector<uint8_t> map;
|
||||||
|
|
||||||
|
bool defaultVal;
|
||||||
|
|
||||||
|
inline void createMap ();
|
||||||
|
|
||||||
|
friend inline ostream &operator << (ostream &out, const Border &border);
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "Border.tpp"
|
||||||
|
|
||||||
|
} // triskele
|
||||||
|
|
||||||
|
#endif // _OTB_TRISKELE_BORDER_HPP
|
@ -10,6 +10,11 @@ Border::getMapLength (DimImg pixelsCount) {
|
|||||||
return (pixelsCount+7)/8;
|
return (pixelsCount+7)/8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
Border::exists () const {
|
||||||
|
return map.size ();
|
||||||
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
Border::isBorder (DimImg idx) const {
|
Border::isBorder (DimImg idx) const {
|
||||||
BOOST_ASSERT (idx < pixelsCount);
|
BOOST_ASSERT (idx < pixelsCount);
|
||||||
@ -60,19 +65,21 @@ Border::Border ()
|
|||||||
inline
|
inline
|
||||||
Border::Border (const Size &size, bool defaultVal)
|
Border::Border (const Size &size, bool defaultVal)
|
||||||
: pixelsCount (getPixelsCount (size)),
|
: pixelsCount (getPixelsCount (size)),
|
||||||
size (size),
|
|
||||||
mapLength (getMapLength (pixelsCount)),
|
mapLength (getMapLength (pixelsCount)),
|
||||||
|
size (size),
|
||||||
map (),
|
map (),
|
||||||
defaultVal (defaultVal) {
|
defaultVal (defaultVal) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
Border::Border (const Border &border, const Rect &tile)
|
Border::Border (const Border &border, const Rect &tile)
|
||||||
: size (tile.width, tile.height),
|
: size (tile.width, tile.height),
|
||||||
pixelsCount (getPixelsCount (size)),
|
|
||||||
mapLength (getMapLength (pixelsCount)),
|
|
||||||
map (),
|
map (),
|
||||||
defaultVal (border.defaultVal) {
|
defaultVal (border.defaultVal) {
|
||||||
|
|
||||||
|
pixelsCount = getPixelsCount (size);
|
||||||
|
mapLength = getMapLength (pixelsCount);
|
||||||
|
|
||||||
if (!border.map.size ())
|
if (!border.map.size ())
|
||||||
return;
|
return;
|
||||||
// XXX todo
|
// XXX todo
|
@ -14,44 +14,18 @@ namespace otb {
|
|||||||
template<typename AttrT>
|
template<typename AttrT>
|
||||||
class CompAttribute {
|
class CompAttribute {
|
||||||
public:
|
public:
|
||||||
inline CompAttribute (const Tree &tree);
|
static inline vector<AttrT> getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue);
|
||||||
|
static inline vector<AttrT> getConvertedThresholds (const vector<double> &thresholds);
|
||||||
|
|
||||||
|
inline CompAttribute (const Tree &tree, const bool &decr = false);
|
||||||
inline ~CompAttribute ();
|
inline ~CompAttribute ();
|
||||||
|
|
||||||
inline void updateTranscient ();
|
inline void updateTranscient ();
|
||||||
inline const AttrT *getValues () const;
|
inline const AttrT *getValues () const;
|
||||||
inline AttrT *getValues ();
|
inline AttrT *getValues ();
|
||||||
inline AttrT getMaxValue () const;
|
inline AttrT getMaxValue () const;
|
||||||
|
inline bool getDecr () const;
|
||||||
|
|
||||||
virtual inline ostream &print (ostream &out) const { print (out, ""); return out; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const Tree &tree;
|
|
||||||
DimNodeId leafCount;
|
|
||||||
vector<AttrT> values;
|
|
||||||
|
|
||||||
inline void free ();
|
|
||||||
inline void book (const DimImg &leafCount);
|
|
||||||
|
|
||||||
ostream &print (ostream &out, const string &msg) const;
|
|
||||||
friend ostream &operator << (ostream& out, const CompAttribute &ca) { return ca.print (out); }
|
|
||||||
};
|
|
||||||
|
|
||||||
} // triskele
|
|
||||||
} // otb
|
|
||||||
|
|
||||||
#include "Attributes/WeightAttributes.hpp"
|
|
||||||
|
|
||||||
namespace otb {
|
|
||||||
namespace triskele {
|
|
||||||
|
|
||||||
template<typename AttrT>
|
|
||||||
class CompAttributeC : public CompAttribute<AttrT> {
|
|
||||||
public:
|
|
||||||
inline CompAttributeC (const Tree &tree);
|
|
||||||
inline ~CompAttributeC ();
|
|
||||||
|
|
||||||
static inline vector<AttrT> getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue);
|
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
||||||
@ -60,11 +34,30 @@ namespace otb {
|
|||||||
inline void cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
inline void cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
||||||
|
|
||||||
|
virtual inline ostream &print (ostream &out) const { print (out, ""); return out; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
const Tree &tree;
|
||||||
|
DimNodeId leafCount;
|
||||||
|
vector<AttrT> values;
|
||||||
|
bool decr;
|
||||||
|
|
||||||
|
inline void free ();
|
||||||
|
inline void book (const DimImg &leafCount);
|
||||||
|
|
||||||
template<typename CumpFunctPSE>
|
template<typename CumpFunctPSE>
|
||||||
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/) const;
|
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/) const;
|
||||||
|
|
||||||
|
ostream &print (ostream &out, const string &msg) const;
|
||||||
|
friend ostream &operator << (ostream& out, const CompAttribute &ca) { return ca.print (out); return out; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // triskele
|
||||||
|
} // otb
|
||||||
|
#include "Attributes/WeightAttributes.hpp"
|
||||||
|
namespace otb {
|
||||||
|
namespace triskele {
|
||||||
#include "CompAttribute.tpp"
|
#include "CompAttribute.tpp"
|
||||||
} // triskele
|
} // triskele
|
||||||
} // otb
|
} // otb
|
||||||
|
@ -1,12 +1,34 @@
|
|||||||
#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
||||||
#define _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
#define _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
template<typename AttrT>
|
||||||
|
inline vector<AttrT>
|
||||||
|
CompAttribute<AttrT>::getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue) {
|
||||||
|
vector<AttrT> result;
|
||||||
|
for (double percent : thresholds)
|
||||||
|
result.push_back (percent*maxValue);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename AttrT>
|
||||||
|
inline vector<AttrT>
|
||||||
|
CompAttribute<AttrT>::getConvertedThresholds (const vector<double> &thresholds) {
|
||||||
|
vector<AttrT> result;
|
||||||
|
for (double value : thresholds)
|
||||||
|
result.push_back ((AttrT) value);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
template<typename AttrT>
|
template<typename AttrT>
|
||||||
inline
|
inline
|
||||||
CompAttribute<AttrT>::CompAttribute (const Tree &tree)
|
CompAttribute<AttrT>::CompAttribute (const Tree &tree, const bool &decr)
|
||||||
: tree (tree),
|
: tree (tree),
|
||||||
leafCount (0),
|
leafCount (0),
|
||||||
values () {
|
values (),
|
||||||
|
decr (decr)
|
||||||
|
{
|
||||||
updateTranscient ();
|
updateTranscient ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,78 +69,13 @@ CompAttribute<AttrT>::getMaxValue () const {
|
|||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename AttrT>
|
|
||||||
inline ostream &
|
|
||||||
CompAttribute<AttrT>::print (ostream &out, const string &msg) const {
|
|
||||||
cout << "values: " << msg << endl;
|
|
||||||
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
|
||||||
return cout << printMap (&values[0], doubleSize, tree.getCompCount ()) << endl << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename AttrT>
|
|
||||||
inline void
|
|
||||||
CompAttribute<AttrT>::free () {
|
|
||||||
values = vector<AttrT> ();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename AttrT>
|
|
||||||
inline void
|
|
||||||
CompAttribute<AttrT>::book (const DimImg &leafCount) {
|
|
||||||
this->leafCount = leafCount;
|
|
||||||
values.resize (leafCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
template<typename AttrT>
|
|
||||||
inline
|
|
||||||
CompAttributeC<AttrT>::CompAttributeC (const Tree &tree)
|
|
||||||
: CompAttribute<AttrT> (tree) {
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename AttrT>
|
|
||||||
inline
|
|
||||||
CompAttributeC<AttrT>::~CompAttributeC () {
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename AttrT>
|
|
||||||
inline vector<AttrT>
|
|
||||||
CompAttributeC<AttrT>::getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue) {
|
|
||||||
vector<AttrT> result;
|
|
||||||
for (AttrT percent : thresholds)
|
|
||||||
result.push_back (percent*maxValue);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename AttrT>
|
|
||||||
template<typename CumpFunctPSE>
|
|
||||||
inline void
|
|
||||||
CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
|
|
||||||
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
|
|
||||||
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
|
|
||||||
DEF_LOG ("CompAttributeC::computeSameCompLevel", "coreCount:" << coreCount);
|
|
||||||
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
|
|
||||||
LOG ("CompAttributeC::computeSameCompLevel: no thread");
|
|
||||||
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DimImg first = weightBounds [0];
|
|
||||||
for (DimImg curBound = 1; curBound < weightBounds.size (); curBound++) {
|
|
||||||
DimImg next = weightBounds [curBound];
|
|
||||||
dealThreadRange (next-first, coreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
|
|
||||||
const DimImg parentId = id+first;
|
|
||||||
cumpFunctPSE (parentId);
|
|
||||||
});
|
|
||||||
first = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename AttrT>
|
template<typename AttrT>
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void
|
inline void
|
||||||
CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
CompAttribute<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
|
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
|
||||||
DEF_LOG ("CompAttributeC::cut", "coreCount:" << CompAttribute<AttrT>::tree.getCoreCount () << " thresholds:" << thresholds.size ());
|
DEF_LOG ("CompAttribute::cut", "coreCount:" << CompAttribute<AttrT>::tree.getCoreCount () << " thresholds:" << thresholds.size ());
|
||||||
dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::tree.getCoreCount (), [this, &allBands, &attributeProfiles, &pixelAttrValue, &thresholds] (const DimImg &leafId) {
|
dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::tree.getCoreCount (), [this, &allBands, &attributeProfiles, &pixelAttrValue, &thresholds] (const DimImg &leafId) {
|
||||||
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, thresholds);
|
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, thresholds);
|
||||||
});
|
});
|
||||||
@ -127,12 +84,13 @@ CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributePr
|
|||||||
template<typename AttrT>
|
template<typename AttrT>
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void
|
inline void
|
||||||
CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
CompAttribute<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const DimImg &leafId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
|
const DimImg &leafId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
|
||||||
// no debug (to many pixels)
|
// no debug (to many pixels)
|
||||||
DimImg parentId = CompAttribute<AttrT>::tree.getLeafParent (leafId);
|
DimImg parentId = CompAttribute<AttrT>::tree.getLeafParent (leafId);
|
||||||
DimChanel thresholdsSize = thresholds.size ();
|
DimChanel thresholdsSize = thresholds.size ();
|
||||||
if (parentId == DimImg_MAX) {
|
if (parentId == DimImg_MAX) {
|
||||||
|
// border case
|
||||||
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel)
|
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel)
|
||||||
allBands[chanel][leafId] = 0;
|
allBands[chanel][leafId] = 0;
|
||||||
return;
|
return;
|
||||||
@ -150,9 +108,17 @@ CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const Attrib
|
|||||||
DimImg rootId = CompAttribute<AttrT>::tree.getCompRoot ();
|
DimImg rootId = CompAttribute<AttrT>::tree.getCompRoot ();
|
||||||
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel) {
|
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel) {
|
||||||
AttrT ceil = thresholds[chanel];
|
AttrT ceil = thresholds[chanel];
|
||||||
for ( ; curValue < ceil && curId < rootId; ) {
|
for ( ; curId < rootId; ) {
|
||||||
|
if (decr) {
|
||||||
|
if (curValue < ceil)
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if (curValue > ceil)
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (parentId == DimImg_MAX || curId >= parentId) {
|
if (parentId == DimImg_MAX || curId >= parentId) {
|
||||||
// cerr << "CompAttributeC::cutOnPos find sub-root:" << rootId << " rootId:" << rootId << endl;
|
// cerr << "CompAttribute::cutOnPos find sub-root:" << rootId << " rootId:" << rootId << endl;
|
||||||
|
// find root
|
||||||
for (; chanel < thresholdsSize; ++chanel)
|
for (; chanel < thresholdsSize; ++chanel)
|
||||||
allBands[chanel][leafId] = curValue;
|
allBands[chanel][leafId] = curValue;
|
||||||
return;
|
return;
|
||||||
@ -167,4 +133,53 @@ CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const Attrib
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
template<typename AttrT>
|
||||||
|
inline ostream &
|
||||||
|
CompAttribute<AttrT>::print (ostream &out, const string &msg) const {
|
||||||
|
cout << "values: " << msg << endl;
|
||||||
|
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
||||||
|
cout << printMap (&values[0], doubleSize, tree.getCompCount ()) << endl << endl;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
template<typename AttrT>
|
||||||
|
inline void
|
||||||
|
CompAttribute<AttrT>::free () {
|
||||||
|
values = vector<AttrT> ();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename AttrT>
|
||||||
|
inline void
|
||||||
|
CompAttribute<AttrT>::book (const DimImg &leafCount) {
|
||||||
|
this->leafCount = leafCount;
|
||||||
|
values.resize (leafCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
template<typename AttrT>
|
||||||
|
template<typename CumpFunctPSE>
|
||||||
|
inline void
|
||||||
|
CompAttribute<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
|
||||||
|
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
|
||||||
|
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
|
||||||
|
DEF_LOG ("CompAttribute::computeSameCompLevel", "coreCount:" << coreCount);
|
||||||
|
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
|
||||||
|
LOG ("CompAttribute::computeSameCompLevel: no thread");
|
||||||
|
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DimImg first = weightBounds [0];
|
||||||
|
for (DimImg curBound = 1; curBound < weightBounds.size (); curBound++) {
|
||||||
|
DimImg next = weightBounds [curBound];
|
||||||
|
dealThreadRange (next-first, coreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
|
||||||
|
const DimImg parentId = id+first;
|
||||||
|
cumpFunctPSE (parentId);
|
||||||
|
});
|
||||||
|
first = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
||||||
|
@ -19,6 +19,7 @@ namespace triskele {
|
|||||||
private:
|
private:
|
||||||
Size size;
|
Size size;
|
||||||
vector<PixelT> pixels;
|
vector<PixelT> pixels;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline void setSize (const Size &size);
|
inline void setSize (const Size &size);
|
||||||
inline const Size &getSize () const;
|
inline const Size &getSize () const;
|
||||||
@ -39,6 +40,8 @@ namespace triskele {
|
|||||||
class IImage {
|
class IImage {
|
||||||
public:
|
public:
|
||||||
void setFileName (string fileName);
|
void setFileName (string fileName);
|
||||||
|
inline void getGeo (string& projectionRef, vector<double> &geoTransform) const;
|
||||||
|
inline void setGeo (const string& projectionRef, vector<double> geoTransform, const Point &topLeft);
|
||||||
inline const string &getFileName () const;
|
inline const string &getFileName () const;
|
||||||
inline const Size &getSize () const;
|
inline const Size &getSize () const;
|
||||||
inline const DimChanel &getBandCount () const;
|
inline const DimChanel &getBandCount () const;
|
||||||
@ -46,11 +49,13 @@ namespace triskele {
|
|||||||
inline const bool isRead () const;
|
inline const bool isRead () const;
|
||||||
inline const bool isEmpty () const;
|
inline const bool isEmpty () const;
|
||||||
|
|
||||||
IImage (const std::string &imageFileName = "");
|
IImage (const std::string &imageFileName = "");
|
||||||
~IImage ();
|
~IImage ();
|
||||||
|
|
||||||
void readImage ();
|
void readImage ();
|
||||||
void createImage (const Size &size, const GDALDataType &dataType, const DimChanel &nbOutputBands);
|
void createImage (const Size &size, const GDALDataType &dataType, const DimChanel &nbOutputBands);
|
||||||
|
void createImage (const Size &size, const GDALDataType &dataType, const DimChanel &nbOutputBands,
|
||||||
|
const IImage &inputImage, const Point &topLeft);
|
||||||
void close ();
|
void close ();
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
@ -66,6 +71,8 @@ namespace triskele {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static size_t gdalCount;
|
static size_t gdalCount;
|
||||||
|
string projectionRef;
|
||||||
|
vector<double> geoTransform;
|
||||||
string fileName;
|
string fileName;
|
||||||
Size size;
|
Size size;
|
||||||
DimChanel bandCount;
|
DimChanel bandCount;
|
||||||
|
@ -86,6 +86,37 @@ IImage::setFileName (string fileName) {
|
|||||||
close ();
|
close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
IImage::getGeo (string& projectionRef, vector<double> &geoTransform) const {
|
||||||
|
projectionRef = this->projectionRef;
|
||||||
|
geoTransform = this->geoTransform;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
IImage::setGeo (const string& projectionRef, vector<double> geoTransform, const Point &topLeft) {
|
||||||
|
DEF_LOG ("IImage::setGeo", "projectionRef:" << projectionRef);
|
||||||
|
// move TopLeft cf WordFile
|
||||||
|
double
|
||||||
|
x (geoTransform[0]),
|
||||||
|
xScale (geoTransform[1]),
|
||||||
|
xSkew (geoTransform[2]),
|
||||||
|
y (geoTransform[3]),
|
||||||
|
ySkew (geoTransform[4]),
|
||||||
|
yScale (geoTransform[5]);
|
||||||
|
double
|
||||||
|
xTrans = x + topLeft.x*xScale + topLeft.y*xSkew,
|
||||||
|
yTrans = y + topLeft.x*ySkew + topLeft.y*yScale;
|
||||||
|
geoTransform[0] = xTrans;
|
||||||
|
geoTransform[3] = yTrans;
|
||||||
|
CPLErr err = gdalOutputDataset->SetGeoTransform (&geoTransform[0]);
|
||||||
|
if (err != CE_None)
|
||||||
|
cerr << "IImage::setGeo: can't set geoTransform for " << fileName << endl;
|
||||||
|
err = gdalOutputDataset->SetProjection (projectionRef.c_str ());
|
||||||
|
if (err != CE_None)
|
||||||
|
cerr << "IImage::setGeo: can't set projection for " << fileName << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const string &
|
inline const string &
|
||||||
IImage::getFileName () const {
|
IImage::getFileName () const {
|
||||||
return fileName;
|
return fileName;
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "triskeleBase.hpp"
|
#include "triskeleBase.hpp"
|
||||||
#include "triskeleDebug.hpp"
|
#include "triskeleDebug.hpp"
|
||||||
|
#include "Border.hpp"
|
||||||
|
|
||||||
namespace otb {
|
namespace otb {
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
@ -121,8 +122,8 @@ namespace otb {
|
|||||||
|
|
||||||
bool compareTo (const Tree &tree, bool testChildren = false) const;
|
bool compareTo (const Tree &tree, bool testChildren = false) const;
|
||||||
|
|
||||||
void checkSpare () const;
|
void checkSpare (const Border& border) const;
|
||||||
void check () const;
|
void check (const Border& border) const;
|
||||||
// XXX void checkWeightCurve (bool incr) const;
|
// XXX void checkWeightCurve (bool incr) const;
|
||||||
|
|
||||||
// nice ostream
|
// nice ostream
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <boost/accumulators/statistics/max.hpp>
|
#include <boost/accumulators/statistics/max.hpp>
|
||||||
#include <boost/accumulators/statistics/mean.hpp>
|
#include <boost/accumulators/statistics/mean.hpp>
|
||||||
|
|
||||||
|
#include "triskeleDebug.hpp"
|
||||||
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
||||||
|
|
||||||
namespace otb {
|
namespace otb {
|
||||||
@ -37,6 +38,7 @@ namespace otb {
|
|||||||
buildParentsStats,
|
buildParentsStats,
|
||||||
buildFromTilesStats,
|
buildFromTilesStats,
|
||||||
buildMergeStats,
|
buildMergeStats,
|
||||||
|
buildForestStats,
|
||||||
buildIndexStats,
|
buildIndexStats,
|
||||||
buildCompressStats,
|
buildCompressStats,
|
||||||
buildChildrenStats,
|
buildChildrenStats,
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
|
#include "triskeleDebug.hpp"
|
||||||
|
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
|
|
||||||
template<typename DimImg, typename FunctId>
|
template<typename DimImg, typename FunctId>
|
||||||
|
@ -71,7 +71,7 @@ dealThread (const DimImg &maxId, unsigned int coreCount, const FunctThreadMinMax
|
|||||||
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
|
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
|
||||||
});
|
});
|
||||||
#else /* BOOST thread */
|
#else /* BOOST thread */
|
||||||
boost::thread tasks [coreCount];
|
std::vector<boost::thread> tasks;
|
||||||
for (unsigned int idCopyValInThread = 0; idCopyValInThread < coreCount; ++idCopyValInThread) {
|
for (unsigned int idCopyValInThread = 0; idCopyValInThread < coreCount; ++idCopyValInThread) {
|
||||||
tasks.push_back (boost::thread ([/*no ref!!!*/idCopyValInThread, &maxIds, &functThreadMinMax] () {
|
tasks.push_back (boost::thread ([/*no ref!!!*/idCopyValInThread, &maxIds, &functThreadMinMax] () {
|
||||||
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
|
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
|
||||||
@ -106,37 +106,37 @@ callOnSortedSets (const std::vector<DimImg> &sizes,
|
|||||||
// get min
|
// get min
|
||||||
bool found = false;
|
bool found = false;
|
||||||
DimImg minVectIdx = 0;
|
DimImg minVectIdx = 0;
|
||||||
WeightT minWeight = 0;
|
WeightT maxWeight = 0;
|
||||||
for (DimImg vectId = 0; vectId < size; ++vectId) {
|
for (DimImg vectId = 0; vectId < size; ++vectId) {
|
||||||
if (!vectCounts [vectId])
|
if (!vectCounts [vectId])
|
||||||
continue;
|
continue;
|
||||||
WeightT tmpWeight = getWeight (vectId, 0);
|
WeightT tmpWeight = getWeight (vectId, 0);
|
||||||
if (found && !isWeightInf (tmpWeight, minWeight))
|
if (found && !isWeightInf (tmpWeight, maxWeight))
|
||||||
continue;
|
continue;
|
||||||
minVectIdx = vectId;
|
minVectIdx = vectId;
|
||||||
minWeight = tmpWeight;
|
maxWeight = tmpWeight;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
LOG ("found:" << found << " minVectIdx:" << minVectIdx << " minWeight:" << minWeight);
|
LOG ("found:" << found << " minVectIdx:" << minVectIdx << " maxWeight:" << maxWeight);
|
||||||
// loop
|
// loop
|
||||||
for ( ; found; ) {
|
for ( ; found; ) {
|
||||||
// get next min
|
// get next min
|
||||||
found = false;
|
found = false;
|
||||||
DimImg nextMinVectIdx = 0;
|
DimImg nextMinVectIdx = 0;
|
||||||
WeightT nextMinWeight = 0;
|
WeightT nextMaxWeight = 0;
|
||||||
for (DimImg vectId = minVectIdx; ; ) {
|
for (DimImg vectId = minVectIdx; ; ) {
|
||||||
if (vectCounts [vectId]) {
|
if (vectCounts [vectId]) {
|
||||||
WeightT tmpWeight = getWeight (vectId, vectIds [vectId]);
|
WeightT tmpWeight = getWeight (vectId, vectIds [vectId]);
|
||||||
if (!isWeightInf (minWeight, tmpWeight)) {
|
if (!isWeightInf (maxWeight, tmpWeight)) {
|
||||||
// minWeight == tmpWeight
|
// maxWeight == tmpWeight
|
||||||
callIdId (vectId, vectIds [vectId]);
|
callIdId (vectId, vectIds [vectId]);
|
||||||
++vectIds [vectId];
|
++vectIds [vectId];
|
||||||
--vectCounts [vectId];
|
--vectCounts [vectId];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!found || isWeightInf (tmpWeight, nextMinWeight)) {
|
if (!found || isWeightInf (tmpWeight, nextMaxWeight)) {
|
||||||
nextMinVectIdx = vectId;
|
nextMinVectIdx = vectId;
|
||||||
nextMinWeight = tmpWeight;
|
nextMaxWeight = tmpWeight;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ callOnSortedSets (const std::vector<DimImg> &sizes,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
minVectIdx = nextMinVectIdx;
|
minVectIdx = nextMinVectIdx;
|
||||||
minWeight = nextMinWeight;
|
maxWeight = nextMaxWeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
#include <boost/chrono.hpp>
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_SMART_LOG
|
#ifdef ENABLE_SMART_LOG
|
||||||
|
|
||||||
@ -18,7 +20,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SMART_LOG_EXPR
|
#ifndef SMART_LOG_EXPR
|
||||||
#define SMART_LOG_EXPR(expr) {if (triskele::debug) {expr;} }
|
#define SMART_LOG_EXPR(expr) {if (::triskele::debug) {expr;} }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -52,15 +54,15 @@
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
#ifndef DEF_LOG
|
#ifndef DEF_LOG
|
||||||
#define DEF_LOG(name, expr) ::triskele::Log log (name); { if (triskele::debug) cerr << expr << endl << flush; }
|
#define DEF_LOG(name, expr) ::triskele::Log log (name); { if (::triskele::debug) cerr << expr << endl << flush; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef LOG
|
#ifndef LOG
|
||||||
#define LOG(expr) { if (triskele::debug) cerr << log << "| " << expr << endl << flush; }
|
#define LOG(expr) { if (::triskele::debug) cerr << log << "| " << expr << endl << flush; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
#define DEBUG(expr) { if (triskele::debug) cerr << expr << endl << flush; }
|
#define DEBUG(expr) { if (::triskele::debug) cerr << expr << endl << flush; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -94,14 +96,18 @@ namespace triskele {
|
|||||||
static unsigned int indent;
|
static unsigned int indent;
|
||||||
string functName;
|
string functName;
|
||||||
public:
|
public:
|
||||||
Log (const string &functName) : functName (functName) { ++indent; if (triskele::debug) cerr << *this << "> "; }
|
Log (const string &functName) : functName (functName) { ++indent; if (::triskele::debug) cerr << *this << "> "; }
|
||||||
~Log () { if (triskele::debug) cerr << *this << "<" << endl << flush; --indent; }
|
~Log () { if (::triskele::debug) cerr << *this << "<" << endl << flush; --indent; }
|
||||||
friend inline ostream &operator << (ostream &out, const Log &log) {
|
friend inline ostream &operator << (ostream &out, const Log &log) {
|
||||||
return out << getLocalTimeStr () << setw (3) << setw ((log.indent % 20)*2) << "" << log.functName;
|
return out << getLocalTimeStr () << setw (3) << setw ((log.indent % 20)*2) << "" << log.functName;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline string ns2string (double delta);
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
|
#include "triskeleDebug.tpp"
|
||||||
|
|
||||||
}//namespace triskele
|
}//namespace triskele
|
||||||
|
|
||||||
#endif //_TRISKELE_DEBUG_HPP
|
#endif //_TRISKELE_DEBUG_HPP
|
||||||
|
24
include/triskeleDebug.tpp
Normal file
24
include/triskeleDebug.tpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef _OTB_TRISKELE_DEBUG_TPP
|
||||||
|
#define _OTB_TRISKELE_DEBUG_TPP
|
||||||
|
|
||||||
|
string
|
||||||
|
ns2string (double delta) {
|
||||||
|
using namespace boost::chrono;
|
||||||
|
|
||||||
|
ostringstream oss;
|
||||||
|
duration<double> ns (delta);
|
||||||
|
oss.fill ('0');
|
||||||
|
// typedef duration<int, ratio<86400> > days;
|
||||||
|
// auto d = duration_cast<days>(ns);
|
||||||
|
// ns -= d;
|
||||||
|
auto h = duration_cast<hours> (ns);
|
||||||
|
ns -= h;
|
||||||
|
auto m = duration_cast<minutes> (ns);
|
||||||
|
ns -= m;
|
||||||
|
oss << setw (2) << h.count () << ":"
|
||||||
|
<< setw (2) << m.count () << ":"
|
||||||
|
<< setw (9) << fixed << setprecision (6) << ns.count ();
|
||||||
|
return oss.str ();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _OTB_TRISKELE_DEBUG_TPP
|
20
python/setup.py
Normal file
20
python/setup.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# \file setup.py
|
||||||
|
# \brief TODO
|
||||||
|
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||||
|
# \version 0.1
|
||||||
|
# \date 11 sept. 2018
|
||||||
|
#
|
||||||
|
# TODO details
|
||||||
|
|
||||||
|
from distutils.core import setup
|
||||||
|
|
||||||
|
setup(name='triskele',
|
||||||
|
version='1.0',
|
||||||
|
description='Python wrapper for Triskele',
|
||||||
|
author='Florent Guiotte',
|
||||||
|
author_email='florent.guiotte@uhb.fr',
|
||||||
|
url='https://git.guiotte.fr/Florent/Triskele',
|
||||||
|
packages=['triskele'],
|
||||||
|
)
|
@ -24,6 +24,10 @@ np_to_gdt = {
|
|||||||
def write(fname, X):
|
def write(fname, X):
|
||||||
"""X.shape = (length, width) or
|
"""X.shape = (length, width) or
|
||||||
X.shape = (length, width, samples)"""
|
X.shape = (length, width, samples)"""
|
||||||
|
|
||||||
|
fname = Path(fname)
|
||||||
|
if not fname.parent.exists():
|
||||||
|
raise IOError('Directory not found: {}'.format(fname.parent))
|
||||||
|
|
||||||
width = X.shape[1]
|
width = X.shape[1]
|
||||||
length = X.shape[0]
|
length = X.shape[0]
|
||||||
@ -38,7 +42,7 @@ def write(fname, X):
|
|||||||
dst_ds = driver.Create(str(fname), width, length, samples, np_to_gdt[X.dtype.type])
|
dst_ds = driver.Create(str(fname), width, length, samples, np_to_gdt[X.dtype.type])
|
||||||
|
|
||||||
for i in range(samples):
|
for i in range(samples):
|
||||||
dst_ds.GetRasterBand(i + 1).WriteArray(X[:,:,i].astype(np.uint8))
|
dst_ds.GetRasterBand(i + 1).WriteArray(X[:,:,i])
|
||||||
dst_ds.FlushCache()
|
dst_ds.FlushCache()
|
||||||
|
|
||||||
def read(fname):
|
def read(fname):
|
||||||
|
@ -37,8 +37,8 @@ class Triskele:
|
|||||||
|
|
||||||
self._write_infile(raster, dtype)
|
self._write_infile(raster, dtype)
|
||||||
|
|
||||||
def filter(self, tree='max-tree', area=None, standard_deviation=None, moment_of_inertia=None):
|
def filter(self, tree='max-tree', area=None, standard_deviation=None, moment_of_inertia=None, feature='weight'):
|
||||||
self._setup(tree, area, standard_deviation, moment_of_inertia)
|
self._setup(tree, area, standard_deviation, moment_of_inertia, feature)
|
||||||
self._run()
|
self._run()
|
||||||
return self._read_outfile()
|
return self._read_outfile()
|
||||||
|
|
||||||
@ -46,14 +46,14 @@ class Triskele:
|
|||||||
return read(self.outfile)
|
return read(self.outfile)
|
||||||
|
|
||||||
def _write_infile(self, rasters, dtype):
|
def _write_infile(self, rasters, dtype):
|
||||||
## Scale to new dtype
|
|
||||||
rep = np.iinfo(dtype)
|
|
||||||
|
|
||||||
## Expand if rasters is 2D
|
## Expand if rasters is 2D
|
||||||
if len(rasters.shape) < 3:
|
if len(rasters.shape) < 3:
|
||||||
rasters = np.expand_dims(rasters, 2)
|
rasters = np.expand_dims(rasters, 2)
|
||||||
|
|
||||||
rasters = rasters.astype(np.float32)
|
## Scale to new dtype
|
||||||
|
rep = np.iinfo(dtype)
|
||||||
|
|
||||||
|
rasters = rasters.astype(np.float64)
|
||||||
|
|
||||||
## Channel independant scale
|
## Channel independant scale
|
||||||
for i in range(rasters.shape[2]):
|
for i in range(rasters.shape[2]):
|
||||||
@ -63,11 +63,12 @@ class Triskele:
|
|||||||
rasters = rasters.astype(dtype)
|
rasters = rasters.astype(dtype)
|
||||||
write(self.infile, rasters)
|
write(self.infile, rasters)
|
||||||
|
|
||||||
def _setup(self, tree, area, standard_deviation, moment_of_inertia):
|
def _setup(self, tree, area, standard_deviation, moment_of_inertia, feature):
|
||||||
self.process = [self.triskele_bin,
|
self.process = [self.triskele_bin,
|
||||||
'-i', '{}'.format(self.infile),
|
'-i', '{}'.format(self.infile),
|
||||||
'-o', '{}'.format(self.outfile),
|
'-o', '{}'.format(self.outfile),
|
||||||
'--{}'.format(tree)]
|
'--{}'.format(tree),
|
||||||
|
'--f-{}'.format(feature)]
|
||||||
|
|
||||||
if area is not None:
|
if area is not None:
|
||||||
np.savetxt(self.areafile, area, fmt='%d')
|
np.savetxt(self.areafile, area, fmt='%d')
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#define LAST_VERSION "2018-03-29 (Debian Stretch)"
|
#define LAST_VERSION "1.1 2018-08-06 (Debian Stretch)"
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -97,26 +96,50 @@ Option::parse (int argc, char** argv) {
|
|||||||
bool helpFlag = false, versionFlag = false, useTheForceLuke = false;
|
bool helpFlag = false, versionFlag = false, useTheForceLuke = false;
|
||||||
string inputFileName, outputFileName, bandsRange;
|
string inputFileName, outputFileName, bandsRange;
|
||||||
long left = -1, top = -1, width = -1, height = -1;
|
long left = -1, top = -1, width = -1, height = -1;
|
||||||
string areaThresholdsName, sdThresholdsName, moiThresholdsName;
|
string areaThresholdsName, levelThresholdsName, sdThresholdsName, moiThresholdsName;
|
||||||
|
bool c4 = false, c6p = false, c6n = false, c8 = false;
|
||||||
|
bool weightFlag = false, meanFlag = false, sdFlag = false, areaFlag = false, moiFlag;
|
||||||
try {
|
try {
|
||||||
desc.add_options ()
|
desc.add_options ()
|
||||||
("help", po::bool_switch (&helpFlag), "produce this help message")
|
("help", po::bool_switch (&helpFlag), "produce this help message")
|
||||||
("version", po::bool_switch (&versionFlag), "display version information")
|
("version", po::bool_switch (&versionFlag), "display version information")
|
||||||
("debug", po::bool_switch (&debugFlag), "debug mode")
|
("debug", po::bool_switch (&debugFlag), "debug mode")
|
||||||
|
|
||||||
("band,b", po::value<string> (&bandsRange), "select input band (first band is 0) (default all bands : 0-*)")
|
("band,b", po::value<string> (&bandsRange), "select input band (first band is 0) (default all bands : 0-*)")
|
||||||
("left,x", po::value<long> (&left), "left crop (default center)")
|
("left,x", po::value<long> (&left), "left crop (default center)")
|
||||||
("top,y", po::value<long> (&top), "top crop (default middle)")
|
("top,y", po::value<long> (&top), "top crop (default middle)")
|
||||||
("width,w", po::value<long> (&width), "width crop (default input width)")
|
("width,w", po::value<long> (&width), "width crop (default input width)")
|
||||||
("height,h", po::value<long> (&height), "height crop (default input height)")
|
("height,h", po::value<long> (&height), "height crop (default input height)")
|
||||||
|
|
||||||
|
("border", po::bool_switch (&border), "build tree without border pixels (no-data)")
|
||||||
|
("C4", po::bool_switch (&c4), (string ("4-connected pixels")+
|
||||||
|
(connectivity == Connectivity::C4 ? " (default)" : "")).c_str ())
|
||||||
|
("C6P", po::bool_switch (&c6p), (string ("6-connected pixels (positive")+
|
||||||
|
(connectivity == Connectivity::C6P ? " (default)" : "")+")").c_str ())
|
||||||
|
("C6N", po::bool_switch (&c6n), (string ("6-connected pixels (negative")+
|
||||||
|
(connectivity == Connectivity::C6N ? " (default)" : "")+")").c_str ())
|
||||||
|
("C8", po::bool_switch (&c8), (string ("8-connected pixels")+
|
||||||
|
(connectivity == Connectivity::C8 ? " (default)" : "")).c_str ())
|
||||||
|
|
||||||
("input,i", po::value<string> (&inputFileName), "input file name image")
|
("input,i", po::value<string> (&inputFileName), "input file name image")
|
||||||
("output,o", po::value<string> (&outputFileName), "output file name hyperbands image (contains attributs profiles)")
|
("output,o", po::value<string> (&outputFileName), "output file name hyperbands image (contains attributs profiles)")
|
||||||
|
|
||||||
("max-tree", po::bool_switch (&maxTreeFlag), "build max-tree")
|
("max-tree", po::bool_switch (&maxTreeFlag), "build max-tree")
|
||||||
("min-tree", po::bool_switch (&minTreeFlag), "build min-tree")
|
("min-tree", po::bool_switch (&minTreeFlag), "build min-tree")
|
||||||
("tos-tree", po::bool_switch (&tosTreeFlag), "build tree-of-shape")
|
("tos-tree", po::bool_switch (&tosTreeFlag), "build tree-of-shape")
|
||||||
("alpha-tree", po::bool_switch (&alphaTreeFlag), "build alpha-tree")
|
("alpha-tree", po::bool_switch (&alphaTreeFlag), "build alpha-tree")
|
||||||
("area,A", po::value<string> (&areaThresholdsName), "produce area attributs")
|
|
||||||
("standard-deviation,S", po::value<string> (&sdThresholdsName), "produce standard deviation attributs")
|
("f-weight", po::bool_switch (&weightFlag), "produce attribut profiles (default)")
|
||||||
("moment-of-inertia,M", po::value<string> (&moiThresholdsName), "produce moment of inertia attributs")
|
// ("f-level,FPL", po::bool_switch (&weightFlag), "produce feature profiles level")
|
||||||
|
("f-mean", po::bool_switch (&meanFlag), "produce feature profiles mean")
|
||||||
|
("f-SD", po::bool_switch (&sdFlag), "produce feature profiles SD")
|
||||||
|
("f-area", po::bool_switch (&areaFlag), "produce feature profiles area")
|
||||||
|
("f-MOI", po::bool_switch (&moiFlag), "produce feature profiles area")
|
||||||
|
|
||||||
|
("area,A", po::value<string> (&areaThresholdsName), "cut according area attributs")
|
||||||
|
("weight,W", po::value<string> (&levelThresholdsName), "cut according level attributs")
|
||||||
|
("standard-deviation,S", po::value<string> (&sdThresholdsName), "cut according standard deviation attributs")
|
||||||
|
("moment-of-inertia,M", po::value<string> (&moiThresholdsName), "cut according moment of inertia attributs")
|
||||||
;
|
;
|
||||||
hide.add_options ()
|
hide.add_options ()
|
||||||
("use-the-force-luke", po::bool_switch (&useTheForceLuke), "display hidded options")
|
("use-the-force-luke", po::bool_switch (&useTheForceLuke), "display hidded options")
|
||||||
@ -186,6 +209,7 @@ Option::parse (int argc, char** argv) {
|
|||||||
usage ("Bad options");
|
usage ("Bad options");
|
||||||
}
|
}
|
||||||
areaThresholds = readThresholds<DimImg> (areaThresholdsName);
|
areaThresholds = readThresholds<DimImg> (areaThresholdsName);
|
||||||
|
levelThresholds = readThresholds<double> (levelThresholdsName);
|
||||||
sdThresholds = readThresholds<double> (sdThresholdsName);
|
sdThresholds = readThresholds<double> (sdThresholdsName);
|
||||||
moiThresholds = readThresholds<double> (moiThresholdsName);
|
moiThresholds = readThresholds<double> (moiThresholdsName);
|
||||||
|
|
||||||
@ -217,6 +241,32 @@ Option::parse (int argc, char** argv) {
|
|||||||
topLeft = Point ((DimSideImg) left, (DimSideImg) top);
|
topLeft = Point ((DimSideImg) left, (DimSideImg) top);
|
||||||
size = Size ((DimSideImg) width, (DimSideImg) height);
|
size = Size ((DimSideImg) width, (DimSideImg) height);
|
||||||
|
|
||||||
|
int connectivityCount = c4 + c6n + c6p + c8;
|
||||||
|
if (connectivityCount > 1)
|
||||||
|
usage ("You must choose only one connectivity model");
|
||||||
|
if (c6p)
|
||||||
|
connectivity = Connectivity::C6P;
|
||||||
|
else if (c6n)
|
||||||
|
connectivity = Connectivity::C6N;
|
||||||
|
else if (c8)
|
||||||
|
connectivity = Connectivity::C8;
|
||||||
|
else
|
||||||
|
connectivity = Connectivity::C4;
|
||||||
|
|
||||||
|
int featureCount = weightFlag + meanFlag + sdFlag + areaFlag + moiFlag;
|
||||||
|
if (featureCount > 1)
|
||||||
|
usage ("You must choose only one feature attribut profile");
|
||||||
|
if (meanFlag)
|
||||||
|
featureType = FeatureType::MEAN;
|
||||||
|
if (sdFlag)
|
||||||
|
featureType = FeatureType::SD;
|
||||||
|
if (areaFlag)
|
||||||
|
featureType = FeatureType::AREA;
|
||||||
|
if (moiFlag)
|
||||||
|
featureType = FeatureType::MOI;
|
||||||
|
else
|
||||||
|
featureType = FeatureType::AP;
|
||||||
|
|
||||||
cout
|
cout
|
||||||
<< "Input:" << inputFileName << " " << orgSize << " (" << bandInputCount << " chanels of " << GDALGetDataTypeName (inputType) << ")" << endl
|
<< "Input:" << inputFileName << " " << orgSize << " (" << bandInputCount << " chanels of " << GDALGetDataTypeName (inputType) << ")" << endl
|
||||||
<< "Crop topLeft:" << topLeft << " size:" << size << " band:" << selectedBand << endl
|
<< "Crop topLeft:" << topLeft << " size:" << size << " band:" << selectedBand << endl
|
||||||
|
@ -14,5 +14,5 @@ otb::triskele::arrayTree::tileItemName[] = {
|
|||||||
|
|
||||||
std::string
|
std::string
|
||||||
otb::triskele::arrayTree::treeTypeLabels[] = {
|
otb::triskele::arrayTree::treeTypeLabels[] = {
|
||||||
"min", "max", "tos"
|
"min", "max", "tos", "alpha"
|
||||||
};
|
};
|
||||||
|
@ -11,10 +11,11 @@ size_t
|
|||||||
IImage::gdalCount = 0;
|
IImage::gdalCount = 0;
|
||||||
|
|
||||||
IImage::IImage (const string &imageFileName)
|
IImage::IImage (const string &imageFileName)
|
||||||
: fileName (imageFileName),
|
: geoTransform (6, 0),
|
||||||
read (false),
|
fileName (imageFileName),
|
||||||
gdalInputDataset (nullptr),
|
gdalInputDataset (nullptr),
|
||||||
gdalOutputDataset (nullptr)
|
gdalOutputDataset (nullptr),
|
||||||
|
read (false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ IImage::~IImage () {
|
|||||||
|
|
||||||
void
|
void
|
||||||
IImage::readImage () {
|
IImage::readImage () {
|
||||||
DEF_LOG ("IImage::readImage", "fileName: " << fileName);
|
DEF_LOG ("IImage::readImage", "fileName: " << fileName << " c_str:" << fileName.c_str ());
|
||||||
BOOST_ASSERT (gdalInputDataset == nullptr);
|
BOOST_ASSERT (gdalInputDataset == nullptr);
|
||||||
BOOST_ASSERT (gdalOutputDataset == nullptr);
|
BOOST_ASSERT (gdalOutputDataset == nullptr);
|
||||||
close ();
|
close ();
|
||||||
@ -36,11 +37,18 @@ IImage::readImage () {
|
|||||||
cerr << "GDALError: can't define dataset" << endl;
|
cerr << "GDALError: can't define dataset" << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = Size (gdalInputDataset->GetRasterXSize (),
|
size = Size (gdalInputDataset->GetRasterXSize (),
|
||||||
gdalInputDataset->GetRasterYSize ());
|
gdalInputDataset->GetRasterYSize ());
|
||||||
bandCount = gdalInputDataset->GetRasterCount ();
|
bandCount = gdalInputDataset->GetRasterCount ();
|
||||||
LOG ("size: " << size << " x " << bandCount);
|
LOG ("size: " << size << " x " << bandCount);
|
||||||
read = true;
|
read = true;
|
||||||
|
projectionRef = gdalInputDataset->GetProjectionRef ();
|
||||||
|
CPLErr err = gdalInputDataset->GetGeoTransform (&geoTransform[0]);
|
||||||
|
if (err != CE_None)
|
||||||
|
cerr << "IImage::readImage: can't read geoTransform from " << fileName << endl;
|
||||||
|
else
|
||||||
|
LOG ("geoTransform: " << geoTransform [0] << " " << geoTransform [1] << " " << geoTransform [2] << " " << geoTransform [3] << " " << geoTransform [4] << " " << geoTransform [5]);
|
||||||
|
|
||||||
for (DimChanel band = 0; band < bandCount; ++band) {
|
for (DimChanel band = 0; band < bandCount; ++band) {
|
||||||
GDALRasterBand &poBand = *gdalInputDataset->GetRasterBand (band+1);
|
GDALRasterBand &poBand = *gdalInputDataset->GetRasterBand (band+1);
|
||||||
@ -81,14 +89,25 @@ IImage::createImage (const Size &size, const GDALDataType &dataType, const DimCh
|
|||||||
GDALDriver *driverTiff = GetGDALDriverManager ()->GetDriverByName ("GTiff");
|
GDALDriver *driverTiff = GetGDALDriverManager ()->GetDriverByName ("GTiff");
|
||||||
remove (fileName.c_str ());
|
remove (fileName.c_str ());
|
||||||
gdalOutputDataset = driverTiff->Create (fileName.c_str (), size.width, size.height, nbBands, dataType, NULL);
|
gdalOutputDataset = driverTiff->Create (fileName.c_str (), size.width, size.height, nbBands, dataType, NULL);
|
||||||
|
|
||||||
LOG("gdalCount: " << gdalCount);
|
LOG("gdalCount: " << gdalCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
IImage::createImage (const Size &size, const GDALDataType &dataType, const DimChanel &nbBands,
|
||||||
|
const IImage &inputImage, const Point &topLeft)
|
||||||
|
{
|
||||||
|
createImage (size, dataType, nbBands);
|
||||||
|
string projectionRef;
|
||||||
|
vector<double> geoTransform;
|
||||||
|
inputImage.getGeo (projectionRef, geoTransform);
|
||||||
|
setGeo (projectionRef, geoTransform, topLeft);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
IImage::close () {
|
IImage::close () {
|
||||||
DEF_LOG ("IImage::close", "fileName: " << fileName);
|
DEF_LOG ("IImage::close", "fileName: " << fileName);
|
||||||
if (gdalOutputDataset) {
|
if (gdalOutputDataset) {
|
||||||
// XXX pour écriture gdalOutputDataset->SetProjection ("WGS84");
|
|
||||||
GDALClose (gdalOutputDataset);
|
GDALClose (gdalOutputDataset);
|
||||||
gdalOutputDataset = nullptr;
|
gdalOutputDataset = nullptr;
|
||||||
if (!--gdalCount)
|
if (!--gdalCount)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "triskeleDebug.hpp"
|
#include "triskeleDebug.hpp"
|
||||||
#include "triskeleBase.hpp"
|
#include "triskeleBase.hpp"
|
||||||
|
#include "Border.hpp"
|
||||||
#include "Tree.hpp"
|
#include "Tree.hpp"
|
||||||
#include "TreeStats.hpp"
|
#include "TreeStats.hpp"
|
||||||
#include "TreeBuilder.hpp"
|
#include "TreeBuilder.hpp"
|
||||||
@ -12,7 +13,6 @@
|
|||||||
#include "AttributeProfiles.hpp"
|
#include "AttributeProfiles.hpp"
|
||||||
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
||||||
#include "ArrayTree/triskeleSort.hpp"
|
#include "ArrayTree/triskeleSort.hpp"
|
||||||
#include "ArrayTree/Border.hpp"
|
|
||||||
#include "ArrayTree/GraphWalker.hpp"
|
#include "ArrayTree/GraphWalker.hpp"
|
||||||
#include "ArrayTree/Leader.hpp"
|
#include "ArrayTree/Leader.hpp"
|
||||||
#include "ArrayTree/Weight.hpp"
|
#include "ArrayTree/Weight.hpp"
|
||||||
@ -33,14 +33,14 @@ perf (const Raster<PixelT> &raster, const GraphWalker &graphWalker, const TreeTy
|
|||||||
Tree tree (coreCount);
|
Tree tree (coreCount);
|
||||||
WeightAttributes<PixelT> weightAttributes (tree);
|
WeightAttributes<PixelT> weightAttributes (tree);
|
||||||
atb.buildTree (tree, weightAttributes);
|
atb.buildTree (tree, weightAttributes);
|
||||||
tree.check ();
|
tree.check (graphWalker.border);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
int
|
int
|
||||||
main (int argc, char **argv, char **envp) {
|
main (int argc, char **argv, char **envp) {
|
||||||
if (argc != 5) {
|
if (argc != 5) {
|
||||||
cerr << "Usage: " << argv[0] << ": treeType coreCount nbTest imageSize" << endl;
|
cerr << "Usage: " << argv[0] << ": {MIN|MAX|TOS|ALPHA} coreCount nbTest imageSize" << endl;
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
string argType (argv[1]);
|
string argType (argv[1]);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "triskeleDebug.hpp"
|
#include "triskeleDebug.hpp"
|
||||||
#include "triskeleBase.hpp"
|
#include "triskeleBase.hpp"
|
||||||
|
#include "Border.hpp"
|
||||||
#include "Tree.hpp"
|
#include "Tree.hpp"
|
||||||
#include "TreeStats.hpp"
|
#include "TreeStats.hpp"
|
||||||
#include "TreeBuilder.hpp"
|
#include "TreeBuilder.hpp"
|
||||||
@ -12,7 +13,6 @@
|
|||||||
#include "AttributeProfiles.hpp"
|
#include "AttributeProfiles.hpp"
|
||||||
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
||||||
#include "ArrayTree/triskeleSort.hpp"
|
#include "ArrayTree/triskeleSort.hpp"
|
||||||
#include "ArrayTree/Border.hpp"
|
|
||||||
#include "ArrayTree/GraphWalker.hpp"
|
#include "ArrayTree/GraphWalker.hpp"
|
||||||
#include "ArrayTree/Leader.hpp"
|
#include "ArrayTree/Leader.hpp"
|
||||||
#include "ArrayTree/Weight.hpp"
|
#include "ArrayTree/Weight.hpp"
|
||||||
@ -23,9 +23,9 @@ using namespace otb::triskele;
|
|||||||
using namespace otb::triskele::arrayTree;
|
using namespace otb::triskele::arrayTree;
|
||||||
|
|
||||||
|
|
||||||
const unsigned int nbTest = 1000;
|
const unsigned int nbTest = 1; // 1000;
|
||||||
const TreeType treeType = ALPHA; // TOS; // MIN; // MAX;
|
const TreeType treeType = MIN; // ALPHA; // TOS; // MIN; // MAX;
|
||||||
const unsigned int coreCount = 4;
|
const unsigned int coreCount = 2;
|
||||||
|
|
||||||
typedef uint16_t PixelT;
|
typedef uint16_t PixelT;
|
||||||
typedef uint16_t WeightT;
|
typedef uint16_t WeightT;
|
||||||
@ -92,7 +92,7 @@ PixelT pixelsB3 [] = { //) parents[0]:0 parentId:6 level child:0 parent:0 parent
|
|||||||
5, 1, 7, 2, 4, 1,
|
5, 1, 7, 2, 4, 1,
|
||||||
6, 6, 4, 6, 1, 5
|
6, 6, 4, 6, 1, 5
|
||||||
};
|
};
|
||||||
PixelT pixelsC1 [] = { //A) childIdx:26 parentId:1 parentIdx:25 rootId:9
|
PixelT pixelsC1_6x4 [] = { //A) childIdx:26 parentId:1 parentIdx:25 rootId:9
|
||||||
6, 1, 7, 7, 3, 3,
|
6, 1, 7, 7, 3, 3,
|
||||||
0, 3, 0, 0, 6, 4,
|
0, 3, 0, 0, 6, 4,
|
||||||
3, 3, 4, 6, 7, 4,
|
3, 3, 4, 6, 7, 4,
|
||||||
@ -208,23 +208,31 @@ PixelT pixelsT7_12x8 [] = {
|
|||||||
// ========================================
|
// ========================================
|
||||||
void test () {
|
void test () {
|
||||||
//Size size (6, 4);
|
//Size size (6, 4);
|
||||||
//Size size (18, 12);
|
// Size size (18, 12);
|
||||||
Size size (12, 8);
|
Size size (12, 8);
|
||||||
Border border (size, false);
|
Border border (size, false);
|
||||||
|
border.setBorder (1);
|
||||||
|
//border.setBorder (12);
|
||||||
|
border.setBorder (13);
|
||||||
|
border.setBorder (24);
|
||||||
|
border.setBorder (25);
|
||||||
|
|
||||||
GraphWalker graphWalker (border);
|
GraphWalker graphWalker (border);
|
||||||
int leafCount = graphWalker.vertexMaxCount ();
|
int leafCount = graphWalker.vertexMaxCount ();
|
||||||
|
|
||||||
// ====================
|
// ====================
|
||||||
|
// PixelT *pixels = pixelsC1_6x4;
|
||||||
|
|
||||||
// PixelT *pixels = pixelsT1_18x12;
|
// PixelT *pixels = pixelsT1_18x12;
|
||||||
// PixelT *pixels = pixelsT2_12x8;
|
// PixelT *pixels = pixelsT2_12x8;
|
||||||
// PixelT *pixels = pixelsT3_12x8;
|
// PixelT *pixels = pixelsT3_12x8;
|
||||||
// PixelT *pixels = pixelsT4_12x8;
|
// PixelT *pixels = pixelsT4_12x8;
|
||||||
// PixelT *pixels = pixelsT5_12x8;
|
PixelT *pixels = pixelsT5_12x8;
|
||||||
// PixelT *pixels = pixelsT6_12x8;
|
// PixelT *pixels = pixelsT6_12x8;
|
||||||
// PixelT *pixels = pixelsT7_12x8;
|
// PixelT *pixels = pixelsT7_12x8;
|
||||||
PixelT *pixels = new PixelT [leafCount];
|
// PixelT *pixels = new PixelT [leafCount];
|
||||||
for (int i = 0; i < leafCount; ++i)
|
// for (int i = 0; i < leafCount; ++i)
|
||||||
pixels[i] = std::rand() % 8;
|
// pixels[i] = std::rand() % 8;
|
||||||
// ====================
|
// ====================
|
||||||
|
|
||||||
Raster<PixelT> raster (size);
|
Raster<PixelT> raster (size);
|
||||||
@ -246,7 +254,7 @@ void test () {
|
|||||||
Tree tree (coreCount);
|
Tree tree (coreCount);
|
||||||
WeightAttributes<PixelT> weightAttributes (tree);
|
WeightAttributes<PixelT> weightAttributes (tree);
|
||||||
atb.buildTree (tree, weightAttributes);
|
atb.buildTree (tree, weightAttributes);
|
||||||
tree.check ();
|
tree.check (border);
|
||||||
|
|
||||||
AttributeProfiles<PixelT> attributeProfiles (tree);
|
AttributeProfiles<PixelT> attributeProfiles (tree);
|
||||||
atb.setAttributProfiles (attributeProfiles);
|
atb.setAttributProfiles (attributeProfiles);
|
||||||
|
46
src/Tree.cpp
46
src/Tree.cpp
@ -1,5 +1,5 @@
|
|||||||
#include "Tree.hpp"
|
#include "Tree.hpp"
|
||||||
#include "ArrayTree/Border.hpp"
|
#include "Border.hpp"
|
||||||
#include "ArrayTree/GraphWalker.hpp"
|
#include "ArrayTree/GraphWalker.hpp"
|
||||||
|
|
||||||
using namespace otb::triskele;
|
using namespace otb::triskele;
|
||||||
@ -7,21 +7,21 @@ using namespace otb::triskele::arrayTree;
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Tree::Tree (const DimSideImg &width, const DimSideImg &height, unsigned int coreCount)
|
Tree::Tree (const DimSideImg &width, const DimSideImg &height, unsigned int coreCount)
|
||||||
: Tree (coreCount)
|
: Tree(coreCount)
|
||||||
{
|
{
|
||||||
resize (width, height);
|
resize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tree::Tree (unsigned int coreCount)
|
Tree::Tree (unsigned int coreCount)
|
||||||
: size (),
|
: coreCount(coreCount),
|
||||||
coreCount (coreCount),
|
size(),
|
||||||
leafCount (0),
|
leafCount(0),
|
||||||
nodeCount (0),
|
nodeCount(0),
|
||||||
leafParents (),
|
leafParents(),
|
||||||
compParents (nullptr),
|
compParents(nullptr),
|
||||||
children (),
|
childrenStart(),
|
||||||
childrenStart (),
|
children(),
|
||||||
state (State::Void)
|
state(State::Void)
|
||||||
{
|
{
|
||||||
clear ();
|
clear ();
|
||||||
}
|
}
|
||||||
@ -170,8 +170,7 @@ Tree::compareTo (const Tree &tree, bool testChildren) const {
|
|||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
void
|
void
|
||||||
Tree::checkSpare () const {
|
Tree::checkSpare (const Border &border) const {
|
||||||
Border border; // default = no border
|
|
||||||
GraphWalker graphWalker (border);
|
GraphWalker graphWalker (border);
|
||||||
vector<Rect> tiles;
|
vector<Rect> tiles;
|
||||||
vector<Rect> boundaries;
|
vector<Rect> boundaries;
|
||||||
@ -195,7 +194,7 @@ Tree::checkSpare () const {
|
|||||||
maxParent = leafParents[leafId];
|
maxParent = leafParents[leafId];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
DimImg *childCount = (DimImg*)&childrenStart[2];
|
// DimImg *childCount = (DimImg*)&childrenStart[2]; // Only used for the assert (so put to comment to prevent warnings)
|
||||||
for (unsigned int i = 0; i < tileCount; ++i) {
|
for (unsigned int i = 0; i < tileCount; ++i) {
|
||||||
DimImg base = vertexMaxBounds [i], maxParent = maxParents [i];
|
DimImg base = vertexMaxBounds [i], maxParent = maxParents [i];
|
||||||
for (DimImg compId = base; compId < maxParent; ++compId) {
|
for (DimImg compId = base; compId < maxParent; ++compId) {
|
||||||
@ -203,7 +202,8 @@ Tree::checkSpare () const {
|
|||||||
BOOST_ASSERT (compParents[compId] != compId);
|
BOOST_ASSERT (compParents[compId] != compId);
|
||||||
BOOST_ASSERT (compParents[compId] < maxParent);
|
BOOST_ASSERT (compParents[compId] < maxParent);
|
||||||
if (compParents[compId] < compId)
|
if (compParents[compId] < compId)
|
||||||
BOOST_ASSERT (childCount[compParents[compId]] > childCount[compId]);
|
BOOST_ASSERT (childrenStart[2 + compParents[compId]] > childrenStart[2 + compId]);
|
||||||
|
//BOOST_ASSERT (childCount[compParents[compId]] > childCount[compId]); // Edited line to prevent the "Unused variable" warning
|
||||||
}
|
}
|
||||||
BOOST_ASSERT (compParents[maxParent] == DimImg_MAX);
|
BOOST_ASSERT (compParents[maxParent] == DimImg_MAX);
|
||||||
}
|
}
|
||||||
@ -228,11 +228,12 @@ Tree::checkSpare () const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Tree::check () const {
|
Tree::check (const Border& border) const {
|
||||||
|
GraphWalker graphWalker (border);
|
||||||
DimImg compCount = getCompCount ();
|
DimImg compCount = getCompCount ();
|
||||||
BOOST_ASSERT (compCount < leafCount);
|
BOOST_ASSERT (compCount < leafCount);
|
||||||
// check parents
|
// check parents
|
||||||
forEachLeaf ([this, &compCount] (const DimImg &leafId) {
|
graphWalker.forEachVertexIdx ([this, &compCount] (const DimImg &leafId) {
|
||||||
// XXX si border => leafParents [leafId] == DimImg_MAX
|
// XXX si border => leafParents [leafId] == DimImg_MAX
|
||||||
BOOST_ASSERT (leafParents[leafId] < compCount);
|
BOOST_ASSERT (leafParents[leafId] < compCount);
|
||||||
});
|
});
|
||||||
@ -296,8 +297,8 @@ Tree::check () const {
|
|||||||
BOOST_ASSERT (children[childId-1] < children[childId]);
|
BOOST_ASSERT (children[childId-1] < children[childId]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (DimImg child = 0; child < nodeCount-1; ++child)
|
for (DimNodeId child = 0; child < nodeCount-1; ++child)
|
||||||
BOOST_ASSERT (childrenMap [child] != DimImg_MAX);
|
BOOST_ASSERT (childrenMap [child] != DimImg_MAX || (child < leafCount && border.isBorder (child)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,10 +320,11 @@ Tree::CPrintTree::print (ostream &out) const {
|
|||||||
if (!onRecord)
|
if (!onRecord)
|
||||||
out << printMap (&tree.children[0], doubleSize, nodeCount-1) << endl << endl;
|
out << printMap (&tree.children[0], doubleSize, nodeCount-1) << endl << endl;
|
||||||
if (tree.weightBounds.size ()) {
|
if (tree.weightBounds.size ()) {
|
||||||
out << "weightBounds: " << endl
|
return out << "weightBounds: " << endl
|
||||||
<< printMap (&tree.weightBounds[0], tree.size, tree.weightBounds.size ()) << endl << endl;
|
<< printMap (&tree.weightBounds[0], tree.size, tree.weightBounds.size ()) << endl << endl;
|
||||||
} else
|
} else
|
||||||
return out << "no weightBounds" << endl << endl;
|
return out << "no weightBounds" << endl << endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Tree::CPrintTree
|
Tree::CPrintTree
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include <boost/chrono.hpp>
|
|
||||||
|
|
||||||
#include "TreeStats.hpp"
|
#include "TreeStats.hpp"
|
||||||
|
|
||||||
using namespace otb::triskele;
|
using namespace otb::triskele;
|
||||||
@ -16,6 +14,7 @@ static string timeTypeLabels [TimeTypeCard] = {
|
|||||||
" parents ",
|
" parents ",
|
||||||
" from tiles ",
|
" from tiles ",
|
||||||
" merge ",
|
" merge ",
|
||||||
|
" forest mgt. ",
|
||||||
" index ",
|
" index ",
|
||||||
" compress ",
|
" compress ",
|
||||||
" children ",
|
" children ",
|
||||||
@ -46,26 +45,6 @@ TreeStats::reset () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
using namespace boost::chrono;
|
|
||||||
inline string
|
|
||||||
ns2string (double delta) {
|
|
||||||
ostringstream oss;
|
|
||||||
duration<double> ns (delta);
|
|
||||||
oss.fill ('0');
|
|
||||||
// typedef duration<int, ratio<86400> > days;
|
|
||||||
// auto d = duration_cast<days>(ns);
|
|
||||||
// ns -= d;
|
|
||||||
auto h = duration_cast<hours> (ns);
|
|
||||||
ns -= h;
|
|
||||||
auto m = duration_cast<minutes> (ns);
|
|
||||||
ns -= m;
|
|
||||||
oss << setw (2) << h.count () << ":"
|
|
||||||
<< setw (2) << m.count () << ":"
|
|
||||||
<< setw (9) << fixed << setprecision (6) << ns.count ();
|
|
||||||
return oss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------
|
|
||||||
TreeStats::CPrintDim::CPrintDim (const TreeStats &treeStats)
|
TreeStats::CPrintDim::CPrintDim (const TreeStats &treeStats)
|
||||||
: treeStats (treeStats) {
|
: treeStats (treeStats) {
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<#include "XMLTree/XMLTreeBuilder.hpp"
|
#include "XMLTree/XMLTreeBuilder.hpp"
|
||||||
|
|
||||||
using namespace otb::triskele;
|
using namespace otb::triskele;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "triskeleDebug.hpp"
|
#include "triskeleDebug.hpp"
|
||||||
#include "triskeleBase.hpp"
|
#include "triskeleBase.hpp"
|
||||||
|
#include "Border.hpp"
|
||||||
#include "Appli/Option.hpp"
|
#include "Appli/Option.hpp"
|
||||||
#include "Tree.hpp"
|
#include "Tree.hpp"
|
||||||
#include "TreeStats.hpp"
|
#include "TreeStats.hpp"
|
||||||
@ -13,7 +14,6 @@
|
|||||||
|
|
||||||
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
||||||
#include "ArrayTree/triskeleSort.hpp"
|
#include "ArrayTree/triskeleSort.hpp"
|
||||||
#include "ArrayTree/Border.hpp"
|
|
||||||
#include "ArrayTree/GraphWalker.hpp"
|
#include "ArrayTree/GraphWalker.hpp"
|
||||||
#include "ArrayTree/Leader.hpp"
|
#include "ArrayTree/Leader.hpp"
|
||||||
#include "ArrayTree/Weight.hpp"
|
#include "ArrayTree/Weight.hpp"
|
||||||
@ -31,9 +31,9 @@
|
|||||||
using namespace otb::triskele;
|
using namespace otb::triskele;
|
||||||
using namespace otb::triskele::arrayTree;
|
using namespace otb::triskele::arrayTree;
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename OutPixelT>
|
||||||
inline void
|
inline void
|
||||||
writeBand (Option &option, PixelT *pixels, DimChanel band) {
|
writeBand (Option &option, const GDALDataType &outDataType, OutPixelT *pixels, DimChanel band) {
|
||||||
if (!option.oneBand) {
|
if (!option.oneBand) {
|
||||||
option.outputImage.writeBand (pixels, band);
|
option.outputImage.writeBand (pixels, band);
|
||||||
return;
|
return;
|
||||||
@ -44,14 +44,15 @@ writeBand (Option &option, PixelT *pixels, DimChanel band) {
|
|||||||
ostringstream fileNameStream;
|
ostringstream fileNameStream;
|
||||||
fileNameStream << outputBaseName << "-" << std::setfill ('0') << std::setw (3) << (band) << outputExtension;
|
fileNameStream << outputBaseName << "-" << std::setfill ('0') << std::setw (3) << (band) << outputExtension;
|
||||||
IImage outputImage (fileNameStream.str ());
|
IImage outputImage (fileNameStream.str ());
|
||||||
outputImage.createImage (option.size, option.inputImage.getDataType (), 1);
|
outputImage.createImage (option.size, outDataType, 1, option.inputImage, option.topLeft);
|
||||||
|
|
||||||
outputImage.writeBand (pixels, 0);
|
outputImage.writeBand (pixels, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename InPixelT, typename OutPixelT, typename APFunct>
|
||||||
inline
|
inline
|
||||||
void apGenerator (Option &option) {
|
void apGenerator (Option &option, const GDALDataType &outDataType, const APFunct &setAP) {
|
||||||
|
|
||||||
vector<TreeType> treeTypes;
|
vector<TreeType> treeTypes;
|
||||||
if (option.minTreeFlag)
|
if (option.minTreeFlag)
|
||||||
@ -66,48 +67,70 @@ void apGenerator (Option &option) {
|
|||||||
if (!treeTypesCard)
|
if (!treeTypesCard)
|
||||||
cerr << "*** no tree type ! => copy mode" << endl;
|
cerr << "*** no tree type ! => copy mode" << endl;
|
||||||
|
|
||||||
Border border (option.size, false); // default = no border
|
Border border (option.size, option.border);
|
||||||
GraphWalker graphWalker (border);
|
GraphWalker graphWalker (border);
|
||||||
DimImg leafCount = graphWalker.vertexMaxCount ();
|
DimImg leafCount = graphWalker.vertexMaxCount ();
|
||||||
DimChanel maxThresholds = max (max (option.areaThresholds.size (), option.sdThresholds.size ()), option.moiThresholds.size ());
|
DimChanel maxThresholds = max (max (max (option.areaThresholds.size (), option.levelThresholds.size ()), option.sdThresholds.size ()), option.moiThresholds.size ());
|
||||||
vector <vector <PixelT> > allBands (maxThresholds, vector<PixelT> (leafCount, 0));
|
vector <vector <OutPixelT> > allBands (maxThresholds, vector<OutPixelT> (leafCount, 0));
|
||||||
|
|
||||||
DimChanel outputBandsCard = option.selectedBand.getSet ().size ()*(1+treeTypesCard*(option.areaThresholds.size ()+option.sdThresholds.size ()+option.moiThresholds.size ()));
|
DimChanel outputBandsCard = option.selectedBand.getSet ().size ()*(1+treeTypesCard*(option.areaThresholds.size ()+option.levelThresholds.size ()+option.sdThresholds.size ()+option.moiThresholds.size ()));
|
||||||
if (!option.oneBand)
|
if (!option.oneBand) {
|
||||||
option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard);
|
option.outputImage.createImage (option.size, outDataType, outputBandsCard,
|
||||||
|
option.inputImage, option.topLeft);
|
||||||
|
}
|
||||||
|
|
||||||
Raster<PixelT> raster;
|
Raster<InPixelT> raster;
|
||||||
|
if (option.border) {
|
||||||
|
DimChanel bandCount (option.inputImage.getBandCount ()); // -1); // XXX sans NDVI
|
||||||
|
for (DimChanel band = 0; band < bandCount; ++band) {
|
||||||
|
option.inputImage.readBand (raster, band, option.topLeft, option.size);
|
||||||
|
for (DimImg idx = 0; idx < leafCount; ++idx)
|
||||||
|
if (raster.getValue (idx))
|
||||||
|
border.clearBorder (idx);
|
||||||
|
}
|
||||||
|
//cerr << "XXX border: " << border.borderCount () << endl;
|
||||||
|
}
|
||||||
|
|
||||||
DimChanel chanel = 0;
|
DimChanel chanel = 0;
|
||||||
for (DimChanel band : option.selectedBand.getSet ()) {
|
for (DimChanel band : option.selectedBand.getSet ()) {
|
||||||
option.inputImage.readBand (raster, band, option.topLeft, option.size);
|
option.inputImage.readBand (raster, band, option.topLeft, option.size);
|
||||||
writeBand (option, raster.getPixels (), chanel++);
|
writeBand (option, outDataType, raster.getPixels (), chanel++);
|
||||||
|
|
||||||
for (TreeType treeType : treeTypes) {
|
for (TreeType treeType : treeTypes) {
|
||||||
ArrayTreeBuilder<PixelT, PixelT> atb (raster, graphWalker, treeType, option.countingSortCeil);
|
ArrayTreeBuilder<InPixelT, InPixelT> atb (raster, graphWalker, treeType, option.countingSortCeil);
|
||||||
Tree tree (option.coreCount);
|
Tree tree (option.coreCount);
|
||||||
WeightAttributes<PixelT> weightAttributes (tree);
|
WeightAttributes<InPixelT> weightAttributes (tree, getDecrFromTreetype (treeType));
|
||||||
atb.buildTree (tree, weightAttributes);
|
atb.buildTree (tree, weightAttributes);
|
||||||
AttributeProfiles<PixelT> attributeProfiles (tree);
|
|
||||||
atb.setAttributProfiles (attributeProfiles);
|
|
||||||
|
|
||||||
|
AttributeProfiles<OutPixelT> attributeProfiles (tree);
|
||||||
AreaAttributes areaAttributes (tree);
|
AreaAttributes areaAttributes (tree);
|
||||||
|
AverageAttributes averageAttributes (tree, raster, areaAttributes);
|
||||||
|
|
||||||
|
setAP (tree, atb, attributeProfiles, raster, averageAttributes, areaAttributes);
|
||||||
|
|
||||||
|
if (option.levelThresholds.size ()) {
|
||||||
|
vector<InPixelT> thresholds (weightAttributes.getConvertedThresholds (option.levelThresholds));
|
||||||
|
weightAttributes.cut (allBands, attributeProfiles, thresholds);
|
||||||
|
for (DimChanel c = 0; c < option.levelThresholds.size (); ++c, ++chanel)
|
||||||
|
writeBand (option, outDataType, &allBands[c][0], chanel);
|
||||||
|
}
|
||||||
if (option.areaThresholds.size ()) {
|
if (option.areaThresholds.size ()) {
|
||||||
areaAttributes.cut (allBands, attributeProfiles, option.areaThresholds);
|
areaAttributes.cut (allBands, attributeProfiles, option.areaThresholds);
|
||||||
for (DimChanel c = 0; c < option.areaThresholds.size (); ++c, ++chanel)
|
for (DimChanel c = 0; c < option.areaThresholds.size (); ++c, ++chanel)
|
||||||
writeBand (option, &allBands[c][0], chanel);
|
writeBand (option, outDataType, &allBands[c][0], chanel);
|
||||||
}
|
}
|
||||||
if (option.sdThresholds.size ()) {
|
if (option.sdThresholds.size ()) {
|
||||||
SDAttributes sdAttributes (tree, areaAttributes);
|
SDAttributes sdAttributes (tree, areaAttributes);
|
||||||
sdAttributes.cut (allBands, attributeProfiles, option.sdThresholds);
|
sdAttributes.cut (allBands, attributeProfiles, option.sdThresholds);
|
||||||
for (DimChanel c = 0; c < option.sdThresholds.size (); ++c, ++chanel)
|
for (DimChanel c = 0; c < option.sdThresholds.size (); ++c, ++chanel)
|
||||||
writeBand (option, &allBands[c][0], chanel);
|
writeBand (option, outDataType, &allBands[c][0], chanel);
|
||||||
}
|
}
|
||||||
if (option.moiThresholds.size ()) {
|
if (option.moiThresholds.size ()) {
|
||||||
XYAttributes xyAttributes (tree, areaAttributes);
|
XYAttributes xyAttributes (tree, areaAttributes);
|
||||||
MoIAttributes moiAttributes (tree, areaAttributes, xyAttributes);
|
MoIAttributes moiAttributes (tree, areaAttributes, xyAttributes);
|
||||||
moiAttributes.cut (allBands, attributeProfiles, option.moiThresholds);
|
moiAttributes.cut (allBands, attributeProfiles, option.moiThresholds);
|
||||||
for (DimChanel c = 0; c < option.moiThresholds.size (); ++c, ++chanel)
|
for (DimChanel c = 0; c < option.moiThresholds.size (); ++c, ++chanel)
|
||||||
writeBand (option, &allBands[c][0], chanel);
|
writeBand (option, outDataType, &allBands[c][0], chanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,6 +140,45 @@ void apGenerator (Option &option) {
|
|||||||
<< globalTreeStats.printTime ();
|
<< globalTreeStats.printTime ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename InPixelT>
|
||||||
|
inline
|
||||||
|
void outTypeSelection (Option &option) {
|
||||||
|
switch (option.featureType) {
|
||||||
|
case MEAN:
|
||||||
|
apGenerator<InPixelT, InPixelT> (option, option.inputImage.getDataType (),
|
||||||
|
[] (Tree &tree, ArrayTreeBuilder<InPixelT, InPixelT> &atb, AttributeProfiles<InPixelT> &attributeProfiles, Raster<InPixelT> &raster, AverageAttributes &averageAttributes, AreaAttributes &areaAttributes) {
|
||||||
|
attributeProfiles.setValues (raster.getPixels (), averageAttributes.getValues ());
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case AREA:
|
||||||
|
apGenerator<InPixelT, DimImg> (option, GDT_UInt32,
|
||||||
|
[] (Tree &tree, ArrayTreeBuilder<InPixelT, InPixelT> &atb, AttributeProfiles<DimImg> &attributeProfiles, Raster<InPixelT> &raster, AverageAttributes &averageAttributes, AreaAttributes &areaAttributes) {
|
||||||
|
attributeProfiles.setValues (1, areaAttributes.getValues ());
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case SD:
|
||||||
|
apGenerator<InPixelT, double> (option, GDT_Float64,
|
||||||
|
[] (Tree &tree, ArrayTreeBuilder<InPixelT, InPixelT> &atb, AttributeProfiles<double> &attributeProfiles, Raster<InPixelT> &raster, AverageAttributes &averageAttributes, AreaAttributes &areaAttributes) {
|
||||||
|
SDAttributes sdAttributes (tree, areaAttributes);
|
||||||
|
attributeProfiles.setValues (0., sdAttributes.getValues ());
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case MOI:
|
||||||
|
apGenerator<InPixelT, double> (option, GDT_Float64,
|
||||||
|
[] (Tree &tree, ArrayTreeBuilder<InPixelT, InPixelT> &atb, AttributeProfiles<double> &attributeProfiles, Raster<InPixelT> &raster, AverageAttributes &averageAttributes, AreaAttributes &areaAttributes) {
|
||||||
|
XYAttributes xyAttributes (tree, areaAttributes);
|
||||||
|
MoIAttributes moiAttributes (tree, areaAttributes, xyAttributes);
|
||||||
|
attributeProfiles.setValues (0., moiAttributes.getValues ());
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
apGenerator<InPixelT, InPixelT> (option, option.inputImage.getDataType (),
|
||||||
|
[] (Tree &tree, ArrayTreeBuilder<InPixelT, InPixelT> &atb, AttributeProfiles<InPixelT> &attributeProfiles, Raster<InPixelT> &raster, AverageAttributes &averageAttributes, AreaAttributes &areaAttributes) {
|
||||||
|
atb.setAttributProfiles (attributeProfiles);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char** argv, char** envp) {
|
main (int argc, char** argv, char** envp) {
|
||||||
Option option (argc, argv);
|
Option option (argc, argv);
|
||||||
@ -124,20 +186,19 @@ main (int argc, char** argv, char** envp) {
|
|||||||
|
|
||||||
switch (option.inputImage.getDataType ()) {
|
switch (option.inputImage.getDataType ()) {
|
||||||
case GDT_Byte:
|
case GDT_Byte:
|
||||||
apGenerator<uint8_t> (option); break;
|
outTypeSelection<uint8_t> (option); break;
|
||||||
|
case GDT_UInt16:
|
||||||
case GDT_UInt16:
|
outTypeSelection<uint16_t> (option); break;
|
||||||
apGenerator<uint16_t> (option); break;
|
case GDT_Int16:
|
||||||
case GDT_Int16:
|
outTypeSelection<int16_t> (option); break;
|
||||||
apGenerator<int16_t> (option); break;
|
case GDT_UInt32:
|
||||||
case GDT_UInt32:
|
outTypeSelection<uint32_t> (option); break;
|
||||||
apGenerator<uint32_t> (option); break;
|
case GDT_Int32:
|
||||||
case GDT_Int32:
|
outTypeSelection<int32_t> (option); break;
|
||||||
apGenerator<int32_t> (option); break;
|
case GDT_Float32:
|
||||||
case GDT_Float32:
|
outTypeSelection<float> (option); break;
|
||||||
apGenerator<float> (option); break;
|
case GDT_Float64:
|
||||||
case GDT_Float64:
|
outTypeSelection<double> (option); break;
|
||||||
apGenerator<double> (option); break;
|
|
||||||
|
|
||||||
default :
|
default :
|
||||||
cerr << "unknown type!" << endl; break;
|
cerr << "unknown type!" << endl; break;
|
||||||
|
91
test/TestDeal.cpp
Normal file
91
test/TestDeal.cpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
// faire test 10000 + lamba + 1...coreCount
|
||||||
|
#include <boost/chrono.hpp>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
|
#include "triskeleDealThreads.hpp"
|
||||||
|
#include "TestThread.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace boost::chrono;
|
||||||
|
using namespace triskele;
|
||||||
|
using namespace otb;
|
||||||
|
using namespace otb::triskele;
|
||||||
|
|
||||||
|
inline void
|
||||||
|
fDirect (const DimImg &nbItem, const vector<DimImg> &global) {
|
||||||
|
DimImg sum = 0;
|
||||||
|
for (DimImg x = 0; x < nbItem; ++x)
|
||||||
|
sum += global[x];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename FunctId>
|
||||||
|
inline void
|
||||||
|
fLambda (DimImg &nbItem, const FunctId &functId/* functId (id) */) {
|
||||||
|
for (DimImg x = 0; x < nbItem; ++x)
|
||||||
|
functId (x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename FunctId>
|
||||||
|
inline void
|
||||||
|
fThread (double &inDuration, const DimImg &nbItem, const FunctId &functId/* functId (id) */) {
|
||||||
|
#if INTEL_TBB_THREAD
|
||||||
|
using namespace tbb;
|
||||||
|
#pragma warning(disable: 588)
|
||||||
|
parallel_for (size_t (0), size_t (1), [&nbItem, &functId] (size_t idCopyValInThread) {
|
||||||
|
auto start = high_resolution_clock::now ();
|
||||||
|
for (DimImg x = 0; x < nbItem; ++x)
|
||||||
|
functId (x);
|
||||||
|
auto end = high_resolution_clock::now ();
|
||||||
|
inDuration = duration_cast<duration<double> > (end-start).count ();
|
||||||
|
});
|
||||||
|
#else /* BOOST thread */
|
||||||
|
std::vector<boost::thread> tasks;
|
||||||
|
for (unsigned int idCopyValInThread = 0; idCopyValInThread < 1; ++idCopyValInThread) {
|
||||||
|
tasks.push_back (boost::thread ([/*no ref!!!*/idCopyValInThread, &nbItem, &functId, &inDuration] () {
|
||||||
|
auto start = high_resolution_clock::now ();
|
||||||
|
for (DimImg x = 0; x < nbItem; ++x)
|
||||||
|
functId (x);
|
||||||
|
auto end = high_resolution_clock::now ();
|
||||||
|
inDuration += duration_cast<duration<double> > (end-start).count ();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
for (unsigned int i = 0; i < 1; ++i)
|
||||||
|
tasks[i].join ();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TestThread::testDeal () {
|
||||||
|
|
||||||
|
DimImg nbItem = global.size ();
|
||||||
|
double inDuration = 0;
|
||||||
|
// XXX direct
|
||||||
|
auto startDirect = high_resolution_clock::now ();
|
||||||
|
fDirect (nbItem, global);
|
||||||
|
|
||||||
|
// XXX lambda
|
||||||
|
auto startLamba = high_resolution_clock::now ();
|
||||||
|
DimImg sum = 0;
|
||||||
|
fLambda (nbItem, [this, &sum] (const DimImg &x) {
|
||||||
|
sum += global [x];
|
||||||
|
});
|
||||||
|
|
||||||
|
// XXX thread
|
||||||
|
auto startThread = high_resolution_clock::now ();
|
||||||
|
sum = 0;
|
||||||
|
fThread (inDuration, nbItem, [this, &sum] (const DimImg &x) {
|
||||||
|
sum += global [x];
|
||||||
|
});
|
||||||
|
|
||||||
|
// XXX n direct
|
||||||
|
|
||||||
|
// XXX n lambda
|
||||||
|
|
||||||
|
// XXX n thread
|
||||||
|
|
||||||
|
auto end = high_resolution_clock::now ();
|
||||||
|
addTime (directDealStats, duration_cast<duration<double> > (startLamba-startDirect).count ());
|
||||||
|
addTime (lambdaDealStats, duration_cast<duration<double> > (startThread-startLamba).count ());
|
||||||
|
addTime (threadDealStats, duration_cast<duration<double> > (end-startThread).count ());
|
||||||
|
addTime (inThreadDealStats, inDuration);
|
||||||
|
}
|
222
test/TestThread.cpp
Normal file
222
test/TestThread.cpp
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
#include <boost/chrono.hpp>
|
||||||
|
|
||||||
|
#include "triskeleDealThreads.hpp"
|
||||||
|
#include "TestThread.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace boost::chrono;
|
||||||
|
using namespace triskele;
|
||||||
|
using namespace otb;
|
||||||
|
using namespace otb::triskele;
|
||||||
|
|
||||||
|
static string timeTypeLabels [TimeTypeCard] = {
|
||||||
|
"directDeal",
|
||||||
|
"lambdaDeal",
|
||||||
|
"threadDeal",
|
||||||
|
"inThreadDeal",
|
||||||
|
|
||||||
|
|
||||||
|
"initStats",
|
||||||
|
"seqReadStats",
|
||||||
|
"parReadStats",
|
||||||
|
"seqWriteStats",
|
||||||
|
"parWriteStats",
|
||||||
|
"seqRWStats",
|
||||||
|
"parRWStats"
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned int
|
||||||
|
TestThread::maxCoreCount = boost::thread::hardware_concurrency ();
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
inline string
|
||||||
|
TestThread::ns2string (double delta) {
|
||||||
|
ostringstream oss;
|
||||||
|
duration<double> ns (delta);
|
||||||
|
oss.fill ('0');
|
||||||
|
// typedef duration<int, ratio<86400> > days;
|
||||||
|
// auto d = duration_cast<days>(ns);
|
||||||
|
// ns -= d;
|
||||||
|
auto h = duration_cast<hours> (ns);
|
||||||
|
ns -= h;
|
||||||
|
auto m = duration_cast<minutes> (ns);
|
||||||
|
ns -= m;
|
||||||
|
oss << setw (2) << h.count () << ":"
|
||||||
|
<< setw (2) << m.count () << ":"
|
||||||
|
<< setw (9) << fixed << setprecision (6) << ns.count ();
|
||||||
|
return oss.str ();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
template<typename DimImg, typename FunctId>
|
||||||
|
inline void
|
||||||
|
nodealThreadRange (const DimImg &maxId, const unsigned int &coreCount, const FunctId &functId/* functId (id) */) {
|
||||||
|
nodealThread (maxId, coreCount, [&functId] (const unsigned int &threadId, const DimImg &minVal, const DimImg &maxVal) {
|
||||||
|
for (DimImg id = minVal; id < maxVal; ++id)
|
||||||
|
functId (id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
template<typename DimImg, typename FunctThreadId>
|
||||||
|
inline void
|
||||||
|
nodealThreadThreadRange (const DimImg &maxId, const unsigned int &coreCount, const FunctThreadId &functThreadId/* functThreadId (threadId, id) */) {
|
||||||
|
nodealThread (maxId, coreCount, [&functThreadId] (const unsigned int &threadId, const DimImg &minVal, const DimImg &maxVal) {
|
||||||
|
for (DimImg id = minVal; id < maxVal; ++id)
|
||||||
|
functThreadId (threadId, id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
template<typename DimImg, typename FunctThreadMinMax>
|
||||||
|
inline void
|
||||||
|
nodealThread (const DimImg &maxId, unsigned int coreCount, const FunctThreadMinMax &functThreadMinMax/* functThreadMinMax (threadId, minVal, maxVal) */) {
|
||||||
|
//DEF_LOG ("dealThreadBound", "coreCount:" << coreCount << " maxId:" << maxId);
|
||||||
|
if (!maxId || !coreCount)
|
||||||
|
return;
|
||||||
|
if (DimImg (coreCount) > maxId)
|
||||||
|
coreCount = (unsigned int) maxId;
|
||||||
|
if (coreCount == 1) {
|
||||||
|
functThreadMinMax (0, 0, maxId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<DimImg> maxIds = getDealThreadBounds (maxId, coreCount);
|
||||||
|
for (unsigned int idCopyValInThread = 0; idCopyValInThread < coreCount; ++idCopyValInThread) {
|
||||||
|
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
TestThread::TestThread (const unsigned int &coreCount)
|
||||||
|
: coreCount (coreCount),
|
||||||
|
global (nbItem*coreCount, 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream &
|
||||||
|
TestThread::print (ostream &out, const AlgoStat stats[]) {
|
||||||
|
out << endl
|
||||||
|
<< setw (16) << left << "Time" << "\t"
|
||||||
|
<< setw (15) << left << "Sum" << "\t"
|
||||||
|
<< setw (3) << left << "Count" << "\t"
|
||||||
|
<< setw (15) << left << "Mean" << "\t"
|
||||||
|
<< setw (15) << left << "Min" << "\t"
|
||||||
|
<< setw (15) << left << "Max" << endl;
|
||||||
|
for (unsigned int i = 0; i < TimeTypeCard; ++i) {
|
||||||
|
if (!ba::count (stats[i]))
|
||||||
|
continue;
|
||||||
|
out << setw (16) << right << timeTypeLabels[i] << "\t"
|
||||||
|
<< ns2string (ba::sum (stats[i])) << "\t" << setw (3) << ba::count (stats[i]) << "\t"
|
||||||
|
<< ns2string (ba::mean (stats[i])) << "\t"
|
||||||
|
<< ns2string (ba::min (stats[i])) << "\t"
|
||||||
|
<< ns2string (ba::max (stats[i]))
|
||||||
|
<< endl << flush;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void
|
||||||
|
TestThread::fillVector (vector<T> &vect) {
|
||||||
|
for (size_t i = 0; i < vect.size (); ++i)
|
||||||
|
vect[i] = (T) std::rand ();
|
||||||
|
}
|
||||||
|
|
||||||
|
// show algin
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TestThread::multiTest () {
|
||||||
|
for (int i = 0; i < 100; ++i) {
|
||||||
|
vector<long> sumSeq (coreCount, 0);
|
||||||
|
vector<long> sumPar (coreCount, 0);
|
||||||
|
|
||||||
|
auto start = high_resolution_clock::now ();
|
||||||
|
fillVector (global);
|
||||||
|
|
||||||
|
// lecture seq => faire somme
|
||||||
|
auto startSeqRead = high_resolution_clock::now ();
|
||||||
|
nodealThreadThreadRange (nbItem, coreCount, [this, &sumSeq] (const unsigned int &threadId, const DimImg &item) {
|
||||||
|
sumSeq[threadId] += global[item];
|
||||||
|
});
|
||||||
|
|
||||||
|
// lecture // => faire somme
|
||||||
|
auto startParRead = high_resolution_clock::now ();
|
||||||
|
dealThreadThreadRange (nbItem, coreCount, [this, &sumPar] (const unsigned int &threadId, const DimImg &item) {
|
||||||
|
sumPar[threadId] += global[item];
|
||||||
|
});
|
||||||
|
// XXX vérifier égalité de sumSeq sumPar
|
||||||
|
|
||||||
|
// écriture seq => écrire idx
|
||||||
|
// écriture // => écrire idx
|
||||||
|
|
||||||
|
// lecture/écriture seq => écrire x/2
|
||||||
|
// lecture/écriture // => écrire x/2
|
||||||
|
|
||||||
|
auto end = high_resolution_clock::now ();
|
||||||
|
addTime (initStats, duration_cast<duration<double> > (startSeqRead-start).count ());
|
||||||
|
addTime (seqReadStats, duration_cast<duration<double> > (startParRead-startSeqRead).count ());
|
||||||
|
addTime (parReadStats, duration_cast<duration<double> > (end-startParRead).count ());
|
||||||
|
}
|
||||||
|
print (cout, timeStats);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
int
|
||||||
|
main (int argc, char** argv) {
|
||||||
|
cout << "start test" << endl;
|
||||||
|
srand (time (NULL));
|
||||||
|
|
||||||
|
TestThread tt;
|
||||||
|
//tt.multiTest ();
|
||||||
|
for (int i = 0; i < 100; ++i)
|
||||||
|
tt.testDeal ();
|
||||||
|
tt.print (cout, tt.timeStats);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// namespace utils {
|
||||||
|
|
||||||
|
// inline size_t alignSize(size_t size, size_t alignment) {
|
||||||
|
// return (size+alignment-1)&~(alignment-1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// inline T * alignPtr(T * ptr, uintptr_t alignment) {
|
||||||
|
// union {
|
||||||
|
// T *p;
|
||||||
|
// uintptr_t u;
|
||||||
|
// } u;
|
||||||
|
// u.p = ptr;
|
||||||
|
// u.u = (u.u+alignment-1)&~(alignment-1);
|
||||||
|
// return u.p;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }//namespace utils
|
||||||
|
// void init (Index c, Data const &d) {
|
||||||
|
// if (count != c) {
|
||||||
|
// kill ();
|
||||||
|
// count = c;
|
||||||
|
// size_t const alignment = 64;
|
||||||
|
// size_t size = alignment-1
|
||||||
|
// + utils::alignSize (count*sizeof (Index), alignment)
|
||||||
|
// + utils::alignSize (count*sizeof (Rank ), alignment)
|
||||||
|
// + utils::alignSize (count*sizeof (Data ), alignment);
|
||||||
|
// //memory.reset (new char[size]);
|
||||||
|
// delete [] memory;
|
||||||
|
// memory = nullptr;
|
||||||
|
// memory = new char[size];
|
||||||
|
|
||||||
|
// char *ptr = utils::alignPtr (memory, alignment);
|
||||||
|
// parents = reinterpret_cast<Index*> (ptr);
|
||||||
|
// ptr += utils::alignSize (count*sizeof (Index), alignment);
|
||||||
|
// ranks = reinterpret_cast<Rank *> (ptr);
|
||||||
|
// ptr += utils::alignSize (count*sizeof (Rank ), alignment);
|
||||||
|
// datas = reinterpret_cast<Data *> (ptr);
|
||||||
|
// }
|
||||||
|
// reset (d);
|
||||||
|
// }
|
80
test/TestThread.hpp
Normal file
80
test/TestThread.hpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// OK faire une classe
|
||||||
|
// OK changer coreCount en maxCoreCount
|
||||||
|
// faire test 10000 + lamba + 1...coreCount
|
||||||
|
// découpe fichier TestThread.cpp
|
||||||
|
// calcul alignement
|
||||||
|
// lecture seq => faire somme
|
||||||
|
// lecture // => faire somme
|
||||||
|
|
||||||
|
// écriture seq => écrire idx
|
||||||
|
// écriture // => écrire idx
|
||||||
|
|
||||||
|
// lecture/écriture seq => écrire x/2
|
||||||
|
// lecture/écriture // => écrire x/2
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/accumulators/accumulators.hpp>
|
||||||
|
#include <boost/accumulators/statistics/stats.hpp>
|
||||||
|
#include <boost/accumulators/statistics/sum.hpp>
|
||||||
|
#include <boost/accumulators/statistics/count.hpp>
|
||||||
|
#include <boost/accumulators/statistics/min.hpp>
|
||||||
|
#include <boost/accumulators/statistics/max.hpp>
|
||||||
|
#include <boost/accumulators/statistics/mean.hpp>
|
||||||
|
|
||||||
|
namespace otb {
|
||||||
|
namespace triskele {
|
||||||
|
using namespace std;
|
||||||
|
namespace ba = boost::accumulators;
|
||||||
|
typedef ba::accumulator_set<double,
|
||||||
|
ba::stats<ba::tag::sum,
|
||||||
|
ba::tag::count,
|
||||||
|
ba::tag::mean,
|
||||||
|
ba::tag::min,
|
||||||
|
ba::tag::max> > AlgoStat;
|
||||||
|
enum TimeType {
|
||||||
|
directDealStats,
|
||||||
|
lambdaDealStats,
|
||||||
|
threadDealStats,
|
||||||
|
inThreadDealStats,
|
||||||
|
|
||||||
|
initStats,
|
||||||
|
seqReadStats,
|
||||||
|
parReadStats,
|
||||||
|
seqWriteStats,
|
||||||
|
parWriteStats,
|
||||||
|
seqRWStats,
|
||||||
|
parRWStats,
|
||||||
|
|
||||||
|
TimeTypeCard
|
||||||
|
};
|
||||||
|
typedef uint32_t DimImg;
|
||||||
|
|
||||||
|
class TestThread {
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const unsigned int maxCoreCount;
|
||||||
|
unsigned int coreCount;
|
||||||
|
AlgoStat timeStats[TimeTypeCard];
|
||||||
|
size_t nbItem = 1000000;
|
||||||
|
// XXX vérifier l'alignement vector
|
||||||
|
vector<DimImg> global;
|
||||||
|
|
||||||
|
TestThread (const unsigned int &coreCount = maxCoreCount);
|
||||||
|
// XXX en commun
|
||||||
|
static inline string ns2string (double delta);
|
||||||
|
inline void addTime (const TimeType &timeType, const double &duration) {
|
||||||
|
timeStats[timeType] (duration);
|
||||||
|
}
|
||||||
|
ostream &print (ostream &out, const AlgoStat stats[]);
|
||||||
|
// XXX déclarer nodealThread
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void fillVector (vector<T> &vect);
|
||||||
|
void multiTest ();
|
||||||
|
|
||||||
|
void testDeal ();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user