Blender  V2.93
COM_PlaneTrackOperation.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 2013, Blender Foundation.
17  */
18 
21 
22 #include "MEM_guardedalloc.h"
23 
24 #include "BLI_listbase.h"
25 #include "BLI_math.h"
26 #include "BLI_math_color.h"
27 
28 #include "BKE_movieclip.h"
29 #include "BKE_node.h"
30 #include "BKE_tracking.h"
31 
32 namespace blender::compositor {
33 
34 /* ******** PlaneTrackCommon ******** */
35 
37 {
38  this->m_movieClip = nullptr;
39  this->m_framenumber = 0;
40  this->m_trackingObjectName[0] = '\0';
41  this->m_planeTrackName[0] = '\0';
42 }
43 
44 void PlaneTrackCommon::readCornersFromTrack(float corners[4][2], float frame)
45 {
46  MovieTracking *tracking;
47  MovieTrackingObject *object;
48 
49  if (!this->m_movieClip) {
50  return;
51  }
52 
53  tracking = &this->m_movieClip->tracking;
54 
55  object = BKE_tracking_object_get_named(tracking, this->m_trackingObjectName);
56  if (object) {
57  MovieTrackingPlaneTrack *plane_track;
58  plane_track = BKE_tracking_plane_track_get_named(tracking, object, this->m_planeTrackName);
59  if (plane_track) {
60  float clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, frame);
61  BKE_tracking_plane_marker_get_subframe_corners(plane_track, clip_framenr, corners);
62  }
63  }
64 }
65 
66 void PlaneTrackCommon::determineResolution(unsigned int resolution[2],
67  unsigned int /*preferredResolution*/[2])
68 {
69  resolution[0] = 0;
70  resolution[1] = 0;
71 
72  if (this->m_movieClip) {
73  int width, height;
74  MovieClipUser user = {0};
77  resolution[0] = width;
78  resolution[1] = height;
79  }
80 }
81 
82 /* ******** PlaneTrackMaskOperation ******** */
83 
85 {
87  float corners[4][2];
88  if (this->m_motion_blur_samples == 1) {
89  readCornersFromTrack(corners, this->m_framenumber);
90  calculateCorners(corners, true, 0);
91  }
92  else {
93  const float frame = (float)this->m_framenumber - this->m_motion_blur_shutter;
94  const float frame_step = (this->m_motion_blur_shutter * 2.0f) / this->m_motion_blur_samples;
95  float frame_iter = frame;
96  for (int sample = 0; sample < this->m_motion_blur_samples; sample++) {
97  readCornersFromTrack(corners, frame_iter);
98  calculateCorners(corners, true, sample);
99  frame_iter += frame_step;
100  }
101  }
102 }
103 
104 /* ******** PlaneTrackWarpImageOperation ******** */
105 
107 {
109  /* TODO(sergey): De-duplicate with mask operation. */
110  float corners[4][2];
111  if (this->m_motion_blur_samples == 1) {
112  readCornersFromTrack(corners, this->m_framenumber);
113  calculateCorners(corners, true, 0);
114  }
115  else {
116  const float frame = (float)this->m_framenumber - this->m_motion_blur_shutter;
117  const float frame_step = (this->m_motion_blur_shutter * 2.0f) / this->m_motion_blur_samples;
118  float frame_iter = frame;
119  for (int sample = 0; sample < this->m_motion_blur_samples; sample++) {
120  readCornersFromTrack(corners, frame_iter);
121  calculateCorners(corners, true, sample);
122  frame_iter += frame_step;
123  }
124  }
125 }
126 
127 } // namespace blender::compositor
typedef float(TangentPoint)[2]
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
struct MovieTrackingPlaneTrack * BKE_tracking_plane_track_get_named(struct MovieTracking *tracking, struct MovieTrackingObject *object, const char *name)
Definition: tracking.c:1806
struct MovieTrackingObject * BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name)
Definition: tracking.c:2183
void BKE_tracking_plane_marker_get_subframe_corners(struct MovieTrackingPlaneTrack *plane_track, float framenr, float corners[4][2])
Definition: tracking.c:2075
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
Read Guarded memory(de)allocation.
void calculateCorners(const float corners[4][2], bool normalized, int sample)
void calculateCorners(const float corners[4][2], bool normalized, int sample)
void readCornersFromTrack(float corners[4][2], float frame)
void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
static void sample(SocketReader *reader, int x, int y, float color[4])
struct MovieTracking tracking