NorMIT-nav
22.09
An IGT application
cxUtilHelpers.cpp
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
#include "
cxUtilHelpers.h
"
13
#include <QStringList>
14
15
#ifndef CX_WINDOWS
16
#include <unistd.h>
17
#endif
18
19
#ifdef CX_WINDOWS
20
#include <windows.h>
21
#endif
22
23
namespace
cx
24
{
25
28
double
constrainValue
(
double
val,
double
min,
double
max)
29
{
30
if
(val<=min)
31
return
min;
32
if
(val>=max)
33
return
max;
34
return
val;
35
}
36
37
int
constrainValue
(
int
val,
int
min,
int
max)
38
{
39
if
(val<=min)
40
return
min;
41
if
(val>=max)
42
return
max;
43
return
val;
44
}
45
46
int
sign
(
double
x)
47
{
48
if
(x>=0)
49
return
1;
50
return
-1;
51
}
52
53
QString
changeExtension
(QString name, QString ext)
54
{
55
QStringList splitName = name.split(
"."
);
56
57
if
(splitName.size()==1)
58
return
name;
59
60
splitName[splitName.size()-1] = ext;
61
62
if
(ext.isEmpty())
63
{
64
splitName.pop_back();
65
}
66
67
return
splitName.join(
"."
);
68
}
69
70
void
sleep_ms
(
int
ms)
71
{
72
#ifndef CX_WINDOWS
73
usleep(ms*1000);
74
#else
75
Sleep(ms);
76
#endif
77
}
78
79
80
}
// namespace cx
81
cx
Namespace for all CustusX production code.
Definition:
cx_dev_group_definitions.h:13
cxUtilHelpers.h
cx::changeExtension
QString changeExtension(QString name, QString ext)
Definition:
cxUtilHelpers.cpp:53
cx::sleep_ms
void sleep_ms(int ms)
Definition:
cxUtilHelpers.cpp:70
cx::constrainValue
double constrainValue(double val, double min, double max)
Definition:
cxUtilHelpers.cpp:28
cx::sign
int sign(double x)
Definition:
cxUtilHelpers.cpp:46
CX
source
resource
core
utilities
cxUtilHelpers.cpp
Generated on Tue Sep 13 2022 11:06:16 for NorMIT-nav by
1.8.17