Skip to content

Commit

Permalink
Added entry point for localRaiseOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
VikingScientist committed Jan 2, 2019
1 parent 19ca96d commit 211a666
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 4 deletions.
59 changes: 55 additions & 4 deletions src/lrsplinesurface_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,53 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
}


// Raise order elements
if (!strcmp("raise_order_elements", cmd)) {
// Check parameters
if (nlhs < 0 || nrhs < 4)
mexErrMsgTxt("raise_order_elements: Unexpected arguments.");

// rewrap results into vector array
double *el = mxGetPr(prhs[2]);
double *p = mxGetPr(prhs[3]);
int m = mxGetM(prhs[2]);
int n = mxGetN(prhs[2]);
vector<Element*> elms(m*n);
for(size_t i=0; i<n*m; i++) {
// error check input
if(el[i]<=0 || el[i] > lr->nElements())
mexErrMsgTxt("Raise_order_elements: element index out of range");
elms[i] = lr->getElement(floor(el[i]-1));
}

lr->order_elevate(elms, 0, (int) p[0]);
lr->order_elevate(elms, 1, (int) p[1]);
return;
}


// Raise order basisfunctions
if (!strcmp("raise_order_basis", cmd)) {
// Check parameters
if (nlhs < 0 || nrhs < 3)
mexErrMsgTxt("raise_order_basis: Unexpected arguments.");

// rewrap results into vector array
double *b = mxGetPr(prhs[2]);
int m = mxGetM(prhs[2]);
int n = mxGetN(prhs[2]);
vector<int> basis(m*n);
for(size_t i=0; i<n*m; i++) {
basis[i] = floor(b[i]-1);
// error check input
if(basis[i]<0 || basis[i] >= lr->nBasisFunctions())
mexErrMsgTxt("Raise_order_basis: function index out of range");
}

lr->orderElevateFunction(basis);
return;
}


// Refine basisfunctions
if (!strcmp("refine_basis", cmd)) {
Expand All @@ -275,7 +322,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
if(basis[i]<0 || basis[i] >= lr->nBasisFunctions())
mexErrMsgTxt("Refine_basis: function index out of range");
}

lr->setRefContinuity(cont);
lr->refineBasisFunction(basis);
return;
Expand Down Expand Up @@ -570,10 +617,14 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
}
if(nlhs > 6) {
int n = lr->nElements();
plhs[6] = mxCreateDoubleMatrix(2, 1, mxREAL);
plhs[6] = mxCreateDoubleMatrix(n, 2, mxREAL);
double *p = mxGetPr(plhs[6]);
p[0] = lr->min_order(0)-1;
p[1] = lr->min_order(1)-1;
vector<Element*>::iterator it;
int i=0;
for(it=lr->elementBegin(); it<lr->elementEnd(); ++it, ++i) {
p[i ] = (**it).order(0);
p[i+n] = (**it).order(1);
}
}
return;
}
Expand Down
47 changes: 47 additions & 0 deletions src/matlab/LRSplineSurface.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
% copy - Performs a deep copy of the spline object
% refine - Performs local refinements
% raiseOrder - Performs global degree elevation
% localRaiseOrder - Performs local degree elevation
% getFunc2Element - Returns list of elements which a given function have support on
% getEdge - Extracts functions with support on one of the four parametric edges
% getElementContaining - Get element index at parametric point (u,v)
Expand Down Expand Up @@ -174,6 +175,52 @@ function print(this)
lrsplinesurface_interface('print', this.objectHandle);
end

function localRaiseOrder(this, varargin)
% LOCALRAISEORDER Performs local degree elevation of elements or basis functions
% LRSplineSurface.localRaiseOrder()
% LRSplineSurface.localRaiseOrder(indices)
% LRSplineSurface.localRaiseOrder(indices, 'basis')
% LRSplineSurface.localRaiseOrder(indices, 'elements', 'p', newP)
%
% parameters:
% indices - index of the basis function or elements to order elevate
% 'elements' - tag certain elements for degree elevation
% 'basis' - degree elevate certain functions
% 'p' - sets the maximum new polynomial degree to raise
% returns:
% none
elements = false; % and uniform refinement
indices = 1:size(this.knots,1);
i = 0;
p = -1;
% read input parameters
while(i<nargin-1)
i=i+1;
if strcmp(varargin{i}, 'elements')
elements = true;
elseif strcmp(varargin{i}, 'basis')
elements = false;
elseif strcmp(varargin{i}, 'p')
p = varargin{i+1};
i = i+1;
elseif(ischar(varargin{i}))
throw(MException('LRSplineSurface:refine', 'Error: Unknown refine parameter'));
else
indices = varargin{i};
end
end

% perform refinement
if(elements)
lrsplinesurface_interface('raise_order_elements', this.objectHandle, indices, p);
else
lrsplinesurface_interface('raise_order_basis', this.objectHandle, indices);
end

% new LR-mesh... update static variables
this.bezierHash = [];
this.updatePrimitives();
end

function refine(this, varargin)
% REFINE Performs local refinement of elements or basis functions. No arguments gives global uniform refinement
Expand Down

0 comments on commit 211a666

Please sign in to comment.