Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Checks: >
WarningsAsErrors: ''

HeaderFilterRegex: '.*'
ExcludeHeaderFilterRegex: 'CMakeLists\.txt'

CompileFlags:
Add:
- '-std=c++17'
- '-I${CMAKE_SOURCE_DIR}/libs'

CheckOptions:
- key: readability-identifier-naming.ClassCase
Expand Down
17 changes: 17 additions & 0 deletions .cppcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<!-- Cppcheck configuration for PolySeg -->

<!-- Include paths for library resolution -->
<includedir>libs</includedir>
<includedir>src</includedir>

<!-- Exclude paths - prevent analysis of build/external files -->
<exclude>
<path name="external"/>
<path name="build"/>
<path name="cmake"/>
<path name="test123"/>
<path name="CMakeLists.txt"/>
</exclude>
</project>
8 changes: 8 additions & 0 deletions .cppcheckignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CMake files - not C++ code
CMakeLists.txt
*/CMakeLists.txt

# External dependencies
external/*
build/*
cmake/*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ debug/
release/

# IDE
.vscode/
.vscode/*
!.vscode/settings.json
.idea/
*.swp
*.swo
Expand Down
35 changes: 35 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// Cppcheck configuration
"cppcheck.enable": true,
"cppcheck.cppcheckPath": "cppcheck",
"cppcheck.standard": ["c++17"],
"cppcheck.language": "c++",
"cppcheck.includePaths": ["${workspaceFolder}/libs", "${workspaceFolder}/src"],
"cppcheck.excludedPaths": ["${workspaceFolder}/external", "${workspaceFolder}/build", "${workspaceFolder}/test123"],
"cppcheck.cppcheckArgs": ["--std=c++17", "--language=c++"],

// C/C++ IntelliSense settings
"C_Cpp.default.standard": "c++17",
"C_Cpp.default.includePath": ["${workspaceFolder}/libs", "${workspaceFolder}/src"],
"C_Cpp.formatting": "clangFormat",
"C_Cpp.clang_format_style": "file",

// Files to exclude from analysis
"files.exclude": {
"**/CMakeLists.txt": true,
"external/**": true,
"build/**": true,
"test123/**": true
},

// Editor settings
"editor.formatOnSave": true,
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format",
"editor.formatOnSave": true
},
"[h]": {
"editor.defaultFormatter": "xaver.clang-format",
"editor.formatOnSave": true
}
}
72 changes: 39 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ set(POLYSEG_SOURCES
src/modeldownloadmanager.cpp
src/modelregistrationdialog.cpp
src/polygoncanvas.cpp
src/qtadapter.cpp
src/projectconfig.cpp
src/pythonenvironmentmanager.cpp
src/settingstabbase.cpp
Expand All @@ -79,6 +80,9 @@ set(POLYSEG_SOURCES
src/shortcutssettingstab.cpp
src/aipluginmanager.cpp
src/pluginwizard.cpp
src/edgedetector.cpp
src/metadataimporter.cpp
src/metadataimportsettingsdialog.cpp
src/wizardpages/welcomepage.cpp
src/wizardpages/pluginselectionpage.cpp
src/wizardpages/custompluginpage.cpp
Expand Down Expand Up @@ -112,6 +116,9 @@ set(POLYSEG_HEADERS
src/shortcutssettingstab.h
src/aipluginmanager.h
src/pluginwizard.h
src/edgedetector.h
src/metadataimporter.h
src/metadataimportsettingsdialog.h
src/wizardpages/welcomepage.h
src/wizardpages/pluginselectionpage.h
src/wizardpages/custompluginpage.h
Expand All @@ -138,6 +145,7 @@ set(POLYSEG_UI_FILES
src/shortcuteditdialog.ui
src/modelcomparisondialog.ui
src/modelregistrationdialog.ui
src/metadataimportsettingsdialog.ui
src/wizardpages/welcomepage.ui
src/wizardpages/pluginselectionpage.ui
src/wizardpages/custompluginpage.ui
Expand All @@ -163,6 +171,16 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# Fetch spdlog for structured logging (statically compiled into PolySeg_lib only)
include(FetchContent)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.15.3
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(spdlog)

# Create a library with core functionality (excluding main.cpp for testability)
set(POLYSEG_LIB_SOURCES ${POLYSEG_SOURCES})
list(REMOVE_ITEM POLYSEG_LIB_SOURCES src/main.cpp)
Expand All @@ -174,12 +192,21 @@ add_library(PolySeg_lib
${POLYSEG_RESOURCES}
)

# Include directories
target_include_directories(PolySeg_lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/libs
)

# Link Qt libraries to the library
target_link_libraries(PolySeg_lib PRIVATE
target_link_libraries(PolySeg_lib PUBLIC
Qt6::Core
Qt6::Gui
Qt6::Widgets
Qt6::Network
imgproc
segcore
spdlog::spdlog
)

# Create the main PolySeg executable
Expand Down Expand Up @@ -290,39 +317,12 @@ endif()
enable_testing()

# Add Google Test from external directory
add_subdirectory(libs/imgproc)
add_subdirectory(libs/segcore)
add_subdirectory(external/googletest)

# Create unit test executable
add_executable(PolySeg_tests
tests/main_test.cpp
# Add additional test files here as you create them
)

# Link Google Test libraries and PolySeg library to test executable
target_link_libraries(PolySeg_tests PRIVATE
gtest
gtest_main
PolySeg_lib
Qt6::Core
Qt6::Gui
Qt6::Widgets
Qt6::Network
)

# Apply coverage flags to test executable if enabled
if(ENABLE_COVERAGE AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
target_compile_options(PolySeg_tests PRIVATE ${COVERAGE_FLAGS})
target_link_libraries(PolySeg_tests PRIVATE ${COVERAGE_FLAGS})
endif()

# Include test directories
target_include_directories(PolySeg_tests PRIVATE
src
external/googletest/googletest/include
)

# Add tests to CTest
add_test(NAME PolySeg_unit_tests COMMAND PolySeg_tests)
# Add unit tests
add_subdirectory(tests)

# Coverage target for easy usage
if(ENABLE_COVERAGE AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
Expand Down Expand Up @@ -353,4 +353,10 @@ if(UNIX AND NOT ANDROID)
install(TARGETS PolySeg
RUNTIME DESTINATION bin
)
endif()
endif()

# Install spdlog license for distribution compliance (statically linked)
install(FILES ${spdlog_SOURCE_DIR}/LICENSE
DESTINATION share/doc/PolySeg/licenses
RENAME spdlog-LICENSE.txt
)
136 changes: 136 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Development Guide

## Code Style & Analysis Tools

### clang-format
Automatically format code according to Google C++ Style Guide:

```bash
# Format all C++ files in libs/ and src/
find libs src -name "*.h" -o -name "*.cpp" | xargs clang-format -i --style=file
```

Configuration: `.clang-format`

### clang-tidy
Static analysis for code quality:

```bash
# Analyze C++ files (requires C++17)
clang-tidy -checks=* libs/imgproc/convolution.h -- -std=c++17 -Ilibs
```

Configuration: `.clang-tidy`

### cppcheck
Static code analysis tool:

```bash
# Run cppcheck with C++17 standard
cppcheck --std=c++17 --language=c++ \
-Ilibs -Isrc \
--exclude-dir=external \
--exclude-dir=build \
--exclude-dir=test123 \
libs/ src/ tests/
```

**Important:** cppcheck requires `--language=c++` flag to properly analyze C++17 namespace syntax.

Configuration files:
- `.cppcheck` - Project-level configuration (for IDE integration)
- `.cppcheckignore` - Paths to exclude from analysis

### IDE Configuration

#### CLion / JetBrains IDEs
1. Go to Settings → Languages & Frameworks → C/C++ → Cppcheck
2. Enable Cppcheck
3. Set options:
- Language: C++
- Standard: C++17
- Include paths: `-Ilibs -Isrc`
- Exclude directories: external, build, test123

#### VSCode
Install cppcheck extension and configure in `.vscode/settings.json`:

```json
{
"cppcheck.cppcheckArgs": ["--std=c++17", "--language=c++"],
"cppcheck.includePaths": ["libs", "src"],
"cppcheck.excludedPaths": ["external", "build", "test123"]
}
```

## Build Instructions

```bash
# Create build directory
mkdir build && cd build

# Configure with CMake
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build
make -j$(nproc)

# Run tests
ctest --output-on-failure
```

## Library Modules

### imgproc (Header-only)
Image processing components:
- `Frame<T>` - Generic frame/image container
- `Kernel<N>` - Convolution kernel
- `Convolution` - Convolution filter application

Pure C++ without Qt dependencies - can be used independently.

### segcore (Static library)
Annotation and project management:
- `AnnotationSet` - Manages polygon annotations with undo/redo
- `Artifact` - Image data container (supports multiple formats)
- `Segment` - Single polygon definition
- `Geometry` - Point-in-polygon, hit testing utilities
- `Project` - Multi-image annotation project management
- `NormalizedFormatSerializer` - Format export/import

Pure C++ without Qt dependencies - can be used independently.

## Testing

```bash
# Run all tests
ctest -j$(nproc) --output-on-failure

# Run specific test
ctest -R segcore_unit_tests --output-on-failure

# Run with verbose output
ctest -VV
```

## Commit Message Format

Follow Conventional Commits:

```
type(scope): subject

body explaining why

footer with references
```

Types: feat, fix, refactor, docs, test, chore, style

Example:
```
refactor(libs): extract image processing to imgproc module

Separate image manipulation code into header-only imgproc library
to enable reuse without Qt dependencies.
```
Loading
Loading