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

« back to all changes in this revision

Viewing changes to Testing/igstkFrameTest.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: igstkFrameTest.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2009-06-19 22:01:18 $
 
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
 
 
34
namespace igstk
 
35
{
 
36
namespace FrameTest
 
37
{
 
38
   
 
39
class VideoImager;
 
40
class VideoImagerTool;
 
41
class DummyVideoImager;
 
42
class DummyVideoImagerTool;
 
43
   
 
44
class DummyVideoImagerTool : public igstk::VideoImagerTool
 
45
{
 
46
public:
 
47
      
 
48
  igstkFriendClassMacro( DummyVideoImager );
 
49
      
 
50
  /** Macro with standard traits declarations. */
 
51
  igstkStandardClassTraitsMacro( DummyVideoImagerTool, igstk::VideoImagerTool )
 
52
 
 
53
  void RequestAttachToVideoImager(DummyVideoImager*  imager );
 
54
 
 
55
  DummyVideoImagerTool::Pointer DummyVideoImagerToolPointer;
 
56
 
 
57
protected:
 
58
   DummyVideoImagerTool(): m_StateMachine(this) {};
 
59
  ~DummyVideoImagerTool()
 
60
    {};
 
61
      
 
62
  /** Check if the tracker tool is configured or not. This method should
 
63
   *  be implemented in the derived classes*/
 
64
  virtual bool CheckIfVideoImagerToolIsConfigured( ) const { return true; }
 
65
};
 
66
 
 
67
 
 
68
class DummyVideoImager : public igstk::VideoImager
 
69
{
 
70
public:
 
71
      
 
72
  igstkFriendClassMacro( DummyVideoImagerTool );
 
73
      
 
74
  double GetImagerValidityTime()
 
75
    {
 
76
    return this->GetValidityTime();
 
77
    }
 
78
 
 
79
  /** Typedef for internal boolean return type. */
 
80
  typedef VideoImager::ResultType   ResultType;
 
81
 
 
82
  /** Open communication with the imaging device. */
 
83
  virtual ResultType InternalOpen( void ) {  return SUCCESS; };
 
84
 
 
85
  /** Close communication with the imaging device. */
 
86
  virtual ResultType InternalClose( void ){  return SUCCESS; };
 
87
 
 
88
  /** Put the imaging device into imaging mode. */
 
89
  virtual ResultType InternalStartImaging( void ){  return SUCCESS; };
 
90
 
 
91
  /** Take the imaging device out of imaging mode. */
 
92
  virtual ResultType InternalStopImaging( void ){  return SUCCESS; };
 
93
 
 
94
  /** Update the status and the transforms for all VideoImagerTools. */
 
95
  virtual ResultType InternalUpdateStatus( void ){  return SUCCESS; };
 
96
 
 
97
  /** Update the status and the frames.
 
98
      This function is called by a separate thread. */
 
99
  virtual ResultType InternalThreadedUpdateStatus( void ){  return SUCCESS; };
 
100
 
 
101
  /** Reset the imaging device to put it back to its original state. */
 
102
  virtual ResultType InternalReset( void ){  return SUCCESS; };
 
103
 
 
104
  /** Verify imager tool information */
 
105
  virtual ResultType VerifyVideoImagerToolInformation( 
 
106
                                                  const VideoImagerToolType * ){  return SUCCESS; };
 
107
 
 
108
  /** The "ValidateSpecifiedFrequency" method checks if the specified
 
109
   * frequency is valid for the imaging device that is being used. */
 
110
  virtual ResultType ValidateSpecifiedFrequency( double frequencyInHz ){  return SUCCESS; };
 
111
 
 
112
  /** Print object information */
 
113
  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const{  return; };
 
114
 
 
115
  /** Remove imager tool entry from internal containers */
 
116
  virtual ResultType RemoveVideoImagerToolFromInternalDataContainers( const
 
117
                                     VideoImagerToolType * imagerTool ){  return SUCCESS; };
 
118
 
 
119
  /** Add imager tool entry to internal containers */
 
120
  virtual ResultType AddVideoImagerToolToInternalDataContainers( const
 
121
                                     VideoImagerToolType * imagerTool ){  return SUCCESS; };
 
122
 
 
123
  DummyVideoImager::Pointer DummyVideoImagerPointer;
 
124
      //typedef ::itk::SmartPointer< Self >       Pointer;    
 
125
 
 
126
  /** Macro with standard traits declarations. */
 
127
  igstkStandardClassTraitsMacro( DummyVideoImager, igstk::VideoImager )
 
128
 
 
129
protected:
 
130
  DummyVideoImager( void ): m_StateMachine(this) {};
 
131
  ~DummyVideoImager( void ) {};
 
132
      
 
133
};
 
134
 
 
135
/** The "RequestAttachToVideoImager" method attaches
 
136
 * the imager tool to a imager. */
 
137
void DummyVideoImagerTool::RequestAttachToVideoImager(DummyVideoImager*  imager )
 
138
{
 
139
  this->VideoImagerTool::RequestAttachToVideoImager( imager );
 
140
}
 
141
   
 
142
}
 
143
}
 
144
 
 
145
int igstkFrameTest( int argv, char * argc[] )
 
146
{
 
147
  typedef igstk::FrameTest::DummyVideoImager     VideoImagerType;
 
148
  typedef igstk::FrameTest::DummyVideoImagerTool VideoImagerToolType;
 
149
  
 
150
  VideoImagerType::Pointer videoImager= VideoImagerType::New();
 
151
 
 
152
  videoImager->RequestOpen();
 
153
 
 
154
  double defaultValidityTime = videoImager->GetImagerValidityTime();
 
155
  std::cout << "Default validity time: " << defaultValidityTime << std::endl;
 
156
 
 
157
  double videoImagerFrequency = 1;
 
158
  double validityTimeShouldBe = (1000.0/videoImagerFrequency) + 10;
 
159
 
 
160
  videoImager->RequestSetFrequency( videoImagerFrequency );
 
161
 
 
162
  double validityTimeReturned = videoImager->GetImagerValidityTime();
 
163
 
 
164
  if( fabs( validityTimeShouldBe - validityTimeReturned ) > 1e-5 )
 
165
    {
 
166
    std::cerr << "Error in RequestSetFrequency()/GetImagerValidityTime() "<<std::endl;
 
167
    return EXIT_FAILURE;
 
168
    }
 
169
 
 
170
  videoImager->RequestSetFrequency( 30 );
 
171
 
 
172
  VideoImagerToolType::Pointer videoImagerTool =
 
173
     VideoImagerToolType::New();
 
174
  VideoImagerToolType::Pointer videoImagerToolCopy =
 
175
     VideoImagerToolType::New();
 
176
 
 
177
  videoImagerTool->RequestConfigure();
 
178
  videoImagerTool->RequestAttachToVideoImager( videoImager );
 
179
  unsigned int dims[3]= {256,256,1};
 
180
 
 
181
  //coverage
 
182
  videoImagerTool->SetFrameDimensions(dims);
 
183
  igstk::Frame* frame1 = videoImagerTool->GetFrameFromBuffer(0);
 
184
  igstk::Frame* frame2 = videoImagerTool->GetTemporalCalibratedFrame();
 
185
  igstk::Frame* frame3(const_cast<igstk::Frame*> (frame2)); 
 
186
  frame1->GetStartTime();
 
187
  frame2->GetExpirationTime();
 
188
  frame3->SetTimeToExpiration(1000);
 
189
  frame3->IsValidAtTime(500);
 
190
  frame3->IsValidNow();
 
191
  frame3->Print(std::cout, 0); 
 
192
 
 
193
  return EXIT_SUCCESS;
 
194
}