//---------------------------------------------------------------------------- bool ImViewer::OnInitialize () { if (!WindowApplication2::OnInitialize()) { return false; } CopySliceToScreen(); OnDisplay(); return true; }
//---------------------------------------------------------------------------- bool ImViewer::OnSpecialKeyDown (int key, int x, int y) { if (mNumDimensions != 3) { return false; } if (key == KEY_UP_ARROW) { // Up arrow pressed, go to next image slize. if (mZ < mBound[2] - 1) { ++mZ; CopySliceToScreen(); if (mMouseDown) { ReadPixelValue(x, y); } OnDisplay(); } return true; } if (key == KEY_DOWN_ARROW) { // Down arrow pressed, go to previous image slice. if (mZ > 0) { --mZ; CopySliceToScreen(); if (mMouseDown) { ReadPixelValue(x, y); } OnDisplay(); } return true; } return false; }
//---------------------------------------------------------------------------- bool WmtfViewer::OnKeyDown (unsigned char key, int x, int y) { switch (key) { case 'a': case 'A': mAlphaActive = !mAlphaActive; CopySliceToScreen(); if (mMouseDown) { ReadPixelValue(x, y); } OnDisplay(); return true; } return WindowApplication2::OnKeyDown(key, x, y); }
//---------------------------------------------------------------------------- bool WmtfViewer::OnInitialize () { if (!WindowApplication2::OnInitialize()) { return false; } // Get the texture information. mFormat = mTexture->GetFormat(); mXDim = mTexture->GetWidth(); mYDim = mTexture->GetHeight(); mNumTexels = mXDim*mYDim; mTexels = mTexture->GetData(0); // The image is stored in right-handed screen coordinates, where the // origin is the lower-left corner of the screen. Reflect the image // to display in left-handed coordinates. unsigned char save[16]; // 16 = maximum number of bytes per pixel unsigned char* data = (unsigned char*)mTexels; int bytesPerPixel = mTexture->GetPixelSize(); for (int y = 0; y < mYDim/2; ++y) { for (int x = 0; x < mXDim; ++x) { int isrc = bytesPerPixel*(x + mXDim*y); int itrg = bytesPerPixel*(x + mXDim*(mYDim - 1 - y)); unsigned char* srcData = &data[isrc]; unsigned char* trgData = &data[itrg]; memcpy(save, srcData, bytesPerPixel); memcpy(srcData, trgData, bytesPerPixel); memcpy(trgData, save, bytesPerPixel); } } // Convert the texture data to a 32-bit floating-point format. mImage = new1<Float4>(mNumTexels); Color::FromFunction[mFormat](mNumTexels, mTexels, mImage); // We need to map the floating-point channels to [0,1] for display. mRGBMin = FLT_MAX; mRGBMax = -FLT_MAX; mAMin = FLT_MAX; mAMax = -FLT_MAX; for (int i = 0; i < mNumTexels; ++i) { Float4 color = mImage[i]; for (int j = 0; j < 3; ++j) { if (color[j] < mRGBMin) { mRGBMin = color[j]; } if (color[j] > mRGBMax) { mRGBMax = color[j]; } } if (color[3] < mAMin) { mAMin = color[3]; } if (color[3] > mAMax) { mAMax = color[3]; } } if (0.0f <= mRGBMin && mRGBMax <= 1.0f) { mRGBMin = 0.0f; mRGBMax = 1.0f; mInvRGBRange = 1.0f; } else if (mRGBMax > mRGBMin) { mInvRGBRange = 1.0f/(mRGBMax - mRGBMin); } else { mInvRGBRange = 0.0f; } if (0.0f <= mAMin && mAMax <= 1.0f) { mAMin = 0.0f; mAMax = 1.0f; mInvARange = 1.0f; } else if (mAMax > mAMin) { mInvARange = 1.0f/(mAMax - mAMin); } else { mInvARange = 0.0f; } CopySliceToScreen(); OnDisplay(); return true; }