def Render(self,sampleCount): currScene = Scene(self.scene) for light in self.light: currScene.addChild(light) currScene.configure() currScene.addSensor(self.cam) currScene.setSensor(self.cam) self.__createSampler(sampleCount) # sample count currScene.setSampler(self.sampler) currScene.setDestinationFile('') # Create a render job and insert it into the queue job = RenderJob('myRenderJob', currScene, self.queue ) job.start() self.queue.waitLeft(0) self.queue.join() film = currScene.getFilm() size = film.getSize() bitmap = Bitmap(Bitmap.ERGBA, Bitmap.EFloat16, size) film.develop(Point2i(0, 0), size, Point2i(0, 0), bitmap) # End of render - get result result_image = np.array(bitmap.getNativeBuffer()) currSceneInfo = currScene.getAABB return result_image, currSceneInfo
def make_synthetic_scene(n_steps): from mitsuba.core import Properties from mitsuba.render import Scene props = Properties("scene") props["_unnamed_0"] = create_stairs(n_steps) return Scene(props)
def Render(self, sampleCount, i): ## Creating a copy of the base scene and add modifications regarding varaiant camera's properties (sensor position, sampler) currScene = Scene(self.scene) currScene.configure() pmgr = PluginManager.getInstance() currScene.addSensor(self.cam) currScene.setSensor(self.cam) self.createSampler(sampleCount) currScene.setSampler(self.sampler) #(self.sampler) currScene.setDestinationFile('') ## Create a render job and insert it into the queue #job = RenderJob('myRenderJob'+str(i), currScene, self.queue ) curSceneResID = self.scheduler.registerResource(currScene) job = RenderJob('myRenderJob' + str(i), currScene, self.queue, curSceneResID) #job = RenderJob('myRenderJob'+str(i), currScene, self.queue,self.sceneResID ) # passing self.sceneResID - in order to create shallow copy of the scene to all warkers job.start() self.queue.waitLeft(0) self.queue.join() ## Aquire Bitmap format of the rendered image: film = currScene.getFilm() size = film.getSize() bitmap = Bitmap(Bitmap.ERGBA, Bitmap.EFloat16, size) film.develop(Point2i(0, 0), size, Point2i(0, 0), bitmap) ## End of render - get result result_image = np.array( bitmap.buffer()) if sys.platform == 'linux2' else np.array( bitmap.getNativeBuffer()) # TODO : update Mitsuba version of Windows, with the updated API - bitmap.getNativeBuffer() doesn't exsists animore currSceneInfo = currScene.getAABB return result_image, currSceneInfo
def test03_depth_packet_stairs(variant_packet_rgb): from mitsuba.core import Ray3f as Ray3fX, Properties from mitsuba.render import Scene if mitsuba.core.MTS_ENABLE_EMBREE: pytest.skip("EMBREE enabled") props = Properties("scene") props["_unnamed_0"] = create_stairs_packet(11) scene = Scene(props) mitsuba.set_variant("scalar_rgb") from mitsuba.core import Ray3f, Vector3f n = 4 inv_n = 1.0 / (n - 1) rays = Ray3fX.zero(n * n) d = [0, 0, -1] wavelengths = [] for x in range(n): for y in range(n): o = Vector3f(x * inv_n, y * inv_n, 2) o = o * 0.999 + 0.0005 rays[x * n + y] = Ray3f(o, d, 0, 100, 0.5, wavelengths) res_naive = scene.ray_intersect_naive(rays) res = scene.ray_intersect(rays) res_shadow = scene.ray_test(rays) # TODO: spot-check (here, we only check consistency) assert ek.all(res_shadow == res.is_valid()) compare_results(res_naive, res, atol=1e-6)
def __init__(self): super().__init__() self.thread = Thread.registerUnmanagedThread('exporter') self.thread.setFileResolver(main_fresolver) self.thread.setLogger(main_logger) self.pmgr = PluginManager.getInstance() self.scene = Scene()
def build_scene(env): #architecture is : #-env.name #--exterior #----ingredients #--compartments #----surface #------ingredients #----interior #------ingredients #create the document and a node for rootenv pmgr=PluginManager.getInstance() scene = Scene(); # Create a sensor,film&samplegenerator scene.addChild(setEnv(pmgr)) scene.addChild(setIntegrator(pmgr)) scene.addChild(setLight(pmgr)) root_env=scene.createNullObject(str(env.name)) r = env.exteriorRecipe if r : scene,root_env = buildRecipe(r,r.name,scene,root_env) for o in env.compartments: rs = o.surfaceRecipe if rs : p,s,bb=up (767.0) #used for lipids pp,ss,bbsurface = up (700.0) bbsurface = numpy.array([[p-ss/2.0],[p+ss/2.0]]) scene,root_env = buildRecipe(rs,str(o.name)+"_surface",scene,root_env,mask=bbsurface) ri = o.innerRecipe if ri : pp,ss,bbmatrix = up (650.0) bbmatrix = numpy.array([[p-ss/2.0],[p+ss/2.0]]) scene,root_env = buildRecipe(ri,str(o.name)+"_interior",scene,root_env,mask=bbsurface) #build the compartments geometry # buildCompartmentsGeom(o,scene,parent=root_env) #['ID']['node', 'color', 'id', 'instances', 'mesh', 'parentmesh'] fname = "/home/ludo/"+env.name+str(env.version)+".mxs" ok = scene.writeMXS(str(fname)); print "write",ok if not ok: print("Error saving MXS ('/home/ludo/"+env.name+str(env.version)+".mxs')"); return 0; return scene #Settheintegrator scene.addChild(pmgr.create({ ' type ' : ' direct ' }))
def __initialize_mitsuba_setting(self): self.plgr = PluginManager.getInstance() self.output_dir = self.scene.output_dir mitsuba_module_path = os.path.dirname(inspect.getfile(MitsubaRenderer)) self.file_resolver = Thread.getThread().getFileResolver() self.file_resolver.appendPath( os.path.join(mitsuba_module_path, "xml_files/")) self.file_resolver.appendPath( os.path.join(mitsuba_module_path, "textures/")) self.file_resolver.appendPath( os.path.join(mitsuba_module_path, "shapes/")) self.mitsuba_scene = Scene()
def render(self, filename): self.scheduler.start() # create globals integrator = self.pmgr.create({'type': self.setup['integrator']}) emitter = self.pmgr.create({'type': self.setup['emitter']}) sensor = self.pmgr.create({ 'type': self.setup['sensor'], 'film': { 'type': self.setup['film'], 'width': self.setup['width'], 'height': self.setup['height'], 'pixelFormat': self.setup['pixelFormat'], 'exposure': self.setup['exposure'], 'banner': self.setup['banner'] }, 'sampler': { 'type': self.setup['sampler'], 'sampleCount': self.setup['sampleCount'] }, 'fov': self.setup['fov'], }) scene = Scene() scene.addChild(integrator) scene.addChild(emitter) scene.addChild(sensor) for mesh in self.mesh: scene.addChild(mesh) scene.configure() scene.initialize() # needed to force build of kd-tree transformCurr = Transform.lookAt(self.setup['eye'], self.setup['target'], self.setup['camera_up']) sensor.setWorldTransform(transformCurr) scene.setDestinationFile(filename) job = RenderJob('job', scene, self.queue) job.start() self.queue.waitLeft(0) self.queue.join() self.scheduler.stop()
def makeScene(): scene = Scene() pmgr = PluginManager.getInstance() # make shapes for i in range(100): shapeProps = Properties("sphere") shapeProps["center"] = Point(i, i, i) shapeProps["radius"] = 0.1 shape = pmgr.createObject(shapeProps) shape.configure() scene.addChild(shape) # make perspective sensor sensorProps = Properties("perspective") sensorProps["toWorld"] = Transform.lookAt(Point(0, 0, 10), Point(0, 0, 0), Vector(0, 1, 0)) sensorProps["fov"] = 45.0 sensor = pmgr.createObject(sensorProps) # make film filmProps = Properties("ldrfilm") filmProps["width"] = 640 filmProps["height"] = 480 film = pmgr.createObject(filmProps) film.configure() sensor.addChild("film", film) sensor.configure() scene.addChild(sensor) scene.configure() return scene
def modifyScene(scene, index, config, pmgr, destinationFolder): #for i in range(number_of_renderings): destination = destinationFolder + '-result_%03i' % index # Create a shallow copy of the scene so that the queue can tell apart the two # rendering processes. This takes almost no extra memory newScene = Scene(scene) # Create a sensor, film & sample generator newSensor = createSensor(pmgr, config, index) newSensor.configure() newScene.addSensor(newSensor) newScene.setSensor(newSensor) newScene.setDestinationFile(destination) # if 'envmap' in config: # addEnvmap(newScene, config, pmgr) newScene.configure() return (newScene)
def construct_simple_scene(scene_objects, sensor) -> Scene: """ Construct a simple scene containing given objects and using the given sensor. Uses the path integrator and constant emitter :param scene_objects: All scene child objects to add :param sensor: The mitsuba sensor definition to use for this scene :return: The scene created, already configured and initialized """ pmgr = PluginManager.getInstance() integrator = pmgr.create({'type': 'path'}) emitter = pmgr.create({'type': 'constant'}) scene = Scene() scene.addChild(integrator) scene.addChild(emitter) scene.addChild(sensor) for obj in scene_objects: scene.addChild(obj) scene.configure() scene.initialize() return scene
def do_simulation_multiangle_seq(seqname): currdir = os.path.split(os.path.realpath(__file__))[0] sys.path.append(currdir + '/bin/rt/' + current_rt_program + '/python/2.7/') os.environ['PATH'] = currdir + '/bin/rt/' + current_rt_program + os.pathsep + os.environ['PATH'] import mitsuba from mitsuba.core import Vector, Point, Ray, Thread, Scheduler, LocalWorker, PluginManager, Transform from mitsuba.render import SceneHandler from mitsuba.render import RenderQueue, RenderJob from mitsuba.render import Scene import multiprocessing scheduler = Scheduler.getInstance() for i in range(0, multiprocessing.cpu_count()): scheduler.registerWorker(LocalWorker(i, 'wrk%i' % i)) scheduler.start() scene_path = session.get_scenefile_path() fileResolver = Thread.getThread().getFileResolver() fileResolver.appendPath(str(scene_path)) scene = SceneHandler.loadScene(fileResolver.resolve( str(os.path.join(session.get_scenefile_path(), main_scene_xml_file)))) scene.configure() scene.initialize() queue = RenderQueue() sceneResID = scheduler.registerResource(scene) bsphere = scene.getKDTree().getAABB().getBSphere() radius = bsphere.radius targetx, targety, targetz = bsphere.center[0], bsphere.center[1], bsphere.center[2] f = open(seqname + ".conf", 'r') params = json.load(f) obs_azimuth = params['seq1']['obs_azimuth'] obs_zenith = params['seq2']['obs_zenith'] cfgfile = session.get_config_file() f = open(cfgfile, 'r') cfg = json.load(f) viewR = cfg["sensor"]["obs_R"] mode = cfg["sensor"]["film_type"] azi_arr = map(lambda x: float(x), obs_azimuth.strip().split(":")[1].split(",")) zeni_arr = map(lambda x: float(x), obs_zenith.strip().split(":")[1].split(",")) seq_header = multi_file_prefix + "_" + seqname index = 0 for azi in azi_arr: for zeni in zeni_arr: distFile = os.path.join(session.get_output_dir(), seq_header + ("_VA_%.2f" % azi).replace(".", "_") + ("_VZ_%.2f" % zeni).replace(".", "_")) newScene = Scene(scene) pmgr = PluginManager.getInstance() newSensor = pmgr.createObject(scene.getSensor().getProperties()) theta = zeni / 180.0 * math.pi phi = (azi - 90) / 180.0 * math.pi scale_x = radius scale_z = radius toWorld = Transform.lookAt( Point(targetx - viewR * math.sin(theta) * math.cos(phi), targety + viewR * math.cos(theta), targetz - viewR * math.sin(theta) * math.sin(phi)), # original Point(targetx, targety, targetz), # target Vector(0, 0, 1) # up ) * Transform.scale( Vector(scale_x, scale_z, 1) # 视场大小 ) newSensor.setWorldTransform(toWorld) newFilm = pmgr.createObject(scene.getFilm().getProperties()) newFilm.configure() newSensor.addChild(newFilm) newSensor.configure() newScene.addSensor(newSensor) newScene.setSensor(newSensor) newScene.setSampler(scene.getSampler()) newScene.setDestinationFile(str(distFile)) job = RenderJob('Simulation Job' + "VA_"+str(azi)+"_VZ_"+str(zeni), newScene, queue, sceneResID) job.start() queue.waitLeft(0) queue.join() # handle npy if mode == "spectrum" and (output_format not in ("npy", "NPY")): for azi in azi_arr: for zeni in zeni_arr: distFile = os.path.join(session.get_output_dir(), seq_header + ("_VA_%.2f" % azi).replace(".", "_") + ("_VZ_%.2f" % zeni).replace( ".", "_")) data = np.load(distFile + ".npy") bandlist = cfg["sensor"]["bands"].split(",") RasterHelper.saveToHdr_no_transform(data, distFile, bandlist, output_format) os.remove(distFile + ".npy")
def addSceneLights(self): """ Adding all the pre-setted lights to the scene""" currScene = Scene(self.scene) for light in self.light: currScene.addChild(light) self.scene = currScene
def renderVPLS(vpls, cam, scene, target): ''' render VPLS having the camera looking at the desired target the scene. The result will be an image that will be used to define the 3D space where the camera and object can be placed in the environment. Target can be either be 'roof' or 'floor' ''' pmgr = PluginManager.getInstance() scheduler = Scheduler.getInstance() if (target == 'roof'): target_height = scene.HeightRoof else: target_height = scene.HeightFloor # Start up the scheduling system with one worker per local core for i in range(0, multiprocessing.cpu_count()): scheduler.registerWorker(LocalWorker(i, 'wrk%i' % i)) scheduler.start() # Create a queue for tracking render jobs queue = RenderQueue() nVPLS = int(vpls[0][1]) * 4 scene = Scene() for i in xrange(1, nVPLS, 4): if (float(vpls[i][2]) == target_height): scene.addChild( pmgr.create({ 'type': 'sphere', 'center': Point(float(vpls[i][1]), float(vpls[i][2]), float(vpls[i][3])), 'radius': 1.0, 'emitter': pmgr.create({ 'type': 'area', 'radiance': Spectrum(10.), }) })) scene.addChild( pmgr.create({ 'type': 'perspective', 'toWorld': Transform.lookAt( Point(cam.origin[0], cam.origin[1], cam.origin[2]), Point(cam.target[0], cam.target[1], cam.target[2]), Vector(cam.up[0], cam.up[1], cam.up[2])), 'fov': cam.fov, 'film': { 'type': 'ldrfilm', 'width': cam.width, 'height': cam.height, 'banner': False, }, 'sampler': { 'type': 'halton', 'sampleCount': 1 }, })) scene.addChild(pmgr.create({'type': 'direct'})) scene.configure() if (target == 'roof'): filename = 'renderVPLSRoof' else: filename = 'renderVPLSFloor' scene.setDestinationFile(filename) # Create a render job and insert it into the queue job = RenderJob('myRenderJob', scene, queue) job.start() # Wait for all jobs to finish and release resources queue.waitLeft(0) queue.join() scheduler.stop()