示例#1
0
文件: WScatterData.C 项目: DTidd/wt
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);
  }
}
示例#2
0
文件: WScatterData.C 项目: DTidd/wt
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);
  }
}