Skip to content

Commit

Permalink
Transform: only setValue if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Nov 12, 2022
1 parent 6b770ba commit feee833
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 50 deletions.
5 changes: 4 additions & 1 deletion Card3D/Card3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,10 @@ Card3DPlugin::changedParam(const InstanceChangedArgs &args,
{
//const double time = args.time;
if ( (paramName == kParamPremult) && (args.reason == eChangeUserEdit) ) {
_srcClipChanged->setValue(true);
// Only set if necessary
if (!_srcClipChanged->getValue()) {
_srcClipChanged->setValue(true);
}
} else if (paramName == kParamCamEnable) {
updateVisibility();
} else if (paramName == kParamOutputFormat) {
Expand Down
61 changes: 38 additions & 23 deletions GodRays/GodRays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ GodRaysPlugin::getInverseTransformCanonical(double time,
void
GodRaysPlugin::resetCenter(double time)
{
// Note: same code as TransformPlugin::resetCenter()
if (!_srcClip || !_srcClip->isConnected()) {
return;
}
Expand Down Expand Up @@ -774,28 +775,36 @@ GodRaysPlugin::resetCenter(double time)
OfxPointD newCenter;
newCenter.x = (rod.x1 + rod.x2) / 2;
newCenter.y = (rod.y1 + rod.y2) / 2;
EditBlock eb(*this, "resetCenter");
if (_center) {
_center->setValue(newCenter.x, newCenter.y);
}
if (_translate) {
double dxrot = newCenter.x - center.x;
double dyrot = newCenter.y - center.y;
Point3D dRot;
dRot.x = dxrot;
dRot.y = dyrot;
dRot.z = 1;
dRot = Rinv * dRot;
if (dRot.z != 0) {
dRot.x /= dRot.z;
dRot.y /= dRot.z;
if (newCenter.x != center.x || newCenter.y != center.y) {
bool editBlockNecessary = false;
OfxPointD newTranslate = {0., 0.};
if (_translate) {
double dxrot = newCenter.x - center.x;
double dyrot = newCenter.y - center.y;
Point3D dRot;
dRot.x = dxrot;
dRot.y = dyrot;
dRot.z = 1;
dRot = Rinv * dRot;
if (dRot.z != 0) {
dRot.x /= dRot.z;
dRot.y /= dRot.z;
}
double dx = dRot.x;
double dy = dRot.y;
newTranslate.x = translate.x + dx - dxrot;
newTranslate.y = translate.y + dy - dyrot;
if (newTranslate.x != translate.x || newTranslate.y != translate.y) {
editBlockNecessary = true;
}
}
EditBlock eb(*this, "resetCenter", editBlockNecessary);
if (_center) {
_center->setValue(newCenter.x, newCenter.y);
}
if (_translate) {
_translate->setValue(newTranslate.x, newTranslate.y);
}
double dx = dRot.x;
double dy = dRot.y;
OfxPointD newTranslate;
newTranslate.x = translate.x + dx - dxrot;
newTranslate.y = translate.y + dy - dyrot;
_translate->setValue(newTranslate.x, newTranslate.y);
}
} // GodRaysPlugin::resetCenter

Expand All @@ -805,7 +814,10 @@ GodRaysPlugin::changedParam(const InstanceChangedArgs &args,
{
if (paramName == kParamTransformResetCenterOld) {
resetCenter(args.time);
_centerChanged->setValue(false);
// Only set if necessary
if (_centerChanged->getValue()) {
_centerChanged->setValue(false);
}
} else if ( (paramName == kParamTransformTranslateOld) ||
( paramName == kParamTransformRotateOld) ||
( paramName == kParamTransformScaleOld) ||
Expand All @@ -816,7 +828,10 @@ GodRaysPlugin::changedParam(const InstanceChangedArgs &args,
( paramName == kParamTransformCenterOld) ) {
if ( (paramName == kParamTransformCenterOld) &&
( (args.reason == eChangeUserEdit) || (args.reason == eChangePluginEdit) ) ) {
_centerChanged->setValue(true);
// Only set if necessary
if (!_centerChanged->getValue()) {
_centerChanged->setValue(true);
}
}
changedTransform(args);
} else if ( (paramName == kParamPremult) && (args.reason == eChangeUserEdit) ) {
Expand Down
2 changes: 1 addition & 1 deletion SupportExt
67 changes: 42 additions & 25 deletions Transform/Transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,28 +330,36 @@ TransformPlugin::resetCenter(double time)
OfxPointD newCenter;
newCenter.x = (rod.x1 + rod.x2) / 2;
newCenter.y = (rod.y1 + rod.y2) / 2;
EditBlock eb(*this, "resetCenter");
if (_center) {
_center->setValue(newCenter.x, newCenter.y);
}
if (_translate) {
double dxrot = newCenter.x - center.x;
double dyrot = newCenter.y - center.y;
Point3D dRot;
dRot.x = dxrot;
dRot.y = dyrot;
dRot.z = 1;
dRot = Rinv * dRot;
if (dRot.z != 0) {
dRot.x /= dRot.z;
dRot.y /= dRot.z;
if (newCenter.x != center.x || newCenter.y != center.y) {
bool editBlockNecessary = false;
OfxPointD newTranslate = {0., 0.};
if (_translate) {
double dxrot = newCenter.x - center.x;
double dyrot = newCenter.y - center.y;
Point3D dRot;
dRot.x = dxrot;
dRot.y = dyrot;
dRot.z = 1;
dRot = Rinv * dRot;
if (dRot.z != 0) {
dRot.x /= dRot.z;
dRot.y /= dRot.z;
}
double dx = dRot.x;
double dy = dRot.y;
newTranslate.x = translate.x + dx - dxrot;
newTranslate.y = translate.y + dy - dyrot;
if (newTranslate.x != translate.x || newTranslate.y != translate.y) {
editBlockNecessary = true;
}
}
EditBlock eb(*this, "resetCenter", editBlockNecessary);
if (_center) {
_center->setValue(newCenter.x, newCenter.y);
}
if (_translate) {
_translate->setValue(newTranslate.x, newTranslate.y);
}
double dx = dRot.x;
double dy = dRot.y;
OfxPointD newTranslate;
newTranslate.x = translate.x + dx - dxrot;
newTranslate.y = translate.y + dy - dyrot;
_translate->setValue(newTranslate.x, newTranslate.y);
}
} // TransformPlugin::resetCenter

Expand All @@ -361,7 +369,10 @@ TransformPlugin::changedParam(const InstanceChangedArgs &args,
{
if (paramName == kParamTransformResetCenterOld) {
resetCenter(args.time);
_centerChanged->setValue(false);
// Only set if necessary
if (_centerChanged->getValue()) {
_centerChanged->setValue(false);
}
} else if ( (paramName == kParamTransformTranslateOld) ||
( paramName == kParamTransformRotateOld) ||
( paramName == kParamTransformScaleOld) ||
Expand All @@ -372,11 +383,17 @@ TransformPlugin::changedParam(const InstanceChangedArgs &args,
( paramName == kParamTransformCenterOld) ) {
if ( (paramName == kParamTransformCenterOld) &&
( (args.reason == eChangeUserEdit) || (args.reason == eChangePluginEdit) ) ) {
_centerChanged->setValue(true);
// Only set if necessary
if (!_centerChanged->getValue()) {
_centerChanged->setValue(true);
}
}
changedTransform(args);
} else if ( (paramName == kParamPremult) && (args.reason == eChangeUserEdit) ) {
_srcClipChanged->setValue(true);
// Only set if necessary
if (!_srcClipChanged->getValue()) {
_srcClipChanged->setValue(true);
}
} else {
Transform3x3Plugin::changedParam(args, paramName);
}
Expand All @@ -388,7 +405,7 @@ TransformPlugin::changedClip(const InstanceChangedArgs &args,
{
if ( (clipName == kOfxImageEffectSimpleSourceClipName) &&
_srcClip && _srcClip->isConnected() &&
!_centerChanged->getValueAtTime(args.time) &&
!_centerChanged->getValue() &&
( args.reason == eChangeUserEdit) ) {
resetCenter(args.time);
}
Expand Down

0 comments on commit feee833

Please sign in to comment.