MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkToFImageRecorderFilter.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14#include <mitkImage.h>
15#include <mitkImageDataItem.h>
18#include "mitkImageReadAccessor.h"
19
20// itk includes
21#include "itksys/SystemTools.hxx"
22
23
24mitk::ToFImageRecorderFilter::ToFImageRecorderFilter(): m_RecordingStarted(false), m_ToFImageWriter(nullptr)
25{
26 m_FileExtension = "";
27}
28
32
34{
35 std::string name = fileName;
36 m_FileExtension = itksys::SystemTools::GetFilenameLastExtension( fileName );
37 if(m_FileExtension == ".nrrd")
38 {
39 m_ToFImageWriter = mitk::ToFNrrdImageWriter::New();
40 }
41 else if(m_FileExtension == ".csv")
42 {
43 m_ToFImageWriter = mitk::ToFImageCsvWriter::New();
44 }
45 else
46 {
47 throw std::logic_error("The specified file type is not supported, standard file type is .nrrd!");
48 }
49 int pos = name.find_last_of(".");
50 name.insert(pos,"_DistanceImage");
51 m_ToFImageWriter->SetDistanceImageFileName(name);
52 name = fileName;
53 name.insert(pos,"_AmplitudeImage");
54 m_ToFImageWriter->SetAmplitudeImageFileName(name);
55 name = fileName;
56 name.insert(pos,"_IntensityImage");
57 m_ToFImageWriter->SetIntensityImageFileName(name);
58}
59
61{
62 m_ToFImageWriter->SetToFImageType(tofImageType);
63}
64
66{
67 mitk::Image::Pointer distanceImageInput = this->GetInput(0);
68 assert(distanceImageInput);
69 mitk::Image::Pointer amplitudeImageInput = this->GetInput(1);
70 assert(amplitudeImageInput);
71 mitk::Image::Pointer intensityImageInput = this->GetInput(2);
72 assert(intensityImageInput);
73 // add current data to file stream
74 ImageReadAccessor distAcc(distanceImageInput, distanceImageInput->GetSliceData(0,0,0));
75 ImageReadAccessor amplAcc(amplitudeImageInput, amplitudeImageInput->GetSliceData(0,0,0));
76 ImageReadAccessor intenAcc(intensityImageInput, intensityImageInput->GetSliceData(0,0,0));
77
78 float* distanceFloatData = (float*) distAcc.GetData();
79 float* amplitudeFloatData = (float*) amplAcc.GetData();
80 float* intensityFloatData = (float*) intenAcc.GetData();
81 if (m_RecordingStarted)
82 {
83 m_ToFImageWriter->Add(distanceFloatData,amplitudeFloatData,intensityFloatData);
84 }
85
86 // set outputs to inputs
87 this->SetNthOutput(0,distanceImageInput);
88 this->SetNthOutput(1,amplitudeImageInput);
89 this->SetNthOutput(2,intensityImageInput);
90}
91
93{
94 if(m_ToFImageWriter.IsNull())
95 {
96 throw std::logic_error("ToFImageWriter is unitialized, set filename first!");
97 return;
98 }
99 m_ToFImageWriter->Open();
100 m_RecordingStarted = true;
101}
102
104{
105 m_ToFImageWriter->Close();
106 m_RecordingStarted = false;
107}
108
110{
111 return m_ToFImageWriter;
112}
113
114void mitk::ToFImageRecorderFilter::SetToFImageWriter(mitk::ToFImageWriter::Pointer tofImageWriter)
115{
116 m_ToFImageWriter = tofImageWriter;
117}
118
119void mitk::ToFImageRecorderFilter::SetInput(const InputImageType *input )
120{
121 this->SetInput(0,input);
122}
123
124void mitk::ToFImageRecorderFilter::SetInput( unsigned int idx, const InputImageType* input )
125{
126 if ((input == nullptr) && (idx == this->GetNumberOfInputs() - 1)) // if the last input is set to nullptr, reduce the number of inputs by one
127 {
128 this->SetNumberOfIndexedInputs(this->GetNumberOfInputs() - 1);
129 }
130 else if(idx == 0 || idx == 1 || idx == 2)
131 {
132 this->ProcessObject::SetNthInput(idx, const_cast<InputImageType*>(input)); // Process object is not const-correct so the const_cast is required here
133 unsigned int xDim = input->GetDimension(0);
134 unsigned int yDim = input->GetDimension(1);
135 m_ToFImageWriter->SetToFCaptureWidth(xDim);
136 m_ToFImageWriter->SetToFCaptureWidth(yDim);
137 }
138
139 this->CreateOutputsForAllInputs();
140}
141
143{
144 return this->GetInput(0);
145}
146
147mitk::Image* mitk::ToFImageRecorderFilter::GetInput( unsigned int idx )
148{
149 if (this->GetNumberOfInputs() < 1)
150 return nullptr;
151 return static_cast< mitk::Image*>(this->ProcessObject::GetInput(idx));
152}
153
155{
156 this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs()); // create outputs for all inputs
157 for (unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx)
158 if (this->GetOutput(idx) == nullptr)
159 {
160 DataObjectPointer newOutput = this->MakeOutput(idx);
161 this->SetNthOutput(idx, newOutput);
162 }
163 this->Modified();
164}
void CreateOutputsForAllInputs()
Create an output for each input.
Image * GetInput()
returns the input of this filter
~ToFImageRecorderFilter() override
standard destructor
void StartRecording()
start recording of data
void SetToFImageWriter(ToFImageWriter::Pointer tofImageWriter)
Sets a pointer to the ToFImageWriter internally used.
void SetFileName(std::string fileName)
Set file name for writing image files This filename will be appended by "_DistanceImage",...
void SetInput(const InputImageType *input) override
sets the input of this filter
void SetImageType(ToFImageWriter::ToFImageType tofImageType)
Set image type for recording.
ToFImageWriter::Pointer GetToFImageWriter()
Returns a pointer to the ToFImageWriter internally used.
void GenerateData() override
method generating the output of this filter. Called in the updated process of the pipeline....
void StopRecording()
stop recording of data