tornavis/source/blender/blenkernel/BKE_mask.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

419 lines
16 KiB
C
Raw Normal View History

/* SPDX-FileCopyrightText: 2012 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
2012-06-04 17:45:04 +02:00
#pragma once
/** \file
* \ingroup bke
2013-09-12 05:02:50 +02:00
*/
#ifdef __cplusplus
extern "C" {
#endif
struct Depsgraph;
struct Image;
struct ImageUser;
struct ListBase;
2012-06-04 17:45:04 +02:00
struct Main;
struct Mask;
struct MaskLayer;
struct MaskLayerShape;
struct MaskParent;
2012-06-04 17:45:04 +02:00
struct MaskSpline;
struct MaskSplinePoint;
struct MaskSplinePointUW;
struct MovieClip;
struct MovieClipUser;
/* `mask_ops.cc` */
Implement asymmetric and free handles type for masks Summary: The title actually says it all, it's just possible to have independent free handles for mask splines. Also it's now possible to have aligned handles displayed as independent handles. Required changes in quite a few places, but they're rather straightforward. From user perspective there's one really visible change which is removed Handle Type menu from the panel. With asymmetric handles it's not clear which handle type to display there. So now the only way to change handle type is via V-key menu. Rewrote normal evaluation function to make it deal with new type of handles we support. Now it works in the following way: - Offset the original spline by maximal weight - Calculate vector between corresponding U positions on offset and original spline - Normalize this vector. Seems to be giving more adequate results and doesn't tend to self-intersect as much as old behavior used to, There're still some changes which needed to be done, but which are planned for further patch: - Support colors and handle size via themes. - Make handles color-coded, just the same as done for regular bezier splines in 3D viewport. Additional changes to make roto workflow even better: - Use circles to draw handles - Support AA for handles - Change click-create-drag to change curvature of the spline instead of adjusting point position. Reviewers: campbellbarton CC: sebastian_k, hype, cronk Differential Revision: http://developer.blender.org/D121
2013-10-30 10:38:45 +01:00
typedef enum {
MASK_WHICH_HANDLE_NONE = 0,
MASK_WHICH_HANDLE_STICK = 1,
MASK_WHICH_HANDLE_LEFT = 2,
MASK_WHICH_HANDLE_RIGHT = 3,
MASK_WHICH_HANDLE_BOTH = 4,
} eMaskWhichHandle;
typedef enum {
MASK_HANDLE_MODE_STICK = 1,
MASK_HANDLE_MODE_INDIVIDUAL_HANDLES = 2,
} eMaskhandleMode;
/* -------------------------------------------------------------------- */
/** \name Mask Layers
* \{ */
2012-06-04 17:45:04 +02:00
struct MaskLayer *BKE_mask_layer_new(struct Mask *mask, const char *name);
/**
* \note The returned mask-layer may be hidden, caller needs to check.
*/
2012-06-04 17:45:04 +02:00
struct MaskLayer *BKE_mask_layer_active(struct Mask *mask);
void BKE_mask_layer_active_set(struct Mask *mask, struct MaskLayer *masklay);
void BKE_mask_layer_remove(struct Mask *mask, struct MaskLayer *masklay);
/** \brief Free all animation keys for a mask layer.
*/
void BKE_mask_layer_free_shapes(struct MaskLayer *masklay);
2012-06-04 17:45:04 +02:00
void BKE_mask_layer_free(struct MaskLayer *masklay);
void BKE_mask_layer_free_list(struct ListBase *masklayers);
2012-06-04 17:45:04 +02:00
void BKE_mask_spline_free(struct MaskSpline *spline);
Merge plane track feature from tomato branch This commit includes all the changes made for plane tracker in tomato branch. Movie clip editor changes: - Artist might create a plane track out of multiple point tracks which belongs to the same track (minimum amount of point tracks is 4, maximum is not actually limited). When new plane track is added, it's getting "tracked" across all point tracks, which makes it stick to the same plane point tracks belong to. - After plane track was added, it need to be manually adjusted in a way it covers feature one might to mask/replace. General transform tools (G, R, S) or sliding corners with a mouse could be sued for this. Plane corner which corresponds to left bottom image corner has got X/Y axis on it (red is for X axis, green for Y). - Re-adjusting plane corners makes plane to be "re-tracked" for the frames sequence between current frame and next and previous keyframes. - Kayframes might be removed from the plane, using Shit-X (Marker Delete) operator. However, currently manual re-adjustment or "re-track" trigger is needed. Compositor changes: - Added new node called Plane Track Deform. - User selects which plane track to use (for this he need to select movie clip datablock, object and track names). - Node gets an image input, which need to be warped into the plane. - Node outputs: * Input image warped into the plane. * Plane, rasterized to a mask. Masking changes: - Mask points might be parented to a plane track, which makes this point deforming in a way as if it belongs to the tracked plane. Some video tutorials are available: - Coder video: http://www.youtube.com/watch?v=vISEwqNHqe4 - Artist video: https://vimeo.com/71727578 This is mine and Keir's holiday code project :)
2013-08-16 11:46:30 +02:00
void BKE_mask_spline_free_list(struct ListBase *splines);
struct MaskSpline *BKE_mask_spline_copy(const struct MaskSpline *spline);
2012-06-04 17:45:04 +02:00
void BKE_mask_point_free(struct MaskSplinePoint *point);
void BKE_mask_layer_unique_name(struct Mask *mask, struct MaskLayer *masklay);
void BKE_mask_layer_rename(struct Mask *mask,
struct MaskLayer *masklay,
2024-04-03 01:22:05 +02:00
const char *oldname,
const char *newname);
2012-06-04 17:45:04 +02:00
struct MaskLayer *BKE_mask_layer_copy(const struct MaskLayer *masklay);
void BKE_mask_layer_copy_list(struct ListBase *masklayers_new, const struct ListBase *masklayers);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Splines
* \{ */
struct MaskSplinePoint *BKE_mask_spline_point_array(struct MaskSpline *spline);
struct MaskSplinePoint *BKE_mask_spline_point_array_from_point(
struct MaskSpline *spline, const struct MaskSplinePoint *point_ref);
2012-06-04 17:45:04 +02:00
struct MaskSpline *BKE_mask_spline_add(struct MaskLayer *masklay);
bool BKE_mask_spline_remove(struct MaskLayer *mask_layer, struct MaskSpline *spline);
2012-06-04 17:45:04 +02:00
void BKE_mask_point_direction_switch(struct MaskSplinePoint *point);
void BKE_mask_spline_direction_switch(struct MaskLayer *masklay, struct MaskSpline *spline);
struct BezTriple *BKE_mask_spline_point_next_bezt(struct MaskSpline *spline,
struct MaskSplinePoint *points_array,
struct MaskSplinePoint *point);
typedef enum {
MASK_PROJ_NEG = -1,
MASK_PROJ_ANY = 0,
MASK_PROJ_POS = 1,
} eMaskSign;
float BKE_mask_spline_project_co(struct MaskSpline *spline,
struct MaskSplinePoint *point,
float start_u,
const float co[2],
eMaskSign sign);
2012-06-04 17:45:04 +02:00
/** \} */
/* -------------------------------------------------------------------- */
/** \name Point
* \{ */
eMaskhandleMode BKE_mask_point_handles_mode_get(const struct MaskSplinePoint *point);
void BKE_mask_point_handle(const struct MaskSplinePoint *point,
Implement asymmetric and free handles type for masks Summary: The title actually says it all, it's just possible to have independent free handles for mask splines. Also it's now possible to have aligned handles displayed as independent handles. Required changes in quite a few places, but they're rather straightforward. From user perspective there's one really visible change which is removed Handle Type menu from the panel. With asymmetric handles it's not clear which handle type to display there. So now the only way to change handle type is via V-key menu. Rewrote normal evaluation function to make it deal with new type of handles we support. Now it works in the following way: - Offset the original spline by maximal weight - Calculate vector between corresponding U positions on offset and original spline - Normalize this vector. Seems to be giving more adequate results and doesn't tend to self-intersect as much as old behavior used to, There're still some changes which needed to be done, but which are planned for further patch: - Support colors and handle size via themes. - Make handles color-coded, just the same as done for regular bezier splines in 3D viewport. Additional changes to make roto workflow even better: - Use circles to draw handles - Support AA for handles - Change click-create-drag to change curvature of the spline instead of adjusting point position. Reviewers: campbellbarton CC: sebastian_k, hype, cronk Differential Revision: http://developer.blender.org/D121
2013-10-30 10:38:45 +01:00
eMaskWhichHandle which_handle,
float r_handle[2]);
Implement asymmetric and free handles type for masks Summary: The title actually says it all, it's just possible to have independent free handles for mask splines. Also it's now possible to have aligned handles displayed as independent handles. Required changes in quite a few places, but they're rather straightforward. From user perspective there's one really visible change which is removed Handle Type menu from the panel. With asymmetric handles it's not clear which handle type to display there. So now the only way to change handle type is via V-key menu. Rewrote normal evaluation function to make it deal with new type of handles we support. Now it works in the following way: - Offset the original spline by maximal weight - Calculate vector between corresponding U positions on offset and original spline - Normalize this vector. Seems to be giving more adequate results and doesn't tend to self-intersect as much as old behavior used to, There're still some changes which needed to be done, but which are planned for further patch: - Support colors and handle size via themes. - Make handles color-coded, just the same as done for regular bezier splines in 3D viewport. Additional changes to make roto workflow even better: - Use circles to draw handles - Support AA for handles - Change click-create-drag to change curvature of the spline instead of adjusting point position. Reviewers: campbellbarton CC: sebastian_k, hype, cronk Differential Revision: http://developer.blender.org/D121
2013-10-30 10:38:45 +01:00
void BKE_mask_point_set_handle(struct MaskSplinePoint *point,
eMaskWhichHandle which_handle,
float loc[2],
bool keep_direction,
2012-06-04 17:45:04 +02:00
float orig_handle[2],
float orig_vec[3][3]);
2012-06-04 17:45:04 +02:00
void BKE_mask_point_segment_co(struct MaskSpline *spline,
struct MaskSplinePoint *point,
float u,
float co[2]);
void BKE_mask_point_normal(struct MaskSpline *spline,
struct MaskSplinePoint *point,
float u,
float n[2]);
float BKE_mask_point_weight_scalar(struct MaskSpline *spline,
struct MaskSplinePoint *point,
float u);
float BKE_mask_point_weight(struct MaskSpline *spline, struct MaskSplinePoint *point, float u);
2012-06-04 17:45:04 +02:00
struct MaskSplinePointUW *BKE_mask_point_sort_uw(struct MaskSplinePoint *point,
struct MaskSplinePointUW *uw);
void BKE_mask_point_add_uw(struct MaskSplinePoint *point, float u, float w);
void BKE_mask_point_select_set(struct MaskSplinePoint *point, bool do_select);
Implement asymmetric and free handles type for masks Summary: The title actually says it all, it's just possible to have independent free handles for mask splines. Also it's now possible to have aligned handles displayed as independent handles. Required changes in quite a few places, but they're rather straightforward. From user perspective there's one really visible change which is removed Handle Type menu from the panel. With asymmetric handles it's not clear which handle type to display there. So now the only way to change handle type is via V-key menu. Rewrote normal evaluation function to make it deal with new type of handles we support. Now it works in the following way: - Offset the original spline by maximal weight - Calculate vector between corresponding U positions on offset and original spline - Normalize this vector. Seems to be giving more adequate results and doesn't tend to self-intersect as much as old behavior used to, There're still some changes which needed to be done, but which are planned for further patch: - Support colors and handle size via themes. - Make handles color-coded, just the same as done for regular bezier splines in 3D viewport. Additional changes to make roto workflow even better: - Use circles to draw handles - Support AA for handles - Change click-create-drag to change curvature of the spline instead of adjusting point position. Reviewers: campbellbarton CC: sebastian_k, hype, cronk Differential Revision: http://developer.blender.org/D121
2013-10-30 10:38:45 +01:00
void BKE_mask_point_select_set_handle(struct MaskSplinePoint *point,
eMaskWhichHandle which_handle,
bool do_select);
2012-06-04 17:45:04 +02:00
/** \} */
/* -------------------------------------------------------------------- */
/** \name General
* \{ */
struct Mask *BKE_mask_new(struct Main *bmain, const char *name);
2012-06-04 17:45:04 +02:00
void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]);
void BKE_mask_coord_from_movieclip(struct MovieClip *clip,
struct MovieClipUser *user,
float r_co[2],
const float co[2]);
void BKE_mask_coord_from_image(struct Image *image,
struct ImageUser *iuser,
float r_co[2],
const float co[2]);
/**
* Inverse of #BKE_mask_coord_from_image.
*/
void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2]);
void BKE_mask_coord_to_movieclip(struct MovieClip *clip,
struct MovieClipUser *user,
float r_co[2],
const float co[2]);
void BKE_mask_coord_to_image(struct Image *image,
struct ImageUser *iuser,
float r_co[2],
const float co[2]);
2012-06-04 17:45:04 +02:00
/** \} */
/* -------------------------------------------------------------------- */
/** \name Parenting
* \{ */
2012-06-04 17:45:04 +02:00
void BKE_mask_evaluate(struct Mask *mask, float ctime, bool do_newframe);
void BKE_mask_layer_evaluate(struct MaskLayer *masklay, float ctime, bool do_newframe);
2012-06-04 17:45:04 +02:00
void BKE_mask_parent_init(struct MaskParent *parent);
2012-06-06 22:05:58 +02:00
void BKE_mask_calc_handle_adjacent_interp(struct MaskSpline *spline,
struct MaskSplinePoint *point,
float u);
/**
* Calculates the tangent of a point by its previous and next
* (ignoring handles - as if its a poly line).
*/
2012-06-06 22:05:58 +02:00
void BKE_mask_calc_tangent_polyline(struct MaskSpline *spline,
struct MaskSplinePoint *point,
float t[2]);
void BKE_mask_calc_handle_point(struct MaskSpline *spline, struct MaskSplinePoint *point);
/**
* \brief Resets auto handles even for non-auto bezier points
*
* Useful for giving sane defaults.
*/
2012-06-06 22:05:58 +02:00
void BKE_mask_calc_handle_point_auto(struct MaskSpline *spline,
struct MaskSplinePoint *point,
bool do_recalc_length);
2012-06-06 22:05:58 +02:00
void BKE_mask_get_handle_point_adjacent(struct MaskSpline *spline,
struct MaskSplinePoint *point,
2012-06-04 17:45:04 +02:00
struct MaskSplinePoint **r_point_prev,
struct MaskSplinePoint **r_point_next);
void BKE_mask_layer_calc_handles(struct MaskLayer *masklay);
2012-06-04 17:45:04 +02:00
void BKE_mask_spline_ensure_deform(struct MaskSpline *spline);
void BKE_mask_point_parent_matrix_get(struct MaskSplinePoint *point,
float ctime,
float parent_matrix[3][3]);
2012-06-04 17:45:04 +02:00
/** \} */
/* -------------------------------------------------------------------- */
/** \name Animation
* \{ */
2012-06-04 17:45:04 +02:00
int BKE_mask_layer_shape_totvert(struct MaskLayer *masklay);
/**
* Inverse of #BKE_mask_layer_shape_to_mask
*/
2012-06-04 17:45:04 +02:00
void BKE_mask_layer_shape_from_mask(struct MaskLayer *masklay,
struct MaskLayerShape *masklay_shape);
/**
* Inverse of #BKE_mask_layer_shape_from_mask
*/
2012-06-04 17:45:04 +02:00
void BKE_mask_layer_shape_to_mask(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape);
/**
* \note Linear interpolation only.
*/
2012-06-04 17:45:04 +02:00
void BKE_mask_layer_shape_to_mask_interp(struct MaskLayer *masklay,
struct MaskLayerShape *masklay_shape_a,
struct MaskLayerShape *masklay_shape_b,
float fac);
struct MaskLayerShape *BKE_mask_layer_shape_find_frame(struct MaskLayer *masklay, int frame);
/**
* When returning 2 - the frame isn't found but before/after frames are.
*/
int BKE_mask_layer_shape_find_frame_range(struct MaskLayer *masklay,
float frame,
2012-06-04 17:45:04 +02:00
struct MaskLayerShape **r_masklay_shape_a,
struct MaskLayerShape **r_masklay_shape_b);
/**
* \note Does *not* add to the list.
*/
struct MaskLayerShape *BKE_mask_layer_shape_alloc(struct MaskLayer *masklay, int frame);
void BKE_mask_layer_shape_free(struct MaskLayerShape *masklay_shape);
struct MaskLayerShape *BKE_mask_layer_shape_verify_frame(struct MaskLayer *masklay, int frame);
struct MaskLayerShape *BKE_mask_layer_shape_duplicate(struct MaskLayerShape *masklay_shape);
void BKE_mask_layer_shape_unlink(struct MaskLayer *masklay, struct MaskLayerShape *masklay_shape);
2012-06-04 17:45:04 +02:00
void BKE_mask_layer_shape_sort(struct MaskLayer *masklay);
bool BKE_mask_layer_shape_spline_from_index(struct MaskLayer *masklay,
int index,
2012-06-04 17:45:04 +02:00
struct MaskSpline **r_masklay_shape,
int *r_index);
int BKE_mask_layer_shape_spline_to_index(struct MaskLayer *masklay, struct MaskSpline *spline);
/**
* When a new points added, resizing all shape-key arrays.
*/
2012-06-04 17:45:04 +02:00
void BKE_mask_layer_shape_changed_add(struct MaskLayer *masklay,
int index,
bool do_init,
bool do_init_interpolate);
2012-06-04 17:45:04 +02:00
/**
* Move array elements to account for removed point.
*/
2012-06-04 17:45:04 +02:00
void BKE_mask_layer_shape_changed_remove(struct MaskLayer *masklay, int index, int count);
2012-06-07 20:24:36 +02:00
int BKE_mask_get_duration(struct Mask *mask);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Clipboard
* \{ */
/**
* Free the clipboard.
*/
void BKE_mask_clipboard_free(void);
/**
* Copy selected visible splines from the given layer to clipboard.
*/
void BKE_mask_clipboard_copy_from_layer(struct MaskLayer *mask_layer);
/**
* Check clipboard is empty.
*/
bool BKE_mask_clipboard_is_empty(void);
/**
* Paste the contents of clipboard to given mask layer.
*/
void BKE_mask_clipboard_paste_to_layer(struct Main *bmain, struct MaskLayer *mask_layer);
#define MASKPOINT_ISSEL_ANY(p) ((((p)->bezt.f1 | (p)->bezt.f2 | (p)->bezt.f3) & SELECT) != 0)
#define MASKPOINT_ISSEL_KNOT(p) (((p)->bezt.f2 & SELECT) != 0)
Implement asymmetric and free handles type for masks Summary: The title actually says it all, it's just possible to have independent free handles for mask splines. Also it's now possible to have aligned handles displayed as independent handles. Required changes in quite a few places, but they're rather straightforward. From user perspective there's one really visible change which is removed Handle Type menu from the panel. With asymmetric handles it's not clear which handle type to display there. So now the only way to change handle type is via V-key menu. Rewrote normal evaluation function to make it deal with new type of handles we support. Now it works in the following way: - Offset the original spline by maximal weight - Calculate vector between corresponding U positions on offset and original spline - Normalize this vector. Seems to be giving more adequate results and doesn't tend to self-intersect as much as old behavior used to, There're still some changes which needed to be done, but which are planned for further patch: - Support colors and handle size via themes. - Make handles color-coded, just the same as done for regular bezier splines in 3D viewport. Additional changes to make roto workflow even better: - Use circles to draw handles - Support AA for handles - Change click-create-drag to change curvature of the spline instead of adjusting point position. Reviewers: campbellbarton CC: sebastian_k, hype, cronk Differential Revision: http://developer.blender.org/D121
2013-10-30 10:38:45 +01:00
#define MASKPOINT_ISSEL_HANDLE(point, which_handle) \
((((which_handle) == MASK_WHICH_HANDLE_STICK) ? \
((((point)->bezt.f1 | (point)->bezt.f3) & SELECT)) : \
(((which_handle) == MASK_WHICH_HANDLE_LEFT) ? ((point)->bezt.f1 & SELECT) : \
((point)->bezt.f3 & SELECT))) != 0)
2012-06-04 17:45:04 +02:00
#define MASKPOINT_SEL_ALL(p) \
{ \
(p)->bezt.f1 |= SELECT; \
(p)->bezt.f2 |= SELECT; \
(p)->bezt.f3 |= SELECT; \
} \
(void)0
#define MASKPOINT_DESEL_ALL(p) \
{ \
(p)->bezt.f1 &= ~SELECT; \
(p)->bezt.f2 &= ~SELECT; \
(p)->bezt.f3 &= ~SELECT; \
} \
(void)0
#define MASKPOINT_INVSEL_ALL(p) \
{ \
(p)->bezt.f1 ^= SELECT; \
(p)->bezt.f2 ^= SELECT; \
(p)->bezt.f3 ^= SELECT; \
} \
(void)0
/** \} */
/* -------------------------------------------------------------------- */
/** \name Evaluation
* \{ */
#define MASK_RESOL_MAX 128
/* `mask_evaluate.cc` */
int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height);
unsigned int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width, int height);
int BKE_mask_spline_differentiate_calc_total(const struct MaskSpline *spline, unsigned int resol);
float (*BKE_mask_spline_differentiate_with_resolution(struct MaskSpline *spline,
unsigned int resol,
unsigned int *r_tot_diff_point))[2];
2013-05-08 14:54:47 +02:00
void BKE_mask_spline_feather_collapse_inner_loops(struct MaskSpline *spline,
float (*feather_points)[2],
unsigned int tot_feather_point);
float (*BKE_mask_spline_differentiate(
struct MaskSpline *spline, int width, int height, unsigned int *r_tot_diff_point))[2];
/**
* values align with #BKE_mask_spline_differentiate_with_resolution
* when \a resol arguments match.
*/
float (*BKE_mask_spline_feather_differentiated_points_with_resolution(
struct MaskSpline *spline,
unsigned int resol,
bool do_feather_isect,
unsigned int *r_tot_feather_point))[2];
/* *** mask point functions which involve evaluation *** */
float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2];
float *BKE_mask_point_segment_diff(struct MaskSpline *spline,
struct MaskSplinePoint *point,
int width,
int height,
unsigned int *r_tot_diff_point);
/* *** mask point functions which involve evaluation *** */
float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline,
struct MaskSplinePoint *point,
int width,
int height,
unsigned int *tot_feather_point);
void BKE_mask_layer_evaluate_animation(struct MaskLayer *masklay, float ctime);
void BKE_mask_layer_evaluate_deform(struct MaskLayer *masklay, float ctime);
void BKE_mask_eval_animation(struct Depsgraph *depsgraph, struct Mask *mask);
void BKE_mask_eval_update(struct Depsgraph *depsgraph, struct Mask *mask);
/** \} */
/* -------------------------------------------------------------------- */
/** \name Rasterization
* \{ */
/* `mask_rasterize.cc` */
struct MaskRasterHandle;
typedef struct MaskRasterHandle MaskRasterHandle;
2012-07-16 10:53:11 +02:00
MaskRasterHandle *BKE_maskrasterize_handle_new(void);
void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle);
void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
struct Mask *mask,
int width,
int height,
bool do_aspect_correct,
bool do_mask_aa,
bool do_feather);
2012-07-16 10:53:11 +02:00
float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2]);
/**
* \brief Rasterize a buffer from a single mask (threaded execution).
*/
void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
unsigned int width,
unsigned int height,
float *buffer);
/** \} */
#ifdef __cplusplus
}
#endif