Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,9 @@ if doConfigure :
]
)

if "-DIECORE_WITH_DEEPEXR" in coreEnv["CPPFLAGS"] :
nukeEnv.Append( CPPFLAGS = [ "-DIECORE_WITH_DEEPEXR" ] )

nukePythonModuleEnv.Append( LIBS = [
os.path.basename( nukeEnv.subst( "$INSTALL_LIB_NAME" ) ),
os.path.basename( coreEnv.subst( "$INSTALL_LIB_NAME" ) ),
Expand Down
32 changes: 25 additions & 7 deletions src/IECoreNuke/DeepImageReader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
// Copyright (c) 2013-2014, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
Expand Down Expand Up @@ -136,9 +136,10 @@ bool DeepImageReader::doDeepEngine( DD::Image::Box box, const DD::Image::Channel
{
continue;
}


bool hasDeepBack = m_channels.contains( DD::Image::Chan_DeepBack );

DD::Image::DeepOutPixel dop;
float previousBack = pixel->getDepth( 0 );
for( unsigned int i = 0; i < nSamples; ++i )
{
float *data( pixel->channelData( i ) );
Expand All @@ -148,12 +149,24 @@ bool DeepImageReader::doDeepEngine( DD::Image::Box box, const DD::Image::Channel
{
if( z == DD::Image::Chan_DeepFront )
{
dop.push_back( previousBack );
previousBack = depth;
dop.push_back( depth );
}
else if( z == DD::Image::Chan_DeepBack )
{
dop.push_back( depth );
if( !hasDeepBack )
{
float nextFront = depth;
if( i < nSamples - 1 )
{
nextFront = pixel->getDepth( i + 1 );
}

dop.push_back( nextFront );
}
else
{
dop.push_back( data[ m_channelMap[DD::Image::Chan_DeepBack] ] );
}
}
else
{
Expand Down Expand Up @@ -194,7 +207,7 @@ bool DeepImageReader::loadFileFromPath( const std::string &filePath, std::string

m_reader->channelNames( channelNames );

m_channels = DD::Image::ChannelSet( DD::Image::Mask_DeepFront | DD::Image::Mask_DeepBack );
m_channels = DD::Image::ChannelSet( DD::Image::Mask_DeepFront );
m_channelMap.clear();
for( std::vector< std::string >::const_iterator it( channelNames.begin() ); it != channelNames.end(); ++it )
{
Expand All @@ -219,6 +232,11 @@ bool DeepImageReader::loadFileFromPath( const std::string &filePath, std::string
m_channels += DD::Image::Chan_Blue;
m_channelMap[DD::Image::Chan_Blue] = idx;
}
else if( *it == "ZBack" )
{
m_channels += DD::Image::Chan_DeepBack;
m_channelMap[DD::Image::Chan_DeepBack] = idx;
}
}

Imath::Box2i dataWindow( m_reader->dataWindow() );
Expand Down
55 changes: 50 additions & 5 deletions test/IECoreNuke/DeepImageReaderTest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##########################################################################
#
# Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
# Copyright (c) 2013-2014, Image Engine Design Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
Expand Down Expand Up @@ -49,16 +49,56 @@
## cache needs to be refreshed before the deepSample returns a correct result. This may be due to a bug in nuke
## or an error in the IECoreNuke::DeepImageReader code. Further investigation is required.
class DeepImageReaderTest( IECoreNuke.TestCase ) :

__smokeWithoutZBack = "test/IECoreRI/data/exr/smokeWithoutZBack.dexr"
__output = "test/IECoreRI/data/exr/smokeWithZBack.exr"

def __inputPaths( self ) :
return { "exr" : "test/IECoreRI/data/exr/primitives.exr", "shw" : "test/IECoreRI/data/shw/primitives.shw" }

def testCreationOfZBack( self ) :

if not IECore.withDeepEXR :
return

# Create a DeepReader to read the deep EXR.
reader = nuke.createNode( "DeepRead" )
reader["file"].setText( DeepImageReaderTest.__smokeWithoutZBack )

# Write it back out. We do this because nuke's DeepSample node is un
writer = nuke.createNode( "DeepWrite" )
writer["file"].setText( DeepImageReaderTest.__output )
nuke.execute( writer, 1, 1 )

# Read the image back in and check the values of it's ZBack channel.
reader = IECore.EXRDeepImageReader( DeepImageReaderTest.__output )
header = reader.readHeader()
resolution = reader['dataWindow'].size() + IECore.V2i( 1 )

self.assertEqual( set( header['channelNames'] ), set( [ 'R', 'G', 'B', 'A', 'ZBack' ] ) )

for y in range( 0, resolution[0] ) :
for x in range( 0, resolution[1] ) :

p = reader.readPixel( x, y )
n = p.numSamples()
zBackIndex = p.channelIndex( 'ZBack' )

if n >= 1 :
n = n - 1

for s in range( 0, n ) :
front = p.getDepth( s )
back = p.getDepth( s+1 )
actualBack = p.channelData( s )[ zBackIndex ]
self.assertEqual( back, actualBack )

def testReadOfShwAgainstExr( self ) :
import IECoreRI

# Create a DeepReader to read a deep EXR.
readerExr = nuke.createNode( "DeepRead" )
readerExr["file"].setText( self.__inputPaths()["exr"] )
reader = nuke.createNode( "DeepRead" )
reader["file"].setText( self.__inputPaths()["exr"] )

# Create an ieDeepImageReader to read the deep SHW.
readerShw = nuke.createNode("DeepRead")
Expand All @@ -72,15 +112,20 @@ def testReadOfShwAgainstExr( self ) :
y = random.randint( 0, 511 )

# Check that both image have the same number of samples.
nSamplesExr = readerExr.deepSampleCount( x, y )
nSamplesExr = reader.deepSampleCount( x, y )
nSamplesShw = readerShw.deepSampleCount( x, y )
self.assertEqual( nSamplesExr, nSamplesShw )

for channel in [ "front", "back", "A" ] :
for idx in range( 0, nSamplesExr ) :
frontExr = readerExr.deepSample( channel, x, y, idx )
frontExr = reader.deepSample( channel, x, y, idx )
frontShw = readerShw.deepSample( channel, x, y, idx )
self.assertEqual( frontExr, frontShw )

def tearDown( self ) :

if os.path.isfile( DeepImageReaderTest.__output ) :
os.remove( DeepImageReaderTest.__output )

if __name__ == "__main__":
unittest.main()
Expand Down
Binary file added test/IECoreRI/data/exr/smokeWithoutZBack.dexr
Binary file not shown.