Blender V4.3
curveprofile.cc File Reference
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "DNA_curve_types.h"
#include "DNA_curveprofile_types.h"
#include "BLI_math_geom.h"
#include "BLI_math_vector.h"
#include "BLI_rect.h"
#include "BLI_utildefines.h"
#include "BKE_curve.hh"
#include "BKE_curveprofile.h"
#include "BLO_read_write.hh"

Go to the source code of this file.

Classes

struct  CurvatureSortPoint
 

Macros

#define PROF_TABLE_MAX   512
 

Functions

Data Handling
CurveProfileBKE_curveprofile_add (eCurveProfilePresets preset)
 
void BKE_curveprofile_free_data (CurveProfile *profile)
 
void BKE_curveprofile_free (CurveProfile *profile)
 
void BKE_curveprofile_copy_data (CurveProfile *target, const CurveProfile *profile)
 
CurveProfileBKE_curveprofile_copy (const CurveProfile *profile)
 
void BKE_curveprofile_blend_write (BlendWriter *writer, const CurveProfile *profile)
 
void BKE_curveprofile_blend_read (BlendDataReader *reader, CurveProfile *profile)
 
Editing
bool BKE_curveprofile_move_handle (CurveProfilePoint *point, const bool handle_1, const bool snap, const float delta[2])
 
bool BKE_curveprofile_move_point (CurveProfile *profile, CurveProfilePoint *point, const bool snap, const float delta[2])
 
bool BKE_curveprofile_remove_point (CurveProfile *profile, CurveProfilePoint *point)
 
void BKE_curveprofile_remove_by_flag (CurveProfile *profile, const short flag)
 
static void point_init (CurveProfilePoint *point, float x, float y, short flag, char h1, char h2)
 
CurveProfilePointBKE_curveprofile_insert (CurveProfile *profile, float x, float y)
 
void BKE_curveprofile_selected_handle_set (CurveProfile *profile, int type_1, int type_2)
 
static CurveProfilePoint mirror_point (const CurveProfilePoint *point)
 
void BKE_curveprofile_reverse (CurveProfile *profile)
 
static void curveprofile_build_supports (CurveProfile *profile)
 
static void curveprofile_build_steps (CurveProfile *profile)
 
void BKE_curveprofile_reset_view (CurveProfile *profile)
 
void BKE_curveprofile_reset (CurveProfile *profile)
 
Sampling and Evaluation
int BKE_curveprofile_table_size (const CurveProfile *profile)
 
static bool is_curved_edge (CurveProfilePoint *path, int i)
 
static void point_calculate_handle (CurveProfilePoint *point, const CurveProfilePoint *prev, const CurveProfilePoint *next)
 
static void calculate_path_handles (CurveProfilePoint *path, int path_len)
 
static float bezt_edge_handle_angle (const CurveProfilePoint *path, int i_edge)
 
static int sort_points_curvature (const void *in_a, const void *in_b)
 
static void create_samples (CurveProfile *profile, int n_segments, bool sample_straight_edges, CurveProfilePoint *r_samples)
 
void BKE_curveprofile_set_defaults (CurveProfile *profile)
 
void BKE_curveprofile_init (CurveProfile *profile, short segments_len)
 
static float curveprofile_distance_to_next_table_point (const CurveProfile *profile, int i)
 
static float curveprofile_total_length (const CurveProfile *profile)
 
static void create_samples_even_spacing (CurveProfile *profile, int n_segments, CurveProfilePoint *r_samples)
 
static void curveprofile_make_table (CurveProfile *profile)
 
static void curveprofile_make_segments_table (CurveProfile *profile)
 
void BKE_curveprofile_update (CurveProfile *profile, const int update_flags)
 
void BKE_curveprofile_evaluate_length_portion (const CurveProfile *profile, float length_portion, float *x_out, float *y_out)
 

Macro Definition Documentation

◆ PROF_TABLE_MAX

#define PROF_TABLE_MAX   512

Number of points in high resolution table is dynamic up to a maximum.

Definition at line 27 of file curveprofile.cc.

Referenced by BKE_curveprofile_insert(), and BKE_curveprofile_table_size().

Function Documentation

◆ bezt_edge_handle_angle()

static float bezt_edge_handle_angle ( const CurveProfilePoint * path,
int i_edge )
static

Helper function for create_samples. Calculates the angle between the handles on the inside of the edge starting at index i. A larger angle means the edge is more curved.

Parameters
i_edgeThe start index of the edge to calculate the angle for.

Definition at line 630 of file curveprofile.cc.

References angle_v2v2(), and sub_v2_v2v2().

Referenced by create_samples().

◆ BKE_curveprofile_add()

CurveProfile * BKE_curveprofile_add ( eCurveProfilePresets preset)

Returns a pointer to a newly allocated curve profile, using the given preset.

Definition at line 33 of file curveprofile.cc.

References BKE_curveprofile_reset(), BKE_curveprofile_set_defaults(), and BKE_curveprofile_update().

Referenced by blo_do_versions_280(), blo_update_defaults_scene(), init_data(), and scene_init_data().

◆ BKE_curveprofile_blend_read()

void BKE_curveprofile_blend_read ( struct BlendDataReader * reader,
struct CurveProfile * profile )

Expects that the curve profile itself has been read already.

Definition at line 90 of file curveprofile.cc.

References BKE_curveprofile_init(), and BLO_read_struct_array.

Referenced by blend_read(), curve_blend_read_data(), and scene_blend_read_data().

◆ BKE_curveprofile_blend_write()

void BKE_curveprofile_blend_write ( BlendWriter * writer,
const CurveProfile * profile )

Definition at line 84 of file curveprofile.cc.

References BLO_write_struct, and BLO_write_struct_array.

◆ BKE_curveprofile_copy()

CurveProfile * BKE_curveprofile_copy ( const CurveProfile * profile)

Definition at line 74 of file curveprofile.cc.

References BKE_curveprofile_copy_data(), and MEM_dupallocN.

◆ BKE_curveprofile_copy_data()

void BKE_curveprofile_copy_data ( CurveProfile * target,
const CurveProfile * profile )

Definition at line 60 of file curveprofile.cc.

References MEM_dupallocN.

Referenced by BKE_curveprofile_copy().

◆ BKE_curveprofile_evaluate_length_portion()

void BKE_curveprofile_evaluate_length_portion ( const CurveProfile * profile,
float length_portion,
float * x_out,
float * y_out )

◆ BKE_curveprofile_free()

void BKE_curveprofile_free ( CurveProfile * profile)

Definition at line 52 of file curveprofile.cc.

References BKE_curveprofile_free_data(), and MEM_freeN().

Referenced by BKE_toolsettings_free(), curve_free_data(), and free_data().

◆ BKE_curveprofile_free_data()

void BKE_curveprofile_free_data ( CurveProfile * profile)

◆ BKE_curveprofile_init()

void BKE_curveprofile_init ( struct CurveProfile * profile,
short segments_len )

Refreshes the higher resolution table sampled from the input points. A call to this or BKE_curveprofile_update is needed before evaluation functions that use the table. Also sets the number of segments used for the display preview of the locations of the sampled points.

Definition at line 825 of file curveprofile.cc.

References BKE_curveprofile_update(), PROF_DIRTY_PRESET, and PROF_UPDATE_NONE.

Referenced by BKE_curveprofile_blend_read(), and set_profile_spacing().

◆ BKE_curveprofile_insert()

CurveProfilePoint * BKE_curveprofile_insert ( struct CurveProfile * profile,
float x,
float y )

Adds a new point at the specified location. The choice for which points to place the new vertex between is made by checking which control point line segment is closest to the new point and placing the new vertex in between that segment's points.

Note
Requires BKE_curveprofile_update call after.

Definition at line 266 of file curveprofile.cc.

References dist_squared_to_line_segment_v2(), distance(), CurveProfilePoint::flag, FLT_MAX, CurveProfilePoint::h2, HD_AUTO, HD_VECT, MEM_freeN(), MEM_mallocN, point_init(), PROF_SELECT, PROF_TABLE_MAX, CurveProfilePoint::profile, CurveProfilePoint::x, and x.

Referenced by ui_do_but_CURVEPROFILE().

◆ BKE_curveprofile_move_handle()

bool BKE_curveprofile_move_handle ( struct CurveProfilePoint * point,
bool handle_1,
bool snap,
const float delta[2] )

Move a point's handle, accounting for the alignment of handles with the HD_ALIGN type.

Parameters
handle_1Whether to move the 1st or 2nd control point.
deltaThe relative change in the handle's position.
Note
Requires BKE_curveprofile_update call after.
Returns
Whether the handle moved from its start position.

Definition at line 110 of file curveprofile.cc.

References copy_v2_v2(), ELEM, equals_v2v2(), HD_ALIGN, HD_FREE, and snap().

Referenced by BKE_curveprofile_selected_handle_set(), and ui_numedit_but_CURVEPROFILE().

◆ BKE_curveprofile_move_point()

bool BKE_curveprofile_move_point ( struct CurveProfile * profile,
struct CurveProfilePoint * point,
bool snap,
const float delta[2] )

Moves a control point, accounting for clipping and snapping, and moving free handles.

Parameters
snapWhether to snap the point to the grid
deltaThe relative change of the point's location.
Returns
Whether the point moved from its start position.
Note
Requires BKE_curveprofile_update call after.

Definition at line 150 of file curveprofile.cc.

References ELEM, HD_ALIGN, HD_FREE, max_ff(), min_ff(), PROF_USE_CLIP, and snap().

Referenced by ui_numedit_but_CURVEPROFILE().

◆ BKE_curveprofile_remove_by_flag()

void BKE_curveprofile_remove_by_flag ( struct CurveProfile * profile,
short flag )

Removes every point in the widget with the supplied flag set, except for the first and last.

Parameters
flagCurveProfilePoint.flag.
Note
Requires BKE_curveprofile_update call after.

Definition at line 227 of file curveprofile.cc.

References flag, MEM_freeN(), and MEM_mallocN.

Referenced by CurveProfile_buttons_layout(), and ui_do_but_CURVEPROFILE().

◆ BKE_curveprofile_remove_point()

bool BKE_curveprofile_remove_point ( struct CurveProfile * profile,
struct CurveProfilePoint * point )

Removes a specific point from the path of control points.

Note
Requires BKE_curveprofile_update call after.

Definition at line 197 of file curveprofile.cc.

References BLI_assert, int, MEM_freeN(), MEM_mallocN, and point.

Referenced by BKE_curveprofile_update().

◆ BKE_curveprofile_reset()

◆ BKE_curveprofile_reset_view()

void BKE_curveprofile_reset_view ( struct CurveProfile * profile)

Reset the view to the clipping rectangle.

Definition at line 419 of file curveprofile.cc.

Referenced by curve_profile_tools_fn().

◆ BKE_curveprofile_reverse()

void BKE_curveprofile_reverse ( struct CurveProfile * profile)

Flips the profile across the diagonal so that its orientation is reversed.

Note
Requires BKE_curveprofile_update call after.

Definition at line 343 of file curveprofile.cc.

References BLI_assert, ELEM, CurveProfilePoint::h1_loc, CurveProfilePoint::h2_loc, HD_ALIGN, HD_FREE, MEM_freeN(), MEM_mallocN, mirror_point(), and CurveProfilePoint::profile.

Referenced by CurveProfile_buttons_layout().

◆ BKE_curveprofile_selected_handle_set()

void BKE_curveprofile_selected_handle_set ( struct CurveProfile * profile,
int type_1,
int type_2 )

Sets the handle type of the selected control points.

Parameters
type_1,type_2Handle type for the first handle. HD_VECT, HD_AUTO, HD_FREE, or HD_ALIGN.
Note
Requires BKE_curveprofile_update call after.

Definition at line 321 of file curveprofile.cc.

References BKE_curveprofile_move_handle(), ELEM, CurveProfilePoint::h1, HD_ALIGN, PROF_H1_SELECT, PROF_H2_SELECT, and PROF_SELECT.

◆ BKE_curveprofile_set_defaults()

void BKE_curveprofile_set_defaults ( struct CurveProfile * profile)

Sets the default settings and clip range for the profile widget. Does not generate either table.

Definition at line 805 of file curveprofile.cc.

References BLI_rctf_init(), MEM_callocN, and PROF_USE_CLIP.

Referenced by BKE_curveprofile_add().

◆ BKE_curveprofile_table_size()

int BKE_curveprofile_table_size ( const CurveProfile * profile)

◆ BKE_curveprofile_update()

void BKE_curveprofile_update ( struct CurveProfile * profile,
int update_flags )

Should be called after the widget is changed. Does profile and remove double checks and more importantly, recreates the display / evaluation and segments tables.

Parameters
update_flagsBit-field with fields defined in header file. Controls removing doubles and clipping.

Definition at line 968 of file curveprofile.cc.

References BKE_curveprofile_remove_point(), BLI_assert, BLI_rctf_size_x(), BLI_rctf_size_y(), clamp_f(), curveprofile_make_segments_table(), curveprofile_make_table(), len_squared_v2v2(), pow2f(), PROF_UPDATE_CLIP, PROF_UPDATE_REMOVE_DOUBLES, PROF_USE_CLIP, rctf::xmax, rctf::xmin, rctf::ymax, and rctf::ymin.

Referenced by BKE_curveprofile_add(), BKE_curveprofile_init(), curve_profile_presets_fn(), curve_profile_tools_fn(), CurveProfile_buttons_layout(), ui_do_but_CURVEPROFILE(), ui_draw_but_CURVEPROFILE(), and ui_numedit_but_CURVEPROFILE().

◆ calculate_path_handles()

static void calculate_path_handles ( CurveProfilePoint * path,
int path_len )
static

Definition at line 615 of file curveprofile.cc.

References point_calculate_handle().

Referenced by create_samples().

◆ create_samples()

static void create_samples ( CurveProfile * profile,
int n_segments,
bool sample_straight_edges,
CurveProfilePoint * r_samples )
static

Used for sampling curves along the profile's path. Any points more than the number of user-defined points will be evenly distributed among the curved edges. Then the remainders will be distributed to the most curved edges.

Parameters
n_segmentsThe number of segments to sample along the path. Ideally it is higher than the number of points used to define the profile (profile->path_len).
sample_straight_edgesWhether to sample points between vector handle control points. If this is true and there are only vector edges the straight edges will still be sampled.
r_samplesReturn array of points to put the sampled positions. Must have length n_segments. Fill the array with the sampled locations and if the point corresponds to a control point, its handle type.

Definition at line 678 of file curveprofile.cc.

References bezt_edge_handle_angle(), BKE_curve_forward_diff_bezier(), BLI_assert, calculate_path_handles(), CurveProfilePoint::flag, CurveProfilePoint::h1, CurveProfilePoint::h2, HD_AUTO, INT16_MAX, is_curved_edge(), MEM_callocN, MEM_freeN(), CurvatureSortPoint::point_curvature, CurvatureSortPoint::point_index, sort_points_curvature(), and UNUSED_VARS_NDEBUG.

Referenced by curveprofile_make_segments_table(), and curveprofile_make_table().

◆ create_samples_even_spacing()

static void create_samples_even_spacing ( CurveProfile * profile,
int n_segments,
CurveProfilePoint * r_samples )
static

Samples evenly spaced positions along the curve profile's table (generated from path). Fills an entire table at once for a speedup if all of the results are going to be used anyway.

Note
Requires BKE_curveprofile_init or BKE_curveprofile_update call before to fill table.
Working, but would conflict with "Sample Straight Edges" option, so this is unused for now.

Definition at line 871 of file curveprofile.cc.

References BLI_assert, curveprofile_distance_to_next_table_point(), curveprofile_total_length(), interpf(), printf, CurveProfilePoint::x, and CurveProfilePoint::y.

Referenced by curveprofile_make_segments_table().

◆ curveprofile_build_steps()

static void curveprofile_build_steps ( CurveProfile * profile)
static

Puts the widgets control points in a step pattern. Uses vector handles for each point.

Definition at line 396 of file curveprofile.cc.

References float, HD_VECT, and point_init().

Referenced by BKE_curveprofile_reset().

◆ curveprofile_build_supports()

static void curveprofile_build_supports ( CurveProfile * profile)
static

Builds a quarter circle profile with space on each side for 'support loops.'

Definition at line 377 of file curveprofile.cc.

References cosf, HD_AUTO, HD_VECT, M_PI_2, point_init(), and sinf.

Referenced by BKE_curveprofile_reset().

◆ curveprofile_distance_to_next_table_point()

static float curveprofile_distance_to_next_table_point ( const CurveProfile * profile,
int i )
static

Gives the distance to the next point in the widgets sampled table, in other words the length of the 'i' edge of the table.

Note
Requires BKE_curveprofile_init or BKE_curveprofile_update call before to fill table.

Definition at line 842 of file curveprofile.cc.

References BKE_curveprofile_table_size(), BLI_assert, and len_v2v2().

Referenced by BKE_curveprofile_evaluate_length_portion(), and create_samples_even_spacing().

◆ curveprofile_make_segments_table()

static void curveprofile_make_segments_table ( CurveProfile * profile)
static

Creates the table of points used for displaying a preview of the sampled segment locations on the widget itself.

Definition at line 947 of file curveprofile.cc.

References create_samples(), create_samples_even_spacing(), MEM_callocN, MEM_SAFE_FREE, PROF_SAMPLE_EVEN_LENGTHS, and PROF_SAMPLE_STRAIGHT_EDGES.

Referenced by BKE_curveprofile_update().

◆ curveprofile_make_table()

static void curveprofile_make_table ( CurveProfile * profile)
static

Creates a higher resolution table by sampling the curved points. This table is used for display and evenly spaced evaluation.

Definition at line 925 of file curveprofile.cc.

References BKE_curveprofile_table_size(), create_samples(), MEM_callocN, MEM_SAFE_FREE, CurveProfilePoint::x, and CurveProfilePoint::y.

Referenced by BKE_curveprofile_update().

◆ curveprofile_total_length()

static float curveprofile_total_length ( const CurveProfile * profile)
static

Calculates the total length of the profile from the curves sampled in the table.

Note
Requires BKE_curveprofile_init or BKE_curveprofile_update call before to fill table.

Definition at line 854 of file curveprofile.cc.

References BKE_curveprofile_table_size(), and len_v2v2().

Referenced by BKE_curveprofile_evaluate_length_portion(), and create_samples_even_spacing().

◆ is_curved_edge()

static bool is_curved_edge ( CurveProfilePoint * path,
int i )
static

Helper for 'curve_profile_create' samples. Returns whether both handles that make up the edge are vector handles.

Definition at line 535 of file curveprofile.cc.

References HD_VECT.

Referenced by create_samples().

◆ mirror_point()

static CurveProfilePoint mirror_point ( const CurveProfilePoint * point)
static

Definition at line 336 of file curveprofile.cc.

References point, point_init(), and CurveProfilePoint::y.

Referenced by BKE_curveprofile_reverse().

◆ point_calculate_handle()

static void point_calculate_handle ( CurveProfilePoint * point,
const CurveProfilePoint * prev,
const CurveProfilePoint * next )
static

Used to set bezier handle locations in the sample creation process. Reduced copy of calchandleNurb_intern code in curve.cc, mostly changed by removing the third dimension.

Definition at line 544 of file curveprofile.cc.

References HD_AUTO, HD_FREE, HD_VECT, len, len_v2(), madd_v2_v2v2fl(), next, and sub_v2_v2v2().

Referenced by calculate_path_handles().

◆ point_init()

static void point_init ( CurveProfilePoint * point,
float x,
float y,
short flag,
char h1,
char h2 )
static

Shorthand helper function for setting location and interpolation of a point.

Definition at line 257 of file curveprofile.cc.

References flag, CurveProfilePoint::x, x, and y.

Referenced by BKE_curveprofile_insert(), BKE_curveprofile_reset(), curveprofile_build_steps(), curveprofile_build_supports(), and mirror_point().

◆ sort_points_curvature()

static int sort_points_curvature ( const void * in_a,
const void * in_b )
static

Helper function for create_samples for sorting edges based on curvature.

Definition at line 653 of file curveprofile.cc.

References b.

Referenced by create_samples().