Skip to content

Commit 1275603

Browse files
IECore : Add Ramp and RampData classes
1 parent 21eaf50 commit 1275603

File tree

18 files changed

+1534
-3
lines changed

18 files changed

+1534
-3
lines changed

Changes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
10.x.x.x (relative to 10.6.x.x)
22
========
33

4+
Features
5+
--------
6+
7+
- IECore : Added Rampff, RampfColor3f, RampfColor4f and corresponding Ramp*Data classes, for representing user facing shader ramp parameters.
8+
49
Breaking Changes
510
----------------
611

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/Ramp.h

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
///
68+
/// This was chosen as superior to IECore::Spline* because IECoreS::spline* requires duplicating the
69+
/// end points in order to make the curve reach the first and last control point.
70+
template<typename X, typename Y>
71+
class IECORE_EXPORT Ramp
72+
{
73+
74+
public :
75+
76+
using XType = X;
77+
using YType = Y;
78+
79+
using PointContainer = std::multimap<X, Y>;
80+
using Point = typename PointContainer::value_type;
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+
// Convert to and from a set of arguments that could be passed to a pair of spline() and
101+
// splineinverse() functions in OSL. This can be useful in converting ramps to parameters
102+
// for OSL shaders.
103+
//
104+
// Some shader libraries use these arguments directly as shader parameters ( i.e. Gaffer ).
105+
// Some shader libraries preprocess shader parameters before passing them to spline(),
106+
// so they don't need some aspects of this conversion ( like endpoint duplication ), but
107+
// the extra endpoint duplication doesn't cause problems ( i.e. PRMan ).
108+
// Some shader libraries are doing their own thing, implementing their own custom math,
109+
// but convention is still similar enough that these function can be a useful building
110+
// block in converting to something that mostly works ( i.e. 3delight ).
111+
void fromOSL( const std::string &basis, const std::vector<X> &positions, const std::vector<Y> &values, const std::string &identifier );
112+
void toOSL( std::string &basis, std::vector<X> &positions, std::vector<Y> &values ) const;
113+
114+
/// The number of times `toOSL()` repeats the initial point.
115+
int oslStartPointMultiplicity() const;
116+
117+
// In Cortex 10.6 and earlier, shader parameters were represented uing IECore::Spline*Data instead of
118+
// IECore::Ramp*Data. This is used in converting SCC files to the new standard.
119+
// \todo : This can probably be removed in the next major version - we're not actually aware of any
120+
// significant users of Cortex who both use SCC files, and cache shaders, so this compatibility shim
121+
// is only needed theoretically.
122+
void fromDeprecatedSpline( const IECore::Spline<X, Y> &deprecated );
123+
124+
bool operator==( const Ramp<X,Y> &rhs ) const;
125+
bool operator!=( const Ramp<X,Y> &rhs ) const;
126+
127+
};
128+
129+
using Rampff = Ramp<float, float>;
130+
using RampfColor3f = Ramp<float, Imath::Color3f>;
131+
using RampfColor4f = Ramp<float, Imath::Color4f>;
132+
133+
template<typename X, typename Y>
134+
inline void murmurHashAppend( IECore::MurmurHash &h, const Ramp<X,Y> &data )
135+
{
136+
h.append( data.interpolation );
137+
for ( auto &p : data.points )
138+
{
139+
h.append( p.first );
140+
h.append( p.second );
141+
}
142+
}
143+
144+
} // namespace IECore
145+
146+
#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

python/IECore/DataTraits.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ def isSequenceDataType(obj):
203203
IECore.SplinefColor3fData: ( IECore.SplinefColor3f, True ),
204204
IECore.SplinefColor4fData: ( IECore.SplinefColor4f, True ),
205205

206+
IECore.RampffData: ( IECore.Rampff, True ),
207+
IECore.RampfColor3fData: ( IECore.RampfColor3f, True ),
208+
IECore.RampfColor4fData: ( IECore.RampfColor4f, True ),
209+
206210
IECore.DateTimeData: ( datetime.datetime, True ),
207211
IECore.TimeCodeData: ( IECore.TimeCode, True ),
208212
IECore.PathMatcherData: ( IECore.PathMatcher, True ),

0 commit comments

Comments
 (0)