Skip to content

Instantly share code, notes, and snippets.

View N-Dekker's full-sized avatar

Niels Dekker N-Dekker

  • LKEB, Leiden University Medical Center
View GitHub Profile
@N-Dekker
N-Dekker / function-template-argument.cpp
Last active December 11, 2023 21:35
std::function versus template argument
// Related to https://github.com/InsightSoftwareConsortium/ITK/pull/4347
// PERF: Replace `std::function` with template argument MultiThreaderBase ParallelizeImageRegion, ParallelizeImageRegionRestrictDirection
// Niels Dekker, LKEB, Leiden University Medical Center, 2023
#include <itkImageRegion.h>
#include <algorithm>
#include <chrono>
#include <numeric>
#include <vector>
#include <chrono>
using namespace std::chrono;
const auto timePoint = high_resolution_clock::now();
// Do the time consuming work here!
std::cout << " Duration: "
<< duration_cast<duration<double>>(high_resolution_clock::now() - timePoint).count() << " seconds" << std::endl;
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// Script to add in-class {} member initializers to ITK classes that have one or more virtual member function,
// itkNewMacro, itkSimpleNewMacro, or itkCreateAnotherMacro calls.
//
// Only tested with Visual Studio 2019 (C++14).
//
// Needs to have the directory path to the ITK sources as command-line argument, for example:
@N-Dekker
N-Dekker / ElastixTranslationExample.cxx
Created February 10, 2022 09:44
ElastixTranslationExample for elastix 4.8 lib interface
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
@N-Dekker
N-Dekker / gist:b5b85167efb752af1e0c0198d8d0ee68
Created November 22, 2020 21:04
Print ITK Transform classes and their number of parameters
/*
Related to:
https://github.com/SuperElastix/elastix/pull/358#issuecomment-731736374
Niels Dekker, LKEB, Leiden University Medical Center, 2020
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*/
@N-Dekker
N-Dekker / EstimateAxisAlignedBoundingBoxRegion.hxx
Last active April 6, 2019 11:57
EstimateAxisAlignedBoundingBoxRegion (ITK5)
/*
Estimates the axis-aligned minimum bounding box of the buffered region of an image.
Roughly equivalent to ImageMaskSpatialObject::GetAxisAlignedBoundingBoxRegion() from
"itkImageMaskSpatialObject.hxx", at
github.com/InsightSoftwareConsortium/ITK/blob/91ab86f63eb5fc9799bb25fa49e76adf0d1b5251/Modules/Core/SpatialObjects/include
Related to:
"ENH: GTest for ImageMaskSpatialObject::GetAxisAlignedBoundingBoxRegion()"
@N-Dekker
N-Dekker / IncreaseCapacityNeighborhoodAllocatorVector.cxx
Created January 13, 2019 19:58
Estimates duration of increasing the capacity of `std::vector<itk::NeighborhoodAllocator<int>>`
/*
Estimates the runtime duration that it takes to increase the capacity of
an `std::vector<itk::NeighborhoodAllocator<int>>`.
With VS2017, the `vector::reserve` in this test appears to run more than 4x faster,
now that `itk::NeighborhoodAllocator` has a move-constructor that is `noexcept`.
Related to the discussion, "Regarding C++11 noexcept" at the ITK forum:
https://discourse.itk.org/t/regarding-c-11-noexcept/1517
@N-Dekker
N-Dekker / ConstNeighborhoodIteratorGetPixelWithIsInBoundsPerf.cxx
Created October 24, 2018 16:01
Measures performance of ConstNeighborhoodIterator::GetPixel(i,isInBounds), related to http://review.source.kitware.com/#/c/23826 by Bradley Lowekamp
/*
Measures performance of "old-school" ConstNeighborhoodIterator::GetPixel(i, isInBounds)
Related to the patch "PERF: Improve ConstNeighborhoodIterator::GetPixel(i, isInBounds )",
http://review.source.kitware.com/#/c/23826/ by Bradley Lowekamp
Niels Dekker, LKEB, Leiden University Medical Center, 2018
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@N-Dekker
N-Dekker / ConstNeighborhoodIteratorPerf.cxx
Created October 22, 2018 16:29
Measures performance of itk::ConstNeighborhoodIterator for http://review.source.kitware.com/#/c/23813
/*
Measures performance of "old-school" itk::ConstNeighborhoodIterator.
Related to the patch "PERF: Made ConstNeighborhoodIterator::GetPixel(i) much faster",
http://review.source.kitware.com/#/c/23813/.
Niels Dekker, LKEB, Leiden University Medical Center, 2018
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@N-Dekker
N-Dekker / CompareOldAndRangeBasedConstantBoundary.cxx
Last active November 7, 2018 17:19
Compares performance of "old-school" and new range-based neighborhood iteration using http://review.source.kitware.com/#/c/23795/7
/*
Compares performance of "old-school" neighborhood iteration, using
itk::ConstantBoundaryCondition, and range-based neighborhood iteration,
using the patch "WIP: Added policy for constant NeighborhoodRange values
outside image", http://review.source.kitware.com/#/c/23795/7.
Niels Dekker, LKEB, Leiden University Medical Center, 2018
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,