<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hello<br>I am using VTK to visualize a stack of binary data ((.raw )see
code below). Now I would like to interactively manipulate the data;
e.g., when the left mouse button is pressed, I would like to divide all
data values by two (i.e. if v(x,y,z) is the value of the data in the
file at position (x,y,z), I want to perform the operation
v(x,y,z)=v(x,y,z)/2 for all x,y,z). I know how to write a callback
function, but I don't know how to access data that have been read in
with vtkVolume16 reader. Is it maybe possible to introduce a new
element into the VTK pipeline between the vtkVolume16Reader and the
vtkContourFilter, some kind of container that allows data manipulation?<br><br>Thank you,<br><br>Frency Varghese<br><br>Here is the code:<br><br>#include "vtkRenderer.h"<br>#include "vtkRenderWindow.h"<br>#include
"vtkRenderWindowInteractor.h"<br>#include "vtkVolume16Reader.h"<br>#include "vtkPolyDataMapper.h"<br>#include "vtkActor.h"<br>#include "vtkOutlineFilter.h"<br>#include "vtkCamera.h"<br>#include "vtkProperty.h"<br>#include "vtkPolyDataNormals.h"<br>#include "vtkContourFilter.h"<br>#include "vtkPolyDataWriter.h"<br><br>#include "vtkStructuredPointsWriter.h"<br><br><br><br>int main (int argc, char **argv)<br>{<br> if (argc < 2)<br> {<br> cout << "Usage: " << argv[0] << " " << endl;<br> return 1;<br> }<br><br> // Create the renderer, the render window, and the interactor. The renderer<br> // draws into the render window, the interactor enables mouse- and<br> // keyboard-based interaction with the data within the render window.<br><br> vtkRenderer *aRenderer = vtkRenderer::New();<br> vtkRenderWindow *renWin =
vtkRenderWindow::New();<br> renWin->AddRenderer(aRenderer);<br> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br> iren->SetRenderWindow(renWin);<br><br> // The following reader is used to read a series of 2D slices (images)<br> // that compose the volume. The slice dimensions are set, and the pixel spacing.<br><br> vtkVolume16Reader *v16 = vtkVolume16Reader::New();<br> v16->SetDataDimensions (54,47);<br> v16->SetImageRange (1,63);<br> v16->SetDataByteOrderToLittleEndian();<br> v16->SetFilePrefix (argv[1]);<br> v16->SetDataSpacing (1,1,1.5);<br><br>// An isosurface, or contour value of 100 is known to correspond to the<br> //skin of the patient. Once generated, a vtkPolyDataNormals filter is<br> // is used to create normals for smooth surface shading during
rendering.<br><br> vtkContourFilter *skinExtractor = vtkContourFilter::New();<br> skinExtractor->SetInputConnection(v16->GetOutputPort());<br> skinExtractor->SetValue(100,100);<br> vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();<br> skinNormals->SetInputConnection(skinExtractor->GetOutputPort());<br> skinNormals->SetFeatureAngle(60);<br> vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();<br> skinMapper->SetInputConnection(skinNormals->GetOutputPort());<br> skinMapper->ScalarVisibilityOff();<br> vtkActor *skin = vtkActor::New();<br> skin->SetMapper(skinMapper);<br><br>// An outline provides context around the data.<br><br> vtkOutlineFilter *outlineData = vtkOutlineFilter::New();<br> outlineData->SetInputConnection(v16->GetOutputPort());<br> vtkPolyDataMapper *mapOutline =
vtkPolyDataMapper::New();<br> mapOutline->SetInputConnection(outlineData->GetOutputPort());<br> vtkActor *outline = vtkActor::New();<br> outline->SetMapper(mapOutline);<br> outline->GetProperty()->SetColor(0,0,0);<br><br><br> vtkCamera *aCamera = vtkCamera::New();<br> aCamera->SetViewUp (0, 0, -1);<br> aCamera->SetPosition (0, 1, 0);<br> aCamera->SetFocalPoint (0, 0, 0);<br> aCamera->ComputeViewPlaneNormal();<br><br><br><br> // Actors are added to the renderer. An initial camera view is created.<br> // The Dolly() method moves the camera towards the FocalPoint,thereby //enlarging the image.<br> aRenderer->AddActor(outline);<br> aRenderer->AddActor(skin);<br> aRenderer->SetActiveCamera(aCamera);<br> aRenderer->ResetCamera ();<br> aCamera->Dolly(1.5);<br><br> // Set a background
color for the renderer and set the size of the render //window<br>(expressed in pixels).<br> aRenderer->SetBackground(1,1,1);<br> renWin->SetSize(500, 500);<br><br> // Note that when camera movement occurs (as it does in the Dolly() method), the<br>// clipping planes often need adjusting. Clipping planes<br> // consist of two planes: near and far along the view direction. The near plane //clips out objects in front of the plane; the far plane clips out objects behind the //plane. This way only what is drawn between the planes is actually rendered.<br> <br>aRenderer->ResetCameraClippingRange ();<br><br> // Initialize the event loop and then start it.<br> iren->Initialize();<br> iren->Start();<br><br>// It is important to delete all objects created previously to prevent<br> // memory leaks. In this case, since the program is on its way
to<br> // exiting, it is not so important. But in applications it is essential.<br> v16->Delete();<br> skinExtractor->Delete();<br> skinMapper->Delete();<br> skin->Delete();<br> outlineData->Delete();<br> mapOutline->Delete();<br> outline->Delete();<br> aCamera->Delete();<br> iren->Delete();<br> renWin->Delete();<br> aRenderer->Delete();<br> writer->Delete();<br> return 0;<br>}<input name="flag" value="" type="hidden">
<table style="width: 527px; height: 42px;" cellspacing="0"><tbody><tr>
<td colspan="3" class="control leftAlign"><br></td>
</tr>
<tr class="control">
<td class="leftAlign" nowrap="nowrap"><br></td>
<td class="leftAlign" nowrap="nowrap"><br></td>
<td class="rightAlign" width="65%" nowrap="nowrap"><br></td></tr></tbody></table></td></tr></table><br>