[Jderobot-admin] jderobot-r930 - in trunk/src/libs/geometry: collada progeo
ahcorde en jderobot.org
ahcorde en jderobot.org
Mie Jun 5 18:11:14 CEST 2013
Author: ahcorde
Date: 2013-06-05 18:10:12 +0200 (Wed, 05 Jun 2013)
New Revision: 930
Modified:
trunk/src/libs/geometry/collada/colladaparser.cpp
trunk/src/libs/geometry/collada/colladaparser.h
trunk/src/libs/geometry/collada/color.cpp
trunk/src/libs/geometry/collada/color.h
trunk/src/libs/geometry/collada/malla.cpp
trunk/src/libs/geometry/collada/malla.h
trunk/src/libs/geometry/collada/material.cpp
trunk/src/libs/geometry/collada/material.h
trunk/src/libs/geometry/collada/submalla.cpp
trunk/src/libs/geometry/collada/submalla.h
trunk/src/libs/geometry/progeo/progeo.cpp
trunk/src/libs/geometry/progeo/progeo.h
Log:
[ahcorde] A?\195?\177ado los namespaces
math, files_3D y progeo
Modified: trunk/src/libs/geometry/collada/colladaparser.cpp
===================================================================
--- trunk/src/libs/geometry/collada/colladaparser.cpp 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/colladaparser.cpp 2013-06-05 16:10:12 UTC (rev 930)
@@ -1,1336 +1,1338 @@
#include "colladaparser.h"
+namespace files_3D {
-ColladaParser::ColladaParser(std::string filename)
-{
- TiXmlDocument xmlDoc;
+ ColladaParser::ColladaParser(std::string filename)
+ {
+ TiXmlDocument xmlDoc;
- this->filename = filename;
+ this->filename = filename;
- std::cout << "Loading " << filename << std::endl;
+ std::cout << "Loading " << filename << std::endl;
- if (!xmlDoc.LoadFile(this->filename)){
- std::cout << "Imposible to load collada file" << std::endl;
- return;
+ if (!xmlDoc.LoadFile(this->filename)){
+ std::cout << "Imposible to load collada file" << std::endl;
+ return;
+ }
+ this->colladaXml = xmlDoc.FirstChildElement("COLLADA");
+ if (!this->colladaXml){
+ std::cout << "Falta la etiqueta Collada" << std::endl;
+ return;
+ }
+ if (std::string(this->colladaXml->Attribute("version")) != "1.4.0" &&
+ std::string(this->colladaXml->Attribute("version")) != "1.4.1"){
+ std::cout << "Invalid version. Must be version 1.4.0 or 1.4.1" << std::endl;
+ return;
+
+ }
+ TiXmlElement *assetXml = this->colladaXml->FirstChildElement("asset");
+ if (assetXml)
+ {
+ TiXmlElement *unitXml = assetXml->FirstChildElement("unit");
+ if (unitXml && unitXml->Attribute("meter")){
+ this->meter = math::parseFloat(unitXml->Attribute("meter"));
+ std::cout << "meter: " << this->meter << std::endl;
+ }
+ }
+ mesh = new Malla();
+ mesh->setPath(this->filename);
+
+ loadScene(mesh);
}
- this->colladaXml = xmlDoc.FirstChildElement("COLLADA");
- if (!this->colladaXml){
- std::cout << "Falta la etiqueta Collada" << std::endl;
- return;
- }
- if (std::string(this->colladaXml->Attribute("version")) != "1.4.0" &&
- std::string(this->colladaXml->Attribute("version")) != "1.4.1"){
- std::cout << "Invalid version. Must be version 1.4.0 or 1.4.1" << std::endl;
- return;
- }
- TiXmlElement *assetXml = this->colladaXml->FirstChildElement("asset");
- if (assetXml)
+ int ite = 0;
+
+ void ColladaParser::draw()
{
- TiXmlElement *unitXml = assetXml->FirstChildElement("unit");
- if (unitXml && unitXml->Attribute("meter")){
- this->meter = math::parseFloat(unitXml->Attribute("meter"));
- std::cout << "meter: " << this->meter << std::endl;
- }
- }
- mesh = new Malla();
- mesh->setPath(this->filename);
- loadScene(mesh);
-}
+ if(ite==0){
+ ite++;
+ std::vector<std::string> listaNombres;
+ std::vector<unsigned int> listaTexturas;
+ for(int i = 0; i < this->mesh->getSubMeshCount();i++){
+ SubMalla* submalla = this->mesh->getSubMesh(i);
-int ite = 0;
+ int indiceMaterial = submalla->getMaterialIndex();
-void ColladaParser::draw()
-{
+ if(indiceMaterial==-1){
+ continue;
+ }
- if(ite==0){
- ite++;
- std::vector<std::string> listaNombres;
- std::vector<unsigned int> listaTexturas;
- for(int i = 0; i < this->mesh->getSubMeshCount();i++){
- SubMalla* submalla = this->mesh->getSubMesh(i);
+ Material* material = this->mesh->getMaterial(indiceMaterial);
- int indiceMaterial = submalla->getMaterialIndex();
+ std::string name = material->texImage;
+ bool encontrado =false;
+ int indiceEncontrado = 0;
+ for(int j = 0; j < listaNombres.size(); j++){
+ if( listaNombres[j].compare(name)==0 ){
+ encontrado = true;
+ indiceEncontrado =j;
+ break;
+ }
+ }
- if(indiceMaterial==-1){
- continue;
- }
+ if(!encontrado){
+ listaNombres.push_back(name);
- Material* material = this->mesh->getMaterial(indiceMaterial);
+ unsigned int m_nID;
+ glGenTextures(1, &m_nID);
+ glBindTexture(GL_TEXTURE_2D, m_nID);
- std::string name = material->texImage;
- bool encontrado =false;
- int indiceEncontrado = 0;
- for(int j = 0; j < listaNombres.size(); j++){
- if( listaNombres[j].compare(name)==0 ){
- encontrado = true;
- indiceEncontrado =j;
- break;
+ cv::Mat image = material->getImage();
+
+ gluBuild2DMipmaps( GL_TEXTURE_2D, 3,
+ image.cols,
+ image.rows,
+ GL_BGR, GL_UNSIGNED_BYTE,
+ image.data );
+ listaTexturas.push_back(m_nID);
+ material->idTextura = m_nID;
+ }else{
+ material->idTextura = listaTexturas[indiceEncontrado];
}
}
+ }
- if(!encontrado){
- listaNombres.push_back(name);
+ for(int i = 0; i < this->mesh->getSubMeshCount();i++){
- unsigned int m_nID;
- glGenTextures(1, &m_nID);
- glBindTexture(GL_TEXTURE_2D, m_nID);
+ SubMalla* submalla = this->mesh->getSubMesh(i);
- cv::Mat image = material->getImage();
+ int indiceMaterial = submalla->getMaterialIndex();
+ Material* material = this->mesh->getMaterial(indiceMaterial);
- gluBuild2DMipmaps( GL_TEXTURE_2D, 3,
- image.cols,
- image.rows,
- GL_BGR, GL_UNSIGNED_BYTE,
- image.data );
- listaTexturas.push_back(m_nID);
- material->idTextura = m_nID;
+ if(submalla->getTexCoordCount()>0){
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, material->idTextura);
+ }
+
+
+ Color c;
+ if(indiceMaterial>0){
+ c = material->getDiffuse();
}else{
- material->idTextura = listaTexturas[indiceEncontrado];
+ c.r = 0.7;
+ c.g = 0.7;
+ c.b = 0.7;
+ c.a = 1;
}
- }
- }
- for(int i = 0; i < this->mesh->getSubMeshCount();i++){
- SubMalla* submalla = this->mesh->getSubMesh(i);
- int indiceMaterial = submalla->getMaterialIndex();
- Material* material = this->mesh->getMaterial(indiceMaterial);
+ if(submalla->getTexCoordCount()==0){
+ glColor3f(c.r, c.g, c.b);
- if(submalla->getTexCoordCount()>0){
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, material->idTextura);
- }
+ }
+ glPointSize(5.0);
+ glBegin(GL_POLYGON);
+ for(int k = 0; k < submalla->getVertexCount(); k++){
- Color c;
- if(indiceMaterial>0){
- c = material->getDiffuse();
- }else{
- c.r = 0.7;
- c.g = 0.7;
- c.b = 0.7;
- c.a = 1;
- }
+ if(k%3==0)
+ glBegin(GL_POLYGON);
+ unsigned int indice =submalla->getIndex(k);
+ math::Vector3 v= submalla->getVertex(indice);
+ math::Vector3 normals= submalla->getNormal(indice);
+ glNormal3f(normals.vector(0), normals.vector(1), normals.vector(2));
- if(submalla->getTexCoordCount()==0){
- glColor3f(c.r, c.g, c.b);
+ if(submalla->getTexCoordCount()>0){
+ math::Vector2d text= submalla->getTexCoord(indice);
+ glTexCoord2f(text.vector(0), text.vector(1));
- }
+ }
+ glVertex3f(v.vector(0), v.vector(1), v.vector(2));
- glPointSize(5.0);
- glBegin(GL_POLYGON);
- for(int k = 0; k < submalla->getVertexCount(); k++){
+ if(k%3==2)
+ glEnd();
- if(k%3==0)
- glBegin(GL_POLYGON);
+ }
- unsigned int indice =submalla->getIndex(k);
+ glEnd();
- math::Vector3 v= submalla->getVertex(indice);
- math::Vector3 normals= submalla->getNormal(indice);
- glNormal3f(normals.vector(0), normals.vector(1), normals.vector(2));
-
if(submalla->getTexCoordCount()>0){
- math::Vector2d text= submalla->getTexCoord(indice);
- glTexCoord2f(text.vector(0), text.vector(1));
-
+ glDisable(GL_TEXTURE_2D);
}
- glVertex3f(v.vector(0), v.vector(1), v.vector(2));
- if(k%3==2)
- glEnd();
-
}
-
- glEnd();
-
- if(submalla->getTexCoordCount()>0){
- glDisable(GL_TEXTURE_2D);
- }
-
}
-}
-/////////////////////////////////////////////////
-void ColladaParser::loadScene(Malla *_mesh)
-{
- TiXmlElement *sceneXml = this->colladaXml->FirstChildElement("scene");
- std::string sceneURL =
- sceneXml->FirstChildElement("instance_visual_scene")->Attribute("url");
+ /////////////////////////////////////////////////
+ void ColladaParser::loadScene(Malla *_mesh)
+ {
+ TiXmlElement *sceneXml = this->colladaXml->FirstChildElement("scene");
+ std::string sceneURL =
+ sceneXml->FirstChildElement("instance_visual_scene")->Attribute("url");
- TiXmlElement *visSceneXml = this->getElementId("visual_scene", sceneURL);
+ TiXmlElement *visSceneXml = this->getElementId("visual_scene", sceneURL);
- if (!visSceneXml)
- {
- std::cout << "Unable to find visual_scene id ='" << sceneURL << "'\n";
- return;
- }
+ if (!visSceneXml)
+ {
+ std::cout << "Unable to find visual_scene id ='" << sceneURL << "'\n";
+ return;
+ }
- TiXmlElement *nodeXml = visSceneXml->FirstChildElement("node");
- while (nodeXml)
- {
- this->loadNode(nodeXml, _mesh, math::Matriz4x4::IDENTITY);
- nodeXml = nodeXml->NextSiblingElement("node");
- }
-}
+ TiXmlElement *nodeXml = visSceneXml->FirstChildElement("node");
+ while (nodeXml)
+ {
+ this->loadNode(nodeXml, _mesh, math::Matriz4x4::IDENTITY);
+ nodeXml = nodeXml->NextSiblingElement("node");
+ }
+ }
-/////////////////////////////////////////////////
-TiXmlElement *ColladaParser::getElementId(const std::string &_name,
- const std::string &_id)
-{
- return this->getElementId(this->colladaXml, _name, _id);
-}
-
-/////////////////////////////////////////////////
-TiXmlElement *ColladaParser::getElementId(TiXmlElement *_parent,
- const std::string &_name,
- const std::string &_id)
-{
- std::string id = _id;
- if (id.length() > 0 && id[0] == '#')
- id.erase(0, 1);
-
- if ((id.empty() && _parent->Value() == _name) ||
- (_parent->Attribute("id") && _parent->Attribute("id") == id) ||
- (_parent->Attribute("sid") && _parent->Attribute("sid") == id))
- {
- return _parent;
- }
-
- TiXmlElement *elem = _parent->FirstChildElement();
- while (elem)
- {
- TiXmlElement *result = this->getElementId(elem, _name, _id);
- if (result)
+ /////////////////////////////////////////////////
+ TiXmlElement *ColladaParser::getElementId(const std::string &_name,
+ const std::string &_id)
{
- return result;
+ return this->getElementId(this->colladaXml, _name, _id);
}
- elem = elem->NextSiblingElement();
- }
+ /////////////////////////////////////////////////
+ TiXmlElement *ColladaParser::getElementId(TiXmlElement *_parent,
+ const std::string &_name,
+ const std::string &_id)
+ {
+ std::string id = _id;
+ if (id.length() > 0 && id[0] == '#')
+ id.erase(0, 1);
- return NULL;
-}
+ if ((id.empty() && _parent->Value() == _name) ||
+ (_parent->Attribute("id") && _parent->Attribute("id") == id) ||
+ (_parent->Attribute("sid") && _parent->Attribute("sid") == id))
+ {
+ return _parent;
+ }
-/////////////////////////////////////////////////
-void ColladaParser::loadNode(TiXmlElement *_elem, Malla *_mesh,
- const math::Matriz4x4 &_transform)
-{
- TiXmlElement *nodeXml;
- TiXmlElement *instGeomXml;
+ TiXmlElement *elem = _parent->FirstChildElement();
+ while (elem)
+ {
+ TiXmlElement *result = this->getElementId(elem, _name, _id);
+ if (result)
+ {
+ return result;
+ }
- math::Matriz4x4 transform = this->loadNodeTransform(_elem);
- transform = _transform * transform;
+ elem = elem->NextSiblingElement();
+ }
- if (_elem->Attribute("name"))
- {
- this->currentNodeName = _elem->Attribute("name");
- }
+ return NULL;
+ }
- nodeXml = _elem->FirstChildElement("node");
- while (nodeXml)
- {
- this->loadNode(nodeXml, _mesh, transform);
- nodeXml = nodeXml->NextSiblingElement("node");
- }
+ /////////////////////////////////////////////////
+ void ColladaParser::loadNode(TiXmlElement *_elem, Malla *_mesh,
+ const math::Matriz4x4 &_transform)
+ {
+ TiXmlElement *nodeXml;
+ TiXmlElement *instGeomXml;
- if (_elem->FirstChildElement("instance_node"))
- {
- std::string nodeURLStr =
- _elem->FirstChildElement("instance_node")->Attribute("url");
+ math::Matriz4x4 transform = this->loadNodeTransform(_elem);
+ transform = _transform * transform;
- nodeXml = this->getElementId("node", nodeURLStr);
- if (!nodeXml)
- {
- std::cout << "Unable to find node[" << nodeURLStr << "]\n";
- return;
- }
- this->loadNode(nodeXml, _mesh, transform);
- return;
- }
- else
- nodeXml = _elem;
+ if (_elem->Attribute("name"))
+ {
+ this->currentNodeName = _elem->Attribute("name");
+ }
- instGeomXml = nodeXml->FirstChildElement("instance_geometry");
- while (instGeomXml)
- {
- std::string geomURL = instGeomXml->Attribute("url");
- TiXmlElement *geomXml = this->getElementId("geometry", geomURL);
+ nodeXml = _elem->FirstChildElement("node");
+ while (nodeXml)
+ {
+ this->loadNode(nodeXml, _mesh, transform);
+ nodeXml = nodeXml->NextSiblingElement("node");
+ }
- this->materialMap.clear();
- TiXmlElement *bindMatXml, *techniqueXml, *matXml;
- bindMatXml = instGeomXml->FirstChildElement("bind_material");
- while (bindMatXml)
- {
- if ((techniqueXml = bindMatXml->FirstChildElement("technique_common")))
+ if (_elem->FirstChildElement("instance_node"))
{
- matXml = techniqueXml->FirstChildElement("instance_material");
- while (matXml)
+ std::string nodeURLStr =
+ _elem->FirstChildElement("instance_node")->Attribute("url");
+
+ nodeXml = this->getElementId("node", nodeURLStr);
+ if (!nodeXml)
{
- std::string symbol = matXml->Attribute("symbol");
- std::string target = matXml->Attribute("target");
- this->materialMap[symbol] = target;
- matXml = matXml->NextSiblingElement("instance_material");
+ std::cout << "Unable to find node[" << nodeURLStr << "]\n";
+ return;
}
+ this->loadNode(nodeXml, _mesh, transform);
+ return;
}
- bindMatXml = bindMatXml->NextSiblingElement("bind_material");
- }
+ else
+ nodeXml = _elem;
- this->loadGeometry(geomXml, transform, _mesh);
- instGeomXml = instGeomXml->NextSiblingElement("instance_geometry");
- }
+ instGeomXml = nodeXml->FirstChildElement("instance_geometry");
+ while (instGeomXml)
+ {
+ std::string geomURL = instGeomXml->Attribute("url");
+ TiXmlElement *geomXml = this->getElementId("geometry", geomURL);
- TiXmlElement *instContrXml =
- nodeXml->FirstChildElement("instance_controller");
- while (instContrXml)
- {
- std::string contrURL = instContrXml->Attribute("url");
- TiXmlElement *contrXml = this->getElementId("controller", contrURL);
-
- TiXmlElement *instSkelXml = instContrXml->FirstChildElement("skeleton");
- std::string rootURL = instSkelXml->GetText();
- TiXmlElement *rootNodeXml = this->getElementId("node", rootURL);
-
- this->materialMap.clear();
- TiXmlElement *bindMatXml, *techniqueXml, *matXml;
- bindMatXml = instContrXml->FirstChildElement("bind_material");
- while (bindMatXml)
- {
- if ((techniqueXml = bindMatXml->FirstChildElement("technique_common")))
- {
- matXml = techniqueXml->FirstChildElement("instance_material");
- while (matXml)
+ this->materialMap.clear();
+ TiXmlElement *bindMatXml, *techniqueXml, *matXml;
+ bindMatXml = instGeomXml->FirstChildElement("bind_material");
+ while (bindMatXml)
{
- std::string symbol = matXml->Attribute("symbol");
- std::string target = matXml->Attribute("target");
- this->materialMap[symbol] = target;
- matXml = matXml->NextSiblingElement("instance_material");
+ if ((techniqueXml = bindMatXml->FirstChildElement("technique_common")))
+ {
+ matXml = techniqueXml->FirstChildElement("instance_material");
+ while (matXml)
+ {
+ std::string symbol = matXml->Attribute("symbol");
+ std::string target = matXml->Attribute("target");
+ this->materialMap[symbol] = target;
+ matXml = matXml->NextSiblingElement("instance_material");
+ }
+ }
+ bindMatXml = bindMatXml->NextSiblingElement("bind_material");
}
+
+ this->loadGeometry(geomXml, transform, _mesh);
+ instGeomXml = instGeomXml->NextSiblingElement("instance_geometry");
}
- bindMatXml = bindMatXml->NextSiblingElement("bind_material");
- }
- this->loadController(contrXml, rootNodeXml, transform, _mesh);
- instContrXml = instContrXml->NextSiblingElement("instance_controller");
- }
-}
+ TiXmlElement *instContrXml =
+ nodeXml->FirstChildElement("instance_controller");
+ while (instContrXml)
+ {
+ std::string contrURL = instContrXml->Attribute("url");
+ TiXmlElement *contrXml = this->getElementId("controller", contrURL);
-/////////////////////////////////////////////////
-math::Matriz4x4 ColladaParser::loadNodeTransform(TiXmlElement *_elem)
-{
- math::Matriz4x4 transform(math::Matriz4x4::IDENTITY);
+ TiXmlElement *instSkelXml = instContrXml->FirstChildElement("skeleton");
+ std::string rootURL = instSkelXml->GetText();
+ TiXmlElement *rootNodeXml = this->getElementId("node", rootURL);
- if (_elem->FirstChildElement("matrix"))
- {
- std::string matrixStr = _elem->FirstChildElement("matrix")->GetText();
- std::istringstream iss(matrixStr);
- std::vector<double> values(16);
- for (unsigned int i = 0; i < 16; i++)
- iss >> values[i];
+ this->materialMap.clear();
+ TiXmlElement *bindMatXml, *techniqueXml, *matXml;
+ bindMatXml = instContrXml->FirstChildElement("bind_material");
+ while (bindMatXml)
+ {
+ if ((techniqueXml = bindMatXml->FirstChildElement("technique_common")))
+ {
+ matXml = techniqueXml->FirstChildElement("instance_material");
+ while (matXml)
+ {
+ std::string symbol = matXml->Attribute("symbol");
+ std::string target = matXml->Attribute("target");
+ this->materialMap[symbol] = target;
+ matXml = matXml->NextSiblingElement("instance_material");
+ }
+ }
+ bindMatXml = bindMatXml->NextSiblingElement("bind_material");
+ }
- transform.set(values[0], values[1], values[2], values[3],
- values[4], values[5], values[6], values[7],
- values[8], values[9], values[10], values[11],
- values[12], values[13], values[14], values[15]);
- }
- else
- {
-
- if (_elem->FirstChildElement("scale"))
- {
- std::string scaleStr = _elem->FirstChildElement("scale")->GetText();
- math::Vector3 scale;
- scale = boost::lexical_cast<math::Vector3>(scaleStr);
- math::Matriz4x4 scaleMat;
- scaleMat.setScale(scale);
- transform = transform * scaleMat;
+ this->loadController(contrXml, rootNodeXml, transform, _mesh);
+ instContrXml = instContrXml->NextSiblingElement("instance_controller");
+ }
}
- if (_elem->FirstChildElement("translate"))
+ /////////////////////////////////////////////////
+ math::Matriz4x4 ColladaParser::loadNodeTransform(TiXmlElement *_elem)
{
- std::string transStr = _elem->FirstChildElement("translate")->GetText();
- math::Vector3 translate;
- translate = boost::lexical_cast<math::Vector3>(transStr);
- // translate *= this->meter;
- transform.setTranslate(translate);
- }
+ math::Matriz4x4 transform(math::Matriz4x4::IDENTITY);
- TiXmlElement *rotateXml = _elem->FirstChildElement("rotate");
+ if (_elem->FirstChildElement("matrix"))
+ {
+ std::string matrixStr = _elem->FirstChildElement("matrix")->GetText();
+ std::istringstream iss(matrixStr);
+ std::vector<double> values(16);
+ for (unsigned int i = 0; i < 16; i++)
+ iss >> values[i];
- while (rotateXml)
- {
- math::Matriz3x3 mat;
- math::Vector3 axis;
- double angle;
+ transform.set(values[0], values[1], values[2], values[3],
+ values[4], values[5], values[6], values[7],
+ values[8], values[9], values[10], values[11],
+ values[12], values[13], values[14], values[15]);
+ }
+ else
+ {
- std::string rotateStr = rotateXml->GetText();
- std::istringstream iss(rotateStr);
+ if (_elem->FirstChildElement("scale"))
+ {
+ std::string scaleStr = _elem->FirstChildElement("scale")->GetText();
+ math::Vector3 scale;
+ scale = boost::lexical_cast<math::Vector3>(scaleStr);
+ math::Matriz4x4 scaleMat;
+ scaleMat.setScale(scale);
+ transform = transform * scaleMat;
+ }
- float x, y, z;
+ if (_elem->FirstChildElement("translate"))
+ {
+ std::string transStr = _elem->FirstChildElement("translate")->GetText();
+ math::Vector3 translate;
+ translate = boost::lexical_cast<math::Vector3>(transStr);
+ // translate *= this->meter;
+ transform.setTranslate(translate);
+ }
- iss >> x >> y >> z;
+ TiXmlElement *rotateXml = _elem->FirstChildElement("rotate");
- axis.setX(x);
- axis.setY(y);
- axis.setZ(z);
+ while (rotateXml)
+ {
+ math::Matriz3x3 mat;
+ math::Vector3 axis;
+ double angle;
- iss >> angle;
- mat.setFromAxis(axis.getX(), axis.getY(), axis.getZ(), angle*3.1416/180);
- transform = transform * mat;
+ std::string rotateStr = rotateXml->GetText();
+ std::istringstream iss(rotateStr);
- rotateXml = rotateXml->NextSiblingElement("rotate");
- }
+ float x, y, z;
+ iss >> x >> y >> z;
- }
+ axis.setX(x);
+ axis.setY(y);
+ axis.setZ(z);
- return transform;
-}
+ iss >> angle;
+ mat.setFromAxis(axis.getX(), axis.getY(), axis.getZ(), angle*3.1416/180);
+ transform = transform * mat;
+ rotateXml = rotateXml->NextSiblingElement("rotate");
+ }
-/////////////////////////////////////////////////
-void ColladaParser::loadVertices(const std::string &_id,
- const math::Matriz4x4 &_transform,
- std::vector<math::Vector3> &_verts,
- std::vector<math::Vector3> &_norms)
-{
- TiXmlElement *verticesXml = this->getElementId(this->colladaXml,
- "vertices", _id);
- if (!verticesXml)
- {
- std::cout << "Unable to find vertices[" << _id << "] in collada file\n";
- return;
- }
+ }
- TiXmlElement *inputXml = verticesXml->FirstChildElement("input");
- while (inputXml)
- {
- std::string semantic = inputXml->Attribute("semantic");
- std::string sourceStr = inputXml->Attribute("source");
- if (semantic == "NORMAL")
- {
- this->loadNormals(sourceStr, _transform, _norms);
+ return transform;
}
- else if (semantic == "POSITION")
- {
- this->loadPositions(sourceStr, _transform, _verts);
- }
- inputXml = inputXml->NextSiblingElement("input");
- }
-}
-/////////////////////////////////////////////////
-void ColladaParser::loadPositions(const std::string &_id,
+ /////////////////////////////////////////////////
+ void ColladaParser::loadVertices(const std::string &_id,
const math::Matriz4x4 &_transform,
- std::vector<math::Vector3> &_values)
-{
- TiXmlElement *sourceXml = this->getElementId("source", _id);
- TiXmlElement *floatArrayXml = sourceXml->FirstChildElement("float_array");
- if (!floatArrayXml)
- {
- std::cout << "Vertex source missing float_array element\n";
- return;
- }
- std::string valueStr = floatArrayXml->GetText();
+ std::vector<math::Vector3> &_verts,
+ std::vector<math::Vector3> &_norms)
+ {
+ TiXmlElement *verticesXml = this->getElementId(this->colladaXml,
+ "vertices", _id);
- std::vector<std::string> strs;
- std::vector<std::string>::iterator iter, end;
- boost::split(strs, valueStr, boost::is_any_of(" "));
+ if (!verticesXml)
+ {
+ std::cout << "Unable to find vertices[" << _id << "] in collada file\n";
+ return;
+ }
- end = strs.end();
- for (iter = strs.begin(); iter != end; iter += 3)
- {
- math::Vector3 vec(math::parseFloat(*iter), math::parseFloat(*(iter+1)),
- math::parseFloat(*(iter+2)));
- vec = _transform * vec;
- _values.push_back(vec);
- }
-}
+ TiXmlElement *inputXml = verticesXml->FirstChildElement("input");
+ while (inputXml)
+ {
+ std::string semantic = inputXml->Attribute("semantic");
+ std::string sourceStr = inputXml->Attribute("source");
+ if (semantic == "NORMAL")
+ {
+ this->loadNormals(sourceStr, _transform, _norms);
+ }
+ else if (semantic == "POSITION")
+ {
+ this->loadPositions(sourceStr, _transform, _verts);
+ }
-/////////////////////////////////////////////////
-void ColladaParser::loadNormals(const std::string &_id,
- const math::Matriz4x4 &_transform,
- std::vector<math::Vector3> &_values)
-{
- TiXmlElement *normalsXml = this->getElementId("source", _id);
- if (!normalsXml)
- {
- std::cout << "Unable to find normals[" << _id << "] in collada file\n";
- return;
- }
+ inputXml = inputXml->NextSiblingElement("input");
+ }
+ }
- TiXmlElement *floatArrayXml = normalsXml->FirstChildElement("float_array");
- if (!floatArrayXml)
- {
- std::cout << "Normal source missing float_array element\n";
- return;
- }
+ /////////////////////////////////////////////////
+ void ColladaParser::loadPositions(const std::string &_id,
+ const math::Matriz4x4 &_transform,
+ std::vector<math::Vector3> &_values)
+ {
+ TiXmlElement *sourceXml = this->getElementId("source", _id);
+ TiXmlElement *floatArrayXml = sourceXml->FirstChildElement("float_array");
+ if (!floatArrayXml)
+ {
+ std::cout << "Vertex source missing float_array element\n";
+ return;
+ }
+ std::string valueStr = floatArrayXml->GetText();
- std::string valueStr = floatArrayXml->GetText();
- std::istringstream iss(valueStr);
- do
- {
- math::Vector3 vec;
- float x, y, z;
- iss >> x >> y >> z;
- vec.setX(x);
- vec.setY(y);
- vec.setZ(z);
+ std::vector<std::string> strs;
+ std::vector<std::string>::iterator iter, end;
+ boost::split(strs, valueStr, boost::is_any_of(" "));
- if (iss)
- {
- vec = _transform * vec;
- vec.normalize();
- _values.push_back(vec);
+ end = strs.end();
+ for (iter = strs.begin(); iter != end; iter += 3)
+ {
+ math::Vector3 vec(math::parseFloat(*iter), math::parseFloat(*(iter+1)),
+ math::parseFloat(*(iter+2)));
+ vec = _transform * vec;
+ _values.push_back(vec);
+ }
}
- } while (iss);
-}
-/////////////////////////////////////////////////
-void ColladaParser::loadGeometry(TiXmlElement *_xml,
- const math::Matriz4x4 &_transform, Malla *_mesh)
-{
- TiXmlElement *meshXml = _xml->FirstChildElement("mesh");
- TiXmlElement *childXml;
+ /////////////////////////////////////////////////
+ void ColladaParser::loadNormals(const std::string &_id,
+ const math::Matriz4x4 &_transform,
+ std::vector<math::Vector3> &_values)
+ {
+ TiXmlElement *normalsXml = this->getElementId("source", _id);
+ if (!normalsXml)
+ {
+ std::cout << "Unable to find normals[" << _id << "] in collada file\n";
+ return;
+ }
- if (!meshXml)
- return;
+ TiXmlElement *floatArrayXml = normalsXml->FirstChildElement("float_array");
+ if (!floatArrayXml)
+ {
+ std::cout << "Normal source missing float_array element\n";
+ return;
+ }
- childXml = meshXml->FirstChildElement("triangles");
- while (childXml)
- {
- this->loadTriangles(childXml, _transform, _mesh);
- childXml = childXml->NextSiblingElement("triangles");
- }
+ std::string valueStr = floatArrayXml->GetText();
+ std::istringstream iss(valueStr);
+ do
+ {
+ math::Vector3 vec;
+ float x, y, z;
+ iss >> x >> y >> z;
+ vec.setX(x);
+ vec.setY(y);
+ vec.setZ(z);
- childXml = meshXml->FirstChildElement("polylist");
- while (childXml)
- {
- this->loadPolylist(childXml, _transform, _mesh);
- childXml = childXml->NextSiblingElement("polylist");
- }
+ if (iss)
+ {
+ vec = _transform * vec;
+ vec.normalize();
+ _values.push_back(vec);
+ }
+ } while (iss);
+ }
- childXml = meshXml->FirstChildElement("lines");
- while (childXml)
- {
- this->loadLines(childXml, _transform, _mesh);
- childXml = childXml->NextSiblingElement("lines");
- }
-}
+ /////////////////////////////////////////////////
+ void ColladaParser::loadGeometry(TiXmlElement *_xml,
+ const math::Matriz4x4 &_transform, Malla *_mesh)
+ {
+ TiXmlElement *meshXml = _xml->FirstChildElement("mesh");
+ TiXmlElement *childXml;
-/////////////////////////////////////////////////
-void ColladaParser::loadLines(TiXmlElement *_xml,
- const math::Matriz4x4 &_transform,
- Malla *_mesh)
-{
- SubMalla *subMalla = new SubMalla();
- subMalla->setName(this->currentNodeName);
- subMalla->setPrimitiveType(SubMalla::LINES);
+ if (!meshXml)
+ return;
- TiXmlElement *inputXml = _xml->FirstChildElement("input");
- // std::string semantic = inputXml->Attribute("semantic");
- std::string source = inputXml->Attribute("source");
+ childXml = meshXml->FirstChildElement("triangles");
+ while (childXml)
+ {
+ this->loadTriangles(childXml, _transform, _mesh);
+ childXml = childXml->NextSiblingElement("triangles");
+ }
- std::vector<math::Vector3> verts;
- std::vector<math::Vector3> norms;
- this->loadVertices(source, _transform, verts, norms);
+ childXml = meshXml->FirstChildElement("polylist");
+ while (childXml)
+ {
+ this->loadPolylist(childXml, _transform, _mesh);
+ childXml = childXml->NextSiblingElement("polylist");
+ }
- TiXmlElement *pXml = _xml->FirstChildElement("p");
- std::string pStr = pXml->GetText();
- std::istringstream iss(pStr);
+ childXml = meshXml->FirstChildElement("lines");
+ while (childXml)
+ {
+ this->loadLines(childXml, _transform, _mesh);
+ childXml = childXml->NextSiblingElement("lines");
+ }
+ }
- do
- {
- int a, b;
- iss >> a >> b;
+ /////////////////////////////////////////////////
+ void ColladaParser::loadLines(TiXmlElement *_xml,
+ const math::Matriz4x4 &_transform,
+ Malla *_mesh)
+ {
+ SubMalla *subMalla = new SubMalla();
+ subMalla->setName(this->currentNodeName);
+ subMalla->setPrimitiveType(SubMalla::LINES);
- if (!iss)
- break;
- subMalla->addVertex(verts[a]);
- subMalla->addIndex(subMalla->getVertexCount() - 1);
- subMalla->addVertex(verts[b]);
- subMalla->addIndex(subMalla->getVertexCount() - 1);
- } while (iss);
+ TiXmlElement *inputXml = _xml->FirstChildElement("input");
+ // std::string semantic = inputXml->Attribute("semantic");
+ std::string source = inputXml->Attribute("source");
- _mesh->addSubMalla(subMalla);
-}
+ std::vector<math::Vector3> verts;
+ std::vector<math::Vector3> norms;
+ this->loadVertices(source, _transform, verts, norms);
-/////////////////////////////////////////////////
-void ColladaParser::loadPolylist(TiXmlElement *_polylistXml,
- const math::Matriz4x4 &_transform,
- Malla *_mesh)
-{
- // This function parses polylist types in collada into
- // a set of triangle meshes. The assumption is that
- // each polylist polygon is convex, and we do decomposion
- // by anchoring each triangle about vertex 0 or each polygon
- SubMalla *subMalla = new SubMalla;
- subMalla->setName(this->currentNodeName);
- bool combinedVertNorms = false;
+ TiXmlElement *pXml = _xml->FirstChildElement("p");
+ std::string pStr = pXml->GetText();
+ std::istringstream iss(pStr);
- subMalla->setPrimitiveType(SubMalla::TRIANGLES);
+ do
+ {
+ int a, b;
+ iss >> a >> b;
- if (_polylistXml->Attribute("material"))
- {
- std::map<std::string, std::string>::iterator iter;
- std::string matStr = _polylistXml->Attribute("material");
+ if (!iss)
+ break;
+ subMalla->addVertex(verts[a]);
+ subMalla->addIndex(subMalla->getVertexCount() - 1);
+ subMalla->addVertex(verts[b]);
+ subMalla->addIndex(subMalla->getVertexCount() - 1);
+ } while (iss);
- iter = this->materialMap.find(matStr);
- if (iter != this->materialMap.end())
- matStr = iter->second;
+ _mesh->addSubMalla(subMalla);
+ }
- int matIndex = _mesh->addMaterial(this->loadMaterial(matStr));
- if (matIndex < 0)
- std::cout << "Unable to add material[" << matStr << "]\n";
- else
- subMalla->setMaterialIndex(matIndex);
- }
+ /////////////////////////////////////////////////
+ void ColladaParser::loadPolylist(TiXmlElement *_polylistXml,
+ const math::Matriz4x4 &_transform,
+ Malla *_mesh)
+ {
+ // This function parses polylist types in collada into
+ // a set of triangle meshes. The assumption is that
+ // each polylist polygon is convex, and we do decomposion
+ // by anchoring each triangle about vertex 0 or each polygon
+ SubMalla *subMalla = new SubMalla;
+ subMalla->setName(this->currentNodeName);
+ bool combinedVertNorms = false;
- TiXmlElement *polylistInputXml = _polylistXml->FirstChildElement("input");
+ subMalla->setPrimitiveType(SubMalla::TRIANGLES);
- std::vector<math::Vector3> verts;
- std::vector<math::Vector3> norms;
- std::vector<math::Vector2d> texcoords;
+ if (_polylistXml->Attribute("material"))
+ {
+ std::map<std::string, std::string>::iterator iter;
+ std::string matStr = _polylistXml->Attribute("material");
- math::Matriz4x4 bindShapeMat(math::Matriz4x4::IDENTITY);
- //if (_mesh->HasSkeleton())
- // bindShapeMat = _mesh->GetSkeleton()->GetBindShapeTransform();
+ iter = this->materialMap.find(matStr);
+ if (iter != this->materialMap.end())
+ matStr = iter->second;
- // read input elements
- std::map<std::string, int> inputs;
- while (polylistInputXml)
- {
- std::string semantic = polylistInputXml->Attribute("semantic");
- std::string source = polylistInputXml->Attribute("source");
- std::string offset = polylistInputXml->Attribute("offset");
- if (semantic == "VERTEX")
- {
- unsigned int count = norms.size();
- this->loadVertices(source, _transform, verts, norms);
- if (norms.size() > count)
- combinedVertNorms = true;
- }
- else if (semantic == "NORMAL")
- {
- this->loadNormals(source, _transform, norms);
- combinedVertNorms = false;
- }
- else if (semantic == "TEXCOORD")
- this->loadTexCoords(source, texcoords);
+ int matIndex = _mesh->addMaterial(this->loadMaterial(matStr));
+ if (matIndex < 0)
+ std::cout << "Unable to add material[" << matStr << "]\n";
+ else
+ subMalla->setMaterialIndex(matIndex);
+ }
- inputs[semantic] = math::parseInt(offset);
+ TiXmlElement *polylistInputXml = _polylistXml->FirstChildElement("input");
- polylistInputXml = polylistInputXml->NextSiblingElement("input");
- }
+ std::vector<math::Vector3> verts;
+ std::vector<math::Vector3> norms;
+ std::vector<math::Vector2d> texcoords;
- // read vcount
- // break poly into triangles
- // if vcount >= 4, anchor around 0 (note this is bad for concave elements)
- // e.g. if vcount = 4, break into triangle 1: [0,1,2], triangle 2: [0,2,3]
- std::vector<std::string> vcountStrs;
- TiXmlElement *vcountXml = _polylistXml->FirstChildElement("vcount");
- std::string vcountStr = vcountXml->GetText();
- boost::split(vcountStrs, vcountStr, boost::is_any_of(" "));
- std::vector<int> vcounts;
- for (unsigned int j = 0; j < vcountStrs.size(); ++j)
- vcounts.push_back(math::parseInt(vcountStrs[j]));
+ math::Matriz4x4 bindShapeMat(math::Matriz4x4::IDENTITY);
+ //if (_mesh->HasSkeleton())
+ // bindShapeMat = _mesh->GetSkeleton()->GetBindShapeTransform();
- // read p
- TiXmlElement *pXml = _polylistXml->FirstChildElement("p");
- std::string pStr = pXml->GetText();
+ // read input elements
+ std::map<std::string, int> inputs;
+ while (polylistInputXml)
+ {
+ std::string semantic = polylistInputXml->Attribute("semantic");
+ std::string source = polylistInputXml->Attribute("source");
+ std::string offset = polylistInputXml->Attribute("offset");
+ if (semantic == "VERTEX")
+ {
+ unsigned int count = norms.size();
+ this->loadVertices(source, _transform, verts, norms);
+ if (norms.size() > count)
+ combinedVertNorms = true;
+ }
+ else if (semantic == "NORMAL")
+ {
+ this->loadNormals(source, _transform, norms);
+ combinedVertNorms = false;
+ }
+ else if (semantic == "TEXCOORD")
+ this->loadTexCoords(source, texcoords);
- std::vector<math::Vector3> vertNorms(verts.size());
- std::vector<int> vertNormsCounts(verts.size());
- std::fill(vertNormsCounts.begin(), vertNormsCounts.end(), 0);
+ inputs[semantic] = math::parseInt(offset);
- int *values = new int[inputs.size()];
- std::map<std::string, int>::iterator end = inputs.end();
- std::map<std::string, int>::iterator iter;
- math::Vector2d vec;
+ polylistInputXml = polylistInputXml->NextSiblingElement("input");
+ }
- std::vector<std::string> strs;
- boost::split(strs, pStr, boost::is_any_of(" "));
- std::vector<std::string>::iterator strs_iter = strs.begin();
- for (unsigned int l = 0; l < vcounts.size(); ++l)
- {
- // put us at the beginning of the polygon list
- if (l > 0) strs_iter += inputs.size()*vcounts[l-1];
+ // read vcount
+ // break poly into triangles
+ // if vcount >= 4, anchor around 0 (note this is bad for concave elements)
+ // e.g. if vcount = 4, break into triangle 1: [0,1,2], triangle 2: [0,2,3]
+ std::vector<std::string> vcountStrs;
+ TiXmlElement *vcountXml = _polylistXml->FirstChildElement("vcount");
+ std::string vcountStr = vcountXml->GetText();
+ boost::split(vcountStrs, vcountStr, boost::is_any_of(" "));
+ std::vector<int> vcounts;
+ for (unsigned int j = 0; j < vcountStrs.size(); ++j)
+ vcounts.push_back(math::parseInt(vcountStrs[j]));
- for (unsigned int k = 2; k < (unsigned int)vcounts[l]; ++k)
- {
- // if vcounts[l] = 5, then read 0,1,2, then 0,2,3, 0,3,4,...
- // here k = the last number in the series
- // j is the triangle loop
- for (unsigned int j = 0; j < 3; ++j)
- {
- // break polygon into triangles
- unsigned int triangle_index;
+ // read p
+ TiXmlElement *pXml = _polylistXml->FirstChildElement("p");
+ std::string pStr = pXml->GetText();
- if (j == 0)
- triangle_index = 0;
- if (j == 1)
- triangle_index = (k-1)*inputs.size();
- if (j == 2)
- triangle_index = (k)*inputs.size();
+ std::vector<math::Vector3> vertNorms(verts.size());
+ std::vector<int> vertNormsCounts(verts.size());
+ std::fill(vertNormsCounts.begin(), vertNormsCounts.end(), 0);
- for (unsigned int i = 0; i < inputs.size(); i++)
- {
- values[i] = math::parseInt(strs_iter[triangle_index+i]);
-// std::cout << "debug parsing "
-// << " poly-i[" << l
-// << "] tri-end-index[" << k
-// << "] tri-vertex-i[" << j
-// << "] triangle[" << triangle_index
-// << "] input[" << i
-// << "] value[" << values[i]
-// << "]\n";
- }
+ int *values = new int[inputs.size()];
+ std::map<std::string, int>::iterator end = inputs.end();
+ std::map<std::string, int>::iterator iter;
+ math::Vector2d vec;
+ std::vector<std::string> strs;
+ boost::split(strs, pStr, boost::is_any_of(" "));
+ std::vector<std::string>::iterator strs_iter = strs.begin();
+ for (unsigned int l = 0; l < vcounts.size(); ++l)
+ {
+ // put us at the beginning of the polygon list
+ if (l > 0) strs_iter += inputs.size()*vcounts[l-1];
- for (iter = inputs.begin(); iter != end; ++iter)
+ for (unsigned int k = 2; k < (unsigned int)vcounts[l]; ++k)
{
- if (iter->first == "VERTEX")
+ // if vcounts[l] = 5, then read 0,1,2, then 0,2,3, 0,3,4,...
+ // here k = the last number in the series
+ // j is the triangle loop
+ for (unsigned int j = 0; j < 3; ++j)
{
- subMalla->addVertex(bindShapeMat * verts[values[iter->second]]);
- subMalla->addIndex(subMalla->getVertexCount()-1);
- if (combinedVertNorms)
- subMalla->addNormal(norms[values[iter->second]]);
-// if (_mesh->HasSkeleton())
-// {
-// Skeleton *skel = _mesh->GetSkeleton();
-// for (unsigned int i = 0;
-// i < skel->GetNumVertNodeWeights(values[iter->second]); i++)
-// {
-// std::pair<std::string, double> node_weight =
-// skel->GetVertNodeWeight(values[iter->second], i);
-// SkeletonNode *node =
-// _mesh->GetSkeleton()->GetNodeByName(node_weight.first);
-// SubMalla->AddNodeAssignment(SubMalla->GetVertexCount()-1,
-// node->GetHandle(), node_weight.second);
-// }
-// }
+ // break polygon into triangles
+ unsigned int triangle_index;
+
+ if (j == 0)
+ triangle_index = 0;
+ if (j == 1)
+ triangle_index = (k-1)*inputs.size();
+ if (j == 2)
+ triangle_index = (k)*inputs.size();
+
+ for (unsigned int i = 0; i < inputs.size(); i++)
+ {
+ values[i] = math::parseInt(strs_iter[triangle_index+i]);
+ // std::cout << "debug parsing "
+ // << " poly-i[" << l
+ // << "] tri-end-index[" << k
+ // << "] tri-vertex-i[" << j
+ // << "] triangle[" << triangle_index
+ // << "] input[" << i
+ // << "] value[" << values[i]
+ // << "]\n";
+ }
+
+
+ for (iter = inputs.begin(); iter != end; ++iter)
+ {
+ if (iter->first == "VERTEX")
+ {
+ subMalla->addVertex(bindShapeMat * verts[values[iter->second]]);
+ subMalla->addIndex(subMalla->getVertexCount()-1);
+ if (combinedVertNorms)
+ subMalla->addNormal(norms[values[iter->second]]);
+ // if (_mesh->HasSkeleton())
+ // {
+ // Skeleton *skel = _mesh->GetSkeleton();
+ // for (unsigned int i = 0;
+ // i < skel->GetNumVertNodeWeights(values[iter->second]); i++)
+ // {
+ // std::pair<std::string, double> node_weight =
+ // skel->GetVertNodeWeight(values[iter->second], i);
+ // SkeletonNode *node =
+ // _mesh->GetSkeleton()->GetNodeByName(node_weight.first);
+ // SubMalla->AddNodeAssignment(SubMalla->GetVertexCount()-1,
+ // node->GetHandle(), node_weight.second);
+ // }
+ // }
+ }
+ else if (iter->first == "NORMAL")
+ {
+ subMalla->addNormal(norms[values[iter->second]]);
+ }
+ else if (iter->first == "TEXCOORD")
+ {
+ subMalla->addTexCoord(texcoords[values[iter->second]].getX(),
+ texcoords[values[iter->second]].getY());
+ }
+ // else
+ // gzerr << "Unhandled semantic[" << iter->first << "]\n";
+ }
}
- else if (iter->first == "NORMAL")
- {
- subMalla->addNormal(norms[values[iter->second]]);
- }
- else if (iter->first == "TEXCOORD")
- {
- subMalla->addTexCoord(texcoords[values[iter->second]].getX(),
- texcoords[values[iter->second]].getY());
- }
- // else
- // gzerr << "Unhandled semantic[" << iter->first << "]\n";
}
}
+ delete [] values;
+
+ _mesh->addSubMalla(subMalla);
}
- }
- delete [] values;
- _mesh->addSubMalla(subMalla);
-}
+ /////////////////////////////////////////////////
+ void ColladaParser::loadTexCoords(const std::string &_id,
+ std::vector<math::Vector2d> &_values)
+ {
+ int stride = 0;
+ int texCount = 0;
+ int totCount = 0;
-/////////////////////////////////////////////////
-void ColladaParser::loadTexCoords(const std::string &_id,
- std::vector<math::Vector2d> &_values)
-{
- int stride = 0;
- int texCount = 0;
- int totCount = 0;
+ // Get the source element for the texture coordinates.
+ TiXmlElement *xml = this->getElementId("source", _id);
+ if (!xml)
+ {
+ std::cout << "Unable to find tex coords[" << _id << "] in collada file\n";
+ return;
+ }
- // Get the source element for the texture coordinates.
- TiXmlElement *xml = this->getElementId("source", _id);
- if (!xml)
- {
- std::cout << "Unable to find tex coords[" << _id << "] in collada file\n";
- return;
- }
+ // Get the array of float values. These are the raw values for the texture
+ // coordinates.
+ TiXmlElement *floatArrayXml = xml->FirstChildElement("float_array");
+ if (!floatArrayXml)
+ {
+ std::cout << "Normal source missing float_array element\n";
+ return;
+ }
- // Get the array of float values. These are the raw values for the texture
- // coordinates.
- TiXmlElement *floatArrayXml = xml->FirstChildElement("float_array");
- if (!floatArrayXml)
- {
- std::cout << "Normal source missing float_array element\n";
- return;
- }
+ // The technique_common holds an <accessor> element that indicates how to
+ // parse the float array.
+ xml = xml->FirstChildElement("technique_common");
+ if (!xml)
+ {
+ std::cout << "Unable to find technique_common element for texture "
+ << "coordinates with id[" << _id << "]\n";
+ return;
+ }
- // The technique_common holds an <accessor> element that indicates how to
- // parse the float array.
- xml = xml->FirstChildElement("technique_common");
- if (!xml)
- {
- std::cout << "Unable to find technique_common element for texture "
- << "coordinates with id[" << _id << "]\n";
- return;
- }
+ // Get the accessor XML element.
+ xml = xml->FirstChildElement("accessor");
+ if (!xml)
+ {
+ std::cout << "Unable to find <accessor> as a child of <technique_common> "
+ << "for texture coordinates with id[" << _id << "]\n";
+ return;
+ }
- // Get the accessor XML element.
- xml = xml->FirstChildElement("accessor");
- if (!xml)
- {
- std::cout << "Unable to find <accessor> as a child of <technique_common> "
- << "for texture coordinates with id[" << _id << "]\n";
- return;
- }
+ // Read in the total number of texture coordinate values
+ if (floatArrayXml->Attribute("count"))
+ totCount = boost::lexical_cast<int>(floatArrayXml->Attribute("count"));
+ else
+ {
+ std::cout << "<float_array> has no count attribute in texture coordinate "
+ << "element with id[" << _id << "]\n";
+ return;
+ }
- // Read in the total number of texture coordinate values
- if (floatArrayXml->Attribute("count"))
- totCount = boost::lexical_cast<int>(floatArrayXml->Attribute("count"));
- else
- {
- std::cout << "<float_array> has no count attribute in texture coordinate "
- << "element with id[" << _id << "]\n";
- return;
- }
+ // Read in the stride for the texture coordinate values. The stride
+ // indicates the number of values in the float array the comprise
+ // a complete texture coordinate.
+ if (xml->Attribute("stride"))
+ stride = boost::lexical_cast<int>(xml->Attribute("stride"));
+ else
+ {
+ std::cout << "<accessor> has no stride attribute in texture coordinate element "
+ << "with id[" << _id << "]\n";
+ return;
+ }
- // Read in the stride for the texture coordinate values. The stride
- // indicates the number of values in the float array the comprise
- // a complete texture coordinate.
- if (xml->Attribute("stride"))
- stride = boost::lexical_cast<int>(xml->Attribute("stride"));
- else
- {
- std::cout << "<accessor> has no stride attribute in texture coordinate element "
- << "with id[" << _id << "]\n";
- return;
- }
+ // Read in the count of texture coordinates.
+ if (xml->Attribute("count"))
+ texCount = boost::lexical_cast<int>(xml->Attribute("count"));
+ else
+ {
+ std::cout << "<accessor> has no count attribute in texture coordinate element "
+ << "with id[" << _id << "]\n";
+ return;
+ }
- // Read in the count of texture coordinates.
- if (xml->Attribute("count"))
- texCount = boost::lexical_cast<int>(xml->Attribute("count"));
- else
- {
- std::cout << "<accessor> has no count attribute in texture coordinate element "
- << "with id[" << _id << "]\n";
- return;
- }
+ // \TODO This is a good a GZ_ASSERT
+ // The total number of texture values should equal the stride multiplied
+ // by the number of texture coordinates.
+ if (texCount * stride != totCount)
+ {
+ std::cout << "Error reading texture coordinates. Coordinate counts in element "
+ "with id[" << _id << "] do not add up correctly\n";
+ return;
+ }
- // \TODO This is a good a GZ_ASSERT
- // The total number of texture values should equal the stride multiplied
- // by the number of texture coordinates.
- if (texCount * stride != totCount)
- {
- std::cout << "Error reading texture coordinates. Coordinate counts in element "
- "with id[" << _id << "] do not add up correctly\n";
- return;
- }
+ // Read the raw texture values, and split them on spaces.
+ std::string valueStr = floatArrayXml->GetText();
+ std::vector<std::string> values;
+ boost::split(values, valueStr, boost::is_any_of(" "));
- // Read the raw texture values, and split them on spaces.
- std::string valueStr = floatArrayXml->GetText();
- std::vector<std::string> values;
- boost::split(values, valueStr, boost::is_any_of(" "));
+ // Read in all the texture coordinates.
+ for (int i = 0; i < totCount; i += stride)
+ {
+ // We only handle 2D texture coordinates right now.
+ _values.push_back(math::Vector2d(boost::lexical_cast<double>(values[i]),
+ 1.0 - boost::lexical_cast<double>(values[i+1])));
+ }
+ }
- // Read in all the texture coordinates.
- for (int i = 0; i < totCount; i += stride)
- {
- // We only handle 2D texture coordinates right now.
- _values.push_back(math::Vector2d(boost::lexical_cast<double>(values[i]),
- 1.0 - boost::lexical_cast<double>(values[i+1])));
- }
-}
+ /////////////////////////////////////////////////
+ void ColladaParser::loadTriangles(TiXmlElement *_trianglesXml,
+ const math::Matriz4x4 &_transform,
+ Malla *_mesh)
+ {
+ SubMalla *subMalla = new SubMalla;
+ subMalla->setName(this->currentNodeName);
+ bool combinedVertNorms = false;
-/////////////////////////////////////////////////
-void ColladaParser::loadTriangles(TiXmlElement *_trianglesXml,
- const math::Matriz4x4 &_transform,
- Malla *_mesh)
-{
- SubMalla *subMalla = new SubMalla;
- subMalla->setName(this->currentNodeName);
- bool combinedVertNorms = false;
+ subMalla->setPrimitiveType(SubMalla::TRIANGLES);
- subMalla->setPrimitiveType(SubMalla::TRIANGLES);
+ if (_trianglesXml->Attribute("material"))
+ {
+ std::map<std::string, std::string>::iterator iter;
+ std::string matStr = _trianglesXml->Attribute("material");
- if (_trianglesXml->Attribute("material"))
- {
- std::map<std::string, std::string>::iterator iter;
- std::string matStr = _trianglesXml->Attribute("material");
+ iter = this->materialMap.find(matStr);
+ if (iter != this->materialMap.end())
+ matStr = iter->second;
- iter = this->materialMap.find(matStr);
- if (iter != this->materialMap.end())
- matStr = iter->second;
+ int matIndex = _mesh->addMaterial(this->loadMaterial(matStr));
+ if (matIndex < 0)
+ std::cout << "Unable to add material[" << matStr << "]\n";
+ else
+ subMalla->setMaterialIndex(matIndex);
+ }
- int matIndex = _mesh->addMaterial(this->loadMaterial(matStr));
- if (matIndex < 0)
- std::cout << "Unable to add material[" << matStr << "]\n";
- else
- subMalla->setMaterialIndex(matIndex);
- }
+ TiXmlElement *trianglesInputXml = _trianglesXml->FirstChildElement("input");
- TiXmlElement *trianglesInputXml = _trianglesXml->FirstChildElement("input");
+ std::vector<math::Vector3> verts;
+ std::vector<math::Vector3> norms;
+ std::vector<math::Vector2d> texcoords;
- std::vector<math::Vector3> verts;
- std::vector<math::Vector3> norms;
- std::vector<math::Vector2d> texcoords;
+ // A list of all the input values.
+ std::list<std::pair<std::string, int> > inputs;
+ while (trianglesInputXml)
+ {
+ std::string semantic = trianglesInputXml->Attribute("semantic");
+ std::string source = trianglesInputXml->Attribute("source");
+ std::string offset = trianglesInputXml->Attribute("offset");
+ if (semantic == "VERTEX")
+ {
+ unsigned int count = norms.size();
+ this->loadVertices(source, _transform, verts, norms);
+ if (norms.size() > count)
+ combinedVertNorms = true;
+ }
+ else if (semantic == "NORMAL")
+ {
+ this->loadNormals(source, _transform, norms);
+ combinedVertNorms = false;
+ }
+ else if (semantic == "TEXCOORD")
+ this->loadTexCoords(source, texcoords);
- // A list of all the input values.
- std::list<std::pair<std::string, int> > inputs;
- while (trianglesInputXml)
- {
- std::string semantic = trianglesInputXml->Attribute("semantic");
- std::string source = trianglesInputXml->Attribute("source");
- std::string offset = trianglesInputXml->Attribute("offset");
- if (semantic == "VERTEX")
- {
- unsigned int count = norms.size();
- this->loadVertices(source, _transform, verts, norms);
- if (norms.size() > count)
- combinedVertNorms = true;
- }
- else if (semantic == "NORMAL")
- {
- this->loadNormals(source, _transform, norms);
- combinedVertNorms = false;
- }
- else if (semantic == "TEXCOORD")
- this->loadTexCoords(source, texcoords);
+ inputs.push_back(std::make_pair(semantic, math::parseInt(offset)));
- inputs.push_back(std::make_pair(semantic, math::parseInt(offset)));
+ trianglesInputXml = trianglesInputXml->NextSiblingElement("input");
+ }
- trianglesInputXml = trianglesInputXml->NextSiblingElement("input");
- }
+ TiXmlElement *pXml = _trianglesXml->FirstChildElement("p");
+ if (!pXml || !pXml->GetText())
+ {
+ std::cout << "Collada file[" << this->filename
+ << "] is invalid. Loading what we can...\n";
+ return;
+ }
+ std::string pStr = pXml->GetText();
- TiXmlElement *pXml = _trianglesXml->FirstChildElement("p");
- if (!pXml || !pXml->GetText())
- {
- std::cout << "Collada file[" << this->filename
- << "] is invalid. Loading what we can...\n";
- return;
- }
- std::string pStr = pXml->GetText();
+ std::vector<math::Vector3> vertNorms(verts.size());
+ std::vector<int> vertNormsCounts(verts.size());
+ std::fill(vertNormsCounts.begin(), vertNormsCounts.end(), 0);
- std::vector<math::Vector3> vertNorms(verts.size());
- std::vector<int> vertNormsCounts(verts.size());
- std::fill(vertNormsCounts.begin(), vertNormsCounts.end(), 0);
+ int *values = new int[inputs.size()];
+ std::list<std::pair<std::string, int> >::iterator end = inputs.end();
+ std::list<std::pair<std::string, int> >::iterator iter;
+ math::Vector2d vec;
- int *values = new int[inputs.size()];
- std::list<std::pair<std::string, int> >::iterator end = inputs.end();
- std::list<std::pair<std::string, int> >::iterator iter;
- math::Vector2d vec;
+ std::vector<std::string> strs;
+ boost::split(strs, pStr, boost::is_any_of(" "));
- std::vector<std::string> strs;
- boost::split(strs, pStr, boost::is_any_of(" "));
+ for (unsigned int j = 0; j < strs.size(); j += inputs.size())
+ {
+ for (unsigned int i = 0; i < inputs.size(); i++)
+ values[i] = math::parseInt(strs[j+i]);
- for (unsigned int j = 0; j < strs.size(); j += inputs.size())
- {
- for (unsigned int i = 0; i < inputs.size(); i++)
- values[i] = math::parseInt(strs[j+i]);
+ bool already = false;
+ for (iter = inputs.begin(); iter != end; ++iter)
+ {
+ if ((*iter).first == "VERTEX")
+ {
+ subMalla->addVertex(verts[values[(*iter).second]]);
+ subMalla->addIndex(subMalla->getVertexCount()-1);
+ if (combinedVertNorms)
+ subMalla->addNormal(norms[values[(*iter).second]]);
+ // if (_mesh->HasSkeleton())
+ // {
+ // Skeleton *skel = _mesh->GetSkeleton();
+ // for (unsigned int i = 0;
+ // i < skel->GetNumVertNodeWeights(values[(*iter).second]); i++)
+ // {
+ // std::pair<std::string, double> node_weight =
+ // skel->GetVertNodeWeight(values[(*iter).second], i);
+ // SkeletonNode *node =
+ // _mesh->GetSkeleton()->GetNodeByName(node_weight.first);
+ // SubMalla->AddNodeAssignment(SubMalla->GetVertexCount()-1,
+ // node->GetHandle(), node_weight.second);
+ // }
+ // }
+ }
+ else if ((*iter).first == "NORMAL")
+ {
+ subMalla->addNormal(norms[values[(*iter).second]]);
+ }
+ else if ((*iter).first == "TEXCOORD" && !already)
+ {
+ already = true;
+ subMalla->addTexCoord(texcoords[values[(*iter).second]].getX(),
+ texcoords[values[(*iter).second]].getY());
+ }
+ // else
+ // gzerr << "Unhandled semantic[" << (*iter).first << "]\n";
+ }
+ }
+ delete [] values;
- bool already = false;
- for (iter = inputs.begin(); iter != end; ++iter)
+ _mesh->addSubMalla(subMalla);
+ }
+
+ /////////////////////////////////////////////////
+ void ColladaParser::loadController(TiXmlElement *_contrXml,
+ TiXmlElement *_skelXml, const math::Matriz4x4 _transform, Malla *_mesh)
{
- if ((*iter).first == "VERTEX")
- {
- subMalla->addVertex(verts[values[(*iter).second]]);
- subMalla->addIndex(subMalla->getVertexCount()-1);
- if (combinedVertNorms)
- subMalla->addNormal(norms[values[(*iter).second]]);
-// if (_mesh->HasSkeleton())
-// {
-// Skeleton *skel = _mesh->GetSkeleton();
-// for (unsigned int i = 0;
-// i < skel->GetNumVertNodeWeights(values[(*iter).second]); i++)
-// {
-// std::pair<std::string, double> node_weight =
-// skel->GetVertNodeWeight(values[(*iter).second], i);
-// SkeletonNode *node =
-// _mesh->GetSkeleton()->GetNodeByName(node_weight.first);
-// SubMalla->AddNodeAssignment(SubMalla->GetVertexCount()-1,
-// node->GetHandle(), node_weight.second);
-// }
-// }
- }
- else if ((*iter).first == "NORMAL")
- {
- subMalla->addNormal(norms[values[(*iter).second]]);
- }
- else if ((*iter).first == "TEXCOORD" && !already)
- {
- already = true;
- subMalla->addTexCoord(texcoords[values[(*iter).second]].getX(),
- texcoords[values[(*iter).second]].getY());
- }
- // else
- // gzerr << "Unhandled semantic[" << (*iter).first << "]\n";
}
- }
- delete [] values;
+ //{
+ // Skeleton *skeleton = new Skeleton(this->LoadSkeletonNodes(_skelXml, NULL));
+ // _mesh->SetSkeleton(skeleton);
- _mesh->addSubMalla(subMalla);
-}
+ // TiXmlElement *rootXml = _contrXml->GetDocument()->RootElement();
-/////////////////////////////////////////////////
-void ColladaParser::loadController(TiXmlElement *_contrXml,
- TiXmlElement *_skelXml, const math::Matriz4x4 _transform, Malla *_mesh)
-{
-}
-//{
-// Skeleton *skeleton = new Skeleton(this->LoadSkeletonNodes(_skelXml, NULL));
-// _mesh->SetSkeleton(skeleton);
+ // if (rootXml->FirstChildElement("library_animations"))
+ // this->LoadAnimations(rootXml->FirstChildElement("library_animations"),
+ // skeleton);
-// TiXmlElement *rootXml = _contrXml->GetDocument()->RootElement();
+ // TiXmlElement *skinXml = _contrXml->FirstChildElement("skin");
+ // std::string geomURL = skinXml->Attribute("source");
-// if (rootXml->FirstChildElement("library_animations"))
-// this->LoadAnimations(rootXml->FirstChildElement("library_animations"),
-// skeleton);
+ // math::Matrix4 bindTrans;
+ // std::string matrixStr =
+ // skinXml->FirstChildElement("bind_shape_matrix")->GetText();
+ // std::istringstream iss(matrixStr);
+ // std::vector<double> values(16);
+ // for (unsigned int i = 0; i < 16; i++)
+ // iss >> values[i];
+ // bindTrans.Set(values[0], values[1], values[2], values[3],
+ // values[4], values[5], values[6], values[7],
+ // values[8], values[9], values[10], values[11],
+ // values[12], values[13], values[14], values[15]);
-// TiXmlElement *skinXml = _contrXml->FirstChildElement("skin");
-// std::string geomURL = skinXml->Attribute("source");
+ // skeleton->SetBindShapeTransform(bindTrans);
-// math::Matrix4 bindTrans;
-// std::string matrixStr =
-// skinXml->FirstChildElement("bind_shape_matrix")->GetText();
-// std::istringstream iss(matrixStr);
-// std::vector<double> values(16);
-// for (unsigned int i = 0; i < 16; i++)
-// iss >> values[i];
-// bindTrans.Set(values[0], values[1], values[2], values[3],
-// values[4], values[5], values[6], values[7],
-// values[8], values[9], values[10], values[11],
-// values[12], values[13], values[14], values[15]);
+ // TiXmlElement *jointsXml = skinXml->FirstChildElement("joints");
+ // std::string jointsURL, invBindMatURL;
+ // TiXmlElement *inputXml = jointsXml->FirstChildElement("input");
+ // while (inputXml)
+ // {
+ // std::string semantic = inputXml->Attribute("semantic");
+ // std::string source = inputXml->Attribute("source");
+ // if (semantic == "JOINT")
+ // jointsURL = source;
+ // else
+ // {
+ // if (semantic == "INV_BIND_MATRIX")
+ // invBindMatURL = source;
+ // }
+ // inputXml = inputXml->NextSiblingElement("input");
+ // }
-// skeleton->SetBindShapeTransform(bindTrans);
+ // jointsXml = this->GetElementId("source", jointsURL);
-// TiXmlElement *jointsXml = skinXml->FirstChildElement("joints");
-// std::string jointsURL, invBindMatURL;
-// TiXmlElement *inputXml = jointsXml->FirstChildElement("input");
-// while (inputXml)
-// {
-// std::string semantic = inputXml->Attribute("semantic");
-// std::string source = inputXml->Attribute("source");
-// if (semantic == "JOINT")
-// jointsURL = source;
-// else
-// {
-// if (semantic == "INV_BIND_MATRIX")
-// invBindMatURL = source;
-// }
-// inputXml = inputXml->NextSiblingElement("input");
-// }
+ // if (!jointsXml)
+ // {
+ // gzerr << "Could not find node[" << jointsURL << "]\n";
+ // gzthrow("Faild to parse skinning information in Collada file.");
+ // }
-// jointsXml = this->GetElementId("source", jointsURL);
+ // std::string jointsStr = jointsXml->FirstChildElement("Name_array")->GetText();
-// if (!jointsXml)
-// {
-// gzerr << "Could not find node[" << jointsURL << "]\n";
-// gzthrow("Faild to parse skinning information in Collada file.");
-// }
+ // std::vector<std::string> joints;
+ // boost::split(joints, jointsStr, boost::is_any_of(" "));
-// std::string jointsStr = jointsXml->FirstChildElement("Name_array")->GetText();
+ // TiXmlElement *invBMXml = this->GetElementId("source", invBindMatURL);
-// std::vector<std::string> joints;
-// boost::split(joints, jointsStr, boost::is_any_of(" "));
+ // if (!invBMXml)
+ // {
+ // gzerr << "Could not find node[" << invBindMatURL << "]\n";
+ // gzthrow("Faild to parse skinning information in Collada file.");
+ // }
-// TiXmlElement *invBMXml = this->GetElementId("source", invBindMatURL);
+ // std::string posesStr = invBMXml->FirstChildElement("float_array")->GetText();
-// if (!invBMXml)
-// {
-// gzerr << "Could not find node[" << invBindMatURL << "]\n";
-// gzthrow("Faild to parse skinning information in Collada file.");
-// }
+ // std::vector<std::string> strs;
+ // boost::split(strs, posesStr, boost::is_any_of(" "));
-// std::string posesStr = invBMXml->FirstChildElement("float_array")->GetText();
+ // for (unsigned int i = 0; i < joints.size(); i++)
+ // {
+ // unsigned int id = i * 16;
+ // math::Matrix4 mat;
+ // mat.Set(math::parseFloat(strs[id + 0]), math::parseFloat(strs[id + 1]),
+ // math::parseFloat(strs[id + 2]), math::parseFloat(strs[id + 3]),
+ // math::parseFloat(strs[id + 4]), math::parseFloat(strs[id + 5]),
+ // math::parseFloat(strs[id + 6]), math::parseFloat(strs[id + 7]),
+ // math::parseFloat(strs[id + 8]), math::parseFloat(strs[id + 9]),
+ // math::parseFloat(strs[id + 10]), math::parseFloat(strs[id + 11]),
+ // math::parseFloat(strs[id + 12]), math::parseFloat(strs[id + 13]),
+ // math::parseFloat(strs[id + 14]), math::parseFloat(strs[id + 15]));
-// std::vector<std::string> strs;
-// boost::split(strs, posesStr, boost::is_any_of(" "));
+ // skeleton->GetNodeByName(joints[i])->SetInverseBindTransform(mat);
+ // }
-// for (unsigned int i = 0; i < joints.size(); i++)
-// {
-// unsigned int id = i * 16;
-// math::Matrix4 mat;
-// mat.Set(math::parseFloat(strs[id + 0]), math::parseFloat(strs[id + 1]),
-// math::parseFloat(strs[id + 2]), math::parseFloat(strs[id + 3]),
-// math::parseFloat(strs[id + 4]), math::parseFloat(strs[id + 5]),
-// math::parseFloat(strs[id + 6]), math::parseFloat(strs[id + 7]),
-// math::parseFloat(strs[id + 8]), math::parseFloat(strs[id + 9]),
-// math::parseFloat(strs[id + 10]), math::parseFloat(strs[id + 11]),
-// math::parseFloat(strs[id + 12]), math::parseFloat(strs[id + 13]),
-// math::parseFloat(strs[id + 14]), math::parseFloat(strs[id + 15]));
+ // TiXmlElement *vertWeightsXml = skinXml->FirstChildElement("vertex_weights");
-// skeleton->GetNodeByName(joints[i])->SetInverseBindTransform(mat);
-// }
+ // inputXml = vertWeightsXml->FirstChildElement("input");
+ // unsigned int jOffset = 0;
+ // unsigned int wOffset = 0;
+ // std::string weightsURL;
+ // while (inputXml)
+ // {
+ // std::string semantic = inputXml->Attribute("semantic");
+ // std::string source = inputXml->Attribute("source");
+ // int offset;
+ // inputXml->Attribute("offset", &offset);
-// TiXmlElement *vertWeightsXml = skinXml->FirstChildElement("vertex_weights");
+ // if (semantic == "JOINT")
+ // jOffset = offset;
+ // else
+ // if (semantic == "WEIGHT")
+ // {
+ // weightsURL = source;
+ // wOffset = offset;
+ // }
+ // inputXml = inputXml->NextSiblingElement("input");
+ // }
-// inputXml = vertWeightsXml->FirstChildElement("input");
-// unsigned int jOffset = 0;
-// unsigned int wOffset = 0;
-// std::string weightsURL;
-// while (inputXml)
-// {
-// std::string semantic = inputXml->Attribute("semantic");
-// std::string source = inputXml->Attribute("source");
-// int offset;
-// inputXml->Attribute("offset", &offset);
+ // TiXmlElement *weightsXml = this->GetElementId("source", weightsURL);
-// if (semantic == "JOINT")
-// jOffset = offset;
-// else
-// if (semantic == "WEIGHT")
-// {
-// weightsURL = source;
-// wOffset = offset;
-// }
-// inputXml = inputXml->NextSiblingElement("input");
-// }
+ // std::string wString = weightsXml->FirstChildElement("float_array")->GetText();
+ // std::vector<std::string> wStrs;
+ // boost::split(wStrs, wString, boost::is_any_of(" "));
-// TiXmlElement *weightsXml = this->GetElementId("source", weightsURL);
+ // std::vector<float> weights;
+ // for (unsigned int i = 0; i < wStrs.size(); i++)
+ // weights.push_back(math::parseFloat(wStrs[i]));
-// std::string wString = weightsXml->FirstChildElement("float_array")->GetText();
-// std::vector<std::string> wStrs;
-// boost::split(wStrs, wString, boost::is_any_of(" "));
+ // std::string cString = vertWeightsXml->FirstChildElement("vcount")->GetText();
+ // std::string vString = vertWeightsXml->FirstChildElement("v")->GetText();
+ // std::vector<std::string> vCountStrs;
+ // std::vector<std::string> vStrs;
-// std::vector<float> weights;
-// for (unsigned int i = 0; i < wStrs.size(); i++)
-// weights.push_back(math::parseFloat(wStrs[i]));
+ // boost::split(vCountStrs, cString, boost::is_any_of(" "));
+ // boost::split(vStrs, vString, boost::is_any_of(" "));
-// std::string cString = vertWeightsXml->FirstChildElement("vcount")->GetText();
-// std::string vString = vertWeightsXml->FirstChildElement("v")->GetText();
-// std::vector<std::string> vCountStrs;
-// std::vector<std::string> vStrs;
+ // std::vector<unsigned int> vCount;
+ // std::vector<unsigned int> v;
-// boost::split(vCountStrs, cString, boost::is_any_of(" "));
-// boost::split(vStrs, vString, boost::is_any_of(" "));
+ // for (unsigned int i = 0; i < vCountStrs.size(); i++)
+ // vCount.push_back(math::parseInt(vCountStrs[i]));
-// std::vector<unsigned int> vCount;
-// std::vector<unsigned int> v;
+ // for (unsigned int i = 0; i < vStrs.size(); i++)
+ // v.push_back(math::parseInt(vStrs[i]));
-// for (unsigned int i = 0; i < vCountStrs.size(); i++)
-// vCount.push_back(math::parseInt(vCountStrs[i]));
+ // skeleton->SetNumVertAttached(vCount.size());
-// for (unsigned int i = 0; i < vStrs.size(); i++)
-// v.push_back(math::parseInt(vStrs[i]));
+ // unsigned int vIndex = 0;
+ // for (unsigned int i = 0; i < vCount.size(); i++)
+ // {
+ // for (unsigned int j = 0; j < vCount[i]; j++)
+ // {
+ // skeleton->AddVertNodeWeight(i, joints[v[vIndex + jOffset]],
+ // weights[v[vIndex + wOffset]]);
+ // vIndex += (jOffset + wOffset + 1);
+ // }
+ // }
-// skeleton->SetNumVertAttached(vCount.size());
+ // TiXmlElement *geomXml = this->GetElementId("geometry", geomURL);
+ // this->LoadGeometry(geomXml, _transform, _mesh);
+ //}
-// unsigned int vIndex = 0;
-// for (unsigned int i = 0; i < vCount.size(); i++)
-// {
-// for (unsigned int j = 0; j < vCount[i]; j++)
-// {
-// skeleton->AddVertNodeWeight(i, joints[v[vIndex + jOffset]],
-// weights[v[vIndex + wOffset]]);
-// vIndex += (jOffset + wOffset + 1);
-// }
-// }
+ /////////////////////////////////////////////////
+ void ColladaParser::loadColorOrTexture(TiXmlElement *_elem,
+ const std::string &_type, Material *_mat)
+ {
+ if (!_elem || !_elem->FirstChildElement(_type))
+ return;
-// TiXmlElement *geomXml = this->GetElementId("geometry", geomURL);
-// this->LoadGeometry(geomXml, _transform, _mesh);
-//}
+ TiXmlElement *typeElem = _elem->FirstChildElement(_type);
-/////////////////////////////////////////////////
-void ColladaParser::loadColorOrTexture(TiXmlElement *_elem,
- const std::string &_type, Material *_mat)
-{
- if (!_elem || !_elem->FirstChildElement(_type))
- return;
-
- TiXmlElement *typeElem = _elem->FirstChildElement(_type);
-
- if (typeElem->FirstChildElement("color"))
- {
- std::string colorStr = typeElem->FirstChildElement("color")->GetText();
- Color color = boost::lexical_cast<Color>(colorStr);
- if (_type == "diffuse")
- _mat->setDiffuse(color);
- else if (_type == "ambient")
- _mat->setAmbient(color);
- else if (_type == "emission")
- _mat->setEmissive(color);
- }
- else if (typeElem->FirstChildElement("texture"))
- {
- TiXmlElement *imageXml = NULL;
- std::string textureName =
- typeElem->FirstChildElement("texture")->Attribute("texture");
- TiXmlElement *textureXml = this->getElementId("newparam", textureName);
- if (textureXml)
- {
- if (std::string(textureXml->Value()) == "image")
+ if (typeElem->FirstChildElement("color"))
{
- imageXml = textureXml;
+ std::string colorStr = typeElem->FirstChildElement("color")->GetText();
+ Color color = boost::lexical_cast<Color>(colorStr);
+ if (_type == "diffuse")
+ _mat->setDiffuse(color);
+ else if (_type == "ambient")
+ _mat->setAmbient(color);
+ else if (_type == "emission")
+ _mat->setEmissive(color);
}
- else
+ else if (typeElem->FirstChildElement("texture"))
{
- TiXmlElement *sampler = textureXml->FirstChildElement("sampler2D");
- if (sampler)
+ TiXmlElement *imageXml = NULL;
+ std::string textureName =
+ typeElem->FirstChildElement("texture")->Attribute("texture");
+ TiXmlElement *textureXml = this->getElementId("newparam", textureName);
+ if (textureXml)
{
- std::string sourceName =
- sampler->FirstChildElement("source")->GetText();
- TiXmlElement *sourceXml = this->getElementId("newparam", sourceName);
- if (sourceXml)
+ if (std::string(textureXml->Value()) == "image")
{
- TiXmlElement *surfaceXml = sourceXml->FirstChildElement("surface");
- if (surfaceXml && surfaceXml->FirstChildElement("init_from"))
+ imageXml = textureXml;
+ }
+ else
+ {
+ TiXmlElement *sampler = textureXml->FirstChildElement("sampler2D");
+ if (sampler)
{
- imageXml = this->getElementId("image",
- surfaceXml->FirstChildElement("init_from")->GetText());
+ std::string sourceName =
+ sampler->FirstChildElement("source")->GetText();
+ TiXmlElement *sourceXml = this->getElementId("newparam", sourceName);
+ if (sourceXml)
+ {
+ TiXmlElement *surfaceXml = sourceXml->FirstChildElement("surface");
+ if (surfaceXml && surfaceXml->FirstChildElement("init_from"))
+ {
+ imageXml = this->getElementId("image",
+ surfaceXml->FirstChildElement("init_from")->GetText());
+ }
+ }
}
}
}
+ else
+ {
+ imageXml = this->getElementId("image", textureName);
+ }
+
+ if (imageXml && imageXml->FirstChildElement("init_from"))
+ {
+ std::string imgFile =
+ imageXml->FirstChildElement("init_from")->GetText();
+
+ _mat->setTextureImage(imgFile, this->path);
+ }
}
}
- else
+
+ float ColladaParser::loadFloat(TiXmlElement *_elem)
{
- imageXml = this->getElementId("image", textureName);
+ float value = 0;
+
+ if (_elem->FirstChildElement("float"))
+ {
+ value = math::parseFloat(_elem->FirstChildElement("float")->GetText());
+ }
+
+ return value;
}
- if (imageXml && imageXml->FirstChildElement("init_from"))
+ /////////////////////////////////////////////////
+ void ColladaParser::loadTransparent(TiXmlElement *_elem, Material *_mat)
{
- std::string imgFile =
- imageXml->FirstChildElement("init_from")->GetText();
+ const char *opaqueCStr = _elem->Attribute("opaque");
+ if (!opaqueCStr)
+ {
+ // gzerr << "No Opaque set\n";
+ return;
+ }
- _mat->setTextureImage(imgFile, this->path);
- }
- }
-}
+ // TODO: Handle transparent textures
+ if (_elem->FirstChildElement("color"))
+ {
+ const char *colorCStr = _elem->FirstChildElement("color")->GetText();
+ if (!colorCStr)
+ {
+ std::cout << "No color string\n";
+ return;
+ }
-float ColladaParser::loadFloat(TiXmlElement *_elem)
-{
- float value = 0;
+ std::string opaqueStr = opaqueCStr;
+ std::string colorStr = colorCStr;
+ Color color = boost::lexical_cast<Color>(colorStr);
- if (_elem->FirstChildElement("float"))
- {
- value = math::parseFloat(_elem->FirstChildElement("float")->GetText());
- }
+ double srcFactor = 0;
+ double dstFactor = 0;
- return value;
-}
+ if (opaqueStr == "RGB_ZERO")
+ {
+ srcFactor = color.r * _mat->getTransparency();
+ dstFactor = 1.0 - color.r * _mat->getTransparency();
+ }
+ else if (opaqueStr == "A_ONE")
+ {
+ srcFactor = 1.0 - color.a * _mat->getTransparency();
+ dstFactor = color.a * _mat->getTransparency();
+ }
-/////////////////////////////////////////////////
-void ColladaParser::loadTransparent(TiXmlElement *_elem, Material *_mat)
-{
- const char *opaqueCStr = _elem->Attribute("opaque");
- if (!opaqueCStr)
- {
- // gzerr << "No Opaque set\n";
- return;
- }
-
- // TODO: Handle transparent textures
- if (_elem->FirstChildElement("color"))
- {
- const char *colorCStr = _elem->FirstChildElement("color")->GetText();
- if (!colorCStr)
- {
- std::cout << "No color string\n";
- return;
+ _mat->setBlendFactors(srcFactor, dstFactor);
+ }
}
- std::string opaqueStr = opaqueCStr;
- std::string colorStr = colorCStr;
- Color color = boost::lexical_cast<Color>(colorStr);
- double srcFactor = 0;
- double dstFactor = 0;
-
- if (opaqueStr == "RGB_ZERO")
+ /////////////////////////////////////////////////
+ Material *ColladaParser::loadMaterial(const std::string &_name)
{
- srcFactor = color.r * _mat->getTransparency();
- dstFactor = 1.0 - color.r * _mat->getTransparency();
- }
- else if (opaqueStr == "A_ONE")
- {
- srcFactor = 1.0 - color.a * _mat->getTransparency();
- dstFactor = color.a * _mat->getTransparency();
- }
+ TiXmlElement *matXml = this->getElementId("material", _name);
+ if (!matXml || !matXml->FirstChildElement("instance_effect"))
+ return NULL;
- _mat->setBlendFactors(srcFactor, dstFactor);
- }
-}
+ Material *mat = new Material();
+ std::string effectName =
+ matXml->FirstChildElement("instance_effect")->Attribute("url");
+ TiXmlElement *effectXml = this->getElementId("effect", effectName);
+ TiXmlElement *commonXml = effectXml->FirstChildElement("profile_COMMON");
+ if (commonXml)
+ {
+ TiXmlElement *techniqueXml = commonXml->FirstChildElement("technique");
+ TiXmlElement *lambertXml = techniqueXml->FirstChildElement("lambert");
-/////////////////////////////////////////////////
-Material *ColladaParser::loadMaterial(const std::string &_name)
-{
- TiXmlElement *matXml = this->getElementId("material", _name);
- if (!matXml || !matXml->FirstChildElement("instance_effect"))
- return NULL;
+ TiXmlElement *phongXml = techniqueXml->FirstChildElement("phong");
+ TiXmlElement *blinnXml = techniqueXml->FirstChildElement("blinn");
+ if (lambertXml)
+ {
+ this->loadColorOrTexture(lambertXml, "ambient", mat);
+ this->loadColorOrTexture(lambertXml, "emission", mat);
+ this->loadColorOrTexture(lambertXml, "diffuse", mat);
+ if (lambertXml->FirstChildElement("transparency"))
+ {
+ mat->setTransparency(
+ this->loadFloat(lambertXml->FirstChildElement("transparency")));
+ }
- Material *mat = new Material();
- std::string effectName =
- matXml->FirstChildElement("instance_effect")->Attribute("url");
- TiXmlElement *effectXml = this->getElementId("effect", effectName);
+ if (lambertXml->FirstChildElement("transparent"))
+ {
+ TiXmlElement *transXml = lambertXml->FirstChildElement("transparent");
+ this->loadTransparent(transXml, mat);
+ }
+ }
+ else if (phongXml)
+ {
+ this->loadColorOrTexture(phongXml, "ambient", mat);
+ this->loadColorOrTexture(phongXml, "emission", mat);
+ this->loadColorOrTexture(phongXml, "specular", mat);
+ this->loadColorOrTexture(phongXml, "diffuse", mat);
+ if (phongXml->FirstChildElement("shininess"))
+ mat->setShininess(
+ this->loadFloat(phongXml->FirstChildElement("shininess")));
- TiXmlElement *commonXml = effectXml->FirstChildElement("profile_COMMON");
- if (commonXml)
- {
- TiXmlElement *techniqueXml = commonXml->FirstChildElement("technique");
- TiXmlElement *lambertXml = techniqueXml->FirstChildElement("lambert");
+ if (phongXml->FirstChildElement("transparency"))
+ mat->setTransparency(
+ this->loadFloat(phongXml->FirstChildElement("transparency")));
+ if (phongXml->FirstChildElement("transparent"))
+ {
+ TiXmlElement *transXml = phongXml->FirstChildElement("transparent");
+ this->loadTransparent(transXml, mat);
+ }
+ }
+ else if (blinnXml)
+ {
+ this->loadColorOrTexture(blinnXml, "ambient", mat);
+ this->loadColorOrTexture(blinnXml, "emission", mat);
+ this->loadColorOrTexture(blinnXml, "specular", mat);
+ this->loadColorOrTexture(blinnXml, "diffuse", mat);
+ if (blinnXml->FirstChildElement("shininess"))
+ mat->setShininess(
+ this->loadFloat(blinnXml->FirstChildElement("shininess")));
- TiXmlElement *phongXml = techniqueXml->FirstChildElement("phong");
- TiXmlElement *blinnXml = techniqueXml->FirstChildElement("blinn");
- if (lambertXml)
- {
- this->loadColorOrTexture(lambertXml, "ambient", mat);
- this->loadColorOrTexture(lambertXml, "emission", mat);
- this->loadColorOrTexture(lambertXml, "diffuse", mat);
- if (lambertXml->FirstChildElement("transparency"))
- {
- mat->setTransparency(
- this->loadFloat(lambertXml->FirstChildElement("transparency")));
+ if (blinnXml->FirstChildElement("transparency"))
+ mat->setTransparency(
+ this->loadFloat(blinnXml->FirstChildElement("transparency")));
+ if (blinnXml->FirstChildElement("transparent"))
+ {
+ TiXmlElement *transXml = blinnXml->FirstChildElement("transparent");
+ this->loadTransparent(transXml, mat);
+ }
+ }
}
- if (lambertXml->FirstChildElement("transparent"))
- {
- TiXmlElement *transXml = lambertXml->FirstChildElement("transparent");
- this->loadTransparent(transXml, mat);
- }
- }
- else if (phongXml)
- {
- this->loadColorOrTexture(phongXml, "ambient", mat);
- this->loadColorOrTexture(phongXml, "emission", mat);
- this->loadColorOrTexture(phongXml, "specular", mat);
- this->loadColorOrTexture(phongXml, "diffuse", mat);
- if (phongXml->FirstChildElement("shininess"))
- mat->setShininess(
- this->loadFloat(phongXml->FirstChildElement("shininess")));
+ TiXmlElement *glslXml = effectXml->FirstChildElement("profile_GLSL");
+ if (glslXml)
+ std::cout << "profile_GLSL unsupported\n";
- if (phongXml->FirstChildElement("transparency"))
- mat->setTransparency(
- this->loadFloat(phongXml->FirstChildElement("transparency")));
- if (phongXml->FirstChildElement("transparent"))
- {
- TiXmlElement *transXml = phongXml->FirstChildElement("transparent");
- this->loadTransparent(transXml, mat);
- }
+ TiXmlElement *cgXml = effectXml->FirstChildElement("profile_CG");
+ if (cgXml)
+ std::cout << "profile_CG unsupported\n";
+ return mat;
}
- else if (blinnXml)
- {
- this->loadColorOrTexture(blinnXml, "ambient", mat);
- this->loadColorOrTexture(blinnXml, "emission", mat);
- this->loadColorOrTexture(blinnXml, "specular", mat);
- this->loadColorOrTexture(blinnXml, "diffuse", mat);
- if (blinnXml->FirstChildElement("shininess"))
- mat->setShininess(
- this->loadFloat(blinnXml->FirstChildElement("shininess")));
-
- if (blinnXml->FirstChildElement("transparency"))
- mat->setTransparency(
- this->loadFloat(blinnXml->FirstChildElement("transparency")));
- if (blinnXml->FirstChildElement("transparent"))
- {
- TiXmlElement *transXml = blinnXml->FirstChildElement("transparent");
- this->loadTransparent(transXml, mat);
- }
- }
- }
-
- TiXmlElement *glslXml = effectXml->FirstChildElement("profile_GLSL");
- if (glslXml)
- std::cout << "profile_GLSL unsupported\n";
-
- TiXmlElement *cgXml = effectXml->FirstChildElement("profile_CG");
- if (cgXml)
- std::cout << "profile_CG unsupported\n";
- return mat;
}
Modified: trunk/src/libs/geometry/collada/colladaparser.h
===================================================================
--- trunk/src/libs/geometry/collada/colladaparser.h 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/colladaparser.h 2013-06-05 16:10:12 UTC (rev 930)
@@ -22,86 +22,88 @@
#include <GL/glut.h>
#include <GL/gl.h>
+namespace files_3D {
-class ColladaParser
-{
-public:
- ColladaParser(std::string filename);
+ class ColladaParser
+ {
+ public:
+ ColladaParser(std::string filename);
- void loadScene(Malla *_mesh);
+ void loadScene(Malla *_mesh);
- void draw();
+ void draw();
- TiXmlElement *getElementId(const std::string &_name,
- const std::string &_id);
+ TiXmlElement *getElementId(const std::string &_name,
+ const std::string &_id);
- TiXmlElement *getElementId(TiXmlElement *_parent,
- const std::string &_name,
- const std::string &_id);
+ TiXmlElement *getElementId(TiXmlElement *_parent,
+ const std::string &_name,
+ const std::string &_id);
- float loadFloat(TiXmlElement *_elem);
- void loadTransparent(TiXmlElement *_elem, Material *_mat);
+ float loadFloat(TiXmlElement *_elem);
+ void loadTransparent(TiXmlElement *_elem, Material *_mat);
- void loadNode(TiXmlElement *_elem,
- Malla *_mesh,
- const math::Matriz4x4 &_transform);
+ void loadNode(TiXmlElement *_elem,
+ Malla *_mesh,
+ const math::Matriz4x4 &_transform);
- void loadColorOrTexture(TiXmlElement *_elem,
- const std::string &_type, Material *_mat);
+ void loadColorOrTexture(TiXmlElement *_elem,
+ const std::string &_type, Material *_mat);
- math::Matriz4x4 loadNodeTransform(TiXmlElement *_elem);
+ math::Matriz4x4 loadNodeTransform(TiXmlElement *_elem);
- void loadGeometry(TiXmlElement *_xml,
- const math::Matriz4x4 &_transform, Malla *_mesh);
+ void loadGeometry(TiXmlElement *_xml,
+ const math::Matriz4x4 &_transform, Malla *_mesh);
- void loadVertices(const std::string &_id,
- const math::Matriz4x4 &_transform,
- std::vector<math::Vector3> &_verts,
- std::vector<math::Vector3> &_norms);
+ void loadVertices(const std::string &_id,
+ const math::Matriz4x4 &_transform,
+ std::vector<math::Vector3> &_verts,
+ std::vector<math::Vector3> &_norms);
- void loadNormals(const std::string &_id,
- const math::Matriz4x4 &_transform,
- std::vector<math::Vector3> &_values);
+ void loadNormals(const std::string &_id,
+ const math::Matriz4x4 &_transform,
+ std::vector<math::Vector3> &_values);
- void loadPositions(const std::string &_id,
- const math::Matriz4x4 &_transform,
- std::vector<math::Vector3> &_values);
+ void loadPositions(const std::string &_id,
+ const math::Matriz4x4 &_transform,
+ std::vector<math::Vector3> &_values);
- void loadController(TiXmlElement *_contrXml,
- TiXmlElement *_skelXml, const math::Matriz4x4 _transform, Malla *_mesh);
+ void loadController(TiXmlElement *_contrXml,
+ TiXmlElement *_skelXml, const math::Matriz4x4 _transform, Malla *_mesh);
- void loadPolylist(TiXmlElement *_polylistXml,
- const math::Matriz4x4 &_transform,
- Malla *_mesh);
+ void loadPolylist(TiXmlElement *_polylistXml,
+ const math::Matriz4x4 &_transform,
+ Malla *_mesh);
- void loadLines(TiXmlElement *_xml,
- const math::Matriz4x4 &_transform,
- Malla *_mesh);
+ void loadLines(TiXmlElement *_xml,
+ const math::Matriz4x4 &_transform,
+ Malla *_mesh);
- void loadTriangles(TiXmlElement *_trianglesXml,
- const math::Matriz4x4 &_transform,
- Malla *_mesh);
- Material *loadMaterial(const std::string &_name);
- void loadTexCoords(const std::string &_id,
- std::vector<math::Vector2d> &_values);
- // collada filename
- private: std::string filename;
- private: std::string path;
+ void loadTriangles(TiXmlElement *_trianglesXml,
+ const math::Matriz4x4 &_transform,
+ Malla *_mesh);
+ Material *loadMaterial(const std::string &_name);
+ void loadTexCoords(const std::string &_id,
+ std::vector<math::Vector2d> &_values);
+ // collada filename
+ private: std::string filename;
+ private: std::string path;
- // root xml element
- private: TiXmlElement *colladaXml;
+ // root xml element
+ private: TiXmlElement *colladaXml;
- // scale factor
- private: double meter;
+ // scale factor
+ private: double meter;
- // Name of the current node.
- private: std::string currentNodeName;
+ // Name of the current node.
+ private: std::string currentNodeName;
- // material dictionary indexed by name
- private: std::map<std::string, std::string> materialMap;
+ // material dictionary indexed by name
+ private: std::map<std::string, std::string> materialMap;
-public: Malla *mesh;
-};
+ public: Malla *mesh;
+ };
+}
#endif // COLLADAPARSER_H
Modified: trunk/src/libs/geometry/collada/color.cpp
===================================================================
--- trunk/src/libs/geometry/collada/color.cpp 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/color.cpp 2013-06-05 16:10:12 UTC (rev 930)
@@ -1,15 +1,16 @@
#include "color.h"
+namespace files_3D {
+ Color::Color()
+ {
+ }
-Color::Color()
-{
-}
-
-void Color::set(float r, float g, float b, float a)
-{
- this->r = r;
- this->g = g;
- this->b = b;
- this->a = a;
+ void Color::set(float r, float g, float b, float a)
+ {
+ this->r = r;
+ this->g = g;
+ this->b = b;
+ this->a = a;
+ }
}
Modified: trunk/src/libs/geometry/collada/color.h
===================================================================
--- trunk/src/libs/geometry/collada/color.h 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/color.h 2013-06-05 16:10:12 UTC (rev 930)
@@ -2,24 +2,25 @@
#define COLOR_H
#include <iostream>
+namespace files_3D {
+ class Color
+ {
+ public:
+ Color();
+ void set(float r, float g, float b, float a);
-class Color
-{
-public:
- Color();
- void set(float r, float g, float b, float a);
+ public: float r, g, b, a;
- public: float r, g, b, a;
+ public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
+ {
+ // Skip white spaces
+ _in.setf(std::ios_base::skipws);
+ _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
+ return _in;
+ }
- public: friend std::istream &operator>> (std::istream &_in, Color &_pt)
- {
- // Skip white spaces
- _in.setf(std::ios_base::skipws);
- _in >> _pt.r >> _pt.g >> _pt.b >> _pt.a;
- return _in;
- }
+ };
+}
-};
-
#endif // COLOR_H
Modified: trunk/src/libs/geometry/collada/malla.cpp
===================================================================
--- trunk/src/libs/geometry/collada/malla.cpp 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/malla.cpp 2013-06-05 16:10:12 UTC (rev 930)
@@ -1,106 +1,107 @@
#include "malla.h"
+namespace files_3D {
+ Malla::Malla()
+ {
+ }
-Malla::Malla()
-{
-}
+ //////////////////////////////////////////////////
+ void Malla::setPath(const std::string &_path)
+ {
+ this->path = _path;
+ }
-//////////////////////////////////////////////////
-void Malla::setPath(const std::string &_path)
-{
- this->path = _path;
-}
+ //////////////////////////////////////////////////
+ void Malla::addSubMalla(SubMalla *_sub)
+ {
+ this->submeshes.push_back(_sub);
+ }
-//////////////////////////////////////////////////
-void Malla::addSubMalla(SubMalla *_sub)
-{
- this->submeshes.push_back(_sub);
-}
+ //////////////////////////////////////////////////
+ int Malla::addMaterial(Material *_mat)
+ {
+ int result = -1;
-//////////////////////////////////////////////////
-int Malla::addMaterial(Material *_mat)
-{
- int result = -1;
+ if (_mat)
+ {
+ this->materials.push_back(_mat);
+ result = this->materials.size()-1;
+ }
- if (_mat)
- {
- this->materials.push_back(_mat);
- result = this->materials.size()-1;
- }
+ return result;
+ }
- return result;
-}
+ //////////////////////////////////////////////////
+ Material *Malla::getMaterial(int index)
+ {
+ if (index >= 0 && index < static_cast<int>(this->materials.size()))
+ return this->materials[index];
-//////////////////////////////////////////////////
-Material *Malla::getMaterial(int index)
-{
- if (index >= 0 && index < static_cast<int>(this->materials.size()))
- return this->materials[index];
+ return NULL;
+ }
- return NULL;
-}
+ //////////////////////////////////////////////////
+ unsigned int Malla::getSubMeshCount() const
+ {
+ return this->submeshes.size();
+ }
-//////////////////////////////////////////////////
-unsigned int Malla::getSubMeshCount() const
-{
- return this->submeshes.size();
-}
+ //////////////////////////////////////////////////
+ SubMalla *Malla::getSubMesh(unsigned int i) const
+ {
+ if (i < this->submeshes.size())
+ return this->submeshes[i];
+ else
+ std::cout << "Invalid index: " << i << " >= " << this->submeshes.size() << "\n";
+ }
-//////////////////////////////////////////////////
-SubMalla *Malla::getSubMesh(unsigned int i) const
-{
- if (i < this->submeshes.size())
- return this->submeshes[i];
- else
- std::cout << "Invalid index: " << i << " >= " << this->submeshes.size() << "\n";
-}
+ //////////////////////////////////////////////////
+ math::Vector3 Malla::getMax() const
+ {
+ math::Vector3 max;
+ std::vector<SubMalla*>::const_iterator iter;
-//////////////////////////////////////////////////
-math::Vector3 Malla::getMax() const
-{
- math::Vector3 max;
- std::vector<SubMalla*>::const_iterator iter;
+ max.setX( -std::numeric_limits<float>::max());
+ max.setY( -std::numeric_limits<float>::max());
+ max.setZ( -std::numeric_limits<float>::max());
- max.setX( -std::numeric_limits<float>::max());
- max.setY( -std::numeric_limits<float>::max());
- max.setZ( -std::numeric_limits<float>::max());
+ for (iter = this->submeshes.begin(); iter != this->submeshes.end(); ++iter)
+ {
+ if ((*iter)->getVertexCount() <= 2)
+ continue;
- for (iter = this->submeshes.begin(); iter != this->submeshes.end(); ++iter)
- {
- if ((*iter)->getVertexCount() <= 2)
- continue;
+ math::Vector3 smax = (*iter)->getMax();
- math::Vector3 smax = (*iter)->getMax();
+ max.setX(std::max(max.getX(), smax.getX()));
+ max.setY(std::max(max.getY(), smax.getY()));
+ max.setZ(std::max(max.getZ(), smax.getZ()));
+ }
- max.setX(std::max(max.getX(), smax.getX()));
- max.setY(std::max(max.getY(), smax.getY()));
- max.setZ(std::max(max.getZ(), smax.getZ()));
- }
+ return max;
+ }
- return max;
-}
+ //////////////////////////////////////////////////
+ math::Vector3 Malla::getMin() const
+ {
+ math::Vector3 min;
+ std::vector<SubMalla *>::const_iterator iter;
-//////////////////////////////////////////////////
-math::Vector3 Malla::getMin() const
-{
- math::Vector3 min;
- std::vector<SubMalla *>::const_iterator iter;
+ min.setX( std::numeric_limits<float>::max());
+ min.setY( std::numeric_limits<float>::max());
+ min.setZ( std::numeric_limits<float>::max());
- min.setX( std::numeric_limits<float>::max());
- min.setY( std::numeric_limits<float>::max());
- min.setZ( std::numeric_limits<float>::max());
+ for (iter = this->submeshes.begin(); iter != this->submeshes.end(); ++iter)
+ {
+ if ((*iter)->getVertexCount() <= 2)
+ continue;
- for (iter = this->submeshes.begin(); iter != this->submeshes.end(); ++iter)
- {
- if ((*iter)->getVertexCount() <= 2)
- continue;
+ math::Vector3 smin = (*iter)->getMin();
+ min.setX(std::min(min.getX(), smin.getX()));
+ min.setY(std::min(min.getY(), smin.getY()));
+ min.setZ(std::min(min.getZ(), smin.getZ()));
+ }
- math::Vector3 smin = (*iter)->getMin();
- min.setX(std::min(min.getX(), smin.getX()));
- min.setY(std::min(min.getY(), smin.getY()));
- min.setZ(std::min(min.getZ(), smin.getZ()));
- }
-
- return min;
+ return min;
+ }
}
Modified: trunk/src/libs/geometry/collada/malla.h
===================================================================
--- trunk/src/libs/geometry/collada/malla.h 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/malla.h 2013-06-05 16:10:12 UTC (rev 930)
@@ -6,30 +6,31 @@
#include "submalla.h"
#include "material.h"
+namespace files_3D {
+ class Malla
+ {
+ public:
+ Malla();
-class Malla
-{
-public:
- Malla();
+ void setPath(const std::string &_path);
+ void addSubMalla(SubMalla *_sub);
+ int addMaterial(Material *_mat);
+ unsigned int getSubMeshCount() const;
+ SubMalla *getSubMesh(unsigned int i) const;
+ Material *getMaterial(int index);
- void setPath(const std::string &_path);
- void addSubMalla(SubMalla *_sub);
- int addMaterial(Material *_mat);
- unsigned int getSubMeshCount() const;
- SubMalla *getSubMesh(unsigned int i) const;
- Material *getMaterial(int index);
+ math::Vector3 getMax() const;
+ math::Vector3 getMin() const;
- math::Vector3 getMax() const;
- math::Vector3 getMin() const;
+ /// \brief The name of the mesh
+ private: std::string name;
- /// \brief The name of the mesh
- private: std::string name;
+ private: std::string path;
- private: std::string path;
+ private: std::vector<SubMalla *> submeshes;
+ private: std::vector<Material *> materials;
+ };
+}
- private: std::vector<SubMalla *> submeshes;
- private: std::vector<Material *> materials;
-};
-
#endif // MALLA_H
Modified: trunk/src/libs/geometry/collada/material.cpp
===================================================================
--- trunk/src/libs/geometry/collada/material.cpp 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/material.cpp 2013-06-05 16:10:12 UTC (rev 930)
@@ -1,139 +1,141 @@
#include "material.h"
-unsigned int Material::counter = 0;
+namespace files_3D {
+ unsigned int Material::counter = 0;
-Material::Material()
-{
- this->name = "gazebo_material_" + boost::lexical_cast<std::string>(counter++);
- this->specular.set(0, 0, 0, 1);
- this->lighting = false;
-}
+ Material::Material()
+ {
+ this->name = "gazebo_material_" + boost::lexical_cast<std::string>(counter++);
+ this->specular.set(0, 0, 0, 1);
+ this->lighting = false;
+ }
-//////////////////////////////////////////////////
-void Material::setDiffuse(const Color &_clr)
-{
- this->diffuse = _clr;
- this->lighting = true;
-}
-//////////////////////////////////////////////////
-Color Material::getDiffuse() const
-{
- return this->diffuse;
-}
+ //////////////////////////////////////////////////
+ void Material::setDiffuse(const Color &_clr)
+ {
+ this->diffuse = _clr;
+ this->lighting = true;
+ }
+ //////////////////////////////////////////////////
+ Color Material::getDiffuse() const
+ {
+ return this->diffuse;
+ }
-//////////////////////////////////////////////////
-void Material::setAmbient(const Color &_clr)
-{
- this->ambient = _clr;
-}
+ //////////////////////////////////////////////////
+ void Material::setAmbient(const Color &_clr)
+ {
+ this->ambient = _clr;
+ }
-//////////////////////////////////////////////////
-Color Material::getAmbient() const
-{
- return this->ambient;
-}
+ //////////////////////////////////////////////////
+ Color Material::getAmbient() const
+ {
+ return this->ambient;
+ }
-//////////////////////////////////////////////////
-void Material::setEmissive(const Color &_clr)
-{
- this->emissive = _clr;
-}
+ //////////////////////////////////////////////////
+ void Material::setEmissive(const Color &_clr)
+ {
+ this->emissive = _clr;
+ }
-//////////////////////////////////////////////////
-Color Material::getEmissive() const
-{
- return this->emissive;
-}
+ //////////////////////////////////////////////////
+ Color Material::getEmissive() const
+ {
+ return this->emissive;
+ }
-//////////////////////////////////////////////////
-double Material::getShininess() const
-{
- return this->shininess;
-}
+ //////////////////////////////////////////////////
+ double Material::getShininess() const
+ {
+ return this->shininess;
+ }
-//////////////////////////////////////////////////
-bool Material::getLighting() const
-{
- return this->lighting;
-}
+ //////////////////////////////////////////////////
+ bool Material::getLighting() const
+ {
+ return this->lighting;
+ }
-//////////////////////////////////////////////////
-void Material::setTextureImage(const std::string &_tex)
-{
- this->texImage = _tex;
-}
+ //////////////////////////////////////////////////
+ void Material::setTextureImage(const std::string &_tex)
+ {
+ this->texImage = _tex;
+ }
-//////////////////////////////////////////////////
-void Material::setTextureImage(const std::string &_tex,
- const std::string &_resourcePath)
-{
- this->texImage = _resourcePath + "/" + _tex;
+ //////////////////////////////////////////////////
+ void Material::setTextureImage(const std::string &_tex,
+ const std::string &_resourcePath)
+ {
+ this->texImage = _resourcePath + "/" + _tex;
- // If the texture image doesn't exist then try the next most likely path.
- if (!boost::filesystem::exists(this->texImage))
- {
- this->texImage = _resourcePath + "./" + _tex;
- if (!boost::filesystem::exists(this->texImage))
+ // If the texture image doesn't exist then try the next most likely path.
+ if (!boost::filesystem::exists(this->texImage))
+ {
+ this->texImage = _resourcePath + "./" + _tex;
+ if (!boost::filesystem::exists(this->texImage))
+ {
+ std::cout << "Unable to find texture[" << _tex << "] in path["
+ << _resourcePath << "]\n";
+ }else{
+ std::cout << "find texture[" << _tex << "] in path["
+ << _resourcePath << "]\n";
+ image = cv::imread(this->texImage);
+ }
+ }
+ }
+
+ cv::Mat Material::getImage()
{
- std::cout << "Unable to find texture[" << _tex << "] in path["
- << _resourcePath << "]\n";
- }else{
- std::cout << "find texture[" << _tex << "] in path["
- << _resourcePath << "]\n";
- image = cv::imread(this->texImage);
+ return image;
}
- }
-}
-cv::Mat Material::getImage()
-{
- return image;
-}
+ //////////////////////////////////////////////////
+ void Material::setTransparency(double _t)
+ {
+ this->transparency = std::min(_t, 1.0);
+ this->transparency = std::max(this->transparency, 0.0);
+ this->lighting = true;
+ }
-//////////////////////////////////////////////////
-void Material::setTransparency(double _t)
-{
- this->transparency = std::min(_t, 1.0);
- this->transparency = std::max(this->transparency, 0.0);
- this->lighting = true;
-}
+ //////////////////////////////////////////////////
+ Color Material::getSpecular() const
+ {
+ return this->specular;
+ }
-//////////////////////////////////////////////////
-Color Material::getSpecular() const
-{
- return this->specular;
-}
+ //////////////////////////////////////////////////
+ double Material::getTransparency() const
+ {
+ return this->transparency;
+ }
-//////////////////////////////////////////////////
-double Material::getTransparency() const
-{
- return this->transparency;
-}
+ //////////////////////////////////////////////////
+ void Material::setBlendFactors(double _srcFactor, double _dstFactor)
+ {
+ this->srcBlendFactor = _srcFactor;
+ this->dstBlendFactor = _dstFactor;
+ }
-//////////////////////////////////////////////////
-void Material::setBlendFactors(double _srcFactor, double _dstFactor)
-{
- this->srcBlendFactor = _srcFactor;
- this->dstBlendFactor = _dstFactor;
-}
+ //////////////////////////////////////////////////
+ void Material::setShininess(double _s)
+ {
+ this->shininess = _s;
+ this->lighting = true;
+ }
-//////////////////////////////////////////////////
-void Material::setShininess(double _s)
-{
- this->shininess = _s;
- this->lighting = true;
-}
+ //////////////////////////////////////////////////
+ std::string Material::getTextureImage() const
+ {
+ return this->texImage;
+ }
-//////////////////////////////////////////////////
-std::string Material::getTextureImage() const
-{
- return this->texImage;
+ //////////////////////////////////////////////////
+ std::string Material::getName() const
+ {
+ return this->name;
+ }
}
-//////////////////////////////////////////////////
-std::string Material::getName() const
-{
- return this->name;
-}
-
Modified: trunk/src/libs/geometry/collada/material.h
===================================================================
--- trunk/src/libs/geometry/collada/material.h 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/material.h 2013-06-05 16:10:12 UTC (rev 930)
@@ -10,86 +10,87 @@
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
+namespace files_3D {
+ class Material
+ {
+ public:
+ Material();
-class Material
-{
-public:
- Material();
+ public: void setDiffuse(const Color &_clr);
+ Color getDiffuse() const;
- public: void setDiffuse(const Color &_clr);
- Color getDiffuse() const;
+ void setAmbient(const Color &_clr);
+ Color getAmbient() const;
- void setAmbient(const Color &_clr);
- Color getAmbient() const;
+ void setEmissive(const Color &_clr);
+ Color getEmissive() const;
- void setEmissive(const Color &_clr);
- Color getEmissive() const;
+ bool getLighting() const;
+ double getShininess() const;
- bool getLighting() const;
- double getShininess() const;
+ std::string getTextureImage() const;
- std::string getTextureImage() const;
+ void setTextureImage(const std::string &_tex);
+ void setTextureImage(const std::string &_tex,
+ const std::string &_resourcePath);
+ void setTransparency(double _t);
+ double getTransparency() const;
+ void setBlendFactors(double _srcFactor, double _dstFactor);
+ void setShininess(double _s);
- void setTextureImage(const std::string &_tex);
- void setTextureImage(const std::string &_tex,
- const std::string &_resourcePath);
- void setTransparency(double _t);
- double getTransparency() const;
- void setBlendFactors(double _srcFactor, double _dstFactor);
- void setShininess(double _s);
+ Color getSpecular() const;
- Color getSpecular() const;
+ std::string getName() const;
- std::string getName() const;
+ cv::Mat getImage();
- cv::Mat getImage();
+ ///////////////////////////////////////////////////////////////////////////
+ /// \brief the name of the material
+ public: std::string name;
-///////////////////////////////////////////////////////////////////////////
- /// \brief the name of the material
- public: std::string name;
+ /// \brief the texture image file name
+ public: std::string texImage;
- /// \brief the texture image file name
- public: std::string texImage;
+ /// \brief the ambient light color
+ public: Color ambient;
- /// \brief the ambient light color
- public: Color ambient;
+ /// \brief the diffuse ligth color
+ public: Color diffuse;
- /// \brief the diffuse ligth color
- public: Color diffuse;
+ /// \brief the specular light color
+ public: Color specular;
- /// \brief the specular light color
- public: Color specular;
+ /// \brief the emissive light color
+ public: Color emissive;
- /// \brief the emissive light color
- public: Color emissive;
+ /// \brief transparency value in the range 0 to 1
+ public: double transparency;
- /// \brief transparency value in the range 0 to 1
- public: double transparency;
+ /// \brief shininess value (0 to 1)
+ public: double shininess;
- /// \brief shininess value (0 to 1)
- public: double shininess;
+ /// \brief the total number of instanciated Material instances
+ private: static unsigned int counter;
- /// \brief the total number of instanciated Material instances
- private: static unsigned int counter;
+ /// \brief flag to perform depth buffer write
+ private: bool depthWrite;
- /// \brief flag to perform depth buffer write
- private: bool depthWrite;
+ private: bool lighting;
- private: bool lighting;
+ /// \brief source blend factor
+ private: double srcBlendFactor;
- /// \brief source blend factor
- private: double srcBlendFactor;
+ /// \brief destination blend factor
+ private: double dstBlendFactor;
- /// \brief destination blend factor
- private: double dstBlendFactor;
+ public: unsigned int idTextura ;
- public: unsigned int idTextura ;
+ cv::Mat image;
+ };
+}
- cv::Mat image;
-};
-
#endif // MATERIAL_H
Modified: trunk/src/libs/geometry/collada/submalla.cpp
===================================================================
--- trunk/src/libs/geometry/collada/submalla.cpp 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/submalla.cpp 2013-06-05 16:10:12 UTC (rev 930)
@@ -1,226 +1,227 @@
#include "submalla.h"
+namespace files_3D {
+ SubMalla::SubMalla()
+ {
+ materialIndex = -1;
+ }
-SubMalla::SubMalla()
-{
- materialIndex = -1;
-}
+ SubMalla::~SubMalla()
+ {
+ }
-SubMalla::~SubMalla()
-{
-}
+ //////////////////////////////////////////////////
+ void SubMalla::setName(const std::string &_n)
+ {
+ this->name = _n;
+ }
-//////////////////////////////////////////////////
-void SubMalla::setName(const std::string &_n)
-{
- this->name = _n;
-}
+ //////////////////////////////////////////////////
+ void SubMalla::setPrimitiveType(PrimitiveType _type)
+ {
+ this->primitiveType = _type;
+ }
-//////////////////////////////////////////////////
-void SubMalla::setPrimitiveType(PrimitiveType _type)
-{
- this->primitiveType = _type;
-}
+ //////////////////////////////////////////////////
+ int SubMalla::getPrimitiveType() const
+ {
+ return this->primitiveType;
+ }
-//////////////////////////////////////////////////
-int SubMalla::getPrimitiveType() const
-{
- return this->primitiveType;
-}
+ //////////////////////////////////////////////////
+ void SubMalla::addVertex(const math::Vector3 &_v)
+ {
+ this->vertices.push_back(_v);
+ }
-//////////////////////////////////////////////////
-void SubMalla::addVertex(const math::Vector3 &_v)
-{
- this->vertices.push_back(_v);
-}
+ //////////////////////////////////////////////////
+ void SubMalla::addIndex(unsigned int _i)
+ {
+ this->indices.push_back(_i);
+ }
-//////////////////////////////////////////////////
-void SubMalla::addIndex(unsigned int _i)
-{
- this->indices.push_back(_i);
-}
+ //////////////////////////////////////////////////
+ unsigned int SubMalla::getVertexCount() const
+ {
+ return this->vertices.size();
+ }
-//////////////////////////////////////////////////
-unsigned int SubMalla::getVertexCount() const
-{
- return this->vertices.size();
-}
+ //////////////////////////////////////////////////
+ math::Vector3 SubMalla::getVertex(unsigned int _i) const
+ {
+ if (_i >= this->vertices.size())
+ std::cout << "Index too large\n";
-//////////////////////////////////////////////////
-math::Vector3 SubMalla::getVertex(unsigned int _i) const
-{
- if (_i >= this->vertices.size())
- std::cout << "Index too large\n";
+ return this->vertices[_i];
+ }
- return this->vertices[_i];
-}
+ //////////////////////////////////////////////////
+ math::Vector3 SubMalla::getNormal(unsigned int _i) const
+ {
+ if (_i >= this->normals.size())
+ std::cout <<"Index too large";
-//////////////////////////////////////////////////
-math::Vector3 SubMalla::getNormal(unsigned int _i) const
-{
- if (_i >= this->normals.size())
- std::cout <<"Index too large";
+ return this->normals[_i];
+ }
- return this->normals[_i];
-}
+ //////////////////////////////////////////////////
+ unsigned int SubMalla::getNormalCount() const
+ {
+ return this->normals.size();
+ }
-//////////////////////////////////////////////////
-unsigned int SubMalla::getNormalCount() const
-{
- return this->normals.size();
-}
+ //////////////////////////////////////////////////
+ void SubMalla::setMaterialIndex(unsigned int _index)
+ {
+ this->materialIndex = _index;
+ }
-//////////////////////////////////////////////////
-void SubMalla::setMaterialIndex(unsigned int _index)
-{
- this->materialIndex = _index;
-}
+ //////////////////////////////////////////////////
+ unsigned int SubMalla::getMaterialIndex() const
+ {
+ return this->materialIndex;
+ }
-//////////////////////////////////////////////////
-unsigned int SubMalla::getMaterialIndex() const
-{
- return this->materialIndex;
-}
+ //////////////////////////////////////////////////
+ void SubMalla::addNormal(const math::Vector3 &_n)
+ {
+ this->normals.push_back(_n);
+ }
-//////////////////////////////////////////////////
-void SubMalla::addNormal(const math::Vector3 &_n)
-{
- this->normals.push_back(_n);
-}
+ //////////////////////////////////////////////////
+ void SubMalla::addTexCoord(double _u, double _v)
+ {
+ this->texCoords.push_back(math::Vector2d(_u, _v));
+ }
-//////////////////////////////////////////////////
-void SubMalla::addTexCoord(double _u, double _v)
-{
- this->texCoords.push_back(math::Vector2d(_u, _v));
-}
+ //////////////////////////////////////////////////
+ unsigned int SubMalla::getTexCoordCount() const
+ {
+ return this->texCoords.size();
+ }
-//////////////////////////////////////////////////
-unsigned int SubMalla::getTexCoordCount() const
-{
- return this->texCoords.size();
-}
+ //////////////////////////////////////////////////
+ unsigned int SubMalla::getIndexCount() const
+ {
+ return this->indices.size();
+ }
-//////////////////////////////////////////////////
-unsigned int SubMalla::getIndexCount() const
-{
- return this->indices.size();
-}
+ //////////////////////////////////////////////////
+ unsigned int SubMalla::getIndex(unsigned int _i) const
+ {
+ if (_i > this->indices.size())
+ std::cout << "Index too large";
-//////////////////////////////////////////////////
-unsigned int SubMalla::getIndex(unsigned int _i) const
-{
- if (_i > this->indices.size())
- std::cout << "Index too large";
+ return this->indices[_i];
+ }
- return this->indices[_i];
-}
+ //////////////////////////////////////////////////
+ math::Vector2d SubMalla::getTexCoord(unsigned int _i) const
+ {
+ if (_i >= this->texCoords.size())
+ std::cout << "Index too large";
-//////////////////////////////////////////////////
-math::Vector2d SubMalla::getTexCoord(unsigned int _i) const
-{
- if (_i >= this->texCoords.size())
- std::cout << "Index too large";
+ return this->texCoords[_i];
+ }
- return this->texCoords[_i];
-}
+ //////////////////////////////////////////////////
+ void SubMalla::center()
+ {
+ math::Vector3 _center(0, 0, 0);
-//////////////////////////////////////////////////
-void SubMalla::center()
-{
- math::Vector3 _center(0, 0, 0);
+ math::Vector3 min, max, half;
+ min = this->getMin();
+ max = this->getMax();
+ half = (max - min) * 0.5;
- math::Vector3 min, max, half;
- min = this->getMin();
- max = this->getMax();
- half = (max - min) * 0.5;
+ this->translate(_center - (min + half));
+ }
- this->translate(_center - (min + half));
-}
+ //////////////////////////////////////////////////
+ void SubMalla::translate(const math::Vector3 &_vec)
+ {
+ for (std::vector<math::Vector3>::iterator iter = this->vertices.begin();
+ iter != this->vertices.end(); ++iter)
+ {
+ (*iter) += _vec;
+ }
+ }
-//////////////////////////////////////////////////
-void SubMalla::translate(const math::Vector3 &_vec)
-{
- for (std::vector<math::Vector3>::iterator iter = this->vertices.begin();
- iter != this->vertices.end(); ++iter)
- {
- (*iter) += _vec;
- }
-}
+ //////////////////////////////////////////////////
+ math::Vector3 SubMalla::getMax() const
+ {
+ math::Vector3 max;
+ std::vector<math::Vector3>::const_iterator iter;
-//////////////////////////////////////////////////
-math::Vector3 SubMalla::getMax() const
-{
- math::Vector3 max;
- std::vector<math::Vector3>::const_iterator iter;
+ max.setX( -std::numeric_limits<float>::max());
+ max.setY( -std::numeric_limits<float>::max());
+ max.setZ( -std::numeric_limits<float>::max());
- max.setX( -std::numeric_limits<float>::max());
- max.setY( -std::numeric_limits<float>::max());
- max.setZ( -std::numeric_limits<float>::max());
+ for (iter = this->vertices.begin(); iter != this->vertices.end(); ++iter)
+ {
+ math::Vector3 v = (*iter);
+ max.setX(std::max(max.getX(), v.getX()));
+ max.setY(std::max(max.getY(), v.getY()));
+ max.setZ(std::max(max.getZ(), v.getZ()));
+ }
- for (iter = this->vertices.begin(); iter != this->vertices.end(); ++iter)
- {
- math::Vector3 v = (*iter);
- max.setX(std::max(max.getX(), v.getX()));
- max.setY(std::max(max.getY(), v.getY()));
- max.setZ(std::max(max.getZ(), v.getZ()));
- }
+ return max;
+ }
- return max;
-}
+ //////////////////////////////////////////////////
+ math::Vector3 SubMalla::getMin() const
+ {
+ math::Vector3 min;
+ std::vector<math::Vector3>::const_iterator iter;
-//////////////////////////////////////////////////
-math::Vector3 SubMalla::getMin() const
-{
- math::Vector3 min;
- std::vector<math::Vector3>::const_iterator iter;
+ min.setX( std::numeric_limits<float>::max());
+ min.setY( std::numeric_limits<float>::max());
+ min.setZ( std::numeric_limits<float>::max());
- min.setX( std::numeric_limits<float>::max());
- min.setY( std::numeric_limits<float>::max());
- min.setZ( std::numeric_limits<float>::max());
+ for (iter = this->vertices.begin(); iter != this->vertices.end(); ++iter)
+ {
+ math::Vector3 v = (*iter);
+ min.setX(std::min(min.getX(), v.getX()));
+ min.setY(std::min(min.getY(), v.getY()));
+ min.setZ(std::min(min.getZ(), v.getZ()));
- for (iter = this->vertices.begin(); iter != this->vertices.end(); ++iter)
- {
- math::Vector3 v = (*iter);
- min.setX(std::min(min.getX(), v.getX()));
- min.setY(std::min(min.getY(), v.getY()));
- min.setZ(std::min(min.getZ(), v.getZ()));
+ }
- }
+ return min;
+ }
- return min;
-}
+ //////////////////////////////////////////////////
+ // PAra ODE
+ ////
+ void SubMalla::FillArrays(float **_vertArr, int **_indArr)
+ {
+ if (this->vertices.size() == 0 || this->indices.size() == 0)
+ std::cout << "No vertices or indices\n";
-//////////////////////////////////////////////////
-// PAra ODE
-////
-void SubMalla::FillArrays(float **_vertArr, int **_indArr)
-{
- if (this->vertices.size() == 0 || this->indices.size() == 0)
- std::cout << "No vertices or indices\n";
+ std::vector< math::Vector3 >::const_iterator viter;
+ std::vector< unsigned int >::const_iterator iiter;
+ unsigned int i;
- std::vector< math::Vector3 >::const_iterator viter;
- std::vector< unsigned int >::const_iterator iiter;
- unsigned int i;
+ if (*_vertArr)
+ delete [] *_vertArr;
- if (*_vertArr)
- delete [] *_vertArr;
+ if (*_indArr)
+ delete [] *_indArr;
- if (*_indArr)
- delete [] *_indArr;
+ *_vertArr = new float[this->vertices.size() * 3];
+ *_indArr = new int[this->indices.size()];
- *_vertArr = new float[this->vertices.size() * 3];
- *_indArr = new int[this->indices.size()];
+ for (viter = this->vertices.begin(), i = 0; viter != this->vertices.end();
+ ++viter){
+ (*_vertArr)[i++] = static_cast<float>((*viter).vector(0));
+ (*_vertArr)[i++] = static_cast<float>((*viter).vector(1));
+ (*_vertArr)[i++] = static_cast<float>((*viter).vector(2));
+ }
- for (viter = this->vertices.begin(), i = 0; viter != this->vertices.end();
- ++viter){
- (*_vertArr)[i++] = static_cast<float>((*viter).vector(0));
- (*_vertArr)[i++] = static_cast<float>((*viter).vector(1));
- (*_vertArr)[i++] = static_cast<float>((*viter).vector(2));
- }
-
- for (iiter = this->indices.begin(), i = 0;
- iiter != this->indices.end(); ++iiter)
- (*_indArr)[i++] = (*iiter);
+ for (iiter = this->indices.begin(), i = 0;
+ iiter != this->indices.end(); ++iiter)
+ (*_indArr)[i++] = (*iiter);
+ }
}
Modified: trunk/src/libs/geometry/collada/submalla.h
===================================================================
--- trunk/src/libs/geometry/collada/submalla.h 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/collada/submalla.h 2013-06-05 16:10:12 UTC (rev 930)
@@ -5,78 +5,79 @@
#include "math/vector3.h"
#include "math/vector2d.h"
+namespace files_3D {
-class SubMalla
-{
+ class SubMalla
+ {
- /// \brief An enumeration of the geometric mesh primitives
- public: enum PrimitiveType {POINTS, LINES, LINESTRIPS, TRIANGLES,
- TRIFANS, TRISTRIPS};
+ /// \brief An enumeration of the geometric mesh primitives
+ public: enum PrimitiveType {POINTS, LINES, LINESTRIPS, TRIANGLES,
+ TRIFANS, TRISTRIPS};
-public:
- SubMalla();
+ public:
+ SubMalla();
- public: virtual ~SubMalla();
+ public: virtual ~SubMalla();
- public: void setName(const std::string &_n);
+ public: void setName(const std::string &_n);
- public: void setPrimitiveType(PrimitiveType _type);
- int getPrimitiveType() const;
+ public: void setPrimitiveType(PrimitiveType _type);
+ int getPrimitiveType() const;
- void addVertex(const math::Vector3 &_v);
- void addIndex(unsigned int _i);
- unsigned int getVertexCount() const;
+ void addVertex(const math::Vector3 &_v);
+ void addIndex(unsigned int _i);
+ unsigned int getVertexCount() const;
- void addNormal(const math::Vector3 &_n);
- unsigned int getNormalCount() const;
+ void addNormal(const math::Vector3 &_n);
+ unsigned int getNormalCount() const;
- void addTexCoord(double _u, double _v);
- unsigned int getTexCoordCount() const;
+ void addTexCoord(double _u, double _v);
+ unsigned int getTexCoordCount() const;
- math::Vector3 getVertex(unsigned int _i) const;
- math::Vector3 getNormal(unsigned int _i) const;
- math::Vector2d getTexCoord(unsigned int _i) const;
+ math::Vector3 getVertex(unsigned int _i) const;
+ math::Vector3 getNormal(unsigned int _i) const;
+ math::Vector2d getTexCoord(unsigned int _i) const;
- unsigned int getIndex(unsigned int _i) const;
- unsigned int getIndexCount() const;
+ unsigned int getIndex(unsigned int _i) const;
+ unsigned int getIndexCount() const;
- public: void setMaterialIndex(unsigned int _index);
- unsigned int getMaterialIndex() const;
+ public: void setMaterialIndex(unsigned int _index);
+ unsigned int getMaterialIndex() const;
- void center();
- math::Vector3 getMax() const;
- math::Vector3 getMin() const;
+ void center();
+ math::Vector3 getMax() const;
+ math::Vector3 getMin() const;
- void translate(const math::Vector3 &_vec);
+ void translate(const math::Vector3 &_vec);
- void FillArrays(float **_vertArr, int **_indArr) ;
+ void FillArrays(float **_vertArr, int **_indArr) ;
- ///////////////////////////////////////////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
- /// \brief the vertex array
- private: std::vector< math::Vector3 > vertices;
+ /// \brief the vertex array
+ private: std::vector< math::Vector3 > vertices;
- /// \brief the normal array
- private: std::vector< math::Vector3 > normals;
+ /// \brief the normal array
+ private: std::vector< math::Vector3 > normals;
- /// \brief the texture coordinate array
- private: std::vector< math::Vector2d > texCoords;
+ /// \brief the texture coordinate array
+ private: std::vector< math::Vector2d > texCoords;
- /// \brief the vertex index array
- private: std::vector<unsigned int> indices;
+ /// \brief the vertex index array
+ private: std::vector<unsigned int> indices;
- /// mesh material list.
- private: int materialIndex;
+ /// mesh material list.
+ private: int materialIndex;
- /// \brief The name of the sub-mesh
- private: std::string name;
+ /// \brief The name of the sub-mesh
+ private: std::string name;
- private: PrimitiveType primitiveType;
-};
-
+ private: PrimitiveType primitiveType;
+ };
+}
#endif // SUBMALLA_H
Modified: trunk/src/libs/geometry/progeo/progeo.cpp
===================================================================
--- trunk/src/libs/geometry/progeo/progeo.cpp 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/progeo/progeo.cpp 2013-06-05 16:10:12 UTC (rev 930)
@@ -1,517 +1,519 @@
#include "progeo.h"
+namespace Progeo {
-Progeo::Progeo()
-{
-}
+ Progeo::Progeo()
+ {
+ }
-void Progeo::xmlReader(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"))){
+ void Progeo::xmlReader(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;
+ }
- xmlChar *key;
- curAux = cur->xmlChildrenNode;
+ cur = xmlDocGetRootElement(doc);
+ if (cur == NULL) {
+ fprintf(stderr,"empty document\n");
+ xmlFreeDoc(doc);
+ return;
+ }
- 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());
+ if (xmlStrcmp(cur->name, (const xmlChar *) "calibration_camera")) {
+ fprintf(stderr,"document of the wrong type, root node != calibration_camera");
+ xmlFreeDoc(doc);
+ return;
+ }
- 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.vector(0) = atof((char*)key);
- xmlFree(key);
+ while (cur != NULL) {
+ if ((!xmlStrcmp(cur->name, (const xmlChar *)"calibration_camera"))){
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"y"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->position.vector(1) = atof((char*)key);
- xmlFree(key);
+ xmlChar *key;
+ curAux = cur->xmlChildrenNode;
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"z"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->position.vector(2) = atof((char*)key);
- xmlFree(key);
+ while (curAux != NULL) {
+ /*
+ if ((!xmlStrcmp(curAux->name, (const xmlChar *)"name"))) {
+ key = xmlNodeListGetString(doc, curAux->xmlChildrenNode, 1);
- }
- 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.vector(0) = atof((char*)key);
- xmlFree(key);
+ char a[((string)key).size()+1];
+ a[key.size()]=0;
+ memcpy(a,key.c_str(),s.size());
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"y"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->foa.vector(1) = atof((char*)key);
- xmlFree(key);
+ 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;
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"z"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->foa.vector(2) = atof((char*)key);
- xmlFree(key);
+ while (curAux_child != NULL) {
+ if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"x"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->position.vector(0) = 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.getMatriz()(0,0) = this->k11;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"y"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->position.vector(1) = atof((char*)key);
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k12"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k12 = atof((char*)key);
- K.getMatriz()(0,1) = this->k12;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"z"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->position.vector(2) = atof((char*)key);
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k13"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k13 = atof((char*)key);
- K.getMatriz()(0,2) = this->k13;
- xmlFree(key);
+ }
+ curAux_child = curAux_child->next;
+ }
+ }else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"foa"))) {
+ curAux_child = curAux->xmlChildrenNode;
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k14"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k14 = atof((char*)key);
- xmlFree(key);
+ while (curAux_child != NULL) {
+ if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"x"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->foa.vector(0) = 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.getMatriz()(1,0) = this->k21;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"y"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->foa.vector(1) = atof((char*)key);
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k22"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k22 = atof((char*)key);
- K.getMatriz()(1,1) = this->k22;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"z"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->foa.vector(2) = atof((char*)key);
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k23"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k23 = atof((char*)key);
- K.getMatriz()(1,2) = this->k23;
- xmlFree(key);
+ }
+ curAux_child = curAux_child->next;
+ }
+ }else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"k_matrix"))) {
+ curAux_child = curAux->xmlChildrenNode;
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k24"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k24 = atof((char*)key);
- xmlFree(key);
+ 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.getMatriz()(0,0) = this->k11;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k31"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k31 = atof((char*)key);
- K.getMatriz()(2,0) = this->k31;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k12"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k12 = atof((char*)key);
+ K.getMatriz()(0,1) = this->k12;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k32"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k32 = atof((char*)key);
- K.getMatriz()(2,1) = this->k32;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k13"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k13 = atof((char*)key);
+ K.getMatriz()(0,2) = this->k13;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k33"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k33 = atof((char*)key);
- K.getMatriz()(2,2) = this->k33;
- 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 *)"k34"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->k34 = 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.getMatriz()(1,0) = this->k21;
+ 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.getMatrix()(0,0) = this->rt11;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k22"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k22 = atof((char*)key);
+ K.getMatriz()(1,1) = this->k22;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt12"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt12 = atof((char*)key);
- RT.getMatrix()(0,1) = this->rt12;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k23"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k23 = atof((char*)key);
+ K.getMatriz()(1,2) = this->k23;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt13"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt13 = atof((char*)key);
- RT.getMatrix()(0,2) = this->rt13;
- 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 *)"rt14"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt14 = atof((char*)key);
- RT.getMatrix()(0,3) = this->rt14;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k31"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k31 = atof((char*)key);
+ K.getMatriz()(2,0) = this->k31;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt21"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt21 = atof((char*)key);
- RT.getMatrix()(1,0) = this->rt21;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k32"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k32 = atof((char*)key);
+ K.getMatriz()(2,1) = this->k32;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt22"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt22 = atof((char*)key);
- RT.getMatrix()(1,1) = this->rt22;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"k33"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->k33 = atof((char*)key);
+ K.getMatriz()(2,2) = this->k33;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt23"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt23 = atof((char*)key);
- RT.getMatrix()(1,2) = this->rt23;
- 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);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt24"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt24 = atof((char*)key);
- RT.getMatrix()(1,3) = this->rt24;
- xmlFree(key);
+ }
+ curAux_child = curAux_child->next;
+ }
+ } else if ((!xmlStrcmp(curAux->name, (const xmlChar *)"rt_matrix"))) {
+ curAux_child = curAux->xmlChildrenNode;
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt31"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt31 = atof((char*)key);
- RT.getMatrix()(2,0) = this->rt31;
- xmlFree(key);
+ 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.getMatrix()(0,0) = this->rt11;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt32"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt32 = atof((char*)key);
- RT.getMatrix()(2,1) = this->rt32;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt12"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt12 = atof((char*)key);
+ RT.getMatrix()(0,1) = this->rt12;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt33"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt33 = atof((char*)key);
- RT.getMatrix()(2,2) = this->rt33;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt13"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt13 = atof((char*)key);
+ RT.getMatrix()(0,2) = this->rt13;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt34"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt34 = atof((char*)key);
- RT.getMatrix()(2,3) = this->rt34;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt14"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt14 = atof((char*)key);
+ RT.getMatrix()(0,3) = this->rt14;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt41"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt41 = atof((char*)key);
- RT.getMatrix()(3,0) = this->rt41;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt21"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt21 = atof((char*)key);
+ RT.getMatrix()(1,0) = this->rt21;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt42"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt42 = atof((char*)key);
- RT.getMatrix()(3,1) = this->rt42;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt22"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt22 = atof((char*)key);
+ RT.getMatrix()(1,1) = this->rt22;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt43"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt43 = atof((char*)key);
- RT.getMatrix()(3,2) = this->rt43;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt23"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt23 = atof((char*)key);
+ RT.getMatrix()(1,2) = this->rt23;
+ xmlFree(key);
- } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt44"))) {
- key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
- this->rt44 = atof((char*)key);
- RT.getMatrix()(3,3) = this->rt44;
- xmlFree(key);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt24"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt24 = atof((char*)key);
+ RT.getMatrix()(1,3) = this->rt24;
+ xmlFree(key);
- }
- curAux_child = curAux_child->next;
- }
- }
- curAux = curAux->next;
- }
- }
- cur = cur->next;
- }
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt31"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt31 = atof((char*)key);
+ RT.getMatrix()(2,0) = this->rt31;
+ xmlFree(key);
- xmlFreeDoc(doc);
- return;
-}
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt32"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt32 = atof((char*)key);
+ RT.getMatrix()(2,1) = this->rt32;
+ xmlFree(key);
-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.getX(),
- position.getY(),
- position.getZ(),
- position.getH());
- printf(" Focus of Attention: (x,y,z,h)=(%.1f,%.1f,%.1f,%.1f)\n\n", foa.getX(),
- foa.getY(),
- foa.getZ(),
- foa.getH());
- 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);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt33"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt33 = atof((char*)key);
+ RT.getMatrix()(2,2) = this->rt33;
+ xmlFree(key);
-// 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.getMatriz() << 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.getMatrix() << std::endl;
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt34"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt34 = atof((char*)key);
+ RT.getMatrix()(2,3) = this->rt34;
+ xmlFree(key);
- printf("------------------------------------------------------\n");
-}
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt41"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt41 = atof((char*)key);
+ RT.getMatrix()(3,0) = this->rt41;
+ xmlFree(key);
-int Progeo::project(math::Vector3H in, math::Vector2H &out)
-/* returns -1 if the point lies behind the camera,
- returns 1 if "in" 3Dpoint projects into a 2D finite point,
- 0 otherwise */
-{
- math::Vector3H a;
- a.vector = RT.getCopyMatrix()*in.vector;
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt42"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt42 = atof((char*)key);
+ RT.getMatrix()(3,1) = this->rt42;
+ xmlFree(key);
- out.vector = K.getCopyMatriz()*a.vector.head(3);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt43"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt43 = atof((char*)key);
+ RT.getMatrix()(3,2) = this->rt43;
+ xmlFree(key);
- // optical 2 graphics
- out.setX(out.getX()/out.getH());
- out.setY(out.getY()/out.getH());
- out.setH(1.0);
+ } else if ((!xmlStrcmp(curAux_child->name, (const xmlChar *)"rt44"))) {
+ key = xmlNodeListGetString(doc, curAux_child->xmlChildrenNode, 1);
+ this->rt44 = atof((char*)key);
+ RT.getMatrix()(3,3) = this->rt44;
+ xmlFree(key);
- float aux =out.getX();
- out.setX(out.getY());
- out.setY(this->rows-1-aux);
+ }
+ curAux_child = curAux_child->next;
+ }
+ }
+ curAux = curAux->next;
+ }
+ }
+ cur = cur->next;
+ }
- if (out.getH()!=0.){
- return 1;
- }else{
- return 0;
+ xmlFreeDoc(doc);
+ return;
}
-}
-void Progeo::backproject(math::Vector2H point, math::Vector3H& pro)
-{
-
- //GRAPHIC_TO_OPTICAL
- int opX = this->rows -1 -point.getY();
- int opY = point.getX();
+ 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.getX(),
+ position.getY(),
+ position.getZ(),
+ position.getH());
+ printf(" Focus of Attention: (x,y,z,h)=(%.1f,%.1f,%.1f,%.1f)\n\n", foa.getX(),
+ foa.getY(),
+ foa.getZ(),
+ foa.getH());
+ printf(" Focus DistanceX(vertical): %.1f mm\n",fdistx);
+ printf(" Focus DistanceY(horizontal): %.1f mm\n",fdisty);
- math::Matriz3x3 ik;
- ik.getMatriz()= K.getCopyMatriz();
- ik.getMatriz() = ik.getCopyMatriz().inverse();
+ printf(" Skew: %.5f \n",skew);
+ printf(" Optical Center: (x,y)=(%.1f,%.1f)\n\n",u0,v0);
- math::Vector2H Pi(opX*this->k11/point.getH(), opY*this->k11/point.getH(),this->k11);
+ // 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;
- math::Vector2H a;
- a.vector = ik.getCopyMatriz()*Pi.vector;
+ std::cout << "K Matrix: \n" << K.getMatriz() << std::endl;
- math::Vector3H aH;
- aH.setX(a.getX());
- aH.setY(a.getY());
- aH.setZ(a.getH());
- aH.setH(1.0);
+ // 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;
- math::Matriz4x4 RT2;
- RT2.getMatrix() = RT.getCopyMatrix();
+ std::cout <<" R&T Matrix:\n"<< RT.getMatrix() << std::endl;
- RT2.getMatrix()(0, 3) = .0;
- RT2.getMatrix()(1, 3) = .0;
- RT2.getMatrix()(2, 3) = .0;
- RT2.getMatrix()(3, 3) = 1.0;
+ printf("------------------------------------------------------\n");
+ }
+ int Progeo::project(math::Vector3H in, math::Vector2H &out)
+ /* returns -1 if the point lies behind the camera,
+ returns 1 if "in" 3Dpoint projects into a 2D finite point,
+ 0 otherwise */
+ {
+ math::Vector3H a;
+ a.vector = RT.getCopyMatrix()*in.vector;
- math::Vector3H b;
+ out.vector = K.getCopyMatriz()*a.vector.head(3);
- b.vector = RT2.getCopyMatrix()*aH.vector;
+ // optical 2 graphics
+ out.setX(out.getX()/out.getH());
+ out.setY(out.getY()/out.getH());
+ out.setH(1.0);
- math::Matriz4x4 Translate(math::Matriz4x4::IDENTITY);
- Translate.getMatrix()(0, 3) = position.getX();
- Translate.getMatrix()(1, 3) = position.getY();
- Translate.getMatrix()(2, 3) = position.getZ();
+ float aux =out.getX();
+ out.setX(out.getY());
+ out.setY(this->rows-1-aux);
- b.vector = Translate.getCopyMatrix()*b.vector;
+ if (out.getH()!=0.){
+ return 1;
+ }else{
+ return 0;
+ }
+ }
- pro.setX(b.getX()/b.getH());
- pro.setY(b.getY()/b.getH());
- pro.setZ(b.getZ()/b.getH());
- pro.setH(b.getH());
-}
+ void Progeo::backproject(math::Vector2H point, math::Vector3H& pro)
+ {
-void Progeo::update_camera_matrix()
-{}
-//{
-// float rc11,rc12,rc13,rc21,rc22,rc23,rc31,rc32,rc33;
-// float rab11,rab12,rab13,rab21,rab22,rab23,rab31,rab32,rab33;
-// float r;
-// /* a very small value but not infinite!! */
-// float SMALL=0.0001;
-// double t;
-// float ux,uy,uz,vx,vy,vz,wx,wy,wz;
+ //GRAPHIC_TO_OPTICAL
+ int opX = this->rows -1 -point.getY();
+ int opY = point.getX();
-// camera->foa.H=1.;
-// camera->position.H=1;
+ math::Matriz3x3 ik;
+ ik.getMatriz()= K.getCopyMatriz();
+ ik.getMatriz() = ik.getCopyMatriz().inverse();
-// /* 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=(float)sqrt((double)(rab31*rab31+rab32*rab32+rab33*rab33));
-// rab31=rab31/r; rab32=rab32/r; rab33=rab33/r;
+ math::Vector2H Pi(opX*this->k11/point.getH(), opY*this->k11/point.getH(),this->k11);
-// /* Second method:*/
-// wx=rab31;
-// wy=rab32;
-// wz=rab33;
-// t = atan2(-wx,wy);
-// vx=(float)cos(t);
-// vy=(float)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;
+ math::Vector2H a;
+ a.vector = ik.getCopyMatriz()*Pi.vector;
-// /* First method:
-// * this was commented in the previous version. only else branch of this if was valid. test it!!*
+ math::Vector3H aH;
+ aH.setX(a.getX());
+ aH.setY(a.getY());
+ aH.setZ(a.getH());
+ aH.setH(1.0);
-// 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=(float)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;}
+ math::Matriz4x4 RT2;
+ RT2.getMatrix() = RT.getCopyMatrix();
-// rab21=rab32*rab13-rab12*rab33; rab22=rab11*rab33-rab31*rab13; rab23=rab31*rab12-rab11*rab32;
-// r=(float)sqrt((double)(rab21*rab21+rab22*rab22+rab23*rab23));
-// rab21=rab21/r; rab22=rab22/r; rab23=rab23/r;
-// }
-// */
+ RT2.getMatrix()(0, 3) = .0;
+ RT2.getMatrix()(1, 3) = .0;
+ RT2.getMatrix()(2, 3) = .0;
+ RT2.getMatrix()(3, 3) = 1.0;
-// 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;
+ math::Vector3H b;
-// 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.;
+ b.vector = RT2.getCopyMatrix()*aH.vector;
-// /* 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.;
+ math::Matriz4x4 Translate(math::Matriz4x4::IDENTITY);
+ Translate.getMatrix()(0, 3) = position.getX();
+ Translate.getMatrix()(1, 3) = position.getY();
+ Translate.getMatrix()(2, 3) = position.getZ();
-// 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);
-//}
+ b.vector = Translate.getCopyMatrix()*b.vector;
+
+ pro.setX(b.getX()/b.getH());
+ pro.setY(b.getY()/b.getH());
+ pro.setZ(b.getZ()/b.getH());
+ pro.setH(b.getH());
+ }
+
+ void Progeo::update_camera_matrix()
+ {}
+ //{
+ // float rc11,rc12,rc13,rc21,rc22,rc23,rc31,rc32,rc33;
+ // float rab11,rab12,rab13,rab21,rab22,rab23,rab31,rab32,rab33;
+ // float r;
+ // /* a very small value but not infinite!! */
+ // float SMALL=0.0001;
+ // double t;
+ // float 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=(float)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=(float)cos(t);
+ // vy=(float)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=(float)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=(float)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);
+ //}
+}
Modified: trunk/src/libs/geometry/progeo/progeo.h
===================================================================
--- trunk/src/libs/geometry/progeo/progeo.h 2013-06-05 16:03:53 UTC (rev 929)
+++ trunk/src/libs/geometry/progeo/progeo.h 2013-06-05 16:10:12 UTC (rev 930)
@@ -29,61 +29,64 @@
#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))
-class Progeo
-{
+namespace Progeo {
- public:Progeo();
+ class Progeo
+ {
- public: void xmlReader(std::string filename);
+ public:Progeo();
- public: void display_camerainfo();
+ public: void xmlReader(std::string filename);
- public: void backproject(math::Vector2H, math::Vector3H& pro);
- public: int project(math::Vector3H in, math::Vector2H &out);
- public: void update_camera_matrix();
+ public: void display_camerainfo();
- /* camera 3d position in mm */
- private: math::Vector3H position;
-
- /* camera 3d focus of attention in mm */
- private: math::Vector3H foa;
-
- /* top right and bottom left points */
- private: math::Vector3 tr, bl;
-
- /* camera roll position angle in rads */
- private: float roll;
+ public: void backproject(math::Vector2H, math::Vector3H& pro);
+ public: int project(math::Vector3H in, math::Vector2H &out);
+ public: void update_camera_matrix();
- /* focus x distance in mm*/
- private: float fdistx;
- private: float fdisty;
-
- /* pixels */
- private: float u0,v0;
-
- /*angle between the x and y pixel axes in rads*/
- private: float skew
-
- /* image height in pixels */;
- private: int rows;
-
- /* image width in pixels */
- private: int columns;
+ /* camera 3d position in mm */
+ private: math::Vector3H position;
- /* camera K matrix */
- private: float k11, k12, k13, k14, k21, k22, k23, k24, k31, k32, k33, k34;
- private: math::Matriz3x3 K;
+ /* camera 3d focus of attention in mm */
+ private: math::Vector3H foa;
- /* camera rotation + translation matrix */
- private: float rt11, rt12, rt13, rt14, rt21, rt22, rt23, rt24, rt31, rt32, rt33, rt34, rt41, rt42, rt43, rt44;
- private: math::Matriz4x4 RT;
-
- /* distortion parameters */
- private: float d1,d2,d3,d4,d5,d6;
- private: float dx,dy;
-
- /* name */
- std::string name;
-};
+ /* top right and bottom left points */
+ private: math::Vector3 tr, bl;
+ /* camera roll position angle in rads */
+ private: float roll;
+
+ /* focus x distance in mm*/
+ private: float fdistx;
+ private: float fdisty;
+
+ /* pixels */
+ private: float u0,v0;
+
+ /*angle between the x and y pixel axes in rads*/
+ private: float skew
+
+ /* image height in pixels */;
+ private: int rows;
+
+ /* image width in pixels */
+ private: int columns;
+
+ /* camera K matrix */
+ private: float k11, k12, k13, k14, k21, k22, k23, k24, k31, k32, k33, k34;
+ private: math::Matriz3x3 K;
+
+ /* camera rotation + translation matrix */
+ private: float rt11, rt12, rt13, rt14, rt21, rt22, rt23, rt24, rt31, rt32, rt33, rt34, rt41, rt42, rt43, rt44;
+ private: math::Matriz4x4 RT;
+
+ /* distortion parameters */
+ private: float d1,d2,d3,d4,d5,d6;
+ private: float dx,dy;
+
+ /* name */
+ std::string name;
+ };
+}
+
#endif
More information about the Jderobot-admin
mailing list