Skip to content

Commit

Permalink
Merge pull request #42 from jchevrie/Add_volume_processing
Browse files Browse the repository at this point in the history
Add volume processing
  • Loading branch information
MarcPouliquenInria authored Jul 9, 2018
2 parents 48af6be + fdffd08 commit 9962889
Show file tree
Hide file tree
Showing 7 changed files with 1,232 additions and 35 deletions.
58 changes: 36 additions & 22 deletions modules/ustk_core/include/visp3/ustk_core/usImage3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ template <class Type> class usImage3D
usImage3D();

/**
* Constructor. Set the dimensions of the volume.
* Constructor. Set the dimensions of the volume. Initialize the data container with default value.
* @param height Volume height.
* @param width Volume width.
* @param frameNumber Volume size in the third dimension (orthogonal to ultrasound 2D frames).
*/
usImage3D(unsigned int height, unsigned int width, unsigned int frameNumber);

/**
* Constructor. Set the dimensions of the volume. Initialize the data container with the specified value.
* @param height Volume height.
* @param width Volume width.
* @param frameNumber Volume size in the third dimension (orthogonal to ultrasound 2D frames).
* @param initialValue The initial data
*/
usImage3D(unsigned int height, unsigned int width, unsigned int frameNumber, Type initialValue);

/**
* Copy constructor. By default performs a deep copy.
Expand Down Expand Up @@ -176,11 +185,11 @@ template <class Type> class usImage3D

/**
* Resize the image if needed (if new dimensions differ from old ones).
* @param width The volume size along i axis.
* @param heigth The volume size along j axis.
* @param height The volume size along i axis.
* @param width The volume size along j axis.
* @param numberOfFrames The volume size along k axis.
*/
void resize(unsigned int width, unsigned int heigth, unsigned int numberOfFrames);
void resize(unsigned int height, unsigned int width, unsigned int numberOfFrames);

/**
* Set the data container.
Expand All @@ -195,11 +204,11 @@ template <class Type> class usImage3D
private:
/**
* Initiation of the image.
* @param heigth Volume height (number of voxels).
* @param height Volume height (number of voxels).
* @param width Volume width (number of voxels).
* @param numberOfFrames Volume size (number of voxels) in the third dimension (orthogonal to ultrasound 2D frames).
*/
void init(unsigned int heigth, unsigned int width, unsigned int numberOfFrames);
void init(unsigned int height, unsigned int width, unsigned int numberOfFrames);

unsigned int m_width; /**< Volume width in voxels (number of voxels on the j-axis)*/
unsigned int m_height; /**< Volume height in voxels (number of voxels on the i-axis)*/
Expand Down Expand Up @@ -246,9 +255,9 @@ inline void usImage3D<Type>::init(unsigned int height, unsigned int width, unsig
}
}

this->m_width = width;
this->m_height = height;
this->m_numberOfFrames = numberOfFrames;
m_width = width;
m_height = height;
m_numberOfFrames = numberOfFrames;

m_size = m_width * m_height * m_numberOfFrames;

Expand All @@ -269,28 +278,34 @@ inline void usImage3D<Type>::init(unsigned int height, unsigned int width, unsig
}

template <class Type>
usImage3D<Type>::usImage3D() : m_width(0), m_height(0), m_numberOfFrames(0), m_size(0), bitmap(NULL), framPointer(NULL)
usImage3D<Type>::usImage3D()
: m_width(0), m_height(0), m_numberOfFrames(0), m_size(0), bitmap(NULL), framPointer(NULL)
{
}

template <class Type>
usImage3D<Type>::usImage3D(unsigned int height, unsigned int width, unsigned int frameNumber)
: m_width(width), m_height(height), m_numberOfFrames(frameNumber), m_size(width * height * frameNumber), bitmap(NULL),
framPointer(NULL)
: m_width(0), m_height(0), m_numberOfFrames(0), m_size(0), bitmap(NULL), framPointer(NULL)
{
init(height, width, frameNumber);
initData(0);
this->init(height, width, frameNumber);
this->initData(Type());
}

template <class Type> usImage3D<Type>::usImage3D(const usImage3D<Type> &volume, const bool copy)
template <class Type>
usImage3D<Type>::usImage3D(unsigned int height, unsigned int width, unsigned int frameNumber, Type initialValue)
: m_width(0), m_height(0), m_numberOfFrames(0), m_size(0), bitmap(NULL), framPointer(NULL)
{
init(volume.getWidth(), volume.getHeight(), volume.getNumberOfFrames());
this->init(height, width, frameNumber);
this->initData(initialValue);
}

m_size = m_width * m_height * m_numberOfFrames;
template <class Type> usImage3D<Type>::usImage3D(const usImage3D<Type> &volume, const bool copy)
: m_width(0), m_height(0), m_numberOfFrames(0), m_size(0), bitmap(NULL), framPointer(NULL)
{
this->init(volume.getHeight(), volume.getWidth(), volume.getNumberOfFrames());

// deep copy
if (copy)
memcpy(bitmap, volume.bitmap, m_size * sizeof(Type));
if(copy) memcpy(bitmap, volume.bitmap, m_size * sizeof(Type));
}

template <class Type> usImage3D<Type>::~usImage3D()
Expand All @@ -307,7 +322,7 @@ template <class Type> usImage3D<Type>::~usImage3D()

template <class Type> usImage3D<Type> &usImage3D<Type>::operator=(const usImage3D<Type> &other)
{
init(other.m_width, other.m_height, other.m_numberOfFrames);
this->init(other.m_height, other.m_width, other.m_numberOfFrames);

memcpy(bitmap, other.bitmap, m_size * sizeof(Type));
return *this;
Expand Down Expand Up @@ -338,7 +353,6 @@ template <class Type> std::ostream &operator<<(std::ostream &out, const usImage3
template <class Type> void usImage3D<Type>::setData(Type *data, int numberOfVoxels)
{
try {
m_size = numberOfVoxels;
if (m_size != numberOfVoxels) {
throw(vpException(vpException::fatalError, "usImage3D::setData() error, bitmap dimensions mismatch."));
}
Expand All @@ -360,6 +374,6 @@ template <class Type> void usImage3D<Type>::initData(Type value)

template <class Type> void usImage3D<Type>::resize(unsigned int height, unsigned int width, unsigned int numberOfFrames)
{
init(height, width, numberOfFrames);
this->init(height, width, numberOfFrames);
}
#endif // __usImage3D_h_
4 changes: 2 additions & 2 deletions modules/ustk_core/include/visp3/ustk_core/usImagePreScan3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ template <class Type> void usImagePreScan3D<Type>::setData(const usImage3D<Type>
*/
template <class Type> void usImagePreScan3D<Type>::setScanLineNumber(unsigned int scanLineNumber)
{
usImage3D<Type>::resize(scanLineNumber, usImage3D<Type>::getHeight(), usImage3D<Type>::getNumberOfFrames());
usImage3D<Type>::resize(usImage3D<Type>::getHeight(), scanLineNumber, usImage3D<Type>::getNumberOfFrames());
usTransducerSettings::setScanLineNumber(scanLineNumber);
}

Expand All @@ -283,7 +283,7 @@ template <class Type> void usImagePreScan3D<Type>::setScanLineNumber(unsigned in
*/
template <class Type> void usImagePreScan3D<Type>::setFrameNumber(unsigned int frameNumber)
{
usImage3D<Type>::resize(usImage3D<Type>::getWidth(), usImage3D<Type>::getHeight(), frameNumber);
usImage3D<Type>::resize(usImage3D<Type>::getHeight(), usImage3D<Type>::getWidth(), frameNumber);
usMotorSettings::setFrameNumber(frameNumber);
}

Expand Down
19 changes: 8 additions & 11 deletions modules/ustk_grabber/src/usNetworkGrabberPreScan3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,23 @@ void usNetworkGrabberPreScan3D::includeFrameInVolume()
m_grabbedImage.getHeight()) { // m_grabbedImage is "turned" so the height corresponds to the scanline numer.
throw(vpException(vpException::badValue, "Transducer settings changed during acquisition, somethink went wrong"));
}
if (m_outputBuffer.at(CURRENT_FILLED_FRAME_POSITION_IN_VEC)->getMotorSettings() != m_motorSettings)
throw(vpException(vpException::badValue, "Motor settings changed during acquisition, somethink went wrong"));
} else { // init case
m_outputBuffer.at(OUTPUT_FRAME_POSITION_IN_VEC)->setImagePreScanSettings(m_grabbedImage);
m_outputBuffer.at(OUTPUT_FRAME_POSITION_IN_VEC)->setScanLineNumber(m_grabbedImage.getHeight());
m_outputBuffer.at(MOST_RECENT_FRAME_POSITION_IN_VEC)->setImagePreScanSettings(m_grabbedImage);
m_outputBuffer.at(MOST_RECENT_FRAME_POSITION_IN_VEC)->setScanLineNumber(m_grabbedImage.getHeight());
}
m_outputBuffer.at(CURRENT_FILLED_FRAME_POSITION_IN_VEC)->setImagePreScanSettings(m_grabbedImage);
m_outputBuffer.at(CURRENT_FILLED_FRAME_POSITION_IN_VEC)->setScanLineNumber(m_grabbedImage.getHeight());

if (m_firstFrameAvailable) {
if (m_outputBuffer.at(CURRENT_FILLED_FRAME_POSITION_IN_VEC)->getMotorSettings() != m_motorSettings)
throw(vpException(vpException::badValue, "Motor settings changed during acquisition, somethink went wrong"));
} else { // init case
m_outputBuffer.at(CURRENT_FILLED_FRAME_POSITION_IN_VEC)->setImagePreScanSettings(m_grabbedImage);
m_outputBuffer.at(CURRENT_FILLED_FRAME_POSITION_IN_VEC)->setScanLineNumber(m_grabbedImage.getHeight());

m_outputBuffer.at(OUTPUT_FRAME_POSITION_IN_VEC)->setMotorSettings(m_motorSettings);
m_outputBuffer.at(MOST_RECENT_FRAME_POSITION_IN_VEC)->setMotorSettings(m_motorSettings);
m_outputBuffer.at(CURRENT_FILLED_FRAME_POSITION_IN_VEC)->setMotorSettings(m_motorSettings);
}
m_outputBuffer.at(CURRENT_FILLED_FRAME_POSITION_IN_VEC)->setMotorSettings(m_motorSettings);


m_outputBuffer.at(CURRENT_FILLED_FRAME_POSITION_IN_VEC)
->resize(m_grabbedImage.getHeight(), m_grabbedImage.getWidth(), m_motorSettings.getFrameNumber());
->resize(m_grabbedImage.getWidth(), m_grabbedImage.getHeight(), m_motorSettings.getFrameNumber());

// Inserting frame in volume by inverting rows and cols voxels (along x and y axis), to match ustk volume storage
int volumeIndex = (m_grabbedImage.getFrameCount() / m_grabbedImage.getFramesPerVolume()); // from 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#############################################################################
#
# This file is part of the ustk software.
# Copyright (C) 2016 - 2017 by Inria. All rights reserved.
#
# This software is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# ("GPL") version 2 as published by the Free Software Foundation.
# See the file LICENSE.txt at the root directory of this source
# distribution for additional information about the GNU GPL.
#
# For using ustk with software that can not be combined with the GNU
# GPL, please contact Inria about acquiring a ViSP Professional
# Edition License.
#
# This software was developed at:
# Inria Rennes - Bretagne Atlantique
# Campus Universitaire de Beaulieu
# 35042 Rennes Cedex
# France
#
# If you have questions regarding the use of this file, please contact
# Inria at [email protected]
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# Authors:
# Fabien Spindler
#
#############################################################################

vp_add_module(ustk_volume_processing visp_core visp_ustk_core)

vp_glob_module_sources()
vp_module_include_directories()
vp_create_module()

vp_add_tests(DEPENDS_ON visp_ustk_volume_processing)

Loading

0 comments on commit 9962889

Please sign in to comment.