//----------------------------------------------------------------------------
void VolumeRenderer::OnDisplay ()
{
    mRT->DrawWireFrame();

    for (int y = 0; y < mBound; ++y)
    {
        for (int x = 0; x < mBound; ++x)
        {
            int i = x + mBound*y;
            unsigned int value = mRT->GetRendered(i);
            unsigned char r = GetRed24(value);
            unsigned char g = GetGreen24(value);
            unsigned char b = GetBlue24(value);
            SetPixel(x, y, ColorRGB(r, g, b));
        }
    }

    WindowApplication2::OnDisplay();
}
Exemple #2
0
//----------------------------------------------------------------------------
bool ImViewer::OnPrecreate ()
{
    if (!WindowApplication2::OnPrecreate())
    {
        return false;
    }

    char* filename = 0;
    Application::TheCommand->GetFilename(filename);
    if (!filename)
    {
        // Input filename must be specified on the command line.
        return false;
    }

    // Load the image data.
    int rtti, sizeOf;
    char* data = 0;
    bool loaded = Lattice::LoadRaw(filename, mNumDimensions, mBound,
        mNumPixels, rtti, sizeOf, data);
    if (!loaded)
    {
        delete1(data);
        delete1(filename);
        return false;
    }

    // Replace the window title by the filename.
    mWindowTitle = std::string(filename);
    delete1(filename);

    // Set window size based on image size.  Adjust height to allow for
    // status bar.  The window width is chosen so that rows are multiples
    // of 4 bytes.
    mHeight = mBound[1];
    if (mHeight < 128)
    {
        mHeight = 128;
    }

    int statusHeight = 20;
    mHeight += statusHeight;

    mWidth = mBound[0];
    if (mWidth < 256)
    {
        mWidth = 256;
    }

    int remainder = (mWidth % 4);
    if (remainder > 0)
    {
        mWidth += 4 - remainder;
    }

    // The application image is stored differently depending on the input
    // image format.
    int i;
    if (rtti == Ergb5::GetRTTI())
    {
        mColorData = new1<ColorRGB>(mNumPixels);
        unsigned short* usData = (unsigned short*)data;
        for (i = 0; i < mNumPixels; i++)
        {
            unsigned char r = GetRed16(usData[i]);
            unsigned char g = GetGreen16(usData[i]);
            unsigned char b = GetBlue16(usData[i]);
            mColorData[i] = ColorRGB(r, g, b);
        }
    }
    else if (rtti == Ergb8::GetRTTI())
    {
        mColorData = new1<ColorRGB>(mNumPixels);
        unsigned int* uiData = (unsigned int*)data;
        for (i = 0; i < mNumPixels; i++)
        {
            unsigned char r = GetRed24(uiData[i]);
            unsigned char g = GetGreen24(uiData[i]);
            unsigned char b = GetBlue24(uiData[i]);
            mColorData[i] = ColorRGB(r, g, b);
        }
    }
    else if (rtti == Efloat::GetRTTI())
    {
        mFloatData = new1<float>(mNumPixels);
        memcpy(mFloatData, data, mNumPixels*sizeof(float));
    }
    else
    {
        mFloatData = new1<float>(mNumPixels);
        ImageConvert(mNumPixels, rtti, data, Efloat::GetRTTI(), mFloatData);
    }
    delete1(data);

    // Compute min, max and range of float images.
    if (mFloatData)
    {
        mMin = mFloatData[0];
        mMax = mMin;
        for (i = 1; i < mNumPixels; ++i)
        {
            if (mFloatData[i] < mMin)
            {
                mMin = mFloatData[i];
            }
            else if (mFloatData[i] > mMax)
            {
                mMax = mFloatData[i];
            }
        }
        mRange = mMax - mMin;
        if (mRange > 0.0f)
        {
            mInvRange = 1.0f/mRange;
        }
        else
        {
            mInvRange = 0.0f;
        }
    }

    // We only need memory to hold the active slice.
    mNumSlicePixels = mBound[0]*mBound[1];
    return true;
}