Hi,<br><br>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:<br>
<br><span style="font-family: courier new,monospace;">#include <vtkSmartPointer.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <vtkRenderer.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include <vtkRenderWindow.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <vtkRenderWindowInteractor.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include <vtkVolume16Reader.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <vtkVolume.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include <vtkVolumeRayCastMapper.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <vtkVolumeRayCastCompositeFunction.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include <vtkVolumeProperty.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <vtkColorTransferFunction.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include <vtkPiecewiseFunction.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <vtkDataSetReader.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include <vtkCamera.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <vtkBoundingBox.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include <vtkOutlineFilter.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <vtkDataSetMapper.h></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include <vtkAVIWriter.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <vtkWindowToImageFilter.h></span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">int main (int argc, char *argv[])</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> vtkRenderer* aren = vtkRenderer::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkRenderWindow *renWin = vtkRenderWindow::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> renWin->AddRenderer(aren);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> renWin->SetSize(800,640);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> iren->SetRenderWindow(renWin);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> aren->SetBackground(0.8, 0.8, 0.8);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkDataSetReader *reader = vtkDataSetReader::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> reader->DebugOff();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> reader->SetFileName("C:\\Coursework\\Coursework\\Research\\vtkVolumes\\output_vol.vtk");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //reader->SetFileName("C:\\Users\\Michael\\Desktop\\Coursework\\Research\\vtkVolumes\\output_vol.vtk");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> reader->Update();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> oTFun->AddSegment(80, 0.0, 255, 1.0);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> oTFun->AddSegment(0, 255, 0, 0);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkVolumeProperty *volProperty = vtkVolumeProperty::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> volProperty->SetScalarOpacity(oTFun);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> volProperty->SetInterpolationTypeToLinear();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> volProperty->ShadeOn();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkVolumeRayCastCompositeFunction *cpf =</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> vtkVolumeRayCastCompositeFunction::New();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkVolumeRayCastMapper *volmap = vtkVolumeRayCastMapper::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> volmap->SetInput(reader->GetOutput());</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> volmap->SetVolumeRayCastFunction(cpf);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkVolume *vol = vtkVolume::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vol->SetMapper(volmap);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> vol->SetProperty(volProperty);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //create a bounding box</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> vtkOutlineFilter* outline = vtkOutlineFilter::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> outline->SetInput(volmap->GetDataSetInput());</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> outline->Update();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkDataSetMapper* outlineMapper = vtkDataSetMapper::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> outlineMapper->SetInput(outline->GetOutput());</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkActor* outlineActor = vtkActor::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> outlineActor->SetMapper(outlineMapper);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //Add actors to renderWindow</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> aren->AddActor(outlineActor);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> aren->AddVolume(vol);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //Camera</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> vtkCamera* camera = aren->GetActiveCamera();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> camera->SetFocalPoint(vol->GetCenter());</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> camera->Zoom(1);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> camera->SetPosition(0,200,1000);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkWindowToImageFilter *imageFilter = vtkWindowToImageFilter::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> imageFilter->SetInput(renWin);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> vtkAVIWriter *avi=vtkAVIWriter::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> avi->SetFileName("c:/TestAVIWriter.avi");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> avi->SetInputConnection(imageFilter->GetOutputPort());</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> avi->Start();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for(int i = 0; i < 360 ; i++){</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> printf("i = %d\n", i);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> renWin->Render();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> camera->Azimuth(1.0);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> imageFilter->Modified();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> avi->Write();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> avi->End();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf("Finished...");</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> /*Cleanup*/</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> avi->Delete();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> imageFilter->Delete();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> camera->Delete();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> vol->Delete();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> volmap->Delete();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> cpf->Delete();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> volProperty->Delete();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> oTFun->Delete();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> reader->Delete();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> renWin->Delete();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> aren->Delete();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br><br><br>The input file is at:<br><a href="http://www.ece.ubc.ca/~myip/work/output_vol.vtk">http://www.ece.ubc.ca/~myip/work/output_vol.vtk</a><br><br>Also, I have a avi video of the output at:<br>
<a href="http://www.ece.ubc.ca/~myip/work/TestAVIWriter.avi">http://www.ece.ubc.ca/~myip/work/TestAVIWriter.avi</a><br><br>Does anyone know what might be causing this? Did I forget to set some sort of render parameter? Thanks,<br>
<br>Mike<br>