OCCT-Light 0.1
C ABI and C++ veneer for multi-language CAD workflows
Loading...
Searching...
No Matches
io_obj.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_OBJ_HPP
22#define OCCTL_HPP_IO_OBJ_HPP
23
24#include <occtl/occtl_io_obj.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_obj
34{
35
43
46{
47 double file_length_unit_m = 1.0;
48 CoordinateSystem system_coordinate_system = CoordinateSystem::ZUp;
49 CoordinateSystem file_coordinate_system = CoordinateSystem::YUp;
50 bool single_precision = false;
51 bool create_shapes = false;
52 bool fill_incomplete = true;
53 int memory_limit_mib = -1;
54 std::string root_prefix;
55
56 [[nodiscard]] ::occtl_io_obj_read_options_t to_c() const noexcept
57 {
58 ::occtl_io_obj_read_options_t aOpts = OCCTL_IO_OBJ_READ_OPTIONS_INIT;
59 aOpts.file_length_unit_m = file_length_unit_m;
61 static_cast<::occtl_io_obj_coordinate_system_t>(system_coordinate_system);
63 static_cast<::occtl_io_obj_coordinate_system_t>(file_coordinate_system);
64 aOpts.single_precision = single_precision ? 1 : 0;
65 aOpts.create_shapes = create_shapes ? 1 : 0;
66 aOpts.fill_incomplete = fill_incomplete ? 1 : 0;
67 aOpts.memory_limit_mib = memory_limit_mib;
68 aOpts.root_prefix = root_prefix.empty() ? nullptr : root_prefix.c_str();
69 return aOpts;
70 }
71};
72
75{
76 CoordinateSystem system_coordinate_system = CoordinateSystem::ZUp;
77 CoordinateSystem file_coordinate_system = CoordinateSystem::YUp;
78 std::string comment;
79 std::string author;
80
81 [[nodiscard]] ::occtl_io_obj_write_options_t to_c() const noexcept
82 {
83 ::occtl_io_obj_write_options_t aOpts = OCCTL_IO_OBJ_WRITE_OPTIONS_INIT;
85 static_cast<::occtl_io_obj_coordinate_system_t>(system_coordinate_system);
87 static_cast<::occtl_io_obj_coordinate_system_t>(file_coordinate_system);
88 aOpts.comment = comment.empty() ? nullptr : comment.c_str();
89 aOpts.author = author.empty() ? nullptr : author.c_str();
90 return aOpts;
91 }
92};
93
96inline std::pair<Graph, NodeId> read(const std::string& thePath,
97 const ReadOptions& theOptions = ReadOptions{})
98{
99 ::occtl_graph_t* aRaw = nullptr;
100 ::occtl_node_id_t aRoot{};
101 const ::occtl_io_obj_read_options_t aOpts = theOptions.to_c();
102 check(::occtl_io_obj_read(thePath.c_str(), &aRaw, &aRoot, &aOpts));
103 return {Graph(aRaw), NodeId(aRoot)};
104}
105
108inline void write(const Graph& theGraph,
109 const NodeId theRoot,
110 const std::string& thePath,
111 const WriteOptions& theOptions = WriteOptions{})
112{
113 const ::occtl_io_obj_write_options_t aOpts = theOptions.to_c();
114 check(::occtl_io_obj_write(theGraph.get(), theRoot.get(), thePath.c_str(), &aOpts));
115}
116
117} // namespace occtl::io_obj
118
119#endif // OCCTL_HPP_IO_OBJ_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
CoordinateSystem
Coordinate system used by OBJ import/export conversion.
Definition io_obj.hpp:38
OCCT-Light: Wavefront OBJ file I/O.
enum occtl_io_obj_coordinate_system occtl_io_obj_coordinate_system_t
occtl_status_t occtl_io_obj_read(const char *path, occtl_graph_t **out_graph, occtl_node_id_t *out_root, const occtl_io_obj_read_options_t *options)
occtl_status_t occtl_io_obj_write(const occtl_graph_t *graph, occtl_node_id_t root, const char *path, const occtl_io_obj_write_options_t *options)
@ OCCTL_IO_OBJ_COORDINATE_SYSTEM_Y_UP
Definition occtl_io_obj.h:51
@ OCCTL_IO_OBJ_COORDINATE_SYSTEM_Z_UP
Definition occtl_io_obj.h:52
@ OCCTL_IO_OBJ_COORDINATE_SYSTEM_GLTF
Definition occtl_io_obj.h:53
struct occtl_graph occtl_graph_t
Definition occtl_topo_types.h:152
Options for read. PascalCase mirror of occtl_io_obj_read_options_t.
Definition io_obj.hpp:46
Options for write. PascalCase mirror of occtl_io_obj_write_options_t.
Definition io_obj.hpp:75
Definition occtl_io_obj.h:64
double file_length_unit_m
Definition occtl_io_obj.h:67
int32_t create_shapes
Definition occtl_io_obj.h:73
int32_t single_precision
Definition occtl_io_obj.h:72
int32_t fill_incomplete
Definition occtl_io_obj.h:74
occtl_io_obj_coordinate_system_t file_coordinate_system
Definition occtl_io_obj.h:71
int32_t memory_limit_mib
Definition occtl_io_obj.h:75
const char * root_prefix
Definition occtl_io_obj.h:76
occtl_io_obj_coordinate_system_t system_coordinate_system
Definition occtl_io_obj.h:69
Definition occtl_io_obj.h:95
occtl_io_obj_coordinate_system_t file_coordinate_system
Definition occtl_io_obj.h:101
occtl_io_obj_coordinate_system_t system_coordinate_system
Definition occtl_io_obj.h:99
const char * comment
Definition occtl_io_obj.h:102
const char * author
Definition occtl_io_obj.h:103
Definition occtl_topo_types.h:50
C++ veneer for the topo module.