[vtkusers] Dont know how to manipulate data interactively, Please help
frency v
frencyvarghese at yahoo.com
Mon Mar 30 17:42:07 EDT 2009
Hello
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?
Thank you,
Frency Varghese
Here is the code:
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume16Reader.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkOutlineFilter.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkPolyDataNormals.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataWriter.h"
#include "vtkStructuredPointsWriter.h"
int main (int argc, char **argv)
{
if (argc < 2)
{
cout << "Usage: " << argv[0] << " " << endl;
return 1;
}
// Create the renderer, the render window, and the interactor. The renderer
// draws into the render window, the interactor enables mouse- and
// keyboard-based interaction with the data within the render window.
vtkRenderer *aRenderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(aRenderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// The following reader is used to read a series of 2D slices (images)
// that compose the volume. The slice dimensions are set, and the
// pixel spacing.
vtkVolume16Reader *v16 = vtkVolume16Reader::New();
v16->SetDataDimensions (54,47);
v16->SetImageRange (1,63);
v16->SetDataByteOrderToLittleEndian();
v16->SetFilePrefix (argv[1]);
v16->SetDataSpacing (1,1,1.5);
// An isosurface, or contour value of 100 is known to correspond to the
//skin of the patient. Once generated, a vtkPolyDataNormals filter is
// is used to create normals for smooth surface shading during rendering.
vtkContourFilter *skinExtractor = vtkContourFilter::New();
skinExtractor->SetInputConnection(v16->GetOutputPort());
skinExtractor->SetValue(100,100);
vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
skinNormals->SetInputConnection(skinExtractor->GetOutputPort());
skinNormals->SetFeatureAngle(60);
vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
skinMapper->SetInputConnection(skinNormals->GetOutputPort());
skinMapper->ScalarVisibilityOff();
vtkActor *skin = vtkActor::New();
skin->SetMapper(skinMapper);
// An outline provides context around the data.
vtkOutlineFilter *outlineData = vtkOutlineFilter::New();
outlineData->SetInputConnection(v16->GetOutputPort());
vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
mapOutline->SetInputConnection(outlineData->GetOutputPort());
vtkActor *outline = vtkActor::New();
outline->SetMapper(mapOutline);
outline->GetProperty()->SetColor(0,0,0);
vtkCamera *aCamera = vtkCamera::New();
aCamera->SetViewUp (0, 0, -1);
aCamera->SetPosition (0, 1, 0);
aCamera->SetFocalPoint (0, 0, 0);
aCamera->ComputeViewPlaneNormal();
// Actors are added to the renderer. An initial camera view is created.
// The Dolly() method moves the camera towards the FocalPoint,thereby //enlarging the
image.
aRenderer->AddActor(outline);
aRenderer->AddActor(skin);
aRenderer->SetActiveCamera(aCamera);
aRenderer->ResetCamera ();
aCamera->Dolly(1.5);
// Set a background color for the renderer and set the size of the render //window
(expressed in pixels).
aRenderer->SetBackground(1,1,1);
renWin->SetSize(500, 500);
// Note that when camera movement occurs (as it does in the Dolly() method), the
clipping planes often need adjusting. Clipping planes
// 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.
aRenderer->ResetCameraClippingRange ();
// Initialize the event loop and then start it.
iren->Initialize();
iren->Start();
// It is important to delete all objects created previously to prevent
// memory leaks. In this case, since the program is on its way to
// exiting, it is not so important. But in applications it is essential.
v16->Delete();
skinExtractor->Delete();
skinMapper->Delete();
skin->Delete();
outlineData->Delete();
mapOutline->Delete();
outline->Delete();
aCamera->Delete();
iren->Delete();
renWin->Delete();
aRenderer->Delete();
writer->Delete();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090330/b07de9fe/attachment.htm>
More information about the vtkusers
mailing list