UsTK : Ultrasound ToolKit  version 2.0.1 under development (2023-12-07)
usImageRF2D.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  * Marc Pouliquen
30  *
31  *****************************************************************************/
32 
38 #ifndef __usImageRF2D_h_
39 #define __usImageRF2D_h_
40 
41 #include <cstring>
42 
43 #include <visp3/ustk_core/usImagePreScanSettings.h>
44 
111 template <class Type> class usImageRF2D : public usImagePreScanSettings
112 {
113  friend class usRawFileParser;
114  friend class usNetworkGrabberRF2D;
115  friend class usNetworkGrabberRF3D;
116  friend class usVirtualServer;
117 
118 public:
120  usImageRF2D(unsigned int height, unsigned int width);
121  usImageRF2D(unsigned int height, unsigned int width, const usImagePreScanSettings &preScanSettings);
122  usImageRF2D(const usImageRF2D &other);
123  virtual ~usImageRF2D();
124 
125  const Type *getBitmap() const;
126 
127  unsigned int getHeight() const;
128  unsigned int getNumberOfPixel() const;
129  unsigned int getRFSampleNumber() const;
130 
131  const Type *getSignal(unsigned int scanlineIndex) const;
132 
133  unsigned int getWidth() const;
134 
136  void init(unsigned int height, unsigned int width);
137 
139  bool operator==(const usImageRF2D<Type> &other);
140 
142  Type operator()(unsigned int i, unsigned int j) const;
143  void operator()(unsigned int i, unsigned int j, const Type &value);
144 
145  void setScanLineNumber(unsigned int scanLineNumber);
146 
147  void resize(const unsigned int height, const unsigned int width);
148  void resize(const unsigned int height, const unsigned int width, const Type &val);
149 
150 private:
151  Type *bitmap;
152  unsigned int npixels;
153  unsigned int width;
154  unsigned int height;
155  Type **col;
156 };
157 
163 template <class Type>
164 usImageRF2D<Type>::usImageRF2D() : usImagePreScanSettings(), bitmap(NULL), npixels(0), width(0), height(0), col(NULL)
165 {
166 }
167 
173 template <class Type>
174 usImageRF2D<Type>::usImageRF2D(unsigned int height, unsigned int width)
175  : usImagePreScanSettings(), bitmap(NULL), npixels(0), width(0), height(0), col(NULL)
176 {
177  init(height, width);
178 }
179 
186 template <class Type>
187 usImageRF2D<Type>::usImageRF2D(unsigned int height, unsigned int width, const usImagePreScanSettings &preScanSettings)
188  : usImagePreScanSettings(preScanSettings), bitmap(NULL), npixels(0), width(0), height(0), col(NULL)
189 {
190  if (width != preScanSettings.getScanLineNumber())
191  throw(vpException(vpException::badValue, "RF image width differ from transducer scan line number"));
192 
193  init(height, width);
194  setImagePreScanSettings(preScanSettings);
195 }
196 
201 template <class Type>
203  : usImagePreScanSettings(other), bitmap(NULL), npixels(0), width(0), height(0), col(NULL)
204 {
205  // allocation and resize
206  resize(other.getHeight(), other.getWidth());
207 
208  // filling pixels values
209  memcpy(bitmap, other.getBitmap(), (size_t)(height * width * sizeof(Type)));
210 }
211 
215 template <class Type> usImageRF2D<Type>::~usImageRF2D()
216 {
217  if (bitmap != NULL) {
218  delete[] bitmap;
219  bitmap = NULL;
220  }
221 
222  if (col != NULL) {
223  delete[] col;
224  col = NULL;
225  }
226 }
227 
232 {
233  resize(other.getHeight(), other.getWidth());
234  memcpy(bitmap, other.getBitmap(), height * width * sizeof(Type));
235 
236  // from usImagePreScanSettings
238 
239  return *this;
240 }
241 
245 template <class Type> bool usImageRF2D<Type>::operator==(const usImageRF2D<Type> &other)
246 {
247 
248  if (this->width != other.getWidth())
249  return false;
250  if (this->height != other.getHeight())
251  return false;
252 
253  for (unsigned int i = 0; i < npixels; i++) {
254  if (bitmap[i] != other.bitmap[i]) {
255  return false;
256  }
257  }
259 }
260 
267 template <class Type> Type usImageRF2D<Type>::operator()(unsigned int i, unsigned int j) const
268 {
269  if (i >= height || j >= width)
270  throw vpException(vpException::dimensionError, "usImageRF2D, try to acess index out of image bounds");
271 
272  return col[j][i];
273 }
274 
281 template <class Type> void usImageRF2D<Type>::operator()(unsigned int i, unsigned int j, const Type &value)
282 {
283  if (i >= height || j >= width)
284  throw vpException(vpException::dimensionError, "usImageRF2D, try to write at index out of image bounds");
285 
286  col[j][i] = value;
287 }
288 
292 template <class Type> std::ostream &operator<<(std::ostream &out, const usImageRF2D<Type> &other)
293 {
294  return out << static_cast<const usImagePreScanSettings &>(other) << "image height : " << other.getHeight()
295  << std::endl
296  << "image width : " << other.getWidth() << std::endl
297  << "number of A-samples in a scan line : " << other.getRFSampleNumber() << std::endl
298  << "number of scan lines : " << other.getScanLineNumber() << std::endl;
299 }
300 
305 template <class Type> unsigned int usImageRF2D<Type>::getRFSampleNumber() const { return getHeight(); }
306 
313 template <class Type> void usImageRF2D<Type>::setScanLineNumber(unsigned int scanLineNumber)
314 {
315  if (scanLineNumber != getWidth())
316  resize(this->getHeight(), scanLineNumber);
317 
319 }
320 
328 template <class Type> void usImageRF2D<Type>::resize(const unsigned int height, const unsigned int width)
329 {
330  this->init(height, width);
331  this->setScanLineNumber(width);
332 }
333 
342 template <class Type>
343 void usImageRF2D<Type>::resize(const unsigned int height, const unsigned int width, const Type &val)
344 {
345  this->init(height, width);
346  this->setScanLineNumber(width);
347 
348  // fill bitmap
349  for (unsigned int n = 0; n < this->npixels; n++) {
350  bitmap[n] = val;
351  }
352 }
353 
371 template <class Type> void usImageRF2D<Type>::init(unsigned int height, unsigned int width)
372 {
373  if (width != this->width) {
374  if (col != NULL) {
375  delete[] col;
376  col = NULL;
377  }
378  }
379 
380  if ((height != this->height) || (width != this->width)) {
381  if (bitmap != NULL) {
382  delete[] bitmap;
383  bitmap = NULL;
384  }
385  }
386  this->width = width;
387  this->height = height;
388 
389  npixels = width * height;
390  if (bitmap == NULL)
391  bitmap = new Type[npixels];
392 
393  if (bitmap == NULL) {
394  throw(vpException(vpException::memoryAllocationError, "cannot allocate bitmap "));
395  }
396 
397  if (col == NULL)
398  col = new Type *[width];
399  if (col == NULL) {
400  throw(vpException(vpException::memoryAllocationError, "cannot allocate col "));
401  }
402 
403  unsigned int j;
404  for (j = 0; j < width; j++)
405  col[j] = bitmap + j * height;
406 }
407 
412 template <class Type> unsigned int usImageRF2D<Type>::getHeight() const { return height; }
413 
418 template <class Type> unsigned int usImageRF2D<Type>::getNumberOfPixel() const { return npixels; }
419 
424 template <class Type> unsigned int usImageRF2D<Type>::getWidth() const { return width; }
425 
430 template <class Type> const Type *usImageRF2D<Type>::getBitmap() const { return bitmap; }
431 
437 template <class Type> const Type *usImageRF2D<Type>::getSignal(unsigned int scanlineIndex) const
438 {
439  return col[scanlineIndex];
440 }
441 #endif // __usImageRF2D_h_
Settings associated to ultrasound pre-scan images implemented in usImageRF2D, usImageRF3D,...
void setImagePreScanSettings(const usImagePreScanSettings &preScanSettings)
bool operator==(const usImagePreScanSettings &other)
usImagePreScanSettings & operator=(const usImagePreScanSettings &other)
2D Radio Frequence (RF) ultrasound image.
Definition: usImageRF2D.h:112
bool operator==(const usImageRF2D< Type > &other)
Definition: usImageRF2D.h:245
void operator()(unsigned int i, unsigned int j, const Type &value)
Definition: usImageRF2D.h:281
usImageRF2D(unsigned int height, unsigned int width)
Definition: usImageRF2D.h:174
usImageRF2D< Type > & operator=(const usImageRF2D< Type > &other)
Definition: usImageRF2D.h:231
unsigned int getNumberOfPixel() const
Definition: usImageRF2D.h:418
void setScanLineNumber(unsigned int scanLineNumber)
Definition: usImageRF2D.h:313
unsigned int getHeight() const
Definition: usImageRF2D.h:412
virtual ~usImageRF2D()
Definition: usImageRF2D.h:215
void resize(const unsigned int height, const unsigned int width, const Type &val)
Definition: usImageRF2D.h:343
usImageRF2D(const usImageRF2D &other)
Definition: usImageRF2D.h:202
friend class usRawFileParser
Definition: usImageRF2D.h:113
void resize(const unsigned int height, const unsigned int width)
Definition: usImageRF2D.h:328
const Type * getSignal(unsigned int scanlineIndex) const
Definition: usImageRF2D.h:437
Type operator()(unsigned int i, unsigned int j) const
operator() allows to access/modify RF samples values in the image.
Definition: usImageRF2D.h:267
unsigned int getWidth() const
Definition: usImageRF2D.h:424
void init(unsigned int height, unsigned int width)
Set the size of the image.
Definition: usImageRF2D.h:371
const Type * getBitmap() const
Definition: usImageRF2D.h:430
usImageRF2D()
Constructor.
Definition: usImageRF2D.h:164
unsigned int getRFSampleNumber() const
Definition: usImageRF2D.h:305
usImageRF2D(unsigned int height, unsigned int width, const usImagePreScanSettings &preScanSettings)
Definition: usImageRF2D.h:187
Specific class to grab RF frames from the ultrasound station on the network.
Specific class to grab RF volumes from the ultrasound station on the network.
unsigned int getScanLineNumber() const
void setScanLineNumber(unsigned int scanLineNumber)
Class to simulate a server sending frames from an ultrasound station. Permits to replay a sequence of...