21 #include <itksys/SystemTools.hxx>
24 #include "mitkIGTException.h"
25 #include "mitkIGTIOException.h"
60 this->SetNthInput(m_NumberOfInputs,
61 const_cast< mitk::NavigationData * >( nd ) );
70 m_RecordingMode = mode;
78 DataObjectPointerArray inputs = this->GetInputs();
84 sysTimestamp = m_SystemTimeClock->GetCurrentStamp();
87 std::ostringstream strs;
90 std::string sysTimeStr = strs.str();
99 *m_Stream <<
"TimeStamp";
100 for (
unsigned int index = 0; index < inputs.size(); index++){ *m_Stream <<
";Valid_Tool" << index <<
101 ";X_Tool" << index <<
102 ";Y_Tool" << index <<
103 ";Z_Tool" << index <<
104 ";QX_Tool" << index <<
105 ";QY_Tool" << index <<
106 ";QZ_Tool" << index <<
107 ";QR_Tool" << index;}
111 *m_Stream << timestamp;
115 for (
unsigned int index = 0; index < inputs.size(); index++)
124 bool hasPosition =
true;
125 bool hasOrientation =
true;
126 bool dataValid =
false;
129 matrix.SetIdentity();
147 auto elem =
new TiXmlElement(
"NavigationData");
149 elem->SetDoubleAttribute(
"Time", timestamp);
150 elem->SetAttribute(
"SystemTime", sysTimeStr);
151 elem->SetDoubleAttribute(
"Tool", index);
152 elem->SetDoubleAttribute(
"X", position[0]);
153 elem->SetDoubleAttribute(
"Y", position[1]);
154 elem->SetDoubleAttribute(
"Z", position[2]);
156 elem->SetDoubleAttribute(
"QX", orientation[0]);
157 elem->SetDoubleAttribute(
"QY", orientation[1]);
158 elem->SetDoubleAttribute(
"QZ", orientation[2]);
159 elem->SetDoubleAttribute(
"QR", orientation[3]);
161 elem->SetDoubleAttribute(
"C00", matrix[0][0]);
162 elem->SetDoubleAttribute(
"C01", matrix[0][1]);
163 elem->SetDoubleAttribute(
"C02", matrix[0][2]);
164 elem->SetDoubleAttribute(
"C03", matrix[0][3]);
165 elem->SetDoubleAttribute(
"C04", matrix[0][4]);
166 elem->SetDoubleAttribute(
"C05", matrix[0][5]);
167 elem->SetDoubleAttribute(
"C10", matrix[1][0]);
168 elem->SetDoubleAttribute(
"C11", matrix[1][1]);
169 elem->SetDoubleAttribute(
"C12", matrix[1][2]);
170 elem->SetDoubleAttribute(
"C13", matrix[1][3]);
171 elem->SetDoubleAttribute(
"C14", matrix[1][4]);
172 elem->SetDoubleAttribute(
"C15", matrix[1][5]);
175 elem->SetAttribute(
"Valid",1);
177 elem->SetAttribute(
"Valid",0);
180 elem->SetAttribute(
"hO",1);
182 elem->SetAttribute(
"hO",0);
185 elem->SetAttribute(
"hP",1);
187 elem->SetAttribute(
"hP",0);
191 it = m_AdditionalAttributes.find( nd );
192 if( it != m_AdditionalAttributes.end() )
194 elem->SetAttribute(it->second.first, it->second.second);
197 *m_Stream <<
" " << *elem << std::endl;
203 *m_Stream <<
";" << dataValid <<
";" << position[0] <<
";" << position[1] <<
";" << position[2] <<
";" << orientation[0] <<
";" << orientation[1] <<
";" << orientation[2] <<
";" << orientation[3];
213 if ((m_RecordCountLimit<=m_RecordCounter)&&(m_RecordCountLimit != -1)) {StopRecording();}
217 const std::string& attributeName
218 ,
const std::string& attributeValue )
221 it = m_AdditionalAttributes.find( nd );
222 if( it == m_AdditionalAttributes.end() )
223 m_AdditionalAttributes[nd] = std::pair<std::string, std::string>(attributeName, attributeValue);
226 it->second.first = attributeName;
227 it->second.second = attributeValue;
235 it = m_AdditionalAttributes.find( nd );
236 if( it != m_AdditionalAttributes.end() )
237 m_AdditionalAttributes.erase(it);
245 if (m_Stream ==
nullptr)
247 std::stringstream ss;
248 std::ostream* stream;
251 std::string tmpPath = itksys::SystemTools::GetFilenamePath(m_FileName);
252 m_FileName = itksys::SystemTools::GetFilenameWithoutExtension(m_FileName);
253 std::string extension =
".xml";
257 ss << tmpPath <<
"/" << m_FileName <<
"-" << m_NumberOfRecordedFiles << extension;
259 if( m_DoNotOverwriteFiles )
261 unsigned int index = m_NumberOfRecordedFiles+1;
262 while( itksys::SystemTools::FileExists( ss.str().c_str() ) )
265 ss << tmpPath <<
"/" << m_FileName <<
"-" << index << extension;
270 switch(m_RecordingMode)
277 if (m_FileName ==
"")
279 std::string message =
"No file name or file path set.";
285 stream =
new std::ofstream(ss.str().c_str());
291 MITK_WARN <<
"Sorry no ZipFile support yet";
299 m_StreamMustBeDeleted =
true;
302 StartRecording(stream);
305 else if (m_Recording)
307 MITK_WARN <<
"Already recording please stop before start new recording session";
316 MITK_WARN <<
"Already recording please stop before start new recording session";
321 m_Stream->precision(10);
325 if (m_Stream->good())
329 *m_Stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" << std::endl;
332 *m_Stream <<
" " <<
"<Data ToolCount=\"" << (m_NumberOfInputs) <<
"\" version=\"1.0\">" << std::endl;
348 std::cout <<
"You have to start a recording first" << std::endl;
354 *m_Stream <<
"</Data>" << std::endl;
357 m_NumberOfRecordedFiles++;
360 if (m_StreamMustBeDeleted)
362 m_StreamMustBeDeleted =
false;
void SetAdditionalAttribute(const NavigationData *nd, const std::string &attributeName, const std::string &attributeValue)
NavigationDataRecorderDeprecated()
void SetRecordingMode(RecordingMode mode)
Sets the recording mode which causes different types of output streams see enum RecordingMode.
unsigned int m_NumberOfInputs
counts the numbers of added input NavigationDatas
void RemoveAdditionalAttribute(const NavigationData *nd)
itk::Matrix< mitk::ScalarType, 6, 6 > CovarianceMatrixType
type that holds the error characterization of the position and orientation measurements ...
void StopRecording()
Stops the recording and closes the stream.
virtual ~NavigationDataRecorderDeprecated()
double GetElapsed()
returns the time elapsed since calling Start() for the first time in milliseconds ...
An object of this class represents an exception of the MITK-IGT module.
virtual OrientationType GetOrientation() const
returns the orientation of the NavigationData object
int m_RecordCounter
counts the number of frames which are recorded since StartRecording
virtual void GenerateData() override
filter execute method here it is not used
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
virtual void AddNavigationData(const NavigationData *nd)
Adds the input NavigationDatas.
std::string m_FileName
stores the file name and path
std::ostream * m_Stream
the output stream
double TimeStampType
type that holds the time at which the data was recorded
void StartRecording()
Starts the recording with the presetted OutputMode. This method calls StartRecording(std::ostream*). Does nothing if the recorder is already recording and the method StartRecording is called again.
bool m_StreamMustBeDeleted
virtual CovarianceMatrixType GetCovErrorMatrix() const
gets the 6x6 Error Covariance Matrix of the NavigationData object
mitk::RealTimeClock::Pointer m_SystemTimeClock
system time clock for system time tag in output xml file
RecordingMode
Determines where the output is directed to.
bool m_Recording
indicates whether the recording is started or not
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
RecordingMode m_RecordingMode
stores the mode see enum RecordingMode
void Start(itk::Object::Pointer device)
starts the time-acquisition
unsigned int m_NumberOfRecordedFiles
necessary for the naming of the file if there is more than one start-stop cycle
virtual bool GetHasOrientation() const
gets the HasOrientation flag of the NavigationData object
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual PositionType GetPosition() const
returns position of the NavigationData object
#define mitkThrowException(classname)
bool m_DoNotOverwriteFiles
do not overwrite any files if true
OutputFormatEnum m_OutputFormat
stores the output format; see enum OutputFormat
virtual bool GetHasPosition() const
gets the HasPosition flag of the NavigationData object
static Pointer New(void)
instanciates a new, operating-system dependant, instance of mitk::RealTimeClock.
int m_RecordCountLimit
limits the number of frames, recording will be stopped if the limit is reached. -1 disables the limit...
virtual void Update()
Every call of update causes one line for each added NavigationData in the output if the recording was...