def test_aerial_cameras():
    """Test creation of default aerial cameras."""
    file_path = r'tests/assets/revit_model/model.hbjson'
    model = Model.from_hbjson(file_path)
    actors = Actor.from_model(model)
    bounds = Actor.get_bounds(actors)
    centroid = Actor.get_centroid(actors)
    cameras = Camera.aerial_cameras(bounds, centroid)

    assert len(cameras) == 4

    def rounded(tup):
        return list(map(lambda x: round(x, 4), tup))

    cam_01, cam_02, cam_03, cam_04 = cameras
    assert rounded((cam_01.position)) == rounded(
        (124.35035099551129, 87.54659771487164, 56.45049285888672))
    assert rounded((cam_01.direction)) == rounded(
        (-108.78812527224468, -108.78812527224468, -41.03615807294845))
    assert cam_01.up_vector == (0.0, 0.0, 1.0)
    assert rounded((cam_02.position)) == rounded(
        (-93.22589954897808, 87.54659771487164, 56.45049285888672))
    assert rounded((cam_02.direction)) == rounded(
        (108.78812527224468, -108.78812527224468, -41.03615807294845))
    assert cam_02.up_vector == (0.0, 0.0, 1.0)
    assert rounded((cam_03.position)) == rounded(
        (-93.22589954897808, -130.02965282961773, 56.45049285888672))
    assert rounded((cam_03.direction)) == rounded(
        (108.78812527224468, 108.78812527224468, -41.03615807294845))
    assert cam_03.up_vector == (0.0, 0.0, 1.0)
    assert rounded((cam_04.position)) == rounded(
        (124.35035099551129, -130.02965282961773, 56.45049285888672))
    assert rounded((cam_04.direction)) == rounded(
        (-108.78812527224468, 108.78812527224468, -41.03615807294845))
    assert cam_04.up_vector == (0.0, 0.0, 1.0)
Example #2
0
def test_aerial_cameras():
    """Test creation of default aerial cameras."""
    file_path = r'tests/assets/revit_model/model.hbjson'
    model = Model.from_hbjson(file_path)
    actors = model.actors()
    bounds = Actor.get_bounds(actors)
    centroid = Actor.get_centroid(actors)
    cameras = Camera.aerial_cameras(bounds, centroid)

    assert len(cameras) == 4

    def rounded(tup):
        return list(map(lambda x: round(x, 4), tup))

    cam_01, cam_02, cam_03, cam_04 = cameras
    assert rounded((cam_01.position)) == rounded(
        (124.2538248261054, 87.99674601954615, 56.45049285888672))
    assert rounded((cam_01.direction)) == rounded(
        (-109.0614780942837, -109.0614780942837, -42.199789583683014))
    assert cam_01.up_vector == (0.0, 0.0, 1.0)

    assert rounded((cam_02.position)) == rounded(
        (-93.869131362462, 87.99674601954615, 56.45049285888672))
    assert rounded((cam_02.direction)) == rounded(
        (109.0614780942837, -109.0614780942837, -42.199789583683014))
    assert cam_02.up_vector == (0.0, 0.0, 1.0)

    assert rounded((cam_03.position)) == rounded(
        (-93.869131362462, -130.12621016902125, 56.45049285888672))
    assert rounded((cam_03.direction)) == rounded(
        (109.0614780942837, 109.0614780942837, -42.199789583683014))
    assert cam_03.up_vector == (0.0, 0.0, 1.0)

    assert rounded((cam_04.position)) == rounded(
        (124.2538248261054, -130.12621016902125, 56.45049285888672))
    assert rounded((cam_04.direction)) == rounded(
        (-109.0614780942837, 109.0614780942837, -42.199789583683014))
    assert cam_04.up_vector == (0.0, 0.0, 1.0)
def translate(hbjson_file, name, folder, file_type, display_mode, grid_options,
              show_html, config):
    """Translate a HBJSON file to an HTML or a vtkjs file.

    \b
    Args:
        hbjson-file: Path to an HBJSON file.

    """
    folder = pathlib.Path(folder)
    folder.mkdir(exist_ok=True)

    # Set Sensor grids
    if grid_options == 'ignore':
        grid_options = SensorGridOptions.Ignore
    elif grid_options == 'points':
        grid_options = SensorGridOptions.Sensors
    elif grid_options == 'meshes':
        grid_options = SensorGridOptions.Mesh

    try:
        model = Model.from_hbjson(hbjson=hbjson_file, load_grids=grid_options)

        # Set display style
        if display_mode == 'shaded':
            model.update_display_mode(DisplayMode.Shaded)
        elif display_mode == 'surface':
            model.update_display_mode(DisplayMode.Surface)
        elif display_mode == 'surfacewithedges':
            model.update_display_mode(DisplayMode.SurfaceWithEdges)
        elif display_mode == 'wireframe':
            model.update_display_mode(DisplayMode.Wireframe)
        elif display_mode == 'points':
            model.update_display_mode(DisplayMode.Points)

        # load data
        if config:
            scene = Scene()
            actors = Actor.from_model(model)
            bounds = Actor.get_bounds(actors)
            centroid = Actor.get_centroid(actors)
            cameras = Camera.aerial_cameras(bounds=bounds, centroid=centroid)
            scene.add_actors(actors)
            scene.add_cameras(cameras)
            model = load_config(config, model, scene)

        # Set file type

        if file_type.lower() == 'html':
            output = model.to_html(folder=folder, name=name, show=show_html)
        elif file_type.lower() == 'vtkjs':
            output = model.to_vtkjs(folder=folder, name=name)
        elif file_type.lower() == 'vtk':
            output = model.to_files(folder=folder,
                                    name=name,
                                    writer=VTKWriters.legacy)
        elif file_type.lower() == 'vtp':
            output = model.to_files(folder=folder,
                                    name=name,
                                    writer=VTKWriters.binary)

    except Exception as e:
        traceback.print_exc()
        sys.exit(1)
    else:
        print(f'Success: {output}', file=sys.stderr)
        return sys.exit(0)
Example #4
0
def export(hbjson_file, folder, image_type, image_width, image_height,
           background_color, model_display_mode, grid_options,
           grid_display_mode, view, config):
    """Export images from radiance views in a HBJSON file.

    \b
    Args:
        hbjson-file: Path to an HBJSON file.

    """
    folder = pathlib.Path(folder)
    folder.mkdir(exist_ok=True)

    # Set image types
    if image_type == 'png':
        image_type = ImageTypes.png
    elif image_type == 'jpg':
        image_type = ImageTypes.jpg
    elif image_type == 'ps':
        image_type == ImageTypes.ps
    elif image_type == 'tiff':
        image_type == ImageTypes.tiff
    elif image_type == 'ps':
        image_type == ImageTypes.ps
    elif image_type == 'pnm':
        image_type == ImageTypes.pnm

    # Set Sensor grids
    if grid_options == 'ignore':
        grid_options = SensorGridOptions.Ignore
    elif grid_options == 'points':
        grid_options = SensorGridOptions.Sensors
    elif grid_options == 'meshes':
        grid_options = SensorGridOptions.Mesh

    try:
        model = Model.from_hbjson(hbjson=hbjson_file, load_grids=grid_options)

        # Set model's display mode
        if model_display_mode == 'shaded':
            model.update_display_mode(DisplayMode.Shaded)
        elif model_display_mode == 'surface':
            model.update_display_mode(DisplayMode.Surface)
        elif model_display_mode == 'surfacewithedges':
            model.update_display_mode(DisplayMode.SurfaceWithEdges)
        elif model_display_mode == 'wireframe':
            model.update_display_mode(DisplayMode.Wireframe)
        elif model_display_mode == 'points':
            model.update_display_mode(DisplayMode.Points)

        # Set model's grid's display mode
        if grid_display_mode == 'shaded':
            model.sensor_grids.display_mode = DisplayMode.Shaded
        elif model_display_mode == 'surface':
            model.sensor_grids.display_mode = DisplayMode.Surface
        elif model_display_mode == 'surfacewithedges':
            model.sensor_grids.display_mode = DisplayMode.SurfaceWithEdges
        elif model_display_mode == 'wireframe':
            model.sensor_grids.display_mode = DisplayMode.Wireframe
        elif model_display_mode == 'points':
            model.sensor_grids.display_mode = DisplayMode.Points

        actors = Actor.from_model(model)

        scene = Scene(background_color=background_color)
        scene.add_actors(actors)

        # Set a default camera if there are no cameras in the model
        if not model.cameras and not view:
            actors = Actor.from_model(model=model)
            camera = Camera(identifier='plan', type='l')
            scene.add_cameras(camera)
            bounds = Actor.get_bounds(actors)
            centroid = Actor.get_centroid(actors)
            aerial_cameras = camera.aerial_cameras(bounds, centroid)
            scene.add_cameras(aerial_cameras)

        else:
            # Collection cameras from model, if the model has it
            if len(model.cameras) != 0:
                cameras = model.cameras
                scene.add_cameras(cameras)

            # if view files are provided collect them
            if view:
                for vf in view:
                    camera = Camera.from_view_file(file_path=vf)
                    scene.add_cameras(camera)

        # load config if provided
        if config:
            load_config(config, model, scene)

        output = scene.export_images(folder=folder,
                                     image_type=image_type,
                                     image_width=image_width,
                                     image_height=image_height)

    except Exception:
        traceback.print_exc()
        sys.exit(1)
    else:
        print(f'Success: {output}', file=sys.stderr)
        return sys.exit(0)