PlaneProjection.h
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2007-2015.
2 // Distributed under the GNU General Public License and under the
3 // BSD 3-Clause License (See accompanying file LICENSE.txt).
4 
5 /** @file */
6 
7 #ifndef NUKLEI_PLANE_PROJECTION_H
8 #define NUKLEI_PLANE_PROJECTION_H
9 
10 #include <nuklei/LinearAlgebra.h>
11 #include <nuklei/Common.h>
13 
14 #ifdef NUKLEI_USE_CIMG
15 // CImg is slow to compile. CImg-related methods will be put in a
16 // separate .cpp, which should include few headers (no KernelCollection.h, ...)
17 // so that it's not compiled too often.
18 namespace cimg_library
19 {
20  template<typename T> class CImg;
21 }
22 #endif
23 
24 namespace nuklei {
25 
26  class Color;
27 
29  {
30  typedef unsigned char pixel_t;
31 #ifdef NUKLEI_USE_CIMG
32  typedef cimg_library::CImg<pixel_t> image_t;
33 #else
34  typedef int image_t;
35 #endif
36 
37  PlaneProjection(const std::string& opencvStereoCalibFile, unsigned camNum = 0);
39  PlaneProjection& operator=(const PlaneProjection& pp);
40  ~PlaneProjection();
41 
42  Vector3 getCamPosition() const;
43  Quaternion getCamOrientation() const;
44 
45  std::vector<Vector2> project(const std::vector<Vector3> worldPoints) const;
46  Vector2 project(const Vector3& p) const;
47 
48  void readImage(const std::string& name);
49  void writeImage(const std::string& name) const;
50 
51  const NUKLEI_UNIQUE_PTR<Color> getColor() const;
52  void setColor(const Color& c);
53 
54  weight_t getOpacity() const { return opacity_; }
55  void setOpacity(const weight_t opacity) { opacity_ = opacity; }
56 
57  const image_t& getImage() const {
58 #ifdef NUKLEI_USE_CIMG
59  NUKLEI_ASSERT(image_.get() != NULL); return *image_;
60 #else
61  NUKLEI_THROW("This function requires CIMG.");
62 #endif
63  }
64 
65  private:
66  void readParameters(const std::string& opencvStereoCalibFile, unsigned camNum);
67 
68  std::vector<double> rotationMatrixData_, translationVectorData_,
69  intrinsicMatrixData_, distortionCoeffsData_;
70 
71 
72  pixel_t color_[3];
73  float opacity_;
74 #ifdef NUKLEI_USE_CIMG
75  NUKLEI_UNIQUE_PTR<image_t> image_;
76 #endif
77  };
78 
80  {
81  typedef unsigned char pixel_t;
82 #ifdef NUKLEI_USE_CIMG
83  typedef cimg_library::CImg<pixel_t> image_t;
84 #else
85  typedef int image_t;
86 #endif
87 
88  StereoPlaneProjection(const std::string& opencvStereoCalibFile) :
89  left_(opencvStereoCalibFile, 0),
90  right_(opencvStereoCalibFile, 1)
91  {}
92  StereoPlaneProjection(const PlaneProjection &left, const PlaneProjection &right) :
93  left_(left),
94  right_(right)
95  {}
97 
98  void project(const std::vector<Vector3> worldPoints) const
99  {
100  left_.project(worldPoints);
101  right_.project(worldPoints);
102  }
103 
104  void readLeftImage(const std::string& name)
105  {
106  left_.readImage(name);
107  }
108  void readRightImage(const std::string& name)
109  {
110  right_.readImage(name);
111  }
112  void writeStereoImage(const std::string& name) const;
113 
114  const NUKLEI_UNIQUE_PTR<Color> getColor() const;
115  void setColor(const Color& c);
116 
117  weight_t getOpacity() const { return opacity_; }
118  void setOpacity(const weight_t opacity)
119  { opacity_ = opacity; left_.setOpacity(opacity_); right_.setOpacity(opacity_); }
120 
121  private:
122  pixel_t color_[3];
123  float opacity_;
124  PlaneProjection left_, right_;
125  };
126 
127 
128 }
129 
130 #endif
Public namespace.
Definition: Color.cpp:9
double weight_t
Type for particle weights.
Definition: Definitions.h:31
#define NUKLEI_ASSERT(expression)
Throws an Error if expression is not true.
Definition: Common.h:113
Definition: Color.h:18
#define NUKLEI_THROW(x)
Throws an Error.
Definition: Common.h:94
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.