Lagrange
Loading...
Searching...
No Matches
AtlasEngine.h
1/*
2 * Copyright 2026 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/SurfaceMesh.h>
15#include <lagrange/xatlas/Options.h>
16#include <lagrange/xatlas/api.h>
17
18#include <memory>
19
20#include <atomic>
21#include <cstddef>
22#include <cstdint>
23#include <functional>
24#include <string>
25#include <string_view>
26
27namespace lagrange::xatlas {
28
46template <typename Scalar, typename Index>
47class AtlasEngine
48{
49public:
50 using Mesh = SurfaceMesh<Scalar, Index>;
51 using NotificationFunc = std::function<void(const std::string&, float)>;
52
53 AtlasEngine();
54 ~AtlasEngine();
55 AtlasEngine(const AtlasEngine&) = delete;
56 AtlasEngine& operator=(const AtlasEngine&) = delete;
57 AtlasEngine(AtlasEngine&&) noexcept;
58 AtlasEngine& operator=(AtlasEngine&&) noexcept;
59
61 void add_mesh(const Mesh& mesh, const UnwrapOptions& options = {});
62
64 void add_uv_mesh(const Mesh& mesh, const RepackOptions& options = {});
65
67 void clear();
68
70 void compute_charts(const ChartOptions& opts = {});
71
73 void pack_charts(const PackOptions& opts);
74
76 void generate(const ChartOptions& chart_opts, const PackOptions& pack_opts);
77
79 void generate(const UnwrapOptions& opts);
80
82 Mesh extract_mesh(
83 size_t mesh_index,
84 MultiAtlasPolicy multi_atlas_policy,
85 std::string_view output_uv_attribute_name,
86 std::string_view output_atlas_attribute_name,
87 std::string_view output_chart_attribute_name) const;
88
90 size_t mesh_count() const;
91
93 uint32_t atlas_width() const;
94
96 uint32_t atlas_height() const;
97
99 uint32_t atlas_count() const;
100
102 uint32_t chart_count() const;
103
105 float texels_per_unit() const;
106
108 float utilization(uint32_t atlas_index) const;
109
111 void set_notification_func(NotificationFunc func);
112
114 void set_cancel(const std::atomic_bool* cancel);
115
116private:
117 struct Impl;
118 std::unique_ptr<Impl> m_impl;
119};
120
121} // namespace lagrange::xatlas
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:73
void set_notification_func(NotificationFunc func)
Set the optional progress callback. xatlas may invoke it from any thread.
Definition AtlasEngine.cpp:409
uint32_t atlas_height() const
Atlas tile height in pixels (0 before pack).
Definition AtlasEngine.cpp:370
float utilization(uint32_t atlas_index) const
Utilization of the given atlas tile (in [0, 1]).
Definition AtlasEngine.cpp:394
void add_uv_mesh(const Mesh &mesh, const RepackOptions &options={})
Add a mesh with existing UVs for repacking only. Throws if any unwrap mesh has been added.
Definition AtlasEngine.cpp:166
void add_mesh(const Mesh &mesh, const UnwrapOptions &options={})
Add a mesh for unwrapping. Throws if any UV-only mesh has already been added.
Definition AtlasEngine.cpp:111
uint32_t atlas_count() const
Number of atlas tiles xatlas produced (0 before pack).
Definition AtlasEngine.cpp:376
void generate(const ChartOptions &chart_opts, const PackOptions &pack_opts)
Convenience: compute_charts() + pack_charts().
Definition AtlasEngine.cpp:309
Mesh extract_mesh(size_t mesh_index, MultiAtlasPolicy multi_atlas_policy, std::string_view output_uv_attribute_name, std::string_view output_atlas_attribute_name, std::string_view output_chart_attribute_name) const
Read back the i-th input mesh with the new UVs applied as an indexed attribute.
Definition AtlasEngine.cpp:324
void pack_charts(const PackOptions &opts)
Pack charts. Valid after compute_charts() (unwrap path) or add_uv_mesh() (repack path).
Definition AtlasEngine.cpp:258
void set_cancel(const std::atomic_bool *cancel)
Set the optional cancellation flag.
Definition AtlasEngine.cpp:415
uint32_t chart_count() const
Total number of charts (0 before chart computation).
Definition AtlasEngine.cpp:382
void clear()
Reset the engine to its initial empty state.
Definition AtlasEngine.cpp:216
uint32_t atlas_width() const
Atlas tile width in pixels (0 before pack).
Definition AtlasEngine.cpp:364
float texels_per_unit() const
Effective texels-per-unit value used by the most recent pack.
Definition AtlasEngine.cpp:388
void compute_charts(const ChartOptions &opts={})
Compute charts. Valid only after at least one add_mesh() call.
Definition AtlasEngine.cpp:222
size_t mesh_count() const
Number of meshes added to the atlas.
Definition AtlasEngine.cpp:358
Definition AtlasEngine.cpp:29
Chart computation options.
Definition Options.h:28
Packing options.
Definition Options.h:71
Options controlling a repack (existing UVs → new packing, no chart computation).
Definition Options.h:168
Options controlling a full unwrap (segment + parameterize + pack).
Definition Options.h:128