```{index} single: Filters; Create Surface Mesh (Surface Nets)
```
# Create Surface Mesh (Surface Nets)

## Group (Subgroup)

Surface Meshing (Generation)

## Description

This filter uses the algorithm from {1} to produce a triangle surface mesh. The code is directly based on the sample code from the paper but has been modified to
work with the simplnx library classes. This filter uses a different algorithm that aims to produce a mush that keeps sharp edges
while still producing a mesh superior to marching cubes or QuickMesh.

From the abstract of the paper:

        We extend 3D SurfaceNets to generate surfaces of segmented 3D medical images composed
        of multiple materials represented as indexed labels. Our extension generates smooth, high-
        quality triangle meshes suitable for rendering and tetrahedralization, preserves topology and
        sharp boundaries between materials, guarantees a user-specified accuracy, and is fast enough
        that users can interactively explore the trade-off between accuracy and surface smoothness.

This filter will ensure that the smallest of the 2 **FaceLabel** values will always be in the first component (component[0]). This will allow assumptions made in
downstream filters to continue to work correctly.

This filter attempts to repair the windings for a mesh. This may not be possible due to the nature of how meshes are stored in the software. See Verify Traingle Winding documentation for detailed breakdown of nuance.

---------------

![Example SurfaceNets Output](Images/SurfaceNets_Output.png)

SurfaceNets without the built-in smoothing applied

---------------

![Example SurfaceNets Output](Images/SurfaceNets_Smooth_Output.png)

SurfaceNets output **with** the built-in smoothing operation applied.

---------------

## Node Types

During the meshing process, each vertex, or node, will get a "Node Type" value assigned to it. These will range from 0 to 6. The value is an internal representation from the SurfaceNets algorithm. They are roughly equivelent to the Node Types from the Quick Surface Mesh algorithm but not strictly the same.

- Node Type = 0: This is a node that ONLY has 2 features connected to the node.
- Node Type = 2: This is a node that has 3 features connected to the node, such as a triple line
- Node Type = 3-6: These nodes have 4 or more features connected to the node.


| Node Type | Example Image                                |
|-----------|----------------------------------------------|
| 0 | ![Node Type 0](Images/SurfaceNets_NodeType_0.png)|
| 2 |  ![Node Type 2](Images/SurfaceNets_NodeType_2.png)|
| 3 |  ![Node Type 3](Images/SurfaceNets_NodeType_3.png)|
| 4 | ![Node Type 4](Images/SurfaceNets_NodeType_4.png)|
| 6 |  ![Node Type 6](Images/SurfaceNets_NodeType_6.png)|

### Exterior or Boundary Nodes

Nodes that appear on the exterior of a volume have Node Type values starting at 10 and going up from there. For instance, a triple line that is also on the exterior of the volume should have a value of 12.

![Exterior Node Types](Images/SurfaceNets_NodeType_Exterior.png)

### Exterior or Boundary Triangles

Each triangle that is created will have an 2 component attribute called `Face Labels` that represent the Feature ID on either
side of the triangle. If one of the triangles represents the border of the virtual box then one of the FaceLables will
have a value of -1.

## Notes

This filter should be used in place of the "QuickMesh Surface Filter".



### Input Parameter(s)

| Parameter Name | Parameter Type | Parameter Notes | Description |
|----------------|----------------|-----------------|-------------|
| Attempt to Make Windings Consistent | Bool |  | If true, attempts to repair the windings for the mesh. This may not be possible. See help page. |
| Apply smoothing operations | Bool |  | Use the built in smoothing operation. |
| Relaxation Iterations | Scalar Value |Int32 | Number of relaxation iterations to perform. More iterations causes more smoothing. |
| Max Distance from Voxel Center | Scalar Value |Float32 | The maximum allowable distance that a node can move from the voxel center |
| Relaxation Factor | Scalar Value |Float32 | The factor used to determine how far a node can move in each smoothing iteration |

### Input Cell Data

| Parameter Name | Parameter Type | Parameter Notes | Description |
|----------------|----------------|-----------------|-------------|
| Input Image Geometry | Geometry Selection | Image | DataPath to input Image Geometry |
| Cell Feature Ids | Array Selection | Allowed Types: int32 Comp. Shape: 1 | Specifies to which feature each cell belongs. |
| Cell Attribute Arrays to Transfer | MultiArraySelection |  | The paths to the Arrays specifying which Cell Attribute Arrays to transfer to the created Triangle Geometry |

### Input Feature Data

| Parameter Name | Parameter Type | Parameter Notes | Description |
|----------------|----------------|-----------------|-------------|
| Feature Attribute Arrays to Transfer | MultiArraySelection |  | The paths to the Arrays specifying which feature Attribute Arrays to transfer to the created Triangle Geometry |

### Output Triangle Geometry

| Parameter Name | Parameter Type | Parameter Notes | Description |
|----------------|----------------|-----------------|-------------|
| Created Triangle Geometry | DataGroupCreation |  | The name of the created Triangle Geometry |

### Output Vertex Data

| Parameter Name | Parameter Type | Parameter Notes | Description |
|----------------|----------------|-----------------|-------------|
| Vertex Data [AttributeMatrix] | DataObjectName |  | The complete path to the DataGroup where the Vertex Data of the Triangle Geometry will be created |
| Node Type | DataObjectName |  | The complete path to the Array specifying the type of node in the Triangle Geometry |

### Output Face Data

| Parameter Name | Parameter Type | Parameter Notes | Description |
|----------------|----------------|-----------------|-------------|
| Face Data [AttributeMatrix] | DataObjectName |  | The complete path to the DataGroup where the Face Data of the Triangle Geometry will be created |
| Face Labels | DataObjectName |  | The complete path to the Array specifying which Features are on either side of each Face in the Triangle Geometry |

## Example Pipelines

        Pipelines/SimplnxCore/SurfaceNets_Demo.d3dpipeline

## Citations

{1}[SurfaceNets for Multi-Label Segmentations with Preservation of Sharp Boundaries](https://jcgt.org/published/0011/01/03/paper.pdf)

## License & Copyright

`Sarah F. Frisken, SurfaceNets for Multi-Label Segmentations with Preservation of Sharp
Boundaries, Journal of Computer Graphics Techniques (JCGT), vol. 11, no. 1, 34–54, 2022`
[http://jcgt.org/published/0011/01/03](http://jcgt.org/published/0011/01/03)

## DREAM3D-NX Mailing Lists

If you need more help with a **Filter**, please consider asking your question on
the [DREAM3D-NX Users Google group!](https://groups.google.com/forum/?hl=en#!forum/dream3d-users)
