Skip to content

Commit

Permalink
switch : instrument oppositePlug
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Dec 7, 2023
1 parent 8565e6c commit 54a934c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Gaffer/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ size_t Switch::inputIndex( const Context *context ) const

const Plug *Switch::oppositePlug( const Plug *plug, const Context *context ) const
{
std::cerr << "oppositePlug 1 " << plug->fullName() << std::endl;
const ArrayPlug *inPlugs = this->inPlugs();
const Plug *outPlug = this->outPlug();
if( !inPlugs || !outPlug )
Expand All @@ -389,6 +390,7 @@ const Plug *Switch::oppositePlug( const Plug *plug, const Context *context ) con
plug = static_cast<const Plug *>( plugParent );
}
}
std::cerr << "oppositePlug 2 " << plug->fullName() << std::endl;

if( !ancestorPlug )
{
Expand All @@ -399,14 +401,18 @@ const Plug *Switch::oppositePlug( const Plug *plug, const Context *context ) con
const Plug *oppositeAncestorPlug = nullptr;
if( plug->direction() == Plug::Out )
{
std::cerr << "oppositePlug 3 " << plug->fullName() << std::endl;
const size_t i = context ? inputIndex( context ) : 0;
std::cerr << "oppositePlug 4 " << plug->fullName() << std::endl;
oppositeAncestorPlug = inPlugs->getChild<Plug>( i );
}
else
{
oppositeAncestorPlug = outPlug;
}

std::cerr << "oppositePlug 5 " << plug->fullName() << std::endl;

// And then find the opposite of plug by traversing down from the ancestor plug.
const Plug *result = oppositeAncestorPlug;
for( auto it = names.rbegin(), eIt = names.rend(); it != eIt; ++it )
Expand All @@ -419,30 +425,30 @@ const Plug *Switch::oppositePlug( const Plug *plug, const Context *context ) con

void Switch::updateInternalConnection()
{
std::cerr << "Switch::updateInternalConnection 1 " << fullName() << std::endl;
//std::cerr << "Switch::updateInternalConnection 1 " << fullName() << std::endl;
Plug *out = outPlug();
if( !out )
{
return;
}
std::cerr << "Switch::updateInternalConnection 2 " << fullName() << std::endl;
//std::cerr << "Switch::updateInternalConnection 2 " << fullName() << std::endl;

if( PlugAlgo::dependsOnCompute( enabledPlug() ) || PlugAlgo::dependsOnCompute( indexPlug() ) )
{
std::cerr << "Switch::updateInternalConnection 2.5 " << fullName() << std::endl;
// std::cerr << "Switch::updateInternalConnection 2.5 " << fullName() << std::endl;
// We can't use an internal connection to implement the switch,
// because the index might vary from context to context. We must
// therefore implement switching via hash()/compute().
out->setInput( nullptr );
std::cerr << "Switch::updateInternalConnection 3 " << fullName() << std::endl;
// std::cerr << "Switch::updateInternalConnection 3 " << fullName() << std::endl;
return;
}

std::cerr << "Switch::updateInternalConnection 3.5 " << fullName() << std::endl;
//std::cerr << "Switch::updateInternalConnection 3.5 " << fullName() << std::endl;

Plug *in = const_cast<Plug *>( oppositePlug( out, nullptr ) );
std::cerr << "Switch::updateInternalConnection 4 " << fullName() << std::endl;
Plug *in = const_cast<Plug *>( oppositePlug( out, Context::current() ) );
//std::cerr << "Switch::updateInternalConnection 4 " << fullName() << std::endl;
out->setInput( in );
std::cerr << "Switch::updateInternalConnection 5 " << fullName() << std::endl;
//std::cerr << "Switch::updateInternalConnection 5 " << fullName() << std::endl;

}

0 comments on commit 54a934c

Please sign in to comment.