Image Component Library (ICL)
RGBDMapping.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLGeom/src/ICLGeom/RGBDMapping.h **
10 ** Module : ICLGeom **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 
32 #pragma once
33 
34 #include <ICLUtils/CompatMacros.h>
35 #include <ICLGeom/Camera.h>
36 #include <ICLUtils/Array2D.h>
37 
38 namespace icl{
39  namespace geom{
40 
41 
43 
47  protected:
51 
53  static inline utils::Point map_rgbd(const Mat &M, const Vec &v){
54  const float phInv = 1.0/ ( M(0,3) * v[0] + M(1,3) * v[1] + M(2,3) * v[2] + M(3,3) );
55  const int px = phInv * ( M(0,0) * v[0] + M(1,0) * v[1] + M(2,0) * v[2] + M(3,0) );
56  const int py = phInv * ( M(0,1) * v[0] + M(1,1) * v[1] + M(2,1) * v[2] + M(3,1) );
57  return utils::Point(px,py);
58  }
59 
60  public:
63 
65  RGBDMapping(const Camera &colorCam, const utils::Array2D<Vec> &depthCamRays,
66  const Vec &depthCamPos):
67  colorCamMatrix(colorCam.getProjectionMatrix() * colorCam.getCSTransformationMatrix()),
68  depthCamRays(depthCamRays){}
69 
71  RGBDMapping(const Camera &colorCam, const Camera &depthCamera):
72  colorCamMatrix(colorCam.getProjectionMatrix() * colorCam.getCSTransformationMatrix()),
73  depthCamRays(depthCamera.getResolution()){
74 
75  utils::Array2D<ViewRay> rays = depthCamera.getAllViewRays();
76  for(int i=0;i<rays.getDim();++i){
77  depthCamRays[i] = rays[i].direction;
78  }
79 
80  depthCamPos = depthCamera.getPosition();
81  }
82 
84  utils::Point apply(const utils::Point &p, float dMM) const{
85  Vec pW = depthCamPos + depthCamRays(p.x,p.y) * dMM;
86  return map_rgbd(colorCamMatrix,pW);
87  }
88 
90  utils::Point operator()(const utils::Point &p, float dMM) const {
91  return apply(p,dMM);
92  }
93 
95 
97  void detach(){
98  depthCamRays.detach();
99  }
100  };
101  }
102 }
Vec depthCamPos
depth camera offset
Definition: RGBDMapping.h:50
static utils::Point map_rgbd(const Mat &M, const Vec &v)
internally used utility function
Definition: RGBDMapping.h:53
RGBDMapping()
empty constructor (no initialization)
Definition: RGBDMapping.h:62
undocument this line if you encounter any issues!
Definition: Any.h:37
const Vec & getPosition() const
Definition: Camera.h:439
void detach()
ensures that the contained data is not shared by other instances
Definition: Array2D.h:201
utils::Array2D< ViewRay > getAllViewRays() const
returns a 2D array of all viewrays
#define ICLGeom_API
Definition: CompatMacros.h:179
Camera class.
Definition: Camera.h:132
Utility class for RGBDMapping.
Definition: RGBDMapping.h:46
int getDim() const
returns the matrix dimension (width*height)
Definition: Array2D.h:160
void detach()
detaches the viewrays from other instances
Definition: RGBDMapping.h:97
utils::Array2D< Vec > depthCamRays
depth camera view rays
Definition: RGBDMapping.h:49
Simple 2D-Array class that provides shallow copy per default.
Definition: Array2D.h:61
utils::Point operator()(const utils::Point &p, float dMM) const
applies the mapping
Definition: RGBDMapping.h:90
RGBDMapping(const Camera &colorCam, const utils::Array2D< Vec > &depthCamRays, const Vec &depthCamPos)
create RGBDMapping from given color camera, and depth camera parameters
Definition: RGBDMapping.h:65
Point class of the ICL used e.g. for the Images ROI offset.
Definition: Point.h:58
Definition: FixedVector.h:40
RGBDMapping(const Camera &colorCam, const Camera &depthCamera)
create RGBDMapping from given color camera, and depth camera
Definition: RGBDMapping.h:71
Mat colorCamMatrix
color camera matrix
Definition: RGBDMapping.h:48
utils::Point apply(const utils::Point &p, float dMM) const
applies the mapping
Definition: RGBDMapping.h:84