[vtkusers] Problem getting opacity values to work
shawn b
brewinull at hotmail.com
Fri Feb 14 12:42:25 EST 2003
I was wondering if anyone could offer some advice as to what I am doing
wrong with a program that I am working on. I am trying to get 1 image to
gradually fade out and another image to gradually fade in. I am using
vtkImageBlend and adjusting the opacity of the 2 bitmaps to try and achieve
this effect.
However what I am getting as a result right now is a quick switch from 1
image to the other without any fading. The first image stays up until the
opacity hits 0 then the second image shows up on the screen. I think it
might be a problem with updating the properties of the different elements
that are being displayed but if that is the case then why is the screen
switching from one image to the other when the opacity hits 0.
Any advice as to what I can do to achieve this gradual fade would be very
welcome. This is the source code for the program that I described above:
int main()
{
int width = 10;
int height = 10;
int i = 0;
float opacity1 = 1;
float opacity2 = 0;
double test_opac1 = 1;
double test_opac2 = 0;
// Path to input file
char* filename = "D:\\shawn\\alafia40.bmp";
char* filename2 = "D:\\shawn\\alafia63.bmp";
vtkImageBlend *test = vtkImageBlend::New();
vtkCamera *camera = vtkCamera::New();
vtkPlaneSource *plane = vtkPlaneSource::New();
vtkPlaneSource *plane2 = vtkPlaneSource::New();
vtkBMPReader *bmp = vtkBMPReader::New();
vtkBMPReader *bmp2 = vtkBMPReader::New();
vtkTexture *texture = vtkTexture::New();
vtkTexture *texture2 = vtkTexture::New();
vtkTexture *TextureTest = vtkTexture::New();
vtkPolyDataMapper *planeMapper = vtkPolyDataMapper::New();
vtkPolyDataMapper *planeMapper2 = vtkPolyDataMapper::New();
vtkActor *planeActor = vtkActor::New();
vtkActor *planeActor2 = vtkActor::New();
camera->SetPosition(0,0,2);
// Read in bitmap
bmp->SetFileName(filename);
bmp2->SetFileName(filename2);
// Set bitmaps as input for vtkImageBlend variable
test->AddInput(bmp->GetOutput());
test->AddInput(bmp2->GetOutput());
// Set the vtkImageBlend variable as the input for the texture
TextureTest->SetInput( test->GetOutput() );
// Set resolution for the plane
plane->SetResolution( width, height);
//Map the plane
planeMapper->SetInput( plane->GetOutput() );
// Set the texutre and mapper for the actor
planeActor->SetMapper( planeMapper );
planeActor->SetTexture( TextureTest );
// create a renderer and assign actors to it
vtkRenderer *renderer1= vtkRenderer::New();
renderer1->AddActor( planeActor );
renderer1->SetBackground( 0, 0, 0 );
//create render window and assign renderer to it
vtkRenderWindow *renderWin = vtkRenderWindow::New();
renderWin->AddRenderer( renderer1 );
renderWin->SetSize( 800, 600 );
//Set initial opacities of actor and bitmaps
planeActor->GetProperty()->SetOpacity(opacity1);
test->SetOpacity(1,test_opac1);
test->SetOpacity(2,test_opac2);
renderWin->Start();
//for loop to test the fading
//slowly lower the opacity of 1 image and lower opacity
//of the other image
for (i = 0; i < 1400; ++i)
{
// render the image
test_opac1 = (test_opac1 - (i/1000));
test_opac2 = (test_opac2 + (i/1000));
test->SetOpacity(1,test_opac1);
test->SetOpacity(2,test_opac2);
renderWin->Render();
renderer1->SetActiveCamera(camera);
}
return 0;
}
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
More information about the vtkusers
mailing list