Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProjectionParametersDynamicLoad.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #include "Geometry/ProjectionParametersDynamicLoad.hh"
27 #include <dlfcn.h>
28 
29 
30 using namespace BIAS;
31 using namespace std;
32 
33 union ptrCaster{
34  void* ptr;
35  void* (*fnct)();
36 };
37 
39 // if(dynptr_!=NULL){
40 // delete dynptr_;
41 // }
42  if(hndl_ != NULL){
43  //int res =
44  dlclose(hndl_);
45  hndl_ = NULL;
46 // if(res != 0){
47 // BIASERR("Something went wrong when trying to close lib!" << res << " " << dlerror() << endl);
48 // }
49  } else {
50  BIASERR("hndl already null, cannot possibly close it")
51  }
52 }
53 
54 
56 
57  /// add other library paths here
58 #if defined(BIAS_DEBUG) && defined(COMPILE_DEBUG) && !defined(COMPILE_NDEBUG)
59 // libPaths_.push_back("/home/ajordt/builds/mip_debug/lib/libMIPProjectionParametersUnderwaterFlatPortD.so");
60 // libPaths_.push_back("/home/ajordt/builds/mip_debug/lib/libMIPProjectionParametersUnderwaterDomePortD.so");
61 // libPaths_.push_back("/home/ajordt/builds/mip_debug/lib/libMIPProjectionParametersUnderwaterFlatPortSphericalD.so");
62  libPaths_.push_back("/opt/net64/gcc48/underwaterProjection/libMIPProjectionParametersUnderwaterFlatPortD.so");
63  libPaths_.push_back("/opt/net64/gcc48/underwaterProjection/libMIPProjectionParametersUnderwaterDomePortD.so");
64  libPaths_.push_back("/opt/net64/gcc48/underwaterProjection/libMIPProjectionParametersUnderwaterFlatPortSphericalD.so");
65 #else
66 // libPaths_.push_back("/home/ajordt/builds/mip_release/lib/libMIPProjectionParametersUnderwaterFlatPort.so");
67 // libPaths_.push_back("/home/ajordt/builds/mip_release/lib/libMIPProjectionParametersUnderwaterDomePort.so");
68 // libPaths_.push_back("/home/ajordt/builds/mip_release/lib/libMIPProjectionParametersUnderwaterFlatPortSpherical.so");
69  libPaths_.push_back("/opt/net64/gcc48/underwaterProjection/libMIPProjectionParametersUnderwaterFlatPort.so");
70  libPaths_.push_back("/opt/net64/gcc48/underwaterProjection/libMIPProjectionParametersUnderwaterDomePort.so");
71  libPaths_.push_back("/opt/net64/gcc48/underwaterProjection/libMIPProjectionParametersUnderwaterFlatPortSpherical.so");
72 #endif
73 
74  unsigned int libIndex = 0;
75  if(className_ == "ProjectionParametersUnderwaterFlatPort"){
76  libIndex = 0;
77  }
78 
79  if(className_ == "ProjectionParametersUnderwaterDomePort"){
80  libIndex = 1;
81  }
82 
83  if(className_ == "ProjectionParametersUnderwaterFlatPortSpherical"){
84  libIndex = 2;
85  }
86 
87 
88  hndl_ = dlopen(libPaths_[libIndex].c_str(), RTLD_NOW);
89  if(hndl_ == NULL){
90  cerr << "Dynamic Load Error: " << dlerror() << endl;
91  } else {
92  ptrCaster mkr;
93  mkr.ptr = dlsym(hndl_,"ppDynLoadMaker");
94  if (mkr.ptr == NULL){
95  cout << "Dynamic Load Error: Library does not seem to be compatible. No ppDynLoadMaker found." << endl;
96  dynptr_ = NULL;
97  } else {
98  maker_t maker = reinterpret_cast<maker_t>(mkr.fnct);
99  dynptr_ = (*maker)();
100 // cout << "dynptr from maker " << dynptr_ << endl << flush;
101 // cout << "content from maker " << *dynptr_ << endl << flush;
102  }
103 
104  // int res = dlclose(hndl_);
105 // if(res != 0){
106 // BIASERR("Something went wrong when trying to close lib!")
107 // }
108 // hndl_ = NULL;
109  }
110 
111 }
112 
113 
115  dynptr_->GetFirstBorderPixel(it);
116 }
117 
119  return dynptr_->GetNextBorderPixel(it);
120 }
121 
123  dynptr_->GetFirstEdgePosition(it);
124 }
125 
127  return dynptr_->GetNextEdgePosition(it);
128 }
129 
131  double& minPhi, double& maxPhi, double& centerPhi,
132  double& minTheta, double& maxTheta){
133  return dynptr_->GetSphericalViewingRange(sphericalReferenceFrame, minPhi, maxPhi, centerPhi, minTheta, maxTheta);
134 }
135 
136 
139 {
140  return dynptr_->DoIntrinsicsDiffer(p);
141 }
142 
145  HomgPoint2D& x,
146  bool IgnoreDistortion) const
147 {
148 
149  return dynptr_->DoesPointProjectIntoImageLocal(localX, x, IgnoreDistortion);
150 }
151 
152 
154 ProjectLocal(const Vector3<double>& point, bool IgnoreDistortion) const
155 {
156  return dynptr_->ProjectLocal(point,IgnoreDistortion);
157 }
158 
159 
162  bool IgnoreDistortion) const
163 {
164 
165  return dynptr_->ProjectLocal(point, p2d, IgnoreDistortion);
166 }
167 
168 
169 
171 UnProjectLocal(const HomgPoint2D& cPos, Vector3<double>& pointOnRay,
172  Vector3<double>& direction, bool IgnoreDistortion) const {
173  dynptr_->UnProjectLocal(cPos, pointOnRay, direction, IgnoreDistortion);
174 }
175 
177 UnProjectToImagePlane(const HomgPoint2D& pos, const double& depth,
178  bool IgnoreDistortion) const
179 {
180 
181  return dynptr_->UnProjectToImagePlane(pos, depth, IgnoreDistortion);
182 }
183 
184 
186 Distort(HomgPoint2D& point2d) const
187 {
188  return dynptr_->Distort(point2d);
189 }
190 
191 
193 Undistort(HomgPoint2D& point2d) const
194 {
195  return dynptr_->Undistort(point2d);
196 }
197 
198 
199 
200 #ifdef BIAS_HAVE_XML2
201 
203 XMLGetClassName(std::string& TopLevelTag, double& Version) const {
204  dynptr_->XMLGetClassName(TopLevelTag, Version);
205  return 0;
206 }
207 
209 XMLOut(const xmlNodePtr Node, XMLIO& XMLObject) const {
210  dynptr_->XMLOut(Node, XMLObject);
211  return 0;
212 }
213 
214 
216 XMLIn(const xmlNodePtr Node, XMLIO& XMLObject) {
217 // cout << "dynptr " << dynptr_ << endl << flush;
218 // cout << "dynptr content " << *dynptr_ << endl << flush;
219  dynptr_->XMLIn(Node, XMLObject);
220 
221  return 0;
222 }
223 
224 #endif // BIAS_HAVE_XML2
225 
226 
227 
228 
229 
230 /////////////////////////////////////////////////////////////////////////////////////
231 
232 
235  bool IgnoreDistortion, bool Normalize)
236 {
237  return dynptr_->UnProjectCovLocal(pos, cov2D, IgnoreDistortion, Normalize);
238 }
239 
240 
241 
virtual void GetFirstEdgePosition(PixelIterator &it)
call this to start a run at the outer boundary of an image.
virtual int XMLOut(const xmlNodePtr Node, XMLIO &XMLObject) const
specialization of XML write function
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
virtual Matrix3x3< double > UnProjectCovLocal(const HomgPoint2D &pos, const Matrix3x3< double > &cov2D, bool IgnoreDistortion=false, bool Normalize=false)
unprojects the covariance matrices to K=Identity camera
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
specialization of XML block name function
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &pointOnRay, Vector3< double > &direction, bool IgnoreDistortion=false) const
calculates the unit size viewing ray from the camera center (in the camera coordinate system) which b...
virtual HomgPoint3D UnProjectToImagePlane(const HomgPoint2D &pos, const double &depth=1.0, bool IgnoreDistortion=false) const
map points from image onto unit diameter image plane in 3D.
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
virtual HomgPoint2D ProjectLocal(const Vector3< double > &point, bool IgnoreDistortion=false) const
calculates the projection of a point in the local camera coordinate system to a pixel in the image pl...
virtual void GetFirstBorderPixel(PixelIterator &it)
call this to start a run at the outer boundary of an image.
virtual bool Undistort(BIAS::HomgPoint2D &point2d) const
Interface defintion for lens undistortion function, implemented by derived classes.
virtual const bool DoIntrinsicsDiffer(const ProjectionParametersBase *p) const
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
virtual bool Distort(BIAS::HomgPoint2D &point2d) const
Interface defintion for lens distortion function, implemented by derived classes. ...
Can be used to run along the image border.
virtual bool DoesPointProjectIntoImageLocal(const Vector3< double > &localX, HomgPoint2D &x, bool IgnoreDistortion=false) const
Checks if 3D point projects into specified image and returns belonging 2D image point.
virtual bool GetNextBorderPixel(PixelIterator &it)
call this iteratively to run at the outer boundary of an image.
virtual int GetSphericalViewingRange(const CoordinateTransform3D &sphericalReferenceFrame, double &minPhi, double &maxPhi, double &centerPhi, double &minTheta, double &maxTheta)
Determines the maximal and minimal viewing range in means of spherical coordinates.
ProjectionParametersBase *(* maker_t)()
virtual bool GetNextEdgePosition(PixelIterator &it)
call this iteratively to run at the outer edge of an image.
Transforms 3d points between two different coodinate systems, e.g.
virtual int XMLIn(const xmlNodePtr Node, XMLIO &XMLObject)
specialization of XML read function
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...