UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-11-21)
usPixelMeterConversion.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ustk software.
4  * Copyright (C) 2016 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ustk with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * This software was developed at:
17  * Inria Rennes - Bretagne Atlantique
18  * Campus Universitaire de Beaulieu
19  * 35042 Rennes Cedex
20  * France
21  *
22  * If you have questions regarding the use of this file, please contact
23  * Inria at ustk@inria.fr
24  *
25  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27  *
28  * Authors:
29  * Marc Pouliquen
30  *
31  *****************************************************************************/
32 
38 #include <algorithm>
39 #include <visp3/ustk_core/usPixelMeterConversion.h>
40 
61 void usPixelMeterConversion::convert(const usImagePostScan2D<unsigned char> &image, const double &u, const double &v,
62  double &x, double &y)
63 {
64  // checking transducer settings to apply corresponding transformation
65  // First convex probe type
66  if (image.isTransducerConvex()) {
67  x = image.getWidthResolution() * u - (((double)image.getWidth() * image.getWidthResolution()) / 2.0);
68  y = image.getHeightResolution() * v +
69  image.getTransducerRadius() *
70  std::cos(((double)image.getScanLineNumber() - 1) * image.getScanLinePitch() / 2.0);
71  }
72  // Then linear probe type
73  else {
74  x = image.getWidthResolution() * u - (((double)image.getWidth() * image.getWidthResolution()) / 2.0);
75  y = image.getHeightResolution() * v;
76  }
77 }
78 
111 void usPixelMeterConversion::convert(const usImagePostScan3D<unsigned char> &image, const double &u, const double &v,
112  const double &w, double &x, double &y, double &z)
113 {
114  // checking transducer/motor settings to apply corresponding transformation
115  if (!image.isTransducerConvex()) { // linear transducer
116  if (image.getMotorType() == usMotorSettings::LinearMotor) { // linear motor
117  x = image.getElementSpacingX() * u - ((image.getWidth() * image.getElementSpacingX()) / 2.0);
118  y = image.getElementSpacingY() * v;
119  z = image.getElementSpacingZ() * w - (image.getNumberOfFrames() * image.getElementSpacingZ() / 2.0);
120  } else if (image.getMotorType() == usMotorSettings::TiltingMotor) { // tilting motor
121  x = image.getElementSpacingX() * u - ((image.getWidth() * image.getElementSpacingX()) / 2.0);
122  y = image.getElementSpacingY() * v +
123  image.getMotorRadius() * std::cos((image.getFrameNumber() - 1) * image.getFramePitch() / 2.0) -
124  image.getMotorRadius();
125  z = image.getElementSpacingZ() * w - (image.getNumberOfFrames() * image.getElementSpacingZ() / 2.0);
126  } else
127  throw(vpException(vpException::notImplementedError, "Rotationnal Motor is not available yet."));
128  }
129  // Then convex transducer
130  else {
131  if (image.getMotorType() == usMotorSettings::LinearMotor) { // linear motor
132  x = image.getElementSpacingX() * u - (image.getWidth() * image.getElementSpacingX() / 2.0);
133  y = image.getElementSpacingY() * v +
134  image.getTransducerRadius() * std::cos((image.getScanLineNumber() - 1) * image.getScanLinePitch() / 2.0);
135  z = image.getElementSpacingZ() * w - (image.getNumberOfFrames() * image.getElementSpacingZ() / 2.0);
136  } else if (image.getMotorType() == usMotorSettings::TiltingMotor) { // tilting motor
137  x = image.getElementSpacingX() * u - (image.getWidth() * image.getElementSpacingX() / 2.0);
138 
139  y = image.getElementSpacingY() * v +
140  (image.getTransducerRadius() * // Rmin
141  std::cos((image.getScanLineNumber() - 1) * image.getScanLinePitch() / 2) // cos (FOV/2)
142  - (image.getTransducerRadius() - image.getMotorRadius())) // Delta R
143  * std::cos((image.getFrameNumber() - 1) * image.getFramePitch() / 2) // cos(Phi/2)
144  + (image.getTransducerRadius() - image.getMotorRadius()); // Delta R
145 
146  z = image.getElementSpacingZ() * w - (image.getNumberOfFrames() * image.getElementSpacingZ() / 2.0);
147  } else
148  throw(vpException(vpException::notImplementedError, "Rotationnal Motor is not available yet."));
149  }
150 }
unsigned int getNumberOfFrames() const
Definition: usImage3D.h:137
unsigned int getWidth() const
Definition: usImage3D.h:125
double getHeightResolution() const
double getWidthResolution() const
double getElementSpacingX() const
double getElementSpacingY() const
double getElementSpacingZ() const
unsigned int getFrameNumber() const
double getMotorRadius() const
double getFramePitch() const
usMotorType getMotorType() const
static void convert(const usImagePostScan2D< unsigned char > &image, const double &u, const double &v, double &x, double &y)
Conversion for 2D post-scan images.
double getTransducerRadius() const
unsigned int getScanLineNumber() const