Skip to content

Commit

Permalink
Merge c6f4361 into aab6056
Browse files Browse the repository at this point in the history
  • Loading branch information
devang-chauhan committed Feb 16, 2022
2 parents aab6056 + c6f4361 commit a1caae0
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 19 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ Options:
Switch between html and vtkjs formats
[default: html]

-dm, --display-mode [shaded|surface|surfacewithedges|wireframe|points]
-mdm, --model-display-mode [shaded|surface|surfacewithedges|wireframe|points]
Set display mode for the model. [default:
shaded]

-gdm, --grid-display-mode [shaded|surface|surfacewithedges|wireframe|points]
Set display mode for the grid. [default:
shaded]

-go, --grid-options [ignore|points|meshes]
Export sensor grids as either points or
meshes. [default: ignore]
Expand Down Expand Up @@ -100,7 +104,7 @@ Options:

-gdm, --grid-display-mode [shaded|surface|surfacewithedges|wireframe|points]
Set display mode for the Sensorgrids.
[default: shaded]
[default: surfacewithedges]

-vf, --view PATH File Path to the Radiance view file.
Multiple view files are accepted.
Expand All @@ -112,6 +116,30 @@ Options:
the model. This is recommended when using
this command locally. [default: False]

--grid / --model Boolean to decide whether to export the
images of a whole model or only the grids.
Set it to True to export the grids.
[default: False]

-gf, --grid-filter TEXT Filter sensor grids by name. Use this option
multiple times to use multiple grid
identifiers as filters. [default: ]

--text TEXT Text to be displayed on the image.
-th, --text-height INTEGER Set the height of the text in pixels.
[default: 15]

-tc, --text-color <INTEGER INTEGER INTEGER>...
Set the text color. [default: 0, 0, 0]
-tp, --text-position <FLOAT FLOAT>...
Set the text position in the image. The
setting is applied at the lower left point
of the text. (0,0) will give you the lower
left corner of the image. (1,1) will give
you the upper right corner of the image.
[default: 0.5, 0.0]

-tb, --text-bold Set the text to be bold. [default: False]
--help Show this message and exit.
```

Expand Down
10 changes: 9 additions & 1 deletion honeybee_vtk/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .camera import Camera
from .types import ImageTypes
from .actor import Actor
from .text_actor import TextActor

from typing import List

Expand All @@ -23,16 +24,19 @@ class Assistant:
actors: A list of actors.
camera: A Camera object.
legend_parameters: A list of legend parameter objects to be added to the scene
text_actor: A TextActor object. Defaults to None.
"""

def __init__(self, background_color: Tuple[int, int, int], camera: Camera,
actors: List[Actor], legend_parameters: list) -> None:
actors: List[Actor], legend_parameters: list,
text_actor: TextActor = None) -> None:

self._background_color = background_color
self._actors = actors
self._camera = camera
self._legend_params = legend_parameters
self._text_actor = text_actor

def _create_window(self) -> \
Tuple[vtk.vtkRenderWindowInteractor, vtk.vtkRenderWindow, vtk.vtkRenderer]:
Expand Down Expand Up @@ -65,6 +69,10 @@ def _create_window(self) -> \
for actor in self._actors:
renderer.AddActor(actor.to_vtk())

# add text actor if provided
if self._text_actor:
renderer.AddActor(self._text_actor.to_vtk())

# Add legends to the window
if self._legend_params:
for legend_param in self._legend_params:
Expand Down
34 changes: 31 additions & 3 deletions honeybee_vtk/cli/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from honeybee_vtk.model import Model
from honeybee_vtk.vtkjs.schema import SensorGridOptions, DisplayMode
from honeybee_vtk.types import ImageTypes
from honeybee_vtk.text_actor import TextActor


@click.group()
Expand Down Expand Up @@ -84,10 +85,33 @@ def export():
help='Filter sensor grids by name. Use this option multiple times to use multiple'
' grid identifiers as filters.'
)
@click.option(
'--text', type=str, default=None, show_default=True, help='Text to be displayed on the'
' image.'
)
@click.option(
'--text-height', '-th', type=int, default=15, show_default=True,
help='Set the height of the text in pixels.'
)
@click.option(
'--text-color', '-tc', type=(int, int, int), default=(0, 0, 0), show_default=True,
help='Set the text color.',
)
@click.option(
'--text-position', '-tp', type=(float, float), default=(0.5, 0.0), show_default=True,
help='Set the text position in the image. The setting is applied at the lower left'
' point of the text. (0,0) will give you the lower left corner of the image.'
' (1,1) will give you the upper right corner of the image.'
)
@click.option(
'--text-bold', '-tb', is_flag=True, default=False, show_default=True,
help='Set the text to be bold.'
)
def export(
hbjson_file, folder, image_type, image_width, image_height,
background_color, model_display_mode, grid_options, grid_display_mode, view,
config, validate_data, grid, grid_filter):
config, validate_data, grid, grid_filter, text, text_height, text_color,
text_position, text_bold):
"""Export images from radiance views in a HBJSON file.
\b
Expand Down Expand Up @@ -144,7 +168,6 @@ def export(
elif grid_display_mode == 'points':
grid_display_mode = DisplayMode.Points


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

Expand All @@ -157,13 +180,18 @@ def export(
image_type=image_type, image_width=image_width,
image_height=image_height,)
else:
text_actor = TextActor(text=text, height=text_height, color=text_color,
position=text_position, bold=text_bold)\
if text else None

output = model.to_grid_images(config=config, folder=folder,
grid_filter=grid_filter,
grid_display_mode=grid_display_mode,
background_color=background_color,
image_type=image_type,
image_width=image_width,
image_height=image_height)
image_height=image_height,
text_actor=text_actor)

except Exception:
traceback.print_exc()
Expand Down
18 changes: 11 additions & 7 deletions honeybee_vtk/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .types import DataSetNames, VTKWriters, JoinedPolyData, ImageTypes
from .config import DataConfig, Autocalculate, Config
from .legend_parameter import Text
from .text_actor import TextActor


_COLORSET = {
Expand Down Expand Up @@ -63,11 +64,11 @@ def _camera_to_grid_actor(actor: Actor, data_name: str, zoom: int = 2,
Args:
actor: An Actor object.
data_name: name of the data being loaded on the grid. This is
data_name: name of the data being loaded on the grid. This is
used in naming the image files.
zoom: The zoom level of the camera. Defaults to 15.
auto_zoom: A boolean to set the camera to auto zoom. Setting this to True will
discard the Zoom level. Set this to False to use the zoom level. Defaults to
discard the Zoom level. Set this to False to use the zoom level. Defaults to
True.
camera_offset: The distance between the camera and the sensor grid.
Defaults to 100.
Expand Down Expand Up @@ -609,7 +610,8 @@ def to_grid_images(self, *, folder: str = '.', config: str,
grid_display_mode: DisplayMode = DisplayMode.SurfaceWithEdges,
background_color: Tuple[int, int, int] = None,
image_type: ImageTypes = ImageTypes.png,
image_width: int = 0, image_height: int = 0) -> List[str]:
image_width: int = 0, image_height: int = 0,
text_actor: TextActor = None) -> List[str]:
"""Export am image for each grid in the model.
Use the config file to specify which grids with which data to export. For
Expand All @@ -628,10 +630,12 @@ def to_grid_images(self, *, folder: str = '.', config: str,
display_mode: Display mode for the grid. Defaults to surface with edges.
background_color: Background color of the image. Defaults to white.
image_type: Image type to be exported. Defaults to png.
image_width: Image width in pixels. Defaults to 0. Which will use the
image_width: Image width in pixels. Defaults to 0. Which will use the
default radiance view's horizontal angle to derive the width.
image_height: Image height in pixels. Defaults to 0. Which will use the
default radiance view's vertical angle to derive the height.
text_actor: A TextActor object that defines the properties of the text to be
added to the image. Defaults to None.
Returns:
Path to the folder where the images are exported for each grid.
Expand Down Expand Up @@ -660,9 +664,9 @@ def to_grid_images(self, *, folder: str = '.', config: str,
display_mode=grid_display_mode)
dataset.color_by = data.identifier
actor = Actor(dataset)
scene = Scene(background_color=background_color)
scene.add_actors(actor)
scene.add_cameras(_camera_to_grid_actor(actor, data.identifier))
scene = Scene(background_color=background_color, actors=[actor],
cameras=[_camera_to_grid_actor(actor, data.identifier)],
text_actor=text_actor)
legend_range = self._get_legend_range(data)
self._load_legend_parameters(data, scene, legend_range)
image_paths += scene.export_images(folder=folder,
Expand Down
65 changes: 60 additions & 5 deletions honeybee_vtk/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .headless import try_headless
from .legend_parameter import LegendParameter
from .types import ImageTypes
from .text_actor import TextActor


class Scene:
Expand All @@ -29,12 +30,19 @@ class Scene:
Args:
background_color: A tuple of three integers that represent RGB values of the
color that you'd like to set as the background color. Defaults to white.
actors: A list of Actor objects to be added to the scene. Defaults to None.
cameras: A list of Camera objects to be added to the scene. Defaults to None.
text_actor: A TextActor object to be added to the scene. Defaults to None.
"""

def __init__(self, background_color: Tuple[int, int, int] = None) -> None:
def __init__(self, background_color: Tuple[int, int, int] = None,
actors: List[Actor] = None, cameras: List[Camera] = None,
text_actor: TextActor = None) -> None:

self.background_color = background_color
self._actors = []
self._cameras = []
self.actors = actors or []
self.cameras = cameras or []
self.text_actor = text_actor
self._assistants = []

@property
Expand All @@ -60,11 +68,52 @@ def actors(self) -> List[Actor]:
"""Actors in the scene."""
return self._actors

@actors.setter
def actors(self, val: List[Actor]) -> None:
"""Set actors for the scene."""
if not val:
self._actors = []
elif _validate_input(val, [Actor]):
self._actors = val
else:
raise ValueError(
'A list of Actor objects is expected.'
f' Instead got {val}.'
)

@property
def cameras(self) -> List[Camera]:
"""A list of honeybee-vtk cameras setup in the scene."""
return self._cameras

@cameras.setter
def cameras(self, val: List[Camera]) -> None:
"""Set cameras for the scene."""
if not val:
self._cameras = []
elif _validate_input(val, [Camera]):
self._cameras = val
else:
raise ValueError(
'A list of Camera objects is expected.'
f' Instead got {val}.'
)

@property
def text_actor(self) -> TextActor:
"""TextActor object in the scene."""
return self._text_actor

@text_actor.setter
def text_actor(self, val: TextActor) -> None:
"""Set the TextActor object in the scene."""
if not val:
self._text_actor = None
elif not isinstance(val, TextActor):
raise ValueError('TextActor object is expected.')
else:
self._text_actor = val

@property
def assistants(self) -> List[Assistant]:
"""A list of honeybee-vtk assistants working in the scene."""
Expand Down Expand Up @@ -102,7 +151,7 @@ def add_cameras(self, val: Union[Camera, List[Camera]]) -> None:
val: Either a list of Camera objects or a single Camera object.
"""
if isinstance(val, list) and _validate_input(val, [Camera]):
self._cameras.extend(val)
self._cameras += val
elif isinstance(val, Camera):
self._cameras.append(val)
else:
Expand All @@ -127,6 +176,11 @@ def add_actors(self, val: Union[Actor, List[Actor]]) -> None:
f' Instead got {val}.'
)

def add_text_actor(self, val: TextActor) -> None:
"""Add a TextActor object to the scene."""
assert isinstance(val, TextActor), 'TextActor object is expected.'
self._text_actor = val

def update_scene(self) -> None:
"""Update the scene.
Expand All @@ -143,7 +197,8 @@ def update_scene(self) -> None:

self._assistants = [
Assistant(background_color=self._background_color, camera=camera,
actors=self._actors, legend_parameters=visible_legend_params)
actors=self._actors, legend_parameters=visible_legend_params,
text_actor=self._text_actor)
for camera in self._cameras]
else:
raise ValueError(
Expand Down
Loading

0 comments on commit a1caae0

Please sign in to comment.