43# define CACHE_PRINTF(...) printf(__VA_ARGS__)
45# define CACHE_PRINTF(...)
54 TracksMap *map = MEM_cnew<TracksMap>(
"TrackingsMap");
60 map->
tracks = MEM_cnew_array<MovieTrackingTrack>(num_tracks,
"TrackingsMap tracks");
90 ListBase tracks = {
nullptr,
nullptr}, new_tracks = {
nullptr,
nullptr};
94 if (!tracking_object) {
99 old_tracks = &tracking_object->
tracks;
107 bool mapped_to_old =
false;
133 mapped_to_old =
true;
137 if (mapped_to_old ==
false) {
162 track->
next = track->
prev =
nullptr;
170 sizeof(track->
name));
175 *old_tracks = new_tracks;
207 const float unified_coords[2],
208 float pixel_coords[2])
210 pixel_coords[0] = unified_coords[0] * frame_width;
211 pixel_coords[1] = unified_coords[1] * frame_height;
215 const float marker_unified_coords[2],
216 float frame_unified_coords[2])
218 frame_unified_coords[0] = marker_unified_coords[0] + marker->
pos[0];
219 frame_unified_coords[1] = marker_unified_coords[1] + marker->
pos[1];
225 const float marker_unified_coords[2],
226 float frame_pixel_coords[2])
229 unified_to_pixel(frame_width, frame_height, frame_pixel_coords, frame_pixel_coords);
235 float frame_pixel[2])
239 frame_width, frame_height, marker, marker->
search_min, frame_pixel);
240 frame_pixel[0] =
int(frame_pixel[0]);
241 frame_pixel[1] =
int(frame_pixel[1]);
246 const float pixel_coords[2],
247 float unified_coords[2])
249 unified_coords[0] = pixel_coords[0] / frame_width;
250 unified_coords[1] = pixel_coords[1] / frame_height;
256 const float marker_unified[2],
257 float search_pixel[2])
259 float frame_pixel[2];
260 float search_origin_frame_pixel[2];
263 frame_width, frame_height, marker, marker_unified, frame_pixel);
265 frame_width, frame_height, marker, search_origin_frame_pixel);
266 sub_v2_v2v2(search_pixel, frame_pixel, search_origin_frame_pixel);
272 const float search_pixel[2],
273 float marker_unified[2])
275 float frame_unified[2];
276 float search_origin_frame_pixel[2];
279 frame_width, frame_height, marker, search_origin_frame_pixel);
280 add_v2_v2v2(frame_unified, search_pixel, search_origin_frame_pixel);
290 double search_pixel_x[5],
291 double search_pixel_y[5])
293 float unified_coords[2];
294 float pixel_coords[2];
297 for (
int i = 0; i < 4; i++) {
299 frame_width, frame_height, marker, marker->
pattern_corners[i], pixel_coords);
300 search_pixel_x[i] = pixel_coords[0] - 0.5f;
301 search_pixel_y[i] = pixel_coords[1] - 0.5f;
305 unified_coords[0] = 0.0f;
306 unified_coords[1] = 0.0f;
309 search_pixel_x[4] = pixel_coords[0] - 0.5f;
310 search_pixel_y[4] = pixel_coords[1] - 0.5f;
316 const double search_pixel_x[5],
317 const double search_pixel_y[5])
319 float marker_unified[2];
320 float search_pixel[2];
323 for (
int i = 0; i < 4; i++) {
324 search_pixel[0] = search_pixel_x[i] + 0.5;
325 search_pixel[1] = search_pixel_y[i] + 0.5;
327 frame_width, frame_height, marker, search_pixel, marker->
pattern_corners[i]);
331 search_pixel[0] = search_pixel_x[4] + 0.5;
332 search_pixel[1] = search_pixel_y[4] + 0.5;
339 for (
int i = 0; i < 4; i++) {
344 marker->
pos[0] += marker_unified[0];
345 marker->
pos[1] += marker_unified[1];
349 const int frame_width,
350 const int frame_height,
351 float r_principal_point_pixel[2])
353 const float frame_center_x =
float(frame_width) / 2;
354 const float frame_center_y =
float(frame_height) / 2;
356 r_principal_point_pixel[0] = frame_center_x + principal_point_normalized[0] * frame_center_x;
357 r_principal_point_pixel[1] = frame_center_y + principal_point_normalized[1] * frame_center_y;
361 const int frame_width,
362 const int frame_height,
363 float r_principal_point_normalized[2])
365 const float frame_center_x =
float(frame_width) / 2;
366 const float frame_center_y =
float(frame_height) / 2;
368 r_principal_point_normalized[0] = (principal_point_pixel[0] - frame_center_x) / frame_center_x;
369 r_principal_point_normalized[1] = (principal_point_pixel[1] - frame_center_y) / frame_center_y;
385 marker_new = *ref_marker;
404 switch (
camera->distortion_model) {
486 const int calibration_width,
487 const int calibration_height,
493 float principal_px[2];
495 camera->principal_point, calibration_width, calibration_height, principal_px);
506 camera_intrinsics_options->
image_width = calibration_width;
507 camera_intrinsics_options->
image_height =
int(calibration_height * aspy);
538 while (a >= 0 && a < track->markersnr) {
539 int next = backwards ? a + 1 : a - 1;
540 bool is_keyframed =
false;
553 if (next_marker ==
nullptr) {
560 if (marker_keyed_fallback ==
nullptr) {
561 marker_keyed_fallback = cur_marker;
565 if (marker_keyed_fallback ==
nullptr) {
566 marker_keyed_fallback = cur_marker;
574 marker_keyed = cur_marker;
582 if (marker_keyed ==
nullptr) {
583 marker_keyed = marker_keyed_fallback;
606 clip = accessor->
clips[clip_index];
627 const size_t num_pixels = size_t(grayscale->
x) * size_t(grayscale->
y);
629 float *rect_float = MEM_cnew_array<float>(num_pixels,
"tracking grayscale image");
630 if (rect_float !=
nullptr) {
633 for (
int i = 0; i < grayscale->
x * grayscale->
y; i++) {
636 rect_float[i] = 0.2126f * pixel[0] + 0.7152f * pixel[1] + 0.0722f * pixel[2];
647 float_image->
width = ibuf->
x;
655 size_t num_total_channels = size_t(ibuf->
x) * size_t(ibuf->
y) * float_image->
channels;
657 float *rect_float = MEM_cnew_array<float>(num_total_channels,
"tracking grayscale image");
658 if (rect_float !=
nullptr) {
661 memcpy(rect_float, float_image->
buffer, num_total_channels *
sizeof(
float));
675 CACHE_PRINTF(
"Calculate new buffer for frame %d\n", frame);
678 if (orig_ibuf ==
nullptr) {
683 if (region !=
nullptr) {
684 int width = region->
max[0] - region->
min[0], height = region->
max[1] - region->
min[1];
690 int clamped_origin_x =
max_ii(
int(region->
min[0]), 0),
691 clamped_origin_y =
max_ii(
int(region->
min[1]), 0);
692 int dst_offset_x = clamped_origin_x -
int(region->
min[0]),
693 dst_offset_y = clamped_origin_y -
int(region->
min[1]);
694 int clamped_width = width - dst_offset_x, clamped_height = height - dst_offset_y;
695 clamped_width =
min_ii(clamped_width, orig_ibuf->
x - clamped_origin_x);
696 clamped_height =
min_ii(clamped_height, orig_ibuf->
y - clamped_origin_y);
715 for (
int y = 0;
y < clamped_height;
y++) {
716 for (
int x = 0;
x < clamped_width;
x++) {
717 int src_x =
x + clamped_origin_x, src_y =
y + clamped_origin_y;
718 int dst_x =
x + dst_offset_x, dst_y =
y + dst_offset_y;
719 int dst_index = (dst_y * width + dst_x) * 4,
720 src_index = (src_y * orig_ibuf->
x + src_x) * 4;
737 final_ibuf = orig_ibuf;
741 if (final_ibuf == orig_ibuf) {
745 orig_ibuf->
x / (1 << downscale),
746 orig_ibuf->
y / (1 << downscale),
755 if (final_ibuf != orig_ibuf) {
770 if (final_ibuf != orig_ibuf) {
774 final_ibuf = grayscale_ibuf;
781 if (final_ibuf == orig_ibuf) {
803 BLI_assert(clip_index >= 0 && clip_index < accessor->num_clips);
814 *destination =
nullptr;
834 float **r_destination,
841 BLI_assert(track_index < accessor->num_tracks);
857 int frame_width, frame_height;
861 const float region_min[2] = {
862 region->
min[0] - marker->
pos[0] * frame_width,
863 region->
min[1] - marker->
pos[1] * frame_height,
865 const float region_max[2] = {
866 region->
max[0] - marker->
pos[0] * frame_width,
867 region->
max[1] - marker->
pos[1] * frame_height,
870 frame_width, frame_height, region_min, region_max, track);
871 *r_width = region->
max[0] - region->
min[0];
872 *r_height = region->
max[1] - region->
min[1];
873 return *r_destination;
878 if (cache_key !=
nullptr) {
879 float *
mask = (
float *)cache_key;
896 accessor->
tracks = MEM_cnew_array<MovieTrackingTrack *>(num_tracks,
"image accessor tracks");
void BKE_movieclip_user_set_frame(struct MovieClipUser *user, int framenr)
void BKE_movieclip_get_size(struct MovieClip *clip, const struct MovieClipUser *user, int *r_width, int *r_height)
float BKE_movieclip_remap_clip_to_scene_frame(const struct MovieClip *clip, float framenr)
struct ImBuf * BKE_movieclip_get_ibuf(struct MovieClip *clip, const struct MovieClipUser *user)
struct MovieTrackingTrack * BKE_tracking_track_duplicate(struct MovieTrackingTrack *track)
struct MovieTrackingObject * BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name)
struct MovieTrackingMarker * BKE_tracking_marker_get(struct MovieTrackingTrack *track, int framenr)
struct MovieTrackingMarker * BKE_tracking_marker_get_exact(struct MovieTrackingTrack *track, int framenr)
void BKE_tracking_track_free(struct MovieTrackingTrack *track)
bool BKE_tracking_track_has_marker_at_frame(struct MovieTrackingTrack *track, int framenr)
struct MovieTrackingObject * BKE_tracking_object_add(struct MovieTracking *tracking, const char *name)
struct MovieTrackingMarker * BKE_tracking_marker_insert(struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker)
#define BLI_assert_msg(a, msg)
bool BLI_ghash_reinsert(GHash *gh, void *key, void *val, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
GHash * BLI_ghash_ptr_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
void BLI_ghash_insert(GHash *gh, void *key, void *val)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
#define STRNCPY(dst, src)
void BLI_uniquename(const struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
void BLI_thread_unlock(int type)
void BLI_thread_lock(int type)
int BLI_system_thread_count(void)
void BLI_spin_init(SpinLock *spin)
void BLI_spin_unlock(SpinLock *spin)
void BLI_spin_lock(SpinLock *spin)
void BLI_spin_end(SpinLock *spin)
#define CTX_DATA_(context, msgid)
#define BLT_I18NCONTEXT_ID_MOVIECLIP
@ MCLIP_PROXY_RENDER_SIZE_FULL
@ TRACK_ALGORITHM_FLAG_USE_MASK
@ TRACKING_DISTORTION_MODEL_DIVISION
@ TRACKING_DISTORTION_MODEL_POLYNOMIAL
@ TRACKING_DISTORTION_MODEL_NUKE
@ TRACKING_DISTORTION_MODEL_BROWN
ImBuf * IMB_dupImBuf(const ImBuf *ibuf1)
void IMB_assign_float_buffer(ImBuf *ibuf, float *buffer_data, ImBufOwnership ownership)
void IMB_rectcpy(ImBuf *dbuf, const ImBuf *sbuf, int destx, int desty, int srcx, int srcy, int width, int height)
void IMB_float_from_rect(ImBuf *ibuf)
bool IMB_scale(ImBuf *ibuf, unsigned int newx, unsigned int newy, IMBScaleFilter filter, bool threaded=true)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its and blue channels(Deprecated)") DefNode(ShaderNode
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void libmv_FrameAccessorDestroy(libmv_FrameAccessor *frame_accessor)
void libmv_frameAccessorgetTransformRun(const libmv_FrameTransform *transform, const libmv_FloatImage *input_image, libmv_FloatImage *output_image)
libmv_FrameAccessor * libmv_FrameAccessorNew(libmv_FrameAccessorUserData *user_data, libmv_GetImageCallback get_image_callback, libmv_ReleaseImageCallback release_image_callback, libmv_GetMaskForTrackCallback get_mask_for_track_callback, libmv_ReleaseMaskCallback release_mask_callback)
struct ImBuf * IMB_allocImBuf(unsigned int, unsigned int, unsigned char, unsigned int)
void IMB_freeImBuf(ImBuf *)
@ LIBMV_DISTORTION_MODEL_POLYNOMIAL
@ LIBMV_DISTORTION_MODEL_NUKE
@ LIBMV_DISTORTION_MODEL_BROWN
@ LIBMV_DISTORTION_MODEL_DIVISION
struct libmv_FrameTransform libmv_FrameTransform
struct libmv_FrameAccessorUserData libmv_FrameAccessorUserData
void libmv_floatImageDestroy(libmv_FloatImage *image)
void MEM_freeN(void *vmemh)
void *(* MEM_dupallocN)(const void *vmemh)
ccl_device_inline float4 mask(const int4 mask, const float4 a)
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
float pattern_corners[4][2]
MovieTrackingMarker * markers
struct MovieTrackingTrack * next
struct MovieTrackingTrack * prev
MovieTrackingCamera camera
struct MovieTrackingTrack ** tracks
struct MovieClip * clips[MAX_ACCESSOR_CLIP]
struct libmv_FrameAccessor * libmv_accessor
char object_name[MAX_NAME]
MovieTrackingTrack * tracks
float * tracking_track_get_mask_for_region(const int frame_width, const int frame_height, const float region_min[2], const float region_max[2], const MovieTrackingTrack *track)
#define MAX_ACCESSOR_CLIP
static void accessor_release_image_callback(libmv_CacheKey cache_key)
static libmv_CacheKey accessor_get_image_callback(libmv_FrameAccessorUserData *user_data, int clip_index, int frame, libmv_InputMode input_mode, int downscale, const libmv_Region *region, const libmv_FrameTransform *transform, float **destination, int *width, int *height, int *channels)
static void pixel_to_unified(int frame_width, int frame_height, const float pixel_coords[2], float unified_coords[2])
static void unified_to_pixel(int frame_width, int frame_height, const float unified_coords[2], float pixel_coords[2])
static libmv_CacheKey accessor_get_mask_for_track_callback(libmv_FrameAccessorUserData *user_data, int clip_index, int frame, int track_index, const libmv_Region *region, float **r_destination, int *r_width, int *r_height)
void tracking_marker_insert_disabled(MovieTrackingTrack *track, const MovieTrackingMarker *ref_marker, bool before, bool overwrite)
static void search_pixel_to_marker_unified(int frame_width, int frame_height, const MovieTrackingMarker *marker, const float search_pixel[2], float marker_unified[2])
int tracks_map_get_size(TracksMap *map)
static ImBuf * accessor_get_preprocessed_ibuf(TrackingImageAccessor *accessor, int clip_index, int frame)
void tracking_principal_point_pixel_to_normalized(const float principal_point_pixel[2], const int frame_width, const int frame_height, float r_principal_point_normalized[2])
static void ibuf_to_float_image(const ImBuf *ibuf, libmv_FloatImage *float_image)
static void marker_unified_to_frame_pixel_coordinates(int frame_width, int frame_height, const MovieTrackingMarker *marker, const float marker_unified_coords[2], float frame_pixel_coords[2])
void tracks_map_free(TracksMap *map)
static void marker_unified_to_search_pixel(int frame_width, int frame_height, const MovieTrackingMarker *marker, const float marker_unified[2], float search_pixel[2])
void tracking_cameraIntrinscisOptionsFromTracking(MovieTracking *tracking, const int calibration_width, const int calibration_height, libmv_CameraIntrinsicsOptions *camera_intrinsics_options)
static ImBuf * make_grayscale_ibuf_copy(ImBuf *ibuf)
void tracking_get_marker_coords_for_tracking(int frame_width, int frame_height, const MovieTrackingMarker *marker, double search_pixel_x[5], double search_pixel_y[5])
TrackingImageAccessor * tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR_CLIP], int num_clips, MovieTrackingTrack **tracks, int num_tracks)
static void distortion_model_parameters_from_options(const libmv_CameraIntrinsicsOptions *camera_intrinsics_options, MovieTrackingCamera *camera)
static void marker_to_frame_unified(const MovieTrackingMarker *marker, const float marker_unified_coords[2], float frame_unified_coords[2])
void tracks_map_insert(TracksMap *map, MovieTrackingTrack *track)
#define CACHE_PRINTF(...)
static ImBuf * float_image_to_ibuf(libmv_FloatImage *float_image)
void tracking_trackingCameraFromIntrinscisOptions(MovieTracking *tracking, const libmv_CameraIntrinsicsOptions *camera_intrinsics_options)
static void distortion_model_parameters_from_tracking(const MovieTrackingCamera *camera, libmv_CameraIntrinsicsOptions *camera_intrinsics_options)
void tracking_image_accessor_destroy(TrackingImageAccessor *accessor)
TracksMap * tracks_map_new(const char *object_name, int num_tracks)
static ImBuf * accessor_get_ibuf(TrackingImageAccessor *accessor, int clip_index, int frame, libmv_InputMode input_mode, int downscale, const libmv_Region *region, const libmv_FrameTransform *transform)
MovieTrackingMarker * tracking_get_keyframed_marker(MovieTrackingTrack *track, int current_frame, bool backwards)
static void accessor_release_mask_callback(libmv_CacheKey cache_key)
void tracking_set_marker_coords_from_tracking(int frame_width, int frame_height, MovieTrackingMarker *marker, const double search_pixel_x[5], const double search_pixel_y[5])
void tracking_get_search_origin_frame_pixel(int frame_width, int frame_height, const MovieTrackingMarker *marker, float frame_pixel[2])
void tracks_map_merge(TracksMap *map, MovieTracking *tracking)
void tracking_principal_point_normalized_to_pixel(const float principal_point_normalized[2], const int frame_width, const int frame_height, float r_principal_point_pixel[2])