Ejemplo n.º 1
0
def create_mesh(**kwargs):
    mtb = MeshTraitsBuilder.getDefault3D()
    if kwargs.get('recordFile'):
        mtb.addTraceRecord()
    mtb.addNodeSet()
    mesh = Mesh(mtb)
    if kwargs.get('recordFile'):
        mesh.getTrace().setDisabled(True)
    MeshReader.readObject3D(mesh, kwargs['in_dir'])
    return mesh
Ejemplo n.º 2
0
def create_mesh(**kwargs):
    mtb = MeshTraitsBuilder.getDefault3D()
    if kwargs.get('recordFile'):
        mtb.addTraceRecord()
    mtb.addNodeSet()
    mesh = Mesh(mtb)
    if kwargs.get('recordFile'):
        mesh.getTrace().setDisabled(True)
    MeshReader.readObject3D(mesh, kwargs['in_dir'])
    return mesh
Ejemplo n.º 3
0
def remesh(**kwargs):
    """Remesh beams of an existing mesh with a singular analytical metric

    It is necessary to remove J_ and G_ groups for wires.
    """
    # Build background mesh
    try:
        liaison = kwargs["liaison"]
    except KeyError:
        mtb = MeshTraitsBuilder.getDefault3D()
        mtb.addNodeSet()
        mesh = Mesh(mtb)
        MeshReader.readObject3D(mesh, kwargs["in_dir"])
        liaison = MeshLiaison.create(mesh, mtb)
    immutable_groups = list()
    if kwargs["immutable_groups_file"]:
        f = open(kwargs["immutable_groups_file"])
        immutable_groups = f.read().split()
        f.close()
        liaison.mesh.tagGroups(immutable_groups, AbstractHalfEdge.IMMUTABLE)
    liaison = remesh_beams(liaison, kwargs["size"], kwargs["rho"], immutable_groups, kwargs["point_metric_file"])
    # Output
    MeshWriter.writeObject3D(liaison.getMesh(), kwargs["out_dir"], "")
Ejemplo n.º 4
0
def remesh_beams(liaison, size, rho, immutable_groups, point_metric_file=None):
    # immutable groups
    # wire metric
    metric = None
    if point_metric_file is not None:
        metric_type = check_metric_type(point_metric_file)
        if metric_type == "singular":
            if rho > 1.0:
                # mixed metric
                metric = SingularMetric(size, point_metric_file, rho, True)
            else:
                # analytic metric
                metric = SingularMetric(size, point_metric_file)
        else:
            metric = DistanceMetric(size, point_metric_file)
    polylines = PolylineFactory(liaison.mesh, 135.0, size * 0.2)
    liaison.mesh.resetBeams()
    for entry in polylines.entrySet():
        groupId = entry.key
        for polyline in entry.value:
            if point_metric_file is None:
                metric = ArrayList()
                for v in polyline:
                    metric.add(EuclidianMetric3D(size))
            if liaison.mesh.getGroupName(groupId) in immutable_groups:
                result = polyline
            else:
                result = RemeshPolyline(liaison.mesh, polyline, metric).compute()
            for i in xrange(result.size() - 1):
                liaison.mesh.addBeam(result.get(i), result.get(i + 1), groupId)
    # redefine liaison to remove orphan nodes
    mesh = liaison.getMesh()
    mtb = MeshTraitsBuilder.getDefault3D()
    mtb.addNodeSet()
    liaison = MeshLiaison.create(mesh, mtb)
    return liaison
Ejemplo n.º 5
0
Archivo: refine.py Proyecto: alclp/jCAE
                  action="store_true", dest="immutable_border",
                  help="Tag free edges as immutable")
parser.add_option("--record", metavar="PREFIX",
                  action="store", type="string", dest="recordFile",
                  help="record mesh operations in a Python file to replay this scenario")

(options, args) = parser.parse_args(args=sys.argv[1:])

if len(args) != 2:
	parser.print_usage()
	sys.exit(1)

xmlDir = args[0]
outDir = args[1]

mtb = MeshTraitsBuilder.getDefault3D()
if options.recordFile:
	mtb.addTraceRecord()
mtb.addNodeSet()
mesh = Mesh(mtb)
if options.recordFile:
	mesh.getTrace().setDisabled(True)
MeshReader.readObject3D(mesh, xmlDir)

liaison = MeshLiaison.create(mesh, mtb)
if options.recordFile:
	liaison.getMesh().getTrace().setDisabled(False)
	liaison.getMesh().getTrace().setLogFile(options.recordFile)
	liaison.getMesh().getTrace().createMesh("mesh", liaison.getMesh())
if options.immutable_border:
	liaison.mesh.tagFreeEdges(AbstractHalfEdge.IMMUTABLE)
Ejemplo n.º 6
0
    type="float",
    dest="coplanarity",
    help=
    "minimum dot product of face normals when building feature edges (default 0.95)"
)

(options, args) = parser.parse_args(args=sys.argv[1:])

if len(args) != 2:
    parser.print_usage()
    sys.exit(1)

xmlDir = args[0]
outDir = args[1]

mtb = MeshTraitsBuilder.getDefault3D()
mtb.addNodeSet()
mesh = Mesh(mtb)
MeshReader.readObject3D(mesh, xmlDir)
liaison = MeshLiaison.create(mesh, mtb)

if options.coplanarity:
    liaison.getMesh().buildRidges(options.coplanarity)
if options.preserveGroups:
    liaison.getMesh().buildGroupBoundaries()

opts = HashMap()
if options.coplanarity:
    opts.put("coplanarity", str(options.coplanarity))
opts.put("checkNormals", str("false"))
ImproveVertexValence(liaison, opts).compute()
Ejemplo n.º 7
0
if len(args) != 2:
	parser.print_usage()
	sys.exit(1)

vtpFile = args[0]
outDir = args[1]

Utils.loadVTKLibraries()
reader = vtkXMLPolyDataReader()
reader.SetFileName(vtpFile)
reader.Update()
 
polydata = reader.GetOutput()

mesh = Mesh(MeshTraitsBuilder())
vertices = jarray.zeros(polydata.GetNumberOfPoints(), Vertex)
coord = jarray.zeros(3, "d")
for i in xrange(len(vertices)):
	polydata.GetPoint(i, coord)
	vertices[i] = mesh.createVertex(coord)

indices = Utils.getValues(polydata.GetPolys())
i = 0
while i < len(indices):
	if (indices[i] == 3):
		mesh.add(mesh.createTriangle(
			vertices[indices[i+1]],
			vertices[indices[i+2]],
			vertices[indices[i+3]]))
	i += indices[i] + 1
Ejemplo n.º 8
0
def read_mesh(path):
    mtb = MeshTraitsBuilder.getDefault3D()
    mtb.addNodeSet()
    mesh = Mesh(mtb)
    MeshReader.readObject3D(mesh, path)
    return mesh
Ejemplo n.º 9
0
def read_mesh(path):
    mtb = MeshTraitsBuilder.getDefault3D()
    mtb.addNodeSet()
    mesh = Mesh(mtb)
    MeshReader.readObject3D(mesh, path)
    return mesh
Ejemplo n.º 10
0
from org.jcae.mesh.amibe.ds import Mesh
from org.jcae.mesh.amibe.traits import MeshTraitsBuilder
from org.jcae.mesh.amibe.algos3d import RandomizeGroups
from org.jcae.mesh.xmldata import *
from optparse import OptionParser
import sys

cmd=("random  ", "<dir>", "Put random triangles in a given group.")
parser = OptionParser(usage="amibebatch %s [OPTIONS] %s\n\n%s" % cmd,	prog="random")
parser.add_option("-r", "--ratio", metavar="FLOAT", default=0.03, action="store",
                  type="float", dest="ratio",
                  help="The ratio of triangles to put in the new group")
parser.add_option("-n", "--name", metavar="STRING", action="store",
                  type="string", dest="group_name", default="random",
                  help="""The name of group to be created.""")

(options, args) = parser.parse_args(args=sys.argv[1:])

if len(args) != 1:
	parser.print_usage()
	sys.exit(1)

mesh = Mesh(MeshTraitsBuilder.getDefault3D())
xmlDir = args[0]
MeshReader.readObject3D(mesh, xmlDir)
RandomizeGroups(options.ratio, options.group_name).compute(mesh, True)
MeshWriter.writeObject3D(mesh, xmlDir, None)
Ejemplo n.º 11
0
                  help="Project new vertices onto approximated surface")
parser.add_option("-c", "--coplanarity", metavar="FLOAT",
                  action="store", type="float", dest="coplanarity",
                  help="dot product of face normals to detect feature edges")

(options, args) = parser.parse_args(args=sys.argv[1:])

if len(args) != 2:
	parser.print_usage()
	sys.exit(1)

xmlDir = args[0]
outDir = args[1]

# Original mesh will be treated as a background mesh
background_mtb = MeshTraitsBuilder.getDefault3D()
background_mtb.addNodeSet()
background_mesh = Mesh(background_mtb)
MeshReader.readObject3D(background_mesh, xmlDir)
if options.coplanarity:
	background_mesh.buildRidges(options.coplanarity)

# New mesh must not have connectivity
new_mtb = MeshTraitsBuilder()
new_mtb.addTriangleList()
new_mtb.addNodeList()
new_mesh = Mesh(new_mtb)

for point in background_mesh.getNodes():
	new_mesh.add(point)
Ejemplo n.º 12
0
def remesh(**kwargs):
    """
    Remesh an existing mesh with a singular analytical metric
    """
    # Process coplanarity options
    coplanarity = cos(kwargs["coplanarityAngle"] * pi / 180.0)
    if kwargs["coplanarity"]:
        coplanarity = kwargs["coplanarity"]

    safe_coplanarity = kwargs["safe_coplanarity"]
    if safe_coplanarity is None:
        safe_coplanarity = 0.8
    safe_coplanarity = max(coplanarity, safe_coplanarity)

    # Build background mesh
    try:
        liaison = kwargs["liaison"]
    except KeyError:
        mtb = MeshTraitsBuilder.getDefault3D()
        if kwargs["recordFile"]:
            mtb.addTraceRecord()
        mtb.addNodeSet()
        mesh = Mesh(mtb)
        if kwargs["recordFile"]:
            mesh.getTrace().setDisabled(True)

        MeshReader.readObject3D(mesh, kwargs["in_dir"])
        liaison = MeshLiaison.create(mesh, mtb)

    if kwargs["recordFile"]:
        liaison.getMesh().getTrace().setDisabled(False)
        liaison.getMesh().getTrace().setLogFile(kwargs["recordFile"])
        liaison.getMesh().getTrace().createMesh("mesh", liaison.getMesh())
    if kwargs["immutable_border"]:
        liaison.mesh.tagFreeEdges(AbstractHalfEdge.IMMUTABLE)
    liaison.getMesh().buildRidges(coplanarity)
    if kwargs["preserveGroups"]:
        liaison.getMesh().buildGroupBoundaries()

    immutable_groups = []
    if kwargs["immutable_groups_file"]:
        f = open(kwargs["immutable_groups_file"])
        immutable_groups = f.read().split()
        f.close()
        liaison.mesh.tagGroups(immutable_groups, AbstractHalfEdge.IMMUTABLE)

    if kwargs["recordFile"]:
        cmds = [
            String("assert self.m.checkNoDegeneratedTriangles()"),
            String("assert self.m.checkNoInvertedTriangles()"),
            String("assert self.m.checkVertexLinks()"),
            String("assert self.m.isValid()"),
        ]
        liaison.getMesh().getTrace().setHooks(cmds)

    # Decimate
    if kwargs["decimateSize"] or kwargs["decimateTarget"]:
        decimateOptions = HashMap()
        if kwargs["decimateSize"]:
            decimateOptions.put("size", str(kwargs["decimateSize"]))
        elif kwargs["decimateTarget"]:
            decimateOptions.put("maxtriangles", str(kwargs["decimateTarget"]))
        decimateOptions.put("coplanarity", str(safe_coplanarity))
        QEMDecimateHalfEdge(liaison, decimateOptions).compute()
        swapOptions = HashMap()
        swapOptions.put("coplanarity", str(safe_coplanarity))
        SwapEdge(liaison, swapOptions).compute()

    # Metric
    if kwargs["rho"] > 1.0:
        # mixed metric
        metric = SingularMetric(kwargs["sizeinf"], kwargs["point_metric_file"],
                                kwargs["rho"], True)
    else:
        # analytic metric
        metric = SingularMetric(kwargs["sizeinf"], kwargs["point_metric_file"])

    # Remesh Skeleton
    if kwargs["skeleton"]:
        RemeshSkeleton(liaison, 1.66, metric, 0.01).compute()

    # Remesh
    refineOptions = HashMap()
    refineOptions.put("size", str(kwargs["sizeinf"]))
    refineOptions.put("coplanarity", str(safe_coplanarity))
    refineOptions.put("nearLengthRatio", str(kwargs["nearLengthRatio"]))
    refineOptions.put("project", "false")
    if kwargs["allowNearNodes"]:
        refineOptions.put("allowNearNodes", "true")
    refineAlgo = Remesh(liaison, refineOptions)
    refineAlgo.setAnalyticMetric(metric)
    refineAlgo.compute()

    if not kwargs["noclean"]:
        # Swap
        swapOptions = HashMap()
        swapOptions.put("coplanarity", str(safe_coplanarity))
        swapOptions.put("minCosAfterSwap", "0.3")
        SwapEdge(liaison, swapOptions).compute()

        # Improve valence
        valenceOptions = HashMap()
        valenceOptions.put("coplanarity", str(safe_coplanarity))
        valenceOptions.put("checkNormals", "false")
        ImproveVertexValence(liaison, valenceOptions).compute()

        # Smooth
        smoothOptions = HashMap()
        smoothOptions.put("iterations", str(8))
        smoothOptions.put("check", "true")
        smoothOptions.put("boundaries", "true")
        smoothOptions.put("relaxation", str(0.6))
        if safe_coplanarity >= 0.0:
            smoothOptions.put("coplanarity", str(safe_coplanarity))
        SmoothNodes3DBg(liaison, smoothOptions).compute()

        # Remove Degenerated
        rdOptions = HashMap()
        rdOptions.put("rho", str(kwargs["eratio"]))
        RemoveDegeneratedTriangles(liaison, rdOptions).compute()

    # remesh beams
    if kwargs["wire_size"] > 0.0:
        liaison = remesh_beams(
            liaison=liaison,
            size=kwargs["wire_size"],
            rho=kwargs["rho"],
            immutable_groups=immutable_groups,
            point_metric_file=kwargs["wire_metric_file"],
        )

    # Output
    MeshWriter.writeObject3D(liaison.getMesh(), kwargs["out_dir"], "")
    if kwargs["recordFile"]:
        liaison.getMesh().getTrace().finish()
Ejemplo n.º 13
0
                  action="store",
                  type="float",
                  dest="coplanarity",
                  help="dot product of face normals to detect feature edges")

(options, args) = parser.parse_args(args=sys.argv[1:])

if len(args) != 2:
    parser.print_usage()
    sys.exit(1)

xmlDir = args[0]
outDir = args[1]

# Original mesh will be treated as a background mesh
background_mtb = MeshTraitsBuilder.getDefault3D()
background_mtb.addNodeSet()
background_mesh = Mesh(background_mtb)
MeshReader.readObject3D(background_mesh, xmlDir)
if options.coplanarity:
    background_mesh.buildRidges(options.coplanarity)

# New mesh must not have connectivity
new_mtb = MeshTraitsBuilder()
new_mtb.addTriangleList()
new_mtb.addNodeList()
new_mesh = Mesh(new_mtb)

for point in background_mesh.getNodes():
    new_mesh.add(point)
Ejemplo n.º 14
0
def clean(**kwargs):
    """Clean a mesh
    """
    # Process coplanarity options
    coplanarity = -2.0
    if kwargs['coplanarityAngle'] > 0:
        coplanarity = cos(kwargs['coplanarityAngle'] * pi / 180.)
    if kwargs['coplanarity']:
        coplanarity = kwargs['coplanarity']

    safe_coplanarity = kwargs['safe_coplanarity']
    if safe_coplanarity is None:
        safe_coplanarity = 0.8
    safe_coplanarity = str(max(coplanarity, safe_coplanarity))

    # Build background mesh
    try:
        liaison = kwargs['liaison']
    except KeyError:
        mtb = MeshTraitsBuilder.getDefault3D()
        if kwargs['recordFile']:
            mtb.addTraceRecord()
        mtb.addNodeSet()
        mesh = Mesh(mtb)
        if kwargs['recordFile']:
            mesh.getTrace().setDisabled(True)

        MeshReader.readObject3D(mesh, kwargs['in_dir'])
        liaison = MeshLiaison.create(mesh, mtb)

    if kwargs['recordFile']:
        liaison.getMesh().getTrace().setDisabled(False)
        liaison.getMesh().getTrace().setLogFile(kwargs['recordFile'])
        liaison.getMesh().getTrace().createMesh("mesh", liaison.getMesh())
    if kwargs['immutable_border']:
        liaison.mesh.tagFreeEdges(AbstractHalfEdge.IMMUTABLE)
    liaison.getMesh().buildRidges(coplanarity)
    if kwargs['preserveGroups']:
        liaison.getMesh().buildGroupBoundaries()

    immutable_groups = []
    if kwargs['immutable_groups_file']:
        f = open(kwargs['immutable_groups_file'])
        immutable_groups = f.read().split()
        f.close()
        liaison.mesh.tagGroups(immutable_groups, AbstractHalfEdge.IMMUTABLE)

    if kwargs['recordFile']:
        cmds = [
            String("assert self.m.checkNoDegeneratedTriangles()"),
            String("assert self.m.checkNoInvertedTriangles()"),
            String("assert self.m.checkVertexLinks()"),
            String("assert self.m.isValid()")
        ]
        liaison.getMesh().getTrace().setHooks(cmds)

    # Swap
    swapOptions = HashMap()
    swapOptions.put("coplanarity", str(safe_coplanarity))
    swapOptions.put("minCosAfterSwap", "0.3")
    SwapEdge(liaison, swapOptions).compute()

    # Improve valence
    valenceOptions = HashMap()
    valenceOptions.put("coplanarity", str(safe_coplanarity))
    valenceOptions.put("checkNormals", "false")
    ImproveVertexValence(liaison, valenceOptions).compute()

    # Smooth
    smoothOptions = HashMap()
    smoothOptions.put("iterations", str(8))
    smoothOptions.put("check", "true")
    smoothOptions.put("boundaries", "true")
    smoothOptions.put("relaxation", str(0.6))
    if (safe_coplanarity >= 0.0):
        smoothOptions.put("coplanarity", str(safe_coplanarity))
    SmoothNodes3DBg(liaison, smoothOptions).compute()

    # Remove Degenerated
    rdOptions = HashMap()
    rdOptions.put("rho", str(kwargs['eratio']))
    RemoveDegeneratedTriangles(liaison, rdOptions).compute()

    # Output
    MeshWriter.writeObject3D(liaison.getMesh(), kwargs['out_dir'], "")
    if kwargs['recordFile']:
        liaison.getMesh().getTrace().finish()
Ejemplo n.º 15
0
cmd = ("random  ", "<dir>", "Put random triangles in a given group.")
parser = OptionParser(usage="amibebatch %s [OPTIONS] %s\n\n%s" % cmd,
                      prog="random")
parser.add_option("-r",
                  "--ratio",
                  metavar="FLOAT",
                  default=0.03,
                  action="store",
                  type="float",
                  dest="ratio",
                  help="The ratio of triangles to put in the new group")
parser.add_option("-n",
                  "--name",
                  metavar="STRING",
                  action="store",
                  type="string",
                  dest="group_name",
                  default="random",
                  help="""The name of group to be created.""")

(options, args) = parser.parse_args(args=sys.argv[1:])

if len(args) != 1:
    parser.print_usage()
    sys.exit(1)

mesh = Mesh(MeshTraitsBuilder.getDefault3D())
xmlDir = args[0]
MeshReader.readObject3D(mesh, xmlDir)
RandomizeGroups(options.ratio, options.group_name).compute(mesh, True)
MeshWriter.writeObject3D(mesh, xmlDir, None)