PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusTrackedFrameProcessor.cxx
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2 Program: Plus
3 Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4 See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #include "PlusConfigure.h"
8 #include "PlusMath.h"
10 #include "vtkIGSIOTrackedFrameList.h"
11 #include "vtkIGSIOTransformRepository.h"
12 #include "igsioCommon.h"
13 
14 //----------------------------------------------------------------------------
15 vtkCxxSetObjectMacro( vtkPlusTrackedFrameProcessor, InputFrames, vtkIGSIOTrackedFrameList );
16 vtkCxxSetObjectMacro( vtkPlusTrackedFrameProcessor, TransformRepository, vtkIGSIOTransformRepository );
17 //----------------------------------------------------------------------------
18 
19 //----------------------------------------------------------------------------
21 {
22  this->InputFrames = NULL;
23  this->TransformRepository = NULL;
24  this->OutputFrames = vtkIGSIOTrackedFrameList::New();
25 }
26 
27 //----------------------------------------------------------------------------
29 {
30  SetInputFrames( NULL );
31  SetTransformRepository( NULL );
32  this->OutputFrames->Delete();
33  this->OutputFrames = NULL;
34 }
35 
36 //----------------------------------------------------------------------------
37 void vtkPlusTrackedFrameProcessor::PrintSelf( ostream& os, vtkIndent indent )
38 {
39  this->Superclass::PrintSelf( os, indent );
40 }
41 
42 //-----------------------------------------------------------------------------
43 PlusStatus vtkPlusTrackedFrameProcessor::ReadConfiguration( vtkXMLDataElement* processingElement )
44 {
45  XML_VERIFY_ELEMENT( processingElement, this->GetTagName() );
46  return PLUS_SUCCESS;
47 }
48 
49 //-----------------------------------------------------------------------------
50 PlusStatus vtkPlusTrackedFrameProcessor::WriteConfiguration( vtkXMLDataElement* processingElement )
51 {
52  XML_VERIFY_ELEMENT( processingElement, this->GetTagName() );
53  processingElement->SetAttribute( "Type", this->GetProcessorTypeName() );
54  return PLUS_SUCCESS;
55 }
56 
57 //-----------------------------------------------------------------------------
59 {
60  this->OutputFrames->Clear();
61  if ( this->InputFrames == NULL || this->InputFrames->GetNumberOfTrackedFrames() == 0 )
62  {
63  // nothing to do
64  return PLUS_SUCCESS;
65  }
66  PlusStatus status = PLUS_SUCCESS;
67  for ( unsigned int frameIndex = 0; frameIndex < this->InputFrames->GetNumberOfTrackedFrames(); frameIndex++ )
68  {
69  igsioTrackedFrame* inputFrame = this->InputFrames->GetTrackedFrame( frameIndex );
70 
71  // Update the transform repository with the tracking information in the frame.
72  // After this we can query any transform from the repository.
73  if ( this->TransformRepository && this->TransformRepository->SetTransforms( *inputFrame ) != PLUS_SUCCESS )
74  {
75  LOG_ERROR( "Failed to set repository transforms from tracked frame!" );
76  status = PLUS_FAIL;
77  continue;
78  }
79 
80  // Create a clone of the input frame in the output buffer
81  // TODO: not very efficient that we copy the image data as well, we could just instantiate an empty output frame
82  this->OutputFrames->AddTrackedFrame( inputFrame );
83  igsioTrackedFrame* outputFrame = this->OutputFrames->GetTrackedFrame( this->OutputFrames->GetNumberOfTrackedFrames() - 1 ); // the last frame that just has been added
84 
85  // Do the actual processing
86  if ( this->ProcessFrame( inputFrame, outputFrame ) != PLUS_SUCCESS )
87  {
88  status = PLUS_FAIL;
89  }
90  }
91 
92  return status;
93 }
igsioStatus PlusStatus
Definition: PlusCommon.h:40
vtkCxxSetObjectMacro(vtkPlusTrackedFrameProcessor, InputFrames, vtkIGSIOTrackedFrameList)
#define PLUS_FAIL
Definition: PlusCommon.h:43
vtkIGSIOTransformRepository * TransformRepository
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
virtual const char * GetProcessorTypeName()=0
vtkIGSIOTrackedFrameList * InputFrames
virtual PlusStatus ProcessFrame(igsioTrackedFrame *inputFrame, igsioTrackedFrame *outputFrame)=0
Simple interface class to allow running various algorithms that process tracked frame lists.
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *processingElement)
virtual void SetInputFrames(vtkIGSIOTrackedFrameList *inputFrames)
vtkIGSIOTrackedFrameList * OutputFrames
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *processingElement)
virtual void SetTransformRepository(vtkIGSIOTransformRepository *transformRepository)