Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Dev-ops, N+1 offset, temporary directory #5

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
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
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on: [push, pull_request]

env:
BUILD_TYPE: Debug

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest, ubuntu-latest]
include:
- os: macos-latest
- os: ubuntu-latest

steps:

- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install Conan
run: pip install conan pytest && conan --version

- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.22.x'

- name: Build
run: |
mkdir build && cd build
conan profile new ./.conan --detect
conan profile update settings.compiler.libcxx=libstdc++11 ./.conan
conan install --profile ./.conan ..
cmake -S .. -B . && make

- name: Test
run: |
build/bin/tests
env:
TRX_TMPDIR: ${{ runner.temp }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
libtrx.a
tests/data
.vscode
data
32 changes: 15 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
set(LOCAL_PROJECT_NAME "trx")
set(LOCAL_PROJECT_VERSION "0.1.0")

cmake_minimum_required(VERSION 3.0.0)
cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0079 NEW)
project(trx VERSION 0.1.0)
set (CMAKE_CXX_STANDARD 11)
project(${LOCAL_PROJECT_NAME} VERSION ${LOCAL_PROJECT_VERSION})
set(CMAKE_CXX_STANDARD 11)

option(TRX_USE_CONAN "Should Conan package manager be used?" ON)

#set(CMAKE_BUILD_TYPE RelWithDebInfo)
set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE Release)

find_package(libzip REQUIRED)
find_package (Eigen3 CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)

add_library(trx src/trx.cpp src/trx.tpp src/trx.h)

TARGET_LINK_LIBRARIES(trx
PRIVATE
nlohmann_json::nlohmann_json
libzip::zip
Eigen3::Eigen
spdlog::spdlog
spdlog::spdlog_header_only
)
add_library(${LOCAL_PROJECT_NAME} src/trx.cpp src/trx.tpp)

include(cmake/ConanSetup.cmake)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

option(TRX_TESTS "Build the tests" ON)
if(TRX_TESTS)
add_subdirectory(tests)
endif()
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,48 @@
The C++ implementations to the memory-mapped tractography file format.

## Installation

The project requires `gcc`, `make` and `cmake`. Please refer to your OS instructions
for proper installation.

### Dependencies
- c++11 compiler / cmake
- libzip
- nlohmann::json
- Eigen3
- spdlog
- GTest (optional)

### Installing
`cmake . && make`
The project dependencies are handled using [Conan](https://conan.io/).
Its installation can be found in their [documentation](https://docs.conan.io/en/latest/installation.html).
TL;DR: It is basically `pip install conan`, and works for Python >= 3.6.

To install the dependencies, run the following:
```bash
# Fresh build
rm -Rf build && mkdir build && cd build

# Creates a Conan profile relative to the project
conan profile new ./.conan --detect && conan profile update settings.compiler.libcxx=libstdc++11 ./.conan

# Install dependencies
conan install --build=missing --settings=build_type=Debug --profile ./.conan ..

# Build
cmake -S .. -B . && make
```
### Running tests

In `./build`:
```bash
bin/tests
```

### Iterating the code with new changes

In `./build`:
```bash
make && bin/tests
```

## How to use
COMING SOON

Examples to set up:
- Adding to my project without cmake?
- Adding to my project without conan
- Adding to my project with conan
19 changes: 19 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake


class TRX(ConanFile):
name = "trx"
version = "1.0.0"
description = "TRX (tee-ar-ex), a community-oriented unified tractography file"
license = "BSD-2-Clause"
url = "https://tee-ar-ex.github.io/"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
requires = [
"eigen/3.4.0@#3bc2bf84eff697283b6bd64d8262c423",
"spdlog/1.10.0@#1e0f4eb6338d05e4bd6fcc6bf4734172",
"nlohmann_json/3.11.2@#a35423bb6e1eb8f931423557e282c7ed",
"libzip/1.8.0@#5a0a692ec9d7d8a4337eb79e55869639",
"mio/cci.20201220",
"gtest/cci.20210126",
]
28 changes: 0 additions & 28 deletions examples/CMakeLists.txt

This file was deleted.

30 changes: 30 additions & 0 deletions examples/install-using-conan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.0.0)
cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0079 NEW)
project(trx_example)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)

add_executable(load_trx load_trx.cpp)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

# target_link_libraries(
# ${LOCAL_PROJECT_NAME}
# PRIVATE ${CONAN_LIBS}
# )

# target_include_directories(${LOCAL_PROJECT_NAME}
# PUBLIC
# $<INSTALL_INTERFACE:include>
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# PRIVATE
# ${CMAKE_CURRENT_SOURCE_DIR}/src
# ${CMAKE_CURRENT_BINARY_DIR}/gen-private-include
# ${CONAN_INCLUDE_DIRS}
# )

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
11 changes: 11 additions & 0 deletions examples/install-using-conan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

```bash
conan editable add ../.. trx/1.0.0@user/channel
```

```bash
cd .. && rm -Rf build && mkdir build && cd build
conan profile new ./.conan --detect && conan profile update settings.compiler.libcxx=libstdc++11 ./.conan
conan install --build=missing --settings=build_type=Debug --profile ./.conan ..
cmake -S .. -B . && make
```
5 changes: 5 additions & 0 deletions examples/install-using-conan/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[requires]
trx/1.0.0@user/channel

[generators]
cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../src/trx.h"
#include <trx/trx.h>

using namespace trxmmap;
int main(int argc, char **argv)
Expand Down
13 changes: 13 additions & 0 deletions examples/install-using-vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.0.0)
project(trx_example)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)

add_executable(load_trx load_trx.cpp)

set(TRX_USE_CONAN OFF)
add_subdirectory(vendor/trx)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
33 changes: 33 additions & 0 deletions examples/install-using-vendor/load_trx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <trx/trx.h>

using namespace trxmmap;
int main(int argc, char **argv)
{
trxmmap::TrxFile<half> *trx = trxmmap::load_from_zip<half>(argv[1]);

std::cout << "Vertices: " << trx->streamlines->_data.size() / 3 << "\n";
std::cout << "First vertex (x,y,z): " << trx->streamlines->_data(0, 0)
<< "," << trx->streamlines->_data(0, 1)
<< "," << trx->streamlines->_data(0, 2) << "\n";
std::cout << "Streamlines: " << trx->streamlines->_offsets.size() << "\n";
std::cout << "Vertices in first streamline: " << trx->streamlines->_offsets(1) - trx->streamlines->_offsets(0) << "\n";
std::cout << "dpg (data_per_group) items: " << trx->data_per_group.size() << "\n";
std::cout << "dps (data_per_streamline) items: " << trx->data_per_streamline.size() << "\n";

for (auto const &x : trx->data_per_streamline)
{
std::cout << "'" << x.first << "' items: "
<< x.second->_matrix.size()
<< "\n";
}

std::cout << "dpv (data_per_vertex) items:" << trx->data_per_vertex.size() << "\n";
for (auto const &x : trx->data_per_vertex)
{
std::cout << "'" << x.first << "' items: "
<< x.second->_data.size()
<< "\n";
}

std::cout << *trx << std::endl;
}
6 changes: 6 additions & 0 deletions src/trx.h → include/trx/trx.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <mio/mmap.hpp>
#include <mio/shared_mmap.hpp>

#ifndef SPDLOG_FMT_EXTERNAL
#define SPDLOG_FMT_EXTERNAL
#endif
#include "spdlog/spdlog.h"

using namespace Eigen;
Expand Down Expand Up @@ -282,6 +285,8 @@ namespace trxmmap
*/
void zip_from_folder(zip_t *zf, const std::string root, const std::string directory, zip_uint32_t compression_standard = ZIP_CM_STORE);

std::string get_extraction_dir();
int free_extraction_dir(std::string extraction_dir);
std::string get_base(const std::string &delimiter, const std::string &str);
std::string get_ext(const std::string &str);
void populate_fps(const char *name, std::map<std::string, std::tuple<long long, long long>> &file_pointer_size);
Expand All @@ -291,6 +296,7 @@ namespace trxmmap
int rm_dir(const char *d);

std::string rm_root(std::string root, const std::string path);

#include "trx.tpp"

}
Expand Down
24 changes: 24 additions & 0 deletions scripts/fetch_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR/..

function hashcheck() {
MD5=$(md5sum "$1" | cut -d " " -f1)
if [[ $MD5 != $2 ]]
then
echo "md5sum for $1 does not match. Please remove the file to download it again."
exit 1
fi
}

mkdir -p data

curl -L https://figshare.com/ndownloader/files/37624154 --output data/DSI.zip
hashcheck data/DSI.zip b847f053fc694d55d935c0be0e5268f7 # V1 (27.09.2022)

curl -L https://figshare.com/ndownloader/files/37624148 --output data/memmap_test_data.zip
hashcheck data/memmap_test_data.zip 03f7651a0f9e3eeabee9aed0ad5f69e1 # V2 (27.09.2022)

curl -L https://figshare.com/ndownloader/files/37624151 --output data/trx_from_scratch.zip
hashcheck data/trx_from_scratch.zip d9f220a095ce7f027772fcd9451a2ee5 # V2 (27.09.2022)
Loading