Skip to content

Commit

Permalink
Merge branch 'release/0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
coord-e committed Jan 12, 2019
2 parents cc1dc65 + 4664886 commit 0b3e529
Show file tree
Hide file tree
Showing 36 changed files with 1,420 additions and 493 deletions.
1 change: 0 additions & 1 deletion bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@

cmake_minimum_required(VERSION 2.7)

flom_add_bin(convert_legacy)
flom_add_bin(json2flom)
flom_add_bin(flom2json)
142 changes: 111 additions & 31 deletions include/flom/effector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,132 @@ namespace flom {

namespace qvm = boost::qvm;

struct Location : boost::operators<Location> {
double weight;
qvm::vec<double, 3> vec;

Location() : weight(0) {}
class Location
: boost::addable<
Location,
boost::subtractable<
Location,
boost::equality_comparable<
Location, boost::multipliable<Location, std::size_t>>>> {
public:
using value_type = qvm::vec<double, 3>;

private:
value_type vector_;

public:
Location();
explicit Location(const value_type &);

const value_type &vector() const;
void set_vector(const value_type &);

Location &operator+=(const Location &);
Location &operator-=(const Location &);
Location &operator*=(std::size_t);
};

bool operator==(const Location &, const Location &);
bool almost_equal(const Location &, const Location &);

struct Rotation : boost::operators<Rotation> {
double weight;
qvm::quat<double> quat;

Rotation() : weight(0) {}
struct Rotation
: boost::addable<
Rotation,
boost::subtractable<
Rotation,
boost::equality_comparable<
Rotation, boost::multipliable<Rotation, std::size_t>>>> {
public:
using value_type = qvm::quat<double>;

private:
value_type quat_;

public:
Rotation();
explicit Rotation(const value_type &);

const value_type &quaternion() const;
void set_quaternion(const value_type &);

Rotation &operator+=(const Rotation &);
Rotation &operator-=(const Rotation &);
Rotation &operator*=(std::size_t);
};

bool operator==(const Rotation &, const Rotation &);
bool almost_equal(const Rotation &, const Rotation &);

struct Effector : boost::operators<Effector> {
std::optional<Location> location;
std::optional<Rotation> rotation;

Effector &operator+=(const Effector &x);
Effector &operator-=(const Effector &x);

template <typename T, std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>
Effector &operator*=(T x) {
if (this->location) {
this->location->vec *= x;
}
if (this->rotation) {
this->rotation->quat *= x;
}
return *this;
}
struct Effector;

class EffectorDifference
: boost::addable<
EffectorDifference,
boost::equality_comparable<
EffectorDifference,
boost::multipliable<EffectorDifference, std::size_t>>> {
private:
std::optional<Location> location_;
std::optional<Rotation> rotation_;

public:
EffectorDifference(const Effector &, const Effector &);

EffectorDifference() = delete;

EffectorDifference(const EffectorDifference &) = default;
EffectorDifference(EffectorDifference &&) = default;

EffectorDifference &operator=(const EffectorDifference &) = default;
EffectorDifference &operator=(EffectorDifference &&) = default;

const std::optional<Location> &location() const &;
std::optional<Location> location() &&;

const std::optional<Rotation> &rotation() const &;
std::optional<Rotation> rotation() &&;

EffectorDifference &operator*=(std::size_t);
EffectorDifference &operator+=(const EffectorDifference &);

bool is_compatible(const EffectorDifference &) const;
};

template <typename T, std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>
Effector operator*(const Effector &t1, T t2) {
return Effector(t1) *= t2;
}
bool operator==(const EffectorDifference &, const EffectorDifference &);
bool almost_equal(const EffectorDifference &, const EffectorDifference &);

struct Effector : boost::addable<Effector, EffectorDifference> {
private:
std::optional<Location> location_;
std::optional<Rotation> rotation_;

public:
Effector();
Effector(const std::optional<Location> &, const std::optional<Rotation> &);

const std::optional<Location> &location() const &;
std::optional<Location> location() &&;

void set_location(const std::optional<Location> &);
void clear_location();

const std::optional<Rotation> &rotation() const &;
std::optional<Rotation> rotation() &&;

void set_rotation(const std::optional<Rotation> &);
void clear_rotation();

Effector new_compatible_effector() const;
bool is_compatible(const Effector &) const;
bool is_compatible(const EffectorDifference &) const;

Effector &operator+=(const EffectorDifference &);
};

bool operator==(const Effector &, const Effector &);
bool operator!=(const Effector &, const Effector &);
bool almost_equal(const Effector &, const Effector &);
EffectorDifference operator-(const Effector &, const Effector &);

bool almost_equal(double, double);

Expand Down
55 changes: 55 additions & 0 deletions include/flom/effector_type.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Copyright 2018 coord.e
//
// This file is part of Flom.
//
// Flom is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Flom is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Flom. If not, see <http://www.gnu.org/licenses/>.
//

#ifndef FLOM_EFFECTOR_TYPE_HPP
#define FLOM_EFFECTOR_TYPE_HPP

#include "flom/effector.hpp"

#include <optional>

namespace flom {

enum class CoordinateSystem { World, Local };

struct EffectorType {
private:
std::optional<CoordinateSystem> location_;
std::optional<CoordinateSystem> rotation_;

public:
EffectorType() = delete;
EffectorType(std::optional<CoordinateSystem> location,
std::optional<CoordinateSystem> rotation);

std::optional<CoordinateSystem> location() const;
std::optional<CoordinateSystem> rotation() const;

void set_location(std::optional<CoordinateSystem>);
void clear_location();
void set_rotation(std::optional<CoordinateSystem>);
void clear_rotation();

Effector new_effector() const;
bool is_compatible(const Effector &) const;
};

} // namespace flom

#endif
46 changes: 46 additions & 0 deletions include/flom/effector_weight.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright 2018 coord.e
//
// This file is part of Flom.
//
// Flom is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Flom is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Flom. If not, see <http://www.gnu.org/licenses/>.
//

#ifndef FLOM_EFFECTOR_WEIGHT_HPP
#define FLOM_EFFECTOR_WEIGHT_HPP

namespace flom {

class EffectorWeight {
private:
double location_;
double rotation_;

static double validate_weight(double);

public:
EffectorWeight() = delete;

EffectorWeight(double location, double rotation);

double location() const noexcept;
double rotation() const noexcept;

void set_location(double);
void set_rotation(double);
};

} // namespace flom

#endif
11 changes: 11 additions & 0 deletions include/flom/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ class InitKeyframeError : public std::exception {
virtual const char *what() const noexcept;
};

class InvalidWeightError : public std::exception {
public:
explicit InvalidWeightError(double);
virtual const char *what() const noexcept;

double weight() const noexcept;

private:
double weight_;
};

} // namespace flom::errors

#endif
90 changes: 69 additions & 21 deletions include/flom/frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,82 @@ using KeyRange =
boost::any_range<K, boost::forward_traversal_tag,
std::add_lvalue_reference_t<K>, std::ptrdiff_t>;

struct Frame : boost::operators<Frame> {
std::unordered_map<std::string, double> positions;
std::unordered_map<std::string, Effector> effectors;
struct Frame;

class FrameDifference
: boost::addable<FrameDifference,
boost::equality_comparable<
FrameDifference,
boost::multipliable<FrameDifference, std::size_t>>> {

private:
std::unordered_map<std::string, double> positions_;
std::unordered_map<std::string, EffectorDifference> effectors_;

public:
FrameDifference(const Frame &, const Frame &);

FrameDifference() = delete;

FrameDifference(const FrameDifference &) = default;
FrameDifference(FrameDifference &&) = default;

FrameDifference &operator=(const FrameDifference &) = default;
FrameDifference &operator=(FrameDifference &&) = default;

const std::unordered_map<std::string, double> &positions() const &;
std::unordered_map<std::string, double> positions() &&;

const std::unordered_map<std::string, EffectorDifference> &
effectors() const &;
std::unordered_map<std::string, EffectorDifference> effectors() &&;

FrameDifference &operator*=(std::size_t);
FrameDifference &operator+=(const FrameDifference &);

bool is_compatible(const FrameDifference &) const;
};

bool operator==(const FrameDifference &, const FrameDifference &);
bool almost_equal(const FrameDifference &, const FrameDifference &);

struct Frame : boost::addable<Frame, FrameDifference> {
private:
using PositionsMap = std::unordered_map<std::string, double>;
using EffectorsMap = std::unordered_map<std::string, Effector>;

PositionsMap positions_;
EffectorsMap effectors_;

public:
Frame();
Frame(const PositionsMap &, const EffectorsMap &);

const PositionsMap &positions() const &;
PositionsMap positions() &&;

void set_positions(const PositionsMap &);
void set_position(const std::string &, double);

const EffectorsMap &effectors() const &;
EffectorsMap effectors() &&;

void set_effectors(const EffectorsMap &);
void set_effector(const std::string &, const Effector &);

KeyRange<std::string> joint_names() const;
KeyRange<std::string> effector_names() const;

Frame &operator+=(const Frame &x);
Frame &operator-=(const Frame &x);

template <typename T, std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>
Frame &operator*=(T x) {
for (auto &&[k, v] : this->positions) {
v *= x;
}
for (auto &&[k, v] : this->effectors) {
v *= x;
}
return *this;
}
};
Frame new_compatible_frame() const;
bool is_compatible(const Frame &) const;
bool is_compatible(const FrameDifference &) const;

template <typename T, std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>
Frame operator*(const Frame &t1, T t2) {
return Frame(t1) *= t2;
}
Frame &operator+=(const FrameDifference &);
};

FrameDifference operator-(const Frame &, const Frame &);
bool operator==(const Frame &, const Frame &);
bool operator!=(const Frame &, const Frame &);
bool almost_equal(const Frame &, const Frame &);

} // namespace flom
Expand Down
Loading

0 comments on commit 0b3e529

Please sign in to comment.