12 #if defined(PHOTOACOUSTICS_USE_GPU) || DOXYGEN 18 mitk::OCLUsedLinesCalculation::OCLUsedLinesCalculation(mitk::BeamformingSettings::Pointer settings)
19 : m_PixelCalculation(NULL),
22 this->AddSourceFile(
"UsedLinesCalculation.cl");
23 this->m_FilterID =
"UsedLinesCalculation";
32 mitk::OCLUsedLinesCalculation::~OCLUsedLinesCalculation()
34 if (this->m_PixelCalculation)
36 clReleaseKernel(m_PixelCalculation);
40 void mitk::OCLUsedLinesCalculation::SetElementHeightsBuffer(cl_mem elementHeightsBuffer)
42 m_ElementHeightsBuffer = elementHeightsBuffer;
45 void mitk::OCLUsedLinesCalculation::SetElementPositionsBuffer(cl_mem elementPositionsBuffer)
47 m_ElementPositionsBuffer = elementPositionsBuffer;
53 if (!this->Initialize())
60 mitkThrow() <<
"Filter is not initialized. Cannot update.";
68 void mitk::OCLUsedLinesCalculation::Execute()
72 unsigned int gridDim[3] = { m_Conf->GetReconstructionLines(), m_Conf->GetSamplesPerLine(), 1 };
73 size_t outputSize = gridDim[0] * gridDim[1] * 3;
77 this->InitExecNoInput(this->m_PixelCalculation, gridDim, outputSize,
sizeof(
unsigned short));
81 MITK_ERROR <<
"Caught exception while initializing UsedLines filter: " << e.what();
88 m_part = (tan(m_Conf->GetAngle() / 360 * 2 * itk::Math::pi) *
89 ((m_Conf->GetSpeedOfSound() * m_Conf->GetTimeSpacing())) /
90 (m_Conf->GetPitchInMeters() * m_Conf->GetTransducerElements())) * m_Conf->GetInputDim()[0];
91 unsigned int reconLines = this->m_Conf->GetReconstructionLines();
92 unsigned int samplesPerLine = this->m_Conf->GetSamplesPerLine();
94 float totalSamples_i = (float)(m_Conf->GetReconstructionDepth()) / (
float)(m_Conf->GetSpeedOfSound() * m_Conf->GetTimeSpacing());
95 totalSamples_i = totalSamples_i <= m_Conf->GetInputDim()[1] ? totalSamples_i : m_Conf->GetInputDim()[1];
96 clErr = clSetKernelArg(this->m_PixelCalculation, 1,
sizeof(cl_float), &(this->m_part));
97 clErr |= clSetKernelArg(this->m_PixelCalculation, 2,
sizeof(cl_uint), &(this->m_Conf->GetInputDim()[0]));
98 clErr |= clSetKernelArg(this->m_PixelCalculation, 3,
sizeof(cl_uint), &(this->m_Conf->GetInputDim()[1]));
99 clErr |= clSetKernelArg(this->m_PixelCalculation, 4,
sizeof(cl_uint), &(reconLines));
100 clErr |= clSetKernelArg(this->m_PixelCalculation, 5,
sizeof(cl_uint), &(samplesPerLine));
101 clErr |= clSetKernelArg(this->m_PixelCalculation, 6,
sizeof(cl_float), &(totalSamples_i));
105 unsigned int reconLines = this->m_Conf->GetReconstructionLines();
106 unsigned int samplesPerLine = this->m_Conf->GetSamplesPerLine();
108 float probeRadius = m_Conf->GetProbeRadius();
109 float sin_deg = std::sin(m_Conf->GetAngle() / 360 * 2 * itk::Math::pi);
111 float horizontalExtent = m_Conf->GetHorizontalExtent();
112 float verticalExtent = m_Conf->GetReconstructionDepth();
114 clErr = clSetKernelArg(this->m_PixelCalculation, 1,
sizeof(cl_mem), &(this->m_ElementHeightsBuffer));
115 clErr |= clSetKernelArg(this->m_PixelCalculation, 2,
sizeof(cl_mem), &(this->m_ElementPositionsBuffer));
116 clErr |= clSetKernelArg(this->m_PixelCalculation, 3,
sizeof(cl_float), &(sin_deg));
117 clErr |= clSetKernelArg(this->m_PixelCalculation, 4,
sizeof(cl_float), &(probeRadius));
118 clErr |= clSetKernelArg(this->m_PixelCalculation, 5,
sizeof(cl_uint), &(this->m_Conf->GetInputDim()[0]));
119 clErr |= clSetKernelArg(this->m_PixelCalculation, 6,
sizeof(cl_uint), &(this->m_Conf->GetInputDim()[1]));
120 clErr |= clSetKernelArg(this->m_PixelCalculation, 7,
sizeof(cl_uint), &(reconLines));
121 clErr |= clSetKernelArg(this->m_PixelCalculation, 8,
sizeof(cl_uint), &(samplesPerLine));
122 clErr |= clSetKernelArg(this->m_PixelCalculation, 9,
sizeof(cl_float), &(horizontalExtent));
123 clErr |= clSetKernelArg(this->m_PixelCalculation, 10,
sizeof(cl_float), &(verticalExtent));
129 if (!this->ExecuteKernelChunksInBatches(m_PixelCalculation, 2, m_ChunkSize, 16, 50))
130 mitkThrow() <<
"openCL Error when executing Kernel";
136 us::Module *mitk::OCLUsedLinesCalculation::GetModule()
141 bool mitk::OCLUsedLinesCalculation::Initialize()
143 bool buildErr =
true;
146 if (OclFilter::Initialize())
150 this->m_PixelCalculation = clCreateKernel(this->m_ClProgram,
"ckUsedLines", &clErr);
155 this->m_PixelCalculation = clCreateKernel(this->m_ClProgram,
"ckUsedLines_g", &clErr);
159 return (OclFilter::IsInitialized() && buildErr);
#define CHECK_OCL_ERR(_er)
virtual void InvalidateStorage()=0
Remove all invalid (=do not compile) programs from the internal storage.
ServiceReferenceU GetServiceReference(const std::string &clazz)
static void Update(vtkPolyData *)
void * GetService(const ServiceReferenceBase &reference)
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Module * GetModule() const
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
Declaration of the OpenCL Resources micro-service.