void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboColor, typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, const AttributeHandler<typename PFP::VEC3,ORBIT, typename PFP::MAP>& colorPerXXX) { typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; typedef Geom::Vec3f VEC3F; std::vector<VEC3F> buffer; buffer.reserve(16384); std::vector<VEC3F> bufferColors; bufferColors.reserve(16384); TraversorCell<typename PFP::MAP, FACE> traFace(map); for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next()) { Dart a = d; Dart b = map.phi1(a); Dart c = map.phi1(b); // loop to cut a polygon in triangle on the fly (works only with convex faces) do { buffer.push_back(positions[d]); bufferColors.push_back(colorPerXXX[d]); buffer.push_back(positions[b]); bufferColors.push_back(colorPerXXX[b]); buffer.push_back(positions[c]); bufferColors.push_back(colorPerXXX[c]); b = c; c = map.phi1(b); } while (c != d); } m_nbTris = GLuint(buffer.size()/3); vboPosition.setDataSize(3); vboPosition.allocate(uint32(buffer.size())); VEC3F* ptrPos = reinterpret_cast<VEC3F*>(vboPosition.lockPtr()); memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3F)); vboPosition.releasePtr(); vboColor.setDataSize(3); vboColor.allocate(uint32(bufferColors.size())); VEC3F* ptrCol = reinterpret_cast<VEC3F*>(vboColor.lockPtr()); memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3F)); vboColor.releasePtr(); }
void Topo3PrimalRender<PFP>::updateData(MAP& mapx, const VertexAttribute<VEC3, MAP>& positions, float ke, float kf) { if (m_attIndex.map() != &mapx) m_attIndex = mapx.template getAttribute<unsigned int, DART, MAP>("dart_index"); if (!m_attIndex.isValid()) m_attIndex = mapx.template addAttribute<unsigned int, DART, MAP>("dart_index"); // m_nbDarts = 0; // for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) // { // m_nbDarts++; // } m_nbDarts = mapx.getNbDarts(); // beta2/3 DartAutoAttribute<VEC3, MAP> fv2(mapx); m_vbo2->bind(); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW); GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); Geom::Vec3f* colorDartBuf = reinterpret_cast<Geom::Vec3f*>(ColorDartsBuffer); if (m_bufferDartPosition!=NULL) delete m_bufferDartPosition; m_bufferDartPosition = new Geom::Vec3f[2*m_nbDarts]; Geom::Vec3f* positionDartBuf = reinterpret_cast<Geom::Vec3f*>(m_bufferDartPosition); unsigned int posDBI = 0; int nbf = 0; //traverse each face of each volume TraversorF<MAP> traFace(mapx); for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) { std::vector<VEC3> vecPos; vecPos.reserve(16); VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW<PFP>(mapx, d, positions); //shrink the face float okf = 1.0f - kf; Dart dd = d; do { VEC3 P = centerFace*okf + positions[dd]*kf; vecPos.push_back(P); dd = mapx.phi1(dd); } while (dd != d); unsigned int nb = vecPos.size(); vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop // compute position of points to use for drawing topo float oke = 1.0f - ke; for (unsigned int i = 0; i < nb; ++i) { VEC3 P = vecPos[i]*ke + vecPos[i+1]*oke; VEC3 Q = vecPos[i+1]*ke + vecPos[i]*oke; // VEC3 PP = 0.52f*P + 0.48f*Q; // VEC3 QQ = 0.52f*Q + 0.48f*P; VEC3 PP = 0.56f*P + 0.44f*Q; VEC3 QQ = 0.56f*Q + 0.44f*P; *positionDartBuf++ = PFP::toVec3f(P); *positionDartBuf++ = PFP::toVec3f(PP); if (mapx.template isBoundaryMarked<3>(d)) { *colorDartBuf++ = m_boundaryDartsColor; *colorDartBuf++ = m_boundaryDartsColor; } else { *colorDartBuf++ = m_dartsColor; *colorDartBuf++ = m_dartsColor; } m_attIndex[d] = posDBI; posDBI+=2; fv2[d] = (P+PP)*0.5f; *positionDartBuf++ = PFP::toVec3f(Q); *positionDartBuf++ = PFP::toVec3f(QQ); Dart dx = mapx.phi3(d); if (mapx.template isBoundaryMarked<3>(dx)) { *colorDartBuf++ = m_boundaryDartsColor; *colorDartBuf++ = m_boundaryDartsColor; } else { *colorDartBuf++ = m_dartsColor; *colorDartBuf++ = m_dartsColor; } m_attIndex[dx] = posDBI; posDBI+=2; fv2[dx] = (Q+QQ)*0.5f; d = mapx.phi1(d); } nbf++; } m_vbo2->bind(); glUnmapBuffer(GL_ARRAY_BUFFER); m_vbo0->bind(); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(Geom::Vec3f), m_bufferDartPosition, GL_STREAM_DRAW); // alpha2 m_vbo1->bind(); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW); GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); Geom::Vec3f* positionF2 = reinterpret_cast<Geom::Vec3f*>(PositionBuffer2); m_nbRel2 = 0; for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) { Dart e = mapx.phi2(mapx.phi3(d)); //if (d < e) { *positionF2++ = PFP::toVec3f(fv2[d]); *positionF2++ = PFP::toVec3f(fv2[e]); m_nbRel2++; } } m_vbo1->bind(); glUnmapBuffer(GL_ARRAY_BUFFER); glBindBuffer(GL_ARRAY_BUFFER, 0); }