Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include <iostream>
34 #include <string>
35 #include <vector>
36 #include <sstream>
37 
38 #include <QtWidgets>
39 
40 #include <boost/cstdint.hpp>
41 #include <limits>
42 
43 #include "cxTransform3D.h"
44 #include "cxPositionStorageFile.h"
45 #include "cxUtilHelpers.h"
46 #include "cxTime.h"
47 #include "cxTypeConversions.h"
48 
49 #define EVENT_DATE_FORMAT "yyyy:MM:dd-HH:mm:ss.zzz000"
50 
53 int main(int argc, char **argv)
54 {
55  QApplication app(argc, argv);
56  int arg = 1;
57 
58  if (argc<2)
59  {
60  std::cout << "Usage: sscPositionFileReader [-v] <filename> <timestamp>\nTimestamp format " << EVENT_DATE_FORMAT << std::endl;
61  return 0;
62  }
63 
64 
65  bool verbose = (QString(argv[1]) == "-v");
66  if (verbose) arg++;
67  QString posFile(argv[arg++]);
68  cx::PositionStorageReader reader(posFile);
69  QString startTS;
70  if (argc == arg + 1)
71  {
72  startTS = QString(argv[arg++]);
73  }
74  else if (reader.version() == 1)
75  {
76  std::cout << "This is a version 1 of the record format, and requires a timestamp parameter.";
77  return 0;
78  }
79 
80  boost::uint64_t tsModifier = 0;
81  if (reader.version() == 1)
82  {
83  QDateTime startTime = QDateTime::fromString(startTS, EVENT_DATE_FORMAT);
84  boost::uint64_t ret64 = startTime.toTime_t();
85  ret64 *= 1000;
86 
87  // workaround for compilling 32 bit version:
88  tsModifier = ret64 & (std::numeric_limits<boost::uint64_t>::max() ^ 0xffffffff); // ffffffffffffffff XOR 00000000ffffffff = ffffffff00000000
89  //boost::uint64_t tsModifier = ret64 & 0xffffffff00000000;
90  std::cout << "Start time: " << startTS << ", converted to " << startTime.toString(EVENT_DATE_FORMAT) << std::endl;
91  }
92 
93 
94  cx::Transform3D T = cx::Transform3D::Identity();
95  double timestamp;
96  QString toolIndex;
97 
98 // QDateTime now = QDateTime::currentDateTime();
99 // boost::uint64_t now_t64 = now.toTime_t();
100 // now_t64 *= 1000;
101 // now_t64 += now.time().msec();
102 //
103 // std::cout << "now_t64 " << now_t64 << std::endl;
104 // uint now_t = now.toTime_t()*1000 + now.time().msec(); //milliseconds
105 // std::cout << "now.toTime_t() " << now.toTime_t() << std::endl;
106 // std::cout << "now.toTime_t()*1000 + now.time().msec() " << now_t << std::endl;
107 // std::cout << "test dir: " << PositionStorageReader::timestampToString(now_t64) << std::endl;
108 // std::cout << "test now: " << PositionStorageReader::timestampToString(getMilliSecondsSinceEpoch()) << std::endl;
109 // std::cout << "test now: " << PositionStorageReader::timestampToString(getMicroSecondsSinceEpoch()/1000) << std::endl;
110 
111 
112  std::cout << "reading file [" << posFile.toStdString() << "]" << std::endl;
113  if (!verbose)
114  std::cout << "[index]\ttimestamp\tmatrix\ttoolIndex" << std::endl;
115  int index = 0;
116  while (!reader.atEnd())
117  {
118  if (reader.version() == 1)
119  {
120  int index = 0;
121  if (!reader.read(&T, &timestamp, &index))
122  break;
123  toolIndex = QString(index);
124  }
125  else
126  {
127  if (!reader.read(&T, &timestamp, &toolIndex))
128  break;
129  }
130 
131  boost::uint64_t ts64 = (boost::uint64_t)timestamp;
132  if (reader.version() == 1)
133  {
134  ts64 |= tsModifier;
135  }
136 
137  if (verbose)
138  {
139  std::cout
140  << "index:\t"<< index << '\t'
141  << "tool id:\t" << toolIndex.toStdString() << '\t'
142 // << "timestamp:\t" << timestamp << '\n'
143  << "timestamp:\t" << cx::PositionStorageReader::timestampToString((double)ts64).toStdString() << '\n'
144  << "matrix:\n" << T << '\n'
145  << std::endl;
146  }
147  else
148  {
149  std::cout << "[" << index << "]" << '\t';
150  std::cout << cx::PositionStorageReader::timestampToString((double)ts64).toStdString() << '\t';
151  boost::array<double, 16> val = T.flatten();
152  cx::stream_range(std::cout, val.begin(), val.end(), ' ');
153  std::cout << '\t' << toolIndex.toStdString();
154  std::cout << std::endl;
155  }
156 
157  ++index;
158  }
159 
160  return 0;
161 }
static QString timestampToString(double timestamp)
#define EVENT_DATE_FORMAT
Definition: main.cpp:49
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:53
int main(int argc, char *argv[])
Definition: main.cpp:37
Reader class for the position file.
bool read(Transform3D *matrix, double *timestamp, int *toolIndex)