OCCT-Light 0.1
C ABI and C++ veneer for multi-language CAD workflows
Loading...
Searching...
No Matches
io_vrml.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
21#ifndef OCCTL_HPP_IO_VRML_HPP
22#define OCCTL_HPP_IO_VRML_HPP
23
24#include <occtl/occtl_io_vrml.h>
25
26#include <occtl-hpp/core.hpp>
27#include <occtl-hpp/topo.hpp>
28
29#include <string>
30#include <utility>
31#include <vector>
32
33namespace occtl::io_vrml
34{
35
43
50
58
61{
62 double file_length_unit_m = 1.0;
63 CoordinateSystem system_coordinate_system = CoordinateSystem::ZUp;
64 CoordinateSystem file_coordinate_system = CoordinateSystem::YUp;
65 bool fill_incomplete = true;
66
67 [[nodiscard]] ::occtl_io_vrml_read_options_t to_c() const noexcept
68 {
69 ::occtl_io_vrml_read_options_t aOpts = OCCTL_IO_VRML_READ_OPTIONS_INIT;
70 aOpts.file_length_unit_m = file_length_unit_m;
72 static_cast<::occtl_io_vrml_coordinate_system_t>(system_coordinate_system);
74 static_cast<::occtl_io_vrml_coordinate_system_t>(file_coordinate_system);
75 aOpts.fill_incomplete = fill_incomplete ? 1 : 0;
76 return aOpts;
77 }
78};
79
82{
83 WriterVersion writer_version = WriterVersion::V2;
84 Representation representation = Representation::Wireframe;
85
86 [[nodiscard]] ::occtl_io_vrml_write_options_t to_c() const noexcept
87 {
88 ::occtl_io_vrml_write_options_t aOpts = OCCTL_IO_VRML_WRITE_OPTIONS_INIT;
89 aOpts.writer_version = static_cast<::occtl_io_vrml_writer_version_t>(writer_version);
90 aOpts.representation = static_cast<::occtl_io_vrml_representation_t>(representation);
91 return aOpts;
92 }
93};
94
97inline std::pair<Graph, NodeId> read(const std::string& thePath,
98 const ReadOptions& theOptions = ReadOptions{})
99{
100 ::occtl_graph_t* aRaw = nullptr;
101 ::occtl_node_id_t aRoot{};
102 const ::occtl_io_vrml_read_options_t aOpts = theOptions.to_c();
103 check(::occtl_io_vrml_read(thePath.c_str(), &aRaw, &aRoot, &aOpts));
104 return {Graph(aRaw), NodeId(aRoot)};
105}
106
109inline void write(const Graph& theGraph,
110 const NodeId theRoot,
111 const std::string& thePath,
112 const WriteOptions& theOptions = WriteOptions{})
113{
114 const ::occtl_io_vrml_write_options_t aOpts = theOptions.to_c();
115 check(::occtl_io_vrml_write(theGraph.get(), theRoot.get(), thePath.c_str(), &aOpts));
116}
117
120inline std::pair<Graph, NodeId> read_memory(const std::vector<uint8_t>& theData,
121 const ReadOptions& theOptions = ReadOptions{})
122{
123 ::occtl_graph_t* aRaw = nullptr;
124 ::occtl_node_id_t aRoot{};
125 const ::occtl_io_vrml_read_options_t aOpts = theOptions.to_c();
126 check(::occtl_io_vrml_read_memory(theData.data(), theData.size(), &aRaw, &aRoot, &aOpts));
127 return {Graph(aRaw), NodeId(aRoot)};
128}
129
132inline std::vector<uint8_t> write_memory(const Graph& theGraph,
133 const NodeId theRoot,
134 const WriteOptions& theOptions = WriteOptions{})
135{
136 const ::occtl_io_vrml_write_options_t aOpts = theOptions.to_c();
137 size_t aSize = 0;
138 check(::occtl_io_vrml_write_memory(theGraph.get(), theRoot.get(), &aOpts, nullptr, 0, &aSize));
139 std::vector<uint8_t> aBuffer(aSize);
141 theRoot.get(),
142 &aOpts,
143 aBuffer.data(),
144 aBuffer.size(),
145 &aSize));
146 return aBuffer;
147}
148
149} // namespace occtl::io_vrml
150
151#endif // OCCTL_HPP_IO_VRML_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
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
Representation
VRML output representation.
Definition io_vrml.hpp:53
WriterVersion
VRML writer version.
Definition io_vrml.hpp:46
CoordinateSystem
Coordinate system used by VRML import/export conversion.
Definition io_vrml.hpp:38
OCCT-Light: VRML file I/O.
occtl_status_t occtl_io_vrml_write_memory(const occtl_graph_t *graph, occtl_node_id_t root, const occtl_io_vrml_write_options_t *options, uint8_t *out_data, size_t capacity, size_t *out_size)
@ OCCTL_IO_VRML_WRITER_VERSION_1
Definition occtl_io_vrml.h:58
@ OCCTL_IO_VRML_WRITER_VERSION_2
Definition occtl_io_vrml.h:59
@ OCCTL_IO_VRML_REPRESENTATION_SHADED
Definition occtl_io_vrml.h:68
@ OCCTL_IO_VRML_REPRESENTATION_WIREFRAME
Definition occtl_io_vrml.h:69
@ OCCTL_IO_VRML_REPRESENTATION_BOTH
Definition occtl_io_vrml.h:70
occtl_status_t occtl_io_vrml_read_memory(const uint8_t *data, size_t size, occtl_graph_t **out_graph, occtl_node_id_t *out_root, const occtl_io_vrml_read_options_t *options)
occtl_status_t occtl_io_vrml_read(const char *path, occtl_graph_t **out_graph, occtl_node_id_t *out_root, const occtl_io_vrml_read_options_t *options)
enum occtl_io_vrml_writer_version occtl_io_vrml_writer_version_t
enum occtl_io_vrml_representation occtl_io_vrml_representation_t
enum occtl_io_vrml_coordinate_system occtl_io_vrml_coordinate_system_t
occtl_status_t occtl_io_vrml_write(const occtl_graph_t *graph, occtl_node_id_t root, const char *path, const occtl_io_vrml_write_options_t *options)
@ OCCTL_IO_VRML_COORDINATE_SYSTEM_Z_UP
Definition occtl_io_vrml.h:48
@ OCCTL_IO_VRML_COORDINATE_SYSTEM_GLTF
Definition occtl_io_vrml.h:49
@ OCCTL_IO_VRML_COORDINATE_SYSTEM_Y_UP
Definition occtl_io_vrml.h:47
struct occtl_graph occtl_graph_t
Definition occtl_topo_types.h:152
Options for read. PascalCase mirror of occtl_io_vrml_read_options_t.
Definition io_vrml.hpp:61
Options for write. PascalCase mirror of occtl_io_vrml_write_options_t.
Definition io_vrml.hpp:82
Definition occtl_io_vrml.h:81
occtl_io_vrml_coordinate_system_t system_coordinate_system
Definition occtl_io_vrml.h:86
occtl_io_vrml_coordinate_system_t file_coordinate_system
Definition occtl_io_vrml.h:88
double file_length_unit_m
Definition occtl_io_vrml.h:84
int32_t fill_incomplete
Definition occtl_io_vrml.h:89
Definition occtl_io_vrml.h:104
occtl_io_vrml_representation_t representation
Definition occtl_io_vrml.h:108
occtl_io_vrml_writer_version_t writer_version
Definition occtl_io_vrml.h:107
Definition occtl_topo_types.h:50
C++ veneer for the topo module.