Blender  V2.93
COM_TrackPositionOperation.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2012, Blender Foundation.
17  */
18 
20 
21 #include "MEM_guardedalloc.h"
22 
23 #include "BLI_listbase.h"
24 #include "BLI_math.h"
25 #include "BLI_math_color.h"
26 
27 #include "BKE_movieclip.h"
28 #include "BKE_node.h"
29 #include "BKE_tracking.h"
30 
31 namespace blender::compositor {
32 
34 {
36  this->m_movieClip = nullptr;
37  this->m_framenumber = 0;
38  this->m_trackingObjectName[0] = 0;
39  this->m_trackName[0] = 0;
40  this->m_axis = 0;
42  this->m_relativeFrame = 0;
43  this->m_speed_output = false;
44  flags.is_set_operation = true;
45 }
46 
48 {
49  MovieTracking *tracking = nullptr;
50  MovieClipUser user = {0};
51  MovieTrackingObject *object;
52 
53  zero_v2(this->m_markerPos);
54  zero_v2(this->m_relativePos);
55 
56  if (!this->m_movieClip) {
57  return;
58  }
59 
60  tracking = &this->m_movieClip->tracking;
61 
63  BKE_movieclip_get_size(this->m_movieClip, &user, &this->m_width, &this->m_height);
64 
65  object = BKE_tracking_object_get_named(tracking, this->m_trackingObjectName);
66  if (object) {
67  MovieTrackingTrack *track;
68 
69  track = BKE_tracking_track_get_named(tracking, object, this->m_trackName);
70 
71  if (track) {
72  MovieTrackingMarker *marker;
74  this->m_framenumber);
75 
76  marker = BKE_tracking_marker_get(track, clip_framenr);
77 
78  copy_v2_v2(this->m_markerPos, marker->pos);
79 
80  if (this->m_speed_output) {
81  int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip,
82  this->m_relativeFrame);
83 
84  marker = BKE_tracking_marker_get_exact(track, relative_clip_framenr);
85  if (marker != nullptr && (marker->flag & MARKER_DISABLED) == 0) {
86  copy_v2_v2(this->m_relativePos, marker->pos);
87  }
88  else {
89  copy_v2_v2(this->m_relativePos, this->m_markerPos);
90  }
91  if (this->m_relativeFrame < this->m_framenumber) {
92  swap_v2_v2(this->m_relativePos, this->m_markerPos);
93  }
94  }
95  else if (this->m_position == CMP_TRACKPOS_RELATIVE_START) {
96  int i;
97 
98  for (i = 0; i < track->markersnr; i++) {
99  marker = &track->markers[i];
100 
101  if ((marker->flag & MARKER_DISABLED) == 0) {
102  copy_v2_v2(this->m_relativePos, marker->pos);
103 
104  break;
105  }
106  }
107  }
108  else if (this->m_position == CMP_TRACKPOS_RELATIVE_FRAME) {
109  int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip,
110  this->m_relativeFrame);
111 
112  marker = BKE_tracking_marker_get(track, relative_clip_framenr);
113  copy_v2_v2(this->m_relativePos, marker->pos);
114  }
115  }
116  }
117 }
118 
120  float /*x*/,
121  float /*y*/,
122  PixelSampler /*sampler*/)
123 {
124  output[0] = this->m_markerPos[this->m_axis] - this->m_relativePos[this->m_axis];
125 
126  if (this->m_axis == 0) {
127  output[0] *= this->m_width;
128  }
129  else {
130  output[0] *= this->m_height;
131  }
132 }
133 
134 void TrackPositionOperation::determineResolution(unsigned int resolution[2],
135  unsigned int preferredResolution[2])
136 {
137  resolution[0] = preferredResolution[0];
138  resolution[1] = preferredResolution[1];
139 }
140 
141 } // namespace blender::compositor
float BKE_movieclip_remap_scene_to_clip_frame(const struct MovieClip *clip, float framenr)
void BKE_movieclip_user_set_frame(struct MovieClipUser *user, int framenr)
Definition: movieclip.c:1633
void BKE_movieclip_get_size(struct MovieClip *clip, struct MovieClipUser *user, int *width, int *height)
Definition: movieclip.c:1540
#define CMP_TRACKPOS_RELATIVE_START
Definition: BKE_node.h:1254
#define CMP_TRACKPOS_RELATIVE_FRAME
Definition: BKE_node.h:1255
#define CMP_TRACKPOS_ABSOLUTE
Definition: BKE_node.h:1253
struct MovieTrackingTrack * BKE_tracking_track_get_named(struct MovieTracking *tracking, struct MovieTrackingObject *object, const char *name)
Definition: tracking.c:1119
struct MovieTrackingMarker * BKE_tracking_marker_get_exact(struct MovieTrackingTrack *track, int framenr)
Definition: tracking.c:1556
struct MovieTrackingObject * BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name)
Definition: tracking.c:2183
struct MovieTrackingMarker * BKE_tracking_marker_get(struct MovieTrackingTrack *track, int framenr)
Definition: tracking.c:1523
MINLINE void swap_v2_v2(float a[2], float b[2])
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void zero_v2(float r[2])
@ MARKER_DISABLED
Read Guarded memory(de)allocation.
#define output
void addOutputSocket(DataType datatype)
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) override
struct MovieTracking tracking
MovieTrackingMarker * markers