Showing revision 3
Difference (from revision 2 to revision 3) (minor diff)

Changed: 2c2

<toc>

Changed: 15c15,16
inputs and outputs are similar to those defined in vol2surf
inputs and outputs are similar to those defined in vol2surf; In v2s,
method can be set to 'cgalmesh' in addition to those allowed by vol2surf.

Changed: 17c18

function [node,elem,face]=s2m(v,f,keepratio,maxvol)



function [node,elem,face]=s2m(v,f,keepratio,maxvol,method)




Added: 20a22,23
if method='cgalpoly', s2m will call cgals2m and keepratio should be a
structure (as the 'opt' input in cgals2m)

Added: 53a57,59
when method='cgalmesh', maxvol can specify the target
for each label (subregion index) by the following syntax
'label1=size1:label2=size2:...'

Changed: 64c70
is not recommended unless other options failed.
is not recommended unless other options has failed.

Changed: 90,91c96,97
opt.keeyratio=a float less than 1: same as above, same for all surf.
opt(1,2,..).keeyratio: setting compression rate for each levelset
opt.keepratio=a float less than 1: same as above, same for all surf.
opt(1,2,..).keepratio: setting compression rate for each levelset

Changed: 156c162
output
output:

Changed: 193c199

function [node,elem,face]=cgals2m(v,f,opt,maxvol)



function [node,elem,face]=cgals2m(v,f,opt,maxvol,varargin)




Changed: 196c202
convert a binary (or multi-valued) volume to tetrahedral mesh
convert a triangular surface to tetrahedral mesh

Changed: 247,248c253,254

function [node,elem,face]=meshabox(p0,p1,opt,nodesize)



[node,elem,face]=meshabox(p0,p1,opt,maxvol)

function [node,face,elem]=meshabox(p0,p1,opt,nodesize)



[node,face,elem]=meshabox(p0,p1,opt,maxvol)

Changed: 262c268
[node,elem,face]=meshabox([2 3 2],[6 12 15],0.1,1);
[node,face,elem]=meshabox([2 3 2],[6 12 15],0.1,1);

Changed: 273c279
output
output:

Added: 320a327,345

function [node,face,elem]=meshacylinder(c0,c1,r,tsize,maxvol,ndiv)



[node,face]=meshacylinder(c0,c1,r,tsize,maxvol,ndiv)
or
[node,face,elem]=meshacylinder(c0,c1,r,tsize,maxvol,ndiv)
create the surface and (optionally) tetrahedral mesh of a 3D cylinder
input:
c0, c1: cylinder axis end points
r: radius of the cylinder
tsize: maximum surface triangle size on the sphere
maxvol: maximu volume of the tetrahedral elements
ndiv: approximate the cylinder surface into ndiv flat pieces, if
ignored, ndiv is set to 20
output:
node: node coordinates, 3 columns for x, y and z respectively
face: integer array with dimensions of NB x 3, each row represents
a surface mesh triangle
elem: (optional) integer array with dimensions of NE x 4, each row
represents a tetrahedron

Changed: 399c424
output
output:

Changed: 448,451c473,476

function f=maxsurf(facecell)



f=maxsurf(facecell)
return the surface with the maximum element number (not
necessarily in area) from a cell arry of surfaces

function [f maxsize]=maxsurf(facecell,node)



[f maxsize]=maxsurf(facecell,node)
return the surface with the maximum element number or
total area from a cell arry of surfaces

Added: 453a479,480
node: optional, node list, if given, the output is the
surface with the largest surface area.

Changed: 455c482,485
f: the surface data (node indices) for the surface with most elements
f: the surface data (node indices) for the surface with the
most elements (or largest area when node is given)
maxsize: if node is not given, maxisize is row number of f;
otherwise, maxsize is the total area of f

Changed: 492c522
decompose edge loops into flat segments alone x/y/z
decompose edge loops into flat segments along the x/y/z

Added: 526a557,565

function elist=surfpart(f,loopedge)



elist=surfpart(f,loopedge)
partition a triangular surface using a closed loop defined by existing edges
input:
f: input, surface face element list, dimension (be,3)
loopedge: a 2-column array, specifying a closed loop in CCW order
output:
elist: list of triangles that is enclosed by the loop


Changed: 540c579
compute Joe-Liu mesh quality measure of a tetrahedral mesh
compute the Joe-Liu mesh quality measure of a tetrahedral mesh

Changed: 544,548c583,591
output
edge: edge list; each row is an edge, specified by the starting and
ending node indices, the total edge number is
size(elem,1) x nchoosek(size(elem,2),2). All edges are ordered
by looping through each element first.
output:
quality: a vector of the same length as size(elem,1), with
each element being the Joe-Liu mesh quality metric (0-1) of
the corresponding element. A value close to 1 represents
higher mesh quality (1 means equilateral tetrahedron);
a value close to 0 means nearly degenerated element.
reference:
A. Liu, B. Joe, Relationship between tetrahedron shape measures,
BIT 34 (2) (1994) 268-287.

Changed: 550,551c593,594

function edges=meshedge(elem)



edges=meshedge(elem)

function edges=meshedge(elem,varargin)



edges=meshedge(elem,opt)

Changed: 555c598,603
output
opt: optional input, giving the additional options. If opt
is a struct, it can have the following field:
opt.nodeorder: if 1, assuming the elem node indices is in CCW
orientation; 0 use nchoosek() output to order edges
you can replace opt by a series of ('param', value) pairs.
output:

Added: 559a608,645

function snorm=surfnorm(node,face,varargin)



snorm=surfnorm(node,face)
or
snorm=surfnorm(node,face,'Normalize',0)
compute the normal vectors for a triangular surface
input:
node: a list of node coordinates (nn x 3)
face: a surface mesh triangle list (ne x 3)
opt: a list of optional parameters, currently surfnorm supports:
'Normalize': [1|0] if set to 1, the normal vectors will be
unitary (default)
output:
snorm: output surface normal vector at each face

function [edges,idx,edgemap]=uniqedges(elem)



[edges,idx,edgemap]=uniqedges(elem)
return the unique edge list from a surface or tetrahedral mesh
input:
elem: a list of elements, each row is a list of nodes for an element.
elem can have 2, 3 or 4 columns
output:
edge: unique edges in the mesh, denoted by a pair of node indices
idx: index of the output in the raw edge list (returned by meshedge)
edgemap: index of the raw edges in the output list (for triangular mesh)

function [elist,nextfront]=advancefront(edges,loop,elen)



[elist,nextfront]=advancefront(edges,loop,elen)
advance an edge-front on an oriented surface to the next separated by
one-element width
input:
edges: edge list of an oriented surface mesh, must be in CCW order
loop: a 2-column array, specifying a closed loop in CCW order
elen: node number inside each element, if ignored, elen is set to 3
output:
elist: list of triangles that is enclosed between the two
edge-fronts
nextfront: a new edge loop list representing the next edge-front

Changed: 562c648

function [node,elem]=meshcheckrepair(node,elem,opt)



function [node,elem]=meshcheckrepair(node,elem,opt,varargin)




Changed: 569c655,657
'duplicated': remove duplicated elements
'dupnode': remove duplicated nodes
'dupelem' or 'duplicated': remove duplicated elements
'dup': both above

Added: 570a659
'open': abort when open surface is found

Added: 571a661,663
'meshfix': repair a closed surface by the meshfix utility (new)
it can remove self-intersecting elements and fill holes
'intersect': test a surface for self-intersecting elements

Changed: 585c677
remove doubly duplicated elements
remove doubly duplicated (folded) elements

Changed: 614c706
remove disjointed surface fragment by using mesh diameter
remove disjointed surface fragment filtered by using mesh diameter

Added: 649a742,752

function [newnode,newface]=surfreorient(node,face)



[newnode,newface]=surfreorient(node,elem)
reorder nodes in a single closed surface to ensure the norms of all
triangles are pointing outward
input:
node: list of nodes
face: list of surface triangles (each row are indices of nodes of each triangle)
output:
newnode: the output node list, in most cases it equals node
newface: the face list with consistent ordering

Changed: 692c795
useralpha: scaler, smoothing parameter, v(k+1)=alpha*v(k)+(1-alpha)*mean(neighbors)
useralpha: scaler, smoothing parameter, v(k+1)=(1-alpha)*v(k)+alpha*mean(neighbors)

Changed: 726c829
merge two or more tetrahedral meshes or triangular surfaces
concatenate two or more tetrahedral meshes or triangular surfaces

Changed: 734c837,839
newelem to remove the duplicated nodes or elements
newelem to remove the duplicated nodes or elements. mergemesh does
detect self-intersecting elements when merging; to remove self-intersecting
elements, you need to use mergesurf().

Changed: 736c841
[node1,elem1,face1]=meshabox([0 0 0],[10 10 10],1,1);
[node1,face1,elem1]=meshabox([0 0 0],[10 10 10],1,1);

Added: 742a848,924

function [newnode,newelem,newface]=meshrefine(node,elem,varargin)



[newnode,newelem,newface]=meshrefine(node,elem,face,opt)
refine a tetrahedral mesh by adding new nodes or constraints
input parameters:
node: existing tetrahedral mesh node list
elem: existing tetrahedral element list
face: (optional) existing tetrahedral mesh surface triangle list
opt: options for mesh refinement:
if opt is a Nx3 array, opt is treated as a list of new nodes to
be inserted into the mesh (must be located on the surface or inside)
if opt is a struct, it can have the following fields:
opt.newnode: same as setting opt to an Nx3 array
opt.reratio: radius-edge ratio, by default, iso2mesh uses 1.414
opt.maxvol: maximum element volume
outputs:
newnode: node coordinates of the tetrahedral mesh
newelem: element list of the tetrahedral mesh
newface: mesh surface element list of the tetrahedral mesh
the last column denotes the boundary ID

function [newnode,newelem]=mergesurf(node,elem,varargin)



[newnode,newelem]=mergesurf(node1,elem1,node2,elem2,...)
merge two or more triangular meshes and split intersecting elements
input:
node: node coordinates, dimension (nn,3)
elem: tetrahedral element or triangle surface (nn,3)
output:
newnode: the node coordinates after merging, dimension (nn,3)
newelem: tetrahedral element or surfaces after merging (nn,4) or (nhn,5)
note: you can call meshcheckrepair for the output newnode and
newelem to remove the duplicated nodes or elements
example:
[node1,face1,elem1]=meshabox([0 0 0],[10 10 10],1,1);
[node2,face2,elem2]=meshasphere([5 5 10],3,0.3,3);
[newnode,newface]=mergemesh(node1,face1,node2,face2);
plotmesh(newnode,newface,'x>5');

function [newnode,newelem,newelem0]=surfboolean(node,elem,varargin)



[newnode,newelem,newelem0]=surfboolean(node1,elem1,op2,node2,elem2,op3,node3,elem3,...)
merge two or more triangular meshes and resolve intersecting elements
input:
node: node coordinates, dimension (nn,3)
elem: tetrahedral element or triangle surface (ne,3)
op: a string of a boolean operator, possible op values include
'union' or 'or': the outter surface of the union of the enclosed space
'inter' or 'and': the surface of the domain contained by both meshes
'diff' or '-': the surface of the domain in mesh 1 excluding that of
mesh 2
'all' or 'xor' or '+': the output contains 4 subsurfaces, identified by the 4th
column of newelem:
1: mesh 1 outside of mesh 2
2: mesh 2 outside of mesh 1
3: mesh 1 inside of mesh 2
4: mesh 2 inside of mesh 1
you can use newelem(find(mod(newelem(:,4),2)==1),:) to
get mesh 1 cut by mesh 2, or newelem(find(mod(newelem(:,4),2)==0),:)
to get mesh 2 cut by mesh 1;
'first': combine 1 and 3 from the output of 'all'
'second': combine 2 and 4 from the output of 'all'
'self': test for self-intersections; only the first mesh is
tested; other inputs are ignored.
'decouple': separate two shells and make sure there is no intersection;
the input surfaces must be closed and ordered from outer to inner
output:
newnode: the node coordinates after boolean operations, dimension (nn,3)
newelem: tetrahedral element or surfaces after boolean operations (nn,4) or (nhn,5)
newelem0: when the operator is 'self', return the intersecting
element list in terms of the input node list (experimental)
example:
[node1,face1,elem1]=meshabox([0 0 0],[10 10 10],1,1);
[node2,face2,elem2]=meshabox([0 0 0]+5,[10 10 10]+5,1,1);
[newnode,newface]=surfboolean(node1,face1,'union',node2,face2);
plotmesh(newnode,newface);
figure;
[newnode,newface]=surfboolean(node1,face1,'diff',node2,face2);
plotmesh(newnode,newface,'x>5');

Added: 761a944,961

function savestl(node,elem,fname,solidname)



savestl(node,elem,fname,solidname)
save a tetrahedral mesh to an STL (Standard Tessellation Language) file
input:
node: input, surface node list, dimension Nx3
elem: input, tetrahedral element list; if size(elem,2)==3, it is a surface
fname: output file name
solidname: an optional string for the name of the object

function savebinstl(node,elem,fname,solidname)



savebinstl(node,elem,fname,solidname)
save a tetrahedral mesh to a binary STL (Standard Tessellation Language) file
input:
node: input, surface node list, dimension Nx3
elem: input, tetrahedral element list; if size(elem,2)==3, it is a surface
fname: output file name
solidname: an optional string for the name of the object


Added: 800a1001,1023

function nedge=savegts(v,f,fname,edges)



nedge=savegts(v,f,fname,edges)
save a surface mesh to GNU Triangulated Surface Format (GTS)
input:
v: input, surface node list, dimension (nn,3)
f: input, surface face element list, dimension (be,3)
fname: output file name
edges: edge list, if ignored, savegts will compute
output:
nedge: the number of unique edges in the mesh

function [node,elem,edges,edgemap]=readgts(fname)



[node,elem,edges,edgemap]=readgts(fname)
read GNU Triangulated Surface files (GTS)
input:
fname: name of the OFF data file
output:
node: node coordinates of the mesh
elem: list of elements of the surface mesh
edges: the edge list section in the GTS file (optional)
edgemap: the face section (in terms of edge indices) in the GTS file
(optional)


Changed: 901c1124
savedmedit(node,face,elem,fname)
savemedit(node,face,elem,fname)

Added: 907a1131,1276

function json=savejson(rootname,obj,varargin)



json=savejson(rootname,obj,filename)
or
json=savejson(rootname,obj,opt)
json=savejson(rootname,obj,'param1',value1,'param2',value2,...)
convert a MATLAB object (cell, struct or array) into a JSON (JavaScript
Object Notation) string
created on 2011/09/09
$Id: savejson.m 394 2012-12-18 17:58:11Z fangq $
input:
rootname: name of the root-object, if set to '', will use variable name
obj: a MATLAB object (array, cell, cell array, struct, struct array)
filename: a string for the file name to save the output JSON data
opt: a struct for additional options, use [] if all use default
opt can have the following fields (first in [.|.] is the default)
opt.FileName [''|string]: a file name to save the output JSON data
opt.FloatFormat ['%.10g'|string]: format to show each numeric element
of a 1D/2D array;
opt.ArrayIndent [1|0]: if 1, output explicit data array with
precedent indentation; if 0, no indentation
opt.ArrayToStruct[0|1]: when set to 0, savejson outputs 1D/2D
array in JSON array format; if sets to 1, an
array will be shown as a struct with fields
"_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
sparse arrays, the non-zero elements will be
saved to _ArrayData_ field in triplet-format i.e.
(ix,iy,val) and "_ArrayIsSparse_" will be added
with a value of 1; for a complex array, the
_ArrayData_ array will include two columns
(4 for sparse) to record the real and imaginary
parts, and also "_ArrayIsComplex_":1 is added.
opt.ParseLogical [0|1]: if this is set to 1, logical array elem
will use true/false rather than 1/0.
opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
numerical element will be shown without a square
bracket, unless it is the root object; if 0, square
brackets are forced for any numerical arrays.
opt.ForceRootName [0|1]: when set to 1 and rootname is empty, savejson
will use the name of the passed obj variable as the
root object name; if obj is an expression and
does not have a name, 'root' will be used; if this
is set to 0 and rootname is empty, the root level
will be merged down to the lower level.
opt.Inf ['"$1_Inf_"'|string]: a customized regular expression pattern
to represent +/-Inf. The matched pattern is '([-+]*)Inf'
and $1 represents the sign. For those who want to use
1e999 to represent Inf, they can set opt.Inf to '$11e999'
opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern
to represent NaN
opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
for example, if opt.JSON='foo', the JSON data is
wrapped inside a function call as 'foo(...);'
opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
back to the string form
opt can be replaced by a list of ('param',value) pairs. The param
string is equivallent to a field in opt.
output:
json: a string in the JSON format (see http://json.org)
examples:
a=struct('node',[1 9 10; 2 1 1.2], 'elem',[9 1;1 2;2 3],...
'face',[9 01 2; 1 2 3; NaN,Inf,-Inf], 'author','FangQ');
savejson('mesh',a)
savejson('',a,'ArrayIndent',0,'FloatFormat','\t%.5g')
license:
BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details

function data = loadjson(fname,varargin)



data=loadjson(fname,opt)
or
data=loadjson(fname,'param1',value1,'param2',value2,...)
parse a JSON (JavaScript Object Notation) file or string
Nedialko Krouchev: http://www.mathworks.com/matlabcentral/fileexchange/25713
François Glineur: http://www.mathworks.com/matlabcentral/fileexchange/23393
Joel Feenstra:
http://www.mathworks.com/matlabcentral/fileexchange/20565
$Id: loadjson.m 394 2012-12-18 17:58:11Z fangq $
input:
fname: input file name, if fname contains "{}" or "[]", fname
will be interpreted as a JSON string
opt: a struct to store parsing options, opt can be replaced by
a list of ('param',value) pairs. The param string is equivallent
to a field in opt.
output:
dat: a cell array, where {...} blocks are converted into cell arrays,
and [...] are converted to arrays
license:
BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details

function savejmesh(node,face,elem,fname,varargin)



savejmesh(node,face,elem,fname,opt)
export a mesh to the JMesh format
input:
node: input, node list, dimension (nn,3)
face: input, optional, surface face element list, dimension (be,3)
elem: input, tetrahedral element list, dimension (ne,4)
fname: output file name
opt: additional parameters in the form of 'parameter',value pairs
valid parameters include:
'Dimension': 0 - a user defined mesh, 2- a 2D mesh, 3- a 3D mesh
'Author': a string to set the author of the mesh
'MeshTitle': a string to set the title of the mesh
'MeshTag': a value as the tag of the mesh data
'MeshGroup': a value to group this mesh with other mesh data
'Comment': a string as the additional note for the mesh data

function savemphtxt(node, face, elem, filename)



savemphtxt(node, face, elem, filename)
save tetrahedron mesh to comsol file (.mphtxt)
author: Donghyeon Kim (danielkim<at> gist.ac.kr)
input:
node: input, node list, dimension (nn,3)
face: input, surface face element list with label, dimension (be,4)
elem: input, tetrahedron element list with label, dimension (ne,5)
filename: input, output file name

function savetetgenele(elem,fname)



savetetgenele(elem,fname)
save a mesh tetrahedral element list to tetgen .ele format
input:
elem: tetrahedral element list, dimension (ne,4)
columns beyound the 4rd column are treated as
markers and attributes associated with the element
fname: output file name

function savetetgennode(node,fname)



savetetgennode(node,fname)
save a mesh node list to tetgen .node format
input:
node: node coordinates, dimension (nn,3)
columns beyound the 3rd column are treated as
markers and attributes associated with the node
fname: output file name

function saveabaqus(node,face,elem,fname,heading)



saveabaqus(node,fname)
saveabaqus(node,face,fname)
saveabaqus(node,face,elem,fname)
save a tetrahedral and/or surface mesh as an ABAQUS input file
input:
node: input, surface node list, dimension (nn,3)
face: input, surface face element list, dimension (be,3)
elem: input, tetrahedral element list, dimension (ne,4)
fname: output file name
heading: optional, a descriptive string for the mesh

Changed: 921,922c1290,1291

function resimg=fillholes3d(img,ballsize)



resimg=fillholes3d(img,ballsize)

function resimg=fillholes3d(img,maxgap)



resimg=fillholes3d(img,maxgap)

Changed: 926c1295
ballsize: maximum gap size for image closing
maxgap: maximum gap size for image closing

Changed: 1016c1385,1389
sub-surfaces and display them in different colors.
sub-surfaces and display them in different colors;
face can be a cell array, each element of the array represents
a polyhedral facet of the mesh, if an element is an array with
two array subelements, the first one is the node index, the
second one is a scalar as the group id of the facet.

Changed: 1024c1397,1399
such as 'x>0 & y+z<1'; opt can have more than one
such as 'x>0 & y+z<1', or an equation defining
a plane at which a mesh cross-section is plotted, for
example 'y=2*x'; opt can have more than one

Added: 1042a1418
h=plotmesh(node,elem,'z=20');

Changed: 1052c1428,1432
sub-surfaces and display them in different colors.
sub-surfaces and display them in different colors;
face can be a cell array, each element of the array represents
a polyhedral facet of the mesh, if an element is an array with
two array subelements, the first one is the node index, the
second one is a scalar as the group id of the facet.

Changed: 1076,1078c1456,1458

function [cutpos,cutvalue,facedata]=qmeshcut(elem,node,value,plane)



[cutpos,cutvalue,facedata]=qmeshcut(elem,node,value,plane)
fast tetrahedral mesh cross-section plot

function [cutpos,cutvalue,facedata,elemid]=qmeshcut(elem,node,value,cutat,varargin)



[cutpos,cutvalue,facedata,elemid]=qmeshcut(elem,node,value,cutat)
fast tetrahedral mesh slicer

Changed: 1085c1465,1480
plane: defines a plane by 3 points: plane=[x1 y1 z1;x2 y2 z2;x3 y3 z3]
cutat: cutat can have different forms:
if cutat is a 3x3 matrix, it defines a plane by 3 points:
cutat=[x1 y1 z1;x2 y2 z2;x3 y3 z3]
if cutat is a vector of 4 element, it defines a plane by
a*x+b*y+c*z+d=0 and cutat=[a b c d]
if cutat is a single scalar, it defines an isosurface
inside the mesh at value=cutat
if cutat is a string, it defines an implicit surface
at which the cut is made. it must has form expr1=expr2
where expr1 expr2 are expressions made of x,y,z,v and
constants
if cutat is a cell in the form of {'expression',scalar},
the expression will be evaluated at each node to
produce a new value, then an isosurface is produced
at the levelset where new value=scalar; the
expression can contain constants and x,y,z,v

Changed: 1087c1482
cutpos: all the intersections of mesh edges by the plane
cutpos: all the intersections of mesh edges by the cutat

Added: 1092a1488,1489
elemid: the index of the elem in which each intersection polygon locates
without any output, qmeshcut generates a cross-section plot

Changed: 1094,1104c1491,1494
patch('Vertices',cutpos,'Faces',facedata,'FaceVertexCData',cutvalue,...
'FaceColor','interp');

function plottetview(session,method)



plottetview(session,method)
wrapper for tetview to plot the generated mesh
input:
session: a string to identify the output files for plotting, '' for
the default session
method: method can be 'cgalsurf' (default), 'simplify', 'cgalpoly'
'cgalmesh' and 'remesh'
% if value has a length of node:
patch('Vertices',cutpos,'Faces',facedata,'FaceVertexCData',cutvalue,'FaceColor','interp');
% if value has a length of elem:
patch('Vertices',cutpos,'Faces',facedata,'CData',cutvalue,'FaceColor','flat');

Changed: 1133,1134c1523,1524

function isoctave=isoctavemesh



isoctave=isoctavemesh

function [isoctave verinfo]=isoctavemesh



[isoctave verinfo]=isoctavemesh

Added: 1137a1528
verinfo: a string, showing the version of octave (OCTAVE_VERSION)

Changed: 1149,1150c1540,1541

function [t,u,v]=raytrace(p,v,node,face)



[t,u,v]=raytrace(p,v,node,face)

function [t,u,v,idx]=raytrace(p0,v0,node,face)



[t,u,v,idx]=raytrace(p0,v0,node,face)

Changed: 1153,1154c1544,1545
p: starting point coordinate of the ray
v: directional vector of the ray
p0: starting point coordinate of the ray
v0: directional vector of the ray

Changed: 1158,1160c1549,1552
t: signed distance from p to the intersection point
u: bary-centric coordinate 1 of the intersection point
v: bary-centric coordinate 2 of the intersection point
t: signed distance from p to the intersection point for each surface
triangle, if ray is parallel to the triangle, t is set to Inf
u: bary-centric coordinate 1 of all intersection points
v: bary-centric coordinate 2 of all intersection points

Changed: 1162,1163c1554,1556
users can find the IDs of the elements intersecting with the ray by
idx=find(u>=0 & v>=0 & u+v<=1.0);
idx: optional output, if requested, idx lists the IDs of the face
elements that intersects the ray; users can manually calc idx by
idx=find(u>=0 & v>=0 & u+v<=1.0 & ~isinf(t));

Added: 1207a1601,1701

function [t,u,v,idx,xnode]=raysurf(p0,v0,node,face)



[t,u,v,idx,xnode]=raysurf(p,v,node,face)
perform a Havel-styled ray tracing for a triangular surface
input:
p0: list of starting points of the rays
v0: directional vector of the rays,
node: a list of node coordinates (nn x 3)
face: a surface mesh triangle list (ne x 3)
output:
t: distance from p0 to the intersection point for each surface
triangle, if t(i)=NaN, no intersection was found for that ray
u: bary-centric coordinate 1 of all intersection points
v: bary-centric coordinate 2 of all intersection points
the final bary-centric triplet is [u,v,1-u-v]
idx: idx lists the IDs of the face elements that intersects
each ray
xnode: optional output, if requested, xnode gives the intersection
point coordinates; to compute manually, xnode=p0+repmat(t,1,3).*v0
Reference:
[1] J. Havel and A. Herout, "Yet faster ray-triangle intersection (using
SSE4)," IEEE Trans. on Visualization and Computer Graphics,
16(3):434-438 (2010)
[2] Q. Fang, "Comment on 'A study on tetrahedron-based inhomogeneous
Monte-Carlo optical simulation'," Biomed. Opt. Express, (in
press)

function val=getoptkey(key,default,varargin)



val=getoptkey(key,default,opt)
or
val=getoptkey(key,default,'key1',val1,'key2',val2, ...)
query the value of a key from a structure or a list of key/value pairs
input:
key: a string name for the target struct field name
default: the default value of the key is not found
opt: a struct object; the field names will be searched to match the
key input, opt can be a list of 'keyname'/value pairs
output:
val: val=opt.key if found, otherwise val=default

function newpt=rotatevec3d(pt,v1,u1,p0)



newpt=rotatevec3d(pt,v1,u1,p0)
rotate 3D points from one Cartesian coordinate system to another
input:
pt: 3D points defined in a standard Cartesian system where a unitary
z-vector is (0,0,1), 3 columns for x, y and z
v1: the unitary z-vector for the target coordinate system
u1: the unitary z-vector for the source coordinate system, if ignored,
u1=(0,0,1)
p0: offset of the new coordinate system, if ignored, p0=(0,0,0)
output:
newpt: the transformed 3D points

function [R,s]=rotmat2vec(u,v)



[R,s]=rotmat2vec(u,v)
the rotation matrix from vector u to v, satisfying R*u*s=v
author: Bruno Luong
URL:http://www.mathworks.com/matlabcentral/newsreader/view_original/827969
input:
u: a 3D vector in the source coordinate system;
v: a 3D vector in the target coordinate system;
output:
R: a rotation matrix to transform normalized u to normalized v
s: a scaling factor, so that R*u(:)*s=v(:)

function opt=varargin2struct(varargin)



opt=varargin2struct('param1',value1,'param2',value2,...)
or
opt=varargin2struct(...,optstruct,...)
convert a series of input parameters into a structure
input:
'param', value: the input parameters should be pairs of a string and a value
optstruct: if a parameter is a struct, the fields will be merged to the output struct
output:
opt: a struct where opt.param1=value1, opt.param2=value2 ...
license:
BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details

function val=jsonopt(key,default,varargin)



val=jsonopt(key,default,optstruct)
setting options based on a struct. The struct can be produced
by varargin2struct from a list of 'param','value' pairs
$Id: loadjson.m 371 2012-06-20 12:43:06Z fangq $
input:
key: a string with which one look up a value from a struct
default: if the key does not exist, return default
optstruct: a struct where each sub-field is a key
output:
val: if key exists, val=optstruct.key; otherwise val=default
license:
BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details

function s=mergestruct(s1,s2)



s=mergestruct(s1,s2)
merge two struct objects into one
input:
s1,s2: a struct object, s1 and s2 can not be arrays
output:
s: the merged struct object. fields in s1 and s2 will be combined in s.
license:
BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
Powered by Habitat