17#include <itksys/SystemTools.hxx>
20#include "mitkIGTException.h"
21#include "mitkIGTIOException.h"
56 this->SetNthInput(m_NumberOfInputs,
66 m_RecordingMode = mode;
74 DataObjectPointerArray inputs = this->GetInputs();
80 sysTimestamp = m_SystemTimeClock->GetCurrentStamp();
83 std::ostringstream strs;
86 std::string sysTimeStr = strs.str();
95 *m_Stream <<
"TimeStamp";
96 for (
unsigned int index = 0; index < inputs.size(); index++){ *m_Stream <<
";Valid_Tool" << index <<
100 ";QX_Tool" << index <<
101 ";QY_Tool" << index <<
102 ";QZ_Tool" << index <<
103 ";QR_Tool" << index;}
107 *m_Stream << timestamp;
111 for (
unsigned int index = 0; index < inputs.size(); index++)
120 bool hasPosition =
true;
121 bool hasOrientation =
true;
122 bool dataValid =
false;
125 matrix.SetIdentity();
127 position = nd->GetPosition();
128 orientation = nd->GetOrientation();
129 matrix = nd->GetCovErrorMatrix();
131 hasPosition = nd->GetHasPosition();
132 hasOrientation = nd->GetHasOrientation();
143 tinyxml2::XMLDocument doc;
144 auto *elem = doc.NewElement(
"NavigationData");
146 elem->SetAttribute(
"Time", timestamp);
147 elem->SetAttribute(
"SystemTime", sysTimeStr.c_str());
148 elem->SetAttribute(
"Tool", index);
149 elem->SetAttribute(
"X", position[0]);
150 elem->SetAttribute(
"Y", position[1]);
151 elem->SetAttribute(
"Z", position[2]);
153 elem->SetAttribute(
"QX", orientation[0]);
154 elem->SetAttribute(
"QY", orientation[1]);
155 elem->SetAttribute(
"QZ", orientation[2]);
156 elem->SetAttribute(
"QR", orientation[3]);
158 elem->SetAttribute(
"C00", matrix[0][0]);
159 elem->SetAttribute(
"C01", matrix[0][1]);
160 elem->SetAttribute(
"C02", matrix[0][2]);
161 elem->SetAttribute(
"C03", matrix[0][3]);
162 elem->SetAttribute(
"C04", matrix[0][4]);
163 elem->SetAttribute(
"C05", matrix[0][5]);
164 elem->SetAttribute(
"C10", matrix[1][0]);
165 elem->SetAttribute(
"C11", matrix[1][1]);
166 elem->SetAttribute(
"C12", matrix[1][2]);
167 elem->SetAttribute(
"C13", matrix[1][3]);
168 elem->SetAttribute(
"C14", matrix[1][4]);
169 elem->SetAttribute(
"C15", matrix[1][5]);
172 elem->SetAttribute(
"Valid",1);
174 elem->SetAttribute(
"Valid",0);
177 elem->SetAttribute(
"hO",1);
179 elem->SetAttribute(
"hO",0);
182 elem->SetAttribute(
"hP",1);
184 elem->SetAttribute(
"hP",0);
188 it = m_AdditionalAttributes.find( nd );
189 if( it != m_AdditionalAttributes.end() )
191 elem->SetAttribute(it->second.first.c_str(), it->second.second.c_str());
194 tinyxml2::XMLPrinter printer;
197 *m_Stream <<
" " << printer.CStr() << std::endl;
201 *m_Stream <<
";" << dataValid <<
";" << position[0] <<
";" << position[1] <<
";" << position[2] <<
";" << orientation[0] <<
";" << orientation[1] <<
";" << orientation[2] <<
";" << orientation[3];
211 if ((m_RecordCountLimit<=m_RecordCounter)&&(m_RecordCountLimit != -1)) {StopRecording();}
215 const std::string& attributeName
216 ,
const std::string& attributeValue )
219 it = m_AdditionalAttributes.find( nd );
220 if( it == m_AdditionalAttributes.end() )
221 m_AdditionalAttributes[nd] = std::pair<std::string, std::string>(attributeName, attributeValue);
224 it->second.first = attributeName;
225 it->second.second = attributeValue;
233 it = m_AdditionalAttributes.find( nd );
234 if( it != m_AdditionalAttributes.end() )
235 m_AdditionalAttributes.erase(it);
243 if (m_Stream ==
nullptr)
245 std::stringstream ss;
246 std::ostream* stream;
249 std::string tmpPath = itksys::SystemTools::GetFilenamePath(m_FileName);
250 m_FileName = itksys::SystemTools::GetFilenameWithoutExtension(m_FileName);
251 std::string extension =
".xml";
255 ss << tmpPath <<
"/" << m_FileName <<
"-" << m_NumberOfRecordedFiles << extension;
257 if( m_DoNotOverwriteFiles )
259 unsigned int index = m_NumberOfRecordedFiles+1;
260 while( itksys::SystemTools::FileExists( ss.str().c_str() ) )
263 ss << tmpPath <<
"/" << m_FileName <<
"-" << index << extension;
268 switch(m_RecordingMode)
275 if (m_FileName ==
"")
277 std::string message =
"No file name or file path set.";
278 MITK_ERROR << message;
283 stream =
new std::ofstream(ss.str().c_str());
289 MITK_WARN <<
"Sorry no ZipFile support yet";
297 m_StreamMustBeDeleted =
true;
300 StartRecording(stream);
305 MITK_WARN <<
"Already recording please stop before start new recording session";
314 MITK_WARN <<
"Already recording please stop before start new recording session";
319 m_Stream->precision(10);
323 if (m_Stream->good())
327 *m_Stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" << std::endl;
330 *m_Stream <<
" " <<
"<Data ToolCount=\"" << (m_NumberOfInputs) <<
"\" version=\"1.0\">" << std::endl;
346 std::cout <<
"You have to start a recording first" << std::endl;
352 *m_Stream <<
"</Data>" << std::endl;
355 m_NumberOfRecordedFiles++;
358 if (m_StreamMustBeDeleted)
360 m_StreamMustBeDeleted =
false;
An object of this class represents an exception of the MITK-IGT module.
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
void Start(itk::Object::Pointer device)
starts the time-acquisition
double GetElapsed()
returns the time elapsed since calling Start() for the first time in milliseconds
void StopRecording()
Stops the recording and closes the stream.
bool m_StreamMustBeDeleted
void GenerateData() override
filter execute method here it is not used
void RemoveAdditionalAttribute(const NavigationData *nd)
bool m_Recording
indicates whether the recording is started or not
int m_RecordCounter
counts the number of frames which are recorded since StartRecording
void SetRecordingMode(RecordingMode mode)
Sets the recording mode which causes different types of output streams see enum RecordingMode.
void Update() override
Every call of update causes one line for each added NavigationData in the output if the recording was...
bool m_DoNotOverwriteFiles
do not overwrite any files if true
void SetAdditionalAttribute(const NavigationData *nd, const std::string &attributeName, const std::string &attributeValue)
void StartRecording()
Starts the recording with the presetted OutputMode. This method calls StartRecording(std::ostream*)....
unsigned int m_NumberOfInputs
counts the numbers of added input NavigationDatas
mitk::RealTimeClock::Pointer m_SystemTimeClock
system time clock for system time tag in output xml file
virtual void AddNavigationData(const NavigationData *nd)
Adds the input NavigationDatas.
std::string m_FileName
stores the file name and path
~NavigationDataRecorderDeprecated() override
unsigned int m_NumberOfRecordedFiles
necessary for the naming of the file if there is more than one start-stop cycle
NavigationDataRecorderDeprecated()
RecordingMode m_RecordingMode
stores the mode see enum RecordingMode
std::ostream * m_Stream
the output stream
int m_RecordCountLimit
limits the number of frames, recording will be stopped if the limit is reached. -1 disables the limit
RecordingMode
Determines where the output is directed to.
OutputFormatEnum m_OutputFormat
stores the output format; see enum OutputFormat
itk::Matrix< mitk::ScalarType, 6, 6 > CovarianceMatrixType
type that holds the error characterization of the position and orientation measurements
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
double TimeStampType
type that holds the time at which the data was recorded in milliseconds
virtual bool IsDataValid() const
returns true if the object contains valid data
mitk::Point3D PositionType
Type that holds the position part of the tracking data.
static Pointer New(void)
instanciates a new, operating-system dependant, instance of mitk::RealTimeClock.