Commit d6c0e496 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge remote-tracking branch 'cgogn/develop' into develop

parents 7a3e52d4 ffaa09d7
...@@ -58,7 +58,8 @@ ENDIF(WIN32) ...@@ -58,7 +58,8 @@ ENDIF(WIN32)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(Boost COMPONENTS regex REQUIRED) find_package(Boost COMPONENTS regex REQUIRED)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
find_package(LibXml2 REQUIRED) #find_package(LibXml2 REQUIRED)
find_package(TinyXml2 REQUIRED)
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
# MESSAGE HERE FOR MORE EASY USER READING # MESSAGE HERE FOR MORE EASY USER READING
...@@ -98,7 +99,7 @@ SET (CGoGN_EXT_INCLUDES ...@@ -98,7 +99,7 @@ SET (CGoGN_EXT_INCLUDES
${OPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS}
${LIBXML2_INCLUDE_DIR} ${TINYXML2_INCLUDE_DIR}
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
) )
...@@ -108,7 +109,7 @@ SET (CGoGN_EXT_LIBS ...@@ -108,7 +109,7 @@ SET (CGoGN_EXT_LIBS
${OPENGL_LIBRARY} ${OPENGL_LIBRARY}
${GLEW_LIBRARIES} ${GLEW_LIBRARIES}
${ZLIB_LIBRARIES} ${ZLIB_LIBRARIES}
${LIBXML2_LIBRARIES} ${TINYXML2_LIBRARY}
${Boost_REGEX_LIBRARY} ${Boost_REGEX_LIBRARY}
) )
......
...@@ -3,7 +3,7 @@ English version bellow ...@@ -3,7 +3,7 @@ English version bellow
Dépendences Linux Dépendences Linux
================= =================
installer les paquets suivants: 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 Pour compiler CGoGN
......
#########################
# UPDATE VARIABLES:
# - TINYXML2_FOUND
# - TINYXML2_INCLUDE_DIR
# - TINYXML2_LIBRARY
#########################
find_path(TINYXML2_INCLUDE_DIR tinyxml2.h
HINTS $ENV{TINYXML2DIR}
PATH_SUFFIXES include
PATHS ~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr)
find_library(TINYXML2_LIBRARY tinyxml2
HINTS $ENV{TINYXML2DIR}
PATH_SUFFIXES lib64 lib
PATH_SUFFIXESS ~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(TINYXML2 DEFAULT_MSG TINYXML2_LIBRARY)
mark_as_advanced(TINYXML2_LIBRARY TINYXML2_INCLUDE_DIR)
...@@ -24,9 +24,12 @@ ...@@ -24,9 +24,12 @@
#include "Geometry/orientation.h" #include "Geometry/orientation.h"
#include <libxml/encoding.h> //#include <libxml/encoding.h>
#include <libxml/xmlwriter.h> //#include <libxml/xmlwriter.h>
#include <libxml/parser.h> //#include <libxml/parser.h>
//#include <tinyxml2.h>
#include "Utils/xml.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -1436,9 +1439,249 @@ bool MeshTablesVolume<PFP>::importVBGZ(const std::string& filename, std::vector< ...@@ -1436,9 +1439,249 @@ bool MeshTablesVolume<PFP>::importVBGZ(const std::string& filename, std::vector<
return true; return true;
} }
//template <typename PFP>
//bool MeshTablesVolume<PFP>::importVTU(const std::string& filename, std::vector<std::string>& attrNames)
//{
// VertexAttribute<VEC3, MAP> position = m_map.template getAttribute<VEC3, VERTEX, MAP>("position") ;
// if (!position.isValid())
// position = m_map.template addAttribute<VEC3, VERTEX, MAP>("position") ;
// attrNames.push_back(position.name()) ;
// //
// AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ;
// xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
// xmlNodePtr vtu_node = xmlDocGetRootElement(doc);
// // std::cout << " NAME "<<vtu_node->name << std::endl;
// xmlChar *prop = xmlGetProp(vtu_node, BAD_CAST "type");
// // std::cout << "type = "<< prop << std::endl;
// xmlNode* grid_node = vtu_node->children;
// while (strcmp((char*)(grid_node->name),(char*)"UnstructuredGrid")!=0)
// grid_node = grid_node->next;
// xmlNode* piece_node = grid_node->children;
// while (strcmp((char*)(piece_node->name),(char*)"Piece")!=0)
// piece_node = piece_node->next;
// prop = xmlGetProp(piece_node, BAD_CAST "NumberOfPoints");
// m_nbVertices = atoi((char*)(prop));
// prop = xmlGetProp(piece_node, BAD_CAST "NumberOfCells");
// m_nbVolumes = atoi((char*)(prop));
// std::cout << "Number of points = "<< m_nbVertices<< std::endl;
// std::cout << "Number of cells = "<< m_nbVolumes << std::endl;
// xmlNode* points_node = piece_node->children;
// while (strcmp((char*)(points_node->name),(char*)"Points")!=0)
// points_node = points_node->next;
// points_node = points_node->children;
// while (strcmp((char*)(points_node->name),(char*)"DataArray")!=0)
// points_node = points_node->next;
// std::vector<unsigned int> verticesID;
// verticesID.reserve(m_nbVertices);
// std::stringstream ss((char*)(xmlNodeGetContent(points_node->children)));
// for (unsigned int i=0; i< m_nbVertices; ++i)
// {
// typename PFP::VEC3 P;
// ss >> P[0]; ss >> P[1]; ss >> P[2];
// unsigned int id = container.insertLine();
// position[id] = P;
// verticesID.push_back(id);
// }
// xmlNode* cell_node = piece_node->children;
// while (strcmp((char*)(cell_node->name),(char*)"Cells")!=0)
// cell_node = cell_node->next;
// std::cout <<"CELL NODE = "<< cell_node->name << std::endl;
// std::vector<unsigned char> typeVols;
// typeVols.reserve(m_nbVolumes);
// std::vector<unsigned int> offsets;
// offsets.reserve(m_nbVolumes);
// std::vector<unsigned int> indices;
// indices.reserve(m_nbVolumes*4);
// for (xmlNode* x_node = cell_node->children; x_node!=NULL; x_node = x_node->next)
// {
// while ((x_node!=NULL) && (strcmp((char*)(x_node->name),(char*)"DataArray")!=0))
// x_node = x_node->next;
// if (x_node == NULL)
// break;
// else
// {
// xmlChar* type = xmlGetProp(x_node, BAD_CAST "Name");
// if (strcmp((char*)(type),(char*)"connectivity")==0)
// {
// std::stringstream ss((char*)(xmlNodeGetContent(x_node->children)));
// while (!ss.eof())
// {
// unsigned int ind;
// ss >> ind;
// indices.push_back(ind);
// }
// }
// if (strcmp((char*)(type),(char*)"offsets")==0)
// {
// std::stringstream ss((char*)(xmlNodeGetContent(x_node->children)));
// for (unsigned int i=0; i< m_nbVolumes; ++i)
// {
// unsigned int o;
// ss >> o;
// offsets.push_back(o);
// }
// }
// if (strcmp((char*)(type),(char*)"types")==0)
// {
// bool unsupported = false;
// std::stringstream ss((char*)(xmlNodeGetContent(x_node->children)));
// for (unsigned int i=0; i< m_nbVolumes; ++i)
// {
// unsigned int t;
// ss >> t;
// if ((t != 12) && (t!= 10))
// {
// unsupported = true;
// typeVols.push_back(0);
// }
// else
// {
// typeVols.push_back((unsigned char)t);
// }
// }
// if (unsupported)
// CGoGNerr << "warning, some unsupported volume cell types"<< CGoGNendl;
// }
// }
// }
// xmlFreeDoc(doc);
// unsigned int currentOffset = 0;
// for (unsigned int i=0; i< m_nbVolumes; ++i)
// {
// if (typeVols[i]==12)
// {
// m_nbFaces.push_back(8);
// unsigned int pt[8];
// pt[0] = indices[currentOffset];
// pt[1] = indices[currentOffset+1];
// pt[2] = indices[currentOffset+2];
// pt[3] = indices[currentOffset+3];
// pt[4] = indices[currentOffset+4];
// typename PFP::VEC3 P = position[verticesID[indices[currentOffset+4]]];
// typename PFP::VEC3 A = position[verticesID[indices[currentOffset ]]];
// typename PFP::VEC3 B = position[verticesID[indices[currentOffset+1]]];
// typename PFP::VEC3 C = position[verticesID[indices[currentOffset+2]]];
// if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::OVER)
// {
// pt[0] = indices[currentOffset+3];
// pt[1] = indices[currentOffset+2];
// pt[2] = indices[currentOffset+1];
// pt[3] = indices[currentOffset+0];
// pt[4] = indices[currentOffset+7];
// pt[5] = indices[currentOffset+6];
// pt[6] = indices[currentOffset+5];
// pt[7] = indices[currentOffset+4];
// }
// else
// {
// pt[0] = indices[currentOffset+0];
// pt[1] = indices[currentOffset+1];
// pt[2] = indices[currentOffset+2];
// pt[3] = indices[currentOffset+3];
// pt[4] = indices[currentOffset+4];
// pt[5] = indices[currentOffset+5];
// pt[6] = indices[currentOffset+6];
// pt[7] = indices[currentOffset+7];
// }
// m_emb.push_back(verticesID[pt[0]]);
// m_emb.push_back(verticesID[pt[1]]);
// m_emb.push_back(verticesID[pt[2]]);
// m_emb.push_back(verticesID[pt[3]]);
// m_emb.push_back(verticesID[pt[4]]);
// m_emb.push_back(verticesID[pt[5]]);
// m_emb.push_back(verticesID[pt[6]]);
// m_emb.push_back(verticesID[pt[7]]);
// }
// else if (typeVols[i]==10)
// {
// m_nbFaces.push_back(4);
// Geom::Vec4ui pt;
// pt[0] = indices[currentOffset];
// pt[1] = indices[currentOffset+1];
// pt[2] = indices[currentOffset+2];
// pt[3] = indices[currentOffset+3];
// typename PFP::VEC3 P = position[verticesID[pt[0]]];
// typename PFP::VEC3 A = position[verticesID[pt[1]]];
// typename PFP::VEC3 B = position[verticesID[pt[2]]];
// typename PFP::VEC3 C = position[verticesID[pt[3]]];
// if (Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::OVER)
// {
// unsigned int ui=pt[1];
// pt[1] = pt[2];
// pt[2] = ui;
// }
// m_emb.push_back(verticesID[pt[0]]);
// m_emb.push_back(verticesID[pt[1]]);
// m_emb.push_back(verticesID[pt[2]]);
// m_emb.push_back(verticesID[pt[3]]);
// }
// currentOffset = offsets[i];
// }
// return true;
//}
//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);
//}
template <typename PFP> template <typename PFP>
bool MeshTablesVolume<PFP>::importVTU(const std::string& filename, std::vector<std::string>& attrNames) bool MeshTablesVolume<PFP>::importVTU(const std::string& filename, std::vector<std::string>& attrNames)
{ {
VertexAttribute<VEC3, MAP> position = m_map.template getAttribute<VEC3, VERTEX, MAP>("position") ; VertexAttribute<VEC3, MAP> position = m_map.template getAttribute<VEC3, VERTEX, MAP>("position") ;
if (!position.isValid()) if (!position.isValid())
...@@ -1449,43 +1692,36 @@ bool MeshTablesVolume<PFP>::importVTU(const std::string& filename, std::vector<s ...@@ -1449,43 +1692,36 @@ bool MeshTablesVolume<PFP>::importVTU(const std::string& filename, std::vector<s
// //
AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ; AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ;
xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0);
xmlNodePtr vtu_node = xmlDocGetRootElement(doc);
// std::cout << " NAME "<<vtu_node->name << std::endl;
xmlChar *prop = xmlGetProp(vtu_node, BAD_CAST "type");
// std::cout << "type = "<< prop << std::endl;
xmlNode* grid_node = vtu_node->children; tinyxml2::XMLDocument doc;
while (strcmp((char*)(grid_node->name),(char*)"UnstructuredGrid")!=0) tinyxml2::XMLError eResult = doc.LoadFile(filename.c_str());
grid_node = grid_node->next;
xmlNode* piece_node = grid_node->children; if (XMLisError(eResult,"unable loading file"+filename))
while (strcmp((char*)(piece_node->name),(char*)"Piece")!=0) return false;
piece_node = piece_node->next;
prop = xmlGetProp(piece_node, BAD_CAST "NumberOfPoints"); tinyxml2::XMLElement* vtu_node = doc.RootElement();
m_nbVertices = atoi((char*)(prop));
prop = xmlGetProp(piece_node, BAD_CAST "NumberOfCells"); tinyxml2::XMLElement* grid_node = vtu_node->FirstChildElement("UnstructuredGrid");
m_nbVolumes = atoi((char*)(prop)); tinyxml2::XMLElement* piece_node = grid_node->FirstChildElement("Piece");
std::cout << "Number of points = "<< m_nbVertices<< std::endl; eResult = piece_node->QueryUnsignedAttribute("NumberOfPoints",&m_nbVertices);
std::cout << "Number of cells = "<< m_nbVolumes << std::endl; if (XMLisError(eResult,"unreadable VTU file: "+filename))
return false;
eResult = piece_node->QueryUnsignedAttribute("NumberOfCells",&m_nbVolumes);
if (XMLisError(eResult,"unreadable VTU file: "+filename))
return false;
xmlNode* points_node = piece_node->children; CGoGNout << "Number of points = "<< m_nbVertices<< CGoGNendl;
while (strcmp((char*)(points_node->name),(char*)"Points")!=0) CGoGNout << "Number of cells = "<< m_nbVolumes << CGoGNendl;
points_node = points_node->next;
points_node = points_node->children; tinyxml2::XMLElement* points_node = piece_node->FirstChildElement("Points");
while (strcmp((char*)(points_node->name),(char*)"DataArray")!=0) tinyxml2::XMLElement* array_node = points_node->FirstChildElement("DataArray");
points_node = points_node->next;
std::vector<unsigned int> verticesID; std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices); verticesID.reserve(m_nbVertices);
std::stringstream ss((char*)(xmlNodeGetContent(points_node->children))); std::stringstream ss(array_node->GetText());
for (unsigned int i=0; i< m_nbVertices; ++i) for (unsigned int i=0; i< m_nbVertices; ++i)
{ {
typename PFP::VEC3 P; typename PFP::VEC3 P;
...@@ -1495,12 +1731,8 @@ bool MeshTablesVolume<PFP>::importVTU(const std::string& filename, std::vector<s ...@@ -1495,12 +1731,8 @@ bool MeshTablesVolume<PFP>::importVTU(const std::string& filename, std::vector<s
verticesID.push_back(id); verticesID.push_back(id);
} }
xmlNode* cell_node = piece_node->children; tinyxml2::XMLElement* cell_node = piece_node->FirstChildElement("Cells");
while (strcmp((char*)(cell_node->name),(char*)"Cells")!=0) array_node = cell_node->FirstChildElement("DataArray");
cell_node = cell_node->next;
std::cout <<"CELL NODE = "<< cell_node->name << std::endl;
std::vector<unsigned char> typeVols; std::vector<unsigned char> typeVols;
typeVols.reserve(m_nbVolumes); typeVols.reserve(m_nbVolumes);
...@@ -1509,63 +1741,60 @@ bool MeshTablesVolume<PFP>::importVTU(const std::string& filename, std::vector<s ...@@ -1509,63 +1741,60 @@ bool MeshTablesVolume<PFP>::importVTU(const std::string& filename, std::vector<s
std::vector<unsigned int> indices; std::vector<unsigned int> indices;
indices.reserve(m_nbVolumes*4); indices.reserve(m_nbVolumes*4);
for (xmlNode* x_node = cell_node->children; x_node!=NULL; x_node = x_node->next) while (array_node)
{ {
while ((x_node!=NULL) && (strcmp((char*)(x_node->name),(char*)"DataArray")!=0)) std::string propName = XMLAttribute(array_node,"Name");
x_node = x_node->next;
if (x_node == NULL) if (propName == "")
break;
else
{ {
xmlChar* type = xmlGetProp(x_node, BAD_CAST "Name"); CGoGNerr << "Error reading VTU unreadable file: "<<filename<< CGoGNendl;
return false;
}
if (strcmp((char*)(type),(char*)"connectivity")==0) if (propName == "connectivity")
{
std::stringstream ss(array_node->GetText());
while (!ss.eof())
{ {
std::stringstream ss((char*)(xmlNodeGetContent(x_node->children))); unsigned int ind;
while (!ss.eof()) ss >> ind;
{ indices.push_back(ind);
unsigned int ind;
ss >> ind;
indices.push_back(ind);
}
} }
if (strcmp((char*)(type),(char*)"offsets")==0) }
if (propName == "offsets")
{
std::stringstream ss(array_node->GetText());
for (unsigned int i=0; i< m_nbVolumes; ++i)
{ {
std::stringstream ss((char*)(xmlNodeGetContent(x_node->children))); unsigned int o;
for (unsigned int i=0; i< m_nbVolumes; ++i) ss >> o;
{ offsets.push_back(o);
unsigned int o;
ss >> o;
offsets.push_back(o);
}
} }
if (strcmp((char*)(type),(char*)"types")==0) }
if (propName == "types")
{
bool unsupported = false;
std::stringstream ss(array_node->GetText());
for (unsigned int i=0; i< m_nbVolumes; ++i)
{ {
bool unsupported = false; unsigned int t;
std::stringstream ss((char*)(xmlNodeGetContent(x_node->children))); ss >> t;
for (unsigned int i=0; i< m_nbVolumes; ++i) if ((t != 12) && (t!= 10))
{ {
unsigned int t; unsupported = true;
ss >> t; typeVols.push_back(0);
if ((t != 12) && (t!= 10)) }
{ else
unsupported = true; {
typeVols.push_back(0); typeVols.push_back((unsigned char)t);
}
else
{
typeVols.push_back((unsigned char)t);
}
} }
if (unsupported)
CGoGNerr << "warning, some unsupported volume cell types"<< CGoGNendl;
} }
if (unsupported)
CGoGNerr << "warning, some unsupported volume cell types"<< CGoGNendl;
} }
array_node = array_node->NextSiblingElement("DataArray");
} }
xmlFreeDoc(doc);
unsigned int currentOffset = 0; unsigned int currentOffset = 0;
for (unsigned int i=0; i< m_nbVolumes; ++i) for (unsigned int i=0; i< m_nbVolumes; ++i)
{ {
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#ifndef __IMPORTSVG_H__ #ifndef __IMPORTSVG_H__
#define __IMPORTSVG_H__ #define __IMPORTSVG_H__
#include "Utils/xml.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -43,16 +45,16 @@ namespace Import ...@@ -43,16 +45,16 @@ namespace Import
* @param name the name * @param name the name
* @ return true if node has the good 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> 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 > >& allPoly,
std::vector<std::vector<VEC3 > >& allBrokenLines, std::vector<std::vector<VEC3 > >& allBrokenLines,
std::vector<float>& allBrokenLinesWidth); std::vector<float>& allBrokenLinesWidth);
template <typename PFP> 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 @@ ...@@ -26,9 +26,13 @@
#include "Geometry/bounding_box.h" #include "Geometry/bounding_box.h"
#include "Geometry/plane_3d.h" #include "Geometry/plane_3d.h"
#include "Algo/BooleanOperator/mergeVertices.h" #include "Algo/BooleanOperator/mergeVertices.h"
#include "Algo/Topo/basic.h"
#include "Container/fakeAttribute.h" #include "Container/fakeAttribute.h"
#include <limits> #include <limits>
#include "Utils/xml.h" // just for highlighting/completion in editor
namespace CGoGN namespace CGoGN
{ {
...@@ -41,9 +45,14 @@ namespace Surface ...@@ -41,9 +45,14 @@ namespace Surface
namespace Import namespace Import