ImFusion C++ SDK 4.4.0
ImFusion::Utils Namespace Reference

Generic utility classes and helper functions. More...

Detailed Description

Generic utility classes and helper functions.

Collection of utility methods not associated with any class.

See also
ImFusionCoreUtils

Namespaces

namespace  EigenVectorWrapperImpl
 Wrapper classes for using std::vector<Eigen::Matrix<T,N,1>> with arbitrary T and N as input of a non-template function.

Classes

class  Expected
 An Expected<T, E> object is an object that contains the storage for another object and manages the lifetime of this contained object T. More...
class  Unexpected
class  bad_expected_access
class  NotCopyable
 Inherit from this class if your class should be neither copy-constructible nor assignable. More...
struct  Overloaded
 Syntactic sugar for easier implementation of visitors of a std::variant or our Utils::Variant. More...
class  ScopeGuard
 Templated proxy class to implement generic scope guards. More...
class  Span
 Describes a non-owning view into contiguous sequence of elements. More...
struct  Variant
 Specialization of std::variant offering additional convenience member functions for functionality that the standard library only provides in the form of free functions. More...
struct  Version
 Utility class to work with version information following the SemVer format. More...
struct  EigenVectorWrapper
 Simple case: non-optional input argument. More...
struct  OutputEigenVectorWrapper
 Non-optional output argument. More...
struct  OptionalEigenVectorWrapper
 Optional input argument. More...
struct  OptionalOutputEigenVectorWrapper
 Optional output argument. More...
class  LinearIterator
 Typed convenience iterator for quick integration into custom containers, especially if traversal requires on-the-fly evaluations. More...
struct  FileGuard
 Utility RAII class that deletes the given file when destructed. More...
class  AutoDisconnectSignals

Typedefs

using BoundingBoxAndLabel = std::pair<Geometry::AlignedBox, size_t>

Functions

template<class E>
constexpr bool operator== (const Unexpected< E > &lhs, const Unexpected< E > &rhs)
template<class E>
constexpr bool operator!= (const Unexpected< E > &lhs, const Unexpected< E > &rhs)
template<class E>
constexpr bool operator< (const Unexpected< E > &lhs, const Unexpected< E > &rhs)
template<class E>
constexpr bool operator<= (const Unexpected< E > &lhs, const Unexpected< E > &rhs)
template<class E>
constexpr bool operator> (const Unexpected< E > &lhs, const Unexpected< E > &rhs)
template<class E>
constexpr bool operator>= (const Unexpected< E > &lhs, const Unexpected< E > &rhs)
template<class E>
Unexpected< typename std::decay< E >::type > make_unexpected (E &&e)
template<class T, class E, class U, class F>
constexpr bool operator== (const Expected< T, E > &lhs, const Expected< U, F > &rhs)
template<class T, class E, class U, class F>
constexpr bool operator!= (const Expected< T, E > &lhs, const Expected< U, F > &rhs)
template<class E, class F>
constexpr bool operator== (const Expected< void, E > &lhs, const Expected< void, F > &rhs)
template<class E, class F>
constexpr bool operator!= (const Expected< void, E > &lhs, const Expected< void, F > &rhs)
template<class T, class E, class U>
constexpr bool operator== (const Expected< T, E > &x, const U &v)
template<class T, class E, class U>
constexpr bool operator== (const U &v, const Expected< T, E > &x)
template<class T, class E, class U>
constexpr bool operator!= (const Expected< T, E > &x, const U &v)
template<class T, class E, class U>
constexpr bool operator!= (const U &v, const Expected< T, E > &x)
template<class T, class E>
constexpr bool operator== (const Expected< T, E > &x, const Unexpected< E > &e)
template<class T, class E>
constexpr bool operator== (const Unexpected< E > &e, const Expected< T, E > &x)
template<class T, class E>
constexpr bool operator!= (const Expected< T, E > &x, const Unexpected< E > &e)
template<class T, class E>
constexpr bool operator!= (const Unexpected< E > &e, const Expected< T, E > &x)
template<class T, class E, detail::enable_if_t<(std::is_void< T >::value||std::is_move_constructible< T >::value) &&detail::is_swappable< T >::value &&std::is_move_constructible< E >::value &&detail::is_swappable< E >::value > * = nullptr>
void swap (Expected< T, E > &lhs, Expected< T, E > &rhs) noexcept(noexcept(lhs.swap(rhs)))
template<class... Ts>
 Overloaded (Ts...) -> Overloaded< Ts... >
template<typename T>
detail::RangeProxy< T > range (T begin, T end)
 An iterable wrapper for the half-open interval of integer numbers [begin, end).
template<typename T>
detail::RangeProxy< T > range (T end)
 An iterable wrapper for the half-open interval of integer numbers [0, end).
template<typename T>
detail::StepRangeProxy< T > range (T begin, T end, T step_size)
 An iterable wrapper for the uniformly numbers in the half-open interval [begin, end).
template<typename T>
detail::ReverseWrapper< T > reverse (T &&iterable)
 Iterator wrapper to reverse the iteration order.
template<class ReleaseFunc>
ScopeGuard< std::remove_reference_t< ReleaseFunc > > makeScopeGuard (ReleaseFunc &&f)
 Generator function to instantiate a ScopeGuard without writing out the templates.
template<class AcquisitionFunc, class ReleaseFunc>
ScopeGuard< std::remove_reference_t< ReleaseFunc > > makeScopeGuard (AcquisitionFunc &&acquisitionFunc, ReleaseFunc &&releaseFunc)
 Generator function to first execute acquisitionFunc and then instantiate a ScopeGuard with releaseFunc.
template<class T, size_t N>
 Span (T(&)[N]) -> Span< T, N >
template<class T, size_t N>
 Span (std::array< T, N > &) -> Span< T, N >
template<class T, size_t N>
 Span (const std::array< T, N > &) -> Span< const T, N >
template<class Container>
 Span (Container &) -> Span< typename std::remove_reference< decltype(*std::data(std::declval< Container & >()))>::type >
template<class Container>
 Span (const Container &) -> Span< const typename Container::value_type >
void applyMask (const MemImage *inImg, const MemImage *mask, MemImage *outImg, double outsideValue, bool const thresholdValue, bool const aboveThreshold, bool const elevateInside)
template<int R, typename Iter>
std::vector< std::array< typename Iter::value_type, R > > combinations (Iter begin, Iter end)
 Return r length subsequences of elements from the input iterable.
template<typename T>
sampleFromSequence (const std::vector< double > &x, const std::vector< T > &y, double x0, std::function< T(T, T, double)> interpFunc=[](T a, T b, double w) { return static_cast< T >(w *b+(1.0 - w) *a);})
 Given a sequence of values y measured at sampling points x, returns the linearly interpolated value for a specific x0.
template<typename T>
std::vector< T > resampleSequence (const std::vector< T > &vals, const std::vector< double > &tHave, const std::vector< double > &tWant, std::function< T(T, T, double)> interpFunc=[](T a, T b, double w) { return w *b+(1.0 - w) *a;})
 Resamples a sequence of values val measured at timestamps tHave with the new timestamps tWant.
template<typename T, typename U>
bool sortByVector (std::vector< T > &toBeSorted, std::vector< U > &valuesToSortBy)
 Sorts a vector according to the values in another vector, for cases where you somehow cannot work with structs containing both values.
template<typename ContainerT>
std::vector< std::tuple< typename ContainerT::const_iterator, typename ContainerT::const_iterator, double > > kMeans (const ContainerT &c, int numCluster, int numIter, std::function< double(const typename ContainerT::value_type &)> mapTToDouble=[](const typename ContainerT::value_type &elem) -> double { return static_cast< double >(elem);})
 A container-based 1D k-means clustering that checks whether all elements in a container are equal to each other.
void autoWindow (const SharedImageSet &img, bool applyTo2dDisplayOptions=true, bool applyTo3dDisplayOptions=true, double lowerLimit=0.0, double upperLimit=0.0)
 Update window/level of img to show the entire intensity range of the image.
template<typename T>
Image::Type imageTypeId ()
template<typename T>
PixelType pixelTypeId ()
mat4 getRenderMatrixToWorld (const SharedImageSet &img, int which=-1)
 Obtains the matrix to render the given image in 2D, MPR, and 3D views.
mat4 getRenderMatrixFromWorld (const SharedImageSet &img, int which=-1)
 Obtains the matrix to render the given image in 2D, MPR, and 3D views.
template<typename T>
bool operator> (const LinearIterator< T > &c1, const LinearIterator< T > &c2)
template<typename T>
bool operator>= (const LinearIterator< T > &c1, const LinearIterator< T > &c2)
template<typename T>
bool operator< (const LinearIterator< T > &c1, const LinearIterator< T > &c2)
template<typename T>
bool operator<= (const LinearIterator< T > &c1, const LinearIterator< T > &c2)
std::string defaultModelsPath ()
 Returns the default path of the machine learning models.
std::string sdkDocDirectory ()
 Returns the absolute directory of the C++ SDK documentation.
std::string userDocDirectory ()
 Returns the absolute directory of the HTML user documentation.
std::string pythonDocDirectory ()
 Returns the absolute directory to the Python documentation.
std::string licenseAgreementDirectory ()
 Returns the absolute directory to the License and Acknowledgments files.
std::string uniqueIdFromUsbPath (const std::string &usbPath)
 Tries to get a unique identifier from a USB device path.
std::vector< std::stringenumerateUsbDevices ()
template<typename F, typename... Args>
auto typeSwitch (Image::Type itype, F &&func, Args &&... args)
 Function for internally type switching a given lambda function on the Image::Type cases.
template<typename F, typename... Args>
auto typeSwitch (const MemImage &img, F &&func, Args &&... args)
 Function for internally type switching a given lambda function on the Image::Type cases.
template<typename F, typename... Args>
auto typeSwitch (const PixelType &type, F &&func, Args &&... args)
std::string vecBoolToString (const std::vector< bool > &vec)
std::vector< bool > stringToVecBool (const std::string &str, size_t vecBoolSize)
QString randomString (int len)
QString generateUniqueID ()
bool paramToQString (const Properties &p, const char *param, QString &out)
const std::vector< vec4 > & colors ()
QString validityToError (Seg::LabelValidity v)
double computeAccuracyScore (SharedImageSet &result, SharedImageSet &gt, int nbClasses)
void setWindowLevel (const SharedImageSet &sis, const ViewerMetadata &m)
void setLabelDataComponent (const SharedImageSet &labelSis, const std::vector< Project::PixelwiseLabelType > &labelTypes, bool globalVis2D, bool globalVis3D, const std::vector< bool > &visibility={})
bool isDemoVersion ()
Filesystem::Path logFileLocation ()
 Returns the path to the global log file.
std::unique_ptr< SharedImageSetrunPixelwiseModel (const QString &path, SharedImageSet &image, SharedImageSet &labels, const RegionOfInterest &roi)
std::unique_ptr< SharedImageSetrunWorkspace (const QString &filename, SharedImageSet &image, SharedImageSet &labels, const RegionOfInterest &roi, QWidget *parent=nullptr)
void updateRegionWithinROI (TypedImage< unsigned char > &main, const TypedImage< unsigned char > &subRegion, const RegionOfInterest &roi)
void runFunctionsROI (TypedImage< unsigned char > &labels, const RegionOfInterest &roi, std::function< void(size_t ind)> fOnlyInside, std::function< void(size_t ind)> fOnlyOutside, std::function< void(size_t ind)> fEverywhere)
void runFunctionInsideROI (TypedImage< unsigned char > &labels, const RegionOfInterest &roi, std::function< void(size_t ind)> f)
void runFunctionOutsideROI (TypedImage< unsigned char > &labels, const RegionOfInterest &roi, std::function< void(size_t ind)> f)
void applyMorphoOperation (SharedImageSet &labels, MorphologicalOperationsAlgorithm::OperationMode opMode, int opSize)
template<typename T>
T * pickLayer (const std::vector< std::unique_ptr< T > > &vec, std::optional< size_t > first, std::optional< size_t > second)
std::pair< QString, QString > volumeDisplay (size_t numPixels, const ImageDescriptor &desc, mat4 imageMat)
template<typename LayerType>
std::vector< Project::TypeMapping > identityLayerMapping (const std::vector< std::unique_ptr< LayerType > > &layers)
std::unique_ptr< TypedImage< unsigned char > > boundingBoxesToLabelMap (const SharedImage &image, const std::vector< BoundingBoxAndLabel > &boundingBoxes)
 Converts a list of BoundingBox types to a label map for the given reference image.
void boundingBoxesToLabelMap (const SharedImage &image, TypedImage< unsigned char > &labelmap, const std::vector< BoundingBoxAndLabel > &boundingBoxes)
 Same as boundingBoxesToLabelMap above, but uses the provided labelmap.
std::unique_ptr< SharedImageSetconvertSignedLabelMap (const SharedImageSet &labels)
QString elideName (const QString &name, const int maxNameLen, const std::string &elisionStr=" [...] ")
 Shortens name whose length exceeds maxNameLen using elision string elisionStr.
std::string modelsLocalDirDefault ()

Variables

PythonInterpreterInterfaceg_pythonInterpreter
 Pointer to the embedded Python interpreter (if any).
std::unique_ptr< LabelsPythonBridgeInterface > g_pythonBridge
 Pointer to the bridge providing Labels types to the above interpreter.

Function Documentation

◆ combinations()

template<int R, typename Iter>
std::vector< std::array< typename Iter::value_type, R > > ImFusion::Utils::combinations ( Iter begin,
Iter end )

Return r length subsequences of elements from the input iterable.

Combinations are emitted in lexicographic sort order. So, if the input iterable is sorted, the combination tuples will be produced in sorted order. Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeat values in each combination.

std::vector<std::string>> l = {"A", "B", "C", "D"};
T begin(T... args)
T end(T... args)
std::vector< std::array< typename Iter::value_type, R > > combinations(Iter begin, Iter end)
Return r length subsequences of elements from the input iterable.
Definition Containers.h:28

Returns {{"A", "B"}, {"A", "C"}, {"A", "D"}, {"B", "C"}, {"B", "D"}, {"C", "D"}}

◆ sampleFromSequence()

template<typename T>
T ImFusion::Utils::sampleFromSequence ( const std::vector< double > & x,
const std::vector< T > & y,
double x0,
std::function< T(T, T, double)> interpFunc = [](T a, T b, double w) { return static_cast<T>(w * b + (1.0 - w) * a); } )

Given a sequence of values y measured at sampling points x, returns the linearly interpolated value for a specific x0.

If the target sampling point is outside the measurement range given by x, it will return the closest valid y. x needs to be monotonically increasing, but does not have to be equidistant.

◆ kMeans()

template<typename ContainerT>
std::vector< std::tuple< typename ContainerT::const_iterator, typename ContainerT::const_iterator, double > > ImFusion::Utils::kMeans ( const ContainerT & c,
int numCluster,
int numIter,
std::function< double(const typename ContainerT::value_type &)> mapTToDouble = [](const typename ContainerT::value_type& elem) -> double { return static_cast<double>(elem); } )

A container-based 1D k-means clustering that checks whether all elements in a container are equal to each other.

Parameters
cA container of elements. Needs to be sorted in ascending order with respect to mapTToDouble.
numClusterExpected number of clusters.
numIterNumber of iterations for the k-means.
mapTToDoubleMapping of the elements of c to a double value. The same mapping needs to be used for sorting.
Returns
A vector of tuples (first, end, mean) with numIter elements. The const iterators first and second give the range of each cluster [first,end) with mean providing the corresponding mean value of the cluster.

◆ autoWindow()

void ImFusion::Utils::autoWindow ( const SharedImageSet & img,
bool applyTo2dDisplayOptions = true,
bool applyTo3dDisplayOptions = true,
double lowerLimit = 0.0,
double upperLimit = 0.0 )

Update window/level of img to show the entire intensity range of the image.

Parameters
imgImage to change the windowing for.
applyTo2dDisplayOptionsFlag whether update the DisplayOptions2d attached to img.
applyTo3dDisplayOptionsFlag whether update the DisplayOptions3d attached to img.
lowerLimitRatio of lower values removed by the auto windowing.
upperLimitRatio of upper values removed by the auto windowing.

◆ getRenderMatrixToWorld()

mat4 ImFusion::Utils::getRenderMatrixToWorld ( const SharedImageSet & img,
int which = -1 )

Obtains the matrix to render the given image in 2D, MPR, and 3D views.

The function evaluates to img.matrixToWorld() for standard SharedImageSets, but correctly considers the internal matrix for derived types (CBCT data, TrackedSharedImageSets, etc.)

◆ getRenderMatrixFromWorld()

mat4 ImFusion::Utils::getRenderMatrixFromWorld ( const SharedImageSet & img,
int which = -1 )

Obtains the matrix to render the given image in 2D, MPR, and 3D views.

The function evaluates to img.matrixFromWorld() for standard SharedImageSets, but correctly considers the internal matrix for derived types (CBCT data, TrackedSharedImageSets, etc.)

◆ defaultModelsPath()

std::string ImFusion::Utils::defaultModelsPath ( )

Returns the default path of the machine learning models.

Use Settings::defaultFolderMLModels to get a path which can be changed by the user.

◆ logFileLocation()

Filesystem::Path ImFusion::Utils::logFileLocation ( )

Returns the path to the global log file.

Assumes that there is only a single FileSink configured.

◆ boundingBoxesToLabelMap() [1/2]

std::unique_ptr< TypedImage< unsigned char > > ImFusion::Utils::boundingBoxesToLabelMap ( const SharedImage & image,
const std::vector< BoundingBoxAndLabel > & boundingBoxes )

Converts a list of BoundingBox types to a label map for the given reference image.

The boundingBoxes are a pair of the box and the label value it will get assigned in the labelmap. If boundingBoxes are overlapping, the boundingBoxes in the front of the vector will overwrite the ones in the back. The labelmap is created with the same size as the image. The image is also used to convert the world coordinates of the bounding boxes to pixel coordinates.

◆ boundingBoxesToLabelMap() [2/2]

void ImFusion::Utils::boundingBoxesToLabelMap ( const SharedImage & image,
TypedImage< unsigned char > & labelmap,
const std::vector< BoundingBoxAndLabel > & boundingBoxes )

Same as boundingBoxesToLabelMap above, but uses the provided labelmap.

The labelmap is not cleared, so values outside any bounding box are unchanged.

Search Tab / S to search, Esc to close