26 #include "Geometry/ProjectionParametersBufferedRay.hh"
27 #include <Base/Common/CompareFloatingPoint.hh>
28 #include <Geometry/ProjectionParametersFactory.hh>
29 #include <MathAlgo/PolynomialSolve.hh>
30 #include <MathAlgo/Minpack.hh>
43 unprojectMappingIgnoreDistortion_ = NULL;
44 unprojectMappingDistortion_ = NULL;
46 if(!UpdateFromProjection_())
48 BIASERR(
"ProjectionParameters are NULL");
57 ppb_ = ppbr.ppb_->
Clone();
60 unprojectMappingIgnoreDistortion_ = NULL;
61 unprojectMappingDistortion_ = NULL;
63 if(!UpdateProjection_())
65 BIASERR(
"ProjectionParameters are NULL");
95 bool IgnoreDistortion)
const
102 bool IgnoreDistortion)
const
113 BIASERR(
"negative index: "<<pos[0]);
115 BIASERR(
"negative index: "<<pos[1]);
116 if((
int)(pos[0]+0.5) >= (
int)
width_)
117 BIASERR(
"index out of bound: "<<(
int)(pos[0]+0.5));
118 if((
int)(pos[1]+0.5) >= (
int)
height_)
119 BIASERR(
"index out of bound: "<<(
int)(pos[1]+0.5));
123 direction = unprojectMappingIgnoreDistortion_[(int)(pos[0]+0.5)+
124 ((int)(pos[1]+0.5))*width_];
128 direction = unprojectMappingDistortion_[(int)(pos[0]+0.5)+((int)(pos[1]+0.5))*width_];
135 bool IgnoreDistortion)
const
143 #ifdef BIAS_HAVE_XML2
148 TopLevelTag =
"ProjectionParametersBufferedRay";
165 xmlNodePtr childNode = XMLObject.
addChildNode(Node,
"WrappedProjection");
168 theNode = XMLObject.
addChildNode(childNode, TopLevelName);
170 ppb_->
XMLOut(theNode, XMLObject);
185 xmlNodePtr childNode = XMLObject.
getChild(Node, TopLevelName);
187 BIASERR(
"Error in XML, tag " << TopLevelName <<
" not found!");
193 if (ppb_)
delete ppb_;
194 childNode = XMLObject.
getChild(Node,
"WrappedProjection");
199 string nodename = XMLObject.
getNodeName(childNode);
200 ppb_ = factory.
Create(nodename);
201 if (ppb_->
XMLIn(childNode, XMLObject) != 0)
return -1;
208 if(!UpdateProjection_())
210 BIASERR(
"ProjectionParameters are NULL");
216 #endif //BIAS_HAVE_XML2
218 const bool ProjectionParametersBufferedRay::UpdateProjection_()
220 if (ppb_ == NULL)
return false;
244 return UpdateBuffer_();
247 const bool ProjectionParametersBufferedRay::UpdateFromProjection_()
249 if (ppb_ == NULL)
return false;
264 return UpdateBuffer_();
267 const bool ProjectionParametersBufferedRay::UpdateBuffer_()
269 if (ppb_ == NULL)
return false;
274 if (unprojectMappingIgnoreDistortion_)
275 delete[] unprojectMappingIgnoreDistortion_;
276 if (unprojectMappingDistortion_)
277 delete[] unprojectMappingDistortion_;
280 for (
unsigned int y = 0; y <
height_; y++)
282 for (
unsigned int x = 0; x <
width_; x++)
286 rx = (x-halfX)/halfX;
287 ry = (y-halfY)/halfY;
288 r = sqrt(rx*rx+ry*ry);
298 BIASASSERT(fabs(tmp.
Length() - 1.0) <= std::numeric_limits<double>::epsilon() ||
299 fabs(tmp.
Length()) <= std::numeric_limits<double>::epsilon())
300 unprojectMappingIgnoreDistortion_[x+y*width_] = tmp;
302 BIASASSERT(fabs(tmp.
Length() - 1.0) <= std::numeric_limits<double>::epsilon() ||
303 fabs(tmp.
Length()) <= std::numeric_limits<double>::epsilon())
304 unprojectMappingDistortion_[x+y*width_] = tmp;
308 unprojectMappingIgnoreDistortion_[x+y*
width_] = zero;
309 unprojectMappingDistortion_[x+y*
width_] = zero;
virtual BIAS::Vector3< double > GetC() const
Get projection center.
void addAttribute(const xmlNodePtr Node, const std::string &AttributeName, bool AttributeValue)
Add an attribute to a node.
virtual void SetCov(const Matrix< POSE_TYPE > &Cov)
Set pose covariance matrix with respect to C, Q.
This class maps image coords to rays which are buffered for fast lookup.
virtual void SetPrincipal(const double x, const double y)
Set principal point (in pixels relative to top left corner).
virtual HomgPoint2D ProjectLocal(const Vector3< double > &point, bool IgnoreDistortion=false) const =0
calculates the projection of a point in the local camera coordinate system to a pixel in the image pl...
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
specialization of XML block name function
double Length() const
returns the Euclidean Length of the Vector
virtual int XMLOut(const xmlNodePtr Node, XMLIO &XMLObject) const
Specialization of XML write function.
ProjectionParametersBase * Create(const std::string &className)
Creates a projection parameters object by a class name.
virtual int GetPrincipal(double &PrincipalX, double &PrincipalY) const
Get principal point (in pixels relative to top left corner).
virtual void SetIdentifier(std::string name)
Set the identification string.
virtual BIAS::Matrix< POSE_TYPE > GetCov() const
Return pose covariance as 7x7 matrix with respect to C, Q.
xmlNodePtr getChild(const xmlNodePtr ParentNode, const std::string &ChildName)
Get a child of a Parent node by specifying the childs name, NULL is returned if the ParentNode has no...
virtual void SetImageSize(const unsigned int w, const unsigned int h)
Set image dimensions (in pixels).
virtual ProjectionParametersBase * Clone() const =0
Covariant virtual copy constructor used in BIAS::Projection.
virtual std::string GetIdentifier() const
virtual const bool DoIntrinsicsDiffer(const ProjectionParametersBase *p) const
virtual const bool DoIntrinsicsDiffer(const ProjectionParametersBase *p) const
ProjectionParametersBufferedRay(const ProjectionParametersBase *ppb)
virtual int XMLOut(const xmlNodePtr Node, XMLIO &XMLObject) const
specialization of XML write function
bool getAttributeValueBool(const xmlAttrPtr Attribute) const
Get the value of a given Attribute, with type-cast overloads for different attribute types...
virtual bool Distort(BIAS::HomgPoint2D &point2d) const
Interface defintion for lens distortion function, implemented by derived classes. ...
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.
virtual bool Distort(BIAS::HomgPoint2D &point2d) const =0
Interface defintion for lens distortion function, implemented by derived classes. ...
virtual int XMLIn(const xmlNodePtr Node, XMLIO &XMLObject)
Specialization of XML read function.
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 SetPose(const BIAS::Pose pose)
Set pose from pose object.
std::string identifier_
Multifunctional identifier.
virtual void SetQ(const BIAS::Quaternion< double > &Q)
Set orientation from unit quaternion Q.
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
xmlNodePtr addChildNode(const xmlNodePtr ParentNode, const std::string &NewNodeName)
Add a child node to an incoming node with the given name.
virtual bool PoseValid() const
Check if current pose is valid.
virtual double GetAspectratio() const
Return aspectratio (i.e.
unsigned int height_
height of image in pixels
xmlNodePtr getFirstChild(const xmlNodePtr ParentNode)
Get the first child of a given parent, or NULL for no childs.
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool ignoreDistortion=false) const =0
Calculates the view ray, which belongs to the given position on the image plane, in local coordinates...
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
virtual bool Undistort(BIAS::HomgPoint2D &point2d) const
Interface defintion for lens undistortion function, implemented by derived classes.
unsigned int width_
width of image in pixels
std::string getNodeName(const xmlNodePtr Node) const
Get the name of a given Node.
double principalX_
principal point in pixel coordinates (one for all zoom settings)
double aspectratio_
aspect ratio of the camera CCD
virtual void SetAspectratio(const double AspectRatio)
Set CCD aspect ratio (i.e.
virtual void SetQC(const BIAS::Quaternion< double > &Q, const BIAS::Vector3< double > &C)
Set pose from unit quaternion Q and projection center C.
virtual int XMLIn(const xmlNodePtr Node, XMLIO &XMLObject)
specialization of XML read function
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
Specialization of XML block name function.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual BIAS::Quaternion< double > GetQ() const
Get orientation as unit quaternion.
virtual const BIAS::Pose & GetPose() const
Return complete pose object.
virtual bool Undistort(BIAS::HomgPoint2D &point2d) const =0
Interface defintion for lens undistortion function, implemented by derived classes.
virtual void SetC(const BIAS::Vector3< double > &C)
Set projection center.
virtual void UnProjectLocal(const HomgPoint2D &pos, Vector3< double > &origin, Vector3< double > &direction, bool IgnoreDistortion=false) const
Calculates the view ray, which belongs to the given position on the image plane, in local coordinates...
bool QValid_
validity flag for orientation and position
class BIASGeometryBase_EXPORT HomgPoint2D
virtual HomgPoint3D UnProjectToImagePlane(const HomgPoint2D &pos, const double &depth=1.0, bool IgnoreDistortion=false) const =0
map points from image onto unit diameter image plane in 3D.
virtual Vector3< double > UnProjectToPointLocal(const HomgPoint2D &pos, const double &depth, bool IgnoreDistortion=false) const
calculates a 3D point in the local camera coordinate system, which belongs to the image position pos ...
virtual void InvalidatePose()
Invalidate currently set pose.