Commit d0e590fe authored by Thomas's avatar Thomas

correcting comments and sliceConvexVolumes

parents b6a9b24e 04072a3b
......@@ -28,11 +28,11 @@
#include <iostream>
#include "Utils/Qt/qtSimple.h"
#include "Utils/Qt/qtInputs.h"
#include "Utils/qtInputs.h"
#include "ui_clipping.h"
// inclure qtui.h juste après le ui_xxx.h
#include "Utils/Qt/qtui.h"
#include "Utils/qtui.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap3.h"
......
......@@ -17,7 +17,7 @@
* 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: https://iggservis.u-strasbg.fr/CGoGN/ *
* Web site: http://cgogn.unistra.fr *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
......@@ -26,7 +26,7 @@
#include "Utils/Qt/qtSimple.h"
#include "ui_mcmesh.h"
#include "Utils/Qt/qtui.h"
#include "Utils/qtui.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
......
......@@ -30,6 +30,7 @@ Viewer::Viewer() :
m_drawEdges(false),
m_drawFaces(true),
m_drawNormals(false),
m_drawTopo(false),
m_render(NULL),
m_phongShader(NULL),
m_flatShader(NULL),
......@@ -68,6 +69,7 @@ void Viewer::initGUI()
setCallBack( dock.check_drawEdges, SIGNAL(toggled(bool)), SLOT(slot_drawEdges(bool)) ) ;
setCallBack( dock.check_drawFaces, SIGNAL(toggled(bool)), SLOT(slot_drawFaces(bool)) ) ;
setCallBack( dock.combo_faceLighting, SIGNAL(currentIndexChanged(int)), SLOT(slot_faceLighting(int)) ) ;
setCallBack( dock.check_drawTopo, SIGNAL(toggled(bool)), SLOT(slot_drawTopo(bool)) ) ;
setCallBack( dock.check_drawNormals, SIGNAL(toggled(bool)), SLOT(slot_drawNormals(bool)) ) ;
setCallBack( dock.slider_normalsSize, SIGNAL(valueChanged(int)), SLOT(slot_normalsSize(int)) ) ;
}
......@@ -79,6 +81,9 @@ void Viewer::cb_initGL()
setFocal(5.0f) ;
m_render = new Algo::Render::GL2::MapRender() ;
m_topoRender = new Algo::Render::GL2::TopoRender() ;
m_topoRender->setInitialDartsColor(0.25f, 0.25f, 0.25f) ;
m_positionVBO = new Utils::VBO() ;
m_normalVBO = new Utils::VBO() ;
......@@ -119,7 +124,6 @@ void Viewer::cb_initGL()
void Viewer::cb_redraw()
{
//glClearColor(1,1,1,0);
if(m_drawVertices)
{
float size = vertexScaleFactor ;
......@@ -135,14 +139,6 @@ void Viewer::cb_redraw()
m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES) ;
}
if(m_drawNormals)
{
float size = normalBaseSize * normalScaleFactor ;
m_vectorShader->setScale(size) ;
glLineWidth(1.0f) ;
m_render->draw(m_vectorShader, Algo::Render::GL2::POINTS) ;
}
if(m_drawFaces)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
......@@ -161,6 +157,19 @@ void Viewer::cb_redraw()
}
glDisable(GL_POLYGON_OFFSET_FILL) ;
}
if(m_drawTopo)
{
m_topoRender->drawTopo() ;
}
if(m_drawNormals)
{
float size = normalBaseSize * normalScaleFactor ;
m_vectorShader->setScale(size) ;
glLineWidth(1.0f) ;
m_render->draw(m_vectorShader, Algo::Render::GL2::POINTS) ;
}
}
void Viewer::cb_Open()
......@@ -209,6 +218,8 @@ void Viewer::importMesh(std::string& filename)
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES) ;
m_topoRender->updateData<PFP>(myMap, position, 0.85f, 0.85f) ;
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
normalBaseSize = bb.diagSize() / 100.0f ;
// vertexBaseSize = normalBaseSize / 5.0f ;
......@@ -234,7 +245,11 @@ void Viewer::exportMesh(std::string& filename)
if (extension == std::string(".off"))
Algo::Export::exportOFF<PFP>(myMap, position, filename.c_str(), allDarts) ;
else if (extension.compare(0, 4, std::string(".ply")) == 0)
Algo::Export::exportPLY<PFP>(myMap, position, filename.c_str(), allDarts) ;
{
std::vector<PFP::TVEC3*> attributes ;
attributes.push_back(&position) ;
Algo::Export::exportPLYnew<PFP>(myMap, attributes, filename.c_str(), true, allDarts) ;
}
else if (extension == std::string(".map"))
myMap.saveMapBin(filename) ;
else
......@@ -271,6 +286,12 @@ void Viewer::slot_faceLighting(int i)
updateGL() ;
}
void Viewer::slot_drawTopo(bool b)
{
m_drawTopo = b ;
updateGL() ;
}
void Viewer::slot_drawNormals(bool b)
{
m_drawNormals = b ;
......@@ -280,6 +301,7 @@ void Viewer::slot_drawNormals(bool b)
void Viewer::slot_normalsSize(int i)
{
normalScaleFactor = i / 50.0f ;
m_topoRender->updateData<PFP>(myMap, position, i / 100.0f, i / 100.0f) ;
updateGL() ;
}
......
......@@ -17,7 +17,7 @@
* 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/ *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
......@@ -26,7 +26,7 @@
#include "Utils/Qt/qtSimple.h"
#include "ui_viewer.h"
#include "Utils/Qt/qtui.h"
#include "Utils/qtui.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
......@@ -90,11 +90,13 @@ public:
bool m_drawEdges ;
bool m_drawFaces ;
bool m_drawNormals ;
bool m_drawTopo ;
PFP::TVEC3 position ;
PFP::TVEC3 normal ;
Algo::Render::GL2::MapRender* m_render ;
Algo::Render::GL2::TopoRender* m_topoRender ;
Utils::VBO* m_positionVBO ;
Utils::VBO* m_normalVBO ;
......@@ -123,6 +125,7 @@ public slots:
void slot_drawEdges(bool b) ;
void slot_drawFaces(bool b) ;
void slot_faceLighting(int i) ;
void slot_drawTopo(bool b) ;
void slot_drawNormals(bool b) ;
void slot_normalsSize(int i) ;
};
......@@ -73,6 +73,13 @@
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawTopo">
<property name="text">
<string>draw topo</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_drawNormals">
<property name="text">
......
......@@ -46,7 +46,7 @@
#include "Utils/frameManipulator.h"
#include "ui_volumeExplorer.h"
#include "Utils/Qt/qtui.h"
#include "Utils/qtui.h"
using namespace CGoGN ;
......
......@@ -56,7 +56,7 @@
#include "ui_show_traversors.h"
// inclure qtui.h juste après le ui_xxx.h
#include "Utils/Qt/qtui.h"
#include "Utils/qtui.h"
using namespace CGoGN ;
......
......@@ -57,7 +57,7 @@
#include "ui_tuto5.h"
// inclure qtui.h juste après le ui_xxx.h
#include "Utils/Qt/qtui.h"
#include "Utils/qtui.h"
using namespace CGoGN ;
......
......@@ -42,7 +42,7 @@
#include "Algo/Parallel/parallel_foreach.h"
// for file input
#include "Utils/Qt/qtInputs.h"
#include "Utils/qtInputs.h"
using namespace CGoGN ;
......
......@@ -40,7 +40,7 @@
#include "ui_tuto_oper2.h"
#include "Utils/Qt/qtui.h"
#include "Utils/qtui.h"
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
......
......@@ -92,7 +92,6 @@ void MyQT::operation(int x)
if (m_selected != NIL)
{
dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.uncutEdge(m_selected);
updateMap();
}
......@@ -104,7 +103,6 @@ void MyQT::operation(int x)
if (myMap.deleteEdgePreCond(m_selected))
{
dm.markAll();
PFP::VEC3 Q = position[myMap.phi1(m_selected)];
myMap.deleteEdge(m_selected);
m_selected = NIL;
updateMap();
......@@ -155,7 +153,30 @@ void MyQT::operation(int x)
updateMap();
}
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:
break;
}
......@@ -284,8 +305,9 @@ void MyQT::cb_keyPress(int keycode)
updateMap();
updateGL();
break;
case 'c':
myMap.check();
break;
case 'a':
m_selected = myMap.phi1(m_selected);
updateGL();
......@@ -409,7 +431,7 @@ void MyQT::svg()
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) ;
if (!filename.empty())
importMesh(filename);
......@@ -434,16 +456,40 @@ void MyQT::importMesh(std::string& filename)
myMap.loadMapBin(filename);
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 ;
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 ;
return;
std::cerr << "could not import " << filename << std::endl ;
return ;
}
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_selected2 = NIL;
......
......@@ -40,7 +40,7 @@
#include "ui_tuto_oper3.h"
#include "Utils/Qt/qtui.h"
#include "Utils/qtui.h"
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
......
......@@ -89,6 +89,16 @@
<string>splitVolume</string>
</property>
</item>
<item>
<property name="text">
<string>collapseFace</string>
</property>
</item>
<item>
<property name="text">
<string>collapseVolume</string>
</property>
</item>
</widget>
</item>
<item>
......
......@@ -57,7 +57,7 @@
#include "ui_tuto_orbits.h"
// inclure qtui.h juste après le ui_xxx.h
#include "Utils/Qt/qtui.h"
#include "Utils/qtui.h"
using namespace CGoGN ;
......
......@@ -207,7 +207,7 @@ void Approximator_MidEdge<PFP>::approximate(Dart d)
Dart d2 = m.phi2(m.phi_1(d)) ;
Dart dd2 = m.phi2(m.phi_1(dd)) ;
VEC3 v2 = this->m_attrV[dd] ;
// VEC3 v2 = this->m_attrV[dd] ;
// temporary edge collapse
m.extractTrianglePair(d) ;
......@@ -297,9 +297,9 @@ void Approximator_CornerCutting<PFP>::approximate(Dart d)
// get some darts
Dart dd = m.phi2(d) ;
Dart d1 = m.phi2(m.phi1(d)) ;
// Dart d1 = m.phi2(m.phi1(d)) ;
Dart d2 = m.phi2(m.phi_1(d)) ;
Dart dd1 = m.phi2(m.phi1(dd)) ;
// Dart dd1 = m.phi2(m.phi1(dd)) ;
Dart dd2 = m.phi2(m.phi_1(dd)) ;
// get the contracted edge vertices positions
......
......@@ -26,6 +26,7 @@
#define __EXPORT_H__
#include "Topology/generic/attributeHandler.h"
#include <stdint.h>
namespace CGoGN
{
......@@ -39,11 +40,24 @@ namespace Export
/**
* export the map into a PLY file
* @param the_map map to be exported
* @param position the position container
* @param filename filename of ply file
* @param binary write in binary mode
* @return true
*/
template <typename PFP>
bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good = allDarts) ;
bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const bool binary, const FunctorSelect& good = allDarts) ;
/**
* export the map into a PLY file
* @param the_map map to be exported
* @param vertexAttrNames the vertex attribute names
* @param filename filename of ply file
* @param binary write in binary mode
* @return true
*/
template <typename PFP>
bool exportPLYnew(typename PFP::MAP& map, const std::vector<typename PFP::TVEC3* >& attributeHandlers, const char* filename, const bool binary, const FunctorSelect& good = allDarts) ;
/**
* export the map into a OFF file
......@@ -84,8 +98,8 @@ bool exportTrian(typename PFP::MAP& map, const typename PFP::TVEC3& position, ch
* @param position the position container
* @return true
*/
template <typename PFP>
bool exportPlySLFgeneric(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good = allDarts) ;
//template <typename PFP>
//bool exportPlySLFgeneric(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good = allDarts) ;
/**
* export the map into a PLYPTMgeneric file (K. Vanhoey generic format).
......@@ -99,8 +113,8 @@ bool exportPlySLFgeneric(typename PFP::MAP& map, const typename PFP::TVEC3& posi
* @param position the position container
* @return true
*/
template <typename PFP>
bool exportPlySLFgenericBin(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good = allDarts) ;
//template <typename PFP>
//bool exportPlySLFgenericBin(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good = allDarts) ;
/**
* export the map into a PLYSLF file (K. Vanhoey generic format).
......
......@@ -38,12 +38,18 @@ namespace Export
{
template <typename PFP>
bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, const FunctorSelect& good)
bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, const char* filename, bool binary, const FunctorSelect& good)
{
typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3;
std::ofstream out(filename, std::ios::out) ;
// open file
std::ofstream out ;
if (!binary)
out.open(filename, std::ios::out) ;
else
out.open(filename, std::ios::out | std::ios::binary) ;
if (!out.good())
{
CGoGNerr << "Unable to open file " << CGoGNendl ;
......@@ -60,6 +66,7 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
std::vector<unsigned int> vertices ;
vertices.reserve(nbDarts/6) ;
// Go over all faces
CellMarker markV(map, VERTEX) ;
TraversorF<MAP> t(map, good) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
......@@ -84,31 +91,231 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
facesIdx.push_back(fidx) ;
}
// Start writing the file
out << "ply" << std::endl ;
out << "format ascii 1.0" << std::endl ;
out << "comment no comment" << std::endl ;
// ascii or binary
if (!binary)
out << "format ascii 1.0" << std::endl ;
else
{ // test endianness
union
{
uint32_t i ;
char c[4] ;
} bint = {0x01020304} ;
if (bint.c[0] == 1) // big endian
out << "format binary_big_endian 1.0" << std::endl ;
else
out << "format binary_little_endian 1.0" << std::endl ;
}
out << "comment File generated by the CGoGN library" << std::endl ;
out << "comment See : http://cgogn.unistra.fr/" << std::endl ;
out << "comment or contact : cgogn@unistra.fr" << std::endl ;
// Vertex elements
out << "element vertex " << vertices.size() << std::endl ;
out << "property float x" << std::endl ;
out << "property float y" << std::endl ;
out << "property float z" << std::endl ;
// Position property
if (position.isValid())
{
out << "property " << nameOfTypePly(position[0][0]) << " x" << std::endl ;
out << "property " << nameOfTypePly(position[0][1]) << " y" << std::endl ;
out << "property " << nameOfTypePly(position[0][2]) << " z" << std::endl ;
}
// Face element
out << "element face " << facesSize.size() << std::endl ;
out << "property list uchar int vertex_indices" << std::endl ;
out << "property list uint8 uint" << 8 * sizeof(facesIdx[0][0]) << " vertex_indices" << std::endl ;
out << "end_header" << std::endl ;
for(unsigned int i = 0; i < vertices.size(); ++i)
if (!binary) // ascii
{
const VEC3& v = position[vertices[i]] ;
out << v[0] << " " << v[1] << " " << v[2] << std::endl ;
// ascii vertices
for(unsigned int i = 0; i < vertices.size(); ++i)
out << position[vertices[i]] << std::endl ;
// ascii faces
for(unsigned int i = 0; i < facesSize.size(); ++i)
{
out << facesSize[i] ;
for(unsigned int j = 0; j < facesIdx[i].size(); ++j)
out << " " << facesIdx[i][j] ;
out << std::endl ;
}
}
for(unsigned int i = 0; i < facesSize.size(); ++i)
else // binary
{
out << facesSize[i] ;
for(unsigned int j = 0; j < facesIdx[i].size(); ++j)
out << " " << facesIdx[i][j] ;
out << std::endl ;
// binary vertices
for(unsigned int i = 0; i < vertices.size(); ++i)
{
Geom::Vec3f v = position[vertices[i]] ;
out.write((char*)(&(v[0])), sizeof(v)) ;
}
// binary faces
for(unsigned int i = 0; i < facesSize.size(); ++i)
{
unsigned char nbe = facesSize[i] ;
out.write((char*)(&nbe), sizeof(unsigned char)) ;
out.write((char*)(&(facesIdx[i][0])), facesSize[i] * sizeof(facesIdx[i][0])) ;
}
}
out.close() ;
return true ;
}
template <typename PFP>
bool exportPLYnew(typename PFP::MAP& map, const std::vector<typename PFP::TVEC3*>& attributeHandlers, const char* filename, bool binary, const FunctorSelect& good)
{
typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3;
// open file
std::ofstream out ;
if (!binary)
out.open(filename, std::ios::out) ;
else
out.open(filename, std::ios::out | std::ios::binary) ;
if (!out.good())
{
CGoGNerr << "Unable to open file " << CGoGNendl ;
return false ;
}
unsigned int nbDarts = map.getNbDarts() ;
std::vector<unsigned int> facesSize ;
std::vector<std::vector<unsigned int> > facesIdx ;
facesSize.reserve(nbDarts/3) ;
facesIdx.reserve(nbDarts/3) ;
std::map<unsigned int, unsigned int> vIndex ;
unsigned int vCpt = 0 ;
std::vector<unsigned int> vertices ;
vertices.reserve(nbDarts/6) ;
// Go over all faces
CellMarker markV(map, VERTEX) ;
TraversorF<MAP> t(map, good) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
std::vector<unsigned int> fidx ;
fidx.reserve(8) ;
unsigned int degree = 0 ;
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
{
++degree ;
unsigned int vNum = map.getEmbedding(VERTEX, it) ;
if(!markV.isMarked(it))
{
markV.mark(it) ;
vIndex[vNum] = vCpt++ ;
vertices.push_back(vNum) ;
}
fidx.push_back(vIndex[vNum]) ;
}
facesSize.push_back(degree) ;
facesIdx.push_back(fidx) ;
}
// Start writing the file
out << "ply" << std::endl ;
// ascii or binary
if (!binary)
out << "format ascii 1.0" << std::endl ;
else
{ // test endianness
union
{
uint32_t i ;
char c[4] ;
} bint = {0x01020304} ;
if (bint.c[0] == 1) // big endian
out << "format binary_big_endian 1.0" << std::endl ;
else
out << "format binary_little_endian 1.0" << std::endl ;
}
out << "comment File generated by the CGoGN library" << std::endl ;
out << "comment See : http://cgogn.unistra.fr/" << std::endl ;
out << "comment or contact : cgogn@unistra.fr" << std::endl ;