/** * Construct a new immutable {@code SMFTriangles} instance. * @param triangleCount The value for the {@code triangleCount} attribute * @param triangleIndexSizeBits The value for the {@code triangleIndexSizeBits} attribute * @return An immutable SMFTriangles instance */ public static SMFTriangles of(long triangleCount, int triangleIndexSizeBits) { return validate(new SMFTriangles(triangleCount, triangleIndexSizeBits)); }
private static SMFTriangles validate(SMFTriangles instance) { instance.checkPreconditions(); return instance; }
/** * This instance is equal to all instances of {@code SMFTriangles} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof SMFTriangles && equalTo((SMFTriangles) another); }
final SMFTriangles triangles = this.header.triangles(); if (Long.compareUnsigned(triangles.triangleCount(), 0L) > 0) { final long size_tri = Math.multiplyExact( Integer.toUnsignedLong(triangles.triangleSizeOctets()), triangles.triangleCount()); this, this.tri_buffer, triangles.triangleIndexSizeBits(), triangles.triangleCount()); } else { LOG.debug("triangle packing requested, but no triangles are available");
this.attribute_queue = Queue.ofAll(attributes); final SMFTriangles triangles = in_header.triangles(); this.triangle_values_remaining = triangles.triangleCount(); this.meta_values_remaining = in_header.metaCount(); String.format( "triangles %s %s", Long.toUnsignedString(triangles.triangleCount()), Long.toUnsignedString(triangles.triangleIndexSizeBits()))); this.writer.newLine();
private void failMissedTriangles() { if (this.parsed_triangles != this.header.triangles().triangleCount()) { this.fail("Too few triangles specified", Optional.empty()); } }
private static int optimize( final SMFMemoryMesh m, final OptionalInt optimize_opt, final long max) { int triangle_size = m.header().triangles().triangleIndexSizeBits(); if (optimize_opt.isPresent()) { if (max < (long) (StrictMath.pow(2.0, 64.0) - 1.0)) { triangle_size = 64; } if (max < (long) (StrictMath.pow(2.0, 32.0) - 1.0)) { triangle_size = 32; } if (max < (long) (StrictMath.pow(2.0, 16.0) - 1.0)) { triangle_size = 16; } if (max < (long) (StrictMath.pow(2.0, 8.0) - 1.0)) { triangle_size = 8; } final int smallest_allowed = optimize_opt.getAsInt(); triangle_size = Math.max(triangle_size, smallest_allowed); } return triangle_size; }
/** * Creates an immutable copy of a {@link SMFTrianglesType} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable SMFTriangles instance */ public static SMFTriangles copyOf(SMFTrianglesType instance) { if (instance instanceof SMFTriangles) { return (SMFTriangles) instance; } return SMFTriangles.builder() .from(instance) .build(); }
/** * Builds a new {@link SMFTriangles SMFTriangles}. * @return An immutable instance of SMFTriangles * @throws java.lang.IllegalStateException if any required attributes are missing */ public SMFTriangles build() { return SMFTriangles.validate(new SMFTriangles(this)); }
private boolean equalTo(SMFHeader another) { return triangles.equals(another.triangles) && vertexCount == another.vertexCount && Objects.equals(schemaIdentifier, another.schemaIdentifier) && coordinateSystem.equals(another.coordinateSystem) && this.attributesInOrder().equals(another.attributesInOrder()) && attributesByName.equals(another.attributesByName); }
/** * Computes a hash code from attributes: {@code triangles}, {@code vertexCount}, {@code schemaIdentifier}, {@code coordinateSystem}, {@code attributesInOrder}, {@code attributesByName}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + triangles.hashCode(); h += (h << 5) + Long.hashCode(vertexCount); h += (h << 5) + Objects.hashCode(schemaIdentifier); h += (h << 5) + coordinateSystem.hashCode(); h += (h << 5) + (attributesInOrder().hashCode()); h += (h << 5) + attributesByName.hashCode(); return h; }
@Override public void onFinish() { if (this.errors.isEmpty()) { Invariants.checkInvariantI( this.attr_buffers.size(), this.attr_buffers.size() == this.config.size(), x -> "Must have correct number of buffers"); final SMFByteBufferPackedMesh.Builder mb = SMFByteBufferPackedMesh.builder(); for (final Tuple2<Integer, ByteBuffer> p : this.attr_buffers) { mb.addAttributeSets(SMFByteBufferPackedAttributeSet.of( p._1.intValue(), this.config.get(p._1).get(), p._2)); } if (this.tri_buffer != null) { final SMFTriangles triangles = this.header.triangles(); mb.setTriangles(SMFByteBufferPackedTriangles.of( this.tri_buffer, triangles.triangleCount(), Math.toIntExact(triangles.triangleIndexSizeBits()))); } mb.setHeader(this.header); this.mesh = mb.build(); } }
private boolean isBodyDone() { final boolean ok_triangles = this.header.triangles().triangleCount() == this.parsed_triangles; final boolean attribute_size_ok = this.attributes_ok.size() == this.header.attributesByName().size(); final boolean attribute_all_done = this.attributes_ok.foldRight( Boolean.TRUE, (p, x) -> Boolean.valueOf(p._2.booleanValue() && x.booleanValue())).booleanValue(); this.log().trace( "triangles done: {}", Boolean.valueOf(ok_triangles)); this.log().trace( "attributes size: {}", Boolean.valueOf(attribute_size_ok)); this.log().trace( "attributes done: {}", Boolean.valueOf(attribute_all_done)); return ok_triangles && attribute_size_ok && attribute_all_done; }
/** * Creates an immutable copy of a {@link SMFTrianglesType} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable SMFTriangles instance */ public static SMFTriangles copyOf(SMFTrianglesType instance) { if (instance instanceof SMFTriangles) { return (SMFTriangles) instance; } return SMFTriangles.builder() .from(instance) .build(); }
/** * Builds a new {@link SMFTriangles SMFTriangles}. * @return An immutable instance of SMFTriangles * @throws java.lang.IllegalStateException if any required attributes are missing */ public SMFTriangles build() { return SMFTriangles.validate(new SMFTriangles(this)); }
private boolean equalTo(SMFHeader another) { return triangles.equals(another.triangles) && vertexCount == another.vertexCount && schemaIdentifier.equals(another.schemaIdentifier) && coordinateSystem.equals(another.coordinateSystem) && this.attributesInOrder().equals(another.attributesInOrder()) && attributesByName.equals(another.attributesByName) && metaCount == another.metaCount; }
/** * Computes a hash code from attributes: {@code triangles}, {@code vertexCount}, {@code schemaIdentifier}, {@code coordinateSystem}, {@code attributesInOrder}, {@code attributesByName}, {@code metaCount}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + triangles.hashCode(); h += (h << 5) + Long.hashCode(vertexCount); h += (h << 5) + schemaIdentifier.hashCode(); h += (h << 5) + coordinateSystem.hashCode(); h += (h << 5) + (attributesInOrder().hashCode()); h += (h << 5) + attributesByName.hashCode(); h += (h << 5) + Long.hashCode(metaCount); return h; }
/** * Copy the current immutable object by setting a value for the {@link SMFTrianglesType#triangleCount() triangleCount} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for triangleCount * @return A modified copy of the {@code this} object */ public final SMFTriangles withTriangleCount(long value) { if (this.triangleCount == value) return this; return validate(new SMFTriangles(value, this.triangleIndexSizeBits)); }
while (this.parsed_triangles != this.header.triangles().triangleCount()) { final Optional<List<String>> line_opt = super.reader.line(); if (!line_opt.isPresent()) {
/** * @return The triangle information for the file */ @Value.Default @Value.Parameter default SMFTriangles triangles() { return SMFTriangles.builder().build(); }