[Radiance-general] RIF file generator class

Randolph M. Fritz RFritz at lbl.gov
Sat Apr 16 13:45:44 PDT 2011


I found this little Python classlet useful when I was running a heap of 
renderings and thought someone else might, too.  Take it as a fragment, 
suitable for modification.

#!/usr/bin/python
# -*- coding: utf-8 -*-

from datetime import datetime
import sys
import subprocess

RIFFMT ="""# {note}
materials = {matfiles}
scene = {scenefiles}

ZONE = {zone} {bounds}
VARIABILITY = {var}
QUALITY = {qual}
INDIRECT = {ind}
DETAIL = {detail}
AMBFILE = {ambfile}

{views}
"""

class radrif:
    def __init__(
        self, matfiles, scenefiles,
        note = None,
        zone = "E", bounds = None,
        var = "H", qual = "M", ind = 0, detail = "M",
        ambfile = "",
        views = ""):

        if note is None:
            note = datetime.today().ctime()
        if zone[0].upper() not in "EI":
            raise Exception("Zone must begin with E or I", zone)
        if bounds is None:
           bounds = self.getbounds(scenefiles)

        self.matfiles = matfiles
        self.scenefiles = scenefiles
        self.note = note
        self.zone = zone
        self.bounds = bounds
        self.var = var
        self.qual = qual
        self.ind = ind
        self.detail = detail
        self.ambfile = ambfile
        self.views = views


    def __str__(self):
        return RIFFMT.format(**self.__dict__)

    def getbounds(self,scenefiles):
        """Get the bounding box of a model"""
        cmd = ['getbbox', '-h'] + scenefiles.split()
        PIPE = subprocess.PIPE
        getbb = subprocess.Popen(cmd, stdout = PIPE, stderr = PIPE)
        (out,err) = getbb.communicate()
        if getbb.returncode != 0:
            raise Exception(
                'Can\'t get bounds of {0}, error {1}: {2}'.format(
                    self.scenefiles, getbb.returncode, err))
        return out

def main():
    print str(radrif(sys.argv[1],sys.argv[2]))

if __name__ == "__main__":
    main()


-- 
Randolph M. Fritz





More information about the Radiance-general mailing list