[Jderobot-admin] jderobot-r959 - in trunk/src/libs/geometry: . math progeo
eperdices en jderobot.org
eperdices en jderobot.org
Vie Ago 2 10:42:48 CEST 2013
Author: eperdices
Date: 2013-08-02 10:41:48 +0200 (Fri, 02 Aug 2013)
New Revision: 959
Added:
trunk/src/libs/geometry/progeo/progeo2.cpp
trunk/src/libs/geometry/progeo/progeo3.h
Modified:
trunk/src/libs/geometry/CMakeLists.txt
trunk/src/libs/geometry/math/Line2D.cpp
trunk/src/libs/geometry/math/Line2D.h
Log:
Adaptado progeo para usar directamente Eigen
Modified: trunk/src/libs/geometry/CMakeLists.txt
===================================================================
--- trunk/src/libs/geometry/CMakeLists.txt 2013-08-01 21:48:02 UTC (rev 958)
+++ trunk/src/libs/geometry/CMakeLists.txt 2013-08-02 08:41:48 UTC (rev 959)
@@ -7,7 +7,7 @@
ADD_LIBRARY(geometry_shared SHARED math/matriz3x3.cpp math/matriz4x4.cpp math/plano.cpp math/recta.cpp
math/segmento.cpp math/utils.cpp math/vector2d.cpp math/vector2H.cpp math/vector3.cpp math/vector3H.cpp
math/Line2D.cpp
- collada/colladaparser.cpp collada/color.cpp collada/malla.cpp collada/material.cpp collada/submalla.cpp progeo/progeo.cpp)
+ collada/colladaparser.cpp collada/color.cpp collada/malla.cpp collada/material.cpp collada/submalla.cpp progeo/progeo2.cpp)
target_link_libraries(geometry_shared tinyxml GLU )
@@ -16,7 +16,7 @@
ADD_LIBRARY(geometry_static STATIC math/matriz3x3.cpp math/matriz4x4.cpp math/plano.cpp math/recta.cpp
math/segmento.cpp math/utils.cpp math/vector2d.cpp math/vector2H.cpp math/vector3.cpp math/vector3H.cpp
math/Line2D.cpp
- collada/colladaparser.cpp collada/color.cpp collada/malla.cpp collada/material.cpp collada/submalla.cpp progeo/progeo.cpp)
+ collada/colladaparser.cpp collada/color.cpp collada/malla.cpp collada/material.cpp collada/submalla.cpp progeo/progeo2.cpp)
target_link_libraries(geometry_shared tinyxml GLU )
SET_TARGET_PROPERTIES(geometry_shared geometry_static PROPERTIES OUTPUT_NAME geometry)
Modified: trunk/src/libs/geometry/math/Line2D.cpp
===================================================================
--- trunk/src/libs/geometry/math/Line2D.cpp 2013-08-01 21:48:02 UTC (rev 958)
+++ trunk/src/libs/geometry/math/Line2D.cpp 2013-08-02 08:41:48 UTC (rev 959)
@@ -1,3 +1,26 @@
+/*
+ *
+ * Copyright (C) 1997-2013 JDERobot Developers Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.
+ *
+ * Authors : Alejandro Hernández <ahcorde [at] gmail [dot] com>
+ * Roberto Calvo <rocapal [at] gsyc [dot] urjc [dot] es>
+ * Eduardo Perdices <eperdices [at] gsyc [dot] es>
+ *
+ */
+
#include "Line2D.h"
Line2D::Line2D() {
Modified: trunk/src/libs/geometry/math/Line2D.h
===================================================================
--- trunk/src/libs/geometry/math/Line2D.h 2013-08-01 21:48:02 UTC (rev 958)
+++ trunk/src/libs/geometry/math/Line2D.h 2013-08-02 08:41:48 UTC (rev 959)
@@ -1,4 +1,28 @@
-/*Represents a 2D line with the general equation of the line: Ax+By+C = 0*/
+/*
+ *
+ * Copyright (C) 1997-2013 JDERobot Developers Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.
+ *
+ * Authors : Alejandro Hernández <ahcorde [at] gmail [dot] com>
+ * Roberto Calvo <rocapal [at] gsyc [dot] urjc [dot] es>
+ * Eduardo Perdices <eperdices [at] gsyc [dot] es>
+ *
+ *
+ *
+ * Line2D: Represents a 2D line with the general equation of the line: Ax+By+C = 0
+ */
#ifndef LINE2D_H
#define LINE2D_H
Added: trunk/src/libs/geometry/progeo/progeo2.cpp
===================================================================
--- trunk/src/libs/geometry/progeo/progeo2.cpp (rev 0)
+++ trunk/src/libs/geometry/progeo/progeo2.cpp 2013-08-02 08:41:48 UTC (rev 959)
@@ -0,0 +1,579 @@
+/*
+ *
+ * Copyright (C) 1997-2013 JDERobot Developers Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.
+ *
+ * Authors : Alejandro Hernández <ahcorde [at] gmail [dot] com>
+ * Roberto Calvo <rocapal [at] gsyc [dot] urjc [dot] es>
+ * Eduardo Perdices <eperdices [at] gsyc [dot] es>
+ *
+ */
+
+#include "progeo3.h"
+namespace Progeo {
+
+ Progeo::Progeo()
+ {
+ }
+
+ Progeo::Progeo(Eigen::Vector4d posCamera,
+ Eigen::Matrix3d KMatrix,
+ Eigen::Matrix4d RTMatrix,
+ int width, int height)
+ {
+
+ setPosition(posCamera);
+ setKMatrix(KMatrix);
+ setRTMatrix(RTMatrix);
+ setImageSize(width, height);
+ }
+
+ Progeo::Progeo(std::string filename)
+ {
+ xmlDocPtr doc;
+ xmlNodePtr cur, curAux, curAux_child;
+ doc = xmlParseFile(filename.c_str());
+ if (doc == NULL ) {
+ fprintf(stderr,"Document not parsed successfully. \n");
+ return;
+ }
+
+ cur = xmlDocGetRootElement(doc);
+ if (cur == NULL) {
+ fprintf(stderr,"empty document\n");
+ xmlFreeDoc(doc);
+ return;
+ }
+
+ if (xmlStrcmp(cur->name, (const xmlChar *) "calibration_camera")) {
+ fprintf(stderr,"document of the wrong type, root node != calibration_camera");
+ xmlFreeDoc(doc);
+ return;
+ }
+
+ while (cur != NULL) {
+ if ((!xmlStrcmp(cur->name, (const xmlChar *)"calibration_camera"))) {
+
+ xmlChar *key;
+ curAux = cur->xmlChildrenNode;
+
+ while (curAux != NULL) {
+ /*
+ if ((!xmlStrcmp(curAux->name, (const xmlChar *)"name"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
+
+ char a[((string)key).size()+1];
+ a[key.size()]=0;
+ memcpy(a,key.c_str(),s.size());
+
+ this->name = a;
+ xmlFree(key);
+ }else */if ((!xmlStrcmp(curAux->name, (const xmlChar *)"roll"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
+ this->roll = atof((char*)(char*)key);
+ xmlFree(key);
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"fdistx"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
+ this->fdistx = atof((char*)key);
+ xmlFree(key);
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"fdisty"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
+ this->fdisty = atof((char*)key);
+ xmlFree(key);
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"u0"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
+ this->u0 = atof((char*)key);
+ xmlFree(key);
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"v0"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
+ this->v0 = atof((char*)key);
+ xmlFree(key);
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"skew"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
+ this->skew = atof((char*)key);
+ xmlFree(key);
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"rows"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
+ this->rows = atof((char*)key);
+ xmlFree(key);
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"columns"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
+ this->columns = atof((char*)key);
+ xmlFree(key);
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"position"))) {
+ curAux_child = curAux->xmlChildrenNode;
+
+ while (curAux_child != NULL) {
+ if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"x"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->position(0) = atof((char*)key);
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"y"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->position(1) = atof((char*)key);
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"z"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->position(2) = atof((char*)key);
+ xmlFree(key);
+
+ }
+ curAux_child = curAux_child->next;
+ }
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"foa"))) {
+ curAux_child = curAux->xmlChildrenNode;
+
+ while (curAux_child != NULL) {
+ if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"x"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->foa(0) = atof((char*)key);
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"y"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->foa(1) = atof((char*)key);
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"z"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->foa(2) = atof((char*)key);
+ xmlFree(key);
+
+ }
+ curAux_child = curAux_child->next;
+ }
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"k_matrix"))) {
+ curAux_child = curAux->xmlChildrenNode;
+
+ while (curAux_child != NULL) {
+ if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k11"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k11 = atof((char*)key);
+ K(0,0) = this->k11;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k12"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k12 = atof((char*)key);
+ K(0,1) = this->k12;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k13"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k13 = atof((char*)key);
+ K(0,2) = this->k13;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k14"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k14 = atof((char*)key);
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k21"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k21 = atof((char*)key);
+ K(1,0) = this->k21;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k22"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k22 = atof((char*)key);
+ K(1,1) = this->k22;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k23"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k23 = atof((char*)key);
+ K(1,2) = this->k23;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k24"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k24 = atof((char*)key);
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k31"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k31 = atof((char*)key);
+ K(2,0) = this->k31;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k32"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k32 = atof((char*)key);
+ K(2,1) = this->k32;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k33"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k33 = atof((char*)key);
+ K(2,2) = this->k33;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k34"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k34 = atof((char*)key);
+ xmlFree(key);
+
+ }
+ curAux_child = curAux_child->next;
+ }
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"rt_matrix"))) {
+ curAux_child = curAux->xmlChildrenNode;
+
+ while (curAux_child != NULL) {
+ if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt11"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt11 = atof((char*)key);
+ RT(0,0) = this->rt11;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt12"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt12 = atof((char*)key);
+ RT(0,1) = this->rt12;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt13"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt13 = atof((char*)key);
+ RT(0,2) = this->rt13;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt14"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt14 = atof((char*)key);
+ RT(0,3) = this->rt14;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt21"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt21 = atof((char*)key);
+ RT(1,0) = this->rt21;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt22"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt22 = atof((char*)key);
+ RT(1,1) = this->rt22;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt23"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt23 = atof((char*)key);
+ RT(1,2) = this->rt23;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt24"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt24 = atof((char*)key);
+ RT(1,3) = this->rt24;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt31"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt31 = atof((char*)key);
+ RT(2,0) = this->rt31;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt32"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt32 = atof((char*)key);
+ RT(2,1) = this->rt32;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt33"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt33 = atof((char*)key);
+ RT(2,2) = this->rt33;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt34"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt34 = atof((char*)key);
+ RT(2,3) = this->rt34;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt41"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt41 = atof((char*)key);
+ RT(3,0) = this->rt41;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt42"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt42 = atof((char*)key);
+ RT(3,1) = this->rt42;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt43"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt43 = atof((char*)key);
+ RT(3,2) = this->rt43;
+ xmlFree(key);
+
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt44"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt44 = atof((char*)key);
+ RT(3,3) = this->rt44;
+ xmlFree(key);
+
+ }
+ curAux_child = curAux_child->next;
+ }
+ }
+ curAux = curAux->next;
+ }
+ }
+ cur = cur->next;
+ }
+
+ xmlFreeDoc(doc);
+ return;
+}
+
+void Progeo::display_camerainfo() {
+ printf("------------------------------------------------------\n");
+ printf("Camera %s\n\n", this->name.c_str());
+ printf(" Position: (X,Y,Z,H)=(%.1f,%.1f,%.1f,%.1f)\n", position(0),
+ position(1),
+ position(2),
+ position(3));
+ printf(" Focus of Attention: (x,y,z,h)=(%.1f,%.1f,%.1f,%.1f)\n\n", foa(0),
+ foa(1),
+ foa(2),
+ foa(3));
+ printf(" Focus DistanceX(vertical): %.1f mm\n",fdistx);
+ printf(" Focus DistanceY(horizontal): %.1f mm\n",fdisty);
+
+ printf(" Skew: %.5f \n",skew);
+ printf(" Optical Center: (x,y)=(%.1f,%.1f)\n\n",u0,v0);
+
+ // std::cout << "\t\tK Matrix:\t" << k11 << " " << k12 << " " << k13 << " " << k14 << std::endl;
+ // std::cout << "\t\t\t" << k21 << " " << k22 << " " << k23 << " " << k24 << std::endl;
+ // std::cout << "\t\t\t" << k31 << " " << k32 << " " << k33 << " " << k34 << std::endl;
+ //std::cout << "\t\t\t\t" << k41 << " " << k42 << " " << k43 << " " << k44 << std::endl;
+
+ std::cout << "K Matrix: \n" << K << std::endl;
+
+ // std::cout << "\t\tR&T Matrix:\t" << rt11 << " " << rt12 << " " << rt13 << " " << rt14 << std::endl;
+ // std::cout << "\t\t\t" << rt21 << " " << rt22 << " " << rt23 << " " << rt24 << std::endl;
+ // std::cout << "\t\t\t" << rt31 << " " << rt32 << " " << rt33 << " " << rt34 << std::endl;
+ // std::cout << "\t\t\t" << rt41 << " " << rt42 << " " << rt43 << " " << rt44 << std::endl;
+
+ std::cout <<" R&T Matrix:\n"<< RT << std::endl;
+
+ printf("------------------------------------------------------\n");
+}
+
+int Progeo::project(Eigen::Vector4d in, Eigen::Vector3d &out)
+/* returns -1 if the point lies behind the camera,
+ returns 1 if "in" 3Dpoint projects into a 2D finite point,
+ 0 otherwise */
+{
+ Eigen::Vector4d a;
+ a = RT*in;
+
+ out = K*a.head(3);
+
+ // optical 2 graphics
+ out(0) = out(0)/out(3);
+ out(1) = out(1)/out(3);
+ out(2) = 1.0;
+
+ double aux = out(0);
+ out(0) = out(1);
+ out(1) = this->rows-1-aux;
+
+ if (out(3)!=0.) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+void Progeo::backproject(Eigen::Vector3d point, Eigen::Vector4d& pro)
+{
+
+ //GRAPHIC_TO_OPTICAL
+ int opX = this->rows -1 -point(1);
+ int opY = point(0);
+
+ Eigen::Matrix3d ik;
+ ik = K;
+ ik = ik.inverse();
+
+ Eigen::Vector3d Pi(opX*this->k11/point(3), opY*this->k11/point(3),this->k11);
+
+ Eigen::Vector3d a;
+ a = ik*Pi;
+
+ Eigen::Vector4d aH;
+ aH(0) = a(0);
+ aH(1) = a(1);
+ aH(2) = a(3);
+ aH(3) = 1.0;
+
+ Eigen::Matrix4d RT2;
+ RT2 = RT;
+
+ RT2(0, 3) = .0;
+ RT2(1, 3) = .0;
+ RT2(2, 3) = .0;
+ RT2(3, 3) = 1.0;
+
+
+ Eigen::Vector4d b;
+
+ b = RT2*aH;
+
+ Eigen::Matrix4d Translate;
+ Translate.setIdentity();
+ Translate(0, 3) = position(0);
+ Translate(1, 3) = position(1);
+ Translate(2, 3) = position(2);
+
+ b = Translate*b;
+
+ pro(0) = b(0)/b(3);
+ pro(1) = b(1)/b(3);
+ pro(2) = b(2)/b(3);
+ pro(3) = b(3);
+}
+
+ void Progeo::setPosition (Eigen::Vector4d pos)
+ {
+ position = pos;
+ }
+
+ void Progeo::setKMatrix (Eigen::Matrix3d KMatrix)
+ {
+ K = KMatrix;
+ fdistx = K(0,0);
+ fdisty = K(1,1);
+ u0 = K(0,2);
+ v0 = K(1,2);
+ }
+
+ void Progeo::setRTMatrix (Eigen::Matrix4d RTMatrix)
+ {
+ RT = RTMatrix;
+ }
+
+ void Progeo::setImageSize (int width, int height)
+ {
+ rows = height;
+ columns = width;
+ }
+
+ void Progeo::update_camera_matrix()
+ {}
+//{
+// double rc11,rc12,rc13,rc21,rc22,rc23,rc31,rc32,rc33;
+// double rab11,rab12,rab13,rab21,rab22,rab23,rab31,rab32,rab33;
+// double r;
+// /* a very small value but not infinite!! */
+// double SMALL=0.0001;
+// double t;
+// double ux,uy,uz,vx,vy,vz,wx,wy,wz;
+
+// camera->foa.H=1.;
+// camera->position.H=1;
+
+// /* Orientation model: focus of attention + roll */
+// rab31=camera->foa.X-camera->position.X;
+// rab32=camera->foa.Y-camera->position.Y;
+// rab33=camera->foa.Z-camera->position.Z;
+// r=(double)sqrt((double)(rab31*rab31+rab32*rab32+rab33*rab33));
+// rab31=rab31/r; rab32=rab32/r; rab33=rab33/r;
+
+// /* Second method:*/
+// wx=rab31;
+// wy=rab32;
+// wz=rab33;
+// t = atan2(-wx,wy);
+// vx=(double)cos(t);
+// vy=(double)sin(t);
+// vz=0.;
+// ux=vy*wz-wy*vz;
+// uy=-vx*wz+wx*vz;
+// uz=vx*wy-wx*vy;
+// if (uz<0.)
+// {vx=-vx; vy=-vy; vz=-vz;
+// ux=-ux; uy=-uy; uz=-uz;}
+// rab11=ux;
+// rab12=uy;
+// rab13=uz;
+// rab21=vx;
+// rab22=vy;
+// rab23=vz;
+
+// /* First method:
+// * this was commented in the previous version. only else branch of this if was valid. test it!!*
+
+// if ((rab31<SMALL) && (rab31>-SMALL) && (rab32<SMALL) && (rab32>-SMALL))
+// * u3 = OZ or FA=camera position *
+// {
+// rab11=1.; rab12=0.; rab13=0.;
+// rab21=0.; rab22=1.; rab23=0.;
+// rab31=0.; rab32=0.; rab33=1.;
+// }else{
+// rab11=rab31*rab33; rab12=rab32*rab33; rab13=-rab31*rab31-rab32*rab32;
+// r=(double)sqrt((double)(rab11*rab11+rab12*rab12+rab13*rab13));
+// rab11=rab11/r; rab12=rab12/r; rab13=rab13/r;
+// if (rab13<0.) {rab11=-rab11; rab12=-rab12; rab13=-rab13;}
+
+// rab21=rab32*rab13-rab12*rab33; rab22=rab11*rab33-rab31*rab13; rab23=rab31*rab12-rab11*rab32;
+// r=(double)sqrt((double)(rab21*rab21+rab22*rab22+rab23*rab23));
+// rab21=rab21/r; rab22=rab22/r; rab23=rab23/r;
+// }
+// */
+
+// rc11=cos(camera->roll); rc12=sin(camera->roll); rc13=0.;
+// rc21=-sin(camera->roll); rc22=cos(camera->roll); rc23=0.;
+// rc31=0.; rc32=0.; rc33=1.;
+
+// camera->rt11=rc11*rab11+rc12*rab21+rc13*rab31;
+// camera->rt12=rc11*rab12+rc12*rab22+rc13*rab32;
+// camera->rt13=rc11*rab13+rc12*rab23+rc13*rab33;
+// camera->rt21=rc21*rab11+rc22*rab21+rc23*rab31;
+// camera->rt22=rc21*rab12+rc22*rab22+rc23*rab32;
+// camera->rt23=rc21*rab13+rc22*rab23+rc23*rab33;
+// camera->rt31=rc31*rab11+rc32*rab21+rc33*rab31;
+// camera->rt32=rc31*rab12+rc32*rab22+rc33*rab32;
+// camera->rt33=rc31*rab13+rc32*rab23+rc33*rab33;
+
+// camera->rt14=-camera->position.X*camera->rt11-camera->position.Y*camera->rt12-camera->position.Z*camera->rt13;
+// camera->rt24=-camera->position.X*camera->rt21-camera->position.Y*camera->rt22-camera->position.Z*camera->rt23;
+// camera->rt34=-camera->position.X*camera->rt31-camera->position.Y*camera->rt32-camera->position.Z*camera->rt33;
+// camera->rt41=0.;
+// camera->rt42=0.;
+// camera->rt43=0.;
+// camera->rt44=1.;
+
+// /* intrinsics parameters */
+// camera->k11=camera->fdistx; camera->k12=camera->skew*camera->fdisty; camera->k13=camera->u0; camera->k14=0.;
+// camera->k21=0.; camera->k22=camera->fdisty; camera->k23=camera->v0; camera->k24=0.;
+// camera->k31=0.; camera->k32=0.; camera->k33=1.; camera->k34=0.;
+
+// if (debug==1) printf("Camera %s Located at (%.f,%.f,%.f)\n",camera->name,camera->position.X,camera->position.Y,camera->position.Z);
+// if (debug==1) printf("Camera %s Orientation: pointing towards FocusOfAtention (%.f,%.f,%.f), roll (%.f)\n",camera->name,camera->foa.X,camera->foa.Y,camera->foa.Z,camera->roll*360./(2*PI));
+// if (debug==1) printf("Camera %s fx= %.5f fy= %.5f skew= %.5f y0=%d x0=%d\n",camera->name, camera->fdistx, camera->fdisty, camera->skew,(int)camera->v0,(int)camera->u0);
+// if (debug==1) printf("Camera %s K matrix\n %.3f %.1f %.1f %.1f\n %.1f %.3f %.1f %.1f\n %.1f %.1f %.1f %.1f\n",camera->name,camera->k11,camera->k12,camera->k13,camera->k14,camera->k21,camera->k22,camera->k23,camera->k24,camera->k31,camera->k32,camera->k33,camera->k34);
+// if (debug==1) printf("Camera %s RT matrix\n %.1f %.1f %.1f %.1f\n %.1f %.1f %.1f %.1f\n %.1f %.1f %.1f %.1f\n %.1f %.1f %.1f %.1f\n",camera->name,camera->rt11,camera->rt12,camera->rt13,camera->rt14,camera->rt21,camera->rt22,camera->rt23,camera->rt24,camera->rt31,camera->rt32,camera->rt33,camera->rt34,camera->rt41,camera->rt42,camera->rt43,camera->rt44);
+//}
+}
Added: trunk/src/libs/geometry/progeo/progeo3.h
===================================================================
--- trunk/src/libs/geometry/progeo/progeo3.h (rev 0)
+++ trunk/src/libs/geometry/progeo/progeo3.h 2013-08-02 08:41:48 UTC (rev 959)
@@ -0,0 +1,122 @@
+/*
+ *
+ * Copyright (C) 1997-2013 JDERobot Developers Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.
+ *
+ * Authors : Alejandro Hernández <ahcorde [at] gmail [dot] com>
+ * Roberto Calvo <rocapal [at] gsyc [dot] urjc [dot] es>
+ * Eduardo Perdices <eperdices [at] gsyc [dot] es>
+ *
+ */
+
+#ifndef PROGEO3_H
+#define PROGEO3_H
+
+#define EIGEN_DONT_ALIGN_STATICALLY True
+
+#include <iostream>
+#include <eigen3/Eigen/Dense>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/*xml*/
+#include <libxml/parser.h>
+#include <libxml/xmlreader.h>
+#include <libxml/xpath.h>
+#include <libxml/tree.h>
+
+#define PI 3.141592654
+#define BIGNUM 1.0e4
+
+/* geometric distances */
+#define DIST2D(p1,p2) sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y))
+#define DIST3D(p1,p2) sqrt((p1.X-p2.X)*(p1.X-p2.X)+(p1.Y-p2.Y)*(p1.Y-p2.Y)+(p1.Z-p2.Z)*(p1.Z-p2.Z))
+
+namespace Progeo {
+
+class Progeo
+{
+
+public:
+
+ Progeo();
+ Progeo(std::string filename);
+
+ Progeo(Eigen::Vector4d posCamera,
+ Eigen::Matrix3d KMatrix,
+ Eigen::Matrix4d RTMatrix,
+ int width, int height);
+
+ void setPosition (Eigen::Vector4d pos);
+ void setKMatrix (Eigen::Matrix3d KMatrix);
+ void setRTMatrix (Eigen::Matrix4d RTMatrix);
+ void setImageSize (int width, int height);
+
+ void display_camerainfo();
+ void backproject(Eigen::Vector3d, Eigen::Vector4d& pro);
+ int project(Eigen::Vector4d in, Eigen::Vector3d &out);
+ void update_camera_matrix();
+
+
+
+private:
+
+ /* camera 3d position in mm */
+ Eigen::Vector4d position;
+
+ /* camera 3d focus of attention in mm */
+ Eigen::Vector4d foa;
+
+ /* top right and bottom left points */
+ Eigen::Vector3d tr, bl;
+
+ /* camera roll position angle in rads */
+ float roll;
+
+ /* focus x distance in mm*/
+ float fdistx;
+ float fdisty;
+
+ /* pixels */
+ float u0,v0;
+
+ /*angle between the x and y pixel axes in rads*/
+ float skew
+
+ /* image height in pixels */;
+ int rows;
+
+ /* image width in pixels */
+ int columns;
+
+ /* camera K matrix */
+ float k11, k12, k13, k14, k21, k22, k23, k24, k31, k32, k33, k34;
+ Eigen::Matrix3d K;
+
+ /* camera rotation + translation matrix */
+ float rt11, rt12, rt13, rt14, rt21, rt22, rt23, rt24, rt31, rt32, rt33, rt34, rt41, rt42, rt43, rt44;
+ Eigen::Matrix4d RT;
+
+ /* distortion parameters */
+ float d1,d2,d3,d4,d5,d6;
+ float dx,dy;
+
+ /* name */
+ std::string name;
+};
+}
+
+#endif
More information about the Jderobot-admin
mailing list