MeVisLab Toolbox Reference
mlReleaseToolsMisc.h
Go to the documentation of this file.
1 // Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2 // **InsertLicense** code
3 //----------------------------------------------------------------------------------
5 
10 //----------------------------------------------------------------------------------
11 #pragma once
12 
13 // Local includes
14 #include "MLReleaseToolsSystem.h"
15 
16 // For StringVector.
17 #include "mlDirectoryMatching.h"
18 
19 // ML includes
20 #include <mlModuleIncludes.h>
21 
22 ML_START_NAMESPACE
23 
24 //----------------------------------------------------------------------------------
26 //----------------------------------------------------------------------------------
27 namespace ReleaseToolsMisc {
28 
30 MLRELEASE_TOOLS_EXPORT extern const std::string LineSeparator;
31 
38  const std::string &sep = LineSeparator);
39 
58  const ReleaseToolsIO::StringVector &regExpressionsVec,
59  std::vector<size_t> *matchedRegExIdxVec=nullptr);
60 
64  const std::string &regEx);
65 
68 MLRELEASE_TOOLS_EXPORT std::string filterLinesWithRegEx(const std::string &str,
69  const std::string &regEx,
70  const std::string &sep=LineSeparator);
71 
107  const bool useRegularExpression,
108  const std::string &firstExpression,
109  const std::string &lineEnd,
110  const MLint index,
111  std::string *errorInfos=nullptr);
112 
140  const std::vector<SubImage> &frameSubImgs,
141  MLint zTranslate = 0,
142  MLuint8 value = 1,
143  bool orValue = false);
144 
148 MLRELEASE_TOOLS_EXPORT bool isEquidistant(const std::vector<double> &dblVec, double eps=10e-5);
149 
152  Empty = 1,
153  Singular = 2,
154  Irregular = 4,
155  Uniform = 8,
160 };
161 
164 MLRELEASE_TOOLS_EXPORT int getMonotonicProperties(const std::vector<double> &dblVec, double eps=10e-5);
165 
178  const SubImage &subImg2,
179  double &avrOfSumOfSquaredDiffs);
180 
181 
185 template <typename DT1, typename DT2>
187  TSubImage<DT2> &img2,
188  SubImageBox box)
189  {
190  double avrOfSumOfSquaredDifferences = -1.;
191  box = box.intersect(img1.getBox().intersect(img2.getBox()));
192  if (!box.isEmpty()){
193  avrOfSumOfSquaredDifferences = 0.;
194  ImageVector p;
195  for (p.u = box.v1.u; p.u <= box.v2.u; ++p.u){
196  for (p.t = box.v1.t; p.t <= box.v2.t; ++p.t){
197  for (p.c = box.v1.c; p.c <= box.v2.c; ++p.c){
198  for (p.z = box.v1.z; p.z <= box.v2.z; ++p.z){
199  for (p.y = box.v1.y; p.y <= box.v2.y; ++p.y){
200  // Get pointers to row starts.
201  p.x = box.v1.x;
202  const DT1 *v1 = img1.getImagePointer(p);
203  const DT2 *v2 = img2.getImagePointer(p);
204  for (; p.x <= box.v2.x; ++p.x, ++v1, ++v2){
205  // Determine difference between both voxels and sum up squares.
206  const double diff = static_cast<double>(*v1) - static_cast<double>(*v2);
207  avrOfSumOfSquaredDifferences += diff*diff;
208  }
209  }
210  }
211  }
212  }
213  }
214  // Calculate the average of all of sum of squared differences.
215  avrOfSumOfSquaredDifferences /= static_cast<double>(box.getNumVoxels());
216  }
217  return avrOfSumOfSquaredDifferences;
218  }
219 
222 MLRELEASE_TOOLS_EXPORT std::string toBase64(const std::string &inString);
223 
226 MLRELEASE_TOOLS_EXPORT std::string fromBase64(const std::string &inString);
227 
235 MLRELEASE_TOOLS_EXPORT std::string createHashFromBytes(const unsigned char *data, size_t numBytes, const std::string &hashAlgorithm="SHA1");
236 
237 };
238 
239 ML_END_NAMESPACE
Project global and OS specific declarations.
#define MLRELEASE_TOOLS_EXPORT
DLL export macro definition.
This class manages/represents a rectangular 6d image region which is organized linearly in memory.
Definition: mlSubImage.h:75
const SubImageBox & getBox() const
Returns the box describing the origin/extent of the subimage.
Definition: mlSubImage.h:230
VectorType v1
Corner v1 of the subimage region (included in region).
Definition: mlSubImageBox.h:63
static TSubImageBox< intT > intersect(const TSubImageBox< intT > &box1, const TSubImageBox< intT > &box2)
Returns the overlapping region of subimage regions box1 and box2.
VectorType v2
Corner v2 of the subimage region (also included in region!).
Definition: mlSubImageBox.h:69
intT getNumVoxels() const
Returns number of voxels in the subimage region, i.e., the product of all extents if this is not empt...
bool isEmpty() const
Returns true if subimage region is empty, i.e., if any of the components of v1 is greater than the co...
This template class manages/represents a rectangular 6d image region in memory which is organized lin...
Definition: mlTSubImage.h:110
const DATATYPE * getImagePointer(const ImageVector &position) const
Returns a pointer to voxel data of image voxel at 6d position position relative to the begin of the c...
Definition: mlTSubImage.h:253
ComponentType c
Color component of the vector.
Definition: mlImageVector.h:65
ComponentType t
Time component of the vector.
Definition: mlImageVector.h:67
ComponentType u
Unit/Modality/User component of the vector.
Definition: mlImageVector.h:69
ComponentType z
Z component of the vector.
Definition: mlImageVector.h:63
ComponentType x
X component of the vector.
Definition: mlImageVector.h:59
ComponentType y
Y component of the vector.
Definition: mlImageVector.h:61
MLint32 MLErrorCode
Type of an ML Error code.
Definition: mlTypeDefs.h:818
Tool function(s) to determine translation information from one directory to another.
unsigned char MLuint8
Definition: mlTypeDefs.h:115
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578
std::vector< std::string > StringVector
Define often used string vector types.
MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector filterWithRegExVector(const ReleaseToolsIO::StringVector &strVec, const std::string &regEx)
Convenience version of filterWithRegExVector(strVec, regExpressionsVec, matchedRegExIdxVec) where reg...
MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector split(const std::string &value, const std::string &sep=LineSeparator)
Subdivides value at all positions of sep and returns all values in the vector.
MLRELEASE_TOOLS_EXPORT std::string toBase64(const std::string &inString)
Converts inString including the terminating null character to a Base64 coded string,...
MLRELEASE_TOOLS_EXPORT const std::string LineSeparator
The default line separator used for line endings.
MLRELEASE_TOOLS_EXPORT bool isEquidistant(const std::vector< double > &dblVec, double eps=10e-5)
Returns true if the number of elements in dblVec is <= 1 or if each dblVec[i]-dblVec[i-1] equals dblV...
MonotonicTypes
An enumerator describing whether elements of a vector have a monotonic order.
@ StrictlyMonotonicIncreasing
v[0] < v[1] < ... < v[N-1], N = v.size(), N > 1
@ MonotonicDecreasing
v[0] >= v[1] >= ... >= v[N-1], N = v.size(), N > 1
@ StrictlyMonotonicDecreasing
v[0] > v[1] > ... > v[N-1], N = v.size(), N > 1
@ Irregular
Nothing else: not empty, not singular, not uniform, and not monotonic.
@ Uniform
All elements are within an epsilon sized interval.
@ MonotonicIncreasing
v[0] <= v[1] <= ... <= v[N-1], N = v.size(), N > 1
MLRELEASE_TOOLS_EXPORT std::string filterLinesWithRegEx(const std::string &str, const std::string &regEx, const std::string &sep=LineSeparator)
Decompose str into lines with split(str, sep), filter them with filterWithRegExVector(strLines,...
MLRELEASE_TOOLS_EXPORT int getMonotonicProperties(const std::vector< double > &dblVec, double eps=10e-5)
Returns a bit mask contains bits defined in MonotonicTypes which describe properties of the elements ...
MLRELEASE_TOOLS_EXPORT std::string createHashFromBytes(const unsigned char *data, size_t numBytes, const std::string &hashAlgorithm="SHA1")
Creates a hash string for the numBytes bytes data pointed to by data; nullptr data and numBytes == 0 ...
MLRELEASE_TOOLS_EXPORT ReleaseToolsIO::StringVector filterLines(const ReleaseToolsIO::StringVector &inLines, const bool useRegularExpression, const std::string &firstExpression, const std::string &lineEnd, const MLint index, std::string *errorInfos=nullptr)
Searches lines in inLines which match given strings/expression to extract string value(s).
MLRELEASE_TOOLS_EXPORT std::string fromBase64(const std::string &inString)
Converts inString from a Base64 coded string to a decoded original string, assuming that the string h...
MLRELEASE_TOOLS_EXPORT MLErrorCode copyBitSubImagesToUInt8SubImage(SubImage &outSubImage, const std::vector< SubImage > &frameSubImgs, MLint zTranslate=0, MLuint8 value=1, bool orValue=false)
Decompose packed bit data from packed single pixel data in frameSubImgs to a normal MLuint8Type'd sub...
double calculateAverageOfSumOfSquaredDifferences(TSubImage< DT1 > &img1, TSubImage< DT2 > &img2, SubImageBox box)
Compares the average of the sum of squared differences over all voxels in the given box in correspond...