SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MatrixTypeConversions.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2012 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 /// @todo Documentation Core/Datatypes/MatrixTypeConversion.h
29 
30 #ifndef CORE_DATATYPES_MATRIX_TYPE_CONVERSIONS_H
31 #define CORE_DATATYPES_MATRIX_TYPE_CONVERSIONS_H
32 
33 #include <Core/Datatypes/Matrix.h>
34 #include <boost/type_traits.hpp>
35 #include <boost/utility/enable_if.hpp>
36 #include <Core/Datatypes/share.h>
37 
38 namespace SCIRun {
39 namespace Core {
40 namespace Datatypes {
41 
42  /// No conversion is done.
43  /// NULL is returned if the matrix is not of the appropriate type.
45  {
46  public:
47  template <class ToType>
48  static boost::shared_ptr<ToType> to(const MatrixHandle& matrix, typename boost::enable_if<boost::is_base_of<MatrixBase<typename ToType::value_type>, ToType> >::type* = 0)
49  {
50  return boost::dynamic_pointer_cast<ToType>(matrix);
51  }
52 
53  static DenseMatrixHandle as_dense(const MatrixHandle& mh);
54  static SparseRowMatrixHandle as_sparse(const MatrixHandle& mh);
55  static DenseColumnMatrixHandle as_column(const MatrixHandle& mh);
56 
57  private:
58  matrix_cast();
59  };
60 
62  {
63  public:
64  // Test to see if the matrix is this subtype.
65  static bool dense(const MatrixHandle& mh);
66  static bool sparse(const MatrixHandle& mh);
67  static bool column(const MatrixHandle& mh);
68  static std::string whatType(const MatrixHandle& mh);
69  private:
70  matrix_is();
71  };
72 
73  /// @todo: move
75  {
76  public:
77  static DenseColumnMatrixHandle to_column(const MatrixHandle& mh);
78  static DenseMatrixHandle to_dense(const MatrixHandle& mh);
79  static SparseRowMatrixHandle to_sparse(const MatrixHandle& mh);
80  private:
82  static const double zero_threshold; /// defines a threshold below that its a zero matrix element (sparsematrix)
83  };
84 
85 }}}
86 
87 
88 #endif
boost::shared_ptr< Matrix > MatrixHandle
Definition: MatrixFwd.h:44
Definition: MatrixTypeConversions.h:61
static boost::shared_ptr< ToType > to(const MatrixHandle &matrix, typename boost::enable_if< boost::is_base_of< MatrixBase< typename ToType::value_type >, ToType > >::type *=0)
Definition: MatrixTypeConversions.h:48
#define SCISHARE
Definition: share.h:39
boost::shared_ptr< SparseRowMatrix > SparseRowMatrixHandle
Definition: MatrixFwd.h:68
Definition: MatrixTypeConversions.h:74
boost::shared_ptr< DenseColumnMatrix > DenseColumnMatrixHandle
Definition: MatrixFwd.h:60
boost::shared_ptr< DenseMatrix > DenseMatrixHandle
Definition: MatrixFwd.h:52
Definition: MatrixTypeConversions.h:44