Skip to content

Commit e1e2812

Browse files
committed
Use tap
1 parent db1589e commit e1e2812

File tree

4 files changed

+46
-45
lines changed

4 files changed

+46
-45
lines changed

external_library/java/hemesh/hec_from_network.rb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,24 @@ def setup
2929
# If the connections are known in advance these can be given as parameter as int[][].
3030
# The second index gives index of first and second point of connection in the points
3131
# array. network = WB_Network.new(vertices, connections)
32-
creator = HEC_FromNetwork.new
33-
creator.setNetwork(network)
34-
# alternatively you can specify a HE_Mesh instead of a WB_Network.
35-
creator.setConnectionRadius(6) # connection radius
36-
# number of faces in the connections, min 3, max whatever blows up the CPU
37-
creator.setConnectionFacets(6)
38-
# rotate the connections by a fraction of a facet. 0 is no rotation, 1 is a rotation over a full facet. More noticeable for low number of facets.
39-
creator.setAngleOffset(0.25)
40-
# Threshold angle to include sphere in joint.
41-
creator.setMinimumBalljointAngle(TWO_PI / 3.0)
42-
# divide connection into equal parts if larger than maximum length.
43-
creator.setMaximumConnectionLength(30)
44-
creator.setCap(true) # cap open endpoints of connections?
45-
creator.setTaper(true) # allow connections to have different radii at each end?
46-
creator.setCreateIsolatedNodes(false) # create spheres for isolated points?
47-
# use the value of the WB_Node as scaling factor, only useful if the frame was created using addNode.
48-
creator.setUseNodeValues(true)
32+
creator = HEC_FromNetwork.new.tap do |net|
33+
net.setNetwork(network)
34+
# alternatively you can specify a HE_Mesh instead of a WB_Network.
35+
net.setConnectionRadius(6) # connection radius
36+
# number of faces in the connections, min 3, max whatever blows up the CPU
37+
net.setConnectionFacets(6)
38+
# rotate the connections by a fraction of a facet. 0 is no rotation, 1 is a rotation over a full facet. More noticeable for low number of facets.
39+
net.setAngleOffset(0.25)
40+
# Threshold angle to include sphere in joint.
41+
net.setMinimumBalljointAngle(TWO_PI / 3.0)
42+
# divide connection into equal parts if larger than maximum length.
43+
net.setMaximumConnectionLength(30)
44+
net.setCap(true) # cap open endpoints of connections?
45+
net.setTaper(true) # allow connections to have different radii at each end?
46+
net.setCreateIsolatedNodes(false) # create spheres for isolated points?
47+
# use the value of the WB_Node as scaling factor, only useful if the frame was created using addNode.
48+
net.setUseNodeValues(true)
49+
end
4950
@mesh = HE_Mesh.new(creator)
5051
HET_Diagnosis.validate(mesh)
5152
@render = WB_Render.new(self)

external_library/java/hemesh/hec_isosurface_image.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ def setup
1414
ArcBall.init(self)
1515
format_string = '/square-%03d.png' # format up to 3 leading zeroes
1616
images = (1..360).map { |index| data_path(format(format_string, index)) }
17-
creator = HEC_IsoSurface.new
18-
creator.set_size(8, 8, 8)
19-
creator.set_values(images.to_java(:string), self, 64, 64, 64)
20-
creator.set_isolevel(128)
21-
creator.set_invert(false)
22-
creator.set_boundary(-20_000)
23-
creator.set_gamma(0.3)
17+
creator = HEC_IsoSurface.new.tap do |iso|
18+
iso.set_size(8, 8, 8)
19+
iso.set_values(images.to_java(:string), self, 64, 64, 64)
20+
iso.set_isolevel(128)
21+
iso.set_invert(false)
22+
iso.set_boundary(-20_000)
23+
iso.set_gamma(0.3)
24+
end
2425
@mesh = HE_Mesh.new(creator)
2526
@render = WB_Render.new(self)
2627
end

external_library/java/hemesh/twin_iso.rb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
java_import 'wblut.hemesh.HEM_Smooth'
66

77
RES ||= 20
8-
98
attr_reader :mesh, :inv_mesh, :render
109

1110
def setup
@@ -23,20 +22,20 @@ def setup
2322
end
2423
values << valu
2524
end
26-
27-
creator = HEC_IsoSurface.new
28-
creator.set_resolution(RES, RES, RES) # number of cells in x,y,z direction
29-
creator.set_size(400.0 / RES, 400.0 / RES, 400.0 / RES) # cell size
30-
# JRuby requires a bit of help to determine correct 'java args', particulary with
31-
# overloaded arrays args as seen below. Note we are saying we have an 'array' of
32-
# 'float array' here, where the values can also be double[][][].
33-
java_values = values.to_java(Java::float[][]) # pre-coerce values to java
34-
creator.set_values(java_values) # the grid points
35-
creator.set_isolevel(1) # isolevel to mesh
36-
creator.set_invert(false) # invert mesh
37-
creator.set_boundary(100) # value of isoFunction outside grid
38-
# use creator.clear_boundary to set boundary values to "no value".
39-
# A boundary value of "no value" results in an open mesh
25+
creator = HEC_IsoSurface.new.tap do |surf|
26+
surf.set_resolution(RES, RES, RES) # number of cells in x,y,z direction
27+
surf.set_size(400.0 / RES, 400.0 / RES, 400.0 / RES) # cell size
28+
# JRuby requires a bit of help to determine correct 'java args', particulary with
29+
# overloaded arrays args as seen below. Note we are saying we have an 'array' of
30+
# 'float array' here, where the values can also be double[][][].
31+
java_values = values.to_java(Java::float[][]) # pre-coerce values to java
32+
surf.set_values(java_values) # the grid points
33+
surf.set_isolevel(1) # isolevel to mesh
34+
surf.set_invert(false) # invert mesh
35+
surf.set_boundary(100) # value of isoFunction outside grid
36+
# use creator.clear_boundary to set boundary values to "no value".
37+
# A boundary value of "no value" results in an open mesh
38+
end
4039
@mesh = HE_Mesh.new(creator)
4140
# mesh.modify(HEM_Smooth.new.set_iterations(10).setAutoRescale(true))
4241
creator.set_invert(true)

external_library/java/hemesh/weaire_phelan.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
def setup
1010
sketch_title 'Weaire Phelan'
1111
ArcBall.init(self)
12-
wp = HEMC_WeairePhelan.new
13-
wp.set_origin(WB_Point.new(0, 0, -100))
14-
wp.set_extents(WB_Vector.new(400, 400, 400))
15-
wp.set_number_of_units(2, 2, 2)
16-
wp.set_scale(150, 150, 150)
17-
@meshes = wp.create
12+
@meshes = HEMC_WeairePhelan.new.tap do |wp|
13+
wp.set_origin(WB_Point.new(0, 0, -100))
14+
wp.set_extents(WB_Vector.new(400, 400, 400))
15+
wp.set_number_of_units(2, 2, 2)
16+
wp.set_scale(150, 150, 150)
17+
end.create
1818
@render = WB_Render.new(self)
1919
end
2020

0 commit comments

Comments
 (0)