Skip to content

Commit

Permalink
Fixes a bug where the single/multi-band materials is not properly han…
Browse files Browse the repository at this point in the history
…dled when using from_corners together with extrude. (issue #381)
  • Loading branch information
fakufaku committed Dec 7, 2024
1 parent e4d183a commit 99a29f2
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions pyroomacoustics/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,24 +1395,45 @@ def extrude(self, height, v_vec=None, absorption=None, materials=None):
if libroom.area_2d_polygon(floor_corners) <= 0:
floor_corners = np.fliplr(floor_corners)

walls = []
wall_corners = {}
wall_materials = {}
for i in range(nw):
corners = np.array(
name = str(i)
wall_corners[name] = np.array(
[
np.r_[floor_corners[:, i], 0],
np.r_[floor_corners[:, (i + 1) % nw], 0],
np.r_[floor_corners[:, (i + 1) % nw], 0] + height * v_vec,
np.r_[floor_corners[:, i], 0] + height * v_vec,
]
).T
walls.append(
wall_factory(
corners,
self.walls[i].absorption,
self.walls[i].scatter,
name=str(i),

if len(self.walls[i].absorption) == 1:
# Single band
wall_materials[name] = Material(
energy_absorption=float(self.walls[i].absorption),
scattering=float(self.walls[i].scatter),
)
elif len(self.walls[i].absorption) == self.octave_bands.n_bands:
# Multi-band
abs_dict = {
"coeffs": self.walls[i].absorption,
"center_freqs": self.octave_bands.centers,
"description": "",
}
sca_dict = {
"coeffs": self.walls[i].scatter,
"center_freqs": self.octave_bands.centers,
"description": "",
}
wall_materials[name] = Material(
energy_absorption=abs_dict,
scattering=sca_dict,
)
else:
raise ValueError(
"Encountered a material with inconsistent number of bands."
)
)

############################
# BEGIN COMPATIBILITY CODE #
Expand Down Expand Up @@ -1477,12 +1498,23 @@ def extrude(self, height, v_vec=None, absorption=None, materials=None):
# we need the floor corners to ordered clockwise (for the normal to point outward)
new_corners["floor"] = np.fliplr(new_corners["floor"])

for key in ["floor", "ceiling"]:
# Concatenate new walls param with old ones.
wall_corners.update(new_corners)
wall_materials.update(materials)

# If some of the materials used are multi-band, we need to resample
# all of them to have the same number of values
if not Material.all_flat(wall_materials):
for name, mat in wall_materials.items():
mat.resample(self.octave_bands)

walls = []
for key, corners in wall_corners.items():
walls.append(
wall_factory(
new_corners[key],
materials[key].absorption_coeffs,
materials[key].scattering_coeffs,
corners,
wall_materials[key].absorption_coeffs,
wall_materials[key].scattering_coeffs,
name=key,
)
)
Expand Down

0 comments on commit 99a29f2

Please sign in to comment.