Skip to content

Commit

Permalink
Adds python interface to RollingMean, Color and Spline (#218)
Browse files Browse the repository at this point in the history
* Adds scripting interface to Color and a python test.
* Adds scripting interface to Spline and a python test.
* Adds python support for operator[] and operator<< to the Color class.
* Adds %rename tag to interface files in order to match pep-8 naiming style.

Signed-off-by: LolaSegura <[email protected]>

Co-authored-by: Steve Peters <[email protected]>
Co-authored-by: Franco Cipollone <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2021
1 parent b3804bf commit c3ab4dc
Show file tree
Hide file tree
Showing 8 changed files with 787 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ if (SWIG_FOUND)

include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PYTHON_INCLUDE_PATH})

set(swig_files
Angle
GaussMarkovProcess
PID
Rand
SemanticVersion
Vector2
Vector3
Vector4)
endif()

#################################
Expand Down Expand Up @@ -71,21 +61,24 @@ if (PYTHONLIBS_FOUND)
# Add the Python tests
set(python_tests
Angle_TEST
Color_TEST
GaussMarkovProcess_TEST
Kmeans_TEST
Line2_TEST
Line3_TEST
PID_TEST
python_TEST
Rand_TEST
RollingMean_TEST
SemanticVersion_TEST
SignalStats_TEST
Spline_TEST
Temperature_TEST
Triangle_TEST
Vector2_TEST
Vector3_TEST
Vector3Stats_TEST
Vector4_TEST
Temperature_TEST
Triangle_TEST
)

foreach (test ${python_tests})
Expand Down
109 changes: 109 additions & 0 deletions src/python/Color.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

%module Color
%{
#include <ignition/math/Color.hh>
#include <ignition/math/config.hh>
#include <ignition/math/Helpers.hh>
#include <ignition/math/Vector3.hh>
%}

%include "std_string.i"

namespace ignition
{
namespace math
{
class Color
{
%rename("%(undercase)s", %$isfunction, %$ismember, %$not %$isconstructor) "";
%rename("%(uppercase)s", %$isstatic, %$isvariable) "";
public: static const Color White;
public: static const Color Black;
public: static const Color Red;
public: static const Color Green;
public: static const Color Blue;
public: static const Color Yellow;
public: static const Color Magenta;
public: static const Color Cyan;
public: typedef unsigned int RGBA;
public: typedef unsigned int BGRA;
public: typedef unsigned int ARGB;
public: typedef unsigned int ABGR;

public: Color();
public: Color(const float _r, const float _g, const float _b,
const float _a = 1.0);
public: Color(const Color &_clr);
public: virtual ~Color();
public: void Reset();
public: void Set(const float _r = 1, const float _g = 1,
const float _b = 1, const float _a = 1);
public: Vector3<float> HSV() const;
public: void SetFromHSV(const float _h, const float _s, const float _v);
public: Vector3<float> YUV() const;
public: void SetFromYUV(const float _y, const float _u, const float _v);
public: RGBA AsRGBA() const;
public: BGRA AsBGRA() const;
public: ARGB AsARGB() const;
public: ABGR AsABGR() const;
public: void SetFromRGBA(const RGBA _v);
public: void SetFromBGRA(const BGRA _v);
public: void SetFromARGB(const ARGB _v);
public: void SetFromABGR(const ABGR _v);
public: Color operator+(const Color &_pt) const;
public: Color operator+(const float &_v) const;
public: const Color &operator+=(const Color &_pt);
public: Color operator-(const Color &_pt) const;
public: Color operator-(const float &_v) const;
public: const Color &operator-=(const Color &_pt);
public: const Color operator/(const Color &_pt) const;
public: const Color operator/(const float &_v) const;
public: const Color &operator/=(const Color &_pt);
public: const Color operator*(const Color &_pt) const;
public: const Color operator*(const float &_v) const;
public: const Color &operator*=(const Color &_pt);
public: bool operator==(const Color &_pt) const;
public: bool operator!=(const Color &_pt) const;
private: void Clamp();
public: float R() const;
public: float G() const;
public: float B() const;
public: float A() const;
public: void R(const float _r);
public: void G(const float _g);
public: void B(const float _b);
public: void A(const float _a);
};

%extend Color{
float __getitem__(const unsigned int i)
{
return (*$self)[i];
}
}

%extend Color {
std::string __str__() const {
std::ostringstream out;
out << *$self;
return out.str();
}
}
}
}
Loading

0 comments on commit c3ab4dc

Please sign in to comment.