Right in time
This commit is contained in:
parent
4b46f00150
commit
d98b2d625e
105
src/bspline.cpp
105
src/bspline.cpp
|
@ -9,7 +9,7 @@ BSpline::BSpline(
|
||||||
int nbPtsCtrlX,
|
int nbPtsCtrlX,
|
||||||
int nbPtsCtrlZ,
|
int nbPtsCtrlZ,
|
||||||
float stepX,
|
float stepX,
|
||||||
float stepY)
|
float stepZ)
|
||||||
{
|
{
|
||||||
// Simple vérification
|
// Simple vérification
|
||||||
switch (typeSpline) {
|
switch (typeSpline) {
|
||||||
|
@ -29,7 +29,7 @@ BSpline::BSpline(
|
||||||
// Initialisation des valeurs
|
// Initialisation des valeurs
|
||||||
_k = k;
|
_k = k;
|
||||||
_stepX = stepX;
|
_stepX = stepX;
|
||||||
_stepY = stepY;
|
_stepZ = stepZ;
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
// Génération du polygone de contrôle
|
// Génération du polygone de contrôle
|
||||||
|
@ -102,40 +102,71 @@ void BSpline::calculerSpline1D()
|
||||||
void BSpline::calculerSpline2D()
|
void BSpline::calculerSpline2D()
|
||||||
{
|
{
|
||||||
// Init
|
// Init
|
||||||
int dec = 0, m = _k - 1;
|
int decX = 0, decZ = 0, m = _k - 1, nbPtsMaillageX = 0, nbPtsMaillageZ = 0;
|
||||||
uint i = 0;
|
uint i = 0, n = 0;
|
||||||
double u = 0;
|
double u = 0, v = 0;
|
||||||
std::vector<glm::vec3> vecteursPointsControle (_nbPtsCtrlX);
|
//std::vector<glm::vec3> vecteursPointsControle (_k);
|
||||||
|
std::vector<glm::vec3> generatrice;
|
||||||
|
std::vector<std::vector<glm::vec3>> pointsInfluents;
|
||||||
|
std::vector<glm::vec3> vecteurHorizontal;
|
||||||
|
|
||||||
|
// Évaluation de p(u, v), revient à évaluer la génératrice sur les directrices
|
||||||
//Parcours de u
|
//Parcours de u
|
||||||
for(u = _vecteurNodal[m]; u <= _vecteurNodal[_nbPtsCtrlX]; u += _stepX){
|
for(u = _vecteurNodal[m]; u <= _vecteurNodal[_nbPtsCtrlX]; u += _stepX){
|
||||||
|
// Parcours de v
|
||||||
for(v = _vecteurNodal[m]; v <= _vecteurNodal[_nbPtsCtrlZ]; v += _stepZ){
|
for(v = _vecteurNodal[m]; v <= _vecteurNodal[_nbPtsCtrlZ]; v += _stepZ){
|
||||||
// Évaluation de p(u, v), revient à évaluer la génératrice sur les directrices
|
// Réinitialisation
|
||||||
|
vecteurHorizontal.clear();
|
||||||
|
pointsInfluents.clear();
|
||||||
|
generatrice.clear();
|
||||||
|
decX = 0;
|
||||||
|
decZ = 0;
|
||||||
|
|
||||||
// Vecteur de nbPtsCtrlZ directrices
|
|
||||||
|
|
||||||
dec = 0;
|
|
||||||
// Calcul du décalage
|
// Calcul du décalage
|
||||||
for(int i = _k; u > _vecteurNodal[i]; ++i)
|
for(int i = _k; u > _vecteurNodal[i]; ++i)
|
||||||
++dec;
|
++decX;
|
||||||
|
for(int j = _k; v > _vecteurNodal[j]; ++j)
|
||||||
|
++decZ;
|
||||||
|
|
||||||
// Récupération des k points de contrôles nécessaires à la floraison
|
// Calcul des points influents
|
||||||
for(int i = 0; i < _k; i++){
|
pointsInfluents.clear();
|
||||||
vecteursPointsControle[i] = _pointsDeControle[dec + i];
|
for(int i = 0; i < _k; ++i) {
|
||||||
|
vecteurHorizontal.clear();
|
||||||
|
for(int j = 0; j < _k; ++j) {
|
||||||
|
glm::vec3 pt = _pointsDeControle[((decX + i) * _nbPtsCtrlZ) + (decZ + j)];
|
||||||
|
vecteurHorizontal.push_back(pt);
|
||||||
|
}
|
||||||
|
pointsInfluents.push_back(vecteurHorizontal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// m+1 directrices floraisons
|
||||||
|
for(int i = 0; i < _k; ++i) {
|
||||||
|
generatrice.push_back(floraison(v, decZ, _k, pointsInfluents[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Calcul de b-spline sur la génératrice (locale)
|
||||||
// Appel de la floraison récursive
|
// Appel de la floraison récursive
|
||||||
glm::vec3 newVertex = floraison(u, dec, _k, vecteursPointsControle);
|
glm::vec3 newVertex = floraison(u, decX, _k, generatrice);
|
||||||
|
|
||||||
// Sauvegardes des paramètres de la B-spline
|
// Sauvegardes des paramètres de la B-spline
|
||||||
|
|
||||||
_vertices.insert(_vertices.end(), {newVertex.x, newVertex.y, newVertex.z});
|
_vertices.insert(_vertices.end(), {newVertex.x, newVertex.y, newVertex.z});
|
||||||
_normals.insert(_normals.end(), {1, -1, -1});
|
//_normals.insert(_normals.end(), {1, -1, -1});
|
||||||
_indices.insert(_indices.end(), {i, i, ++i});
|
//_indices.insert(_indices.end(), {i, i, ++i});
|
||||||
|
|
||||||
|
|
||||||
|
// Incrémenter taille en z
|
||||||
|
if(u == _vecteurNodal[m]) nbPtsMaillageZ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nbPtsMaillageX++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << nbPtsMaillageX * nbPtsMaillageZ << " INDICES CALCULÉS" << std::endl;
|
||||||
|
|
||||||
// Maillage
|
// Maillage
|
||||||
for(unsigned int i = 0; i < _pointsDeControle.size(); ++i) {
|
for(unsigned int i = 0; i < _vertices.size() / 3; ++i) {
|
||||||
// Indices
|
// Indices
|
||||||
int x = i / nbPtsMaillageZ;
|
int x = i / nbPtsMaillageZ;
|
||||||
int z = i % nbPtsMaillageX;
|
int z = i % nbPtsMaillageX;
|
||||||
|
@ -152,8 +183,11 @@ void BSpline::calculerSpline2D()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << _vertices.size() / 3 * 2 << " TRIANGLES CALCULÉS" << std::endl;
|
||||||
|
|
||||||
// Normales
|
// Normales
|
||||||
_normals.assign(_vertices.size(), 0.0f);
|
_normals.assign(_vertices.size(), 0.0f);
|
||||||
|
|
||||||
for(int i = 0; i < _indices.size(); i+=3) {
|
for(int i = 0; i < _indices.size(); i+=3) {
|
||||||
// Récupération des sommets
|
// Récupération des sommets
|
||||||
uint indiceSommetA = _indices[i];
|
uint indiceSommetA = _indices[i];
|
||||||
|
@ -171,35 +205,39 @@ void BSpline::calculerSpline2D()
|
||||||
_normals[indiceSommetB*3] += normale.x; _normals[indiceSommetB*3+1] += normale.y; _normals[indiceSommetB*3+2] += normale.z;
|
_normals[indiceSommetB*3] += normale.x; _normals[indiceSommetB*3+1] += normale.y; _normals[indiceSommetB*3+2] += normale.z;
|
||||||
_normals[indiceSommetC*3] += normale.x; _normals[indiceSommetC*3+1] += normale.y; _normals[indiceSommetC*3+2] += normale.z;
|
_normals[indiceSommetC*3] += normale.x; _normals[indiceSommetC*3+1] += normale.y; _normals[indiceSommetC*3+2] += normale.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalisation des normales en chaque sommet
|
// Normalisation des normales en chaque sommet
|
||||||
for(int i = 0; i < _normals.size(); i+=3) {
|
for(int i = 0; i < _vertices.size(); i+=3) {
|
||||||
glm::vec3 normale = glm::normalize(glm::vec3(_normals[i*3], _normals[i*3+1], _normals[i*3+2]));
|
glm::vec3 normale = glm::normalize(glm::vec3(_normals[i], _normals[i+1], _normals[i+2]));
|
||||||
_normals[i*3] = normale.x;
|
_normals.at(i) = normale.x;
|
||||||
_normals[i*3+1] = normale.y;
|
_normals.at(i+1) = normale.y;
|
||||||
_normals[i*3+2] = normale.z;
|
_normals.at(i+2) = normale.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << _normals.size()/3 << " NORMALES CALCULÉES" << std::endl;
|
||||||
|
|
||||||
// Ajouter le polygone de controle aux vecteurs
|
// Ajouter le polygone de controle aux vecteurs
|
||||||
int offset = static_cast<unsigned int>(_vertices.size())/3;
|
int offset = static_cast<unsigned int>(_vertices.size())/3;
|
||||||
std::cout << _pointsDeControle.size() << std::endl;
|
|
||||||
for(unsigned int i = 0; i < _pointsDeControle.size(); ++i) {
|
for(unsigned int i = 0; i < _pointsDeControle.size(); ++i) {
|
||||||
// Indices
|
// Indices
|
||||||
int x = i / _nbPtsCtrlZ;
|
int x = i / _nbPtsCtrlZ;
|
||||||
int z = i % _nbPtsCtrlX;
|
int z = i % _nbPtsCtrlX;
|
||||||
std::cout << "z: " << z << "; x: " << x << std::endl;
|
//std::cout << "z: " << z << "; x: " << x << std::endl;
|
||||||
|
|
||||||
// Sommets
|
// Sommets
|
||||||
uint sommetA = x * _nbPtsCtrlX + z + offset;
|
uint sommetA = x * _nbPtsCtrlX + z + offset;
|
||||||
uint sommetB = x * _nbPtsCtrlX + z+1 + offset;
|
uint sommetB = x * _nbPtsCtrlX + z+1 + offset;
|
||||||
uint sommetC = (x+1) * _nbPtsCtrlX + z + offset;
|
uint sommetC = (x+1) * _nbPtsCtrlX + z + offset;
|
||||||
uint sommetD = (x+1) * _nbPtsCtrlX + z+1 + offset;
|
//uint sommetD = (x+1) * _nbPtsCtrlX + z+1 + offset;
|
||||||
|
|
||||||
// Triangles
|
// Triangles
|
||||||
if (x != _nbPtsCtrlX - 1 && z != _nbPtsCtrlZ - 1) {
|
if (x != _nbPtsCtrlX - 1 && z != _nbPtsCtrlZ - 1) {
|
||||||
// Faces
|
// Faces
|
||||||
/*
|
//_indices.insert(_indices.end(), {sommetA, sommetD, sommetB}); // Triangle 1
|
||||||
_indices.insert(_indices.end(), {sommetA, sommetD, sommetB}); // Triangle 1
|
//_indices.insert(_indices.end(), {sommetA, sommetC, sommetD}); // Triangle 2
|
||||||
_indices.insert(_indices.end(), {sommetA, sommetC, sommetD}); // Triangle 2
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arêtes
|
// Arêtes
|
||||||
if (x != _nbPtsCtrlX - 1)
|
if (x != _nbPtsCtrlX - 1)
|
||||||
_indices.insert(_indices.end(), {sommetA, sommetC, sommetA}); // Arête Horizontale
|
_indices.insert(_indices.end(), {sommetA, sommetC, sommetA}); // Arête Horizontale
|
||||||
|
@ -208,6 +246,7 @@ void BSpline::calculerSpline2D()
|
||||||
_vertices.insert(_vertices.end(), {_pointsDeControle[i].x, _pointsDeControle[i].y, _pointsDeControle[i].z});
|
_vertices.insert(_vertices.end(), {_pointsDeControle[i].x, _pointsDeControle[i].y, _pointsDeControle[i].z});
|
||||||
_normals.insert(_normals.end(), {0, 0, 0});
|
_normals.insert(_normals.end(), {0, 0, 0});
|
||||||
}
|
}
|
||||||
|
std::cout << "POLYGONE AJOUTÉ" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 BSpline::floraison(float u, int dec, int k, std::vector<glm::vec3> vecteursPointsControle)
|
glm::vec3 BSpline::floraison(float u, int dec, int k, std::vector<glm::vec3> vecteursPointsControle)
|
||||||
|
@ -260,7 +299,7 @@ void BSpline::construirePolygone(EPolygone typePolygone, int nbPtsCtrlX, int nbP
|
||||||
}
|
}
|
||||||
|
|
||||||
case EPolygone::GAUSSIEN3D: {
|
case EPolygone::GAUSSIEN3D: {
|
||||||
float sigma = 0.5f;
|
float sigma = 0.3f;
|
||||||
float r, s = 2.0f * sigma * sigma;
|
float r, s = 2.0f * sigma * sigma;
|
||||||
for(int x = - (nbPtsCtrlX / 2) + 1; x < nbPtsCtrlX / 2; ++x) {
|
for(int x = - (nbPtsCtrlX / 2) + 1; x < nbPtsCtrlX / 2; ++x) {
|
||||||
for(int z = - (nbPtsCtrlZ / 2) + 1; z < nbPtsCtrlZ / 2; ++z) {
|
for(int z = - (nbPtsCtrlZ / 2) + 1; z < nbPtsCtrlZ / 2; ++z) {
|
||||||
|
@ -278,7 +317,7 @@ void BSpline::construirePolygone(EPolygone typePolygone, int nbPtsCtrlX, int nbP
|
||||||
for(int i = 0; i < nbPtsCtrlX; ++i) {
|
for(int i = 0; i < nbPtsCtrlX; ++i) {
|
||||||
for(int j = 0; j < nbPtsCtrlZ; ++j) {
|
for(int j = 0; j < nbPtsCtrlZ; ++j) {
|
||||||
x = (i * xMin + (nbPtsCtrlX - i) * xMax) / (xMax - xMin);
|
x = (i * xMin + (nbPtsCtrlX - i) * xMax) / (xMax - xMin);
|
||||||
y = fmod(x + z, 3) / 2;
|
y = fmod(x + z, 3);
|
||||||
z = (j * zMin + (nbPtsCtrlZ - j) * zMax) / (zMin - zMax);
|
z = (j * zMin + (nbPtsCtrlZ - j) * zMax) / (zMin - zMax);
|
||||||
_pointsDeControle.push_back(glm::vec3(x, y, z));
|
_pointsDeControle.push_back(glm::vec3(x, y, z));
|
||||||
}
|
}
|
||||||
|
@ -293,7 +332,7 @@ void BSpline::construirePolygone(EPolygone typePolygone, int nbPtsCtrlX, int nbP
|
||||||
for(int i = 0; i < nbPtsCtrlX; ++i) {
|
for(int i = 0; i < nbPtsCtrlX; ++i) {
|
||||||
for(int j = 0; j < nbPtsCtrlZ; ++j) {
|
for(int j = 0; j < nbPtsCtrlZ; ++j) {
|
||||||
x = (i * xMin + (nbPtsCtrlX - i) * xMax) / (xMax - xMin);
|
x = (i * xMin + (nbPtsCtrlX - i) * xMax) / (xMax - xMin);
|
||||||
y = yMin + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(yMax-yMin))) / 3;
|
y = yMin + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(yMax-yMin))) / 2;
|
||||||
z = (j * zMin + (nbPtsCtrlZ - j) * zMax) / (zMin - zMax);
|
z = (j * zMin + (nbPtsCtrlZ - j) * zMax) / (zMin - zMax);
|
||||||
_pointsDeControle.push_back(glm::vec3(x, y, z));
|
_pointsDeControle.push_back(glm::vec3(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
int nbPtsCtrlX = 10,
|
int nbPtsCtrlX = 10,
|
||||||
int nbPtsCtrlZ = 10,
|
int nbPtsCtrlZ = 10,
|
||||||
float stepX = 0.1,
|
float stepX = 0.1,
|
||||||
float stepY = 0.1);
|
float stepZ = 0.1);
|
||||||
std::vector<GLfloat> const & getVertices() const {return _vertices;}
|
std::vector<GLfloat> const & getVertices() const {return _vertices;}
|
||||||
std::vector<GLfloat> const & getNormals() const {return _normals;}
|
std::vector<GLfloat> const & getNormals() const {return _normals;}
|
||||||
std::vector<GLuint> const & getIndices() const {return _indices;}
|
std::vector<GLuint> const & getIndices() const {return _indices;}
|
||||||
|
@ -32,7 +32,7 @@ private:
|
||||||
|
|
||||||
// Paramètres
|
// Paramètres
|
||||||
int _k, _nbPtsCtrlX, _nbPtsCtrlZ;
|
int _k, _nbPtsCtrlX, _nbPtsCtrlZ;
|
||||||
float _stepX, _stepY;
|
float _stepX, _stepZ;
|
||||||
|
|
||||||
ESpline _typeSpline;
|
ESpline _typeSpline;
|
||||||
EPolygone _typePolygone;
|
EPolygone _typePolygone;
|
||||||
|
|
|
@ -19,11 +19,11 @@ SimpleSpline::SimpleSpline(int width, int height, MainWindow* w) : Scene(width,
|
||||||
* Pas pour delta u et Pas pour delta v */
|
* Pas pour delta u et Pas pour delta v */
|
||||||
BSpline bspline = BSpline(
|
BSpline bspline = BSpline(
|
||||||
BSpline::ESpline::SPLINE2D,
|
BSpline::ESpline::SPLINE2D,
|
||||||
3,
|
4,
|
||||||
BSpline::EPolygone::RANDOM3D,
|
BSpline::EPolygone::RANDOM3D,
|
||||||
BSpline::EVecteurNodal::UNIFORME,
|
BSpline::EVecteurNodal::OUVERTUNIFORME,
|
||||||
16,
|
8,
|
||||||
16,
|
8,
|
||||||
0.1,
|
0.1,
|
||||||
0.1
|
0.1
|
||||||
);
|
);
|
||||||
|
@ -31,7 +31,7 @@ SimpleSpline::SimpleSpline(int width, int height, MainWindow* w) : Scene(width,
|
||||||
_vertices = bspline.getVertices();
|
_vertices = bspline.getVertices();
|
||||||
_indices = bspline.getIndices();
|
_indices = bspline.getIndices();
|
||||||
_normals = bspline.getNormals();
|
_normals = bspline.getNormals();
|
||||||
|
//std::cout << "test" << std::endl;
|
||||||
std::cout << "Vertices count: " << _vertices.size() / 3 << std::endl;
|
std::cout << "Vertices count: " << _vertices.size() / 3 << std::endl;
|
||||||
std::cout << "Edges count: " << _indices.size() << std::endl;
|
std::cout << "Edges count: " << _indices.size() << std::endl;
|
||||||
std::cout << "Triangles count: " << _indices.size() / 3 << std::endl;
|
std::cout << "Triangles count: " << _indices.size() / 3 << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user