Skip to content

Commit

Permalink
Fill: issue of incorrect bound box
Browse files Browse the repository at this point in the history
  • Loading branch information
chsh2 committed Jul 16, 2023
1 parent 539c850 commit ecc7657
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
9 changes: 4 additions & 5 deletions operators/operator_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ def fill_single_frame(line_frame, hint_frame, fill_frame):
# Get points and bound box of line frame
margin_sizes = (0.1, 0.3, 0.5)
corners = [None, None, None, None]
stroke_list = []
for stroke in line_frame.strokes:
stroke_list.append(stroke)
stroke_list = [stroke for stroke in line_frame.strokes]
t_mat, inv_mat = get_transformation_mat(mode=context.scene.nijigp_working_plane,
gp_obj=gp_obj, strokes=stroke_list, operator=self)
for stroke in line_frame.strokes:
for co in (stroke.bound_box_min, stroke.bound_box_max):
bound_points = get_full_bound_box(stroke)
for co in bound_points:
co_2d = t_mat @ co
u, v = co_2d[0], co_2d[1]
corners[0] = u if (not corners[0] or u<corners[0]) else corners[0]
Expand Down Expand Up @@ -207,7 +206,7 @@ def fill_single_frame(line_frame, hint_frame, fill_frame):
if c_key not in label_map:
label_map[c_key] = len(labels_info)
labels_info.append([color, material_idx, use_vertex_color])
hint_points_co.append(np.array(t_mat @ point.co) * scale_factor)
hint_points_co.append((np.array(t_mat @ point.co) * scale_factor)[:2])
hint_points_label.append(label_map[c_key])
solver.set_labels_from_points(hint_points_co, hint_points_label)
solver.propagate_labels()
Expand Down
4 changes: 2 additions & 2 deletions solvers/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def initialize_from_bmesh(self, bm: bmesh.types.BMesh, scale_factor, boundary_ma
v1 = edge.verts[1]
# Frequently used constants that do not change in each iteration
self.graph_coef[(v0.index, v1.index)] = ((v0.co.x - v1.co.x) * (v0[normal_map_layer].x * 2 - 1)
+ (v0.co.y - v1.co.y) * (v0[normal_map_layer].y * 2 - 1)) / scale_factor
+ (v0.co.y - v1.co.y) * (v0[normal_map_layer].y * 2 - 1)) / scale_factor
self.graph_coef[(v1.index, v0.index)] = ((v1.co.x - v0.co.x) * (v1[normal_map_layer].x * 2 - 1)
+ (v1.co.y - v0.co.y) * (v1[normal_map_layer].y * 2 - 1)) / scale_factor
+ (v1.co.y - v0.co.y) * (v1[normal_map_layer].y * 2 - 1)) / scale_factor

def solve(self, max_iter: int):
def cost(z):
Expand Down
22 changes: 11 additions & 11 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ def get_an_inside_co(poly):
delta /= 2
return None

def get_full_bound_box(s):
"""Bpy provides two bound box points for each stroke, but we need all 8 if transformed"""
bound_points = []
for x in (s.bound_box_min.x, s.bound_box_max.x):
for y in (s.bound_box_min.y, s.bound_box_max.y):
for z in (s.bound_box_min.z, s.bound_box_max.z):
bound_points.append(Vector([x,y,z]))
return bound_points

def stroke_bound_box_overlapping(s1, s2, t_mat):
"""Judge if bound boxes of two strokes overlap in any given 2D plane"""

# Bpy provides two bound box points for each stroke, however we need all 8 points
bound_points = []
for s in (s1,s2):
bound_points.append([])
for x in (s.bound_box_min.x, s.bound_box_max.x):
for y in (s.bound_box_min.y, s.bound_box_max.y):
for z in (s.bound_box_min.z, s.bound_box_max.z):
bound_points[-1].append(Vector([x,y,z]))
bound_points = [get_full_bound_box(s1), get_full_bound_box(s2)]
for i in range(2):
for j in range(8):
co_2d = t_mat @ bound_points[i][j]
bound_points[i][j] = co_2d
bound_points[i][j] = t_mat @ bound_points[i][j]
# Check first two axes if strokes overlap on them
bound_points = np.array(bound_points)
for i in range(2):
Expand Down

0 comments on commit ecc7657

Please sign in to comment.