Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
main.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 <iostream>
13 #include <string>
14 #include <vector>
15 #include <sstream>
16 
17 #include <QtWidgets>
18 
19 #include <boost/cstdint.hpp>
20 #include <limits>
21 
22 #include "cxTransform3D.h"
23 #include "cxPositionStorageFile.h"
24 #include "cxUtilHelpers.h"
25 #include "cxTime.h"
26 #include "cxTypeConversions.h"
27 
28 #define EVENT_DATE_FORMAT "yyyy:MM:dd-HH:mm:ss.zzz000"
29 
32 int main(int argc, char **argv)
33 {
34  QApplication app(argc, argv);
35  int arg = 1;
36 
37  if (argc<2)
38  {
39  std::cout << "Usage: sscPositionFileReader [-v] <filename> <timestamp>\nTimestamp format " << EVENT_DATE_FORMAT << std::endl;
40  return 0;
41  }
42 
43 
44  bool verbose = (QString(argv[1]) == "-v");
45  if (verbose) arg++;
46  QString posFile(argv[arg++]);
47  cx::PositionStorageReader reader(posFile);
48  QString startTS;
49  if (argc == arg + 1)
50  {
51  startTS = QString(argv[arg++]);
52  }
53  else if (reader.version() == 1)
54  {
55  std::cout << "This is a version 1 of the record format, and requires a timestamp parameter.";
56  return 0;
57  }
58 
59  boost::uint64_t tsModifier = 0;
60  if (reader.version() == 1)
61  {
62  QDateTime startTime = QDateTime::fromString(startTS, EVENT_DATE_FORMAT);
63  boost::uint64_t ret64 = startTime.toTime_t();
64  ret64 *= 1000;
65 
66  // workaround for compilling 32 bit version:
67  tsModifier = ret64 & (std::numeric_limits<boost::uint64_t>::max() ^ 0xffffffff); // ffffffffffffffff XOR 00000000ffffffff = ffffffff00000000
68  //boost::uint64_t tsModifier = ret64 & 0xffffffff00000000;
69  std::cout << "Start time: " << startTS << ", converted to " << startTime.toString(EVENT_DATE_FORMAT) << std::endl;
70  }
71 
72 
73  cx::Transform3D T = cx::Transform3D::Identity();
74  double timestamp;
75  QString toolIndex;
76 
77 // QDateTime now = QDateTime::currentDateTime();
78 // boost::uint64_t now_t64 = now.toTime_t();
79 // now_t64 *= 1000;
80 // now_t64 += now.time().msec();
81 //
82 // std::cout << "now_t64 " << now_t64 << std::endl;
83 // uint now_t = now.toTime_t()*1000 + now.time().msec(); //milliseconds
84 // std::cout << "now.toTime_t() " << now.toTime_t() << std::endl;
85 // std::cout << "now.toTime_t()*1000 + now.time().msec() " << now_t << std::endl;
86 // std::cout << "test dir: " << PositionStorageReader::timestampToString(now_t64) << std::endl;
87 // std::cout << "test now: " << PositionStorageReader::timestampToString(getMilliSecondsSinceEpoch()) << std::endl;
88 // std::cout << "test now: " << PositionStorageReader::timestampToString(getMicroSecondsSinceEpoch()/1000) << std::endl;
89 
90 
91  std::cout << "reading file [" << posFile.toStdString() << "]" << std::endl;
92  if (!verbose)
93  std::cout << "[index]\ttimestamp\tmatrix\ttoolIndex" << std::endl;
94  int index = 0;
95  while (!reader.atEnd())
96  {
97  if (reader.version() == 1)
98  {
99  int index = 0;
100  if (!reader.read(&T, &timestamp, &index))
101  break;
102  toolIndex = QString(index);
103  }
104  else
105  {
106  if (!reader.read(&T, &timestamp, &toolIndex))
107  break;
108  }
109 
110  boost::uint64_t ts64 = (boost::uint64_t)timestamp;
111  if (reader.version() == 1)
112  {
113  ts64 |= tsModifier;
114  }
115 
116  if (verbose)
117  {
118  std::cout
119  << "index:\t"<< index << '\t'
120  << "tool id:\t" << toolIndex.toStdString() << '\t'
121 // << "timestamp:\t" << timestamp << '\n'
122  << "timestamp:\t" << cx::PositionStorageReader::timestampToString((double)ts64).toStdString() << '\n'
123  << "matrix:\n" << T << '\n'
124  << std::endl;
125  }
126  else
127  {
128  std::cout << "[" << index << "]" << '\t';
129  std::cout << cx::PositionStorageReader::timestampToString((double)ts64).toStdString() << '\t';
130  boost::array<double, 16> val = T.flatten();
131  cx::stream_range(std::cout, val.begin(), val.end(), ' ');
132  std::cout << '\t' << toolIndex.toStdString();
133  std::cout << std::endl;
134  }
135 
136  ++index;
137  }
138 
139  return 0;
140 }
static QString timestampToString(double timestamp)
#define EVENT_DATE_FORMAT
Definition: main.cpp:28
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
std::ostream & stream_range(std::ostream &s, ITER begin, ITER end, char separator=' ')
Definition: cxUtilHelpers.h:32
int main(int argc, char *argv[])
Definition: main.cpp:16
Reader class for the position file.
bool read(Transform3D *matrix, double *timestamp, int *toolIndex)