[vtkusers] vtkImage > Data / MapToColors / Cast / Actor..
Edward Pham
lost_bits1110 at hotmail.com
Fri Feb 27 11:55:17 EST 2004
Hi
I'm trying to create a noisy background using vtkImageData (i've used the
gaussian distribution to create this) Its a 2D image along x and z
Below are some details of my code (its not that long, it just seems long but
its quite straightforward):
I used vtkImageMapToColors and vtkImageCast (because my scalars aer of type
float not unsigned char)
So all I see is black on my screen...! :o(
what could i be missing? any ideas..??
thanks in advance...
Ed
---------------------------------------------------------------------------------------------------------------------------------------
int offset, iOffset, kOffset, gaussLimit;
float scalarRange[2] = {VTK_LARGE_FLOAT,-VTK_LARGE_FLOAT};
float x, y, z, gauss, sigmaSquared, sigma;
NoiseData = vtkImageData::New();
NoiseFloatArray = vtkFloatArray::New();
NoiseLookupTable = vtkLookupTable::New();
ImageMapToColors = vtkImageMapToColors::New();
ImageCast = vtkImageCast::New();
ConvertedNoiseData = vtkImageData::New();
NoiseData->SetDimensions( 50, 1, 50 );
NoiseData->SetOrigin(0, 1, 0);
NoiseData->SetSpacing( 1, 1, 1 );
NoiseData->SetScalarType(VTK_FLOAT);
for ( int k=0; k < noiseDimZ; k++ )
{
z = sigma*Randomize()*gaussLimit;
kOffset = k*noiseDimZ*noiseDimY;
for ( int i=0; i < noiseDimX; i++ )
{
x = sigma*Randomize()*gaussLimit; //Randomize generates a random
number b/w -1 & 1
gauss = exp(-0.5*((x*x + z*z)/(sigmaSquared)));
if (gauss<scalarRange[0])
scalarRange[0] = gauss;
if (gauss>scalarRange[1])
scalarRange[1] = gauss;
offset = i + kOffset;
NoiseFloatArray->InsertTuple1( offset, gauss );
}
}
NoiseData->GetPointData()->SetScalars( NoiseFloatArray );
NoiseLookupTable->SetAlphaRange(0,1);
NoiseLookupTable->SetHueRange(0, 0);
NoiseLookupTable->SetNumberOfColors(256);
NoiseLookupTable->SetSaturationRange(0, 1);
NoiseLookupTable->SetValueRange(0, 1);
NoiseLookupTable->SetTableRange(scalarRange);
NoiseLookupTable->Build();
ImageCast->SetInput( NoiseData );
ImageCast->SetOutputScalarTypeToUnsignedChar();
ImageMapToColors->SetInput(ImageCast->GetOutput());
ImageMapToColors->SetLookupTable(NoiseLookupTable);
// NoiseData->Modified();
// ImageMapToColors->Update();
NoiseActor->SetInput(ImageMapToColors->GetOutput());
Ren1->AddActor( NoiseActor );
RenWin->AddRenderer( Ren1 );
RenWin->SetInteractor(Iren);
Iren->Initialize();
Iren->Render();
_________________________________________________________________
Get fast, reliable access with MSN 9 Dial-up. Click here for Special Offer!
http://click.atdmt.com/AVE/go/onm00200361ave/direct/01/
More information about the vtkusers
mailing list