Source code for raytraverse.scene.scene

# -*- coding: utf-8 -*-
# Copyright (c) 2020 Stephen Wasilewski, HSLU and EPFL
# =======================================================================
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# =======================================================================
import os
import re
import sys

import numpy as np
from clasp.script_tools import pipeline

from raytraverse.mapper import ViewMapper
from raytraverse.renderer import SpRenderer
from raytraverse.scene.basescene import BaseScene
from raytraverse.formatter import RadianceFormatter


[docs]class Scene(BaseScene): """container for radiance scene description WARNING!! if scene parameter contains and instance primitive, sunsampler will throw a segmentation fault when it tries to change the source. As scene instanciation will make a frozen octree, it is better to feed complete scene description files, or an octree. Parameters ---------- outdir: str path to store scene info and output files formatter: raytraverse.formatter.RadianceFormatter, optional intended renderer format """ def __init__(self, outdir, scene=None, frozen=True, formatter=RadianceFormatter, **kwargs): self._refl_scene = None super().__init__(outdir, scene=scene, frozen=frozen, formatter=formatter, **kwargs)
[docs] def reflection_search_scene(self): octf = f"{self.outdir}/scene_reflections.oct" if os.path.isfile(octf): self._refl_scene = octf elif self._refl_scene is None: skyf = f"{self.outdir}/reflections_sky.rad" f = open(skyf, 'w') f.write(self.formatter.get_skydef((1, 1, 1), ground=False)) f.close() files, frozen = self.formatter.get_scene(self.scene) if frozen: print(f"Warning, scene made from frozen octree or source scene " f"files can no longer be located, reflection search will" f"miss specular plastic", file=sys.stderr) pipeline([f"oconv -w {files} {skyf}"], outfile=octf, writemode='wb') self._refl_scene = octf return self._refl_scene
[docs] def source_scene(self, srcfile, srcname): files, frozen = self.formatter.get_scene(self.scene) octf = f"{self.outdir}/scene_{srcname}.oct" pipeline([f"oconv -w {files} {srcfile}"], outfile=octf, writemode='wb') return octf