Blender V5.3
mask_rasterize.cc File Reference
#include <algorithm>
#include <numeric>
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "DNA_mask_types.h"
#include "DNA_scene_types.h"
#include "DNA_vec_types.h"
#include "BLI_array.hh"
#include "BLI_delaunay_2d.hh"
#include "BLI_math_geom_c.hh"
#include "BLI_math_vector_c.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_memarena.hh"
#include "BLI_scanfill.hh"
#include "BLI_utildefines.hh"
#include "BLI_vector.hh"
#include "BLI_linklist.hh"
#include "BLI_listbase.hh"
#include "BLI_rect.hh"
#include "BLI_task_c.hh"
#include "BKE_mask.hh"
#include "BLI_strict_flags.hh"

Go to the source code of this file.

Classes

struct  blender::MaskRasterLayer
struct  blender::MaskRasterSplineInfo
struct  blender::MaskRasterHandle
struct  blender::MaskRasterizeBufferData

Namespaces

namespace  blender
 BMesh Iterators.

Macros

#define USE_SCANFILL_EDGE_WORKAROUND
#define SPLINE_RESOL_CAP_PER_PIXEL   2
#define SPLINE_RESOL_CAP_MIN   8
#define SPLINE_RESOL_CAP_MAX   64
#define SF_EDGE_IS_BOUNDARY   0xff
#define SF_KEYINDEX_TEMP_ID   uint(-1)
#define TRI_TERMINATOR_ID   uint(-1)
#define TRI_VERT   uint(-1)
#define FACE_ASSERT(face, vert_max)
#define CALC_CAP_RESOL
#define CALC_CAP_RESOL

Functions

static void blender::rotate_point_v2 (float r_p[2], const float p[2], const float cent[2], const float angle, const float asp[2])
BLI_INLINE uint blender::clampis_uint (const uint v, const uint min, const uint max)
static ScanFillVert * blender::scanfill_vert_add_v2_with_depth (ScanFillContext *sf_ctx, const float co_xy[2], const float co_z)
static uint blender::maskrasterize_layer_fill_open_spline_feather_quads (const MaskRasterSplineInfo *open_spline_ranges, uint open_spline_index, uint *face, const uint vert_num)
static void blender::maskrasterize_spline_differentiate_point_outset (float(*diff_feather_points)[2], float(*diff_points)[2], const uint tot_diff_point, const float ofs, const bool do_test)
static bool blender::isect_aabb_tri_v2 (const float xmin, const float ymin, const float xmax, const float ymax, const float v1[2], const float v2[2], const float v3[2])
static bool blender::layer_bucket_isect_test (const MaskRasterLayer *layer, uint face_index, const uint bucket_x, const uint bucket_y, const float bucket_size_x, const float bucket_size_y)
static void blender::maskrasterize_layer_init_from_mask_layer (MaskRasterLayer *layer, const MaskLayer *masklay)
static void blender::layer_bucket_init_dummy (MaskRasterLayer *layer)
static void blender::layer_bucket_init (MaskRasterLayer *layer, const float pixel_size)
static void blender::maskrasterize_layer_init_scanfill (MaskRasterHandle *mr_handle, MaskLayer *masklay, uint masklay_index, const rctf &default_bounds, const float pixel_size, const float asp_xy[2], const int width, const int height, const bool do_aspect_correct, const bool do_mask_aa, const bool do_feather, MemArena *sf_arena)
static void blender::maskrasterize_layer_init_cdt (MaskRasterHandle *mr_handle, MaskLayer *masklay, uint masklay_index, const rctf &default_bounds, const float pixel_size, const float asp_xy[2], const int width, const int height, const bool do_aspect_correct, const bool do_mask_aa, const bool do_feather)
static float blender::maskrasterize_layer_z_depth_quad (const float pt[2], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
static float blender::maskrasterize_layer_isect (const uint *face, float(*cos)[3], const float dist_orig, const float xy[2])
BLI_INLINE uint blender::layer_bucket_index_from_xy (MaskRasterLayer *layer, const float xy[2])
static float blender::layer_bucket_depth_from_xy (MaskRasterLayer *layer, const float xy[2])
static void blender::maskrasterize_buffer_cb (void *__restrict userdata, const int y, const TaskParallelTLS *__restrict)
Rasterization
MaskRasterHandle * blender::BKE_maskrasterize_handle_new ()
void blender::BKE_maskrasterize_handle_free (MaskRasterHandle *mr_handle)
void blender::BKE_maskrasterize_handle_init (MaskRasterHandle *mr_handle, Mask *mask, int width, int height, bool do_aspect_correct, bool do_mask_aa, bool do_feather)
float blender::BKE_maskrasterize_handle_sample (MaskRasterHandle *mr_handle, const float xy[2])
void blender::BKE_maskrasterize_buffer (MaskRasterHandle *mr_handle, unsigned int width, unsigned int height, float *buffer)
 Rasterize a buffer from a single mask (threaded execution).

Variables

static constexpr int blender::BUCKET_PIXELS_PER_CELL = 8
static CLG_LogRef blender::LOG = {"mask.rasterize"}

Detailed Description

This module exposes a rasterizer that works as a black box - implementation details are confined to this file.

The basic method to access is:

  • create & initialize a handle from a #Mask datablock.
  • execute pixel lookups.
  • free the handle.

This file is admittedly a bit confusticated, in quite few areas speed was chosen over readability, though it is commented - so shouldn't be so hard to see what's going on.

Implementation:

To rasterize the mask its converted into geometry that use a ray-cast for each pixel lookup.

Initially kdopbvh was used but this ended up being too slow.

To gain some extra speed we take advantage of a few shortcuts that can be made rasterizing masks specifically.

  • All triangles are known to be completely white - so no depth check is done on triangle intersection.
  • All quads are known to be feather outlines - the 1 and 0 depths are known by the vertex order in the quad,
  • There is no color - just a value for each mask pixel.
  • The mask spacial structure always maps to space 0-1 on X and Y axis.
  • Bucketing is used to speed up lookups for geometry.

Other Details:

  • used unsigned values all over for some extra speed on some arch's.
  • anti-aliasing is faked, just ensuring at least one pixel feather - avoids oversampling.
  • mask lookups need not be pixel aligned so any sub-pixel values from x/y (0 - 1), can be found. (perhaps masks can be used as a vector texture in 3D later on) Currently, to build the spacial structure we have to calculate the total number of faces ahead of time.

This is getting a bit complicated with the addition of unfilled splines and end capping - If large changes are needed here we would be better off using an iterable BLI_mempool for triangles and converting to a contiguous array afterwards.

Definition in file mask_rasterize.cc.

Macro Definition Documentation

◆ CALC_CAP_RESOL [1/2]

#define CALC_CAP_RESOL
Value:
clampis_uint(uint(len_v2v2(fp_cent, fp_turn) / (pixel_size * SPLINE_RESOL_CAP_PER_PIXEL)), \
#define SPLINE_RESOL_CAP_MAX
#define SPLINE_RESOL_CAP_MIN
#define SPLINE_RESOL_CAP_PER_PIXEL

◆ CALC_CAP_RESOL [2/2]

#define CALC_CAP_RESOL
Value:
clampis_uint(uint(len_v2v2(fp_cent, fp_turn) / (pixel_size * SPLINE_RESOL_CAP_PER_PIXEL)), \

Referenced by blender::maskrasterize_layer_init_cdt(), and blender::maskrasterize_layer_init_scanfill().

◆ FACE_ASSERT

#define FACE_ASSERT ( face,
vert_max )
Value:
{ \
uint *_t = face; \
BLI_assert(_t[0] < vert_max); \
BLI_assert(_t[1] < vert_max); \
BLI_assert(_t[2] < vert_max); \
BLI_assert(_t[3] < vert_max || _t[3] == TRI_VERT); \
UNUSED_VARS_NDEBUG(vert_max); \
} \
(void)0
#define TRI_VERT

Definition at line 105 of file mask_rasterize.cc.

Referenced by blender::maskrasterize_layer_fill_open_spline_feather_quads(), blender::maskrasterize_layer_init_cdt(), and blender::maskrasterize_layer_init_scanfill().

◆ SF_EDGE_IS_BOUNDARY

#define SF_EDGE_IS_BOUNDARY   0xff

Definition at line 96 of file mask_rasterize.cc.

Referenced by blender::maskrasterize_layer_init_scanfill().

◆ SF_KEYINDEX_TEMP_ID

#define SF_KEYINDEX_TEMP_ID   uint(-1)

Definition at line 97 of file mask_rasterize.cc.

Referenced by blender::maskrasterize_layer_init_scanfill().

◆ SPLINE_RESOL_CAP_MAX

#define SPLINE_RESOL_CAP_MAX   64

Definition at line 88 of file mask_rasterize.cc.

◆ SPLINE_RESOL_CAP_MIN

#define SPLINE_RESOL_CAP_MIN   8

Definition at line 87 of file mask_rasterize.cc.

◆ SPLINE_RESOL_CAP_PER_PIXEL

#define SPLINE_RESOL_CAP_PER_PIXEL   2

Definition at line 86 of file mask_rasterize.cc.

◆ TRI_TERMINATOR_ID

#define TRI_TERMINATOR_ID   uint(-1)

◆ TRI_VERT

◆ USE_SCANFILL_EDGE_WORKAROUND

#define USE_SCANFILL_EDGE_WORKAROUND

Definition at line 84 of file mask_rasterize.cc.