[vtkusers] how to update after manipulating data using interactor

frency v frencyvarghese at yahoo.com
Mon Apr 6 15:05:38 EDT 2009


Hello everyone
I am working on a set of images. I am using vtkimageimport to  to read an array. everything works well. but when i use interactor to make changes in the image nothing happens. I dont know if it is getting updated or there is some mistake in my code.
What i would like to do is when key "y" is pressed, the value half the array should be set to zero. which is not happening.
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 "vtkCamera.h"
#include "vtkImageFlip.h"
#include "vtkCommand.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];


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/2)
               p[index]=0;
           }
        }
       }

      }
      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);
   
          }

        }
     }
     vtkRenderer *aRenderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(aRenderer);
    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

vtkImageImport *Importer = vtkImageImport::New();
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->SetDataScalarTypeToUnsignedChar();
Importer->SetImportVoidPointer(p);

vtkContourFilter *skinExtractor = vtkContourFilter::New();
    skinExtractor->SetInputConnection(Importer->GetOutputPort());
   skinExtractor->SetValue(0,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);
//skin->Update();

 vtkCamera *aCamera = vtkCamera::New();
    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);
 //renWin1->SetParentId(m_hWnd);
 iren =vtkRenderWindowInteractor::New();
 iren->SetRenderWindow(renWin);
 renWin->Render();
 renWin->SetSize( 500, 500 );
//renWin->Update();

 vtkMyCallback *callback = vtkMyCallback::New();
  iren->AddObserver(vtkCommand::KeyPressEvent, callback);
  //iren->Update();

  iren->Initialize();
  iren->Start();
 // Importing the Buffer

   //char dummy;
//mporter->Update();

    inputFile.close();
Importer->Delete();
  skinExtractor->Delete();
  skinMapper->Delete();
  skin->Delete();
//outlineData->Delete();
//  mapOutline->Delete();
  //outline->Delete();
  aCamera->Delete();
  iren->Delete();
  renWin->Delete();
  aRenderer->Delete();
  // writer->Delete();
   // cin>>dummy;
    return 0;
}






      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090406/7c0b04c9/attachment.htm>


More information about the vtkusers mailing list