Skip to content

Commit

Permalink
Add Images::getScalarData(std::uint32_t imageIndex, ...) overload for…
Browse files Browse the repository at this point in the history
… retrieving image scalar data in one operation (#629)

* Add Images::getScalarData(std::uint32_t imageIndex, ...) overload to retrieve image in one operation

* Add randomized point depth to point renderer (#632)

* Add Images::getScalarData(std::uint32_t imageIndex, ...) overload to retrieve image in one operation

---------

Co-authored-by: Baldur van Lew <[email protected]>
  • Loading branch information
ThomasKroes and bldrvnlw authored Jul 15, 2024
1 parent e199345 commit b6cb5e9
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 7 deletions.
111 changes: 108 additions & 3 deletions ManiVault/src/plugins/ImageData/src/Images.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ void Images::getScalarData(const std::uint32_t& dimensionIndex, QVector<float>&
{
try
{
if (static_cast<std::uint32_t>(scalarData.count()) < getNumberOfPixels())
const auto numberOfElementsRequired = getNumberOfPixels();

if (static_cast<std::uint32_t>(scalarData.count()) < numberOfElementsRequired)
throw std::runtime_error("Scalar data vector number of elements is smaller than the number of pixels");

switch (_imageData->getType())
Expand Down Expand Up @@ -237,10 +239,113 @@ void Images::getScalarData(const std::uint32_t& dimensionIndex, QVector<float>&
}
catch (std::exception& e)
{
exceptionMessageBox("Unable to get scalar data", e);
exceptionMessageBox("Unable to get scalar data for the given dimension index", e);
}
catch (...) {
exceptionMessageBox("Unable to get scalar data for the given dimension index");
}
}

void Images::getScalarData(const std::vector<std::uint32_t>& dimensionIndices, QVector<float>& scalarData, QPair<float, float>& scalarDataRange)
{
try
{
const auto numberOfPixels = static_cast<std::int32_t>(getNumberOfPixels());
const auto numberOfElementsRequired = dimensionIndices.size() * getNumberOfPixels();
const auto numberOfComponentsPerPixel = static_cast<std::int32_t>(getNumberOfComponentsPerPixel());

if (static_cast<std::uint32_t>(scalarData.count()) < numberOfElementsRequired)
throw std::runtime_error("Scalar data vector number of elements is smaller than (nDimensions * nPixels)");

QVector<float> tempScalarData(numberOfElementsRequired);
QPair<float, float> tempScalarDataRange(std::numeric_limits<float>::max(), std::numeric_limits<float>::lowest());

switch (_imageData->getType())
{
case ImageData::Undefined:
break;

case ImageData::Sequence:
{
std::int32_t componentIndex = 0;

for (const auto& dimensionIndex : dimensionIndices) {
getScalarDataForImageSequence(dimensionIndex, tempScalarData, tempScalarDataRange);

for (std::int32_t pixelIndex = 0; pixelIndex < numberOfPixels; pixelIndex++)
scalarData[(pixelIndex * numberOfComponentsPerPixel) + componentIndex] = tempScalarData[pixelIndex];

componentIndex++;
}

break;
}

case ImageData::Stack:
{
std::int32_t componentIndex = 0;

for (const auto& dimensionIndex : dimensionIndices) {
getScalarDataForImageStack(dimensionIndex, tempScalarData, tempScalarDataRange);

for (std::int32_t pixelIndex = 0; pixelIndex < numberOfPixels; pixelIndex++)
scalarData[(pixelIndex * numberOfComponentsPerPixel) + componentIndex] = tempScalarData[pixelIndex];

componentIndex++;
}

break;
}

case ImageData::MultiPartSequence:
break;

default:
break;
}

scalarDataRange = { std::numeric_limits<float>::max(), std::numeric_limits<float>::lowest() };

for (auto& scalar : scalarData) {
scalarDataRange.first = std::min(scalar, scalarDataRange.first);
scalarDataRange.second = std::max(scalar, scalarDataRange.second);
}
}
catch (std::exception& e)
{
exceptionMessageBox("Unable to get scalar data for the given dimension indices", e);
}
catch (...) {
exceptionMessageBox("Unable to get scalar data for the given dimension indices");
}
}

void Images::getImageScalarData(std::uint32_t imageIndex, QVector<float>& scalarData, QPair<float, float>& scalarDataRange)
{
try {
const auto numberOfPixels = static_cast<std::int32_t>(getNumberOfPixels());
const auto numberOfComponentsPerPixel = static_cast<std::int32_t>(getNumberOfComponentsPerPixel());
const auto numberOfElementsRequired = numberOfPixels * numberOfComponentsPerPixel;

if (static_cast<std::uint32_t>(scalarData.count()) < numberOfElementsRequired)
throw std::runtime_error("Scalar data vector number of elements is smaller than (nComponentsPerPixel * nPixels)");

const auto dimensionIndexOffset = imageIndex * getNumberOfComponentsPerPixel();

std::vector<std::uint32_t> dimensionIndices;

dimensionIndices.resize(getNumberOfComponentsPerPixel());

std::iota(dimensionIndices.begin(), dimensionIndices.end(), dimensionIndexOffset);

getScalarData(dimensionIndices, scalarData, scalarDataRange);
}
catch (std::exception& e)
{
exceptionMessageBox("Unable to get image scalar data", e);
}
catch (...) {
exceptionMessageBox("Unable to get scalar data");
exceptionMessageBox("Unable to get image scalar data");
}
}

Expand Down
24 changes: 20 additions & 4 deletions ManiVault/src/plugins/ImageData/src/Images.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,29 @@ class IMAGEDATA_EXPORT Images : public mv::DatasetImpl
public:

/**
* Get scalar image data
* Get scalar image data for \p dimensionIndex, populates \p scalarData and \p establishes the \p scalarDataRange
* @param dimensionIndex Dimension index
* @param scalarData Scalar data for the specified dimension
* @param scalarData Scalar data for the specified dimension (assumes enough elements are allocated by the caller)
* @param scalarDataRange Scalar data range
*/
void getScalarData(const std::uint32_t& dimensionIndex, QVector<float>& scalarData, QPair<float, float>& scalarDataRange);

/**
* Get scalar image data for \p dimensionIndices, populates \p scalarData and \p establishes the \p scalarDataRange
* @param dimensionIndices Dimension indices to retrieve the scalar data for
* @param scalarData Scalar data for the specified dimension (assumes enough elements are allocated by the caller)
* @param scalarDataRange Scalar data range
*/
void getScalarData(const std::vector<std::uint32_t>& dimensionIndices, QVector<float>& scalarData, QPair<float, float>& scalarDataRange);

/**
* Get scalar image data for \p imageIndex
* @param imageIndex Index of the image to retrieve the scalar data for
* @param scalarData Scalar data for the specified dimension (assumes enough elements are allocated by the caller)
* @param scalarDataRange Scalar data range
*/
void getImageScalarData(std::uint32_t imageIndex, QVector<float>& scalarData, QPair<float, float>& scalarDataRange);

/**
* Get mask image data (for subsets)
* @param maskData Mask scalar data
Expand All @@ -200,15 +216,15 @@ class IMAGEDATA_EXPORT Images : public mv::DatasetImpl
protected:

/**
* Get scalar data for image sequence
* Get image sequence scalar data for \p dimensionIndex, populate \p scalarData and establish the \p scalarDataRange
* @param dimensionIndex Dimension index
* @param scalarData Scalar data for the specified dimension
* @param scalarDataRange Scalar data range
*/
void getScalarDataForImageSequence(const std::uint32_t& dimensionIndex, QVector<float>& scalarData, QPair<float, float>& scalarDataRange);

/**
* Get scalar data for image stack
* Get image stack scalar data for \p dimensionIndex, populate \p scalarData and establish the \p scalarDataRange
* @param dimensionIndex Dimension index
* @param scalarData Scalar data for the specified dimension
* @param scalarDataRange Scalar data range
Expand Down

0 comments on commit b6cb5e9

Please sign in to comment.