/* for documentation see tensorfunctions.h Author: Raimundo Sierra www.rsierra.com Copyright: Copyright (c) 2000 Raimundo Sierra. All rights reserved. LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "tensorfunctions.h" void creatOuterProdDerivative(float * inarray, tensorfield & correlationMatrix, const int dimx=256, const int dimy=256, const int dimz=1, const int neighbourhood=0) { int volume = dimx*dimy*dimz; float * dxT1 = new float[volume]; float * dyT1 = new float[volume]; float * dzT1 = new float[volume]; float * dxxT1 = new float[volume]; float * dyxT1 = new float[volume]; float * dyyT1 = new float[volume]; float * dzxT1 = new float[volume]; float * dzyT1 = new float[volume]; float * dzzT1 = new float[volume]; deriveFloatArray(inarray, dxT1, dyT1, dzT1, dimx, dimy, dimz); for(int i=0; i1){ /* GaussSmoothFloatArray( dxxT1, dimx, dimy, dimz, neighbourhood); GaussSmoothFloatArray( dyxT1, dimx, dimy, dimz, neighbourhood); GaussSmoothFloatArray( dyyT1, dimx, dimy, dimz, neighbourhood); GaussSmoothFloatArray( dzxT1, dimx, dimy, dimz, neighbourhood); GaussSmoothFloatArray( dzyT1, dimx, dimy, dimz, neighbourhood); GaussSmoothFloatArray( dzzT1, dimx, dimy, dimz, neighbourhood); */ MeanFloatArray( dxxT1, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dyxT1, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dyyT1, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dzxT1, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dzyT1, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dzzT1, dimx, dimy, dimz, neighbourhood); } correlationMatrix.merge(dxxT1, dyyT1, dzzT1, dyxT1, dzxT1, dzyT1); delete[] dxT1; delete[] dyT1; delete[] dzT1; delete[] dxxT1; delete[] dyxT1; delete[] dyyT1; delete[] dzxT1; delete[] dzyT1; delete[] dzzT1; } void findPointsInFloatArray(float * inarray, float * pointarray, const int dimx=256, const int dimy=256, const int dimz=1, const int neighbourhood=3, const float sigmathresh=0.01, const int pointmethod=0) { int volume = dimx*dimy*dimz; float * dxT1 = new float[volume]; float * dyT1 = new float[volume]; float * dzT1 = new float[volume]; float * dxxT1 = new float[volume]; float * dyxT1 = new float[volume]; float * dyyT1 = new float[volume]; float * dzxT1 = new float[volume]; float * dzyT1 = new float[volume]; float * dzzT1 = new float[volume]; for(int i=0; i> a; //return; //for(int i=0; i> a; */ //delete &correlationMatrix; //delete &disp; //delete[] offset; //delete[] window; delete[] dxT1; delete[] dyT1; delete[] dzT1; delete[] dxxT1; delete[] dyxT1; delete[] dyyT1; delete[] dzxT1; delete[] dzyT1; delete[] dzzT1; } void findPointsInTensorfield(tensorfield * t_field_ptr, float * pointarray, const int neighbourhood=3, const float sigmathresh=0.01, const int pointmethod=0, const int searchwindowsize=7, const int movingwindowsize=7, const int matchmethod=0, const int matchwindowweighting=0) { int x=0, y=0, z=0; t_field_ptr->getDimension(x, y, z); int volume = x*y*z; float * pointarray1 = new float[volume]; float * pointarray2 = new float[volume]; float * pointarray3 = new float[volume]; float * pointarray4 = new float[volume]; float * pointarray5 = new float[volume]; float * pointarray6 = new float[volume]; for(int i=0; iseparate(Txx, Tyy, Tzz, Txy, Txz, Tyz); findPointsInFloatArray(Txx, pointarray1, x, y, z, neighbourhood, sigmathresh, pointmethod); findPointsInFloatArray(Tyy, pointarray2, x, y, z, neighbourhood, sigmathresh, pointmethod); findPointsInFloatArray(Tzz, pointarray3, x, y, z, neighbourhood, sigmathresh, pointmethod); findPointsInFloatArray(Txy, pointarray4, x, y, z, neighbourhood, sigmathresh, pointmethod); findPointsInFloatArray(Txz, pointarray5, x, y, z, neighbourhood, sigmathresh, pointmethod); findPointsInFloatArray(Tyz, pointarray6, x, y, z, neighbourhood, sigmathresh, pointmethod); display.greyarray(pointarray1, x, y, z); display.greyarray(pointarray2, x, y, z); display.greyarray(pointarray3, x, y, z); display.greyarray(pointarray4, x, y, z); display.greyarray(pointarray5, x, y, z); display.greyarray(pointarray6, x, y, z); for(int i=0; i> stop; delete[] pointarray1; delete[] pointarray2; delete[] pointarray3; delete[] pointarray4; delete[] pointarray5; delete[] pointarray6; delete[] Txx; delete[] Tyy; delete[] Tzz; delete[] Txy; delete[] Txz; delete[] Tzz; } void findPointsInTensorfield2(tensorfield * t_field_ptr, float * pointarray, const int neighbourhood=3, const float sigmathresh=0.01, const int pointmethod=0, const int searchwindowsize=7, const int movingwindowsize=7, const int matchmethod=0, const int matchwindowweighting=0) { int dimx=0, dimy=0, dimz=0; t_field_ptr->getDimension(dimx, dimy, dimz); int volume = dimx*dimy*dimz; float * Txx = new float[volume]; float * Txy = new float[volume]; float * Txz = new float[volume]; float * Tyy = new float[volume]; float * Tyz = new float[volume]; float * Tzz = new float[volume]; float * dxTxx = new float[volume]; float * dyTxx = new float[volume]; float * dzTxx = new float[volume]; float * dxTyy = new float[volume]; float * dyTyy = new float[volume]; float * dzTyy = new float[volume]; float * dxTzz = new float[volume]; float * dyTzz = new float[volume]; float * dzTzz = new float[volume]; float * dxTxy = new float[volume]; float * dyTxy = new float[volume]; float * dzTxy = new float[volume]; float * dxTxz = new float[volume]; float * dyTxz = new float[volume]; float * dzTxz = new float[volume]; float * dxTyz = new float[volume]; float * dyTyz = new float[volume]; float * dzTyz = new float[volume]; float * dxxTxx = new float[volume]; float * dxyTxx = new float[volume]; float * dxzTxx = new float[volume]; float * dxxTyy = new float[volume]; float * dxyTyy = new float[volume]; float * dxzTyy = new float[volume]; float * dxxTzz = new float[volume]; float * dxyTzz = new float[volume]; float * dxzTzz = new float[volume]; float * dxxTxy = new float[volume]; float * dxyTxy = new float[volume]; float * dxzTxy = new float[volume]; float * dxxTxz = new float[volume]; float * dxyTxz = new float[volume]; float * dxzTxz = new float[volume]; float * dxxTyz = new float[volume]; float * dxyTyz = new float[volume]; float * dxzTyz = new float[volume]; float * dyyTxx = new float[volume]; float * dyzTxx = new float[volume]; float * dzzTxx = new float[volume]; float * dyyTyy = new float[volume]; float * dyzTyy = new float[volume]; float * dzzTyy = new float[volume]; float * dyyTzz = new float[volume]; float * dyzTzz = new float[volume]; float * dzzTzz = new float[volume]; float * dyyTxy = new float[volume]; float * dyzTxy = new float[volume]; float * dzzTxy = new float[volume]; float * dyyTxz = new float[volume]; float * dyzTxz = new float[volume]; float * dzzTxz = new float[volume]; float * dyyTyz = new float[volume]; float * dyzTyz = new float[volume]; float * dzzTyz = new float[volume]; t_field_ptr->separate(Txx, Tyy, Tzz, Txy, Txz, Tyz); deriveFloatArray(Txx, dxTxx, dyTxx, dzTxx, dimx, dimy, dimz); deriveFloatArray(Tyy, dxTyy, dyTyy, dzTyy, dimx, dimy, dimz); deriveFloatArray(Tzz, dxTzz, dyTzz, dzTzz, dimx, dimy, dimz); deriveFloatArray(Txy, dxTxy, dyTxy, dzTxy, dimx, dimy, dimz); deriveFloatArray(Txz, dxTxz, dyTxz, dzTxz, dimx, dimy, dimz); deriveFloatArray(Tyz, dxTyz, dyTyz, dzTyz, dimx, dimy, dimz); outerProduct(dxTxx, dyTxx, dzTxx, dxxTxx, dyyTxx, dzzTxx, dxyTxx, dxzTxx, dyzTxx, dimx, dimy, dimz); outerProduct(dxTyy, dyTyy, dzTyy, dxxTyy, dyyTyy, dzzTyy, dxyTyy, dxzTyy, dyzTyy, dimx, dimy, dimz); outerProduct(dxTzz, dyTzz, dzTzz, dxxTzz, dyyTzz, dzzTzz, dxyTzz, dxzTzz, dyzTzz, dimx, dimy, dimz); outerProduct(dxTxy, dyTxy, dzTxy, dxxTxy, dyyTxy, dzzTxy, dxyTxy, dxzTxy, dyzTxy, dimx, dimy, dimz); outerProduct(dxTxz, dyTxz, dzTxz, dxxTxz, dyyTxz, dzzTxz, dxyTxz, dxzTxz, dyzTxz, dimx, dimy, dimz); outerProduct(dxTyz, dyTyz, dzTyz, dxxTyz, dyyTyz, dzzTyz, dxyTyz, dxzTyz, dyzTyz, dimx, dimy, dimz); for(int i=0; i1){ MeanFloatArray( dxTxx, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dxTyy, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dxTzz, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dxTxy, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dxTxz, dimx, dimy, dimz, neighbourhood); MeanFloatArray( dxTyz, dimx, dimy, dimz, neighbourhood); } delete[] Txx ; delete[] Txy ; delete[] Txz ; delete[] Tyy ; delete[] Tyz ; delete[] Tzz ; delete[] dxxTxx ; delete[] dxyTxx ; delete[] dxzTxx ; delete[] dxxTyy ; delete[] dxyTyy ; delete[] dxzTyy ; delete[] dxxTzz ; delete[] dxyTzz ; delete[] dxzTzz ; delete[] dxxTxy ; delete[] dxyTxy ; delete[] dxzTxy ; delete[] dxxTxz ; delete[] dxyTxz ; delete[] dxzTxz ; delete[] dxxTyz ; delete[] dxyTyz ; delete[] dxzTyz ; delete[] dyyTxx ; delete[] dyzTxx ; delete[] dzzTxx ; delete[] dyyTyy ; delete[] dyzTyy ; delete[] dzzTyy ; delete[] dyyTzz ; delete[] dyzTzz ; delete[] dzzTzz ; delete[] dyyTxy ; delete[] dyzTxy ; delete[] dzzTxy ; delete[] dyyTxz ; delete[] dyzTxz ; delete[] dzzTxz ; delete[] dyyTyz ; delete[] dyzTyz ; delete[] dzzTyz ; tensorfield correlationMatrix(dimx, dimy, dimz); correlationMatrix.merge(dxTxx, dxTyy, dxTzz, dxTxy, dxTxz, dxTyz); correlationMatrix.roundnessCF(pointarray, sigmathresh); delete[] dxTxx ; delete[] dyTxx ; delete[] dzTxx ; delete[] dxTyy ; delete[] dyTyy ; delete[] dzTyy ; delete[] dxTzz ; delete[] dyTzz ; delete[] dzTzz ; delete[] dxTxy ; delete[] dyTxy ; delete[] dzTxy ; delete[] dxTxz ; delete[] dyTxz ; delete[] dzTxz ; delete[] dxTyz ; delete[] dyTyz ; delete[] dzTyz ; } void displaceTensorField(tensorfield * t_field_input_ptr, tensorfield * t_field_out_ptr, float * dx, float * dy, float * dz) { cout << "Displacing tensorfield\t\t\t\t"<getDimension(dimx, dimy, dimz); t_field_input_ptr->getDelta(deltax, deltay, deltaz); // for now: set deltas to 1 deltax=1.0; deltay=1.0; deltaz=1.0; // int volume = dimx*dimy*dimz; float * Txx = new float[volume]; float * Txy = new float[volume]; float * Txz = new float[volume]; float * Tyy = new float[volume]; float * Tyz = new float[volume]; float * Tzz = new float[volume]; float * warpedTxx = new float[volume]; float * warpedTxy = new float[volume]; float * warpedTxz = new float[volume]; float * warpedTyy = new float[volume]; float * warpedTyz = new float[volume]; float * warpedTzz = new float[volume]; t_field_input_ptr->separate(Txx, Tyy, Tzz, Txy, Txz, Tyz); displaceFloatArray(Txx, warpedTxx, dx, dy, dz, dimx, dimy, dimz, deltax, deltay, deltaz); displaceFloatArray(Txy, warpedTxy, dx, dy, dz, dimx, dimy, dimz, deltax, deltay, deltaz); displaceFloatArray(Txz, warpedTxz, dx, dy, dz, dimx, dimy, dimz, deltax, deltay, deltaz); displaceFloatArray(Tyy, warpedTyy, dx, dy, dz, dimx, dimy, dimz, deltax, deltay, deltaz); displaceFloatArray(Tyz, warpedTyz, dx, dy, dz, dimx, dimy, dimz, deltax, deltay, deltaz); displaceFloatArray(Tzz, warpedTzz, dx, dy, dz, dimx, dimy, dimz, deltax, deltay, deltaz); t_field_out_ptr->merge(warpedTxx, warpedTyy, warpedTzz, warpedTxy, warpedTxz, warpedTyz); delete[] Txx; delete[] Txy; delete[] Txz; delete[] Tyy; delete[] Tyz; delete[] Tzz; delete[] warpedTxx; delete[] warpedTxy; delete[] warpedTxz; delete[] warpedTyy; delete[] warpedTyz; delete[] warpedTzz; cout << "done\n"<getDimension(dimx, dimy, dimz); t_field_out_ptr->getDelta(deltax, deltay, deltaz); int volume = dimx*dimy*dimz; float * dxx = new float[volume]; float * dyx = new float[volume]; float * dzx = new float[volume]; float * dxy = new float[volume]; float * dyy = new float[volume]; float * dzy = new float[volume]; float * dxz = new float[volume]; float * dyz = new float[volume]; float * dzz = new float[volume]; invertValues(dx, volume); invertValues(dy, volume); invertValues(dz, volume); tensorfield warptensor(dimx, dimy, dimz); deriveFloatArray(dx, dxx, dxy, dxz, dimx, dimy, dimz); // how to treat the deltas? deriveFloatArray(dy, dyx, dyy, dyz, dimx, dimy, dimz); deriveFloatArray(dz, dzx, dzy, dzz, dimx, dimy, dimz); for(int i=0; imerge(resultxx, resultyy, resultzz, resultxy, resultxz, resultyz); delete[] Axx; delete[] Ayx; delete[] Azx; delete[] Axy; delete[] Ayy; delete[] Azy; delete[] Axz; delete[] Ayz; delete[] Azz; } else {*/ warptensor.merge(dxx, dxy, dxz, dyx, dyy, dyz, dzx, dzy, dzz); //float det = 0; double scale = 1; double tmpscale = 1; tensor orig, result, warp, transpose; tensor A, AT, U, V, VT; tensor test, temp; float r1, r2, r3; for(int k=0; kget(i+j*dimx + ktmp)); test = orig; if(!orig.isZero()){ warp = (*warptensor.get(i+j*dimx + ktmp)); warp.trans(transpose); //cout << "Determinants: warp.det "<1.01 || A.det()<0.99) cout <<"A.det is larger than 1.01 or smaller than 0.99!\n";/* if(orig.det()!=0 && (fabs(result.det()*0.99)>fabs(orig.det()) || fabs(result.det()*1.01)=fabs(orig.det()) || fabs(result.det()*1.01)<=fabs(orig.det())){ cout << "Scale is: "<set(result, i, j, k); //cout << "---------------\n"; } } } } //} cout << "\t\t\t\t\t\tdone\n"<> a; // block so images can be displayed } void makeSynthField3D( eigenfield & e_field, tensorfield &t_field) { float vec1a[3] = {1, 0, 0}; float vec2a[3] = {0, 1, 0}; float vec3a[3] = {0, 0, 1}; float vec1b[3] = {0, 1, 0}; float vec2b[3] = {1, 0, 0}; float vec3b[3] = {0, 0, -1}; float vec1c[3] = {0, 0, 1}; float vec2c[3] = {1, 0, 0}; float vec3c[3] = {0, 1, 0}; eigen eigen1(1000, 300, 100, vec1a, vec2a, vec3a); eigen eigen2(1000, 300, 200, vec1b, vec2b, vec3b); eigen eigen3(1000, 500, 50, vec1c, vec2c, vec3c); int z1 = 2; int z2 = 6; for(int i=5; i<15; i++){ for(int j=5; j<15; j++){ e_field.set(eigen1, i, j, z1); } } for(int i=6; i<14; i++){ e_field.set(eigen2, 5, i, z1); e_field.set(eigen2, 14, i, z1); e_field.set(eigen2, 5, i, z2); e_field.set(eigen2, 14, i, z2); } for(int i=7; i<13; i++){ e_field.set(eigen2, 6, i, z1); e_field.set(eigen2, 13, i, z1); e_field.set(eigen2, 6, i, z2); e_field.set(eigen2, 13, i, z2); } for(int i=8; i<12; i++){ e_field.set(eigen2, 7, i, z1); e_field.set(eigen2, 12, i, z1); e_field.set(eigen2, 7, i, z2); e_field.set(eigen2, 12, i, z2); } for(int i=9; i<11; i++){ e_field.set(eigen2, 8, i, z1); e_field.set(eigen2, 11, i, z1); e_field.set(eigen2, 8, i, z2); e_field.set(eigen2, 11, i, z2); } for(int k=z1+1; k