[vtkusers] (no subject)
frency v
frencyvarghese at yahoo.com
Wed Apr 8 12:04:05 EDT 2009
Hello
I am a new comer to vtk.
I am working on linux platform.
I have
few questions about vtk data manipulation. i have a 3D dataset (.raw). i
am using imageimport to
import the dataset. i am able to visualize the dataset in the
renderwindow. everything works fine till here. Then, I defined key
"y " in the call back function (renderwindowinteractor) to make
the dataset blank. ie when i press "y" the dataset has been set to zero ie the image in the renderwindow
should go blank. This is not happening.
I need help with customizing the key press events. so that when i press
one of the keyboard keys a particular event should happen (like half or full of
the dataset goes blank).
please help.
thank you
frency varghese
here is my code
#include <iostream>
#include <fstream>
#include <string>
#include "vtkImageImport.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataNormals.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkOutlineFilter.h"
#include "vtkCamera.h"
#include "vtkImageFlip.h"
//#include "vtkInteractorStyle.h"
#include "vtkCommand.h"
#include "vtkInteractorStyleUser.h"
using namespace std;
const int x_max=54;
const int y_max=47;
const int z_max=63;
unsigned char* p= new unsigned char[x_max*y_max*z_max];
vtkImageImport *Importer = vtkImageImport::New();
vtkRenderer *aRenderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
vtkContourFilter *skinExtractor = vtkContourFilter::New();
vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
vtkActor *skin = vtkActor::New();
vtkCamera *aCamera = vtkCamera::New();
class vtkMyCallback : public vtkCommand
{
public:
static vtkMyCallback *New()
{ return new vtkMyCallback;}
void Delete()
{ delete this; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
int x,y,z;
int index;
vtkRenderWindowInteractor *iren= reinterpret_cast<
vtkRenderWindowInteractor*>( caller);
char key = *(iren->GetKeySym());
if (key=='y')
{
for(z=0; z<z_max; z++)
{
for(y=0; y<y_max; y++)
{
for(x=0; x<x_max; x++)
{
index=(z*x_max*y_max+y*x_max+ x);
if (z<z_max)
p[index]=0;
}
}
}
cout << "Deleted the array" << endl;
Importer->Update();
renWin->Render();
}
if (key=='n') cout << "you chose no" << endl;
}
};
int main()
{
int x;
int y;
int z;
unsigned char* p1= new unsigned char[x_max*y_max*z_max];
ifstream inputFile;
inputFile.open("/home/owner/ Desktop/iteration/15s.raw", ios::binary);
for(z=0; z<z_max; z++)
{
for(y=0; y<y_max; y++)
{
for(x=0; x<x_max; x++)
{
inputFile.read((char*) &(p[z*x_max*y_max+y*x_max+x]), 1);
inputFile.read((char*) &(p1[z*x_max*y_max+y*x_max+x]) ,1);
}
}
}
renWin->AddRenderer(aRenderer) ;
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor:: New();
iren->SetRenderWindow(renWin);
Importer->SetDataExtent(0, 53, 0, 46, 0, 62);
Importer->SetWholeExtent(0, 53, 0, 46, 0, 62);
Importer->SetDataSpacing(1.0, 1.0,1.0);
Importer-> SetNumberOfScalarComponents(1) ;
Importer-> SetDataScalarTypeToUnsignedCha r();
Importer-> SetImportVoidPointer(p);
skinExtractor-> SetInputConnection(Importer-> GetOutputPort());
skinExtractor->SetValue(0,100) ;
skinNormals-> SetInputConnection( skinExtractor->GetOutputPort() );
skinNormals->SetFeatureAngle( 60);
skinMapper-> SetInputConnection( skinNormals->GetOutputPort());
skinMapper-> ScalarVisibilityOff();
skin->SetMapper(skinMapper);
aCamera->SetViewUp (0, 0, -1);
aCamera->SetPosition (0, 1, 0);
aCamera->SetFocalPoint (0, 0, 0);
aCamera-> ComputeViewPlaneNormal();
aRenderer->AddActor(skin);
aRenderer->SetActiveCamera( aCamera);
aRenderer->ResetCamera ();
aCamera->Dolly(1.5);
iren =vtkRenderWindowInteractor:: New();
iren->SetRenderWindow(renWin) ;
renWin->Render();
renWin->SetSize( 500, 500 );
vtkMyCallback *callback = vtkMyCallback::New();
iren->AddObserver(vtkCommand:: KeyPressEvent, callback);
iren->start();
iren->Initialize();
inputFile.close();
Importer->Delete();
skinExtractor->Delete();
skinMapper->Delete();
skin->Delete();
aCamera->Delete();
iren->Delete();
renWin->Delete();
aRenderer->Delete();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090408/16beabad/attachment.htm>
More information about the vtkusers
mailing list