Compare commits

..
2 Commits
60 changed files with 2799 additions and 4636 deletions
-246
View File
@@ -1,246 +0,0 @@
Annotation and view-object rendering notes
==========================================
Scope
-----
BRL-CAD has two related, but deliberately distinct, ways to represent visual
markup:
* An annotation is an ID_ANNOT database primitive. It is persistent model
content with enough semantic and presentation information to be reproduced
outside the application that created it.
* A view object is application-owned scene state. It is useful for interactive
construction and manipulation, but is intentionally not backed by a database
object.
They share portions of the interactive display infrastructure, but they do not
currently have interchangeable ownership, lifetime, or rendering semantics.
Annotation capabilities
-----------------------
An rt_annot_internal stores a model-space anchor, a set of 2D vertices, and
either a model plane basis or screen-space placement. Its segment types cover
lines, circular arcs, NURBS, Beziers, text, and filled polygons. Segment style
records include a semantic role, line pattern and width, RGBA color, font or
symbol, text scaling, and decorative flags.
The libged annotate command can create styled text, leaders, linear/angular/
radius/diameter/ordinate dimensions, and bounding-box autodim groups. It can
regenerate derived annotations from saved attributes and associate them with
source model objects without making them part of those objects' CSG trees.
Annotations therefore have the properties needed for persistent markup:
* database naming, paths, transforms, and instances;
* survival across save/reopen and transfer to another application;
* semantic segment roles and per-segment presentation data;
* model-space and view-dependent screen-space placement; and
* high-level generation metadata and source-object associations.
An annotation is informational coverage, not a CSG solid. The raytracing
implementation preserves that distinction. It prepares annotation coverage
from active database paths and composites it on primary samples after ordinary
geometry has established color and depth. Model-space annotation coverage is
occluded by nearer solid geometry. Screen-space annotation coverage uses the
render view and image dimensions. Annotations do not acquire artificial
volume, alter model bounds, cast shadows, or participate in reflection and
refraction rays.
Visible coverage is returned in back-to-front layers. Model-space layers are
ordered by ray distance, followed by view-space layers ordered by projected
anchor depth; segment draw order breaks ties within an annotation. This lets
the image renderers apply source-over alpha consistently while retaining the
single-frontmost-hit query for compatibility. NIRT continues to report one
frontmost segment per model-space annotation rather than exposing these
presentation layers as solid partitions.
Color follows normal database tree state. An annotation segment with an
explicit RGBA style wins; otherwise it inherits the resolved combination-path
color; otherwise it is white. The legacy region-ID color table is not applied
to annotation display or coverage, since annotations are informational leaves
rather than regions.
Prepared coverage uses the existing libbg RTree implementation. A 3D RTree
culls model-space annotation instances and a 2D local RTree culls segments
inside every annotation. Screen-space instance extents cannot be placed in a
static world-space index because they change with the view, so those instances
remain in a compact list while still using their local segment RTree. This
avoids a new spatial data structure and keeps prepared scenes immutable and
safe for concurrent sample queries.
The rt, ART, and ADRT/ISST integrations follow this overlay model. ERT invokes
rt with the database, displayed database paths, and view, so database-backed
annotations can follow that route as well. ERT does not currently serialize
or pass application-owned view objects to its subprocess.
NIRT keeps annotation diagnostics opt-in. `useannot 1` enables model-space
annotation intersections, and the `fmt a` action reports them. Default NIRT
output is unchanged. Screen-space annotations are deliberately omitted
because a NIRT ray does not define an image size, pixel footprint, or complete
model-to-view mapping.
View-object capabilities
------------------------
The core representation is bv_scene_obj. A view set owns shared view objects,
and a particular bview can also own local objects. Independent views force
local ownership. bv_obj_put recycles objects when their application lifetime
ends; the objects are not written to the .g database.
The `view obj` command exposes the principal markup types:
* Lines are model-coordinate polylines represented by vlists. Generic scene
rendering can add arrowheads to segment ends.
* Labels have a model anchor and optional model-space target/leader. Their text
is projected and drawn as screen-facing HUD text. If the command omits Z,
screen X/Y coordinates are projected onto the current view plane at creation
time.
* Polygons include general polygons, circles, ellipses, rectangles, and
squares. Creation and editing operate on a saved view plane with a view-Z
offset. Selection, movement, open/close, area, overlap, and 2D boolean
operations are supported. A "fill" is currently a set of hatch lines, not
an opaque surface. Polygons can be explicitly imported from or exported to
persistent sketch primitives.
Scene objects also provide object color, transparency, pixel line width, dash
style, and arrow dimensions. Not all of these properties have a uniform
command interface for every object type.
There are other visual layers that should not be conflated with these objects.
Legacy gv_tcl data/sdata arrows, axes, lines, labels, and polygons have a
separate representation. Faceplate/HUD elements are screen UI. Database
objects temporarily cloned for editing are also transient, but retain database
primitive semantics and live in the database-object scene containers.
Comparison
----------
Both annotations and view objects eventually produce display-manager pixels,
often through bv_scene_obj and vlists. That common final path does not make
their source representations equivalent.
Annotations are the canonical choice when markup must be saved, named in a
database, instanced, shared, raytraced from a .g file, or understood by another
program. View objects are the right choice for application/session state that
must be created and manipulated without changing the database.
Some view objects have a direct annotation analogue, but conversion is not
lossless without type-aware logic:
* A view polyline maps naturally to line segments, including arrowhead style.
* A polygon outline and its hatch lines can map to annotation coverage, but the
existing view "fill" must not silently become an opaque filled polygon.
* A label is hybrid. Its target and leader are model-space geometry while its
glyphs remain screen-facing at a projected model anchor.
* Arbitrary vlist extraction is insufficient because display-matrix commands,
point and line sizes, child objects, glyph behavior, and semantic roles are
otherwise lost or ambiguous.
View-object line width and annotation line width also need an explicit unit
policy. View-object widths are display pixels. Screen-space annotation widths
are view-dependent coverage widths. A model-space annotation's line_width is
used as a scale on the automatically selected model-space stroke width. In
other words, removing a separate raytracer "stroke-width" setting does not
remove width control: the annotation's existing line_width/`--line-width`
style remains the single user-facing control. The renderer interprets it in
the appropriate coordinate system rather than exposing a second competing
knob.
Recommended transient rendering design
--------------------------------------
Do not make librt or the raytracers depend on bv_scene_obj, libbv application
containers, or libged. Do not manufacture tubes, TGCs, meshes, or geometry
just in front of the view plane. Artificial geometry would affect bounds,
depth, shadows, and secondary rays, and would make antialiasing and perspective
behavior depend on a fabricated distance from the eye.
If transient view objects need to appear in raytraced output, use an explicit
application-to-renderer snapshot boundary:
1. The GED/application layer snapshots selected live view objects when a render
is launched. This is the only layer that owns their lifetime and semantics.
2. A type-aware adapter in libged or libbv translates supported objects into a
renderer-neutral overlay/coverage description. It should reuse annotation
coverage preparation through an in-memory annotation-instance interface,
rather than duplicate line, glyph, and arrow intersection algorithms.
3. The snapshot travels with the exact view state: model-to-view transform,
perspective, image width and height, and sampling convention. In-process
renderers can receive it directly; subprocess rt/ERT needs an explicit
serialized side channel.
4. Raytracers composite this coverage only on primary image samples, after
geometry color and depth are known. It remains outside CSG, model bounds,
shadows, reflections, and refractions.
5. Initial support should be deliberately finite: polyline strokes and
arrowheads, label glyphs and leaders, polygon outlines, and polygon hatches.
Faceplate elements and legacy gv_tcl overlays should be separately specified
opt-in layers rather than being included accidentally.
6. Snapshot records should preserve object name and type, RGBA, visibility,
local/shared ownership, presentation units, and source identity. Unsupported
object types should produce a deliberate diagnostic or documented omission.
Application-side compositing of the interactive display-manager layer over an
ERT framebuffer is a viable smaller feature if only ERT screen captures need
view objects. It would closely reproduce the interactive view, but it would
not make the objects available to standalone rt, ART, or ISST output and should
not be presented as the general renderer solution.
Conversion between the two systems should remain explicit. Automatically
turning view objects into database annotations would violate their deliberately
transient contract. A user command to promote selected view markup to a
persistent annotation would be reasonable; polygon-to-sketch export is an
existing precedent. Conversely, a view-object editor may be used as a front
end for constructing an annotation, provided the persistence action is clear.
Maintenance findings before implementing the adapter
----------------------------------------------------
Several representation issues should be corrected before type-driven snapshot
conversion is relied upon:
* Container-selection flags (BV_DB_OBJS, BV_VIEW_OBJS, BV_LOCAL_OBJS, and
BV_CHILD_OBJS) reuse numeric bits also used for semantic s_type_flags
(BV_DBOBJ_BASED, BV_VIEWONLY, BV_LINES, and others). bv_obj_create currently
assigns its type argument to s_type_flags. A local view object consequently
acquires BV_LINES incidentally, while the line command does not explicitly
tag lines. The namespaces should be separated and every object explicitly
typed.
* Lines, labels, and polygons should have unambiguous type tags and per-type
lifecycle/extraction callbacks. Snapshot conversion must inspect typed data,
not infer semantics from a rendered vlist.
* Label construction should initialize every bv_label field deliberately,
including size, line_flag, anchor, arrow, and target. Current construction
does not establish all of those values on every path.
* The status of legacy gv_tcl overlay data should be decided explicitly:
migrate it, support it through a separate adapter, or document its exclusion.
* Screen-space annotation display and raytrace units need a parity test. The
legacy display-matrix vlist path and the ray coverage path currently express
screen offsets through different mechanisms; their apparent agreement must
be verified rather than assumed.
* Per-segment annotation colors exceed the legacy interactive vlist object's
single-color model. Uniform annotate-command colors work today, but true
multicolor interactive parity may require split scene objects or a richer
display representation.
Tests for a future adapter should cover shared and local ownership, cleanup,
label anchors and leaders, polygon holes/hatches/view-Z, perspective, pixel
width, model-space occlusion, screen-space overlay, and serialization across
the ERT subprocess boundary.
Conclusion
----------
Persistent annotations and transient view objects should continue to coexist.
The annotation coverage scene is the correct renderer-side abstraction for
both saved annotations and a future snapshot of transient markup. The
application should perform the semantic conversion and transfer a view-complete
snapshot; the renderer should treat it as primary-ray coverage, never as
invented scene geometry.
+1 -53
View File
@@ -132,10 +132,6 @@ Command to set the backout flag. With no option, prints the current value. When
Sets the _useair_ member of the __rt_i__ structure to the integer _n_. If _n_ is 0, then *nirt* ignores any air in the geometry. If this command is invoked with no arguments, *nirt* prints the current value of _useair_. Default is 0.
*useannot [* _n_*]*::
Enables (_n_=1) or disables (_n_=0) diagnostic annotation intersections. When enabled, *nirt* evaluates all model-space annotations below the active database paths and invokes the *a* output action for each crossing. Screen-space annotations are not evaluated because an individual NIRT ray does not supply a pixel size or model-to-view transform. If this command is invoked with no arguments, *nirt* prints the current value. Default is 0.
*overlap_claims [* _n_*]*::
Specifies how to handle multiple regions' claims to segments of a ray. If _n_ is 0 or "resolve", then all overlaps are resolved in favor of a single region and any other claimants are ignored. If _n_ is 2 or "rebuild_all", then all overlaps are rebuilt, so any overlapping regions along the ray create individual (geometrically intersecting) partitions. If _n_ is 3 or "retain", then all overlaps are retained. In this case, the resulting partitions are always geometrically disjoint, each one is owned by a single region according to the current overlap resolution strategy, but every claimant is recorded. If _n_ is 1 or "rebuild_fastgen", then *nirt* takes on _FASTGEN_ behavior, so overlaps of plate-mode primitives are rebuilt, but other overlaps are retained. This command is useful with the __claimant_count__, __claimant_list__, and __claimant_listn__ output items. Default is "resolve".
@@ -201,11 +197,7 @@ Quits *nirt*.
[[output_statements]]
== OUTPUT STATEMENTS
*nirt* allows the user a high degree of control, via the _fmt_ command, over what information gets printed out for each ray and in what format. There are eight types of output statements, each of which is executed under appropriate circumstances. The types and their use are:
*a*::
Annotation. Executed once for each model-space annotation crossing when *useannot* is enabled. Crossings are reported in ray-distance order after the ordinary solid shotline output. The default format is empty.
*nirt* allows the user a high degree of control, via the _fmt_ command, over what information gets printed out for each ray and in what format. There are six types of output statements, each of which is executed under appropriate circumstances. The types and their use are:
*r*::
@@ -286,41 +278,6 @@ azimuth of view (i.e., of ray direction).
elevation of view (i.e., of ray direction).
Annotation Information
*annot_path*::
full database path of the annotation primitive.
*annot_segment*::
zero-based annotation segment index.
*annot_role*::
semantic role of the annotation segment, such as `text`, `leader`, `dimension`, or `arrowhead`.
*annot_x*::
_x_ coordinate of the annotation hit point.
*annot_y*::
_y_ coordinate of the annotation hit point.
*annot_z*::
_z_ coordinate of the annotation hit point.
*annot_d*::
_d_ grid-plane coordinate of the annotation hit point.
*annot_visible*::
1 if no non-air solid surface is closer to the ray origin, otherwise 0. Occluded annotation crossings are still reported so they can be inspected during debugging.
Partition Information
@@ -564,15 +521,6 @@ nirt -A material_id -A los_density model.g all
Each region the ray passes through is reported together with its _material_id_ and _los_density_ attribute values via the *attributes* output item, which is useful for vulnerability and mass-properties analyses.
====
.Reporting annotation crossings for debugging
====
[source,bash]
----
nirt -s -e 'useannot 1;fmt a "%s %d (%g %g %g) visible=%d\n" annot_path annot_segment annot_x annot_y annot_z annot_visible;s' model.g component dimensions
----
This opt-in format reports every model-space annotation crossing and whether it is in front of the first solid surface. Ordinary NIRT output is unchanged unless *useannot* is enabled and an *a* format is supplied.
====
[[hints]]
== HINTS
+2 -32
View File
@@ -25,7 +25,7 @@ where the "char" argument is replaced by a single character identifying the cate
[[nirt_format_categories]]
== Output Categories
NIRT offers eight categories of output reporting:
NIRT offers seven categories of output reporting:
[cols="3*"]
[%noheader]
@@ -33,9 +33,6 @@ NIRT offers eight categories of output reporting:
|*Category Name*
|*Char*
|*Description*
|*Annotation*
|*a*
|Output for each model-space annotation crossing when annotation reporting is enabled with *useannot 1*. The default annotation format is empty.
|*Ray*
|*r*
|Report of ray information. The formatting associated with r will print once per ray, regardless of whether a region is encountered.
@@ -65,7 +62,7 @@ NIRT offers eight categories of output reporting:
[[nirt_format_str]]
== Format Strings
NIRT's format specifications are a subset of those found in printf implementations. The d, i, f, e, E, g, G, and s types are supported, as well as width and precision specifiers.
NIRT's format specifications are a subset of those found in printf implementations. Specifically, the d, i, and f types are supported, as well as width and precision specifiers.
[[nirt_format_keys]]
@@ -103,33 +100,6 @@ Unlike the full C/C++ printf, NIRT accepts only pre-defined string keys that ide
Footnote and Miss categories have no particular keys unique to them, although they (like all categories) can use the Ray keys if desired. Partition, Overlap, and Gap, on the other hand, have keys that are unique to their contexts and valid only within those contexts:
.Annotation Variables
[cols="2*"]
[%noheader]
|===
|annot_path
|Full database path of the annotation primitive.
|annot_segment
|Zero-based annotation segment index.
|annot_role
|Semantic role of the annotation segment, such as `text`, `leader`, `dimension`, or `arrowhead`.
|annot_x
|x coordinate of the annotation hit point.
|annot_y
|y coordinate of the annotation hit point.
|annot_z
|z coordinate of the annotation hit point.
|annot_d
|d grid-plane coordinate of the annotation hit point.
|annot_visible
|1 if no non-air solid surface is closer to the ray origin, otherwise 0.
|===
Annotation reporting is diagnostic and opt-in. It returns all model-space
annotation crossings in ray-distance order, including occluded crossings.
Screen-space annotations are not reported because a NIRT shot does not define
the pixel dimensions and model-to-view transform needed to evaluate them.
.Partition Variables
[cols="2*"]
[%noheader]
+9 -8
View File
@@ -40,11 +40,12 @@ Coordinates and explicit sizes use the database's current modeling units.
Creation commands draw the new annotation immediately. Use *--no-draw* to
create it without changing the display. Names must not already exist.
Ray-traced annotations are zero-thickness informational coverage rather than
solid regions. Model-space annotations are depth-tested against ordinary
geometry. Screen-space annotations are generated for the current camera and
composited in the foreground; they do not participate in shadows, reflections,
line-of-sight thickness, or Boolean evaluation.
Model-space annotations also participate in raytracing. Librt expands their
strokes and filled areas into transient mesh geometry during preparation; the
generated geometry is not written to the database. It uses the normal region
material and color resolved from the containing combination tree. Screen-space
annotations remain display-only because primitive preparation has no render
view or image dimensions with which to place them.
The supported dimensions follow the general presentation conventions of ISO
129-1. Lettering defaults to OSIFont, an ISO 3098-style technical font shipped
@@ -208,9 +209,9 @@ Set the persistent annotation color using integer red, green, and blue values
from 0 through 255.
*--line-width width*::
Set the presentation line width. Display and screen-space ray rendering use
the value as a pixel width. Model-space ray rendering uses it to scale the
automatic stroke width derived from the annotation's text height or extent.
Set the display line width. For a model-space raytrace, this value scales the
physical stroke width inferred from the annotation's text height or overall
extent.
*--line-style style*::
Set semantic line-pattern metadata to *continuous*, *dashed*, *dotted*,
+164
View File
@@ -0,0 +1,164 @@
/* B I N D I N G . H
* BRL-CAD
*
* Copyright (c) 2026 United States Government as represented by
* the U.S. Army Research Laboratory.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; see the file named COPYING for more
* information.
*/
/** @addtogroup bu_binding
* @brief
* Universal input binding schema and action dispatch.
*/
/** @{ */
/** @file bu/binding.h */
#ifndef BU_BINDING_H
#define BU_BINDING_H
#include "common.h"
#include "bu/defines.h"
#include "bu/vls.h"
__BEGIN_DECLS
/* Standardized Attribute Keys (for W3C validation logic) */
#define BU_BINDING_ATTR_TYPE "type"
#define BU_BINDING_ATTR_KEY "key" /* Values MUST be W3C standard strings */
#define BU_BINDING_ATTR_BUTTON "button" /* Values MUST be W3C button integers */
#define BU_BINDING_ATTR_MODIFIERS "modifiers"
/* Standardized Event Types */
#define BU_BINDING_EVENT_KEY_PRESS "key-press"
#define BU_BINDING_EVENT_KEY_RELEASE "key-release"
#define BU_BINDING_EVENT_MOUSE_PRESS "mouse-press"
#define BU_BINDING_EVENT_MOUSE_RELEASE "mouse-release"
#define BU_BINDING_EVENT_MOUSE_MOTION "mouse-motion"
#define BU_BINDING_EVENT_MOUSE_SCROLL "mouse-scroll"
/**
* @brief Action callback signature
*
* Invoked when an incoming event matches a loaded binding.
* The callback receives the full JSON string of the triggering event.
*
* @param event_json Raw JSON string describing the incoming event
* @param registered_data Opaque pointer passed during registration
* @param event_data Opaque pointer passed during event processing
*/
typedef void (*bu_action_func_t)(const char *event_json, void *registered_data, void *event_data);
/**
* @brief Load JSON bindings from a file
*
* Parses a JSON configuration specifying bindings for various contexts.
* Performs two-phase validation:
* 1. Checks standard fields (like W3C key strings) for correctness.
* 2. Invokes context-specific validation hooks (if registered).
*
* @param json_path Path to the JSON file
* @return 0 on success, <0 on error
*/
BU_EXPORT extern int bu_binding_load(const char *json_path);
/**
* @brief Load JSON bindings from a raw string
*
* Parses a JSON configuration string specifying bindings for various contexts.
* Allows applications to embed overriding bindings natively without external files.
*
* @param json_string Raw JSON string containing bindings
* @return 0 on success, <0 on error
*/
BU_EXPORT extern int bu_binding_load_str(const char *json_string);
/**
* @brief Register a JSON schema for a specific context
*
* Defines the allowed vocabulary for a context using a JSON schema file.
* The schema file is lazily parsed during bu_binding_load().
*
* @param context The interaction context (e.g., "dm", "fb")
* @param json_path Absolute path to the schema JSON file
*/
BU_EXPORT extern void bu_binding_register_schema(const char *context, const char *json_path);
/**
* @brief Augment an existing schema with a custom action
*
* @param context The interaction context (e.g., "dm")
* @param action_name The new abstract action string
* @param description Human-readable description of the action
*/
BU_EXPORT extern void bu_binding_schema_add_action(const char *context, const char *action_name, const char *description);
/**
* @brief Remove a custom action from an existing schema
*
* @param context The interaction context (e.g., "dm")
* @param action_name The abstract action string to remove
*/
BU_EXPORT extern void bu_binding_schema_remove_action(const char *context, const char *action_name);
/**
* @brief Register a C callback for a semantic action
*
* @param action_name The abstract action string (e.g., "fb_close_window")
* @param func The C function to invoke when the action is triggered
* @param client_data Opaque pointer passed to the callback
*/
BU_EXPORT extern void bu_binding_register_action(const char *action_name, bu_action_func_t func, void *client_data);
/**
* @brief Process an incoming native event
*
* Matches the event JSON against the loaded bindings for the given context.
* If a matching action is found and a handler is registered for that action,
* the callback is invoked.
*
* @param context The interaction context (e.g., "view3d", "fb_raw")
* @param event_json A JSON string containing the event attributes
* @param event_data Opaque pointer passed to the callback representing instance state
* @return 1 if an action was triggered and handled, 0 otherwise
*/
BU_EXPORT extern int bu_binding_process_event(const char *context, const char *event_json, void *event_data);
/**
* @brief Check if a specific action is bound in a given context
*
* Use this to verify that an application has provided a binding for an essential action.
*
* @param context The interaction context (e.g., "view3d", "fb_raw")
* @param action_name The abstract action string (e.g., "view_mouse_drag_rotate")
* @return 1 if bound, 0 if not
*/
BU_EXPORT extern int bu_binding_action_is_bound(const char *context, const char *action_name);
__END_DECLS
#endif /* BU_BINDING_H */
/** @} */
/*
* Local Variables:
* mode: C
* tab-width: 8
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/
+3
View File
@@ -444,6 +444,9 @@ DM_EXPORT extern int fb_get_interactive(const struct fb *ifp);
*/
DM_EXPORT extern int fb_next_event(struct fb *ifp, struct fb_event *e);
/** Dispatch an application-facing event through the framebuffer bindings. */
DM_EXPORT extern int fb_process_event_bindings(struct fb *ifp, const struct fb_event *e);
/* Library entry points */
-85
View File
@@ -29,19 +29,10 @@
#include "bu/list.h"
#include "bu/vls.h"
#include "bn/tol.h"
#include "rt/geom.h"
#include "rt/defines.h"
__BEGIN_DECLS
struct db_i;
struct xray;
#define RT_ANNOT_SCREEN_DPI 96.0
#define RT_ANNOT_MILLIMETERS_PER_INCH 25.4
#define RT_ANNOT_SCREEN_PIXELS_PER_MM \
(RT_ANNOT_SCREEN_DPI / RT_ANNOT_MILLIMETERS_PER_INCH)
RT_EXPORT extern struct rt_annot_internal *rt_copy_annot(const struct rt_annot_internal *annot_ip);
/** Validate annotation topology, model-space placement, and optional segment
@@ -49,82 +40,6 @@ RT_EXPORT extern struct rt_annot_internal *rt_copy_annot(const struct rt_annot_i
RT_EXPORT extern int rt_annot_validate(const struct rt_annot_internal *annot_ip,
struct bu_vls *messages);
/** Opaque, immutable collection of prepared annotation instances. */
struct rt_annot_scene;
/** Camera state needed to evaluate view-space annotations. Pixel sample
* coordinates use a lower-left origin. */
struct rt_annot_view {
mat_t model2view;
size_t width;
size_t height;
fastf_t perspective;
};
/** A zero-thickness annotation coverage event. path is owned by the scene. */
struct rt_annot_hit {
const char *path;
size_t segment;
uint32_t role;
point_t point;
fastf_t distance;
unsigned char color[4];
int screen_space;
int visible;
};
/** Prepare annotations referenced by the supplied top-level database paths.
* Boolean operations are intentionally ignored: annotations are
* informational leaves, not solids. */
RT_EXPORT extern struct rt_annot_scene *rt_annot_scene_create(
struct db_i *dbip, int path_count, const char * const *paths,
const struct bg_tess_tol *ttol, const struct bn_tol *tol);
RT_EXPORT extern void rt_annot_scene_destroy(struct rt_annot_scene *scene);
RT_EXPORT extern size_t rt_annot_scene_count(const struct rt_annot_scene *scene);
/** Return model-space bounds for prepared annotations. Screen-space geometry
* contributes its model-space anchor because its extent is view-dependent. */
RT_EXPORT extern int rt_annot_scene_bounds(const struct rt_annot_scene *scene,
point_t minimum, point_t maximum);
/** Return the top visible coverage event for a primary sample. */
RT_EXPORT extern int rt_annot_scene_query(const struct rt_annot_scene *scene,
const struct rt_annot_view *view, const struct xray *ray,
fastf_t sample_x, fastf_t sample_y, fastf_t scene_distance,
struct rt_annot_hit *hit);
/** Return all visible primary-sample coverage events in back-to-front order.
* Model-space events precede screen-space events. When hits is NULL or
* capacity is zero, only the required result count is returned. */
RT_EXPORT extern size_t rt_annot_scene_query_layers(
const struct rt_annot_scene *scene, const struct rt_annot_view *view,
const struct xray *ray, fastf_t sample_x, fastf_t sample_y,
fastf_t scene_distance, struct rt_annot_hit *hits, size_t capacity);
/** Return all model-space coverage events, sorted by ray distance. When hits
* is NULL or capacity is zero, only the required result count is returned. */
RT_EXPORT extern size_t rt_annot_scene_query_model(const struct rt_annot_scene *scene,
const struct xray *ray, fastf_t scene_distance,
struct rt_annot_hit *hits, size_t capacity);
/** Alpha-composite a coverage result over a linear RGB sample. */
RT_EXPORT extern void rt_annot_hit_blend(fastf_t color[3],
const struct rt_annot_hit *hit);
/** Alpha-composite all visible primary-sample coverage over color. If
* front_hit is non-NULL, it receives the frontmost event. */
RT_EXPORT extern int rt_annot_scene_composite(const struct rt_annot_scene *scene,
const struct rt_annot_view *view, const struct xray *ray,
fastf_t sample_x, fastf_t sample_y, fastf_t scene_distance,
fastf_t color[3], struct rt_annot_hit *front_hit);
/** Generate one annotation segment in annotation-local XY coordinates. This
* is shared by plotting and the coverage preparer to keep curve and font
* expansion identical. */
RT_EXPORT extern int rt_annot_segment_vlist(struct bu_list *vlfree,
struct bu_list *vhead, const struct bg_tess_tol *ttol,
const struct rt_annot_internal *annot_ip, size_t segment);
__END_DECLS
/** @} */
-1
View File
@@ -1,6 +1,5 @@
# default.nrt
# Description: default - Standard NIRT Reporting Format
fmt a ""
fmt r "Origin (x y z) = (%.8f %.8f %.8f) (h v d) = (%.4f %.4f %.4f)\nDirection (x y z) = (%.8f %.8f %.8f) (az el) = (%.8f %.8f)\n" x_orig y_orig z_orig h v d_orig x_dir y_dir z_dir a e
fmt h " Region Name Entry (x y z) LOS Obliq_in Attrib\n"
fmt p "%-20s (%9.4f %9.4f %9.4f) %8.4f %8.4f%s\n" reg_name x_in y_in z_in los obliq_in attributes
+2 -3
View File
@@ -53,7 +53,7 @@ set(
)
brlcad_addlib(librender "${LIBRENDER_SRCS}" "" "${ADRT_LOCAL_INCLUDE_DIRS}"
PRIVATE_LIBS libgcv librt ZLIB::ZLIB ${M_LIBRARY}
PRIVATE_LIBS libgcv ZLIB::ZLIB ${M_LIBRARY}
)
set_target_properties(librender PROPERTIES VERSION 20.0.1 SOVERSION 20)
add_dependencies(librender gcv_plugins)
@@ -109,9 +109,8 @@ cmakefiles(isst.c)
add_subdirectory(master)
add_subdirectory(slave)
add_subdirectory(tests)
set(adrt_ignore_files load.h load_g.h tienet.h)
set(adrt_ignore_files load.h tienet.h)
cmakefiles(${adrt_ignore_files})
cmakefiles(CMakeLists.txt)
-8
View File
@@ -90,19 +90,11 @@ enum
#define ADRT_NAME_SIZE 256
/* TIE geometry is normalized from millimeters to meters while loading. */
#define ADRT_MODEL_UNITS_PER_TIE_UNIT 1000.0
#define ADRT_LOAD_FORMAT_G 42
#define ADRT_LOAD_FORMAT_REG 43
#define ADRT_LOAD_FORMAT_KDTREE 44
struct rt_annot_scene;
RENDER_EXPORT extern int load_g(struct tie_s *tie, const char *db, int argc, const char **argv, struct adrt_mesh_s **);
RENDER_EXPORT extern int load_g_annotations(struct tie_s *tie, const char *db,
int argc, const char **argv, struct adrt_mesh_s **,
struct rt_annot_scene **annotations);
#endif
+38 -23
View File
@@ -59,7 +59,6 @@ struct isst_s {
struct render_camera_s camera;
struct camera_tile_s tile;
struct adrt_mesh_s *meshes;
struct rt_annot_scene *annotations;
tienet_buffer_t buffer_image;
int ogl, sflags, w, h, gs, ui;
double dt, fps, uic;
@@ -68,7 +67,6 @@ struct isst_s {
void *texdata;
vect_t camera_pos_init;
vect_t camera_focus_init;
fastf_t scene_radius;
int64_t t1;
int64_t t2;
int dirty;
@@ -121,7 +119,13 @@ resize_isst(struct isst_s *isstp)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
isstp->texdata = realloc(isstp->texdata, isstp->camera.w * isstp->camera.h * 3);
{
/* realloc through a temporary so a failure does not leak (and null out)
* the existing buffer. */
void *tmp = realloc(isstp->texdata, isstp->camera.w * isstp->camera.h * 3);
if (tmp)
isstp->texdata = tmp;
}
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, isstp->camera.w, isstp->camera.h, 0, GL_RGB, GL_UNSIGNED_BYTE, isstp->texdata);
glDisable(GL_LIGHTING);
@@ -154,14 +158,11 @@ isst_load_g(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc,
argv = (char **)malloc(sizeof(char *) * (strlen(Tcl_GetString(objv[3])) + 1)); /* allocate way too much. */
argc = (int)bu_argv_from_string(argv, strlen(Tcl_GetString(objv[3])), Tcl_GetString(objv[3]));
rt_annot_scene_destroy(isst->annotations);
isst->annotations = NULL;
load_g_annotations(isst->tie, Tcl_GetString(objv[2]), argc,
(const char **)argv, &(isst->meshes), &isst->annotations);
load_g(isst->tie, Tcl_GetString(objv[2]), argc, (const char **)argv, &(isst->meshes));
free(argv);
isst->scene_radius = render_camera_fit_scene(&isst->camera, isst->tie,
isst->annotations, ADRT_MODEL_UNITS_PER_TIE_UNIT);
VSETALL(isst->camera.pos, isst->tie->radius);
VMOVE(isst->camera.focus, isst->tie->mid);
VMOVE(isst->camera_pos_init, isst->camera.pos);
VMOVE(isst->camera_focus_init, isst->camera.focus);
@@ -238,9 +239,7 @@ paint_window(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Ob
isst->buffer_image.ind = 0;
render_camera_prep(&isst->camera);
render_camera_render_annotations(&isst->camera, isst->tie, &isst->tile,
&isst->buffer_image, isst->annotations,
ADRT_MODEL_UNITS_PER_TIE_UNIT);
render_camera_render(&isst->camera, isst->tie, &isst->tile, &isst->buffer_image);
isst->t1 = bu_gettime();
@@ -283,6 +282,7 @@ set_resolution(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_
}
CLAMP(resolution, 1, 20);
/* gs is the render grid size; 0 means render at full window resolution */
if (resolution == 20)
isst->gs = 0;
else
@@ -326,10 +326,13 @@ isst_zap(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Obj *c
return TCL_ERROR;
}
/* Release the buffers owned directly by the workspace before the struct
* itself. (The tie and mesh list have a more involved lifecycle and are
* left for a dedicated teardown.) */
TIENET_BUFFER_FREE(isst->buffer_image);
if (isst->texdata)
free(isst->texdata);
rt_annot_scene_destroy(isst->annotations);
bu_free(isst, "isst free");
isst = NULL;
@@ -351,7 +354,7 @@ render_mode(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Obj
if (objc == 4)
buf = Tcl_GetString(objv[3]);
/* pack the 'rest' into buf - probably should use a vls for this*/
/* pack the 'rest' into buf - probably should use a vls for this */
if ( strlen(mode) == 3 && bu_strncmp("cut", mode, 3) == 0 ) {
struct adrt_mesh_s *mesh;
@@ -388,22 +391,26 @@ zero_view(ClientData UNUSED(clientData), Tcl_Interp *UNUSED(interp), int UNUSED(
static int
move_walk(ClientData UNUSED(clientData), Tcl_Interp *interp, int UNUSED(objc), Tcl_Obj *const *objv)
move_walk(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
{
vect_t vec;
int flag;
if (objc < 3) {
Tcl_WrongNumArgs(interp, 1, objv, "pathName flag");
return TCL_ERROR;
}
if (Tcl_GetIntFromObj(interp, objv[2], &flag) != TCL_OK)
return TCL_ERROR;
if (flag >= 0) {
VSUB2(vec, isst->camera.focus, isst->camera.pos);
VSCALE(vec, vec, 0.1 * isst->scene_radius);
VSCALE(vec, vec, 0.1 * isst->tie->radius);
VADD2(isst->camera.pos, isst->camera.pos, vec);
VADD2(isst->camera.focus, isst->camera.focus, vec);
} else {
VSUB2(vec, isst->camera.pos, isst->camera.focus);
VSCALE(vec, vec, 0.1 * isst->scene_radius);
VSCALE(vec, vec, 0.1 * isst->tie->radius);
VADD2(isst->camera.pos, isst->camera.pos, vec);
VADD2(isst->camera.focus, isst->camera.focus, vec);
}
@@ -412,12 +419,16 @@ move_walk(ClientData UNUSED(clientData), Tcl_Interp *interp, int UNUSED(objc), T
}
static int
move_strafe(ClientData UNUSED(clientData), Tcl_Interp *interp, int UNUSED(objc), Tcl_Obj *const *objv)
move_strafe(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
{
vect_t vec, dir, up;
int flag;
if (objc < 3) {
Tcl_WrongNumArgs(interp, 1, objv, "pathName flag");
return TCL_ERROR;
}
if (Tcl_GetIntFromObj(interp, objv[2], &flag) != TCL_OK)
return TCL_ERROR;
@@ -426,13 +437,13 @@ move_strafe(ClientData UNUSED(clientData), Tcl_Interp *interp, int UNUSED(objc),
if (flag >= 0) {
VSUB2(dir, isst->camera.focus, isst->camera.pos);
VCROSS(vec, dir, up);
VSCALE(vec, vec, 0.1 * isst->scene_radius);
VSCALE(vec, vec, 0.1 * isst->tie->radius);
VADD2(isst->camera.pos, isst->camera.pos, vec);
VADD2(isst->camera.focus, isst->camera.pos, dir);
} else {
VSUB2(dir, isst->camera.focus, isst->camera.pos);
VCROSS(vec, dir, up);
VSCALE(vec, vec, -0.1 * isst->scene_radius);
VSCALE(vec, vec, -0.1 * isst->tie->radius);
VADD2(isst->camera.pos, isst->camera.pos, vec);
VADD2(isst->camera.focus, isst->camera.pos, dir);
}
@@ -540,10 +551,14 @@ aerotate(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Obj *c
VSCALE(vecdfoc, vecdfoc, mag_focus);
VADD2(isst->camera.focus, isst->camera_focus_init, vecdfoc);
}
/* Update the tcl copies of the az/el vars */
/* Update the tcl copies of the az/el vars. Store them in the same units
* as isst_load_g (radians via -DEG2RAD); previously aerotate wrote the raw
* degrees from bn_ae_vec, leaving the Tcl vars inconsistent after a drag. */
VSUB2(vec, isst->camera.focus, isst->camera.pos);
VUNITIZE(vec);
bn_ae_vec(&az, &el, vec);
az = az * -DEG2RAD;
el = el * -DEG2RAD;
bu_vls_sprintf(&tclstr, "%f", az);
Tcl_SetVar(interp, "az", bu_vls_addr(&tclstr), 0);
bu_vls_sprintf(&tclstr, "%f", el);
@@ -561,7 +576,7 @@ open_dm(ClientData UNUSED(cdata), Tcl_Interp *interp, int UNUSED(objc), Tcl_Obj
dmp = dm_open(NULL, (void *)interp, dm_default_type(), sizeof(av)/sizeof(void*)-1, (const char **)av);
if (dmp == DM_NULL) {
printf("dm failed?\n");
printf("Failed to open display manager\n");
return TCL_ERROR;
}
@@ -639,7 +654,7 @@ const char *fullname;
argv = __argv;
#endif
/* initialize progname for run-tim resource finding */
/* initialize progname for run-time resource finding */
bu_setprogname(argv[0]);
#ifdef HAVE_WINDOWS_H
+21 -225
View File
@@ -29,7 +29,6 @@
#include "bu/dylib.h"
#include "bu/log.h"
#include "bu/str.h"
#include "rt/primitives/annot.h"
#include "./camera.h"
@@ -44,27 +43,13 @@ struct render_shader_s {
static struct render_shader_s *shaders = NULL;
struct render_camera_annotation_data {
const struct rt_annot_scene *scene;
fastf_t model_units_per_tie_unit;
struct rt_annot_view view;
};
struct render_camera_parallel_data {
render_camera_thread_data_t thread;
struct render_camera_annotation_data annotation;
};
static const fastf_t render_camera_default_scene_radius = 1.0;
/* number of leading characters compared when matching a shader by name */
#define RENDER_SHADER_NAME_CMP_LEN 8
void render_camera_render_thread(int cpu, void *ptr); /* for bu_parallel */
static void render_camera_prep_ortho(render_camera_t *camera);
static void render_camera_prep_persp(render_camera_t *camera);
static void render_camera_prep_persp_dof(render_camera_t *camera);
static void render_camera_annotation_view(const render_camera_t *camera,
fastf_t model_units_per_tie_unit, struct rt_annot_view *view);
static struct render_shader_s *render_shader_register (const char *name, int (*init)(render_t *, const char *));
@@ -408,147 +393,20 @@ render_camera_prep(render_camera_t *camera)
}
fastf_t
render_camera_fit_scene(render_camera_t *camera, const struct tie_s *tie,
const struct rt_annot_scene *annotations,
fastf_t model_units_per_tie_unit)
{
point_t annotation_min, annotation_max;
point_t scene_min, scene_max;
vect_t offset;
fastf_t scene_radius;
if (!camera || !tie)
return 0.0;
if (!annotations || !rt_annot_scene_bounds(annotations,
annotation_min, annotation_max)) {
VSETALL(camera->pos, tie->radius);
VMOVE(camera->focus, tie->mid);
return tie->radius;
}
if (!isfinite(model_units_per_tie_unit) ||
model_units_per_tie_unit <= 0.0)
model_units_per_tie_unit = 1.0;
VSCALE(annotation_min, annotation_min,
1.0 / model_units_per_tie_unit);
VSCALE(annotation_max, annotation_max,
1.0 / model_units_per_tie_unit);
VMOVE(scene_min, annotation_min);
VMOVE(scene_max, annotation_max);
if (tie->tri_num) {
VMINMAX(scene_min, scene_max, tie->amin);
VMINMAX(scene_min, scene_max, tie->amax);
}
VADD2SCALE(camera->focus, scene_min, scene_max, 0.5);
VSUB2(offset, scene_max, scene_min);
scene_radius = 0.5 * MAGNITUDE(offset);
if (!isfinite(scene_radius) || scene_radius <= SMALL_FASTF)
scene_radius = render_camera_default_scene_radius;
/* Keep the established isometric initial direction while positioning it
* relative to the combined scene center. */
VSETALL(offset, scene_radius);
VADD2(camera->pos, camera->focus, offset);
return scene_radius;
}
static void
render_camera_annotation_view(const render_camera_t *camera,
fastf_t model_units_per_tie_unit, struct rt_annot_view *view)
{
vect_t look, up, side, temp, right;
point_t model_position;
fastf_t angle, sine, cosine, xy_scale = 1.0;
mat_t *matrix = &view->model2view;
VSUB2(look, camera->focus, camera->pos);
VUNITIZE(look);
VSET(up, 0.0, 0.0, 1.0);
VMOVE(temp, look);
angle = VDOT(up, temp);
VSCALE(temp, temp, angle);
VSUB2(up, up, temp);
VUNITIZE(up);
VCROSS(side, up, look);
sine = sin(-camera->tilt * DEG2RAD);
cosine = cos(-camera->tilt * DEG2RAD);
VSCALE(up, up, cosine);
VSCALE(side, side, sine);
VADD2(up, up, side);
VCROSS(side, up, look);
VREVERSE(right, side);
MAT_IDN(*matrix);
if (camera->type == RENDER_CAMERA_ORTHOGRAPHIC &&
camera->aspect > 0.0 && camera->gridsize > 0.0) {
xy_scale = 2.0 / (camera->aspect * camera->gridsize *
model_units_per_tie_unit);
} else if (camera->aspect > 0.0) {
xy_scale = 1.0 / camera->aspect;
}
for (size_t axis = 0; axis < 3; ++axis) {
(*matrix)[axis] = right[axis] * xy_scale;
(*matrix)[4 + axis] = up[axis] * xy_scale;
(*matrix)[8 + axis] = -look[axis];
}
VSCALE(model_position, camera->pos, model_units_per_tie_unit);
(*matrix)[3] = -VDOT(&(*matrix)[0], model_position);
(*matrix)[7] = -VDOT(&(*matrix)[4], model_position);
(*matrix)[11] = -VDOT(&(*matrix)[8], model_position);
view->width = camera->w;
view->height = camera->h;
view->perspective =
camera->type == RENDER_CAMERA_PERSPECTIVE ? 2.0 * camera->fov : 0.0;
}
static void
render_camera_composite_annotation(render_camera_thread_data_t *td,
const struct render_camera_annotation_data *annotation,
const struct tie_ray_s *tie_ray, fastf_t sample_x, fastf_t sample_y,
vect_t *pixel)
{
struct rt_annot_hit back_layer = {0};
struct xray ray;
fastf_t scene_distance = INFINITY;
if (!annotation || !annotation->scene)
return;
VSCALE(ray.r_pt, tie_ray->pos, annotation->model_units_per_tie_unit);
VMOVE(ray.r_dir, tie_ray->dir);
if (!rt_annot_scene_query_layers(annotation->scene, &annotation->view,
&ray, sample_x, sample_y, INFINITY, &back_layer, 1))
return;
if (!back_layer.screen_space) {
struct tie_id_s id;
struct tie_ray_s depth_ray = *tie_ray;
if (TIE_WORK(td->tie, &depth_ray, &id, render_hit, NULL))
scene_distance = id.dist * annotation->model_units_per_tie_unit;
}
(void)rt_annot_scene_composite(annotation->scene, &annotation->view,
&ray, sample_x, sample_y, scene_distance, *pixel, NULL);
}
static void
render_camera_render_thread_impl(int UNUSED(cpu), render_camera_thread_data_t *td,
const struct render_camera_annotation_data *annotation)
void
render_camera_render_thread(int UNUSED(cpu), void *ptr)
{
render_camera_thread_data_t *td;
int d, n, res_ind, scanline, v_scanline;
vect_t pixel, accum;
vect_t v1 = VINIT_ZERO;
vect_t v2 = VINIT_ZERO;
struct tie_ray_s ray;
struct tie_ray_s annotation_ray;
fastf_t view_inv;
VSETALL(v1, 0);
td = (render_camera_thread_data_t *)ptr;
view_inv = 1.0 / td->camera->view_num;
td->camera->render.tie = td->tie;
@@ -599,15 +457,9 @@ render_camera_render_thread_impl(int UNUSED(cpu), render_camera_thread_data_t *t
VMOVE(ray.pos, td->camera->view_list[d].pos);
ray.depth = 0;
VUNITIZE(ray.dir);
annotation_ray = ray;
/* Compute pixel value using this ray */
td->camera->render.work(&td->camera->render, td->tie, &ray, &pixel);
render_camera_composite_annotation(td, annotation,
&annotation_ray,
(fastf_t)n + 0.5,
(fastf_t)td->camera->h - (fastf_t)v_scanline - 0.5,
&pixel);
VADD2(accum, accum, pixel);
}
@@ -624,7 +476,6 @@ render_camera_render_thread_impl(int UNUSED(cpu), render_camera_thread_data_t *t
VMOVE(ray.pos, td->camera->view_list[0].pos);
ray.depth = 0;
VUNITIZE(ray.dir);
annotation_ray = ray;
/* Compute pixel value using this ray */
td->camera->render.work(&td->camera->render, td->tie, &ray, &pixel);
@@ -639,19 +490,12 @@ render_camera_render_thread_impl(int UNUSED(cpu), render_camera_thread_data_t *t
VSET(pixel, (TFLOAT)RENDER_CAMERA_BGR, (TFLOAT)RENDER_CAMERA_BGG, (TFLOAT)RENDER_CAMERA_BGB);
ray.depth = 0;
annotation_ray = ray;
/* Compute pixel value using this ray */
td->camera->render.work(&td->camera->render, td->tie, &ray, &pixel);
}
}
if (td->camera->view_num == 1)
render_camera_composite_annotation(td, annotation,
&annotation_ray, (fastf_t)n + 0.5,
(fastf_t)td->camera->h - (fastf_t)v_scanline - 0.5,
&pixel);
if (td->tile->format == RENDER_CAMERA_BIT_DEPTH_24) {
V_MIN(pixel[0], 1);
@@ -679,30 +523,9 @@ render_camera_render_thread_impl(int UNUSED(cpu), render_camera_thread_data_t *t
void
render_camera_render_thread(int cpu, void *ptr)
render_camera_render(render_camera_t *camera, struct tie_s *tie, camera_tile_t *tile, tienet_buffer_t *result)
{
render_camera_render_thread_impl(cpu, (render_camera_thread_data_t *)ptr,
NULL);
}
static void
render_camera_render_annotations_thread(int cpu, void *ptr)
{
struct render_camera_parallel_data *data =
(struct render_camera_parallel_data *)ptr;
render_camera_render_thread_impl(cpu, &data->thread, &data->annotation);
}
static void
render_camera_render_internal(render_camera_t *camera, struct tie_s *tie,
camera_tile_t *tile, tienet_buffer_t *result,
const struct rt_annot_scene *annotations,
fastf_t model_units_per_tie_unit)
{
struct render_camera_parallel_data data = {0};
render_camera_thread_data_t td;
unsigned int scanline;
uint32_t ind;
@@ -720,47 +543,19 @@ render_camera_render_internal(render_camera_t *camera, struct tie_s *tie,
TCOPY(camera_tile_t, tile, 0, result->data, result->ind);
result->ind += sizeof(camera_tile_t);
data.thread.tie = tie;
data.thread.camera = camera;
data.thread.tile = tile;
data.thread.res_buf = &((char *)result->data)[result->ind];
td.tie = tie;
td.camera = camera;
td.tile = tile;
td.res_buf = &((char *)result->data)[result->ind];
scanline = 0;
data.thread.scanline = &scanline;
data.thread.sem_tie_worker = bu_semaphore_register("sem_tie_worker");
data.annotation.scene = annotations;
data.annotation.model_units_per_tie_unit =
model_units_per_tie_unit > 0.0 ? model_units_per_tie_unit : 1.0;
if (annotations)
render_camera_annotation_view(camera,
data.annotation.model_units_per_tie_unit, &data.annotation.view);
td.scanline = &scanline;
td.sem_tie_worker = bu_semaphore_register("sem_tie_worker");
if (annotations)
bu_parallel(render_camera_render_annotations_thread,
camera->thread_num, &data);
else
bu_parallel(render_camera_render_thread, camera->thread_num,
&data.thread);
bu_parallel(render_camera_render_thread, camera->thread_num, &td);
result->ind = ind;
}
void
render_camera_render(render_camera_t *camera, struct tie_s *tie,
camera_tile_t *tile, tienet_buffer_t *result)
{
render_camera_render_internal(camera, tie, tile, result, NULL, 1.0);
}
void
render_camera_render_annotations(render_camera_t *camera, struct tie_s *tie,
camera_tile_t *tile, tienet_buffer_t *result,
const struct rt_annot_scene *annotations,
fastf_t model_units_per_tie_unit)
{
render_camera_render_internal(camera, tie, tile, result, annotations,
model_units_per_tie_unit);
return;
}
@@ -825,9 +620,9 @@ render_shader_unload_plugin(render_t *r, const char *name)
{
#ifdef HAVE_DLFCN_H
struct render_shader_s *t, *s = shaders, *meh;
if (!bu_strncmp(s->name, name, 8)) {
if (!bu_strncmp(s->name, name, RENDER_SHADER_NAME_CMP_LEN)) {
t = s->next;
if (r && r->shader && !bu_strncmp(r->shader, name, 8)) {
if (r && r->shader && !bu_strncmp(r->shader, name, RENDER_SHADER_NAME_CMP_LEN)) {
meh = s->next;
while (meh) {
if (render_shader_init(r, meh->name, NULL) != -1)
@@ -846,7 +641,7 @@ LOADED:
}
while (s->next) {
if (!bu_strncmp(s->next->name, name, 8)) {
if (!bu_strncmp(s->next->name, name, RENDER_SHADER_NAME_CMP_LEN)) {
if (r)
render_shader_init(r, s->name, NULL);
if (s->next->dlh)
@@ -856,6 +651,7 @@ LOADED:
bu_free(t, "unload shader");
return 0;
}
s = s->next;
}
bu_log("Could not find shader \"%s\"\n", name);
@@ -871,7 +667,7 @@ render_shader_init(render_t *r, const char *name, const char *buf)
{
struct render_shader_s *s = shaders;
while (s) {
if (!bu_strncmp(s->name, name, 8)) {
if (!bu_strncmp(s->name, name, RENDER_SHADER_NAME_CMP_LEN)) {
s->init(r, buf);
r->shader = s->name;
return 0;
-11
View File
@@ -99,18 +99,7 @@ __BEGIN_DECLS
RENDER_EXPORT extern void render_camera_init(render_camera_t *camera, size_t threads);
RENDER_EXPORT extern void render_camera_free(render_camera_t *camera);
RENDER_EXPORT extern void render_camera_prep(render_camera_t *camera);
/** Center a camera on TIE geometry and any prepared annotations. Returns the
* effective scene radius in TIE coordinates. */
RENDER_EXPORT extern fastf_t render_camera_fit_scene(render_camera_t *camera,
const struct tie_s *tie, const struct rt_annot_scene *annotations,
fastf_t model_units_per_tie_unit);
RENDER_EXPORT extern void render_camera_render(render_camera_t *camera, struct tie_s *tie, camera_tile_t *tile, tienet_buffer_t *result);
/** Render with an externally owned annotation scene. The coordinate scale
* converts TIE coordinates to database model coordinates. */
RENDER_EXPORT extern void render_camera_render_annotations(render_camera_t *camera,
struct tie_s *tie, camera_tile_t *tile, tienet_buffer_t *result,
const struct rt_annot_scene *annotations,
fastf_t model_units_per_tie_unit);
RENDER_EXPORT extern int render_shader_init(render_t *, const char *name, const char *buf);
RENDER_EXPORT extern const char *render_shader_load_plugin(const char *filename);
+10 -86
View File
@@ -40,13 +40,11 @@
#include "vmath.h"
#include "nmg.h"
#include "rt/geom.h"
#include "rt/search.h"
#include "raytrace.h"
#include "rt/tie.h"
#include "adrt.h"
#include "adrt_struct.h"
#include "load_g.h"
static struct bn_tol tol; /* calculation tolerance */
@@ -106,42 +104,6 @@ struct gcv_data {
static struct gcv_data gcvwriter = {{load_nmg_to_adrt_gcvwrite, NULL, NULL}, NULL};
int
adrt_path_has_geometry(struct db_i *database, const char *path)
{
static const char *geometry_search = "! -type comb ! -type annot";
struct directory *root;
if (!database || !path)
return 0;
root = db_lookup(database, path, LOOKUP_QUIET);
/* Let db_walk_tree report a missing path rather than hiding the error. */
if (!root)
return 1;
return db_search(NULL, DB_SEARCH_QUIET, geometry_search, 1, &root,
database, NULL, NULL, NULL) != 0;
}
union tree *
adrt_leaf_tess(struct db_tree_state *tsp, const struct db_full_path *pathp,
struct rt_db_internal *ip, void *client_data)
{
union tree *result;
if (!ip || ip->idb_type != ID_ANNOT)
return rt_booltree_leaf_tess(tsp, pathp, ip, client_data);
/* Annotations are rendered directly and have no NMG representation. */
BU_GET(result, union tree);
RT_TREE_INIT(result);
result->tr_op = OP_NOP;
return result;
}
/* load the region into the tie image */
static void
load_nmg_to_adrt_internal(struct adrt_mesh_s *mesh, struct nmgregion *r)
@@ -191,8 +153,7 @@ load_nmg_to_adrt_internal(struct adrt_mesh_s *mesh, struct nmgregion *r)
NMG_CK_VERTEX(v);
/* convert mm to m */
VSCALE((*tribuf[vert_count]).v, v->vg_p->coord,
1.0 / ADRT_MODEL_UNITS_PER_TIE_UNIT);
VSCALE((*tribuf[vert_count]).v, v->vg_p->coord, 1.0/1000.0);
vert_count++;
}
if (vert_count > 3)
@@ -287,12 +248,9 @@ load_nmg_to_adrt_regstart(struct db_tree_state *ts, const struct db_full_path *p
for (i=0;i<bot->num_faces;i++)
{
VSCALE((*tribuf[0]).v, (bot->vertices+3*bot->faces[3*i+0]),
1.0 / ADRT_MODEL_UNITS_PER_TIE_UNIT);
VSCALE((*tribuf[1]).v, (bot->vertices+3*bot->faces[3*i+1]),
1.0 / ADRT_MODEL_UNITS_PER_TIE_UNIT);
VSCALE((*tribuf[2]).v, (bot->vertices+3*bot->faces[3*i+2]),
1.0 / ADRT_MODEL_UNITS_PER_TIE_UNIT);
VSCALE((*tribuf[0]).v, (bot->vertices+3*bot->faces[3*i+0]), 1.0/1000.0);
VSCALE((*tribuf[1]).v, (bot->vertices+3*bot->faces[3*i+1]), 1.0/1000.0);
VSCALE((*tribuf[2]).v, (bot->vertices+3*bot->faces[3*i+2]), 1.0/1000.0);
TIE_VAL(tie_push)(cur_tie, tribuf, 1, mesh, 0);
}
@@ -340,16 +298,11 @@ load_nmg_to_adrt_gcvwrite(struct nmgregion *r, const struct db_full_path *pathp,
int
load_g_annotations(struct tie_s *tie, const char *db, int argc,
const char **argv, struct adrt_mesh_s **meshes,
struct rt_annot_scene **annotations)
load_g(struct tie_s *tie, const char *db, int argc, const char **argv, struct adrt_mesh_s **meshes)
{
struct model *the_model;
struct bg_tess_tol ttol; /* tessellation tolerance in mm */
struct db_tree_state tree_state; /* includes tol & model */
const char **geometry_paths = NULL;
int geometry_count = 0;
int walk_result = 0;
cur_tie = tie; /* NOTE: cur_tie is a file-scope global; this is not
* reentrant and would need locking to be thread-safe. */
@@ -385,21 +338,13 @@ load_g_annotations(struct tie_s *tie, const char *db, int argc,
if ((dbip = db_open(db, DB_OPEN_READONLY)) == DBI_NULL) {
perror(db);
bu_log("Unable to open geometry database file (%s)\n", db);
nmg_km(the_model);
return -1;
}
if (db_dirbuild(dbip)) {
bu_log("ERROR: db_dirbuild failed\n");
db_close(dbip);
dbip = DBI_NULL;
nmg_km(the_model);
return -1;
}
if (annotations) {
*annotations = rt_annot_scene_create(dbip, argc, argv, &ttol, &tol);
}
BN_CK_TOL(tree_state.ts_tol);
BG_CK_TESS_TOL(tree_state.ts_ttol);
@@ -417,26 +362,15 @@ load_g_annotations(struct tie_s *tie, const char *db, int argc,
tribuf[1] = (TIE_3 *)bu_malloc(sizeof(TIE_3) * 3, "triangle tribuffer");
tribuf[2] = (TIE_3 *)bu_malloc(sizeof(TIE_3) * 3, "triangle tribuffer");
if (argc > 0) {
geometry_paths = (const char **)bu_calloc((size_t)argc,
sizeof(const char *), "ADRT geometry paths");
for (int i = 0; i < argc; ++i) {
if (adrt_path_has_geometry(dbip, argv[i]))
geometry_paths[geometry_count++] = argv[i];
}
}
if (geometry_count) {
walk_result = db_walk_tree(dbip,
geometry_count, /* number of toplevel regions */
geometry_paths, /* region names */
(void) db_walk_tree(dbip,
argc, /* number of toplevel regions */
argv, /* region names */
1, /* ncpu */
&tree_state, /* initial tree state */
load_nmg_to_adrt_regstart, /* region start function */
gcv_region_end, /* region end function */
adrt_leaf_tess, /* leaf func */
rt_booltree_leaf_tess, /* leaf func */
(void *)&gcvwriter); /* client data */
}
/* Release dynamic storage */
nmg_km(the_model);
@@ -446,20 +380,10 @@ load_g_annotations(struct tie_s *tie, const char *db, int argc,
bu_free(tribuf[1], "vert");
bu_free(tribuf[2], "vert");
bu_free(tribuf, "tri");
if (geometry_paths)
bu_free(geometry_paths, "ADRT geometry paths");
TIE_VAL(tie_prep)(cur_tie);
return walk_result;
}
int
load_g(struct tie_s *tie, const char *db, int argc, const char **argv,
struct adrt_mesh_s **meshes)
{
return load_g_annotations(tie, db, argc, argv, meshes, NULL);
return 0;
}
/*
-43
View File
@@ -1,43 +0,0 @@
/* L O A D _ G . H
* BRL-CAD / ADRT
*
* Copyright (c) 2026 United States Government as represented by
* the U.S. Army Research Laboratory.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef ADRT_LOAD_G_H
#define ADRT_LOAD_G_H
#include "common.h"
#include "adrt.h"
struct db_i;
struct db_tree_state;
struct db_full_path;
struct rt_db_internal;
union tree;
__BEGIN_DECLS
RENDER_EXPORT extern int adrt_path_has_geometry(struct db_i *dbip,
const char *path);
RENDER_EXPORT extern union tree *adrt_leaf_tess(struct db_tree_state *tsp,
const struct db_full_path *pathp, struct rt_db_internal *ip,
void *client_data);
__END_DECLS
#endif /* ADRT_LOAD_G_H */
/*
* Local Variables:
* tab-width: 8
* mode: C
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/
-16
View File
@@ -1,16 +0,0 @@
brlcad_addexec(adrt_annotation_test annotation.c
"librender;libwdb;librt;libbu;${M_LIBRARY}" TEST)
target_include_directories(adrt_annotation_test PRIVATE
${BRLCAD_SOURCE_DIR}/src/adrt
${BRLCAD_SOURCE_DIR}/src/adrt/librender
)
brlcad_add_test(NAME adrt_annotation_test COMMAND adrt_annotation_test)
cmakefiles(annotation.c CMakeLists.txt)
# Local Variables:
# tab-width: 8
# mode: cmake
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
-179
View File
@@ -1,179 +0,0 @@
/* A N N O T A T I O N . C
* BRL-CAD
*
* Copyright (c) 2026 United States Government as represented by
* the U.S. Army Research Laboratory.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "common.h"
#include <math.h>
#include <stdio.h>
#include "bu/app.h"
#include "bu/file.h"
#include "raytrace.h"
#include "rt/primitives/annot.h"
#include "wdb.h"
#include "load_g.h"
#include "librender/camera.h"
static void
write_test_database(struct db_i *dbip)
{
struct rt_wdb *wdbp = wdb_dbopen(dbip, RT_WDB_TYPE_DB_DISK);
struct rt_annot_internal annot = {0};
point2d_t vertices[2];
struct line_seg line = {0};
void *segments[1];
int reverse[1] = {0};
point_t center = VINIT_ZERO;
struct wmember members;
if (wdbp == RT_WDB_NULL)
bu_exit(1, "unable to open ADRT annotation test database\n");
annot.magic = RT_ANNOT_INTERNAL_MAGIC;
VSET(annot.V, 10.0, 0.0, 0.0);
annot.flags = RT_ANNOT_MODEL_SPACE;
VSET(annot.u_vec, 0.0, 1.0, 0.0);
VSET(annot.v_vec, 0.0, 0.0, 1.0);
annot.vert_count = 2;
annot.verts = vertices;
V2SET(vertices[0], -1.0, 0.0);
V2SET(vertices[1], 1.0, 0.0);
annot.ant.count = 1;
annot.ant.reverse = reverse;
annot.ant.segments = segments;
line.magic = CURVE_LSEG_MAGIC;
line.start = 0;
line.end = 1;
segments[0] = &line;
if (rt_annot_validate(&annot, NULL) ||
mk_annot(wdbp, "test.annot", &annot) < 0 ||
mk_sph(wdbp, "test.sph", center, 1.0) < 0)
bu_exit(1, "unable to write ADRT annotation test objects\n");
BU_LIST_INIT(&members.l);
if (!mk_addmember("test.annot", &members.l, NULL, WMOP_UNION) ||
mk_lcomb(wdbp, "annotation-only.c", &members, 0, NULL, NULL,
NULL, 0))
bu_exit(1, "unable to write annotation-only test combination\n");
BU_LIST_INIT(&members.l);
if (!mk_addmember("test.annot", &members.l, NULL, WMOP_UNION) ||
!mk_addmember("test.sph", &members.l, NULL, WMOP_UNION) ||
mk_lcomb(wdbp, "mixed.c", &members, 0, NULL, NULL, NULL, 0))
bu_exit(1, "unable to write mixed test combination\n");
}
static void
check_geometry_filter(struct db_i *dbip)
{
struct rt_db_internal intern;
union tree *leaf;
if (adrt_path_has_geometry(dbip, "test.annot") ||
adrt_path_has_geometry(dbip, "annotation-only.c") ||
!adrt_path_has_geometry(dbip, "test.sph") ||
!adrt_path_has_geometry(dbip, "mixed.c"))
bu_exit(1, "ADRT annotation geometry filtering failed\n");
RT_DB_INTERNAL_INIT(&intern);
intern.idb_type = ID_ANNOT;
leaf = adrt_leaf_tess(NULL, NULL, &intern, NULL);
if (!leaf || leaf->tr_op != OP_NOP)
bu_exit(1, "ADRT annotation leaf did not become a no-op\n");
db_free_tree(leaf);
}
static void
check_camera_fit(struct db_i *dbip)
{
const char *paths[] = {"test.annot"};
struct bg_tess_tol ttol = BG_TESS_TOL_INIT_TOL;
struct bn_tol tol = BN_TOL_INIT_TOL;
struct rt_annot_scene *scene = rt_annot_scene_create(dbip, 1, paths,
&ttol, &tol);
render_camera_t camera = {0};
struct tie_s tie = {0};
fastf_t radius;
const fastf_t combined_radius = 0.5 * sqrt(41.0);
if (!scene || rt_annot_scene_count(scene) != 1)
bu_exit(1, "unable to prepare ADRT annotation test scene\n");
tie.radius = 2.0;
VSET(tie.mid, 1.0, 2.0, 3.0);
radius = render_camera_fit_scene(&camera, &tie, NULL, 1.0);
if (!NEAR_EQUAL(radius, 2.0, BN_TOL_DIST) ||
!VNEAR_EQUAL(camera.focus, tie.mid, BN_TOL_DIST) ||
!NEAR_EQUAL(camera.pos[X], 2.0, BN_TOL_DIST) ||
!NEAR_EQUAL(camera.pos[Y], 2.0, BN_TOL_DIST) ||
!NEAR_EQUAL(camera.pos[Z], 2.0, BN_TOL_DIST))
bu_exit(1, "ADRT geometry-only camera framing changed\n");
radius = render_camera_fit_scene(&camera, &tie, scene, 10.0);
if (radius <= SMALL_FASTF ||
!NEAR_EQUAL(camera.focus[X], 1.0, BN_TOL_DIST) ||
!NEAR_ZERO(camera.focus[Y], BN_TOL_DIST) ||
!NEAR_ZERO(camera.focus[Z], BN_TOL_DIST) ||
!NEAR_EQUAL(camera.pos[X] - camera.focus[X], radius, BN_TOL_DIST) ||
!NEAR_EQUAL(camera.pos[Y] - camera.focus[Y], radius, BN_TOL_DIST) ||
!NEAR_EQUAL(camera.pos[Z] - camera.focus[Z], radius, BN_TOL_DIST))
bu_exit(1, "ADRT annotation-only camera framing failed: radius=%g "
"focus=(%g %g %g) pos=(%g %g %g)\n", radius,
V3ARGS(camera.focus), V3ARGS(camera.pos));
tie.tri_num = 1;
VSET(tie.amin, -2.0, -2.0, -2.0);
VSET(tie.amax, 0.0, 2.0, 2.0);
radius = render_camera_fit_scene(&camera, &tie, scene, 10.0);
if (!NEAR_EQUAL(radius, combined_radius, BN_TOL_DIST) ||
!NEAR_EQUAL(camera.focus[X], -0.5, BN_TOL_DIST) ||
!NEAR_ZERO(camera.focus[Y], BN_TOL_DIST) ||
!NEAR_ZERO(camera.focus[Z], BN_TOL_DIST))
bu_exit(1, "ADRT combined geometry and annotation framing failed\n");
rt_annot_scene_destroy(scene);
}
int
main(int argc, char **argv)
{
char path[MAXPATHLEN];
struct db_i *dbip;
bu_setprogname(argv[0]);
if (argc != 1)
return 1;
{
FILE *fp = bu_temp_file(path, MAXPATHLEN);
if (!fp)
bu_exit(1, "unable to create ADRT annotation test path\n");
fclose(fp);
}
dbip = db_create(path, 5);
if (dbip == DBI_NULL)
bu_exit(1, "unable to create ADRT annotation test database\n");
write_test_database(dbip);
check_geometry_filter(dbip);
check_camera_fit(dbip);
db_close(dbip);
bu_file_delete(path);
return 0;
}
/*
* Local Variables:
* tab-width: 8
* mode: C
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/
+480 -399
View File
File diff suppressed because it is too large Load Diff
+4 -5
View File
@@ -64,17 +64,16 @@ ArtTileCallback::on_tile_end(const renderer::Frame* frame, const size_t tile_x,
{
foundation::Tile& t = frame->image().tile(tile_x, tile_y);
const foundation::Tile rgb(t, PixelFormatUInt8);
const foundation::CanvasProperties& properties = frame->image().properties();
// fb_write(fbp, tile_x, tile_y, rgb.get_storage(), rgb.get_size());
// printf("yay!\n");
// printf("%lu %lu \n", tile_x, tile_y);
// printf("%lu %lu \n", rgb.get_width(), rgb.get_height());
for (size_t y = 0; y < rgb.get_height(); y++) {
for (size_t x = 0; x < rgb.get_width(); x++) {
size_t x_coord = tile_x * properties.m_tile_width + x;
size_t y_coord = tile_y * properties.m_tile_height + y;
size_t img_h = properties.m_canvas_height;
fb_write(fbp, (int)x_coord, (int)(img_h - y_coord - 1), rgb.get_storage()+((y * rgb.get_width() * 4) + (x * 4)), 1);
size_t x_coord = tile_x * rgb.get_width() + x;
size_t y_coord = tile_y * rgb.get_height() + y;
size_t img_h = frame->image().properties().m_canvas_height;
fb_write(fbp, (int)x_coord, (int)(img_h - y_coord), rgb.get_storage()+((y * rgb.get_width() * 4) + (x * 4)), 1);
}
}
}
+1
View File
@@ -42,6 +42,7 @@ if(BRLCAD_ENABLE_QT AND OPENGL_TARGETS)
Qt6::Widgets
Qt6::OpenGL
Qt6::OpenGLWidgets
${OPENGL_TARGETS}
)
else(Qt6Widgets_FOUND)
qt5_wrap_cpp(moc_srcs ${isst_headers})
+15 -52
View File
@@ -26,7 +26,6 @@
#include <QFile>
#include <QPlainTextEdit>
#include <QTextStream>
#include <vector>
#include "gfile.h"
#include "bu/malloc.h"
@@ -34,7 +33,6 @@
#include "gcv.h"
#include "nmg.h"
#include "rt/geom.h"
#include "load_g.h"
/* Replace the load_g globals from adrt with a struct that is
* passed through the callers. */
@@ -104,8 +102,7 @@ nmg_to_adrt_internal(TIE_3 **tribuf, struct tie_s *cur_tie, struct adrt_mesh_s *
NMG_CK_VERTEX(v);
/* convert mm to m */
VSCALE((*tribuf[vert_count]).v, v->vg_p->coord,
1.0 / ADRT_MODEL_UNITS_PER_TIE_UNIT);
VSCALE((*tribuf[vert_count]).v, v->vg_p->coord, 1.0/1000.0);
vert_count++;
}
if (vert_count > 3)
@@ -188,12 +185,9 @@ nmg_to_adrt_regstart(struct db_tree_state *ts, const struct db_full_path *path,
for (i=0;i<bot->num_faces;i++)
{
VSCALE((*d->tribuf[0]).v, (bot->vertices+3*bot->faces[3*i+0]),
1.0 / ADRT_MODEL_UNITS_PER_TIE_UNIT);
VSCALE((*d->tribuf[1]).v, (bot->vertices+3*bot->faces[3*i+1]),
1.0 / ADRT_MODEL_UNITS_PER_TIE_UNIT);
VSCALE((*d->tribuf[2]).v, (bot->vertices+3*bot->faces[3*i+2]),
1.0 / ADRT_MODEL_UNITS_PER_TIE_UNIT);
VSCALE((*d->tribuf[0]).v, (bot->vertices+3*bot->faces[3*i+0]), 1.0/1000.0);
VSCALE((*d->tribuf[1]).v, (bot->vertices+3*bot->faces[3*i+1]), 1.0/1000.0);
VSCALE((*d->tribuf[2]).v, (bot->vertices+3*bot->faces[3*i+2]), 1.0/1000.0);
TIE_VAL(tie_push)(d->cur_tie, d->tribuf, 1, mesh, 0);
}
@@ -239,13 +233,6 @@ nmg_to_adrt_gcvwrite(struct nmgregion *r, const struct db_full_path *pathp, stru
nmg_to_adrt_internal(d->tribuf, d->cur_tie, mesh, r);
}
GFile::~GFile()
{
closedb();
}
int
GFile::load_g(const char *filename, int argc, const char *argv[])
{
@@ -254,9 +241,6 @@ GFile::load_g(const char *filename, int argc, const char *argv[])
struct bg_tess_tol ttol; /* tessellation tolerance in mm */
struct db_tree_state tree_state; /* includes tol & model */
struct isst_nmg_data d;
std::vector<const char *> geometry_paths;
closedb();
RT_DBTS_INIT(&tree_state);
tree_state.ts_tol = &tol;
@@ -294,8 +278,6 @@ GFile::load_g(const char *filename, int argc, const char *argv[])
}
if (db_dirbuild(dbip)) {
bu_log("ERROR: db_dirbuild failed\n");
db_close(dbip);
dbip = NULL;
return -1;
}
d.dbip = dbip;
@@ -322,30 +304,20 @@ GFile::load_g(const char *filename, int argc, const char *argv[])
tribuf[2] = (TIE_3 *)bu_malloc(sizeof(TIE_3) * 3, "triangle tribuffer");
d.tribuf = this->tribuf;
annotations = rt_annot_scene_create(dbip, argc, argv, &ttol, &tol);
for (int i = 0; i < argc; ++i) {
if (adrt_path_has_geometry(dbip, argv[i]))
geometry_paths.push_back(argv[i]);
}
if (!geometry_paths.empty()) {
(void) db_walk_tree(dbip,
(int)geometry_paths.size(), /* number of toplevel regions */
geometry_paths.data(), /* region names */
1, /* ncpu */
&tree_state, /* initial tree state */
nmg_to_adrt_regstart, /* region start function */
gcv_region_end, /* region end function */
adrt_leaf_tess, /* leaf func */
(void *)&gcvwriter); /* client data */
}
(void) db_walk_tree(dbip,
argc, /* number of toplevel regions */
argv, /* region names */
1, /* ncpu */
&tree_state, /* initial tree state */
nmg_to_adrt_regstart, /* region start function */
gcv_region_end, /* region end function */
rt_booltree_leaf_tess, /* leaf func */
(void *)&gcvwriter); /* client data */
/* Release dynamic storage */
nmg_km(the_model);
rt_vlist_cleanup();
db_close(dbip);
dbip = NULL;
bu_free(tribuf[0], "vert");
bu_free(tribuf[1], "vert");
bu_free(tribuf[2], "vert");
@@ -359,17 +331,7 @@ GFile::load_g(const char *filename, int argc, const char *argv[])
void
GFile::closedb()
{
rt_annot_scene_destroy(annotations);
annotations = NULL;
if (tie) {
TIE_FREE(tie);
bu_free(tie, "free tie");
tie = NULL;
}
if (dbip) {
db_close(dbip);
dbip = NULL;
}
bu_free(tie, "free tie");
current_file.clear();
}
@@ -383,3 +345,4 @@ GFile::closedb()
* End:
* ex: shiftwidth=4 tabstop=8
*/
+5 -8
View File
@@ -32,7 +32,6 @@
extern "C" {
#include "bn/tol.h"
#include "raytrace.h"
#include "rt/primitives/annot.h"
#include "rt/tie.h"
#include "adrt.h"
@@ -44,16 +43,13 @@ class GFile : public QObject
Q_OBJECT
public:
~GFile() override;
int load_g(const char *filename, int argc, const char **argv);
void closedb();
struct tie_s *tie = NULL;
struct adrt_mesh_s *meshes = NULL;
struct db_i *dbip = NULL;
struct rt_annot_scene *annotations = NULL;
TIE_3 **tribuf = NULL;
struct tie_s *tie;
struct adrt_mesh_s *meshes;
struct db_i *dbip;
TIE_3 **tribuf;
QString current_file;
};
@@ -70,3 +66,4 @@ class GFile : public QObject
* End:
* ex: shiftwidth=4 tabstop=8
*/
+2 -4
View File
@@ -28,9 +28,6 @@
int
ISSTApp::load_g(const char *filename, int argc, const char *argv[])
{
/* Synchronize with the render thread before GFile releases the old
* annotation scene and TIE data. */
w.canvas->clear_tie();
if (g.load_g(filename, argc, argv)) {
w.statusBar()->showMessage("open failed");
return -1;
@@ -38,7 +35,7 @@ ISSTApp::load_g(const char *filename, int argc, const char *argv[])
// The OpenGL widget manages the rendering, so let it know about the
// TIE data structure associated with the current model
w.canvas->set_tie(g.tie, g.annotations);
w.canvas->set_tie(g.tie);
return 0;
}
@@ -54,3 +51,4 @@ ISSTApp::load_g(const char *filename, int argc, const char *argv[])
* End:
* ex: shiftwidth=4 tabstop=8
*/
+4 -1
View File
@@ -36,14 +36,16 @@
class ISSTApp : public QApplication
{
Q_OBJECT
public:
ISSTApp(int &argc, char *argv[]) :QApplication(argc, argv) {};
~ISSTApp() {};
int load_g(const char *filename, int argc, const char **argv);
GFile g;
ISST_MainWindow w;
GFile g;
};
#endif // ISSTAPP_H
@@ -58,3 +60,4 @@ class ISSTApp : public QApplication
* End:
* ex: shiftwidth=4 tabstop=8
*/
+9 -28
View File
@@ -159,13 +159,8 @@ void TIERenderer::render()
m_grabCond.wait(&m_grabMutex);
QMutexLocker lock(&m_renderMutex);
m_grabMutex.unlock();
/* The GUI may clear a scene while a queued render is waiting for the
* context. Return the context before leaving that stale request. */
if (m_exiting || !tie) {
ctx->moveToThread(qGuiApp->thread());
if (m_exiting)
return;
}
Q_ASSERT(ctx->thread() == QThread::currentThread());
@@ -188,8 +183,7 @@ void TIERenderer::render()
// Core TIE render
render_camera_prep(&camera);
render_camera_render_annotations(&camera, tie, &tile, &buffer_image,
annotations, ADRT_MODEL_UNITS_PER_TIE_UNIT);
render_camera_render(&camera, tie, &tile, &buffer_image);
glDisable(GL_LIGHTING);
@@ -303,31 +297,17 @@ void isstGL::grabContext()
}
void
isstGL::clear_tie()
isstGL::set_tie(struct tie_s *in_tie)
{
m_renderer->lockRenderer();
m_renderer->tie = NULL;
m_renderer->annotations = NULL;
m_renderer->changed = false;
m_renderer->unlockRenderer();
}
void
isstGL::set_tie(struct tie_s *in_tie, struct rt_annot_scene *annotations)
{
m_renderer->lockRenderer();
m_renderer->tie = in_tie;
m_renderer->annotations = annotations;
render_camera_fit_scene(&m_renderer->camera, m_renderer->tie, annotations,
ADRT_MODEL_UNITS_PER_TIE_UNIT);
// Initialize the camera position
VSETALL(m_renderer->camera.pos, m_renderer->tie->radius);
VMOVE(m_renderer->camera.focus, m_renderer->tie->mid);
// Record the initial settings for use in subsequent calculations
VMOVE(m_renderer->camera_pos_init, m_renderer->camera.pos);
VMOVE(m_renderer->camera_focus_init, m_renderer->camera.focus);
m_renderer->changed = true;
m_renderer->unlockRenderer();
VSETALL(m_renderer->camera_pos_init, m_renderer->tie->radius);
VMOVE(m_renderer->camera_focus_init, m_renderer->tie->mid);
// Having just loaded a new TIE scene,
// we need a new image
@@ -389,3 +369,4 @@ void isstGL::save_image() {
// c-file-style: "stroustrup"
// End:
// ex: shiftwidth=4 tabstop=8
+2 -3
View File
@@ -77,7 +77,6 @@ class TIERenderer : public QObject, protected QOpenGLFunctions
public:
struct tie_s *tie = NULL; // From parent app
struct rt_annot_scene *annotations = NULL; // Owned by the parent app
struct render_camera_s camera;
vect_t camera_pos_init;
vect_t camera_focus_init;
@@ -114,8 +113,7 @@ class isstGL : public QOpenGLWidget
explicit isstGL(QWidget *parent = nullptr);
~isstGL();
void clear_tie();
void set_tie(struct tie_s *in_tie, struct rt_annot_scene *annotations);
void set_tie(struct tie_s *in_tie);
void save_image();
@@ -155,3 +153,4 @@ class isstGL : public QOpenGLWidget
// c-file-style: "stroustrup"
// End:
// ex: shiftwidth=4 tabstop=8
+3 -196
View File
@@ -480,22 +480,6 @@ _nirt_get_resource(struct nirt_state *nss)
}
static void
_nirt_annotation_result_clear(struct nirt_state *nss)
{
delete nss->i->vals->annotation;
nss->i->vals->annotation = NULL;
}
static void
_nirt_annotation_scene_clear(struct nirt_state *nss)
{
rt_annot_scene_destroy(nss->i->annotation_scene);
nss->i->annotation_scene = NULL;
}
int
_nirt_raytrace_prep(struct nirt_state *nss)
{
@@ -533,17 +517,11 @@ _nirt_raytrace_prep(struct nirt_state *nss)
bu_free(attrs, "objs");
return -1;
}
bu_free(objs, "objs");
bu_free(attrs, "objs");
nmsg(nss, "Prepping the geometry...\n");
rt_prep(nss->i->ap->a_rt_i);
_nirt_annotation_scene_clear(nss);
if (nss->i->use_annotations) {
nss->i->annotation_scene = rt_annot_scene_create(nss->i->dbip,
ocnt, objs, &nss->i->ap->a_rt_i->rti_ttol,
&nss->i->ap->a_rt_i->rti_tol);
}
bu_free(objs, "objs");
nmsg(nss, "%s ", (nss->i->active_paths.size() == 1) ? "Object" : "Objects");
for (size_t i = 0; i < nss->i->active_paths.size(); i++) {
if (i == 0) {
@@ -982,17 +960,6 @@ _nirt_print_fmt_substr(struct nirt_state *nss, struct bu_vls *ostr, const char *
nirt_print_key("a", r->a);
nirt_print_key("e", r->e);
if (r->annotation) {
nirt_print_key("annot_path", r->annotation->path.c_str());
nirt_print_key("annot_segment", r->annotation->segment);
nirt_print_key("annot_role", r->annotation->role.c_str());
nirt_print_key("annot_x", r->annotation->point[X] * base2local);
nirt_print_key("annot_y", r->annotation->point[Y] * base2local);
nirt_print_key("annot_z", r->annotation->point[Z] * base2local);
nirt_print_key("annot_d", r->annotation->d * base2local);
nirt_print_key("annot_visible", r->annotation->visible);
}
if (!r->seg || r->seg->type == 0) return;
if (r->seg->type == NIRT_PARTITION_SEG || r->seg->type == NIRT_ALL_SEG) {
@@ -1089,9 +1056,6 @@ _nirt_report(struct nirt_state *nss, char type, struct nirt_output_record *r)
std::vector<std::pair<std::string,std::string> >::iterator f_it;
switch (type) {
case 'a':
fmt_vect = &nss->i->fmt.annotation;
break;
case 'r':
fmt_vect = &nss->i->fmt.ray;
break;
@@ -1127,75 +1091,6 @@ _nirt_report(struct nirt_state *nss, char type, struct nirt_output_record *r)
}
static const char *
_nirt_annotation_role(uint32_t role)
{
switch (role) {
case RT_ANNOT_ROLE_UNSPECIFIED:
return "unspecified";
case RT_ANNOT_ROLE_GEOMETRY:
return "geometry";
case RT_ANNOT_ROLE_TEXT:
return "text";
case RT_ANNOT_ROLE_LEADER:
return "leader";
case RT_ANNOT_ROLE_EXTENSION:
return "extension";
case RT_ANNOT_ROLE_DIMENSION:
return "dimension";
case RT_ANNOT_ROLE_ARROWHEAD:
return "arrowhead";
case RT_ANNOT_ROLE_SYMBOL:
return "symbol";
case RT_ANNOT_ROLE_MASK:
return "mask";
case RT_ANNOT_ROLE_CENTERMARK:
return "centermark";
case RT_ANNOT_ROLE_PLACEHOLDER:
return "placeholder";
case RT_ANNOT_ROLE_TEXT_DECORATION:
return "text-decoration";
default:
return "unknown";
}
}
static void
_nirt_report_annotations(struct nirt_state *nss)
{
const size_t count = rt_annot_scene_query_model(nss->i->annotation_scene,
&nss->i->ap->a_ray, nss->i->first_solid_distance, NULL, 0);
if (!count)
return;
std::vector<struct rt_annot_hit> hits(count);
const size_t found = rt_annot_scene_query_model(nss->i->annotation_scene,
&nss->i->ap->a_ray, nss->i->first_solid_distance, hits.data(),
hits.size());
nirt_seg *saved_segment = nss->i->vals->seg;
nss->i->vals->seg = NULL;
for (size_t i = 0; i < std::min(found, hits.size()); ++i) {
const struct rt_annot_hit &hit = hits[i];
if (hit.segment > (size_t)std::numeric_limits<int>::max()) {
nerr(nss, "Annotation segment index is too large for NIRT reporting\n");
continue;
}
if (!nss->i->vals->annotation)
nss->i->vals->annotation = new nirt_annotation_record;
nirt_annotation_record *record = nss->i->vals->annotation;
record->path = hit.path ? hit.path : "";
record->segment = (int)hit.segment;
record->role = _nirt_annotation_role(hit.role);
VMOVE(record->point, hit.point);
record->d = d_calc(nss, record->point);
record->visible = hit.visible;
_nirt_report(nss, 'a', nss->i->vals);
}
nss->i->vals->seg = saved_segment;
}
/************************
* Raytracing Callbacks *
************************/
@@ -1318,21 +1213,6 @@ _nirt_if_hit(struct application *ap, struct partition *part_head, struct seg *UN
int ev_odd = 1; /* first partition is colored as "odd" */
point_t out_old = VINIT_ZERO;
double d_out_old = 0.0;
nss->i->first_solid_distance = INFINITY;
for (part = part_head->pt_forw; part != part_head; part = part->pt_forw) {
if (part->pt_regionp->reg_aircode)
continue;
if (part->pt_inhit->hit_dist >= 0.0) {
nss->i->first_solid_distance = part->pt_inhit->hit_dist;
break;
}
if (part->pt_outhit->hit_dist >= 0.0) {
nss->i->first_solid_distance = part->pt_outhit->hit_dist;
break;
}
}
nirt_seg *s = new nirt_seg;
if (vals->seg) {
delete vals->seg;
@@ -1669,10 +1549,9 @@ static const struct nirt_cmd_desc nirt_descs[] = {
{ "s", "shoot a ray at the target", NULL },
{ "backout", "back out of model", NULL },
{ "useair", "set/query use of air", "<0|1|2|...>" },
{ "useannot", "set/query annotation reporting", "<0|1>" },
{ "units", "set/query local units", "<mm|cm|m|in|ft>" },
{ "overlap_claims", "set/query overlap rebuilding/retention", "<0|1|2|3>" },
{ "fmt", "set/query output formats", "{arhpfmog} format item item ..." },
{ "fmt", "set/query output formats", "{rhpfmog} format item item ..." },
{ "plotfile", "designate an output file to hold plot data", "file" },
{ "print", "query an output item", "item" },
{ "debug", "set/query nirt debug flags", "[-h] [-l [lib]] [-C [lib]] [-V [lib] [val]] [lib [flag]]" },
@@ -1949,9 +1828,6 @@ _nirt_cmd_shoot(void *ns, int argc, const char **UNUSED(argv))
return -1;
}
_nirt_annotation_result_clear(nss);
nss->i->first_solid_distance = INFINITY;
/* If we have no active rtip, we don't need to prep or shoot */
if (!_nirt_get_rtip(nss)) {
return 0;
@@ -1984,10 +1860,9 @@ _nirt_cmd_shoot(void *ns, int argc, const char **UNUSED(argv))
nss->i->ap->a_ray.r_pt[2] * nss->i->base2local,
V3ARGS(nss->i->ap->a_ray.r_dir));
// TODO - any necessary initialization for data collection by callbacks
_nirt_init_ovlp(nss);
(void)rt_shootray(nss->i->ap);
if (nss->i->use_annotations)
_nirt_report_annotations(nss);
// Undo backout
for (i = 0; i < 3; ++i) {
@@ -2090,45 +1965,6 @@ _nirt_cmd_use_air(void *ns, int argc, const char *argv[])
}
extern "C" int
_nirt_cmd_use_annotations(void *ns, int argc, const char *argv[])
{
struct nirt_state *nss = (struct nirt_state *)ns;
struct bu_vls optparse_msg = BU_VLS_INIT_ZERO;
int enabled = 0;
if (!ns) return -1;
if (argc == 1) {
nout(nss, "use_annotations = %d\n", nss->i->use_annotations);
return 0;
}
if (argc > 2) {
nerr(nss, "Usage: useannot %s\n", _nirt_get_desc_args("useannot"));
return -1;
}
if (bu_opt_int(&optparse_msg, 1, (const char **)&argv[1],
(void *)&enabled) == -1) {
nerr(nss, "Error: bu_opt value read failure: %s\n\nUsage: useannot %s\n",
bu_vls_cstr(&optparse_msg), _nirt_get_desc_args("useannot"));
bu_vls_free(&optparse_msg);
return -1;
}
bu_vls_free(&optparse_msg);
if (enabled != 0 && enabled != 1) {
nerr(nss, "useannot must be set to 0 (off) or 1 (on)\n");
return -1;
}
if (enabled != nss->i->use_annotations) {
nss->i->use_annotations = enabled;
_nirt_annotation_scene_clear(nss);
_nirt_annotation_result_clear(nss);
if (enabled)
nss->i->need_reprep = 1;
}
return 0;
}
extern "C" int
_nirt_cmd_units(void *ns, int argc, const char *argv[])
{
@@ -2249,9 +2085,6 @@ _nirt_cmd_format_output(void *ns, int argc, const char **argv)
// print out current fmt str for the specified type
struct bu_vls ostr = BU_VLS_INIT_ZERO;
switch (type) {
case 'a':
_nirt_print_fmt_str(&ostr, nss->i->fmt.annotation);
break;
case 'r':
_nirt_print_fmt_str(&ostr, nss->i->fmt.ray);
break;
@@ -2358,10 +2191,6 @@ _nirt_cmd_format_output(void *ns, int argc, const char **argv)
* formatting instructions with the new. */
set_fmt:
switch (type) {
case 'a':
nss->i->fmt.annotation.clear();
nss->i->fmt.annotation = fmt_tmp;
break;
case 'r':
nss->i->fmt.ray.clear();
nss->i->fmt.ray = fmt_tmp;
@@ -2714,7 +2543,6 @@ _nirt_cmd_state(void *ns, int argc, const char *argv[])
bu_vls_printf(&dumpstr, "xyz %g %g %g\n", V3ARGS(nss->i->vals->orig));
bu_vls_printf(&dumpstr, "dir %g %g %g\n", V3ARGS(nss->i->vals->dir));
bu_vls_printf(&dumpstr, "useair %d\n", nss->i->use_air);
bu_vls_printf(&dumpstr, "useannot %d\n", nss->i->use_annotations);
bu_vls_printf(&dumpstr, "units %s\n", bu_units_string(nss->i->local2base));
bu_vls_printf(&dumpstr, "overlap_claims ");
switch (nss->i->overlap_claims) {
@@ -2735,8 +2563,6 @@ _nirt_cmd_state(void *ns, int argc, const char *argv[])
break;
}
struct bu_vls ostr = BU_VLS_INIT_ZERO;
_nirt_print_fmt_cmd(&ostr, 'a', nss->i->fmt.annotation);
bu_vls_printf(&dumpstr, "%s", bu_vls_cstr(&ostr));
_nirt_print_fmt_cmd(&ostr, 'r', nss->i->fmt.ray);
bu_vls_printf(&dumpstr, "%s", bu_vls_cstr(&ostr));
_nirt_print_fmt_cmd(&ostr, 'h', nss->i->fmt.head);
@@ -2791,7 +2617,6 @@ const struct bu_cmdtab _libanalyze_nirt_cmds[] = {
{ "state", _nirt_cmd_state},
{ "units", _nirt_cmd_units},
{ "useair", _nirt_cmd_use_air},
{ "useannot", _nirt_cmd_use_annotations},
{ "xyz", _nirt_cmd_target_coor},
{ (char *)NULL, NULL}
};
@@ -2958,14 +2783,6 @@ static const char *nirt_cmd_tbl_defs =
"z_dir, FNOUNIT, Ray direction unit vector z component,"
"a, FNOUNIT, Azimuth,"
"e, FNOUNIT, Elevation,"
"annot_path, STRING, Annotation database path,"
"annot_segment, INT, Annotation segment index,"
"annot_role, STRING, Annotation segment role,"
"annot_x, FLOAT, Annotation hit X coordinate,"
"annot_y, FLOAT, Annotation hit Y coordinate,"
"annot_z, FLOAT, Annotation hit Z coordinate,"
"annot_d, FLOAT, Annotation hit gridplane distance,"
"annot_visible, INT, Annotation hit visibility,"
"x_in, FLOAT, ,"
"y_in, FLOAT, ,"
"z_in, FLOAT, ,"
@@ -3078,7 +2895,6 @@ nirt_init(struct nirt_state *ns)
n->base2local = 0.0;
n->local2base = 0.0;
n->use_air = 0;
n->use_annotations = 0;
n->backout = 1;
n->b_state = false;
@@ -3093,8 +2909,6 @@ nirt_init(struct nirt_state *ns)
BU_GET(n->res_air, struct resource);
n->rtip = RTI_NULL;
n->rtip_air = RTI_NULL;
n->annotation_scene = NULL;
n->first_solid_distance = INFINITY;
n->need_reprep = 1;
BU_GET(n->val_types, struct bu_attribute_value_set);
@@ -3108,7 +2922,6 @@ nirt_init(struct nirt_state *ns)
n->vals->h = 0.0;
n->vals->v = 0.0;
n->vals->d_orig = 0.0;
n->vals->annotation = NULL;
n->vals->seg = NULL;
_nirt_diff_create(ns);
@@ -3212,8 +3025,6 @@ nirt_clear_dbip(struct nirt_state *ns)
{
if (!ns) return -1;
_nirt_annotation_scene_clear(ns);
_nirt_annotation_result_clear(ns);
db_close(ns->i->dbip);
ns->i->dbip = NULL;
@@ -3234,9 +3045,6 @@ void
nirt_destroy(struct nirt_state *ns)
{
if (!ns) return;
_nirt_annotation_scene_clear(ns);
_nirt_annotation_result_clear(ns);
bu_vls_free(&ns->nirt_cmd);
bu_vls_free(ns->i->err);
bu_vls_free(ns->i->msg);
@@ -3249,7 +3057,6 @@ nirt_destroy(struct nirt_state *ns)
db_close(ns->i->dbip);
delete ns->i->vals->seg;
BU_PUT(ns->i->vals, struct nirt_output_record);
BU_PUT(ns->i->res, struct resource);
+1 -17
View File
@@ -83,7 +83,7 @@ extern "C" b_off_t ftello(FILE *);
#define NIRT_OVLP_RETAIN 3
#define NIRT_PRINTF_SPECIFIERS "difeEgGs"
#define NIRT_OUTPUT_TYPE_SPECIFIERS "arhpfmog"
#define NIRT_OUTPUT_TYPE_SPECIFIERS "rhpfmog"
#define HELPFLAG "--print-help"
#define PURPOSEFLAG "--print-purpose"
@@ -274,16 +274,6 @@ class nirt_seg {
}
};
class nirt_annotation_record {
public:
std::string path;
int segment;
std::string role;
point_t point;
fastf_t d;
int visible;
};
/* This record structure doesn't have to correspond exactly to the above list
* of available values, but it needs to retain sufficient information to
* support the ability to generate all of them upon request. */
@@ -296,7 +286,6 @@ struct nirt_output_record {
fastf_t a;
fastf_t e;
struct nirt_overlap ovlp_list;
nirt_annotation_record *annotation;
nirt_seg *seg;
};
@@ -305,7 +294,6 @@ struct nirt_diff_state;
class nirt_fmt_state {
public:
std::vector<std::pair<std::string,std::string> > annotation;
std::vector<std::pair<std::string,std::string> > ray;
std::vector<std::pair<std::string,std::string> > head;
std::vector<std::pair<std::string,std::string> > part;
@@ -315,7 +303,6 @@ class nirt_fmt_state {
std::vector<std::pair<std::string,std::string> > gap;
void clear() {
annotation.clear();
ray.clear();
head.clear();
part.clear();
@@ -360,7 +347,6 @@ struct nirt_state_impl {
int backout;
int overlap_claims;
int use_air;
int use_annotations;
std::set<std::string> attrs; // active attributes
std::vector<std::string> active_paths; // active paths for raytracer
struct nirt_output_record *vals;
@@ -382,8 +368,6 @@ struct nirt_state_impl {
struct resource *res;
struct rt_i *rtip_air;
struct resource *res_air;
struct rt_annot_scene *annotation_scene;
fastf_t first_solid_distance;
int need_reprep;
/* internal format specifier arrays */
-3
View File
@@ -1,9 +1,6 @@
brlcad_addexec(analyze_raydiff raydiff.c "libanalyze;librt;libbu" TEST)
brlcad_addexec(analyze_sp solid_partitions.c "libanalyze;librt;libbu" TEST)
brlcad_addexec(analyze_nhit nhit.cpp "libanalyze;librt;libbu" TEST_USESDATA)
brlcad_addexec(analyze_nirt_annotations nirt_annotations.cpp
"libanalyze;libwdb;librt;libbu" TEST_USESDATA)
brlcad_add_test(NAME analyze_nirt_annotations COMMAND analyze_nirt_annotations)
#####################################
# analyze_densities testing #
-191
View File
@@ -1,191 +0,0 @@
/* N I R T _ A N N O T A T I O N S . C P P
* BRL-CAD
*
* Copyright (c) 2026 United States Government as represented by the
* U.S. Army Research Laboratory.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "common.h"
#include <cstdio>
#include <cstdlib>
#include "analyze.h"
#include "bu/app.h"
#include "bu/file.h"
#include "bu/malloc.h"
#include "raytrace.h"
#include "wdb.h"
static constexpr fastf_t FRONT_ANNOTATION_X = 18.0;
static constexpr fastf_t REAR_ANNOTATION_X = 10.0;
static constexpr fastf_t SCREEN_ANNOTATION_X = 19.0;
static constexpr fastf_t OCCLUDER_MINIMUM_X = 15.0;
static constexpr fastf_t OCCLUDER_MAXIMUM_X = 16.0;
static constexpr fastf_t RAY_ORIGIN_X = 20.0;
static constexpr fastf_t TEST_HALF_EXTENT = 1.0;
static int
capture_output(struct nirt_state *state, void *data)
{
struct bu_vls current = BU_VLS_INIT_ZERO;
struct bu_vls *captured = (struct bu_vls *)data;
nirt_log(&current, state, NIRT_OUT);
bu_vls_vlscat(captured, &current);
bu_vls_free(&current);
return 0;
}
static void
write_annotation(struct rt_wdb *wdbp, const char *name, fastf_t x,
bool screen_space)
{
struct rt_annot_internal annotation = {};
struct line_seg line = {};
struct rt_annot_seg_style style = {};
int reverse = 0;
void *segment = &line;
point2d_t vertices[2] = {{0.0, 0.0}, {TEST_HALF_EXTENT, 0.0}};
annotation.magic = RT_ANNOT_INTERNAL_MAGIC;
VSET(annotation.V, x, 0.0, 0.0);
annotation.flags = screen_space ? RT_ANNOT_SCREEN_SPACE :
RT_ANNOT_MODEL_SPACE;
VSET(annotation.u_vec, 0.0, 1.0, 0.0);
VSET(annotation.v_vec, 0.0, 0.0, 1.0);
annotation.vert_count = 2;
annotation.verts = vertices;
annotation.ant.count = 1;
annotation.ant.reverse = &reverse;
annotation.ant.segments = &segment;
annotation.styles = &style;
line.magic = CURVE_LSEG_MAGIC;
line.start = 0;
line.end = 1;
style.role = RT_ANNOT_ROLE_LEADER;
style.line_pattern = RT_ANNOT_LINE_CONTINUOUS;
if (rt_annot_validate(&annotation, NULL) ||
mk_annot(wdbp, name, &annotation) < 0)
bu_exit(EXIT_FAILURE, "unable to write %s\n", name);
}
static void
clear_standard_formats(struct nirt_state *state)
{
const char *commands[] = {
"fmt r \"\"", "fmt h \"\"", "fmt p \"\"", "fmt f \"\"",
"fmt m \"\"", "fmt o \"\"", "fmt g \"\""
};
for (size_t i = 0; i < sizeof(commands) / sizeof(commands[0]); ++i)
if (nirt_exec(state, commands[i]))
bu_exit(EXIT_FAILURE, "NIRT rejected command: %s\n", commands[i]);
}
static void
get_output(struct bu_vls *output, struct bu_vls *captured)
{
bu_vls_sprintf(output, "%s", bu_vls_cstr(captured));
bu_vls_trunc(captured, 0);
}
int
main(int argc, char **argv)
{
char path[MAXPATHLEN];
struct db_i *dbip;
struct rt_wdb *wdbp;
struct nirt_state *state;
struct bu_vls captured = BU_VLS_INIT_ZERO;
struct bu_vls output = BU_VLS_INIT_ZERO;
struct wmember members;
point_t minimum, maximum;
bu_setprogname(argv[0]);
if (argc != 1)
return EXIT_FAILURE;
{
FILE *fp = bu_temp_file(path, sizeof(path));
if (!fp)
bu_exit(EXIT_FAILURE, "unable to create temporary database path\n");
fclose(fp);
}
dbip = db_create(path, 5);
if (!dbip)
bu_exit(EXIT_FAILURE, "unable to create temporary database\n");
wdbp = wdb_dbopen(dbip, RT_WDB_TYPE_DB_DISK);
if (!wdbp)
bu_exit(EXIT_FAILURE, "unable to open temporary database for writing\n");
write_annotation(wdbp, "front.annot", FRONT_ANNOTATION_X, false);
write_annotation(wdbp, "rear.annot", REAR_ANNOTATION_X, false);
write_annotation(wdbp, "screen.annot", SCREEN_ANNOTATION_X, true);
VSET(minimum, OCCLUDER_MINIMUM_X, -TEST_HALF_EXTENT,
-TEST_HALF_EXTENT);
VSET(maximum, OCCLUDER_MAXIMUM_X, TEST_HALF_EXTENT,
TEST_HALF_EXTENT);
if (mk_rpp(wdbp, "occluder.s", minimum, maximum) < 0)
bu_exit(EXIT_FAILURE, "unable to write occluder\n");
BU_LIST_INIT(&members.l);
if (!mk_addmember("occluder.s", &members.l, NULL, WMOP_UNION) ||
mk_lcomb(wdbp, "occluder.r", &members, 1, NULL, NULL, NULL, 0))
bu_exit(EXIT_FAILURE, "unable to write occluding region\n");
BU_GET(state, struct nirt_state);
if (nirt_init(state))
bu_exit(EXIT_FAILURE, "unable to initialize NIRT\n");
nirt_udata(state, &captured);
nirt_hook(state, capture_output, NIRT_OUT);
if (nirt_exec(state,
"draw front.annot rear.annot screen.annot occluder.r") ||
nirt_init_dbip(state, dbip))
bu_exit(EXIT_FAILURE, "unable to prepare NIRT test database\n");
clear_standard_formats(state);
if (nirt_exec(state,
"fmt a \"%s|%d|%s|%.1f|%.1f|%d\\n\" annot_path annot_segment annot_role annot_x annot_d annot_visible"))
bu_exit(EXIT_FAILURE, "unable to set annotation report format\n");
struct bu_vls shot = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&shot, "backout 0;xyz %g 0 0;dir -1 0 0;s",
RAY_ORIGIN_X);
if (nirt_exec(state, bu_vls_cstr(&shot)))
bu_exit(EXIT_FAILURE, "unable to shoot default NIRT ray\n");
bu_vls_free(&shot);
get_output(&output, &captured);
if (bu_vls_strlen(&output))
bu_exit(EXIT_FAILURE,
"annotations were reported without useannot: %s\n",
bu_vls_cstr(&output));
if (nirt_exec(state, "useannot 1;s"))
bu_exit(EXIT_FAILURE, "unable to shoot annotation NIRT ray\n");
get_output(&output, &captured);
struct bu_vls expected = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&expected,
"/front.annot|0|leader|%.1f|%.1f|1\n"
"/rear.annot|0|leader|%.1f|%.1f|0\n",
FRONT_ANNOTATION_X, FRONT_ANNOTATION_X,
REAR_ANNOTATION_X, REAR_ANNOTATION_X);
if (!BU_STR_EQUAL(bu_vls_cstr(&output), bu_vls_cstr(&expected)))
bu_exit(EXIT_FAILURE, "unexpected annotation report:\n%s",
bu_vls_cstr(&output));
bu_vls_free(&expected);
nirt_destroy(state);
BU_PUT(state, struct nirt_state);
bu_vls_free(&captured);
bu_vls_free(&output);
db_close(dbip);
bu_file_delete(path);
return EXIT_SUCCESS;
}
+6 -12
View File
@@ -419,7 +419,7 @@ protected:
ListNode* AllocListNode();
void FreeListNode(ListNode* a_listNode);
bool Overlap(Rect* a_rectA, Rect* a_rectB) const;
bool Intersect(const Rect* a_rect, const Ray* a_ray) const;
bool Intersect(Rect* a_rect, Ray* a_ray) const;
void ReInsert(Node* a_node, ListNode** a_listNode);
bool Search(Node* a_node, Rect* a_rect, int& a_foundCount, std::function<bool(const DataType&, void *)> callback, void *a_context) const;
void RemoveAllRec(Node* a_node);
@@ -433,15 +433,14 @@ protected:
size_t CheckNodes(Node *a_nodeA, Node *a_nodeB, std::set<DataType> *a_result, std::set<DataType> *b_result);
size_t CheckNodes(Node *a_nodeA, Node *a_nodeB, std::set<std::pair<DataType, DataType>> *result);
size_t IsectNode(const Node *a_node, const Ray *a_ray,
std::set<DataType> *result) const;
size_t IsectNode(Node *a_node, Ray *a_ray, std::set<DataType> *result);
Node* m_root = nullptr; ///< Root of tree
ElementTypeReal m_unitSphereVolume = kElementTypeRealZero; ///< Unit sphere constant for required number of dimensions
public:
// Find the leaves intersected by a ray, returning the data from the leaves in a set.
size_t Intersects(const Ray *a_ray, std::set<DataType> *result) const;
size_t Intersects(Ray *a_ray, std::set<DataType> *result);
void plot(const char *fname);
void plot2d(const char *fname);
@@ -1552,7 +1551,7 @@ bool RTREE_QUAL::Overlap(Rect* a_rectA, Rect* a_rectB) const
// Decide whether a ray intersect a Rect.
RTREE_TEMPLATE
bool RTREE_QUAL::Intersect(const Rect* a_rect, const Ray* a_ray) const
bool RTREE_QUAL::Intersect(Rect* a_rect, Ray* a_ray) const
{
RTreeAssert(a_rect);
if (kNumDimensions != 3) return false;
@@ -1686,8 +1685,7 @@ size_t RTREE_QUAL::Overlaps(RTree &other, std::set<std::pair<DataType, DataType>
RTREE_TEMPLATE
size_t RTREE_QUAL::IsectNode(const Node *a_node, const Ray *a_ray,
std::set<DataType> *result) const
size_t RTREE_QUAL::IsectNode(Node *a_node, Ray *a_ray, std::set<DataType> *result)
{
size_t ocnt = 0;
for (int index = 0; index < a_node->m_count; ++index) {
@@ -1705,8 +1703,7 @@ size_t RTREE_QUAL::IsectNode(const Node *a_node, const Ray *a_ray,
// Loosely based on the idea from the openNURBS code to search two R-trees for all pairs elements whose bounding boxes overlap.
RTREE_TEMPLATE
size_t RTREE_QUAL::Intersects(const Ray *a_ray,
std::set<DataType> *result) const
size_t RTREE_QUAL::Intersects(Ray *a_ray, std::set<DataType> *result)
{
if (!m_root) return 0;
size_t ovlp_cnt = IsectNode(m_root, a_ray, result);
@@ -1803,9 +1800,6 @@ void RTREE_QUAL::plot2d(const char *fname)
}
#undef BB_PLOT2D
#undef BB_PLOT
#undef TREE_LEAF_FACE_3D
#undef RTREE_TEMPLATE
#undef RTREE_QUAL
+1
View File
@@ -41,6 +41,7 @@ set(
badmagic.c
bitv.c
bomb.c
binding.cpp
booleanize.c
bu_init.cpp
cache.cpp
+362
View File
@@ -0,0 +1,362 @@
/* B I N D I N G . C P P
* BRL-CAD
*
* Copyright (c) 2026 United States Government as represented by
* the U.S. Army Research Laboratory.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; see the file named COPYING for more
* information.
*/
#include "common.h"
#include <string>
#include <vector>
#include <map>
#include <set>
#include <fstream>
#include <sstream>
#include "bu/binding.h"
#include "bu/log.h"
#include "bu/malloc.h"
#include "bu/str.h"
#include "bu/vls.h"
#include "json.hpp"
using json = nlohmann::json;
/*
* Internal data structures to hold the parsed bindings and callbacks
*/
struct ActionCallback {
bu_action_func_t func;
void *client_data;
};
struct BindingDef {
json match;
std::string action;
};
/* Global state for libbu bindings */
static std::map<std::string, std::vector<BindingDef>>& get_contexts() {
static auto* ptr = new std::map<std::string, std::vector<BindingDef>>();
return *ptr;
}
static std::map<std::string, ActionCallback>& get_action_registry() {
static auto* ptr = new std::map<std::string, ActionCallback>();
return *ptr;
}
static std::map<std::string, std::string>& get_schema_paths() {
static auto* ptr = new std::map<std::string, std::string>();
return *ptr;
}
static std::map<std::string, std::set<std::string>>& get_schemas() {
static auto* ptr = new std::map<std::string, std::set<std::string>>();
return *ptr;
}
static void
ensure_schema_loaded(const std::string& ctx_name)
{
if (get_schemas().find(ctx_name) != get_schemas().end()) {
return;
}
auto it = get_schema_paths().find(ctx_name);
if (it == get_schema_paths().end()) {
return;
}
std::ifstream file(it->second);
if (!file.is_open()) {
bu_log("ensure_schema_loaded: Failed to open schema %s\n", it->second.c_str());
return;
}
json j;
try {
file >> j;
} catch (const json::parse_error& e) {
bu_log("ensure_schema_loaded: JSON parse error in schema %s: %s\n", it->second.c_str(), e.what());
return;
}
std::set<std::string> valid_actions;
if (j.contains("actions") && j["actions"].is_object()) {
for (auto el = j["actions"].begin(); el != j["actions"].end(); ++el) {
valid_actions.insert(el.key());
}
}
get_schemas()[ctx_name] = valid_actions;
}
/* W3C Key validation placeholder. A full implementation would check against
* an exhaustive list of W3C standard keys (e.g., "Escape", "ArrowUp").
* For demonstration, we'll just implement a simple sanity check.
*/
static int
validate_w3c_key(const std::string& key)
{
/* Example: Reject completely upper-case strings that might be native C macros */
if (key.length() > 1 && key == "RETURN") return 0;
if (key.length() > 1 && key == "SPACE") return 0;
return 1;
}
/* W3C Button validation. Values 0, 1, 2, 3, 4 are standard. */
static int
validate_w3c_button(int button)
{
return (button >= 0 && button <= 4);
}
int
bu_binding_load(const char *json_path)
{
if (!json_path) return -1;
std::ifstream file(json_path);
if (!file.is_open()) {
bu_log("bu_binding_load: Failed to open %s\n", json_path);
return -1;
}
std::stringstream buffer;
buffer << file.rdbuf();
return bu_binding_load_str(buffer.str().c_str());
}
int
bu_binding_load_str(const char *json_string)
{
if (!json_string) return -1;
json j;
try {
j = json::parse(json_string);
} catch (const json::parse_error& e) {
bu_log("bu_binding_load_str: JSON parse error: %s\n", e.what());
return -1;
}
if (!j.contains("contexts") || !j["contexts"].is_object()) {
bu_log("bu_binding_load_str: Invalid JSON structure (missing 'contexts' object)\n");
return -1;
}
for (auto it = j["contexts"].begin(); it != j["contexts"].end(); ++it) {
std::string ctx_name = it.key();
const auto& ctx_obj = it.value();
if (!ctx_obj.contains("bindings") || !ctx_obj["bindings"].is_array()) {
continue;
}
std::vector<BindingDef> defs;
ensure_schema_loaded(ctx_name);
bool has_schema = (get_schemas().find(ctx_name) != get_schemas().end());
for (const auto& binding : ctx_obj["bindings"]) {
if (!binding.contains("match") || !binding.contains("action")) {
bu_log("bu_binding_load_str: Binding missing 'match' or 'action' in context %s. Skipping.\n", ctx_name.c_str());
continue;
}
const json& match = binding["match"];
std::string action = binding["action"].get<std::string>();
/* Phase 1 Validation: Check W3C standard compliance */
int is_valid = 1;
if (match.contains(BU_BINDING_ATTR_KEY)) {
if (!match[BU_BINDING_ATTR_KEY].is_string() || !validate_w3c_key(match[BU_BINDING_ATTR_KEY].get<std::string>())) {
bu_log("bu_binding_load_str: Invalid W3C key '%s' in context %s. Binding rejected.\n",
match[BU_BINDING_ATTR_KEY].dump().c_str(), ctx_name.c_str());
is_valid = 0;
}
}
if (match.contains(BU_BINDING_ATTR_BUTTON)) {
if (!match[BU_BINDING_ATTR_BUTTON].is_number_integer() || !validate_w3c_button(match[BU_BINDING_ATTR_BUTTON].get<int>())) {
bu_log("bu_binding_load_str: Invalid W3C button '%s' in context %s. Binding rejected.\n",
match[BU_BINDING_ATTR_BUTTON].dump().c_str(), ctx_name.c_str());
is_valid = 0;
}
}
if (!is_valid) continue;
/* Phase 2 Validation: Schema constraints */
if (has_schema) {
if (get_schemas()[ctx_name].find(action) == get_schemas()[ctx_name].end()) {
bu_log("bu_binding_load_str: Binding for action '%s' rejected by schema for context '%s'.\n",
action.c_str(), ctx_name.c_str());
continue;
}
}
BindingDef def;
def.match = match;
def.action = action;
get_contexts()[ctx_name].insert(get_contexts()[ctx_name].begin(), def);
}
}
return 0;
}
void
bu_binding_register_schema(const char *context, const char *json_path)
{
if (!context || !json_path) return;
get_schema_paths()[std::string(context)] = std::string(json_path);
}
void
bu_binding_schema_add_action(const char *context, const char *action_name, const char *description)
{
if (!context || !action_name) return;
std::string ctx(context);
ensure_schema_loaded(ctx);
get_schemas()[ctx].insert(std::string(action_name));
}
void
bu_binding_schema_remove_action(const char *context, const char *action_name)
{
if (!context || !action_name) return;
std::string ctx(context);
ensure_schema_loaded(ctx);
get_schemas()[ctx].erase(std::string(action_name));
}
void
bu_binding_register_action(const char *action_name, bu_action_func_t func, void *client_data)
{
if (!action_name || !func) return;
ActionCallback cb;
cb.func = func;
cb.client_data = client_data;
get_action_registry()[std::string(action_name)] = cb;
}
/* Helper to check if the json 'event' contains all the key-value pairs required by 'match' */
static int
is_match(const json& match, const json& event)
{
for (auto it = match.begin(); it != match.end(); ++it) {
if (!event.contains(it.key())) {
return 0;
}
/* If it's an array (like modifiers), we need to ensure all elements in 'match' exist in 'event' */
if (it.value().is_array()) {
if (!event[it.key()].is_array()) return 0;
for (const auto& req_mod : it.value()) {
int found = 0;
for (const auto& ev_mod : event[it.key()]) {
if (ev_mod == req_mod) {
found = 1;
break;
}
}
if (!found) return 0;
}
}
/* Otherwise, simple equality */
else if (event[it.key()] != it.value()) {
return 0;
}
}
return 1;
}
int
bu_binding_process_event(const char *context, const char *event_json, void *event_data)
{
if (!context || !event_json) return 0;
std::string ctx_name(context);
auto it = get_contexts().find(ctx_name);
if (it == get_contexts().end()) {
return 0; /* Context not found */
}
const char *json_str = event_json;
json event_json_obj;
try {
event_json_obj = json::parse(json_str);
} catch (const json::parse_error& e) {
bu_log("bu_binding_process_event: Invalid event JSON: %s\n", e.what());
return 0;
}
if (!event_json_obj.is_object()) {
return 0;
}
for (const auto& def : it->second) {
if (is_match(def.match, event_json_obj)) {
/* Match found */
auto reg_it = get_action_registry().find(def.action);
if (reg_it != get_action_registry().end()) {
reg_it->second.func(event_json, reg_it->second.client_data, event_data);
return 1;
} else {
/* We have a binding, but no callback registered for this action */
bu_log("Warning: Event mapped to action '%s', but no callback is registered.\n", def.action.c_str());
return 1; /* Still mark as handled since it matched a binding */
}
}
}
return 0; /* Unhandled */
}
extern "C" int
bu_binding_action_is_bound(const char *context, const char *action_name)
{
if (!context || !action_name) return 0;
std::string ctx(context);
std::string act(action_name);
auto it = get_contexts().find(ctx);
if (it == get_contexts().end()) return 0;
for (const auto& def : it->second) {
if (def.action == act) {
return 1;
}
}
return 0;
}
/*
* Local Variables:
* mode: C++
* tab-width: 8
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/
+2
View File
@@ -10,6 +10,7 @@ set(
test_bomb.c
test_badmagic.c
test_basename.c
test_binding.cpp
test_bitv.c
test_booleanize.c
test_cache.cpp
@@ -122,6 +123,7 @@ brlcad_addexec(bu_gethostname test_gethostname.c libbu TEST)
brlcad_add_test(NAME bu_argv COMMAND bu_test test_argv)
brlcad_add_test(NAME bu_backtrace COMMAND bu_test test_backtrace)
brlcad_add_test(NAME bu_bomb COMMAND bu_test test_bomb "$<TARGET_FILE:bu_test>")
brlcad_add_test(NAME bu_binding COMMAND bu_test test_binding "${CMAKE_CURRENT_SOURCE_DIR}/test_bindings.json")
brlcad_add_test(NAME bu_dir COMMAND bu_test test_dir)
brlcad_add_test(NAME bu_list_empty COMMAND bu_test test_list 0)
brlcad_add_test(NAME bu_list_single COMMAND bu_test test_list 1)
+109
View File
@@ -0,0 +1,109 @@
/* T E S T _ B I N D I N G . C P P
* BRL-CAD
*
* Copyright (c) 2026 United States Government as represented by
* the U.S. Army Research Laboratory.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; see the file named COPYING for more
* information.
*/
#include "common.h"
#include <stdio.h>
#include <string.h>
#include "bu/binding.h"
#include "bu/vls.h"
int action_triggered = 0;
void mock_action_handler(const char *event_json, void *registered_data, void *event_data) {
action_triggered = 1;
printf("Action handler triggered with JSON: %s\n", event_json);
}
int main(int argc, char *argv[]) {
bu_setprogname(argv[0]);
if (argc < 2) {
printf("Usage: %s <path_to_test_bindings.json>\n", argv[0]);
return -1;
}
const char *json_path = argv[1];
/* Register schema to restrict allowed actions */
bu_binding_schema_add_action("fb", "fb_zoom", "Zoom");
bu_binding_schema_add_action("fb", "fb_close_window", "Close Window");
/* Register hooks before loading JSON */
bu_binding_register_action("fb_close_window", mock_action_handler, NULL);
printf("Loading bindings from %s\n", json_path);
if (bu_binding_load(json_path) < 0) {
printf("Failed to load bindings.\n");
return -1;
}
/* Test 1: Simulate a matching event */
struct bu_vls ev_json = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&ev_json, "{\"type\": \"mouse-press\", \"button\": 2}");
action_triggered = 0;
bu_binding_process_event("fb", bu_vls_cstr(&ev_json), NULL);
if (!action_triggered) {
printf("Test 1 Failed: Expected action was not triggered.\n");
return -1;
}
printf("Test 1 Passed: Action triggered successfully.\n");
/* Test 2: Simulate a non-matching event */
bu_vls_sprintf(&ev_json, "{\"type\": \"mouse-press\", \"button\": 1}");
action_triggered = 0;
bu_binding_process_event("fb", bu_vls_cstr(&ev_json), NULL);
if (action_triggered) {
printf("Test 2 Failed: Action should not have been triggered.\n");
return -1;
}
printf("Test 2 Passed: Non-matching event correctly ignored.\n");
/* Test 3: The Escape key binding should have been rejected by the validator */
bu_vls_sprintf(&ev_json, "{\"type\": \"key-press\", \"key\": \"Escape\"}");
action_triggered = 0;
bu_binding_process_event("fb", bu_vls_cstr(&ev_json), NULL);
if (action_triggered) {
printf("Test 3 Failed: Escape binding should have been filtered by the validator.\n");
return -1;
}
printf("Test 3 Passed: Validator correctly rejected binding at load time.\n");
bu_vls_free(&ev_json);
return 0;
}
/*
* Local Variables:
* mode: C++
* tab-width: 8
* indent-tabs-mode: t
* c-file-style: "stroustrup"
* End:
* ex: shiftwidth=4 tabstop=8
*/
+22
View File
@@ -0,0 +1,22 @@
{
"contexts": {
"fb": {
"bindings": [
{
"match": {
"type": "mouse-press",
"button": 2
},
"action": "fb_close_window"
},
{
"match": {
"type": "key-press",
"key": "Escape"
},
"action": "fb_invalid_action"
}
]
}
}
}
+6
View File
@@ -38,6 +38,11 @@ set_property(
PROPERTY COMPILE_DEFINITIONS "DM_PLUGIN_SUFFIX=\"${CMAKE_SHARED_LIBRARY_SUFFIX}\""
)
# Files related to key/mouse binding management
brlcad_manage_files(dm_bindings.json ${DATA_DIR}/bindings)
brlcad_manage_files(dm_schema.json ${DATA_DIR}/bindings)
brlcad_manage_files(fb_schema.json ${DATA_DIR}/bindings)
brlcad_find_package(PNG REQUIRED)
find_package(OpenSSL QUIET)
@@ -165,3 +170,4 @@ cmakefiles(${libdm_ignore_files})
# indent-tabs-mode: t
# End:
# ex: shiftwidth=2 tabstop=8
+1
View File
@@ -2925,6 +2925,7 @@ X24_handle_event(struct fb *ifp, XEvent *event)
case ButtonPress:
{
int button = (int) event->xbutton.button;
int w3c_button = 0;
/* In interactive mode, report the event to the application
* rather than consuming it here. */
+59
View File
@@ -0,0 +1,59 @@
{
"contexts": {
"fb": {
"description": "Standard interactions for raw framebuffers (rt, fbserv)",
"bindings": [
{
"match": {
"type": "mouse-press",
"button": 1
},
"action": "fb_print_pixel_rgb"
},
{
"match": {
"type": "mouse-press",
"button": 2
},
"action": "fb_close_window"
},
{
"match": {
"type": "key-press",
"key": "Escape"
},
"action": "fb_close_window"
}
]
},
"dm": {
"description": "Standard bindings for the Geometry Editor (qged & mged)",
"bindings": [
{ "match": { "type": "key-press", "key": "A" }, "action": "view_toggle_adc" },
{ "match": { "type": "key-press", "key": "M" }, "action": "view_toggle_model_axes" },
{ "match": { "type": "key-press", "key": "V" }, "action": "view_toggle_view_axes" },
{ "match": { "type": "key-press", "key": "2" }, "action": "view_2" },
{ "match": { "type": "key-press", "key": "3" }, "action": "view_3" },
{ "match": { "type": "key-press", "key": "4" }, "action": "view_4" },
{ "match": { "type": "key-press", "key": "5" }, "action": "view_5" },
{ "match": { "type": "key-press", "key": "6" }, "action": "view_6" },
{ "match": { "type": "key-press", "key": "7" }, "action": "view_7" },
{ "match": { "type": "key-press", "key": "F" }, "action": "view_front" },
{ "match": { "type": "key-press", "key": "T" }, "action": "view_top" },
{ "match": { "type": "key-press", "key": "B" }, "action": "view_bottom" },
{ "match": { "type": "key-press", "key": "L" }, "action": "view_left" },
{ "match": { "type": "key-press", "key": "R", "modifiers": ["Shift"] }, "action": "view_rear" },
{ "match": { "type": "key-press", "key": "R" }, "action": "view_right" },
{ "match": { "type": "mouse-press", "button": 0 }, "action": "view_mouse_press_left" },
{ "match": { "type": "mouse-release", "button": 0 }, "action": "view_mouse_release_left" },
{ "match": { "type": "mouse-release", "button": 2 }, "action": "view_mouse_release_right" },
{ "match": { "type": "mouse-release", "button": 1 }, "action": "view_mouse_release_middle" },
{ "match": { "type": "mouse-move", "button": 0, "modifiers": ["Control"] }, "action": "view_mouse_drag_rotate" },
{ "match": { "type": "mouse-move", "button": 0, "modifiers": ["Shift"] }, "action": "view_mouse_drag_translate" },
{ "match": { "type": "mouse-move", "button": 0, "modifiers": ["Control", "Shift"] }, "action": "view_mouse_drag_scale" },
{ "match": { "type": "mouse-move", "button": 0 }, "action": "view_mouse_drag_adjust" },
{ "match": { "type": "mouse-wheel" }, "action": "view_mouse_wheel_scale" }
]
}
}
}
+12
View File
@@ -66,10 +66,22 @@ dm_init_msgs()
}
#include "bu/binding.h"
static void
libdm_init(void)
{
bu_vls_init(&init_msgs);
const char *dm_schema = bu_dir(NULL, 0, BU_DIR_DATA, "bindings", "dm_schema.json", NULL);
if (dm_schema) {
bu_binding_register_schema("dm", dm_schema);
}
const char *fb_schema = bu_dir(NULL, 0, BU_DIR_DATA, "bindings", "fb_schema.json", NULL);
if (fb_schema) {
bu_binding_register_schema("fb", fb_schema);
}
const char *ppath = bu_dir(NULL, 0, BU_DIR_LIBEXEC, "dm", NULL);
char **dm_filenames;
+14
View File
@@ -29,6 +29,7 @@
#include <cctype>
#include <cstring>
#include <map>
#include "bu/binding.h"
#include <set>
#include <string>
#include <cstdio>
@@ -62,6 +63,13 @@ dm_open(void *ctx, void *interp, const char *type, int argc, const char *argv[])
const struct dm *d = d_it->second;
struct dm *dmp = d->i->dm_open(ctx, interp, argc, argv);
char *bindings_path = (char *)bu_dir(NULL, 0, BU_DIR_DATA, "bindings", "dm_bindings.json", NULL);
if (bindings_path) {
bu_binding_load(bindings_path);
bu_free(bindings_path, "bindings_path");
}
return dmp;
}
@@ -528,6 +536,12 @@ found_interface:
return FB_NULL;
}
char *bindings_path = (char *)bu_dir(NULL, 0, BU_DIR_DATA, "bindings", "dm_bindings.json", NULL);
if (bindings_path) {
bu_binding_load(bindings_path);
bu_free(bindings_path, "bindings_path");
}
return ifp;
}
+25
View File
@@ -0,0 +1,25 @@
{
"actions": {
"view_toggle_adc": "Toggle Angle Distance Cursor",
"view_toggle_model_axes": "Toggle Model Axes",
"view_toggle_view_axes": "Toggle View Axes",
"view_2": "Set View 2",
"view_3": "Set View 3",
"view_4": "Set View 4",
"view_5": "Set View 5",
"view_6": "Set View 6",
"view_7": "Set View 7",
"view_front": "Set Front View",
"view_top": "Set Top View",
"view_bottom": "Set Bottom View",
"view_left": "Set Left View",
"view_right": "Set Right View",
"view_rear": "Set Rear View",
"view_mouse_drag_rotate": "Rotate view via mouse drag",
"view_mouse_drag_translate": "Translate view via mouse drag",
"view_mouse_drag_scale": "Scale view via mouse drag",
"view_mouse_wheel_scale": "Scale view via mouse wheel",
"view_mouse_press_left": "Left mouse press action",
"view_mouse_press_right": "Right mouse press action"
}
}
+54
View File
@@ -53,6 +53,7 @@
#include "./include/private.h"
#include "icv.h"
#include "dm.h"
#include "bu/binding.h"
struct fb *fb_get(void)
@@ -258,6 +259,59 @@ long fb_poll_rate(struct fb *ifp)
return ifp->i->if_poll_refresh_rate;
}
static int
fb_event_button_to_w3c(int button)
{
return (button >= 1 && button <= 3) ? button - 1 : button;
}
int
fb_process_event_bindings(struct fb *ifp, const struct fb_event *event)
{
struct bu_vls event_json = BU_VLS_INIT_ZERO;
int handled = 0;
if (!ifp || !event)
return 0;
switch (event->type) {
case FB_EVENT_BUTTON_PRESS:
bu_vls_sprintf(&event_json,
"{\"type\": \"mouse-press\", \"button\": %d, \"x\": %d, \"y\": %d}",
fb_event_button_to_w3c(event->button), event->x, event->y);
break;
case FB_EVENT_BUTTON_RELEASE:
bu_vls_sprintf(&event_json,
"{\"type\": \"mouse-release\", \"button\": %d, \"x\": %d, \"y\": %d}",
fb_event_button_to_w3c(event->button), event->x, event->y);
break;
case FB_EVENT_MOTION:
bu_vls_sprintf(&event_json,
"{\"type\": \"mouse-move\", \"x\": %d, \"y\": %d}",
event->x, event->y);
break;
case FB_EVENT_KEY_PRESS:
if (event->keycode == 27) {
bu_vls_sprintf(&event_json, "{\"type\": \"key-press\", \"key\": \"Escape\"}");
} else if (event->keycode >= 32 && event->keycode <= 126) {
bu_vls_sprintf(&event_json,
"{\"type\": \"key-press\", \"key\": \"%c\"}",
event->keycode);
}
break;
case FB_EVENT_CLOSE:
bu_vls_sprintf(&event_json, "{\"type\": \"key-press\", \"key\": \"Escape\"}");
break;
default:
break;
}
if (bu_vls_strlen(&event_json) > 0)
handled = bu_binding_process_event("fb", bu_vls_cstr(&event_json), ifp);
bu_vls_free(&event_json);
return handled;
}
void fb_set_interactive(struct fb *ifp, int on)
{
if (!ifp)
+6
View File
@@ -0,0 +1,6 @@
{
"actions": {
"fb_print_pixel_rgb": "Print RGB values of pixel under cursor",
"fb_close_window": "Close framebuffer window"
}
}
+171 -72
View File
@@ -61,6 +61,10 @@
#include "dm.h"
#include "./fb_ogl.h"
#include "bu/binding.h"
#include "bu/file.h"
#include <X11/keysym.h>
extern struct fb ogl_interface;
#define DIRECT_COLOR_VISUAL_ALLOWED 0
@@ -774,6 +778,52 @@ ogl_configureWindow(struct fb *ifp, int width, int height)
return 0;
}
static void
ogl_action_fb_print_pixel_rgb(const struct bu_vls *event_json, void *registered_data, void *event_data)
{
struct fb *ifp = (struct fb *)event_data;
int x = -1, y = -1;
char *p;
if (!ifp) return;
if ((p = strstr(bu_vls_cstr(event_json), "\"x\":"))) {
sscanf(p + 4, "%d", &x);
}
if ((p = strstr(bu_vls_cstr(event_json), "\"y\":"))) {
sscanf(p + 4, "%d", &y);
}
if (x < 0 || y < 0) {
fb_log("No RGB (outside image viewport)\n");
return;
}
size_t memidx = (y * WIN(ifp)->mi_pixwidth) * sizeof(struct fb_pixel);
struct fb_pixel *oglp = (struct fb_pixel *)&ifp->i->if_mem[memidx];
fb_log("At image (%d, %d), real RGB=(%3d %3d %3d)\n",
x, y, (int)oglp[x].red, (int)oglp[x].green, (int)oglp[x].blue);
}
static void
ogl_action_fb_close_window(const struct bu_vls *event_json, void *registered_data, void *event_data)
{
struct fb *ifp = (struct fb *)event_data;
if (ifp) OGL(ifp)->alive = 0;
}
static int bindings_loaded = 0;
static void
ogl_init_bindings(void)
{
if (bindings_loaded) return;
bindings_loaded = 1;
bu_binding_register_action("fb_print_pixel_rgb", ogl_action_fb_print_pixel_rgb, NULL);
bu_binding_register_action("fb_close_window", ogl_action_fb_close_window, NULL);
}
static void
ogl_do_event(struct fb *ifp)
@@ -781,76 +831,122 @@ ogl_do_event(struct fb *ifp)
XEvent event;
while (XCheckWindowEvent(OGL(ifp)->dispp, OGL(ifp)->wind,
OGL(ifp)->event_mask, &event)) {
switch (event.type) {
case Expose:
if (!OGL(ifp)->use_ext_ctrl)
expose_callback(ifp);
break;
case ButtonPress:
{
int button = (int) event.xbutton.button;
if (button == Button1) {
/* Check for single button mouse remap.
* ctrl-1 => 2
* meta-1 => 3
* cmdkey => 3
*/
if (event.xbutton.state & ControlMask) {
button = Button2;
} else if (event.xbutton.state & Mod1Mask) {
button = Button3;
} else if (event.xbutton.state & Mod2Mask) {
button = Button3;
}
}
switch (button) {
case Button1:
break;
case Button2:
{
int x, y;
register struct fb_pixel *oglp;
x = event.xbutton.x;
y = ifp->i->if_height - event.xbutton.y - 1;
if (x < 0 || y < 0) {
fb_log("No RGB (outside image viewport)\n");
break;
}
size_t memidx = (y * WIN(ifp)->mi_pixwidth) * sizeof(struct fb_pixel);
oglp = (struct fb_pixel *)&ifp->i->if_mem[memidx];
fb_log("At image (%d, %d), real RGB=(%3d %3d %3d)\n",
x, y, (int)oglp[x].red, (int)oglp[x].green, (int)oglp[x].blue);
break;
}
case Button3:
OGL(ifp)->alive = 0;
break;
default:
fb_log("unhandled mouse event\n");
break;
}
break;
}
case ConfigureNotify:
{
XConfigureEvent *conf = (XConfigureEvent *)&event;
if (conf->width == OGL(ifp)->win_width &&
conf->height == OGL(ifp)->win_height)
return;
ogl_configureWindow(ifp, conf->width, conf->height);
}
default:
break;
}
OGL(ifp)->event_mask, &event)) {
switch (event.type) {
case Expose:
if (!OGL(ifp)->use_ext_ctrl)
expose_callback(ifp);
if (fb_get_interactive(ifp)) {
struct fb_event ev = {FB_EVENT_EXPOSE, 0, 0, 0, 0, 0};
fb_enqueue_event(ifp, &ev);
}
break;
case ButtonPress:
if (fb_get_interactive(ifp)) {
struct fb_event ev;
memset(&ev, 0, sizeof(ev));
ev.type = FB_EVENT_BUTTON_PRESS;
ev.button = (int)event.xbutton.button;
ev.x = event.xbutton.x;
ev.y = ifp->i->if_height - event.xbutton.y - 1;
ev.state = (int)event.xbutton.state;
fb_enqueue_event(ifp, &ev);
} else {
int button = (int)event.xbutton.button;
int w3c_button = 0;
if (button == Button1) {
if (event.xbutton.state & ControlMask) button = Button2;
else if (event.xbutton.state & Mod1Mask) button = Button3;
else if (event.xbutton.state & Mod2Mask) button = Button3;
}
if (button == Button1) w3c_button = 0;
else if (button == Button2) w3c_button = 1;
else if (button == Button3) w3c_button = 2;
else w3c_button = button;
struct bu_vls ev_json = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&ev_json,
"{\"type\": \"mouse-press\", \"button\": %d, \"x\": %d, \"y\": %d}",
w3c_button, event.xbutton.x,
ifp->i->if_height - event.xbutton.y - 1);
bu_binding_process_event("fb", bu_vls_cstr(&ev_json), ifp);
bu_vls_free(&ev_json);
}
break;
case ButtonRelease:
if (fb_get_interactive(ifp)) {
struct fb_event ev;
memset(&ev, 0, sizeof(ev));
ev.type = FB_EVENT_BUTTON_RELEASE;
ev.button = (int)event.xbutton.button;
ev.x = event.xbutton.x;
ev.y = ifp->i->if_height - event.xbutton.y - 1;
ev.state = (int)event.xbutton.state;
fb_enqueue_event(ifp, &ev);
}
break;
case MotionNotify:
if (fb_get_interactive(ifp)) {
struct fb_event ev;
memset(&ev, 0, sizeof(ev));
ev.type = FB_EVENT_MOTION;
ev.x = event.xmotion.x;
ev.y = ifp->i->if_height - event.xmotion.y - 1;
ev.state = (int)event.xmotion.state;
fb_enqueue_event(ifp, &ev);
}
break;
case KeyPress:
if (fb_get_interactive(ifp)) {
struct fb_event ev;
char keybuf[8] = {0};
KeySym keysym;
int n;
memset(&ev, 0, sizeof(ev));
ev.type = FB_EVENT_KEY_PRESS;
n = XLookupString(&event.xkey, keybuf, sizeof(keybuf), &keysym, NULL);
ev.keycode = (n > 0) ? (unsigned char)keybuf[0] : (int)keysym;
ev.state = (int)event.xkey.state;
fb_enqueue_event(ifp, &ev);
} else {
KeySym keysym = XLookupKeysym(&event.xkey, 0);
char *key_str = XKeysymToString(keysym);
if (key_str) {
struct bu_vls ev_json = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&ev_json,
"{\"type\": \"key-press\", \"key\": \"%s\"}", key_str);
bu_binding_process_event("fb", bu_vls_cstr(&ev_json), ifp);
bu_vls_free(&ev_json);
}
}
break;
case ClientMessage:
if (fb_get_interactive(ifp)) {
struct fb_event ev = {FB_EVENT_CLOSE, 0, 0, 0, 0, 0};
fb_enqueue_event(ifp, &ev);
} else {
OGL(ifp)->alive = 0;
}
break;
case ConfigureNotify:
{
XConfigureEvent *conf = (XConfigureEvent *)&event;
if (conf->width == OGL(ifp)->win_width &&
conf->height == OGL(ifp)->win_height)
break;
ogl_configureWindow(ifp, conf->width, conf->height);
if (fb_get_interactive(ifp)) {
struct fb_event ev;
memset(&ev, 0, sizeof(ev));
ev.type = FB_EVENT_RESIZE;
ev.x = conf->width;
ev.y = conf->height;
fb_enqueue_event(ifp, &ev);
}
}
break;
default:
break;
}
}
}
@@ -1021,9 +1117,10 @@ fb_ogl_open(struct fb *ifp, const char *file, int width, int height)
int mode, i;
long valuemask;
XSetWindowAttributes swa;
FB_CK_FB(ifp->i);
ogl_init_bindings();
/*
* First, attempt to determine operating mode for this open,
* based upon the "unit number" or flags.
@@ -1214,7 +1311,7 @@ fb_ogl_open(struct fb *ifp, const char *file, int width, int height)
OGL(ifp)->vip->screen);
swa.event_mask = OGL(ifp)->event_mask =
ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | ButtonReleaseMask;
ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask;
swa.colormap = OGL(ifp)->xcmap;
#define XCreateWindowDebug(display, parent, x, y, width, height, border_width, depth, class, visual, valuemask, attributes) \
@@ -1381,6 +1478,8 @@ ogl_open_existing(struct fb *ifp, int width, int height, struct fb_platform_spec
{
struct ogl_fb_info *ogl_internal = (struct ogl_fb_info *)fb_p->data;
BU_CKMAG(fb_p, FB_OGL_MAGIC, "ogl framebuffer");
ogl_init_bindings();
return open_existing(ifp, ogl_internal->dpy, ogl_internal->win,
ogl_internal->cmap, ogl_internal->vip, width, height, ogl_internal->glxc,
ogl_internal->double_buffer, ogl_internal->soft_cmap);
+6 -8
View File
@@ -62,8 +62,9 @@ constexpr fastf_t DEFAULT_LEADER_MARGIN_SCALE = 2.0;
constexpr fastf_t DEFAULT_SCREEN_TEXT_HEIGHT_MM = 3.0;
/* The display-plane renderer uses this nominal density. --dpi makes the
* physical size explicit for displays whose effective density differs. */
constexpr fastf_t DEFAULT_SCREEN_DPI = RT_ANNOT_SCREEN_DPI;
constexpr fastf_t DISPLAY_PIXELS_PER_MM = RT_ANNOT_SCREEN_PIXELS_PER_MM;
constexpr fastf_t DEFAULT_SCREEN_DPI = 96.0;
constexpr fastf_t MILLIMETERS_PER_INCH = 25.4;
constexpr fastf_t DISPLAY_PIXELS_PER_MM = DEFAULT_SCREEN_DPI / MILLIMETERS_PER_INCH;
constexpr double AUTODIM_TEXT_WIDTH_SCALE = 0.65;
/* Layout penalties deliberately dominate the smaller rewards so avoiding
* collisions and crossings wins over merely moving a label farther out. */
@@ -472,12 +473,10 @@ parse_options(struct ged *gedp, int argc, const char **argv,
bu_vls_printf(gedp->ged_result_str, "Precision must be between 0 and 15");
return -1;
}
if (!std::isfinite(opts.text_height) || !std::isfinite(opts.line_width) ||
opts.text_height < 0.0 || opts.line_width < 0.0 ||
std::isinf(opts.offset) ||
if (opts.text_height < 0.0 || opts.line_width < 0.0 ||
(std::isfinite(opts.offset) && opts.offset < 0.0)) {
bu_vls_printf(gedp->ged_result_str,
"Text height and line width must be finite and non-negative; offset must be finite and non-negative when specified");
"Text height, line width, and offset must not be negative");
return -1;
}
if (!std::isfinite(opts.dpi) || opts.dpi <= 0.0) {
@@ -2905,8 +2904,7 @@ cmd_info(void *data, int argc, const char **argv)
if (rt_db_get_internal(&intern, dp, gedp->dbip, NULL) == ID_ANNOT) {
struct rt_annot_internal *annotation =
static_cast<struct rt_annot_internal *>(intern.idb_ptr);
bu_vls_printf(gedp->ged_result_str,
"\nspace: %s\nsegments: %zu",
bu_vls_printf(gedp->ged_result_str, "\nspace: %s\nsegments: %zu",
(annotation->flags & RT_ANNOT_MODEL_SPACE) ? "model" : "view",
annotation->ant.count);
rt_db_free_internal(&intern);
+241 -246
View File
@@ -37,6 +37,12 @@ extern "C" {
#include "qtcad/defines.h"
#include "bindings.h"
extern "C" {
#include "bu/binding.h"
#include "bu/file.h"
#include "bu/log.h"
}
typedef void (*bounds_update_t)(struct bview *);
static std::unordered_map<struct bview *, bounds_update_t> drag_bounds_updates;
static std::unordered_map<struct bview *, long long> drag_update_ts;
@@ -68,247 +74,256 @@ restore_drag_bounds_update(struct bview *v, int refresh_bounds)
drag_update_ts.erase(v);
}
// TODO - look into QShortcut, see if it might be a better way
// to manage this
static int bindings_loaded = 0;
static void qtcad_action_toggle_adc(const char *, void *, void *event_data) {
struct bview *v = (struct bview *)event_data;
if (v) v->gv_s->gv_adc.draw = !v->gv_s->gv_adc.draw;
}
static void qtcad_action_toggle_model_axes(const char *, void *, void *event_data) {
struct bview *v = (struct bview *)event_data;
if (v) v->gv_s->gv_model_axes.draw = !v->gv_s->gv_model_axes.draw;
}
static void qtcad_action_toggle_view_axes(const char *, void *, void *event_data) {
struct bview *v = (struct bview *)event_data;
if (v) v->gv_s->gv_view_axes.draw = !v->gv_s->gv_view_axes.draw;
}
static void qtcad_action_view_set(const char *, void *registered_data, void *event_data) {
struct bview *v = (struct bview *)event_data;
const char *aet_str = (const char *)registered_data;
if (v && aet_str) {
bn_decode_vect(v->gv_aet, aet_str);
bv_mat_aet(v);
bv_update(v);
}
}
static void qtcad_action_mouse_release(const char *event_json, void *, void *event_data) {
struct bview *v = (struct bview *)event_data;
if (!v) return;
int cx = 0, cy = 0, mode = 0, dx = 1, dy = 1;
char *p;
if ((p = strstr(event_json, "\"cx\":"))) sscanf(p + 5, "%d", &cx);
if ((p = strstr(event_json, "\"cy\":"))) sscanf(p + 5, "%d", &cy);
if ((p = strstr(event_json, "\"mode\":"))) sscanf(p + 7, "%d", &mode);
int button = 0;
if ((p = strstr(event_json, "\"button\":"))) sscanf(p + 9, "%d", &button);
unsigned long long view_flags = BV_IDLE;
if (button == 0) { // Left
if (mode != BV_CENTER) { view_flags = BV_SCALE; dx = 10; dy = 5; }
else { view_flags = BV_CENTER; dx = cx; dy = cy; }
} else if (button == 2) { // Right
if (mode == BV_CENTER) return;
view_flags = BV_SCALE; dx = 1; dy = 2;
} else if (button == 1) { // Middle
view_flags = BV_CENTER; dx = cx; dy = cy;
} else {
return;
}
point_t keypt = VINIT_ZERO;
bv_adjust(v, dx, dy, keypt, 0, view_flags);
}
static void qtcad_action_adjust_view(const char *event_json, void *registered_data, void *event_data) {
struct bview *v = (struct bview *)event_data;
if (!v) return;
int dx = 0, dy = 0, mode = 0;
int view_flags = (int)(intptr_t)registered_data;
char *p;
if ((p = strstr(event_json, "\"dx\":"))) sscanf(p + 5, "%d", &dx);
if ((p = strstr(event_json, "\"dy\":"))) sscanf(p + 5, "%d", &dy);
if ((p = strstr(event_json, "\"mode\":"))) sscanf(p + 7, "%d", &mode);
if (view_flags == 0) { // dynamic fallback
view_flags = mode;
if (mode == BV_CENTER) view_flags = BV_SCALE;
}
if (view_flags == BV_SCALE) {
int mdelta = (abs(dx) > abs(dy)) ? dx : -dy;
int f = (int)(2*100*(double)abs(mdelta)/(double)v->gv_height);
if (mdelta > 0) { dy = 101 + f; dx = 100; }
else { dy = 99 - f; dx = 100; }
}
point_t center;
MAT_DELTAS_GET_NEG(center, v->gv_center);
if (view_flags & (BV_ROT | BV_TRANS | BV_SCALE))
suspend_drag_bounds_update(v);
bv_adjust(v, dx, dy, center, 0, view_flags);
}
static void qtcad_action_wheel_scale(const char *event_json, void *, void *event_data) {
struct bview *v = (struct bview *)event_data;
if (!v) return;
int delta = 0;
char *p;
if ((p = strstr(event_json, "\"delta\":"))) sscanf(p + 8, "%d", &delta);
int dx = 100 + delta;
int dy = 100;
point_t origin = VINIT_ZERO;
bv_adjust(v, dx, dy, origin, 0, BV_SCALE);
}
extern "C" QCAD_EXPORT int qtcad_load_bindings(const char *json_path) {
if (bu_binding_load(json_path) < 0) {
bu_log("libqtcad: Failed to load bindings from %s\n", json_path);
return -1;
}
if (!bu_binding_action_is_bound("dm", "view_toggle_adc") ||
!bu_binding_action_is_bound("dm", "view_2")) {
bu_log("libqtcad Validation Failed: Provided bindings missing required standard actions.\n");
return -1;
}
return 0;
}
static void qtcad_init_bindings(void) {
if (bindings_loaded) return;
bindings_loaded = 1;
bu_binding_register_action("view_toggle_adc", qtcad_action_toggle_adc, NULL);
bu_binding_register_action("view_toggle_model_axes", qtcad_action_toggle_model_axes, NULL);
bu_binding_register_action("view_toggle_view_axes", qtcad_action_toggle_view_axes, NULL);
bu_binding_register_action("view_2", qtcad_action_view_set, (void*)"35 -25 0");
bu_binding_register_action("view_3", qtcad_action_view_set, (void*)"35 25 0");
bu_binding_register_action("view_4", qtcad_action_view_set, (void*)"45 45 0");
bu_binding_register_action("view_5", qtcad_action_view_set, (void*)"145 25 0");
bu_binding_register_action("view_6", qtcad_action_view_set, (void*)"215 25 0");
bu_binding_register_action("view_7", qtcad_action_view_set, (void*)"325 25 0");
bu_binding_register_action("view_front", qtcad_action_view_set, (void*)"0 0 0");
bu_binding_register_action("view_top", qtcad_action_view_set, (void*)"270 90 0");
bu_binding_register_action("view_bottom", qtcad_action_view_set, (void*)"270 -90 0");
bu_binding_register_action("view_left", qtcad_action_view_set, (void*)"90 0 0");
bu_binding_register_action("view_rear", qtcad_action_view_set, (void*)"180 0 0");
bu_binding_register_action("view_right", qtcad_action_view_set, (void*)"270 0 0");
bu_binding_register_action("view_mouse_release_left", qtcad_action_mouse_release, NULL);
bu_binding_register_action("view_mouse_release_right", qtcad_action_mouse_release, NULL);
bu_binding_register_action("view_mouse_release_middle", qtcad_action_mouse_release, NULL);
bu_binding_register_action("view_mouse_drag_rotate", qtcad_action_adjust_view, (void*)(intptr_t)BV_ROT);
bu_binding_register_action("view_mouse_drag_translate", qtcad_action_adjust_view, (void*)(intptr_t)BV_TRANS);
bu_binding_register_action("view_mouse_drag_scale", qtcad_action_adjust_view, (void*)(intptr_t)BV_SCALE);
bu_binding_register_action("view_mouse_drag_adjust", qtcad_action_adjust_view, (void*)(intptr_t)0);
bu_binding_register_action("view_mouse_wheel_scale", qtcad_action_wheel_scale, NULL);
}
static void append_modifiers(struct bu_vls *vls, QInputEvent *e) {
if (!e->modifiers()) return;
bu_vls_printf(vls, ", \"modifiers\": [");
int added = 0;
if (e->modifiers().testFlag(Qt::ShiftModifier)) { bu_vls_printf(vls, "\"Shift\""); added=1; }
if (e->modifiers().testFlag(Qt::ControlModifier)) { if(added) bu_vls_printf(vls, ", "); bu_vls_printf(vls, "\"Control\""); added=1; }
if (e->modifiers().testFlag(Qt::AltModifier)) { if(added) bu_vls_printf(vls, ", "); bu_vls_printf(vls, "\"Alt\""); }
bu_vls_printf(vls, "]");
}
int CADkeyPressEvent(struct bview *v, int UNUSED(x_prev), int UNUSED(y_prev), QKeyEvent *k)
{
QTCAD_EVENT("keyPress", 1);
if (!v)
return 0;
#if 0
QString kstr = QKeySequence(k->key()).toString();
bu_log("%s\n", kstr.toStdString().c_str());
#endif
switch (k->key()) {
case 'A':
v->gv_s->gv_adc.draw = !v->gv_s->gv_adc.draw;
return 1;
case 'M':
v->gv_s->gv_model_axes.draw = !v->gv_s->gv_model_axes.draw;
return 1;
case 'V':
v->gv_s->gv_view_axes.draw = !v->gv_s->gv_view_axes.draw;
return 1;
case '2':
bn_decode_vect(v->gv_aet, "35 -25 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case '3':
bn_decode_vect(v->gv_aet, "35 25 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case '4':
bn_decode_vect(v->gv_aet, "45 45 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case '5':
bn_decode_vect(v->gv_aet, "145 25 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case '6':
bn_decode_vect(v->gv_aet, "215 25 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case '7':
bn_decode_vect(v->gv_aet, "325 25 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case 'F':
bn_decode_vect(v->gv_aet, "0 0 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case 'T':
bn_decode_vect(v->gv_aet, "270 90 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case 'B':
bn_decode_vect(v->gv_aet, "270 -90 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case 'L':
bn_decode_vect(v->gv_aet, "90 0 0");
bv_mat_aet(v);
bv_update(v);
return 1;
case 'R':
if (k->modifiers().testFlag(Qt::ShiftModifier) == true) {
bn_decode_vect(v->gv_aet, "180 0 0");
} else {
bn_decode_vect(v->gv_aet, "270 0 0");
}
bv_mat_aet(v);
bv_update(v);
return 1;
default:
break;
if (!v) return 0;
qtcad_init_bindings();
struct bu_vls ev_json = BU_VLS_INIT_ZERO;
char key_str[8] = {0};
if (k->key() >= 0x20 && k->key() <= 0x7E) {
key_str[0] = (char)k->key();
} else {
QString kstr = QKeySequence(k->key()).toString();
strncpy(key_str, kstr.toStdString().c_str(), 7);
}
return 0;
bu_vls_sprintf(&ev_json, "{\"type\": \"key-press\", \"key\": \"%s\"", key_str);
append_modifiers(&ev_json, k);
bu_vls_printf(&ev_json, "}");
int handled = bu_binding_process_event("dm", bu_vls_cstr(&ev_json), v);
bu_vls_free(&ev_json);
return handled;
}
int CADmousePressEvent(struct bview *v, int UNUSED(x_prev), int UNUSED(y_prev), QMouseEvent *e)
{
QTCAD_EVENT("mousePress", 1);
if (!v) return 0;
qtcad_init_bindings();
if (!v)
return 0;
int button = -1;
if (e->buttons().testFlag(Qt::LeftButton)) button = 0;
else if (e->buttons().testFlag(Qt::MiddleButton)) button = 1;
else if (e->buttons().testFlag(Qt::RightButton)) button = 2;
if (button < 0) return 0;
// If we're intending the mouse motion to do the work,
// then the press has to be a no-op. If we're going
// to do configurable key bindings, this will take some
// thought - if we want unmodded left button to be a
// rotation, and Ctrl+Left to do something else, these
// checks are all going to have to be exact-flag-combo-only
// actions.
if (e->modifiers()) {
return 0;
}
if (e->buttons().testFlag(Qt::LeftButton)) {
//bu_log("Press Left\n");
}
if (e->buttons().testFlag(Qt::RightButton)) {
//bu_log("Press Right\n");
}
if (e->buttons().testFlag(Qt::MiddleButton)) {
//bu_log("Press Middle\n");
}
return 0;
struct bu_vls ev_json = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&ev_json, "{\"type\": \"mouse-press\", \"button\": %d", button);
append_modifiers(&ev_json, e);
bu_vls_printf(&ev_json, "}");
int handled = bu_binding_process_event("dm", bu_vls_cstr(&ev_json), v);
bu_vls_free(&ev_json);
return handled;
}
int CADmouseReleaseEvent(struct bview *v, double x_press, double y_press, int UNUSED(x_prev), int UNUSED(y_prev), QMouseEvent *e, int mode)
{
QTCAD_EVENT("mouseRelease", 1);
if (!v)
return 0;
if (!v) return 0;
qtcad_init_bindings();
restore_drag_bounds_update(v, 1);
// If we're intending the mouse motion to do the work,
// then the release has to be a no-op. If we're going
// to do configurable key bindings, this will take some
// thought - if we want unmodded left button to be a
// rotation, and Ctrl+Left to do something else, these
// checks are all going to have to be exact-flag-combo-only
// actions.
if (e->modifiers()) {
return 0;
}
if (e->buttons().testFlag(Qt::LeftButton) || e->buttons().testFlag(Qt::RightButton)) {
return 0;
}
double cx, cy;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
cx = (double)e->x();
cy = (double)e->y();
double cx = e->x();
double cy = e->y();
#else
cx = e->position().x();
cy = e->position().y();
double cx = e->position().x();
double cy = e->position().y();
#endif
if ((fabs(cx - x_press) > 10) || (fabs(cy - y_press) > 10))
return 0;
int dx = 1;
int dy = 1;
unsigned long long view_flags = BV_IDLE;
if ((fabs(cx - x_press) > 10) || (fabs(cy - y_press) > 10)) return 0;
if (e->button() == Qt::LeftButton) {
//bu_log("Release Left\n");
if (mode != BV_CENTER) {
view_flags = BV_SCALE;
dx = 10;
dy = 5;
} else {
view_flags = BV_CENTER;
dx = (int)cx;
dy = (int)cy;
}
}
if (e->button() == Qt::RightButton) {
//bu_log("Release Right\n");
if (mode == BV_CENTER)
return 0;
view_flags = BV_SCALE;
dx = 1;
dy = 2;
}
int button = -1;
if (e->button() == Qt::LeftButton) button = 0;
else if (e->button() == Qt::MiddleButton) button = 1;
else if (e->button() == Qt::RightButton) button = 2;
if (button < 0) return 0;
if (e->button() == Qt::MiddleButton) {
//bu_log("Release Center\n");
view_flags = BV_CENTER;
dx = (int)cx;
dy = (int)cy;
}
point_t keypt = VINIT_ZERO;
return bv_adjust(v, dx, dy, keypt, 0, view_flags);
struct bu_vls ev_json = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&ev_json, "{\"type\": \"mouse-release\", \"button\": %d, \"cx\": %d, \"cy\": %d, \"mode\": %d", button, (int)cx, (int)cy, mode);
append_modifiers(&ev_json, e);
bu_vls_printf(&ev_json, "}");
int handled = bu_binding_process_event("dm", bu_vls_cstr(&ev_json), v);
bu_vls_free(&ev_json);
return handled;
}
int CADmouseMoveEvent(struct bview *v, int x_prev, int y_prev, QMouseEvent *e, int mode)
{
QTCAD_EVENT("mouseMove", 2);
if (!v) return 0;
qtcad_init_bindings();
if (!v)
return 0;
unsigned long long view_flags = BV_IDLE;
if (x_prev == -INT_MAX) {
//x_prev = e->x();
//y_prev = e->y();
return 0;
}
view_flags = mode;
if (mode == BV_CENTER)
view_flags = BV_SCALE;
if (e->buttons().testFlag(Qt::LeftButton)) {
//bu_log("Left\n");
if (e->modifiers().testFlag(Qt::ControlModifier)) {
//bu_log("Ctrl+Left\n");
view_flags = BV_ROT;
}
if (e->modifiers().testFlag(Qt::ShiftModifier)) {
//bu_log("Shift+Left\n");
view_flags = BV_TRANS;
}
if (e->modifiers().testFlag(Qt::ShiftModifier) && e->modifiers().testFlag(Qt::ControlModifier)) {
//bu_log("Ctrl+Shift+Left\n");
view_flags = BV_SCALE;
}
}
if (e->buttons().testFlag(Qt::MiddleButton)) {
//bu_log("Middle\n");
}
if (e->buttons().testFlag(Qt::RightButton)) {
//bu_log("Right\n");
}
if (!e->buttons().testFlag(Qt::LeftButton))
return 0;
if (x_prev == -INT_MAX) return 0;
if (!e->buttons().testFlag(Qt::LeftButton)) return 0;
long long now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch()).count();
std::unordered_map<struct bview *, long long>::iterator ts_it = drag_update_ts.find(v);
if (ts_it != drag_update_ts.end() && (now_ms - ts_it->second) < drag_update_interval_ms)
return -1;
if (ts_it != drag_update_ts.end() && (now_ms - ts_it->second) < drag_update_interval_ms) return -1;
drag_update_ts[v] = now_ms;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@@ -319,53 +334,33 @@ int CADmouseMoveEvent(struct bview *v, int x_prev, int y_prev, QMouseEvent *e, i
int dy = e->position().y() - y_prev;
#endif
if (view_flags == BV_SCALE) {
// Build in some sensitivity to how much the mouse moved when doing
// a motion based scale
int mdelta = (abs(dx) > abs(dy)) ? dx : -dy;
int f = (int)(2*100*(double)abs(mdelta)/(double)v->gv_height);
if (mdelta > 0) {
dy = 101 + f;
dx = 100;
} else {
dy = 99 - f;
dx = 100;
}
}
// TODO - the key point and the mode/flags are all hardcoded
// right now, but eventually for shift grips they will need to
// respond to the various mod keys. The intent is to set flags
// based on which mod keys are set to allow bv_adjust to
// do the correct math.
point_t center;
MAT_DELTAS_GET_NEG(center, v->gv_center);
if (view_flags & (BV_ROT | BV_TRANS | BV_SCALE))
suspend_drag_bounds_update(v);
return bv_adjust(v, dx, dy, center, 0, view_flags);
struct bu_vls ev_json = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&ev_json, "{\"type\": \"mouse-move\", \"button\": 0, \"dx\": %d, \"dy\": %d, \"mode\": %d", dx, dy, mode);
append_modifiers(&ev_json, e);
bu_vls_printf(&ev_json, "}");
int handled = bu_binding_process_event("dm", bu_vls_cstr(&ev_json), v);
bu_vls_free(&ev_json);
return handled;
}
int CADwheelEvent(struct bview *v, QWheelEvent *e)
{
QTCAD_EVENT("mouseWheel", 1);
if (!v)
return 0;
if (!v) return 0;
qtcad_init_bindings();
QPoint delta = e->angleDelta();
int mdelta = -1* delta.y() / 8;
int dx = 100 + mdelta;
int dy = 100;
point_t origin = VINIT_ZERO;
return bv_adjust(v, dx, dy, origin, 0, BV_SCALE);
int mdelta = -1 * delta.y() / 8;
struct bu_vls ev_json = BU_VLS_INIT_ZERO;
bu_vls_sprintf(&ev_json, "{\"type\": \"mouse-wheel\", \"delta\": %d", mdelta);
append_modifiers(&ev_json, e);
bu_vls_printf(&ev_json, "}");
int handled = bu_binding_process_event("dm", bu_vls_cstr(&ev_json), v);
bu_vls_free(&ev_json);
return handled;
}
// Local Variables:
-1
View File
@@ -150,7 +150,6 @@ set(
prep.cpp
${LIBRT_PRIMEDIT_SOURCES}
primitives/annot/annot.c
primitives/annot/annot_render.cpp
primitives/arb8/arb8.c
primitives/arb8/arb8_brep.cpp
primitives/arb8/arb8_mirror.c
+586 -47
View File
@@ -49,6 +49,7 @@
#include "nmg.h"
#include "rt/geom.h"
#include "rt/primitives/annot.h"
#include "rt/primitives/bot.h"
#include "raytrace.h"
#if defined(__GNUC__) && !defined(__clang__)
@@ -76,8 +77,46 @@
#define ANNOT_PRES_MAGIC 0x414e5032u /* "ANP2" */
#define ANNOT_PRES_VERSION 1u
/* Stored line widths are display-scale multipliers, not model distances.
* Primitive prep has no view pixel scale, so infer a stable model-space base
* width from the annotation content before applying that multiplier. */
#define ANNOT_TEXT_STROKE_RATIO (1.0 / 14.0)
#define ANNOT_GEOMETRY_STROKE_RATIO 0.01
#define ANNOT_MIN_WIDTH_TOL_FACTOR 4.0
struct annot_mesh {
point_t *vertices;
size_t vertex_count;
size_t vertex_capacity;
int *faces;
fastf_t *thickness;
size_t face_count;
size_t face_capacity;
};
C_DECL void rt_annot_ifree(struct rt_db_internal *ip);
/* Annotation prep uses BOT as a transient raytrace representation, as ARS
* does. These callbacks are internal to librt rather than public BOT APIs. */
C_DECL int rt_bot_prep(struct soltab *stp, struct rt_db_internal *ip,
struct rt_i *rtip);
C_DECL int rt_bot_shot(struct soltab *stp, struct xray *rp,
struct application *ap, struct seg *seghead);
C_DECL void rt_bot_print(const struct soltab *stp);
C_DECL void rt_bot_norm(struct hit *hitp, struct soltab *stp,
struct xray *rp);
C_DECL void rt_bot_curve(struct curvature *cvp, struct hit *hitp,
struct soltab *stp);
C_DECL void rt_bot_uv(struct application *ap, struct soltab *stp,
struct hit *hitp, struct uvcoord *uvp);
C_DECL void rt_bot_free(struct soltab *stp);
C_DECL void rt_bot_ifree(struct rt_db_internal *ip);
static int annot_to_bot(struct rt_bot_internal **result,
const struct rt_annot_internal *annot_ip,
const struct bg_tess_tol *ttol, const struct bn_tol *tol,
unsigned char bot_mode);
static uint32_t
annot_get_uint32(const unsigned char *cp)
{
@@ -434,9 +473,8 @@ rt_annot_validate(const struct rt_annot_internal *annot_ip,
annot_validation_message(messages, i, "fill has no compatible outline segments");
ret++;
} else {
size_t legacy_end = (size_t)fsg->legacy_start +
(size_t)fsg->legacy_count;
for (j = (size_t)fsg->legacy_start; j < legacy_end; ++j)
for (j = (size_t)fsg->legacy_start;
j < (size_t)(fsg->legacy_start + fsg->legacy_count); ++j)
if (!ant->segments[j] ||
*(uint32_t *)ant->segments[j] != CURVE_LSEG_MAGIC) {
annot_validation_message(messages, i,
@@ -503,25 +541,59 @@ rt_annot_validate(const struct rt_annot_internal *annot_ip,
C_DECL int
rt_annot_prep(struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
{
struct bg_tess_tol default_ttol = BG_TESS_TOL_INIT_TOL;
struct bn_tol default_tol = BN_TOL_INIT_TOL;
const struct rt_annot_internal *annot_ip;
struct rt_bot_internal *bot = NULL;
struct rt_db_internal bot_intern;
const struct bg_tess_tol *ttol = &default_ttol;
const struct bn_tol *tol = &default_tol;
int ret;
if (!stp)
return -1;
RT_CK_SOLTAB(stp);
if (ip) RT_CK_DB_INTERNAL(ip);
if (rtip) RT_CK_RTI(rtip);
if (!ip)
return -1;
RT_CK_DB_INTERNAL(ip);
if (rtip) {
RT_CK_RTI(rtip);
ttol = &rtip->rti_ttol;
tol = &rtip->rti_tol;
}
if (ip && rt_annot_validate(
(const struct rt_annot_internal *)ip->idb_ptr, NULL))
annot_ip = (const struct rt_annot_internal *)ip->idb_ptr;
if (rt_annot_validate(annot_ip, NULL))
return -1;
/* View-space annotations need camera state, which primitive prep does not
* have. Leave them non-intersecting until a view-aware prep API exists. */
stp->st_specific = (void *)NULL;
return 0;
if (!(annot_ip->flags & RT_ANNOT_MODEL_SPACE))
return 0;
if (annot_to_bot(&bot, annot_ip, ttol, tol, RT_BOT_PLATE) || !bot)
return -1;
RT_DB_INTERNAL_INIT(&bot_intern);
bot_intern.idb_major_type = DB5_MAJORTYPE_BRLCAD;
bot_intern.idb_type = ID_BOT;
bot_intern.idb_meth = &OBJ[ID_BOT];
bot_intern.idb_ptr = bot;
ret = rt_bot_prep(stp, &bot_intern, rtip);
rt_bot_ifree(&bot_intern);
return ret;
}
C_DECL void
rt_annot_print(const struct soltab *stp)
{
if (stp) RT_CK_SOLTAB(stp);
if (!stp)
return;
RT_CK_SOLTAB(stp);
if (stp->st_specific)
rt_bot_print(stp);
}
@@ -543,25 +615,18 @@ rt_annot_shot(struct soltab *stp, struct xray *rp, struct application *ap, struc
RT_CK_RAY(rp);
RT_CK_APPLICATION(ap);
/* Annotation coverage is evaluated separately from solid partitions. */
return 0; /* MISS */
return stp->st_specific ? rt_bot_shot(stp, rp, ap, seghead) : 0;
}
/**
* Vectorized rt_annot_shot(): annotations do not create solid partitions, so
* every ray in the batch misses.
* Vectorized annotation shooting uses the scalar wrapper so view-space
* annotations without prepared geometry continue to miss safely.
*/
C_DECL void
rt_annot_vshot(struct soltab **stp, struct xray **UNUSED(rp), struct seg *segp, int n, struct application *ap)
rt_annot_vshot(struct soltab **stp, struct xray **rp, struct seg *segp, int n, struct application *ap)
{
int i;
if (ap) RT_CK_APPLICATION(ap);
for (i = 0; i < n; i++) {
if (stp[i] == 0) continue; /* skip this ray */
segp[i].seg_stp = (struct soltab *)0; /* always MISS */
}
rt_vshot_via_shot(rt_annot_shot, stp, rp, segp, n, ap);
}
@@ -578,6 +643,10 @@ rt_annot_norm(struct hit *hitp, struct soltab *stp, struct xray *rp)
if (stp) RT_CK_SOLTAB(stp);
RT_CK_RAY(rp);
if (stp && stp->st_specific) {
rt_bot_norm(hitp, stp, rp);
return;
}
VJOIN1(hitp->hit_point, rp->r_pt, hitp->hit_dist, rp->r_dir);
}
@@ -594,6 +663,10 @@ rt_annot_curve(struct curvature *cvp, struct hit *hitp, struct soltab *stp)
RT_CK_HIT(hitp);
if (stp) RT_CK_SOLTAB(stp);
if (stp && stp->st_specific) {
rt_bot_curve(cvp, hitp, stp);
return;
}
cvp->crv_c1 = cvp->crv_c2 = 0;
bn_vec_ortho(cvp->crv_pdir, hitp->hit_normal);
@@ -608,13 +681,19 @@ rt_annot_uv(struct application *ap, struct soltab *stp, struct hit *hitp, struct
if (hitp) RT_CK_HIT(hitp);
if (!uvp)
return;
if (stp && stp->st_specific)
rt_bot_uv(ap, stp, hitp, uvp);
}
C_DECL void
rt_annot_free(struct soltab *stp)
{
if (stp) RT_CK_SOLTAB(stp);
if (!stp)
return;
RT_CK_SOLTAB(stp);
if (stp->st_specific)
rt_bot_free(stp);
}
@@ -1526,29 +1605,6 @@ seg_to_vlist(struct bu_list *vlfree, struct bu_list *vhead, const struct bg_tess
}
int
rt_annot_segment_vlist(struct bu_list *vlfree, struct bu_list *vhead,
const struct bg_tess_tol *ttol,
const struct rt_annot_internal *annot_ip, size_t segment)
{
struct rt_annot_internal local;
point_t base = VINIT_ZERO;
if (!vlfree || !vhead || !ttol || !annot_ip ||
segment >= annot_ip->ant.count || !annot_ip->ant.segments ||
!annot_ip->ant.segments[segment])
return 1;
RT_ANNOT_CK_MAGIC(annot_ip);
local = *annot_ip;
local.flags = RT_ANNOT_SCREEN_SPACE;
VSETALL(local.V, 0.0);
return seg_to_vlist(vlfree, vhead, ttol, base, &local,
annot_ip->ant.segments[segment], annot_ip->styles ?
&annot_ip->styles[segment] : NULL);
}
static int
annot_is_fill_compatibility_outline(const struct rt_ant *ant, size_t seg_no)
{
@@ -1635,6 +1691,489 @@ ant_to_vlist(struct bu_list *vlfree, struct bu_list *vhead, const struct bg_tess
}
static void
annot_mesh_free(struct annot_mesh *mesh)
{
if (!mesh)
return;
if (mesh->vertices)
bu_free(mesh->vertices, "annotation mesh vertices");
if (mesh->faces)
bu_free(mesh->faces, "annotation mesh faces");
if (mesh->thickness)
bu_free(mesh->thickness, "annotation mesh thickness");
memset(mesh, 0, sizeof(*mesh));
}
static int
annot_mesh_reserve_vertices(struct annot_mesh *mesh, size_t additional)
{
size_t capacity;
size_t required;
if (additional > SIZE_MAX - mesh->vertex_count)
return 1;
required = mesh->vertex_count + additional;
if (required <= mesh->vertex_capacity)
return 0;
capacity = mesh->vertex_capacity ? mesh->vertex_capacity : 64;
while (capacity < required) {
if (capacity > SIZE_MAX / 2) {
capacity = required;
break;
}
capacity *= 2;
}
if (capacity > SIZE_MAX / sizeof(point_t))
return 1;
mesh->vertices = (point_t *)bu_realloc(mesh->vertices,
capacity * sizeof(point_t), "annotation mesh vertices");
mesh->vertex_capacity = capacity;
return 0;
}
static int
annot_mesh_reserve_faces(struct annot_mesh *mesh, size_t additional)
{
size_t capacity;
size_t required;
if (additional > SIZE_MAX - mesh->face_count)
return 1;
required = mesh->face_count + additional;
if (required <= mesh->face_capacity)
return 0;
capacity = mesh->face_capacity ? mesh->face_capacity : 96;
while (capacity < required) {
if (capacity > SIZE_MAX / 2) {
capacity = required;
break;
}
capacity *= 2;
}
if (capacity > SIZE_MAX / (3 * sizeof(int)) ||
capacity > SIZE_MAX / sizeof(fastf_t))
return 1;
mesh->faces = (int *)bu_realloc(mesh->faces,
capacity * 3 * sizeof(int), "annotation mesh faces");
mesh->thickness = (fastf_t *)bu_realloc(mesh->thickness,
capacity * sizeof(fastf_t), "annotation mesh thickness");
mesh->face_capacity = capacity;
return 0;
}
static int
annot_mesh_add_triangle(struct annot_mesh *mesh, const point_t a,
const point_t b, const point_t c, const vect_t normal, fastf_t thickness,
const struct bn_tol *tol)
{
point_t ordered[3];
vect_t ab, ac, bc, face_normal;
size_t base;
if (VINVALID(a) || VINVALID(b) || VINVALID(c)) {
bu_log("annotation mesh contains a non-finite triangle\n");
return 1;
}
VSUB2(ab, b, a);
VSUB2(ac, c, a);
VSUB2(bc, c, b);
VCROSS(face_normal, ab, ac);
if (INVALID(MAGSQ(ab)) || INVALID(MAGSQ(ac)) || INVALID(MAGSQ(bc)) ||
INVALID(MAGSQ(face_normal))) {
bu_log("annotation mesh triangle exceeds the numeric range\n");
return 1;
}
if (MAGNITUDE(face_normal) <= tol->dist_sq)
return 0;
VMOVE(ordered[0], a);
if (VDOT(face_normal, normal) >= 0.0) {
VMOVE(ordered[1], b);
VMOVE(ordered[2], c);
} else {
VMOVE(ordered[1], c);
VMOVE(ordered[2], b);
}
if (!mesh || mesh->vertex_count > (size_t)INT_MAX - 3 ||
annot_mesh_reserve_vertices(mesh, 3) ||
annot_mesh_reserve_faces(mesh, 1))
return 1;
base = mesh->vertex_count;
VMOVE(mesh->vertices[base], ordered[0]);
VMOVE(mesh->vertices[base + 1], ordered[1]);
VMOVE(mesh->vertices[base + 2], ordered[2]);
mesh->vertex_count += 3;
mesh->faces[3 * mesh->face_count] = (int)base;
mesh->faces[3 * mesh->face_count + 1] = (int)base + 1;
mesh->faces[3 * mesh->face_count + 2] = (int)base + 2;
mesh->thickness[mesh->face_count++] = thickness;
return 0;
}
static int
annot_mesh_add_stroke_span(struct annot_mesh *mesh, const point_t start,
const point_t end, const vect_t normal, fastf_t width,
const struct bn_tol *tol)
{
point_t corners[4];
point_t first, last;
vect_t direction, side;
fastf_t half_width;
fastf_t length;
VSUB2(direction, end, start);
length = MAGNITUDE(direction);
if (INVALID(length))
return 1;
if (length <= tol->dist)
return 0;
VSCALE(direction, direction, 1.0 / length);
VCROSS(side, normal, direction);
if (VINVALID(side))
return 1;
if (MAGNITUDE(side) <= SMALL_FASTF)
return 0;
VUNITIZE(side);
half_width = 0.5 * width;
VJOIN1(first, start, -half_width, direction);
VJOIN1(last, end, half_width, direction);
VJOIN1(corners[0], first, -half_width, side);
VJOIN1(corners[1], last, -half_width, side);
VJOIN1(corners[2], last, half_width, side);
VJOIN1(corners[3], first, half_width, side);
if (annot_mesh_add_triangle(mesh, corners[0], corners[1], corners[2],
normal, width, tol))
return 1;
return annot_mesh_add_triangle(mesh, corners[0], corners[2], corners[3],
normal, width, tol);
}
static void
annot_line_pattern(uint32_t pattern, const fastf_t **intervals,
size_t *interval_count)
{
/* Entries alternate mark and gap lengths in stroke-width units. */
static const fastf_t dashed[] = {8.0, 4.0};
static const fastf_t dotted[] = {1.0, 3.0};
static const fastf_t center[] = {8.0, 3.0, 2.0, 3.0};
static const fastf_t phantom[] = {8.0, 3.0, 2.0, 3.0, 2.0, 3.0};
*intervals = NULL;
*interval_count = 0;
switch (pattern) {
case RT_ANNOT_LINE_DASHED:
*intervals = dashed;
*interval_count = sizeof(dashed) / sizeof(dashed[0]);
break;
case RT_ANNOT_LINE_DOTTED:
*intervals = dotted;
*interval_count = sizeof(dotted) / sizeof(dotted[0]);
break;
case RT_ANNOT_LINE_CENTER:
*intervals = center;
*interval_count = sizeof(center) / sizeof(center[0]);
break;
case RT_ANNOT_LINE_PHANTOM:
*intervals = phantom;
*interval_count = sizeof(phantom) / sizeof(phantom[0]);
break;
default:
break;
}
}
static int
annot_mesh_add_stroke(struct annot_mesh *mesh, const point_t start,
const point_t end, const vect_t normal, fastf_t width, uint32_t pattern,
fastf_t *path_distance, const struct bn_tol *tol)
{
const fastf_t *intervals;
size_t interval_count;
vect_t delta;
fastf_t length;
fastf_t period = 0.0;
fastf_t position = 0.0;
fastf_t phase;
size_t interval = 0;
size_t i;
VSUB2(delta, end, start);
length = MAGNITUDE(delta);
if (INVALID(length))
return 1;
if (length <= tol->dist)
return 0;
annot_line_pattern(pattern, &intervals, &interval_count);
if (!interval_count) {
*path_distance += length;
return annot_mesh_add_stroke_span(mesh, start, end, normal, width, tol);
}
for (i = 0; i < interval_count; ++i)
period += intervals[i] * width;
phase = fmod(*path_distance, period);
while (phase >= intervals[interval] * width) {
phase -= intervals[interval] * width;
interval = (interval + 1) % interval_count;
}
while (position < length) {
fastf_t available = intervals[interval] * width - phase;
fastf_t run = available < length - position ? available : length - position;
if (!(interval & 1) && run > tol->dist) {
point_t run_start, run_end;
VJOIN1(run_start, start, position / length, delta);
VJOIN1(run_end, start, (position + run) / length, delta);
if (annot_mesh_add_stroke_span(mesh, run_start, run_end, normal,
width, tol))
return 1;
}
position += run;
phase = 0.0;
interval = (interval + 1) % interval_count;
}
*path_distance += length;
return 0;
}
static fastf_t
annot_default_width(const struct rt_annot_internal *annot_ip,
const struct bn_tol *tol)
{
fastf_t largest_text = 0.0;
fastf_t local_width = 0.0;
fastf_t plane_scale;
point2d_t minimum, maximum;
vect_t normal;
size_t i;
for (i = 0; i < annot_ip->ant.count; ++i) {
if (annot_ip->ant.segments[i] &&
*(uint32_t *)annot_ip->ant.segments[i] == ANN_TSEG_MAGIC) {
const struct txt_seg *text =
(const struct txt_seg *)annot_ip->ant.segments[i];
if (text->txt_size > largest_text)
largest_text = text->txt_size;
}
}
if (largest_text > 0.0) {
local_width = largest_text * ANNOT_TEXT_STROKE_RATIO;
} else if (annot_ip->vert_count) {
V2MOVE(minimum, annot_ip->verts[0]);
V2MOVE(maximum, annot_ip->verts[0]);
for (i = 1; i < annot_ip->vert_count; ++i) {
V_MIN(minimum[X], annot_ip->verts[i][X]);
V_MIN(minimum[Y], annot_ip->verts[i][Y]);
V_MAX(maximum[X], annot_ip->verts[i][X]);
V_MAX(maximum[Y], annot_ip->verts[i][Y]);
}
local_width = hypot(maximum[X] - minimum[X],
maximum[Y] - minimum[Y]) * ANNOT_GEOMETRY_STROKE_RATIO;
}
VCROSS(normal, annot_ip->u_vec, annot_ip->v_vec);
plane_scale = sqrt(MAGNITUDE(normal));
local_width *= plane_scale;
if (local_width < ANNOT_MIN_WIDTH_TOL_FACTOR * tol->dist)
local_width = ANNOT_MIN_WIDTH_TOL_FACTOR * tol->dist;
return local_width;
}
static int
annot_segment_mesh(struct annot_mesh *mesh,
const struct rt_annot_internal *annot_ip, size_t segment,
const struct bg_tess_tol *ttol, const struct bn_tol *tol,
const vect_t normal, fastf_t base_width)
{
struct bu_list vhead;
struct bu_list vlfree;
struct bv_vlist *vp;
const struct rt_annot_seg_style *style = annot_ip->styles ?
&annot_ip->styles[segment] : NULL;
uint32_t magic = *(uint32_t *)annot_ip->ant.segments[segment];
uint32_t pattern = style ? style->line_pattern : RT_ANNOT_LINE_CONTINUOUS;
fastf_t width = base_width;
point_t line_start = VINIT_ZERO;
point_t polygon[3];
fastf_t path_distance = 0.0;
size_t polygon_count = 0;
int have_line_start = 0;
int ret = 0;
if (style && (style->flags & RT_ANNOT_STYLE_WIDTH))
width *= style->line_width;
else if (style && magic == ANN_TSEG_MAGIC &&
(style->flags & RT_ANNOT_STYLE_BOLD))
width *= 2.0;
if (!isfinite(width) || width <= 0.0)
return 1;
BU_LIST_INIT(&vhead);
BU_LIST_INIT(&vlfree);
ret = seg_to_vlist(&vlfree, &vhead, ttol,
(fastf_t *)annot_ip->V, (struct rt_annot_internal *)annot_ip,
annot_ip->ant.segments[segment], style);
if (ret)
goto cleanup;
for (BU_LIST_FOR(vp, bv_vlist, &vhead)) {
size_t i;
for (i = 0; i < vp->nused; ++i) {
switch (vp->cmd[i]) {
case BV_VLIST_LINE_MOVE:
VMOVE(line_start, vp->pt[i]);
have_line_start = 1;
path_distance = 0.0;
break;
case BV_VLIST_LINE_DRAW:
if (have_line_start && annot_mesh_add_stroke(mesh,
line_start, vp->pt[i], normal, width, pattern,
&path_distance, tol)) {
ret = 1;
goto cleanup;
}
VMOVE(line_start, vp->pt[i]);
have_line_start = 1;
break;
case BV_VLIST_POLY_MOVE:
case BV_VLIST_TRI_MOVE:
VMOVE(polygon[0], vp->pt[i]);
polygon_count = 1;
break;
case BV_VLIST_POLY_DRAW:
case BV_VLIST_TRI_DRAW:
if (polygon_count < 3) {
VMOVE(polygon[polygon_count], vp->pt[i]);
polygon_count++;
}
break;
case BV_VLIST_POLY_END:
case BV_VLIST_TRI_END:
if (polygon_count == 3 && annot_mesh_add_triangle(mesh,
polygon[0], polygon[1], polygon[2], normal,
base_width, tol)) {
ret = 1;
goto cleanup;
}
polygon_count = 0;
break;
default:
break;
}
}
}
cleanup:
BV_FREE_VLIST(&vlfree, &vhead);
bv_vlist_cleanup(&vlfree);
return ret;
}
static int
annot_to_bot(struct rt_bot_internal **result,
const struct rt_annot_internal *annot_ip,
const struct bg_tess_tol *ttol, const struct bn_tol *tol,
unsigned char bot_mode)
{
struct annot_mesh mesh = {0};
struct rt_bot_internal *bot;
vect_t normal;
fastf_t base_width;
size_t i;
if (!result)
return 1;
*result = NULL;
if (!annot_ip || !ttol || !tol ||
(bot_mode != RT_BOT_PLATE && bot_mode != RT_BOT_SURFACE) ||
!(annot_ip->flags & RT_ANNOT_MODEL_SPACE))
return 1;
VCROSS(normal, annot_ip->u_vec, annot_ip->v_vec);
if (VINVALID(normal) || MAGNITUDE(normal) <= SMALL_FASTF)
return 1;
VUNITIZE(normal);
base_width = annot_default_width(annot_ip, tol);
if (!isfinite(base_width) || base_width <= 0.0)
return 1;
for (i = 0; i < annot_ip->ant.count; ++i) {
if (!annot_ip->ant.segments[i] ||
annot_is_fill_compatibility_outline(&annot_ip->ant, i))
continue;
if (annot_segment_mesh(&mesh, annot_ip, i, ttol, tol, normal,
base_width)) {
annot_mesh_free(&mesh);
return 1;
}
}
if (!mesh.vertex_count || !mesh.face_count) {
annot_mesh_free(&mesh);
return 1;
}
BU_ALLOC(bot, struct rt_bot_internal);
bot->magic = RT_BOT_INTERNAL_MAGIC;
bot->mode = bot_mode;
bot->orientation = RT_BOT_UNORIENTED;
bot->num_vertices = mesh.vertex_count;
bot->vertices = (fastf_t *)mesh.vertices;
bot->num_faces = mesh.face_count;
bot->faces = mesh.faces;
if (bot_mode == RT_BOT_PLATE)
bot->thickness = mesh.thickness;
else
bu_free(mesh.thickness, "annotation mesh thickness");
mesh.vertices = NULL;
mesh.faces = NULL;
mesh.thickness = NULL;
*result = bot;
return 0;
}
C_DECL int
rt_annot_tess(struct nmgregion **r, struct model *m,
struct rt_db_internal *ip, const struct bg_tess_tol *ttol,
const struct bn_tol *tol)
{
struct rt_bot_internal *bot = NULL;
struct rt_db_internal bot_intern;
const struct rt_annot_internal *annot_ip;
int ret;
if (!r || !m || !ip || !ttol || !tol)
return -1;
RT_CK_DB_INTERNAL(ip);
annot_ip = (const struct rt_annot_internal *)ip->idb_ptr;
if (rt_annot_validate(annot_ip, NULL) ||
annot_to_bot(&bot, annot_ip, ttol, tol, RT_BOT_SURFACE))
return -1;
RT_DB_INTERNAL_INIT(&bot_intern);
bot_intern.idb_major_type = DB5_MAJORTYPE_BRLCAD;
bot_intern.idb_type = ID_BOT;
bot_intern.idb_meth = &OBJ[ID_BOT];
bot_intern.idb_ptr = bot;
ret = rt_bot_tess(r, m, &bot_intern, ttol, tol);
rt_bot_ifree(&bot_intern);
return ret;
}
C_DECL int
rt_annot_plot(struct bu_list *vhead, struct rt_db_internal *ip, const struct bg_tess_tol *ttol, const struct bn_tol *UNUSED(tol), const struct bview *UNUSED(info))
{
@@ -3527,11 +4066,11 @@ rt_annot_adjust(struct bu_vls *logstr, struct rt_db_internal *intern, int argc,
fastf_t *new_vert;
vert_no = atol(argv[0] + 1);
if (vert_no < 0 || (size_t)vert_no >= annot_ip->vert_count) {
new_vert = annot_ip->verts[vert_no];
if (vert_no < 0 || (size_t)vert_no > annot_ip->vert_count) {
bu_vls_printf(logstr, "ERROR: Illegal vertex number\n");
return BRLCAD_ERROR;
}
new_vert = annot_ip->verts[vert_no];
array_len = 2;
if (_rt_tcl_list_to_fastf_array(argv[1], &new_vert, &array_len) != array_len) {
bu_vls_printf(logstr, "ERROR: Incorrect number of coordinates for vertex\n");
File diff suppressed because it is too large Load Diff
+138 -318
View File
@@ -19,14 +19,13 @@
#include "bu/malloc.h"
#include "bu/str.h"
#include "bv/vlist.h"
#include "nmg.h"
#include "raytrace.h"
#include "rt/geom.h"
#include "rt/primitives/annot.h"
#include "rt/primitives/datum.h"
#include "wdb.h"
enum { LAYER_TEST_MAX_SEGMENTS = 2 };
static void
check_vector(const char *name, const fastf_t *actual, const fastf_t *expected)
@@ -47,46 +46,79 @@ lookup(struct db_i *dbip, const char *name)
}
static void
write_layer_annotation(struct rt_wdb *wdbp, const char *name,
fastf_t anchor_x, uint32_t space, size_t segment_count,
const unsigned char colors[][4])
{
struct rt_annot_internal annot = {0};
point2d_t vertices[2];
struct line_seg lines[LAYER_TEST_MAX_SEGMENTS] = {{0}};
void *segments[LAYER_TEST_MAX_SEGMENTS] = {NULL, NULL};
int reverse[LAYER_TEST_MAX_SEGMENTS] = {0, 0};
struct rt_annot_seg_style styles[LAYER_TEST_MAX_SEGMENTS] = {{0}};
size_t i;
struct annot_ray_result {
fastf_t in_dist;
fastf_t out_dist;
fastf_t color[3];
int color_valid;
int partitions;
};
if (!wdbp || !name || !colors || segment_count < 1 ||
segment_count > LAYER_TEST_MAX_SEGMENTS)
bu_exit(1, "invalid ordered-layer test annotation\n");
annot.magic = RT_ANNOT_INTERNAL_MAGIC;
VSET(annot.V, anchor_x, 0.0, 0.0);
annot.flags = space;
VSET(annot.u_vec, 0.0, 1.0, 0.0);
VSET(annot.v_vec, 0.0, 0.0, 1.0);
annot.vert_count = 2;
annot.verts = vertices;
V2SET(vertices[0], -1.0, 0.0);
V2SET(vertices[1], 1.0, 0.0);
annot.ant.count = segment_count;
annot.ant.reverse = reverse;
annot.ant.segments = segments;
annot.styles = styles;
for (i = 0; i < segment_count; ++i) {
lines[i].magic = CURVE_LSEG_MAGIC;
lines[i].start = 0;
lines[i].end = 1;
segments[i] = &lines[i];
styles[i].flags = RT_ANNOT_STYLE_COLOR;
styles[i].line_pattern = RT_ANNOT_LINE_CONTINUOUS;
memcpy(styles[i].color, colors[i], sizeof(styles[i].color));
static int
annot_ray_hit(struct application *ap, struct partition *part_head,
struct seg *UNUSED(finished_segs))
{
struct annot_ray_result *result = (struct annot_ray_result *)ap->a_uptr;
struct partition *part;
for (part = part_head->pt_forw; part != part_head;
part = part->pt_forw) {
if (!result->partitions) {
result->in_dist = part->pt_inhit->hit_dist;
result->out_dist = part->pt_outhit->hit_dist;
result->color_valid = part->pt_regionp->reg_mater.ma_color_valid;
VMOVE(result->color, part->pt_regionp->reg_mater.ma_color);
}
result->partitions++;
}
if (rt_annot_validate(&annot, NULL) || mk_annot(wdbp, name, &annot) < 0)
bu_exit(1, "unable to write ordered-layer test annotation\n");
return result->partitions > 0;
}
static int
annot_ray_miss(struct application *UNUSED(ap))
{
return 0;
}
static void
check_annot_ray(struct db_i *dbip, const char *object,
const fastf_t *expected_color)
{
struct rt_i *rtip = rt_i_create(dbip);
struct resource resource = RT_RESOURCE_INIT_ZERO;
struct application ap;
struct annot_ray_result result = {0};
const fastf_t expected_thickness = 0.2;
int shot_result;
if (!rtip || rt_gettree(rtip, object))
bu_exit(1, "unable to prepare annotation raytrace object %s\n", object);
rt_prep(rtip);
rt_init_resource(&resource, 0, rtip);
RT_APPLICATION_INIT(&ap);
ap.a_rt_i = rtip;
ap.a_resource = &resource;
ap.a_hit = annot_ray_hit;
ap.a_miss = annot_ray_miss;
ap.a_uptr = &result;
VSET(ap.a_ray.r_pt, 0.0, -2.0, 0.03);
VSET(ap.a_ray.r_dir, 1.0, 0.0, 0.0);
shot_result = rt_shootray(&ap);
if (shot_result != 1 || result.partitions != 1 ||
!result.color_valid ||
!NEAR_EQUAL(result.out_dist - result.in_dist,
expected_thickness, rtip->rti_tol.dist) ||
!VNEAR_EQUAL(result.color, expected_color, VUNITIZE_TOL)) {
bu_log("%s: shot=%d partitions=%d LOS=%g color-valid=%d color=%g/%g/%g\n",
object, shot_result, result.partitions,
result.out_dist - result.in_dist, result.color_valid,
V3ARGS(result.color));
bu_exit(1, "annotation did not produce the expected colored partition\n");
}
rt_i_destroy(rtip);
}
@@ -225,78 +257,48 @@ main(int argc, char **argv)
annot.styles[10].role = RT_ANNOT_ROLE_MASK;
annot.styles[10].flags = RT_ANNOT_STYLE_FILLED;
annot.styles[10].symbol = (char *)"owned fill with hole";
{
const size_t segment_count = annot.ant.count;
annot.ant.count = 1;
annot.styles[0].line_pattern = RT_ANNOT_LINE_CONTINUOUS;
annot.styles[0].line_width = 1.0;
if (rt_annot_validate(&annot, NULL) ||
mk_annot(wdbp, "thin.annot", &annot) < 0)
bu_exit(1, "unable to write default-width annotation\n");
annot.styles[0].line_width = 2.5;
if (rt_annot_validate(&annot, NULL) ||
mk_annot(wdbp, "wide.annot", &annot) < 0)
bu_exit(1, "unable to write wide annotation\n");
annot.ant.count = segment_count;
annot.styles[0].line_pattern = RT_ANNOT_LINE_DASHED;
}
if (rt_annot_validate(&annot, NULL) ||
mk_annot(wdbp, "leader.annot", &annot) < 0)
bu_exit(1, "unable to write enhanced annotation\n");
{
struct wmember members;
mat_t member_transform = MAT_INIT_IDN;
unsigned char inherited_color[3] = {90, 80, 70};
BU_LIST_INIT(&members.l);
MAT_DELTAS(member_transform, 100.0, 0.0, 0.0);
if (!mk_addmember("leader.annot", &members.l, member_transform,
WMOP_UNION) ||
mk_lcomb(wdbp, "annotation-group", &members, 0, NULL, NULL,
inherited_color, 0))
bu_exit(1, "unable to write annotation instance combination\n");
}
{
struct wmember members;
unsigned char inherited_color[3] = {21, 31, 41};
BU_LIST_INIT(&members.l);
if (!mk_addmember("annotation-group", &members.l, NULL, WMOP_UNION) ||
mk_lcomb(wdbp, "inherited-annotation-group", &members, 0,
NULL, NULL, inherited_color, 1))
bu_exit(1, "unable to write inherited annotation combination\n");
}
{
struct wmember members;
mat_t member_transform = MAT_INIT_IDN;
BU_LIST_INIT(&members.l);
MAT_SCALE_ALL(member_transform, 1000.0);
if (!mk_addmember("leader.annot", &members.l, member_transform,
WMOP_UNION) ||
mk_lcomb(wdbp, "scaled-annotation-group", &members, 0, NULL,
NULL, NULL, 0))
bu_exit(1, "unable to write scaled annotation instance combination\n");
}
{
point_t saved_anchor;
VMOVE(saved_anchor, annot.V);
VSETALL(annot.V, 0.0);
annot.flags = RT_ANNOT_SCREEN_SPACE;
if (mk_annot(wdbp, "screen.annot", &annot) < 0)
bu_exit(1, "unable to write screen annotation\n");
VMOVE(annot.V, saved_anchor);
annot.flags = RT_ANNOT_MODEL_SPACE;
}
{
const unsigned char far_color[][4] = {{0, 0, 255, 128}};
const unsigned char near_colors[][4] = {
{255, 0, 0, 128}, {0, 255, 0, 128}
};
const unsigned char screen_color[][4] = {{255, 255, 255, 128}};
write_layer_annotation(wdbp, "alpha-far.annot", 20.0,
RT_ANNOT_MODEL_SPACE, 1, far_color);
write_layer_annotation(wdbp, "alpha-near.annot", 10.0,
RT_ANNOT_MODEL_SPACE, 2, near_colors);
write_layer_annotation(wdbp, "alpha-screen.annot", 0.0,
RT_ANNOT_SCREEN_SPACE, 1, screen_color);
struct rt_annot_internal ray_annot = {0};
point2d_t ray_vertices[2];
struct line_seg ray_line = {0};
void *ray_segments[1];
int ray_reverse[1] = {0};
struct rt_annot_seg_style ray_style[1] = {{0}};
struct wmember member;
unsigned char region_color[3] = {90, 80, 70};
ray_annot.magic = RT_ANNOT_INTERNAL_MAGIC;
VSET(ray_annot.V, 10.0, 0.0, 0.0);
ray_annot.flags = RT_ANNOT_MODEL_SPACE;
VSET(ray_annot.u_vec, 0.0, 1.0, 0.0);
VSET(ray_annot.v_vec, 0.0, 0.0, 1.0);
ray_annot.vert_count = 2;
ray_annot.verts = ray_vertices;
V2SET(ray_vertices[0], -5.0, 0.0);
V2SET(ray_vertices[1], 5.0, 0.0);
ray_line.magic = CURVE_LSEG_MAGIC;
ray_line.start = 0;
ray_line.end = 1;
ray_segments[0] = &ray_line;
ray_annot.ant.count = 1;
ray_annot.ant.reverse = ray_reverse;
ray_annot.ant.segments = ray_segments;
ray_style[0].flags = RT_ANNOT_STYLE_WIDTH;
ray_style[0].line_pattern = RT_ANNOT_LINE_CONTINUOUS;
ray_style[0].line_width = 2.0;
ray_annot.styles = ray_style;
if (rt_annot_validate(&ray_annot, NULL) ||
mk_annot(wdbp, "ray.annot", &ray_annot) < 0)
bu_exit(1, "unable to write raytrace annotation\n");
BU_LIST_INIT(&member.l);
if (!mk_addmember("ray.annot", &member.l, NULL, WMOP_UNION) ||
mk_lcomb(wdbp, "ray.r", &member, 1, NULL, NULL,
region_color, 0))
bu_exit(1, "unable to write raytrace annotation region\n");
}
/* ANP2 is deliberately appended after the main-branch ANT2 body. A
@@ -396,7 +398,12 @@ main(int argc, char **argv)
struct bu_list vhead;
struct bg_tess_tol ttol = BG_TESS_TOL_INIT_TOL;
struct bn_tol tol = BN_TOL_INIT_TOL;
if (!(loaded->flags & RT_ANNOT_MODEL_SPACE) || !loaded->styles ||
if (!loaded || !loaded->styles || !loaded->ant.segments ||
loaded->ant.count != 11 || !loaded->ant.segments[10])
bu_exit(1,
"enhanced annotation structure did not round trip\n");
if (!(loaded->flags & RT_ANNOT_MODEL_SPACE) ||
loaded->styles[0].role != RT_ANNOT_ROLE_CENTERMARK ||
loaded->styles[0].line_pattern != RT_ANNOT_LINE_DASHED ||
!loaded->styles[0].font ||
@@ -415,7 +422,6 @@ main(int argc, char **argv)
!NEAR_EQUAL(loaded->styles[1].xy_scale, 0.25, SMALL_FASTF) ||
!NEAR_EQUAL(loaded->styles[1].yx_scale, 0.1, SMALL_FASTF) ||
!NEAR_EQUAL(loaded->styles[1].y_scale, 0.75, SMALL_FASTF) ||
loaded->ant.count != 11 ||
*(uint32_t *)loaded->ant.segments[10] != ANN_FSEG_MAGIC ||
loaded->styles[10].role != RT_ANNOT_ROLE_MASK ||
!loaded->styles[10].symbol ||
@@ -467,222 +473,36 @@ main(int argc, char **argv)
}
check_vector("annotation plot anchor", loaded->V, original_anchor);
BV_FREE_VLIST(&rt_vlfree, &vhead);
{
struct model *model = nmg_mm();
struct nmgregion *region = NULL;
if (rt_obj_tess(&region, model, &intern, &ttol, &tol) || !region)
bu_exit(1, "unable to tessellate model-space annotation\n");
nmg_km(model);
}
}
rt_db_free_internal(&intern);
{
const char *paths[] = {"leader.annot"};
struct bg_tess_tol ttol = BG_TESS_TOL_INIT_TOL;
struct bn_tol tol = BN_TOL_INIT_TOL;
struct rt_annot_scene *scene = rt_annot_scene_create(dbip, 1, paths,
&ttol, &tol);
struct xray ray;
struct rt_annot_hit hit = {0};
struct rt_annot_hit all_hit = {0};
point_t render_min, render_max, width_sample;
const fastf_t line_offset = 0.12;
const fastf_t inverse_line_length = 1.0 / sqrt(41.0);
const fastf_t offset_x = 2.0 - 5.0 * line_offset * inverse_line_length;
const fastf_t offset_y = 2.5 + 4.0 * line_offset * inverse_line_length;
VSET(ray.r_pt, 0.0, 24.0, 37.5);
VSET(ray.r_dir, 1.0, 0.0, 0.0);
if (!scene || rt_annot_scene_count(scene) != 1)
bu_exit(1, "annotation render scene did not collect its leaf\n");
if (!rt_annot_scene_bounds(scene, render_min, render_max) ||
!NEAR_EQUAL(render_min[X], 10.0, SMALL_FASTF) ||
!NEAR_EQUAL(render_max[X], 10.0, SMALL_FASTF) ||
render_min[Y] >= render_max[Y] ||
render_min[Z] >= render_max[Z])
bu_exit(1, "annotation render scene bounds are invalid\n");
if (!rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
INFINITY, &hit) || hit.screen_space || !hit.visible ||
!NEAR_EQUAL(hit.distance, 10.0, SMALL_FASTF) ||
hit.color[0] != 12 || hit.color[1] != 34 || hit.color[2] != 56)
bu_exit(1, "model annotation coverage query failed\n");
if (rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0, 5.0, &hit))
bu_exit(1, "occluded annotation was returned as visible\n");
if (!rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
9.99975, &hit))
bu_exit(1, "annotation visibility ignored model tolerance\n");
if (rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
9.999, &hit))
bu_exit(1, "annotation visibility exceeded model tolerance\n");
if (rt_annot_scene_query_model(scene, &ray, 5.0, &all_hit, 1) != 1 ||
all_hit.visible)
bu_exit(1, "annotation diagnostic query lost occluded coverage\n");
VSET(ray.r_pt, 0.0, 12.0, 18.0);
if (!rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
INFINITY, &hit) || hit.segment != 10)
bu_exit(1, "filled annotation coverage was not returned\n");
VSET(ray.r_pt, 0.0, 17.0, 25.5);
if (rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
INFINITY, &hit))
bu_exit(1, "annotation fill hole unexpectedly reported coverage\n");
rt_annot_scene_destroy(scene);
VSET(width_sample, 0.0, 20.0 + 2.0 * offset_x,
30.0 + 3.0 * offset_y);
paths[0] = "wide.annot";
scene = rt_annot_scene_create(dbip, 1, paths, &ttol, &tol);
VMOVE(ray.r_pt, width_sample);
if (!scene || !rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
INFINITY, &hit) || hit.segment != 0)
bu_exit(1, "annotation line width did not expand ray coverage\n");
rt_annot_scene_destroy(scene);
paths[0] = "thin.annot";
scene = rt_annot_scene_create(dbip, 1, paths, &ttol, &tol);
VMOVE(ray.r_pt, width_sample);
if (!scene || rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
INFINITY, &hit))
bu_exit(1, "default line width unexpectedly covered wide sample\n");
rt_annot_scene_destroy(scene);
}
{
const char *paths[] = {"scaled-annotation-group"};
struct bg_tess_tol ttol = BG_TESS_TOL_INIT_TOL;
struct bn_tol tol = BN_TOL_INIT_TOL;
struct rt_annot_scene *scene = rt_annot_scene_create(dbip, 1, paths,
&ttol, &tol);
struct xray ray;
struct rt_annot_hit hit = {0};
VSET(ray.r_pt, 0.0, 0.028, 0.045);
VSET(ray.r_dir, 1.0, 0.0, 0.0);
if (!scene || rt_annot_scene_count(scene) != 1 ||
!rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
INFINITY, &hit) ||
!NEAR_EQUAL(hit.distance, 0.01, SMALL_FASTF))
bu_exit(1, "scaled annotation instance coverage failed\n");
rt_annot_scene_destroy(scene);
}
{
const char *paths[] = {"annotation-group"};
struct bg_tess_tol ttol = BG_TESS_TOL_INIT_TOL;
struct bn_tol tol = BN_TOL_INIT_TOL;
struct rt_annot_scene *scene = rt_annot_scene_create(dbip, 1, paths,
&ttol, &tol);
struct xray ray;
struct rt_annot_hit hit = {0};
VSET(ray.r_pt, 0.0, 28.0, 45.0);
VSET(ray.r_dir, 1.0, 0.0, 0.0);
if (!scene || rt_annot_scene_count(scene) != 1 ||
!rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
INFINITY, &hit) ||
!NEAR_EQUAL(hit.distance, 110.0, SMALL_FASTF) ||
hit.segment != 10 || hit.color[0] != 90 ||
hit.color[1] != 80 || hit.color[2] != 70)
bu_exit(1, "annotation instance transform was not applied\n");
VSET(ray.r_pt, 0.0, 24.0, 37.5);
if (!rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
INFINITY, &hit) || hit.segment != 0 || hit.color[0] != 12 ||
hit.color[1] != 34 || hit.color[2] != 56)
bu_exit(1, "annotation segment color did not override inherited color\n");
rt_annot_scene_destroy(scene);
}
{
const char *paths[] = {"inherited-annotation-group"};
struct bg_tess_tol ttol = BG_TESS_TOL_INIT_TOL;
struct bn_tol tol = BN_TOL_INIT_TOL;
struct rt_annot_scene *scene = rt_annot_scene_create(dbip, 1, paths,
&ttol, &tol);
struct xray ray;
struct rt_annot_hit hit = {0};
VSET(ray.r_pt, 0.0, 28.0, 45.0);
VSET(ray.r_dir, 1.0, 0.0, 0.0);
if (!scene || !rt_annot_scene_query(scene, NULL, &ray, 0.0, 0.0,
INFINITY, &hit) || hit.segment != 10 || hit.color[0] != 21 ||
hit.color[1] != 31 || hit.color[2] != 41)
bu_exit(1, "annotation color did not follow tree inheritance\n");
rt_annot_scene_destroy(scene);
}
{
const char *paths[] = {"screen.annot"};
struct bg_tess_tol ttol = BG_TESS_TOL_INIT_TOL;
struct bn_tol tol = BN_TOL_INIT_TOL;
struct rt_annot_scene *scene = rt_annot_scene_create(dbip, 1, paths,
&ttol, &tol);
struct rt_annot_view view = {MAT_INIT_IDN, 100, 100, 0.0};
struct xray ray;
struct rt_annot_hit hit = {0};
VSET(ray.r_pt, 0.0, 0.0, 10.0);
VSET(ray.r_dir, 0.0, 0.0, -1.0);
if (!scene || !rt_annot_scene_query(scene, &view, &ray, 50.0, 50.0,
0.0, &hit) || !hit.screen_space || !hit.visible)
bu_exit(1, "screen annotation coverage query failed\n");
rt_annot_scene_destroy(scene);
}
{
const char *paths[] = {
"alpha-far.annot", "alpha-near.annot", "alpha-screen.annot"
const fastf_t default_color[3] = {1.0, 1.0, 1.0};
const fastf_t annotation_color[3] = {
12.0 / 255.0, 34.0 / 255.0, 56.0 / 255.0
};
struct bg_tess_tol ttol = BG_TESS_TOL_INIT_TOL;
struct bn_tol tol = BN_TOL_INIT_TOL;
struct rt_annot_scene *scene = rt_annot_scene_create(dbip, 3, paths,
&ttol, &tol);
struct rt_annot_view view = {MAT_INIT_IDN, 100, 100, 0.0};
struct rt_annot_hit layers[4] = {{0}};
struct rt_annot_hit diagnostic_hits[2] = {{0}};
struct rt_annot_hit top = {0};
struct xray ray;
size_t layer_count;
fastf_t color[3] = {0.0, 0.0, 0.0};
const fastf_t alpha = 128.0 / 255.0;
const fastf_t remainder = 1.0 - alpha;
const fastf_t expected_color[3] = {
alpha + remainder * remainder * alpha,
alpha + remainder * alpha,
alpha + remainder * remainder * remainder * alpha
const fastf_t region_color[3] = {
90.0 / 255.0, 80.0 / 255.0, 70.0 / 255.0
};
VSET(ray.r_pt, 0.0, 0.0, 0.0);
VSET(ray.r_dir, 1.0, 0.0, 0.0);
layer_count = rt_annot_scene_query_layers(scene, &view, &ray,
50.0, 50.0, INFINITY, layers, 2);
if (!scene || layer_count != 4 ||
bu_strcmp(layers[0].path, "/alpha-far.annot") ||
bu_strcmp(layers[1].path, "/alpha-near.annot") ||
layers[1].segment != 0)
bu_exit(1, "annotation layer count or capacity handling failed: "
"count=%zu first=%s second=%s/%zu\n", layer_count,
layers[0].path ? layers[0].path : "(null)",
layers[1].path ? layers[1].path : "(null)", layers[1].segment);
if (rt_annot_scene_query_layers(scene, &view, &ray, 50.0, 50.0,
INFINITY, layers, 4) != 4 ||
!NEAR_EQUAL(layers[0].distance, 20.0, SMALL_FASTF) ||
!NEAR_EQUAL(layers[1].distance, 10.0, SMALL_FASTF) ||
layers[1].segment != 0 ||
layers[2].segment != 1 || !layers[3].screen_space)
bu_exit(1, "annotation layers are not back-to-front\n");
if (!rt_annot_scene_query(scene, &view, &ray, 50.0, 50.0,
INFINITY, &top) || !top.screen_space ||
bu_strcmp(top.path, "/alpha-screen.annot"))
bu_exit(1, "annotation top-layer compatibility query changed\n");
if (rt_annot_scene_query_layers(scene, &view, &ray, 50.0, 50.0,
15.0, NULL, 0) != 3)
bu_exit(1, "annotation layer visibility filtering failed\n");
if (rt_annot_scene_query_model(scene, &ray, INFINITY,
diagnostic_hits, 2) != 2 ||
bu_strcmp(diagnostic_hits[0].path, "/alpha-near.annot") ||
diagnostic_hits[0].segment != 1 ||
bu_strcmp(diagnostic_hits[1].path, "/alpha-far.annot"))
bu_exit(1, "annotation diagnostic hits changed layer semantics\n");
if (!rt_annot_scene_composite(scene, &view, &ray, 50.0, 50.0,
INFINITY, color, &top) ||
!VNEAR_EQUAL(color, expected_color, SMALL_FASTF) ||
!top.screen_space)
bu_exit(1, "annotation alpha compositing order failed\n");
MAT_DELTAS(view.model2view, 0.0, 0.0, -2.0);
view.width = 160;
view.height = 90;
view.perspective = 60.0;
if (rt_annot_scene_query_layers(scene, &view, &ray, 80.0, 45.0,
INFINITY, NULL, 0) != 4)
bu_exit(1, "perspective screen annotation coverage failed\n");
rt_annot_scene_destroy(scene);
/* m35.g has this broad table entry, which includes the synthetic ID 0
* assigned to bare solids. It must not replace annotation colors. */
db_mater_add(dbip, 0, 15000, 210, 146, 1, MATER_NO_ADDR);
check_annot_ray(dbip, "ray.annot", default_color);
if (db5_update_attribute("ray.annot", "rgb", "12/34/56", dbip))
bu_exit(1, "unable to set annotation raytrace color\n");
check_annot_ray(dbip, "ray.annot", annotation_color);
check_annot_ray(dbip, "ray.r", region_color);
}
dp = lookup(dbip, "leader.annot");
MAT_DELTAS(transform, -5.0, 6.0, 7.0);
RT_DB_INTERNAL_INIT(&intern);
if (rt_db_get_internal(&intern, dp, dbip, transform) != ID_ANNOT)
+180 -234
View File
@@ -49,6 +49,7 @@
#include "bu/path.h"
#include "bu/process.h"
#include "bu/units.h"
#include "bu/binding.h"
#include "vmath.h"
#include "rt/db4.h"
#include "rt/geom.h"
@@ -2824,6 +2825,148 @@ to_data_vZ(struct ged *gedp,
}
static void tclcad_action_eval_aet(const struct bu_vls *ev, void *reg, void *event_data) {
struct bview *gdvp = (struct bview *)event_data;
const char *aet_args = (const char *)reg;
struct bu_vls cmd = BU_VLS_INIT_ZERO;
bu_vls_printf(&cmd, "%s aet %s %s", bu_vls_cstr(&current_top->to_gedp->go_name), bu_vls_cstr(&gdvp->gv_name), aet_args);
Tcl_Eval(current_top->to_interp, bu_vls_cstr(&cmd));
bu_vls_free(&cmd);
}
static void tclcad_action_mouse_drag(const struct bu_vls *ev, void *reg, void *event_data) {
struct bview *gdvp = (struct bview *)event_data;
const char *cmd_name = (const char *)reg;
int cx = gdvp->gv_prevMouseX;
int cy = gdvp->gv_prevMouseY;
char *p;
if ((p = strstr(bu_vls_cstr(ev), "\"cx\":"))) sscanf(p + 5, "%d", &cx);
if ((p = strstr(bu_vls_cstr(ev), "\"cy\":"))) sscanf(p + 5, "%d", &cy);
struct bu_vls cmd = BU_VLS_INIT_ZERO;
bu_vls_printf(&cmd, "%s %s %s %d %d", bu_vls_cstr(&current_top->to_gedp->go_name), cmd_name, bu_vls_cstr(&gdvp->gv_name), cx, cy);
Tcl_Eval(current_top->to_interp, bu_vls_cstr(&cmd));
bu_vls_free(&cmd);
}
static void tclcad_action_wheel_scale(const struct bu_vls *ev, void *reg, void *event_data) {
struct bview *gdvp = (struct bview *)event_data;
int delta = 0;
char *p;
if ((p = strstr(bu_vls_cstr(ev), "\"delta\":"))) sscanf(p + 8, "%d", &delta);
const char *sf = (delta > 0) ? "1.1" : "0.9";
struct bu_vls cmd = BU_VLS_INIT_ZERO;
bu_vls_printf(&cmd, "%s zoom %s %s", bu_vls_cstr(&current_top->to_gedp->go_name), bu_vls_cstr(&gdvp->gv_name), sf);
Tcl_Eval(current_top->to_interp, bu_vls_cstr(&cmd));
bu_vls_free(&cmd);
}
static void tclcad_action_mouse_click(const struct bu_vls *ev, void *reg, void *event_data) {
struct bview *gdvp = (struct bview *)event_data;
const char *cmd_format = (const char *)reg;
int cx = gdvp->gv_prevMouseX;
int cy = gdvp->gv_prevMouseY;
char *p;
if ((p = strstr(bu_vls_cstr(ev), "\"cx\":"))) sscanf(p + 5, "%d", &cx);
if ((p = strstr(bu_vls_cstr(ev), "\"cy\":"))) sscanf(p + 5, "%d", &cy);
struct bu_vls cmd = BU_VLS_INIT_ZERO;
bu_vls_printf(&cmd, cmd_format, bu_vls_cstr(&current_top->to_gedp->go_name), bu_vls_cstr(&gdvp->gv_name), cx, cy);
Tcl_Eval(current_top->to_interp, bu_vls_cstr(&cmd));
bu_vls_free(&cmd);
}
static int bindings_loaded_mged = 0;
static int tclcad_load_bindings_cmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]) {
if (argc < 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " <json_path>\"", NULL);
return TCL_ERROR;
}
char *path = (char *)bu_dir(NULL, 0, BU_DIR_DATA, argv[1], NULL);
if (!path) {
Tcl_AppendResult(interp, "Failed to resolve path: ", argv[1], NULL);
return TCL_ERROR;
}
if (bu_binding_load(path) < 0) {
bu_free(path, "path");
Tcl_AppendResult(interp, "Failed to load bindings from: ", argv[1], NULL);
return TCL_ERROR;
}
bu_free(path, "path");
/* Validate that application provided required bindings */
if (!bu_binding_action_is_bound("dm", "view_mouse_drag_rotate") ||
!bu_binding_action_is_bound("dm", "view_mouse_drag_translate") ||
!bu_binding_action_is_bound("dm", "view_mouse_drag_scale")) {
Tcl_AppendResult(interp, "Validation Failed: The provided bindings do not map inputs for view_mouse_drag_rotate/translate/scale. These are required standard actions.", NULL);
return TCL_ERROR;
}
return TCL_OK;
}
static int tclcad_dispatch_event_cmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]) {
if (argc < 8) return TCL_OK;
struct tclcad_obj *to = (struct tclcad_obj *)clientData;
struct bview *gdvp = bv_set_find_view(&to->to_gedp->ged_views, argv[2]);
if (!gdvp) return TCL_OK;
int x = atoi(argv[5]);
int y = atoi(argv[6]);
int state = atoi(argv[7]);
struct bu_vls ev = BU_VLS_INIT_ZERO;
bu_vls_printf(&ev, "{\"type\": \"%s\"", argv[3]);
if (!strcmp(argv[3], "key-press")) {
char key_str[16] = {0};
bu_strlcpy(key_str, argv[4], sizeof(key_str));
if (strlen(key_str) == 1 && key_str[0] >= 'a' && key_str[0] <= 'z') {
key_str[0] = key_str[0] - 'a' + 'A';
}
bu_vls_printf(&ev, ", \"key\": \"%s\"", key_str);
} else if (!strcmp(argv[3], "mouse-wheel")) {
int delta = (argc > 8) ? atoi(argv[8]) : 0;
int mdelta = -1 * delta / 120;
bu_vls_printf(&ev, ", \"delta\": %d", mdelta);
} else {
int btn = atoi(argv[4]) - 1;
if (!strcmp(argv[3], "mouse-move")) {
if (state & 0x100) btn = 0;
else if (state & 0x200) btn = 1;
else if (state & 0x400) btn = 2;
else btn = -1;
int dx = x - gdvp->gv_prevMouseX;
int dy = y - gdvp->gv_prevMouseY;
bu_vls_printf(&ev, ", \"dx\": %d, \"dy\": %d, \"mode\": 0", dx, dy);
}
if (btn >= 0) bu_vls_printf(&ev, ", \"button\": %d", btn);
bu_vls_printf(&ev, ", \"cx\": %d, \"cy\": %d", x, y);
}
if (state & (1 | 4 | 8)) {
bu_vls_printf(&ev, ", \"modifiers\": [");
int added = 0;
if (state & 1) { bu_vls_printf(&ev, "\"Shift\""); added=1; }
if (state & 4) { if(added) bu_vls_printf(&ev, ", "); bu_vls_printf(&ev, "\"Control\""); added=1; }
if (state & 8) { if(added) bu_vls_printf(&ev, ", "); bu_vls_printf(&ev, "\"Alt\""); }
bu_vls_printf(&ev, "]");
}
bu_vls_printf(&ev, "}");
bu_binding_process_event("dm", bu_vls_cstr(&ev), gdvp);
gdvp->gv_prevMouseX = x;
gdvp->gv_prevMouseY = y;
bu_vls_free(&ev);
return TCL_OK;
}
static void
to_init_default_bindings(struct bview *gdvp)
{
@@ -2832,6 +2975,35 @@ to_init_default_bindings(struct bview *gdvp)
if (dm_get_pathname((struct dm *)gdvp->dmp)) {
struct bu_vls *pathvls = dm_get_pathname((struct dm *)gdvp->dmp);
if (pathvls) {
if (!bindings_loaded_mged) {
bindings_loaded_mged = 1;
bu_binding_register_action("view_2", tclcad_action_eval_aet, (void*)"35 -25 0");
bu_binding_register_action("view_3", tclcad_action_eval_aet, (void*)"35 25 0");
bu_binding_register_action("view_4", tclcad_action_eval_aet, (void*)"45 45 0");
bu_binding_register_action("view_5", tclcad_action_eval_aet, (void*)"145 25 0");
bu_binding_register_action("view_6", tclcad_action_eval_aet, (void*)"215 25 0");
bu_binding_register_action("view_7", tclcad_action_eval_aet, (void*)"325 25 0");
bu_binding_register_action("view_front", tclcad_action_eval_aet, (void*)"0 0 0");
bu_binding_register_action("view_top", tclcad_action_eval_aet, (void*)"270 90 0");
bu_binding_register_action("view_bottom", tclcad_action_eval_aet, (void*)"270 -90 0");
bu_binding_register_action("view_left", tclcad_action_eval_aet, (void*)"90 0 0");
bu_binding_register_action("view_rear", tclcad_action_eval_aet, (void*)"180 0 0");
bu_binding_register_action("view_right", tclcad_action_eval_aet, (void*)"270 0 0");
bu_binding_register_action("view_mouse_drag_rotate", tclcad_action_mouse_drag, (void*)"mouse_rot");
bu_binding_register_action("view_mouse_drag_translate", tclcad_action_mouse_drag, (void*)"mouse_trans");
bu_binding_register_action("view_mouse_drag_scale", tclcad_action_mouse_drag, (void*)"mouse_scale");
bu_binding_register_action("view_mouse_wheel_scale", tclcad_action_wheel_scale, NULL);
bu_binding_register_action("view_mouse_press_left", tclcad_action_mouse_click, (void*)"%s zoom %s 0.5");
bu_binding_register_action("view_mouse_press_right", tclcad_action_mouse_click, (void*)"%s zoom %s 2.0");
Tcl_CreateCommand(current_top->to_interp, "tclcad_dispatch_event", tclcad_dispatch_event_cmd, (ClientData)current_top, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateCommand(current_top->to_interp, "tclcad_load_bindings", tclcad_load_bindings_cmd, (ClientData)current_top, (Tcl_CmdDeleteProc *)NULL);
}
bu_vls_printf(&bindings, "bind %s <Configure> {%s configure %s; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
@@ -2848,240 +3020,14 @@ to_init_default_bindings(struct bview *gdvp)
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
/* Mouse Bindings */
bu_vls_printf(&bindings, "bind %s <2> {%s vslew %s %%x %%y; focus %s; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name),
bu_vls_addr(pathvls));
bu_vls_printf(&bindings, "bind %s <1> {%s zoom %s 0.5; focus %s; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name),
bu_vls_addr(pathvls));
bu_vls_printf(&bindings, "bind %s <3> {%s zoom %s 2.0; focus %s; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name),
bu_vls_addr(pathvls));
bu_vls_printf(&bindings, "bind %s <4> {%s zoom %s 1.1; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <5> {%s zoom %s 0.9; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <MouseWheel> {if {%%D < 0} {%s zoom %s 0.9} else {%s zoom %s 1.1}; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
/* Idle Mode */
bu_vls_printf(&bindings, "bind %s <ButtonRelease> {%s idle_mode %s}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <KeyRelease-Control_L> {%s idle_mode %s}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <KeyRelease-Control_R> {%s idle_mode %s}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <KeyRelease-Shift_L> {%s idle_mode %s}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <KeyRelease-Shift_R> {%s idle_mode %s}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <KeyRelease-Alt_L> {%s idle_mode %s; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <KeyRelease-Alt_R> {%s idle_mode %s; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
/* Rotate Mode */
bu_vls_printf(&bindings, "bind %s <Control-ButtonRelease-1> {%s idle_mode %s}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Control-ButtonPress-1> {%s rotate_mode %s %%x %%y}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Control-ButtonPress-2> {%s rotate_mode %s %%x %%y}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Control-ButtonPress-3> {%s rotate_mode %s %%x %%y}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
/* Translate Mode */
bu_vls_printf(&bindings, "bind %s <Shift-ButtonRelease-1> {%s idle_mode %s}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Shift-ButtonPress-1> {%s translate_mode %s %%x %%y}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Shift-ButtonPress-2> {%s translate_mode %s %%x %%y}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Shift-ButtonPress-3> {%s translate_mode %s %%x %%y}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
/* Scale Mode */
bu_vls_printf(&bindings, "bind %s <Control-Shift-ButtonRelease-1> {%s idle_mode %s}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Control-Shift-ButtonPress-1> {%s scale_mode %s %%x %%y}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Control-Shift-ButtonPress-2> {%s scale_mode %s %%x %%y}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Control-Shift-ButtonPress-3> {%s scale_mode %s %%x %%y}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
/* Constrained Rotate Mode */
bu_vls_printf(&bindings, "bind %s <Control-Lock-ButtonRelease-1> {%s idle_mode %s}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Control-Lock-ButtonPress-1> {%s constrain_rmode %s x %%x %%y; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Control-Lock-ButtonPress-2> {%s constrain_rmode %s y %%x %%y; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Control-Lock-ButtonPress-3> {%s constrain_rmode %s z %%x %%y; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
/* Constrained Translate Mode */
bu_vls_printf(&bindings, "bind %s <Shift-Lock-ButtonRelease-1> {%s idle_mode %s; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Shift-Lock-ButtonPress-1> {%s constrain_tmode %s x %%x %%y; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Shift-Lock-ButtonPress-2> {%s constrain_tmode %s y %%x %%y; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Shift-Lock-ButtonPress-3> {%s constrain_tmode %s z %%x %%y; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
/* Key Bindings */
bu_vls_printf(&bindings, "bind %s 3 {%s aet %s 35 25; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s 4 {%s aet %s 45 45; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s f {%s aet %s 0 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s F {%s aet %s 0 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s R {%s aet %s 180 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s r {%s aet %s 270 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s l {%s aet %s 90 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s L {%s aet %s 90 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s t {%s aet %s 270 90; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s T {%s aet %s 270 90; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s b {%s aet %s 270 -90; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s B {%s aet %s 270 -90; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s + {%s zoom %s 2.0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s = {%s zoom %s 2.0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s _ {%s zoom %s 0.5; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s - {%s zoom %s 0.5; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Key-Left> {%s rot %s -v 0 1 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Key-Right> {%s rot %s -v 0 -1 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Key-Up> {%s rot %s -v 1 0 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Key-Down> {%s rot %s -v -1 0 0; break}; ",
bu_vls_addr(pathvls),
bu_vls_addr(&current_top->to_gedp->go_name),
bu_vls_addr(&gdvp->gv_name));
Tcl_Eval(current_top->to_interp, bu_vls_addr(&bindings));
/* Dispatch all events to bu_binding */
bu_vls_printf(&bindings, "bind %s <Any-KeyPress> {tclcad_dispatch_event %%W %s %s key-press %%K %%x %%y %%s; break}; ", bu_vls_addr(pathvls), bu_vls_addr(&current_top->to_gedp->go_name), bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Any-ButtonPress> {tclcad_dispatch_event %%W %s %s mouse-press %%b %%x %%y %%s; break}; ", bu_vls_addr(pathvls), bu_vls_addr(&current_top->to_gedp->go_name), bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Any-ButtonRelease> {tclcad_dispatch_event %%W %s %s mouse-release %%b %%x %%y %%s; break}; ", bu_vls_addr(pathvls), bu_vls_addr(&current_top->to_gedp->go_name), bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <Any-Motion> {tclcad_dispatch_event %%W %s %s mouse-move 0 %%x %%y %%s; break}; ", bu_vls_addr(pathvls), bu_vls_addr(&current_top->to_gedp->go_name), bu_vls_addr(&gdvp->gv_name));
bu_vls_printf(&bindings, "bind %s <MouseWheel> {tclcad_dispatch_event %%W %s %s mouse-wheel 0 %%x %%y %%s %%D; break}; ", bu_vls_addr(pathvls), bu_vls_addr(&current_top->to_gedp->go_name), bu_vls_addr(&gdvp->gv_name));
Tcl_Eval(current_top->to_interp, bu_vls_cstr(&bindings));
}
}
bu_vls_free(&bindings);
+1
View File
@@ -889,3 +889,4 @@ done:
// c-file-style: "stroustrup"
// End:
// ex: shiftwidth=4 tabstop=8
-1
View File
@@ -56,7 +56,6 @@ add_target_deps(rtscale dm_plugins)
brlcad_addexec(rt "${LIBRTUIF_SOURCES};view.c" "${OPENCL_LIBS};${RT_STD_LIBS}" FOLDER Rt)
target_include_directories(rt BEFORE PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
set_property(TARGET rt APPEND PROPERTY COMPILE_DEFINITIONS "RT_ANNOT_OVERLAY")
add_target_deps(rt dm_plugins dm-txt)
brlcad_addexec(rtarea "${LIBRTUIF_SOURCES};viewarea.c" "${RT_STD_LIBS}" FOLDER Rt)
+10 -211
View File
@@ -80,15 +80,6 @@ extern void worker(int cpu, void *arg);
extern struct icv_image *bif;
unsigned char *pixmap = NULL; /**< Pixel Map for rerendering of black pixels */
#ifdef RT_ANNOT_OVERLAY
static struct rt_annot_scene *annotation_scene = NULL;
static struct rt_annot_view annotation_view = {MAT_INIT_IDN, 0, 0, 0.0};
static struct db_i *annotation_dbip = DBI_NULL;
static struct bu_ptbl annotation_paths = BU_PTBL_INIT_ZERO;
static struct bg_tess_tol annotation_ttol = BG_TESS_TOL_INIT_ZERO;
static struct bn_tol annotation_tol = BN_TOL_INIT_ZERO;
static int annotation_cache_valid = 0;
#endif
enum view_command_flag {
VIEW_COMMAND_EYE_SET = 1u << 0,
@@ -329,9 +320,6 @@ int cm_end(const int UNUSED(argc), const char **UNUSED(argv))
return -1;
}
#ifdef RT_ANNOT_OVERLAY
rtuif_prepare_annotations(rtip);
#endif
do_view_finalize(azimuth, elevation);
if (do_frame(curframe) < 0)
@@ -484,9 +472,6 @@ int cm_multiview(const int UNUSED(argc), const char **UNUSED(argv))
if (rtip && BU_LIST_IS_EMPTY(&rtip->HeadRegion) && !def_tree(rtip, NULL)) {
return -1;
}
#ifdef RT_ANNOT_OVERLAY
rtuif_prepare_annotations(rtip);
#endif
for (i = 0; i < (sizeof(a)/sizeof(a[0])); i++) {
do_ae((double)a[i], (double)e[i]);
(void)do_frame(curframe++);
@@ -507,9 +492,6 @@ int cm_anim(const int argc, const char **argv)
bu_log("cm_anim: %s %s failed\n", argv[1], argv[2]);
return -1; /* BAD */
}
#ifdef RT_ANNOT_OVERLAY
rtuif_clear_annotations();
#endif
return 0;
}
@@ -905,19 +887,11 @@ validate_raytrace(struct rt_i *rtip)
bu_log("ERROR: No raytracing instance.\n");
return 1;
}
if (rtip->stats.nsolids <= 0
#ifdef RT_ANNOT_OVERLAY
&& (!annotation_scene || !rt_annot_scene_count(annotation_scene))
#endif
) {
if (rtip->stats.nsolids <= 0) {
bu_log("ERROR: No primitives remaining.\n");
return 2;
}
if (rtip->stats.nregions <= 0
#ifdef RT_ANNOT_OVERLAY
&& (!annotation_scene || !rt_annot_scene_count(annotation_scene))
#endif
) {
if (rtip->stats.nregions <= 0) {
bu_log("ERROR: No regions remaining.\n");
return 3;
}
@@ -926,152 +900,6 @@ validate_raytrace(struct rt_i *rtip)
}
#ifdef RT_ANNOT_OVERLAY
static void
annotation_cache_clear(void)
{
size_t i;
rt_annot_scene_destroy(annotation_scene);
annotation_scene = NULL;
if (BU_PTBL_TEST(&annotation_paths)) {
for (i = 0; i < BU_PTBL_LEN(&annotation_paths); ++i)
bu_free((char *)BU_PTBL_GET(&annotation_paths, i),
"cached annotation path");
bu_ptbl_free(&annotation_paths);
}
annotation_dbip = DBI_NULL;
annotation_cache_valid = 0;
}
static int
annotation_scalar_equal(double a, double b)
{
return a <= b && a >= b;
}
static int
annotation_tolerances_match(const struct rt_i *rtip)
{
const struct bg_tess_tol *ttol = &rtip->rti_ttol;
const struct bn_tol *tol = &rtip->rti_tol;
return annotation_ttol.magic == ttol->magic &&
annotation_scalar_equal(annotation_ttol.abs, ttol->abs) &&
annotation_scalar_equal(annotation_ttol.rel, ttol->rel) &&
annotation_scalar_equal(annotation_ttol.norm, ttol->norm) &&
annotation_scalar_equal(annotation_ttol.absmax, ttol->absmax) &&
annotation_scalar_equal(annotation_ttol.absmin, ttol->absmin) &&
annotation_scalar_equal(annotation_ttol.relmax, ttol->relmax) &&
annotation_scalar_equal(annotation_ttol.relmin, ttol->relmin) &&
annotation_scalar_equal(annotation_ttol.rel_lmax, ttol->rel_lmax) &&
annotation_scalar_equal(annotation_ttol.rel_lmin, ttol->rel_lmin) &&
annotation_tol.magic == tol->magic &&
annotation_scalar_equal(annotation_tol.dist, tol->dist) &&
annotation_scalar_equal(annotation_tol.dist_sq, tol->dist_sq) &&
annotation_scalar_equal(annotation_tol.perp, tol->perp) &&
annotation_scalar_equal(annotation_tol.para, tol->para);
}
static int
annotation_cache_matches(const struct rt_i *rtip, int path_count,
const char * const *paths)
{
int i;
if (!annotation_cache_valid || annotation_dbip != rtip->rti_dbip ||
path_count < 0 ||
(size_t)path_count != BU_PTBL_LEN(&annotation_paths) ||
!annotation_tolerances_match(rtip))
return 0;
for (i = 0; i < path_count; ++i)
if (!BU_STR_EQUAL((const char *)BU_PTBL_GET(&annotation_paths, i),
paths[i]))
return 0;
return 1;
}
static void
annotation_cache_store(const struct rt_i *rtip, int path_count,
const char * const *paths)
{
int i;
bu_ptbl_init(&annotation_paths, (size_t)path_count,
"cached annotation paths");
for (i = 0; i < path_count; ++i)
bu_ptbl_ins(&annotation_paths, (long *)bu_strdup(paths[i]));
annotation_dbip = rtip->rti_dbip;
annotation_ttol = rtip->rti_ttol;
annotation_tol = rtip->rti_tol;
annotation_cache_valid = 1;
}
const struct rt_annot_scene *
rtuif_annotations(void)
{
return annotation_scene;
}
const struct rt_annot_view *
rtuif_annotation_view(void)
{
return &annotation_view;
}
void
rtuif_clear_annotations(void)
{
annotation_cache_clear();
MAT_IDN(annotation_view.model2view);
annotation_view.width = 0;
annotation_view.height = 0;
annotation_view.perspective = 0.0;
}
size_t
rtuif_prepare_annotations(struct rt_i *rtip)
{
const char **treev = NULL;
int treec = 0;
size_t count;
if (!rtip) {
rtuif_clear_annotations();
return 0;
}
if (cmd_objs && BU_PTBL_LEN(cmd_objs)) {
treec = (int)BU_PTBL_LEN(cmd_objs);
treev = (const char **)cmd_objs->buffer;
} else if (!rtuif_tree_list(rtip, &treec, &treev, NULL)) {
rtuif_clear_annotations();
return 0;
}
if (!annotation_cache_matches(rtip, treec, treev)) {
annotation_cache_clear();
annotation_scene = rt_annot_scene_create(rtip->rti_dbip, treec, treev,
&rtip->rti_ttol, &rtip->rti_tol);
annotation_cache_store(rtip, treec, treev);
}
count = rt_annot_scene_count(annotation_scene);
if (opencl_mode && count) {
bu_log("rt: annotations require primary-sample compositing; using the CPU renderer\n");
opencl_mode = 0;
}
return count;
}
#endif
/**
* Do all the actual work to run a frame.
*
@@ -1096,10 +924,6 @@ do_frame(int framenumber)
/* Compute model RPP, etc. */
do_prep(rtip);
#ifdef RT_ANNOT_OVERLAY
rtuif_prepare_annotations(rtip);
#endif
if (rt_verbosity & VERBOSE_VIEWDETAIL)
bu_log("Tree: %zu solids in %zu regions\n", rtip->stats.nsolids, rtip->stats.nregions);
@@ -1134,13 +958,6 @@ do_frame(int framenumber)
bu_vls_free(&msg);
}
#ifdef RT_ANNOT_OVERLAY
MAT_COPY(annotation_view.model2view, model2view);
annotation_view.width = width;
annotation_view.height = height;
annotation_view.perspective = rt_perspective;
#endif
/* az/el 0, 0 is when screen +Z is model +X */
VSET(work, 0, 0, 1);
MAT3X3VEC(temp, view2model, work);
@@ -1589,32 +1406,22 @@ do_ae_internal(double azim, double elev, int center_eye)
{
struct rt_i *rtip = APP.a_rt_i;
point_t view_min, view_max;
#ifdef RT_ANNOT_OVERLAY
point_t annotation_min, annotation_max;
int have_annotation_bounds;
#endif
if (rtip == NULL)
return;
if (rtip->mdl_min[X] >= INFINITY || rtip->mdl_max[X] <= -INFINITY) {
if (rtip->mdl_max[X] >= INFINITY) {
bu_log("do_ae: infinite model bounds? setting a unit minimum\n");
VSETALL(rtip->mdl_min, -1);
}
if (rtip->mdl_max[X] <= -INFINITY) {
/* Model not yet loaded (librt initial state: mdl_min=+INF, mdl_max=-INF).
* Reset both bounds to a unit box so that autoviewsize() does not
* propagate +INFINITY through mdl_min into cell_width (which causes a
* bu_bomb("bad cell size") crash when work is dispatched). */
#ifdef RT_ANNOT_OVERLAY
have_annotation_bounds = rt_annot_scene_bounds(annotation_scene,
annotation_min, annotation_max);
if (have_annotation_bounds) {
VMOVE(rtip->mdl_min, annotation_min);
VMOVE(rtip->mdl_max, annotation_max);
} else
#endif
{
bu_log("do_ae: infinite model bounds? setting unit bounds\n");
VSETALL(rtip->mdl_min, -1);
VSETALL(rtip->mdl_max, 1);
}
bu_log("do_ae: infinite model bounds? setting unit bounds\n");
VSETALL(rtip->mdl_min, -1);
VSETALL(rtip->mdl_max, 1);
}
/*
@@ -1636,14 +1443,6 @@ do_ae_internal(double azim, double elev, int center_eye)
*/
VMOVE(view_min, rtip->mdl_min);
VMOVE(view_max, rtip->mdl_max);
#ifdef RT_ANNOT_OVERLAY
have_annotation_bounds = rt_annot_scene_bounds(annotation_scene,
annotation_min, annotation_max);
if (have_annotation_bounds) {
VMINMAX(view_min, view_max, annotation_min);
VMINMAX(view_min, view_max, annotation_max);
}
#endif
if (autoview_argc > 0) {
point_t sub_min, sub_max;
if (rt_obj_bounds(NULL, rtip->rti_dbip, autoview_argc,
-9
View File
@@ -151,9 +151,6 @@ extern vect_t dx_model; /* view delta-X as model-space vect (width of pixel as
extern vect_t dx_unit; /* unit-len dir vector of pixel side-to-side */
extern vect_t dy_model; /* view delta-Y as model-space vect (height of pixel as vector) */
extern vect_t dy_unit; /* unit-len dir vector of pixel top-to-bottom */
#ifdef RT_ANNOT_OVERLAY
# define RTUIF_ANNOTATION_ONLY 2
#endif
/** 'jitter' variable values **/
#define JITTER_CELL 0x1 /* jitter position of ray in each cell */
#define JITTER_FRAME 0x2 /* jitter position of entire frame */
@@ -200,12 +197,6 @@ extern void do_ae(double azim, double elev);
extern void do_view_finalize(double azim, double elev);
extern int old_way(FILE *fp);
extern int do_frame(int framenumber);
#ifdef RT_ANNOT_OVERLAY
extern size_t rtuif_prepare_annotations(struct rt_i *rtip);
extern const struct rt_annot_scene *rtuif_annotations(void);
extern const struct rt_annot_view *rtuif_annotation_view(void);
extern void rtuif_clear_annotations(void);
#endif
#ifdef USE_OPENCL
enum {
-6
View File
@@ -620,9 +620,6 @@ int main(int argc, char *argv[])
}
}
#ifdef RT_ANNOT_OVERLAY
rtuif_prepare_annotations(APP.a_rt_i);
#endif
do_view_finalize(azimuth, elevation);
if (need_fb != 0 && !fbp) {
@@ -742,9 +739,6 @@ int main(int argc, char *argv[])
}
rt_cleanup:
#ifdef RT_ANNOT_OVERLAY
rtuif_clear_annotations();
#endif
/* Clean up objv memory, if necessary */
if (objs_free_argv) {
for (i = 0; i < objc; i++) {
-9
View File
@@ -267,14 +267,6 @@ view_pixel(struct application *ap)
fp->ff_frame = -1; /* Don't cache misses */
return;
}
#ifdef RT_ANNOT_OVERLAY
if (ap->a_flag == RTUIF_ANNOTATION_ONLY) {
/* Annotation coverage has no region or reusable model hit. */
fp->ff_dist = -INFINITY;
fp->ff_regp = NULL;
return;
}
#endif
/* XXX a_dist is negative and misleading when eye is in air */
fp->ff_dist = (float)ap->a_dist;
VJOIN1(fp->ff_hitpt, ap->a_ray.r_pt,
@@ -1238,7 +1230,6 @@ viewit(struct application *ap, struct partition *PartHeadp, struct seg *UNUSED(s
}
hitp = pp->pt_inhit;
ap->a_dist = hitp->hit_dist;
RT_HIT_NORMAL(normal, hitp, pp->pt_inseg->seg_stp, &(ap->a_ray), pp->pt_inflip);
/*
+2 -70
View File
@@ -151,46 +151,6 @@ jitter_start_pnt(vect_t point, struct application *a, int samplenum, int pat_num
}
#ifdef RT_ANNOT_OVERLAY
static int
annotation_overlay_active(void)
{
const struct rt_annot_scene *scene = rtuif_annotations();
return scene && rt_annot_scene_count(scene);
}
static void
annotate_primary_sample(struct application *ap, const point_t viewplane_point)
{
point_t view_point;
struct rt_annot_hit hit = {0};
fastf_t sample_x;
fastf_t sample_y;
fastf_t scene_distance;
const struct rt_annot_scene *scene = rtuif_annotations();
const struct rt_annot_view *view = rtuif_annotation_view();
if (!scene || !rt_annot_scene_count(scene))
return;
MAT4X3PNT(view_point, model2view, viewplane_point);
sample_x = (view_point[X] + 1.0) * (fastf_t)width * 0.5;
sample_y = view_point[Y] * (fastf_t)width * 0.5 +
(fastf_t)height * 0.5;
scene_distance = ap->a_user ? ap->a_dist : INFINITY;
if (rt_annot_scene_composite(scene, view, &ap->a_ray,
sample_x, sample_y, scene_distance, ap->a_color, &hit)) {
if (!ap->a_user) {
ap->a_user = 1;
ap->a_flag = RTUIF_ANNOTATION_ONLY;
ap->a_dist = hit.screen_space ? INFINITY : hit.distance;
}
}
}
#endif
void
do_pixel(int cpu, int pat_num, int pixelnum)
{
@@ -279,11 +239,7 @@ do_pixel(int cpu, int pat_num, int pixelnum)
if (fullfloat_mode) {
register struct floatpixel *fp;
fp = &curr_float_frame[a.a_y*width + a.a_x];
if (fp->ff_frame >= 0
#ifdef RT_ANNOT_OVERLAY
&& !annotation_overlay_active()
#endif
) {
if (fp->ff_frame >= 0) {
return; /* pixel was reprojected */
}
}
@@ -291,11 +247,7 @@ do_pixel(int cpu, int pat_num, int pixelnum)
/* Check the pixel map to determine if this image should be
* rendered or not.
*/
if (pixmap
#ifdef RT_ANNOT_OVERLAY
&& !annotation_overlay_active()
#endif
) {
if (pixmap) {
a.a_user= 1; /* Force Shot Hit */
if (pixmap[pindex + RED] + pixmap[pindex + GRN] + pixmap[pindex + BLU]) {
@@ -376,12 +328,7 @@ do_pixel(int cpu, int pat_num, int pixelnum)
a.a_level = 0; /* recursion level */
a.a_purpose = "main ray";
a.a_flag = 0;
a.a_dist = INFINITY;
(void)rt_shootray(&a);
#ifdef RT_ANNOT_OVERLAY
annotate_primary_sample(&a, point);
#endif
if (stereo) {
fastf_t right, left;
@@ -403,12 +350,7 @@ do_pixel(int cpu, int pat_num, int pixelnum)
}
a.a_level = 0; /* recursion level */
a.a_purpose = "left eye ray";
a.a_flag = 0;
a.a_dist = INFINITY;
(void)rt_shootray(&a);
#ifdef RT_ANNOT_OVERLAY
annotate_primary_sample(&a, point);
#endif
left = CRT_BLEND(a.a_color);
VSET(a.a_color, left, 0, right);
@@ -471,12 +413,7 @@ do_pixel(int cpu, int pat_num, int pixelnum)
a.a_level = 0; /* recursion level */
a.a_purpose = "main ray";
a.a_flag = 0;
a.a_dist = INFINITY;
(void)rt_shootray(&a);
#ifdef RT_ANNOT_OVERLAY
annotate_primary_sample(&a, point);
#endif
if (stereo) {
fastf_t right, left;
@@ -498,12 +435,7 @@ do_pixel(int cpu, int pat_num, int pixelnum)
}
a.a_level = 0; /* recursion level */
a.a_purpose = "left eye ray";
a.a_flag = 0;
a.a_dist = INFINITY;
(void)rt_shootray(&a);
#ifdef RT_ANNOT_OVERLAY
annotate_primary_sample(&a, point);
#endif
left = CRT_BLEND(a.a_color);
VSET(a.a_color, left, 0, right);
+9 -396
View File
@@ -49,12 +49,8 @@ proc mged_bind_dm { w } {
bind $w <Enter> [list mged_activate_dm $w]
#default mouse bindings
default_mouse_bindings $w
# Load standardized JSON bindings for mged
#default key bindings
set forwarding_key($w) 0
default_key_bindings $w
}
proc print_return_val str {
@@ -64,129 +60,6 @@ proc print_return_val str {
}
}
if ![info exists mged_default(dm_key_bindings)] {
set mged_default(dm_key_bindings) "\tKey Sequence\t\tBehavior
\ta\t\t\ttoggle angle distance cursor (ADC)
\te\t\t\ttoggle edit axes
\tm\t\t\ttoggle model axes
\tv\t\t\ttoggle view axes
\ti\t\t\tadvance illumination pointer forward
\tI\t\t\tadvance illumination pointer backward
\tp\t\t\tsimulate mouse press (i.e. to pick a solid)
\t3\t\t\tview - ae 35 25
\t4\t\t\tview - ae 45 45
\tf\t\t\tfront view
\tt\t\t\ttop view
\tb\t\t\tbottom view
\tl\t\t\tleft view
\tr\t\t\tright view
\tR\t\t\trear view
\ts\t\t\tenter solid illumination state
\to\t\t\tenter object illumination state
\tq\t\t\treject edit
\tu\t\t\tzero knobs and sliders
\t<F1>\t\t\ttoggle depthcue
\t<F2>\t\t\ttoggle zclip
\t<F3>\t\t\ttoggle perspective
\t<F4>\t\t\ttoggle zbuffer
\t<F5>\t\t\ttoggle lighting
\t<F6>\t\t\ttoggle perspective angle
\t<F7>\t\t\ttoggle faceplate
\t<F8>\t\t\ttoggle faceplate GUI
\t<F9>\t\t\ttoggle keystroke forwarding
\t<F12>\t\t\tzero knobs
\t<Left>\t\t\tabsolute rotate about y axis
\t<Right>\t\t\tabsolute rotate about y axis
\t<Down>\t\t\tabsolute rotate about x axis
\t<Up>\t\t\tabsolute rotate about x axis
\t<Shift-Left>\t\tabsolute translate in X direction
\t<Shift-Right>\t\tabsolute translate in X direction
\t<Shift-Down>\t\tabsolute translate in Z direction
\t<Shift-Up>\t\tabsolute translate in Z direction
\t<Control-Shift-Left>\tabsolute rotate about z axis
\t<Control-Shift-Right>\tabsolute rotate about z axis
\t<Control-Shift-Down>\tabsolute translate in Y direction
\t<Control-Shift-Up>\tabsolute translate in Y direction
\t<Control-n>\t\tgoto next view
\t<Control-p>\t\tgoto previous view
\t<Control-t>\t\ttoggle between the current view and the last view"
}
proc default_key_bindings { w } {
# common view shortcuts
bind $w 2 "winset $w; ae 35 -25; break"
bind $w 3 "winset $w; press 35,25; break"
bind $w 4 "winset $w; press 45,45; break"
bind $w 5 "winset $w; ae 145 25; break"
bind $w 6 "winset $w; ae 215 25; break"
bind $w 7 "winset $w; ae 325 25; break"
# default key shortcuts
bind $w a "winset $w; adc; break"
bind $w b "winset $w; press bottom; break"
bind $w c "open_cmd_win id_0"
bind $w e "winset $w; rset ax edit_draw !; update_gui $w edit_draw \[rset ax edit_draw\]; break"
bind $w f "winset $w; press front; break"
bind $w i "winset $w; aip f; break"
bind $w l "winset $w; press left; break"
bind $w m "winset $w; rset ax model_draw !; update_gui $w model_draw \[rset ax model_draw\]; break"
bind $w o "winset $w; press oill; break"
bind $w p "winset $w; M 1 0 0; break"
bind $w q "winset $w; press reject; break"
bind $w r "winset $w; press right; break"
bind $w s "winset $w; press sill; break"
bind $w t "winset $w; press top; break"
bind $w u "winset $w; svb; break"
bind $w v "winset $w; rset ax view_draw !; update_gui $w view_draw \[rset ax view_draw\]; break"
# default shift+key shortcuts
bind $w A "winset $w; press accept; break"
bind $w I "winset $w; aip b; break"
bind $w N "winset $w; puts \[nirt -b\]; break"
bind $w P "winset $w; catch {sed_apply}; break"
bind $w R "winset $w; press rear; break"
bind $w S "winset $w; catch {sed_reset}; break"
# default control+key shortcuts
bind $w <Control-n> "winset $w; _mged_view_ring next; break"
bind $w <Control-p> "winset $w; _mged_view_ring prev; break"
bind $w <Control-t> "winset $w; _mged_view_ring toggle; break"
# shift grips navigation
bind $w <Control-Shift-Down> "winset $w; knob -i aY \$mged_default(tran_factor); break"
bind $w <Control-Shift-Left> "winset $w; knob -i az \$mged_default(rot_factor); break"
bind $w <Control-Shift-Right> "winset $w; knob -i az -\$mged_default(rot_factor); break"
bind $w <Control-Shift-Up> "winset $w; knob -i aY -\$mged_default(tran_factor); break"
bind $w <Down> "winset $w; knob -i ax \$mged_default(rot_factor); break"
bind $w <Left> "winset $w; knob -i ay -\$mged_default(rot_factor); break"
bind $w <Right> "winset $w; knob -i ay \$mged_default(rot_factor); break"
bind $w <Up> "winset $w; knob -i ax -\$mged_default(rot_factor); break"
bind $w <Shift-Down> "winset $w; knob -i aZ -\$mged_default(tran_factor); break"
bind $w <Shift-Left> "winset $w; knob -i aX \$mged_default(tran_factor); break"
bind $w <Shift-Right> "winset $w; knob -i aX -\$mged_default(tran_factor); break"
bind $w <Shift-Up> "winset $w; knob -i aZ \$mged_default(tran_factor); break"
# function keys (settings)
bind $w <F1> "winset $w; dm set depthcue !; update_gui $w depthcue \[dm set depthcue\]; break"
bind $w <F2> "winset $w; dm set zclip !; update_gui $w zclip \[dm set zclip\]; break"
bind $w <F3> "winset $w; set perspective_mode !; update_gui $w perspective_mode \$perspective_mode; break"
bind $w <F4> "winset $w; dm set zbuffer !; update_gui $w zbuffer \[dm set zbuffer\]; break"
bind $w <F5> "winset $w; dm set lighting !; update_gui $w lighting \[dm set lighting\]; break"
bind $w <F6> "winset $w; set toggle_perspective !; break"
bind $w <F7> "winset $w; set faceplate !; update_gui $w faceplate \$faceplate; break"
bind $w <F8> "winset $w; set orig_gui !; update_gui $w orig_gui \$orig_gui; break"
bind $w <F9> "toggle_forward_key_bindings $w; update_gui $w forward_keys \$forwarding_key($w); break"
bind $w <F12> "winset $w; knob zero; break"
# interrupt
bind $w <Escape> "winset $w; reset_everything $w; break"
# Throw away other key events
bind $w <KeyPress> {
break
}
}
proc reset_everything { w } {
global mged_gui
@@ -202,274 +75,6 @@ proc reset_everything { w } {
set_mouse_behavior $id
}
proc set_forward_keys { w val } {
global forwarding_key
set forwarding_key($w) $val
if {$forwarding_key($w)} {
forward_key_bindings $w
} else {
default_key_bindings $w
}
}
proc toggle_forward_key_bindings { w } {
global forwarding_key
if {$forwarding_key($w)} {
default_key_bindings $w
set forwarding_key($w) 0
} else {
forward_key_bindings $w
set forwarding_key($w) 1
}
}
proc forward_key_bindings { w } {
set id [get_player_id_dm $w]
if {$id == "mged"} {
return
}
# First, unset the default key bindings
bind $w a {}
bind $w e {}
bind $w m {}
bind $w v {}
bind $w i {}
bind $w I {}
bind $w p {}
bind $w 2 {}
bind $w 3 {}
bind $w 4 {}
bind $w 5 {}
bind $w 6 {}
bind $w 7 {}
bind $w f {}
bind $w t {}
bind $w b {}
bind $w l {}
bind $w N {}
bind $w r {}
bind $w R {}
bind $w s {}
bind $w o {}
bind $w q {}
bind $w u {}
bind $w c {}
bind $w A {}
bind $w P {}
bind $w S {}
bind $w <F1> {}
bind $w <F2> {}
bind $w <F3> {}
bind $w <F4> {}
bind $w <F5> {}
bind $w <F6> {}
bind $w <F7> {}
bind $w <F8> {}
bind $w <F12> {}
bind $w <Left> {}
bind $w <Right> {}
bind $w <Down> {}
bind $w <Up> {}
bind $w <Shift-Left> {}
bind $w <Shift-Right> {}
bind $w <Shift-Down> {}
bind $w <Shift-Up> {}
bind $w <Control-Shift-Left> {}
bind $w <Control-Shift-Right> {}
bind $w <Control-Shift-Down> {}
bind $w <Control-Shift-Up> {}
bind $w <Control-n> {}
bind $w <Control-p> {}
bind $w <Control-t> {}
bind $w <Escape> {}
# The focus commands in the binding below are necessary to insure
# that .$id.t gets the event.
bind $w <KeyPress> "\
focus .$id.t;\
set mged_gui(.$id.t,insert_char_flag) 1;\
event generate .$id.t <KeyPress> -state %s -keysym %K;\
set mged_gui(.$id.t,insert_char_flag) 0;\
focus %W;\
break"
}
proc default_mouse_bindings { w } {
global no_focus_hack
global transform
global tcl_platform
# default button bindings
if {![regexp {^[0-9]+} $::tcl_platform(osVersion) osMajorVersion]} {
set osMajorVersion 0
}
if {[info exists no_focus_hack] && $no_focus_hack} {
bind $w <1> "winset $w; zoom 0.5; break"
bind $w <2> "winset $w; set tmpstr \[dm m %x %y\]; print_return_val \$tmpstr; break"
bind $w <3> "winset $w; zoom 2.0; break"
# Mouse wheel fun with Tcl/Tk - see https://wiki.tcl-lang.org/page/mousewheel
bind $w <MouseWheel> "winset $w; focus $w; if {%D < 0} {zoom 0.9} else {zoom 1.1}"
bind $w <Button-4> {event generate [focus] <MouseWheel> -delta 120}
bind $w <Button-5> {event generate [focus] <MouseWheel> -delta -120}
if {$::tcl_platform(os) == "Darwin"} {
# Mac option-key emulates mouse 2 (doesn't work?)
bind $w <Option-ButtonPress-1> "winset $w; set tmpstr \[dm m %x %y\]; print_return_val \$tmpstr; break"
# Mac command-key emulates mouse 3
bind $w <Mod2-ButtonPress-1> "winset $w; zoom 2.0; break"
}
} else {
bind $w <1> "winset $w; focus $w; zoom 0.5; break"
bind $w <2> "winset $w; focus $w; set tmpstr \[dm m %x %y\]; print_return_val \$tmpstr; break"
bind $w <3> "winset $w; focus $w; zoom 2.0; break"
# Mouse wheel fun with Tcl/Tk - see https://wiki.tcl-lang.org/page/mousewheel
bind $w <MouseWheel> "winset $w; focus $w; if {%D < 0} {zoom 0.9} else {zoom 1.1}; break"
bind $w <Button-4> {event generate [focus] <MouseWheel> -delta 120}
bind $w <Button-5> {event generate [focus] <MouseWheel> -delta -120}
if {$::tcl_platform(os) == "Darwin"} {
# Mac command-key emulates mouse 2 (doesn't work?)
bind $w <Option-ButtonPress-1> "winset $w; focus $w; set tmpstr \[dm m %x %y\]; print_return_val \$tmpstr; break"
# Mac command-key emulates mouse 3
bind $w <Mod2-ButtonPress-1> "winset $w; focus $w; zoom 2.0; break"
}
}
bind $w <ButtonRelease> "winset $w; dm idle; break"
bind $w <Motion> "winset $w; if {\[dm type\] == \"tkswrast\"} {dm motion %x %y}; break"
bind $w <KeyRelease-Control_L> "winset $w; dm idle; break"
bind $w <KeyRelease-Control_R> "winset $w; dm idle; break"
bind $w <KeyRelease-Shift_L> "winset $w; dm idle; break"
bind $w <KeyRelease-Shift_R> "winset $w; dm idle; break"
bind $w <KeyRelease-Alt_L> "winset $w; dm idle; break"
bind $w <KeyRelease-Alt_R> "winset $w; dm idle; break"
if ![catch {adc draw} result] {
set adcflag $result
} else {
set adcflag 0
}
if {$adcflag == "1" && $transform == "a"} {
bind $w <Shift-ButtonPress-1> "winset $w; dm adc t %x %y; \
shift_grip_hints $w \"Translate ADC\"; break"
bind $w <Shift-ButtonPress-2> "winset $w; dm adc t %x %y; \
shift_grip_hints $w \"Translate ADC\"; break"
bind $w <Shift-ButtonPress-3> "winset $w; dm adc d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
bind $w <Control-ButtonPress-1> "winset $w; dm adc 1 %x %y; \
shift_grip_hints $w \"Rotate Angle 1\"; break"
bind $w <Control-ButtonPress-2> "winset $w; dm adc 2 %x %y; \
shift_grip_hints $w \"Rotate Angle 2\"; break"
bind $w <Control-ButtonPress-3> "winset $w; dm adc d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
bind $w <Shift-Control-ButtonPress-1> "winset $w; dm adc d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
bind $w <Shift-Control-ButtonPress-2> "winset $w; dm adc d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
bind $w <Shift-Control-ButtonPress-3> "winset $w; dm adc d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
#constrained adc defaults
bind $w <Alt-Shift-ButtonPress-1> "winset $w; dm con a x %x %y; \
shift_grip_hints $w \"X Translate ADC\"; break"
bind $w <Alt-Shift-ButtonPress-2> "winset $w; dm con a y %x %y; \
shift_grip_hints $w \"Y Translate ADC\"; break"
bind $w <Alt-Shift-ButtonPress-3> "winset $w; dm con a d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
bind $w <Alt-Control-ButtonPress-1> "winset $w; dm con a 1 %x %y; \
shift_grip_hints $w \"Rotate Angle 1\"; break"
bind $w <Alt-Control-ButtonPress-2> "winset $w; dm con a 2 %x %y; \
shift_grip_hints $w \"Rotate Angle 2\"; break"
bind $w <Alt-Control-ButtonPress-3> "winset $w; dm con a d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
bind $w <Alt-Shift-Control-ButtonPress-1> "winset $w; dm con a d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
bind $w <Alt-Shift-Control-ButtonPress-2> "winset $w; dm con a d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
bind $w <Alt-Shift-Control-ButtonPress-3> "winset $w; dm con a d %x %y; \
shift_grip_hints $w \"Translate Tick Distance\"; break"
} else {
bind $w <Shift-ButtonPress-1> "winset $w; dm am t %x %y; \
shift_grip_hints $w Translate; break"
bind $w <Shift-ButtonPress-2> "winset $w; dm am t %x %y; \
shift_grip_hints $w Translate; break"
bind $w <Shift-ButtonPress-3> "winset $w; dm am t %x %y; \
shift_grip_hints $w Translate; break"
bind $w <Control-ButtonPress-1> "winset $w; dm am r %x %y; \
shift_grip_hints $w Rotate; break"
bind $w <Control-ButtonPress-2> "winset $w; dm am r %x %y; \
shift_grip_hints $w Rotate; break"
bind $w <Control-ButtonPress-3> "winset $w; dm am r %x %y; \
shift_grip_hints $w Rotate; break"
bind $w <Shift-Control-ButtonPress-1> "winset $w; dm am s %x %y; \
shift_grip_hints $w Scale/Zoom; break"
bind $w <Shift-Control-ButtonPress-2> "winset $w; dm am s %x %y; \
shift_grip_hints $w Scale/Zoom; break"
bind $w <Shift-Control-ButtonPress-3> "winset $w; dm am s %x %y; \
shift_grip_hints $w Scale/Zoom; break"
#constrained defaults
bind $w <Alt-Shift-ButtonPress-1> "winset $w; dm con t x %x %y; \
shift_grip_hints $w \"X Translation\"; break"
bind $w <Alt-Shift-ButtonPress-2> "winset $w; dm con t y %x %y; \
shift_grip_hints $w \"Y Translation\"; break"
bind $w <Alt-Shift-ButtonPress-3> "winset $w; dm con t z %x %y; \
shift_grip_hints $w \"Z Translation\"; break"
bind $w <Alt-Control-ButtonPress-1> "winset $w; dm con r x %x %y; \
shift_grip_hints $w \"X Rotation\"; break"
bind $w <Alt-Control-ButtonPress-2> "winset $w; dm con r y %x %y; \
shift_grip_hints $w \"Y Rotation\"; break"
bind $w <Alt-Control-ButtonPress-3> "winset $w; dm con r z %x %y; \
shift_grip_hints $w \"Z Rotation\"; break"
bind $w <Alt-Shift-Control-ButtonPress-1> "winset $w; dm con s x %x %y; \
scale_shift_grip_hints $w X; break"
bind $w <Alt-Shift-Control-ButtonPress-2> "winset $w; dm con s y %x %y; \
scale_shift_grip_hints $w Y; break"
bind $w <Alt-Shift-Control-ButtonPress-3> "winset $w; dm con s z %x %y; \
scale_shift_grip_hints $w Z; break"
}
}
proc shift_grip_hints { w hint } {
global mged_display
global mged_gui
global win_to_id
if ![info exists win_to_id($w)] {
return
}
set id $win_to_id($w)
set mged_gui($id,illum_label) $hint
}
proc scale_shift_grip_hints { w axis } {
if {[status state] == "OBJ EDIT"} {
shift_grip_hints $w "$axis Scale"
} else {
shift_grip_hints $w "Scale/Zoom"
}
}
proc update_gui { w vname val } {
global mged_players
global mged_gui
@@ -482,6 +87,14 @@ proc update_gui { w vname val } {
}
}
# Dummy stubs to prevent legacy scripts from failing if they try to invoke them
proc default_key_bindings { w } {}
proc default_mouse_bindings { w } {}
proc forward_key_bindings { w } {}
proc toggle_forward_key_bindings { w } {}
proc set_forward_keys { w val } {}
proc shift_grip_hints { w hint } {}
proc scale_shift_grip_hints { w axis } {}
# Local Variables:
# mode: Tcl