Since MeshRegion
and BoundaryMeshRegion
objects already have a display form, it is fairly simple to construct a corresponding set of Graphics
box objects from them. The one tricky part is to strip out the usual blue color that is used to render region objects, since we want the new primitive to use whatever colors that have been set by graphics directives. After a bit of spelunking, it turns out that blocking a particular internal symbol will do this.
Then, we can use Simon Wood's answer about how to create new graphics primitives to have them render inside of Graphics
. Here is the code:
Typeset`MakeBoxes[m_MeshRegion, form_, Graphics] := Block[{Region`MeshInformation = {}&},
First @ ToBoxes @ m /. "MeshGraphics"->"MeshRegion"
]
Typeset`MakeBoxes[m_BoundaryMeshRegion, form_, Graphics] := Block[{Region`MeshInformation = {}&},
First @ ToBoxes @ m /. "MeshGraphics"->"BoundaryMeshRegion"
]
Blocking Region`MeshInformation
will prevent the blue region color from being inserted into the graphics boxes corresponding to the mesh regions. Here is an example (in M11.3):
Graphics[{BoundaryDiscretizeRegion[Rectangle[]]}, ImageSize->200]
If the MeshRegion
comes with custom styling, it will be retained:
Graphics[{DiscretizeRegion[Disk[{0,0}, 1], MeshCellStyle->{2->Red}]}, ImageSize->200]
Otherwise, the primitive will use the directives that have been specified:
Graphics[{Green, EdgeForm[Blue], BoundaryDiscretizeRegion[Rectangle[]]}, ImageSize->200]