From 9d754526eeef1dc14daccd93cb75359bd9339b03 Mon Sep 17 00:00:00 2001 From: Ralph Gasser Date: Wed, 28 Aug 2024 10:47:36 +0200 Subject: [PATCH] Minor adjustments: - Uses default Json instance now and moves custom serializer to Texture class. - All getters for cached content are synchronized. - Renamed classes to be consistent. --- .../{Model3DContent.kt => Model3dContent.kt} | 4 +-- .../content/factory/CachedContentFactory.kt | 4 +-- .../model/content/factory/ContentFactory.kt | 4 +-- .../content/factory/InMemoryContentFactory.kt | 8 ++--- .../content/impl/cache/CachedAudioContent.kt | 2 +- .../content/impl/cache/CachedImageContent.kt | 2 +- ...MeshContent.kt => CachedModel3dContent.kt} | 35 +++++-------------- .../content/impl/cache/CachedTextContent.kt | 2 +- ...3DContent.kt => InMemoryModel3dContent.kt} | 6 ++-- .../core/model/mesh/texturemodel/Texture.kt | 7 ++-- .../types/{Quaterinionf.kt => Quaternionf.kt} | 35 +++---------------- .../mesh/texturemodel/util/types/Vec3f.kt | 29 ++------------- .../mesh/texturemodel/util/types/Vec4f.kt | 2 +- .../BufferedImageSerializer.kt | 12 +++++-- .../sphericalharmonics/SphericalHarmonics.kt | 16 ++++----- .../SphericalHarmonicsExtractor.kt | 8 ++--- .../SphericalHarmonicsRetriever.kt | 4 +-- 17 files changed, 61 insertions(+), 119 deletions(-) rename vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/element/{Model3DContent.kt => Model3dContent.kt} (74%) rename vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/{CachedMeshContent.kt => CachedModel3dContent.kt} (51%) rename vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/memory/{InMemoryMesh3DContent.kt => InMemoryModel3dContent.kt} (55%) rename vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/{Quaterinionf.kt => Quaternionf.kt} (85%) rename vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/{mesh/texturemodel/util => serializer}/BufferedImageSerializer.kt (83%) diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/element/Model3DContent.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/element/Model3dContent.kt similarity index 74% rename from vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/element/Model3DContent.kt rename to vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/element/Model3dContent.kt index 831c3a33c..df58ace16 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/element/Model3DContent.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/element/Model3dContent.kt @@ -9,8 +9,8 @@ import org.vitrivr.engine.core.model.mesh.texturemodel.Model3d * @author Rahel Arnold * @version 1.0.0 */ -interface Model3DContent : ContentElement { - /** The [ContentType] of a [Model3DContent] is always [ContentType.MESH]. */ +interface Model3dContent : ContentElement { + /** The [ContentType] of a [Model3dContent] is always [ContentType.MESH]. */ override val type: ContentType get() = ContentType.MESH diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/CachedContentFactory.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/CachedContentFactory.kt index 1845b5fe0..f2c49ff7d 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/CachedContentFactory.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/CachedContentFactory.kt @@ -114,9 +114,9 @@ class CachedContentFactory : ContentFactoriesFactory { return content } - override fun newMeshContent(model3d: Model3d): Model3DContent { + override fun newMeshContent(model3d: Model3d): Model3dContent { check(!this.closed) { "CachedContentFactory has been closed." } - val content = CachedMeshContent(this.nextPath(), model3d) + val content = CachedModel3dContent(this.nextPath(), model3d) this.refSet.add(CachedItem(content, this.referenceQueue)) return content } diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/ContentFactory.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/ContentFactory.kt index 1b0a3f758..30a0a6edf 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/ContentFactory.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/ContentFactory.kt @@ -2,7 +2,7 @@ package org.vitrivr.engine.core.model.content.factory import org.vitrivr.engine.core.model.content.element.AudioContent import org.vitrivr.engine.core.model.content.element.ImageContent -import org.vitrivr.engine.core.model.content.element.Model3DContent +import org.vitrivr.engine.core.model.content.element.Model3dContent import org.vitrivr.engine.core.model.content.element.TextContent import org.vitrivr.engine.core.model.mesh.texturemodel.Model3d import java.awt.image.BufferedImage @@ -15,5 +15,5 @@ interface ContentFactory { fun newTextContent(text: String): TextContent - fun newMeshContent(model3d: Model3d): Model3DContent + fun newMeshContent(model3d: Model3d): Model3dContent } \ No newline at end of file diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/InMemoryContentFactory.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/InMemoryContentFactory.kt index 2c40aad83..d1eab3f2a 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/InMemoryContentFactory.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/factory/InMemoryContentFactory.kt @@ -2,11 +2,11 @@ package org.vitrivr.engine.core.model.content.factory import org.vitrivr.engine.core.context.Context import org.vitrivr.engine.core.model.content.element.ContentElement -import org.vitrivr.engine.core.model.content.element.Model3DContent +import org.vitrivr.engine.core.model.content.element.Model3dContent import org.vitrivr.engine.core.model.content.element.TextContent import org.vitrivr.engine.core.model.content.impl.memory.InMemoryAudioContent import org.vitrivr.engine.core.model.content.impl.memory.InMemoryImageContent -import org.vitrivr.engine.core.model.content.impl.memory.InMemoryMeshContent +import org.vitrivr.engine.core.model.content.impl.memory.InMemoryModel3dContent import org.vitrivr.engine.core.model.content.impl.memory.InMemoryTextContent import org.vitrivr.engine.core.model.mesh.texturemodel.Model3d import org.vitrivr.engine.core.model.metamodel.Schema @@ -21,10 +21,10 @@ import java.nio.ShortBuffer */ class InMemoryContentFactory : ContentFactoriesFactory { override fun newContentFactory(schema: Schema, context: Context): ContentFactory = Instance() - private class Instance() : ContentFactory { + private class Instance : ContentFactory { override fun newImageContent(bufferedImage: BufferedImage) = InMemoryImageContent(bufferedImage) override fun newAudioContent(channels: Short, sampleRate: Int, audio: ShortBuffer) = InMemoryAudioContent(channels, sampleRate, audio) override fun newTextContent(text: String): TextContent = InMemoryTextContent(text) - override fun newMeshContent(model3d: Model3d): Model3DContent = InMemoryMeshContent(model3d) + override fun newMeshContent(model3d: Model3d): Model3dContent = InMemoryModel3dContent(model3d) } } diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedAudioContent.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedAudioContent.kt index 2a3d60eed..f295a8b31 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedAudioContent.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedAudioContent.kt @@ -9,7 +9,6 @@ import java.nio.ShortBuffer import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardOpenOption -import java.util.* /** * A [AudioContent] implementation that is backed by a cache file. @@ -29,6 +28,7 @@ class CachedAudioContent(override val path: Path, override val channels: Short, /** The audio samples contained in this [CachedAudioContent]. */ override val content: ShortBuffer + @Synchronized get() { var buffer = this.reference.get() if (buffer == null) { diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedImageContent.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedImageContent.kt index 498511401..288c5239c 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedImageContent.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedImageContent.kt @@ -7,7 +7,6 @@ import java.lang.ref.SoftReference import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardOpenOption -import java.util.* import javax.imageio.ImageIO /** @@ -29,6 +28,7 @@ class CachedImageContent(override val path: Path, image: BufferedImage, override /** The [BufferedImage] contained in this [CachedImageContent]. */ override val content: BufferedImage + @Synchronized get() { var image = this.reference.get() if (image == null) { diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedMeshContent.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedModel3dContent.kt similarity index 51% rename from vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedMeshContent.kt rename to vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedModel3dContent.kt index 42490100e..8cdd0350d 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedMeshContent.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedModel3dContent.kt @@ -2,12 +2,9 @@ package org.vitrivr.engine.core.model.content.impl.cache import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import kotlinx.serialization.modules.SerializersModule -import kotlinx.serialization.modules.contextual import org.vitrivr.engine.core.model.content.element.ContentId -import org.vitrivr.engine.core.model.content.element.Model3DContent +import org.vitrivr.engine.core.model.content.element.Model3dContent import org.vitrivr.engine.core.model.mesh.texturemodel.Model3d -import org.vitrivr.engine.core.model.mesh.texturemodel.util.BufferedImageSerializer import java.lang.ref.SoftReference import java.nio.charset.StandardCharsets import java.nio.file.Files @@ -15,7 +12,7 @@ import java.nio.file.Path import java.nio.file.StandardOpenOption /** - * A [Model3DContent] implementation that is backed by a cache file. + * A [Model3dContent] implementation that is backed by a cache file. * * This class caches a 3D model to disk in JSON format and uses a [SoftReference] to hold it in memory, * reloading from JSON if necessary. @@ -23,14 +20,14 @@ import java.nio.file.StandardOpenOption * @author Rahel Arnold * @version 1.0.0 */ -class CachedMeshContent(override val path: Path, model: Model3d, override val id: ContentId = ContentId.randomUUID()) : - Model3DContent, CachedContent { +class CachedModel3dContent(override val path: Path, model: Model3d, override val id: ContentId = ContentId.randomUUID()) : Model3dContent, CachedContent { /** The [SoftReference] of the [Model3d] used for caching. */ private var reference: SoftReference = SoftReference(model) - /** The [Model3d] contained in this [CachedMeshContent]. */ + /** The [Model3d] contained in this [CachedModel3dContent]. */ override val content: Model3d + @Synchronized get() { var cachedModel = reference.get() if (cachedModel == null) { @@ -40,24 +37,10 @@ class CachedMeshContent(override val path: Path, model: Model3d, override val id return cachedModel } - /** JSON format configuration for serialization. */ - private val jsonFormat = Json { prettyPrint = true } - init { - // Serialize the Model3d to JSON and write it to the cache file during initialization. - val jsonFormat = Json { - prettyPrint = true - serializersModule = SerializersModule { - contextual(BufferedImageSerializer) // Register the custom BufferedImage serializer - } - } - Files.newBufferedWriter( - this.path, - StandardCharsets.UTF_8, - StandardOpenOption.CREATE_NEW, - StandardOpenOption.WRITE - ).use { writer -> - writer.write(jsonFormat.encodeToString(model)) + /* Serialize the Model3d to JSON and write it to the cache file during initialization. */ + Files.newBufferedWriter(this.path, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE).use { writer -> + writer.write(Json.encodeToString(model)) } } @@ -68,7 +51,7 @@ class CachedMeshContent(override val path: Path, model: Model3d, override val id */ private fun reload(): Model3d { return Files.newBufferedReader(this.path, StandardCharsets.UTF_8).use { reader -> - jsonFormat.decodeFromString(reader.readText()) + Json.decodeFromString(reader.readText()) } } } \ No newline at end of file diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedTextContent.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedTextContent.kt index 4038e3c8a..b20ed0164 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedTextContent.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/cache/CachedTextContent.kt @@ -6,7 +6,6 @@ import java.lang.ref.SoftReference import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardOpenOption -import java.util.* /** * A [TextContent] implementation that is backed by a cache file. @@ -24,6 +23,7 @@ class CachedTextContent(override val path: Path, text: String, override val id: /** The [String] contained in this [CachedTextContent]. */ override val content: String + @Synchronized get() { var image = this.reference.get() if (image == null) { diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/memory/InMemoryMesh3DContent.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/memory/InMemoryModel3dContent.kt similarity index 55% rename from vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/memory/InMemoryMesh3DContent.kt rename to vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/memory/InMemoryModel3dContent.kt index 6170e9902..f7384f5bc 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/memory/InMemoryMesh3DContent.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/content/impl/memory/InMemoryModel3dContent.kt @@ -2,15 +2,15 @@ package org.vitrivr.engine.core.model.content.impl.memory import org.vitrivr.engine.core.model.content.element.ContentId import org.vitrivr.engine.core.model.content.element.ImageContent -import org.vitrivr.engine.core.model.content.element.Model3DContent +import org.vitrivr.engine.core.model.content.element.Model3dContent import org.vitrivr.engine.core.model.mesh.texturemodel.Model3d /** * A naive in-memory implementation of the [ImageContent] interface. * - * Warning: Usage of [InMemoryMeshContent] may lead to out-of-memory situations in large extraction pipelines. + * Warning: Usage of [InMemoryModel3dContent] may lead to out-of-memory situations in large extraction pipelines. * * @author Luca Rossetto. * @version 1.0.0 */ -data class InMemoryMeshContent(override val content: Model3d, override val id: ContentId = ContentId.randomUUID()) : Model3DContent +data class InMemoryModel3dContent(override val content: Model3d, override val id: ContentId = ContentId.randomUUID()) : Model3dContent diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Texture.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Texture.kt index b0b1bafee..c257c9dc9 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Texture.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/Texture.kt @@ -1,11 +1,11 @@ package org.vitrivr.engine.core.model.mesh.texturemodel -import kotlinx.serialization.Contextual import kotlinx.serialization.Serializable +import org.vitrivr.engine.core.model.serializer.BufferedImageSerializer import java.awt.image.BufferedImage import java.io.* -import java.io.Serializable as JavaSerializable import javax.imageio.ImageIO +import java.io.Serializable as JavaSerializable /** * This class represents a texture. @@ -14,7 +14,8 @@ import javax.imageio.ImageIO @Serializable data class Texture( var texturePath: String? = null, - @Contextual + + @Serializable(with = BufferedImageSerializer::class) var textureImage: BufferedImage? = null ) : JavaSerializable { diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Quaterinionf.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Quaternionf.kt similarity index 85% rename from vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Quaterinionf.kt rename to vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Quaternionf.kt index 78ab15173..958e86a40 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Quaterinionf.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Quaternionf.kt @@ -1,44 +1,17 @@ package org.vitrivr.engine.core.model.mesh.texturemodel.util.types +import kotlinx.serialization.Serializable import kotlin.math.cos import kotlin.math.sin import kotlin.math.sqrt -import kotlinx.serialization.Serializable + /** * Represents a quaternion, which is a complex number used to represent rotations in 3D space. */ @Serializable -class Quaternionf { - var x: Float = 0f - var y: Float = 0f - var z: Float = 0f - var w: Float = 0f - - /** - * Default constructor - initializes the quaternion as an identity quaternion (no rotation). - */ - constructor() { - identity() - } - - /** - * Constructor with specified components. - * - * @param x The x-component of the quaternion. - * @param y The y-component of the quaternion. - * @param z The z-component of the quaternion. - * @param w The w-component of the quaternion. - */ - constructor(x: Float, y: Float, z: Float, w: Float) { - this.x = x - this.y = y - this.z = z - this.w = w - } - +data class Quaternionf(var x: Float = 0f, var y: Float = 0f, var z: Float = 0f, var w: Float = 0f,) { /** - * Sets the quaternion to the identity quaternion. - * The identity quaternion represents no rotation. + * Sets the quaternion to the identity quaternion. The identity quaternion represents no rotation. * * @return This quaternion after being set to the identity quaternion. */ diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Vec3f.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Vec3f.kt index 6972f08c3..622756bc5 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Vec3f.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Vec3f.kt @@ -1,14 +1,15 @@ package org.vitrivr.engine.core.model.mesh.texturemodel.util.types +import kotlinx.serialization.Serializable import kotlin.math.sqrt import java.io.Serializable as JavaSerializable -import kotlinx.serialization.Serializable + /** * Represents a 3D vector with floating-point coordinates. * This class provides basic vector operations such as addition, subtraction, scaling, and normalization. */ @Serializable -class Vec3f +data class Vec3f @JvmOverloads constructor(var x: Float = 0.0f, var y: Float = 0.0f, var z: Float = 0.0f) : JavaSerializable { /** @@ -177,30 +178,6 @@ class Vec3f return "Vec3f($x, $y, $z)" } - /** - * Compares this vector to another object for equality. - * - * @param obj The object to compare to. - * @return True if the object is a Vec3f with the same x, y, and z components, false otherwise. - */ - override fun equals(obj: Any?): Boolean { - if (this === obj) return true - if (obj == null || javaClass != obj.javaClass) return false - val vector = obj as Vec3f - return java.lang.Float.compare(vector.x, x) == 0 && java.lang.Float.compare( - vector.y, y - ) == 0 && java.lang.Float.compare(vector.z, z) == 0 - } - - /** - * Computes a hash code for this vector. - * - * @return A hash code value for the vector. - */ - override fun hashCode(): Int { - return java.lang.Float.hashCode(x) xor java.lang.Float.hashCode(y) xor java.lang.Float.hashCode(z) - } - /** * Computes the squared distance between this vector and another vector. * diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Vec4f.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Vec4f.kt index 05ba20946..6a52e9953 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Vec4f.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/types/Vec4f.kt @@ -13,7 +13,7 @@ import java.io.Serializable as JavaSerializable * @property w The w component of the vector. */ @Serializable -class Vec4f( +data class Vec4f( var x: Float = 0.0f, var y: Float = 0.0f, var z: Float = 0.0f, var w: Float = 0.0f ) : JavaSerializable { diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/BufferedImageSerializer.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/serializer/BufferedImageSerializer.kt similarity index 83% rename from vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/BufferedImageSerializer.kt rename to vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/serializer/BufferedImageSerializer.kt index e986b86b3..17b1d479a 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/mesh/texturemodel/util/BufferedImageSerializer.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/serializer/BufferedImageSerializer.kt @@ -1,4 +1,4 @@ -package org.vitrivr.engine.core.model.mesh.texturemodel.util +package org.vitrivr.engine.core.model.serializer import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.PrimitiveKind @@ -9,9 +9,17 @@ import kotlinx.serialization.encoding.Encoder import java.awt.image.BufferedImage import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream -import javax.imageio.ImageIO import java.util.* +import javax.imageio.ImageIO +/** + * A custom [KSerializer] for [BufferedImage] objects. + * + * This serializer encodes a [BufferedImage] as a Base64 encoded PNG image. + * + * @author Rahel Arnold + * @version 1.0.0 + */ object BufferedImageSerializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("BufferedImage", PrimitiveKind.STRING) diff --git a/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonics.kt b/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonics.kt index 2ccbb603c..e10d9b2ea 100644 --- a/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonics.kt +++ b/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonics.kt @@ -7,7 +7,7 @@ import org.apache.commons.math3.util.FastMath import org.vitrivr.engine.core.context.IndexContext import org.vitrivr.engine.core.context.QueryContext import org.vitrivr.engine.core.model.content.element.ContentElement -import org.vitrivr.engine.core.model.content.element.Model3DContent +import org.vitrivr.engine.core.model.content.element.Model3dContent import org.vitrivr.engine.core.model.descriptor.vector.FloatVectorDescriptor import org.vitrivr.engine.core.model.mesh.texturemodel.Mesh import org.vitrivr.engine.core.model.metamodel.Analyser @@ -37,7 +37,7 @@ private val logger: KLogger = KotlinLogging.logger {} * @author Ralph Gasser * @version 1.2.0 */ -class SphericalHarmonics : Analyser { +class SphericalHarmonics : Analyser { companion object { /** Name of the grid_size parameter; determines size of voxel grid for rasterization. */ const val GRID_SIZE_PARAMETER_NAME = "grid_size" @@ -87,7 +87,7 @@ class SphericalHarmonics : Analyser { * @param minL The minimum L parameter to obtain [SphericalHarmonics] function value for. * @param maxL The maximum L parameter to obtain [SphericalHarmonics] function value for. */ - fun analyse(mesh: org.vitrivr.engine.core.model.mesh.texturemodel.Mesh, gridSize: Int, cap: Int, minL: Int, maxL: Int): FloatVectorDescriptor { + fun analyse(mesh: Mesh, gridSize: Int, cap: Int, minL: Int, maxL: Int): FloatVectorDescriptor { val voxelizer = Voxelizer(2.0f / gridSize) val increment = 0.1 /* Increment of the angles during calculation of the descriptors. */ val R: Int = gridSize / 2 @@ -153,7 +153,7 @@ class SphericalHarmonics : Analyser { } } - override val contentClasses: Set>> = setOf(Model3DContent::class) + override val contentClasses: Set>> = setOf(Model3dContent::class) override val descriptorClass: KClass = FloatVectorDescriptor::class override fun prototype(field: Schema.Field<*, *>): FloatVectorDescriptor { val gridSize = field.parameters[GRID_SIZE_PARAMETER_NAME]?.toIntOrNull() ?: GRID_SIZE_PARAMETER_DEFAULT @@ -165,7 +165,7 @@ class SphericalHarmonics : Analyser { return FloatVectorDescriptor(UUID.randomUUID(), UUID.randomUUID(), Value.FloatVector(FloatArray(vectorSize))) } - override fun newRetrieverForQuery(field: Schema.Field, query: Query, context: QueryContext): Retriever { + override fun newRetrieverForQuery(field: Schema.Field, query: Query, context: QueryContext): Retriever { require(field.analyser == this) { "The field '${field.fieldName}' analyser does not correspond with this analyser. This is a programmer's error!" } require(query is ProximityQuery<*> && query.value is Value.FloatVector) { } @@ -174,7 +174,7 @@ class SphericalHarmonics : Analyser { return SphericalHarmonicsRetriever(field, query as ProximityQuery, context) } - override fun newRetrieverForDescriptors(field: Schema.Field, descriptors: Collection, context: QueryContext): Retriever { + override fun newRetrieverForDescriptors(field: Schema.Field, descriptors: Collection, context: QueryContext): Retriever { /* Extract parameters from field and context. */ val k = context.getProperty(field.fieldName, "limit")?.toLongOrNull() ?: 1000L val returnDescriptor = context.getProperty(field.fieldName, "returnDescriptor")?.toBooleanStrictOrNull() ?: false @@ -184,7 +184,7 @@ class SphericalHarmonics : Analyser { return this.newRetrieverForQuery(field, query, context) } - override fun newRetrieverForContent(field: Schema.Field, content: Collection, context: QueryContext): Retriever { + override fun newRetrieverForContent(field: Schema.Field, content: Collection, context: QueryContext): Retriever { require(field.analyser == this) { "The field '${field.fieldName}' analyser does not correspond with this analyser. This is a programmer's error!" } /* Extract parameters from field and context. */ @@ -206,7 +206,7 @@ class SphericalHarmonics : Analyser { * @param context The [IndexContext] to use with the [Extractor]. * @return [SphericalHarmonicsExtractor] */ - override fun newExtractor(field: Schema.Field, input: Operator, context: IndexContext): SphericalHarmonicsExtractor { + override fun newExtractor(field: Schema.Field, input: Operator, context: IndexContext): SphericalHarmonicsExtractor { val gridSize = field.parameters[GRID_SIZE_PARAMETER_NAME]?.toIntOrNull() ?: context.getProperty("", "")?.toIntOrNull() ?: GRID_SIZE_PARAMETER_DEFAULT val cap = field.parameters[CAP_PARAMETER_NAME]?.toIntOrNull() ?: context.getProperty("", "")?.toIntOrNull() ?: CAP_PARAMETER_DEFAULT val minL = field.parameters[MINL_PARAMETER_NAME]?.toIntOrNull() ?: context.getProperty("", "")?.toIntOrNull() ?: MINL_PARAMETER_DEFAULT diff --git a/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonicsExtractor.kt b/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonicsExtractor.kt index fd445cd71..34b486476 100644 --- a/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonicsExtractor.kt +++ b/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonicsExtractor.kt @@ -3,7 +3,7 @@ package org.vitrivr.engine.model3d.features.sphericalharmonics import org.vitrivr.engine.core.features.AbstractExtractor import org.vitrivr.engine.core.features.metadata.source.file.FileSourceMetadataExtractor import org.vitrivr.engine.core.model.content.ContentType -import org.vitrivr.engine.core.model.content.element.Model3DContent +import org.vitrivr.engine.core.model.content.element.Model3dContent import org.vitrivr.engine.core.model.descriptor.vector.FloatVectorDescriptor import org.vitrivr.engine.core.model.metamodel.Schema import org.vitrivr.engine.core.model.retrievable.Retrievable @@ -23,13 +23,13 @@ import org.vitrivr.engine.core.source.file.FileSource class SphericalHarmonicsExtractor( input: Operator, analyser: SphericalHarmonics, - field: Schema.Field?, + field: Schema.Field?, private val gridSize: Int, private val cap: Int, private val minL: Int, private val maxL: Int ) : - AbstractExtractor(input, analyser, field) { + AbstractExtractor(input, analyser, field) { init { require(this.minL < this.maxL) { "Parameter mismatch: min_l must be smaller than max_l. "} @@ -52,7 +52,7 @@ class SphericalHarmonicsExtractor( * @return List of resulting [FloatVectorDescriptor]s. */ override fun extract(retrievable: Retrievable): List { - val content = retrievable.content.filterIsInstance() + val content = retrievable.content.filterIsInstance() return content.flatMap { c -> c.content.getMaterials().flatMap { mat -> mat.materialMeshes.map { mesh -> SphericalHarmonics.analyse(mesh, this.gridSize, this.minL, this.maxL, this.cap).copy(field = this.field) } } } } } \ No newline at end of file diff --git a/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonicsRetriever.kt b/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonicsRetriever.kt index 3febb29ac..41816b868 100644 --- a/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonicsRetriever.kt +++ b/vitrivr-engine-module-m3d/src/main/kotlin/org/vitrivr/engine/model3d/features/sphericalharmonics/SphericalHarmonicsRetriever.kt @@ -4,7 +4,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import org.vitrivr.engine.core.context.QueryContext -import org.vitrivr.engine.core.model.content.element.Model3DContent +import org.vitrivr.engine.core.model.content.element.Model3dContent import org.vitrivr.engine.core.model.descriptor.vector.FloatVectorDescriptor import org.vitrivr.engine.core.model.metamodel.Schema import org.vitrivr.engine.core.model.query.proximity.ProximityQuery @@ -22,7 +22,7 @@ import org.vitrivr.engine.core.operators.retrieve.Retriever * @author Ralph Gasser * @version 1.0.0 */ -class SphericalHarmonicsRetriever(override val field: Schema.Field, private val query: ProximityQuery<*>, private val context: QueryContext) : Retriever { +class SphericalHarmonicsRetriever(override val field: Schema.Field, private val query: ProximityQuery<*>, private val context: QueryContext) : Retriever { companion object { private const val MAXIMUM_DISTANCE = 1.0f fun scoringFunction(retrieved: Retrieved) : Float {