Commit 50dba34d authored by Sylvain Thery's avatar Sylvain Thery

MAJ MC

rm vieux Viewer.cpp
MAJ ear Algo
parent 1262e060
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include "Algo/Render/SVG/mapSVGRender.h" #include "Algo/Render/SVG/mapSVGRender.h"
#include "Algo/Modelisation/triangulation.h"
using namespace CGoGN ; using namespace CGoGN ;
...@@ -156,7 +158,7 @@ void MyQT::cb_initGL() ...@@ -156,7 +158,7 @@ void MyQT::cb_initGL()
void MyQT::cb_redraw() void MyQT::cb_redraw()
{ {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
if (m_shader) if (m_shader)
{ {
...@@ -170,7 +172,7 @@ void MyQT::cb_redraw() ...@@ -170,7 +172,7 @@ void MyQT::cb_redraw()
m_render->draw(m_shader, Algo::Render::GL2::LINES); m_render->draw(m_shader, Algo::Render::GL2::LINES);
glPolygonOffset(0.8f, 0.8f); glPolygonOffset(0.8f, 0.8f);
m_shader->setColor(Geom::Vec4f(1.0,0.,0.,0.)); m_shader->setColor(Geom::Vec4f(0.0,0.,0.,0.));
glLineWidth(1.0f); glLineWidth(1.0f);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
m_render->drawSub(m_shader, Algo::Render::GL2::TRIANGLES, nb_ears); m_render->drawSub(m_shader, Algo::Render::GL2::TRIANGLES, nb_ears);
...@@ -185,32 +187,58 @@ void MyQT::cb_redraw() ...@@ -185,32 +187,58 @@ void MyQT::cb_redraw()
void MyQT::cb_keyPress(int code) void MyQT::cb_keyPress(int code)
{ {
if (code == '+') switch(code)
{ {
case '+':
nb_ears++; nb_ears++;
// born sup dans drawing // born sup dans drawing
updateGL(); updateGL();
} break;
case '-':
if (code == '-')
{
if (nb_ears>=1) if (nb_ears>=1)
nb_ears--; nb_ears--;
updateGL(); updateGL();
} break;
case 'n':
if (code == 'n')
{
nb_ears=0; nb_ears=0;
updateGL(); updateGL();
} break;
if (code == 'a') case 'a':
{
nb_ears=99999999; nb_ears=99999999;
updateGL(); updateGL();
break;
case 't':
{
Algo::Modelisation::EarTriangulation<PFP> triangulation(myMap);
triangulation.triangule();
SelectorTrue allDarts;
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
updateGL();
}
break;
// case 'u':
// {
// Dart d=myMap.begin();
// while (d != myMap.end())
// {
// if (myMap.phi2(d) != d)
// {
// Dart e = d;
// myMap.next(d);
// if (d== myMap.phi2(e))
// myMap.next(d);
// myMap.mergeFaces(e);
// }
// else
// myMap.next(d);
// }
// }
// break;
} }
} }
int main(int argc, char **argv) int main(int argc, char **argv)
...@@ -218,7 +246,6 @@ int main(int argc, char **argv) ...@@ -218,7 +246,6 @@ int main(int argc, char **argv)
position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position"); position = myMap.addAttribute<PFP::VEC3>(VERTEX, "position");
Dart d0 = myMap.newFace(12); Dart d0 = myMap.newFace(12);
position[d0] = PFP::VEC3(0, 20, 0); position[d0] = PFP::VEC3(0, 20, 0);
d0 = myMap.phi1(d0); d0 = myMap.phi1(d0);
...@@ -241,7 +268,7 @@ int main(int argc, char **argv) ...@@ -241,7 +268,7 @@ int main(int argc, char **argv)
position[d0] = PFP::VEC3(5, 30, 0); position[d0] = PFP::VEC3(5, 30, 0);
d0 = myMap.phi1(d0); d0 = myMap.phi1(d0);
position[d0] = PFP::VEC3(0, 30, 0); position[d0] = PFP::VEC3(0, 30, 0);
d0 = myMap.phi1(d0);
d0 = myMap.newFace(4); d0 = myMap.newFace(4);
...@@ -382,7 +409,6 @@ int main(int argc, char **argv) ...@@ -382,7 +409,6 @@ int main(int argc, char **argv)
for (int i=0; i<174;++i) for (int i=0; i<174;++i)
{ {
float a = float(rand()-RAND_MAX/2)/float(RAND_MAX) * 0.25f; float a = float(rand()-RAND_MAX/2)/float(RAND_MAX) * 0.25f;
position[d9] = PFP::VEC3(60.0,60.0,0.0f) + Gfont[2*i] * V1 + Gfont[2*i+1]*V2 + a*V3; position[d9] = PFP::VEC3(60.0,60.0,0.0f) + Gfont[2*i] * V1 + Gfont[2*i+1]*V2 + a*V3;
d9 = myMap.phi1(d9); d9 = myMap.phi1(d9);
} }
...@@ -417,8 +443,10 @@ int main(int argc, char **argv) ...@@ -417,8 +443,10 @@ int main(int argc, char **argv)
SelectorTrue allDarts; SelectorTrue allDarts;
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES); sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES); sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS);
// show final pour premier redraw // show final pour premier redraw
sqt.show(); sqt.show();
// et on attend la fin. // et on attend la fin.
......
This diff is collapsed.
...@@ -38,7 +38,7 @@ Viewer::Viewer() : ...@@ -38,7 +38,7 @@ Viewer::Viewer() :
m_pointSprite(NULL) m_pointSprite(NULL)
{ {
normalScaleFactor = 1.0f ; normalScaleFactor = 1.0f ;
vertexScaleFactor = 1.0f ; vertexScaleFactor = 0.1f ;
faceShrinkage = 1.0f ; faceShrinkage = 1.0f ;
colClear = Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f) ; colClear = Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f) ;
...@@ -121,7 +121,7 @@ void Viewer::cb_redraw() ...@@ -121,7 +121,7 @@ void Viewer::cb_redraw()
{ {
if(m_drawVertices) if(m_drawVertices)
{ {
float size = vertexBaseSize * vertexScaleFactor ; float size = vertexScaleFactor ;
m_pointSprite->setSize(size) ; m_pointSprite->setSize(size) ;
m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ; m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ;
m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ; m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ;
...@@ -189,7 +189,8 @@ void Viewer::importMesh(std::string& filename) ...@@ -189,7 +189,8 @@ void Viewer::importMesh(std::string& filename)
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ; bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
normalBaseSize = bb.diagSize() / 100.0f ; normalBaseSize = bb.diagSize() / 100.0f ;
vertexBaseSize = normalBaseSize * 2.0f ; // vertexBaseSize = normalBaseSize /5.0f ;
if(!normal.isValid()) if(!normal.isValid())
normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ; normal = myMap.addAttribute<PFP::VEC3>(VERTEX, "normal") ;
...@@ -211,7 +212,7 @@ void Viewer::slot_drawVertices(bool b) ...@@ -211,7 +212,7 @@ void Viewer::slot_drawVertices(bool b)
void Viewer::slot_verticesSize(int i) void Viewer::slot_verticesSize(int i)
{ {
vertexScaleFactor = i / 50.0f ; vertexScaleFactor = i / 500.0f ;
updateGL() ; updateGL() ;
} }
......
...@@ -26,10 +26,10 @@ ...@@ -26,10 +26,10 @@
#define IMAGE_H #define IMAGE_H
#include <gmtl/Vec.h> #include "Geometry/vector_gen.h"
#include "Algo/MC/type.h" #include "Algo/MC/type.h"
#include "img3D_IO.h" #include "Utils/img3D_IO.h"
#include "Zinrimage.h" #include "Zinrimage.h"
...@@ -228,7 +228,7 @@ public: ...@@ -228,7 +228,7 @@ public:
* get the origin * get the origin
* @return a vector with origin * @return a vector with origin
*/ */
gmtl::Vec3i getOrigin() const { return gmtl::Vec3i(m_OX, m_OY, m_OZ);} Geom::Vec3i getOrigin() const { return Geom::Vec3i(m_OX, m_OY, m_OZ);}
/** /**
* get the data const version * get the data const version
...@@ -287,7 +287,7 @@ public: ...@@ -287,7 +287,7 @@ public:
* @param _Vec vector of voxel position * @param _Vec vector of voxel position
* @return the value of the voxel * @return the value of the voxel
*/ */
DataType getVoxel( const gmtl::Vec3i &_Vec); DataType getVoxel( const Geom::Vec3i &_Vec);
/** /**
...@@ -308,13 +308,13 @@ public: ...@@ -308,13 +308,13 @@ public:
* Get the lower corner of bounding AABB * Get the lower corner of bounding AABB
*/ */
// gmtl::Vec3f boundMin() const { return gmtl::Vec3f(0.0f, 0.0f, 0.0f);} // gmtl::Vec3f boundMin() const { return gmtl::Vec3f(0.0f, 0.0f, 0.0f);}
gmtl::Vec3f boundMin() const { return gmtl::Vec3f(m_SX*m_OX, m_SY*m_OY, m_SZ*m_OZ);} Geom::Vec3f boundMin() const { return Geom::Vec3f(m_SX*m_OX, m_SY*m_OY, m_SZ*m_OZ);}
/** /**
* Get the upper corner of bounding AABB * Get the upper corner of bounding AABB
*/ */
// gmtl::Vec3f boundMax() const { return gmtl::Vec3f(m_SX*(m_WX-2*m_OX), m_SY*(m_WY-2*m_OY), m_SZ*(m_WZ-2*m_OZ));} // gmtl::Vec3f boundMax() const { return gmtl::Vec3f(m_SX*(m_WX-2*m_OX), m_SY*(m_WY-2*m_OY), m_SZ*(m_WZ-2*m_OZ));}
gmtl::Vec3f boundMax() const { return gmtl::Vec3f(m_SX*(m_WX-m_OX), m_SY*(m_WY-m_OY), m_SZ*(m_WZ-m_OZ));} Geom::Vec3f boundMax() const { return Geom::Vec3f(m_SX*(m_WX-m_OX), m_SY*(m_WY-m_OY), m_SZ*(m_WZ-m_OZ));}
/** /**
* Compute the volume in cm3 * Compute the volume in cm3
* @param wind the windowing function * @param wind the windowing function
...@@ -322,7 +322,10 @@ public: ...@@ -322,7 +322,10 @@ public:
template< typename Windowing > template< typename Windowing >
float computeVolume(const Windowing& wind) const; float computeVolume(const Windowing& wind) const;
void Blur3(); /**
* local (3x3) blur of image
*/
Image<DataType>* Blur3();
void createMaskOffsetSphere(std::vector<int>& table, int _i32radius); void createMaskOffsetSphere(std::vector<int>& table, int _i32radius);
...@@ -336,7 +339,7 @@ public: ...@@ -336,7 +339,7 @@ public:
} // end namespace } // end namespace
} // end namespace } // end namespace
#include "image.hpp" #include "Algo/MC/image.hpp"
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <math.h> #include <math.h>
#include <typeinfo> #include <typeinfo>
#include "img3D_IO.h" #include "Utils/img3D_IO.h"
#include "Zinrimage.h" #include "Zinrimage.h"
namespace CGoGN namespace CGoGN
...@@ -205,8 +205,6 @@ bool Image<DataType>::loadPNG3D(const char* filename) ...@@ -205,8 +205,6 @@ bool Image<DataType>::loadPNG3D(const char* filename)
template< typename DataType > template< typename DataType >
bool Image<DataType>::loadInrgz(const char* filename) bool Image<DataType>::loadInrgz(const char* filename)
{ {
mImage = readZInrimage(filename); mImage = readZInrimage(filename);
// A modifier en verifiant le type de donne // A modifier en verifiant le type de donne
...@@ -309,7 +307,7 @@ Image<DataType>* Image<DataType>::addFrame(int frameMax) ...@@ -309,7 +307,7 @@ Image<DataType>* Image<DataType>::addFrame(int frameMax)
float realFS = static_cast<float>(frameMax) * minVS; float realFS = static_cast<float>(frameMax) * minVS;
// real frame size for anisotropic images // real frame size for anisotropic images
int32 lFX = static_cast<int32>( ceilf( realFS / m_SX) ); int32 lFX = static_cast<int32>( ceilf( realFS / m_SX) );
int32 lFY = static_cast<int32>( ceilf( realFS / m_SY) ); int32 lFY = static_cast<int32>( ceilf( realFS / m_SY) );
int32 lFZ = static_cast<int32>( ceilf( realFS / m_SZ) ); int32 lFZ = static_cast<int32>( ceilf( realFS / m_SZ) );
...@@ -418,45 +416,37 @@ float Image<DataType>::computeVolume(const Windowing& wind) const ...@@ -418,45 +416,37 @@ float Image<DataType>::computeVolume(const Windowing& wind) const
} }
template< typename DataType > template< typename DataType >
void Image<DataType>::Blur3() Image<DataType>* Image<DataType>::Blur3()
{ {
int txm = m_WX-1; int txm = m_WX-1;
int tym = m_WY-1; int tym = m_WY-1;
int tzm = m_WZ-1; int tzm = m_WZ-1;
DataType* data2 = new DataType[m_WX*m_WY*m_WZ];
Image<DataType>* newImg = new Image<DataType>(data2,m_WX,m_WY,m_WZ,getVoxSizeX(),getVoxSizeY(),getVoxSizeZ());
newImg->m_Alloc=true;
// set origin of real data in image ??
// coef sur le mask 3x3: 8/4/2/1 pour vox/6-vois/18-vois/26-vois // for frame
for(int y=0; y<=tym; ++y)
for(int x=0; x<=txm; ++x)
*(newImg->getVoxelPtr(x,y,0)) = *(getVoxelPtr(x,y,0));
for(int x=1; x<txm; ++x) for(int z=1; z<tzm; ++z)
{ {
for(int x=0; x<=txm; ++x)
*(newImg->getVoxelPtr(x,0,z)) = *(getVoxelPtr(x,0,z));
for(int y=1; y<tym; ++y) for(int y=1; y<tym; ++y)
{ {
for(int z=1; z<tzm; ++z) *(newImg->getVoxelPtr(0,y,z)) = *(getVoxelPtr(0,y,z));
#pragma omp parallel for // OpenMP
for(int x=1; x<txm; ++x)
{ {
DataType* ori = getVoxelPtr(x,y,z);
DataType* ptr = getVoxelPtr(x,y,z) - m_WXY - m_WX -1; DataType* dest = newImg->getVoxelPtr(x,y,z);
DataType* ori = ptr; DataType* ptr = ori - m_WXY - m_WX -1;
double val=0; double val=0.0;
// for (int i=0; i<3;++i)
// {
// double coef=1.0f;
// if (i%2)
// coef=2.0f;
//
// val += coef*(*ptr++);
// val += 2.0*coef*(*ptr++);
// val += coef*(*ptr);
// ptr += m_WX;
// val += 2.0*coef*(*ptr--);
// val += 4.0*coef*(*ptr--);
// val += 2.0*coef*(*ptr);
// ptr += m_WX;
// val += coef*(*ptr++);
// val += 2.0*coef*(*ptr++);
// val += coef*(*ptr);
// ptr += m_WXY -( 2+m_WX*2);
// }
// val /= 64.0;
for (int i=0; i<3;++i) for (int i=0; i<3;++i)
{ {
val += (*ptr++); val += (*ptr++);
...@@ -472,12 +462,24 @@ void Image<DataType>::Blur3() ...@@ -472,12 +462,24 @@ void Image<DataType>::Blur3()
val += (*ptr); val += (*ptr);
ptr += m_WXY -( 2+m_WX*2); ptr += m_WXY -( 2+m_WX*2);
} }
val /= 27.0; val += 3.0 * (*ori);
val /= (27.0 + 3.0);
*ori= DataType(val); DataType res(val);
*dest= res;
} }
*(newImg->getVoxelPtr(txm,y,z)) = *(getVoxelPtr(txm,y,z));
} }
for(int x=0; x<=txm; ++x)
*(newImg->getVoxelPtr(x,tym,z)) = *(getVoxelPtr(x,tym,z));
} }
for(int y=0; y<=tym; ++y)
for(int x=1; x<txm; ++x)
*(newImg->getVoxelPtr(x,y,tzm)) = *(getVoxelPtr(x,y,tzm));
return newImg;
} }
template<typename DataType> template<typename DataType>
...@@ -501,8 +503,8 @@ void Image<DataType>::createMaskOffsetSphere(std::vector<int>& table, int _i32ra ...@@ -501,8 +503,8 @@ void Image<DataType>::createMaskOffsetSphere(std::vector<int>& table, int _i32ra
{ {
for (int x = -_i32radius; x<=_i32radius; x++) for (int x = -_i32radius; x<=_i32radius; x++)
{ {
gmtl::Vec3f v((float)x,(float)y,(float)z); Geom::Vec3f v((float)x,(float)y,(float)z);
float fLength = gmtl::lengthSquared(v); float fLength = v.norm2();
// if inside the sphere // if inside the sphere
if (fLength<=fRad2) if (fLength<=fRad2)
{ {
...@@ -518,9 +520,10 @@ void Image<DataType>::createMaskOffsetSphere(std::vector<int>& table, int _i32ra ...@@ -518,9 +520,10 @@ void Image<DataType>::createMaskOffsetSphere(std::vector<int>& table, int _i32ra
template<typename DataType> template<typename DataType>
float Image<DataType>::computeCurvatureCount(const DataType *ptrVox, const std::vector<int>& sphere, DataType val) float Image<DataType>::computeCurvatureCount(const DataType *ptrVox, const std::vector<int>& sphere, DataType val)
{ {
int noir =0; int noir = 0;
int blanc = 0; int blanc = 0;
for (std::vector<int>::const_iterator it=sphere.begin(); it!=sphere.end();it++) for (std::vector<int>::const_iterator it=sphere.begin(); it!=sphere.end();it++)
{ {
const DataType *data = ptrVox + *it; const DataType *data = ptrVox + *it;
...@@ -534,7 +537,7 @@ float Image<DataType>::computeCurvatureCount(const DataType *ptrVox, const std:: ...@@ -534,7 +537,7 @@ float Image<DataType>::computeCurvatureCount(const DataType *ptrVox, const std::
} }
} }
if (blanc > noir) if (blanc >= noir)
{ {
return 1.0f - ((float)noir) / ((float)blanc); return 1.0f - ((float)noir) / ((float)blanc);
} }
......
...@@ -30,8 +30,7 @@ ...@@ -30,8 +30,7 @@
#include "Algo/MC/buffer.h" #include "Algo/MC/buffer.h"
#include "Algo/MC/tables.h" #include "Algo/MC/tables.h"
#include <gmtl/Vec.h> #include "Geometry/vector_gen.h"
#include <gmtl/VecOps.h>
namespace CGoGN namespace CGoGN
{ {
...@@ -193,9 +192,10 @@ protected: ...@@ -193,9 +192,10 @@ protected:
L_DART createTriEmb(unsigned int e1, unsigned int e2, unsigned int e3) { L_DART createTriEmb(unsigned int e1, unsigned int e2, unsigned int e3) {
L_DART d = m_map->newFace(3); L_DART d = m_map->newFace(3);
m_map->setSingleVertexEmb(d,e1); d = m_map->phi1(d); //TODO change this which work only with 2-maps
m_map->setSingleVertexEmb(d,e2); d = m_map->phi1(d); m_map->setDartEmbedding(VERTEX,d,e1); d = m_map->phi1(d);
m_map->setSingleVertexEmb(d,e3); d = m_map->phi1(d); m_map->setDartEmbedding(VERTEX,d,e2); d = m_map->phi1(d);
m_map->setDartEmbedding(VERTEX,d,e3); d = m_map->phi1(d);
return d; return d;
} }
...@@ -222,7 +222,7 @@ public: ...@@ -222,7 +222,7 @@ public:
* @param wind the windowing class (for inside/outside distinguish) * @param wind the windowing class (for inside/outside distinguish)
* @param boundRemoved true is bound is going to be removed * @param boundRemoved true is bound is going to be removed
*/ */
MarchingCube(Image<DataType>* img, L_MAP* map, unsigned int idPos, Windowing<DataType> wind, bool boundRemoved); MarchingCube(Image<DataType>* img, L_MAP* map, const typename PFP::TVEC3& position, Windowing<DataType> wind, bool boundRemoved);
/** /**
* destructor * destructor
...@@ -267,5 +267,5 @@ public: ...@@ -267,5 +267,5 @@ public:
} // end namespace } // end namespace
} // end namespace } // end namespace
#include "marchingcube.hpp" #include "Algo/MC/marchingcube.hpp"
#endif #endif
...@@ -60,12 +60,12 @@ MarchingCube<DataType, Windowing, PFP>::MarchingCube(Image<DataType>* img, Windo ...@@ -60,12 +60,12 @@ MarchingCube<DataType, Windowing, PFP>::MarchingCube(Image<DataType>* img, Windo
} }
template< typename DataType, template < typename D2 > class Windowing, typename PFP > template< typename DataType, template < typename D2 > class Windowing, typename PFP >
MarchingCube<DataType, Windowing, PFP>::MarchingCube(Image<DataType>* img, L_MAP* map, unsigned int idPos, Windowing<DataType> wind, bool boundRemoved): MarchingCube<DataType, Windowing, PFP>::MarchingCube(Image<DataType>* img, L_MAP* map, const typename PFP::TVEC3& position, Windowing<DataType> wind, bool boundRemoved):
m_Image(img), m_Image(img),
m_windowFunc(wind), m_windowFunc(wind),
m_Buffer(NULL), m_Buffer(NULL),
m_map(map), m_map(map),
m_positions(idPos,*map), m_positions(position),
m_fOrigin(typename PFP::VEC3(0.0,0.0,0.0)), m_fOrigin(typename PFP::VEC3(0.0,0.0,0.0)),
m_fScal(typename PFP::VEC3(1.0,1.0,1.0)), m_fScal(typename PFP::VEC3(1.0,1.0,1.0)),
m_brem(boundRemoved) m_brem(boundRemoved)
...@@ -102,7 +102,6 @@ template< typename DataType, template < typename D2 > class Windowing, typename ...@@ -102,7 +102,6 @@ template< typename DataType, template < typename D2 > class Windowing, typename
void MarchingCube<DataType, Windowing, PFP>::simpleMeshing() void MarchingCube<DataType, Windowing, PFP>::simpleMeshing()
{ {
// create the mesh if needed // create the mesh if needed
if (m_map==NULL) if (m_map==NULL)
{ {
...@@ -208,7 +207,7 @@ void MarchingCube<DataType, Windowing, PFP>::simpleMeshing() ...@@ -208,7 +207,7 @@ void MarchingCube<DataType, Windowing, PFP>::simpleMeshing()
m_Buffer->nextSlice(); m_Buffer->nextSlice();
} }