BinaryStlFacetDefinition.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.geometry.io.euclidean.threed.stl;

  18. import java.util.List;

  19. import org.apache.commons.geometry.euclidean.threed.Vector3D;
  20. import org.apache.commons.geometry.io.euclidean.threed.SimpleFacetDefinition;

  21. /** Facet definition class that provides access to the 2-byte attribute value
  22.  * stored with each triangle in the binary STL format.
  23.  */
  24. public class BinaryStlFacetDefinition extends SimpleFacetDefinition {

  25.     /** Attribute value for the facet (2 bytes). */
  26.     private final int attributeValue;

  27.     /** Construct a new instance.
  28.      * @param vertices facet vertices
  29.      * @param normal facet normal
  30.      * @param attributeValue 2-byte attribute value
  31.      */
  32.     public BinaryStlFacetDefinition(final List<Vector3D> vertices, final Vector3D normal,
  33.             final int attributeValue) {
  34.         super(vertices, normal);
  35.         this.attributeValue = attributeValue;
  36.     }

  37.     /** Get the 2-byte attribute value (known as the "attribute byte count") stored at the end of the STL
  38.      * facet definition binary representation. This value is typically set to zero but non-standard implementations
  39.      * may choose to store other values here.
  40.      *
  41.      * <p>The bytes are stored with the first byte in the upper portion (bits 8-15) of the int and the second byte
  42.      * in the lower portion (bits 0-7).</p>
  43.      * @return 2-byte attribute value for the facet
  44.      */
  45.     public int getAttributeValue() {
  46.         return attributeValue;
  47.     }
  48. }