Commit 3b558815 authored by Pierre Kraemer's avatar Pierre Kraemer

Merge cgogn:~untereiner/CGoGN

Conflicts:
	include/Algo/Import/import2tablesSurface.hpp
parents 7db271ad 50a9f367
...@@ -92,7 +92,6 @@ void MyQT::operation(int x) ...@@ -92,7 +92,6 @@ void MyQT::operation(int x)
if (m_selected != NIL) if (m_selected != NIL)
{ {
dm.markAll(); dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.uncutEdge(m_selected); myMap.uncutEdge(m_selected);
updateMap(); updateMap();
} }
...@@ -104,7 +103,6 @@ void MyQT::operation(int x) ...@@ -104,7 +103,6 @@ void MyQT::operation(int x)
if (myMap.deleteEdgePreCond(m_selected)) if (myMap.deleteEdgePreCond(m_selected))
{ {
dm.markAll(); dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.deleteEdge(m_selected); myMap.deleteEdge(m_selected);
m_selected = NIL; m_selected = NIL;
updateMap(); updateMap();
...@@ -155,7 +153,30 @@ void MyQT::operation(int x) ...@@ -155,7 +153,30 @@ void MyQT::operation(int x)
updateMap(); updateMap();
} }
break; break;
case 8:
CGoGNout <<"collapse face"<<CGoGNendl;
if (m_selected != NIL)
{
PFP::VEC3 Q = Algo::Geometry::faceCentroid<PFP>(myMap,m_selected,position);
Dart x = myMap.collapseFace(m_selected);
dm.markAll();
position[x]= Q;
m_selected = NIL;
updateMap();
}
break;
case 9:
CGoGNout <<"collapse volume"<<CGoGNendl;
if (m_selected != NIL)
{
PFP::VEC3 Q = Algo::Geometry::volumeCentroid<PFP>(myMap,m_selected,position);
Dart x = myMap.collapseVolume(m_selected);
dm.markAll();
position[x]= Q;
m_selected = NIL;
updateMap();
}
break;
default: default:
break; break;
} }
...@@ -284,8 +305,9 @@ void MyQT::cb_keyPress(int keycode) ...@@ -284,8 +305,9 @@ void MyQT::cb_keyPress(int keycode)
updateMap(); updateMap();
updateGL(); updateGL();
break; break;
case 'c':
myMap.check();
break;
case 'a': case 'a':
m_selected = myMap.phi1(m_selected); m_selected = myMap.phi1(m_selected);
updateGL(); updateGL();
...@@ -409,7 +431,7 @@ void MyQT::svg() ...@@ -409,7 +431,7 @@ void MyQT::svg()
void MyQT::cb_Open() void MyQT::cb_Open()
{ {
std::string filters("all (*.*);; trian (*.trian);; off (*.off);; ply (*.ply);; map (*.map)") ; std::string filters("all (*.*);; map (*.map)") ;
std::string filename = selectFile("Open Mesh", "", filters) ; std::string filename = selectFile("Open Mesh", "", filters) ;
if (!filename.empty()) if (!filename.empty())
importMesh(filename); importMesh(filename);
...@@ -434,16 +456,40 @@ void MyQT::importMesh(std::string& filename) ...@@ -434,16 +456,40 @@ void MyQT::importMesh(std::string& filename)
myMap.loadMapBin(filename); myMap.loadMapBin(filename);
position = myMap.getAttribute<PFP::VEC3>(VERTEX, "position") ; position = myMap.getAttribute<PFP::VEC3>(VERTEX, "position") ;
} }
else else if (extension == std::string(".node"))
{
std::vector<std::string> attrNames ;
if(!Algo::Import::importMeshV<PFP>(myMap, filename, attrNames, Algo::Import::ImportVolumique::NODE))
{
std::cerr << "could not import " << filename << std::endl ;
return ;
}
position = myMap.getAttribute<PFP::VEC3>(VERTEX, attrNames[0]) ;
}
else if(extension == std::string(".tet"))
{ {
std::vector<std::string> attrNames ; std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(myMap, filename.c_str(), attrNames)) if(!Algo::Import::importMeshV<PFP>(myMap, filename, attrNames, Algo::Import::ImportVolumique::TET))
{ {
CGoGNerr << "could not import " << filename << CGoGNendl ; std::cerr << "could not import " << filename << std::endl ;
return; return ;
} }
position = myMap.getAttribute<PFP::VEC3>(VERTEX, attrNames[0]) ; position = myMap.getAttribute<PFP::VEC3>(VERTEX, attrNames[0]) ;
} }
else if(extension == std::string(".off"))
{
std::vector<std::string> attrNames ;
if(!Algo::Import::importMeshV<PFP>(myMap, filename, attrNames, Algo::Import::ImportVolumique::OFF))
{
std::cerr << "could not import " << filename << std::endl ;
return ;
}
position = myMap.getAttribute<PFP::VEC3>(VERTEX, attrNames[0]) ;
}
else
{
std::cerr << "could not import " << filename << std::endl ;
}
m_selected = NIL; m_selected = NIL;
m_selected2 = NIL; m_selected2 = NIL;
......
...@@ -89,6 +89,16 @@ ...@@ -89,6 +89,16 @@
<string>splitVolume</string> <string>splitVolume</string>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>collapseFace</string>
</property>
</item>
<item>
<property name="text">
<string>collapseVolume</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item> <item>
......
...@@ -89,6 +89,9 @@ bool importMoka(typename PFP::MAP& gmap, const std::string& filename, std::vecto ...@@ -89,6 +89,9 @@ bool importMoka(typename PFP::MAP& gmap, const std::string& filename, std::vecto
template <typename PFP> template <typename PFP>
bool importOFFWithELERegions(typename PFP::MAP& the_map, const std::string& filenameOFF, const std::string& filenameELE, std::vector<std::string>& attrNames); bool importOFFWithELERegions(typename PFP::MAP& the_map, const std::string& filenameOFF, const std::string& filenameELE, std::vector<std::string>& attrNames);
template <typename PFP>
bool importNodeWithELERegions(typename PFP::MAP& map, const std::string& filenameNode, const std::string& filenameELE, std::vector<std::string>& attrNames);
template <typename PFP> template <typename PFP>
bool importTet(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f); bool importTet(typename PFP::MAP& the_map, const std::string& filename, std::vector<std::string>& attrNames, float scaleFactor = 1.0f);
...@@ -112,5 +115,6 @@ bool importTs(typename PFP::MAP& the_map, const std::string& filename, std::vect ...@@ -112,5 +115,6 @@ bool importTs(typename PFP::MAP& the_map, const std::string& filename, std::vect
#include "Algo/Import/importObjEle.hpp" #include "Algo/Import/importObjEle.hpp"
#include "Algo/Import/importTet.hpp" #include "Algo/Import/importTet.hpp"
#include "Algo/Import/importTs.hpp" #include "Algo/Import/importTs.hpp"
#include "Algo/Import/importNodeEle.hpp"
#endif #endif
...@@ -57,7 +57,7 @@ namespace Import ...@@ -57,7 +57,7 @@ namespace Import
namespace ImportVolumique namespace ImportVolumique
{ {
enum ImportType { UNKNOWNVOLUME , TET, ELE, TS }; enum ImportType { UNKNOWNVOLUME , TET, OFF, TS, NODE};
} }
......
...@@ -591,7 +591,7 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector< ...@@ -591,7 +591,7 @@ bool MeshTablesSurface<PFP>::importPly(const std::string& filename, std::vector<
CGoGNerr << "Unable to open file " << filename << CGoGNendl; CGoGNerr << "Unable to open file " << filename << CGoGNendl;
return false; return false;
} }
AttributeHandler<typename PFP::VEC3> colors = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "color") ; AttributeHandler<typename PFP::VEC3> colors = m_map.template getAttribute<typename PFP::VEC3>(VERTEX, "color") ;
if (pid.hasColors()) if (pid.hasColors())
{ {
...@@ -1102,7 +1102,6 @@ bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vect ...@@ -1102,7 +1102,6 @@ bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vect
} }
*/ */
template <typename PFP> template <typename PFP>
bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector<std::string>& attrNames) bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector<std::string>& attrNames)
{ {
...@@ -1116,7 +1115,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -1116,7 +1115,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
return false; return false;
} }
// Read header // Read header
AHEMHeader hdr; AHEMHeader hdr;
...@@ -1126,11 +1124,9 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -1126,11 +1124,9 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
if(hdr.magic != AHEM_MAGIC) if(hdr.magic != AHEM_MAGIC)
CGoGNerr << "Warning: " << filename << " invalid magic" << CGoGNendl; CGoGNerr << "Warning: " << filename << " invalid magic" << CGoGNendl;
m_nbVertices = hdr.meshHdr.vxCount; m_nbVertices = hdr.meshHdr.vxCount;
m_nbFaces = hdr.meshHdr.faceCount; m_nbFaces = hdr.meshHdr.faceCount;
// Read attributes // Read attributes
AHEMAttributeDescriptor* ahemAttrDesc = new AHEMAttributeDescriptor[hdr.attributesChunkNumber]; AHEMAttributeDescriptor* ahemAttrDesc = new AHEMAttributeDescriptor[hdr.attributesChunkNumber];
...@@ -1144,7 +1140,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -1144,7 +1140,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
fp.read(ahemAttrNames[i], ahemAttrDesc[i].nameSize); fp.read(ahemAttrNames[i], ahemAttrDesc[i].nameSize);
ahemAttrNames[i][ahemAttrDesc[i].nameSize] = '\0'; ahemAttrNames[i][ahemAttrDesc[i].nameSize] = '\0';
} }
// Compute buffer size for largest chunk and allocate // Compute buffer size for largest chunk and allocate
...@@ -1154,23 +1149,18 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -1154,23 +1149,18 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
if(ahemAttrDesc[i].attributeChunkSize > bufferSize) if(ahemAttrDesc[i].attributeChunkSize > bufferSize)
bufferSize = ahemAttrDesc[i].attributeChunkSize; bufferSize = ahemAttrDesc[i].attributeChunkSize;
char* buffer = new char[bufferSize]; char* buffer = new char[bufferSize];
// Allocate vertices // Allocate vertices
AttributeContainer& vxContainer = m_map.getAttributeContainer(VERTEX); AttributeContainer& vxContainer = m_map.getAttributeContainer(VERTEX);
std::vector<unsigned int> verticesId; std::vector<unsigned int> verticesId;
verticesId.resize(hdr.meshHdr.vxCount); verticesId.resize(hdr.meshHdr.vxCount);
for(unsigned int i = 0 ; i < hdr.meshHdr.vxCount ; i++) for(unsigned int i = 0 ; i < hdr.meshHdr.vxCount ; i++)
verticesId[i] = vxContainer.insertLine(); verticesId[i] = vxContainer.insertLine();
// Read faces stream // Read faces stream
m_nbEdges.resize(hdr.meshHdr.faceCount); m_nbEdges.resize(hdr.meshHdr.faceCount);
...@@ -1200,8 +1190,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -1200,8 +1190,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
fCount += fbd->batchLength; fCount += fbd->batchLength;
batch = (char*)ix; batch = (char*)ix;
} }
// Read positions // Read positions
...@@ -1215,11 +1203,13 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -1215,11 +1203,13 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
AHEMAttributeDescriptor* posDesc = NULL; AHEMAttributeDescriptor* posDesc = NULL;
for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++) for(unsigned int i = 0 ; i < hdr.attributesChunkNumber ; i++)
{
if(IsEqualGUID(ahemAttrDesc[i].semantic, AHEMATTRIBUTE_POSITION)) if(IsEqualGUID(ahemAttrDesc[i].semantic, AHEMATTRIBUTE_POSITION))
{ {
posDesc = ahemAttrDesc + i; posDesc = ahemAttrDesc + i;
break; break;
} }
}
fp.seekg(posDesc->fileStartOffset, std::ios_base::beg); fp.seekg(posDesc->fileStartOffset, std::ios_base::beg);
fp.read(buffer, posDesc->attributeChunkSize); fp.read(buffer, posDesc->attributeChunkSize);
...@@ -1232,9 +1222,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -1232,9 +1222,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
q += 3; q += 3;
} }
// Close file and release allocated stuff // Close file and release allocated stuff
fp.close(); fp.close();
...@@ -1249,7 +1236,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector ...@@ -1249,7 +1236,6 @@ bool MeshTablesSurface<PFP>::importAHEM(const std::string& filename, std::vector
return true; return true;
} }
#ifdef WITH_ASSIMP #ifdef WITH_ASSIMP
template<typename PFP> template<typename PFP>
void MeshTablesSurface<PFP>::extractMeshRec(AttributeContainer& container, AttributeHandler<typename PFP::VEC3>& positions, const struct aiScene* scene, const struct aiNode* nd, struct aiMatrix4x4* trafo) void MeshTablesSurface<PFP>::extractMeshRec(AttributeContainer& container, AttributeHandler<typename PFP::VEC3>& positions, const struct aiScene* scene, const struct aiNode* nd, struct aiMatrix4x4* trafo)
...@@ -1332,9 +1318,9 @@ bool MeshTablesSurface<PFP>::importASSIMP(const std::string& filename, std::vect ...@@ -1332,9 +1318,9 @@ bool MeshTablesSurface<PFP>::importASSIMP(const std::string& filename, std::vect
template<typename PFP> template<typename PFP>
bool MeshTablesSurface<PFP>::mergeCloseVertices() bool MeshTablesSurface<PFP>::mergeCloseVertices()
{ {
const int NBV=64; // seems to be good const int NBV = 64; // seems to be good
const int NEIGH[27]={ const int NEIGH[27] = {
-NBV*NBV - NBV - 1, -NBV*NBV - NBV, -NBV*NBV - NBV + 1, -NBV*NBV - NBV - 1, -NBV*NBV - NBV, -NBV*NBV - NBV + 1,
-NBV*NBV - 1, -NBV*NBV, -NBV*NBV + 1, -NBV*NBV - 1, -NBV*NBV, -NBV*NBV + 1,
-NBV*NBV + NBV - 1, -NBV*NBV + NBV, - NBV*NBV + NBV + 1, -NBV*NBV + NBV - 1, -NBV*NBV + NBV, - NBV*NBV + NBV + 1,
...@@ -1368,12 +1354,10 @@ bool MeshTablesSurface<PFP>::mergeCloseVertices() ...@@ -1368,12 +1354,10 @@ bool MeshTablesSurface<PFP>::mergeCloseVertices()
bb.addPoint( bb.min() - one); bb.addPoint( bb.min() - one);
bb.addPoint( bb.max() + one); bb.addPoint( bb.max() + one);
bbsize = (bb.max() - bb.min()); bbsize = (bb.max() - bb.min());
AutoAttributeHandler<unsigned int> gridIndex(m_map,VERTEX, "gridIndex"); AutoAttributeHandler<unsigned int> gridIndex(m_map,VERTEX, "gridIndex");
AutoAttributeHandler<unsigned int> newIndices(m_map,VERTEX, "newIndices"); AutoAttributeHandler<unsigned int> newIndices(m_map,VERTEX, "newIndices");
// Store each vertex in the grid and store voxel index in vertex attribute // Store each vertex in the grid and store voxel index in vertex attribute
for (unsigned int i = positions.begin(); i != positions.end(); positions.next(i)) for (unsigned int i = positions.begin(); i != positions.end(); positions.next(i))
{ {
...@@ -1479,8 +1463,6 @@ bool MeshTablesSurface<PFP>::mergeCloseVertices() ...@@ -1479,8 +1463,6 @@ bool MeshTablesSurface<PFP>::mergeCloseVertices()
return true; return true;
} }
} // namespace Import } // namespace Import
} // namespace Algo } // namespace Algo
......
...@@ -37,8 +37,8 @@ ImportVolumique::ImportType MeshTablesVolume<PFP>::getFileType(const std::string ...@@ -37,8 +37,8 @@ ImportVolumique::ImportType MeshTablesVolume<PFP>::getFileType(const std::string
if ((filename.rfind(".tet")!=std::string::npos) || (filename.rfind(".TET")!=std::string::npos)) if ((filename.rfind(".tet")!=std::string::npos) || (filename.rfind(".TET")!=std::string::npos))
return ImportVolumique::TET; return ImportVolumique::TET;
if ((filename.rfind(".ele")!=std::string::npos) || (filename.rfind(".ELE")!=std::string::npos)) if ((filename.rfind(".node")!=std::string::npos) || (filename.rfind(".NODE")!=std::string::npos))
return ImportVolumique::ELE; return ImportVolumique::NODE;
if ((filename.rfind(".ts")!=std::string::npos) || (filename.rfind(".TS")!=std::string::npos)) if ((filename.rfind(".ts")!=std::string::npos) || (filename.rfind(".TS")!=std::string::npos))
return ImportVolumique::TS; return ImportVolumique::TS;
...@@ -56,7 +56,7 @@ bool MeshTablesVolume<PFP>::importMesh(const std::string& filename, std::vector< ...@@ -56,7 +56,7 @@ bool MeshTablesVolume<PFP>::importMesh(const std::string& filename, std::vector<
case ImportVolumique::TET: case ImportVolumique::TET:
return importTet(filename, attrNames, scaleFactor); return importTet(filename, attrNames, scaleFactor);
break; break;
case ImportVolumique::ELE: case ImportVolumique::NODE:
break; break;
case ImportVolumique::TS: case ImportVolumique::TS:
break; break;
......
...@@ -268,8 +268,8 @@ bool importMeshV(typename PFP::MAP& map, const std::string& filename, std::vecto ...@@ -268,8 +268,8 @@ bool importMeshV(typename PFP::MAP& map, const std::string& filename, std::vecto
if ((filename.rfind(".tet") != std::string::npos) || (filename.rfind(".TET") != std::string::npos)) if ((filename.rfind(".tet") != std::string::npos) || (filename.rfind(".TET") != std::string::npos))
kind = ImportVolumique::TET; kind = ImportVolumique::TET;
if ((filename.rfind(".ele") != std::string::npos) || (filename.rfind(".ELE") != std::string::npos)) if ((filename.rfind(".off") != std::string::npos) || (filename.rfind(".OFF") != std::string::npos))
kind = ImportVolumique::ELE; kind = ImportVolumique::OFF;
if ((filename.rfind(".ts") != std::string::npos) || (filename.rfind(".TS") != std::string::npos)) if ((filename.rfind(".ts") != std::string::npos) || (filename.rfind(".TS") != std::string::npos))
kind = ImportVolumique::TS; kind = ImportVolumique::TS;
...@@ -279,13 +279,22 @@ bool importMeshV(typename PFP::MAP& map, const std::string& filename, std::vecto ...@@ -279,13 +279,22 @@ bool importMeshV(typename PFP::MAP& map, const std::string& filename, std::vecto
case ImportVolumique::TET: case ImportVolumique::TET:
return Algo::Import::importTet<PFP>(map, filename, attrNames, 1.0f); return Algo::Import::importTet<PFP>(map, filename, attrNames, 1.0f);
break; break;
case ImportVolumique::ELE: case ImportVolumique::OFF:
{ {
size_t pos = filename.rfind("."); size_t pos = filename.rfind(".");
std::string fileOFF = filename; std::string fileEle = filename;
fileOFF.erase(pos); fileEle.erase(pos);
fileOFF.append(".off"); fileEle.append(".ele");
return Algo::Import::importOFFWithELERegions<PFP>(map, fileOFF, filename, attrNames); return Algo::Import::importOFFWithELERegions<PFP>(map, filename, fileEle, attrNames);
break;
}
case ImportVolumique::NODE:
{
size_t pos = filename.rfind(".");
std::string fileEle = filename;
fileEle.erase(pos);
fileEle.append(".ele");
return Algo::Import::importNodeWithELERegions<PFP>(map, filename, fileEle, attrNames);
break; break;
} }
case ImportVolumique::TS: case ImportVolumique::TS:
......
...@@ -323,7 +323,7 @@ public: ...@@ -323,7 +323,7 @@ public:
/** /**
* Traverse volumes adjacent to a volumee by a vertex * Traverse volumes adjacent to a volume by a vertex
*/ */
template <typename MAP> template <typename MAP>
class Traversor3WWaV: public Traversor3XXaY<MAP> class Traversor3WWaV: public Traversor3XXaY<MAP>
...@@ -333,7 +333,7 @@ public: ...@@ -333,7 +333,7 @@ public:
}; };
/** /**
* Traverse volumes adjacent to a volumee by an edge * Traverse volumes adjacent to a volume by an edge
*/ */
template <typename MAP> template <typename MAP>
class Traversor3WWaE: public Traversor3XXaY<MAP> class Traversor3WWaE: public Traversor3XXaY<MAP>
...@@ -343,7 +343,7 @@ public: ...@@ -343,7 +343,7 @@ public:
}; };
/** /**
* Traverse volumes adjacent to a volumee by a face * Traverse volumes adjacent to a volume by a face
*/ */
template <typename MAP> template <typename MAP>
class Traversor3WWaF: public Traversor3XXaY<MAP> class Traversor3WWaF: public Traversor3XXaY<MAP>
......
...@@ -78,6 +78,12 @@ public: ...@@ -78,6 +78,12 @@ public:
*/ */
virtual void splitFace(Dart d, Dart e); virtual void splitFace(Dart d, Dart e);
//!
/*!
*
*/
virtual Dart collapseFace(Dart d, bool delDegenerateVolumes = true);
//! //!
/*! /*!
*/ */
...@@ -98,6 +104,11 @@ public: ...@@ -98,6 +104,11 @@ public:
*/ */
virtual void splitVolume(std::vector<Dart>& vd); virtual void splitVolume(std::vector<Dart>& vd);
//!
/*!
*/
virtual Dart collapseVolume(Dart d, bool delDegenerateVolumes = true);
//! //!
/*! No attribute is attached to the new volume /*! No attribute is attached to the new volume
*/ */
......
/*******************************************************************************
* 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 *