16 #include <itkImageIOBase.h> 19 #include <itkImageIOBase.h> 33 float* ApodWindow =
new float[samples];
35 for (
int n = 0; n < samples; ++n)
37 ApodWindow[n] = (1 - cos(2 * itk::Math::pi * n / (samples - 1))) / 2;
45 float* ApodWindow =
new float[samples];
47 for (
int n = 0; n < samples; ++n)
49 ApodWindow[n] = 0.54 - 0.46*cos(2 * itk::Math::pi*n / (samples - 1));
57 float* ApodWindow =
new float[samples];
59 for (
int n = 0; n < samples; ++n)
69 unsigned int outputL = (
unsigned int)config->GetReconstructionLines();
70 unsigned int outputS = (
unsigned int)config->GetSamplesPerLine();
72 unsigned short* dDest =
new unsigned short[outputL * outputS * 2];
74 unsigned int inputL = (
unsigned int)config->GetInputDim()[0];
76 float horizontalExtent = config->GetHorizontalExtent();
77 float verticalExtent = config->GetReconstructionDepth();
79 float partMult = (tan(config->GetAngle() / 360 * 2 * itk::Math::pi) *
80 ((config->GetSpeedOfSound() * config->GetTimeSpacing())) /
81 (config->GetPitchInMeters() * config->GetTransducerElements())) * inputL;
82 float totalSamples_i = (float)(config->GetReconstructionDepth()) / (
float)(config->GetSpeedOfSound() * config->GetTimeSpacing());
84 totalSamples_i = totalSamples_i <= config->GetInputDim()[1] ? totalSamples_i : config->GetInputDim()[1];
86 if ((
int)config->GetGeometry() == 0)
88 for (
unsigned int x = 0; x < outputL; ++x)
90 for (
unsigned int y = 0; y < outputS; ++y)
92 float l_i = (float)x / outputL * inputL;
93 float s_i = (float)y / (
float)outputS * totalSamples_i;
95 float part = partMult * s_i;
98 unsigned short maxLine =
std::min((l_i + part) + 1, (
float)inputL);
99 unsigned short minLine =
std::max((l_i - part), 0.0f);
101 dDest[y * 2 * outputL + 2 * x] = (
unsigned short)minLine;
102 dDest[y * 2 * outputL + 2 * x + 1] = (
unsigned short)maxLine;
109 float probeRadius = config->GetProbeRadius();
110 float* elementHeights = config->GetElementHeights();
111 float* elementPositions = config->GetElementPositions();
113 float sin_deg = std::sin(config->GetAngle() / 360 * 2 * itk::Math::pi);
115 float x_center_pos = horizontalExtent / 2.0;
116 float y_center_pos = probeRadius;
118 for (
unsigned int x = 0; x < outputL; ++x)
120 for (
unsigned int y = 0; y < outputS; ++y)
122 float x_cm = (float)x / outputL * horizontalExtent;
123 float y_cm = (float)y / (
float)outputS * verticalExtent;
125 unsigned int maxLine = inputL;
126 unsigned int minLine = 0;
128 for (
unsigned int l_s = minLine; l_s <= inputL; l_s += 1)
130 float x_sensor_pos = elementPositions[l_s];
131 float y_sensor_pos = elementHeights[l_s];
133 float distance_sensor_target = sqrt((x_cm - x_sensor_pos)*(x_cm - x_sensor_pos)
134 + (y_cm - y_sensor_pos)*(y_cm - y_sensor_pos));
137 float center_to_sensor_a = y_sensor_pos - y_center_pos;
138 float center_to_sensor_b = x_center_pos - x_sensor_pos;
139 float center_to_sensor_c = -(center_to_sensor_a * x_center_pos + center_to_sensor_b * y_center_pos);
140 float distance_to_sensor_direction = std::fabs((center_to_sensor_a * x_cm
141 + center_to_sensor_b * y_cm
142 + center_to_sensor_c)) /
143 (sqrt(center_to_sensor_a*center_to_sensor_a + center_to_sensor_b*center_to_sensor_b));
145 if (distance_to_sensor_direction < sin_deg*distance_sensor_target)
152 for (
unsigned int l_s = maxLine - 1; l_s > minLine; l_s -= 1)
154 float x_sensor_pos = elementPositions[l_s];
155 float y_sensor_pos = elementHeights[l_s];
157 float distance_sensor_target = sqrt((x_cm - x_sensor_pos)*(x_cm - x_sensor_pos)
158 + (y_cm - y_sensor_pos)*(y_cm - y_sensor_pos));
161 float center_to_sensor_a = y_sensor_pos - y_center_pos;
162 float center_to_sensor_b = x_center_pos - x_sensor_pos;
163 float center_to_sensor_c = -(center_to_sensor_a * x_center_pos + center_to_sensor_b * y_center_pos);
164 float distance_to_sensor_direction = std::fabs((center_to_sensor_a * x_cm
165 + center_to_sensor_b * y_cm
166 + center_to_sensor_c)) /
167 (sqrt(center_to_sensor_a*center_to_sensor_a + center_to_sensor_b*center_to_sensor_b));
169 if (distance_to_sensor_direction < sin_deg*distance_sensor_target)
175 dDest[y * 2 * outputL + 2 * x] = (
unsigned short)minLine;
176 dDest[y * 2 * outputL + 2 * x + 1] = (
unsigned short)maxLine;
184 float* input,
float* output,
float inputDim[2],
float outputDim[2],
185 const short&
line,
const mitk::BeamformingSettings::Pointer config)
187 const float* apodisation = config->GetApodizationFunction();
188 const short apodArraySize = config->GetApodizationArraySize();
190 const float* elementHeights = config->GetElementHeights();
191 const float* elementPositions = config->GetElementPositions();
193 float& inputS = inputDim[1];
194 float& inputL = inputDim[0];
196 float& outputS = outputDim[1];
197 float& outputL = outputDim[0];
207 short usedLines = (maxLine - minLine);
209 float totalSamples_i = (float)(config->GetReconstructionDepth()) / (
float)(config->GetSpeedOfSound() * config->GetTimeSpacing());
210 totalSamples_i = totalSamples_i <= inputS ? totalSamples_i : inputS;
212 l_p = (float)line / outputL * config->GetHorizontalExtent();
214 for (
short sample = 0; sample < outputS; ++sample)
216 s_i = (float)sample / outputS * totalSamples_i;
218 minLine = config->GetMinMaxLines()[2*sample*(short)outputL + 2*line];
219 maxLine = config->GetMinMaxLines()[2*sample*(short)outputL + 2*line + 1];
220 usedLines = (maxLine - minLine);
222 apod_mult = (float)apodArraySize / (
float)usedLines;
224 for (
short l_s = minLine; l_s < maxLine; ++l_s)
226 AddSample = (int)sqrt(
227 pow(s_i-elementHeights[l_s]/(config->GetSpeedOfSound()*config->GetTimeSpacing()), 2)
229 pow((1 / (config->GetTimeSpacing()*config->GetSpeedOfSound())) * (l_p - elementPositions[l_s]), 2)
230 ) + (1 - config->GetIsPhotoacousticImage())*s_i;
231 if (AddSample < inputS && AddSample >= 0)
232 output[sample*(short)outputL + line] += input[l_s + AddSample*(
short)inputL] *
233 apodisation[(short)((l_s - minLine)*apod_mult)];
237 output[sample*(short)outputL + line] = output[sample*(
short)outputL +
line] / usedLines;
242 float* input,
float* output,
float inputDim[2],
float outputDim[2],
243 const short&
line,
const mitk::BeamformingSettings::Pointer config)
245 const float* apodisation = config->GetApodizationFunction();
246 const short apodArraySize = config->GetApodizationArraySize();
248 const float* elementHeights = config->GetElementHeights();
249 const float* elementPositions = config->GetElementPositions();
251 float& inputS = inputDim[1];
252 float& inputL = inputDim[0];
254 float& outputS = outputDim[1];
255 float& outputL = outputDim[0];
266 short usedLines = (maxLine - minLine);
268 float totalSamples_i = (float)(config->GetReconstructionDepth()) /
269 (
float)(config->GetSpeedOfSound() * config->GetTimeSpacing());
270 totalSamples_i = totalSamples_i <= inputS ? totalSamples_i : inputS;
272 l_p = (float)line / outputL * config->GetHorizontalExtent();
274 for (
short sample = 0; sample < outputS; ++sample)
276 s_i = (float)sample / outputS * totalSamples_i;
278 minLine = config->GetMinMaxLines()[2 * sample*(short)outputL + 2 * line];
279 maxLine = config->GetMinMaxLines()[2 * sample*(short)outputL + 2 * line + 1];
280 usedLines = (maxLine - minLine);
282 apod_mult = (float)apodArraySize / (
float)usedLines;
285 short* AddSample =
new short[maxLine - minLine];
286 for (
short l_s = 0; l_s < maxLine - minLine; ++l_s)
288 AddSample[l_s] = (int)sqrt(
289 pow(s_i - elementHeights[l_s + minLine] / (config->GetSpeedOfSound()*config->GetTimeSpacing()), 2)
291 pow((1 / (config->GetTimeSpacing()*config->GetSpeedOfSound())) * (l_p - elementPositions[l_s + minLine]), 2)
292 ) + (1 - config->GetIsPhotoacousticImage())*s_i;
298 for (
short l_s1 = minLine; l_s1 < maxLine - 1; ++l_s1)
300 if (AddSample[l_s1 - minLine] < inputS && AddSample[l_s1 - minLine] >= 0)
302 for (
short l_s2 = l_s1 + 1; l_s2 < maxLine; ++l_s2)
304 if (AddSample[l_s2 - minLine] < inputS && AddSample[l_s2 - minLine] >= 0)
306 s_2 = input[l_s2 + AddSample[l_s2 - minLine] * (short)inputL];
307 s_1 = input[l_s1 + AddSample[l_s1 - minLine] * (short)inputL];
309 mult = s_2 * apodisation[(int)((l_s2 - minLine)*apod_mult)] * s_1 * apodisation[(
int)((l_s1 - minLine)*apod_mult)];
310 output[sample*(short)outputL + line] += sqrt(fabs(mult)) * ((mult > 0) - (mult < 0));
318 output[sample*(short)outputL + line] = output[sample*(
short)outputL +
line] / (float)(pow(usedLines, 2) - (usedLines - 1));
325 float* input,
float* output,
float inputDim[2],
float outputDim[2],
326 const short&
line,
const mitk::BeamformingSettings::Pointer config)
328 const float* apodisation = config->GetApodizationFunction();
329 const short apodArraySize = config->GetApodizationArraySize();
331 const float* elementHeights = config->GetElementHeights();
332 const float* elementPositions = config->GetElementPositions();
334 float& inputS = inputDim[1];
335 float& inputL = inputDim[0];
337 float& outputS = outputDim[1];
338 float& outputL = outputDim[0];
349 short usedLines = (maxLine - minLine);
351 float totalSamples_i = (float)(config->GetReconstructionDepth()) /
352 (
float)(config->GetSpeedOfSound() * config->GetTimeSpacing());
353 totalSamples_i = totalSamples_i <= inputS ? totalSamples_i : inputS;
355 l_p = (float)line / outputL * config->GetHorizontalExtent();
357 for (
short sample = 0; sample < outputS; ++sample)
359 s_i = (float)sample / outputS * totalSamples_i;
361 minLine = config->GetMinMaxLines()[2 * sample*(short)outputL + 2 * line];
362 maxLine = config->GetMinMaxLines()[2 * sample*(short)outputL + 2 * line + 1];
363 usedLines = (maxLine - minLine);
365 apod_mult = (float)apodArraySize / (
float)usedLines;
368 short* AddSample =
new short[maxLine - minLine];
369 for (
short l_s = 0; l_s < maxLine - minLine; ++l_s)
371 AddSample[l_s] = (int)sqrt(
372 pow(s_i - elementHeights[l_s + minLine] / (config->GetSpeedOfSound()*config->GetTimeSpacing()), 2)
374 pow((1 / (config->GetTimeSpacing()*config->GetSpeedOfSound())) * (l_p - elementPositions[l_s + minLine]), 2)
375 ) + (1 - config->GetIsPhotoacousticImage())*s_i;
382 for (
short l_s1 = minLine; l_s1 < maxLine - 1; ++l_s1)
384 if (AddSample[l_s1 - minLine] < inputS && AddSample[l_s1 - minLine] >= 0)
386 s_1 = input[l_s1 + AddSample[l_s1 - minLine] * (short)inputL];
389 for (
short l_s2 = l_s1 + 1; l_s2 < maxLine; ++l_s2)
391 if (AddSample[l_s2 - minLine] < inputS && AddSample[l_s2 - minLine] >= 0)
393 s_2 = input[l_s2 + AddSample[l_s2 - minLine] * (short)inputL];
395 mult = s_2 * apodisation[(int)((l_s2 - minLine)*apod_mult)] * s_1 * apodisation[(
int)((l_s1 - minLine)*apod_mult)];
396 output[sample*(short)outputL + line] += sqrt(fabs(mult)) * ((mult > 0) - (mult < 0));
404 output[sample*(short)outputL + line] = output[sample*(
short)outputL +
line] / (float)(pow(usedLines, 2) - (usedLines - 1)) * ((sign > 0) - (sign < 0));