2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2012 Blender Foundation. */
|
2012-06-19 17:29:58 +00:00
|
|
|
|
|
|
|
|
#include "COM_TrackPositionOperation.h"
|
|
|
|
|
|
2022-01-12 18:02:08 +01:00
|
|
|
#include "DNA_defaults.h"
|
|
|
|
|
|
2013-12-22 14:11:10 +11:00
|
|
|
#include "BKE_movieclip.h"
|
|
|
|
|
#include "BKE_node.h"
|
|
|
|
|
#include "BKE_tracking.h"
|
2012-06-19 17:29:58 +00:00
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
namespace blender::compositor {
|
|
|
|
|
|
2020-08-07 15:58:58 +02:00
|
|
|
TrackPositionOperation::TrackPositionOperation()
|
2012-06-19 17:29:58 +00:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
this->add_output_socket(DataType::Value);
|
|
|
|
|
movie_clip_ = nullptr;
|
2021-10-13 23:01:04 +02:00
|
|
|
framenumber_ = 0;
|
2021-10-13 23:01:15 +02:00
|
|
|
tracking_object_name_[0] = 0;
|
|
|
|
|
track_name_[0] = 0;
|
2021-10-13 23:01:04 +02:00
|
|
|
axis_ = 0;
|
|
|
|
|
position_ = CMP_TRACKPOS_ABSOLUTE;
|
2021-10-13 23:01:15 +02:00
|
|
|
relative_frame_ = 0;
|
2021-10-13 23:01:04 +02:00
|
|
|
speed_output_ = false;
|
2021-10-13 23:01:53 +02:00
|
|
|
flags_.is_set_operation = true;
|
2021-08-10 15:24:28 +02:00
|
|
|
is_track_position_calculated_ = false;
|
2012-06-19 17:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void TrackPositionOperation::init_execution()
|
2012-06-19 17:29:58 +00:00
|
|
|
{
|
2021-08-10 15:24:28 +02:00
|
|
|
if (!is_track_position_calculated_) {
|
|
|
|
|
calc_track_position();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TrackPositionOperation::calc_track_position()
|
|
|
|
|
{
|
|
|
|
|
is_track_position_calculated_ = true;
|
2020-11-06 17:49:09 +01:00
|
|
|
MovieTracking *tracking = nullptr;
|
2022-01-12 18:02:08 +01:00
|
|
|
MovieClipUser user = *DNA_struct_default_get(MovieClipUser);
|
2012-07-27 11:07:09 +00:00
|
|
|
MovieTrackingObject *object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-10 15:24:28 +02:00
|
|
|
track_position_ = 0;
|
2021-10-13 23:01:15 +02:00
|
|
|
zero_v2(marker_pos_);
|
|
|
|
|
zero_v2(relative_pos_);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
if (!movie_clip_) {
|
2012-06-19 17:29:58 +00:00
|
|
|
return;
|
2019-04-23 11:21:22 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
tracking = &movie_clip_->tracking;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-13 23:01:04 +02:00
|
|
|
BKE_movieclip_user_set_frame(&user, framenumber_);
|
2021-10-13 23:01:15 +02:00
|
|
|
BKE_movieclip_get_size(movie_clip_, &user, &width_, &height_);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
object = BKE_tracking_object_get_named(tracking, tracking_object_name_);
|
2012-07-27 11:07:09 +00:00
|
|
|
if (object) {
|
|
|
|
|
MovieTrackingTrack *track;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
track = BKE_tracking_track_get_named(tracking, object, track_name_);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-27 11:07:09 +00:00
|
|
|
if (track) {
|
|
|
|
|
MovieTrackingMarker *marker;
|
2021-10-13 23:01:15 +02:00
|
|
|
int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(movie_clip_, framenumber_);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-27 11:07:12 +00:00
|
|
|
marker = BKE_tracking_marker_get(track, clip_framenr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
copy_v2_v2(marker_pos_, marker->pos);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-13 23:01:04 +02:00
|
|
|
if (speed_output_) {
|
2021-10-13 23:01:15 +02:00
|
|
|
int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(movie_clip_,
|
|
|
|
|
relative_frame_);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-02-15 12:43:14 +01:00
|
|
|
marker = BKE_tracking_marker_get_exact(track, relative_clip_framenr);
|
2020-11-06 17:49:09 +01:00
|
|
|
if (marker != nullptr && (marker->flag & MARKER_DISABLED) == 0) {
|
2021-10-13 23:01:15 +02:00
|
|
|
copy_v2_v2(relative_pos_, marker->pos);
|
2015-12-15 13:51:09 +05:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-13 23:01:15 +02:00
|
|
|
copy_v2_v2(relative_pos_, marker_pos_);
|
2015-12-15 13:51:09 +05:00
|
|
|
}
|
2021-10-13 23:01:15 +02:00
|
|
|
if (relative_frame_ < framenumber_) {
|
|
|
|
|
swap_v2_v2(relative_pos_, marker_pos_);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-02-15 12:43:14 +01:00
|
|
|
}
|
2021-10-13 23:01:04 +02:00
|
|
|
else if (position_ == CMP_TRACKPOS_RELATIVE_START) {
|
2012-07-27 11:07:09 +00:00
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-27 11:07:09 +00:00
|
|
|
for (i = 0; i < track->markersnr; i++) {
|
|
|
|
|
marker = &track->markers[i];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-27 11:07:09 +00:00
|
|
|
if ((marker->flag & MARKER_DISABLED) == 0) {
|
2021-10-13 23:01:15 +02:00
|
|
|
copy_v2_v2(relative_pos_, marker->pos);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-27 11:07:09 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-10 11:01:25 +00:00
|
|
|
}
|
2021-10-13 23:01:04 +02:00
|
|
|
else if (position_ == CMP_TRACKPOS_RELATIVE_FRAME) {
|
2021-10-13 23:01:15 +02:00
|
|
|
int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(movie_clip_,
|
|
|
|
|
relative_frame_);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-27 11:07:12 +00:00
|
|
|
marker = BKE_tracking_marker_get(track, relative_clip_framenr);
|
2021-10-13 23:01:15 +02:00
|
|
|
copy_v2_v2(relative_pos_, marker->pos);
|
2012-07-27 11:07:12 +00:00
|
|
|
}
|
2012-07-10 11:01:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-08-10 15:24:28 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
track_position_ = marker_pos_[axis_] - relative_pos_[axis_];
|
2021-10-13 23:01:04 +02:00
|
|
|
if (axis_ == 0) {
|
|
|
|
|
track_position_ *= width_;
|
2021-08-10 15:24:28 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-13 23:01:04 +02:00
|
|
|
track_position_ *= height_;
|
2021-08-10 15:24:28 +02:00
|
|
|
}
|
2012-07-27 11:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void TrackPositionOperation::execute_pixel_sampled(float output[4],
|
|
|
|
|
float /*x*/,
|
|
|
|
|
float /*y*/,
|
|
|
|
|
PixelSampler /*sampler*/)
|
2012-07-27 11:07:09 +00:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
output[0] = marker_pos_[axis_] - relative_pos_[axis_];
|
2012-07-10 11:01:25 +00:00
|
|
|
|
2021-10-13 23:01:04 +02:00
|
|
|
if (axis_ == 0) {
|
|
|
|
|
output[0] *= width_;
|
2019-04-23 11:21:22 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-13 23:01:04 +02:00
|
|
|
output[0] *= height_;
|
2019-04-23 11:21:22 +10:00
|
|
|
}
|
2012-06-19 17:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-10 15:24:28 +02:00
|
|
|
const float *TrackPositionOperation::get_constant_elem()
|
|
|
|
|
{
|
|
|
|
|
if (!is_track_position_calculated_) {
|
|
|
|
|
calc_track_position();
|
|
|
|
|
}
|
|
|
|
|
return &track_position_;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 19:32:49 +02:00
|
|
|
void TrackPositionOperation::determine_canvas(const rcti &preferred_area, rcti &r_area)
|
2012-06-19 17:29:58 +00:00
|
|
|
{
|
2021-09-28 19:32:49 +02:00
|
|
|
r_area = preferred_area;
|
2012-06-19 17:29:58 +00:00
|
|
|
}
|
2021-03-23 17:12:27 +01:00
|
|
|
|
|
|
|
|
} // namespace blender::compositor
|