About

A Mt2dTrackData object stores information on 2D tracks created with the Motion Tracker object. It provides access to Mt2dTrack objects that represent such tracks. Spacial information is represented by MtData objects.

Access

The Mt2dTrackData object is obtained from the parent MotionTrackerObject.

Warning
The returned object is a copy owned by the caller.
// This example accesses the track data to print the track count.
Mt2dTrackData* trackData = moTrackObject->Get2dTrackData();
if (trackData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
const Int32 trackCount = trackData->GetTrackCount();
ApplicationOutput("Track Count: " + String::IntToString(trackCount));
Mt2dTrackData::Free(trackData);
Definition: lib_motiontracker.h:71
Int32 GetTrackCount() const
static void Free(Mt2dTrackData *&p)
static String IntToString(Int32 v)
Definition: c4d_string.h:495
maxon::Int32 Int32
Definition: ge_sys_math.h:60
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210

Access Tracks

The Mt2dTrackData object provides access to 2D tracks:

A copy of a track has to be freed with:

// This example accesses the track data to loop
// through all tracks and print their names.
Mt2dTrackData* trackData = moTrackObject->Get2dTrackData();
if (trackData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// AutoFree takes ownership
freeData.Assign(trackData);
const Int32 trackCount = trackData->GetTrackCount();
// loop all tracks
for (Int32 i = 0; i < trackCount; ++i)
{
Mt2dTrack* track = trackData->GetTrackByIndex(i);
if (track == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// AutoFree takes ownership
freeTrack.Assign(track);
// print track index and name
const String trackName = track->GetName();
const String trackIndex = String::IntToString(i);
ApplicationOutput("Track " + trackIndex + " : " + trackName);
}
Py_ssize_t i
Definition: abstract.h:645
Definition: ge_autoptr.h:155
void Assign(TYPE *p)
Definition: ge_autoptr.h:234
Mt2dTrack * GetTrackByIndex(Int32 idx) const
Definition: lib_motiontracker.h:156
String GetName() const
Definition: c4d_string.h:39

Access Track Data

A Mt2dTrack object stores several properties:

A valid status is:

A track may only be valid for certain frames. This validity is stored in a BaseSelect object:

// This example checks for what frames the given track
// contains 2D tracking data.
BaseSelect* frameRange = track->GetFramesWithTrackData();
if (frameRange == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// AutoFree takes ownership
freeFrames.Assign(frameRange);
Int32 seg = 0, a, b;
// loop through all segments of the BaseSelect
while (frameRange->GetRange(seg++, LIMIT<Int32>::MAX, &a, &b))
{
const String segmentBeginStr = String::IntToString(a);
const String segmentEndStr = String::IntToString(b);
const String trackName = track->GetName();
ApplicationOutput(trackName + " contains data for the range " + segmentBeginStr + " to " + segmentEndStr);
}
Definition: c4d_baseselect.h:32
Bool GetRange(Int32 seg, Int32 maxElements, Int32 *a, Int32 *b) const
Definition: apibasemath.h:34
BaseSelect * GetFramesWithTrackData() const

Position Data

The information on the position of the track for a given frame is stored in a MtData object. Such an object is returned by the Mt2dTrack:

Spacial information is obtained from that MtData object:

// This example loops through all frames of the footage and
// checks for each frame if the given track contains data for it.
// If so, the data is printed to the console.
// get footage range
const Int32 firstFrame = footage->GetFirstFrameNumber();
const Int32 lastFrame = footage->GetLastFrameNumber();
// loop through all frames
for (Int32 frame = firstFrame; frame < lastFrame; frame++)
{
// check if track contains data for the given frame
if (frameRange->IsSelected(frame))
{
// access data
MtData* frameData = track->GetDataForFrame(frame);
if (frameData == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// AutoFree takes ownership
AutoFree<MtData> freeMtData;
freeMtData.Assign(frameData);
// get position
const Vector pos = frameData->GetPixelPosition(footage, true);
// print to console
const String frameStr = String::IntToString(frame);
ApplicationOutput("Position for frame " + frameStr + ": " + posStr);
}
}
Bool IsSelected(Int32 num) const
Definition: c4d_baseselect.h:162
MtData * GetDataForFrame(Int32 frameNum) const
Definition: lib_motiontracker.h:223
Vector GetPixelPosition(MtFootageData *sdkFh, Bool originalRes) const
static String VectorToString(const Vector32 &v, Int32 nnk=-1)
Definition: c4d_string.h:571
void Py_ssize_t * pos
Definition: dictobject.h:50
PyFrameObject * frame
Definition: pycore_traceback.h:92

Further Reading