26 #ifndef __BIAS_Projection_hh__
27 #define __BIAS_Projection_hh__
29 #include <bias_config.h>
33 #include <Base/Debug/Debug.hh>
34 #include <Base/Math/Matrix4x4.hh>
35 #include <Base/Math/Vector4.hh>
36 #include <Base/Geometry/HomgPoint3D.hh>
37 #include <Base/Geometry/Quaternion.hh>
38 #include <Geometry/Pose.hh>
39 #include <Geometry/PMatrix.hh>
40 #include <Geometry/ProjectionParametersBase.hh>
41 #include <Geometry/ProjectionParametersPerspective.hh>
42 #include <Geometry/ProjectionParametersPerspectiveDepth.hh>
43 #include <Geometry/ProjectionParametersSpherical.hh>
44 #include <Geometry/ProjectionParametersSphericalFast.hh>
45 #include <Geometry/ProjectionParametersSphericalSimple.hh>
46 #include <Geometry/ProjectionParametersCylindric.hh>
47 #include <Geometry/ProjectionParametersProjective.hh>
48 #include <Geometry/ProjectionParametersIO.hh>
50 #ifdef BUILD_DYNAMIC_LOAD_PROJECTION
51 #include <Geometry/ProjectionParametersDynamicLoad.hh>
54 #include <Geometry/ProjectionParametersFactory.hh>
57 # include <Base/Common/XMLBase.hh>
58 #endif // BIAS_HAVE_XML2
73 #endif // BIAS_HAVE_XML2
87 for (
unsigned int i=0; i<vecParameters_.size(); i++) {
88 delete vecParameters_[i];
90 vecParameters_.clear();
110 void CreatePerspective(
const BIAS::Pose& pose,
112 int width,
int height,
114 const std::vector<double>&
115 UndistortionCoefficients =
116 std::vector<double>(4, 0.0));
120 void CreateSpherical(
const Pose& pose,
121 const unsigned int width,
const int height,
122 const double principalX,
const double principalY,
124 const double aspect=1.0 );
148 #ifdef BIAS_HAVE_XML2
154 int ReadFromCamParamFile(
const std::string& filename,
const bool silent =
false);
156 #endif // BIAS_HAVE_XML2
162 int ReadFromBBC(
const std::string& filename,
const bool silent =
false);
166 int InitFromCameraData(
const std::vector<CameraData>& vcd);
170 virtual int Load(
const std::string& filename);
174 bool IsEmpty()
const {
return (vecParameters_.size()==0);}
178 inline unsigned int Size()
const
180 return (
unsigned int)vecParameters_.size();
186 for (
unsigned int i=0; i<vecParameters_.size(); i++) {
187 delete vecParameters_[i];
189 vecParameters_.clear();
195 if(cam >= vecParameters_.size()){
196 BIASWARN(
"No parameters for camera with index:"<<cam);
199 return vecParameters_[cam];
205 if(cam >= vecParameters_.size()){
206 BIASWARN(
"No parameters for camera with index:"<<cam);
209 return vecParameters_[cam];
219 if(cam >= vecParameters_.size()){
220 BIASWARN(
"No parameters for camera with index:"<<cam);
225 Pose rigPose = vecParameters_[0]->GetPose();
237 BIASASSERT(cam<vecParameters_.size() && vecParameters_[cam]);
238 return vecParameters_[cam]->GetC();
244 BIASASSERT(cam<vecParameters_.size() && vecParameters_[cam]);
245 return vecParameters_[cam]->GetR();
251 BIASASSERT(cam<vecParameters_.size());
252 BIASASSERT(vecParameters_.size()>cam && vecParameters_[0] && vecParameters_[cam]);
254 return vecParameters_[0]->GetR() * vecParameters_[cam]->GetR();
256 return vecParameters_[cam]->GetR();
262 BIASASSERT(cam<vecParameters_.size());
263 BIASASSERT(vecParameters_.size()>cam && vecParameters_[0] && vecParameters_[cam]);
265 return vecParameters_[0]->GetC() +
266 vecParameters_[0]->GetR() *vecParameters_[cam]->GetC();
268 return vecParameters_[0]->GetC();
274 BIASASSERT(cam<vecParameters_.size());
275 BIASASSERT(vecParameters_.size()>cam && vecParameters_[0] && vecParameters_[cam]);
277 return vecParameters_[0]->GetQ() * vecParameters_[cam]->GetQ();
280 return vecParameters_[0]->GetQ();
293 BIASASSERT(vecParameters_.size()>cam && vecParameters_[cam]);
294 BIASASSERT(cam<vecParameters_.size());
296 return vecParameters_[cam]->GetExternals();
298 BIASWARN(
"Externals of relative camera may be incorrect!");
299 return vecParameters_[cam]->GetExternals();
307 BIASASSERT(cam<vecParameters_.size() && vecParameters_[cam]);
308 if (cam==0)
return vecParameters_[cam]->GetCov();
310 BIASWARN(
"Not yet defined behaviour!");
311 return vecParameters_[cam]->GetCov();
319 BIASASSERT(cam<vecParameters_.size() && vecParameters_[cam]);
320 return vecParameters_[cam]->GetPose();
325 BIASASSERT(cam<vecParameters_.size() && vecParameters_[cam]);
326 vecParameters_[cam]->SetCov(Cov);
332 BIASASSERT(vecParameters_.size()>cam && vecParameters_[cam]);
333 vecParameters_[cam]->SetC(C);
339 BIASASSERT(vecParameters_.size()>cam && vecParameters_[cam]);
340 vecParameters_[cam]->SetQ(Q);
346 BIASASSERT(vecParameters_.size()>cam && vecParameters_[cam]);
347 vecParameters_[cam]->SetR(R);
353 BIASASSERT(vecParameters_.size()>cam && vecParameters_[cam]);
354 vecParameters_[cam]->SetPose(pose);
360 if (vecParameters_.size()<=cam || !vecParameters_[cam])
return false;
361 return vecParameters_[cam]->PoseValid();
370 bool IgnoreDistortion =
false)
const;
380 unsigned int cam = 0,
381 bool IgnoreDistortion =
false)
const;
402 unsigned int cam = 0,
403 bool IgnoreDistortion =
false)
const;
411 unsigned int cam = 0,
412 bool IgnoreDistortion =
false)
const;
420 unsigned int cam = 0,
421 bool IgnoreDistortion =
false)
const;
430 unsigned int camSystem = 0,
431 unsigned int cam = 0,
432 bool IgnoreDistortion =
false)
const;
440 unsigned int camSystem = 0,
441 unsigned int cam = 0,
442 bool IgnoreDistortion =
false,
443 bool Normalize =
false)
const;
450 unsigned int camSystem = 0,
451 unsigned int cam = 0,
452 bool IgnoreDistortion =
false)
const;
454 #ifdef BIAS_HAVE_XML2
457 virtual int XMLGetClassName(std::string& TopLevelTag,
458 double& Version)
const;
462 virtual int XMLOut(
const xmlNodePtr Node,
XMLIO& XMLObject)
const;
466 virtual int XMLIn(
const xmlNodePtr Node,
XMLIO& XMLObject);
467 #endif // BIAS_HAVE_XML2
471 inline void Rescale(
float ratio,
unsigned int cam = 0) {
472 BIASASSERT(cam < vecParameters_.size());
473 BIASASSERT(vecParameters_[cam]!=NULL);
474 vecParameters_[cam]->Rescale(ratio);
479 identifier_ = identString;
505 os <<
"vecParameters_.size(): "<<p.
Size()<<
"\n";
506 std::vector<ProjectionParametersBase* >::const_iterator it;
509 #ifdef BUILD_DYNAMIC_LOAD_PROJECTION
512 if ((dynamic_cast<ProjectionParametersDynamicLoad*>(*it))!=NULL){
513 os << *(dynamic_cast<ProjectionParametersDynamicLoad*>(*it));
522 if ((dynamic_cast<ProjectionParametersPerspectiveDepth *>(*it))!=NULL)
523 os <<*(dynamic_cast<ProjectionParametersPerspectiveDepth *>(*it));
524 else if ((dynamic_cast<ProjectionParametersPerspective *>(*it))!=NULL)
525 os <<*(dynamic_cast<ProjectionParametersPerspective *>(*it));
526 else if ((dynamic_cast<ProjectionParametersSpherical*>(*it))!=NULL)
527 os << *(dynamic_cast<ProjectionParametersSpherical *>(*it));
528 else if ((dynamic_cast<ProjectionParametersSphericalFast*>(*it))!=NULL)
529 os << *(dynamic_cast<ProjectionParametersSphericalFast *>(*it));
530 else if ((dynamic_cast<ProjectionParametersSphericalSimple*>(*it))!=NULL)
531 os << *(dynamic_cast<ProjectionParametersSphericalSimple*>(*it));
532 else if ((dynamic_cast<ProjectionParametersProjective*>(*it))!=NULL)
533 os << *(dynamic_cast<ProjectionParametersProjective*>(*it));
542 #endif //__BIAS_Projection_hh__
Quaternion< double > GetAbsoluteQ(unsigned int cam=0) const
return rotation quaternion of camera with index cam.
bool PoseValid(unsigned int cam=0) const
Determine whether the pose is valid or not.
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
std::string identifier_
Multifunctional identifier.
virtual const Pose & GetPose(unsigned int cam=0) const
return complete pose object.
ProjectionParametersBase * GetParameters(unsigned int cam=0)
Non-const access function to parameters.
virtual ProjectionParametersBase * Clone() const =0
Covariant virtual copy constructor used in BIAS::Projection.
Matrix3x4< double > GetExternals(unsigned int cam=0) const
Obtain the external camera parameters.
std::string GetIdentifier() const
Return the identifier of the Projection such as a name.
std::vector< ProjectionParametersBase * > vecParameters_
the intrinsics (like K, ...) of the camera usually only one only in rig mode there may be many...
void Rescale(float ratio, unsigned int cam=0)
adapt internal params to resampled image
void Clear()
Delete all ProjectionParameterBase objects contained in Projection.
virtual void SetC(const Vector3< double > &C, unsigned int cam=0)
Set center of camera with index cam.
virtual void SetPose(const BIAS::Pose pose)
Set pose from pose object.
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
virtual void SetR(const RMatrix &R, unsigned int cam=0)
Set rotation matrix of camera with index cam.
virtual void SetPose(const BIAS::Pose pose, unsigned int cam=0)
Set the Pose of the camera with index cam.
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
const Projection & operator=(const Projection &p)
operator=
Base class with interface for xml output.
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
bool IsEmpty() const
Determine whether the Projection is Empty.
virtual void SetCov(const Matrix< double > &Cov, unsigned int cam=0)
Set the Pose covariance.
virtual Matrix< double > GetCov(unsigned int cam=0) const
Get the Pose covariance.
BIAS_ProjParaPersp_DISTORTION_TYPE
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
virtual void SetQ(const Quaternion< double > &Q, unsigned int cam=0)
Set rotation quaternion of camera with index cam.
unsigned int Size() const
Determine number of ProjectionParameterBase pointers in Projection.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual const BIAS::Pose & GetPose() const
Return complete pose object.
Vector3< double > GetC(unsigned int cam=0) const
return Center of camera with index cam.
void SetIdentifier(const std::string &identString)
Set the identifier of the Projection such as a name.
ProjectionParametersBase * GetParameterCloneWithAbsolutePose(unsigned int cam=0) const
Allocates memory for parameters base type and returns pointer to it!
RMatrix GetR(unsigned int cam=0) const
return RMatrix of camera with index cam.
Vector3< double > GetAbsoluteC(unsigned int cam=0) const
Return center of camera with index cam.
RMatrix GetAbsoluteR(unsigned int cam=0) const
return RMatrix of camera with index cam.