# doc-cache created by Octave 10.3.0
# name: cache
# type: cell
# rows: 3
# columns: 2
# name: <cell-element>
# type: sq_string
# elements: 1
# length: 10
brain2mesh


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

 Brain2mesh: a one-liner for human brain 3D mesh generation
 
 == Format == 
 [node,elem,face] = brain2mesh(seg,cfg); 
     or 
 [node,elem,face] = brain2mesh(seg)
 
 == 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. 
 
 == 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
 
 == Methodology ==
 The underlying methodology behind this function is described in:
 Anh Phong Tran and Qianqian Fang, "Fast and high-quality tetrahedral mesh generation \
 from neuroanatomical scans,". In: arXiv pre-print (August 2017). arXiv:1708.08954v1 [physics.med-ph]




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

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



# 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...





