Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ endif ()

find_package(benchmark REQUIRED)


include_directories(${PROJECT_SOURCE_DIR}/lib/include ${PROJECT_SOURCE_DIR}/include ${TBB_INCLUDE_DIRS})

include_directories(${GBENCHMARK_INCLUDE_DIRS})

set(FILES_BENCHMARK
main.cpp
utils.cpp
benchmark_lca.cpp
# benchmark_component_tree_casf.cpp
#benchmark_undirected_graph.cpp
#benchmark_regular_graph.cpp
#benchmark_accumulator.cpp
Expand All @@ -87,7 +86,6 @@ target_compile_definitions(${BENCHMARK_TARGET} PRIVATE HG_USE_TBB)
target_link_libraries(${BENCHMARK_TARGET} benchmark -lpthread ${TBB_LIBRARIES})



add_custom_target(benchmark_exe
COMMAND benchmark_higra
DEPENDS ${BENCHMARK_TARGET})
657 changes: 657 additions & 0 deletions benchmark/benchmark_component_tree_casf.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions higra/hierarchy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(PY_FILES
__init__.py
binary_partition_tree.py
component_tree.py
component_tree_dual_filter.py
constrained_connectivity_hierarchy.py
hierarchy_core.py
random_hierarchy.py
Expand All @@ -21,6 +22,7 @@ set(PYMODULE_COMPONENTS ${PYMODULE_COMPONENTS}
${CMAKE_CURRENT_SOURCE_DIR}/py_binary_partition_tree.cpp
${CMAKE_CURRENT_SOURCE_DIR}/py_common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/py_component_tree.cpp
${CMAKE_CURRENT_SOURCE_DIR}/py_component_tree_dual_filter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/py_hierarchy_core.cpp
${CMAKE_CURRENT_SOURCE_DIR}/py_watershed_hierarchy.cpp
PARENT_SCOPE)
Expand Down
1 change: 1 addition & 0 deletions higra/hierarchy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .binary_partition_tree import *
from .component_tree import *
from .component_tree_dual_filter import *
from .constrained_connectivity_hierarchy import *
from .hierarchy_core import *
from .random_hierarchy import *
Expand Down
1 change: 1 addition & 0 deletions higra/hierarchy/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
#include "py_binary_partition_tree.hpp"
#include "py_common.hpp"
#include "py_component_tree.hpp"
#include "py_component_tree_dual_filter.hpp"
#include "py_hierarchy_core.hpp"
#include "py_watershed_hierarchy.hpp"
52 changes: 52 additions & 0 deletions higra/hierarchy/component_tree_dual_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
############################################################################
# Copyright ESIEE Paris (2018) #
# #
# Contributor(s) : Wonder Alexandre Luz Alves #
# #
# Distributed under the terms of the CECILL-B License. #
# #
# The full license is in the file LICENSE, distributed with this software. #
############################################################################

import higra as hg


def _get_attribute_map():
return {
"area": hg.CasfAttribute.area,
"bounding_box_width": hg.CasfAttribute.bounding_box_width,
"bounding_box_height": hg.CasfAttribute.bounding_box_height,
"bounding_box_diagonal": hg.CasfAttribute.bounding_box_diagonal,
}


def connected_alternating_sequential_filter(graph, vertex_weights, attribute, thresholds):
"""
Connected alternating sequential filter on a vertex weighted graph.

The filter alternates an extensive max-tree pruning step and an anti-extensive
min-tree pruning step for each threshold in ``thresholds``.

:param graph: input graph
:param vertex_weights: vertex weights of the input graph
:param attribute: one of ``"area"``, ``"bounding_box_width"``,
``"bounding_box_height"``, ``"bounding_box_diagonal"``, or the
corresponding :class:`~higra.CasfAttribute` value
:param thresholds: sequence of thresholds applied successively
:return: filtered vertex weights
"""
attribute_map = _get_attribute_map()

if isinstance(attribute, str):
try:
attribute = attribute_map[attribute]
except KeyError:
raise ValueError("Unknown CASF attribute '" + attribute + "'. Expected one of " + str(tuple(attribute_map.keys())) + ".")
elif attribute not in attribute_map.values():
raise ValueError("attribute must be a string or a higra.CasfAttribute value.")

vertex_weights = hg.linearize_vertex_weights(vertex_weights, graph)

filtered_weights = hg.cpp._connected_alternating_sequential_filter(graph, vertex_weights, attribute, thresholds)

return hg.delinearize_vertex_weights(filtered_weights, graph)
54 changes: 54 additions & 0 deletions higra/hierarchy/py_component_tree_dual_filter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/***************************************************************************
* Copyright ESIEE Paris (2018) *
* *
* Contributor(s) : Wonder Alexandre Luz Alves *
* *
* Distributed under the terms of the CECILL-B License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "py_component_tree_dual_filter.hpp"
#include "higra/hierarchy/component_tree_casf.hpp"
#include "../py_common.hpp"
#include "xtensor-python/pyarray.hpp"
#include "xtensor-python/pytensor.hpp"

namespace py_component_tree_dual_filter {
template<typename T>
using pyarray = xt::pyarray<T>;

namespace py = pybind11;

template<typename graph_t>
struct def_connected_alternating_sequential_filter {
template<typename value_t, typename C>
static
void def(C &c, const char *doc) {
c.def("_connected_alternating_sequential_filter",
[](const graph_t &graph,
const pyarray<value_t> &vertex_weights,
hg::ComponentTreeCasfAttribute attribute,
const std::vector<double> &thresholds) {
hg::ComponentTreeCasf<value_t, graph_t> casf(graph, vertex_weights, attribute);
return casf.filter(thresholds);
},
doc,
py::arg("graph"),
py::arg("vertex_weights").noconvert(),
py::arg("attribute"),
py::arg("thresholds"));
}
};

void py_init_component_tree_dual_filter(pybind11::module &m) {
py::enum_<hg::ComponentTreeCasfAttribute>(m, "CasfAttribute")
.value("area", hg::ComponentTreeCasfAttribute::area)
.value("bounding_box_width", hg::ComponentTreeCasfAttribute::bounding_box_width)
.value("bounding_box_height", hg::ComponentTreeCasfAttribute::bounding_box_height)
.value("bounding_box_diagonal", hg::ComponentTreeCasfAttribute::bounding_box_diagonal);

add_type_overloads<def_connected_alternating_sequential_filter<hg::ugraph>, HG_TEMPLATE_NUMERIC_TYPES>(m, "Connected alternating sequential filter on a vertex weighted graph.");
add_type_overloads<def_connected_alternating_sequential_filter<hg::regular_grid_graph_2d>, HG_TEMPLATE_NUMERIC_TYPES>(m,"Connected alternating sequential filter on a regular grid graph.");
}
}
17 changes: 17 additions & 0 deletions higra/hierarchy/py_component_tree_dual_filter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/***************************************************************************
* Copyright ESIEE Paris (2018) *
* *
* Contributor(s) : Wonder Alexandre Luz Alves *
* *
* Distributed under the terms of the CECILL-B License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#pragma once

#include "pybind11/pybind11.h"

namespace py_component_tree_dual_filter {
void py_init_component_tree_dual_filter(pybind11::module &m);
}
3 changes: 2 additions & 1 deletion higra/pymodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ PYBIND11_MODULE(higram, m) {
py_bipartite_graph::py_init_bipartite_graph(m);
py_common_hierarchy::py_init_common_hierarchy(m);
py_component_tree::py_init_component_tree(m);
py_component_tree_dual_filter::py_init_component_tree_dual_filter(m);
py_contour_2d::py_init_contour_2d(m);
py_embedding::py_init_embedding(m);
py_graph_accumulator::py_init_graph_accumulator(m);
Expand Down Expand Up @@ -72,4 +73,4 @@ PYBIND11_MODULE(higram, m) {
py_undirected_graph::py_init_undirected_graph(m);
py_watershed::py_init_watershed(m);
py_watershed_hierarchy::py_init_watershed_hierarchy(m);
}
}
Loading