[vtkusers] How to:

Vincenzo Mormino viciomor at tin.it
Thu Sep 26 07:00:24 EDT 2002


Hello for all.
I have a problem :
I must read a "n" number of imaging pgm, in way to recostruct a volume.
So i use the calss vtkPNMReader when i load the images, after i don't
have succes for visualizing. So i write the code wtring from me: In the
first section i build a "n" number of imaging pgm for rappresentig a
cube,the first and the last imaging have the point all ugual to zero. In
the second section there is the codde for load and visualize the imaging
so i will explane the second section for visualize the imaging in 3D,
the class vtkPNMReader return a volume if the imaging sequences is more
that one imaging,but idon't have success when i visualize this. Exactly
i haven't eb error but i don't see anything in the video, only the
background. Thankyou for all.
PS: in this code i assume that you have created 8 imaging 16x16 See
SetDataExtend, if you can explain the parameter of this metod i am
happy.
 
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPNMReader.h"
#include "vtkDataSetMapper.h"
#include "vtkPolyDataMapper.h"
#include "vtkImageViewer.h"
#include "vtkContourFilter.h"
 
int main(int argc, char* argv[])
{
      /***Creazione Immagini pgm****/
      int numimm;
      FILE *pgm;
      printf("Insert the number of imaging that you want to build: ");
      scanf("%d", &numimm);
      int dimx;
      int dimy;
      printf("Insert the dimension x: ");
      scanf("%d", &dimx);
      printf("Insert the dimension y: ");
      scanf("%d", &dimy);
      int i;
      char file[6];
      for (i=0; i<numimm; i++)
      {
            char nomefile[80]="";
            strcpy(nomefile,"immagine.pgm.");
            _itoa(i,file,10);
            strcat(nomefile,file);
            pgm=fopen(nomefile,"w+");
            fprintf(pgm,"P2\n");
            fprintf(pgm,"#Created from Vicio\n");
            fprintf(pgm,"%d %d\n",dimx,dimy);
            fprintf(pgm,"255\n");
            if((i==0) || (i==numimm-1))
            {
                  int contx;
                  int conty;
                  for (conty=1 ;conty<=dimy; conty++)
                  {
                        for(contx=1; contx<=dimx; contx++)
                        {
                             fprintf(pgm,"0 ");
                        }
                        fprintf(pgm,"\n");
                  }
            }
            else 
            {
                  int contx;
                  int conty;
                  for(conty=1; conty<=dimy; conty++)
                  {
                        for(contx=1; contx<=dimx; contx++)
                        {     
                             if ((conty==4 ||conty==5 || conty==6) &&
(contx==4 || contx==5 || contx==6))
                             {
                             fprintf(pgm,"255 ");
                             }
                             else fprintf(pgm,"0 ");
                        }
                        fprintf(pgm,"\n");
                  }
            }
      }
      fclose(pgm);
 
      
 
      vtkRenderer *ren1 = vtkRenderer::New();
      vtkRenderWindow *renWin = vtkRenderWindow::New();
      vtkRenderWindowInteractor *iren =
vtkRenderWindowInteractor::New();
      vtkActor *aVoxelActor = vtkActor::New();
      vtkPNMReader *immagini = vtkPNMReader::New();
      vtkDataSetMapper *aVoxelMapper = vtkDataSetMapper::New();
      vtkPolyDataMapper *grigio = vtkPolyDataMapper::New();
 
 
      immagini->SetDataExtent(0,7,0,7,0,7);
 
immagini->SetFilePrefix("c:\\esempivtk\\immaginiPgm\\immagine.pgm");
      immagini->SetDataMask(0x7fff); 
      
      aVoxelMapper->SetInput(immagini->GetOutput());
      aVoxelActor->SetMapper(aVoxelMapper);
      aVoxelActor->GetProperty()->SetColor(1,0,0);
 
      renWin->AddRenderer(ren1);
      renWin->SetSize(300,150);
      iren->SetRenderWindow(renWin);
 
      ren1->SetBackground(0.1,0.2,0.4);
      ren1->AddActor(aVoxelActor);
      renWin->Render();
      iren->Start();
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20020926/6eddffce/attachment.htm>


More information about the vtkusers mailing list