# What are some useful (or hidden) properties of MeshRegion?

There is quite a bit of powerful functionality built in to MeshRegion, but it seems to be lacking in some areas. For example: extracting a list of edges that live on the boundary, or an adjacency list of cell connectivity, etc. There appears to be quite a few of these properties hidden inside of MeshRegion:

mr = MeshRegion[{{0, 0}, {1, 0}, {2, 0}, {0, 1}, {1, 1}, {2,
1}}, {Polygon[{1, 2, 5, 4}], Polygon[{3, 6, 5, 2}]}]

mrProps = mr["Properties"]


For comparison, using properties with SparseArray is well documented What are SparseArray Properties? How and when should they be used?. But, trying to use the same notation on a MeshRegion doesn't appear to work:

mr["BoundaryCells"]


Any thoughts on this, or other useful tips/tricks on using MeshRegion would prove helpful.

Edit:

Unfortunately there is no method "Methods" in MeshRegion, so instead here are the outputs to mr["Properties"] instead:

• Looking at what's in "MethodInformation" might clue you in on how to use it. – J. M. is away Jun 6 '15 at 21:40
• Maybe I don't know how to use "MethodInformation" correctly, but it doesn't seem that MeshRegion has such a method. – leibs Jun 6 '15 at 22:01
• Well, can you post the output of mr["Methods"] for reference? – J. M. is away Jun 6 '15 at 22:04
• @J. M. I've edited the post to include this output due to character limits in the comment section. – leibs Jun 6 '15 at 22:52
• @leibs Adding them to the question is preferred anyway, so thanks. – Michael E2 Jun 7 '15 at 0:01

First, it would seem there is a fair amount to say.

On the other hand, there is even more not to say, as this shows all the unimplemented properties (both regions give the same result):

mr = DiscretizeRegion@Disk[];
(* mr = DiscretizeRegion@ImplicitRegion[1/4 <= x^2 + y^2 <= 1, {x, y}] *)

Pick[mr["Properties"],
Quiet@Check[mr[#], Missing[#]] & /@ mr["Properties"],
_Missing | With[{mr = mr}, HoldPattern[mr[_]]]]

(* 142 missing/unimplemented properties: {"AbsoluteDimension", "AdjacencyMatrix", "AlternateVertexCoordinates", "Boundary", "BoundaryCellFaceConnectivity", "BoundaryCells", "BoundaryCellsIds", "BoundaryCellsRenderingPrimitives", "BoundaryEdges", "BoundaryFaces", "BoundaryGroups", "BoundaryMeshObject", "BoundaryNesting", "BoundaryPolygons", "BoundaryVertices", "BoundingBox", "BSPTree", "Centroid", "ClearRepresentation", "CompGeomData", "ConnectedEdges", "ConnectedElements", "ConnectedFaces", "ConnectedVertices", "Connectivity", "ConnectivityMatrix", "ConvexHullVolume", "Coordinates", "DataLabels", "Dimension", "EdgeCoordinates", "EdgeCount", "EdgeEdgeConnectivity", "EdgeFaceConnectivity", "EdgeFaceConnectivityRules", "EdgeLabelRules", "EdgeLengths", "EdgeRules", "Edges", "EdgesIDs", "EdgesRules", "EdgeVertexConnectivity", "EdgeVertexConnectivityRules", "Elements", "FaceAreas", "FaceCoordinates", "FaceCount", "FaceEdgeConnectivity", "FaceEdgeConnectivityRules", "FaceEdgesCount", "FaceFaceConnectivity", "FaceOutline", "Faces", "FacesClosed", "FacesIDs", "FacesRules", "FaceVertexConnectivity", "FaceVertexConnectivityClosed", "FaceVertexConnectivityRules", "Frontier", "GatherCellsByPropertyValue", "Graphics", "Graphics3D", "GraphicsComplex", "HalfEdgeRules", "Index", "IndexedBoundaryPolygons", "InnerBoundary", "InnerFaces", "InputForm", "Interior", "InteriorBoundary", "InteriorEdges", "InteriorFaces", "InteriorVertices", "MakeRepresentation", "Measure", "MeshBoundaryElements", "MeshCellCount", "MeshCells", "MeshConnectivity", "MeshConnectivityRules", "MeshCoordinates", "MeshElementCount", "MeshElements", "MeshElementsData", "MeshElementsDataRule", "MeshElementsIds", "MeshElementsMarker", "MeshElementsMarkerRules", "MeshElementsProperty", "MeshElementsPropertyRules", "MeshElementsQuality", "MeshElementsQualityRules", "MeshElementsTags", "MeshLinesEdges", "MeshLinesElementsTags", "MeshLinesVertices", "MeshMulticells", "MeshObjectID", "MeshSimpleLinesEdges", "MeshSimpleLinesVertices", "Normals", "OuterBoundary", "OuterFaces", "ParameterCoordinates", "Persistence", "PointInFaces", "PropertyBoundary", "PropertyValueCells", "RawCoordinates", "RegionCentroid", "RegionDimension", "RegionEmbeddingDimension", "RegionMeasure", "RegularFacesIds", "SetDimension", "SetMeshElementsMarker", "SetMeshElementsProperty", "SetRegionSpecification", "SimpleVertices", "SolidCoordinates", "SolidCount", "SolidsIDs", "SparseAdjacencyMatrix", "SparseConnectivity", "SpatialTree", "StrictBoundaryFaces", "StrictInteriorFaces", "TotalArea", "VertexCoordinateRules", "VertexCoordinates", "VertexCount", "VertexEdgeConnectivity", "VertexEdgeConnectivityRules", "VertexFaceConnectivity", "VertexFaceConnectivityRules", "VertexIDs", "VertexNormals", "VertexVertexConnectivity", "VertexVertexConnectivityRules", "WingData"} *)


Here's what left:

Complement[mr["Properties"], %]
(*
{"ComponentDimensions", "DeepCopy", "GetRegionSpecification",
"MakeLinear", "MeshCellTypes", "MeshOrder", "Properties",
"RegionHoles", "Representations", "Show", "SimplexMeshQ"}
*)


They are fairly self-explanatory, I think. I don't know if "DeepCopy" is the sort of deep copy talked about in this answer, where a copy of each element (instead of a pointer) is made.

My own opinion is that these properties may be harbingers of things to come.

• thank you for doing this.+1 of course :) – ubpdqn Jun 7 '15 at 0:16
• This was my fear. I guess we will have to wait a bit longer for this functionality. Hopefully the wait won't be long as the unimplemented properties are precisely what I need. – leibs Jun 7 '15 at 0:31
• @leibs, perhaps using ElementMesh is an option for you, that has quite a few properties implemented and documented. – user21 Jun 8 '15 at 7:29
• Great suggestion. ElementMesh looks to be much closer to the object I am looking for. I'll poke around and see what all it can do. – leibs Jun 9 '15 at 16:44
• @leibs You need to put "@user21", or he might not be notified of your reply (as I did here with your id, but you can put only one "@user" in a comment). – Michael E2 Jun 9 '15 at 16:48

I want to add some more information to this post after seeing the answer of Chip Hurst to the question How to obtain the cell-adjacency graph of a mesh. Unfortunately this is a bit longer than a comment so I put it as an answer. I would of course be happy to delete this if this is superfluous or reformulate as another question depending on what people think.

It seems that although many of the properties highlighted in Michael E2's answer to this question are flagged as being missing or unimplemented, there are several that still give results that are useful (and faster than self-coded alternatives!).

A good example is the linked answer to speed up the calculation of the cell-adjacency list of a mesh. This uses the undocumented function mesh["ConnectivityMatrix"[2,1]], which returns a sparse array of dimensions (number of faces x number of edges) which gives non-zero values, _ when a given face is connected to a given edge. Chip Hurst's answer shows that if mesh["ConnectivityMatrix"[2,1]] is multiplied by its transpose then one gets the adjacency matrix of faces of a mesh.

The parameters a and b of the mesh["ConnectivityMatrix"[a,b]], I think correspond to the dimensionality of the different parts of the mesh, so for example:

mesh["ConnectivityMatrix"[1,0]] gives a sparse matrix whose non-zero elements give which edge is connected to which vertex. This in the same way can be used to calculate the connectivity of edges. or can be used to calculate the connectivity of vertices (via edges).
mesh["ConnectivityMatrix"[2,0]] gives a sparse matrix whose non-zero elements give which face is connected to which vertex. This can in the same way be used to calculate the connectivity of faces on a mesh, or can be used to calculate the connectivity of vertices (via faces).

This ConnectivityMatrix seems to work for both 2D and 3D meshes, however other "Properties" such as "Connectivity" or "FaceFaceConnectivity" give only results for meshes in 2D (as pointed out in a comment by Henrik Schumacher). Furthermore it seems that some of the properties i.e. "FaceFaceConnectivity" come up with an alternative labelling system compared to the input mesh, which is difficult to interpret.

To conclude:

• the ConnectivityMatrix is one clear example where a hidden property can be very helpful in providing a huge speed up in calculating some properties of meshes.
• Other properties give outputs only for 2D meshes and not meshes embedded in 3D, perhaps MichaelE2's answer can be modified to test this automatically.
• It seems like some of the output uses a different labelling system for vertices, edges, and faces of a mesh, which to me is not clear.

• I think it would be worthwhile to systematically document this functionality (hence this extended comment or half-answer), although I am not too sure of the best approach to do it. Again feel free to suggest that this post be moved / deleted or reformulated as a question, but I think many people could benefit especially in terms of speed for certain problems if this information was more accessible.