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

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
/*=========================================================================

  Program:   Image Guided Surgery Software Toolkit
  Module:    $RCSfile: igstkVideoImagerTest.cxx,v $
  Language:  C++
  Date:      $Date: 2009-06-19 15:53:29 $
  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.

=========================================================================*/

#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 "igstkLandmark3DRegistration.h"
#include "igstkLogger.h"
#include "itkStdStreamLogOutput.h"
#include "itkObject.h"
#include "itkCommand.h"
#include "itkMacro.h"
#include "igstkEvents.h"
#include "igstkVideoImager.h"
#include "igstkVideoImagerTool.h"

namespace igstk
{

namespace VideoImagerTest
{
   
class VideoImager;
class VideoImagerTool;
class DummyVideoImager;
class DummyVideoImagerTool;
   
class DummyVideoImagerTool : public igstk::VideoImagerTool
{
public:
      
  igstkFriendClassMacro( DummyVideoImager );
      
  /** Macro with standard traits declarations. */
  igstkStandardClassTraitsMacro( DummyVideoImagerTool, igstk::VideoImagerTool )

  void RequestAttachToVideoImager(DummyVideoImager*  imager );

  DummyVideoImagerTool::Pointer DummyVideoImagerToolPointer;

protected:
   DummyVideoImagerTool(): m_StateMachine(this) {};
  ~DummyVideoImagerTool()
    {};
      
  /** Check if the tracker tool is configured or not. This method should
   *  be implemented in the derived classes*/
  virtual bool CheckIfVideoImagerToolIsConfigured( ) const { return true; }
};


class DummyVideoImager : public igstk::VideoImager
{
public:
      
  igstkFriendClassMacro( DummyVideoImagerTool );
      
  double GetImagerValidityTime()
    {
    return this->GetValidityTime();
    }

  /** Typedef for internal boolean return type. */
  typedef VideoImager::ResultType   ResultType;

  /** Open communication with the imaging device. */
  virtual ResultType InternalOpen( void ) {  return SUCCESS; };

  /** Close communication with the imaging device. */
  virtual ResultType InternalClose( void ){  return SUCCESS; };

  /** Put the imaging device into imaging mode. */
  virtual ResultType InternalStartImaging( void ){  return SUCCESS; };

  /** Take the imaging device out of imaging mode. */
  virtual ResultType InternalStopImaging( void ){  return SUCCESS; };

  /** Update the status and the transforms for all VideoImagerTools. */
  virtual ResultType InternalUpdateStatus( void ){  return SUCCESS; };

  /** Update the status and the frames.
      This function is called by a separate thread. */
  virtual ResultType InternalThreadedUpdateStatus( void ){  return SUCCESS; };

  /** Reset the imaging device to put it back to its original state. */
  virtual ResultType InternalReset( void ){  return SUCCESS; };

  /** Verify imager tool information */
  virtual ResultType VerifyVideoImagerToolInformation( 
                                                  const VideoImagerToolType * ){  return SUCCESS; };

  /** The "ValidateSpecifiedFrequency" method checks if the specified
   * frequency is valid for the imaging device that is being used. */
  virtual ResultType ValidateSpecifiedFrequency( double frequencyInHz ){  return SUCCESS; };

  /** Print object information */
  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const{  return; };

  /** Remove imager tool entry from internal containers */
  virtual ResultType RemoveVideoImagerToolFromInternalDataContainers( const
                                     VideoImagerToolType * imagerTool ){  return SUCCESS; };

  /** Add imager tool entry to internal containers */
  virtual ResultType AddVideoImagerToolToInternalDataContainers( const
                                     VideoImagerToolType * imagerTool ){  return SUCCESS; };

  DummyVideoImager::Pointer DummyVideoImagerPointer;
      //typedef ::itk::SmartPointer< Self >       Pointer;    

  /** Macro with standard traits declarations. */
  igstkStandardClassTraitsMacro( DummyVideoImager, igstk::VideoImager )

protected:
  DummyVideoImager( void ): m_StateMachine(this) {};
  ~DummyVideoImager( void ) {};
      
};

/** The "RequestAttachToVideoImager" method attaches
 * the imager tool to a imager. */
void DummyVideoImagerTool::RequestAttachToVideoImager(DummyVideoImager*  imager )
{
  this->VideoImagerTool::RequestAttachToVideoImager( imager );
}
   
}
}

int igstkVideoImagerTest( int argv, char * argc[] )
{
  typedef igstk::VideoImagerTest::DummyVideoImager     VideoImagerType;
  typedef igstk::VideoImagerTest::DummyVideoImagerTool VideoImagerToolType;
  
  VideoImagerType::Pointer videoImager= VideoImagerType::New();

  videoImager->RequestOpen();

  double defaultValidityTime = videoImager->GetImagerValidityTime();
  std::cout << "Default validity time: " << defaultValidityTime << std::endl;

  double videoImagerFrequency = 1;
  double validityTimeShouldBe = (1000.0/videoImagerFrequency) + 10;

  videoImager->RequestSetFrequency( videoImagerFrequency );

  double validityTimeReturned = videoImager->GetImagerValidityTime();

  if( fabs( validityTimeShouldBe - validityTimeReturned ) > 1e-5 )
    {
    std::cerr << "Error in RequestSetFrequency()/GetImagerValidityTime() "<<std::endl;
    return EXIT_FAILURE;
    }

  videoImager->RequestSetFrequency( 30 );

  VideoImagerToolType::Pointer videoImagerTool = VideoImagerToolType::New();

  videoImagerTool->RequestConfigure();
  videoImagerTool->RequestAttachToVideoImager( videoImager );

  videoImager->RequestStartImaging();
  videoImager->RequestStopImaging();
  videoImager->RequestReset();
  videoImager->VerifyVideoImagerToolInformation(videoImagerTool); 
  videoImager->ValidateSpecifiedFrequency(50); 
  videoImager->Print(std::cout);
  videoImager->AddVideoImagerToolToInternalDataContainers(videoImagerTool);
  videoImager->RemoveVideoImagerToolFromInternalDataContainers(videoImagerTool);
  videoImager->RequestClose();

  return EXIT_SUCCESS;
}