Skip to content

Commit e08b59f

Browse files
IECore : Add Ramp and RampData classes
1 parent 2a646bf commit e08b59f

File tree

18 files changed

+1540
-3
lines changed

18 files changed

+1540
-3
lines changed

include/IECore/DataAlgo.inl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "IECore/PathMatcherData.h"
4040
#include "IECore/SimpleTypedData.h"
4141
#include "IECore/SplineData.h"
42+
#include "IECore/RampData.h"
4243
#include "IECore/TransformationMatrixData.h"
4344
#include "IECore/VectorTypedData.h"
4445

@@ -132,6 +133,12 @@ typename std::invoke_result_t<F, Data *, Args&&...> dispatch( Data *data, F &&fu
132133
return functor( static_cast<SplinefColor3fData *>( data ), std::forward<Args>( args )... );
133134
case SplinefColor4fDataTypeId :
134135
return functor( static_cast<SplinefColor4fData *>( data ), std::forward<Args>( args )... );
136+
case RampffDataTypeId :
137+
return functor( static_cast<RampffData *>( data ), std::forward<Args>( args )... );
138+
case RampfColor3fDataTypeId :
139+
return functor( static_cast<RampfColor3fData *>( data ), std::forward<Args>( args )... );
140+
case RampfColor4fDataTypeId :
141+
return functor( static_cast<RampfColor4fData *>( data ), std::forward<Args>( args )... );
135142
case DateTimeDataTypeId :
136143
return functor( static_cast<DateTimeData *>( data ), std::forward<Args>( args )... );
137144
case BoolVectorDataTypeId :
@@ -286,6 +293,12 @@ typename std::invoke_result_t<F, const Data *, Args&&...> dispatch( const Data *
286293
return functor( static_cast<const SplinefColor3fData *>( data ), std::forward<Args>( args )... );
287294
case SplinefColor4fDataTypeId :
288295
return functor( static_cast<const SplinefColor4fData *>( data ), std::forward<Args>( args )... );
296+
case RampffDataTypeId :
297+
return functor( static_cast<const RampffData *>( data ), std::forward<Args>( args )... );
298+
case RampfColor3fDataTypeId :
299+
return functor( static_cast<const RampfColor3fData *>( data ), std::forward<Args>( args )... );
300+
case RampfColor4fDataTypeId :
301+
return functor( static_cast<const RampfColor4fData *>( data ), std::forward<Args>( args )... );
289302
case DateTimeDataTypeId :
290303
return functor( static_cast<const DateTimeData *>( data ), std::forward<Args>( args )... );
291304
case BoolVectorDataTypeId :

include/IECore/DespatchTypedData.inl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "IECore/DateTimeData.h"
3939
#include "IECore/SimpleTypedData.h"
4040
#include "IECore/SplineData.h"
41+
#include "IECore/RampData.h"
4142
#include "IECore/TransformationMatrixData.h"
4243
#include "IECore/TypeTraits.h"
4344
#include "IECore/VectorTypedData.h"
@@ -263,6 +264,18 @@ typename Functor::ReturnType despatchTypedData( Data *data, Functor &functor, Er
263264
return
264265
typename Detail::DespatchTypedData< Functor, SplinefColor4fData, ErrorHandler >
265266
::template Func<Enabler>()( static_cast<SplinefColor4fData *>( data ), functor, errorHandler );
267+
case RampffDataTypeId :
268+
return
269+
typename Detail::DespatchTypedData< Functor, RampffData, ErrorHandler >
270+
::template Func<Enabler>()( static_cast<RampffData *>( data ), functor, errorHandler );
271+
case RampfColor3fDataTypeId :
272+
return
273+
typename Detail::DespatchTypedData< Functor, RampfColor3fData, ErrorHandler >
274+
::template Func<Enabler>()( static_cast<RampfColor3fData *>( data ), functor, errorHandler );
275+
case RampfColor4fDataTypeId :
276+
return
277+
typename Detail::DespatchTypedData< Functor, RampfColor4fData, ErrorHandler >
278+
::template Func<Enabler>()( static_cast<RampfColor4fData *>( data ), functor, errorHandler );
266279
case DateTimeDataTypeId :
267280
return
268281
typename Detail::DespatchTypedData< Functor, DateTimeData, ErrorHandler >

include/IECore/Ramp.h

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2025, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECORE_RAMP_H
36+
#define IECORE_RAMP_H
37+
38+
#include "IECore/Export.h"
39+
#include "IECore/Spline.h"
40+
#include "IECore/MessageHandler.h"
41+
42+
IECORE_PUSH_DEFAULT_VISIBILITY
43+
#include "Imath/ImathColor.h"
44+
IECORE_POP_DEFAULT_VISIBILITY
45+
46+
#include <map>
47+
48+
namespace IECore
49+
{
50+
51+
// This lives outside the class because we don't want multiple incompatible templated versions of
52+
// the same enum floating around
53+
enum class RampInterpolation
54+
{
55+
Linear = 0,
56+
CatmullRom = 1,
57+
BSpline = 2,
58+
MonotoneCubic = 3,
59+
Constant = 4,
60+
};
61+
62+
/// A Ramp represents a spline-like curve as it is represented in a simple UI: with a set of independent
63+
/// control points, and an interpolation type selected from RampInterpolation.
64+
///
65+
/// Rather than storing the lower level IECore::Spline*, we now store this Ramp type in shader networks,
66+
/// and only convert to the lower level class with the evaluator() function when evaluation is needed.
67+
template<typename X, typename Y>
68+
class IECORE_EXPORT Ramp
69+
{
70+
71+
public :
72+
73+
typedef X XType;
74+
typedef Y YType;
75+
76+
typedef CubicBasis<XType> Basis;
77+
typedef std::multimap<X, Y> PointContainer;
78+
typedef typename PointContainer::value_type Point;
79+
80+
81+
82+
Ramp() : interpolation( RampInterpolation::CatmullRom )
83+
{
84+
}
85+
86+
Ramp( const PointContainer &p, RampInterpolation i )
87+
: points( p ), interpolation( i )
88+
{
89+
}
90+
91+
PointContainer points;
92+
RampInterpolation interpolation;
93+
94+
95+
// Convert to Cortex Spline
96+
// In the future, IECore::Spline may be replaced with IECore::SplineEvaluator, and this
97+
// function would be the only way to setup one.
98+
IECore::Spline<X, Y> evaluator() const;
99+
100+
// In order to write shader parameters to renderers or USD, we need to convert Ramps to a convention
101+
// that can be stored in raw OSL. Based on the arguments to the OSL spline() function, we've come up
102+
// with a convention for storing a string basis and separate position and value arrays, where the
103+
// the position and value arrays contain any duplicated end points necessary for the resulting OSL
104+
// spline to cover the full range of the ramp.
105+
//
106+
// These functions convert to and from this convention ( and can also be used for converting from other
107+
// similar conventions with some pre-processing ).
108+
//
109+
// NOTE: Some aspects of the convention we've picked are not actually very universal. We haven't
110+
// found any shader's in the wild that actually expect duplicated end point ( aside from Gaffer's
111+
// shader library ). Other shader authors seem to be implementing their own spline functions that don't
112+
// require duplicated endpoints ( 3delight ), or put code to perform the duplication in their shader
113+
// before calling spline ( PRMan ). We've stuck to duplicating the end points because unnecessarily
114+
// duplicating endpoints doesn't cause any problems other than being a minor waste of performance.
115+
// It seems like there's an argument that the best approach would be to put the endpoint duplication
116+
// inside the shader like PRMan, but this is working fine for now.
117+
void fromOSL( const std::string &basis, const std::vector<X> &positions, const std::vector<Y> &values, const std::string &identifier );
118+
void toOSL( std::string &basis, std::vector<X> &positions, std::vector<Y> &values ) const;
119+
120+
// If there are connections to a Ramp, and we convert it to the OSL convention with duplicated endpoints,
121+
// then the connections will need to be offset to match - this defines the offset.
122+
int oslAdaptorOffset() const;
123+
124+
// In Cortex 10.6 and earlier, shader parameters were represented uing IECore::Spline*Data instead of
125+
// IECore::Ramp*Data. This is used in converting SCC files to the new standard.
126+
// \todo : This can probably be removed in the next major version - we're not actually aware of any
127+
// significant users of Cortex who both use SCC files, and cache shaders, so this compatibility shim
128+
// is only needed theoretically.
129+
void fromDeprecatedSpline( const IECore::Spline<X, Y> &deprecated );
130+
131+
bool operator==( const Ramp<X,Y> &rhs ) const;
132+
bool operator!=( const Ramp<X,Y> &rhs ) const;
133+
134+
};
135+
136+
using Rampff = Ramp<float, float>;
137+
using RampfColor3f = Ramp<float, Imath::Color3f>;
138+
using RampfColor4f = Ramp<float, Imath::Color4f>;
139+
140+
template<typename X, typename Y>
141+
inline void murmurHashAppend( IECore::MurmurHash &h, const Ramp<X,Y> &data )
142+
{
143+
h.append( data.interpolation );
144+
for ( auto &p : data.points )
145+
{
146+
h.append( p.first );
147+
h.append( p.second );
148+
}
149+
}
150+
151+
} // namespace IECore
152+
153+
#endif // IECORE_RAMP_H

include/IECore/RampData.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2025, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECORE_RAMPDATA_H
36+
#define IECORE_RAMPDATA_H
37+
38+
#include "IECore/Ramp.h"
39+
#include "IECore/TypedData.h"
40+
41+
namespace IECore
42+
{
43+
44+
// Ramp data types.
45+
46+
IECORE_DECLARE_TYPEDDATA( RampffData, Rampff, void, SharedDataHolder )
47+
IECORE_DECLARE_TYPEDDATA( RampfColor3fData, RampfColor3f, void, SharedDataHolder )
48+
IECORE_DECLARE_TYPEDDATA( RampfColor4fData, RampfColor4f, void, SharedDataHolder )
49+
50+
}
51+
52+
#endif // IECORE_RAMPDATA_H

include/IECore/TypeIds.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ enum TypeId
203203
YUVImageWriterTypeId = 265,
204204
DateTimeDataTypeId = 269,
205205
DateTimeParameterTypeId = 270,
206-
TimeDurationDataTypeId = 272, // Obsolete
207-
TimeDurationParameterTypeId = 273, // Obsolete
208-
TimePeriodDataTypeId = 274, // Obsolete
206+
RampffDataTypeId = 272,
207+
RampfColor3fDataTypeId = 273,
208+
RampfColor4fDataTypeId = 274,
209209
TimePeriodParameterTypeId = 275, // Obsolete
210210
FrameListTypeId = 279,
211211
EmptyFrameListTypeId = 280,

include/IECore/TypeTraits.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include "IECore/SimpleTypedData.h"
4141
#include "IECore/Spline.h"
4242
#include "IECore/SplineData.h"
43+
#include "IECore/Ramp.h"
44+
#include "IECore/RampData.h"
4345
#include "IECore/TransformationMatrixData.h"
4446
#include "IECore/VectorTypedData.h"
4547

@@ -293,6 +295,14 @@ template<typename T, typename U> struct IsSpline< const Spline<T, U> > : public
293295
/// IsSplineTypedData
294296
template< typename T > struct IsSplineTypedData : boost::mpl::and_< IsTypedData<T>, IsSpline< typename ValueType<T>::type > > {};
295297

298+
/// IsRamp
299+
template<typename T, typename U = void > struct IsRamp : public boost::false_type {};
300+
template<typename T, typename U> struct IsRamp< Ramp<T, U> > : public boost::true_type {};
301+
template<typename T, typename U> struct IsRamp< const Ramp<T, U> > : public boost::true_type {};
302+
303+
/// IsRampTypedData
304+
template< typename T > struct IsRampTypedData : boost::mpl::and_< IsTypedData<T>, IsRamp< typename ValueType<T>::type > > {};
305+
296306
/// IsStringVectorTypeData
297307
template<typename T> struct IsStringVectorTypedData : public boost::false_type {};
298308
template<> struct IsStringVectorTypedData< TypedData<std::vector<std::string> > > : public boost::true_type {};

include/IECorePython/RampBinding.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2025, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECOREPYTHON_RAMPBINDING_H
36+
#define IECOREPYTHON_RAMPBINDING_H
37+
38+
#include "IECorePython/Export.h"
39+
40+
namespace IECorePython
41+
{
42+
43+
IECOREPYTHON_API void bindRamp();
44+
45+
}
46+
47+
#endif // IECOREPYTHON_RAMPBINDING_H
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2008-2010, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECOREPYTHON_RAMPDATABINDING_H
36+
#define IECOREPYTHON_RAMPDATABINDING_H
37+
38+
#include "IECorePython/Export.h"
39+
40+
namespace IECorePython
41+
{
42+
IECOREPYTHON_API void bindRampData();
43+
}
44+
45+
#endif // IECOREPYTHON_RAMPDATABINDING_H

0 commit comments

Comments
 (0)