MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / onAverageTracksButtonClicked

Method onAverageTracksButtonClicked

Gui/MultiInstancePanel.cpp:1912–1995  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1910}
1911
1912void
1913TrackerPanelV1::onAverageTracksButtonClicked()
1914{
1915 std::list<Node*> selectedInstances;
1916
1917 getSelectedInstances(&selectedInstances);
1918 if ( selectedInstances.empty() ) {
1919 Dialogs::warningDialog( tr("Average").toStdString(), tr("No tracks selected").toStdString() );
1920
1921 return;
1922 }
1923
1924 NodePtr newInstance = addInstanceInternal(true);
1925 ///give an appropriate name to the new instance
1926 int avgIndex = 0;
1927 const std::list<std::pair<NodeWPtr, bool > > & allInstances = getInstances();
1928 for (std::list<std::pair<NodeWPtr, bool > >::const_iterator it = allInstances.begin();
1929 it != allInstances.end(); ++it) {
1930 if ( QString::fromUtf8( it->first.lock()->getScriptName().c_str() ).contains(QString::fromUtf8("average"), Qt::CaseInsensitive) ) {
1931 ++avgIndex;
1932 }
1933 }
1934 QString newName = QString::fromUtf8("Average%1").arg(avgIndex + 1);
1935 try {
1936 newInstance->setScriptName( newName.toStdString() );
1937 } catch (...) {
1938 }
1939
1940 newInstance->updateEffectLabelKnob(newName);
1941
1942 KnobDoublePtr newInstanceCenter = getCenterKnobForTracker( newInstance.get() );
1943 std::list<KnobDoublePtr> centers;
1944 RangeD keyframesRange;
1945 keyframesRange.min = std::numeric_limits<int>::max();
1946 keyframesRange.max = std::numeric_limits<int>::min();
1947
1948 for (std::list<Node*>::iterator it = selectedInstances.begin(); it != selectedInstances.end(); ++it) {
1949 KnobDoublePtr dblKnob = getCenterKnobForTracker(*it);
1950 centers.push_back(dblKnob);
1951 double mini, maxi;
1952 bool hasKey = dblKnob->getFirstKeyFrameTime(ViewIdx(0), 0, &mini);
1953 if (!hasKey) {
1954 continue;
1955 }
1956 if (mini < keyframesRange.min) {
1957 keyframesRange.min = mini;
1958 }
1959
1960 hasKey = dblKnob->getLastKeyFrameTime(ViewIdx(0), 0, &maxi);
1961
1962 ///both dimensions must have keyframes
1963 assert(hasKey);
1964 if (maxi > keyframesRange.max) {
1965 keyframesRange.max = maxi;
1966 }
1967 }
1968 if (keyframesRange.min == std::numeric_limits<int>::min()) {
1969 keyframesRange.min = 0;

Callers

nothing calls this directly

Calls 15

getCenterKnobForTrackerFunction · 0.85
maxFunction · 0.85
allFunction · 0.85
emptyMethod · 0.80
toStdStringMethod · 0.80
updateEffectLabelKnobMethod · 0.80
getFirstKeyFrameTimeMethod · 0.80
getLastKeyFrameTimeMethod · 0.80
ViewIdxClass · 0.50
beginMethod · 0.45
endMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected