Ejemplo n.º 1
0
  /**
   * Returns value of the given vertex attribute's ordinate. The ordinate is always 0 because
   * integer attributes always have one component.
   *
   * @param semantics The attribute semantics.
   * @param ordinate The attribute's ordinate. For example, the y coordinate of the NORMAL has
   *     ordinate of 1.
   * @return The ordinate value truncated to a 32 bit integer value.
   */
  public int getAttributeAsInt(int semantics, int ordinate) {
    if (isEmptyImpl())
      throw new GeometryException("This operation was performed on an Empty Geometry.");

    int ncomps = VertexDescription.getComponentCount(semantics);
    if (ordinate >= ncomps) throw new IndexOutOfBoundsException();

    int attributeIndex = m_description.getAttributeIndex(semantics);
    if (attributeIndex >= 0)
      return (int) m_attributes[m_description._getPointAttributeOffset(attributeIndex) + ordinate];
    else return (int) VertexDescription.getDefaultValue(semantics);
  }
Ejemplo n.º 2
0
  @Override
  void _afterAddAttributeImpl(int semantics) {
    _touch();
    if (m_attributes == null) return;

    int attributeIndex = m_description.getAttributeIndex(semantics);
    int offset = m_description._getPointAttributeOffset(attributeIndex);
    int comps = VertexDescription.getComponentCount(semantics);
    int totalComps = m_description._getTotalComponents();
    resizeAttributes(totalComps);

    for (int i = totalComps - 1; i >= offset + comps; i--)
      m_attributes[i] = m_attributes[i - comps];

    double dv = VertexDescription.getDefaultValue(semantics);
    for (int i = 0; i < comps; i++) m_attributes[offset + i] = dv;
  }
  @Override
  public void insertAttributes(int start, Point pt, int semantics, int validSize) {
    if (m_bReadonly) throw new GeometryException("invalid_call");

    int comp = VertexDescription.getComponentCount(semantics);

    System.arraycopy(m_buffer, start, m_buffer, start + comp, validSize - start);

    for (int c = 0; c < comp; c++) {
      m_buffer[start + c] = (int) pt.getAttributeAsDbl(semantics, c);
    }
  }
Ejemplo n.º 4
0
  /** Returns XYZ coordinates of the point. Z will be set to 0 if Z is missing. */
  Point3D getXYZ() {
    if (isEmptyImpl())
      throw new GeometryException("This operation should not be performed on an empty geometry.");

    Point3D pt = new Point3D();
    pt.x = m_attributes[0];
    pt.y = m_attributes[1];
    if (m_description.hasZ()) pt.z = m_attributes[2];
    else pt.z = VertexDescription.getDefaultValue(Semantics.Z);

    return pt;
  }
Ejemplo n.º 5
0
  /**
   * Sets the value of the attribute.
   *
   * @param semantics The attribute semantics.
   * @param ordinate The ordinate of the attribute.
   * @param value Is the array to write values to. The attribute type and the number of elements
   *     must match the persistence type, as well as the number of components of the attribute.
   */
  public void setAttribute(int semantics, int ordinate, double value) {
    _touch();
    int ncomps = VertexDescription.getComponentCount(semantics);
    if (ncomps < ordinate) throw new IndexOutOfBoundsException();

    int attributeIndex = m_description.getAttributeIndex(semantics);
    if (attributeIndex < 0) {
      addAttribute(semantics);
      attributeIndex = m_description.getAttributeIndex(semantics);
    }

    if (m_attributes == null) _setToDefault();

    m_attributes[m_description._getPointAttributeOffset(attributeIndex) + ordinate] = value;
  }
Ejemplo n.º 6
0
  @Override
  void _beforeDropAttributeImpl(int semantics) {
    _touch();
    if (m_attributes == null) return;

    // _ASSERT(semantics != enum_value2(VertexDescription, Semantics,
    // POSITION));
    int attributeIndex = m_description.getAttributeIndex(semantics);
    int offset = m_description._getPointAttributeOffset(attributeIndex);
    int comps = VertexDescription.getComponentCount(semantics);
    int totalCompsOld = m_description._getTotalComponents();
    if (totalCompsOld > comps) {
      for (int i = offset + comps; i < totalCompsOld; i++)
        m_attributes[i - comps] = m_attributes[i];
    }
  }
Ejemplo n.º 7
0
  /**
   * Sets the XYZ coordinates of this point.
   *
   * @param pt The point to create the XYZ coordinate from.
   */
  void setXYZ(Point3D pt) {
    _touch();
    boolean bHasZ = hasAttribute(Semantics.Z);
    if (!bHasZ && !VertexDescription.isDefaultValue(Semantics.Z, pt.z)) { // add
      // Z
      // only
      // if
      // pt.z
      // is
      // not
      // a
      // default
      // value.
      addAttribute(Semantics.Z);
      bHasZ = true;
    }

    if (m_attributes == null) _setToDefault();

    m_attributes[0] = pt.x;
    m_attributes[1] = pt.y;
    if (bHasZ) m_attributes[2] = pt.z;
  }