Track input node: move all initializaiton to initExecution function
This commit is contained in:
@@ -65,4 +65,5 @@ void TrackPositionNode::convertToOperations(ExecutionSystem *graph, CompositorCo
|
||||
outputY->relinkConnections(operationY->getOutputSocket());
|
||||
|
||||
graph->addOperation(operationX);
|
||||
graph->addOperation(operationY);
|
||||
}
|
||||
|
||||
@@ -39,58 +39,69 @@ extern "C" {
|
||||
TrackPositionOperation::TrackPositionOperation() : NodeOperation()
|
||||
{
|
||||
this->addOutputSocket(COM_DT_VALUE);
|
||||
this->movieClip = NULL;
|
||||
this->framenumber = 0;
|
||||
this->trackingObject[0] = 0;
|
||||
this->trackName[0] = 0;
|
||||
this->axis = 0;
|
||||
this->relative = false;
|
||||
this->m_movieClip = NULL;
|
||||
this->m_framenumber = 0;
|
||||
this->m_trackingObjectName[0] = 0;
|
||||
this->m_trackName[0] = 0;
|
||||
this->m_axis = 0;
|
||||
this->m_relative = false;
|
||||
}
|
||||
|
||||
void TrackPositionOperation::initExecution()
|
||||
{
|
||||
MovieTracking *tracking = NULL;
|
||||
MovieClipUser user = {0};
|
||||
MovieTrackingObject *object;
|
||||
|
||||
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;
|
||||
|
||||
marker = BKE_tracking_marker_get(track, this->m_framenumber);
|
||||
|
||||
copy_v2_v2(this->m_markerPos, marker->pos);
|
||||
|
||||
if (this->m_relative) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TrackPositionOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler)
|
||||
{
|
||||
MovieClipUser user = {0};
|
||||
MovieTracking *tracking = &movieClip->tracking;
|
||||
MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, this->trackingObject);
|
||||
MovieTrackingTrack *track;
|
||||
MovieTrackingMarker *marker;
|
||||
int width, height;
|
||||
outputValue[0] = this->m_markerPos[this->m_axis] - this->m_relativePos[this->m_axis];
|
||||
|
||||
outputValue[0] = 0.0f;
|
||||
|
||||
if (!object)
|
||||
return;
|
||||
|
||||
track = BKE_tracking_track_get_named(tracking, object, this->trackName);
|
||||
|
||||
if (!track)
|
||||
return;
|
||||
|
||||
BKE_movieclip_user_set_frame(&user, this->framenumber);
|
||||
BKE_movieclip_get_size(this->movieClip, &user, &width, &height);
|
||||
|
||||
marker = BKE_tracking_marker_get(track, this->framenumber);
|
||||
|
||||
outputValue[0] = marker->pos[this->axis];
|
||||
|
||||
if (this->relative) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < track->markersnr; i++) {
|
||||
marker = &track->markers[i];
|
||||
|
||||
if ((marker->flag & MARKER_DISABLED) == 0) {
|
||||
outputValue[0] -= marker->pos[this->axis];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this->axis == 0)
|
||||
outputValue[0] *= width;
|
||||
if (this->m_axis == 0)
|
||||
outputValue[0] *= this->m_width;
|
||||
else
|
||||
outputValue[0] *= height;
|
||||
outputValue[0] *= this->m_height;
|
||||
}
|
||||
|
||||
void TrackPositionOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[])
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_movieclip_types.h"
|
||||
#include "DNA_tracking_types.h"
|
||||
|
||||
#include "BLI_listbase.h"
|
||||
|
||||
@@ -39,12 +40,16 @@
|
||||
*/
|
||||
class TrackPositionOperation : public NodeOperation {
|
||||
protected:
|
||||
MovieClip *movieClip;
|
||||
int framenumber;
|
||||
char trackingObject[64];
|
||||
char trackName[64];
|
||||
int axis;
|
||||
bool relative;
|
||||
MovieClip *m_movieClip;
|
||||
int m_framenumber;
|
||||
char m_trackingObjectName[64];
|
||||
char m_trackName[64];
|
||||
int m_axis;
|
||||
bool m_relative;
|
||||
|
||||
int m_width, m_height;
|
||||
float m_markerPos[2];
|
||||
float m_relativePos[2];
|
||||
|
||||
/**
|
||||
* Determine the output resolution. The resolution is retrieved from the Renderer
|
||||
@@ -54,12 +59,14 @@ protected:
|
||||
public:
|
||||
TrackPositionOperation();
|
||||
|
||||
void setMovieClip(MovieClip *clip) {this->movieClip = clip;}
|
||||
void setTrackingObject(char *object) {strncpy(this->trackingObject, object, sizeof(this->trackingObject));}
|
||||
void setTrackName(char *track) {strncpy(this->trackName, track, sizeof(this->trackName));}
|
||||
void setFramenumber(int framenumber) {this->framenumber = framenumber;}
|
||||
void setAxis(int value) {this->axis = value;}
|
||||
void setRelative(bool value) {this->relative = value;}
|
||||
void setMovieClip(MovieClip *clip) {this->m_movieClip = clip;}
|
||||
void setTrackingObject(char *object) {strncpy(this->m_trackingObjectName, object, sizeof(this->m_trackingObjectName));}
|
||||
void setTrackName(char *track) {strncpy(this->m_trackName, track, sizeof(this->m_trackName));}
|
||||
void setFramenumber(int framenumber) {this->m_framenumber = framenumber;}
|
||||
void setAxis(int value) {this->m_axis = value;}
|
||||
void setRelative(bool value) {this->m_relative = value;}
|
||||
|
||||
void initExecution();
|
||||
|
||||
void executePixel(float *color, float x, float y, PixelSampler sampler);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user