diff --git a/Modules/PhotoacousticsAlgorithms/Resources/DASQuadratic.cl b/Modules/PhotoacousticsAlgorithms/Resources/DASQuadratic.cl index e1a1b8c6ac..2918efcf8a 100644 --- a/Modules/PhotoacousticsAlgorithms/Resources/DASQuadratic.cl +++ b/Modules/PhotoacousticsAlgorithms/Resources/DASQuadratic.cl @@ -1,48 +1,77 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ __kernel void ckDASQuad( __read_only image3d_t dSource, // input image __global float* dDest, // output buffer __global float* apodArray, unsigned short apodArraySize, - unsigned short inputS, - unsigned short inputL, - unsigned short boundL, - unsigned short boundU // parameters + unsigned short outputS, + unsigned short outputL, + float SpeedOfSound, + float RecordTime, + float Pitch, + float Angle, + unsigned short PAImage // parameters ) { // get thread identifier unsigned int globalPosX = get_global_id(0); unsigned int globalPosY = get_global_id(1); unsigned int globalPosZ = get_global_id(2); // get image width and weight - const unsigned int uiWidth = get_image_width( dSource ); - const unsigned int uiHeight = get_image_height( dSource ); - const unsigned int uiDepth = get_image_depth( dSource ); + const unsigned int inputL = get_image_width( dSource ); + const unsigned int inputS = get_image_height( dSource ) / (PAImage + 1); + const unsigned int Slices = get_image_depth( dSource ); // create an image sampler const sampler_t defaultSampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST ; // terminate non-valid threads - if ( globalPosX < uiWidth && globalPosY < uiHeight && globalPosZ < uiDepth ) - { - // store the result - dDest[ globalPosZ * uiWidth * uiHeight + globalPosY * uiWidth + globalPosX ] = globalPosX; - } + if ( globalPosX < outputL && globalPosY < outputS && globalPosZ < Slices ) + { + float l_i = (float)globalPosX / outputL * inputL; + float s_i = (float)globalPosY / outputS * inputS; + + float tan_phi = tan(Angle / 360 * 2 * M_PI); + float part_multiplicator = tan_phi * RecordTime / inputS * SpeedOfSound / Pitch; + + float part = part_multiplicator * s_i; + if (part < 1) + part = 1; -} + short maxLine = min((l_i + part) + 1, (float)inputL); + short minLine = max((l_i - part), 0.0f); + short usedLines = (maxLine - minLine); + float apod_mult = apodArraySize / (maxLine - minLine); + + short AddSample = 0; + float output = 0; + float delayMultiplicator = pow(inputS / (RecordTime*SpeedOfSound) * Pitch, 2) / s_i / 2; + + for (short l_s = minLine; l_s < maxLine; ++l_s) + { + AddSample = delayMultiplicator * pow((l_s - l_i), 2) + s_i; + if (AddSample < inputS && AddSample >= 0) + output += apodArray[(short)((l_s - minLine)*apod_mult)] * read_imagef( dSource, defaultSampler, (int4)(l_s, AddSample, globalPosZ, 0 )).x; + else + --usedLines; + } + + dDest[ globalPosZ * outputL * outputS + globalPosY * outputL + globalPosX ] = output / usedLines; + } +} \ No newline at end of file diff --git a/Modules/PhotoacousticsAlgorithms/Resources/DASspherical.cl b/Modules/PhotoacousticsAlgorithms/Resources/DASspherical.cl index 5ae67eb19b..38509133f8 100644 --- a/Modules/PhotoacousticsAlgorithms/Resources/DASspherical.cl +++ b/Modules/PhotoacousticsAlgorithms/Resources/DASspherical.cl @@ -1,86 +1,80 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ __kernel void ckDASSphe( __read_only image3d_t dSource, // input image __global float* dDest, // output buffer __global float* apodArray, unsigned short apodArraySize, unsigned short outputS, unsigned short outputL, float SpeedOfSound, float RecordTime, float Pitch, float Angle, unsigned short PAImage // parameters ) { // get thread identifier unsigned int globalPosX = get_global_id(0); unsigned int globalPosY = get_global_id(1); unsigned int globalPosZ = get_global_id(2); // get image width and weight const unsigned int inputL = get_image_width( dSource ); const unsigned int inputS = get_image_height( dSource ) / (PAImage + 1); const unsigned int Slices = get_image_depth( dSource ); // create an image sampler const sampler_t defaultSampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST ; // terminate non-valid threads if ( globalPosX < outputL && globalPosY < outputS && globalPosZ < Slices ) { - short AddSample = 0; - - float delayMultiplicator = 0; - float l_i = 0; - float s_i = 0; + float l_i = (float)globalPosX / outputL * inputL; + float s_i = (float)globalPosY / outputS * inputS; float tan_phi = tan(Angle / 360 * 2 * M_PI); float part_multiplicator = tan_phi * RecordTime / inputS * SpeedOfSound / Pitch; - - l_i = (float)globalPosX / outputL * inputL; - s_i = (float)globalPosY / outputS * inputS; float part = part_multiplicator * s_i; if (part < 1) part = 1; short maxLine = min((l_i + part) + 1, (float)inputL); short minLine = max((l_i - part), 0.0f); short usedLines = (maxLine - minLine); float apod_mult = apodArraySize / (maxLine - minLine); + short AddSample = 0; float output = 0; for (short l_s = minLine; l_s < maxLine; ++l_s) { AddSample = sqrt( pow(s_i, 2) + pow((inputS / (RecordTime*SpeedOfSound) * ((l_s - l_i)*Pitch*outputL) / inputL), 2) ); if (AddSample < inputS && AddSample >= 0) output += apodArray[(short)((l_s - minLine)*apod_mult)] * read_imagef( dSource, defaultSampler, (int4)(l_s, AddSample, globalPosZ, 0 )).x; - else --usedLines; } dDest[ globalPosZ * outputL * outputS + globalPosY * outputL + globalPosX ] = output / usedLines; } -} +} \ No newline at end of file diff --git a/Modules/PhotoacousticsAlgorithms/Resources/DMASQuadratic.cl b/Modules/PhotoacousticsAlgorithms/Resources/DMASQuadratic.cl index d316a3e8b0..45a7812795 100644 --- a/Modules/PhotoacousticsAlgorithms/Resources/DMASQuadratic.cl +++ b/Modules/PhotoacousticsAlgorithms/Resources/DMASQuadratic.cl @@ -1,48 +1,125 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ __kernel void ckDMASQuad( __read_only image3d_t dSource, // input image __global float* dDest, // output buffer __global float* apodArray, unsigned short apodArraySize, - unsigned short inputS, - unsigned short inputL, - unsigned short boundL, - unsigned short boundU // parameters + unsigned short outputS, + unsigned short outputL, + float SpeedOfSound, + float RecordTime, + float Pitch, + float Angle, + unsigned short PAImage // parameters ) { // get thread identifier unsigned int globalPosX = get_global_id(0); unsigned int globalPosY = get_global_id(1); unsigned int globalPosZ = get_global_id(2); // get image width and weight - const unsigned int uiWidth = get_image_width( dSource ); - const unsigned int uiHeight = get_image_height( dSource ); - const unsigned int uiDepth = get_image_depth( dSource ); + const unsigned int inputL = get_image_width( dSource ); + const unsigned int inputS = get_image_height( dSource ) / (PAImage + 1); + const unsigned int Slices = get_image_depth( dSource ); // create an image sampler const sampler_t defaultSampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST ; // terminate non-valid threads - if ( globalPosX < uiWidth && globalPosY < uiHeight && globalPosZ < uiDepth ) - { - // store the result - dDest[ globalPosZ * uiWidth * uiHeight + globalPosY * uiWidth + globalPosX ] = globalPosX; - } + if ( globalPosX < outputL && globalPosY < outputS && globalPosZ < Slices ) + { + float l_i = (float)globalPosX / outputL * inputL; + float s_i = (float)globalPosY / outputS * inputS; + + float tan_phi = tan(Angle / 360 * 2 * M_PI); + float part_multiplicator = tan_phi * RecordTime / inputS * SpeedOfSound / Pitch; + float part = part_multiplicator * s_i; + if (part < 1) + part = 1; + + short maxLine = min((l_i + part) + 1, (float)inputL); + short minLine = max((l_i - part), 0.0f); + short usedLines = (maxLine - minLine); + float apod_mult = apodArraySize / (maxLine - minLine); + + float delayMultiplicator = pow((inputS / (RecordTime*SpeedOfSound) * Pitch), 2) / s_i / 2; + + float mult = 0; + float output = 0; + float AddSample1 = 0; + float AddSample2 = 0; + + for (short l_s1 = minLine; l_s1 < maxLine - 1; ++l_s1) + { + //AddSample1 = delayMultiplicator * pow((l_s1 - l_i), 2) + s_i; + if (AddSample1 < inputS && AddSample1 >= 0) + { + for (short l_s2 = l_s1 + 1; l_s2 < maxLine; ++l_s2) + { + //AddSample2 = delayMultiplicator * pow((l_s2 - l_i), 2) + s_i; + if (AddSample2 < inputS && AddSample2 >= 0) + { + mult = read_imagef( dSource, defaultSampler, (int4)(l_s2, AddSample2, globalPosZ, 0 )).x + * apodArray[(short)((l_s2 - minLine)*apod_mult)] + * read_imagef( dSource, defaultSampler, (int4)(l_s1, AddSample1, globalPosZ, 0 )).x + * apodArray[(short)((l_s1 - minLine)*apod_mult)]; + output += sqrt(mult*(mult>0)) * ((mult > 0) - (mult < 0)); + } + } + } + else + --usedLines; + } + + dDest[ globalPosZ * outputL * outputS + globalPosY * outputL + globalPosX ] = 10 * output / (pow((float)usedLines, 2.0f) - (usedLines - 1)); + } } + + +/* + //calculate the AddSamples beforehand to save some time + for (short l_s = 0; l_s < maxLine - minLine; ++l_s) + { + AddSample[l_s] = delayMultiplicator * pow((minLine + l_s - l_i), 2) + s_i; + } + + float mult = 0; + float output = 0; + + for (short l_s1 = minLine; l_s1 < maxLine - 1; ++l_s1) + { + if (AddSample[l_s1 - minLine] < inputS && AddSample[l_s1 - minLine] >= 0) + { + for (short l_s2 = l_s1 + 1; l_s2 < maxLine; ++l_s2) + { + if (AddSample[l_s2 - minLine] < inputS && AddSample[l_s2 - minLine] >= 0) + { + mult = read_imagef( dSource, defaultSampler, (int4)(l_s2, AddSample[l_s2], globalPosZ, 0 )).x + * apodArray[(short)((l_s2 - minLine)*apod_mult)] + * read_imagef( dSource, defaultSampler, (int4)(l_s1, AddSample[l_s1], globalPosZ, 0 )).x + * apodArray[(short)((l_s1 - minLine)*apod_mult)]; + output += sqrt(mult*(mult>0)) * ((mult > 0) - (mult < 0)); + } + } + } + else + --usedLines; + } +*/ \ No newline at end of file diff --git a/Modules/PhotoacousticsAlgorithms/Resources/DMASspherical.cl b/Modules/PhotoacousticsAlgorithms/Resources/DMASspherical.cl index 8ced7e75d4..aba1c30b68 100644 --- a/Modules/PhotoacousticsAlgorithms/Resources/DMASspherical.cl +++ b/Modules/PhotoacousticsAlgorithms/Resources/DMASspherical.cl @@ -1,47 +1,97 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ __kernel void ckDMASSphe( __read_only image3d_t dSource, // input image __global float* dDest, // output buffer __global float* apodArray, unsigned short apodArraySize, - unsigned short inputS, - unsigned short inputL, - unsigned short boundL, - unsigned short boundU // parameters + unsigned short outputS, + unsigned short outputL, + float SpeedOfSound, + float RecordTime, + float Pitch, + float Angle, + unsigned short PAImage // parameters ) -{ +{/* // get thread identifier unsigned int globalPosX = get_global_id(0); unsigned int globalPosY = get_global_id(1); unsigned int globalPosZ = get_global_id(2); // get image width and weight - const unsigned int uiWidth = get_image_width( dSource ); - const unsigned int uiHeight = get_image_height( dSource ); - const unsigned int uiDepth = get_image_depth( dSource ); + const unsigned int inputL = get_image_width( dSource ); + const unsigned int inputS = get_image_height( dSource ) / (PAImage + 1); + const unsigned int Slices = get_image_depth( dSource ); // create an image sampler const sampler_t defaultSampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST ; // terminate non-valid threads - if ( globalPosX < uiWidth && globalPosY < uiHeight && globalPosZ < uiDepth ) + if ( globalPosX < outputL && globalPosY < outputS && globalPosZ < Slices ) { - // store the result - dDest[ globalPosZ * uiWidth * uiHeight + globalPosY * uiWidth + globalPosX ] = globalPosX; - } -} + float l_i = (float)globalPosX / outputL * inputL; + float s_i = (float)globalPosY / outputS * inputS; + + float tan_phi = tan(Angle / 360 * 2 * M_PI); + float part_multiplicator = tan_phi * RecordTime / inputS * SpeedOfSound / Pitch; + + float part = part_multiplicator * s_i; + if (part < 1) + part = 1; + + short maxLine = min((l_i + part) + 1, (float)inputL); + short minLine = max((l_i - part), 0.0f); + short usedLines = (maxLine - minLine); + float apod_mult = apodArraySize / (maxLine - minLine); + + float mult = 0; + float output = 0; + float AddSample1 = 0; + float AddSample2 = 0; + + for (short l_s1 = minLine; l_s1 < maxLine - 1; ++l_s1) + { + AddSample1 = sqrt( + pow(s_i, 2) + + + pow((inputS / (RecordTime*SpeedOfSound) * ((l_s1 - l_i)*Pitch)), 2)); + if (AddSample1 < inputS && AddSample1 >= 0) + { + for (short l_s2 = l_s1 + 1; l_s2 < maxLine; ++l_s2) + { + AddSample2 = sqrt( + pow(s_i, 2) + + + pow((inputS / (RecordTime*SpeedOfSound) * ((l_s2 - l_i)*Pitch)), 2)); + if (AddSample2 < inputS && AddSample2 >= 0) + { + mult = read_imagef( dSource, defaultSampler, (int4)(l_s2, AddSample2, globalPosZ, 0 )).x + * apodArray[(short)((l_s2 - minLine)*apod_mult)] + * read_imagef( dSource, defaultSampler, (int4)(l_s1, AddSample1, globalPosZ, 0 )).x + * apodArray[(short)((l_s1 - minLine)*apod_mult)]; + output += sqrt(mult*(mult>0)) * ((mult > 0) - (mult < 0)); + } + } + } + else + --usedLines; + } + + dDest[ globalPosZ * outputL * outputS + globalPosY * outputL + globalPosX ] = 10 * output / (pow((float)usedLines, 2.0f) - (usedLines - 1)); + }*/ +} \ No newline at end of file