Skip to content

Commit 1dde256

Browse files
committed
Merge pull request #143 from goddardl/LensDistortMissingKnobError
Fixed bug #4837: "Knobs not found" warning messages.
2 parents 52ba952 + 85464ea commit 1dde256

File tree

2 files changed

+55
-25
lines changed

2 files changed

+55
-25
lines changed

include/IECoreNuke/LensDistort.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ class LensDistort : public DD::Image::Iop
144144

145145
/// Iterates over all of the lens model's attributes and if they are associated with a knob, retrieves the information from the knob.
146146
void updatePluginAttributesFromKnobs();
147+
148+
/// Updates the dynamic knobs. This method should be called whenever a knob is changed or an event happens that requires
149+
/// the dynamic knobs to be recreated or their enabled state changed.
150+
void updateUI();
147151

148152
/// The maximum number of threads that we are going to use in parallel.
149153
const int m_nThreads;

src/IECoreNuke/LensDistort.cpp

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "DDImage/Pixel.h"
4444
#include "DDImage/Tile.h"
4545
#include "IECore/CachedReader.h"
46+
#include "IECore/FastFloat.h"
4647
#include "IECore/Reader.h"
4748
#include "IECore/NumericParameter.h"
4849
#include "boost/algorithm/string.hpp"
@@ -223,9 +224,10 @@ void LensDistort::_validate(bool for_real)
223224
}
224225

225226
// Set the output bounding box according to the lens model.
227+
bool black = input0().black_outside();
226228
Imath::Box2i input( Imath::V2i( input0().info().x(), input0().info().y() ), Imath::V2i( input0().info().r()-1, input0().info().t()-1 ) );
227229
Imath::Box2i box( m_model[0]->bounds( m_mode, input, format().width(), format().height() ) );
228-
info_.set( box.min.x, box.min.y, box.max.x, box.max.y );
230+
info_.set( box.min.x-black, box.min.y-black, box.max.x+black, box.max.y+black );
229231

230232
set_out_channels( Mask_All );
231233
}
@@ -243,6 +245,14 @@ void LensDistort::_request( int x, int y, int r, int t, ChannelMask channels, in
243245

244246
void LensDistort::engine( int y, int x, int r, ChannelMask channels, Row & outrow )
245247
{
248+
// Provide an early-out for any black rows.
249+
bool blackOutside = info().black_outside();
250+
if( blackOutside && ( y == info().t()-1 || y == info().y() ) )
251+
{
252+
outrow.erase( channels );
253+
return;
254+
}
255+
246256
const Info &info = input0().info();
247257
const double h( format().height() );
248258
const double w( format().width() );
@@ -305,10 +315,20 @@ void LensDistort::engine( int y, int x, int r, ChannelMask channels, Row & outro
305315
DD::Image::Pixel out(channels);
306316

307317
// Lock the tile into the cache
308-
DD::Image::Tile t( input0(), int(floor(x_min)), int(floor(y_min)), int(ceil(x_max)), int(ceil(y_max)), channels );
309-
310-
// Loop over our array of precomputed points, and ask nuke to perform a filtered lookup for us
311-
for( int i = x; i < r; i++ )
318+
DD::Image::Tile t( input0(), IECore::fastFloatFloor( x_min ), IECore::fastFloatFloor( y_min ), IECore::fastFloatCeil( x_max ), IECore::fastFloatCeil( y_max ), channels );
319+
320+
// Write the black outside pixels.
321+
if( blackOutside )
322+
{
323+
foreach ( z, channels )
324+
{
325+
outrow.writable(z)[x] = 0.f;
326+
outrow.writable(z)[r-1] = 0.f;
327+
}
328+
}
329+
330+
// Loop over our array of precomputed points, and ask nuke to perform a filtered lookup for us.
331+
for( int i = x+blackOutside; i < r-blackOutside; i++ )
312332
{
313333
if(aborted()) break;
314334
input0().sample( distort[i-x].x+0.5, distort[i-x].y+0.5, 1.0, 1.0, &m_filter, out );
@@ -317,7 +337,6 @@ void LensDistort::engine( int y, int x, int r, ChannelMask channels, Row & outro
317337
outrow.writable(z)[i] = out[z];
318338
}
319339
}
320-
321340
}
322341

323342
void LensDistort::append( DD::Image::Hash &hash )
@@ -486,32 +505,38 @@ void LensDistort::updatePluginAttributesFromKnobs()
486505

487506
int LensDistort::knob_changed(Knob* k)
488507
{
489-
bool updateUI = false;
490-
491508
// If the lensFileSequence knob just changed then we need to check if it is valid and load it.
492-
// Once loaded then we set the updateUI flag to trigger a UI update.
493509
if ( k->is( "lensFileSequence" ) )
494510
{
511+
bool updateRequired = false;
512+
495513
std::string path;
496514
bool oldValue = m_useFileSequence;
497515
m_useFileSequence = getFileSequencePath( path );
498-
updateUI |= oldValue != m_useFileSequence;
516+
updateRequired |= oldValue != m_useFileSequence;
499517

500518
if ( m_useFileSequence )
501519
{
502520
bool oldValue = m_hasValidFileSequence;
503521
std::string path;
504522
m_hasValidFileSequence = setLensFromFile( path );
505-
updateUI |= m_hasValidFileSequence != oldValue;
523+
updateRequired |= m_hasValidFileSequence != oldValue;
524+
}
525+
526+
if( updateRequired )
527+
{
528+
updateUI();
506529
}
507530

531+
return true;
508532
}
509533

510534
// If the lens model was just changed then we need to set it internally and then update the UI.
511535
if ( k->is( "model" ) )
512536
{
513537
setLensModel( modelNames()[getLensModel()] );
514-
updateUI = true;
538+
updateUI();
539+
return true;
515540
}
516541

517542
// Update our internal reference of the knob value that just changed...
@@ -531,27 +556,28 @@ int LensDistort::knob_changed(Knob* k)
531556
}
532557
}
533558

534-
if ( k->is( "lensFileSequence" ) ) return true;
535-
536559
// Do we need to update the UI?
537-
if ( k == &Knob::showPanel || updateUI )
560+
if ( k == &Knob::showPanel )
538561
{
539-
m_numNewKnobs = replace_knobs( m_lastStaticKnob, m_numNewKnobs, addDynamicKnobs, this->firstOp() );
540-
541-
// Handle the knobs state.
542-
if ( knob("model" ) != NULL) knob("model")->enable( !m_useFileSequence );
543-
for ( PluginAttributeList::iterator it = m_pluginAttributes.begin(); it != m_pluginAttributes.end(); it++ )
544-
{
545-
if ( it->m_knob != NULL) it->m_knob->enable( !m_useFileSequence );
546-
}
547-
562+
updateUI();
548563
return true;
549564
}
550565

551-
552566
return Iop::knob_changed(k);
553567
}
554568

569+
void LensDistort::updateUI()
570+
{
571+
m_numNewKnobs = replace_knobs( m_lastStaticKnob, m_numNewKnobs, addDynamicKnobs, this->firstOp() );
572+
573+
// Handle the knobs state.
574+
if ( knob("model" ) != NULL) knob("model")->enable( !m_useFileSequence );
575+
for ( PluginAttributeList::iterator it = m_pluginAttributes.begin(); it != m_pluginAttributes.end(); it++ )
576+
{
577+
if ( it->m_knob != NULL) it->m_knob->enable( !m_useFileSequence );
578+
}
579+
}
580+
555581
void LensDistort::buildDynamicKnobs(void* p, DD::Image::Knob_Callback f)
556582
{
557583
PluginAttributeList& attributeList( ((LensDistort*)p)->attributeList() );

0 commit comments

Comments
 (0)