1 //----------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------
5 #include "MyGridOnImageGenerator.h"
7 //----------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------
10 //----------------------------------------------------------------------------
12 //----------------------------------------------------------------------------
14 MyGridOnImageGenerator::MyGridOnImageGenerator( vtkImageData* nImage, double nScpX, double nScpY, double nScpZ)
22 //----------------------------------------------------------------------------
24 //----------------------------------------------------------------------------
26 MyGridOnImageGenerator::~MyGridOnImageGenerator( )
30 //----------------------------------------------------------------------------
32 //----------------------------------------------------------------------------
35 void MyGridOnImageGenerator::setScpX(double nScpX)
40 void MyGridOnImageGenerator::setScpY(double nScpY)
45 void MyGridOnImageGenerator::setScpZ(double nScpZ)
51 void MyGridOnImageGenerator::setImage(vtkImageData* nImage)
56 vtkImageData* MyGridOnImageGenerator::getGridOnImage( )
61 int sizeX = 0, sizeY = 0, sizeZ = 0;
62 double minMaxValue[2];
63 double minValue = 0, maxValue = 0;
64 int spcVoxelX = 0, spcVoxelY = 0, spcVoxelZ = 0;
66 vtkImageData* gridImage = vtkImageData::New();
67 gridImage->ShallowCopy(image);
70 //Get image spacing, size and mix and max values
71 gridImage->GetSpacing(spc);
72 gridImage->GetDimensions(dims);
76 gridImage->GetScalarRange(minMaxValue);
77 minValue = minMaxValue[0];
78 maxValue = minMaxValue[1];
80 //Grid spacing in voxels
81 spcVoxelX = spcX / spc[0];
82 spcVoxelY = spcY / spc[1];
83 spcVoxelZ = spcZ / spc[2];
85 std::cout << "spcVoxelX:" << spcVoxelX << ", spcVoxelY:" << spcVoxelY << ", spcVoxelZ:" << spcVoxelZ <<std::endl;
86 std::cout << "minValue:" << minValue << ", maxValue:" << maxValue << std::endl;
87 std::cout << "sizeX:" << sizeX << ", sizeY:" << sizeY << ", sizeZ:" << sizeZ <<std::endl;
89 for(int px = 0; px < sizeX; px++)
91 for(int py = 0; py < sizeY; py++)
93 for(int pz = 0; pz < sizeZ; pz++)
95 if(px % spcVoxelX == 0 || py % spcVoxelY == 0 || pz % spcVoxelZ == 0)
98 unsigned char* pointer = (unsigned char*) gridImage->GetScalarPointer(px, py, pz);
99 if( (*pointer - minValue) < (maxValue - *pointer) )