[vtkusers] beginner question - how to display different images sequentially?

Akiko Campbell adcampbell at shaw.ca
Sat Apr 2 21:34:30 EST 2005


Hello again Paul,

I managed to get your sample to work in C++.  Thank you very much for
your help! I'm posting my C++ sample here in case anyone as newbie as me
is interested:

void DisplayMeshes()
{
 char strCtr[20];
 char fileExtension[20] = ".vtk";
 vtkUnstructuredGridReader* reader = vtkUnstructuredGridReader::New();
 vtkRenderWindow* renWin = vtkRenderWindow::New();
 renWin->SetSize(1000,1200);
    
 for(unsigned int ctr=1; ctr < 10; ctr++){
  char vtkFileName[20] = "";
  itoa (ctr, strCtr, 10);
  strcpy(vtkFileName, strcat(strCtr, fileExtension)); 

  reader->SetFileName( vtkFileName );
  reader->Update();
	 
  vtkUnstructuredGrid* deformedGrid = reader->GetOutput();
  vtkDataSetMapper* deformedMesh = vtkDataSetMapper::New();
  deformedMesh->SetInput( deformedGrid );
  vtkActor* deformedMeshActor = vtkActor::New();
  deformedMeshActor->SetMapper( deformedMesh );
  deformedMeshActor->GetProperty()->SetColor(.4,.2,.1);
  vtkExtractEdges* deformedExtract = vtkExtractEdges::New();
  deformedExtract->SetInput( deformedGrid );
  vtkTubeFilter* deformedTubes = vtkTubeFilter::New();
  deformedTubes->SetInput( deformedExtract->GetOutput() );
  deformedTubes->SetRadius(0.01);
  deformedTubes->SetNumberOfSides(6);
  vtkDataSetMapper* deformedMapEdges = vtkDataSetMapper::New();
  deformedMapEdges->SetInput( deformedTubes->GetOutput() );
  vtkActor* deformedEdgeActor = vtkActor::New();
  deformedEdgeActor->SetMapper( deformedMapEdges );
  deformedEdgeActor->GetProperty()->SetColor(1,0,1);

  vtkRenderer* ren = vtkRenderer::New();
  ren->SetBackground(1,1,1); 
  renWin->AddRenderer(ren);
  ren->AddActor(deformedMeshActor);
  ren->AddActor(deformedEdgeActor);
  renWin->Render();
     
  deformedMesh->Delete();
  deformedMeshActor->Delete();
  deformedEdgeActor->Delete();
  ren->Delete();
  }

  renWin->Delete();
}

-----Original Message-----
From: Paul Cochrane [mailto:cochrane at esscc.uq.edu.au] 
Sent: Thursday, March 31, 2005 5:06 PM
To: Akiko Campbell
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] beginner question - how to display different
images sequentially?

Akiko,

I'm a bit of vtk newbie, but hopefully I can be of some help

I'd try doing something like in the following code (python; untested, so
may
not work; should map fairly easily to your favourite language)

import vtk

for i in range(11):
    # generate the filename to load
    fname = "%d.vtk" % i
    
    # set up the reader
    reader = vtk.vtkPolyDataReader()
    reader.SetFileName(fname)
    reader.Update()

    # read the data
    polydata = reader.GetOutput()
    
    # map the data to something that can be viewed
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInput(polydata)

    # set up the actor for the data mapper
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    # set up the renderer
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)

    # add the actor to the renderer
    ren.AddActor(actor)

    # render!
    renWin.Render()


That would be the code I would write initially.  Hope it is of some help
to
you.

Paul
    
-- 
Paul Cochrane
Computational Scientist/Software Developer
Earth Systems Science Computational Centre
Rm 703, SMI Building
University of Queensland
Brisbane
Queensland 4072
Australia

E: cochrane at esscc.uq.edu.au
P: +61 7 3346 4109
F: +61 7 3365 7347

-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.0 - Release Date: 2005-03-31
 

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.1 - Release Date: 2005-04-01
 




More information about the vtkusers mailing list