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 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
/*=========================================================================
Program: Image Guided Surgery Software Toolkit
Module: $RCSfile: TrackingVolumeViewer.h,v $
Language: C++
Date: $Date: 2009-04-27 17:36:47 $
Version: $Revision: 1.2 $
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 __TrackingVolumeViewer_h
#define __TrackingVolumeViewer_h
#include "TrackingVolumeViewerGUI.h"
#include "igstkConfigure.h"
#include "igstkStateMachine.h"
#include "igstkMacros.h"
#include "igstkObject.h"
#include "igstkEvents.h"
#include "igstkTracker.h"
#include "igstkTrackerTool.h"
#include "igstkEllipsoidObject.h"
#include "igstkEllipsoidObjectRepresentation.h"
#include "igstkMeshReader.h"
#include "igstkMeshObjectRepresentation.h"
#include "igstkAxesObject.h"
#include "igstkAxesObjectRepresentation.h"
#include "itkStdStreamLogOutput.h"
#include "igstkTrackerController.h"
#include "igstkTrackerConfiguration.h"
#include "igstkReslicerPlaneSpatialObject.h"
#include "igstkMeshResliceObjectRepresentation.h"
#include "igstkMicronTrackerConfiguration.h"
#include "igstkAuroraTrackerConfiguration.h"
#include "igstkTransformFileReader.h"
#include "igstkRigidTransformXMLFileReader.h"
#include "igstkTrackerConfigurationFileReader.h"
#include "igstkTrackerConfigurationXMLFileReaderBase.h"
/** \class TrackingVolumeViewer
*
* \brief Implementation class for TrackingVolumeViewerGUI.
*
* This class implements the main application.
*
*/
class TrackingVolumeViewer : public TrackingVolumeViewerGUI
{
public:
/** Typedefs */
igstkStandardClassBasicTraitsMacro( TrackingVolumeViewer, TrackingVolumeViewerGUI );
igstkLoggerMacro();
/** Declarations needed for the State Machine */
igstkStateMachineMacro();
/** typedef for mesh readers */
typedef igstk::MeshReader MeshReaderType;
/** typedef for mesh spatial object */
typedef MeshReaderType::MeshObjectType MeshObjectType;
/** typedef for mesh spatial object representation */
typedef igstk::MeshObjectRepresentation MeshRepresentationType;
/** typedef for ellipsoid spatial object */
typedef igstk::EllipsoidObject EllipsoidType;
/** typedef for ellipsoid spatial object representation*/
typedef igstk::EllipsoidObjectRepresentation EllipsoidRepresentationType;
/** typedef for a vector of ellipsoid spatial objects and representations*/
typedef std::vector < EllipsoidType::Pointer >
EllipsoidSpatialObjectVectorType;
typedef std::vector < EllipsoidRepresentationType::Pointer >
EllipsoidRepresentationVectorType;
/** reslicer plane spatial object */
typedef igstk::ReslicerPlaneSpatialObject ReslicerPlaneType;
/** mesh reslice representation */
typedef igstk::MeshResliceObjectRepresentation MeshResliceRepresentationType;
/** typedef for axes spatial objects */
typedef igstk::AxesObject AxesObjectType;
typedef igstk::AxesObjectRepresentation AxesRepresentationType;
/** typedef for the vector of tracker tools */
typedef std::vector < igstk::TrackerTool::Pointer > ToolVectorType;
/** Public request methods from the GUI */
virtual void RequestLoadTrackerMesh();
virtual void RequestLoadWorkingVolumeMesh();
virtual void RequestPrepareToQuit();
/**
* Open the relevant tracker settings dialog (Polaris/Aurora/Micron/Ascension)
* and get the users input.
*/
virtual void RequestConfigureTracker();
virtual void RequestInitializeTracker();
virtual void RequestStartTracking();
virtual void RequestStopTracking();
virtual void RequestDisconnectTracker();
/**
* Observer for the event generated by
* TrackerConfigurationFileReader->RequestGetData() method.
*/
igstkObserverObjectMacro( TrackerConfiguration,
igstk::TrackerConfigurationFileReader::TrackerConfigurationDataEvent,
igstk::TrackerConfiguration)
igstkObserverMacro( TransformData,
igstk::TransformFileReader::TransformDataEvent,
igstk::PrecomputedTransformData::Pointer )
igstkObserverMacro( TransformationDescription,
igstk::StringEvent,
std::string )
igstkObserverMacro( TransformationDate,
igstk::PrecomputedTransformData::TransformDateTypeEvent,
std::string )
typedef igstk::TrackerConfigurationFileReader::ReadTrackerConfigurationFailSuccessObserver
ReadTrackerConfigurationFailSuccessObserverType;
igstkObserverMacro( TransformError,
igstk::PrecomputedTransformData::TransformErrorTypeEvent,
igstk::PrecomputedTransformData::ErrorType )
/** Define observers for event communication */
igstkObserverObjectMacro( MeshObject, igstk::MeshReader::MeshModifiedEvent,
igstk::MeshObject);
igstkEventMacro( InvalidRequestErrorEvent, igstk::IGSTKErrorEvent );
TrackingVolumeViewer();
virtual ~TrackingVolumeViewer();
private:
TrackingVolumeViewer(const Self&); // purposely not implemented
void operator=(const Self&); // purposely not implemented
/** States for the State Machine */
igstkDeclareStateMacro( Initial );
igstkDeclareStateMacro( ConfiguringTracker );
igstkDeclareStateMacro( TrackerConfigurationReady );
igstkDeclareStateMacro( InitializingTracker );
igstkDeclareStateMacro( TrackerInitializationReady );
igstkDeclareStateMacro( LoadingMesh );
igstkDeclareStateMacro( StartingTracker );
igstkDeclareStateMacro( StoppingTracker );
igstkDeclareStateMacro( DisconnectingTracker );
igstkDeclareStateMacro( Tracking );
/** Inputs to the state machine and it's designed transitions */
igstkDeclareInputMacro( Success );
igstkDeclareInputMacro( Failure );
igstkDeclareInputMacro( LoadTrackerMesh );
igstkDeclareInputMacro( LoadWorkingVolumeMesh );
igstkDeclareInputMacro( ConfigureTracker );
igstkDeclareInputMacro( InitializeTracker );
igstkDeclareInputMacro( StartTracking );
igstkDeclareInputMacro( StopTracking );
igstkDeclareInputMacro( DisconnectTracker );
/** Define a initial world coordinate system */
AxesObjectType::Pointer m_WorldReference;
AxesRepresentationType::Pointer m_WorldReferenceRepresentation;
/** SpatialObject and representation for the trackers working volume */
MeshObjectType::Pointer m_MeshSpatialObject;
MeshRepresentationType::Pointer m_MeshRepresentation;
/** SpatialObject and representation for the trackers tip */
EllipsoidSpatialObjectVectorType m_TipSpatialObjectVector;
EllipsoidRepresentationVectorType m_TipRepresentationVector;
/** tracker configuration object */
const igstk::TrackerConfiguration * m_TrackerConfiguration;
/** plane reslicer spatial objects */
ReslicerPlaneType::Pointer m_AxialPlaneSpatialObject;
ReslicerPlaneType::Pointer m_SagittalPlaneSpatialObject;
ReslicerPlaneType::Pointer m_CoronalPlaneSpatialObject;
MeshResliceRepresentationType::Pointer m_AxialMeshResliceRepresentation;
MeshResliceRepresentationType::Pointer m_SagittalMeshResliceRepresentation;
MeshResliceRepresentationType::Pointer m_CoronalMeshResliceRepresentation;
/** Class that observes the events generated by the tracker controller. */
class TrackerControllerObserver : public itk::Command
{
public:
typedef TrackerControllerObserver Self;
typedef ::itk::Command Superclass;
typedef ::itk::SmartPointer<Self> Pointer;
typedef ::itk::SmartPointer<const Self> ConstPointer;
igstkNewMacro(Self)
igstkTypeMacro(TrackerControllerObserver, itk::Command)
void SetParent(TrackingVolumeViewer *p);
/** Invoke this method when an initialization event occurs. */
void Execute(itk::Object *caller, const itk::EventObject & event);
void Execute(const itk::Object *caller, const itk::EventObject & event);
/**
* Clear the current error.
*/
void ClearError()
{
this->m_ErrorOccured = false;
this->m_ErrorMessage.clear();
}
/**
* If an error occurs in one of the observed IGSTK components this method will return true.
*/
bool Error()
{
return this->m_ErrorOccured;
}
void GetErrorMessage(std::string &errorMessage)
{
errorMessage = this->m_ErrorMessage;
}
protected:
TrackerControllerObserver() : m_Parent(NULL), m_ErrorOccured(false) {}
virtual ~TrackerControllerObserver(){}
private:
TrackingVolumeViewer *m_Parent;
bool m_ErrorOccured;
std::string m_ErrorMessage;
//purposely not implemented
TrackerControllerObserver(const Self&);
void operator=(const Self&);
};
/** Class that observes the events generated by the transform reader. */
class ReadObserver : public itk::Command
{
public:
typedef ReadObserver Self;
typedef ::itk::Command Superclass;
typedef ::itk::SmartPointer<Self> Pointer;
typedef ::itk::SmartPointer<const Self> ConstPointer;
igstkNewMacro( Self )
igstkTypeMacro( ReadObserver, itk::Command )
virtual void Execute( itk::Object *caller, const itk::EventObject & event )
{
const igstk::TransformFileReader::ReadFailureEvent *rfe;
if( ( rfe = dynamic_cast<const igstk::TransformFileReader::ReadFailureEvent *>( &event ) ) )
std::cerr<<rfe->Get()<<"\n";
else if( dynamic_cast<const igstk::TransformFileReader::ReadSuccessEvent *>( &event ) )
( static_cast<igstk::TransformFileReader *>( caller ) )->RequestGetData();
}
virtual void Execute( const itk::Object *caller,
const itk::EventObject & event )
{
const itk::Object * constCaller = caller;
this->Execute( constCaller, event );
}
protected:
ReadObserver(){}
virtual ~ReadObserver(){}
private:
//purposely not implemented
ReadObserver(const Self&);
void operator=(const Self&);
};
igstk::TrackerController::Pointer m_TrackerController;
TrackerControllerObserver::Pointer m_TrackerControllerObserver;
ToolVectorType m_ToolVector;
/** Action methods to be invoked only by the state machine */
void NoProcessing();
void ReportInvalidRequestProcessing();
void ReportSuccessSpatialObjectLoadedProcessing();
void ReportFailuredSpatialObjectLoadedProcessing();
void ReportSuccessMeshLoadedProcessing();
void ReportFailuredMeshLoadedProcessing();
void ReportSuccessTrackerConfigurationProcessing();
void ReportFailureTrackerConfigurationProcessing();
void ReportSuccessTrackerInitializationProcessing();
void ReportFailureTrackerInitializationProcessing();
void ReportSuccessTrackerDisconnectionProcessing();
void ReportFailureTrackerDisconnectionProcessing();
void ReportSuccessStopTrackingProcessing();
void ReportFailureStopTrackingProcessing();
void ReportSuccessStartTrackingProcessing();
void ReportFailureStartTrackingProcessing();
void LoadTrackerMeshProcessing();
void LoadWorkingVolumeMeshProcessing();
void ConfigureTrackerProcessing();
void InitializeTrackerProcessing();
void StartTrackingProcessing();
void StopTrackingProcessing();
void DisconnectTrackerProcessing();
void ReportError( const std::string &message );
void ReportError( const char *message );
/** Observer type for loaded event,
* the callback can be set to a member function. */
typedef itk::ReceptorMemberCommand < Self > LoadedObserverType;
typedef itk::SimpleMemberCommand < Self > CancelObserverType;
CancelObserverType::Pointer m_TrackerConfigurationCancelObserver;
/** Log file */
std::ofstream m_LogFile;
};
#endif
|