Skip to content
Closed
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
112 changes: 16 additions & 96 deletions include/Gaffer/SplinePlug.h → include/Gaffer/RampPlug.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,98 +41,22 @@
#include "Gaffer/PlugType.h"
#include "Gaffer/TypedPlug.h"

#include "IECore/Spline.h"
#include "IECore/Ramp.h"

namespace Gaffer
{

// This lives outside the class because we don't want multiple incompatible templated versions of
// the same enum floating around
enum SplineDefinitionInterpolation
{
SplineDefinitionInterpolationLinear,
SplineDefinitionInterpolationCatmullRom,
SplineDefinitionInterpolationBSpline,
SplineDefinitionInterpolationMonotoneCubic,
SplineDefinitionInterpolationConstant,
};

// Represents a spline in a way closely aligned with how a user interacts with a spline in the UI.
// The significant differences from IECore::Spline are that end points are not duplicated, and the
// MonotoneCubic interpolation is supported.
//
// This class takes care of converting to IECore::Spline, and helps with converting back from it.
//
// In the future, we aim to move this to Cortex, and use it for all setup of splines, and replace
// IECore::Spline with IECore::SplineEvaluator, which would store things in the right
// format for fast evaluation, but would be totally opaque otherwise - the only way to set up an
// evaluator would be using setting up a SplineDefinition and calling SplineDefinition::evaluator().

template<typename T>
struct GAFFER_API SplineDefinition
{
using XType = typename T::XType;
using YType = typename T::YType;
using PointContainer = typename T::PointContainer;
using Point = typename PointContainer::value_type;

SplineDefinition() : interpolation( SplineDefinitionInterpolationCatmullRom )
{
}

SplineDefinition( const PointContainer &p, SplineDefinitionInterpolation i )
: points( p ), interpolation( i )
{
}

PointContainer points;
SplineDefinitionInterpolation interpolation;


// Convert to Cortex Spline
// In the future, IECore::Spline may be replaced with IECore::SplineEvaluator, and this
// function would be the only way to setup one.
T spline() const;

// Removes start and end points with duplicated X values.
//
// Sources of spline data may or may not contain duplicated end points for a variety of reasons
// ( such as IECore::Splineff having duplicated end points so that spline evaluation will reach
// the final value, or OSL have duplicated end points even for constant and linear splines ).
//
// The spline UI's that Gaffer uses to interact with splines don't support duplicated end
// points well, so regardless of why they are there, this function will remove them.
bool trimEndPoints();

bool operator==( const SplineDefinition<T> &rhs ) const
{
return interpolation == rhs.interpolation && points == rhs.points;
}

bool operator!=( const SplineDefinition<T> &rhs ) const
{
return interpolation != rhs.interpolation || points != rhs.points;
}

private:
int endPointMultiplicity() const;
};

/// The SplinePlug allows the user to manipulate splines that can be
/// converted to IECore::Splines. It's value is a very simple and easy to edit
/// spline representation named SplineDefinition - just a list of control points
/// with one of the interpolations above.
/// The RampPlug allows the user to manipulate an IECore::Ramp, which is
/// a simple curve representation with a list of control points and an
/// interpolations.
//
/// Rather than storing the value atomically, the
/// points and interpolation are represented as individual plugs,
/// allowing the positions of individual points to have input
/// connections from other nodes.
///
/// The value stored should be a clean, user editable value. Underlying technical
/// details such as adding repeated endpoint values are added when converting to
/// IECore::Spline.

template<typename T>
class GAFFER_API SplinePlug : public ValuePlug
class GAFFER_API RampPlug : public ValuePlug
{

public :
Expand All @@ -141,15 +65,15 @@ class GAFFER_API SplinePlug : public ValuePlug
using XPlugType = typename PlugType<typename T::XType>::Type;
using YPlugType = typename PlugType<typename T::YType>::Type;

GAFFER_PLUG_DECLARE_TEMPLATE_TYPE( SplinePlug<T>, ValuePlug );
GAFFER_PLUG_DECLARE_TEMPLATE_TYPE( RampPlug<T>, ValuePlug );

explicit SplinePlug(
const std::string &name = defaultName<SplinePlug>(),
explicit RampPlug(
const std::string &name = defaultName<RampPlug>(),
Direction direction=In,
const T &defaultValue = T(),
unsigned flags = Default
);
~SplinePlug() override;
~RampPlug() override;

/// Implemented to only accept children which are suitable for use as points
/// in the spline.
Expand Down Expand Up @@ -195,16 +119,12 @@ class GAFFER_API SplinePlug : public ValuePlug
T m_defaultValue;
};

using SplineDefinitionff = SplineDefinition<IECore::Splineff>;
using SplineDefinitionfColor3f = SplineDefinition<IECore::SplinefColor3f>;
using SplineDefinitionfColor4f = SplineDefinition<IECore::SplinefColor4f>;

using SplineffPlug = SplinePlug<SplineDefinitionff>;
using SplinefColor3fPlug = SplinePlug<SplineDefinitionfColor3f>;
using SplinefColor4fPlug = SplinePlug<SplineDefinitionfColor4f>;
using RampffPlug = RampPlug<IECore::Rampff>;
using RampfColor3fPlug = RampPlug<IECore::RampfColor3f>;
using RampfColor4fPlug = RampPlug<IECore::RampfColor4f>;

IE_CORE_DECLAREPTR( SplineffPlug );
IE_CORE_DECLAREPTR( SplinefColor3fPlug );
IE_CORE_DECLAREPTR( SplinefColor4fPlug );
IE_CORE_DECLAREPTR( RampffPlug );
IE_CORE_DECLAREPTR( RampfColor3fPlug );
IE_CORE_DECLAREPTR( RampfColor4fPlug );

} // namespace Gaffer
6 changes: 3 additions & 3 deletions include/Gaffer/TypeIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ enum TypeId
V3iPlugTypeId = 118016,
Color3fPlugTypeId = 118017,
Color4fPlugTypeId = 118018,
SplineffPlugTypeId = 118019,
SplinefColor3fPlugTypeId = 118020,
RampffPlugTypeId = 118019,
RampfColor3fPlugTypeId = 118020,
M33fPlugTypeId = 118021,
M44fPlugTypeId = 118022,
BoolPlugTypeId = 118023,
Expand Down Expand Up @@ -98,7 +98,7 @@ enum TypeId
AtomicCompoundDataPlugTypeId = 118052,
BoxTypeId = 118053,
InternedStringVectorDataPlugTypeId = 118054,
SplinefColor4fPlugTypeId = 118055,
RampfColor4fPlugTypeId = 118055,
NumericBookmarkSetTypeId = 118056,
NameSwitchTypeId = 118057,
Transform2DPlugTypeId = 118058,
Expand Down
8 changes: 4 additions & 4 deletions include/GafferCycles/IECoreCyclesPreview/SocketAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "IECore/Export.h"

#include "IECore/CompoundData.h"
#include "IECore/Spline.h"
#include "IECore/Ramp.h"

// Cycles
IECORE_PUSH_DEFAULT_VISIBILITY
Expand Down Expand Up @@ -74,9 +74,9 @@ IECORECYCLES_API Imath::M44f getTransform( const ccl::Transform transform );
IECORECYCLES_API void setSocket( ccl::Node *node, const ccl::SocketType *socket, const IECore::Data *value );
IECORECYCLES_API void setSocket( ccl::Node *node, const std::string &name, const IECore::Data *value );

// Splines
IECORECYCLES_API void setRampSocket( ccl::Node *node, const ccl::SocketType *socket, const IECore::Splineff &spline );
IECORECYCLES_API void setRampSocket( ccl::Node *node, const ccl::SocketType *socket, const IECore::SplinefColor3f &spline );
// Ramps
IECORECYCLES_API void setRampSocket( ccl::Node *node, const ccl::SocketType *socket, const IECore::Rampff &ramp );
IECORECYCLES_API void setRampSocket( ccl::Node *node, const ccl::SocketType *socket, const IECore::RampfColor3f &ramp );

// ParamValue
IECORECYCLES_API ccl::ParamValue setParamValue( const IECore::InternedString &name, const IECore::Data *value );
Expand Down
6 changes: 3 additions & 3 deletions include/GafferImage/Ramp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "GafferImage/FormatPlug.h"

#include "Gaffer/CompoundNumericPlug.h"
#include "Gaffer/SplinePlug.h"
#include "Gaffer/RampPlug.h"
#include "Gaffer/StringPlug.h"

namespace Gaffer
Expand All @@ -66,8 +66,8 @@ class GAFFERIMAGE_API Ramp : public FlatImageSource
GafferImage::FormatPlug *formatPlug();
const GafferImage::FormatPlug *formatPlug() const;

Gaffer::SplinefColor4fPlug *rampPlug();
const Gaffer::SplinefColor4fPlug *rampPlug() const;
Gaffer::RampfColor4fPlug *rampPlug();
const Gaffer::RampfColor4fPlug *rampPlug() const;

Gaffer::V2fPlug *startPositionPlug();
const Gaffer::V2fPlug *startPositionPlug() const;
Expand Down
6 changes: 3 additions & 3 deletions include/GafferScene/AttributeVisualiser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "GafferScene/AttributeProcessor.h"

#include "Gaffer/NumericPlug.h"
#include "Gaffer/SplinePlug.h"
#include "Gaffer/RampPlug.h"

namespace Gaffer
{
Expand Down Expand Up @@ -81,8 +81,8 @@ class GAFFERSCENE_API AttributeVisualiser : public AttributeProcessor
Gaffer::FloatPlug *maxPlug();
const Gaffer::FloatPlug *maxPlug() const;

Gaffer::SplinefColor3fPlug *rampPlug();
const Gaffer::SplinefColor3fPlug *rampPlug() const;
Gaffer::RampfColor3fPlug *rampPlug();
const Gaffer::RampfColor3fPlug *rampPlug() const;

Gaffer::StringPlug *shaderTypePlug();
const Gaffer::StringPlug *shaderTypePlug() const;
Expand Down
2 changes: 1 addition & 1 deletion include/GafferUI/PathColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class GAFFERUI_API PathColumn : public IECore::RefCounted, public Gaffer::Signal
/// - FloatData, DoubleData
/// - DateTimeData
/// - V2fData, V3fData, Color3fData, Color4fData
/// - SplineffData, SplinefColor3fData
/// - RampffData, RampfColor3fData
IECore::ConstDataPtr value;
/// An additional icon to be displayed next to the primary
/// value. Supported types :
Expand Down
2 changes: 1 addition & 1 deletion python/Gaffer/ExtensionAlgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __removeDynamicFlags( self ) :

for plug in Gaffer.Plug.Range( self ) :
plug.setFlags( Gaffer.Plug.Flags.Dynamic, False )
if not isinstance( plug, ( Gaffer.SplineffPlug, Gaffer.SplinefColor3fPlug, Gaffer.SplinefColor4fPlug ) ) :
if not isinstance( plug, ( Gaffer.RampffPlug, Gaffer.RampfColor3fPlug, Gaffer.RampfColor4fPlug ) ) :
for plug in Gaffer.Plug.RecursiveRange( plug ) :
plug.setFlags( Gaffer.Plug.Flags.Dynamic, False )

Expand Down
6 changes: 3 additions & 3 deletions python/GafferDispatch/Wedge.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def __init__( self, name = "Wedge" ) :

# color range

self["ramp"] = Gaffer.SplinefColor3fPlug(
defaultValue = Gaffer.SplineDefinitionfColor3f(
self["ramp"] = Gaffer.RampfColor3fPlug(
defaultValue = IECore.RampfColor3f(
(
( 0, imath.Color3f( 0 ) ),
( 1, imath.Color3f( 1 ) ),
),
Gaffer.SplineDefinitionInterpolation.CatmullRom
IECore.RampInterpolation.CatmullRom
)
)

Expand Down
2 changes: 1 addition & 1 deletion python/GafferImageTest/SamplerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def testVisitPixels( self ):
ramp["format"].setValue( GafferImage.Format( width, height, 1.000 ) )
rampScale = ( width * height - 1 ) / ( width * width + 1 )
ramp["endPosition"].setValue( imath.V2f( 0.5 + 1 * rampScale, 0.5 + width * rampScale ) )
ramp['ramp'].setValue( Gaffer.SplineDefinitionfColor4f( ( ( 0, imath.Color4f( 0 ) ), ( 1, imath.Color4f( width * height - 1 ) )), Gaffer.SplineDefinitionInterpolation.Linear ) )
ramp['ramp'].setValue( IECore.RampfColor4f( ( ( 0, imath.Color4f( 0 ) ), ( 1, imath.Color4f( width * height - 1 ) )), IECore.RampInterpolation.Linear ) )

center = imath.V2i( width // 2, height // 2 )

Expand Down
12 changes: 5 additions & 7 deletions python/GafferOSLTest/OSLCodeTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,16 @@ def testImageProcessingFunctions( self ) :
oslCode["out"]["out"] = Gaffer.FloatPlug( direction = Gaffer.Plug.Direction.Out, flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
self.__assertNoError( oslCode, oslCode["code"].setValue, 'out = inChannel( "R", 0 );' )

def testColorSpline( self ) :
def testColorRamp( self ) :

oslCode = GafferOSL.OSLCode()
oslCode["parameters"]["sp"] = Gaffer.SplinefColor3fPlug(
defaultValue = IECore.SplinefColor3f(
IECore.CubicBasisf.catmullRom(),
oslCode["parameters"]["sp"] = Gaffer.RampfColor3fPlug(
defaultValue = IECore.RampfColor3f(
(
( 0, imath.Color3f( 0 ) ),
( 0, imath.Color3f( 0 ) ),
( 1, imath.Color3f( 1 ) ),
( 1, imath.Color3f( 1 ) ),
)
),
IECore.RampInterpolation.CatmullRom
),
flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic
)
Expand Down
2 changes: 1 addition & 1 deletion python/GafferOSLTest/OSLExpressionEngineTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def testIdentifier( self ) :
s["n"] = Gaffer.Node()
s["n"]["user"]["i"] = Gaffer.FloatPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
s["n"]["user"]["o"] = Gaffer.FloatPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
s["n"]["user"]["s"] = Gaffer.SplineffPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
s["n"]["user"]["s"] = Gaffer.RampffPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )

s["e"] = Gaffer.Expression()
s["e"].setExpression( "", "OSL" )
Expand Down
Loading
Loading