OCCT-Light 0.1
C ABI and C++ veneer for multi-language CAD workflows
Loading...
Searching...
No Matches
viz.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Capgemini Engineering Research and Development.
2//
3// This file is part of OCCT-Light software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Affero General Public License version 3 as published
7// by the Free Software Foundation, with an option to use any later version.
8// Consult the file LICENSE_AGPL_30.txt included in OCCT-Light distribution
9// for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of a commercial
12// license or contractual agreement.
13//
14// SPDX-License-Identifier: AGPL-3.0-or-later
15
25#ifndef OCCTL_HPP_VIZ_HPP
26#define OCCTL_HPP_VIZ_HPP
27
28#include <occtl/occtl_viz.h>
29
30#include <occtl-hpp/core.hpp>
31#include <occtl-hpp/topo.hpp>
32
33#include <cstddef>
34#include <cstdint>
35#include <string>
36#include <vector>
37
38namespace occtl::viz
39{
40
42enum class DisplayMode
43{
48};
49
65
67enum class StandardView
68{
74 Bottom = OCCTL_VIZ_VIEW_BOTTOM,
76};
77
80{
81 bool enable_vbo = true;
82 bool enable_vsync = true;
83
84 [[nodiscard]] ::occtl_viz_driver_options_t to_c() const noexcept
85 {
87 anOptions.enable_vbo = enable_vbo ? 1 : 0;
88 anOptions.enable_vsync = enable_vsync ? 1 : 0;
89 return anOptions;
90 }
91};
92
95{
96 int width = 640;
97 int height = 480;
98 void* native_handle = nullptr;
99 bool offscreen = true;
100
101 [[nodiscard]] ::occtl_viz_view_options_t to_c() const noexcept
102 {
104 anOptions.width = width;
105 anOptions.height = height;
106 anOptions.native_handle = native_handle;
107 anOptions.offscreen = offscreen ? 1 : 0;
108 return anOptions;
109 }
110};
111
113struct Camera
114{
118
120 [[nodiscard]] ::occtl_viz_camera_t to_c() const noexcept
121 {
122 ::occtl_viz_camera_t aCamera;
123 aCamera.eye = eye.c_type();
124 aCamera.center = center.c_type();
125 aCamera.up = up.c_type();
126 return aCamera;
127 }
128
130 static Camera from_c(const ::occtl_viz_camera_t& theC) noexcept
131 {
132 return Camera{Point3(theC.eye), Point3(theC.center), Vector3(theC.up)};
133 }
134};
135
138{
144
146 static PickResult from_c(const ::occtl_viz_pick_result_t& theC) noexcept
147 {
148 PickResult aResult;
149 aResult.uid = UID(theC.uid);
150 aResult.node = NodeId(theC.node);
151 aResult.ref = RefId(theC.ref);
152 aResult.selection_mode = static_cast<SelectionMode>(theC.selection_mode);
153 aResult.usage_transform = Transform(theC.usage_transform);
154 return aResult;
155 }
156};
157
162{
163public:
164 explicit Driver(const DriverOptions& theOptions = DriverOptions{})
165 {
166 ::occtl_viz_driver_options_t anOptions = theOptions.to_c();
167 check(::occtl_viz_driver_create(&anOptions, &myHandle));
168 }
169
170 ~Driver() noexcept { ::occtl_viz_driver_free(myHandle); }
171
172 Driver(const Driver&) = delete;
173 Driver& operator=(const Driver&) = delete;
174
175 Driver(Driver&& theOther) noexcept
176 : myHandle(theOther.myHandle)
177 {
178 theOther.myHandle = nullptr;
179 }
180
181 Driver& operator=(Driver&& theOther) noexcept
182 {
183 if (this != &theOther)
184 {
185 ::occtl_viz_driver_free(myHandle);
186 myHandle = theOther.myHandle;
187 theOther.myHandle = nullptr;
188 }
189 return *this;
190 }
191
192 ::occtl_viz_driver_t* get() const noexcept { return myHandle; }
193
194private:
195 ::occtl_viz_driver_t* myHandle = nullptr;
196};
197
202{
203public:
204 explicit Viewer(Driver& theDriver)
205 {
206 check(::occtl_viz_viewer_create(theDriver.get(), &myHandle));
207 }
208
209 ~Viewer() noexcept { ::occtl_viz_viewer_free(myHandle); }
210
211 Viewer(const Viewer&) = delete;
212 Viewer& operator=(const Viewer&) = delete;
213
214 Viewer(Viewer&& theOther) noexcept
215 : myHandle(theOther.myHandle)
216 {
217 theOther.myHandle = nullptr;
218 }
219
220 Viewer& operator=(Viewer&& theOther) noexcept
221 {
222 if (this != &theOther)
223 {
224 ::occtl_viz_viewer_free(myHandle);
225 myHandle = theOther.myHandle;
226 theOther.myHandle = nullptr;
227 }
228 return *this;
229 }
230
231 ::occtl_viz_viewer_t* get() const noexcept { return myHandle; }
232
233private:
234 ::occtl_viz_viewer_t* myHandle = nullptr;
235};
236
241{
242public:
244 Presentable(Viewer& theViewer, Graph& theGraph, const NodeId theRoot)
245 {
246 check(
247 ::occtl_viz_presentable_create(theViewer.get(), theGraph.get(), theRoot.get(), &myHandle));
248 }
249
250 ~Presentable() noexcept { ::occtl_viz_presentable_free(myHandle); }
251
252 Presentable(const Presentable&) = delete;
253 Presentable& operator=(const Presentable&) = delete;
254
255 Presentable(Presentable&& theOther) noexcept
256 : myHandle(theOther.myHandle)
257 {
258 theOther.myHandle = nullptr;
259 }
260
261 Presentable& operator=(Presentable&& theOther) noexcept
262 {
263 if (this != &theOther)
264 {
266 myHandle = theOther.myHandle;
267 theOther.myHandle = nullptr;
268 }
269 return *this;
270 }
271
273 void set_display_mode(const DisplayMode theMode)
274 {
275 check(
277 static_cast<::occtl_viz_display_mode_t>(theMode)));
278 }
279
283 {
284 int32_t aChanged = 0;
285 check(::occtl_viz_presentable_synchronize(myHandle, &aChanged));
286 return aChanged != 0;
287 }
288
291
293 void set_visible_nodes(const std::vector<NodeId>& theNodes)
294 {
295 std::vector<::occtl_node_id_t> aIds;
296 aIds.reserve(theNodes.size());
297 for (const NodeId& aNode : theNodes)
298 aIds.push_back(aNode.get());
299 check(::occtl_viz_presentable_set_visible_nodes(myHandle, aIds.data(), aIds.size()));
300 }
301
304
305 ::occtl_viz_presentable_t* get() const noexcept { return myHandle; }
306
307private:
308 ::occtl_viz_presentable_t* myHandle = nullptr;
309};
310
314class View
315{
316public:
317 explicit View(Viewer& theViewer, const ViewOptions& theOptions = ViewOptions{})
318 {
319 ::occtl_viz_view_options_t anOptions = theOptions.to_c();
320 check(::occtl_viz_view_create(theViewer.get(), &anOptions, &myHandle));
321 }
322
323 ~View() noexcept { ::occtl_viz_view_free(myHandle); }
324
325 View(const View&) = delete;
326 View& operator=(const View&) = delete;
327
328 View(View&& theOther) noexcept
329 : myHandle(theOther.myHandle)
330 {
331 theOther.myHandle = nullptr;
332 }
333
334 View& operator=(View&& theOther) noexcept
335 {
336 if (this != &theOther)
337 {
338 ::occtl_viz_view_free(myHandle);
339 myHandle = theOther.myHandle;
340 theOther.myHandle = nullptr;
341 }
342 return *this;
343 }
344
346 void display(Presentable& thePresentable)
347 {
348 check(::occtl_viz_view_display(myHandle, thePresentable.get()));
349 }
350
352 void erase(Presentable& thePresentable)
353 {
354 check(::occtl_viz_view_erase(myHandle, thePresentable.get()));
355 }
356
358 void resize(const int32_t theWidth, const int32_t theHeight)
359 {
360 check(::occtl_viz_view_resize(myHandle, theWidth, theHeight));
361 }
362
364 void redraw() { check(::occtl_viz_view_redraw(myHandle)); }
365
368
370 void set_background(const ::occtl_color_rgba_t& theColor)
371 {
372 check(::occtl_viz_view_set_background(myHandle, theColor));
373 }
374
376 void set_camera(const Camera& theCamera)
377 {
378 ::occtl_viz_camera_t aCamera = theCamera.to_c();
379 check(::occtl_viz_view_set_camera(myHandle, &aCamera));
380 }
381
383 [[nodiscard]] Camera get_camera() const
384 {
385 ::occtl_viz_camera_t aCamera{};
386 check(::occtl_viz_view_get_camera(myHandle, &aCamera));
387 return Camera::from_c(aCamera);
388 }
389
391 void set_standard_view(const StandardView theView)
392 {
394 static_cast<::occtl_viz_standard_view_t>(theView)));
395 }
396
398 void pan(const int32_t theDx, const int32_t theDy)
399 {
400 check(::occtl_viz_view_pan(myHandle, theDx, theDy));
401 }
402
404 void zoom(const int32_t theX1, const int32_t theY1, const int32_t theX2, const int32_t theY2)
405 {
406 check(::occtl_viz_view_zoom(myHandle, theX1, theY1, theX2, theY2));
407 }
408
410 void orbit_start(const int32_t theX, const int32_t theY)
411 {
412 check(::occtl_viz_view_orbit_start(myHandle, theX, theY));
413 }
414
416 void orbit_update(const int32_t theX, const int32_t theY)
417 {
418 check(::occtl_viz_view_orbit_update(myHandle, theX, theY));
419 }
420
422 void activate_selection(Presentable& thePresentable, const SelectionMode theMode)
423 {
425 thePresentable.get(),
426 static_cast<::occtl_viz_selection_mode_t>(theMode)));
427 }
428
430 void pick(const int32_t theX, const int32_t theY, const bool theSelect, PickResult& theResult)
431 {
432 ::occtl_viz_pick_result_t aRaw = OCCTL_VIZ_PICK_RESULT_INIT;
433 check(::occtl_viz_view_pick(myHandle, theX, theY, theSelect ? 1 : 0, &aRaw));
434 theResult = PickResult::from_c(aRaw);
435 }
436
438 [[nodiscard]] std::vector<std::uint8_t> read_pixels_rgba()
439 {
440 size_t aCount = 0;
441 check(::occtl_viz_view_read_pixels_rgba(myHandle, nullptr, 0, &aCount));
442 std::vector<std::uint8_t> aPixels(aCount);
443 check(::occtl_viz_view_read_pixels_rgba(myHandle, aPixels.data(), aPixels.size(), &aCount));
444 return aPixels;
445 }
446
448 void dump_image(const std::string& thePath)
449 {
450 check(::occtl_viz_view_dump_image(myHandle, thePath.c_str()));
451 }
452
453 ::occtl_viz_view_t* get() const noexcept { return myHandle; }
454
455private:
456 ::occtl_viz_view_t* myHandle = nullptr;
457};
458
459} // namespace occtl::viz
460
461#endif // OCCTL_HPP_VIZ_HPP
RAII handle for a topology graph. Mirrors occtl_graph_t.
Definition topo.hpp:1444
::occtl_graph_t * get() const noexcept
Borrows-it pointer to the underlying C handle, for direct ABI calls.
Definition topo.hpp:1494
Session-local identity of a graph node. Mirrors occtl_node_id_t.
Definition topo.hpp:52
::occtl_node_id_t get() const noexcept
Borrows-it view of the underlying C value type, for direct ABI calls.
Definition topo.hpp:64
Session-local identity of a reference entry. Mirrors occtl_ref_id_t.
Definition topo.hpp:90
Persistent identity surviving node removal and graph compaction. Mirrors occtl_uid_t.
Definition uid.hpp:39
RAII wrapper for the process-local visualization driver.
Definition viz.hpp:162
RAII wrapper for a display object bound to a graph root.
Definition viz.hpp:241
void set_display_mode(const DisplayMode theMode)
Sets the display mode.
Definition viz.hpp:273
void clear_visible_nodes()
Clears a visible node mask (display everything).
Definition viz.hpp:303
bool synchronize()
Synchronizes presentation after graph or metadata changes.
Definition viz.hpp:282
void set_visible_nodes(const std::vector< NodeId > &theNodes)
Restricts display to a visible node mask.
Definition viz.hpp:293
void invalidate()
Invalidates cached presentation state.
Definition viz.hpp:290
Presentable(Viewer &theViewer, Graph &theGraph, const NodeId theRoot)
Creates a display object for a graph root.
Definition viz.hpp:244
RAII wrapper for a native or offscreen view.
Definition viz.hpp:315
void zoom(const int32_t theX1, const int32_t theY1, const int32_t theX2, const int32_t theY2)
Zooms using two screen-space points.
Definition viz.hpp:404
void orbit_start(const int32_t theX, const int32_t theY)
Starts an orbit interaction at a screen point.
Definition viz.hpp:410
void pick(const int32_t theX, const int32_t theY, const bool theSelect, PickResult &theResult)
Picks or selects at a screen point and returns graph identity.
Definition viz.hpp:430
void pan(const int32_t theDx, const int32_t theDy)
Pans the camera by screen-space pixels.
Definition viz.hpp:398
void orbit_update(const int32_t theX, const int32_t theY)
Updates an orbit interaction at a screen point.
Definition viz.hpp:416
void redraw()
Redraws the view.
Definition viz.hpp:364
void activate_selection(Presentable &thePresentable, const SelectionMode theMode)
Activates graph-native selection for a presentable.
Definition viz.hpp:422
void set_background(const ::occtl_color_rgba_t &theColor)
Sets the view background colour.
Definition viz.hpp:370
void dump_image(const std::string &thePath)
Dumps a view image to a PNG path when OCCT image codecs are available.
Definition viz.hpp:448
std::vector< std::uint8_t > read_pixels_rgba()
Reads view pixels as tightly packed RGBA bytes (two-call buffer pattern).
Definition viz.hpp:438
void erase(Presentable &thePresentable)
Erases a presentable from this view.
Definition viz.hpp:352
void resize(const int32_t theWidth, const int32_t theHeight)
Resizes the view.
Definition viz.hpp:358
void set_camera(const Camera &theCamera)
Sets the camera.
Definition viz.hpp:376
Camera get_camera() const
Returns the current camera.
Definition viz.hpp:383
void display(Presentable &thePresentable)
Displays a presentable in this view.
Definition viz.hpp:346
void fit_all()
Fits all displayed content into view.
Definition viz.hpp:367
void set_standard_view(const StandardView theView)
Sets a standard camera orientation.
Definition viz.hpp:391
RAII wrapper for a viewer bound to a Driver.
Definition viz.hpp:202
C++ veneer for the core module.
void check(const ::occtl_status_t theStatus)
Throw on non-OK; otherwise a no-op.
Definition core.hpp:85
OCCT-Light: graph-native visualization module public API.
occtl_status_t occtl_viz_view_zoom(occtl_viz_view_t *view, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
#define OCCTL_VIZ_VIEW_OPTIONS_INIT
Definition occtl_viz.h:203
@ OCCTL_VIZ_SELECT_WIRE
Definition occtl_viz.h:125
@ OCCTL_VIZ_SELECT_PRODUCT
Definition occtl_viz.h:129
@ OCCTL_VIZ_SELECT_WHOLE
Definition occtl_viz.h:121
@ OCCTL_VIZ_SELECT_VERTEX
Definition occtl_viz.h:124
@ OCCTL_VIZ_SELECT_COEDGE
Definition occtl_viz.h:128
@ OCCTL_VIZ_SELECT_SHELL
Definition occtl_viz.h:126
@ OCCTL_VIZ_SELECT_COMPSOLID
Definition occtl_viz.h:131
@ OCCTL_VIZ_SELECT_SOLID
Definition occtl_viz.h:127
@ OCCTL_VIZ_SELECT_FACE
Definition occtl_viz.h:122
@ OCCTL_VIZ_SELECT_COMPOUND
Definition occtl_viz.h:130
@ OCCTL_VIZ_SELECT_EDGE
Definition occtl_viz.h:123
void occtl_viz_view_free(occtl_viz_view_t *view)
void occtl_viz_presentable_free(occtl_viz_presentable_t *presentable)
struct occtl_viz_viewer occtl_viz_viewer_t
Definition occtl_viz.h:68
occtl_status_t occtl_viz_presentable_clear_visible_nodes(occtl_viz_presentable_t *presentable)
occtl_status_t occtl_viz_view_display(occtl_viz_view_t *view, occtl_viz_presentable_t *presentable)
occtl_status_t occtl_viz_driver_create(const occtl_viz_driver_options_t *options, occtl_viz_driver_t **out_driver)
occtl_status_t occtl_viz_view_dump_image(occtl_viz_view_t *view, const char *path)
enum occtl_viz_selection_mode occtl_viz_selection_mode_t
enum occtl_viz_display_mode occtl_viz_display_mode_t
occtl_status_t occtl_viz_viewer_create(occtl_viz_driver_t *driver, occtl_viz_viewer_t **out_viewer)
occtl_status_t occtl_viz_view_set_camera(occtl_viz_view_t *view, const occtl_viz_camera_t *camera)
@ OCCTL_VIZ_VIEW_TOP
Definition occtl_viz.h:148
@ OCCTL_VIZ_VIEW_ISO
Definition occtl_viz.h:150
@ OCCTL_VIZ_VIEW_RIGHT
Definition occtl_viz.h:147
@ OCCTL_VIZ_VIEW_LEFT
Definition occtl_viz.h:146
@ OCCTL_VIZ_VIEW_BOTTOM
Definition occtl_viz.h:149
@ OCCTL_VIZ_VIEW_BACK
Definition occtl_viz.h:145
@ OCCTL_VIZ_VIEW_FRONT
Definition occtl_viz.h:144
occtl_status_t occtl_viz_presentable_create(occtl_viz_viewer_t *viewer, occtl_graph_t *graph, occtl_node_id_t root, occtl_viz_presentable_t **out_presentable)
occtl_status_t occtl_viz_view_set_background(occtl_viz_view_t *view, occtl_color_rgba_t color)
occtl_status_t occtl_viz_view_read_pixels_rgba(occtl_viz_view_t *view, uint8_t *out_rgba, size_t cap, size_t *out_count)
#define OCCTL_VIZ_DRIVER_OPTIONS_INIT
Definition occtl_viz.h:178
void occtl_viz_driver_free(occtl_viz_driver_t *driver)
occtl_status_t occtl_viz_view_create(occtl_viz_viewer_t *viewer, const occtl_viz_view_options_t *options, occtl_viz_view_t **out_view)
struct occtl_viz_presentable occtl_viz_presentable_t
Definition occtl_viz.h:94
occtl_status_t occtl_viz_view_get_camera(const occtl_viz_view_t *view, occtl_viz_camera_t *out_camera)
occtl_status_t occtl_viz_presentable_synchronize(occtl_viz_presentable_t *presentable, int32_t *out_has_changed)
occtl_status_t occtl_viz_view_activate_selection(occtl_viz_view_t *view, occtl_viz_presentable_t *presentable, occtl_viz_selection_mode_t mode)
occtl_status_t occtl_viz_view_pick(occtl_viz_view_t *view, int32_t x, int32_t y, int32_t select, occtl_viz_pick_result_t *out_pick)
occtl_status_t occtl_viz_view_set_standard_view(occtl_viz_view_t *view, occtl_viz_standard_view_t standard_view)
occtl_status_t occtl_viz_view_fit_all(occtl_viz_view_t *view)
occtl_status_t occtl_viz_presentable_set_display_mode(occtl_viz_presentable_t *presentable, occtl_viz_display_mode_t mode)
void occtl_viz_viewer_free(occtl_viz_viewer_t *viewer)
occtl_status_t occtl_viz_view_orbit_update(occtl_viz_view_t *view, int32_t x, int32_t y)
occtl_status_t occtl_viz_view_orbit_start(occtl_viz_view_t *view, int32_t x, int32_t y)
occtl_status_t occtl_viz_view_resize(occtl_viz_view_t *view, int32_t width, int32_t height)
enum occtl_viz_standard_view occtl_viz_standard_view_t
@ OCCTL_VIZ_DISPLAY_WIREFRAME
Definition occtl_viz.h:105
@ OCCTL_VIZ_DISPLAY_SHADED
Definition occtl_viz.h:106
@ OCCTL_VIZ_DISPLAY_MESH_DEBUG
Definition occtl_viz.h:108
@ OCCTL_VIZ_DISPLAY_SHADED_WITH_EDGES
Definition occtl_viz.h:107
occtl_status_t occtl_viz_view_redraw(occtl_viz_view_t *view)
struct occtl_viz_view occtl_viz_view_t
Definition occtl_viz.h:81
occtl_status_t occtl_viz_view_pan(occtl_viz_view_t *view, int32_t dx, int32_t dy)
occtl_status_t occtl_viz_presentable_invalidate(occtl_viz_presentable_t *presentable)
occtl_status_t occtl_viz_presentable_set_visible_nodes(occtl_viz_presentable_t *presentable, const occtl_node_id_t *nodes, size_t n_nodes)
struct occtl_viz_driver occtl_viz_driver_t
Definition occtl_viz.h:55
occtl_status_t occtl_viz_view_erase(occtl_viz_view_t *view, occtl_viz_presentable_t *presentable)
3D point value type. Mirrors occtl_point3_t with STL-flavoured access.
Definition geom.hpp:82
const occtl_point3_t & c_type() const noexcept
Borrows-it view of the underlying C value type, for direct ABI calls.
Definition geom.hpp:102
3-by-4 affine transform value type. Mirrors occtl_transform_t.
Definition geom.hpp:442
3D free-vector value type. Mirrors occtl_vector3_t.
Definition geom.hpp:184
const occtl_vector3_t & c_type() const noexcept
Borrows-it view of the underlying C value type.
Definition geom.hpp:204
Camera placement (eye, target, up) for a viz view.
Definition viz.hpp:114
static Camera from_c(const ::occtl_viz_camera_t &theC) noexcept
Constructs from the C value type received from the ABI.
Definition viz.hpp:130
::occtl_viz_camera_t to_c() const noexcept
Converts to the C value type for passing to the ABI.
Definition viz.hpp:120
Vector3 up
Camera up vector.
Definition viz.hpp:117
Point3 center
Camera target point.
Definition viz.hpp:116
Point3 eye
Camera eye point.
Definition viz.hpp:115
Options for creating a visualization driver.
Definition viz.hpp:80
bool enable_vsync
Request vertical sync.
Definition viz.hpp:82
bool enable_vbo
Enable VBOs before view creation.
Definition viz.hpp:81
Graph identity returned by View::pick().
Definition viz.hpp:138
RefId ref
Picked reference, or invalid when none.
Definition viz.hpp:141
Transform usage_transform
Accumulated usage transform.
Definition viz.hpp:143
UID uid
Persistent identity of the picked node.
Definition viz.hpp:139
NodeId node
Session-local picked node ID.
Definition viz.hpp:140
static PickResult from_c(const ::occtl_viz_pick_result_t &theC) noexcept
Constructs from the C value type received from the ABI.
Definition viz.hpp:146
SelectionMode selection_mode
Selection mode that produced the owner.
Definition viz.hpp:142
Options for creating a native or offscreen view.
Definition viz.hpp:95
void * native_handle
Borrowed native window/view handle; nullptr for offscreen.
Definition viz.hpp:98
bool offscreen
Create an offscreen-capable view when true.
Definition viz.hpp:99
int width
View width in pixels.
Definition viz.hpp:96
int height
View height in pixels.
Definition viz.hpp:97
Definition occtl_viz.h:213
occtl_vector3_t up
Definition occtl_viz.h:216
occtl_point3_t eye
Definition occtl_viz.h:214
occtl_point3_t center
Definition occtl_viz.h:215
Definition occtl_viz.h:168
int32_t enable_vbo
Definition occtl_viz.h:171
int32_t enable_vsync
Definition occtl_viz.h:172
Definition occtl_viz.h:229
Definition occtl_viz.h:191
void * native_handle
Definition occtl_viz.h:196
int32_t height
Definition occtl_viz.h:195
int32_t offscreen
Definition occtl_viz.h:197
int32_t width
Definition occtl_viz.h:194
C++ veneer for the topo module.
DisplayMode
Display mode for graph presentables.
Definition viz.hpp:43
SelectionMode
Graph-native selection mode for picking.
Definition viz.hpp:52
StandardView
Standard camera orientation presets.
Definition viz.hpp:68