Exemplo n.º 1
0
bool vesMaterial::addAttribute(vesSharedPtr<vesMaterialAttribute> attribute)
{
  if (!attribute) {
    return false;
  }

  if (attribute->type()    != vesMaterialAttribute::Texture &&
      attribute->binding() == vesMaterialAttribute::BindAll) {

    // Shader is a special attribute.
    if (attribute->type() == vesMaterialAttribute::Shader) {
      return this->setShaderProgram(std::tr1::static_pointer_cast<vesShaderProgram>(attribute));
    }

    // Everything else.
    return this->m_internal->addAttribute(
      this->m_internal->m_attributes, attribute);
  }
  else  if(attribute->type() == vesMaterialAttribute::Texture) {
    vesSharedPtr<vesTexture> texture = std::tr1::static_pointer_cast<vesTexture>(attribute);

    // Cache last texture so that we can release graphics resources on it.
    this->m_internal->m_textureAttributes[texture->textureUnit()] = texture;

    return true;
  }
  else if(attribute->binding() == vesMaterialAttribute::BindMinimal)
  {
    return this->m_internal->addAttribute(
      this->m_internal->m_minimalAttributes, attribute);
  }

  return false;
}
void vesKiwiDataConversionTools::GenericConvertTriangles(vtkPolyData* input,
  vesSharedPtr<vesGeometryData> output)
{
  vesSourceDataP3N3f::Ptr sourceData (new vesSourceDataP3N3f());

  double inPoint[3];
  for (int i = 0; i < input->GetNumberOfPoints(); ++i){
    input->GetPoint(i, inPoint);

    vesVertexDataP3N3f vertexData;
    vertexData.m_position = vesVector3f(inPoint[0], inPoint[1], inPoint[2]);
    sourceData->pushBack(vertexData);
  }

  // copy triangles in place to ves structure
  vtkCellArray* polys = input->GetPolys();
  vtkIdType num;
  vtkIdType* vertices;

  vesSharedPtr< vesIndices<T> > indicesObj =
    std::tr1::static_pointer_cast< vesIndices<T> >
    (output->triangles()->getVesIndices());

  typename vesIndices<T>::Indices* triangleIndices
    = indicesObj->indices();

  triangleIndices->clear();
  triangleIndices->resize(polys->GetNumberOfCells());

  T* outIndex = &triangleIndices->front();
  for (int i = 0; i < polys->GetNumberOfCells(); ++i)
  {
    // there are 4 elements for each triangle cell in the array (count, i1, i2, i3)
    polys->GetCell(4*i, num, vertices);
    *outIndex++ = vertices[0];
    *outIndex++ = vertices[1];
    *outIndex++ = vertices[2];
  }

  if (input->GetPointData()->GetNormals())
  {
    vtkDataArray* normals = input->GetPointData()->GetNormals();
    for (int i = 0; i < input->GetNumberOfPoints(); ++i)
    {
      sourceData->arrayReference()[i].m_normal[0] = normals->GetTuple(i)[0];
      sourceData->arrayReference()[i].m_normal[1] = normals->GetTuple(i)[1];
      sourceData->arrayReference()[i].m_normal[2] = normals->GetTuple(i)[2];
    }
  }
  else
  {
    output->computeNormals<T>();
  }

  output->computeBounds();
  output->addSource(sourceData);
}
Exemplo n.º 3
0
void vesMapper::drawPrimitive(const vesRenderState &renderState,
                              vesSharedPtr<vesPrimitive> primitive)
{
  // Send the primitive type information out
  renderState.m_material->bindRenderData(
    renderState, vesRenderData(primitive->primitiveType(), this->pointSize(), this->lineWidth()));

  glDrawElements(primitive->primitiveType(), primitive->numberOfIndices(),
                 primitive->indicesValueType(),  (void*)0);
}
Exemplo n.º 4
0
bool vesShaderProgram::addShader(vesSharedPtr<vesShader> shader)
{
    if (!shader)
        return false;

    std::vector< vesSharedPtr<vesShader> >::iterator itr
        = this->m_internal->m_shaders.begin();

    // \todo: Memory management.
    for (; itr != this->m_internal->m_shaders.end(); ++itr) {

        if (shader == *itr)
            return false;

        if ((*itr)->shaderType() == shader->shaderType()) {
            this->m_internal->m_shaders.erase(itr);
            break;
        }
    }

    this->m_internal->m_shaders.push_back(shader);

    // shader->addProgramReference(this);

    this->setDirtyStateOn();

    return true;
}
//----------------------------------------------------------------------------
void vesKiwiDataConversionTools::SetTextureData(vtkUnsignedCharArray* pixels,
  vesSharedPtr<vesTexture> texture, int width, int height)
{
  assert(texture);
  vesImage::Ptr image = vesKiwiDataConversionTools::ImageFromPixels(pixels, width, height);
  texture->setImage(image);
}
//----------------------------------------------------------------------------
void vesKiwiDataConversionTools::SetVertexColors(vtkDataArray* scalars,
  vtkScalarsToColors* scalarsToColors, vesSharedPtr<vesGeometryData> geometryData)
{
  if (geometryData) {
    vesSourceData::Ptr colorSourceData = ConvertScalarsToColors(scalars, scalarsToColors);
    if (colorSourceData) {
      geometryData->addSource(colorSourceData);
    }
  }
}
//----------------------------------------------------------------------------
void vesKiwiDataConversionTools::SetTextureCoordinates(vtkDataArray* tcoords,
  vesSharedPtr<vesGeometryData> geometryData)
{
  if (geometryData) {
    vesSourceDataT2f::Ptr tcoordSourceData = ConvertTCoords(tcoords);
    if (tcoordSourceData) {
      geometryData->addSource(tcoordSourceData);
    }
  }
}
//----------------------------------------------------------------------------
void vesKiwiDataConversionTools::SetVertexColors(
  vtkUnsignedCharArray* colors, vesSharedPtr<vesGeometryData> geometryData)
{
  if (geometryData) {
    vesSourceData::Ptr colorSourceData = ConvertColors(colors);
    if (colorSourceData) {
      geometryData->addSource(colorSourceData);
    }
  }
}
Exemplo n.º 9
0
void vesMapper::drawPoints(const vesRenderState &renderState,
                           vesSharedPtr<vesPrimitive> points)
{
  assert(this->m_geometryData);

  if(points->size())
  {
    // Draw using indices
    this->drawPrimitive(renderState, points);
  }
  else
  {
    vesSharedPtr<vesSourceData> data =
        m_geometryData->sourceData(vesVertexAttributeKeys::Position);
    // Send the primitive type information out
    renderState.m_material->bindRenderData(
      renderState, vesRenderData(vesPrimitiveRenderType::Points, this->pointSize(), this->lineWidth()));
    glDrawArrays(points->primitiveType(), 0, data->sizeOfArray());
  }
}
Exemplo n.º 10
0
bool vesMaterial::vesInternal::addAttribute(
  Attributes &attributes,
  vesSharedPtr<vesMaterialAttribute> attribute)
{
  if (!attribute) {
    return false;
  }

  vesInternal::Attributes::iterator itr =
    attributes.find(attribute->type());

  if (itr == attributes.end() || ( (itr->second) != attribute )) {

    attributes[attribute->type()] = attribute;

    return true;
  }

  return false;
}
Exemplo n.º 11
0
bool vesMaterial::setShaderProgram(vesSharedPtr<vesShaderProgram> shaderProgram)
{
  if (!shaderProgram || shaderProgram == this->m_shaderProgram) {
    return false;
  }

  this->m_shaderProgram = shaderProgram;
  this->m_internal->m_attributes[shaderProgram->type()] =
    this->m_shaderProgram;

  return true;
}
Exemplo n.º 12
0
void vesMapper::drawTriangles(const vesRenderState &renderState,
                              vesSharedPtr<vesPrimitive> triangles)
{
  assert(this->m_geometryData);

  const unsigned int numberOfIndices
    = triangles->numberOfIndices();

  unsigned int drawnIndices = 0;

  while (drawnIndices < numberOfIndices) {
    int numberOfIndicesToDraw = numberOfIndices - drawnIndices;

    if (numberOfIndicesToDraw > this->m_maximumTriangleIndicesPerDraw) {
      numberOfIndicesToDraw = this->m_maximumTriangleIndicesPerDraw;
    }

    uintptr_t offset = 0;

    // Send the primitive type information out
    renderState.m_material->bindRenderData(
      renderState, vesRenderData(triangles->primitiveType(), this->pointSize(), this->lineWidth()));

    if (!this->m_enableWireframe) {
      offset = triangles->sizeOfDataType() * drawnIndices;

      glDrawElements(triangles->primitiveType(), numberOfIndicesToDraw,
                     triangles->indicesValueType(), (void*)offset);
    }
    else {
      for(int i = 0; i < numberOfIndicesToDraw; i += 3)
      {
          offset = triangles->sizeOfDataType() * i + triangles->sizeOfDataType()
                   * drawnIndices;
          glDrawElements(GL_LINE_LOOP, 3,
                         triangles->indicesValueType(), (void*)offset);
      }
    }

    drawnIndices += numberOfIndicesToDraw;
  }
}
Exemplo n.º 13
0
bool vesGroupNode::removeChild(vesSharedPtr<vesNode> child)
{
  if (!child) {
    return false;
  }

  // \note:No check if the child really existed. This is for performance
  // reasons.

  // \note: Ensure that parent of this node is "this" group node.
  if (child->parent() == this) {

    this->m_children.remove(child);

    this->setBoundsDirty(true);

    return true;
  }

  return false;
}
//----------------------------------------------------------------------------
void vesKiwiDataConversionTools::SetTextureCoordinates(vtkDataArray* tcoords,
  vesSharedPtr<vesGeometryData> geometryData)
{
  assert(tcoords);
  assert(tcoords->GetNumberOfComponents() == 2);
  assert(geometryData);

  const size_t nTuples = tcoords->GetNumberOfTuples();

  vesSourceDataT2f::Ptr texCoordSourceData (new vesSourceDataT2f());

  for (size_t i = 0; i < nTuples; ++i)
    {
    double* values = tcoords->GetTuple(i);
    vesVertexDataT2f textureCoordinate;
    textureCoordinate.m_textureCoordinate = vesVector2f(values[0], values[1]);
    texCoordSourceData->pushBack(textureCoordinate);
    }

  geometryData->addSource(texCoordSourceData);
}
//----------------------------------------------------------------------------
void vesKiwiDataConversionTools::SetVertexColors(
  vtkUnsignedCharArray* colors, vesSharedPtr<vesGeometryData> geometryData)
{
  assert(geometryData);
  assert(colors);
  assert(colors->GetNumberOfComponents() == 3);

  unsigned char rgb[3];
  const size_t nTuples = colors->GetNumberOfTuples();

  vesSourceDataC3f::Ptr colorSourceData (new vesSourceDataC3f());
  for (size_t i = 0; i < nTuples; ++i)
    {
    colors->GetTupleValue(i, rgb);
    vesVertexDataC3f color;
    color.m_color = vesVector3f(rgb[0]/255.0, rgb[1]/255.0, rgb[2]/255.0);
    colorSourceData->pushBack(color);
    }

  geometryData->addSource(colorSourceData);
}
Exemplo n.º 16
0
bool vesGroupNode::addChild(vesSharedPtr<vesNode> child)
{
  if (!child) {
    return false;
  }

  Children::iterator itr = this->m_children.begin();

  for (; itr != this->m_children.end(); ++itr) {
    if ( (*itr) == child ) {
      return false;
    }
  }

  child->setParent(this);

  this->m_children.push_back(child);

  this->setBoundsDirty(true);

  return true;
}
//----------------------------------------------------------------------------
void vesKiwiDataConversionTools::SetVertexColors(vtkDataArray* scalars,
  vtkScalarsToColors* scalarsToColors, vesSharedPtr<vesGeometryData> geometryData)
{
  assert(scalars);
  assert(scalars->GetNumberOfComponents() == 1);
  assert(geometryData);

  double rgb[3];
  const size_t nTuples = scalars->GetNumberOfTuples();

  vesSourceDataC3f::Ptr colorSourceData (new vesSourceDataC3f());

  for (size_t i = 0; i < nTuples; ++i)
    {
    scalarsToColors->GetColor(scalars->GetComponent(i, 0), rgb);
    vesVertexDataC3f color;
    color.m_color = vesVector3f(rgb[0], rgb[1], rgb[2]);
    colorSourceData->pushBack(color);
    }

  geometryData->addSource(colorSourceData);
}
Exemplo n.º 18
0
//----------------------------------------------------------------------------
void vesKiwiPolyDataRepresentation::addSelfToRenderer(
  vesSharedPtr<vesRenderer> renderer)
{
  assert(renderer);
  renderer->addActor(this->Internal->Actor);
}
Exemplo n.º 19
0
//----------------------------------------------------------------------------
void vesKiwiPolyDataRepresentation::removeSelfFromRenderer(
  vesSharedPtr<vesRenderer> renderer)
{
  assert(renderer);
  renderer->removeActor(this->Internal->Actor);
}
//-----------------------------------------------------------------------------
vesSharedPtr<vesGeometryData> vesKiwiDataConversionTools::ConvertPVWebData(vesSharedPtr<vesPVWebDataSet> dataset)
{
  vesSharedPtr<vesGeometryData> geometryData = vesSharedPtr<vesGeometryData>(new vesGeometryData);
  geometryData->setName("PolyData");

  const int numberOfVerts = dataset->m_numberOfVerts;


  // Todo- handle point primitives
  //vesPrimitive::Ptr pointPrimitive(new vesPrimitive());
  //pointPrimitive->setPrimitiveType(vesPrimitiveRenderType::Points);
  //pointPrimitive->setIndexCount(1);
  //geometryData->addPrimitive(pointPrimitive);


  if (dataset->m_datasetType == 'M') {
    // verts and normals
    vesSourceDataP3N3f::Ptr sourceData(new vesSourceDataP3N3f());
    vesVertexDataP3N3f vertexData;
    for (int i = 0; i < numberOfVerts; ++i) {
      float* vertex = dataset->vertices() + i*3;
      float* normal = dataset->normals() + i*3;
      vertexData.m_position[0] = vertex[0];
      vertexData.m_position[1] = vertex[1];
      vertexData.m_position[2] = vertex[2];
      vertexData.m_normal[0] = normal[0];
      vertexData.m_normal[1] = normal[1];
      vertexData.m_normal[2] = normal[2];
      sourceData->pushBack(vertexData);
    }
    geometryData->addSource(sourceData);

    // triangles
    vesSharedPtr<vesIndices<unsigned short> > triangleIndices =
      vesSharedPtr<vesIndices<unsigned short> >(new vesIndices<unsigned short>());
    vesPrimitive::Ptr trianglesPrimitive = vesPrimitive::Ptr(new vesPrimitive());
    trianglesPrimitive->setIndexCount(3);
    trianglesPrimitive->setIndicesValueType(vesPrimitiveIndicesValueType::UnsignedShort);
    trianglesPrimitive->setPrimitiveType(vesPrimitiveRenderType::Triangles);
    trianglesPrimitive->setVesIndices(triangleIndices);
    geometryData->addPrimitive(trianglesPrimitive);

    for (int i = 0; i < dataset->m_numberOfIndices/3; ++i) {
      short* indices = dataset->indices() + i*3;
      triangleIndices->pushBackIndices(indices[0], indices[1], indices[2]);
    }

  }
  else if (dataset->m_datasetType == 'L') {

    // verts
    vesSourceDataP3f::Ptr vertexSourceData(new vesSourceDataP3f());
    vesVertexDataP3f vertexData;
    for (int i = 0; i < numberOfVerts; ++i) {
      float* vertex = dataset->vertices() + i*3;
      vertexData.m_position[0] = vertex[0];
      vertexData.m_position[1] = vertex[1];
      vertexData.m_position[2] = vertex[2];
      vertexSourceData->pushBack(vertexData);
    }
    geometryData->addSource(vertexSourceData);

    // lines
    vesSharedPtr<vesIndices<unsigned short> > lineIndices =
      vesSharedPtr<vesIndices<unsigned short> >(new vesIndices<unsigned short>());
    vesPrimitive::Ptr linesPrimitive = vesPrimitive::Ptr(new vesPrimitive());
    linesPrimitive->setIndexCount(2);
    linesPrimitive->setIndicesValueType(vesPrimitiveIndicesValueType::UnsignedShort);
    linesPrimitive->setPrimitiveType(vesPrimitiveRenderType::Lines);
    linesPrimitive->setVesIndices(lineIndices);
    geometryData->addPrimitive(linesPrimitive);

    for (int i = 0; i < dataset->m_numberOfIndices/2; ++i) {
      short* indices = dataset->indices() + i*2;
      lineIndices->pushBackIndices(indices[0], indices[1]);
    }
  }

  // colors
  float opacity = 1.0;
  if (dataset->m_transparency) {
    opacity = 0.4;
  }

  vesSourceDataC4f::Ptr colorSourceData(new vesSourceDataC4f());
  vesVertexDataC4f vertColor;
  for (size_t i = 0; i < numberOfVerts; ++i)
    {
    unsigned char* color = dataset->colors() + i*4;
    vertColor.m_color = vesVector4f(color[0]/255.0, color[1]/255.0, color[2]/255.0, opacity);
    colorSourceData->pushBack(vertColor);
    }

  geometryData->addSource(colorSourceData);
  return geometryData;
}