Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProjectionParametersOrthographic.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 #include "Geometry/ProjectionParametersOrthographic.hh"
26 
27 using namespace std;
28 using namespace BIAS;
30 
31 bool PPO::Distort(HomgPoint2D& point2d) const{
32  BIASERR("no distortion for orthographic projection implemented");
33  BIASABORT;
34  return false;
35 }
36 
37 bool PPO::Undistort(HomgPoint2D& point2d) const{
38  BIASERR("no undistortion for orthographic projection implemented");
39  BIASABORT;
40  return false;
41 }
42 
43 HomgPoint3D PPO::UnProjectToImagePlane(const HomgPoint2D& pos, const double& depth, bool IgnoreDistortion) const{
44  // Distortion is not implemented for orthographic projections!
45  BIASASSERT(IgnoreDistortion);
46  Vector3<double> p(0, 0, 0);
47  p[0] = (pos[0]-principalX_)*dX_ + rayDir_[0]*depth;
48  p[1] = (pos[1]-principalY_)*dY_ + rayDir_[1]*depth;
49  p[2] = rayDir_[2]*depth;
50  HomgPoint3D local(p);
51  return Pose_.LocalToGlobal(local);
52 }
53 
54 HomgPoint2D PPO::ProjectLocal(const Vector3<double> &point, bool IgnoreDistortion) const{
55  // Distortion is not implemented for orthographic projections!
56  BIASASSERT(IgnoreDistortion);
57  HomgPoint2D res;
58  res[2] = 1.0;
59  res[1] = point[2]/rayDir_[2];
60  res[0] = (point[0] - rayDir_[0]*res[1])/dX_+principalX_;
61  res[1] = (point[1] - rayDir_[1]*res[1])/dY_+principalY_;
62  return res;
63 }
64 
65 const bool PPO::DoIntrinsicsDiffer(const PPB* p) const{
66  if(PPB::DoIntrinsicsDiffer(p)){
67  return true;
68  }
69  const PPO* ppo = dynamic_cast<const PPO*>(p);
70  if(ppo == NULL){
71  return true;
72  }
73  if(dX_ != ppo->dX_ || dY_ != ppo->dY_){
74  return true;
75  }
76  if(rayDir_ != ppo->rayDir_){
77  return true;
78  }
79  return false;
80 }
81 
83  HomgPoint2D &p, bool IgnoreDistortion) const{
84  // Distortion is not implemented for orthographic projections!
85  BIASASSERT(IgnoreDistortion);
86  p = ProjectLocal(localP, IgnoreDistortion);
87  p.Homogenize(); //neccessary ?
88  return (p[0] >= 0.0 && p[1] >= 0.0 &&
89  p[0] <= (double)(width_-1) && p[1] <= (double)(height_-1));
90 }
91 
92 
93 #ifdef BIAS_HAVE_XML2
94 int PPO::XMLGetClassName(string &TopLevelTag, double &Version) const{
95  TopLevelTag = "ProjectionParametersOrthographic";
96  Version = 0.1;
97  return 0;
98 }
99 
100 int PPO::XMLOut(const xmlNodePtr Node, XMLIO &XMLObject) const{
101  xmlNodePtr theNode;
102  string TopLevelName;
103  double Version;
104  PPB::XMLGetClassName(TopLevelName, Version);
105  theNode = XMLObject.addChildNode(Node, TopLevelName);
106  XMLObject.addAttribute(theNode, "Version", Version);
107  PPB::XMLOut(theNode, XMLObject);
108  XMLObject.addAttribute(Node, "dX", dX_);
109  XMLObject.addAttribute(Node, "dY", dY_);
110  XMLObject.addAttribute(Node, "rayDirX", rayDir_[0]);
111  XMLObject.addAttribute(Node, "rayDirY", rayDir_[1]);
112  XMLObject.addAttribute(Node, "rayDirZ", rayDir_[2]);
113  return 0;
114 }
115 
116 int PPO::XMLIn(const xmlNodePtr Node, XMLIO &XMLObject){
117  string TopLevelName;
118  double Version;
119  PPB::XMLGetClassName(TopLevelName, Version);
120  xmlNodePtr childNode = XMLObject.getChild(Node, TopLevelName);
121  if(!childNode){
122  BIASERR("Error in XML, tag " << TopLevelName << " not found!");
123  return -1;
124  }
125  if(PPB::XMLIn(childNode, XMLObject) != 0){
126  return -1;
127  }
128  dX_ = XMLObject.getAttributeValueDouble(Node, "dX");
129  dY_ = XMLObject.getAttributeValueDouble(Node, "dY");
130  rayDir_[0] = XMLObject.getAttributeValueDouble(Node, "rayDirX");
131  rayDir_[1] = XMLObject.getAttributeValueDouble(Node, "rayDirY");
132  rayDir_[2] = XMLObject.getAttributeValueDouble(Node, "rayDirZ");
133  return 0;
134 }
135 #endif // BIAS_HAVE_XML2
HomgPoint3D UnProjectToImagePlane(const HomgPoint2D &pos, const double &depth=1.0, bool IgnoreDistortion=true) const
map points from image onto unit diameter image plane in 3D.
void addAttribute(const xmlNodePtr Node, const std::string &AttributeName, bool AttributeValue)
Add an attribute to a node.
Definition: XMLIO.cpp:156
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
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...
Definition: XMLIO.cpp:489
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
Definition: HomgPoint2D.hh:215
virtual int XMLIn(const xmlNodePtr Node, XMLIO &XMLObject)
specialization of XML read function
virtual int XMLOut(const xmlNodePtr Node, XMLIO &XMLObject) const
specialization of XML write function
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
Definition: XMLIO.hh:72
xmlNodePtr addChildNode(const xmlNodePtr ParentNode, const std::string &NewNodeName)
Add a child node to an incoming node with the given name.
Definition: XMLIO.cpp:131
virtual bool Distort(HomgPoint2D &point2d) const
Interface defintion for lens distortion function, implemented by derived classes. ...
virtual int XMLGetClassName(std::string &TopLevelTag, double &Version) const
specialization of XML block name function
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
virtual bool Undistort(HomgPoint2D &point2d) const
Interface defintion for lens undistortion function, implemented by derived classes.
double getAttributeValueDouble(const xmlAttrPtr Attribute) const
Definition: XMLIO.cpp:736
bool DoesPointProjectIntoImageLocal(const Vector3< double > &localP, HomgPoint2D &p, bool IgnoreDistortion=true) const
Checks if 3D point projects into specified image and returns belonging 2D image point.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
virtual HomgPoint2D ProjectLocal(const Vector3< double > &point, bool IgnoreDistortion=true) const
calculates the projection of a point in the camera coordinate system to a pixel in the image plane of...
virtual const bool DoIntrinsicsDiffer(const PPB *p) const