Blender V4.3
subpatch.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __SUBD_SUBPATCH_H__
6#define __SUBD_SUBPATCH_H__
7
8#include "util/map.h"
9#include "util/types.h"
10
12
13/* Subpatch */
14
15class Subpatch {
16 public:
17 class Patch *patch; /* Patch this is a subpatch of. */
19
20 struct edge_t {
21 int T;
22 int offset; /* Offset along main edge, interpretation depends on the two flags below. */
23
26
27 struct Edge *edge;
28
29 int get_vert_along_edge(int n) const;
30 };
31
32 /*
33 * eu1
34 * c01 --------- c11
35 * | |
36 * ev0 | | ev1
37 * | |
38 * c00 --------- c10
39 * eu0
40 */
41
42 union {
43 float2 corners[4]; /* UV within patch, clockwise starting from uv (0, 0) towards (0, 1) etc. */
44 struct {
45 float2 c00, c01, c11, c10;
46 };
47 };
48
49 union {
50 edge_t
51 edges[4]; /* Edges of this subpatch, each edge starts at the corner of the same index. */
52 struct {
54 };
55 };
56
57 explicit Subpatch(Patch *patch = nullptr)
58 : patch(patch),
60 c01(make_float2(0.0f, 1.0f)),
61 c11(one_float2()),
62 c10(make_float2(1.0f, 0.0f))
63 {
64 }
65
70
72 {
73 int Mu = max(edge_u0.T, edge_u1.T);
74 int Mv = max(edge_v0.T, edge_v1.T);
75 Mu = max(Mu, 2);
76 Mv = max(Mv, 2);
77 return (Mu - 1) * (Mv - 1);
78 }
79
81 {
82 int Mu = max(edge_u0.T, edge_u1.T);
83 int Mv = max(edge_v0.T, edge_v1.T);
84 Mu = max(Mu, 2);
85 Mv = max(Mv, 2);
86
87 int inner_triangles = (Mu - 2) * (Mv - 2) * 2;
88 int edge_triangles = edge_u0.T + edge_u1.T + edge_v0.T + edge_v1.T + (Mu - 2) * 2 +
89 (Mv - 2) * 2;
90
91 return inner_triangles + edge_triangles;
92 }
93
94 int get_vert_along_edge(int e, int n) const;
95
96 int get_vert_along_grid_edge(int edge, int n) const
97 {
98 int Mu = max(edge_u0.T, edge_u1.T);
99 int Mv = max(edge_v0.T, edge_v1.T);
100 Mu = max(Mu, 2);
101 Mv = max(Mv, 2);
102
103 switch (edge) {
104 case 0:
105 return inner_grid_vert_offset + n * (Mu - 1);
106 case 1:
107 return inner_grid_vert_offset + (Mu - 1) * (Mv - 2) + n;
108 case 2:
109 return inner_grid_vert_offset + ((Mu - 1) * (Mv - 1) - 1) - n * (Mu - 1);
110 case 3:
111 return inner_grid_vert_offset + (Mu - 2) - n;
112 }
113
114 return -1;
115 }
116};
117
118struct Edge {
119 /* Number of segments the edge will be diced into, see DiagSplit paper. */
120 int T;
121
122 /* top is edge adjacent to start, bottom is adjacent to end. */
124
127
130
131 /* Index of the second vert from this edges corner along the edge towards the next corner. */
133
134 /* Vertices on edge are to be stitched. */
136
137 /* Key to match this edge with others to be stitched with.
138 * The ints in the pair are ordered stitching indices */
139 pair<int, int> stitch_edge_key;
140
141 /* Full T along edge (may be larger than T for edges split from ngon edges) */
147
149 : T(0),
150 top(nullptr),
151 bottom(nullptr),
152 top_offset(-1),
153 bottom_offset(-1),
157 end_vert_index(-1),
160 stitch_edge_T(0),
162 {
163 }
164
165 int get_vert_along_edge(int n) const
166 {
167 assert(n >= 0 && n <= T);
168
169 if (n == 0) {
170 return start_vert_index;
171 }
172 else if (n == T) {
173 return end_vert_index;
174 }
175
176 return second_vert_index + n - 1;
177 }
178};
179
181{
182 assert(n >= 0 && n <= T);
183
185 n = offset + n;
186 }
188 n = edge->T - offset - T + n;
189 }
191 n = offset + T - n;
192 }
194 n = edge->T - offset - n;
195 }
196
197 return edge->get_vert_along_edge(n);
198}
199
200inline int Subpatch::get_vert_along_edge(int edge, int n) const
201{
202 return edges[edge].get_vert_along_edge(n);
203}
204
206
207#endif /* __SUBD_SUBPATCH_H__ */
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
int get_vert_along_grid_edge(int edge, int n) const
Definition subpatch.h:96
float2 c11
Definition subpatch.h:45
Subpatch(Patch *patch=nullptr)
Definition subpatch.h:57
int inner_grid_vert_offset
Definition subpatch.h:18
edge_t edge_v1
Definition subpatch.h:53
edge_t edge_u0
Definition subpatch.h:53
float2 c01
Definition subpatch.h:45
class Patch * patch
Definition subpatch.h:17
int calc_num_triangles() const
Definition subpatch.h:80
edge_t edge_u1
Definition subpatch.h:53
Subpatch(Patch *patch, float2 c00, float2 c01, float2 c11, float2 c10)
Definition subpatch.h:66
int calc_num_inner_verts() const
Definition subpatch.h:71
edge_t edge_v0
Definition subpatch.h:53
float2 c10
Definition subpatch.h:45
float2 c00
Definition subpatch.h:45
int get_vert_along_edge(int e, int n) const
Definition subpatch.h:200
#define CCL_NAMESPACE_END
ccl_device_forceinline float2 make_float2(const float x, const float y)
ccl_device_inline float2 one_float2()
Definition math_float2.h:19
CCL_NAMESPACE_BEGIN ccl_device_inline float2 zero_float2()
Definition math_float2.h:14
int stitch_offset
Definition subpatch.h:143
int T
Definition subpatch.h:120
bool bottom_indices_decrease
Definition subpatch.h:126
int second_vert_index
Definition subpatch.h:132
Edge * bottom
Definition subpatch.h:123
Edge()
Definition subpatch.h:148
int stitch_end_vert_index
Definition subpatch.h:146
int start_vert_index
Definition subpatch.h:128
int bottom_offset
Definition subpatch.h:125
Edge * top
Definition subpatch.h:123
int stitch_top_offset
Definition subpatch.h:144
pair< int, int > stitch_edge_key
Definition subpatch.h:139
bool is_stitch_edge
Definition subpatch.h:135
bool top_indices_decrease
Definition subpatch.h:126
int get_vert_along_edge(int n) const
Definition subpatch.h:165
int stitch_edge_T
Definition subpatch.h:142
int top_offset
Definition subpatch.h:125
int stitch_start_vert_index
Definition subpatch.h:145
int end_vert_index
Definition subpatch.h:129
bool sub_edges_created_in_reverse_order
Definition subpatch.h:25
int get_vert_along_edge(int n) const
Definition subpatch.h:180
struct Edge * edge
Definition subpatch.h:27
bool indices_decrease_along_edge
Definition subpatch.h:24
float max