# doc-cache created by Octave 10.3.0
# name: cache
# type: cell
# rows: 3
# columns: 5
# name: <cell-element>
# type: sq_string
# elements: 1
# length: 9
brain1020


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 5710

 landmarks=brain1020(node, face)
   or
 landmarks=brain1020(node, face, [], perc1, perc2)
 landmarks=brain1020(node, face, initpoints)
 landmarks=brain1020(node, face, initpoints, perc1, perc2)
 [landmarks, curves, initpoints]=brain1020(node, face, initpoints, perc1, perc2, options)

 compute 10-20-like scalp landmarks with user-specified density on a head mesh

 author: Qianqian Fang (q.fang at neu.edu)

 == Input ==
    node: full head mesh node list
    face: full head mesh element list- a 3-column array defines face list
          for the exterior (scalp) surface; a 4-column array defines the
          tetrahedral mesh of the full head.
    initpoints:(optional) one can provide the 3-D coordinates of the below
          5 landmarks: nz, iz, lpa, rpa, cz0 (cz0 is the initial guess of cz)
          initpoints can be a struct with the above landmark names
          as subfield, or a 5x3 array definining these points in the above
          mentioned order (one can use the output landmarks as initpoints)
    perc1:(optional) the percentage of geodesic distance towards the rim of 
          the landmarks; this is the first number of the 10-20 or 10-10 or
          10-5 systems, in this case, it is 10 (for 10%). default is 10.
    perc2:(optional) the percentage of geodesic distance twoards the center 
          of the landmarks; this is the 2nd number of the 10-20 or 10-10 or
          10-5 systems, which are 20, 10, 5, respectively, default is 20
    options: one can add additional 'name',value pairs to the function
          call to provide additional control. Supported optional names
          include
           'display' : [1] or 0, if set to 1, plot landmarks and curves
           'cztol' : [1e-6], the tolerance for searching cz that bisects
                   saggital and coronal reference curves
           'maxcziter' : [10] the maximum number of iterations to update
                   cz to bisect both cm and sm curves
           'baseplane' : [1] or 0, if set to 1, create the reference
                   curves along the primary control points (nz,iz,lpa,rpa)
           'minangle' : [0] if set to a positive number, this specifies
                   the minimum angle (radian) between adjacent segments in
                   the reference curves to avoid sharp turns (such as the
                   dips near ear canals), this parameter will be
                   passed to polylinesimplify to simplify the curve first.
                   Please be noted that the landmarks generated with
                   simplified curves may not land exactly on the surface.

 == Output ==
    landmarks: a structure storing all computed landmarks. The subfields
          include two sections: 
          1) 'nz','iz','lpa','rpa','cz': individual 3D positions defining
             the 5 principle reference points: nasion (nz), inion (in),
             left-pre-auricular-point (lpa), right-pre-auricular-point 
             (rpa) and vertex (cz) - cz is updated from initpoints to bisect
             the saggital and coronal ref. curves.
          2) landmarks along specific cross-sections, each cross section
             may contain more than 1 position. The cross-sections are
             named in the below format:
             2.1: a fieldname starting from 'c', 's' and 'a' indicates
                  the cut is along coronal, saggital and axial directions,
                  respectively;
             2.2: a name starting from 'pa' indicates the cut is along the
                  axial plane acrossing principle reference points
             2.3: the following letter 'm', 'a','p' suggests the 'medial',
                  'anterior' and 'posterior', respectively
             2.4: the last letter 'l' or 'r' suggests the 'left' and
                  'right' side, respectively
             2.5: non-medial coronal cuts are divided into two groups, the
                  anterior group (ca{l,r}) and the posterior group
                  (cp{lr}), with a number indicates the node spacing 
                  stepping away from the medial plane.

             for example, landmarks.cm refers to the landmarks along the
                  medial-coronal plane, anterior-to-posteior order
             similarly, landmarks.cpl_3 refers to the landmarks along the
                  coronal (c) cut plane located in the posterior-left side
                  of the head, with 3 saggital landmark spacing from the
                  medial-coronal reference curve.
    curves: a structure storing all computed cross-section curves. The
             subfields are named similarly to landmarks, except that
             landmarks stores the 10-? points, and curves stores the
             detailed cross-sectional curves
    initpoints: a 5x3 array storing the principle reference points in the
             orders of 'nz','iz','lpa','rpa','cz'

 
 == Example ==
 See brain2mesh/examples/SPM_example_brain.m for an example
 https://github.com/fangq/brain2mesh/blob/master/examples/SPM_example_brain.m

 == Dependency ==
 This function requires a pre-installed Iso2Mesh Toolbox
  Download URL: http://github.com/fangq/iso2mesh
  Website: http://iso2mesh.sf.net

 == Reference ==
 If you use this function in your publication, the authors of this toolbox
 apprecitate if you can cite the below paper

  Anh Phong Tran, Shijie Yan and Qianqian Fang, "Improving model-based
  fNIRS analysis using mesh-based anatomical and light-transport models,"
  Neurophotonics, 7(1), 015008, 2020 
  URL: http://dx.doi.org/10.1117/1.NPh.7.1.015008


 -- this function is part of brain2mesh toolbox (http://mcx.space/brain2mesh)
    License: GPL v3 or later, see LICENSE.txt for details




# name: <cell-element>
# type: sq_string
# elements: 1
# length: 80

 landmarks=brain1020(node, face)
   or
 landmarks=brain1020(node, face, [], ...



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 10
brain2mesh


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 4278

 Brain2mesh: a one-liner for human brain 3D mesh generation

 Author: Qianqian Fang <q.fang at neu.edu>
 Other contributors: see AUTHORS.txt for details
 Version: 0.8
 URL: http://mcx.space/brain2mesh
 License: GPL version 3
 Reference: 
  Anh Phong Tran, Shijie Yan and Qianqian Fang, "Improving model-based
  fNIRS analysis using mesh-based anatomical and light-transport models,"
  Neurophotonics, 7(1), 015008, URL: http://dx.doi.org/10.1117/1.NPh.7.1.015008
 
 == Format == 
 [node,elem,face] = brain2mesh(seg)
     or 
 [node,elem,face] = brain2mesh(seg,cfg); 
 
 == Input ==
      seg: pre-segmented brain volume (supporting both probalistic tissue 
           segmentation and labeled volume). Two formats are accepted
           1. a structure with subfields (wm,gm,csf,skull,scalp)
              e.g.: seg.wm, seg.gm, seg.csf represents the white-matter, 
              gray-matter and csf segmentaions, respectively,
                  or 
           2. a 4D array for with tissued sorted in outer-to-inner order
              the 4th dimension of the array can 3-6, with the following assumptions
              size(seg,4) == 6 assumes 1-Scalp, 2-Skull, 3-CSF, 4-GM, 5-WM, 6-air pockets
              size(seg,4) == 5 assumes 1-Scalp, 2-Skull, 3-CSF, 4-GM, 5-WM
              size(seg,4) == 4 assumes 1-Scalp, 2-CSF, 3-GM, 4-WM
              size(seg,4) == 3 assumes 1-CSF, 2-GM, 3-WM

      cfg: a struct defining the options for the resulting tetrahedral mesh
          default values are applied if field is not defined
          cfg.radbound.{wm,gm,csf,skull,scalp}
             Radius of the Delaunay sphere used in the sampling the surfaces.
             Default values are 1.7, 1.7, 2, 2.5 and 3, respectively (reference values for 1x1x1mm^3)
             Scale proportionally for denser volumes. Lower values correspond to denser, higher
             fidelity surface extraction, but also results in denser meshes.
          cfg.maxnode: [100000] - when  the value cfg.sampling__ creates surfaces that are too 
             dense. This limits the maximum of number of nodes extracted for a given surface.
          cfg.maxvol: [100] indicates the volumetric maximum size of elements
             Lowering this value helps with obtaining a denser tetrahedral
             mesh. For dense meshes, values close to 3-5 are recommended.
          cfg.smooth: [0] - number of iterations to smooth each tissue surface
          cfg.ratio: [1.414] radius-edge ratio. Lower values increase 
             the quality of tetrahedral elements, but results in denser meshes
          cfg.dorelabel: [0] or 1 - This step removes most of the assumptions 
             created by the layered meshing workflow. Currently only works if all five tissue types are present.
             When deactivated, a 1 voxel length gap is assumed between each of the tissue layers.
          cfg.doairseg: 0 or [1]. Within the skull layer, additional segmentations can be found. 
             By default, these regions are merged to the skull because they can be ambiguously be
             vessels or air. When the option 1 is chosen, these regions are labeled as air instead.
          cfg.dotruncate: 0 or [1]. by default, the mesh is truncated a few pixel in the 
             +z direction below the lowest pixel containing CSF to focus on the brain areas. 
             A value of 0 gives a complete head mesh. 
          cfg.imfill: ['imfill'], 'mri_fillholes' etc, the function name
             for 3D image hole-filling function, default is imfill,
             requires MATLAB image processing toolbox or octave-image
             toolbox

 == Outputs ==
      node: node coordinates of the tetrahedral mesh
      elem: element list of the tetrahedral mesh / the last column denotes the boundary ID
      face: mesh surface element list of the tetrahedral mesh 
      
 Tissue ID for the outputs are as follow:
 0-Air/background, 1-Scalp, 2-Skull, 3-CSF, 4-GM, 5-WM, 6-air pockets
 
 == Reference ==
 If you use Brain2Mesh in your publication, the authors of this toolbox
 apprecitate if you can cite our Neurophotonics paper listed above.


 -- this function is part of brain2mesh toolbox (http://mcx.space/brain2mesh)
    License: GPL v3 or later, see LICENSE.txt for details




# name: <cell-element>
# type: sq_string
# elements: 1
# length: 60

 Brain2mesh: a one-liner for human brain 3D mesh generation



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 15
intriangulation


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1987
 intriangulation: Test points in 3d wether inside or outside a (closed) triangulation
 usage: in = intriangulation(vertices,faces,testp,heavytest)

 arguments: (input)
  vertices   - points in 3d as matrix with three columns

  faces      - description of triangles as matrix with three columns.
               Each row contains three indices into the matrix of vertices
               which gives the three cornerpoints of the triangle.

  testp      - points in 3d as matrix with three columns

  heavytest  - int n >= 0. Perform n additional randomized rotation tests.

 IMPORTANT: the set of vertices and faces has to form a watertight surface!

 arguments: (output)
  in - a vector of length size(testp,1), containing 0 and 1.
       in(nr) =  0: testp(nr,:) is outside the triangulation
       in(nr) =  1: testp(nr,:) is inside the triangulation
       in(nr) = -1: unable to decide for testp(nr,:) 

 Thanks to Adam A for providing the FEX submission voxelise. The
 algorithms of voxelise form the algorithmic kernel of intriangulation.

 Thanks to Sven to discussions about speed and avoiding problems in
 special cases.

 Example usage:

      n = 10;
      vertices = rand(n, 3)-0.5; % Generate random points
      tetra = delaunayn(vertices); % Generate delaunay triangulization
      faces = freeBoundary(TriRep(tetra,vertices)); % use free boundary as triangulation
      n = 1000;
      testp = 2*rand(n,3)-1; % Generate random testpoints
      in = intriangulation(vertices,faces,testp);
      % Plot results
      h = trisurf(faces,vertices(:,1),vertices(:,2),vertices(:,3));
      set(h,'FaceColor','black','FaceAlpha',1/3,'EdgeColor','none');
      hold on;
      plot3(testp(:,1),testp(:,2),testp(:,3),'b.');
      plot3(testp(in==1,1),testp(in==1,2),testp(in==1,3),'ro');

 See also: intetrahedron, tsearchn, inpolygon

 Author: Johannes Korsawe, heavily based on voxelise from Adam A.
 E-mail: johannes.korsawe@volkswagen.de
 Release: 1.3
 Release date: 25/09/2013



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 80
 intriangulation: Test points in 3d wether inside or outside a (closed) trian...



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 9
label2tpm


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 807

 seg=label2tpm(vol)
   or
 seg=label2tpm(vol, names)

 converting a multi-lable volume to binary tissue probablistic maps (TPMs) 

 author: Qianqian Fang (q.fang at neu.edu)

 input:
    vol: a 2-D or 3-D array of integer values.
    names (optional): a cell array of strings defining the names of each label,
         alternatively, a containers.Map object with label (integer) as
         the key and name as the value. The names can be a subset of all
         labels.

 output:
    seg: a struct with subfields of 3D or 4D uint8 array; the subfield 
         names are defined via the optional names input; the unnamed
         labels will be named as 'label_#'. 

 -- this function is part of brain2mesh toolbox (http://mcx.space/brain2mesh)
    License: GPL v3 or later, see LICENSE.txt for details




# name: <cell-element>
# type: sq_string
# elements: 1
# length: 53

 seg=label2tpm(vol)
   or
 seg=label2tpm(vol, names)



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 9
tpm2label


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 1073

 vol=tpm2label(seg)
   or
 vol=tpm2label(seg, segorder)
 [vol, names]=tpm2label(seg, segorder)

 converting tissue probablistic maps (TPMs) to a multi-lable volume

 author: Qianqian Fang (q.fang at neu.edu)

 input:
    seg: a struct, a cell array, or a 3D or 4D array; if seg is a cell
         or a struct, their subfields must be 2D/3D arrays of the same
         sizes;
    segorder: if seg is a struct, segorder allows one to assign output
         labels using customized order instead of the creation order

 output:
    vol: a 2-D or 3-D array of the same type/size of the input arrays. The
         label for each voxel is determined by the index to the highest
         value in TPM of the same voxel. If a voxel is a background voxel
         - i.e. zeros for all TPMs, it stays 0
    names: a cell array storing the names of the labels (if input is a
         struct), the first string is the name for label 1, and so on

 -- this function is part of brain2mesh toolbox (http://mcx.space/brain2mesh)
    License: GPL v3 or later, see LICENSE.txt for details




# name: <cell-element>
# type: sq_string
# elements: 1
# length: 80

 vol=tpm2label(seg)
   or
 vol=tpm2label(seg, segorder)
 [vol, names]=tpm2la...





