This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/compositor/operations/COM_TrackPositionOperation.cc
Manuel Castilla 1a9b9dd64d Compositor: Full frame input nodes
Adds full frame implementation to "Bokeh Image" node, "Track Position"
node, `SetVectorOperation` and `MovieClipAttribute`.
The other nodes in "Input" submenu are implemented separately.

`MovieClipAttribute` needs resolution to calculate its constant value, it can't be constant folded,
which requires it to be a `ConstantOperation`. Now `ConstantOperation` contemplate this case
and any operation that is always constant without depending on inputs should implement it.
If in the future an operation needs to get an input constant element during
`determineResolution` it must first determine its input resolution.

The nodes have no functional changes.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D12090
2021-08-10 16:16:22 +02:00

168 lines
5.0 KiB
C++

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2012, Blender Foundation.
*/
#include "COM_TrackPositionOperation.h"
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_math_color.h"
#include "BKE_movieclip.h"
#include "BKE_node.h"
#include "BKE_tracking.h"
namespace blender::compositor {
TrackPositionOperation::TrackPositionOperation()
{
this->addOutputSocket(DataType::Value);
this->m_movieClip = nullptr;
this->m_framenumber = 0;
this->m_trackingObjectName[0] = 0;
this->m_trackName[0] = 0;
this->m_axis = 0;
this->m_position = CMP_TRACKPOS_ABSOLUTE;
this->m_relativeFrame = 0;
this->m_speed_output = false;
flags.is_set_operation = true;
is_track_position_calculated_ = false;
}
void TrackPositionOperation::initExecution()
{
if (!is_track_position_calculated_) {
calc_track_position();
}
}
void TrackPositionOperation::calc_track_position()
{
is_track_position_calculated_ = true;
MovieTracking *tracking = nullptr;
MovieClipUser user = {0};
MovieTrackingObject *object;
track_position_ = 0;
zero_v2(this->m_markerPos);
zero_v2(this->m_relativePos);
if (!this->m_movieClip) {
return;
}
tracking = &this->m_movieClip->tracking;
BKE_movieclip_user_set_frame(&user, this->m_framenumber);
BKE_movieclip_get_size(this->m_movieClip, &user, &this->m_width, &this->m_height);
object = BKE_tracking_object_get_named(tracking, this->m_trackingObjectName);
if (object) {
MovieTrackingTrack *track;
track = BKE_tracking_track_get_named(tracking, object, this->m_trackName);
if (track) {
MovieTrackingMarker *marker;
int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip,
this->m_framenumber);
marker = BKE_tracking_marker_get(track, clip_framenr);
copy_v2_v2(this->m_markerPos, marker->pos);
if (this->m_speed_output) {
int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip,
this->m_relativeFrame);
marker = BKE_tracking_marker_get_exact(track, relative_clip_framenr);
if (marker != nullptr && (marker->flag & MARKER_DISABLED) == 0) {
copy_v2_v2(this->m_relativePos, marker->pos);
}
else {
copy_v2_v2(this->m_relativePos, this->m_markerPos);
}
if (this->m_relativeFrame < this->m_framenumber) {
swap_v2_v2(this->m_relativePos, this->m_markerPos);
}
}
else if (this->m_position == CMP_TRACKPOS_RELATIVE_START) {
int i;
for (i = 0; i < track->markersnr; i++) {
marker = &track->markers[i];
if ((marker->flag & MARKER_DISABLED) == 0) {
copy_v2_v2(this->m_relativePos, marker->pos);
break;
}
}
}
else if (this->m_position == CMP_TRACKPOS_RELATIVE_FRAME) {
int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip,
this->m_relativeFrame);
marker = BKE_tracking_marker_get(track, relative_clip_framenr);
copy_v2_v2(this->m_relativePos, marker->pos);
}
}
}
track_position_ = this->m_markerPos[this->m_axis] - this->m_relativePos[this->m_axis];
if (this->m_axis == 0) {
track_position_ *= this->m_width;
}
else {
track_position_ *= this->m_height;
}
}
void TrackPositionOperation::executePixelSampled(float output[4],
float /*x*/,
float /*y*/,
PixelSampler /*sampler*/)
{
output[0] = this->m_markerPos[this->m_axis] - this->m_relativePos[this->m_axis];
if (this->m_axis == 0) {
output[0] *= this->m_width;
}
else {
output[0] *= this->m_height;
}
}
const float *TrackPositionOperation::get_constant_elem()
{
if (!is_track_position_calculated_) {
calc_track_position();
}
return &track_position_;
}
void TrackPositionOperation::determineResolution(unsigned int resolution[2],
unsigned int preferredResolution[2])
{
resolution[0] = preferredResolution[0];
resolution[1] = preferredResolution[1];
}
} // namespace blender::compositor