v0.1.0: 初始工程骨架 — 7模块 40头文件 32源文件 17文档 Apache-2.0
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include "vde/core/point.h"
|
||||
#include <vector>
|
||||
|
||||
namespace vde::curves {
|
||||
|
||||
class BezierCurve {
|
||||
public:
|
||||
explicit BezierCurve(std::vector<Point3D> control_points);
|
||||
|
||||
[[nodiscard]] Point3D evaluate(double t) const;
|
||||
[[nodiscard]] Vector3D derivative(double t, int order = 1) const;
|
||||
[[nodiscard]] int degree() const { return static_cast<int>(cp_.size()) - 1; }
|
||||
[[nodiscard]] std::pair<double, double> domain() const { return {0.0, 1.0}; }
|
||||
[[nodiscard]] const std::vector<Point3D>& control_points() const { return cp_; }
|
||||
|
||||
/// Split at parameter t into two curves
|
||||
[[nodiscard]] std::pair<BezierCurve, BezierCurve> split(double t) const;
|
||||
|
||||
/// Degree elevation
|
||||
[[nodiscard]] BezierCurve degree_elevate(int times = 1) const;
|
||||
|
||||
private:
|
||||
std::vector<Point3D> cp_;
|
||||
};
|
||||
|
||||
} // namespace vde::curves
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "vde/core/point.h"
|
||||
#include <vector>
|
||||
|
||||
namespace vde::curves {
|
||||
|
||||
class BezierSurface {
|
||||
public:
|
||||
BezierSurface(std::vector<std::vector<Point3D>> control_grid);
|
||||
|
||||
[[nodiscard]] Point3D evaluate(double u, double v) const;
|
||||
[[nodiscard]] Vector3D derivative_u(double u, double v) const;
|
||||
[[nodiscard]] Vector3D derivative_v(double u, double v) const;
|
||||
[[nodiscard]] Vector3D normal(double u, double v) const;
|
||||
|
||||
[[nodiscard]] int degree_u() const { return static_cast<int>(cp_.size()) - 1; }
|
||||
[[nodiscard]] int degree_v() const { return static_cast<int>(cp_[0].size()) - 1; }
|
||||
|
||||
private:
|
||||
std::vector<std::vector<Point3D>> cp_;
|
||||
[[nodiscard]] Point3D de_casteljau(double t, const std::vector<Point3D>& pts) const;
|
||||
};
|
||||
|
||||
} // namespace vde::curves
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include "vde/core/point.h"
|
||||
#include <vector>
|
||||
|
||||
namespace vde::curves {
|
||||
|
||||
class BSplineCurve {
|
||||
public:
|
||||
BSplineCurve(std::vector<Point3D> control_points,
|
||||
std::vector<double> knots, int degree);
|
||||
|
||||
[[nodiscard]] Point3D evaluate(double t) const;
|
||||
[[nodiscard]] Vector3D derivative(double t, int order = 1) const;
|
||||
[[nodiscard]] int degree() const { return degree_; }
|
||||
[[nodiscard]] std::pair<double, double> domain() const;
|
||||
[[nodiscard]] const std::vector<Point3D>& control_points() const { return cp_; }
|
||||
[[nodiscard]] const std::vector<double>& knots() const { return knots_; }
|
||||
|
||||
/// Find knot span index for t
|
||||
[[nodiscard]] int find_span(double t) const;
|
||||
|
||||
/// Evaluate basis functions at t
|
||||
[[nodiscard]] std::vector<double> basis_functions(double t, int span = -1) const;
|
||||
|
||||
private:
|
||||
std::vector<Point3D> cp_;
|
||||
std::vector<double> knots_;
|
||||
int degree_;
|
||||
};
|
||||
|
||||
} // namespace vde::curves
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "vde/curves/bspline_curve.h"
|
||||
#include <vector>
|
||||
|
||||
namespace vde::curves {
|
||||
|
||||
class BSplineSurface {
|
||||
public:
|
||||
BSplineSurface(std::vector<std::vector<Point3D>> control_grid,
|
||||
std::vector<double> knots_u, std::vector<double> knots_v,
|
||||
int degree_u, int degree_v);
|
||||
|
||||
[[nodiscard]] Point3D evaluate(double u, double v) const;
|
||||
[[nodiscard]] int degree_u() const { return degree_u_; }
|
||||
[[nodiscard]] int degree_v() const { return degree_v_; }
|
||||
[[nodiscard]] const std::vector<double>& knots_u() const { return knots_u_; }
|
||||
[[nodiscard]] const std::vector<double>& knots_v() const { return knots_v_; }
|
||||
|
||||
private:
|
||||
std::vector<std::vector<Point3D>> cp_;
|
||||
std::vector<double> knots_u_, knots_v_;
|
||||
int degree_u_, degree_v_;
|
||||
};
|
||||
|
||||
} // namespace vde::curves
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include "vde/curves/bspline_curve.h"
|
||||
#include <vector>
|
||||
|
||||
namespace vde::curves {
|
||||
|
||||
class NurbsCurve {
|
||||
public:
|
||||
NurbsCurve(std::vector<Point3D> control_points, std::vector<double> knots,
|
||||
std::vector<double> weights, int degree);
|
||||
|
||||
[[nodiscard]] Point3D evaluate(double t) const;
|
||||
[[nodiscard]] Vector3D derivative(double t, int order = 1) const;
|
||||
[[nodiscard]] int degree() const { return degree_; }
|
||||
[[nodiscard]] std::pair<double, double> domain() const;
|
||||
[[nodiscard]] const std::vector<Point3D>& control_points() const { return cp_; }
|
||||
[[nodiscard]] const std::vector<double>& weights() const { return weights_; }
|
||||
[[nodiscard]] const std::vector<double>& knots() const { return knots_; }
|
||||
|
||||
private:
|
||||
std::vector<Point3D> cp_;
|
||||
std::vector<double> knots_;
|
||||
std::vector<double> weights_;
|
||||
int degree_;
|
||||
};
|
||||
|
||||
} // namespace vde::curves
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "vde/core/point.h"
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
namespace vde::curves {
|
||||
|
||||
/// Tessellate a parametric surface into a triangle mesh
|
||||
/// @param eval Function(u,v) -> Point3D
|
||||
/// @param res_u, res_v Number of samples in u/v directions
|
||||
/// @return Pairs of (vertices, triangle indices)
|
||||
std::pair<std::vector<Point3D>, std::vector<std::array<int, 3>>>
|
||||
tessellate(const std::function<Point3D(double,double)>& eval,
|
||||
int res_u, int res_v);
|
||||
|
||||
} // namespace vde::curves
|
||||
Reference in New Issue
Block a user