Skip to content

Commit

Permalink
Merge branch 'cmaking' of https://github.com/dkazanc/Tomophantom into…
Browse files Browse the repository at this point in the history
… cmaking

Conflicts:
	Wrappers/Python/setup.py.in
  • Loading branch information
paskino committed Oct 4, 2018
2 parents 94ba6bd + 9c136ae commit 4cf19d6
Show file tree
Hide file tree
Showing 58 changed files with 394 additions and 1,237 deletions.
8 changes: 4 additions & 4 deletions Core/TomoP3DModel_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ float TomoP3DObject_core(float *A, long N1, long N2, long N3, long Z1, long Z2,
psi2 = psi_gr2*((float)M_PI / 180.0f);
psi3 = psi_gr3*((float)M_PI / 180.0f);

float bs[3][3] = {
{ 0.0f,0.0f,0.0f },
{ 0.0f,0.0f,0.0f },
{ 0.0f,0.0f,0.0f } };
float bs[3][3] = {
{0.0f,0.0f,0.0f},
{0.0f,0.0f,0.0f},
{0.0f,0.0f,0.0f} };

float xh[3] = { 0.0f, 0.0f, 0.0f };
float xh3[3] = { 0.0f, 0.0f, 0.0f };
Expand Down
2 changes: 0 additions & 2 deletions Core/TomoP3DModel_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ limitations under the License.
#include "CCPiDefines.h"
#include "utils.h"


//CCPI_EXPORT float TomoP3DModel_core(float *A, int ModelSelected, int N, char *ModelParametersFilename);
CCPI_EXPORT float TomoP3DModel_core(float *A, int ModelSelected, long N1, long N2, long N3, long Z1, long Z2, char *ModelParametersFilename);
CCPI_EXPORT float TomoP3DObject_core(float *A, long N1, long N2, long N3, long Z1, long Z2, char *Object,
float C0, /* intensity */
Expand Down
96 changes: 29 additions & 67 deletions Core/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,82 +502,44 @@ float checkParams3D(int *params_switch, int ModelSelected, char *ModelParameters
}

/***********************************************************************************************/
/* rotation matrix routine */
float matrot3(float *Ad, float psi1, float psi2, float psi3)
/* rotation matrix */
float matrot3(float Ad[3][3], float psi1, float psi2, float psi3)
{
Ad[0] = cosf(psi1)*cosf(psi2)*cosf(psi3)-sinf(psi1)*sinf(psi3);
Ad[1] = sinf(psi1)*cosf(psi2)*cosf(psi3)+cosf(psi1)*sinf(psi3);
Ad[2] = -sinf(psi2)*cosf(psi3);
Ad[3] = -cosf(psi1)*cosf(psi2)*sinf(psi3)-sinf(psi1)*cosf(psi3);
Ad[4] = -sinf(psi1)*cosf(psi2)*sinf(psi3)+cosf(psi1)*cosf(psi3);
Ad[5] = sinf(psi2)*sinf(psi3);
Ad[6] = cosf(psi1)*sinf(psi2);
Ad[7] = sinf(psi1)*sinf(psi2);
Ad[8] = cosf(psi2);
return *Ad;
Ad[0][0]=cosf(psi1)*cosf(psi2)*cosf(psi3)-sinf(psi1)*sinf(psi3);
Ad[0][1]=sinf(psi1)*cosf(psi2)*cosf(psi3)+cosf(psi1)*sinf(psi3);
Ad[0][2]=-sinf(psi2)*cosf(psi3);
Ad[1][0]=-cosf(psi1)*cosf(psi2)*sinf(psi3)-sinf(psi1)*cosf(psi3);
Ad[1][1]=-sinf(psi1)*cosf(psi2)*sinf(psi3)+cosf(psi1)*cosf(psi3);
Ad[1][2]=sinf(psi2)*sinf(psi3);
Ad[2][0]=cosf(psi1)*sinf(psi2);
Ad[2][1]=sinf(psi1)*sinf(psi2);
Ad[2][2]=cosf(psi2);
return 1;
}

/*matrix-vector multiplication*/
float matvet3(float *Ad, float *V1, float *V2)
float matvet3(float Ad[3][3], float V1[3], float V2[3])
{
int l, m, counterT;

counterT = 0;
int l, m;
for(l=0; l<3; l++) {
V2[l] = 0.0f;
for(m=0; m<3; m++) {
V2[l] += Ad[counterT]*V1[m];
counterT++;
V2[l] += Ad[l][m]*V1[m];
}}
return *V2;
return 1;
}

/*matrix-matrix multiplication*/
// float matmat3(float *A, float *B, float *C)
// {
// float Am[3][3];
// float Bm[3][3];
// float Cm[3][3];
//
// Am[0][0]=A[0];
// Am[0][1]=A[1];
// Am[0][2]=A[2];
// Am[1][0]=A[3];
// Am[1][1]=A[4];
// Am[1][2]=A[5];
// Am[2][0]=A[6];
// Am[2][1]=A[7];
// Am[2][2]=A[8];
//
// Bm[0][0]=B[0];
// Bm[0][1]=B[1];
// Bm[0][2]=B[2];
// Bm[1][0]=B[3];
// Bm[1][1]=B[4];
// Bm[1][2]=B[5];
// Bm[2][0]=B[6];
// Bm[2][1]=B[7];
// Bm[2][2]=B[8];
//
// int i, j, k;
// for(i=0; i<3; i++) {
// for(j=0; j<3; j++) {
// Cm[i][j]=0.0f;
// for(k=0; k<3; k++) {
// Cm[i][j] += Am[i][k]*Bm[k][j];
// }
// }}
//
// C[0] = Cm[0][0];
// C[1] = Cm[0][1];
// C[2] = Cm[0][2];
// C[3] = Cm[1][0];
// C[4] = Cm[1][1];
// C[5] = Cm[1][2];
// C[6] = Cm[2][0];
// C[7] = Cm[2][1];
// C[8] = Cm[2][2];
//
//
// return *C;
// }
/*float matmat3(float Am[3][3], float Bm[3][3], float Cm[3][3])
{
int i, j, k;
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
Cm[i][j]=0.0f;
for(k=0; k<3; k++) {
Cm[i][j] += Am[i][k]*Bm[k][j];
}
}}
return 1;
}
*/
6 changes: 3 additions & 3 deletions Core/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ extern "C" {
#endif
CCPI_EXPORT float checkParams2D(int *params_switch, int ModelSelected, char *ModelParametersFilename);
CCPI_EXPORT float checkParams3D(int *params_switch, int ModelSelected, char *ModelParametersFilename);
CCPI_EXPORT float matrot3(float *Ad, float psi1, float psi2, float psi3);
CCPI_EXPORT float matvet3(float *Ad, float *V1, float *V2);
// float matmat3(float *A, float *B, float *C);
CCPI_EXPORT float matrot3(float Ad[3][3], float psi1, float psi2, float psi3);
CCPI_EXPORT float matvet3(float Ad[3][3], float V1[3], float V2[3]);
// CCPI_EXPORT float matmat3(float Am[3][3], float Bm[3][3], float Cm[3][3]);
#ifdef __cplusplus
}
#endif
4 changes: 1 addition & 3 deletions Wrappers/MATLAB/Model2DGeneratorDemo.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
close all;clc;clear;
% adding paths
fsep = '/';
pathtoModels = sprintf(['..' fsep 'functions' fsep 'models' fsep], 1i);
addpath(pathtoModels);
addpath('compiled'); addpath('supplem');

ModelNo = 4; % Select a model from Phantom2DLibrary.dat
Expand All @@ -21,7 +19,7 @@
% Generate 2D phantom:
curDir = pwd;
mainDir = fileparts(curDir);
pathtoLibrary = sprintf([fsep 'functions' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathtoLibrary = sprintf([fsep '..' fsep 'PhantomLibrary' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathTP = strcat(mainDir, pathtoLibrary); % path to TomoPhantom parameters file
[G] = TomoP2DModel(ModelNo,N,pathTP);
figure; imagesc(G, [0 1]); daspect([1 1 1]); colormap hot;
Expand Down
10 changes: 4 additions & 6 deletions Wrappers/MATLAB/Model2D_tGeneratorDemo.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
close all;clc;clear;
% adding paths
fsep = '/';
pathtoModels = sprintf(['..' fsep 'functions' fsep 'models' fsep], 1i);
addpath(pathtoModels);
addpath('compiled'); addpath('supplem');

ModelNo = 100; % Select a model from Phantom2DLibrary.dat
Expand All @@ -21,10 +19,10 @@
% Generate 2D+t phantom:
curDir = pwd;
mainDir = fileparts(curDir);
pathtoLibrary = sprintf([fsep 'functions' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathtoLibrary = sprintf([fsep '..' fsep 'PhantomLibrary' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathTP = strcat(mainDir, pathtoLibrary); % path to TomoPhantom parameters file
[G] = TomoP2DModel(ModelNo,N,pathTP);
figure(1); imagesc(G, [0 1]); daspect([1 1 1]); title('2D+t model, t=3 here'); colormap hot;
figure(1); imagesc(G(:,:,3), [0 1]); daspect([1 1 1]); title('2D+t model, t=3 here'); colormap hot;
%%
% Lets look at more finely discretized temporal model and related sinograms
ModelNo = 101; % Select a model from Phantom2DLibrary.dat
Expand All @@ -34,7 +32,7 @@
% Generate 2D phantom:
curDir = pwd;
mainDir = fileparts(curDir);
pathtoLibrary = sprintf([fsep 'functions' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathtoLibrary = sprintf([fsep '..' fsep 'PhantomLibrary' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathTP = strcat(mainDir, pathtoLibrary); % path to TomoPhantom parameters file
[G] = TomoP2DModel(ModelNo,N,pathTP);

Expand All @@ -58,7 +56,7 @@
timeFrames = 25; %must be the same as in model
curDir = pwd;
mainDir = fileparts(curDir);
pathtoLibrary = sprintf([fsep 'functions' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathtoLibrary = sprintf([fsep '..' fsep 'PhantomLibrary' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathTP = strcat(mainDir, pathtoLibrary); % path to TomoPhantom parameters file
[G] = TomoP2DModel(ModelNo,N,pathTP);

Expand Down
4 changes: 1 addition & 3 deletions Wrappers/MATLAB/Model3DGeneratorDemo.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
close all;clc;clear;
% adding paths
fsep = '/';
pathtoModels = sprintf(['..' fsep 'functions' fsep 'models' fsep], 1i);
addpath(pathtoModels);
addpath('compiled'); addpath('supplem');

ModelNo = 10; % Select a model
Expand All @@ -19,7 +17,7 @@
% generate 3D phantom (modify your PATH bellow):
curDir = pwd;
mainDir = fileparts(curDir);
pathtoLibrary = sprintf([fsep 'functions' fsep 'models' fsep 'Phantom3DLibrary.dat'], 1i);
pathtoLibrary = sprintf([fsep '..' fsep 'PhantomLibrary' fsep 'models' fsep 'Phantom3DLibrary.dat'], 1i);
pathTP = strcat(mainDir, pathtoLibrary); % path to TomoPhantom parameters file
tic; [G] = TomoP3DModel(ModelNo,N,pathTP); toc;

Expand Down
7 changes: 2 additions & 5 deletions Wrappers/MATLAB/Model3D_tGeneratorDemo.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
close all;clc;clear;
% adding paths
fsep = '/';
pathtoModels = sprintf(['..' fsep 'functions' fsep 'models' fsep], 1i);
addpath(pathtoModels);
addpath('compiled'); addpath('supplem');

ModelNo = 100; % Select a model
Expand All @@ -19,7 +17,7 @@
% generate 4D phantom (modify your PATH bellow):
curDir = pwd;
mainDir = fileparts(curDir);
pathtoLibrary = sprintf([fsep 'functions' fsep 'models' fsep 'Phantom3DLibrary.dat'], 1i);
pathtoLibrary = sprintf([fsep '..' fsep 'PhantomLibrary' fsep 'models' fsep 'Phantom3DLibrary.dat'], 1i);
pathTP = strcat(mainDir, pathtoLibrary); % path to TomoPhantom parameters file
[G] = TomoP3DModel(ModelNo,N,pathTP);

Expand All @@ -38,11 +36,10 @@
% generate 4D phantom (modify your PATH bellow):
curDir = pwd;
mainDir = fileparts(curDir);
pathtoLibrary = sprintf([fsep 'functions' fsep 'models' fsep 'Phantom3DLibrary.dat'], 1i);
pathtoLibrary = sprintf([fsep '..' fsep 'PhantomLibrary' fsep 'models' fsep 'Phantom3DLibrary.dat'], 1i);
pathTP = strcat(mainDir, pathtoLibrary); % path to TomoPhantom parameters file
[G] = TomoP3DModel(ModelNo,N,pathTP);

%%
sliceM = round(0.5*N);
figure(2);
ll = 10;
Expand Down
4 changes: 1 addition & 3 deletions Wrappers/MATLAB/Reconstruction_Demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
close all;clc;clear;
% adding paths
fsep = '/';
pathtoModels = sprintf(['..' fsep 'functions' fsep 'models' fsep], 1i);
addpath(pathtoModels);
addpath('compiled'); addpath('supplem');

ModelNo = 4; % Select a model from Phantom2DLibrary.dat
Expand All @@ -21,7 +19,7 @@
% Generate 2D phantom:
curDir = pwd;
mainDir = fileparts(curDir);
pathtoLibrary = sprintf([fsep 'functions' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathtoLibrary = sprintf([fsep '..' fsep 'PhantomLibrary' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathTP = strcat(mainDir, pathtoLibrary); % path to TomoPhantom parameters file
[G] = TomoP2DModel(ModelNo,N,pathTP);
figure; imagesc(G, [0 1]); daspect([1 1 1]); colormap hot;
Expand Down
4 changes: 1 addition & 3 deletions Wrappers/MATLAB/SpectralPhantomDemo.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
close all;clc;clear;
% adding paths
fsep = '/';
pathtoModels = sprintf(['..' fsep 'functions' fsep 'models' fsep], 1i);
addpath(pathtoModels);
addpath('compiled'); addpath('supplem');


Expand All @@ -22,7 +20,7 @@
% generate the 2D phantom:
curDir = pwd;
mainDir = fileparts(curDir);
pathtoLibrary = sprintf([fsep 'functions' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathtoLibrary = sprintf([fsep '..' fsep 'PhantomLibrary' fsep 'models' fsep 'Phantom2DLibrary.dat'], 1i);
pathTP = strcat(mainDir, pathtoLibrary); % path to TomoPhantom parameters file
[G] = TomoP2DModel(ModelNo,N,pathTP);

Expand Down
15 changes: 11 additions & 4 deletions Wrappers/MATLAB/install/compile_mex_linux.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

mkdir compiled

PathFunc = sprintf(['..' fsep 'functions' fsep], 1i);
cd(PathFunc);
PathFunc = sprintf(['..' fsep '..' fsep 'Core' fsep], 1i);

Pathmove = sprintf(['..' fsep 'matlab' fsep 'compiled' fsep], 1i);
copyfile(PathFunc, 'mex_wrappers');

cd('mex_wrappers');

Pathmove = sprintf(['..' fsep 'compiled' fsep], 1i);

fprintf('%s \n', 'Building functions...');
mex TomoP2DModel.c TomoP2DModel_core.c utils.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp"
Expand All @@ -24,7 +27,11 @@
movefile('TomoP3DModel.mex*',Pathmove);
mex TomoP3DObject.c TomoP3DModel_core.c utils.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp"
movefile('TomoP3DObject.mex*',Pathmove);
mex TomoP2DSinoNum.c TomoP2DSinoNum_core.c utils.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp"
movefile('TomoP2DSinoNum.mex*',Pathmove);

delete TomoP2DModel_core* TomoP2DModelSino_core* TomoP3DModel_core* TomoP2DSinoNum_core* CCPiDefines.h utils* CMakeLists.txt;

fprintf('%s \n', 'All compiled!');

cd(UpPath);
cd matlab
22 changes: 16 additions & 6 deletions Wrappers/MATLAB/install/compile_mex_windows.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

mkdir compiled

PathFunc = sprintf(['..' fsep 'functions' fsep], 1i);
cd(PathFunc);
Pathmove = sprintf(['..' fsep 'matlab' fsep 'compiled' fsep], 1i);
PathFunc = sprintf(['..' fsep '..' fsep 'Core' fsep], 1i);

copyfile(PathFunc, 'mex_wrappers');

cd('mex_wrappers');

Pathmove = sprintf(['..' fsep 'compiled' fsep], 1i);
% One way to compile using Matlab-installed MinGW:
fprintf('%s \n', 'Building functions...');
mex TomoP2DModel.c TomoP2DModel_core.c utils.c COMPFLAGS="\$COMPFLAGS -fopenmp -Wall -std=c99"
Expand All @@ -32,6 +35,11 @@
movefile('TomoP3DModel.mex*',Pathmove);
mex TomoP3DObject.c TomoP3DModel_core.c utils.c COMPFLAGS="\$COMPFLAGS -fopenmp -Wall -std=c99"
movefile('TomoP3DObject.mex*',Pathmove);
mex TomoP2DSinoNum.c TomoP2DSinoNum_core.c utils.c COMPFLAGS="\$COMPFLAGS -fopenmp -Wall -std=c99"
movefile('TomoP2DSinoNum.mex*',Pathmove);


delete TomoP2DModel_core* TomoP2DModelSino_core* TomoP3DModel_core* TomoP2DSinoNum_core* CCPiDefines.h utils* CMakeLists.txt;

%%% The second approach to compile using TDM-GCC which follows this
%%% discussion:
Expand All @@ -55,7 +63,9 @@
% movefile('TomoP3DModel.mex*',Pathmove);
% mex C:\TDMGCC\lib\gcc\x86_64-w64-mingw32\5.1.0\libgomp.a CXXFLAGS="$CXXFLAGS -std=c++11 -fopenmp" TomoP3DObject.c TomoP3DModel_core.c utils.c
% movefile('TomoP3DObject.mex*',Pathmove);
% fprintf('%s \n', 'All compiled!');
% mex C:\TDMGCC\lib\gcc\x86_64-w64-mingw32\5.1.0\libgomp.a CXXFLAGS="$CXXFLAGS -std=c++11 -fopenmp" TomoP2DSinoNum.c TomoP2DSinoNum_core.c utils.c
% movefile('TomoP2DSinoNum.mex*',Pathmove);
% delete TomoP2DModel_core* TomoP2DModelSino_core* TomoP3DModel_core* TomoP2DSinoNum_core* CCPiDefines.h utils* CMakeLists.txt;

cd(UpPath);
cd matlab
fprintf('%s \n', 'All compiled!');
cd(UpPath);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Wrappers/Python/Demos/DemoModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
model = 1 # selecting a model
N_size = 512
#specify a full path to the parameters file
pathTP = '../../functions/models/Phantom2DLibrary.dat'
pathTP = '../../../PhantomLibrary/models/Phantom2DLibrary.dat'
#objlist = modelfile2Dtolist(pathTP, model) # one can extract parameters
#This will generate a N_size x N_size phantom (2D)
phantom_2D = TomoP2D.Model(model, N_size, pathTP)
Expand Down
Loading

0 comments on commit 4cf19d6

Please sign in to comment.