wolfhece.wolf_array._clipping

Clipping zones for WolfArray OpenGL rendering.

Provides WolfArrayClipZone (extends header_wolf) to restrict rendering to predefined or dynamically-defined world-coordinate regions using the OpenGL scissor test.

A typical use case is a “curtain” comparison: two overlapping arrays are stacked, and a draggable ClipSlider lets the user reveal one array vs. the other by sliding a horizontal or vertical bar.

Author: HECE - University of Liege, Pierre Archambeau Date: 2024

Copyright (c) 2024 University of Liege. All rights reserved.

Module Contents

wolfhece.wolf_array._clipping.DEFAULT_COLOR = (1.0, 0.0, 1.0, 0.8)[source]
class wolfhece.wolf_array._clipping.ClipSliderEdge(*args, **kwds)[source]

Bases: enum.Enum

Inheritance diagram of wolfhece.wolf_array._clipping.ClipSliderEdge

Which edge of the clip zone the slider controls.

LEFT = 'left'[source]
RIGHT = 'right'[source]
BOTTOM = 'bottom'[source]
TOP = 'top'[source]
class wolfhece.wolf_array._clipping.WolfArrayClipZone(xmin: float = 0.0, ymin: float = 0.0, xmax: float = 1.0, ymax: float = 1.0, active: bool = True, owner_name: str = '', invert: bool = False)[source]

Bases: wolfhece.wolf_array._header_wolf.header_wolf

Inheritance diagram of wolfhece.wolf_array._clipping.WolfArrayClipZone

Rectangular clipping zone in world coordinates.

Extends header_wolf so that existing spatial tools (find_intersection(), get_bounds(), …) work seamlessly.

The zone is defined by world-coordinate bounds [xmin, xmax] × [ymin, ymax]. When active, the zone is applied as an OpenGL scissor rectangle during rendering: only the pixels that fall inside the zone are drawn.

Usage:

clip = WolfArrayClipZone(xmin=160000, ymin=130000,
                         xmax=170000, ymax=140000)
my_array.add_clip_zone(clip)

Or from an existing header (another WolfArray for instance):

clip = WolfArrayClipZone.from_header(other_array)
active = True[source]
owner_name = ''[source]
invert = False[source]
_sliders: list[ClipSlider] = [][source]
set_bounds_clip(xmin: float, ymin: float, xmax: float, ymax: float)[source]

Set the clipping zone from world-coordinate bounds.

property clip_xmin: float[source]
property clip_xmax: float[source]
property clip_ymin: float[source]
property clip_ymax: float[source]
world_to_scissor(view_xmin: float, view_ymin: float, view_xmax: float, view_ymax: float, vp_width: int, vp_height: int) tuple[int, int, int, int][source]

Convert world-coordinate bounds to a glScissor rectangle.

The returned (sx, sy, sw, sh) tuple is in window-pixel coordinates, clamped to the current viewport.

Parameters:
  • view_xmin – Current viewport left (world coords).

  • view_ymin – Current viewport bottom (world coords).

  • view_xmax – Current viewport right (world coords).

  • view_ymax – Current viewport top (world coords).

  • vp_width – Viewport width in pixels.

  • vp_height – Viewport height in pixels.

enable_scissor(view_xmin: float, view_ymin: float, view_xmax: float, view_ymax: float, vp_width: int, vp_height: int)[source]

Enable GL_SCISSOR_TEST restricted to this clip zone.

static disable_scissor()[source]

Disable GL_SCISSOR_TEST.

draw_border(color: tuple = DEFAULT_COLOR, width: float = 2.0)[source]

Draw the clip-zone border as a world-coordinate rectangle.

property sliders: list[ClipSlider][source]

All ClipSlider objects attached to this zone.

property slider: ClipSlider | None[source]

First attached slider, or None.

attach_slider(edge: ClipSliderEdge = ClipSliderEdge.RIGHT, **kwargs) ClipSlider[source]

Create and attach a ClipSlider controlling edge.

Extra kwargs are forwarded to the ClipSlider constructor.

Returns:

The newly created slider.

serialize() dict[source]

Return a JSON-compatible dict describing this clip zone.

classmethod deserialize(data: dict) WolfArrayClipZone[source]

Reconstruct a clip zone from a serialized dict.

classmethod from_header(h: wolfhece.wolf_array._header_wolf.header_wolf, active: bool = True, owner_name: str = '') WolfArrayClipZone[source]

Create a clip zone matching a header_wolf extent.

classmethod from_extent(xmin: float, ymin: float, xmax: float, ymax: float, active: bool = True, owner_name: str = '') WolfArrayClipZone[source]

Alias for the regular constructor (explicit factory).

class wolfhece.wolf_array._clipping.ClipSlider(clip_zone: WolfArrayClipZone, edge: ClipSliderEdge = ClipSliderEdge.RIGHT, color: tuple = DEFAULT_COLOR, line_width: float = 3.0, grab_tolerance_px: int = 8, owner_name: str = '')[source]

Draggable horizontal or vertical bar controlling a clip-zone edge.

Provides the visual bar, hit testing, and drag logic. Mouse-event dispatch must be wired from the host viewer (e.g. WolfMapViewer).

clip_zone[source]
edge[source]
color = (1.0, 0.0, 1.0, 0.8)[source]
line_width = 3.0[source]
grab_tolerance_px = 8[source]
owner_name = ''[source]
_dragging = False[source]
property position: float[source]

Current world-coordinate position of the controlled edge.

property is_horizontal: bool[source]

True if the bar is horizontal (top / bottom edge).

property label: str[source]

Human-readable label for status-bar display.

draw(view_xmin: float, view_ymin: float, view_xmax: float, view_ymax: float)[source]

Draw the slider bar across the full viewport extent.

Must be called outside any active scissor test so the bar is always fully visible.

hit_test(world_x: float, world_y: float, sx: float, sy: float) bool[source]

Check whether a world-coordinate point is close enough to grab.

Parameters:
  • world_x – Pointer X in world coordinates.

  • world_y – Pointer Y in world coordinates.

  • sx – Pixels per world-unit (horizontal scale).

  • sy – Pixels per world-unit (vertical scale).

Returns:

True if within grab_tolerance_px pixels.

start_drag()[source]

Begin a drag operation.

update_drag(world_x: float, world_y: float)[source]

Update the controlled edge position during a drag.

end_drag()[source]

Finish a drag operation.

property is_dragging: bool[source]

True while a drag is in progress.

serialize() dict[source]

Return a JSON-compatible dict.

class wolfhece.wolf_array._clipping.ClipConfig(name: str, owner_name: str, zones: list[WolfArrayClipZone])[source]

Named snapshot of clip zones for one array.

name[source]
owner_name[source]
zones[source]
serialize() dict[source]
classmethod deserialize(data: dict) ClipConfig[source]
class wolfhece.wolf_array._clipping.ClipConfigs[source]

Collection of named ClipConfig snapshots.

Follows the same pattern as Memory_Views.

configs: dict[str, ClipConfig][source]
add(cfg: ClipConfig)[source]
remove(name: str)[source]
reset()[source]
save(filename: str)[source]
load(filename: str)[source]