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
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"], "")
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) if options.coplanarity: liaison.getMesh().buildRidges(options.coplanarity) if options.preserveGroups: liaison.getMesh().buildGroupBoundaries() if options.recordFile: cmds = [ String("assert self.m.checkNoDegeneratedTriangles()"), String("assert self.m.checkNoInvertedTriangles()"), String("assert self.m.checkVertexLinks()"), String("assert self.m.isValid()") ]
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() MeshWriter.writeObject3D(liaison.getMesh(), outDir, String())
def read_mesh(path): mtb = MeshTraitsBuilder.getDefault3D() mtb.addNodeSet() mesh = Mesh(mtb) MeshReader.readObject3D(mesh, path) return mesh
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) # Split triangles into 4 new triangles mapSeenTriangles = {} for triangle in background_mesh.getTriangles():
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()
from java.lang import String # Python import sys, os from optparse import OptionParser """ Extract specified groups from a mesh """ cmd=("extract ", "<inputDir> <outputDir> <groupName> [<groupName>...]", "Extract specified groups") parser = OptionParser(usage="amibebatch %s [OPTIONS] %s\n\n%s" % cmd, prog="extract") (options, args) = parser.parse_args(args=sys.argv[1:]) if len(args) < 3: parser.print_usage() sys.exit(1) xmlDir = args[0] outDir = args[1] s = SubMeshWorker(xmlDir) groups = args[2:] extractedDir = s.extractGroups(groups) m = Mesh() MeshReader.readObject3D(m, extractedDir) MeshWriter.writeObject3D(m, outDir, String())
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()