// create fixed vertex buffer to store mesh vertices void RenderBlock:: createMeshPositionVBO(int w, int h) { int y1 = 0, x1 = 0, y2 = h, x2 = w; // edge dropout to eliminate visible glitches if (w>2) x1--, x2++; if (h>2) y1--, y2++; std::vector<float> posdata( (x2-x1)*(y2-y1)*4 ); float *pos = &posdata[0]; for(int y=y1; y<y2; y++) { for(int x=x1; x<x2; x++) { float u = x / (float) (w-1); float v = y / (float) (h-1); *pos++ = u; *pos++ = 0.0f; *pos++ = v; *pos++ = 1.0f; } } _mesh_position.reset( new Vbo( (w+2)*(h+2)*4*sizeof(float), GL_ARRAY_BUFFER, GL_STATIC_DRAW, &posdata[0] )); }
//----------------------------------------------------------------------------------------- // Reading cell positions from a file. Out of date. // NOT USED //----------------------------------------------------------------------------------------- void MyVTK::read_cell_positions(QString infileName, QString outfileName, bool savepos) { TCpos_list.clear(); // DCpos_list.clear(); // bondpos_list.clear(); QString line, saveline; QTextStream *out = NULL; QFile *vtkdata = NULL; if (savepos) { vtkdata = new QFile(outfileName); if (!vtkdata->open(QFile::Append )) { LOG_MSG("Open failure on vtk file"); return; } out = new QTextStream(vtkdata); } QFile posdata(infileName); if (posdata.open(QFile::ReadOnly)) { QTextStream in(&posdata); do { line = in.readLine(); if (line.length() > 0) { if (savepos) { *out << line << "\n"; out->flush(); } saveline = line; QStringList s = line.split(" ",QString::SkipEmptyParts); if (s[0].compare("T") == 0) { CELL_POS cp; cp.tag = s[1].toInt(); cp.x = s[2].toInt(); cp.y = s[3].toInt(); cp.z = s[4].toInt(); cp.diameter = s[5].toDouble(); cp.state = s[6].toDouble(); TCpos_list.append(cp); // } // else if (s[0].compare("D") == 0) { // CELL_POS cp; // cp.tag = s[1].toInt(); // cp.x = s[2].toInt(); // cp.y = s[3].toInt(); // cp.z = s[4].toInt(); // cp.diameter = s[5].toDouble(); // cp.state = s[6].toDouble(); // DCpos_list.append(cp); // } else if (s[0].compare("B") == 0) { // BOND_POS cp; // cp.BCtag = s[1].toInt(); // cp.DCtag = s[2].toInt(); // bondpos_list.append(cp); } else if (s[0].compare("E") == 0) { break; } } } while (!line.isNull()); } posdata.close(); if (savepos) { delete out; vtkdata->close(); delete vtkdata; } if (QFile::exists(infileName)) { QFile::rename(infileName,"TO_REMOVE"); } }