Skip to content

Commit 9103461

Browse files
authored
121 cluster (#122)
* Implement C library for clusterization of match table * Add tests
1 parent a1e1879 commit 9103461

15 files changed

Lines changed: 621 additions & 147 deletions

File tree

.vscode/settings.json

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,39 @@
1010
"image_deform_gc.h": "c",
1111
"stdlib.h": "c",
1212
"structmember.h": "c",
13-
"imagedeform_gc.h": "c"
13+
"imagedeform_gc.h": "c",
14+
"vector": "cpp",
15+
"cmath": "cpp",
16+
"cstdarg": "cpp",
17+
"cstddef": "cpp",
18+
"cstdio": "cpp",
19+
"cstdlib": "cpp",
20+
"cstring": "cpp",
21+
"array": "cpp",
22+
"bit": "cpp",
23+
"*.tcc": "cpp",
24+
"compare": "cpp",
25+
"concepts": "cpp",
26+
"cstdint": "cpp",
27+
"string": "cpp",
28+
"unordered_map": "cpp",
29+
"exception": "cpp",
30+
"algorithm": "cpp",
31+
"functional": "cpp",
32+
"iterator": "cpp",
33+
"memory": "cpp",
34+
"memory_resource": "cpp",
35+
"optional": "cpp",
36+
"tuple": "cpp",
37+
"type_traits": "cpp",
38+
"utility": "cpp",
39+
"initializer_list": "cpp",
40+
"iosfwd": "cpp",
41+
"limits": "cpp",
42+
"new": "cpp",
43+
"span": "cpp",
44+
"stdexcept": "cpp",
45+
"typeinfo": "cpp"
1446
},
1547
"editor.tabSize": 4,
1648
"editor.insertSpaces": true,

setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
import numpy as np
1717
from setuptools import setup, Extension
1818

19+
clusterization = Extension(name="vstarstack.library.clusters.clusterization",
20+
sources=[
21+
"src/vstarstack/library/clusters/clusterization/module.cc",
22+
"src/vstarstack/library/clusters/clusterization/lib/src/clusters.cc"
23+
],
24+
include_dirs=[
25+
"src/vstarstack/library/clusters/clusterization/lib/include"
26+
])
27+
1928
projection = Extension( name="vstarstack.library.projection.projections",
2029
sources=[
2130
"src/vstarstack/library/projection/projections/module.c",
@@ -75,6 +84,7 @@
7584
ext_modules = [projection,
7685
movements,
7786
image_deform,
87+
clusterization,
7888
],
7989
entry_points = {
8090
'console_scripts': [

src/vstarstack/library/cluster.py

Lines changed: 0 additions & 135 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
3+
project(clusters)
4+
5+
# Library sources
6+
add_library(clusters STATIC src/clusters.cc)
7+
8+
set(HEADERS "include/clusters.hpp;")
9+
10+
target_include_directories(clusters PUBLIC include)
11+
set_target_properties(clusters PROPERTIES PUBLIC_HEADER "${HEADERS}")
12+
13+
# Fail on warnings
14+
if(MSVC)
15+
target_compile_options(clusters PRIVATE /W4 /WX)
16+
else()
17+
target_compile_options(clusters PRIVATE -Wall -Wextra -Wpedantic -Werror)
18+
endif()
19+
20+
install(TARGETS clusters
21+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libclusters)
22+
23+
# Tests
24+
if (BUILD_TESTS)
25+
set(INSTALL_GTEST OFF)
26+
include(FetchContent)
27+
FetchContent_Declare(
28+
googletest
29+
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
30+
)
31+
32+
# For Windows: Prevent overriding the parent project's compiler/linker settings
33+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
34+
FetchContent_MakeAvailable(googletest)
35+
36+
enable_testing()
37+
add_executable(
38+
clusters_test
39+
tests/clusters_test.cc
40+
)
41+
42+
target_link_libraries(
43+
clusters_test
44+
GTest::gtest_main
45+
clusters
46+
)
47+
48+
include(GoogleTest)
49+
gtest_discover_tests(clusters_test)
50+
51+
if (UNIX)
52+
add_custom_target(memory_leak_test sh ${CMAKE_SOURCE_DIR}/run_valgrind_tests.sh ${CMAKE_BINARY_DIR}/clusters_test
53+
DEPENDS clusters_test)
54+
endif()
55+
endif()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2024 Vladislav Tsendrovskii
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, version 3 of the License.
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
* See the GNU General Public License for more details.
11+
* You should have received a copy of the GNU General Public License
12+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
13+
*/
14+
15+
#pragma once
16+
17+
#include <vector>
18+
19+
struct item_s {
20+
int frame_id;
21+
int keypoint_id;
22+
};
23+
24+
struct match_s {
25+
item_s item1;
26+
item_s item2;
27+
};
28+
29+
struct cluster_s {
30+
std::vector<item_s> items;
31+
};
32+
33+
std::vector<cluster_s> build_clusters(const std::vector<match_s> &matches);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
valgrind --error-exitcode 1 -s $1
4+
exit $?

0 commit comments

Comments
 (0)