Commit bbc8a3a9 authored by Thomas Pitiot 's avatar Thomas Pitiot

added surface representation

parent aa471233
#ifndef Surface_H
#define Surface_H
#include <iostream>
#include "glm/glm.hpp"
#include "env_map.h"
#include "ArticulatedObject.h"
#include "Algo/Tiling/Surface/triangular.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/vbo.h"
#include "Utils/Shaders/shaderSimpleColor.h"
//particules
using namespace CGoGN ;
class Simulator;
class Surface : public ArticulatedObject
{
public:
Surface(Simulator* sim, VEC3 offset) ;
SURFACE surfaceMap; // map
VertexAttribute<VEC3, SURFACE> positionSurface ; //position
VertexAttribute<int, SURFACE> indexParticule; // index des particules de chaque sommet
void initPlane(); //initialisation d'une grille
// visualisation
void initGL();
void draw();
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::ShaderSimpleColor* m_simpleColorShader;
};
#endif
#include "simulator.h"
//initialisation Surface
Surface::Surface(Simulator* sim,VEC3 offset)
{
surfaceMap.initImplicitProperties();
positionSurface = surfaceMap.addAttribute<VEC3, VERTEX, SURFACE>("positionSurface");
indexParticule = surfaceMap.addAttribute<int, VERTEX, SURFACE>("indexParticule");
initPlane();
index_articulated=sim->objects.size();
r=0.1f;
g=0.4f;
b=0.5f;
sim_=sim;
width=1.0;
nbVertices=0;
nbEdges=0;
belonging_cells = new std::vector<Dart>[nbEdges];
neighbor_cells = new std::vector<Dart>[nbEdges];
TraversorV<SURFACE> tv(surfaceMap);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
positionSurface[d]+=offset;
indexParticule[d]=nbVertices;
parts_.push_back(new CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP>(sim_->envMap_.map, sim_->envMap_.getBelongingCell(positionSurface[d]), positionSurface[d] , sim_->envMap_.position));
nbVertices ++;
}
TraversorE<SURFACE> tE(surfaceMap);
for(Dart d = tE.begin() ; d != tE.end() ; d = tE.next())
{
#ifdef DEBUG_affichage
CGoGNout<<" init Segment :"<< nbEdges ;
CGoGNout<<" || nb_segments :"<< Segments_.size() <<CGoGNendl;
#endif
unsigned int ind1=indexParticule[d];
unsigned int ind2=indexParticule[surfaceMap.phi1(d)];
Segment* o = new Segment(parts_[ind1]->getPosition(),
parts_[ind2]->getPosition(),
this,ind1,ind2,nbEdges,r,g,b);
Segments_.push_back(o);
sim_->envMap_.FirstRegistrationSegment(o);
nbEdges ++;
}
}
void Surface::initGL()
{
//rendering
m_render = new Algo::Render::GL2::MapRender();
m_positionVBO = new Utils::VBO();
m_simpleColorShader = new Utils::ShaderSimpleColor();
m_simpleColorShader->setAttributePosition(m_positionVBO);
m_simpleColorShader->setColor(Geom::Vec4f(0.,1.,0.,0.));
m_positionVBO->updateData(position) ;
m_render->initPrimitives<PFP2>(map, Algo::Render::GL2::TRIANGLES) ;
m_render->initPrimitives<PFP2>(map, Algo::Render::GL2::LINES) ;
}
void Surface::draw()
{
m_positionVBO->updateData(position) ;
m_simpleColorShader->setColor(Geom::Vec4f(1.0,0.627,0.0,0.));
m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
m_simpleColorShader->setColor(Geom::Vec4f(0.0,0.0,0.0,0.));
m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES);
}
void Surface::initPlane()
{
Algo::Surface::Tilings::Triangular::Grid<PFPSurface> prim(surfaceMap, 1,1) ;
prim.embedIntoGrid(positionSurface,1.0f, 1.0f, 0.0f) ;
Dart dY = prim.getDart() ; //remind the first quad of the line
Dart dX = prim.getDart() ; //goes through the line
bool odd = true ; //odd line or not
int nx =1,ny=1;
for (unsigned int i = 0; i < nx*ny;)
{
Dart dNext = surfaceMap.phi1(surfaceMap.phi2(surfaceMap.phi1(dX))) ;
Dart toCut = dX ;
if (odd)
{
toCut = surfaceMap.phi1(toCut) ; //change the side of the split face
positionSurface[toCut][0] -= sim_->envMap_.maxCellSize / 2.0f ; //move vertices for equilateral triangles
}
surfaceMap.splitFace(toCut, surfaceMap.phi1(surfaceMap.phi1(toCut))) ;
++i ;
if (i % nx == 0 && i > 0) //goes up and change side of split
{
Dart endSquare = surfaceMap.newFace(3) ; //add triangle add end of lines to make a square
Dart dN ;
if (odd)
{
dN = surfaceMap.phi1(surfaceMap.phi2(surfaceMap.phi1(dX))) ;
surfaceMap.sewFaces(dN, endSquare) ;
positionSurface[surfaceMap.phi_1(endSquare)] = positionSurface[surfaceMap.phi1(endSquare)] ;
positionSurface[surfaceMap.phi_1(endSquare)][0] += sim_->envMap_.maxCellSize / 2.0f ;
}
else
{
dN = surfaceMap.phi1(dX) ;
surfaceMap.sewFaces(dN, endSquare) ;
positionSurface[surfaceMap.phi_1(endSquare)] = positionSurface[endSquare] ;
}
if (odd)
dY = surfaceMap.phi2(surfaceMap.phi_1(surfaceMap.phi2(surfaceMap.phi1(dY)))) ;
else
dY = surfaceMap.phi2(surfaceMap.phi1(surfaceMap.phi2(surfaceMap.phi_1(dY)))) ;
dX = dY ;
odd = !odd ;
}
else
dX = dNext ;
}
// //add hexagons
// for(Dart d = surfaceMap.begin(); d != surfaceMap.end(); surfaceMap.next(d))
// {
// if(surfaceMap.vertexDegree(d)==6)
// {
// surfaceMap.deleteVertex(d);
// }
// }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment