vmmlib  1.7.0
 All Classes Namespaces Functions Pages
matrix_traits.hpp
1 /*
2  * Copyright (c) 2006-2014, Visualization and Multimedia Lab,
3  * University of Zurich <http://vmml.ifi.uzh.ch>,
4  * Eyescale Software GmbH,
5  * Blue Brain Project, EPFL
6  *
7  * This file is part of VMMLib <https://github.com/VMML/vmmlib/>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * Redistributions of source code must retain the above copyright notice, this
13  * list of conditions and the following disclaimer. Redistributions in binary
14  * form must reproduce the above copyright notice, this list of conditions and
15  * the following disclaimer in the documentation and/or other materials provided
16  * with the distribution. Neither the name of the Visualization and Multimedia
17  * Lab, University of Zurich nor the names of its contributors may be used to
18  * endorse or promote products derived from this software without specific prior
19  * written permission.
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 //Copyright (c) 2010 Daniel Pfeifer
33 
34 #ifndef __VMML_MATRIX_TRAITS_HPP__
35 #define __VMML_MATRIX_TRAITS_HPP__
36 
37 #include <vmmlib/matrix.hpp>
38 #include <boost/la/matrix_traits.hpp>
39 
40 namespace boost
41 {
42 namespace la
43 {
44 
45 template<size_t M, size_t N, typename T>
46 struct matrix_traits<vmml::matrix<M, N, T> >
47 {
49 
50  static const int rows = M;
51  static const int cols = N;
52 
53  typedef T scalar_type;
54 
55  template<int Row, int Col>
56  static scalar_type r(const matrix_type& m)
57  {
58  BOOST_STATIC_ASSERT(Row >= 0);
59  BOOST_STATIC_ASSERT(Row < rows);
60  BOOST_STATIC_ASSERT(Col >= 0);
61  BOOST_STATIC_ASSERT(Col < cols);
62  return m.at(Col, Row);
63  }
64 
65  template<int Row, int Col>
66  static scalar_type& w(matrix_type& m)
67  {
68  BOOST_STATIC_ASSERT(Row >= 0);
69  BOOST_STATIC_ASSERT(Row < rows);
70  BOOST_STATIC_ASSERT(Col >= 0);
71  BOOST_STATIC_ASSERT(Col < cols);
72  return m.at(Col, Row);
73  }
74 
75  static scalar_type ir(int row, int col, const matrix_type& m)
76  {
77  BOOST_ASSERT(row >= 0);
78  BOOST_ASSERT(row < rows);
79  BOOST_ASSERT(col >= 0);
80  BOOST_ASSERT(col < cols);
81  return m.at(col, row);
82  }
83 
84  static scalar_type& iw(int row, int col, matrix_type& m)
85  {
86  BOOST_ASSERT(row >= 0);
87  BOOST_ASSERT(row < rows);
88  BOOST_ASSERT(col >= 0);
89  BOOST_ASSERT(col < cols);
90  return m.at(col, row);
91  }
92 };
93 
94 } // namespace la
95 } // namespace boost
96 
97 #endif /* VMML_MATRIX_TRAITS_HPP */
98