~ubuntu-branches/ubuntu/lucid/igstk/lucid

« back to all changes in this revision

Viewing changes to Testing/igstkVideoImagerTest.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Dominique Belhachemi
  • Date: 2009-10-07 17:35:43 UTC
  • mfrom: (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091007173543-69eyhyjrh0bfoqe5
Tags: 4.2.0-2
* Fixed link issue (Closes: #549799)
* switch to quilt

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Image Guided Surgery Software Toolkit
 
4
  Module:    $RCSfile: igstkVideoImagerTest.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2009-06-19 15:53:29 $
 
7
  Version:   $Revision: 1.2 $
 
8
 
 
9
  Copyright (c) ISC  Insight Software Consortium.  All rights reserved.
 
10
  See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
 
11
 
 
12
     This software is distributed WITHOUT ANY WARRANTY; without even
 
13
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 
14
     PURPOSE.  See the above copyright notices for more information.
 
15
 
 
16
=========================================================================*/
 
17
 
 
18
#if defined(_MSC_VER)
 
19
// Warning about: identifier was truncated to '255' characters 
 
20
// in the debug information (MVC6.0 Debug)
 
21
#pragma warning( disable : 4786 )
 
22
#endif
 
23
 
 
24
#include <iostream>
 
25
#include "igstkLandmark3DRegistration.h"
 
26
#include "igstkLogger.h"
 
27
#include "itkStdStreamLogOutput.h"
 
28
#include "itkObject.h"
 
29
#include "itkCommand.h"
 
30
#include "itkMacro.h"
 
31
#include "igstkEvents.h"
 
32
#include "igstkVideoImager.h"
 
33
#include "igstkVideoImagerTool.h"
 
34
 
 
35
namespace igstk
 
36
{
 
37
 
 
38
namespace VideoImagerTest
 
39
{
 
40
   
 
41
class VideoImager;
 
42
class VideoImagerTool;
 
43
class DummyVideoImager;
 
44
class DummyVideoImagerTool;
 
45
   
 
46
class DummyVideoImagerTool : public igstk::VideoImagerTool
 
47
{
 
48
public:
 
49
      
 
50
  igstkFriendClassMacro( DummyVideoImager );
 
51
      
 
52
  /** Macro with standard traits declarations. */
 
53
  igstkStandardClassTraitsMacro( DummyVideoImagerTool, igstk::VideoImagerTool )
 
54
 
 
55
  void RequestAttachToVideoImager(DummyVideoImager*  imager );
 
56
 
 
57
  DummyVideoImagerTool::Pointer DummyVideoImagerToolPointer;
 
58
 
 
59
protected:
 
60
   DummyVideoImagerTool(): m_StateMachine(this) {};
 
61
  ~DummyVideoImagerTool()
 
62
    {};
 
63
      
 
64
  /** Check if the tracker tool is configured or not. This method should
 
65
   *  be implemented in the derived classes*/
 
66
  virtual bool CheckIfVideoImagerToolIsConfigured( ) const { return true; }
 
67
};
 
68
 
 
69
 
 
70
class DummyVideoImager : public igstk::VideoImager
 
71
{
 
72
public:
 
73
      
 
74
  igstkFriendClassMacro( DummyVideoImagerTool );
 
75
      
 
76
  double GetImagerValidityTime()
 
77
    {
 
78
    return this->GetValidityTime();
 
79
    }
 
80
 
 
81
  /** Typedef for internal boolean return type. */
 
82
  typedef VideoImager::ResultType   ResultType;
 
83
 
 
84
  /** Open communication with the imaging device. */
 
85
  virtual ResultType InternalOpen( void ) {  return SUCCESS; };
 
86
 
 
87
  /** Close communication with the imaging device. */
 
88
  virtual ResultType InternalClose( void ){  return SUCCESS; };
 
89
 
 
90
  /** Put the imaging device into imaging mode. */
 
91
  virtual ResultType InternalStartImaging( void ){  return SUCCESS; };
 
92
 
 
93
  /** Take the imaging device out of imaging mode. */
 
94
  virtual ResultType InternalStopImaging( void ){  return SUCCESS; };
 
95
 
 
96
  /** Update the status and the transforms for all VideoImagerTools. */
 
97
  virtual ResultType InternalUpdateStatus( void ){  return SUCCESS; };
 
98
 
 
99
  /** Update the status and the frames.
 
100
      This function is called by a separate thread. */
 
101
  virtual ResultType InternalThreadedUpdateStatus( void ){  return SUCCESS; };
 
102
 
 
103
  /** Reset the imaging device to put it back to its original state. */
 
104
  virtual ResultType InternalReset( void ){  return SUCCESS; };
 
105
 
 
106
  /** Verify imager tool information */
 
107
  virtual ResultType VerifyVideoImagerToolInformation( 
 
108
                                                  const VideoImagerToolType * ){  return SUCCESS; };
 
109
 
 
110
  /** The "ValidateSpecifiedFrequency" method checks if the specified
 
111
   * frequency is valid for the imaging device that is being used. */
 
112
  virtual ResultType ValidateSpecifiedFrequency( double frequencyInHz ){  return SUCCESS; };
 
113
 
 
114
  /** Print object information */
 
115
  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const{  return; };
 
116
 
 
117
  /** Remove imager tool entry from internal containers */
 
118
  virtual ResultType RemoveVideoImagerToolFromInternalDataContainers( const
 
119
                                     VideoImagerToolType * imagerTool ){  return SUCCESS; };
 
120
 
 
121
  /** Add imager tool entry to internal containers */
 
122
  virtual ResultType AddVideoImagerToolToInternalDataContainers( const
 
123
                                     VideoImagerToolType * imagerTool ){  return SUCCESS; };
 
124
 
 
125
  DummyVideoImager::Pointer DummyVideoImagerPointer;
 
126
      //typedef ::itk::SmartPointer< Self >       Pointer;    
 
127
 
 
128
  /** Macro with standard traits declarations. */
 
129
  igstkStandardClassTraitsMacro( DummyVideoImager, igstk::VideoImager )
 
130
 
 
131
protected:
 
132
  DummyVideoImager( void ): m_StateMachine(this) {};
 
133
  ~DummyVideoImager( void ) {};
 
134
      
 
135
};
 
136
 
 
137
/** The "RequestAttachToVideoImager" method attaches
 
138
 * the imager tool to a imager. */
 
139
void DummyVideoImagerTool::RequestAttachToVideoImager(DummyVideoImager*  imager )
 
140
{
 
141
  this->VideoImagerTool::RequestAttachToVideoImager( imager );
 
142
}
 
143
   
 
144
}
 
145
}
 
146
 
 
147
int igstkVideoImagerTest( int argv, char * argc[] )
 
148
{
 
149
  typedef igstk::VideoImagerTest::DummyVideoImager     VideoImagerType;
 
150
  typedef igstk::VideoImagerTest::DummyVideoImagerTool VideoImagerToolType;
 
151
  
 
152
  VideoImagerType::Pointer videoImager= VideoImagerType::New();
 
153
 
 
154
  videoImager->RequestOpen();
 
155
 
 
156
  double defaultValidityTime = videoImager->GetImagerValidityTime();
 
157
  std::cout << "Default validity time: " << defaultValidityTime << std::endl;
 
158
 
 
159
  double videoImagerFrequency = 1;
 
160
  double validityTimeShouldBe = (1000.0/videoImagerFrequency) + 10;
 
161
 
 
162
  videoImager->RequestSetFrequency( videoImagerFrequency );
 
163
 
 
164
  double validityTimeReturned = videoImager->GetImagerValidityTime();
 
165
 
 
166
  if( fabs( validityTimeShouldBe - validityTimeReturned ) > 1e-5 )
 
167
    {
 
168
    std::cerr << "Error in RequestSetFrequency()/GetImagerValidityTime() "<<std::endl;
 
169
    return EXIT_FAILURE;
 
170
    }
 
171
 
 
172
  videoImager->RequestSetFrequency( 30 );
 
173
 
 
174
  VideoImagerToolType::Pointer videoImagerTool = VideoImagerToolType::New();
 
175
 
 
176
  videoImagerTool->RequestConfigure();
 
177
  videoImagerTool->RequestAttachToVideoImager( videoImager );
 
178
 
 
179
  videoImager->RequestStartImaging();
 
180
  videoImager->RequestStopImaging();
 
181
  videoImager->RequestReset();
 
182
  videoImager->VerifyVideoImagerToolInformation(videoImagerTool); 
 
183
  videoImager->ValidateSpecifiedFrequency(50); 
 
184
  videoImager->Print(std::cout);
 
185
  videoImager->AddVideoImagerToolToInternalDataContainers(videoImagerTool);
 
186
  videoImager->RemoveVideoImagerToolFromInternalDataContainers(videoImagerTool);
 
187
  videoImager->RequestClose();
 
188
 
 
189
  return EXIT_SUCCESS;
 
190
}