Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxtestUtilities.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXTESTUTILITIES_H_
13 #define CXTESTUTILITIES_H_
14 
15 #include "cxtestutilities_export.h"
16 
17 #include <vector>
18 #include "vtkForwardDeclarations.h"
19 #include "cxForwardDeclarations.h"
20 #include "cxVector3D.h"
21 #include <string>
22 #include <QString>
23 #include "sscConfig.h"
24 
25 namespace cxtest
26 {
27 
28 struct CXTESTUTILITIES_EXPORT TestUtilities
29 {
30  static inline QString GetDataRoot();
31  static inline QString ExpandDataFileName(QString fileName);
32 };
33 
34 inline
36 {
37  QString dataRoot = SSC_DATA_ROOT;
38  return dataRoot;
39 }
40 
41 inline
42 QString TestUtilities::ExpandDataFileName(QString fileName)
43 {
44  QString dataRoot = SSC_DATA_ROOT;
45  QString expandedName = dataRoot + fileName;
46  return expandedName;
47 }
48 
55 class CXTESTUTILITIES_EXPORT Utilities
56 {
57 public:
58  static QString getDataRoot(QString suffix = "");
59  static vtkImageDataPtr create3DVtkImageData(Eigen::Array3i dim = Eigen::Array3i(3,3,3), const unsigned int voxelValue = 100);
60  static cx::ImagePtr create3DImage(Eigen::Array3i dim = Eigen::Array3i(3,3,3), const unsigned int voxelValue = 100);
61  static cx::ImagePtr create3DImage(Eigen::Array3i dim, cx::Vector3D spacing, const unsigned int voxelValue);
62  static std::vector<cx::ImagePtr> create3DImages(unsigned int imageCount, Eigen::Array3i dim = Eigen::Array3i(3,3,3), const unsigned int voxelValue = 100);
63 
64  static unsigned int getNumberOfVoxelsAboveThreshold(vtkImageDataPtr image, int threshold, int component=0);
65  static unsigned int getNumberOfNonZeroVoxels(vtkImageDataPtr image);
66  static double getFractionOfVoxelsAboveThreshold(vtkImageDataPtr image, int threshold, int component=0);
67 
68  static void sleep_sec(int seconds);
69 };
70 
71 //To link the executable (Catch) which runs the tests on Windows, each test lib must contain at least one class to be exported.
72 //If your test lib doesn't contain any classes which must be exported, this macro can be used to create a dummy class in a uniform way across the code base.
73 //Put this macro in a cpp file in your test folder. To make it more visible the name cxtestExportDummyClassOnWindowsForLinking.cpp has been used for such files.
74 //Remember to include the export header file and then use this macro with the export macro for your lib.
75 //Example:
76 // #include "cxtest_org_custusx_registration_method_manual_export.h"
77 //
78 // namespace
79 // {
80 // EXPORT_DUMMY_CLASS_FOR_LINKING_ON_WINDOWS_IN_LIB_WITHOUT_EXPORTED_CLASS(CXTEST_ORG_CUSTUSX_REGISTRATION_METHOD_MANUAL_EXPORT)
81 // }
82 #define EXPORT_DUMMY_CLASS_FOR_LINKING_ON_WINDOWS_IN_LIB_WITHOUT_EXPORTED_CLASS(EXPORT_MACRO) \
83 class EXPORT_MACRO DummyTestClassForLinkingOnWindows \
84 { \
85 };
86 
87 } /* namespace cxtest */
88 #endif /* CXTESTUTILITIES_H_ */
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
static QString GetDataRoot()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
static QString ExpandDataFileName(QString fileName)
vtkSmartPointer< class vtkImageData > vtkImageDataPtr