-matrix multipla test
-matrix devide test
-debug print test
make_rotation make_scaling ***
test for above
sample for matrix
+++ /dev/null
-#pragma once
-#include <cstddef>
-#include <mof/base/tstring.hpp>
-
-
-namespace mof
-{
-
-}// namespace mof
+++ /dev/null
-#pragma once
-
-#include <string>
-#ifndef _MSC_VER
-/* Microsoft VisualC++\82Å\92è\8b`\82³\82ê\82Ä\82¢\82éTCHAR\8c^\82ð\92è\8b` */
-typedef char TCHAR;
-#else
-#include <tchar.h>
-#endif
-
-namespace mof
-{
- typedef std::basic_string<TCHAR> tstring;
-}// namespace mof
+++ /dev/null
-#pragma once
-#include <mof/base/mofdef.hpp>
-#include <boost/operators.hpp>
-#include <ostream>
-
-namespace mof
-{
-namespace math
-{
-
- template <size_t Dim> struct row_of_matrix;
-
- /**
- * @brief 同次座標変換行列テンプレートクラス
- * @note このテンプレートから直接特殊化することは想定していない.
- * あくまでmatrixxを実装するための補助テンプレートである.
- * このクラスは不変クラスである.
- * @tparam Dim 行列の次元(要素数はこの数値の2乗)
- * @tparam Derived 特殊化されたテンプレートの派生クラス(matrixx)の型
- * @tparam Coordinate 対応するベクトルクラス(vectorx)の型
- */
- template <size_t Dim, typename Derived, typename Coordinate>
- class basic_matrix
- : boost::addable< Derived
- , boost::addable2< Derived, float
- , boost::subtractable< Derived
- , boost::subtractable2< Derived, float
- , boost::multipliable< Derived
- , boost::multipliable2< Derived, float
- , boost::equality_comparable< Derived
- > > > > > > >
- {
- protected:
-//{{{ last_index
- /**
- * @brief elements_の最後の添字を得る
- */
- size_t last_index() const
- {
- return (Dim + 1) * (Dim + 1);
- }
-//}}}
- float elements_[(Dim + 1) * (Dim + 1)];///< 要素の配列
- public:
-//{{{ array
-/*
- struct array
- {
- float arr_[(Dim + 1) * (Dim + 1) - 1];
-
- float& operator[](size_t index)
- {
- return arr_[index];
- }
-
- };
-*/
-//}}}
- // コンストラクタ,デストラクタはデフォルトのものを使う
- // 代入演算子,コピーコンストラクタはデフォルトのものを使う
-//{{{ operator +=
- Derived& operator+=(const Derived& rhs)
- {
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- elements_[i] += rhs.elements_[i];
- }
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- Derived& operator+=(float rhs)
- {
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- elements_[i] += rhs;
- }
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- friend Derived operator+(float rhs1, Derived& rhs2)
- {
- Derived retval;
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- retval.elements_[i] = rhs1 + rhs2.elements_[i];
- }
- return retval;
- }
-//}}}
-//{{{ operator -=
- Derived& operator-=(const Derived& rhs)
- {
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- elements_[i] -= rhs.elements_[i];
- }
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- Derived& operator-=(float rhs)
- {
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- elements_[i] -= rhs;
- }
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- friend Derived operator-(float rhs1, Derived& rhs2)
- {
- Derived retval;
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- retval.elements_[i] = rhs1 - rhs2.elements_[i];
- }
- return retval;
- }
-//}}}
-//{{{ operator *=
- Derived& operator*=(const Derived& rhs)
- {
- Derived retval;
- for (size_t a = 0; a < last_index(); ++a) {
- int b = a / Dim * Dim;
- int c = a % Dim;
- float sum = 0;
- for (size_t i = 0; i < Dim; ++i) {
- sum += elements_[b + i] * rhs.elements_[c + i * Dim];
- }
- retval.elements_[a] = sum;
- }
- *this = retval;
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- Derived& operator*=(float rhs)
- {
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- elements_[i] *= rhs;
- }
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- Coordinate& operator*(const Coordinate& rhs)
- {
- Coordinate retval;
- for (size_t a = 0; a < Dim; ++a) {
- int b = a / Dim * Dim;
- int c = a % Dim;
- float sum = 0;
- for (size_t i = 0; i < Dim; ++i) {
- sum += elements_[b + i] * rhs[c + i];
- }
- retval.components_[a] = sum;
- }
- return retval;
- }
-
- friend Derived operator*(float rhs1, Derived& rhs2)
- {
- Derived retval;
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- retval.elements_[i] = rhs1 * rhs2.elements_[i];
- }
- return retval;
- }
-//}}}
-//{{{ operator /=
- Derived& operator/=(float rhs)
- {
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- elements_[i] /= rhs;
- }
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-//}}}
-//{{{ operator ==
- bool operator==(const Derived& rhs) const
- {
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- if (elements_[i] != rhs.elements_[i]) return false;
- }
- return true;
- }
-//}}}
-//{{{ operator []
- /**
- * @note 補助クラスによってM[i][j]のように参照可能
- * @note この方法による複数の要素への参照は非効率
- */
- row_of_matrix<Dim> operator [](size_t i) const
- {
- return row_of_matrix<Dim>(elements_, i);
- }
-//}}}
-//{{{ operator <<
- /**
- * @brief デバッグ出力用ストリーム演算子
- * @param [in] stream 出力ストリーム
- * @param [in] rhs 出力対象となる行列オブジェクト
- * @return 引数で与えられた出力ストリーム
- */
- friend std::ostream& operator<<
- (
- std::ostream& stream,
- const Derived& rhs
- )
- {
- for (size_t i = 0; i < Dim + 1; ++i) {
- for (size_t j = 0; j < Dim + 1; ++j) {
- if (j != 0) stream << ", ";
- else if (j != Dim) stream << "\n";
- stream << rhs.elements_[i * (Dim + 1) + j];
- }
- }
- return stream;
- }
-//}}}
- };
-//{{{ row_of_matrix
- /**
- * @brief M[i][j]のように行列の要素を参照できるようにするための補助クラス
- */
- template <size_t Dim>
- struct row_of_matrix
- {
- const float* elements_;
- size_t row_index_;
-
- row_of_matrix(const float* elements, size_t row_index)
- : elements_(elements), row_index_(row_index)
- {
- }
-
- float operator [](size_t index)
- {
- return elements_[row_index_ * (Dim + 1) + index];
- }
- };
-//}}}
-
-}// namespace math
-}// namespace mof
+++ /dev/null
-#pragma once
-#include <mof/base/mofdef.hpp>
-#include <boost/operators.hpp>
-#include <ostream>
-
-namespace mof
-{
-namespace math
-{
- /**
- * @brief 同次列ベクトルテンプレートクラス
- * @note このテンプレートから直接特殊化することは想定していない.
- * あくまでvectorxを実装するための補助テンプレートである.
- * このクラスは不変クラスである.
- * @tparam Dim ベクトルの次元(要素数)
- * @tparam Derived 特殊化されたテンプレートの派生クラス(vectorx)の型
- */
- template <size_t Dim, typename Derived>
- class basic_vector
- : boost::addable< Derived
- , boost::addable2< Derived, float
- , boost::subtractable< Derived
- , boost::subtractable2< Derived, float
- , boost::multipliable2< Derived, float
- , boost::dividable2< Derived, float
- , boost::equality_comparable< Derived
- > > > > > > >
- {
- protected:
- float components_[Dim];///< 要素の配列
- public:
-//{{{ array
- struct array
- {
- float arr_[Dim];
-
- float& operator[](size_t index)
- {
- return arr_[index];
- }
-
- };
-//}}}
- // コンストラクタ,デストラクタはデフォルトのものを使う
- // 代入演算子,コピーコンストラクタはデフォルトのものを使う
-//{{{ operator +=
- Derived& operator+=(const Derived& rhs)
- {
- for (size_t i = 0; i < Dim; ++i) components_[i] += rhs.components_[i];
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- Derived& operator+=(float rhs)
- {
- for (size_t i = 0; i < Dim; ++i) components_[i] += rhs;
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- friend Derived operator+(float rhs1, Derived& rhs2)
- {
- Derived retval;
- for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 + rhs2.components_[i];
- return retval;
- }
-//}}}
-//{{{ operator -=
- Derived& operator-=(const Derived& rhs)
- {
- for (size_t i = 0; i < Dim; ++i) components_[i] -= rhs.components_[i];
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- Derived& operator-=(float rhs)
- {
- for (size_t i = 0; i < Dim; ++i) components_[i] -= rhs;
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- friend Derived operator-(float rhs1, Derived& rhs2)
- {
- Derived retval;
- for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 - rhs2.components_[i];
- return retval;
- }
-//}}}
-//{{{ operator *=
- Derived& operator*=(float rhs)
- {
- for (size_t i = 0; i < Dim; ++i) components_[i] *= rhs;
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
- friend Derived operator*(float rhs1, Derived& rhs2)
- {
- Derived retval;
- for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 * rhs2.components_[i];
- return retval;
- }
-//}}}
-//{{{ operator /=
- Derived& operator/=(float rhs)
- {
- for (size_t i = 0; i < Dim; ++i) components_[i] /= rhs;
- return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
- }
-
-//}}}
-//{{{ operator ==
- bool operator==(const Derived& rhs) const
- {
- for (size_t i = 0; i < Dim; ++i) {
- if (components_[i] != rhs.components_[i]) return false;
- }
- return true;
- }
-//}}}
-//{{{ operator []
- /**
- * @note Dim+1番目の要素は常に1
- * @param[in] index 添字
- */
- float operator[](size_t index) const
- {
- if (index < Dim) return components_[index];
- else if (index == Dim) return 1;
- // TODO exception
- return 0;
- }
-//}}}
-//{{{ operator <<
- /**
- * @brief デバッグ出力用ストリーム演算子
- * @param[in] stream 出力ストリーム
- * @param[in] rhs 出力対象となるベクトルオブジェクト
- * @return 引数で与えられた出力ストリーム
- */
- friend std::ostream& operator<<
- (
- std::ostream& stream,
- const Derived& rhs
- )
- {
- for (size_t i = 0; i < Dim; ++i)
- {
- if (i != 0) stream << ", ";
- stream << rhs.components_[i];
- }
- return stream;
- }
-//}}}
- };
-
-
-}// namespace math
-}// namespace mof
+++ /dev/null
-/**
- * @file 各次元の行列をまとめてインクルードするためのヘッダ
- */
-#pragma once
-#include <mof/math/matrix2.hpp>
-#include <mof/math/matrix3.hpp>
+++ /dev/null
-#pragma once
-#include <mof/math/basic_matrix.hpp>
-
-namespace mof
-{
-namespace math
-{
- class vector2;
-
- /**
- * @brief 2次元同次座標変換行列クラス
- */
- class matrix2 : public basic_matrix<2, matrix2, vector2>
- {
- public:
-//{{{ constructor
- /**
- * @brief デフォルトコンストラクタ.最後の要素以外を0で初期化する.
- */
- matrix2()
- {
- for (size_t i = 0; i < last_index() - 1; ++i) {
- elements_[i] = 0;
- }
- elements_[last_index() - 1] = 1;
- }
-
- /**
- * @brief 指定した値で初期化する.
- * @param[in] arr 初期化用配列
- */
-/*
- matrix2(const matrix2::array& arr)
- {
- for (size_t i = 0; i < last_index() - 1; ++i) {
- elements_[i] = arr[i];
- }
- elements_[last_index() - 1] = 1;
- }
-*/
-
- /**
- * @brief 指定した値で初期化する.
- */
- matrix2
- (
- float m11, float m12, float m13,
- float m21, float m22, float m23,
- float m31, float m32
- )
- {
- const float* table[] =
- {
- &m11, &m12, &m13,
- &m21, &m22, &m23,
- &m31, &m32
- };
- for (size_t i = 0; i < last_index() - 1; ++i) {
- elements_[i] = *table[i];
- }
- elements_[last_index() - 1] = 1;
- }
-
-//}}}
-//{{{ copy constructor
- matrix2(const matrix2& rhs)
- {
- for (size_t i = 0; i < last_index(); ++i) {
- elements_[i] = rhs.elements_[i];
- }
- }
-//}}}
-//{{{ operator =
- matrix2& operator = (const matrix2& rhs)
- {
- for (size_t i = 0; i < last_index(); ++i) {
- elements_[i] = rhs.elements_[i];
- }
- return *this;
- }
-//}}}
- };
-
-}// namespace math
-}// namespace mof
+++ /dev/null
-#pragma once
-#include <mof/math/basic_matrix.hpp>
-
-namespace mof
-{
-namespace math
-{
- class vector3;
-
- /**
- * @brief 3次元同次座標変換行列クラス
- */
- class matrix3 : public basic_matrix<3, matrix3, vector3>
- {
- public:
-//{{{ constructor
- /**
- * @brief デフォルトコンストラクタ.最後の要素以外を0で初期化する.
- */
- matrix3()
- {
- for (size_t i = 0; i < last_index() - 1; ++i) {
- elements_[i] = 0;
- }
- elements_[last_index() - 1] = 1;
- }
-
- /**
- * @brief 指定した値で初期化する.
- * @param[in] arr 初期化用配列
- */
-/*
- matrix3(const matrix3::array& arr)
- {
- for (size_t i = 0; i < last_index() - 1; ++i) {
- elements_[i] = arr[i];
- }
- elements_[last_index() - 1] = 1;
- }
-*/
-
- /**
- * @brief 指定した値で初期化する.
- */
- matrix3
- (
- float m11, float m12, float m13, float m14,
- float m21, float m22, float m23, float m24,
- float m31, float m32, float m33, float m34,
- float m41, float m42, float m43
- )
- {
- const float* table[] =
- {
- &m11, &m12, &m13, &m14,
- &m21, &m22, &m23, &m24,
- &m31, &m32, &m33, &m34,
- &m41, &m42, &m43
- };
- for (size_t i = 0; i < last_index() - 1; ++i) {
- elements_[i] = *table[i];
- }
- elements_[last_index() - 1] = 1;
- }
-
-//}}}
-//{{{ copy constructor
- matrix3(const matrix3& rhs)
- {
- for (size_t i = 0; i < last_index(); ++i) {
- elements_[i] = rhs.elements_[i];
- }
- }
-//}}}
-//{{{ operator =
- /**
- * @note コピーのパフォーマンスのためにこの関数の定義は重要
- */
- matrix3& operator = (const matrix3& rhs)
- {
- for (size_t i = 0; i < last_index(); ++i) {
- elements_[i] = rhs.elements_[i];
- }
- return *this;
- }
-//}}}
- };
-
-}// namespace math
-}// namespace mof
+++ /dev/null
-/**
- * @file 各次元のベクトルをまとめてインクルードするためのヘッダ
- */
-#pragma once
-#include <mof/math/vector2.hpp>
-#include <mof/math/vector3.hpp>
+++ /dev/null
-#pragma once
-#include <mof/math/basic_vector.hpp>
-
-namespace mof
-{
-namespace math
-{
- /**
- * @brief 2次元同次列ベクトルクラス
- */
- class vector2 : public basic_vector<2, vector2>
- {
- public:
-//{{{ constructor
- /**
- * @brief デフォルトコンストラクタ.全ての要素を0で初期化する.
- */
- vector2()
- {
- components_[0] = 0;
- components_[1] = 0;
- }
-
- /**
- * @brief 指定した値で初期化する.
- * @param[in] x x座標成分
- * @param[in] y y座標成分
- */
- vector2(float x, float y)
- {
- components_[0] = x;
- components_[1] = y;
- }
-
- /**
- * @brief 指定した値で初期化する.
- * @param[in] arr 初期化用配列
- */
-/*
- vector2(const vector2::array& arr)
- {
- components_[0] = arr[0];
- components_[1] = arr[1];
- }
-*/
-//}}}
-//{{{ accessers
- float x() const { return components_[0]; }
- float y() const { return components_[1]; }
- float z() const { return 1; }// 第3要素は常に1
-//}}}
- };
-
-}// namespace math
-}// namespace mof
+++ /dev/null
-#pragma once
-#include <mof/math/basic_vector.hpp>
-#include <mof/math/vector2.hpp>
-
-namespace mof
-{
-namespace math
-{
- /**
- * @brief 3次元同次列ベクトルクラス
- */
- class vector3 : public basic_vector<3, vector3>
- {
- public:
-//{{{ constructor
- /**
- * @brief デフォルトコンストラクタ.全ての要素を0で初期化する.
- */
- vector3()
- {
- components_[0] = 0;
- components_[1] = 0;
- components_[2] = 0;
- }
-
- /**
- * @brief 指定した値で初期化する.
- * @param[in] x x座標成分
- * @param[in] y y座標成分
- * @param[in] z z座標成分
- */
- vector3(float x, float y, float z)
- {
- components_[0] = x;
- components_[1] = y;
- components_[2] = z;
- }
-
- /**
- * @brief 指定した値で初期化する.
- * @param[in] arr 初期化用配列
- */
-/*
- vector3(const vector3::array& arr)
- {
- components_[0] = arr[0];
- components_[1] = arr[1];
- components_[2] = arr[2];
- }
-*/
-
-//}}}
-//{{{ accesser
- float x() const { return components_[0]; }
- float y() const { return components_[1]; }
- float z() const { return components_[2]; }
- float w() const { return 1; }// 第4要素は常に1
-//}}}
- };
-
-}// namespace math
-}// namespace mof
+++ /dev/null
-#pragma once
-#include <boost/foreach.hpp>
-#define foreach BOOST_FOREACH
+++ /dev/null
-#pragma once
-#include <memory>
-#include <boost/utility.hpp>
-
-namespace mof
-{
-namespace util
-{
-
- /**
- * @brief システムのタイマによる高精度な時間計測
- * @note Linux版の実装ではclock_gettimeのCLOCK_REALTIMEが用いられている.
- */
- class multimedia_timer : boost::noncopyable
- {
- struct impl;
- std::unique_ptr<impl> pimpl_;
- public:
-//{{{ constructor
- /**
- * @brief デフォルトコンストラクタ.内部でreset()が呼ばれる.
- */
- multimedia_timer();
-//}}}
-//{{{ destructor
- ~multimedia_timer();
-//}}}
-//{{{ reset
- /**
- * @brief 時間の計測を初期化する.
- * @sa get_time_in_micro_sec
- */
- void reset();
-//}}}
-//{{{ get_time_in_micro_sec
- /**
- * @brief 最後にreset()を読んだ時点から現在までの経過時間をマイクロ秒単位で返す
- * @note 経過時間が長時間だった場合、返却値はオーバーフローしている可能性がある.
- * @retval 経過時間(マイクロ秒単位)
- */
- int get_time_in_micro_sec() const;
-//}}}
- };
-
-}// namespace util
-}// namespace mof
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../bin/)
# moflib
-include_directories("${PROJECT_SOURCE_DIR}/../include/")
+include_directories("${PROJECT_SOURCE_DIR}/../src")
link_directories("${PROJECT_SOURCE_DIR}/../lib")
# set compile flags
# The C and CXX include file search paths:
SET(CMAKE_C_INCLUDE_PATH
- "../../include"
+ "../../src"
"../BOOST_INCLUDE_DIR"
)
SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})
# The C and CXX include file search paths:
SET(CMAKE_C_INCLUDE_PATH
- "../../include"
+ "../../src"
"../BOOST_INCLUDE_DIR"
)
SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})
#IncludeRegexTransform:
-../../include/mof/base/mofdef.hpp
+../../src/mof/base/mofdef.hpp
cstddef
-
mof/base/tstring.hpp
-
-../../include/mof/base/tstring.hpp
+../../src/mof/base/tstring.hpp
string
-
tchar.h
-
-../../include/mof/math/basic_matrix.hpp
+../../src/mof/math/basic_matrix.hpp
mof/base/mofdef.hpp
-
+mof/math/threshold.hpp
+-
boost/operators.hpp
-
ostream
-
+iomanip
+-
+cmath
+-
-../../include/mof/math/basic_vector.hpp
+../../src/mof/math/basic_vector.hpp
mof/base/mofdef.hpp
-
+mof/math/threshold.hpp
+-
boost/operators.hpp
-
ostream
-
+cmath
+-
-../../include/mof/math/matrix.hpp
+../../src/mof/math/matrix.hpp
mof/math/matrix2.hpp
-
mof/math/matrix3.hpp
-
-../../include/mof/math/matrix2.hpp
+../../src/mof/math/matrix2.hpp
mof/math/basic_matrix.hpp
-
-../../include/mof/math/matrix3.hpp
+../../src/mof/math/matrix3.hpp
mof/math/basic_matrix.hpp
-
-../../include/mof/math/matrix_tmp.hpp
-mof/math/basic_matrix.hpp
--
+../../src/mof/math/threshold.hpp
-../../include/mof/math/vector.hpp
+../../src/mof/math/vector.hpp
mof/math/vector2.hpp
-
mof/math/vector3.hpp
-
-../../include/mof/math/vector2.hpp
+../../src/mof/math/vector2.hpp
mof/math/basic_vector.hpp
-
-../../include/mof/math/vector3.hpp
+../../src/mof/math/vector3.hpp
mof/math/basic_vector.hpp
-
mof/math/vector2.hpp
-
-../../include/mof/util/multimedia_timer.hpp
+../../src/mof/util/multimedia_timer.hpp
memory
-
boost/utility.hpp
-
mof/math/matrix.hpp
-
-mof/math/matrix_tmp.hpp
--
mof/util/multimedia_timer.hpp
-
iostream
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
numeric/CMakeFiles/numeric.dir/main.cpp.o
- ../../include/mof/base/mofdef.hpp
- ../../include/mof/base/tstring.hpp
- ../../include/mof/math/basic_matrix.hpp
- ../../include/mof/math/basic_vector.hpp
- ../../include/mof/math/matrix.hpp
- ../../include/mof/math/matrix2.hpp
- ../../include/mof/math/matrix3.hpp
- ../../include/mof/math/matrix_tmp.hpp
- ../../include/mof/math/vector.hpp
- ../../include/mof/math/vector2.hpp
- ../../include/mof/math/vector3.hpp
- ../../include/mof/util/multimedia_timer.hpp
+ ../../src/mof/base/mofdef.hpp
+ ../../src/mof/base/tstring.hpp
+ ../../src/mof/math/basic_matrix.hpp
+ ../../src/mof/math/basic_vector.hpp
+ ../../src/mof/math/matrix.hpp
+ ../../src/mof/math/matrix2.hpp
+ ../../src/mof/math/matrix3.hpp
+ ../../src/mof/math/threshold.hpp
+ ../../src/mof/math/vector.hpp
+ ../../src/mof/math/vector2.hpp
+ ../../src/mof/math/vector3.hpp
+ ../../src/mof/util/multimedia_timer.hpp
/home/yasutomo/devel/moflib/sample/numeric/main.cpp
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/base/mofdef.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/base/tstring.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/basic_matrix.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/basic_vector.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/matrix.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/matrix2.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/matrix3.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/matrix_tmp.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/vector.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/vector2.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/math/vector3.hpp
-numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../include/mof/util/multimedia_timer.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/base/mofdef.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/base/tstring.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/basic_matrix.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/basic_vector.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/matrix.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/matrix2.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/matrix3.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/threshold.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/vector.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/vector2.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/math/vector3.hpp
+numeric/CMakeFiles/numeric.dir/main.cpp.o: ../../src/mof/util/multimedia_timer.hpp
numeric/CMakeFiles/numeric.dir/main.cpp.o: ../numeric/main.cpp
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
# compile CXX with /usr/bin/c++
-CXX_FLAGS = -Wall -O3 -DNDEBUG -std=c++0x -I/home/yasutomo/devel/moflib/sample/../include -I/home/yasutomo/devel/moflib/sample/BOOST_INCLUDE_DIR
+CXX_FLAGS = -Wall -O3 -DNDEBUG -std=c++0x -I/home/yasutomo/devel/moflib/sample/../src -I/home/yasutomo/devel/moflib/sample/BOOST_INCLUDE_DIR
CXX_DEFINES =
#include <mof/math/vector.hpp>
#include <mof/math/matrix.hpp>
-#include <mof/math/matrix_tmp.hpp>
#include <mof/util/multimedia_timer.hpp>
#include <iostream>
#include <memory>
}
};
//}}}
-//{{{ raw_type16
- class raw_type16
+//{{{ raw_type
+ template <size_t Dim>
+ class raw_type
{
- float data[16];
- };
-//}}}
-//{{{ raw_type3
- class raw_type3
- {
- float data[3];
+ float data[Dim];
};
//}}}
mof::math::vector2 unused1;// block compile optimation
- mof::math::vector3 unused2;// block compile optimation
- mof::math::matrix2 unused3;// block compile optimation
- mof::math::matrix3 unused4;// block compile optimation
- raw_type3 unused6;
- raw_type16 unused7;
- shared_type unused5; // block compile optimation
+ raw_type<2> unused2;// block compile optimation
+ mof::math::vector3 unused3;// block compile optimation
+ raw_type<3> unused4;// block compile optimation
+ mof::math::matrix2 unused5;// block compile optimation
+ raw_type<9> unused6;// block compile optimation
+ mof::math::matrix3 unused7;// block compile optimation
+ raw_type<16> unused8;// block compile optimation
+ shared_type unused9;// block compile optimation
//{{{ copy_test
template <typename T>
int copy_test(T& unused) {
return timer.get_time_in_micro_sec();
}
//}}}
+//{{{ add_test
+ template <typename T>
+ int add_test(T& unused) {
+ using namespace mof::util;
+ T x;
+ multimedia_timer timer;
+ for (int i = 0; i < REPEAT_COUNT; i++) unused = x + unused;
+ return timer.get_time_in_micro_sec();
+ }
+//}}}
+//{{{ multiply_test
+ template <typename Matrix, typename Vector>
+ int multiply_test(Vector& unused) {
+ using namespace mof::util;
+ Matrix M;
+ Vector v;
+ multimedia_timer timer;
+ for (int i = 0; i < REPEAT_COUNT; i++) unused = M * unused;
+ return timer.get_time_in_micro_sec();
+ }
+//}}}
}
+void copy_tests();
+void add_tests();
+void multiply_tests();
+
+//{{{ main
int main()
{
+ std::cout << REPEAT_COUNT << " times repeating" << std::endl;
+ copy_tests();
+ add_tests();
+ multiply_tests();
+ return 0;
+}
+//}}}
+//{{{ copy_tests
+void copy_tests()
+{
using namespace std;
using namespace mof::math;
cout << "***copy performance test***" << endl;
- cout << REPEAT_COUNT << " times repeating" << endl;
cout << "vector2 --- " ;
cout << copy_test<vector2>(unused1) << "[micro sec]" << endl;
+ cout << "raw type2 --- " ;
+ cout << copy_test<raw_type<2>>(unused2) << "[micro sec]" << endl;
+
cout << "vector3 --- " ;
- cout << copy_test<vector3>(unused2) << "[micro sec]" << endl;
+ cout << copy_test<vector3>(unused3) << "[micro sec]" << endl;
+ cout << "raw type3 --- " ;
+ cout << copy_test<raw_type<3>>(unused4) << "[micro sec]" << endl;
+
cout << "matrix2 --- " ;
- cout << copy_test<matrix2>(unused3) << "[micro sec]" << endl;
+ cout << copy_test<matrix2>(unused5) << "[micro sec]" << endl;
+
+ cout << "raw type9 --- " ;
+ cout << copy_test<raw_type<9>>(unused6) << "[micro sec]" << endl;
cout << "matrix3 --- " ;
- cout << copy_test<matrix3>(unused4) << "[micro sec]" << endl;
+ cout << copy_test<matrix3>(unused7) << "[micro sec]" << endl;
- cout << "raw type3 --- " ;
- cout << copy_test<raw_type3>(unused6) << "[micro sec]" << endl;
-
cout << "raw type16 --- " ;
- cout << copy_test<raw_type16>(unused7) << "[micro sec]" << endl;
-
+ cout << copy_test<raw_type<16>>(unused8) << "[micro sec]" << endl;
+
cout << "shared type --- " ;
- cout << copy_test<shared_type>(unused5) << "[micro sec]" << endl;
+ cout << copy_test<shared_type>(unused9) << "[micro sec]" << endl;
+}
+//}}}
+//{{{ add_tests
+void add_tests()
+{
+ using namespace std;
+ using namespace mof::math;
+
+ cout << "***add performance test***" << endl;
+
+ cout << "vector2 + vector2 --- " ;
+ cout << add_test<vector2>(unused1) << "[micro sec]" << endl;
+ cout << "vector3 + vector3 --- " ;
+ cout << add_test<vector3>(unused3) << "[micro sec]" << endl;
+ cout << "matrix2 + matrix2 --- " ;
+ cout << add_test<matrix2>(unused5) << "[micro sec]" << endl;
- return 0;
+ cout << "matrix3 + matrix3 --- " ;
+ cout << add_test<matrix3>(unused7) << "[micro sec]" << endl;
+}
+//}}}
+//{{{ multiply_tests
+void multiply_tests()
+{
+ using namespace std;
+ using namespace mof::math;
+
+ cout << "***multiply performance test***" << endl;
+
+ cout << "matrix2 * vector2 --- " ;
+ cout << multiply_test<matrix2, vector2>(unused1) << "[micro sec]" << endl;
+ cout << "matrix3 * vector3 --- " ;
+ cout << multiply_test<matrix3, vector3>(unused3) << "[micro sec]" << endl;
}
+//}}}
-Start testing: Aug 17 13:29 PDT
+Start testing: Aug 18 13:21 PDT
----------------------------------------------------------
1/4 Testing: vector2_test
1/4 Test: vector2_test
Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/vector2_test"
Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"vector2_test" start time: Aug 17 13:29 PDT
+"vector2_test" start time: Aug 18 13:21 PDT
Output:
----------------------------------------------------------
<end of output>
-Test time = 0.00 sec
+Test time = 0.01 sec
----------------------------------------------------------
Test Passed.
-"vector2_test" end time: Aug 17 13:29 PDT
+"vector2_test" end time: Aug 18 13:21 PDT
"vector2_test" time elapsed: 00:00:00
----------------------------------------------------------
2/4 Test: vector3_test
Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/vector3_test"
Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"vector3_test" start time: Aug 17 13:29 PDT
+"vector3_test" start time: Aug 18 13:21 PDT
Output:
----------------------------------------------------------
<end of output>
-Test time = 0.00 sec
+Test time = 0.01 sec
----------------------------------------------------------
Test Passed.
-"vector3_test" end time: Aug 17 13:29 PDT
+"vector3_test" end time: Aug 18 13:21 PDT
"vector3_test" time elapsed: 00:00:00
----------------------------------------------------------
3/4 Test: matrix2_test
Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/matrix2_test"
Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"matrix2_test" start time: Aug 17 13:29 PDT
+"matrix2_test" start time: Aug 18 13:21 PDT
Output:
----------------------------------------------------------
-1
-
-1, 2, 3
-4, 5, 6
-7, 8, 1
<end of output>
-Test time = 0.00 sec
+Test time = 0.01 sec
----------------------------------------------------------
Test Passed.
-"matrix2_test" end time: Aug 17 13:29 PDT
+"matrix2_test" end time: Aug 18 13:21 PDT
"matrix2_test" time elapsed: 00:00:00
----------------------------------------------------------
4/4 Test: matrix3_test
Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/matrix3_test"
Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"matrix3_test" start time: Aug 17 13:29 PDT
+"matrix3_test" start time: Aug 18 13:21 PDT
Output:
----------------------------------------------------------
-
-1, 2, 3, 4
-5, 6, 7, 8
-9, 10, 11, 12
-13, 14, 15, 1
<end of output>
-Test time = 0.00 sec
+Test time = 0.01 sec
----------------------------------------------------------
Test Passed.
-"matrix3_test" end time: Aug 17 13:29 PDT
+"matrix3_test" end time: Aug 18 13:21 PDT
"matrix3_test" time elapsed: 00:00:00
----------------------------------------------------------
-End testing: Aug 17 13:29 PDT
+End testing: Aug 18 13:21 PDT
+3:matrix2_test
4:matrix3_test
../mof/math/basic_matrix.hpp
mof/base/mofdef.hpp
-
+mof/math/threshold.hpp
+-
+boost/operators.hpp
+-
+ostream
+-
+iomanip
+-
+cmath
+-
+
+../mof/math/basic_vector.hpp
+mof/base/mofdef.hpp
+-
+mof/math/threshold.hpp
+-
boost/operators.hpp
-
ostream
-
+cmath
+-
../mof/math/matrix2.hpp
mof/math/basic_matrix.hpp
-
+../mof/math/threshold.hpp
+
+../mof/math/vector2.hpp
+mof/math/basic_vector.hpp
+-
+
/home/yasutomo/devel/moflib/src/mof/math/test/matrix2_test.cpp
mof/math/matrix2.hpp
-
+mof/math/vector2.hpp
+-
iostream
-
sstream
../mof/base/mofdef.hpp
../mof/base/tstring.hpp
../mof/math/basic_matrix.hpp
+ ../mof/math/basic_vector.hpp
../mof/math/matrix2.hpp
+ ../mof/math/threshold.hpp
+ ../mof/math/vector2.hpp
/home/yasutomo/devel/moflib/src/mof/math/test/matrix2_test.cpp
mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/base/mofdef.hpp
mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/base/tstring.hpp
mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/basic_matrix.hpp
+mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/basic_vector.hpp
mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/matrix2.hpp
+mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/threshold.hpp
+mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/vector2.hpp
mof/math/CMakeFiles/matrix2_test.dir/test/matrix2_test.cpp.o: ../mof/math/test/matrix2_test.cpp
../mof/math/basic_matrix.hpp
mof/base/mofdef.hpp
-
+mof/math/threshold.hpp
+-
boost/operators.hpp
-
ostream
-
+iomanip
+-
+cmath
+-
+
+../mof/math/basic_vector.hpp
+mof/base/mofdef.hpp
+-
+mof/math/threshold.hpp
+-
+boost/operators.hpp
+-
+ostream
+-
+cmath
+-
../mof/math/matrix3.hpp
mof/math/basic_matrix.hpp
-
+../mof/math/threshold.hpp
+
+../mof/math/vector2.hpp
+mof/math/basic_vector.hpp
+-
+
+../mof/math/vector3.hpp
+mof/math/basic_vector.hpp
+-
+mof/math/vector2.hpp
+-
+
/home/yasutomo/devel/moflib/src/mof/math/test/matrix3_test.cpp
mof/math/matrix3.hpp
-
+mof/math/vector3.hpp
+-
iostream
-
sstream
../mof/base/mofdef.hpp
../mof/base/tstring.hpp
../mof/math/basic_matrix.hpp
+ ../mof/math/basic_vector.hpp
../mof/math/matrix3.hpp
+ ../mof/math/threshold.hpp
+ ../mof/math/vector2.hpp
+ ../mof/math/vector3.hpp
/home/yasutomo/devel/moflib/src/mof/math/test/matrix3_test.cpp
mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/base/mofdef.hpp
mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/base/tstring.hpp
mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/basic_matrix.hpp
+mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/basic_vector.hpp
mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/matrix3.hpp
+mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/threshold.hpp
+mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/vector2.hpp
+mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/vector3.hpp
mof/math/CMakeFiles/matrix3_test.dir/test/matrix3_test.cpp.o: ../mof/math/test/matrix3_test.cpp
../mof/math/basic_vector.hpp
mof/base/mofdef.hpp
-
+mof/math/threshold.hpp
+-
boost/operators.hpp
-
ostream
-
+cmath
+-
+
+../mof/math/threshold.hpp
../mof/math/vector2.hpp
mof/math/basic_vector.hpp
../mof/base/mofdef.hpp
../mof/base/tstring.hpp
../mof/math/basic_vector.hpp
+ ../mof/math/threshold.hpp
../mof/math/vector2.hpp
/home/yasutomo/devel/moflib/src/mof/math/test/vector2_test.cpp
mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/base/mofdef.hpp
mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/base/tstring.hpp
mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/math/basic_vector.hpp
+mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/math/threshold.hpp
mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/math/vector2.hpp
mof/math/CMakeFiles/vector2_test.dir/test/vector2_test.cpp.o: ../mof/math/test/vector2_test.cpp
../mof/math/basic_vector.hpp
mof/base/mofdef.hpp
-
+mof/math/threshold.hpp
+-
boost/operators.hpp
-
ostream
-
+cmath
+-
+
+../mof/math/threshold.hpp
../mof/math/vector2.hpp
mof/math/basic_vector.hpp
../mof/base/mofdef.hpp
../mof/base/tstring.hpp
../mof/math/basic_vector.hpp
+ ../mof/math/threshold.hpp
../mof/math/vector2.hpp
../mof/math/vector3.hpp
/home/yasutomo/devel/moflib/src/mof/math/test/vector3_test.cpp
mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/base/mofdef.hpp
mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/base/tstring.hpp
mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/basic_vector.hpp
+mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/threshold.hpp
mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/vector2.hpp
mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/vector3.hpp
mof/math/CMakeFiles/vector3_test.dir/test/vector3_test.cpp.o: ../mof/math/test/vector3_test.cpp
#pragma once
#include <mof/base/mofdef.hpp>
+#include <mof/math/threshold.hpp>
#include <boost/operators.hpp>
#include <ostream>
+#include <iomanip>
+#include <cmath>
namespace mof
{
, boost::subtractable2< Derived, float
, boost::multipliable< Derived
, boost::multipliable2< Derived, float
+ , boost::dividable2< Derived, float
, boost::equality_comparable< Derived
- > > > > > > >
+ > > > > > > > >
{
protected:
//{{{ last_index
*/
size_t last_index() const
{
- return (Dim + 1) * (Dim + 1);
+ return (Dim + 1) * (Dim + 1) - 1;
}
//}}}
float elements_[(Dim + 1) * (Dim + 1)];///< 要素の配列
Derived& operator+=(const Derived& rhs)
{
const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
+ for (size_t i = 0; i <= END; ++i) {
elements_[i] += rhs.elements_[i];
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
Derived& operator+=(float rhs)
{
const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
+ for (size_t i = 0; i <= END; ++i) {
elements_[i] += rhs;
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
{
Derived retval;
const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
+ for (size_t i = 0; i <= END; ++i) {
retval.elements_[i] = rhs1 + rhs2.elements_[i];
}
return retval;
Derived& operator-=(const Derived& rhs)
{
const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
+ for (size_t i = 0; i <= END; ++i) {
elements_[i] -= rhs.elements_[i];
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
Derived& operator-=(float rhs)
{
const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
+ for (size_t i = 0; i <= END; ++i) {
elements_[i] -= rhs;
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
{
Derived retval;
const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
+ for (size_t i = 0; i <= END; ++i) {
retval.elements_[i] = rhs1 - rhs2.elements_[i];
}
return retval;
}
//}}}
//{{{ operator *=
+ /**
+ * @brief 行列の積を計算し,最後の要素が1になるように定数倍する.
+ */
Derived& operator*=(const Derived& rhs)
{
Derived retval;
- for (size_t a = 0; a < last_index(); ++a) {
- int b = a / Dim * Dim;
- int c = a % Dim;
+ const int SIZE = Dim + 1;
+
+ // calculate the last element previously
+ int b = last_index() - Dim;
+ int c = Dim;
+ float last_sum = 0;
+ for (int i = 0; i < SIZE; ++i) {
+ last_sum += elements_[b + i] * rhs.elements_[c + i * SIZE];
+ }
+ retval.elements_[last_index()] = 1;
+
+ for (int a = last_index() - 1; a >= 0; --a) {
+ int b = a / SIZE * SIZE;
+ int c = a % SIZE;
float sum = 0;
- for (size_t i = 0; i < Dim; ++i) {
- sum += elements_[b + i] * rhs.elements_[c + i * Dim];
+ for (int i = 0; i < SIZE; ++i) {
+ sum += elements_[b + i] * rhs.elements_[c + i * SIZE];
}
- retval.elements_[a] = sum;
+ retval.elements_[a] = sum / last_sum;
}
*this = retval;
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
Derived& operator*=(float rhs)
{
const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
+ for (size_t i = 0; i <= END; ++i) {
elements_[i] *= rhs;
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
}
- Coordinate& operator*(const Coordinate& rhs)
+ /**
+ * @brief ベクトルを変換し,最後の要素が1になるように定数倍する.
+ */
+ Coordinate operator*(const Coordinate& rhs)
{
- Coordinate retval;
+ typename Coordinate::array arr;
+ const size_t SIZE = Dim + 1;
+
+ float last_sum = 0;
+ for (size_t i = 0; i < SIZE; ++i) {
+ last_sum += elements_[Dim * SIZE + i] * rhs[i];
+ }
+
for (size_t a = 0; a < Dim; ++a) {
- int b = a / Dim * Dim;
- int c = a % Dim;
float sum = 0;
- for (size_t i = 0; i < Dim; ++i) {
- sum += elements_[b + i] * rhs[c + i];
+ for (size_t i = 0; i < SIZE; ++i) {
+ sum += elements_[a * SIZE + i] * rhs[i];
}
- retval.components_[a] = sum;
+ arr[a] = sum / last_sum;
}
- return retval;
+ return Coordinate(arr);
}
+
friend Derived operator*(float rhs1, Derived& rhs2)
{
Derived retval;
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
+ const size_t END = rhs2.last_index() - 1;// 最後の要素は1で保存
+ for (size_t i = 0; i <= END; ++i) {
retval.elements_[i] = rhs1 * rhs2.elements_[i];
}
return retval;
Derived& operator/=(float rhs)
{
const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
+ for (size_t i = 0; i <= END; ++i) {
elements_[i] /= rhs;
}
return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
//{{{ operator ==
bool operator==(const Derived& rhs) const
{
- const size_t END = last_index() - 1;// 最後の要素は1で保存
- for (size_t i = 0; i < END; ++i) {
- if (elements_[i] != rhs.elements_[i]) return false;
+ const size_t END = last_index() - 1;// 最後の要素は1で保存されている
+ for (size_t i = 0; i <= END; ++i) {
+ if (std::abs(elements_[i] - rhs.elements_[i]) > MOF_ERROR_THRESHOLD) return false;
}
return true;
}
for (size_t j = 0; j < Dim + 1; ++j) {
if (j != 0) stream << ", ";
else if (j != Dim) stream << "\n";
- stream << rhs.elements_[i * (Dim + 1) + j];
+ stream << std::setw(5) << rhs.elements_[i * (Dim + 1) + j];
}
}
return stream;
#pragma once
#include <mof/base/mofdef.hpp>
+#include <mof/math/threshold.hpp>
#include <boost/operators.hpp>
#include <ostream>
+#include <cmath>
+
namespace mof
{
struct array
{
float arr_[Dim];
-
- float& operator[](size_t index)
- {
- return arr_[index];
- }
-
+ float& operator[](size_t index){return arr_[index];}
+ const float& operator[](size_t index) const {return arr_[index];}
};
//}}}
// コンストラクタ,デストラクタはデフォルトのものを使う
bool operator==(const Derived& rhs) const
{
for (size_t i = 0; i < Dim; ++i) {
- if (components_[i] != rhs.components_[i]) return false;
+ if (std::abs(components_[i] - rhs.components_[i]) > MOF_ERROR_THRESHOLD) return false;
}
return true;
}
*/
matrix2()
{
- for (size_t i = 0; i < last_index() - 1; ++i) {
+ for (size_t i = 0; i <= last_index() - 1; ++i) {
elements_[i] = 0;
}
- elements_[last_index() - 1] = 1;
+ elements_[last_index()] = 1;
}
/**
&m21, &m22, &m23,
&m31, &m32
};
- for (size_t i = 0; i < last_index() - 1; ++i) {
+ for (size_t i = 0; i <= last_index() - 1; ++i) {
elements_[i] = *table[i];
}
- elements_[last_index() - 1] = 1;
+ elements_[last_index()] = 1;
}
//}}}
//{{{ copy constructor
matrix2(const matrix2& rhs)
{
- for (size_t i = 0; i < last_index(); ++i) {
+ for (size_t i = 0; i <= last_index(); ++i) {
elements_[i] = rhs.elements_[i];
}
}
//{{{ operator =
matrix2& operator = (const matrix2& rhs)
{
- for (size_t i = 0; i < last_index(); ++i) {
+ for (size_t i = 0; i <= last_index(); ++i) {
elements_[i] = rhs.elements_[i];
}
return *this;
*/
matrix3()
{
- for (size_t i = 0; i < last_index() - 1; ++i) {
+ for (size_t i = 0; i <= last_index() - 1; ++i) {
elements_[i] = 0;
}
- elements_[last_index() - 1] = 1;
+ elements_[last_index()] = 1;
}
/**
&m31, &m32, &m33, &m34,
&m41, &m42, &m43
};
- for (size_t i = 0; i < last_index() - 1; ++i) {
+ for (size_t i = 0; i <= last_index() - 1; ++i) {
elements_[i] = *table[i];
}
- elements_[last_index() - 1] = 1;
+ elements_[last_index()] = 1;
}
//}}}
#include <mof/math/matrix2.hpp>
+#include <mof/math/vector2.hpp>
#include <iostream>
#include <sstream>
for (size_t i = 0; i < 8; ++i) {
if (M[i / 3][i % 3] != 0) failed = true;
}
- std::cout << M[2][2] << std::endl;
if (failed || M[2][2] != 1) {
cerr << "Failed:" << " default constructor makes zero matrix" << endl;
failed_count++;
{
matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
- std::cout << M << std::endl;
bool failed = false;
for (size_t i = 0; i < 8; ++i) {
if (M[i / 3][i % 3] != i + 1) failed = true;
matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
matrix2 N(1, 2, 3, 4, 5, 6, 7, 8);
if (M != N) {
- cerr << "Failed:" << " comparation test" << endl;
+ cerr << "Failed:" << " M == N test" << endl;
failed_count++;
}
}
matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
matrix2 N(0, 2, 3, 4, 5, 6, 7, 8);
if (M == N) {
- cerr << "Failed:" << " comparation test" << endl;
+ cerr << "Failed:" << " M != N test" << endl;
failed_count++;
}
}
}
}
- /*
- v = vector2(10, 10);
- v = 2 * v * 3;
- if (v.x() != 60 || v.y() != 60 || v.z() != 1) {
- cerr << "Failed:" << " multiplation with scalar test" << endl;
- failed_count++;
+ {
+ matrix2 N1(1, 2, 3, 4, 5, 6, 0, 0);
+ matrix2 N2(2, 3, 4, 5, 6, 7, 0, 0);
+ matrix2 N = N1 * N2;
+ matrix2 A(12, 15, 21, 33, 42, 57, 0, 0);
+ if (N != A) {
+ cerr << "Failed:" << "Affine matrix N1 * N2 test" << endl;
+ failed_count++;
+ }
+ }
+
+ {
+ matrix2 N1(1, 2, 3, 4, 5, 6, 7, 8);
+ matrix2 N2(2, 3, 4, 5, 6, 7, 8, 9);
+ matrix2 N = N1 * N2;
+ matrix2 A(0.42353f, 0.49412f, 0.24706f, 0.95294f, 1.12941f, 0.67059f, 0.72941f, 0.91765f);
+ if (N != A) {
+ cerr << "Failed:" << "Projective matrix N1 * N2 test" << endl;
+ failed_count++;
+ }
}
- */
- // TODO matrix devide
+ {
+ matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
+ vector2 v(1, 2);
+ vector2 w = M * v;
+ vector2 a(0.33333f, 0.83333f);
+ if (a != w) {
+ cerr << "Failed:" << "M * v test" << endl;
+ failed_count++;
+ }
+ }
+
+
+ {
+ matrix2 M(1, 2, 3, 4, 5, 6, 7, 8);
+ matrix2 N = 2 * M * 3;
+ matrix2 A(6, 12, 18, 24, 30, 36, 42, 48);
+ if (N != A) {
+ cerr << "Failed:" << "s * M * s test" << endl;
+ failed_count++;
+ }
+ }
+
+ {
+ matrix2 M(3, 6, 9, 12, 15, 18, 21, 24);
+ matrix2 N = M / 3;
+ matrix2 A(1, 2, 3, 4, 5, 6, 7, 8);
+ if (N != A) {
+ cerr << "Failed:" << "M / s test" << endl;
+ failed_count++;
+ }
+ }
+
return failed_count;
}
#include <mof/math/matrix3.hpp>
+#include <mof/math/vector3.hpp>
#include <iostream>
#include <sstream>
for (size_t i = 0; i < 15; ++i) {
if (M[i / 4][i % 4] != i + 1) failed = true;
}
- cout << M << endl;
if (failed || M[3][3] != 1) {
cerr << "Failed:" << " initialize test" << endl;
failed_count++;
matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
matrix3 N(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
if (M != N) {
- cerr << "Failed:" << " comparation test" << endl;
+ cerr << "Failed:" << " M == N test" << endl;
failed_count++;
}
}
matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
matrix3 N(0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
if (M == N) {
- cerr << "Failed:" << " comparation test" << endl;
+ cerr << "Failed:" << " M != N test" << endl;
failed_count++;
}
}
}
}
- /*
- v = vector2(10, 10);
- v = 2 * v * 3;
- if (v.x() != 60 || v.y() != 60 || v.z() != 1) {
- cerr << "Failed:" << " multiplation with scalar test" << endl;
- failed_count++;
+ {
+ matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 0, 0);
+ matrix3 N2(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0, 0);
+ matrix3 N = N1 * N2;
+ matrix3 A(44, 50, 56, 66, 116, 134, 152, 178, 188, 218, 248, 290, 0, 0, 0);
+ if (N != A) {
+ cerr << "Failed:" << "Affine matrix N1 * N2 test" << endl;
+ failed_count++;
+ }
}
- */
- // TODO matrix devide
+ {
+ matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+ matrix3 N2(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
+ matrix3 N = N1 * N2;
+ matrix3 A
+ (
+ 0.25840f, 0.28424f, 0.31008, 0.17054f,
+ 0.58915f, 0.65633f, 0.72351f, 0.45995f,
+ 0.91990f, 1.02842f, 1.13695f, 0.74935f,
+ 0.70801f, 0.81912f, 0.93023f
+ );
+ if (N != A) {
+ cerr << "Failed:" << "Projective matrix N1 * N2 test" << endl;
+ failed_count++;
+ }
+ }
+
+ {
+ matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+ vector3 v(1, 2, 3);
+ vector3 w = M * v;
+ vector3 a(0.20690f, 0.52874f, 0.85057f);
+ if (a != w) {
+ cerr << "Failed:" << "M * v test" << endl;
+ failed_count++;
+ }
+ }
+
+
+ {
+ matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+ matrix3 N = 2 * M * 3;
+ matrix3 A(6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90);
+ if (N != A) {
+ cerr << "Failed:" << "s * M * s test" << endl;
+ failed_count++;
+ }
+ }
+
+ {
+ matrix3 M(6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90);
+ matrix3 N = M / 6;
+ matrix3 A(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+ if (N != A) {
+ cerr << "Failed:" << "M / s test" << endl;
+ failed_count++;
+ }
+ }
return failed_count;
}
--- /dev/null
+#pragma once
+
+#define MOF_ERROR_THRESHOLD 1e-3// 誤差閾値
* @brief 指定した値で初期化する.
* @param[in] arr 初期化用配列
*/
-/*
vector2(const vector2::array& arr)
{
components_[0] = arr[0];
components_[1] = arr[1];
}
-*/
//}}}
//{{{ accessers
float x() const { return components_[0]; }
* @brief 指定した値で初期化する.
* @param[in] arr 初期化用配列
*/
-/*
vector3(const vector3::array& arr)
{
components_[0] = arr[0];
components_[1] = arr[1];
components_[2] = arr[2];
}
-*/
//}}}
//{{{ accesser