1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
/*=========================================================================
Program: Image Guided Surgery Software Toolkit
Module: $RCSfile: igstkOpenIGTLinkTrackerConfigurationFileReader.h,v $
Language: C++
Date: $Date: 2009-06-04 19:49:05 $
Version: $Revision: 1.1 $
Copyright (c) ISC Insight Software Consortium. All rights reserved.
See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __igstkOpenIGTLinkTrackerConfigurationFileReader_h
#define __igstkOpenIGTLinkTrackerConfigurationFileReader_h
#include "igstkStateMachine.h"
#include "igstkTrackerConfigurationXMLFileReaderBase.h"
#include "igstkTrackerConfiguration.h"
#include "igstkMacros.h"
#include "igstkObject.h"
namespace igstk
{
/** \class OpenIGTLinkTrackerConfigurationFileReader
*
* \brief This class is an IGSTK wrapper for all readers of xml files
* containing a tracker configuration with additional OpenIGTLink
* data (each tool should send data to the specified host on the
* specified port).
*
* This class is an IGSTK wrapper for all readers of xml files
* containing a tracker configuration with additional OpenIGTLink
* data (each tool should send data to the specified host on the
* specified port).
* The specific type of tracker (Micron, Aurora...) configuration is
* defined by the actual reader given in the RequestSetReader() method.
*
*/
class OpenIGTLinkTrackerConfigurationFileReader : public Object
{
public:
/**Macro with standard traits declarations (Self, SuperClass, state machine
* etc.). */
igstkStandardClassTraitsMacro( OpenIGTLinkTrackerConfigurationFileReader,
Object )
/** This is the container type which holds all the data associated with the
* tracker configuration (e.g. COM port...).*/
typedef TrackerConfiguration::Pointer TrackerConfigurationDataType;
typedef std::pair<std::string, unsigned int> ConnectionDataType;
typedef std::map<std::string, std::vector<ConnectionDataType> >
OpenIGTLinkDataType;
/**
* A container with tracker and open IGT link settings. Each tool will send
* its tracking data to one or more locations.
*/
struct OpenIGTLinkConfigurationDataType
{
TrackerConfigurationDataType m_TrackerConfiguration;
OpenIGTLinkDataType m_ToolNamesAndConnections;
};
typedef OpenIGTLinkConfigurationDataType*
OpenIGTLinkConfigurationDataPointerType;
/**
* Set a specific reader, which also defines the type of the tracker.
* This method generates two events: If the reader is NULL
* SetReaderFailureEvent, otherwise SetReaderSuccessEvent.
*/
void RequestSetReader( TrackerConfigurationXMLFileReaderBase::Pointer
trackerConfigurationReader );
/**
* Set the file name from which the data is loaded.
* This method generates two events: If the file name is empty
* SetFileNameFailureEvent, otherwise SetFileNameSuccessEvent.
*/
void RequestSetFileName( const std::string &fileName );
/**
* Actually perform the read operation. This method generates a
* ReadSuccessEvent upon success and a ReadFailureEvent if reading failed.
* If reading fails because the xml reader doesn't match the tracker type
* then an UnexpectedTrackerTypeEvent is also generated. If
* the reader hasn't been initialized yet (missing file name or xml reader)
* an InvalidRequestErrorEvent is generated.
*/
void RequestRead();
/**
* Get the tracker configuration data. This method generates a
* OpenIGTLinkConfigurationDataEvent if the data was loaded, otherwise an
* InvalidRequestErrorEvent.
*/
void RequestGetData();
/** This event is generated when the configuration data is requested and the
* data is available. */
igstkLoadedEventMacro( OpenIGTLinkConfigurationDataEvent, IGSTKEvent,
OpenIGTLinkConfigurationDataPointerType );
/** This event is generated if setting the xml reader succeeded. */
igstkEventMacro( SetReaderSuccessEvent, IGSTKEvent );
/** This event is generated if setting the xml reader failed. */
igstkEventMacro( SetReaderFailureEvent, IGSTKErrorEvent );
/** This event is generated if setting the file name succeeded. */
igstkEventMacro( SetFileNameSuccessEvent, IGSTKEvent );
/** This event is generated if setting the file name failed. */
igstkEventMacro( SetFileNameFailureEvent, IGSTKErrorEvent );
/** This event is generated if the reading succeeded. */
igstkEventMacro( ReadSuccessEvent, IGSTKEvent );
/** This event is generated if reading failed. */
igstkLoadedEventMacro( ReadFailureEvent, IGSTKErrorEvent,
EventHelperType::StringType );
/** This event is generated if reading failed because of a mismatch between
the reader and the actual tracker data. */
igstkEventMacro( UnexpectedTrackerTypeEvent, IGSTKEvent );
/**
* \class Class that observers both read success,
* igstk::OpenIGTLinkTrackerConfigurationFileReader::ReadSuccessEvent
* and read failure,
* igstk::OpenIGTLinkTrackerConfigurationFileReader::ReadFailureEvent,
* igstk::OpenIGTLinkTrackerConfigurationFileReader::
* UnexpectedTrackerTypeEvent,
* events generated by the OpenIGTLinkTrackerConfigurationFileReader class.
*/
class ReadFailSuccessObserver : public ::itk::Command
{
public:
typedef ReadFailSuccessObserver Self;
typedef ::itk::Command Superclass;
typedef ::itk::SmartPointer<Self> Pointer;
itkNewMacro( Self );
protected:
ReadFailSuccessObserver() :
m_GotFailure( false ),
m_GotSuccess( false ),
m_GotUnexpectedTrackerType( false )
{ }
~ReadFailSuccessObserver() {}
public:
void Execute(itk::Object *caller, const itk::EventObject & event)
{
const itk::Object * constCaller = caller;
this->Execute( constCaller, event );
}
void Execute(const itk::Object *caller, const itk::EventObject & event)
{
if( dynamic_cast<const igstk::OpenIGTLinkTrackerConfigurationFileReader::
ReadSuccessEvent *>( &event) )
{
m_GotSuccess = true;
}
else if( const igstk::OpenIGTLinkTrackerConfigurationFileReader::
ReadFailureEvent *rfe =
dynamic_cast<const igstk::OpenIGTLinkTrackerConfigurationFileReader::
ReadFailureEvent *>( &event) )
{
m_GotFailure = true;
m_FailureMessage = rfe->Get();
}
else if( dynamic_cast<const
igstk::OpenIGTLinkTrackerConfigurationFileReader::
UnexpectedTrackerTypeEvent *>( &event) )
{
m_GotUnexpectedTrackerType = true;
}
}
bool GotSuccess() {return this->m_GotSuccess;}
bool GotFailure() {return this->m_GotFailure;}
bool GotUnexpectedTrackerType() {return this->m_GotUnexpectedTrackerType;}
void Reset()
{
this->m_GotSuccess = false;
this->m_GotFailure = false;
this->m_GotUnexpectedTrackerType = false;
this->m_FailureMessage.clear();
}
std::string GetFailureMessage() const
{
return m_FailureMessage;
}
private:
std::string m_FailureMessage;
bool m_GotSuccess;
bool m_GotFailure;
bool m_GotUnexpectedTrackerType;
};
protected:
OpenIGTLinkTrackerConfigurationFileReader( void );
virtual ~OpenIGTLinkTrackerConfigurationFileReader( void );
/** Print the object information in a stream. */
void PrintSelf( std::ostream& os, itk::Indent indent ) const;
private:
/** List of state machine states */
igstkDeclareStateMacro( Idle );
igstkDeclareStateMacro( AttemptingSetFileName );
igstkDeclareStateMacro( AttemptingSetReader );
igstkDeclareStateMacro( FileNameSet );
igstkDeclareStateMacro( ReaderSet );
igstkDeclareStateMacro( AttemptingSetReaderHaveFileName );
igstkDeclareStateMacro( AttemptingSetFileNameHaveReader );
igstkDeclareStateMacro( Initialized );
igstkDeclareStateMacro( AttemptingRead );
igstkDeclareStateMacro( HaveData );
/** List of state machine inputs */
igstkDeclareInputMacro( SetReader );
igstkDeclareInputMacro( SetFileName );
igstkDeclareInputMacro( Read );
igstkDeclareInputMacro( GetData );
igstkDeclareInputMacro( Success );
igstkDeclareInputMacro( Failure );
/**List of state machine actions*/
void ReportInvalidRequestProcessing();
void SetReaderProcessing();
void ReportSetReaderSuccessProcessing();
void ReportSetReaderFailureProcessing();
void SetFileNameProcessing();
void ReportSetFileNameSuccessProcessing();
void ReportSetFileNameFailureProcessing();
void ReadProcessing();
void ReportReadSuccessProcessing();
void ReportReadFailureProcessing();
void GetDataProcessing();
OpenIGTLinkConfigurationDataType m_OpenIGTLinkTrackerConfiguration;
TrackerConfigurationXMLFileReaderBase::Pointer m_TmpXMLFileReader;
TrackerConfigurationXMLFileReaderBase::Pointer m_XMLFileReader;
std::string m_TmpFileName;
std::string m_FileName;
//if reading fails the ReadProcessing() method updates this string
//with an appropriate error message which the user recieves when
//the ReportReadFailureProcessing() generates the ReadFailureEvent
EventHelperType::StringType m_ReadFailureErrorMessage;
};
}
#endif //__igstkOpenIGTLinkTrackerConfigurationFileReader_h
|