Beispiel #1
0
    def import_obj(cls, filename, scaling=1.0, **kwargs):
        """
        Create a mesh instance from a Wavefront OBJ mesh file (.obj).

        :param str filename: Mesh file path.
        :param double scaling: Scale the mesh by this factor (default=1.0).
        :param kwargs: Accepts optional keyword arguments from the Mesh class.
        :rtype: Mesh

        .. code-block:: pycon

            >>> from raysect.optical import World, translate, rotate, ConstantSF, Sellmeier, Dielectric
            >>> from raysect.primitive import import_obj
            >>>
            >>> world = World()
            >>>
            >>> diamond = Dielectric(Sellmeier(0.3306, 4.3356, 0.0, 0.1750**2, 0.1060**2, 0.0),
            >>>                      ConstantSF(1.0))
            >>>
            >>> bunny_mesh = import_obj("resources/stanford_bunny.obj", scaling=1, parent=world,
            >>>                         transform=translate(0, 0, 0)*rotate(165, 0, 0), material=diamond)
        """

        vertices = []
        normals = []
        triangles = []

        with open(filename) as f:
            for line in f:

                # skip comments
                if line[0] == "#":
                    continue

                # clean up and tokenise
                tokens = line.strip().split(" ")

                # parse tokens
                cmd = tokens[0]
                tokens = tokens[1:]

                if cmd == "v":
                    vertex = cls._to_point(tokens, scaling)
                    vertices.append(vertex)

                elif cmd == "vt":
                    # texture coordinates not currently supported
                    continue

                elif cmd == "vn":
                    normal = cls._to_normal(tokens)
                    normals.append(normal)

                elif cmd == "f":
                    triangle = cls._to_triangle(tokens)
                    triangles.append(triangle)

        if normals:
            return Mesh(vertices, triangles, normals, **kwargs)
        return Mesh(vertices, triangles, **kwargs)
Beispiel #2
0
    def load_cad(self, load_full=False):
        from raysect.primitive.mesh import Mesh
        from raysect.optical.material.absorber import AbsorbingSurface
        from raysect.optical import World
        import os
        world = World()

        if load_full:
            MESH_PARTS = MASTU_FULL_MESH + VACUUM_VESSEL + \
                         UPPER_DIVERTOR_NOSE + UPPER_DIVERTOR_ARMOUR + UPPER_DIVERTOR + \
                         LOWER_DIVERTOR_NOSE + LOWER_DIVERTOR_ARMOUR + LOWER_DIVERTOR + \
                         LOWER_ELM_COILS + LOWER_GAS_BAFFLE + \
                         UPPER_ELM_COILS + UPPER_GAS_BAFFLE + \
                         ELM_COILS + PF_COILS + \
                         T5_LOWER + T4_LOWER + T3_LOWER + T2_LOWER + T1_LOWER + \
                         T5_UPPER + T4_UPPER + T3_UPPER + T2_UPPER + T1_UPPER + \
                         C6_TILES + C5_TILES + C4_TILES + C3_TILES + C2_TILES + C1_TILE + \
                         B1_UPPER + B2_UPPER + B3_UPPER + B4_UPPER + \
                         B1_LOWER + B2_LOWER + B3_LOWER + B4_LOWER +  \
                         BEAM_DUMPS + SXD_BOLOMETERS
        else:
            MESH_PARTS = CENTRE_COLUMN + LOWER_DIVERTOR_ARMOUR

        #MESH_PARTS=VACUUM_VESSEL
        for cad_file in MESH_PARTS:
            directory, filename = os.path.split(cad_file[0])
            name, ext = filename.split('.')
            print("importing {} ...".format(filename))
            Mesh.from_file(cad_file[0],
                           parent=world,
                           material=AbsorbingSurface(),
                           name=name)
        return world
Beispiel #3
0
    def import_vtk(cls, filename, scaling=1.0, mode=VTK_AUTOMATIC, **kwargs):
        """
        Create a mesh instance from a VTK mesh data file (.vtk).

        .. warning ::
           Currently only supports VTK DataFile v2.0 and unstructured grid data with
           3 element (triangular) cells.

        :param str filename: Mesh file path.
        :param double scaling: Scale the mesh by this factor (default=1.0).
        :param str mode: The file format to load: 'ascii', 'binary', 'auto' (default='auto').
        :param kwargs: Accepts optional keyword arguments from the Mesh class.
        :rtype: Mesh
        """

        mode = mode.lower()
        if mode == VTK_ASCII:
            vertices, triangles, mesh_name = cls._load_ascii(filename, scaling)
        elif mode == VTK_BINARY:
            raise NotImplementedError('The binary .vtk loading routine has not been implemented yet.')
        elif mode == VTK_AUTOMATIC:
            try:
                vertices, triangles, mesh_name = cls._load_ascii(filename, scaling)
            except ValueError:
                # vertices, triangles, mesh_name = cls._load_binary(filename, scaling)
                raise NotImplementedError('The binary .vtk loading routine has not been implemented yet.')
        else:
            modes = (VTK_ASCII, VTK_BINARY)
            raise ValueError('Unrecognised import mode, valid values are: {}'.format(modes))

        if 'name' not in kwargs.keys():
            kwargs['name'] = mesh_name or "VTKMesh"

        return Mesh(vertices, triangles, smoothing=False, **kwargs)
Beispiel #4
0
    def import_ply(cls, filename, scaling=1.0, mode=PLY_AUTOMATIC, **kwargs):
        """
        Create a mesh instance from a Polygon File Format (PLY) mesh file (.ply).
        Note PLY is also known as the Stanford Triangle Format.

        Some engineering meshes are exported in different units (mm for example)
        whereas Raysect units are in m. Applying a scale factor of 0.001 would
        convert the mesh into m for use in Raysect.

        :param str filename: Mesh file path.
        :param double scaling: Scale the mesh by this factor (default=1.0).
        :param str mode: The file format to load: 'ascii', 'binary', 'auto' (default='auto').
        :param kwargs: Accepts optional keyword arguments from the Mesh class.
        :rtype: Mesh
        
        .. code-block:: pycon

            >>> from raysect.optical import World, translate, rotate, ConstantSF, Sellmeier, Dielectric
            >>> from raysect.primitive import import_ply
            >>>
            >>> world = World()
            >>>
            >>> diamond = Dielectric(Sellmeier(0.3306, 4.3356, 0.0, 0.1750**2, 0.1060**2, 0.0),
            >>>                      ConstantSF(1.0))
            >>>
            >>> mesh = import_ply("your_mesh.ply", scaling=1, mode='binary', parent=world,
            >>>                   transform=translate(0, 0, 0)*rotate(165, 0, 0), material=diamond)
        """

        mode = mode.lower()
        if mode == PLY_ASCII:
            vertices, triangles = cls._load_ascii(filename, scaling)

        elif mode == PLY_BINARY:
            vertices, triangles = cls._load_binary(filename, scaling)

        elif mode == PLY_AUTOMATIC:
            try:
                vertices, triangles = cls._load_ascii(filename, scaling)
            except ValueError:
                vertices, triangles = cls._load_binary(filename, scaling)

        else:
            modes = (PLY_AUTOMATIC, PLY_ASCII, PLY_BINARY)
            raise ValueError(
                'Unrecognised import mode, valid values are: {}'.format(modes))

        return Mesh(vertices, triangles, smoothing=False, **kwargs)
Beispiel #5
0
from raysect.core import Vector3D, Point3D
from raysect.optical import World, translate, rotate_basis
from raysect.optical.observer import FibreOptic, SpectralPipeline0D
from raysect.primitive.mesh import Mesh

plt.ion()
world = World()

MESH_PARTS = CENTRE_COLUMN + LOWER_DIVERTOR_ARMOUR

for cad_file in MESH_PARTS:
    directory, filename = os.path.split(cad_file)
    name, ext = filename.split('.')
    print("importing {} ...".format(filename))
    Mesh.from_file(cad_file,
                   parent=world,
                   material=AbsorbingSurface(),
                   name=name)

# Load plasma from SOLPS model
mds_server = 'solps-mdsplus.aug.ipp.mpg.de:8001'
ref_number = 69636
sim = SOLPSSimulation.load_from_mdsplus(mds_server, ref_number)
plasma = sim.plasma
mesh = sim.mesh
vessel = mesh.vessel

# Setup deuterium lines
d_alpha = Line(deuterium, 0, (3, 2), wavelength=656.19)
d_beta = Line(deuterium, 0, (4, 2), wavelength=486.1)
d_gamma = Line(deuterium, 0, (5, 2), wavelength=433.99)
d_delta = Line(deuterium, 0, (6, 2), wavelength=410.2)
Beispiel #6
0
from cherab.tools.observers import load_calcam_calibration
from cherab.solps import load_solps_from_mdsplus
from cherab.openadas import OpenADAS

from cherab.mastu.machine import CENTRE_COLUMN, LOWER_DIVERTOR_ARMOUR

world = World()

MESH_PARTS = CENTRE_COLUMN + LOWER_DIVERTOR_ARMOUR

for cad_file in MESH_PARTS:
    directory, filename = os.path.split(cad_file)
    name, ext = filename.split('.')
    print("importing {} ...".format(filename))
    Mesh.from_file(cad_file,
                   parent=world,
                   material=AbsorbingSurface(),
                   name=name)  # material=Lambert(ConstantSF(0.25))

# Load plasma from SOLPS model
mds_server = 'solps-mdsplus.aug.ipp.mpg.de:8001'
ref_number = 69636  #69637
sim = load_solps_from_mdsplus(mds_server, ref_number)
plasma = sim.create_plasma(parent=world)
plasma.atomic_data = OpenADAS(permit_extrapolation=True)
mesh = sim.mesh
vessel = mesh.vessel

# Pick emission models
# d_alpha = Line(deuterium, 0, (3, 2))
# plasma.models = [ExcitationLine(d_alpha), RecombinationLine(d_alpha)]
Beispiel #7
0
the cartesian hit point of the ray with the materials in the scene (rabit and floor)
is recorded. In Figure 1 the 3D hit point for each ray in the camera is plotted in
3D space. In Figure 2 the z coordinate of each hit point is scaled and plotted to
indicate distance from the camera. Both methods allow simple visualisation of a
scene and extraction of intersection geometry data.

Bunny model source:
  Stanford University Computer Graphics Laboratory
  http://graphics.stanford.edu/data/3Dscanrep/
  Converted to obj format using MeshLab
"""

world = World()

mesh_path = path.join(path.dirname(__file__), "../resources/stanford_bunny.rsm")
mesh = Mesh.from_file(mesh_path, parent=world, transform=rotate(180, 0, 0))

# LIGHT BOX
padding = 1e-5
enclosure_thickness = 0.001 + padding
glass_thickness = 0.003

light_box = Node(parent=world)

enclosure_outer = Box(Point3D(-0.10 - enclosure_thickness, -0.02 - enclosure_thickness, -0.10 - enclosure_thickness),
                      Point3D(0.10 + enclosure_thickness, 0.0, 0.10 + enclosure_thickness))
enclosure_inner = Box(Point3D(-0.10 - padding, -0.02 - padding, -0.10 - padding),
                      Point3D(0.10 + padding, 0.001, 0.10 + padding))
enclosure = Subtract(enclosure_outer, enclosure_inner, material=Lambert(ConstantSF(0.2)), parent=light_box)

glass_outer = Box(Point3D(-0.10, -0.02, -0.10),
Beispiel #8
0
    'inner_heat_shield_s06.rsm', 'inner_heat_shield_s07.rsm',
    'inner_heat_shield_s08.rsm', 'inner_heat_shield_s09.rsm',
    'inner_heat_shield_s10.rsm', 'inner_heat_shield_s11.rsm',
    'inner_heat_shield_s12.rsm', 'inner_heat_shield_s13.rsm',
    'inner_heat_shield_s14.rsm', 'inner_heat_shield_s15.rsm',
    'inner_heat_shield_s16.rsm'
]

machine_material = AbsorbingSurface()  # Mesh with perfect absorber

for path in MESH_PARTS:
    path = MESH_PATH + path
    print("importing {}  ...".format(os.path.split(path)[1]))
    directory, filename = os.path.split(path)
    name, ext = filename.split('.')
    Mesh.from_file(path, parent=world, material=machine_material, name=name)

# Load simulation from MDSplus
mds_server = 'solps-mdsplus.aug.ipp.mpg.de:8001'
ref_number = 40195
sim = SOLPSSimulation.load_from_mdsplus(mds_server, ref_number)

# Load simulation from raw output files
# SIM_PATH = '/home/mcarr/mst1/aug_2016/solps_testcase/'
# sim = SOLPSSimulation.load_from_output_files(SIM_PATH)

plasma = sim.plasma
mesh = sim.mesh
plasma_cylinder = solps_total_radiated_power(world, sim, step=0.001)

X_WIDTH = 0.01