Skip to content

Commit

Permalink
feat(gen): add genbox and genrev"
Browse files Browse the repository at this point in the history
  • Loading branch information
taoning committed Aug 28, 2024
1 parent 800a65c commit 9e938d8
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pyradiance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
)
from .gen import (
genblinds,
genbox,
genbsdf,
gendaylit,
gendaymtx,
genrev,
gensdaymtx,
gensky,
genssky,
Expand Down Expand Up @@ -79,9 +81,11 @@
"evalglare",
"falsecolor",
"genblinds",
"genbox",
"genbsdf",
"gendaylit",
"gendaymtx",
"genrev",
"gensdaymtx",
"gensky",
"genssky",
Expand Down
59 changes: 59 additions & 0 deletions pyradiance/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,40 @@ def genblinds(
cmd.extend(["-r", str(rcurv)])
return sp.run(cmd, check=True, stdout=sp.PIPE).stdout

@handle_called_process_error
def genbox(
mat: str,
name: str,
xsiz: float,
ysiz: float,
zsiz: float,
inward: bool = False,
beveled: Optional[float] = None,
rounded: Optional[float] = None,
nsegs: Optional[int] = None,
smoothing: bool = False,
waveout: bool = False,
) -> bytes:
cmd = [str(BINPATH / "genbox")]
cmd.append(mat)
cmd.append(name)
cmd.append(str(xsiz))
cmd.append(str(ysiz))
cmd.append(str(zsiz))
if inward:
cmd.append("-i")
if beveled is not None:
cmd.extend(["-b", str(beveled)])
if rounded is not None:
cmd.extend(["-r", str(rounded)])
if nsegs is not None:
cmd.extend(["-n", str(nsegs)])
if smoothing:
cmd.append("-s")
if waveout:
cmd.append("-o")
return sp.run(cmd, stdout=sp.PIPE).stdout


@handle_called_process_error
def genbsdf(
Expand Down Expand Up @@ -296,6 +330,31 @@ def gendaymtx(
out = sp.run(cmd, check=True, input=stdin, stdout=sp.PIPE, stderr=sp.PIPE)
return out.stdout

@handle_called_process_error
def genrev(
mat: str,
name: str,
z_t: str,
r_t: str,
nseg: int,
expr: Optional[str] = None,
file: Optional[str] = None,
smooth: bool = False,
) -> bytes:
cmd = [str(BINPATH/"genrev")]
cmd.append(mat)
cmd.append(name)
cmd.append(z_t)
cmd.append(r_t)
cmd.append(str(nseg))
if expr is not None:
cmd.extend(["-e", expr])
if file is not None:
cmd.extend(["-f", file])
if smooth:
cmd.append("-s")
return sp.run(cmd, stdout=sp.PIPE).stdout


@handle_called_process_error
def gensdaymtx(
Expand Down
36 changes: 28 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,81 @@
RADTAG = "f275c068"

RADBINS = [
"bsdf2ttree",
"bsdf2klems",
"bsdf2ttree",
"bsdfquery",
"cnt",
"dctimestep",
"epw2wea",
"evalglare",
"falsecolor",
"getbbox",
"getinfo",
"genblinds",
"genBSDF",
"genblinds",
"genbox",
"gendaylit",
"gendaymtx",
"genprism",
"genrev",
"gensdaymtx",
"gensky",
"genssky",
"gensurf",
"genworm",
"getbbox",
"getinfo",
"histo",
"ies2rad",
"mgf2rad",
"mkillum",
"obj2rad",
"mkpmap",
"obj2mesh",
"obj2rad",
"oconv",
"pabopto2bsdf",
"pcomb",
"pcompos",
"pcond",
"pextrem",
"pfilt",
"pflip",
"pkgBSDF",
"protate",
"pvalue",
"rad",
"ra_tiff",
"ra_bmp",
"ra_ppm",
"ra_tiff",
"ra_xyze",
"rad",
"rcalc",
"rcode2bmp",
"rcode_depth",
"rcode_ident",
"rcode_norm",
"rcollate",
"rcomb",
"rcontrib",
"rcrop",
"rfluxmtx",
"rlam",
"rmtxop",
"robjutil",
"rpict",
"rpiece",
"rsensor",
"rsplit",
"rtpict",
"rtrace",
"rttree_reduce",
"tabfunc",
"total",
"vwrays",
"vwright",
"wrapBSDF",
"xform",
# For Windows Perl scripts
"perl530",
"libgcc_s_seh-1",
"libstdc++-6",
"libgcc_s_seh-1",
"libwinpthread-1",
]

Expand Down
13 changes: 13 additions & 0 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,16 @@ def test_ra_tiff(tmpdir: Path, resources_dir: Path):
out = tmpdir / "test.tif"
pr.ra_tiff(hdr, out=str(out))
assert out.exists()

def test_genbox():
out_bytes = pr.genbox("mat", "name", 1, 2, 3)
out_str = out_bytes.decode()
prims = pr.parse_primitive(out_str)
assert prims[0] == pr.Primitive("mat", "polygon", "name.1540", [], [1, 0, 0,1,0,3,0,0,3,0,0,0])


def test_genrev():
out_bytes = pr.genrev("steel", "torus", "sin(2*PI*t)", "2+cos(2*PI*t)", 2)
out_str = out_bytes.decode()
prims = pr.parse_primitive(out_str)
assert prims[0] == pr.Primitive("steel", "ring", "torus.1", [], [0, 0,1.22464679915e-16,0,0,1,3,1])

0 comments on commit 9e938d8

Please sign in to comment.