/** * Progam made by Olivier Bernard, associate professor * at Institut National des Sciences Appliquees (INSA) Lyon, * CREATIS-LRMN Laboratory, * 69621 Villeurbanne, France, * 31th of march 2011 */ #ifndef __vtkOptimizedImageData_h__ #define __vtkOptimizedImageData_h__ #include #include #include using namespace std; template class VTK_EXPORT vtkOptimizedImageData : public vtkImageData { private: T* data; int dimX; int dimY; int dimZ; protected: vtkOptimizedImageData() : data(NULL) {} ~vtkOptimizedImageData() {} public: static vtkOptimizedImageData *New() { vtkObject* ret = vtkObjectFactory::CreateInstance("vtkOptimizedImageData"); if(ret) { return (vtkOptimizedImageData*)ret; } // If the factory was unable to create the object, then create it here. return (new vtkOptimizedImageData); } vtkOptimizedImageData& operator=(vtkImageData &m) { this->DeepCopy(&m); return *this; } T& operator()(int x, int y, int z) { if ( !data ) { data = static_cast(this->PointData->GetScalars()->GetVoidPointer(0)); dimX = this->GetDimensions()[0]; dimY = this->GetDimensions()[1]; dimZ = this->GetDimensions()[2]; } return data[x+y*dimX+z*dimX*dimY]; // if ( (x>=0 && x=0 && y=0 && z(this->PointData->GetScalars()->GetVoidPointer(0)); dimX = this->GetDimensions()[0]; dimY = this->GetDimensions()[1]; dimZ = this->GetDimensions()[2]; } int x0,y0,z0; x0=(int) x; y0=(int) y; z0=(int) z; // cout << x << " " << y << " " << z << " " << endl; // cout << x0 << " " << y0 << " " << z0 << " " << endl; int x1,y1,z1; x1=x0+1; y1=y0+1; z1=z0+1; // cout << x1 << " " << y1 << " " << z1 << " " << endl; double xd,yd,zd; xd=x-x0; yd=y-y0; zd=z-z0; // cout << xd << " " << yd << " " << zd << " " << endl; double xdi=1.0-xd; double ydi=1.0-yd; double zdi=1.0-zd; double c00, c10, c01, c11; c00 = data[x0+y0*dimX+z0*dimX*dimY]*xdi+data[x1+y0*dimX+z0*dimX*dimY]*xd; c10 = data[x0+y1*dimX+z0*dimX*dimY]*xdi+data[x1+y1*dimX+z0*dimX*dimY]*xd; c01 = data[x0+y0*dimX+z1*dimX*dimY]*xdi+data[x1+y0*dimX+z1*dimX*dimY]*xd; c11 = data[x0+y1*dimX+z1*dimX*dimY]*xdi+data[x1+y1*dimX+z1*dimX*dimY]*xd; double c0,c1; c0=c00*ydi+c10*yd; c1=c01*ydi+c11*yd; return c0*zdi+c1*zd; } T& operator()(int x, int y) { if ( !data ) { data = static_cast(this->PointData->GetScalars()->GetVoidPointer(0)); dimX = this->GetDimensions()[0]; dimY = this->GetDimensions()[1]; dimZ = 1; } if ( (x>=0 && x=0 && y(this->PointData->GetScalars()->GetVoidPointer(0)); dimX = this->GetDimensions()[0]; dimY = this->GetDimensions()[1]; dimZ = this->GetDimensions()[2]; } if (k>=0 && k