Fraxinus  18.10
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 sign(double x)
38 {
39  if (x>=0)
40  return 1;
41  return -1;
42 }
43 
44 QString changeExtension(QString name, QString ext)
45 {
46  QStringList splitName = name.split(".");
47 
48  if (splitName.size()==1)
49  return name;
50 
51  splitName[splitName.size()-1] = ext;
52 
53  if (ext.isEmpty())
54  {
55  splitName.pop_back();
56  }
57 
58  return splitName.join(".");
59 }
60 
61 void sleep_ms(int ms)
62 {
63 #ifndef CX_WINDOWS
64  usleep(ms*1000);
65 #else
66  Sleep(ms);
67 #endif
68 }
69 
70 } // namespace cx
71 
double constrainValue(double val, double min, double max)
int sign(double x)
QString changeExtension(QString name, QString ext)
void sleep_ms(int ms)
Namespace for all CustusX production code.