[vtkusers] jittering of vtkVolume when changing vtkCamera azimuth angle
Michael Yip
myip at ece.ubc.ca
Tue Apr 26 13:53:03 EDT 2011
Hi,
I've been having a problem when trying to animate a 360 degree pan of
ray-casted vtkVolume. What happens is that the volume itself seems to be
jittering as the camera pans around. The bounding box for it however, does
not jitter. Heres the code that I am using:
#include <vtkSmartPointer.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkVolume16Reader.h>
#include <vtkVolume.h>
#include <vtkVolumeRayCastMapper.h>
#include <vtkVolumeRayCastCompositeFunction.h>
#include <vtkVolumeProperty.h>
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkDataSetReader.h>
#include <vtkCamera.h>
#include <vtkBoundingBox.h>
#include <vtkOutlineFilter.h>
#include <vtkDataSetMapper.h>
#include <vtkAVIWriter.h>
#include <vtkWindowToImageFilter.h>
int main (int argc, char *argv[])
{
vtkRenderer* aren = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(aren);
renWin->SetSize(800,640);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
aren->SetBackground(0.8, 0.8, 0.8);
vtkDataSetReader *reader = vtkDataSetReader::New();
reader->DebugOff();
reader->SetFileName("C:\\Coursework\\Coursework\\Research\\vtkVolumes\\output_vol.vtk");
//reader->SetFileName("C:\\Users\\Michael\\Desktop\\Coursework\\Research\\vtkVolumes\\output_vol.vtk");
reader->Update();
vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
oTFun->AddSegment(80, 0.0, 255, 1.0);
oTFun->AddSegment(0, 255, 0, 0);
vtkVolumeProperty *volProperty = vtkVolumeProperty::New();
volProperty->SetScalarOpacity(oTFun);
volProperty->SetInterpolationTypeToLinear();
volProperty->ShadeOn();
vtkVolumeRayCastCompositeFunction *cpf =
vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper *volmap = vtkVolumeRayCastMapper::New();
volmap->SetInput(reader->GetOutput());
volmap->SetVolumeRayCastFunction(cpf);
vtkVolume *vol = vtkVolume::New();
vol->SetMapper(volmap);
vol->SetProperty(volProperty);
//create a bounding box
vtkOutlineFilter* outline = vtkOutlineFilter::New();
outline->SetInput(volmap->GetDataSetInput());
outline->Update();
vtkDataSetMapper* outlineMapper = vtkDataSetMapper::New();
outlineMapper->SetInput(outline->GetOutput());
vtkActor* outlineActor = vtkActor::New();
outlineActor->SetMapper(outlineMapper);
//Add actors to renderWindow
aren->AddActor(outlineActor);
aren->AddVolume(vol);
//Camera
vtkCamera* camera = aren->GetActiveCamera();
camera->SetFocalPoint(vol->GetCenter());
camera->Zoom(1);
camera->SetPosition(0,200,1000);
vtkWindowToImageFilter *imageFilter = vtkWindowToImageFilter::New();
imageFilter->SetInput(renWin);
vtkAVIWriter *avi=vtkAVIWriter::New();
avi->SetFileName("c:/TestAVIWriter.avi");
avi->SetInputConnection(imageFilter->GetOutputPort());
avi->Start();
for(int i = 0; i < 360 ; i++){
printf("i = %d\n", i);
renWin->Render();
camera->Azimuth(1.0);
imageFilter->Modified();
avi->Write();
}
avi->End();
printf("Finished...");
/*Cleanup*/
avi->Delete();
imageFilter->Delete();
camera->Delete();
vol->Delete();
volmap->Delete();
cpf->Delete();
volProperty->Delete();
oTFun->Delete();
reader->Delete();
renWin->Delete();
aren->Delete();
}
The input file is at:
http://www.ece.ubc.ca/~myip/work/output_vol.vtk
Also, I have a avi video of the output at:
http://www.ece.ubc.ca/~myip/work/TestAVIWriter.avi
Does anyone know what might be causing this? Did I forget to set some sort
of render parameter? Thanks,
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110426/23f43367/attachment.htm>
More information about the vtkusers
mailing list