ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkOpenCVBasicTypeBridge.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkOpenCVBasicTypeBridge_h
19 #define itkOpenCVBasicTypeBridge_h
20 
21 #include "itkPoint.h"
22 #include "itkSize.h"
23 #include "itkIndex.h"
24 #include "itkMatrix.h"
25 
26 #include "cv.h"
27 
28 namespace itk
29 {
30 template< typename TITKData, typename TOpenCVData >
32 {};
33 
34 template< typename TPoint >
35 struct OpenCVBasicTypeBridge< TPoint, cv::Point_< typename TPoint::CoordRepType > >
36 {
37  typedef TPoint ITKDataType;
38  typedef typename TPoint::CoordRepType CoordinateType;
39  typedef cv::Point_< CoordinateType > OpenCVDataType;
40 
42  {
43  ITKDataType oP;
44  oP[0] = iP.x;
45  oP[1] = iP.y;
46 
47  return oP;
48  }
49 
51  {
52  return OpenCVDataType( iP[0], iP[1] );
53  }
54 
55 #ifdef ITK_USE_CONCEPT_CHECKING
56  // Begin concept checking
57  itkConceptMacro( SameDimensionCheck,
59 #endif
60 
61 };
62 
63 template< typename TPoint >
64 struct OpenCVBasicTypeBridge< TPoint, cv::Point3_< typename TPoint::CoordRepType > >
65 {
66  typedef TPoint ITKDataType;
67  typedef typename TPoint::CoordRepType CoordinateType;
68  typedef cv::Point3_< CoordinateType > OpenCVDataType;
69 
71  {
72  ITKDataType oP;
73  oP[0] = iP.x;
74  oP[1] = iP.y;
75  oP[2] = iP.z;
76 
77  return oP;
78  }
79 
81  {
82  return OpenCVDataType( iP[0], iP[1], iP[2] );
83  }
84 
85 #ifdef ITK_USE_CONCEPT_CHECKING
86  // Begin concept checking
87  itkConceptMacro( SameDimensionCheck,
89 #endif
90 };
91 
92 template<>
93 struct OpenCVBasicTypeBridge< itk::Index< 2 >, cv::Point >
94 {
96  typedef cv::Point OpenCVDataType;
97 
99  {
100  ITKDataType oP;
101  oP[0] = static_cast< itk::IndexValueType >( iP.x );
102  oP[1] = static_cast< itk::IndexValueType >( iP.y );
103 
104  return oP;
105  }
106 
108  {
109  return OpenCVDataType( static_cast< int >( iP[0] ), static_cast< int >( iP[1] ) );
110  }
111 };
112 
113 template<>
114 struct OpenCVBasicTypeBridge< itk::Index< 3 >, cv::Point3i >
115 {
117  typedef cv::Point3i OpenCVDataType;
118 
120  {
121  ITKDataType oP;
122  oP[0] = static_cast< itk::IndexValueType >( iP.x );
123  oP[1] = static_cast< itk::IndexValueType >( iP.y );
124  oP[2] = static_cast< itk::IndexValueType >( iP.z );
125 
126  return oP;
127  }
128 
130  {
131  return OpenCVDataType( static_cast< int >( iP[0] ), static_cast< int >( iP[1] ), static_cast< int >( iP[2] ) );
132  }
133 };
134 
135 template<>
136 struct OpenCVBasicTypeBridge< itk::Size< 2 >, cv::Size >
137 {
139  typedef cv::Size OpenCVDataType;
140 
142  {
143  ITKDataType oP;
144  oP[0] = static_cast< itk::SizeValueType >( iP.width );
145  oP[1] = static_cast< itk::SizeValueType >( iP.height );
146 
147  return oP;
148  }
149 
151  {
152  return OpenCVDataType( static_cast< int >( iP[0] ), static_cast< int >( iP[1] ) );
153  }
154 };
155 
156 template< typename T, unsigned int NRows, unsigned int NColumns >
157 struct OpenCVBasicTypeBridge< itk::Matrix< T, NRows, NColumns >, cv::Matx< T, NRows, NColumns > >
158 {
160  typedef cv::Matx< T, NRows, NColumns > OpenCVDataType;
161 
163  {
164  return ITKDataType( typename ITKDataType::InternalMatrixType().copy_in( iP.val ) );
165  }
166 
168  {
169  OpenCVDataType oM;
170  iP.GetVnlMatrix().copy_out( oM.val );
171  return oM;
172  }
173 
174 };
175 
176 template< typename TVector >
177 struct OpenCVBasicTypeBridge< TVector, cv::Vec< typename TVector::ValueType, TVector::Dimension > >
178 {
179  typedef TVector ITKDataType;
180  typedef typename TVector::ValueType ValueType;
181  typedef cv::Vec< ValueType, TVector::Dimension > OpenCVDataType;
182 
184  {
185  return ITKDataType( iP.val );
186  }
187 
189  {
190  OpenCVDataType oM;
191  std::copy( iP.Begin(), iP.End(), oM.val );
192  return oM;
193  }
194 };
195 
196 }
197 #endif
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:46
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
signed long IndexValueType
Definition: itkIntTypes.h:150
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
vnl_matrix_fixed< T, NRows, NColumns > InternalMatrixType
Definition: itkMatrix.h:62
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
unsigned long SizeValueType
Definition: itkIntTypes.h:143
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
InternalMatrixType & GetVnlMatrix(void)
Definition: itkMatrix.h:166
#define itkConceptMacro(name, concept)
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:71