예제 #1
0
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))
    }
}
예제 #2
0
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;
    }
}
예제 #3
0
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))
    }
}
예제 #4
0
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;
}