Celenort
Conciencia
게시물 306
오늘 0
주간 0
A site about logging consciousness

[컴선설] Lec 10A C++ code for coons method

LN10A. C++ Code for a Coons Method

1. Code of de Casteljau Algorithm of a Triangular Coons Patch

The algorithm evaluates one coordinate of an $n$th-degree triangular Bézier patch at one barycentric coordinate $(u,v,w)$.

For degree $n$, the number of triangular control points is

\[N_{\mathrm{tri}}=\frac{(n+1)(n+2)}{2}\]

For a cubic triangular net, use the following linear order.

\[\mathbf{b}_{300}, \mathbf{b}_{210}, \mathbf{b}_{201}, \mathbf{b}_{120}, \mathbf{b}_{111}, \mathbf{b}_{102}, \mathbf{b}_{030}, \mathbf{b}_{021}, \mathbf{b}_{012}, \mathbf{b}_{003}\]

void tri_decast(
    double bpts[],
    int tri_num,
    int ndeg,
    double u[3],
    double b[],
    double& patch_pt)
{
    int i, L, m;
    int r;

    // Copy the original control points into the working array.
    for (i = 0; i < tri_num; i++) {
        b[i] = bpts[i];
    }

    // Apply triangular de Casteljau recursion.
    for (r = 1; r <= ndeg; r++) {
        m = -1;

        for (i = 0; i <= ndeg - r; i++) {
            for (L = 0; L <= i; L++) {
                m = m + 1;

                b[m] =
                    u[0] * b[m]
                    + u[1] * b[m + 1 + i]
                    + u[2] * b[m + 2 + i];
            }
        }
    }

    patch_pt = b[0];
}

2. Code of Bilinearly Coons Patch

For four boundary curves, construct the two ruled surfaces and subtract the bilinear corner patch.

\[\mathbf{S}(u,v) = (1-v)\mathbf{b}(u)+v\mathbf{t}(u) +(1-u)\mathbf{l}(v)+u\mathbf{r}(v) -\mathbf{S}_{\mathrm{bilinear}}(u,v)\] \[\begin{aligned} \mathbf{S}_{\mathrm{bilinear}}(u,v) ={}&(1-u)(1-v)\mathbf{p}_{00} +u(1-v)\mathbf{p}_{10}\\ &+(1-u)v\mathbf{p}_{01} +uv\mathbf{p}_{11} \end{aligned}\]
Point bilinearCoons(
    double u,
    double v,
    const Curve& left,
    const Curve& right,
    const Curve& bottom,
    const Curve& top)
{
    Point Su = (1.0 - v) * bottom(u) + v * top(u);
    Point Sv = (1.0 - u) * left(v) + u * right(v);

    Point corner =
        (1.0 - u) * (1.0 - v) * bottom(0.0)
        + u * (1.0 - v) * bottom(1.0)
        + (1.0 - u) * v * top(0.0)
        + u * v * top(1.0);

    return Su + Sv - corner;
}

3. Rectangular Coons Patch

Parameter domain

\[0\le u\le1, \qquad 0\le v\le1\]

Input

  • $u=0$: left boundary
  • $u=1$: right boundary
  • $v=0$: bottom boundary
  • $v=1$: top boundary

Use a matrix represented by a vector of vectors.

std::vector<std::vector<t_point3d>> control_points;

Determine the surface data in the following order.

  1. Four corner control points, which are points on the surface.
  2. Boundary control points.
  3. Inner control points computed by the Coons method.

Shading

  1. Flat shading
    • One normal vector per triangle.
    • Same color over the triangle.
    • Lowest quality and fastest speed.
  2. Gouraud shading
    • One normal vector per vertex.
    • Vertex colors are linearly interpolated over the triangle.
    • Medium quality and medium speed.
  3. Phong shading
    • Interpolate the normal and evaluate lighting at every point.
    • Highest quality and slowest speed.

4. Triangular Coons Patch

Barycentric coordinates

\[u+v+w=1\]

The parameter domain has two degrees of freedom.

Input

  • three boundary curves: $u=0$, $v=0$, and $w=0$,
  • barycentric coordinates satisfying $u+v+w=1$.

Output

  • the inner control points,
  • the completed triangular Bézier control net,
  • a point on the surface after evaluation.
\[N_{\mathrm{control}} = \frac{(n+1)(n+2)}{2}\]

For degree $3$,

\[N_{\mathrm{control}} = \frac{4\cdot5}{2}=10\]

Nine boundary control points are given, so the unknown point is $\mathbf{b}_{111}$.

Construct

  • the $u$ruled boundary patch,
  • the $v$ruled boundary patch,
  • the $w$ruled boundary patch,
  • the $uvw$linear patch.
\[\mathbf{S} = \frac{ \mathbf{S}_{u} +\mathbf{S}_{v} +\mathbf{S}_{w} -\mathbf{S}_{uvw} }{2}\]

The surface normal can be obtained from two directional derivatives.

\[\mathbf{n} = \frac{\mathbf{S}_{u}\times\mathbf{S}_{v}} {\|\mathbf{S}_{u}\times\mathbf{S}_{v}\|}\]

A simpler implementation is

  1. evaluate points on the surface,
  2. approximate tangent vectors by finite differences between neighboring mesh points,
  3. use the cross product, or use flat shading directly.

댓글을 불러오는 중입니다.