diff --git a/pxr/base/lib/gf/CMakeLists.txt b/pxr/base/lib/gf/CMakeLists.txt index d384c4a023..22a41e5fd3 100644 --- a/pxr/base/lib/gf/CMakeLists.txt +++ b/pxr/base/lib/gf/CMakeLists.txt @@ -16,7 +16,6 @@ pxr_shared_library(gf PUBLIC_CLASSES bbox3d camera - colorRamp frustum gamma half @@ -49,8 +48,6 @@ pxr_shared_library(gf range3f ray rect2i - rgb - rgba rotation size2 size3 @@ -83,7 +80,6 @@ pxr_shared_library(gf module.cpp wrapBBox3d.cpp wrapCamera.cpp - wrapColorRamp.cpp wrapFrustum.cpp wrapGamma.cpp wrapHalf.cpp @@ -112,8 +108,6 @@ pxr_shared_library(gf wrapRange3d.cpp wrapRange3f.cpp wrapRay.cpp - wrapRGB.cpp - wrapRGBA.cpp wrapRect2i.cpp wrapRotation.cpp wrapSize2.cpp @@ -166,7 +160,6 @@ pxr_build_test(testGfHardToReach pxr_test_scripts( testenv/testGfBBox3d.py testenv/testGfCamera.py - testenv/testGfColorRamp.py testenv/testGfDecomposeRotation.py testenv/testGfFrustum.py testenv/testGfGamma.py @@ -182,7 +175,6 @@ pxr_test_scripts( testenv/testGfRange.py testenv/testGfRay.py testenv/testGfRect2i.py - testenv/testGfRGB.py testenv/testGfRotation.py testenv/testGfSize.py testenv/testGfTransform.py @@ -193,10 +185,6 @@ pxr_register_test(testGfBBox3d PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testGfBBox3d" ) -pxr_register_test(testGfColorRamp - PYTHON - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testGfColorRamp" -) pxr_register_test(testGfDecomposeRotation PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testGfDecomposeRotation" @@ -260,10 +248,6 @@ pxr_register_test(testGfRect2i PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testGfRect2i" ) -pxr_register_test(testGfRGB - PYTHON - COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testGfRGB" -) pxr_register_test(testGfRotation PYTHON COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testGfRotation" diff --git a/pxr/base/lib/gf/__init__.py b/pxr/base/lib/gf/__init__.py index 1774b70441..8dd1dec7f7 100644 --- a/pxr/base/lib/gf/__init__.py +++ b/pxr/base/lib/gf/__init__.py @@ -40,6 +40,3 @@ del __DOC except Exception: pass - -# FIXME XXX: need to remove Interval, RGB, RGBA, ColorRamp for public -# API, need to leave them for tests. diff --git a/pxr/base/lib/gf/colorRamp.cpp b/pxr/base/lib/gf/colorRamp.cpp deleted file mode 100644 index da14f17d0f..0000000000 --- a/pxr/base/lib/gf/colorRamp.cpp +++ /dev/null @@ -1,175 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the Apache License, Version 2.0 (the "Apache License") -// with the following modification; you may not use this file except in -// compliance with the Apache License and the following modification to it: -// Section 6. Trademarks. is deleted and replaced with: -// -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor -// and its affiliates, except as required to comply with Section 4(c) of -// the License and to reproduce the content of the NOTICE file. -// -// You may obtain a copy of the Apache License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the Apache License with the above modification is -// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the Apache License for the specific -// language governing permissions and limitations under the Apache License. -// -#include "pxr/base/gf/colorRamp.h" -#include "pxr/base/gf/math.h" -#include "pxr/base/gf/rgb.h" -#include "pxr/base/tf/type.h" - -TF_REGISTRY_FUNCTION(TfType) { - TfType::Define(); -} - -/* - * A ramp from (X0,Y0) to (X1,Y1), with slope D0 at X0 and D1 at Y1. - * The ramp is constructed piecewise from a quadratic "shoulder" segment, - * then a linear segment, then a quadratic "shoulder" segment; the widths - * of the shoulders are given by w0 and w1. - */ -static double -_Stramp(double X, double X0, double X1, double Y0, double Y1, double D0, - double D1, double w0, double w1) -{ - double DX, DY, x, d0, d1, wnorm, y; - - /* - * change variables to x in [0,1] and y in [0,1] - */ - DY = Y1-Y0; - DX = X1-X0; - if (DY == 0 || DX==0) return Y0; - x = (X-X0)/DX; - d0 = D0*DX/DY; - d1 = D1*DX/DY; - - /* - * make sure shoulder widths don't sum to more than 1 - */ - wnorm = 1./GfMax(1.,w0+w1); - w0 *= wnorm; - w1 *= wnorm; - - /* compute y */ - if (x <= 0.) - y = 0.; - else if (x >= 1.) - y = 1.; - else { - double xr = 2.-w0-w1; - double a = (2. - w1*d1 + (w1-2.)*d0)/(2.*xr); - double b = (2. - w0*d0 + (w0-2.)*d1)/(2.*xr); - if (x < w0) - y = a*x*x/w0 + d0*x; - else if (x > 1.-w1) { - double omx = 1.-x; - y = 1. - b*omx*omx/w1 - d1*omx; - } - else { - double ya = a*w0 + d0*w0; - double da = 2.*a + d0; - y = ya + (x-w0)*da; - } - } - - /* - * map y back to Y and return. Note: analytically y is always in - * [0,1], but numerically it might have noise so clamp it. - */ - return GfClamp(y,0.,1.)*DY + Y0; -} - -static GfRGB -_ShapeColorInterpExperiment( - const GfRGB &C0, const GfRGB &C1, const GfRGB &Cmid, - double slide, double width0, double width1, double /* widthMid */, - double widthMid0, double widthMid1, double alpha) -{ - GfRGB Cret; - - for (int i=0; i<3; i++) { - double c0 = C0[i]; - double c1 = C1[i]; - double cMid = Cmid[i]; - double cmin = GfMin(c0,c1); - double cmax = GfMax(c0,c1); - double slope; - - /* - * determine slope at center point. - */ - if (cMid <= cmin || cMid >= cmax) { - /* - * if the center is outside the min/max, we want it to be the - * extremum, its slope should be 0. - */ - slope = 0; - } - else { - /* compute a desired slope by averaging the normalized - * tangents, considering each segment to be linear. - * (should this be a weighted average? something else?) - */ - - double tan0y = cMid-c0; - double tan0x = slide; - double tan1y = c1-cMid; - double tan1x = 1.-slide; - - double len0 = hypot(tan0x,tan0y); - double len1 = hypot(tan1x,tan1y); - - double cseg, scale; - - slope = (len1*tan0y+len0*tan1y)/(len1*tan0x+len0*tan1x); - - /* that desired slope is OK if the center value is actually on the - * segment from min to max. but as the value approach either of - * those bounds, we want the slope to be 0. so we scale that slope - * linearly with distance from the hypothetical intercept. - */ - cseg = GfLerp(slide,c0,c1); - scale = cMid < cseg ? (cMid-cmin)/(cseg-cmin) - : (cMid-cmax)/(cseg-cmax); - slope *= scale; - } - - /* - * now do a smoothramp on each side of the center, matching the - * target slope. - */ - if (alpha < slide) { - Cret[i] = _Stramp(alpha, - 0.,slide, - c0,cMid, - 0.,slope, - width0,widthMid0); - } - else { - Cret[i] = _Stramp(alpha, - slide,1., - cMid,c1, - slope,0., - widthMid1,width1); - } - } - - return Cret; -} - -GfRGB -GfColorRamp::Eval(const double x) const -{ - return _ShapeColorInterpExperiment( _cMax, _cMin, _cMid, - _midPos, _widthMax, _widthMin, 0 /* unused */, - _widthMidOut, _widthMidIn, x ); -} diff --git a/pxr/base/lib/gf/colorRamp.h b/pxr/base/lib/gf/colorRamp.h deleted file mode 100644 index 4ef98839dd..0000000000 --- a/pxr/base/lib/gf/colorRamp.h +++ /dev/null @@ -1,150 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the Apache License, Version 2.0 (the "Apache License") -// with the following modification; you may not use this file except in -// compliance with the Apache License and the following modification to it: -// Section 6. Trademarks. is deleted and replaced with: -// -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor -// and its affiliates, except as required to comply with Section 4(c) of -// the License and to reproduce the content of the NOTICE file. -// -// You may obtain a copy of the Apache License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the Apache License with the above modification is -// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the Apache License for the specific -// language governing permissions and limitations under the Apache License. -// -#ifndef GF_COLORRAMP_H -#define GF_COLORRAMP_H - -/// \file gf/colorRamp.h -/// \ingroup group_gf_Color - -#include "pxr/base/gf/math.h" -#include "pxr/base/gf/rgb.h" -#include "pxr/base/tf/tf.h" -#include - -/// \class GfColorRamp -/// \ingroup group_gf_Color -/// -/// A color ramp, as commonly used in Pixar shaders. -/// -class GfColorRamp -{ -public: - /// Constructor. - /// The default color ramp is a red->green->blue gradient. - GfColorRamp( - const GfRGB& cMin = GfRGB(1,0,0), - const GfRGB& cMid = GfRGB(0,1,0), - const GfRGB& cMax = GfRGB(0,0,1), - float midPos = 0.5, - float widthMin = 0.3, - float widthMidIn = 0.3, - float widthMidOut = 0.3, - float widthMax = 0.5, - bool useColorRamp = true, - bool switchable = false - ) : - _useColorRamp(useColorRamp), - _switchable(switchable), - _cMin(cMin), - _cMid(cMid), - _cMax(cMax), - _midPos(midPos), - _widthMin(widthMin), - _widthMidIn(widthMidIn), - _widthMidOut(widthMidOut), - _widthMax(widthMax) - { - } - - /// Constructor. - /// The default color ramp is a red->green->blue gradient. - GfColorRamp( - bool useColorRamp, - const GfRGB& cMin = GfRGB(1,0,0), - const GfRGB& cMid = GfRGB(0,1,0), - const GfRGB& cMax = GfRGB(0,0,1), - float midPos = 0.5, - float widthMin = 0.3, - float widthMidIn = 0.3, - float widthMidOut = 0.3, - float widthMax = 0.5, - bool switchable = false - ) : - _useColorRamp(useColorRamp), - _switchable(switchable), - _cMin(cMin), - _cMid(cMid), - _cMax(cMax), - _midPos(midPos), - _widthMin(widthMin), - _widthMidIn(widthMidIn), - _widthMidOut(widthMidOut), - _widthMax(widthMax) - { - } - - /// Evaluate the ramp at the given value. x is in [0..1]. - GfRGB Eval(const double x) const; - - bool operator ==(const GfColorRamp &ramp) const { - return ((_useColorRamp == ramp._useColorRamp) && - (_cMin == ramp._cMin) && - (_cMid == ramp._cMid) && - (_cMax == ramp._cMax) && - (_midPos == ramp._midPos) && - (_widthMin == ramp._widthMin) && - (_widthMidIn == ramp._widthMidIn) && - (_widthMidOut == ramp._widthMidOut) && - (_widthMax == ramp._widthMax)); - } - - bool operator !=(const GfColorRamp &ramp) const { - return !(*this == ramp); - } - - bool GetUseColorRamp() const {return !_switchable || _useColorRamp;} - - const GfRGB &GetCMin() const { return _cMin; } - const GfRGB &GetCMid() const { return _cMid; } - const GfRGB &GetCMax() const { return _cMax; } - - double GetMidPos() const { return _midPos; } - double GetWidthMin() const { return _widthMin; } - double GetWidthMidIn() const { return _widthMidIn; } - double GetWidthMidOut() const { return _widthMidOut; } - double GetWidthMax() const { return _widthMax; } - - bool GetSwitchable() const { return _switchable; } - - void SetUseColorRamp(bool b) { _useColorRamp = b; } - - void SetCMin(const GfRGB &c) { _cMin = c; } - void SetCMid(const GfRGB &c) { _cMid = c; } - void SetCMax(const GfRGB &c) { _cMax = c; } - - void SetMidPos(double val) { _midPos = val; } - void SetWidthMin(double val) { _widthMin = val; } - void SetWidthMidIn(double val) { _widthMidIn = val; } - void SetWidthMidOut(double val) { _widthMidOut = val; } - void SetWidthMax(double val) { _widthMax = val; } - - void SetSwitchable(bool b) { _switchable = b; } - -private: - bool _useColorRamp, _switchable; - GfRGB _cMin, _cMid, _cMax; - double _midPos, _widthMin, _widthMidIn, _widthMidOut, _widthMax; -}; - -#endif diff --git a/pxr/base/lib/gf/declare.h b/pxr/base/lib/gf/declare.h index 0b0b9cdd55..b74008c052 100644 --- a/pxr/base/lib/gf/declare.h +++ b/pxr/base/lib/gf/declare.h @@ -31,7 +31,6 @@ class half; class GfBBox3d; -class GfColorRamp; class GfFrustum; class GfInterval; class GfMultiInterval; @@ -45,8 +44,6 @@ class GfQuaternion; template class GfRandom; class GfRay; class GfRect2i; -class GfRGBA; -class GfRGB; class GfRect2i; class GfRotation; class GfSize2; diff --git a/pxr/base/lib/gf/module.cpp b/pxr/base/lib/gf/module.cpp index 0614ce211e..4475e6f162 100644 --- a/pxr/base/lib/gf/module.cpp +++ b/pxr/base/lib/gf/module.cpp @@ -26,7 +26,6 @@ TF_WRAP_MODULE { TF_WRAP( BBox3d ); - TF_WRAP( ColorRamp ); TF_WRAP( Frustum ); TF_WRAP( Gamma ); TF_WRAP( Half ); @@ -51,8 +50,6 @@ TF_WRAP_MODULE TF_WRAP( Quath ); TF_WRAP( Quaternion ); TF_WRAP( Ray ); - TF_WRAP( RGB ); - TF_WRAP( RGBA ); // Order of wrapping Ranges matters because in the cases where overloads // could choose either float or double, we want the double versions to be diff --git a/pxr/base/lib/gf/rgb.cpp b/pxr/base/lib/gf/rgb.cpp deleted file mode 100644 index 019b1a8f0c..0000000000 --- a/pxr/base/lib/gf/rgb.cpp +++ /dev/null @@ -1,190 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the Apache License, Version 2.0 (the "Apache License") -// with the following modification; you may not use this file except in -// compliance with the Apache License and the following modification to it: -// Section 6. Trademarks. is deleted and replaced with: -// -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor -// and its affiliates, except as required to comply with Section 4(c) of -// the License and to reproduce the content of the NOTICE file. -// -// You may obtain a copy of the Apache License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the Apache License with the above modification is -// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the Apache License for the specific -// language governing permissions and limitations under the Apache License. -// -#include "pxr/base/gf/rgb.h" -#include "pxr/base/gf/math.h" -#include "pxr/base/gf/matrix4d.h" -#include "pxr/base/tf/type.h" - -#include - -TF_REGISTRY_FUNCTION(TfType) -{ - TfType::Define(); -} - -GfRGB GfRGB::Transform(const GfMatrix4d &m) const -{ - return GfRGB(m.TransformDir(_rgb)); -} - -GfRGB operator *(const GfRGB &c, const GfMatrix4d &m) -{ - return c.Transform(m); -} - -bool -GfIsClose(const GfRGB &v1, const GfRGB &v2, double tolerance) -{ - return GfIsClose(v1._rgb, v2._rgb, tolerance); -} - -void -GfRGB::GetHSV(float *h, float *s, float *v) const -{ - const GfRGB &rgb = *this; - - float max = GfMax(rgb[0], GfMax(rgb[1], rgb[2])); - float min = GfMin(rgb[0], GfMin(rgb[1], rgb[2])); - float diff = max - min; - - // The value is the maximum component. - *v = max; - - // Saturation - *s = (max != 0.0 ? diff / max : 0.0); - - // Hue - if (*s != 0.0) { - if (rgb[0] == max) - *h = (rgb[1] - rgb[2]) / diff; - else if (rgb[1] == max) - *h = 2.0 + (rgb[2] - rgb[0]) / diff; - else - *h = 4.0 + (rgb[0] - rgb[1]) / diff; - if (*h < 0.0) - *h += 6.0; - *h /= 6.0; - } - else - *h = 0.0; -} - -void -GfRGB::SetHSV(float h, float s, float v) -{ - float hue = (h == 1.0 ? 0.0 : 6.0 * h); - int hueSextant = int(floor(hue)); - float hueFrac = hue - hueSextant; - - float t1 = v * (1.0 - s); - float t2 = v * (1.0 - (s * hueFrac)); - float t3 = v * (1.0 - (s * (1.0 - hueFrac))); - - switch (hueSextant) { - case 0: - Set(v, t3, t1); - break; - case 1: - Set(t2, v, t1); - break; - case 2: - Set(t1, v, t3); - break; - case 3: - Set(t1, t2, v); - break; - case 4: - Set(t3, t1, v); - break; - case 5: - Set(v, t1, t2); - break; - } -} - -// Offsets are kinda funky. Essentially each component of an offset is -// a scaling term which says how far a component should be changed and in -// what direction. An offset of 0.5, for example, moves its component 50% -// of the distance between the base value and its maximum value in the -// positive direction, whereas an offset of -0.1 moves its component 10% of -// the distance between its base value and its minimum value in the negative -// direction. -// -GfRGB GfRGB::GetColorFromOffset(const GfRGB &offsetBase, - const GfRGB &offsetHSV) -{ - GfRGB offsetBaseHSV, offsetColorHSV; - - // Convert base to HSV space - offsetBase.GetHSV(&offsetBaseHSV[0], &offsetBaseHSV[1], - &offsetBaseHSV[2]); - - // Offset each component of base in HSV space - for (int c = 0; c < 3; ++c) { - // For sanity - float baseC = GfClamp(offsetBaseHSV[c], 0, 1); - float off = GfClamp(offsetHSV[c], -1, 1); - - offsetColorHSV[c] = baseC + off * (off > 0 ? 1 - baseC : baseC); - } - - // Convert offsetColorHSV to RGB space - GfRGB offsetColor; - offsetColor.SetHSV(offsetColorHSV[0], offsetColorHSV[1], - offsetColorHSV[2]); - - return offsetColor; -} - -GfRGB GfRGB::GetOffsetFromColor(const GfRGB &offsetBase, - const GfRGB &offsetColor) -{ - GfRGB offsetHSV; - - // Convert offsetBase and offsetColor to HSV space - GfRGB offsetBaseHSV, offsetColorHSV; - - offsetBase.GetHSV(&offsetBaseHSV[0], &offsetBaseHSV[1], - &offsetBaseHSV[2]); - offsetColor.GetHSV(&offsetColorHSV[0], &offsetColorHSV[1], - &offsetColorHSV[2]); - - // Determine the offset for each component in HSV space - for (int c = 0; c < 3; ++c) { - // For sanity - float baseC = GfClamp(offsetBaseHSV[c], 0, 1); - float offC = GfClamp(offsetColorHSV[c], 0, 1); - - float delta = offC - baseC; - - if (delta > 0) - // baseC must be < 1 for delta > 0 - offsetHSV[c] = delta / (1 - baseC); - - else if (delta < 0) - // baseC must be > 0 for delta < 0 - offsetHSV[c] = delta / baseC; - - else // delta == 0 - offsetHSV[c] = 0; - } - - return offsetHSV; -} - -std::ostream & -operator<<(std::ostream& out, const GfRGB& c) -{ - return out << '(' << c[0] << ", " << c[1] << ", " << c[2] << ')'; -} diff --git a/pxr/base/lib/gf/rgb.h b/pxr/base/lib/gf/rgb.h deleted file mode 100644 index 17d40c76cd..0000000000 --- a/pxr/base/lib/gf/rgb.h +++ /dev/null @@ -1,266 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the Apache License, Version 2.0 (the "Apache License") -// with the following modification; you may not use this file except in -// compliance with the Apache License and the following modification to it: -// Section 6. Trademarks. is deleted and replaced with: -// -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor -// and its affiliates, except as required to comply with Section 4(c) of -// the License and to reproduce the content of the NOTICE file. -// -// You may obtain a copy of the Apache License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the Apache License with the above modification is -// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the Apache License for the specific -// language governing permissions and limitations under the Apache License. -// -#ifndef GF_RGB_H -#define GF_RGB_H - -/// \file gf/rgb.h -/// \ingroup group_gf_Color - -#include "pxr/base/gf/math.h" -#include "pxr/base/gf/vec3f.h" - -#include - -class GfMatrix4d; - -/// \class GfRGB -/// -/// A color represented as 3 floats for red, green, and blue. -/// -/// The \c GfRGB class contains three floats that represent an RGB -/// color, in the order red, green, blue. -/// Conversions to and from some other color spaces are provided. -/// -class GfRGB { - - public: - /// The default constructor creates an invalid color. - GfRGB() { Set(NAN, NAN, NAN); } - - /// This constructor initializes the color to grey. - explicit GfRGB(int bw) { _rgb[0] = _rgb[1] = _rgb[2] = bw; } - - explicit GfRGB(GfVec3f const &v) : _rgb(v) {} - - /// This constructor initializes the color to grey. - explicit GfRGB(float grey) : _rgb(grey, grey, grey) {} - - /// Constructor that takes an array of 3 floats. - explicit GfRGB(const float rgb[3]) : _rgb(rgb) {} - - /// Constructor that takes individual red, green, and blue values. - GfRGB(float red, float green, float blue) : _rgb(red, green, blue) {} - - /// Sets the color from an array of 3 floats. - GfRGB &Set(const float rgb[3]) { - _rgb.Set(rgb); - return *this; - } - - /// Sets the color to individual red, green, and blue values. - GfRGB &Set(float red, float green, float blue) { - _rgb.Set(red, green, blue); - return *this; - } - - /// Returns whether or not the color is valid. By convention, a color is - /// valid if the first color component is not NAN. - bool IsValid() const { return !isnan(_rgb[0]); } - - /// Returns the RGB color as a \c GfVec3f. - const GfVec3f &GetVec() const { return _rgb; } - - /// Returns the RGB color as an array of 3 floats. - const float *GetArray() const { return _rgb.GetArray(); } - - /// Accesses indexed component of color as a modifiable l-value. - float &operator [](int i) { return _rgb[i]; } - - /// Accesses indexed component of color as a \c const l-value. - const float &operator [](int i) const { return _rgb[i]; } - - /// Clamps each component of the color to be in the given range. - void Clamp(float min = 0.0, float max = 1.0) { - _rgb[0] = GfClamp(_rgb[0], min, max); - _rgb[1] = GfClamp(_rgb[1], min, max); - _rgb[2] = GfClamp(_rgb[2], min, max); - } - - /// All components must match exactly for colors to be considered equal. - bool operator ==(const GfRGB &c) const { - return _rgb == c._rgb; - } - - /// Any component may differ - bool operator !=(const GfRGB &c) const { - return !(*this == c); - } - - /// Check to see if all components are set to 0. - bool IsBlack() const { - return _rgb == GfVec3f(0); - } - - /// Check to see if all components are set to 1. - bool IsWhite() const { - return _rgb == GfVec3f(1,1,1); - } - - /// Component-wise color addition. - GfRGB &operator +=(const GfRGB &c) { - _rgb += c._rgb; - return *this; - } - - /// Component-wise color subtraction. - GfRGB &operator -=(const GfRGB &c) { - _rgb -= c._rgb; - return *this; - } - - /// Component-wise color multiplication. - GfRGB &operator *=(const GfRGB &c) { - _rgb = GfCompMult(_rgb, c._rgb); - return *this; - } - - /// Component-wise color division. - GfRGB &operator /=(const GfRGB &c) { - _rgb = GfCompDiv(_rgb, c._rgb); - return *this; - } - - /// Component-wise scalar multiplication. - GfRGB &operator *=(float d) { - _rgb *= d; - return *this; - } - - /// Component-wise scalar division. - GfRGB &operator /=(float d) { - _rgb /= d; - return *this; - } - - /// Returns component-wise multiplication of colors \p c1 and \p c2. - /// \warning this is \em not a dot product operator, as it is with vectors. - friend GfRGB operator *(const GfRGB &c1, const GfRGB &c2) { - return GfRGB(GfCompMult(c1._rgb, c2._rgb)); - } - - /// quotient operator - friend GfRGB operator /(const GfRGB &c1, const GfRGB &c2) { - return GfRGB(GfCompDiv(c1._rgb, c2._rgb)); - } - - /// addition operator. - friend GfRGB operator +(const GfRGB &c1, const GfRGB &c2) { - return GfRGB(c1._rgb + c2._rgb); - } - - /// subtraction operator. - friend GfRGB operator -(const GfRGB &c1, const GfRGB &c2) { - return GfRGB(c1._rgb - c2._rgb); - } - - /// multiplication operator. - friend GfRGB operator *(const GfRGB &c, float s) { - return GfRGB(c._rgb * s); - } - - /// Component-wise binary color/scalar multiplication operator. - friend GfRGB operator *(float s, const GfRGB &c) { - return c * s; - } - - /// Component-wise binary color/scalar division operator. - friend GfRGB operator /(const GfRGB &c, float s) { - return c * (1./s); - } - - /// Tests for equality within a given tolerance, returning true if the - /// difference between each component is less than \p tolerance. - friend bool GfIsClose(const GfRGB &v1, const GfRGB &v2, double tolerance); - - /// Returns \code (1-alpha) * a + alpha * b \endcode similar to GfLerp for - /// other vector types. - friend GfRGB GfLerp(float alpha, const GfRGB &a, const GfRGB &b) { - return (1.0-alpha) * a + alpha * b; - } - - /// \name Color-space conversions. - /// - /// The methods in this group convert between RGB and other color spaces. - /// - ///@{ - - /// Transform the color into an arbitrary space. - GfRGB Transform(const GfMatrix4d &m) const; - - /// Transform the color into an arbitrary space. - friend GfRGB operator *(const GfRGB &c, const GfMatrix4d &m); - - /// Return the complement of a color. - /// \note This assumes normalized RGB channels in [0,1] and doesn't work - /// with HDR color values. - GfRGB GetComplement() const { - return GfRGB(1) - *this; - } - - /// Return the luminance of a color given a set of RGB weighting values. - /// Defaults are Rec.709 weights for linear RGB components. - float GetLuminance(float wr = 0.2126390, - float wg = 0.7151687, - float wb = 0.07219232) const { - return _rgb[0]*wr + _rgb[1]*wg + _rgb[2]*wb; - } - - /// Return the luminance of a color given a set of RGB weighting values - /// passed as a GfRGB color object. - float GetLuminance(const GfRGB &coeffs) const { - return _rgb[0]*coeffs._rgb[0] + - _rgb[1]*coeffs._rgb[1] + - _rgb[2]*coeffs._rgb[2]; - } - - /// Returns the equivalent of this color in HSV space - void GetHSV(float *hue, float *sat, float *value) const; - - /// Sets this RGB to the RGB equivalent of the given HSV color. - void SetHSV(float hue, float sat, float value); - - /// Given an RGB base and HSV offset, get an RGB color. - static GfRGB GetColorFromOffset(const GfRGB &offsetBase, - const GfRGB &offsetHSV); - - /// Given an HSV offset color and an RGB base, get the HSV offset - static GfRGB GetOffsetFromColor(const GfRGB &offsetBase, - const GfRGB &offsetColor); - - ///@} - - private: - /// Color storage. - GfVec3f _rgb; -}; - -// Friend functions must be declared. -bool GfIsClose(const GfRGB &v1, const GfRGB &v2, double tolerance); -GfRGB operator *(const GfRGB &c, const GfMatrix4d &m); - -/// Output a GfRGB color using the format (r, g, b). -/// \ingroup group_gf_DebuggingOutput -std::ostream& operator<<(std::ostream& out, const GfRGB& c); - -#endif // GF_RGB_H diff --git a/pxr/base/lib/gf/rgba.cpp b/pxr/base/lib/gf/rgba.cpp deleted file mode 100644 index cf98e15802..0000000000 --- a/pxr/base/lib/gf/rgba.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the Apache License, Version 2.0 (the "Apache License") -// with the following modification; you may not use this file except in -// compliance with the Apache License and the following modification to it: -// Section 6. Trademarks. is deleted and replaced with: -// -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor -// and its affiliates, except as required to comply with Section 4(c) of -// the License and to reproduce the content of the NOTICE file. -// -// You may obtain a copy of the Apache License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the Apache License with the above modification is -// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the Apache License for the specific -// language governing permissions and limitations under the Apache License. -// -#include "pxr/base/gf/rgba.h" - -#include "pxr/base/gf/math.h" -#include "pxr/base/gf/matrix4d.h" -#include "pxr/base/gf/rgb.h" -#include "pxr/base/tf/type.h" - -#include - -TF_REGISTRY_FUNCTION(TfType) -{ - TfType::Define(); -} - -GfRGBA GfRGBA::Transform(const GfMatrix4d &m) const -{ - return GfRGBA(_rgba * m); -} - -GfRGBA operator *(const GfRGBA &c, const GfMatrix4d &m) -{ - return c.Transform(m); -} - -bool -GfIsClose(const GfRGBA &v1, const GfRGBA &v2, double tolerance) -{ - return GfIsClose(v1._rgba, v2._rgba, tolerance); -} - -void -GfRGBA::GetHSV(float *h, float *s, float *v) const -{ - return GfRGB(GetArray()).GetHSV(h, s, v); -} - -void -GfRGBA::SetHSV(float h, float s, float v) -{ - GfRGB tmp; - tmp.SetHSV(h, s, v); - Set(tmp[0], tmp[1], tmp[2], _rgba[3]); -} - - -std::ostream & -operator<<(std::ostream& out, const GfRGBA& c) -{ - return out << '(' << c[0] << ", " << c[1] << ", " - << c[2] << ", " << c[3] << ')'; -} diff --git a/pxr/base/lib/gf/rgba.h b/pxr/base/lib/gf/rgba.h deleted file mode 100644 index 35eb6f23f3..0000000000 --- a/pxr/base/lib/gf/rgba.h +++ /dev/null @@ -1,270 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the Apache License, Version 2.0 (the "Apache License") -// with the following modification; you may not use this file except in -// compliance with the Apache License and the following modification to it: -// Section 6. Trademarks. is deleted and replaced with: -// -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor -// and its affiliates, except as required to comply with Section 4(c) of -// the License and to reproduce the content of the NOTICE file. -// -// You may obtain a copy of the Apache License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the Apache License with the above modification is -// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the Apache License for the specific -// language governing permissions and limitations under the Apache License. -// -#ifndef GF_RGBA_H -#define GF_RGBA_H - -/// \file gf/rgba.h -/// \ingroup group_gf_Color - -#include "pxr/base/gf/math.h" -#include "pxr/base/gf/rgb.h" -#include "pxr/base/gf/vec4f.h" - -#include - -class GfMatrix4d; - -/// \class GfRGBA -/// -/// A color represented as 4 floats for red, green, blue, and alpha. -/// -/// The \c GfRGBA class contains four floats that represent an RGBA -/// color, in the order red, green, blue, alpha (opacity). Several -/// color operations are provided. -/// -class GfRGBA { - - public: - /// The default constructor creates an invalid color. - GfRGBA() { - Set(NAN, NAN, NAN, NAN); - } - - /// Constructor that takes a \c GfVec4f. - explicit GfRGBA(const GfVec4f &v) : _rgba(v) {} - - /// This constructor initializes the each component to \a grey. - explicit GfRGBA(float grey) : _rgba(grey, grey, grey, grey) {} - - /// Constructor that takes an array of 4 floats. - explicit GfRGBA(const float rgba[4]) : _rgba(rgba) {} - - /// Constructor that takes individual red, green, and blue values. - GfRGBA(float red, float green, float blue) : - _rgba(red, green, blue, 1.0) - { - } - - /// Constructor that takes individual red, green, blue, and alpha values. - GfRGBA(float red, float green, float blue, float alpha) : - _rgba(red, green, blue, alpha) - { - } - - /// Constructor and implicit conversion from GfRGB that takes an optional - /// alpha value. - GfRGBA(const GfRGB &rgb, float alpha=1.0) : - _rgba(rgb[0], rgb[1], rgb[2], alpha) - { - } - - /// Sets the color from an array of 4 floats. - GfRGBA &Set(const float rgba[4]) { - _rgba.Set(rgba); - return *this; - } - - /// Sets the color to individual red, green, blue, and alpha values. - GfRGBA &Set(float red, float green, float blue, float alpha) { - _rgba.Set(red, green, blue, alpha); - return *this; - } - - /// Sets the color from a \c GfRGB and an alpha (opacity) value. - GfRGBA &Set(const GfRGB &rgb, float alpha) { - _rgba.Set(rgb[0], rgb[1], rgb[2], alpha); - return *this; - } - - /// Returns the RGBA color as a \c GfVec4f. - const GfVec4f &GetVec() const { return _rgba; } - - /// Returns the RGBA color as an array of 4 floats. - const float *GetArray() const { return _rgba.GetArray(); } - - /// Returns whether or not the color is valid. By convention, a color is - /// valid if the first color component is not NAN. - bool IsValid() const { return !isnan(_rgba[0]); } - - /// Accesses indexed component of color as a modifiable l-value. - float &operator [](int i) { return _rgba[i]; } - - /// Accesses indexed component of color as a \c const l-value. - const float &operator [](int i) const { return _rgba[i]; } - - /// Clamps each component of the color to be in the given range. - void Clamp(float min = 0.0, float max = 1.0) { - _rgba[0] = GfClamp(_rgba[0], min, max); - _rgba[1] = GfClamp(_rgba[1], min, max); - _rgba[2] = GfClamp(_rgba[2], min, max); - _rgba[3] = GfClamp(_rgba[3], min, max); - } - - /// Component-wise color equality test. All components must match exactly - /// for colors to be considered equal. - bool operator ==(const GfRGBA &c) const { - return _rgba == c._rgba; - } - - /// Component-wise color inequality test. All components must match - /// exactly for colors to be considered equal. - bool operator !=(const GfRGBA &c) const { - return ! (*this == c); - } - - /// Check to see if all color components are set to 0, ignoring alpha. - bool IsBlack() const { - return GfVec3f(_rgba[0], _rgba[1], _rgba[2]) == GfVec3f(0); - } - - /// Check to see if all color components are set to 1, ignoring alpha. - bool IsWhite() const { - return GfVec3f(_rgba[0], _rgba[1], _rgba[2]) == GfVec3f(1,1,1); - } - - /// Return true if \a alpha is 0. - bool IsTransparent() const { - return _rgba[3] == 0; - } - - /// Return true if \a alpha is 1. - bool IsOpaque() const { - return _rgba[3] == 1; - } - - /// Component-wise unary color addition. - GfRGBA &operator +=(const GfRGBA &c) { - _rgba += c._rgba; - return *this; - } - - /// Component-wise unary color subtraction. - GfRGBA &operator -=(const GfRGBA &c) { - _rgba -= c._rgba; - return *this; - } - - /// Component-wise color multiplication. - GfRGBA &operator *=(const GfRGBA &c) { - _rgba = GfCompMult(_rgba, c._rgba); - return *this; - } - - /// Component-wise color division. - GfRGBA &operator /=(const GfRGBA &c) { - _rgba = GfCompDiv(_rgba, c._rgba); - return *this; - } - - /// Component-wise scalar multiplication. - GfRGBA &operator *=(double d) { - _rgba *= d; - return *this; - } - - /// Component-wise unary scalar division. - GfRGBA &operator /=(double d) { - _rgba /= d; - return *this; - } - - /// Returns component-wise multiplication of colors \p c1 and \p c2. Note - /// that this is \em not a dot product operator, as it is with vectors. - friend GfRGBA operator *(const GfRGBA &c1, const GfRGBA &c2) { - return GfRGBA(GfCompMult(c1._rgba, c2._rgba)); - } - - /// quotient operator. - friend GfRGBA operator /(const GfRGBA &c1, const GfRGBA &c2) { - return GfRGBA(GfCompDiv(c1._rgba, c2._rgba)); - } - - /// Component-wise binary color addition operator. - friend GfRGBA operator +(const GfRGBA &c1, const GfRGBA &c2) { - return GfRGBA(c1._rgba + c2._rgba); - } - - /// Component-wise binary color subtraction operator. - friend GfRGBA operator -(const GfRGBA &c1, const GfRGBA &c2) { - return GfRGBA(c1._rgba - c2._rgba); - } - - /// Component-wise binary color/scalar multiplication operator. - friend GfRGBA operator *(const GfRGBA &c, double s) { - return GfRGBA(c._rgba * s); - } - - /// Component-wise binary color/scalar multiplication operator. - friend GfRGBA operator *(double s, const GfRGBA &c) { - return c * s; - } - - /// Component-wise binary color/scalar division operator. - friend GfRGBA operator /(const GfRGBA &c, double s) { - return c * (1./s); - } - - /// Tests for equality within a given tolerance, returning true if the - /// difference between each component is less than \p tolerance. - friend bool GfIsClose(const GfRGBA &v1, const GfRGBA &v2, double tolerance); - - /// \name Color-space conversions. - /// - /// The methods in this group convert between RGBA and other color spaces. - /// - ///@{ - - /// Transform the color into an arbitrary space. - GfRGBA Transform(const GfMatrix4d &m) const; - - /// Transform the color into an arbitrary space. - friend GfRGBA operator *(const GfRGBA &c, const GfMatrix4d &m); - - /// Return the complement of a color. - GfRGBA GetComplement() const { - return GfRGBA(1) - *this; - } - - /// Returns the equivalent of this color in HSV space - void GetHSV(float *hue, float *sat, float *value) const; - - /// Sets this RGB to the RGB equivalent of the given HSV color. - void SetHSV(float hue, float sat, float value); - - ///@} - - private: - /// Color storage. - GfVec4f _rgba; -}; - -// Friend functions must be declared. -bool GfIsClose(const GfRGBA &v1, const GfRGBA &v2, double tolerance); -GfRGBA operator *(const GfRGBA &c, const GfMatrix4d &m); - -/// Output a GfRGBA color using the format (r, g, b, a). -/// \ingroup group_gf_DebuggingOutput -std::ostream& operator<<(std::ostream& out, const GfRGBA& c); - -#endif // TF_RGBA_H diff --git a/pxr/base/lib/gf/testenv/testGfColorRamp.py b/pxr/base/lib/gf/testenv/testGfColorRamp.py deleted file mode 100644 index 1635a274b2..0000000000 --- a/pxr/base/lib/gf/testenv/testGfColorRamp.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/pxrpythonsubst -# -# Copyright 2016 Pixar -# -# Licensed under the Apache License, Version 2.0 (the "Apache License") -# with the following modification; you may not use this file except in -# compliance with the Apache License and the following modification to it: -# Section 6. Trademarks. is deleted and replaced with: -# -# 6. Trademarks. This License does not grant permission to use the trade -# names, trademarks, service marks, or product names of the Licensor -# and its affiliates, except as required to comply with Section 4(c) of -# the License and to reproduce the content of the NOTICE file. -# -# You may obtain a copy of the Apache License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the Apache License with the above modification is -# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the Apache License for the specific -# language governing permissions and limitations under the Apache License. -# - -import sys -import unittest -import math -from pxr import Gf - -class TestGfColorRamp(unittest.TestCase): - - def test_Constructors(self): - results = [] - results.append( Gf.ColorRamp() ) - results.append( Gf.ColorRamp( Gf.RGB() ) ) - results.append( Gf.ColorRamp( Gf.RGB(), Gf.RGB() ) ) - results.append( Gf.ColorRamp( Gf.RGB(), Gf.RGB(), Gf.RGB() ) ) - results.append( Gf.ColorRamp( Gf.RGB(), Gf.RGB(), Gf.RGB(), 1 ) ) - results.append( Gf.ColorRamp( Gf.RGB(), Gf.RGB(), Gf.RGB(), 1, 2 ) ) - results.append( Gf.ColorRamp( Gf.RGB(), Gf.RGB(), Gf.RGB(), 1, 2, 3 ) ) - results.append( Gf.ColorRamp( Gf.RGB(), Gf.RGB(), Gf.RGB(), 1, 2, 3, 4 ) ) - results.append( Gf.ColorRamp( Gf.RGB(), Gf.RGB(), Gf.RGB(), 1, 2, 3, 4, 5 ) ) - for r in results: - self.assertIsInstance(r, Gf.ColorRamp) - - def test_Operators(self): - # generate some unique values - r1 = Gf.ColorRamp( Gf.RGB( 1, 2, 3 ) ) - r2 = Gf.ColorRamp( Gf.RGB( 1, 2, 4 ) ) - r3 = Gf.ColorRamp( Gf.RGB( 3, 2, 1 ) ) - results = [r1, r2, r3] - - # test operators - for i in range(len(results)): - # Test repr - self.assertTrue(eval(repr(results[i])) == results[i]) - # Test equality - for j in range(len(results)): - if i == j: - self.assertTrue(results[i] == results[j]) - else: - self.assertTrue(results[i] != results[j]) - - def test_Eval(self): - '''Eval -- make sure ends and middle are exact, make sure betweens are - between them.''' - r = Gf.ColorRamp() - self.assertTrue(r.Eval(0) == Gf.RGB(0, 0, 1) and - r.Eval(0.5) == Gf.RGB(0, 1, 0) and - r.Eval(1) == Gf.RGB(1, 0, 0)) - - self.assertFalse(r.Eval(0.25).r != 0 or \ - r.Eval(0.75).b != 0 or \ - r.Eval(0.25).g <= 0 or \ - r.Eval(0.25).g >= 1 or \ - r.Eval(0.25).b <= 0 or \ - r.Eval(0.25).b >= 1 or \ - r.Eval(0.75).r <= 0 or \ - r.Eval(0.75).r >= 1 or \ - r.Eval(0.75).g <= 0 or \ - r.Eval(0.75).g >= 1) - - - def test_Properties(self): - r = Gf.ColorRamp() - - testVal = 0.314159 - for propName in 'midPos widthMin widthMax widthMidIn widthMidOut'.split(): - self.assertNotEqual(getattr(r, propName), testVal) - setattr(r, propName, testVal) - self.assertEqual(getattr(r, propName), testVal) - -if __name__ == '__main__': - unittest.main() diff --git a/pxr/base/lib/gf/testenv/testGfRGB.py b/pxr/base/lib/gf/testenv/testGfRGB.py deleted file mode 100644 index c039f75b0e..0000000000 --- a/pxr/base/lib/gf/testenv/testGfRGB.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/pxrpythonsubst -# -# Copyright 2016 Pixar -# -# Licensed under the Apache License, Version 2.0 (the "Apache License") -# with the following modification; you may not use this file except in -# compliance with the Apache License and the following modification to it: -# Section 6. Trademarks. is deleted and replaced with: -# -# 6. Trademarks. This License does not grant permission to use the trade -# names, trademarks, service marks, or product names of the Licensor -# and its affiliates, except as required to comply with Section 4(c) of -# the License and to reproduce the content of the NOTICE file. -# -# You may obtain a copy of the Apache License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the Apache License with the above modification is -# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the Apache License for the specific -# language governing permissions and limitations under the Apache License. -# - -from pxr import Gf -import unittest - -import ctypes - -def ToFloat(x): - return ctypes.c_float(x).value - -class TestGfRGB(unittest.TestCase): - - def Test(self, cls): - def make(*vals): - return cls((vals*size)[:size]) - - size = len(cls()) - - # default ctor zero initializes - self.assertEqual(cls(), cls()) - self.assertEqual([0]*size, [x for x in cls()]) - - # unary ctor sets all components - self.assertEqual([ToFloat(1.234)]*size, [x for x in cls(1.234)]) - - # explicit ctor - ctorArgs = range(123, 123 + size) - self.assertEqual([x for x in cls(*ctorArgs)], range(123, 123 + size)) - - # construct from vec - if size == 3: - self.assertEqual(cls(Gf.Vec3f(1,2,3)), cls(1,2,3)) - elif size == 4: - self.assertEqual(cls(Gf.Vec4f(1,2,3,4)), cls(1,2,3,4)) - - # Clamp - self.assertEqual(make(-.5,.5,.75,1.25).Clamp(), make(0,.5,.75,1)) - self.assertEqual(make(1,2,3,4).Clamp(), make(1,1,1,1)) - self.assertEqual(make(1,2,3,4).Clamp(min=2), make(2,1,1,1)) - self.assertEqual(make(1,2,3,4).Clamp(max=2), make(1,2,2,2)) - self.assertEqual(make(1,2,3,4).Clamp(min=2,max=3), make(2,2,3,3)) - - # Clamp should modify in-place - x = make(1,2,3,4) - x.Clamp(2, 3) - self.assertEqual(x, make(2,2,3,3)) - - # IsBlack and IsWhite - self.assertTrue(make(0).IsBlack()) - self.assertTrue(make(1).IsWhite()) - self.assertFalse(make(1).IsBlack()) - self.assertFalse(make(0).IsWhite()) - self.assertFalse(make(0.5).IsBlack()) - self.assertFalse(make(0.5).IsWhite()) - - # Transform - # XXX add test - - # GetComplement - self.assertEqual(make(0).GetComplement(), make(1)) - self.assertEqual(make(0, 0.25, 0.75, 1).GetComplement(), make(1, 0.75, 0.25, 0)) - self.assertEqual(make(-1, 0, 1, 2).GetComplement(), make(2, 1, 0, -1)) - - # GetVec - # XXX add test - - # GetHSV - # XXX add test - - # SetHSV - # XXX add test - - # r,g,b,a - # XXX add test - - # repr - self.assertEqual(eval(repr(make(1,2,3,4))), make(1,2,3,4)) - self.assertEqual(eval(repr(make(0))), make(0)) - self.assertEqual(eval(repr(make(1))), make(1)) - - # str - self.assertTrue(len(str(make(0)))) - self.assertTrue(len(str(make(1)))) - self.assertTrue(len(str(make(1,2,3,4)))) - - # operators - # XXX add test - - # tuples implicitly convert to rgb(a) - self.assertEqual(cls((1,)*size), make(1)) - self.assertEqual(cls((0,)*size), make(0)) - - def test_RGB(self): - self.Test(Gf.RGB) - - def test_RGBA(self): - self.Test(Gf.RGBA) - -if __name__ == '__main__': - unittest.main() diff --git a/pxr/base/lib/gf/wrapColorRamp.cpp b/pxr/base/lib/gf/wrapColorRamp.cpp deleted file mode 100644 index 5908b455eb..0000000000 --- a/pxr/base/lib/gf/wrapColorRamp.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the Apache License, Version 2.0 (the "Apache License") -// with the following modification; you may not use this file except in -// compliance with the Apache License and the following modification to it: -// Section 6. Trademarks. is deleted and replaced with: -// -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor -// and its affiliates, except as required to comply with Section 4(c) of -// the License and to reproduce the content of the NOTICE file. -// -// You may obtain a copy of the Apache License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the Apache License with the above modification is -// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the Apache License for the specific -// language governing permissions and limitations under the Apache License. -// -#include "pxr/base/gf/colorRamp.h" -#include "pxr/base/tf/pyUtils.h" -#include "pxr/base/tf/wrapTypeHelpers.h" - -#include - -using namespace boost::python; - -static std::string -_Repr(const GfColorRamp &r) -{ - return TfStringPrintf( - "%sColorRamp(%s, %s, %s, %g, %g, %g, %g, %g, %s, %s)", - TF_PY_REPR_PREFIX.c_str(), - TfPyRepr(r.GetCMin()).c_str(), - TfPyRepr(r.GetCMid()).c_str(), - TfPyRepr(r.GetCMax()).c_str(), - r.GetMidPos(), - r.GetWidthMin(), - r.GetWidthMidIn(), - r.GetWidthMidOut(), - r.GetWidthMax(), - TfPyRepr(r.GetUseColorRamp()).c_str(), - TfPyRepr(r.GetSwitchable()).c_str()); -} - -void wrapColorRamp() -{ - typedef GfColorRamp This; - - class_ ( "ColorRamp", "Color ramp, as commonly used in Pixar shaders", - init< optional< - const GfRGB &, - const GfRGB &, - const GfRGB &, - float, float, float, float, float, - bool, bool - > >()) - - .def(TfTypePythonClass()) - .def(init >()) - - .def("Eval", &This::Eval, "Evaluate the ramp at x in [0, 1]") - - // These GfRGB-valued fields are not wrapped as properties, - // since it is a mutable type and so usage like this - // - // ramp.cMin.red = 5 - // - // does not do what callers might expect -- it just modifies a - // temporary. - // - //.add_property("cMin", - // make_function(&This::GetCMin, - // return_value_policy()), - // &This::SetCMin) - //.add_property("cMid", - // make_function(&This::GetCMid, - // return_value_policy()), - // &This::SetCMid) - //.add_property("cMax", - // make_function(&This::GetCMax, - // return_value_policy()), - // &This::SetCMax) - - .def("GetCMin", &This::GetCMin, - return_value_policy()) - .def("GetCMid", &This::GetCMid, - return_value_policy()) - .def("GetCMax", &This::GetCMax, - return_value_policy()) - .def("SetCMin", &This::SetCMin) - .def("SetCMid", &This::SetCMid) - .def("SetCMax", &This::SetCMax) - - .add_property("midPos", - &This::GetMidPos, - &This::SetMidPos) - .add_property("widthMin", - &This::GetWidthMin, - &This::SetWidthMin) - .add_property("widthMax", - &This::GetWidthMax, - &This::SetWidthMax) - .add_property("widthMidIn", - &This::GetWidthMidIn, - &This::SetWidthMidIn) - .add_property("widthMidOut", - &This::GetWidthMidOut, - &This::SetWidthMidOut) - .add_property("switchable", - &This::GetSwitchable, - &This::SetSwitchable) - .add_property("useColorRamp", - &This::GetUseColorRamp, - &This::SetUseColorRamp) - - .def( self == self ) - .def( self != self ) - .def( "__repr__", _Repr ) - ; - -} diff --git a/pxr/base/lib/gf/wrapRGB.cpp b/pxr/base/lib/gf/wrapRGB.cpp deleted file mode 100644 index cf905576b1..0000000000 --- a/pxr/base/lib/gf/wrapRGB.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the Apache License, Version 2.0 (the "Apache License") -// with the following modification; you may not use this file except in -// compliance with the Apache License and the following modification to it: -// Section 6. Trademarks. is deleted and replaced with: -// -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor -// and its affiliates, except as required to comply with Section 4(c) of -// the License and to reproduce the content of the NOTICE file. -// -// You may obtain a copy of the Apache License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the Apache License with the above modification is -// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the Apache License for the specific -// language governing permissions and limitations under the Apache License. -// -#include - -#include "pxr/base/gf/rgb.h" -#include "pxr/base/gf/matrix4d.h" - -#include "pxr/base/tf/pyUtils.h" -#include "pxr/base/tf/wrapTypeHelpers.h" - -using namespace boost::python; - -static GfRGB *__init__() { - // Default ctor in python zero-initializes - return new GfRGB(0.0f); -} - -static tuple _GetHSV(const GfRGB &self) { - float hue, saturation, value; - self.GetHSV(&hue, &saturation, &value); - return make_tuple(hue, saturation, value); -} - -static std::string __repr__(GfRGB const &self) -{ - return TF_PY_REPR_PREFIX + "RGB(" + - TfPyRepr(self[0]) + ", " + - TfPyRepr(self[1]) + ", " + - TfPyRepr(self[2]) + ")"; -} - -static int -_NormalizeIndex(int index) { - return TfPyNormalizeIndex(index, 3, true /*throw error*/); -} - -static int __len__(GfRGB const &self) { - return 3; -} - -static float __getitem__(const GfRGB &self, int index) { - index = _NormalizeIndex(index); - return self[index]; -} - -static void __setitem__(GfRGB &self, int index, float value) { - index = _NormalizeIndex(index); - self[index] = value; -} - -static bool __contains__(const GfRGB &self, float value) { - for (int i = 0; i < 3; ++i) - if (self[i] == value) - return true; - return false; -} - -template -static float _GetComponent(GfRGB const &self) { - return self[Component]; -} - -template -static void _SetComponent(GfRGB &self, float value) { - self[Component] = value; -} - - -struct GfRGBFromPythonTuple { - GfRGBFromPythonTuple() { - converter::registry:: - push_back(&_convertible, &_construct, - boost::python::type_id()); - } - - private: - - static void *_convertible(PyObject *obj_ptr) { - if (not PyTuple_Check(obj_ptr)) - return 0; - size_t size = PyTuple_GET_SIZE(obj_ptr); - if (size != 3) - return 0; - for (size_t i = 0; i < size; ++i) - if (not extract(PyTuple_GET_ITEM(obj_ptr, i)).check()) - return 0; - return obj_ptr; - } - - static void _construct(PyObject *obj_ptr, converter:: - rvalue_from_python_stage1_data *data) { - void *storage = ((converter::rvalue_from_python_storage*)data) - ->storage.bytes; - new (storage) - GfRGB(extract(PyTuple_GET_ITEM(obj_ptr, 0)), - extract(PyTuple_GET_ITEM(obj_ptr, 1)), - extract(PyTuple_GET_ITEM(obj_ptr, 2))); - data->convertible = storage; - } -}; - -// This adds support for python's builtin pickling library -// This is used by our Shake plugins which need to pickle entire classes -// (including code), which we don't support in pxml. -struct RGB_Pickle_Suite : boost::python::pickle_suite -{ - static boost::python::tuple getinitargs(const GfRGB &c) - { - return boost::python::make_tuple(c[0], c[1], c[2]); - } -}; - -// We should not need this declaration. -//bool GfIsClose(const GfRGB &v1, const GfRGB &v2, double tolerance); - - -void wrapRGB() -{ - typedef GfRGB This; - - def("IsClose", (bool (*)(const GfRGB &, - const GfRGB &, double)) GfIsClose); - - class_("RGB", no_init) - - .def(TfTypePythonClass()) - .def_pickle(RGB_Pickle_Suite()) - - .def("__init__", make_constructor(__init__)) - .def(init()) - .def(init()) - .def(init()) - - .def("Clamp", &This::Clamp, - (arg("min")=0.0f, arg("max")=1.0f), return_self<>()) - .def("IsBlack", &This::IsBlack) - .def("IsWhite", &This::IsWhite) - .def("Transform", &This::Transform) - .def("GetComplement", &This::GetComplement) - .def("GetVec", &This::GetVec, return_value_policy()) - .def("GetHSV", _GetHSV) - .def("SetHSV", &This::SetHSV) - - .add_property("r", _GetComponent<0>, _SetComponent<0>) - .add_property("g", _GetComponent<1>, _SetComponent<1>) - .add_property("b", _GetComponent<2>, _SetComponent<2>) - - .def("__repr__", __repr__) - - .def("__len__", __len__) - .def("__contains__", __contains__) - .def("__getitem__", __getitem__) - .def("__setitem__", __setitem__) - - .def(self_ns::str(self)) - - .def(self == self) - .def(self != self) - - .def(double() * self) - .def(self * double()) - .def(self * self) - .def(self *= double()) - .def(self *= self) - .def(self + self) - .def(self += self) - .def(self - self) - .def(self -= self) - .def(self / double()) - .def(self / self) - .def(self /= double()) - .def(self /= self) - - .def(self * GfMatrix4d()) - - ; - - // Allow appropriate tuples to be passed where GfRGBAs are expected. - GfRGBFromPythonTuple(); -} diff --git a/pxr/base/lib/gf/wrapRGBA.cpp b/pxr/base/lib/gf/wrapRGBA.cpp deleted file mode 100644 index 80bca56f99..0000000000 --- a/pxr/base/lib/gf/wrapRGBA.cpp +++ /dev/null @@ -1,214 +0,0 @@ -// -// Copyright 2016 Pixar -// -// Licensed under the Apache License, Version 2.0 (the "Apache License") -// with the following modification; you may not use this file except in -// compliance with the Apache License and the following modification to it: -// Section 6. Trademarks. is deleted and replaced with: -// -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor -// and its affiliates, except as required to comply with Section 4(c) of -// the License and to reproduce the content of the NOTICE file. -// -// You may obtain a copy of the Apache License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the Apache License with the above modification is -// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the Apache License for the specific -// language governing permissions and limitations under the Apache License. -// -#include - -#include "pxr/base/gf/rgba.h" -#include "pxr/base/gf/matrix4d.h" - -#include "pxr/base/tf/pyUtils.h" -#include "pxr/base/tf/wrapTypeHelpers.h" - -using namespace boost::python; - -static GfRGBA *__init__() { - // Default ctor in python zero-initializes - return new GfRGBA(0.0f); -} - -static tuple _GetHSV(const GfRGBA &self) { - float hue, saturation, value; - self.GetHSV(&hue, &saturation, &value); - return make_tuple(hue, saturation, value); -} - -static std::string __repr__(GfRGBA const &self) -{ - return TF_PY_REPR_PREFIX + "RGBA(" + - TfPyRepr(self[0]) + ", " + - TfPyRepr(self[1]) + ", " + - TfPyRepr(self[2]) + ", " + - TfPyRepr(self[3]) + ")"; -} - -static int -_NormalizeIndex(int index) { - return TfPyNormalizeIndex(index, 4, true /*throw error*/); -} - -static int __len__(GfRGBA const &self) { - return 4; -} - -static float __getitem__(const GfRGBA &self, int index) { - index = _NormalizeIndex(index); - return self[index]; -} - -static void __setitem__(GfRGBA &self, int index, float value) { - index = _NormalizeIndex(index); - self[index] = value; -} - -static bool __contains__(const GfRGBA &self, float value) { - for (int i = 0; i < 4; ++i) - if (self[i] == value) - return true; - return false; -} - - -template -static float _GetComponent(GfRGBA const &self) { - return self[Component]; -} - -template -static void _SetComponent(GfRGBA &self, float value) { - self[Component] = value; -} - - -struct GfRGBAFromPythonTuple { - GfRGBAFromPythonTuple() { - converter::registry:: - push_back(&_convertible, &_construct, - boost::python::type_id()); - } - - private: - - static void* _convertible(PyObject *obj_ptr) { - if (not PyTuple_Check(obj_ptr)) - return 0; - size_t size = PyTuple_GET_SIZE(obj_ptr); - if (size != 3 and size != 4) - return 0; - for (size_t i = 0; i < size; ++i) - if (not extract(PyTuple_GET_ITEM(obj_ptr, i)).check()) - return 0; - return obj_ptr; - } - - static void _construct(PyObject *obj_ptr, converter:: - rvalue_from_python_stage1_data *data) { - void* storage = ((converter::rvalue_from_python_storage*)data) - ->storage.bytes; - size_t size = PyTuple_GET_SIZE(obj_ptr); - - double r = extract(PyTuple_GET_ITEM(obj_ptr, 0)); - double g = extract(PyTuple_GET_ITEM(obj_ptr, 1)); - double b = extract(PyTuple_GET_ITEM(obj_ptr, 2)); - double a = (size == 4) ? - extract(PyTuple_GET_ITEM(obj_ptr, 4)) : - 1.0; - - new (storage) - GfRGBA(r, g, b, a); - - data->convertible = storage; - } -}; - -// This adds support for python's builtin pickling library -// This is used by our Shake plugins which need to pickle entire classes -// (including code), which we don't support in pxml. -struct RGBA_Pickle_Suite : boost::python::pickle_suite -{ - static boost::python::tuple getinitargs(const GfRGBA &c) - { - return boost::python::make_tuple(c[0], c[1], c[2], c[3]); - } -}; - -bool GfIsClose(const GfRGBA &v1, const GfRGBA &v2, double tolerance); - - -void wrapRGBA() -{ - typedef GfRGBA This; - - def("IsClose", (bool (*)(const GfRGBA &, - const GfRGBA &, double)) GfIsClose); - - class_("RGBA", no_init) - - .def(TfTypePythonClass()) - .def_pickle(RGBA_Pickle_Suite()) - - .def("__init__", make_constructor(__init__)) - .def(init()) - .def(init >()) - .def(init()) - .def(init >()) - - .def("Clamp", &This::Clamp, - (arg("min")=0.0f, arg("max")=1.0f), return_self<>()) - .def("IsBlack", &This::IsBlack) - .def("IsWhite", &This::IsWhite) - .def("IsTransparent", &This::IsTransparent) - .def("IsOpaque", &This::IsOpaque) - .def("Transform", &This::Transform) - .def("GetComplement", &This::GetComplement) - .def("GetVec", &This::GetVec, return_value_policy()) - .def("GetHSV", _GetHSV) - .def("SetHSV", &This::SetHSV) - - .add_property("r", _GetComponent<0>, _SetComponent<0>) - .add_property("g", _GetComponent<1>, _SetComponent<1>) - .add_property("b", _GetComponent<2>, _SetComponent<2>) - .add_property("a", _GetComponent<3>, _SetComponent<3>) - - .def("__repr__", __repr__) - - .def("__len__", __len__) - .def("__contains__", __contains__) - .def("__getitem__", __getitem__) - .def("__setitem__", __setitem__) - - .def(self_ns::str(self)) - - .def(self == self) - .def(self != self) - - .def(double() * self) - .def(self * double()) - .def(self * self) - .def(self *= double()) - .def(self *= self) - .def(self + self) - .def(self += self) - .def(self - self) - .def(self -= self) - .def(self / double()) - .def(self / self) - .def(self /= double()) - .def(self /= self) - - .def(self * GfMatrix4d()) - - ; - - // Allow appropriate tuples to be passed where GfRGBAs are expected. - GfRGBAFromPythonTuple(); -}