Skip to content

Commit b0d60cc

Browse files
committed
Merge pull request #243 from goddardl/NukeDeepReaderBack
Added support in IECoreNuke::DeepImageReader for ZBack channels
2 parents cdc0d50 + 79b53e3 commit b0d60cc

File tree

4 files changed

+78
-12
lines changed

4 files changed

+78
-12
lines changed

SConstruct

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,9 @@ if doConfigure :
22842284
]
22852285
)
22862286

2287+
if "-DIECORE_WITH_DEEPEXR" in coreEnv["CPPFLAGS"] :
2288+
nukeEnv.Append( CPPFLAGS = [ "-DIECORE_WITH_DEEPEXR" ] )
2289+
22872290
nukePythonModuleEnv.Append( LIBS = [
22882291
os.path.basename( nukeEnv.subst( "$INSTALL_LIB_NAME" ) ),
22892292
os.path.basename( coreEnv.subst( "$INSTALL_LIB_NAME" ) ),

src/IECoreNuke/DeepImageReader.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////
22
//
3-
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
3+
// Copyright (c) 2013-2014, Image Engine Design Inc. All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
66
// modification, are permitted provided that the following conditions are
@@ -136,9 +136,10 @@ bool DeepImageReader::doDeepEngine( DD::Image::Box box, const DD::Image::Channel
136136
{
137137
continue;
138138
}
139-
139+
140+
bool hasDeepBack = m_channels.contains( DD::Image::Chan_DeepBack );
141+
140142
DD::Image::DeepOutPixel dop;
141-
float previousBack = pixel->getDepth( 0 );
142143
for( unsigned int i = 0; i < nSamples; ++i )
143144
{
144145
float *data( pixel->channelData( i ) );
@@ -148,12 +149,24 @@ bool DeepImageReader::doDeepEngine( DD::Image::Box box, const DD::Image::Channel
148149
{
149150
if( z == DD::Image::Chan_DeepFront )
150151
{
151-
dop.push_back( previousBack );
152-
previousBack = depth;
152+
dop.push_back( depth );
153153
}
154154
else if( z == DD::Image::Chan_DeepBack )
155155
{
156-
dop.push_back( depth );
156+
if( !hasDeepBack )
157+
{
158+
float nextFront = depth;
159+
if( i < nSamples - 1 )
160+
{
161+
nextFront = pixel->getDepth( i + 1 );
162+
}
163+
164+
dop.push_back( nextFront );
165+
}
166+
else
167+
{
168+
dop.push_back( data[ m_channelMap[DD::Image::Chan_DeepBack] ] );
169+
}
157170
}
158171
else
159172
{
@@ -194,7 +207,7 @@ bool DeepImageReader::loadFileFromPath( const std::string &filePath, std::string
194207

195208
m_reader->channelNames( channelNames );
196209

197-
m_channels = DD::Image::ChannelSet( DD::Image::Mask_DeepFront | DD::Image::Mask_DeepBack );
210+
m_channels = DD::Image::ChannelSet( DD::Image::Mask_DeepFront );
198211
m_channelMap.clear();
199212
for( std::vector< std::string >::const_iterator it( channelNames.begin() ); it != channelNames.end(); ++it )
200213
{
@@ -219,6 +232,11 @@ bool DeepImageReader::loadFileFromPath( const std::string &filePath, std::string
219232
m_channels += DD::Image::Chan_Blue;
220233
m_channelMap[DD::Image::Chan_Blue] = idx;
221234
}
235+
else if( *it == "ZBack" )
236+
{
237+
m_channels += DD::Image::Chan_DeepBack;
238+
m_channelMap[DD::Image::Chan_DeepBack] = idx;
239+
}
222240
}
223241

224242
Imath::Box2i dataWindow( m_reader->dataWindow() );

test/IECoreNuke/DeepImageReaderTest.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
##########################################################################
22
#
3-
# Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
3+
# Copyright (c) 2013-2014, Image Engine Design Inc. All rights reserved.
44
#
55
# Redistribution and use in source and binary forms, with or without
66
# modification, are permitted provided that the following conditions are
@@ -49,16 +49,56 @@
4949
## cache needs to be refreshed before the deepSample returns a correct result. This may be due to a bug in nuke
5050
## or an error in the IECoreNuke::DeepImageReader code. Further investigation is required.
5151
class DeepImageReaderTest( IECoreNuke.TestCase ) :
52+
53+
__smokeWithoutZBack = "test/IECoreRI/data/exr/smokeWithoutZBack.dexr"
54+
__output = "test/IECoreRI/data/exr/smokeWithZBack.exr"
5255

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

59+
def testCreationOfZBack( self ) :
60+
61+
if not IECore.withDeepEXR :
62+
return
63+
64+
# Create a DeepReader to read the deep EXR.
65+
reader = nuke.createNode( "DeepRead" )
66+
reader["file"].setText( DeepImageReaderTest.__smokeWithoutZBack )
67+
68+
# Write it back out. We do this because nuke's DeepSample node is un
69+
writer = nuke.createNode( "DeepWrite" )
70+
writer["file"].setText( DeepImageReaderTest.__output )
71+
nuke.execute( writer, 1, 1 )
72+
73+
# Read the image back in and check the values of it's ZBack channel.
74+
reader = IECore.EXRDeepImageReader( DeepImageReaderTest.__output )
75+
header = reader.readHeader()
76+
resolution = reader['dataWindow'].size() + IECore.V2i( 1 )
77+
78+
self.assertEqual( set( header['channelNames'] ), set( [ 'R', 'G', 'B', 'A', 'ZBack' ] ) )
79+
80+
for y in range( 0, resolution[0] ) :
81+
for x in range( 0, resolution[1] ) :
82+
83+
p = reader.readPixel( x, y )
84+
n = p.numSamples()
85+
zBackIndex = p.channelIndex( 'ZBack' )
86+
87+
if n >= 1 :
88+
n = n - 1
89+
90+
for s in range( 0, n ) :
91+
front = p.getDepth( s )
92+
back = p.getDepth( s+1 )
93+
actualBack = p.channelData( s )[ zBackIndex ]
94+
self.assertEqual( back, actualBack )
95+
5696
def testReadOfShwAgainstExr( self ) :
5797
import IECoreRI
5898

5999
# Create a DeepReader to read a deep EXR.
60-
readerExr = nuke.createNode( "DeepRead" )
61-
readerExr["file"].setText( self.__inputPaths()["exr"] )
100+
reader = nuke.createNode( "DeepRead" )
101+
reader["file"].setText( self.__inputPaths()["exr"] )
62102

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

74114
# Check that both image have the same number of samples.
75-
nSamplesExr = readerExr.deepSampleCount( x, y )
115+
nSamplesExr = reader.deepSampleCount( x, y )
76116
nSamplesShw = readerShw.deepSampleCount( x, y )
77117
self.assertEqual( nSamplesExr, nSamplesShw )
78118

79119
for channel in [ "front", "back", "A" ] :
80120
for idx in range( 0, nSamplesExr ) :
81-
frontExr = readerExr.deepSample( channel, x, y, idx )
121+
frontExr = reader.deepSample( channel, x, y, idx )
82122
frontShw = readerShw.deepSample( channel, x, y, idx )
83123
self.assertEqual( frontExr, frontShw )
124+
125+
def tearDown( self ) :
126+
127+
if os.path.isfile( DeepImageReaderTest.__output ) :
128+
os.remove( DeepImageReaderTest.__output )
84129

85130
if __name__ == "__main__":
86131
unittest.main()
1.18 MB
Binary file not shown.

0 commit comments

Comments
 (0)