/*////////////////////////////////////////////////////////////////////////////// // CMT Cosmic Muon Tomography project ////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova All rights reserved Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it > ------------------------------------------------------------------ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. //////////////////////////////////////////////////////////////////////////////*/ /* * * Copyright (C) 2012 Andrea Rigoni Garola * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of the * License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA * */ #ifndef ULIB_DENSEMATRIX_H #define ULIB_DENSEMATRIX_H #include #include #include #include "Core/Types.h" #include "Core/Serializable.h" /////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // NEW PART // namespace uLib { //////////////////////////////////////////////////////////////////////////////// // DENSE MATRIX DEFINITION ///////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// using Eigen::Matrix; //////////////////////////////////////////////////////////////////////////////// // DENSE TYPES DEFINITIONS ///////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ typedef Eigen::Matrix Matrix##SizeSuffix##TypeSuffix; \ typedef Eigen::Matrix Vector##SizeSuffix##TypeSuffix; \ typedef Eigen::Matrix RowVector##SizeSuffix##TypeSuffix; \ // /* IMPORT INTERFACES */ \ // typedef Interface::DenseMatrix, mpl::int_ > IMatrix##SizeSuffix##TypeSuffix; \ // typedef Interface::DenseArray > IVector##SizeSuffix##TypeSuffix; \ // typedef Interface::DenseArray > IRowVector##SizeSuffix##TypeSuffix; #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \ EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \ EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i) EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f) EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d) EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex, cf) EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex, cd) #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES #undef EIGEN_MAKE_TYPEDEFS //#define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ ///** \ingroup arraytypedefs */ \ //typedef Eigen::Array Array##SizeSuffix##SizeSuffix##TypeSuffix; \ ///** \ingroup arraytypedefs */ \ //typedef Eigen::Array Array##SizeSuffix##TypeSuffix; //#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \ ///** \ingroup arraytypedefs */ \ //typedef Eigen::Array Array##Size##X##TypeSuffix; \ ///** \ingroup arraytypedefs */ \ //typedef Eigen::Array Array##X##Size##TypeSuffix; //#define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ //EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \ //EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \ //EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \ //EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \ //EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \ //EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \ //EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4) //EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i) //EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f) //EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d) //EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex, cf) //EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex, cd) //#undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES //#undef EIGEN_MAKE_ARRAY_TYPEDEFS //#undef EIGEN_MAKE_ARRAY_TYPEDEFS_LARGE //#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \ //using Eigen::Matrix##SizeSuffix##TypeSuffix; \ //using Eigen::Vector##SizeSuffix##TypeSuffix; \ //using Eigen::RowVector##SizeSuffix##TypeSuffix; //#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \ //EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \ //EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \ //EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \ //EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \ //#define EIGEN_USING_ARRAY_TYPEDEFS \ //EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \ //EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \ //EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \ //EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \ //EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd) } // uLib //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // OLD PART // //// BOOST SERIALIZATION /////////////////////////////////////////////////////// #include #include #include #include #include #include namespace boost { namespace serialization { template void serialize(Archive & ar, ::Eigen::Matrix & m, const unsigned int /*version*/) { ar & boost::serialization::make_array(m.data(), RowsAtCompileTime * ColsAtCompileTime); } } // serialization } // boost //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // EIGEN VECTOR STREAM INTERACTIONS //////////////////////////////////////////// // this is needed by boost::lexical_cast to cope with Eigens Vectors /////////// namespace Eigen { template std::istream & operator >> (std::basic_istream &is, Eigen::Matrix &vec) { std::basic_string str; for( unsigned int i=0; i> std::skipws >> str; if(is.fail()) vec(i) = 0; else vec(i) = boost::lexical_cast(str); } return is; } template Eigen::Matrix & operator >> (const std::basic_string &str, Eigen::Matrix &vec) { std::stringstream ss(str); ss >> vec; return vec; } template std::basic_ostream & operator << (std::basic_ostream &os, const Eigen::Matrix &vec) { // os << "[" << vec.transpose() << "]T"; // TODO: read and write Transposition with a proper symbol os << vec.transpose(); return os; } template std::basic_string & operator << (std::basic_string &str, const Eigen::Matrix &vec) { std::basic_stringstream ss; ss << vec; str += ss.str(); return str; } } // Eigen //////////////////////////////////////////////////////////////////////////////// namespace uLib { typedef int Scalari; typedef unsigned int Scalarui; typedef long Scalarl; typedef unsigned long Scalarul; typedef float Scalarf; typedef double Scalard; } // uLib //typedef Eigen::Matrix Matrix1i; //typedef Eigen::Matrix2i Matrix2i; //typedef Eigen::Matrix3i Matrix3i; //typedef Eigen::Matrix4i Matrix4i; //typedef Eigen::Matrix Matrix1f; //typedef Eigen::Matrix2f Matrix2f; //typedef Eigen::Matrix3f Matrix3f; //typedef Eigen::Matrix4f Matrix4f; //typedef Eigen::Matrix Vector1i; //typedef Eigen::Vector2i Vector2i; //typedef Eigen::Vector3i Vector3i; //typedef Eigen::Vector4i Vector4i; //typedef Eigen::Matrix Vector1f; //typedef Eigen::Vector2f Vector2f; //typedef Eigen::Vector3f Vector3f; //typedef Eigen::Vector4f Vector4f; //////////////////////////////////////////////////////////////////////////////// // Vector String interaction /////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// ///*! Given a string consisting of a series of doubles with some //* delimiter, return an Eigen::Vector populated with those //* values, in the same order as they are given in the string. //* //* \param vec A double vector to be populated with the results //* \param str A string to be parsed as a series of doubles. //* \param delim Delimiters of the text (a typical default is " ," for comma and space-delimited text //* //*/ //template //void VectorxT_StringTo(Eigen::Matrix &vec, std::string str, const char *delim = " ,;\t\n") { // std::vector strvec; // boost::algorithm::trim_if( str, boost::algorithm::is_any_of(delim)); // boost::algorithm::split(strvec,str,boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on); // for( unsigned int i=0; i(strvec[i]); // } //} //template //std::string VectorxT_ToString(const Eigen::Matrix &vec) { // std::stringstream sst; // sst << vec.transpose(); // return sst.str(); //} ////template ////Eigen::Matrix & operator >> (std::istream &is, Eigen::Matrix &vec) { ////} //template //void operator>> (std::string& str, Eigen::Matrix &vec){ // VectorxT_StringTo(vec,str); //} //////////////////////////////////////////////////////////////////////////////// ////// HOMOGENEOUS VECTORS ////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //template //class _HPoint3f : public Eigen::Matrix< Scalarf,4,1 > { //public: // typedef Eigen::Matrix< Scalarf,4,1 > BaseClass; // _HPoint3f

() : BaseClass(0,0,0,p) {} // _HPoint3f

(float x,float y,float z) : BaseClass(x,y,z,p) {} // _HPoint3f

(Vector3f &in) : BaseClass(in.homogeneous()) { this->w = p; } // // This constructor allows to construct MyVectorType from Eigen expressions // template // inline _HPoint3f

(const Eigen::MatrixBase& other) // : BaseClass(other) // { } // // This method allows to assign Eigen expressions to Vector3H // template // inline _HPoint3f

& operator= (const Eigen::MatrixBase & other) // { // this->BaseClass::operator=(other); // return *this; // } //}; //typedef _HPoint3f Vector4f; //typedef _HPoint3f HPoint3f; //////////////////////////////////////////////////////////////////////////////// ////// HOMOGENEOUS LINE ////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //struct _HLine3f //{ // HPoint3f origin; // Vector4f direction; //}; //typedef struct _HLine3f HLine3f; //inline std::ostream& //operator<< (std::ostream& stream, const HLine3f &line) { // stream << "HLine3f(" << "pt[" << line.origin.transpose() <<"] , dr[" << line.direction.transpose() << "]) "; // return stream; //} //struct _HError3f //{ // Vector4f position_error; // Vector4f direction_error; //}; //typedef struct _HError3f HError3f; //inline std::ostream& //operator<< (std::ostream& stream, const HError3f &err) { // stream << "HError3f(" << "ept[" << err.position_error.transpose() <<"] , edr[" << err.direction_error.transpose() << "]) "; // return stream; //} //} //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // SERIALIZTION // // NEW // ULIB_SERIALIZABLE(uLib::Vector2i) ULIB_SERIALIZABLE(uLib::Vector3i) ULIB_SERIALIZABLE(uLib::Vector4i) ULIB_SERIALIZABLE(uLib::Vector2f) ULIB_SERIALIZABLE(uLib::Vector3f) ULIB_SERIALIZABLE(uLib::Vector4f) ULIB_SERIALIZABLE(uLib::Vector2d) ULIB_SERIALIZABLE(uLib::Vector3d) ULIB_SERIALIZABLE(uLib::Vector4d) //ULIB_SERIALIZABLE(uLib::HPoint3f) //ULIB_SERIALIZABLE(uLib::Vector4f) //ULIB_SERIALIZABLE(uLib::HLine3f) //ULIB_SERIALIZABLE(uLib::HError3f) #endif // U_DENSEMATRIX_H