def readback(self, readbackPath, readmode="hds", embedded={}, **kwargs): outputFile = readbackPath params = dict(self.params) for p in kwargs: if kwargs[p] is not None: params[p] = kwargs[p] if readmode == "hds": return hdsutils.loadHDSImage(outputFile) elif readmode == "shds": print("numberOfWeights: ", params["numBSDFWeights"]) return shdsutils.loadSHDS(outputFile, numWeights=params["numBSDFWeights"] if "numBSDFWeights" in params else 0) elif readmode == "raw": if "ignoreIndex" not in self.eParams: print( "'$ignoreIndex' must be specified as an embedded parameter (not as part of kwargs)" ) return None return rawutils.loadRAW(outputFile, numSlices=self.eParams["ignoreIndex"]) else: print("Invalid readmode ", readmode) return None
def renderDictionary(renderParams, dictionary, directory=".", cache=False): data = [] if not os.path.exists(directory + "/linear-dictionary"): os.mkdir(directory + "/linear-dictionary") for k, params in enumerate(dictionary): targets = [] for i, l in enumerate(renderParams["lights"]): outfile = directory + "/linear-dictionary/entry-" + format(k).zfill(6) + "-img-" + format(i).zfill(2) + ".hds" print "Rendering: ", params if (not cache) or (not os.path.exists(outfile)): os.system(("mitsuba " + directory + "/" + renderParams["scene"] + " -o " + outfile + " -DlightX=" + format(l[0]) + " -DlightY=" + format(l[1]) + " -DlightZ=" + format(l[2]) + " -Ddepth=" + format(renderParams["depth"]) + " -DsampleCount=" + format(renderParams["samples"]) + " -Dmesh=" + directory + "/" + format(renderParams["mesh"]) + " -Dweight1=" + format(params[0]) + " -Dweight2=" + format(params[1]) + " -Dalpha=" + format(params[2]) + " -Deta=" + format(params[3]) )) targets.append(hdsutils.loadHDSImage(outfile)) data.append(np.stack(targets, axis=0)) return np.stack(data, axis=0)
def renderMesh(meshname, scenename, targethdsfile, targetnpyfile, W=256, H=256, autoskip=False): if (not autoskip) or (not os.path.exists(targethdsfile)): print("RENDERING") copyfile(meshname, "/tmp/mts_mesh_copy_3.ply") os.system("mitsuba " + scenename + " -o \"" + targethdsfile + "\" -Dwidth=" + format(W) + " -Dheight=" + format(H) + "") if (not autoskip) or (not os.path.exists(targetnpyfile) and os.path.exists(targethdsfile)): print("CONVERING TO NPY") narr = loadHDSImage(targethdsfile) np.save(targetnpyfile, narr)
def getError(hparams, params, sampleCount=128, directory="."): pstring = buildPString(hparams, params) currents = [] for i, l in enumerate(params["lights"]["data"]): os.system("mitsuba " + directory + "/" + params["scenes"]["intensity"] + " -o " + "./error-surface/" + format(i).zfill(2) + ".hds" + " -Dirradiance=" + format(params["lights"]["intensity-data"][i]) + " -Dwidth=" + format(params["target"]["width"]) + " -Dheight=" + format(params["target"]["height"]) + " -DlightX=" + format(l[0]) + " -DlightY=" + format(l[1]) + " -DlightZ=" + format(l[2]) + " -Ddepth=" + format(params["estimator"]["depth"]) + " -DsampleCount=" + format(sampleCount) + pstring + " > /dev/null") currents.append(hdsutils.loadHDSImage("./error-surface/" + format(i).zfill(2) + ".hds")) plt.close() nImgs = len(params["lights"]["intensity-data"]) fig = plt.figure(figsize=(nImgs, 2)) for i in range(nImgs): fig.add_subplot(nImgs, 2, (i*2)+1) print(params["target"]["data"].shape) plt.imshow(params["target"]["data"][:,:,i]) fig.add_subplot(nImgs, 2, (i*2)+2) plt.imshow(currents[i][:,:,0]) plt.show(block=False) plt.pause(2) return np.sum(np.square(params["target"]["data"] - np.stack(currents, axis=0)))
create_dir(directory + "/renders/normaldeltas") categories = [("normals", normals_scene_name), ("gradients", colors_scene_name), ("normaldeltas", colors_scene_name)] for meshtype, scene_name in categories: for superindex in superindices: create_dir(directory + "/renders/" + meshtype + "/" + superindex) files = os.listdir(directory + "/meshes/" + meshtype + "/" + superindex) for fname in files: print(directory + "/renders/" + meshtype + "/" + superindex + "/" + fname) if fname.endswith("ply") and not (".ply.ply" in fname): fullmeshname = directory + "/meshes/" + meshtype + "/" + superindex + "/" + fname targethdsfile = directory + "/renders/" + meshtype + "/" + superindex + "/" + fname.replace( "ply", "hds").replace(".nhds", ".n.hds").replace( ".phds", ".p.hds") targetnpyfile = directory + "/renders/" + meshtype + "/" + superindex + "/" + fname.replace( "ply", "npy").replace(".nnpy", ".n.npy").replace( ".pnpy", ".p.npy") if not os.path.exists(targethdsfile): copyfile(fullmeshname, "/tmp/mts_mesh_copy_3.ply") os.system("mitsuba " + scene_name + " -o \"" + targethdsfile + "\"") if not os.path.exists(targetnpyfile) and os.path.exists( targethdsfile): narr = loadHDSImage(targethdsfile) np.save(targetnpyfile, narr)
intensitiesfile = directory + "/" + config["initial-reconstruction"]["light-intensities"] lights = open(lightsfile, "r").readlines() lts = [ll.split(" ")[1:4] for ll in lights] flts = [ [float(k) for k in lt] for lt in lts ] intensities = open(intensitiesfile, "r").readlines() its = [float(li) for li in intensities] irType = config["initial-reconstruction"]["type"] if irType == "render": # Render the original images first. numLights = renderOriginals(directory, config, extension="hds", fileFormat="hds", samples=64) # Load the HDS images. W,H = loadHDSImage(directory + "/originals/" + format(0).zfill(4) + ".hds").squeeze().shape print("W,H:", W,H) images = np.zeros((numLights,W,H)) for i in range(numLights): images[i,:,:] = loadHDSImage(directory + "/originals/" + format(i).zfill(4) + ".hds").squeeze() elif irType == "file": # Load images straight from file. images = np.load(directory + "/" + config["initial-reconstruction"]["file"]) W,H = images.shape[:2] images = images.transpose([2,0,1]) else: print("Invalid reconstruction type: ", irType) sys.exit(1)
import hdsutils import numpy as np import matplotlib.pyplot as plt import optparse parser = optparse.OptionParser() parser.add_option("-l", "--log", dest="log", action="store_true", default=False) (options, args) = parser.parse_args() filename = args[0] npdata = hdsutils.loadHDSImage(filename) if options.log: npdata = np.log(np.abs(npdata[:, :, 0])) else: npdata = npdata[:, :, 0] plt.imshow(npdata) plt.show()