Volume Rendering

Sandeep Pulla sandeep_pulla at hotmail.com
Tue Dec 7 08:36:43 EST 1999


<x-flowed>Hi,

I'm trying to raycast an 8-bit volume and am running into all sorts of 
problems. The program seems to be reading the data(vtk/tiff) fine, only 
nothing gets rendered. What am I doing wrong ? (Forgive me if my problem is 
too trivial).

Relevant source code is below (version 2.4):
-----------------------------------------------------------------
void main()
{
	vtkRenderer *ren = vtkRenderer::New();
	vtkRenderWindow *renWin = vtkRenderWindow::New();
		renWin->AddRenderer(ren);
		renWin->DoubleBufferOff();
	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
		iren->SetRenderWindow(renWin);

/* I use one of these input formats... */
/* VTK */
	char FileName[] = "C:\\Vox99\\VolRen\\t.vtk";
	vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();
		reader->SetFileName(FileName);
		reader->Update();

/* Multiple TIFF files */
	vtkImageReader *reader = vtkImageReader::New();
		reader->SetFilePrefix("C:\\VOX99\\TIF\\C01F");
		reader->SetFilePattern("%s%.4d.tif");
		reader->SetDataScalarTypeToUnsignedChar();
		reader->SetDataExtent(0,511,0,511,1,64);
		reader->SetDataByteOrderToBigEndian();
		reader->Update();
/* Raw data */
	vtkStructuredPoints *pts;
	pts = ReadRawData(512,512,5,"C:\\Vox99\\VolRen\\t.raw");

	vtkColorTransferFunction *colorTransfer = vtkColorTransferFunction::New();
		colorTransfer->AddRGBSegment(0, 1.0, 1.0, 1.0, 255, 1.0, 1.0, 1.0);

	vtkPiecewiseFunction *opacityTransfer = vtkPiecewiseFunction::New();
		opacityTransfer->AddSegment(0, 1.0, 255, 1.0);

	vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
		volumeProperty->SetColor(colorTransfer);
		volumeProperty->SetScalarOpacity(opacityTransfer);
		volumeProperty->SetInterpolationTypeToLinear();
		volumeProperty->ShadeOn();

	vtkVolumeRayCastCompositeFunction *compositeFunction = 
vtkVolumeRayCastCompositeFunction::New();
	vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
		volumeMapper->SetInput(reader->GetOutput());
		volumeMapper->SetVolumeRayCastFunction(compositeFunction);

	vtkVolume *volume = vtkVolume::New();
		volume->SetVolumeMapper(volumeMapper);
		volume->SetVolumeProperty(volumeProperty);

	vtkOutlineFilter *outline = vtkOutlineFilter::New();
		outline->SetInput(reader->GetOutput());
	vtkPolyDataMapper* outlineMapper = vtkPolyDataMapper::New();
		outlineMapper->SetInput(outline->GetOutput());
	vtkActor* outlineActor = vtkActor::New();
		outlineActor->SetMapper(outlineMapper);
		outlineActor->GetProperty()->SetColor(1,1,1);

	ren->AddVolume(volume);
	ren->AddActor(outlineActor);
	renWin->Render();
	iren->Start();
}

Another problem is that I'm unable to use raw data because:
  a. I need to use vtkScalars and,
  b. vtkScalars stores data as float and,
  c. vtkVolumeRayCastMapper does not accept float !

Notice that my raw data is 8-bit, only the intermediate (vtkScalars) turns 
it into float.

How do I get around this ?


Thanks,
Sandeep

P.S. If you're interested, here's how I read in raw data:

vtkStructuredPoints* ReadRawData(int Nx, int Ny, int Nz, char* FileName)
{
	vtkStructuredPoints *pts = vtkStructuredPoints::New();
		pts->SetDimensions(Nx,Ny,Nz);
	vtkScalars *scalars = new vtkScalars;
	unsigned char value;
	int i, j, k, jOffset, kOffset;
	ifstream ifs(FileName);
	if(!ifs)
		error("ReadRawData: Unable to open file");
	for(k = 0; k < Nz; k++)
	{
		kOffset = k * Ny * Nx;
		for(j = 0; j < Ny; j++)
		{
			jOffset = j * Nx;
			for(i = 0; i < Nx; i++)
			{
				ifs >> value;
				if(!ifs)
					error("ReadRawData: Error reading from file");
				scalars->InsertScalar(i + jOffset + kOffset,value);
			}
		}
	}
	ifs.close();
	pts->GetPointData()->SetScalars(scalars);
	scalars->Delete();
	return pts;
}



______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com


-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------

</x-flowed>



More information about the vtkusers mailing list