Bezier Surface Structure#

struct BezierSurface#

A generic implementation of a cubic bezier surface. In the context of the PhotoshopAPI we use this to evaluate warps stored as cubic bezier surfaces. This struct is specialized for use within Photoshop.

Public Functions

inline BezierSurface(const std::vector<Point2D<double>> &controlPoints, size_t gridWidth, size_t gridHeight, std::optional<std::vector<double>> slices_x = std::nullopt, std::optional<std::vector<double>> slices_y = std::nullopt)#

Constructor that initializes control points, these must be in scanline order. So the points should go as follows:

1 2 3 4 5

6 7 8 9 10 …

inline Point2D<double> bias_uv(double u, double v) const#

Bias a UV coordinate according to the local slices. Is a no-op if the slices are not defined. This should always be done before calling evaluate to get the real UV coordinate.

inline Point2D<double> evaluate(double u, double v) const#

Evaluate any patch at (u, v) based on the subdivisions across x and y. This will return the screen-space coordinate from the given mesh.

If the bezier surface is made up of non-uniform slices (i.e. the bezier isn’t split at .33, .66 etc for a 4x4 bezier) one should use bias_uv() to account for this. In fact because it evaluates to a no-op if that isn’t the case the UV should always first be biased before calling this function.

Parameters:
  • u – The u value to sample the bezier at. This should be from 0-1

  • v – The v value to sample the bezier at. This should be from 0-1

Returns:

The screen-space coordinate for the mesh at the given uv coordinate.

inline QuadMesh<double> mesh(size_t divisions_x, size_t divisions_y, bool move_to_zero) const#

Convert the bezier patch into a mesh by repeatedly calling evaluate for x and y intervals across the surface This function will create a quadrilateral mesh which can be more easily queried for UV coordinates at a given point than the bezier surface itself lending itself to e.g. mesh warps.

Parameters:
  • divisions_x – The resolution across the x division

  • divisions_y – The resolution across the y division

  • move_to_zero – Whether to move the resulting mesh to have its top left coordinate be 0, 0

inline std::vector<std::array<Point2D<double>, 16>> patches() const noexcept#

Get the patches associated with the Bezier surface, these are sorted in scanline order and represent 4x4 cubic bezier patches

inline size_t grid_width() const noexcept#

Get the number of divisions across the x plane.

inline size_t grid_height() const noexcept#

Get the number of divisions across the y plane.