float ImageAccess::getScalar(VectorXi position, uchar channel) const { if(mImage->getDimensions() == 2) position = Vector3i(position.x(), position.y(), 0); switch(mImage->getDataType()) { fastSwitchTypeMacro(return getScalarAsFloat<FAST_TYPE>((FAST_TYPE*)mData, position, mImage, channel)) } }
void setScalarAsFloat(T* data, VectorXi position, Image::pointer image, float value, uchar channel) { Vector3ui size = image->getSize(); if(position.x() < 0 || position.y() < 0 || position.z() < 0 || position.x() > size.x()-1 || position.y() > size.y()-1 || position.z() > size.z()-1 || channel >= image->getNrOfComponents()) throw OutOfBoundsException(); uint address = (position.x() + position.y()*size.x() + position.z()*size.x()*size.y())*image->getNrOfComponents() + channel; if(image->getDataType() == TYPE_SNORM_INT16) { data[address] = value * 32767.0f;; } else if(image->getDataType() == TYPE_UNORM_INT16) { data[address] = value * 65535.0f;; } else { data[address] = value; } }
void ImageAccess::setScalar(VectorXi position, float value, uchar channel) { Vector3i size(mImage->getWidth(), mImage->getHeight(), mImage->getDepth()); if(mImage->getDimensions() == 2) position = Vector3i(position.x(), position.y(), 0); switch(mImage->getDataType()) { fastSwitchTypeMacro(setScalarAsFloat<FAST_TYPE>((FAST_TYPE*)mData, position, mImage, value, channel)) } }
float getScalarAsFloat(T* data, VectorXi position, Image::pointer image, uchar channel) { Vector3ui size = image->getSize(); if(position.x() < 0 || position.y() < 0 || position.z() < 0 || position.x() > size.x()-1 || position.y() > size.y()-1 || position.z() > size.z()-1 || channel >= image->getNrOfComponents()) throw OutOfBoundsException(); T value = data[(position.x() + position.y()*size.x() + position.z()*size.x()*size.y())*image->getNrOfComponents() + channel]; float floatValue; if(image->getDataType() == TYPE_SNORM_INT16) { floatValue = std::max(-1.0f, (float)value / 32767.0f); } else if(image->getDataType() == TYPE_UNORM_INT16) { floatValue = (float)value / 65535.0f; } else { floatValue = value; } return floatValue; }