Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[occjava] adding some feature #14

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
17c4ef2
[OccJava] adding some more methods and classes
dzufferey Mar 8, 2018
31aed5c
[OccJava] adding first/last parameters for adaptors
dzufferey Mar 8, 2018
e08e104
[OccJava] unpacking vector/points
dzufferey Mar 8, 2018
d91f41c
[occjava] transform for point
dzufferey Mar 28, 2018
18a4965
[occjava] adding BRepClass_FaceClassifier
dzufferey Apr 30, 2018
785b68e
[occjava] c++ exception to java with error msg
dzufferey May 3, 2018
91433ae
[occjava] add BRepBuilderAPI_Copy
dzufferey Aug 10, 2018
6812439
[occjava] face from plane
dzufferey Nov 22, 2018
a3dd59d
[occjava] making face from plan and wire
dzufferey Nov 22, 2018
e5a30d5
[Amibe] python: distinguish coplanarity tolerance for feature edges a…
Sep 3, 2019
0969d9b
[Amibe] Add SplitTagged algorithm
Sep 16, 2019
e779026
[Amibe] python: fix boundaries option in Smooth3DBg
Sep 30, 2019
3581f72
[Amibe] python: SplitTagged: add background option
Sep 30, 2019
72d82ea
[OccJava] Fix OCE 0.17 API for Sewing to allow nonmanifold sewing
Oct 1, 2019
2ecc9f9
[OccJava] Add parallel option in BRepMesh_IncrementalMesh
Oct 3, 2019
cef38ab
[viewer3d] Add a selection behavior SINGLE_RECTANGLE_MODE
Oct 2, 2019
ca77aea
[viewer3d] Allow fitting view over a list of objects
Oct 2, 2019
3b43c05
[Amibe] python: add various metrics for beams remeshing
Dec 9, 2019
0816e62
[Amibe] python: fix usage of boundaries and coplanarity options for S…
Dec 13, 2019
789a58f
Fix SkeletonProjector on non manifold polylines
jeromerobert Jan 23, 2020
544b6e7
[Amibe] python: minor fixes
Mar 26, 2020
343b3f0
[OccJava] adding some more methods and classes
dzufferey Mar 8, 2018
2900fb6
[OccJava] adding first/last parameters for adaptors
dzufferey Mar 8, 2018
daf0f80
[OccJava] unpacking vector/points
dzufferey Mar 8, 2018
e4808f0
[occjava] transform for point
dzufferey Mar 28, 2018
ebeac3c
[occjava] adding BRepClass_FaceClassifier
dzufferey Apr 30, 2018
350b6a9
[occjava] c++ exception to java with error msg
dzufferey May 3, 2018
36aee3b
[occjava] add BRepBuilderAPI_Copy
dzufferey Aug 10, 2018
2d4f832
[occjava] face from plane
dzufferey Nov 22, 2018
a601c2f
[occjava] making face from plan and wire
dzufferey Nov 22, 2018
f7934cb
Merge branch 'master' of github.com:dzufferey/jCAE
dzufferey Sep 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions amibe/python/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
def clean(**kwargs):
"""Clean a mesh
"""
# Process coplanarity option
coplanarity = cos(kwargs['coplanarityAngle'] * pi / 180.)
# 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']
Expand Down Expand Up @@ -66,27 +73,24 @@ def clean(**kwargs):

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

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

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

# Remove Degenerated
Expand Down Expand Up @@ -114,6 +118,9 @@ def clean(**kwargs):
parser.add_option("-c", "--coplanarity", metavar="FLOAT",
action="store", type="float", dest="coplanarity",
help="dot product of face normals to detect feature edges")
parser.add_option("-s", "--safe-coplanarity", metavar="FLOAT",
action="store", type="float", dest="safe_coplanarity", default=0.8,
help="dot product of face normals tolerance for algorithms")
parser.add_option("-g", "--preserveGroups", action="store_true", dest="preserveGroups",
help="edges adjacent to two different groups are handled like free edges")
parser.add_option("-e", "--eratio", metavar="FLOAT", default=50.0,
Expand Down
15 changes: 10 additions & 5 deletions amibe/python/remesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def __remesh(options):
point_metric = options.point_metric
else:
point_metric = None
safe_coplanarity = str(max(options.coplanarity, 0.8))
if options.safe_coplanarity == None:
options.safe_coplanarity = 0.8
safe_coplanarity = str(max(options.coplanarity, options.safe_coplanarity))

if options.forced_points:
if point_metric:
Expand Down Expand Up @@ -334,7 +336,7 @@ def __remesh(options):
writeVTK(liaison)
opts.clear()
opts.put("size", str(options.size))
opts.put("coplanarity", str(options.coplanarity))
opts.put("coplanarity", safe_coplanarity)
opts.put("minCosAfterSwap", "0.3")
opts.put("nearLengthRatio", "0.6")
algo = Remesh(liaison, opts)
Expand All @@ -355,7 +357,7 @@ def __remesh(options):
writeVTK(liaison)

opts.clear()
opts.put("coplanarity", str(options.coplanarity))
opts.put("coplanarity", safe_coplanarity)
opts.put("iterations", "2")
opts.put("size", str(options.size))
algo = SmoothNodes3DBg(liaison, opts)
Expand All @@ -365,7 +367,7 @@ def __remesh(options):
writeVTK(liaison)

opts.clear()
opts.put("coplanarity", str(options.coplanarity))
opts.put("coplanarity", safe_coplanarity)
opts.put("expectInsert", "false" if options.afront_path else "true")
opts.put("minCosAfterSwap", "0.3")
algo = SwapEdge(liaison, opts)
Expand Down Expand Up @@ -401,7 +403,7 @@ def __remesh(options):
writeVTK(liaison)

opts.clear()
opts.put("coplanarity", str(options.coplanarity))
opts.put("coplanarity", safe_coplanarity)
opts.put("expectInsert", "false" if options.afront_path else "true")
opts.put("minCosAfterSwap", "0.3")
algo = SwapEdge(liaison, opts)
Expand Down Expand Up @@ -483,6 +485,9 @@ def __remesh(options):
parser.add_option("-c", "--coplanarity", metavar="FLOAT",
action="store", type="float", dest="coplanarity", default=0.9,
help="dot product of face normals to detect feature edges")
parser.add_option("-s", "--safe-coplanarity", metavar="FLOAT",
action="store", type="float", dest="safe_coplanarity", default=0.8,
help="dot product of face normals tolerance for algorithms")
parser.add_option("-P", "--point-metric", metavar="STRING",
action="store", type="string", dest="point_metric_file",
help="""A CSV file containing points which to refine around. Each line must contains 6 values:
Expand Down
172 changes: 128 additions & 44 deletions amibe/python/remeshBeams.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,149 @@

# jCAE
from org.jcae.mesh.amibe.ds import Mesh, Vertex
from org.jcae.mesh.amibe.ds import Mesh, Vertex, AbstractHalfEdge
from org.jcae.mesh.amibe.traits import MeshTraitsBuilder
from org.jcae.mesh.amibe.metrics import EuclidianMetric3D
from org.jcae.mesh.amibe.metrics import (
EuclidianMetric3D,
DistanceMetric,
SingularMetric,
)
from org.jcae.mesh.amibe.algos3d import PolylineFactory, RemeshPolyline
from org.jcae.mesh.xmldata import MeshReader, MeshWriter
from org.jcae.mesh.amibe.projection import MeshLiaison

# Java
from java.util import ArrayList
from java.util import LinkedHashMap
from java.lang import String, Math
from java.util import HashMap

# Python
import sys
from optparse import OptionParser
from remesh import check_metric_type


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


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"], "")

"""
Remesh beams
"""

cmd=("remeshBeams ", "<inputDir> <outputDir>", "Remesh beams")
parser = OptionParser(usage="amibebatch %s [OPTIONS] %s\n\n%s" % cmd,
prog="remeshESN")
parser.add_option("-t", "--size", metavar="FLOAT", default=0.0,
action="store", type="float", dest="size",
help="target size")
if __name__ == "__main__":
"""
Recreate an existing wire mesh, remesh around singularities
"""

(options, args) = parser.parse_args(args=sys.argv[1:])
cmd = (
"remeshBeams",
"<inputDir> <outputDir> <size>",
"""Remesh an existing mesh around singularities:
Refine according to pointMetric and size

if len(args) != 2:
parser.print_usage()
sys.exit(1)
inputDir
input amibe mesh

xmlDir = args[0]
outDir = args[1]
if options.size:
size = options.size
else:
size = 1.0
outputDir
output amibe mesh

mtb = MeshTraitsBuilder.getDefault3D()
mtb.addNodeList()
mesh = Mesh(mtb)
MeshReader.readObject3D(mesh, xmlDir)
size
Target size""",
)
parser = OptionParser(
usage="amibebatch %s [OPTIONS] %s\n\n%s" % cmd, prog="remeshBeams"
)
parser.add_option(
"-P",
"--point-metric",
metavar="STRING",
action="store",
type="string",
dest="point_metric_file",
help="A text file containing points which to refine around.",
)
parser.add_option(
"-r",
"--rho",
metavar="FLOAT",
default=2.0,
action="store",
type="float",
dest="rho",
help="numerical metric ratio (required: rho > 1, default: 2)",
)
parser.add_option(
"-M",
"--immutable-groups",
metavar="STRING",
action="store",
type="string",
dest="immutable_groups_file",
help="A text file containing the list of groups whose "
"beam elements and nodes must not be modified by this algorithm.",
)

polylines=PolylineFactory(mesh)
mesh.resetBeams()
for entry in polylines.entrySet():
groupId = entry.key
for polyline in entry.value:
listM = ArrayList()
for v in polyline:
listM.add(EuclidianMetric3D(size))
#for v in polyline:
# print v
#print "Remesh polyline "+str(numPoly+1)+"/"+str(nrPoly)+" of group "+str(bId)+"/"+str(bgroupMap.size())+" "+str(polyline.size())+" vertices"
result = RemeshPolyline(mesh, polyline, listM).compute()
for i in xrange(result.size() - 1):
mesh.addBeam(result.get(i), result.get(i+1), groupId)
print " New polyline: "+str(result.size())+" vertices"
#for v in result:
# print v
(options, args) = parser.parse_args(args=sys.argv[1:])

MeshWriter.writeObject3D(mesh, outDir, "")
if len(args) != 3:
parser.print_usage()
sys.exit(1)
options.in_dir = args[0]
options.out_dir = args[1]
options.size = float(args[3])
remesh(**options.__dict__)
Loading