UsTK : Ultrasound ToolKit  version 2.0.1 under development (2023-12-07)
usImagePreScan3D.h
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  * Pierre Chatelain
30  * Marc Pouliquen
31  *
32  *****************************************************************************/
33 
39 #ifndef __usImagePreScan3D_h_
40 #define __usImagePreScan3D_h_
41 
42 #include <visp3/ustk_core/usImage3D.h>
43 #include <visp3/ustk_core/usImagePreScan2D.h>
44 
45 #include <visp3/ustk_core/usImagePreScanSettings.h>
46 
47 #include <visp3/ustk_core/usMotorSettings.h>
48 
138 template <class Type>
140 {
141 public:
142  // default constructors
144  // All parameters initialisation constructors
145  usImagePreScan3D(const usImage3D<Type> &image, const usImagePreScanSettings &preScanSettings,
146  const usMotorSettings &motorSettings);
147  // usImagePreScan3D copy constructor
149 
150  // destructor
151  virtual ~usImagePreScan3D();
152 
153  unsigned int getBModeSampleNumber() const;
154 
155  void getFrame(usImagePreScan2D<Type> &image, unsigned int index);
156 
157  void insertFrame(const usImagePreScan2D<Type> &frame, unsigned int index);
158 
159  // assignement
161  // comparison
162  bool operator==(const usImagePreScan3D<Type> &other);
163 
164  void setData(const usImage3D<Type> &image);
165  void setFrameNumber(unsigned int frameNumber);
166  void setScanLineNumber(unsigned int scanLineNumber);
167 
168  // Filtering before calling vpImage::resize() to update scanLineNumber
169  void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames);
170 };
171 
175 template <class Type>
177 {
178 }
179 
186 template <class Type>
188  const usMotorSettings &motorSettings)
189  : usImage3D<Type>(image), usImagePreScanSettings(preScanSettings), usMotorSettings(motorSettings)
190 {
191  if (image.getWidth() != preScanSettings.getScanLineNumber())
192  throw(vpException(vpException::badValue, "3D pre-scan image X-size differ from transducer scan line number"));
193  if (image.getNumberOfFrames() != motorSettings.getFrameNumber())
194  throw(vpException(vpException::badValue, "3D pre-scan image Z-size differ from motor frame number"));
195 }
196 
201 template <class Type>
203  : usImage3D<Type>(other), usImagePreScanSettings(other), usMotorSettings(other)
204 {
205 }
206 
211 
216 {
217  // from vpImage
219 
220  // from usImageSettings
222 
223  // for motor settings
225 
226  return *this;
227 }
228 
232 template <class Type> bool usImagePreScan3D<Type>::operator==(const usImagePreScan3D<Type> &other)
233 {
234  return (usImage3D<Type>::operator==(other) && usImagePreScanSettings::operator==(other) &&
235  usMotorSettings::operator==(other));
236 }
237 
241 template <class Type> std::ostream &operator<<(std::ostream &out, const usImagePreScan3D<Type> &other)
242 {
243  return out << static_cast<const usImage3D<Type> &>(other) << static_cast<const usImagePreScanSettings &>(other)
244  << static_cast<const usMotorSettings &>(other);
245 }
246 
250 template <class Type> unsigned int usImagePreScan3D<Type>::getBModeSampleNumber() const
251 {
253 }
254 
259 template <class Type> void usImagePreScan3D<Type>::setData(const usImage3D<Type> &image)
260 {
262  setScanLineNumber(image.getWidth());
263  setFrameNumber(image.getNumberOfFrames());
264 }
265 
272 template <class Type> void usImagePreScan3D<Type>::setScanLineNumber(unsigned int scanLineNumber)
273 {
276 }
277 
284 template <class Type> void usImagePreScan3D<Type>::setFrameNumber(unsigned int frameNumber)
285 {
287  usMotorSettings::setFrameNumber(frameNumber);
288 }
289 
299 template <class Type>
300 void usImagePreScan3D<Type>::resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
301 {
302  usImage3D<Type>::resize(height, width, numberOfFrames);
303  usMotorSettings::setFrameNumber(numberOfFrames);
305 }
306 
312 template <class Type> void usImagePreScan3D<Type>::insertFrame(const usImagePreScan2D<Type> &frame, unsigned int index)
313 {
314  // Dimentions checks
315  if (index > this->getNumberOfFrames())
316  throw(vpException(vpException::badValue, "usImage3D::insertFrame : frame index out of volume"));
317 
318  if (frame.getHeight() != this->getHeight() || frame.getWidth() != this->getWidth())
319  throw(vpException(vpException::badValue, "usImage3D::insertFrame : frame size don't match volume size"));
320 
321  // offset to access the frame in the volume
322  int offset = index * this->getHeight() * this->getWidth();
323  Type *frameBeginning = this->getData() + offset;
324 
325  // copy
326  for (unsigned int i = 0; i < this->getWidth(); i++) {
327  for (unsigned int j = 0; j < this->getHeight(); j++) {
328  frameBeginning[i + this->getWidth() * j] = frame[j][i];
329  }
330  }
331 }
332 
338 template <class Type> void usImagePreScan3D<Type>::getFrame(usImagePreScan2D<Type> &image, unsigned int index)
339 {
340 
341  // Dimentions checks
342  if (index > this->getNumberOfFrames() - 1)
343  throw(vpException(vpException::badValue, "usImage3D::getFrame : frame index out of volume"));
344 
345  image.resize(this->getHeight(), this->getWidth());
346 
347  // offset to access the frame in the volume
348  int offset = index * this->getHeight() * this->getWidth();
349  const Type *frameBeginning = this->getConstData() + offset;
350 
351  // copy
352  for (unsigned int i = 0; i < this->getWidth(); i++) {
353  for (unsigned int j = 0; j < this->getHeight(); j++) {
354  image[j][i] = frameBeginning[i + this->getWidth() * j];
355  }
356  }
357 }
358 
359 #endif // __usImagePreScan3D_h_
Representation of a physical image volume.
Definition: usImage3D.h:61
unsigned int getNumberOfFrames() const
Definition: usImage3D.h:137
void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
Definition: usImage3D.h:376
unsigned int getHeight() const
Definition: usImage3D.h:131
unsigned int getWidth() const
Definition: usImage3D.h:125
usImage3D< Type > & operator=(const usImage3D< Type > &other)
Definition: usImage3D.h:324
2D pre-scan ultrasound image.
void resize(const unsigned int h, const unsigned int w)
3D pre-scan ultrasound image.
void getFrame(usImagePreScan2D< Type > &image, unsigned int index)
void setScanLineNumber(unsigned int scanLineNumber)
usImagePreScan3D< Type > & operator=(const usImagePreScan3D< Type > &other)
void setData(const usImage3D< Type > &image)
bool operator==(const usImagePreScan3D< Type > &other)
virtual ~usImagePreScan3D()
void setFrameNumber(unsigned int frameNumber)
void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
void insertFrame(const usImagePreScan2D< Type > &frame, unsigned int index)
usImagePreScan3D(const usImage3D< Type > &image, const usImagePreScanSettings &preScanSettings, const usMotorSettings &motorSettings)
usImagePreScan3D(const usImagePreScan3D &other)
unsigned int getBModeSampleNumber() const
Settings associated to ultrasound pre-scan images implemented in usImageRF2D, usImageRF3D,...
usImagePreScanSettings & operator=(const usImagePreScanSettings &other)
Generic class for 3D ultrasound motor settings associated to the 3D probe used during acquisition.
usMotorSettings & operator=(const usMotorSettings &other)
unsigned int getFrameNumber() const
void setFrameNumber(unsigned int frameNumber)
unsigned int getScanLineNumber() const
void setScanLineNumber(unsigned int scanLineNumber)