Skip to content

Commit

Permalink
Created a custom mex function for Bragg periods cell array generation…
Browse files Browse the repository at this point in the history
… that is generally ten times faster. Added a makemex.m catch all script.
  • Loading branch information
nicolasayotte committed Jun 2, 2014
1 parent 65967d5 commit 065e513
Show file tree
Hide file tree
Showing 26 changed files with 72 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Functions - Component/BraggFromParameters.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@
x1 = x1 + cumsum(tps);
end
end
x2 = x1 + obragg(row).period(col) * obragg(row).dc(col);
x2 = x1 + (obragg(row).period(col) + linspace(0, obragg(row).chirp(col), periods)') * obragg(row).dc(col);

y1 = (-0.5 * obragg(row).w(col) - obragg(row).corw(col)) * ones(periods,1);
y2 = y1 + obragg(row).w(col) + 2 * obragg(row).corw(col);

for kk = 1 : periods
grating{kk} = [x1(kk), y1(kk); x2(kk), y1(kk); x2(kk), y2(kk); x1(kk), y2(kk); x1(kk), y1(kk)];
if(exist('CornersToRects') == 3)
grating(1:periods) = CornersToRects(x1, x2, y1, y2);
else
grating(1:periods) = num2cell(reshape([x1, x2, x2, x1, x1, y1, y1, y2, y2, y1]', 5, 2, length(x1)), [1, 2]);
end

end

% Guide
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/@gds_element/private/isref.mexw64
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_beginlib.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_beginstruct.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_close.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_endlib.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_endstruct.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_ftell.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_libdata.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_open.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_read_element.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_record_info.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_structdata.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Basic/gdsio/gds_write_element.mexw64
Binary file not shown.
Binary file modified Functions - GDSII Library/Boolean/poly_boolmex.mexw64
Binary file not shown.
1 change: 0 additions & 1 deletion Functions - GDSII Library/makemex.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
mex -O -I../../gdsio set_element_data.c ../../gdsio/mexfuncs.c

cd ../../../Structures/private
mex -O datamatrixmex.c

% Boolean functions
fprintf('\n\n>>>>>\n');
Expand Down
57 changes: 57 additions & 0 deletions Functions - Utils/CornersToRects.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

/*_________________________________________________________________________
*
* MEX Script
* File Creation : Nicolas Ayotte, May 2014
* CornersToRects.cpp
* _________________________________________________________________________*/


#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
// Declare variables
int nz, j;
double *x1, *x2, *y1, *y2;
mxArray *mat, *p;
double *pr, *pd;

// Get the number of elements in the input argument
nz = mxGetNumberOfElements(prhs[0]);

// Get input pointer
x1 = (double *)mxGetData(prhs[0]);
x2 = (double *)mxGetData(prhs[1]);
y1 = (double *)mxGetData(prhs[2]);
y2 = (double *)mxGetData(prhs[3]);

// Get output pointer
plhs[0] = mxCreateCellMatrix(1, (mwSize)nz);

// Initialize output
mat = mxCreateDoubleMatrix(5, 2, mxREAL);
pr = (double *)mxGetData(mat);

for (j=0; j<nz; j++)
{

pr[0] = (double)x1[j];
pr[3] = (double)x1[j];
pr[4] = (double)x1[j];

pr[1] = (double)x2[j];
pr[2] = (double)x2[j];

pr[5] = (double)y1[j];
pr[6] = (double)y1[j];
pr[9] = (double)y1[j];

pr[7] = (double)y2[j];
pr[8] = (double)y2[j];

mxSetCell(plhs[0], j, mxDuplicateArray(mat));
}
return;
}

Binary file added Functions - Utils/CornersToRects.mexw64
Binary file not shown.
9 changes: 9 additions & 0 deletions makemex.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%% Compiling the mex files

cd 'Functions - Utils'
mex -O CornersToRects.c;

cd ..

cd 'Functions - GDSII Library'
makemex

0 comments on commit 065e513

Please # to comment.