Polyhedral-net Splines
Loading...
Searching...
No Matches
PnSpline.hpp
1/* copyright(c)Jorg Peters [jorg.peters@gmail.com] */
2
3#pragma once
4
5#include <vector>
6#include <array>
7#include <string>
8#include <cstdint>
9
10#include "PnSPatch.hpp"
11#include "PnSpline_impl.hpp"
12
13struct Patch;
14extern "C" {
15 struct PnSplineImpl; // opaque handle to impl
16}
17
21
35class PnSpline {
36public:
42 PnSpline();
43
55 PnSpline(std::vector<std::array<double,3>>& controlPoints,
56 std::vector<std::vector<uint32_t>>& controlIndices,
57 bool degRaise = false);
58
63 PnSpline(const PnSpline& other);
64
70 PnSpline& operator=(const PnSpline& other);
71
76 PnSpline(PnSpline&& other) noexcept;
77
83 PnSpline& operator=(PnSpline&& other) noexcept;
84
88 ~PnSpline();
89
101 std::vector<uint32_t> updateControlMesh(
102 std::vector<std::array<double,3>>& updatedControlPoints,
103 std::vector<uint32_t>& updateIndices);
104
108 void degRaise();
109
114 uint32_t numPatches() const;
115
124 PnSPatch getPatch(uint32_t index) const;
125
126private:
129};
130
131
133inline PnSpline::PnSpline() : impl(PnSpline_create_empty()) {}
134
135inline PnSpline::PnSpline(std::vector<std::array<double,3>>& controlPoints,
136 std::vector<std::vector<uint32_t>>& controlIndices,
137 bool degRaise) {
138 std::vector<double> flatPts;
139 flatPts.reserve(controlPoints.size() * 3);
140 for (auto& p : controlPoints) {
141 flatPts.insert(flatPts.end(), {p[0], p[1], p[2]});
142 }
143
144 std::vector<uint32_t> flatIndices;
145 std::vector<uint64_t> faceSizes;
146 for (auto& face : controlIndices) {
147 faceSizes.push_back(face.size());
148 flatIndices.insert(flatIndices.end(), face.begin(), face.end());
149 }
150
151 impl = PnSpline_create_from_points(flatPts.data(), controlPoints.size(),
152 flatIndices.data(), faceSizes.data(), controlIndices.size(),
153 degRaise);
154}
155
156inline PnSpline::PnSpline(const PnSpline& other)
157 : impl(PnSpline_clone(other.impl)) {}
158
159inline PnSpline& PnSpline::operator=(const PnSpline& other) {
160 if (this != &other) {
161 if (impl) PnSpline_destroy(impl);
162 impl = PnSpline_clone(other.impl);
163 }
164 return *this;
165}
166
167inline PnSpline::PnSpline(PnSpline&& other) noexcept : impl(other.impl) {
168 other.impl = nullptr;
169}
170
171inline PnSpline& PnSpline::operator=(PnSpline&& other) noexcept {
172 if (this != &other) {
173 if (impl) PnSpline_destroy(impl);
174 impl = other.impl;
175 other.impl = nullptr;
176 }
177 return *this;
178}
179
181 if (impl) PnSpline_destroy(impl);
182}
183
184
185inline std::vector<uint32_t> PnSpline::updateControlMesh(
186 std::vector<std::array<double,3>>& updatedControlPoints,
187 std::vector<uint32_t>& updateIndices) {
188
189 std::vector<double> flatPts;
190 flatPts.reserve(updatedControlPoints.size() * 3);
191 for (auto& p : updatedControlPoints) {
192 flatPts.insert(flatPts.end(), {p[0], p[1], p[2]});
193 }
194
195 std::vector<uint32_t> outPatchIds(PnSpline_getNumPatches(impl)); // over-allocate
196 uint64_t numUpdated = PnSpline_updateControlMesh(
197 impl, flatPts.data(), updatedControlPoints.size(),
198 updateIndices.data(), updateIndices.size(),
199 outPatchIds.data(), outPatchIds.size());
200
201 outPatchIds.resize(numUpdated);
202 return outPatchIds;
203}
204
205inline void PnSpline::degRaise() { PnSpline_degRaise(impl); }
206
207inline uint32_t PnSpline::numPatches() const {
208 return PnSpline_getNumPatches(impl);
209}
210
211inline PnSPatch PnSpline::getPatch(uint32_t index) const {
212 return PnSPatch(PnSpline_getPatch(impl, index));
213}
Represents a polynomial patch in Bernstein–Bézier form.
Definition PnSPatch.hpp:20
uint32_t numPatches() const
Get the number of patches in this PnSpline.
Definition PnSpline.hpp:207
PnSpline & operator=(const PnSpline &other)
Copy assignment operator.
Definition PnSpline.hpp:159
void degRaise()
Degree raise all patches upto degree 3 for each paramter. Degree greater than 3 will remain unchanged...
Definition PnSpline.hpp:205
PnSPatch getPatch(uint32_t index) const
Access an individual patch by index.
Definition PnSpline.hpp:211
~PnSpline()
Destructor.
Definition PnSpline.hpp:180
PnSplineImpl * impl
Opaque pointer to implementation (PIMPL idiom). This is to ensure binary compatibility.
Definition PnSpline.hpp:128
std::vector< uint32_t > updateControlMesh(std::vector< std::array< double, 3 > > &updatedControlPoints, std::vector< uint32_t > &updateIndices)
Update part of the control mesh.
Definition PnSpline.hpp:185
PnSpline()
Construct an empty PnSpline.
Definition PnSpline.hpp:133
A class representing a Bézier patch.
Definition Patch.hpp:20
Definition PnSpline_impl.cpp:17