ITK  5.1.0
Insight 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 "opencv2/core/version.hpp"
27 #if !defined(CV_VERSION_EPOCH)
28 // OpenCV 3.x
29 # include "opencv2/core.hpp"
30 #else
31 // OpenCV 2.4.x
32 # include "cv.h"
33 #endif
34 
35 namespace itk
36 {
37 template <typename TITKData, typename TOpenCVData>
39 {};
40 
41 template <typename TPoint>
42 struct OpenCVBasicTypeBridge<TPoint, cv::Point_<typename TPoint::CoordRepType>>
43 {
44  using ITKDataType = TPoint;
45  using CoordinateType = typename TPoint::CoordRepType;
46  using OpenCVDataType = cv::Point_<CoordinateType>;
47 
48  static ITKDataType
50  {
51  ITKDataType oP;
52  oP[0] = iP.x;
53  oP[1] = iP.y;
54 
55  return oP;
56  }
57 
58  static OpenCVDataType
60  {
61  return OpenCVDataType(iP[0], iP[1]);
62  }
63 
64 #ifdef ITK_USE_CONCEPT_CHECKING
65  // Begin concept checking
67 #endif
68 };
69 
70 template <typename TPoint>
71 struct OpenCVBasicTypeBridge<TPoint, cv::Point3_<typename TPoint::CoordRepType>>
72 {
73  using ITKDataType = TPoint;
74  using CoordinateType = typename TPoint::CoordRepType;
75  using OpenCVDataType = cv::Point3_<CoordinateType>;
76 
77  static ITKDataType
79  {
80  ITKDataType oP;
81  oP[0] = iP.x;
82  oP[1] = iP.y;
83  oP[2] = iP.z;
84 
85  return oP;
86  }
87 
88  static OpenCVDataType
90  {
91  return OpenCVDataType(iP[0], iP[1], iP[2]);
92  }
93 
94 #ifdef ITK_USE_CONCEPT_CHECKING
95  // Begin concept checking
97 #endif
98 };
99 
100 template <>
101 struct OpenCVBasicTypeBridge<itk::Index<2>, cv::Point>
102 {
104  using OpenCVDataType = cv::Point;
105 
106  static ITKDataType
108  {
109  ITKDataType oP;
110  oP[0] = static_cast<itk::IndexValueType>(iP.x);
111  oP[1] = static_cast<itk::IndexValueType>(iP.y);
112 
113  return oP;
114  }
115 
116  static OpenCVDataType
118  {
119  return OpenCVDataType(static_cast<int>(iP[0]), static_cast<int>(iP[1]));
120  }
121 };
122 
123 template <>
124 struct OpenCVBasicTypeBridge<itk::Index<3>, cv::Point3i>
125 {
127  using OpenCVDataType = cv::Point3i;
128 
129  static ITKDataType
131  {
132  ITKDataType oP;
133  oP[0] = static_cast<itk::IndexValueType>(iP.x);
134  oP[1] = static_cast<itk::IndexValueType>(iP.y);
135  oP[2] = static_cast<itk::IndexValueType>(iP.z);
136 
137  return oP;
138  }
139 
140  static OpenCVDataType
142  {
143  return OpenCVDataType(static_cast<int>(iP[0]), static_cast<int>(iP[1]), static_cast<int>(iP[2]));
144  }
145 };
146 
147 template <>
148 struct OpenCVBasicTypeBridge<itk::Size<2>, cv::Size>
149 {
151  using OpenCVDataType = cv::Size;
152 
153  static ITKDataType
155  {
156  ITKDataType oP;
157  oP[0] = static_cast<itk::SizeValueType>(iP.width);
158  oP[1] = static_cast<itk::SizeValueType>(iP.height);
159 
160  return oP;
161  }
162 
163  static OpenCVDataType
165  {
166  return OpenCVDataType(static_cast<int>(iP[0]), static_cast<int>(iP[1]));
167  }
168 };
169 
170 template <typename T, unsigned int NRows, unsigned int NColumns>
171 struct OpenCVBasicTypeBridge<itk::Matrix<T, NRows, NColumns>, cv::Matx<T, NRows, NColumns>>
172 {
174  using OpenCVDataType = cv::Matx<T, NRows, NColumns>;
175 
176  static ITKDataType
178  {
179  return ITKDataType(typename ITKDataType::InternalMatrixType().copy_in(iP.val));
180  }
181 
182  static OpenCVDataType
184  {
185  OpenCVDataType oM;
186  iP.GetVnlMatrix().copy_out(oM.val);
187  return oM;
188  }
189 };
190 
191 template <typename TVector>
192 struct OpenCVBasicTypeBridge<TVector, cv::Vec<typename TVector::ValueType, TVector::Dimension>>
193 {
194  using ITKDataType = TVector;
195  using ValueType = typename TVector::ValueType;
196  using OpenCVDataType = cv::Vec<ValueType, TVector::Dimension>;
197 
198  static ITKDataType
200  {
201  return ITKDataType(iP.val);
202  }
203 
204  static OpenCVDataType
206  {
207  OpenCVDataType oM;
208  std::copy(iP.Begin(), iP.End(), oM.val);
209  return oM;
210  }
211 };
212 
213 } // namespace itk
214 #endif
itk::OpenCVBasicTypeBridge< itk::Matrix< T, NRows, NColumns >, cv::Matx< T, NRows, NColumns > >::FromITKToOpenCV
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:183
itk::OpenCVBasicTypeBridge< TPoint, cv::Point_< typename TPoint::CoordRepType > >::ITKDataType
TPoint ITKDataType
Definition: itkOpenCVBasicTypeBridge.h:44
itk::OpenCVBasicTypeBridge< TPoint, cv::Point3_< typename TPoint::CoordRepType > >::FromITKToOpenCV
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:89
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
itk::Matrix::GetVnlMatrix
InternalMatrixType & GetVnlMatrix()
Definition: itkMatrix.h:177
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::OpenCVBasicTypeBridge< itk::Matrix< T, NRows, NColumns >, cv::Matx< T, NRows, NColumns > >::FromOpenCVToITK
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:177
itkMatrix.h
itk::OpenCVBasicTypeBridge< itk::Size< 2 >, cv::Size >::FromOpenCVToITK
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:154
itk::OpenCVBasicTypeBridge< TVector, cv::Vec< typename TVector::ValueType, TVector::Dimension > >::OpenCVDataType
cv::Vec< ValueType, TVector::Dimension > OpenCVDataType
Definition: itkOpenCVBasicTypeBridge.h:196
itk::Matrix::InternalMatrixType
vnl_matrix_fixed< T, NRows, NColumns > InternalMatrixType
Definition: itkMatrix.h:65
itkPoint.h
itk::OpenCVBasicTypeBridge< itk::Index< 2 >, cv::Point >::FromOpenCVToITK
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:107
itk::OpenCVBasicTypeBridge< TPoint, cv::Point_< typename TPoint::CoordRepType > >::CoordinateType
typename TPoint::CoordRepType CoordinateType
Definition: itkOpenCVBasicTypeBridge.h:45
itk::OpenCVBasicTypeBridge< TPoint, cv::Point_< typename TPoint::CoordRepType > >::FromOpenCVToITK
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:49
itk::OpenCVBasicTypeBridge< TPoint, cv::Point3_< typename TPoint::CoordRepType > >::CoordinateType
typename TPoint::CoordRepType CoordinateType
Definition: itkOpenCVBasicTypeBridge.h:74
itk::OpenCVBasicTypeBridge< itk::Index< 2 >, cv::Point >::FromITKToOpenCV
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:117
itk::OpenCVBasicTypeBridge< TPoint, cv::Point3_< typename TPoint::CoordRepType > >::ITKDataType
TPoint ITKDataType
Definition: itkOpenCVBasicTypeBridge.h:73
itk::OpenCVBasicTypeBridge< itk::Size< 2 >, cv::Size >::OpenCVDataType
cv::Size OpenCVDataType
Definition: itkOpenCVBasicTypeBridge.h:151
itk::Concept::SameDimension
Definition: itkConceptChecking.h:692
itk::OpenCVBasicTypeBridge< TPoint, cv::Point3_< typename TPoint::CoordRepType > >::OpenCVDataType
cv::Point3_< CoordinateType > OpenCVDataType
Definition: itkOpenCVBasicTypeBridge.h:75
itk::OpenCVBasicTypeBridge< TVector, cv::Vec< typename TVector::ValueType, TVector::Dimension > >::FromITKToOpenCV
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:205
itk::OpenCVBasicTypeBridge< TVector, cv::Vec< typename TVector::ValueType, TVector::Dimension > >::FromOpenCVToITK
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:199
itk::OpenCVBasicTypeBridge< itk::Size< 2 >, cv::Size >::FromITKToOpenCV
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:164
itk::OpenCVBasicTypeBridge< TPoint, cv::Point3_< typename TPoint::CoordRepType > >::FromOpenCVToITK
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:78
itk::OpenCVBasicTypeBridge< itk::Index< 3 >, cv::Point3i >::FromITKToOpenCV
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:141
itk::OpenCVBasicTypeBridge< TVector, cv::Vec< typename TVector::ValueType, TVector::Dimension > >::ValueType
typename TVector::ValueType ValueType
Definition: itkOpenCVBasicTypeBridge.h:195
itk::OpenCVBasicTypeBridge< itk::Index< 3 >, cv::Point3i >::FromOpenCVToITK
static ITKDataType FromOpenCVToITK(const OpenCVDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:130
itkIndex.h
itk::Matrix
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:50
itk::OpenCVBasicTypeBridge< TVector, cv::Vec< typename TVector::ValueType, TVector::Dimension > >::ITKDataType
TVector ITKDataType
Definition: itkOpenCVBasicTypeBridge.h:194
itk::OpenCVBasicTypeBridge< itk::Index< 2 >, cv::Point >::OpenCVDataType
cv::Point OpenCVDataType
Definition: itkOpenCVBasicTypeBridge.h:104
itk::OpenCVBasicTypeBridge< itk::Matrix< T, NRows, NColumns >, cv::Matx< T, NRows, NColumns > >::OpenCVDataType
cv::Matx< T, NRows, NColumns > OpenCVDataType
Definition: itkOpenCVBasicTypeBridge.h:174
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:64
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::OpenCVBasicTypeBridge< TPoint, cv::Point_< typename TPoint::CoordRepType > >::OpenCVDataType
cv::Point_< CoordinateType > OpenCVDataType
Definition: itkOpenCVBasicTypeBridge.h:46
itk::OpenCVBasicTypeBridge
Definition: itkOpenCVBasicTypeBridge.h:38
itk::OpenCVBasicTypeBridge< itk::Index< 3 >, cv::Point3i >::OpenCVDataType
cv::Point3i OpenCVDataType
Definition: itkOpenCVBasicTypeBridge.h:127
itkSize.h
itk::OpenCVBasicTypeBridge< TPoint, cv::Point_< typename TPoint::CoordRepType > >::FromITKToOpenCV
static OpenCVDataType FromITKToOpenCV(const ITKDataType &iP)
Definition: itkOpenCVBasicTypeBridge.h:59