Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds python interface to RollingMean, Color and Spline #218

Merged
merged 17 commits into from
Sep 8, 2021
Merged
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
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>
francocipollone marked this conversation as resolved.
Show resolved Hide resolved
#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