The MESH_MERGE function merges two polygonal meshes.
Syntax
Result = MESH_MERGE (Verts, Conn, Verts1, Conn1 [, /COMBINE_VERTICES] [, TOLERANCE=value] )
Return Value
The function return value is the number of triangles in the modified polygonal mesh connectivity array.
Arguments
Verts
Input/Output array of polygonal vertices [3, n]. These are potentially modified and returned to the user. If either Verts or Verts1 is a double precision array then IDL uses double precision for the computations and returns a double-precision array. Otherwise, IDL uses single precision for the computations and returns a single-precision array.
Conn
Input/Output polygonal mesh connectivity array. This array is modified and returned to the user.
Verts1
Additional input polygonal vertex array [3, n].
Conn1
Additional input polygonal mesh connectivity array.
Keywords
COMBINE_VERTICES
If this keyword is set, the routine will attempt to collapse vertices which are at the same location in space into single vertices. If the expression
is true, the points (i) and (i+1) can be collapsed into a single vertex. The result is returned as a modification of the Verts argument.
TOLERANCE
This keyword is used to specify the tolerance value used with the COMBINE_VERTICES keyword. The default value is 1e-8.
Examples
This example merges two simple meshes: a single square and a single right triangle. The right side of the square is in the same location as the left side of the triangle. Each mesh is originally its own polygon object. These objects are then added to a model object. The model is displayed in the XOBJVIEW utility. The XOBJVEW utility allows you to click-and-drag the polygon object to rotate and translate it. See XOBJVIEW for more information on this utility.
When you quit out of the first XOBJVIEW display, the second XOBJVIEW display will appear. The meshes are merged into a single polygon object. After you quit out of the second display, the final display shows the results of decimating the merged mesh to obtain the least number connections for these vertices. Decimation can often be used to refine the results of merging.
This example is split into several parts; click on each section to enter the code at the IDL command line.
vertices = [[-2., -1., 0.], [0., -1., 0.], $
[0., 1., 0.], [-2., 1., 0.]]
connectivity = [4, 0, 1, 2, 3]
triangleVertices = [[0., -1., 0.], [2., -1., 0.], $
[0., 1., 0.]]
triangleConnectivity = [3, 0, 1, 2]
oModel = OBJ_NEW('IDLgrModel')
oPolygon = OBJ_NEW('IDLgrPolygon', vertices, $
POLYGONS = connectivity, COLOR = [0, 128, 0], $
STYLE = 1)
oTrianglePolygon = OBJ_NEW('IDLgrPolygon', $
triangleVertices, POLYGONS = triangleConnectivity, $
COLOR = [0, 0, 255], STYLE = 1)
oModel->Add, oPolygon
oModel->Add, oTrianglePolygon
XOBJVIEW, oModel, /BLOCK, $
TITLE = 'Two Separate Meshes'
numberTriangles = MESH_MERGE(vertices, $
connectivity, triangleVertices, $
triangleConnectivity, /COMBINE_VERTICES)
numberVertices = SIZE(vertices, /DIMENSIONS)
PRINT, 'numberVertices = ', numberVertices[1]
PRINT, 'numberTriangles = ', numberTriangles
OBJ_DESTROY, [oTrianglePolygon]
oPolygon->SetProperty, DATA = vertices, $
POLYGONS = connectivity, COLOR = [0, 128, 128]
XOBJVIEW, oModel, /BLOCK, $
TITLE = 'Result of Merging the Meshes into One'
numberTriangles = MESH_DECIMATE(vertices, connectivity, $
decimatedConnectivity, PERCENT_POLYGONS = 75)
PRINT, 'After Decimation: numberTriangles = ', numberTriangles
oPolygon->SetProperty, DATA = vertices, $
POLYGONS = decimatedConnectivity, COLOR = [0, 0, 0]
XOBJVIEW, oModel, /BLOCK, $
TITLE = 'Decimation of Mesh'
OBJ_DESTROY, [oModel]
The results for this example are shown in the following figure: original, separate meshes (left), merged mesh (center) and decimated mesh (right).
Version History
5.5 |
Introduced |
8.6 |
Add support for double-precision input. |
See Also
MESH_CLIP, MESH_DECIMATE, MESH_ISSOLID, MESH_NUMTRIANGLES, MESH_OBJ, MESH_SMOOTH, MESH_SURFACEAREA, MESH_VALIDATE, MESH_VOLUME