All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
utils.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  */
19 
20 #ifndef UTILS_H_
21 #define UTILS_H_
22 
23 #include <string>
24 #include "fmatvec/fmatvec.h"
25 #include <mbsim/numerics/csparse.h>
26 #include <mbxmlutilshelper/dom.h>
27 #include <xercesc/dom/DOMDocument.hpp>
28 #include <limits>
29 #include <vector>
30 #include <set>
31 #include <boost/lexical_cast.hpp>
32 #include <boost/algorithm/string/trim.hpp>
33 
34 namespace MBSim {
35 
36  std::string numtostr(int i);
37  std::string numtostr(double d);
38  template<class Type, class Row, class Col>
39  std::string numtostr(fmatvec::Matrix<Type,Row,Col,double> m) {
40  std::ostringstream oss;
41  oss << "[ ";
42  for(int i=0;i<m.rows()-1;i++) {
43  for(int j=0;i<m.cols()-1;j++) oss << m.e(i,j) << ", ";
44  oss << "\n";
45  }
46  oss << "]";
47  return oss.str();
48  }
49 
50  double sign(double x);
51 
58  double ArcTan(double x,double y);
59 
63  fmatvec::Mat cs2Mat(cs* sparseMat);
64 
65  template <class T>
66  inline std::string toStr(const T &val) {
67  std::stringstream s;
68  s << std::setprecision(std::numeric_limits<double>::digits10+1) << val;
69  return s.str();
70  }
71 
72  template <class Arg>
73  class ToDouble {
74  };
75 
76  template <>
77  class ToDouble<double> {
78  public:
79  static double cast(const double &x) {
80  return x;
81  }
82  };
83 
84  template <class Col>
85  class ToDouble<fmatvec::Vector<Col,double> > {
86  public:
87  static double cast(const fmatvec::Vector<Col,double> &x) {
88  return x.e(0);
89  }
90  };
91 
92  template <class Row>
93  class ToDouble<fmatvec::RowVector<Row,double> > {
94  public:
95  static double cast(const fmatvec::RowVector<Row,double> &x) {
96  return x.e(0);
97  }
98  };
99 
100  template <class Ret>
101  class FromMatStr {
102  public:
103  static Ret cast(const char *x) {
104  return Ret(x);
105  }
106  };
107 
108  template <>
109  class FromMatStr<double> {
110  public:
111  static double cast(const std::string &x) {
112  return boost::lexical_cast<double>(boost::algorithm::trim_copy(x));
113  }
114  };
115 
116  template <class Ret>
117  class FromDouble {
118  public:
119  static Ret cast(double x) {
120  return Ret(1,fmatvec::INIT,x);
121  }
122  };
123 
124  template <>
125  class FromDouble<double> {
126  public:
127  static double cast(double x) {
128  return x;
129  }
130  };
131 
132  template <class Ret>
133  class FromVecV {
134  public:
135  static Ret cast(const fmatvec::VecV &x) {
136  return x;
137  }
138  };
139 
140  template <>
141  class FromVecV<double> {
142  public:
143  static double cast(const fmatvec::VecV &x) {
144  return x(0);
145  }
146  };
147 
152  fmatvec::Vec3 computeTangential(const fmatvec::Vec3 &n);
153 
154 }
155 
156 #endif
Definition: utils.h:133
int rows() const
int cols() const
Definition: utils.h:73
double ArcTan(double x, double y)
calculates planar angle in [0,2] with respect to Cartesian coordinates of: Arc Tangent (y/x) ...
Definition: utils.cc:51
Definition: csparse.h:20
Definition: utils.h:117
Mat cs2Mat(cs *sparseMat)
calculate a fmatvec::Mat out of a sparse matrix
Definition: utils.cc:60
Definition: utils.h:101

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Home