[vtkusers] How to load matrix into vtkImageData

Mehdi Esteghamatian mestegha at uwo.ca
Thu Jul 23 09:54:43 EDT 2009


It should be sth like this. 


Mehdi

/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: ImportExport.cxx,v $
  Language:  C++
  Date:      $Date: 2002/08/08 13:54:44 $
  Version:   $Revision: 1.8 $

  Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkImageData.h"
#include "vtkImageViewer.h"


int ImportExport( int argc, char *argv[] )
{
  int x, y;
  vtkImageData *image;
  
  image = vtkImageData::New();
  image->SetDimensions(256, 256, 1);
  image->SetScalarTypeToFloat();
  image->AllocateScalars();

  float *ptr = static_cast<float*>(image->GetScalarPointer());

  for (y = 0; y < 256; ++y)
    {
    for (x = 0; x < 256; ++x)
      {
      *ptr++ = 10.0 * sin(0.1 * x) * sin(0.1 * y);
      }
    }




 vtkImageViewer *viewer = vtkImageViewer::New();
 viewer->SetInput(image);
 viewer->SetColorWindow(20.0);
 viewer->SetColorLevel(0.0);

 viewer->Render();
  
 Sleep(5000);
 image->Delete();
 viewer->Delete();
 source->Delete();

 return 0;
}






----- Original Message -----
From: Lic. José M. Rodriguez Bacallao <jmrbcu at gmail.com>
Date: Wednesday, July 22, 2009 1:01 pm
Subject: Re: [vtkusers] How to load matrix into vtkImageData
To: Mehdi Esteghamatian <mestegha at uwo.ca>

> no one?
> 
> On 7/21/09, Mehdi Esteghamatian <mestegha at uwo.ca> wrote:
> > Hi All,
> >
> > I wonder how I can get a matrix representing an image uploaded 
> into a
> > vtkImageData. I ran through all its members but could not find 
> a method
> > helping me load a matrix into vtkImageData.
> >
> > Thanks,
> >
> > Mehdi
> >
> >
> 
> 
> -- 
> Lic. José M. Rodriguez Bacallao
> Centro de Biofisica Medica
> -----------------------------------------------------------------
> Todos somos muy ignorantes, lo que ocurre es que no todos 
> ignoramos lo mismo.
> 
> Recuerda: El arca de Noe fue construida por aficionados, el titanic
> por profesionales
> -----------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090723/d500d136/attachment.htm>


More information about the vtkusers mailing list