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
|
/*=========================================================================
Program: Image Guided Surgery Software Toolkit
Module: $RCSfile: igstkSpatialObjectTest.cxx,v $
Language: C++
Date: $Date: 2010-12-14 16:31:34 $
Version: $Revision: 1.16 $
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.
=========================================================================*/
#if defined(_MSC_VER)
// Warning about: identifier was truncated to '255' characters
// in the debug information (MVC6.0 Debug)
#pragma warning( disable : 4786 )
#endif
#include <iostream>
#include "igstkAxesObject.h"
#include "igstkSpatialObject.h"
#include "igstkTracker.h"
#include "igstkTrackerTool.h"
namespace igstk
{
namespace SpatialObjectTest
{
class MyTracker;
class DummyTrackerTool : public igstk::TrackerTool
{
public:
/** Macro with standard traits declarations. */
igstkStandardClassTraitsMacro( DummyTrackerTool, TrackerTool )
/** The "RequestAttachToTracker" method attaches
* the tracker tool to a tracker. */
virtual void RequestAttachToTracker( MyTracker * );
protected:
DummyTrackerTool():m_StateMachine(this)
{
}
~DummyTrackerTool()
{
}
/** Check if the tracker tool is configured or not. This method should
* be implemented in the derived classes*/
virtual bool CheckIfTrackerToolIsConfigured( ) const { return true; }
};
class DummySpatialObject : public SpatialObject
{
public:
igstkStandardClassTraitsMacro( DummySpatialObject, SpatialObject )
bool TestMethods()
{
this->RequestSetInternalSpatialObject( NULL ); // Test with null pointer
Self::Pointer sibling = Self::New(); // Test with valid pointer
typedef SpatialObject::SpatialObjectType SpatialObjectType;
SpatialObjectType::Pointer so = SpatialObjectType::New();
this->RequestSetInternalSpatialObject( so ); // Test with valid pointer
sibling->RequestSetInternalSpatialObject( so );
SpatialObject::SpatialObjectType * spatialObject =
this->GetInternalSpatialObject();
if( spatialObject != so.GetPointer() )
{
return false;
}
return true;
}
protected:
DummySpatialObject( void ):m_StateMachine(this) {};
~DummySpatialObject( void ) {};
};
class MyTracker : public Tracker
{
public:
/** Macro with standard traits declarations. */
igstkStandardClassTraitsMacro( MyTracker, Tracker )
typedef Superclass::TransformType TransformType;
protected:
MyTracker():m_StateMachine(this)
{
m_Position[0] = 0.0;
m_Position[1] = 0.0;
m_Position[2] = 0.0;
m_ValidityTime = 100.0; // 100.0 milliseconds
}
virtual ~MyTracker() {};
typedef Tracker::ResultType ResultType;
typedef TransformType::VectorType PositionType;
typedef TransformType::ErrorType ErrorType;
virtual ResultType InternalOpen( void ) { return SUCCESS; }
virtual ResultType InternalStartTracking( void ) { return SUCCESS; }
virtual ResultType InternalUpdateStatus( void )
{
typedef TrackerToolsContainerType::const_iterator ConstIteratorType;
TrackerToolsContainerType trackerToolContainer =
this->GetTrackerToolContainer();
ConstIteratorType inputItr = trackerToolContainer.begin();
ConstIteratorType inputEnd = trackerToolContainer.end();
typedef igstk::Transform TransformType;
TransformType transform;
while( inputItr != inputEnd )
{
transform.SetToIdentity( this->GetValidityTime() );
m_Position[0] += 1.0; // drift along a vector (1.0, 2.0, 3.0)
m_Position[1] += 2.0; // just to simulate a linear movement
m_Position[2] += 3.0; // being tracked in space.
ErrorType errorValue = 0.5;
transform.SetTranslation( m_Position, errorValue, m_ValidityTime );
// set the raw transform
this->SetTrackerToolRawTransform(
trackerToolContainer[inputItr->first], transform );
this->SetTrackerToolTransformUpdate(
trackerToolContainer[inputItr->first], true );
++inputItr;
}
return SUCCESS;
}
virtual ResultType InternalThreadedUpdateStatus( void )
{ return SUCCESS; }
virtual ResultType InternalReset( void )
{ return SUCCESS; }
virtual ResultType InternalStopTracking( void )
{ return SUCCESS; }
virtual ResultType InternalClose( void )
{ return SUCCESS; }
virtual ResultType VerifyTrackerToolInformation(
const TrackerToolType * itkNotUsed(trackerTool) )
{ return SUCCESS; }
virtual ResultType RemoveTrackerToolFromInternalDataContainers(
const TrackerToolType * itkNotUsed(trackerTool) )
{ return SUCCESS; }
virtual ResultType AddTrackerToolToInternalDataContainers(
const TrackerToolType * itkNotUsed(trackerTool) )
{ return SUCCESS; }
private:
MyTracker(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
typedef TrackerTool TrackerToolType;
typedef Transform::TimePeriodType TimePeriodType;
TimePeriodType m_ValidityTime;
PositionType m_Position;
};
/** The "RequestAttachToTracker" method attaches
* the tracker tool to a tracker. */
void DummyTrackerTool::RequestAttachToTracker( MyTracker * tracker )
{
// This delegation is done only to enforce type matching between
// TrackerTool and Tracker. It prevents the user from accidentally
// mix TrackerTools and Trackers of different type;
this->Superclass::RequestAttachToTracker( tracker );
}
} // end SpatialObjectTest namespace
} // end igstk namespace
int igstkSpatialObjectTest( int, char * [] )
{
igstk::RealTimeClock::Initialize();
igstk::AxesObject::Pointer worldReference = igstk::AxesObject::New();
typedef igstk::SpatialObjectTest::DummySpatialObject ObjectType;
ObjectType::Pointer dummyObject = ObjectType::New();
dummyObject->TestMethods();
typedef igstk::SpatialObjectTest::MyTracker TrackerType;
TrackerType::Pointer tracker = TrackerType::New();
igstk::Transform identityTransform;
identityTransform.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() );
tracker->RequestSetTransformAndParent( identityTransform, worldReference );
tracker->RequestOpen();
typedef igstk::SpatialObjectTest::DummyTrackerTool TrackerToolType;
typedef TrackerToolType::TransformType TransformType;
TrackerToolType::Pointer trackerTool = TrackerToolType::New();
trackerTool->RequestConfigure();
trackerTool->RequestAttachToTracker( tracker );
dummyObject->RequestSetTransformAndParent( identityTransform, trackerTool );
dummyObject->Print( std::cout );
tracker->RequestStartTracking();
for(unsigned int i=0; i<50; i++)
{
igstk::PulseGenerator::CheckTimeouts();
dummyObject->RequestGetTransformToParent();
}
tracker->RequestStopTracking();
tracker->RequestClose();
std::cout << "Tracked object [PASSED]" << std::endl;
ObjectType::Pointer dummyObject2 = ObjectType::New();
igstk::Transform trackerTransform;
trackerTransform.SetToIdentity( igstk::TimeStamp::GetLongestPossibleTime() );
dummyObject2->RequestSetTransformAndParent(
trackerTransform, worldReference );
std::cout << "Test [DONE]" << std::endl;
return EXIT_SUCCESS;
}
|