UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-12-03)
usMeterPixelConversion.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 <visp3/ustk_core/usMeterPixelConversion.h>
39 
49 void usMeterPixelConversion::convert(const usImagePostScan2D<unsigned char> &image, const double &x, const double &y,
50  double &u, double &v)
51 {
52  // checking transducer settings to apply corresponding transformation
53  // First convex probe type
54  if (image.isTransducerConvex()) {
55  u = (x + ((image.getWidth() * image.getWidthResolution()) / 2)) / image.getWidthResolution();
56  v = (y - image.getTransducerRadius() * std::cos((image.getScanLineNumber() - 1) * image.getScanLinePitch() / 2)) /
57  image.getHeightResolution();
58  }
59  // Then linear probe type
60  else {
61  u = (x + ((image.getWidth() * image.getWidthResolution()) / 2)) / image.getWidthResolution();
62  v = y / image.getHeightResolution();
63  }
64 }
65 
77 void usMeterPixelConversion::convert(const usImagePostScan3D<unsigned char> &image, const double &x, const double &y,
78  const double &z, double &u, double &v, double &w)
79 {
80  // checking transducer/motor settings to apply corresponding transformation
81  if (!image.isTransducerConvex()) { // linear transducer
82  if (image.getMotorType() == usMotorSettings::LinearMotor) { // linear motor
83  u = (x + ((image.getWidth() * image.getElementSpacingX()) / 2)) / image.getElementSpacingX();
84  v = y / image.getElementSpacingY();
85  w = (z + image.getNumberOfFrames() * image.getElementSpacingZ() / 2) / image.getElementSpacingZ();
86  } else if (image.getMotorType() == usMotorSettings::TiltingMotor) { // tilting motor
87  u = (x + ((image.getWidth() * image.getElementSpacingX()) / 2)) / image.getElementSpacingX();
88  v = (y - image.getMotorRadius() * std::cos((image.getFrameNumber() - 1) * image.getFramePitch() / 2) +
89  image.getMotorRadius()) /
90  image.getElementSpacingY();
91  w = (z + image.getNumberOfFrames() * image.getElementSpacingZ() / 2) / image.getElementSpacingZ();
92  } else
93  throw(vpException(vpException::notImplementedError, "Rotationnal Motor is not available yet."));
94  }
95  // Then convex transducer
96  else {
97  if (image.getMotorType() == usMotorSettings::LinearMotor) { // linear motor
98  u = (x + ((image.getWidth() * image.getElementSpacingX()) / 2)) / image.getElementSpacingX();
99  v = (y - image.getTransducerRadius() * std::cos((image.getScanLineNumber() - 1) * image.getScanLinePitch() / 2)) /
100  image.getElementSpacingY();
101  w = (z + image.getNumberOfFrames() * image.getElementSpacingZ() / 2) / image.getElementSpacingZ();
102  } else if (image.getMotorType() == usMotorSettings::TiltingMotor) { // tilting motor
103  u = (x + ((image.getWidth() * image.getElementSpacingX()) / 2)) / image.getElementSpacingX();
104 
105  v = (y -
106  (image.getTransducerRadius() * // Rmin
107  std::cos((image.getScanLineNumber() - 1) * image.getScanLinePitch() / 2) // cos (FOV/2)
108  - (image.getTransducerRadius() - image.getMotorRadius())) // Delta R
109  * std::cos((image.getFrameNumber() - 1) * image.getFramePitch() / 2) // cos(Phi/2)
110  - (image.getTransducerRadius() - image.getMotorRadius())) // Delta R
111  / image.getElementSpacingY();
112 
113  w = (z + image.getNumberOfFrames() * image.getElementSpacingZ() / 2) / image.getElementSpacingZ();
114  } else
115  throw(vpException(vpException::notImplementedError, "Rotationnal Motor is not available yet."));
116  }
117 }
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
static void convert(const usImagePostScan2D< unsigned char > &image, const double &x, const double &y, double &u, double &v)
unsigned int getFrameNumber() const
double getMotorRadius() const
double getFramePitch() const
usMotorType getMotorType() const
double getTransducerRadius() const
unsigned int getScanLineNumber() const