Commit 51206dcd authored by Sylvain Thery's avatar Sylvain Thery

replace libXml2 by tinyxml2

parent f2a4af2f
......@@ -58,7 +58,7 @@ ENDIF(WIN32)
find_package(OpenGL REQUIRED)
find_package(Boost COMPONENTS regex REQUIRED)
find_package(ZLIB REQUIRED)
find_package(LibXml2 REQUIRED)
#find_package(LibXml2 REQUIRED)
find_package(GLEW REQUIRED)
# MESSAGE HERE FOR MORE EASY USER READING
......@@ -98,7 +98,7 @@ SET (CGoGN_EXT_INCLUDES
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS}
${LIBXML2_INCLUDE_DIR}
# ${LIBXML2_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
)
......@@ -108,7 +108,8 @@ SET (CGoGN_EXT_LIBS
${OPENGL_LIBRARY}
${GLEW_LIBRARIES}
${ZLIB_LIBRARIES}
${LIBXML2_LIBRARIES}
# ${LIBXML2_LIBRARIES}
tinyxml2
${Boost_REGEX_LIBRARY}
)
......
......@@ -3,7 +3,7 @@ English version bellow
Dépendences Linux
=================
installer les paquets suivants:
cmake cmake-curses-gui cmake-qt-gui libXi-dev libXmu-dev libglew-dev libxml2-dev libboost-all-dev zlib1g-dev qt4-designer qt4-dev-tools uuid-dev libgsl0-dev libsuitesparse-dev
cmake cmake-curses-gui cmake-qt-gui libXi-dev libXmu-dev libglew-dev libtinyxml2-dev libboost-all-dev zlib1g-dev qt4-designer qt4-dev-tools uuid-dev libgsl0-dev libsuitesparse-dev
Pour compiler CGoGN
......
This diff is collapsed.
......@@ -25,6 +25,8 @@
#ifndef __IMPORTSVG_H__
#define __IMPORTSVG_H__
#include "Utils/xml.h"
namespace CGoGN
{
......@@ -43,16 +45,16 @@ namespace Import
* @param name the name
* @ return true if node has the good name
*/
bool checkXmlNode(xmlNodePtr node, const std::string& name);
bool checkXmlNode(tinyxml2::XMLElement* node, const std::string& name);
template <typename PFP>
void readCoordAndStyle(xmlNode* cur_path,
void readCoordAndStyle(tinyxml2::XMLElement* cur_path,
std::vector<std::vector<VEC3 > >& allPoly,
std::vector<std::vector<VEC3 > >& allBrokenLines,
std::vector<float>& allBrokenLinesWidth);
template <typename PFP>
bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3>& position, CellMarker<EDGE>& polygons, CellMarker<FACE>& polygonsFaces);
bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3,typename PFP::MAP>& position, CellMarker<typename PFP::MAP,EDGE>& polygons, CellMarker<typename PFP::MAP,FACE>& polygonsFaces);
/**
*
......
......@@ -26,9 +26,13 @@
#include "Geometry/bounding_box.h"
#include "Geometry/plane_3d.h"
#include "Algo/BooleanOperator/mergeVertices.h"
#include "Algo/Topo/basic.h"
#include "Container/fakeAttribute.h"
#include <limits>
#include "Utils/xml.h" // just for highlighting/completion in editor
namespace CGoGN
{
......@@ -41,9 +45,14 @@ namespace Surface
namespace Import
{
inline bool checkXmlNode(xmlNodePtr node, const std::string& name)
//inline bool checkXmlNode(xmlNodePtr node, const std::string& name)
//{
// return (strcmp((char*)(node->name),(char*)(name.c_str())) == 0);
//}
inline bool checkXmlNode(tinyxml2::XMLElement* node, const std::string& name)
{
return (strcmp((char*)(node->name),(char*)(name.c_str())) == 0);
return (strcmp(node->Name(),name.c_str()) == 0);
}
template<typename T>
......@@ -206,7 +215,7 @@ void getPolygonFromSVG(std::string allcoords, std::vector<VEC3>& curPoly, bool&
}
template <typename PFP>
void readCoordAndStyle(xmlNode* cur_path,
void readCoordAndStyle(tinyxml2::XMLElement* cur_path,
std::vector<std::vector<VEC3 > >& allPoly,
std::vector<std::vector<VEC3 > >& allBrokenLines,
std::vector<float>& allBrokenLinesWidth)
......@@ -218,14 +227,16 @@ void readCoordAndStyle(xmlNode* cur_path,
POLYGON curPoly;
// CGoGNout << "--load a path--"<< CGoGNendl;
xmlChar* prop = xmlGetProp(cur_path, BAD_CAST "d");
std::string allcoords((reinterpret_cast<const char*>(prop)));
// xmlChar* prop = xmlGetProp(cur_path, BAD_CAST "d");
// std::string allcoords((reinterpret_cast<const char*>(prop)));
std::string allcoords = XMLAttribute(cur_path,"d");
getPolygonFromSVG(allcoords,curPoly,closedPoly);
//check orientation : set in CCW
if(curPoly.size()>2)
{
VEC3 v(0), v1, v2;
VEC3 v(0)/*, v1, v2*/;
typename std::vector<VEC3 >::iterator it0, it1, it2;
it0 = curPoly.begin();
it1 = it0+1;
......@@ -255,8 +266,11 @@ void readCoordAndStyle(xmlNode* cur_path,
{
//if not : read the linewidth for further dilatation
allBrokenLines.push_back(curPoly);
xmlChar* prop = xmlGetProp(cur_path, BAD_CAST "style");
std::string allstyle((reinterpret_cast<const char*>(prop)));
// xmlChar* prop = xmlGetProp(cur_path, BAD_CAST "style");
// std::string allstyle((reinterpret_cast<const char*>(prop)));
std::string allstyle = XMLAttribute(cur_path,"style");
std::stringstream is(allstyle);
std::string style;
while ( std::getline( is, style, ';' ) )
......@@ -274,7 +288,7 @@ void readCoordAndStyle(xmlNode* cur_path,
}
template <typename PFP>
bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3>& position, CellMarker<EDGE>& obstacleMark, CellMarker<FACE>& buildingMark)
bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3,typename PFP::MAP>& position, CellMarker<typename PFP::MAP,EDGE>& obstacleMark, CellMarker<typename PFP::MAP,FACE>& buildingMark)
{
//TODO : remove auto-intersecting faces
//TODO : handling polygons with holes
......@@ -282,8 +296,18 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
typedef typename PFP::VEC3 VEC3;
typedef std::vector<VEC3> POLYGON;
xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
xmlNodePtr map_node = xmlDocGetRootElement(doc);
tinyxml2::XMLDocument doc;
tinyxml2::XMLError eResult = doc.LoadFile(filename.c_str());
if (XMLisError(eResult,"unable loading file"+filename))
return false;
tinyxml2::XMLElement* map_node = doc.RootElement();
// xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
// xmlNodePtr map_node = xmlDocGetRootElement(doc);
if (!checkXmlNode(map_node,"svg"))
{
......@@ -295,11 +319,11 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
std::vector<POLYGON> allBrokenLines;
std::vector<float> allBrokenLinesWidth;
for (xmlNode* cur_node = map_node->children; cur_node; cur_node = cur_node->next)
for (tinyxml2::XMLElement* cur_node = map_node->FirstChildElement(); cur_node; cur_node = cur_node->NextSiblingElement())
{
// for each layer
if (checkXmlNode(cur_node, "g"))
for (xmlNode* cur_path = cur_node->children ; cur_path; cur_path = cur_path->next)
for (tinyxml2::XMLElement* cur_path = cur_node->FirstChildElement(); cur_path; cur_path = cur_path->NextSiblingElement())
{
if (checkXmlNode(cur_path, "path"))
readCoordAndStyle<PFP>(cur_path, allPoly, allBrokenLines, allBrokenLinesWidth);
......@@ -308,17 +332,30 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
readCoordAndStyle<PFP>(cur_node, allPoly, allBrokenLines, allBrokenLinesWidth);
}
xmlFreeDoc(doc);
// for (xmlNode* cur_node = map_node->children; cur_node; cur_node = cur_node->next)
// {
// // for each layer
// if (checkXmlNode(cur_node, "g"))
// for (xmlNode* cur_path = cur_node->children ; cur_path; cur_path = cur_path->next)
// {
// if (checkXmlNode(cur_path, "path"))
// readCoordAndStyle<PFP>(cur_path, allPoly, allBrokenLines, allBrokenLinesWidth);
// }
// else if (checkXmlNode(cur_node, "path"))
// readCoordAndStyle<PFP>(cur_node, allPoly, allBrokenLines, allBrokenLinesWidth);
// }
// xmlFreeDoc(doc);
std::cout << "importSVG : XML read." << std::endl;
CellMarker<EDGE> brokenMark(map);
EdgeAttribute<float> edgeWidth = map.template addAttribute<float, EDGE>("width");
CellMarker<typename PFP::MAP,EDGE> brokenMark(map);
EdgeAttribute<float,typename PFP::MAP> edgeWidth = map.template addAttribute<float, EDGE,typename PFP::MAP>("width");
// EdgeAttribute<NoMathAttribute<Geom::Plane3D<typename PFP::REAL> > > edgePlanes = map.template addAttribute<NoMathAttribute<Geom::Plane3D<typename PFP::REAL> >, EDGE>("planes");
EdgeAttribute<NoTypeNameAttribute<Geom::Plane3D<typename PFP::REAL> > > edgePlanes = map.template addAttribute<NoTypeNameAttribute<Geom::Plane3D<typename PFP::REAL> >, EDGE>("planes");
EdgeAttribute<NoTypeNameAttribute<Geom::Plane3D<typename PFP::REAL> >, typename PFP::MAP> edgePlanes = map.template addAttribute<NoTypeNameAttribute<Geom::Plane3D<typename PFP::REAL> >, EDGE,typename PFP::MAP>("planes");
/////////////////////////////////////////////////////////////////////////////////////////////
//create broken lines
DartMarker brokenL(map);
DartMarker<typename PFP::MAP> brokenL(map);
typename std::vector<POLYGON >::iterator it;
std::vector<float >::iterator itW = allBrokenLinesWidth.begin();
......@@ -459,7 +496,7 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
/////////////////////////////////////////////////////////////////////////////////////////////
//process broken lines
CellMarker<EDGE> eMTreated(map) ;
CellMarker<typename PFP::MAP,EDGE> eMTreated(map) ;
for (Dart d = map.begin() ; d != map.end() ; map.next(d))
{
if (brokenL.isMarked(d) && !eMTreated.isMarked(d))
......@@ -521,7 +558,7 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
{
for (Dart d = map.begin() ; d != map.end() ; map.next(d))
{
if(map.isBoundaryMarked2(d))
if(map.template isBoundaryMarked<2>(d))
{
map.fillHole(d);
}
......@@ -552,14 +589,14 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
}
}
map.template initAllOrbitsEmbedding<FACE>(true);
Algo::Topo::initAllOrbitsEmbedding<FACE>(map,true);
for (Dart d = map.begin() ; d != map.end() ; map.next(d))
{
if (!map.isBoundaryMarked2(d) && brokenL.isMarked(d))
if (!map.template isBoundaryMarked<2>(d) && brokenL.isMarked(d))
{
map.deleteFace(d,false);
// ??? map.deleteFace(d,false);
map.deleteCycle(d); // ???
}
}
......@@ -567,7 +604,7 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
for (Dart d = map.begin() ; d != map.end() ; map.next(d))
{
if (map.isBoundaryMarked2(d))
if (map.template isBoundaryMarked<2>(d))
buildingMark.mark(d);
}
......
......@@ -31,9 +31,6 @@
#include <vector>
#include <map>
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
#include <libxml/parser.h>
namespace CGoGN
{
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGoGN_XML__
#define __CGoGN_XML__
#include <string>
#include "Utils/cgognStream.h"
#include <tinyxml2.h>
namespace CGoGN
{
inline bool XMLisError(tinyxml2::XMLError err, const std::string& msg)
{
if (err != tinyxml2::XML_NO_ERROR)
{
CGoGNerr << msg << CGoGNendl;
return true;
}
return false;
}
inline std::string XMLAttribute(tinyxml2::XMLElement* node, const char* attName)
{
const char *ptr = node->Attribute(attName);
if (ptr == NULL)
{
CGoGNerr << "Warning attrbute "<< attName << " not found"<< CGoGNendl;
return "";
}
return std::string(ptr);
}
}
#endif
......@@ -25,8 +25,6 @@
#include <typeinfo>
#include <stdio.h>
#include <string.h>
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
#include <iostream>
#include "Container/attributeContainer.h"
......@@ -430,227 +428,7 @@ void AttributeContainer::removeLine(unsigned int index)
/**************************************
* SAVE & LOAD *
**************************************/
//
//bool AttributeContainer::loadXmlBWF(xmlNodePtr node)
//{
// xmlChar* prop = xmlGetProp(node, BAD_CAST "nb");
// unsigned int nb = atoi((char*)prop);
// m_tableBlocksWithFree.clear();
//
// // charge et cree les attributs
// for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next)
// {
// unsigned int ind = atoi((char*)(xmlNodeGetContent(x_node)));
// m_tableBlocksWithFree.push_back(ind);
// }
// if (m_tableBlocksWithFree.size() != nb)
// {
// CGoGNerr <<"Erreur lecture fichier XML incoherent"<< CGoGNendl;
// return false;
// }
// return true;
//}
//
//bool AttributeContainer::loadXmlAN(xmlNodePtr node, unsigned int nbb)
//{
// xmlChar* prop = xmlGetProp(node, BAD_CAST "nb");
//// unsigned int nb = atoi((char*)prop);
// prop = xmlGetProp(node, BAD_CAST "sv");
//// unsigned int sv = atoi((char*)prop);
//
// // Noooooooo!!!!
//// m_tableAttribs.resize(sv);
//// for (unsigned int i=0; i< sv; ++i)
//// m_tableAttribs[i]=NULL;
//
// // charge et cree les attributs
// for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next)
// {
// prop = xmlGetProp(x_node, BAD_CAST "id");
//// unsigned int id = unsigned int(atoi((char*)prop);
//
// prop = xmlGetProp(x_node, BAD_CAST "type");
// // recupere l'attribut enregistrer par son type
// if (m_attributes_registry_map !=NULL)
// {
// std::map<std::string, RegisteredBaseAttribute*>::iterator itAtt = m_attributes_registry_map->find(std::string((char*)prop));
// if (itAtt == m_attributes_registry_map->end())
// {
// CGoGNout << "Skipping non registred attribute "<< std::string((char*)prop)<<CGoGNendl;
// }
// else
// {
// RegisteredBaseAttribute* ra = itAtt->second;
// prop = xmlGetProp(x_node, BAD_CAST "name");
//// ra->addAttribute(*this, std::string((char*)prop), id);
// AttributeMultiVectorGen* amvg = ra->addAttribute(*this, std::string((char*)prop));
// amvg->setNbBlocks(nbb);
// }
// }
// else
// {
// CGoGNerr << "Attribute Registry non initialized"<< CGoGNendl;
// return false;
// }
// }
//// if (m_attribNameMap.size() != nb)
//// {
//// CGoGNerr << "Pb lecture attributs"<< CGoGNendl;
//// return false;
//// }
// return true;
//}
//
//bool AttributeContainer::loadXmlDL(xmlNodePtr node)
//{
// // charge et cree les attributs
// for (xmlNode* x_node = node->children; x_node != NULL; x_node = x_node->next)
// {
// // get index
// xmlChar* prop = xmlGetProp(x_node, BAD_CAST "id");
// unsigned int id = atoi((char*)prop);
// // get & set nbref
// prop = xmlGetProp(x_node, BAD_CAST "refs");
// unsigned int nbr = atoi((char*)prop);
// setNbRefs(id, nbr);
//
// if (nbr > 0)
// {
//// for (MapNameId::iterator it = m_attribNameMap.begin(); it != m_attribNameMap.end(); ++it)
//// {
//// prop = xmlGetProp(x_node, BAD_CAST (it->first).c_str());
//// // if name of data unkwown then error
//// if (prop == NULL)
//// {
//// CGoGNerr << "inconsistent xml file"<<CGoGNendl;
//// return false;
//// }
//// m_tableAttribs[it->second]->input(id, std::string((char*)prop));
//// }
// }
// }
// return true;
//}
//
//void AttributeContainer::saveXml(xmlTextWriterPtr writer, unsigned int id)
//{
// if (m_nbAttributes == 0)
// return;
//
// // noeud du container
// int rc = xmlTextWriterStartElement(writer, BAD_CAST "Attributes_Container");
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id","%u",id);
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "BlockSize","%u",_BLOCKSIZE_);
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size","%u",m_maxSize);
//
// // recuperer le nombre d'attributs
// unsigned int nbAtt = m_nbAttributes;
// unsigned int sizeVectAtt = m_tableAttribs.size();
//
// // noeud avec la liste de attributs
// rc = xmlTextWriterStartElement(writer, BAD_CAST "Attributes_Names");
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "nb","%u",nbAtt);
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "sv","%u",sizeVectAtt);
//
// // recuperer les attributs dans la map et les sauver
//// for (std::map<std::string, unsigned int>::iterator it = m_attribNameMap.begin(); it!= m_attribNameMap.end(); ++it)
//// {
//// int rc = xmlTextWriterStartElement(writer, BAD_CAST "Attribute");
//// rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name",BAD_CAST (it->first).c_str());
//// const std::string& str_type = m_tableAttribs[it->second]->getTypeName();
//// rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "type",BAD_CAST str_type.c_str());
//// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id","%u",it->second);
//// rc = xmlTextWriterEndElement(writer);
//// }
// // fin du noeud
// rc = xmlTextWriterEndElement(writer);
//
// // parcourir le container et sauver les lignes
// rc = xmlTextWriterStartElement(writer, BAD_CAST "Data_Lines");
//// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size","%u",m_maxSize);
// for (unsigned int i = 0; i != m_maxSize; ++i)
// {
// unsigned int nbr = getNbRefs(i);
// rc = xmlTextWriterStartElement(writer, BAD_CAST "Line");
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id","%u",i);
// rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "refs","%u",nbr);
// if (nbr > 0)
// {
// // tous les attributs de la ligne
//// for (MapNameId::iterator it = m_attribNameMap.begin(); it!= m_attribNameMap.end(); ++it)
//// {
//// std::string st_att = m_tableAttribs[it->second]->output(i);
//// rc = xmlTextWriterWriteAttribute(writer,(xmlChar*)( (it->first).c_str()), (xmlChar*)( st_att.c_str()));
//// }
// }
// // fin du noeud Line
// rc = xmlTextWriterEndElement(writer);
// }
// // fin du noeud Data Lines
// rc = xmlTextWriterEndElement(writer);
//
// // fin du noeud Container
// rc = xmlTextWriterEndElement(writer);
//}
//
//unsigned int AttributeContainer::getIdXmlNode(xmlNodePtr node)
//{
// xmlChar *prop = xmlGetProp(node, BAD_CAST "id");
// unsigned int id = atoi((char*)prop);
// return id;
//}
//
//bool AttributeContainer::loadXml(xmlNodePtr node)
//{
// xmlChar *prop = xmlGetProp(node, BAD_CAST "BlockSize");
// unsigned int bs = atoi((char*)prop);
//
// if (bs != _BLOCKSIZE_)
// {
// CGoGNerr << "Chargement impossible, tailles de block differentes: "<<_BLOCKSIZE_<<" / " << bs << CGoGNendl;
// return false;
// }
//
//// prop = xmlGetProp(node, BAD_CAST "id");
//// unsigned int id = atoi((char*)prop);
//
// prop = xmlGetProp(node, BAD_CAST "size");
// m_maxSize = atoi((char*)prop);
//
// char* ANnode = (char*)"Attributes_Names";
// char* DLnode= (char*)"Data_Lines";
//
// // calcul le nombre de block et les alloue
// unsigned int nbb = m_maxSize/_BLOCKSIZE_;
// if (m_maxSize%_BLOCKSIZE_)
// nbb++;
//
// m_holesBlocks.resize(nbb);
// for (unsigned int i=0; i<nbb; ++i)
// m_holesBlocks[i] = new HoleBlockRef;
//
// //load Attributes
// xmlNode* cur = node->children;
// while ( strcmp((char*)(cur->name),ANnode))
// cur = cur->next;
// loadXmlAN(cur,nbb);
//
// cur = node->children;
// while ( strcmp((char*)(cur->name),DLnode))
// cur = cur->next;
// loadXmlDL(cur);
//
// // recreate free holes in blocks
// nbb--;
// for (unsigned int i = 0; i < nbb; ++i)
// {
// if (m_holesBlocks[i]->updateHoles(_BLOCKSIZE_))
// m_tableBlocksWithFree.push_back(i);
// }
// m_holesBlocks[nbb]->updateHoles(m_maxSize - nbb * _BLOCKSIZE_);
//
// return true;
//}
void AttributeContainer::saveBin(CGoGNostream& fs, unsigned int id) const
{
......
......@@ -29,9 +29,6 @@
#include <cassert>
#include <stdio.h>
#include <string.h>
#include <libxml/encoding.h>
#include <libxml/xmlwriter.h>
#include <libxml/parser.h>
#include <iostream>
#include <sstream>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment