[vtkusers] Help using OpenGL
Baudelet, Jean-Benoit
JBAUDELET at PARTNERS.ORG
Tue Aug 5 16:23:53 EDT 2008
Hi,
I am having some issues with the vtkImageViewer2.
I am basically trying to show bigtiff images using VTK.
The tiff i am trying to open is organized in tiles (200 pix by 200 pix) so i
have to open every tile, read it and
re-organize the tile in a vtkDataArray so that it displays nicely using
vtkImageViewer2.
Showing one column of tiles seems fine. It displays nicely.
The problem is the following :
when i try to display 4 tiles (2 by 2), the upper row is not showing properly.
The upper row is shrunk by a factor of 2. The rest of the row is black.
I've tried testing to see if my loop was accessing the pixels of black color. To
check I forced the 100 000th pixel to be white but it still showed up as black
when i retrieved it (using the data->GetTuple3(100000))
I copied my code below so that, hopefully, you'll be able to see where the
problem is.
Thank you very much for any advice you can give me
/-- CODE --/
#include "vtkImageQuantizeRGBToIndex.h"
#include "vtkLookupTable.h"
#include "vtkImageMapToColors.h"
#include "vtkImageMapToWindowLevelColors.h"
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkDataArray.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageToVTKImageFilter.h"
#include "vtkImageViewer2.h"
#include "vtkRenderWindowInteractor.h"
#include "tiffio.h"
#include "stdio.h"
#define DEBUG 1
#define DEBUG_P 0
int main( int argc, char *argv[] ) {
TIFF* tif;
uint32* buf;
uint32 sizeTotalW,sizeTotalL,nbPixelTile,startPixel, offset, alpha;
uint sizeTileW;
uint sizeTileL;
uint32 r,g,b,a;
int i,j,k,l;
vtkImageData * img;
vtkDataArray * data;
int totalTileX = atoi(argv[2]);
int totalTileY = atoi(argv[3]);
int startTileX = atoi(argv[4]);
int startTileY = atoi(argv[5]);
if(DEBUG)
{
std::cout <<"totalTileX: "<<totalTileX <<std::endl;
std::cout <<"totalTileY: "<<totalTileY<<std::endl;
std::cout <<"startTileX: "<<startTileX<<std::endl;
std::cout <<"startTileY: "<<startTileY<<std::endl;
}
img = vtkImageData::New();
img->SetOrigin(0,0,0);
img->SetSpacing(1,1,1);
img->SetNumberOfScalarComponents(3);
img->SetScalarType(VTK_UNSIGNED_CHAR);
tif = TIFFOpen(argv[1], "r");
if(tif)
{
TIFFGetField(tif, TIFFTAG_TILEWIDTH,&sizeTileW);
TIFFGetField(tif, TIFFTAG_TILELENGTH,&sizeTileL);
sizeTotalW = totalTileY*sizeTileW;
sizeTotalL = totalTileX*sizeTileL;
nbPixelTile = sizeTileW * sizeTileL;
img->SetDimensions(sizeTotalL,sizeTotalW,1);
img->AllocateScalars();
data = img->GetPointData()->GetScalars();
buf = (uint32 *) _TIFFmalloc(nbPixelTile*sizeof(uint32 * ));
if(DEBUG)
{
std::cout <<"sizeTotalW: "<<sizeTotalW <<std::endl;
std::cout <<"sizeTotalL: "<<sizeTotalL <<std::endl;
std::cout <<"Total pixel "<< sizeTotalW*sizeTotalL <<
std::endl;
}
for(i = 0; i < totalTileY; i++)
{
for(j = 0; j < totalTileX; j++)
{
offset = 0;
TIFFReadRGBATile(tif, (startTileY + j)*
sizeTileW, (startTileX + i)* sizeTileL , buf);
startPixel = (totalTileY- i + - 1) *
nbPixelTile + j * sizeTileL;
if(DEBUG)
{
std::cout <<"\nStart pixel for :
"<<(startTileX + i)<<","<<(startTileY + j)<<": "<<startPixel<<"------"<<
std::endl;
}
alpha = sizeTileW * (sizeTileL - 1);
for(k = 0 ; k < sizeTileW; k++)
{
for(l = 0 ; l < sizeTileL ; l++)
{
if(startPixel + offset + l ==
100000)
{
std::cout <<
"Reached" << std::endl;
data->SetTuple3(100000,255,0,0);
}
if(DEBUG_P)
{ if(l%10==0)
std::cout << startPixel
+ offset + l <<"\t";
}
/*r = TIFFGetR(buf[k*sizeTileW
+ l]);
g = TIFFGetG(buf[k*sizeTileW +
l]);
b = TIFFGetB(buf[k*sizeTileW +
l]);
data->SetTuple3(startPixel +
offset + l,r,g,b);*/
if(j%2==0){
if(i%2==0)
{
data->SetTuple3(startPixel + offset + l,255,255,255);
}
else
{
data->SetTuple3(startPixel + offset + l,0,255,0);
}
}
else
{
if(i%2==0)
{
data->SetTuple3(startPixel + offset + l,0,255,255);
}
else
{
data->SetTuple3(startPixel + offset + l,255,255,0);
}
}
alpha = (alpha == sizeTileL * (sizeTileW
- 1) + 2*(sizeTileL-1))?sizeTileW * (sizeTileL - 1):alpha+2;
}
offset = offset + sizeTileL *
totalTileX;
}
}
}
_TIFFfree(buf);
TIFFClose(tif);
}
if(DEBUG)
{
std::cout <<"Actual Memory size "<<
img->GetActualMemorySize() <<std::endl;
}
vtkImageViewer2 * viewer = vtkImageViewer2::New();
vtkRenderWindowInteractor * renderWindowInteractor =
vtkRenderWindowInteractor::New();
viewer->SetupInteractor( renderWindowInteractor );
vtkImageQuantizeRGBToIndex * imgRGB =
vtkImageQuantizeRGBToIndex::New();
imgRGB->SetInput(img);
imgRGB->SetNumberOfColors(500);
viewer->GetWindowLevel()->SetLookupTable(imgRGB->GetLookupTable());
viewer->GetWindowLevel()->SetInput(imgRGB->GetOutput());
viewer->GetWindowLevel()->SetLevel(-256);
viewer->SetInput( imgRGB->GetOutput() );
viewer->Render();
double * pixel = data->GetTuple3(100000);
std::cout << pixel[0]<<std::endl;
std::cout << pixel[2]<<std::endl;
std::cout << pixel[2]<<std::endl;
renderWindowInteractor->Start();
return 0;
}
Thank you very much in advance and please don't hesitate to reply with any
comments.
Ben
--
Ben Baudelet
Division of Informatics
Pathology Department
Massachusetts General Hospital
Boston, MA 02114
The information transmitted in this electronic communication is intended only
for the person or entity to whom it is addressed and may contain confidential
and/or privileged material. Any review, retransmission, dissemination or other
use of or taking of any action in reliance upon this information by persons or
entities other than the intended recipient is prohibited. If you received this
information in error, please contact the Compliance HelpLine at 800-856-1983 and
properly dispose of this information.
More information about the vtkusers
mailing list