[vtkusers] Update renderwindow for various events

frency v frencyvarghese at yahoo.com
Thu Apr 9 12:46:18 EDT 2009


Hello everyone
i am working on a dataset(.raw). i am importing the dataset using imageimport function. I am able to visualize the dataset on the renderwindow. after that i try to invoke some key press events. Like if i press "y" half the dataset should become blank and then when i press "m" one fourth of the dataset should become blank. All this should happend on the same window one after the other.  In my program what happens is, If i press "y" then half the dataset goes blank, but when i try to press"m" after i press "y" nothing happens. What i want is on the same renderwindow when i press "y" half the dataset should go blank and then when i press"m" again on the same window the dataset should reduce by one fourth.
Please help me 
Thanks 
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"
#include "vtkDataObject.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();
vtkImageImport *Importer1 = vtkImageImport::New();
     vtkRenderer *aRenderer1 = vtkRenderer::New();
  vtkRenderWindow *renWin1 = vtkRenderWindow::New();
vtkContourFilter *skinExtractor1 = vtkContourFilter::New();
vtkPolyDataNormals *skinNormals1 = vtkPolyDataNormals::New();
 vtkPolyDataMapper *skinMapper1 = vtkPolyDataMapper::New();
 vtkActor *skin1 = vtkActor::New();
vtkCamera *aCamera1 = vtkCamera::New();
vtkRenderWindowInteractor *iren1 = vtkRenderWindowInteractor::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 *iren1= reinterpret_cast<vtkRenderWindowInteractor*>(caller);

      char key = *(iren1->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;

           }
        }
       }
      }
      // char key = *(iren1->GetKeySym());
      if (key=='m')
       {
       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/4)
               p[index]=0;

           }
        }
       }
       }

      if (key=='o')
      {
       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/3)
               p[index]=0;

           }
        }
       }

}
cout << "Deleted the array" << endl;

Importer1->Update();
skinExtractor1->Update();
skinNormals1->Update();
skinMapper1->Update();
skinExtractor1->SetInputConnection(Importer->GetOutputPort());
skin1->SetMapper(skinMapper1);
renWin1->Render();
    }
  if (key=='n') {
      cout << "you chose no" << endl;
  cout << " test value of the array " << (int) p[68000] << 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->SetDataScalarTypeToUnsignedChar();
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 );

  iren->Initialize();

 iren->Start();

vtkMyCallback *callback = vtkMyCallback::New();
  iren1->AddObserver(vtkCommand::CharEvent, callback);

Importer1->SetDataExtent(0, 53, 0, 46, 0,  62);
Importer1->SetWholeExtent(0, 53, 0, 46, 0, 62);
Importer1->SetDataSpacing(1.0,1.0,1.0);
Importer1->SetNumberOfScalarComponents(1);
Importer1->SetDataScalarTypeToUnsignedChar();
Importer1->SetImportVoidPointer(p);

  renWin1->AddRenderer(aRenderer1);

    iren1->SetRenderWindow(renWin1);
    skinExtractor1->SetInputConnection(Importer1->GetOutputPort());
   skinExtractor1->SetValue(0,100);

   skinNormals1->SetInputConnection(skinExtractor1->GetOutputPort());
   skinNormals1->SetFeatureAngle(60);

    skinMapper1->SetInputConnection(skinNormals1->GetOutputPort());
    skinMapper1->ScalarVisibilityOff();

   skin1->SetMapper(skinMapper1);

    aCamera1->SetViewUp (0, 0, -1);
    aCamera1->SetPosition (0, 1, 0);
    aCamera1->SetFocalPoint (0, 0, 0);
    aCamera1->ComputeViewPlaneNormal();

  aRenderer1->AddActor(skin1);
  aRenderer1->SetActiveCamera(aCamera1);
  aRenderer1->ResetCamera ();
  aCamera1->Dolly(1.5);
 
iren =vtkRenderWindowInteractor::New();
 iren->SetRenderWindow(renWin);
 renWin1->Render();
 renWin1->SetSize( 500, 500 );

  iren1->Initialize();
 iren1->Start();

  inputFile.close();
  Importer->Delete();
  skinExtractor->Delete();
  skinMapper->Delete();
  skin->Delete();
  aCamera->Delete();
  iren->Delete();
  renWin->Delete();
  aRenderer->Delete();
  skinExtractor1->Delete();
  skinMapper1->Delete();
  skin1->Delete();
  aCamera1->Delete();
  iren1->Delete();
  renWin1->Delete();
  aRenderer1->Delete();
  Importer1->Delete();
    return 0;
}




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090409/07eeb74f/attachment.htm>


More information about the vtkusers mailing list