Fraxinus  22.09
An IGT application
vtkSonixVideoSource.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Module: $RCSfile: vtkSonixVideoSource.h,v $
4 \author Siddharth Vikal, Queens School Of Computing
5 
6 Copyright (c) 2008, Queen's University, Kingston, Ontario, Canada
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above copyright
17  notice, this list of conditions and the following disclaimer in
18  the documentation and/or other materials provided with the
19  distribution.
20 
21  * Neither the name of Queen's University nor the names of any
22  contributors may be used to endorse or promote products derived
23  from this software without specific prior written permission.
24 
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37 
38 =========================================================================*/
39 
40 // .NAME vtkSonixVideoSource - VTK interface for video input from Ultrasonix machine
41 // .SECTION Description
42 // vtkSonixVideoSource is a class for providing video input interfaces between VTK and Ultrasonix machine.
43 // The goal is to provide the ability to be able to do acquisition
44 // in various imaging modes, buffer the image/volume series being acquired
45 // and stream the frames to output.
46 // Note that the data coming out of the Sonix rp through ulterius is always RGB
47 // This class talks to Ultrasonix's Ulterius SDK for executing the tasks
48 // .SECTION Caveats
49 // You must call the ReleaseSystemResources() method before the application
50 // exits. Otherwise the application might hang while trying to exit.
51 // .SECTION Usage
52 // sonixGrabber->SetSonixIP("130.15.7.212");
53 // sonixGrabber->SetImagingMode(0);
54 // sonixGrabber->SetAcquisitionDataType(0x00000004);
55 // sonixGrabber->Record();
56 // imageviewer->SetInput(sonixGrabber->GetOutput());
57 // See SonixVideoSourceTest.cxx for more details
58 // .SECTION See Also
59 // vtkWin32VideoSource vtkMILVideoSource
60 
61 /**************************************************************************************
62  Some modifications to this code have been performed by SINTEF (Ole Vegard Solberg)
63  in order to make it function for our purposes
64 ***************************************************************************************/
65 
66 #ifndef __vtkSonixVideoSource_h
67 #define __vtkSonixVideoSource_h
68 
70 #include <vtkVideoSource.h>
71 #include "SonixHelper.h"
72 
73 //BTX
74 
75 class uDataDesc;
76 class ulterius;
77 class uROI;
78 
80 
88 {
89 public:
92 };
93 //ETX
94 
95 
96 class VTK_EXPORT vtkSonixVideoSource : public vtkVideoSource //, public QObject
97 {
98  //Q_OBJECT
99 public:
100 
101  //static vtkSonixVideoSource *New();
102  vtkTypeRevisionMacro(vtkSonixVideoSource,vtkVideoSource);
103  void PrintSelf(ostream& os, vtkIndent indent);
104  // Description:
105  // This is a singleton pattern New. There will only be ONE
106  // reference to a vtkOutputWindow object per process. Clients that
107  // call this must call Delete on the object so that the reference
108  // counting will work. The single instance will be unreferenced when
109  // the program exits.
110  static vtkSonixVideoSource* New();
111  // Description:
112  // Return the singleton instance with no reference counting.
113  static vtkSonixVideoSource* GetInstance();
114 
115  // Description:
116  // Supply a user defined output window. Call ->Delete() on the supplied
117  // instance after setting it.
118  static void SetInstance(vtkSonixVideoSource *instance);
119  //BTX
120  // use this as a way of memory management when the
121  // program exits the SmartPointer will be deleted which
122  // will delete the Instance singleton
124  //ETX
125 
126  // Description:
127  // Record incoming video at the specified FrameRate. The recording
128  // continues indefinitely until Stop() is called.
129  virtual void Record();
130 
131  // Description:
132  // Play through the 'tape' sequentially at the specified frame rate.
133  // If you have just finished Recoding, you should call Rewind() first.
134  virtual void Play();
135 
136  // Description:
137  // Stop recording or playing.
138  virtual void Stop();
139 
140  // Description:
141  // Grab a single video frame.
142  void Grab();
143 
144  // Description:
145  // Request a particular vtk output format (default: VTK_RGB).
146  void SetOutputFormat(int format);
147 
148  // Description:
149  // Request a particular mode of imaging (e.g. B-mode (0), M-mode(1), Color-doppler(2), pulsed-doppler(3); default: B-mode).
150  void SetImagingMode(int mode){ImagingMode = mode;};
151  void GetImagingMode(int & mode){mode = ImagingMode;};
152 
153  // Description:
154  // Give the IP address of the sonix machine
155  void SetSonixIP(const char *SonixIP);
156 
157  /* List of parameters which can be set or read in B-mode, other mode parameters not currently implemented*/
158 
159  // Description:
160  // Request a particular mode of imaging (e.g. B-mode (0), M-mode(1), Color-doppler(2), pulsed-doppler(3); default: B-mode).
161  // Frequency corresponds to paramID value of 414 for Uterius SDK
162  vtkGetMacro(Frequency, int);
163  vtkSetMacro(Frequency, int);
164 
165  // Description:
166  // Get/set the depth (mm) of B-mode ultrasound; valid range: ; in increments of
167  // Depth corresponds to paramID value of 206 for Uterius SDK
168  vtkGetMacro(Depth, int);
169  vtkSetMacro(Depth, int);
170 
171  // Description:
172  // Get/set the frame rate (fps) of B-mode ultrasound; valid range: ; in increments of
173  // FrameRate corresponds to paramID value of 584 for Uterius SDK
174  vtkGetMacro(FrameRate, float);
175  vtkSetMacro(FrameRate, float);
176 
177  // Description:
178  // Request a particular data type from sonix machine by means of a mask.
179  // Range of types supported: 1) Screen (800 x 600); 2) B Pre Scan Converted; 3) B Post Scan Converted (8 bit);
180  // 4) B Post Scan Converted (32 bit); 5) RF; 6) M Pre Scan Converted;
181  // 7) M Post Scan Converted; 8) PW RF; 9) PW Spectrum;
182  // 10)Color RF; 11) Color Post; 12) Color Sigma;
183  // 13)Color Velocity; 14) Elasto + B-image (32); 15) Elasto Overlay (8 bit); 16) Elasto Pre Scan Coverted (8 bit)
184  // Currently supported data masks: 1) Screen
185  // The mask must be applied before any data can be acquired via realtime imaging or cine retreival
186  vtkGetMacro(AcquisitionDataType, int);
187  vtkSetMacro(AcquisitionDataType, int);
188 
189 
190  // Description:
191  // Initialize the driver (this is called automatically when the
192  // first grab is done).
193  void Initialize();
194 
195  int IsInitialized();
196  bool getFreezeState();
197 
198  // Description:
199  // Free the driver (this is called automatically inside the
200  // destructor).
201  void ReleaseSystemResources();
202 
203  //Description:
204  // Request data method override
205  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
206 
207  //signals:
208  //void newFrame(cx::Frame newFrame); ///< Emitted when a new frame is available
209 
210  void setSonixHelper(SonixHelper* sonixHelper);
211  void setDebugOutput(bool debug);
212  void setSonixConnectionDelay(int delay);
213  void setUseSharedMemory(bool useSharedMemory);
214 
215 protected:
218 
219  int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
220 
221  ulterius *ult;
222  uDataDesc *DataDescriptor;
224  int Depth;
229 
230  char *SonixHostIP;
231 
232  void UnpackRasterLine(char *outptr, char *inptr,
233  int start, int count);
234 
235  void DoFormatSetup();
236  void calculateSpacingAndOrigin();
237  void UpdateFrameBufferExtent(uROI roi);
238  void ResetFrameBufferExtent();
239 
240  // Description:
241  // For internal use only
242  void LocalInternalGrab(void * data, int type, int sz, bool cine, int frmnum);
243 
245 
250 
254 
255  int max(int a, int b){ if(a > b) return a; else return b;};
256  int min(int a, int b){ if(a < b) return a; else return b;};
257 
258 private:
259 
260 
261  static vtkSonixVideoSource* Instance;
262  static bool vtkSonixVideoSourceNewFrameCallback(void * data, int type, int sz, bool cine, int frmnum);
263  vtkSonixVideoSource(const vtkSonixVideoSource&); // Not implemented.
264  void operator=(const vtkSonixVideoSource&); // Not implemented.
265 
266  void waitForSonixWindow();
267 };
268 
273 #endif
274 
275 
276 
277 
278 
Support Qt support for vtkSonixVideoSource.
Definition: SonixHelper.h:36
static vtkSonixVideoSourceCleanup Cleanup
void GetImagingMode(int &mode)
#define VTK_ULTRASOUND_EXPORT
void SetImagingMode(int mode)
bool mFirstConnect
Is this the first time we try to connect to Sonix.
int min(int a, int b)
class VTK_ULTRASOUND_EXPORT vtkSonixVideoSource
int max(int a, int b)
SonixHelper * mSonixHelper
Support Qt functionality to vtkSonixVideoSource.