float* GLQuadRenderer::createTextureBuffer(const Group& group) const { FloatBuffer* fbuffer = NULL; switch(texturingMode) { case TEXTURE_2D : fbuffer = dynamic_cast<FloatBuffer*>(group.createBuffer(TEXTURE_BUFFER_NAME,FloatBufferCreator(8),TEXTURE_2D,false)); if (!group.getModel()->isEnabled(PARAM_TEXTURE_INDEX)) { float t[8] = {1.0f,0.0f,0.0f,0.0f,0.0f,1.0f,1.0f,1.0f}; for (size_t i = 0; i < group.getParticles().getNbReserved() << 3; ++i) fbuffer->getData()[i] = t[i & 7]; } break; case TEXTURE_3D : fbuffer = dynamic_cast<FloatBuffer*>(group.createBuffer(TEXTURE_BUFFER_NAME,FloatBufferCreator(12),TEXTURE_3D,false)); float t[12] = {1.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f,1.0f,1.0f,0.0f}; for (size_t i = 0; i < group.getParticles().getNbReserved() * 12; ++i) fbuffer->getData()[i] = t[i % 12]; break; } return fbuffer->getData(); }
/** * SPHデータのロード * @param filename ファイルパス * @retval true 成功 * @retval false 失敗 */ bool SPHLoader::Load(const char* filename) { Clear(); m_volume = BufferVolumeData::CreateInstance(); SimpleSPH sph; const float* buf = sph.Load(filename); if (!buf) { fprintf(stderr,"Failed to load SPH volume: %s\n", filename); return false; } const int w = sph.GetDim(0); const int h = sph.GetDim(1); const int d = sph.GetDim(2); const int c = sph.GetComponent(); m_volume->Create(w, h, d, c); FloatBuffer* buffer = m_volume->Buffer(); const int fnum = w * h * d * c; memcpy(buffer->GetBuffer(), buf, fnum * sizeof(float)); delete [] buf; m_origin[0] = sph.GetOrigin(0); m_origin[1] = sph.GetOrigin(1); m_origin[2] = sph.GetOrigin(2); m_pitch[0] = sph.GetPitch(0); m_pitch[1] = sph.GetPitch(1); m_pitch[2] = sph.GetPitch(2); m_time = sph.GetTime(); m_step = sph.GetStep(); return true; }
void GLQuadRenderer::createBuffers(const Group& group) { FloatBuffer* fBuffer = dynamic_cast<FloatBuffer*>(group.createBuffer(GPU_BUFFER_NAME,FloatBufferCreator(28),0,false)); gpuIterator = gpuBuffer = fBuffer->getData(); if (texturingMode != TEXTURE_NONE) textureIterator = textureBuffer = createTextureBuffer(group); }
/** * STLデータのロード * @param filename ファイルパス * @retval true 成功 * @retval false 失敗 */ bool STLLoader::Load(const char* filename){ Clear(); SimpleSTLB obj; bool r = obj.Load(filename); mesh.Create(obj.GetVertexNum(), obj.GetIndexNum()); Vec3Buffer* pos = mesh.Position(); Vec3Buffer* normal = mesh.Normal(); FloatBuffer* mat = mesh.Material(); UintBuffer* index = mesh.Index(); Vec2Buffer* texcoord = mesh.Texcoord(); memcpy(pos->GetBuffer(), obj.GetPositionBuffer(), sizeof(float) * 3 * pos->GetNum()); normal->Create(obj.GetVertexNum()); memcpy(normal->GetBuffer(), obj.GetNormalBuffer(), sizeof(float) * 3 * normal->GetNum()); mat->Create(obj.GetVertexNum()); memset(mat->GetBuffer(), 0, sizeof(float) * mat->GetNum()); index->Create(obj.GetIndexNum()); memcpy(index->GetBuffer(), obj.GetIndex(), sizeof(unsigned int) * index->GetNum()); printf("%d\n", pos->GetNum() ); printf("%d\n", normal->GetNum() ); printf("%d\n", mat->GetNum() ); printf("%d\n", index->GetNum() ); return r; }
/** * マテリアル設定 * @param i 対象index * @param matID マテリアルID */ void PDBLoader::SetMaterial(int i, float matID) { FloatBuffer* mat = ball.Material(); if (i < 0 || i >= mat->GetNum()) { return; } mat->GetBuffer()[i] = matID; }
bool GLLineRenderer::checkBuffers(const Group& group) { FloatBuffer* fBuffer; if ((fBuffer = dynamic_cast<FloatBuffer*>(group.getBuffer(GPU_BUFFER_NAME))) == NULL) return false; gpuIterator = gpuBuffer = fBuffer->getData(); return true; }
bool GLQuadRenderer::checkBuffers(const Group& group) { FloatBuffer* fGpuBuffer; if ((fGpuBuffer = dynamic_cast<FloatBuffer*>(group.getBuffer(GPU_BUFFER_NAME))) == NULL) return false; if (texturingMode != TEXTURE_NONE) { FloatBuffer* fTextureBuffer; if ((fTextureBuffer = dynamic_cast<FloatBuffer*>(group.getBuffer(TEXTURE_BUFFER_NAME,texturingMode))) == NULL) textureBuffer = createTextureBuffer(group); textureIterator = textureBuffer = fTextureBuffer->getData(); } gpuIterator = gpuBuffer = fGpuBuffer->getData(); return true; }
void update(uint64_t read_time) { if (prev_sent == 0) prev_sent = last_sent; if (last_time == 0) { last_time = read_time; prev_sent = last_sent; speed = 0.0; speeds.append(speed); } else if (read_time - last_time >= 10000) { /* double dt = (double)(read_time - last_time); double dv = (double)(last_sent - prev_sent); speed = (long)( dv / dt * 1000000.0) ; */ rate_len = findMovement(positions, 20, *position_history); if (rate_len < *position_history) { speed = 1000000.0 * rate(positions, (rate_len<4)? 4 : rate_len); } else speed = 0.0; speeds.append(speed); last_time = read_time; prev_sent = last_sent; } }
/** * BufferVolumeDataの作成 * @param w Widthサイズ * @param h Heightサイズ * @param d Depthサイズ * @param component component数 * @param nonUniform flag for non-uniform volume */ void Create(int w, int h, int d, int component, bool nonUniform) { this->m_dim[0] = w; this->m_dim[1] = h; this->m_dim[2] = d; this->m_comp = component; FloatBuffer* buf = new FloatBuffer(); FloatBuffer* spacingX = new FloatBuffer(); FloatBuffer* spacingY = new FloatBuffer(); FloatBuffer* spacingZ = new FloatBuffer(); buf->Create(w * h * d * component); this->m_buffer = buf; spacingX->Create(w+1); spacingY->Create(h+1); spacingZ->Create(d+1); this->m_spacingX = spacingX; this->m_spacingY = spacingY; this->m_spacingZ = spacingZ; this->m_isNonUniform = nonUniform; }
void WScatterData::dropLineVertices(FloatBuffer& dataPoints, FloatBuffer& verticesOUT) { int size = dataPoints.size(); int index; for (int i=0; i < size/3; i++) { index = 3*i; verticesOUT.push_back(dataPoints[index]); verticesOUT.push_back(dataPoints[index + 1]); verticesOUT.push_back(dataPoints[index + 2]); verticesOUT.push_back(dataPoints[index]); verticesOUT.push_back(dataPoints[index + 1]); verticesOUT.push_back(0.0f); } }
bool GLLineTrailRenderer::checkBuffers(const Group& group) { FloatBuffer* fVertexBuffer; FloatBuffer* fColorBuffer; FloatBuffer* fValueBuffer; if ((fVertexBuffer = dynamic_cast<FloatBuffer*>(group.getBuffer(VERTEX_BUFFER_NAME,nbSamples))) == NULL) return false; if ((fColorBuffer = dynamic_cast<FloatBuffer*>(group.getBuffer(COLOR_BUFFER_NAME,nbSamples))) == NULL) return false; if ((fValueBuffer = dynamic_cast<FloatBuffer*>(group.getBuffer(VALUE_BUFFER_NAME,nbSamples))) == NULL) return false; vertexIterator = vertexBuffer = fVertexBuffer->getData(); colorIterator = colorBuffer = fColorBuffer->getData(); valueIterator = valueBuffer = fValueBuffer->getData(); return true; }
void GLLineTrailRenderer::createBuffers(const Group& group) { FloatBuffer* fVertexBuffer = dynamic_cast<FloatBuffer*>(group.createBuffer(VERTEX_BUFFER_NAME,FloatBufferCreator((nbSamples + 2) * 3),nbSamples,true)); FloatBuffer* fColorBuffer = dynamic_cast<FloatBuffer*>(group.createBuffer(COLOR_BUFFER_NAME,FloatBufferCreator((nbSamples + 2) << 2),nbSamples,true)); FloatBuffer* fValueBuffer = dynamic_cast<FloatBuffer*>(group.createBuffer(VALUE_BUFFER_NAME,FloatBufferCreator(nbSamples),nbSamples,true)); vertexIterator = vertexBuffer = fVertexBuffer->getData(); colorIterator = colorBuffer = fColorBuffer->getData(); valueIterator = valueBuffer = fValueBuffer->getData(); // Fills the buffers with correct values for (size_t i = 0; i < group.getNbParticles(); ++i) { const Particle& particle = group.getParticle(i); init(particle,particle.getAge()); } // Resets the iterators at the beginning after the init vertexIterator = vertexBuffer; colorIterator = colorBuffer; valueIterator = valueBuffer; }
void WScatterData::updateGL() { int N = model_->rowCount(); int cnt = countSimpleData(); FloatBuffer simplePtsArray = Utils::createFloatBuffer(3*cnt); FloatBuffer simplePtsSize = Utils::createFloatBuffer(cnt); FloatBuffer coloredPtsArray = Utils::createFloatBuffer(3*(N-cnt)); FloatBuffer coloredPtsSize = Utils::createFloatBuffer(N-cnt); FloatBuffer coloredPtsColor = Utils::createFloatBuffer(4*(N-cnt)); dataFromModel(simplePtsArray, simplePtsSize, coloredPtsArray, coloredPtsSize, coloredPtsColor); if (simplePtsArray.size() != 0) { // initialize vertex-buffer vertexPosBuffer_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexPosBuffer_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, simplePtsArray, WGLWidget::STATIC_DRAW, true); vertexBufferSize_ = simplePtsArray.size(); // sizes of simple points vertexSizeBuffer_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexSizeBuffer_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, simplePtsSize, WGLWidget::STATIC_DRAW, true); } if (coloredPtsArray.size() != 0) { // pos of colored points vertexPosBuffer2_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexPosBuffer2_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, coloredPtsArray, WGLWidget::STATIC_DRAW, true); vertexBuffer2Size_ = coloredPtsArray.size(); // size of colored points vertexSizeBuffer2_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexSizeBuffer2_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, coloredPtsSize, WGLWidget::STATIC_DRAW, true); // color of colored points vertexColorBuffer2_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, vertexColorBuffer2_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, coloredPtsColor, WGLWidget::STATIC_DRAW, true); } if (droplinesEnabled_) { FloatBuffer dropLineVerts = Utils::createFloatBuffer(2*3*N); dropLineVertices(simplePtsArray, dropLineVerts); dropLineVertices(coloredPtsArray, dropLineVerts); lineVertBuffer_ = chart_->createBuffer(); chart_->bindBuffer(WGLWidget::ARRAY_BUFFER, lineVertBuffer_); chart_->bufferDatafv(WGLWidget::ARRAY_BUFFER, dropLineVerts, WGLWidget::STATIC_DRAW, true); lineVertBufferSize_ = dropLineVerts.size(); } // initialize texture colormapTexture_ = colorTexture(); chart_->texParameteri(WGLWidget::TEXTURE_2D, WGLWidget::TEXTURE_MAG_FILTER, WGLWidget::NEAREST); chart_->texParameteri(WGLWidget::TEXTURE_2D, WGLWidget::TEXTURE_MIN_FILTER, WGLWidget::NEAREST); chart_->texParameteri(WGLWidget::TEXTURE_2D, WGLWidget::TEXTURE_WRAP_S,WGLWidget::CLAMP_TO_EDGE); chart_->texParameteri(WGLWidget::TEXTURE_2D, WGLWidget::TEXTURE_WRAP_T,WGLWidget::CLAMP_TO_EDGE); initShaders(); chart_->useProgram(shaderProgram_); chart_->uniformMatrix4(mvMatrixUniform_, mvMatrix_); chart_->uniformMatrix4(pMatrixUniform_, chart_->pMatrix()); chart_->useProgram(colShaderProgram_); chart_->uniformMatrix4(mvMatrixUniform2_, mvMatrix_); chart_->uniformMatrix4(pMatrixUniform2_, chart_->pMatrix()); chart_->useProgram(linesProgram_); chart_->uniformMatrix4(mvMatrixUniform3_, mvMatrix_); chart_->uniformMatrix4(pMatrixUniform3_, chart_->pMatrix()); chart_->useProgram(shaderProgram_); float text_min, text_max; if (colormap_ != 0) { text_min = (float)chart_->toPlotCubeCoords(colormap_->minimum(), ZAxis_3D); text_max = (float)chart_->toPlotCubeCoords(colormap_->maximum(), ZAxis_3D); chart_->uniform1f(offsetUniform_, text_min); chart_->uniform1f(scaleFactorUniform_, 1.0/(text_max - text_min)); } else { chart_->uniform1f(offsetUniform_, 0.0); chart_->uniform1f(scaleFactorUniform_, 1.0); } }
void WScatterData::dataFromModel(FloatBuffer& simplePtsArray, FloatBuffer& simplePtsSize, FloatBuffer& coloredPtsArray, FloatBuffer& coloredPtsSize, FloatBuffer& coloredPtsColor) { int N = model_->rowCount(); double xMin = chart_->axis(XAxis_3D).minimum(); double xMax = chart_->axis(XAxis_3D).maximum(); double yMin = chart_->axis(YAxis_3D).minimum(); double yMax = chart_->axis(YAxis_3D).maximum(); double zMin = chart_->axis(ZAxis_3D).minimum(); double zMax = chart_->axis(ZAxis_3D).maximum(); for (int i=0; i < N; i++) { if (colorColumn_ == -1 && model_->data(i,ZSeriesColumn_, MarkerBrushColorRole).empty()) { simplePtsArray.push_back((float)((Wt::asNumber(model_->data(i,XSeriesColumn_)) - xMin)/(xMax - xMin))); simplePtsArray.push_back((float)((Wt::asNumber(model_->data(i,YSeriesColumn_)) - yMin)/(yMax - yMin))); simplePtsArray.push_back((float)((Wt::asNumber(model_->data(i,ZSeriesColumn_)) - zMin)/(zMax - zMin))); } else if (colorColumn_ == -1) { coloredPtsArray.push_back((float)((Wt::asNumber(model_->data(i,XSeriesColumn_)) - xMin)/(xMax - xMin))); coloredPtsArray.push_back((float)((Wt::asNumber(model_->data(i,YSeriesColumn_)) - yMin)/(yMax - yMin))); coloredPtsArray.push_back((float)((Wt::asNumber(model_->data(i,ZSeriesColumn_)) - zMin)/(zMax - zMin))); WColor color = boost::any_cast<WColor>(model_->data(i,ZSeriesColumn_,MarkerBrushColorRole)); coloredPtsColor.push_back((float)color.red()); coloredPtsColor.push_back((float)color.green()); coloredPtsColor.push_back((float)color.blue()); coloredPtsColor.push_back((float)color.alpha()); } else { coloredPtsArray.push_back((float)((Wt::asNumber(model_->data(i,XSeriesColumn_)) - xMin)/(xMax - xMin))); coloredPtsArray.push_back((float)((Wt::asNumber(model_->data(i,YSeriesColumn_)) - yMin)/(yMax - yMin))); coloredPtsArray.push_back((float)((Wt::asNumber(model_->data(i,ZSeriesColumn_)) - zMin)/(zMax - zMin))); WColor color = boost::any_cast<WColor>(model_->data(i,colorColumn_,asColorRole_)); coloredPtsColor.push_back((float)color.red()); coloredPtsColor.push_back((float)color.green()); coloredPtsColor.push_back((float)color.blue()); coloredPtsColor.push_back((float)color.alpha()); } FloatBuffer& sizeArrayAlias = (colorColumn_ == -1 && model_->data(i,ZSeriesColumn_, MarkerBrushColorRole).empty()) ? simplePtsSize : coloredPtsSize; if (sizeColumn_ == -1 && model_->data(i,ZSeriesColumn_,MarkerScaleFactorRole).empty()) { sizeArrayAlias.push_back((float)pointSize_); } else if (sizeColumn_ == -1) { sizeArrayAlias.push_back((float)(Wt::asNumber(model_->data(i,ZSeriesColumn_,MarkerScaleFactorRole)))); } else { sizeArrayAlias.push_back((float)(Wt::asNumber(model_->data(i,sizeColumn_, asSizeRole_)))); } } }
void GLLineRenderer::createBuffers(const Group& group) { FloatBuffer* fBuffer = dynamic_cast<FloatBuffer*>(group.createBuffer(GPU_BUFFER_NAME,FloatBufferCreator(14),0,false)); gpuIterator = gpuBuffer = fBuffer->getData(); }
/** * BCMデータのロード * @param filename ファイルパス * @param generateBond 線primitiveとの接点作成 * @retval true 成功 * @retval false 失敗 */ bool PDBLoader::Load(const char* filename, bool generateBond){ Clear(); tinypdb::TinyPDB pdb(filename); if (pdb.Parse(/* isBondGenerated = */ generateBond)) { fprintf(stderr,"[PDBLoader] PDB parsing failed: %s \n", filename); return false; } m_atoms = pdb.GetAtoms(); // copy int numAtoms = static_cast<int>(pdb.GetAtoms().size()); { ball.Create(numAtoms); Vec3Buffer* pos = ball.Position(); FloatBuffer* mat = ball.Material(); FloatBuffer* radius = ball.Radius(); printf("[PDBLoader] # of atoms: %ld\n", numAtoms); float* pp = pos->GetBuffer(); for (size_t i = 0; i < numAtoms; i++) { pp[3*i+0] = pdb.GetAtoms()[i].GetX(); pp[3*i+1] = pdb.GetAtoms()[i].GetY(); pp[3*i+2] = pdb.GetAtoms()[i].GetZ(); } // @fixme float* rad = radius->GetBuffer(); for (int i = 0; i < numAtoms; ++i) { rad[i] = 0.25f; } // @todo memset(mat->GetBuffer(), 0, sizeof(float) * mat->GetNum()); } if (generateBond) { // We reprent Bond as line primitives. std::vector<float> bondLines; for (unsigned int i = 0; i < numAtoms; i++) { tinypdb::Atom& atom = pdb.GetAtoms()[i]; for (unsigned int j = 0; j < atom.GetBonds().size(); j++) { const tinypdb::Atom* dst = atom.GetBonds()[j]; if (dst->Visited()) { continue; } bondLines.push_back(atom.GetX()); bondLines.push_back(atom.GetY()); bondLines.push_back(atom.GetZ()); bondLines.push_back(dst->GetX()); bondLines.push_back(dst->GetY()); bondLines.push_back(dst->GetZ()); } atom.SetVisited(true); } size_t numBonds = bondLines.size() / 3 / 2; size_t numBondVertices = numBonds * 2; printf("[PDBLoader] # of bonds: %ld\n", numBonds); stick.Create(numBondVertices, /* index num = */0, /* use vrying radius */false); Vec3Buffer* pos = stick.Position(); FloatBuffer* mat = stick.Material(); //FloatBuffer* radius = stick.Radius(); //UintBuffer* index = stick.Index(); // not used. float* pp = pos->GetBuffer(); for (size_t i = 0; i < numBondVertices; i++) { pp[3*i+0] = bondLines[3*i+0]; pp[3*i+1] = bondLines[3*i+1]; pp[3*i+2] = bondLines[3*i+2]; } // Don't use varying radius. //float* rad = radius->GetBuffer(); //for (int i = 0; i < numBondVertices; ++i) { // rad[i] = 1.0f; //} // @todo memset(mat->GetBuffer(), 0, sizeof(float) * mat->GetNum()); } return true; }