[vtkusers] vtkImageData - GetSpacing() : HELP

Yi-Yu Chou chouyiyu at hotmail.com
Sat Jan 17 08:03:44 EST 2004


Dear vtk users,

I am trying to build my own vtk class, which has the ability to access the 
vtkImageData.
Below are my simple test codes, and I tried to get the spaing and 
dimensions of the input image.
However, when I checked the return values, the dimensions are correct but 
the spacings are wrong.
Could anyone help me find out the problem ? 
Thanks in advance !!

YY

// vtkLocalExample.h
#ifndef __vtkLocalExample_h
#define __vtkLocalExample_h

#include "vtkLocalConfigure.h" // Include configuration header.
#include "vtkObject.h"
#include "vtkImageData.h"

class VTK_vtkLocal_EXPORT vtkLocalExample : public vtkObject
{
public:
  static vtkLocalExample* New();
  vtkTypeMacro(vtkLocalExample, vtkObject);
  void SetOriImg(vtkImageData *img);
  double GetSpcX();
  double GetSpcY();
  double GetSpcZ();
  int GetDimX();
  int GetDimY();
  int GetDimZ();
 
protected:
  vtkLocalExample();
  ~vtkLocalExample();
  float spc_x;
  float spc_y;
  float spc_z;
  int dim_x;
  int dim_y;
  int dim_z;
};

#endif

// vtkLocalExample.cxx
#include "vtkLocalExample.h"
#include "vtkObjectFactory.h"
#include "vtkDataSet.h"
#include "vtkStructuredData.h"
#include "vtkPointData.h"
#include "vtkDataArray.h"
#include <stdio.h>
#include <sys/stat.h>
#include <string.h>

vtkStandardNewMacro(vtkLocalExample);

//----------------------------------------------------------------------------

vtkLocalExample::vtkLocalExample()
{
}

//----------------------------------------------------------------------------

vtkLocalExample::~vtkLocalExample()
{
}

//----------------------------------------------------------------------------


double vtkLocalExample::GetSpcX()
{
  	return this->spc_x;
}

double vtkLocalExample::GetSpcY()
{
        return this->spc_y;
}

double vtkLocalExample::GetSpcZ()
{
        return this->spc_z;
}

int vtkLocalExample::GetDimX()
{
	return this->dim_x;
}

int vtkLocalExample::GetDimY()
{
	return this->dim_y;
}

int vtkLocalExample::GetDimZ()
{
	return this->dim_z;
}

void vtkLocalExample::SetOriImg(vtkImageData *img)
{
  int dimtemp[3];
  int *dim;
  dim=dimtemp;
  dim = img->GetDimensions();
  this->dim_x = dim[0];
  this->dim_y = dim[1];
  this->dim_z = dim[2];

  float spctemp[3];
  float *spc;
  spc=spctemp;
  img->GetSpacing(spc);
  printf("%f %f %f \n",spc[0], spc[1], spc[2]);
  this->spc_x = spc[0];
  this->spc_y = spc[1];
  this->spc_z = spc[2];
}

//test.py
.........
A = vtkLocalExample()
A.SetOriImg(ori_img)  // ori_image is vtkImageData
.........

_________________________________________________________________
想戀愛?交朋友?MSN 線上交友:由 Match.com 提供,全世界最受歡迎的線上交友服
務 http://match.msn.com.tw 




More information about the vtkusers mailing list