001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.geometry.io.euclidean.threed.stl;
018
019import java.util.List;
020
021import org.apache.commons.geometry.euclidean.threed.Vector3D;
022import org.apache.commons.geometry.io.euclidean.threed.SimpleFacetDefinition;
023
024/** Facet definition class that provides access to the 2-byte attribute value
025 * stored with each triangle in the binary STL format.
026 */
027public class BinaryStlFacetDefinition extends SimpleFacetDefinition {
028
029    /** Attribute value for the facet (2 bytes). */
030    private final int attributeValue;
031
032    /** Construct a new instance.
033     * @param vertices facet vertices
034     * @param normal facet normal
035     * @param attributeValue 2-byte attribute value
036     */
037    public BinaryStlFacetDefinition(final List<Vector3D> vertices, final Vector3D normal,
038            final int attributeValue) {
039        super(vertices, normal);
040        this.attributeValue = attributeValue;
041    }
042
043    /** Get the 2-byte attribute value (known as the "attribute byte count") stored at the end of the STL
044     * facet definition binary representation. This value is typically set to zero but non-standard implementations
045     * may choose to store other values here.
046     *
047     * <p>The bytes are stored with the first byte in the upper portion (bits 8-15) of the int and the second byte
048     * in the lower portion (bits 0-7).</p>
049     * @return 2-byte attribute value for the facet
050     */
051    public int getAttributeValue() {
052        return attributeValue;
053    }
054}