Skip to content

Commit

Permalink
Swap to tl-ranges. Add FOV check
Browse files Browse the repository at this point in the history
  • Loading branch information
spinicist committed Mar 6, 2024
1 parent 6ad70b7 commit aa7b243
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 23 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ find_package(FFTW3f CONFIG REQUIRED)
find_package(unofficial-graphicsmagick CONFIG REQUIRED)
find_package(hdf5 CONFIG REQUIRED)
find_package(NIFTI CONFIG REQUIRED)
find_package(range-v3 CONFIG REQUIRED)
find_package(scn CONFIG REQUIRED)
find_package(tl-ranges CONFIG REQUIRED)

# Ensure this is always defined across all .cpp files
add_definitions(-DEIGEN_USE_THREADS)
Expand Down Expand Up @@ -100,7 +100,7 @@ target_link_libraries(vineyard PUBLIC
hdf5::hdf5-static
hdf5::hdf5_hl-static
NIFTI::niftiio
range-v3
tl::ranges
scn::scn
)
set_target_properties(vineyard PROPERTIES
Expand All @@ -126,13 +126,13 @@ add_executable(riesling
src/cmd/filter.cpp
src/cmd/frames.cpp
src/cmd/grad.cpp
src/cmd/graphics.cpp
src/cmd/grid.cpp
src/cmd/h5.cpp
# src/cmd/lad.cpp
src/cmd/lookup.cpp
src/cmd/lsmr.cpp
src/cmd/lsqr.cpp
src/cmd/montage.cpp
src/cmd/merge.cpp
src/cmd/nii.cpp
src/cmd/noisify.cpp
Expand Down
2 changes: 0 additions & 2 deletions src/cmd/frames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "log.hpp"
#include "parse_args.hpp"

#include <range/v3/numeric.hpp>

int main_frames(args::Subparser &parser)
{
args::Positional<std::string> oname(parser, "OUTPUT", "Name for the basis file");
Expand Down
26 changes: 14 additions & 12 deletions src/cmd/graphics.cpp → src/cmd/montage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include "tensorOps.hpp"
#include "types.hpp"
#include <Magick++.h>
#include <range/v3/range.hpp>
#include <range/v3/view.hpp>
#include <ranges>
#include <tl/chunk.hpp>
#include <tl/to.hpp>
#include <scn/scn.h>
#include <sys/ioctl.h>

Expand Down Expand Up @@ -61,10 +62,10 @@ auto SliceData(rl::Cx3 const &data,
auto const N = slN ? std::min(slN, maxN) : maxN;

std::vector<Magick::Image> slices;
for (Index iK = start; iK <= end; iK += maxN / N) {
for (Index iK = start; iK <= end; iK += maxN / (N - 1)) {
rl::Cx2 temp = data.chip(iK, slDim);
auto const slice = rl::Colorize(temp, win, grey, log);
slices.push_back(Magick::Image(dShape[(slDim + 1) % 3], dShape[(slDim + 3) % 2], "RGB", Magick::CharPixel, slice.data()));
slices.push_back(Magick::Image(dShape[(slDim + 1) % 3], dShape[(slDim + 2) % 3], "RGB", Magick::CharPixel, slice.data()));
}
return slices;
}
Expand All @@ -75,17 +76,18 @@ auto DoMontage(std::vector<Magick::Image> &slices, Index const cols, Index const
Magick::Montage montageOpts;
montageOpts.backgroundColor(Magick::Color(0, 0, 0));
montageOpts.tile(Magick::Geometry(cols, rows));
montageOpts.geometry(Magick::Geometry(px, px));
montageOpts.geometry(slices.front().size());
std::vector<Magick::Image> frames;
Magick::montageImages(&frames, slices.begin(), slices.end(), montageOpts);
frames.front().size().width(), frames.front().size().height();
return frames.front();
}

void Kittify(Magick::Image &graphic)
{
struct winsize winSize;
ioctl(0, TIOCGWINSZ, &winSize);
auto const scaling = winSize.ws_xpixel / graphic.size().width();
auto const scaling = winSize.ws_xpixel / (float)graphic.size().width();
graphic.resize(Magick::Geometry(winSize.ws_xpixel, scaling * graphic.size().height()));
Magick::Blob blob;
graphic.write(&blob);
Expand All @@ -94,18 +96,18 @@ void Kittify(Magick::Image &graphic)
if (b64.size() <= ChunkSize) {
fmt::print(stderr, "\x1B_Ga=T,f=100;{}\x1B\\", b64);
} else {
auto const chunks = b64 | ranges::views::chunk(ChunkSize);
auto const chunks = b64 | tl::views::chunk(ChunkSize);
auto const nChunks = chunks.size();
fmt::print(stderr, "\x1B_Ga=T,f=100,m=1;{}\x1B\\", std::string_view(chunks[0].data(), chunks[0].size()));
for (size_t i = 1; i < nChunks - 1; i++) {
fmt::print(stderr, "\x1B_Gm=1;{}\x1B\\", std::string_view(chunks[i].data(), chunks[i].size()));
fmt::print(stderr, "\x1B_Ga=T,f=100,m=1;{}\x1B\\", std::string_view(chunks.front().data(), chunks.front().size()));
for (auto && chunk : chunks | std::ranges::views::drop(1) | std::ranges::views::take(nChunks - 2)) {
fmt::print(stderr, "\x1B_Gm=1;{}\x1B\\", std::string_view(chunk.data(), chunk.size()));
}
fmt::print(stderr, "\x1B_Gm=0;{}\x1B\\", std::string_view(chunks[nChunks - 1].data(), chunks[nChunks - 1].size()));
fmt::print(stderr, "\x1B_Gm=0;{}\x1B\\", std::string_view(chunks.back().data(), chunks.back().size()));
}
fmt::print(stderr, "\n");
}

int main_graphics(args::Subparser &parser)
int main_montage(args::Subparser &parser)
{
args::Positional<std::string> iname(parser, "FILE", "HD5 file to slice");
args::Positional<std::string> oname(parser, "FILE", "Image file to save");
Expand Down
5 changes: 5 additions & 0 deletions src/cropper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "cropper.h"

#include <ranges>

namespace rl {

Cropper::Cropper(Sz3 const matrix, Sz3 const fullSz, Eigen::Array3f const voxelSz, Eigen::Array3f const extent)
Expand Down Expand Up @@ -36,6 +38,9 @@ void Cropper::calcStart(Sz3 const &fullSz)
{
// After truncation the -1 makes even and odd sizes line up the way we want
st_ = Sz3{(fullSz[0] - (sz_[0] - 1)) / 2, (fullSz[1] - (sz_[1] - 1)) / 2, (fullSz[2] - (sz_[2] - 1)) / 2};
if (std::ranges::any_of(st_, [](Index const x) { return x < 0; })) {
Log::Fail("Requested crop size {} was larger than available size {}", sz_, fullSz);
}
}

Sz3 Cropper::size() const { return sz_; }
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ int main(int const argc, char const *const argv[])
COMMAND(filter, "filter", "Apply Tukey filter to image");
COMMAND(frames, "frames", "Create a frame basis");
COMMAND(grad, "grad", "Apply grad/div operator");
COMMAND(graphics, "graphics", "Make beautiful output images");
COMMAND(grid, "grid", "Grid from/to non/cartesian");
COMMAND(h5, "h5", "Probe an H5 file");
// COMMAND(lad, "lad", "Least Absolute Deviations");
COMMAND(lookup, "lookup", "Basis dictionary lookup");
COMMAND(lsmr, "lsmr", "Recon with LSMR optimizer");
COMMAND(lsqr, "lsqr", "Recon with LSQR optimizer");
COMMAND(montage, "montage", "Make beautiful output images");
COMMAND(merge, "merge", "Merge non-cartesian data");
COMMAND(noisify, "noisify", "Add noise to dataset");
COMMAND(nii, "nii", "Convert h5 to nifti");
Expand Down
9 changes: 5 additions & 4 deletions src/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include <cfenv>
#include <cmath>
#include <range/v3/range.hpp>
#include <range/v3/view.hpp>
#include <ranges>
#include <tl/chunk.hpp>
#include <tl/to.hpp>

#include "tensorOps.hpp"

Expand Down Expand Up @@ -216,11 +217,11 @@ Mapping<Rank>::Mapping(Trajectory const &traj, float const nomOS, Index const kW
std::vector<Bucket> chunked;
for (auto &bucket : buckets) {
if (bucket.size() > splitSize) {
for (auto const indexChunk : ranges::views::chunk(bucket.indices, splitSize)) {
for (auto const indexChunk : tl::views::chunk(bucket.indices, splitSize)) {
chunked.push_back(Bucket{.gridSize = bucket.gridSize,
.minCorner = bucket.minCorner,
.maxCorner = bucket.maxCorner,
.indices = indexChunk | ranges::to<std::vector<int32_t>>()});
.indices = indexChunk | tl::to<std::vector<int32_t>>()});
}
bucket.indices.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
]
},
"nifticlib",
"range-v3",
"scnlib",
"tl-ranges",
"zlib"
],
"builtin-baseline":"53bef8994c541b6561884a8395ea35715ece75db",
Expand Down

0 comments on commit aa7b243

Please sign in to comment.