Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ppanopticon committed Mar 26, 2024
2 parents 81e8575 + edb40a8 commit f3b77fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import org.vitrivr.engine.core.model.descriptor.vector.FloatVectorDescriptor
import org.vitrivr.engine.core.model.mesh.Mesh
import org.vitrivr.engine.core.model.metamodel.Analyser
import org.vitrivr.engine.core.model.metamodel.Schema
import org.vitrivr.engine.core.model.query.Query
import org.vitrivr.engine.core.model.query.basics.Distance
import org.vitrivr.engine.core.model.query.proximity.ProximityQuery
import org.vitrivr.engine.core.model.retrievable.Retrievable
import org.vitrivr.engine.core.model.types.Value
import org.vitrivr.engine.core.operators.Operator
Expand Down Expand Up @@ -75,18 +78,29 @@ class SphericalHarmonics: Analyser<Model3DContent, FloatVectorDescriptor> {

override fun newRetrieverForContent(field: Schema.Field<Model3DContent, FloatVectorDescriptor>, content: Collection<Model3DContent>, context: QueryContext): Retriever<Model3DContent, FloatVectorDescriptor> {
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. */
val mesh = content.first().content.getMaterials().first().meshes.first()
val gridSize = field.parameters[GRID_SIZE_PARAMETER_NAME]?.toIntOrNull() ?: GRID_SIZE_PARAMETER_DEFAULT
val cap = field.parameters[CAP_PARAMETER_NAME]?.toIntOrNull() ?: CAP_PARAMETER_DEFAULT
val minL = field.parameters[MINL_PARAMETER_NAME]?.toIntOrNull() ?: MINL_PARAMETER_DEFAULT
val maxL = field.parameters[MAXL_PARAMETER_NAME]?.toIntOrNull() ?: MAXL_PARAMETER_DEFAULT
val descriptor = this.analyse(mesh, gridSize, cap, minL, maxL)
return SphericalHarmonicsRetriever(field, descriptor, context)
val k = context.getProperty(field.fieldName, "limit")?.toIntOrNull() ?: 1000 //TODO get limit
val returnDescriptor = context.getProperty(field.fieldName, "returnDescriptor")?.toBooleanStrictOrNull() ?: false

/* Construct query. */
val query = ProximityQuery(value = descriptor.vector, k = k, distance = Distance.EUCLIDEAN, fetchVector = returnDescriptor)
return SphericalHarmonicsRetriever(field, query, context)
}

override fun newRetrieverForDescriptors(field: Schema.Field<Model3DContent, FloatVectorDescriptor>, descriptors: Collection<FloatVectorDescriptor>, context: QueryContext): Retriever<Model3DContent, FloatVectorDescriptor> {
override fun newRetrieverForQuery(field: Schema.Field<Model3DContent, FloatVectorDescriptor>, query: Query, context: QueryContext): Retriever<Model3DContent, FloatVectorDescriptor> {
require(field.analyser == this) { "The field '${field.fieldName}' analyser does not correspond with this analyser. This is a programmer's error!" }
return SphericalHarmonicsRetriever(field, descriptors.first(), context)
require(query is ProximityQuery<*> && query.value.first() is Value.Float) { }

/* Construct query. */
@Suppress("UNCHECKED_CAST")
return SphericalHarmonicsRetriever(field, query as ProximityQuery<Value.Float>, context)
}

override fun newExtractor(field: Schema.Field<Model3DContent, FloatVectorDescriptor>, input: Operator<Retrievable>, context: IndexContext, persisting: Boolean, parameters: Map<String, Any>): SphericalHarmonicsExtractor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.vitrivr.engine.core.operators.retrieve.Retriever
* @author Ralph Gasser
* @version 1.0.0
*/
class SphericalHarmonicsRetriever(override val field: Schema.Field<Model3DContent, FloatVectorDescriptor>, private val query: FloatVectorDescriptor, private val context: QueryContext) : Retriever<Model3DContent, FloatVectorDescriptor> {
class SphericalHarmonicsRetriever(override val field: Schema.Field<Model3DContent, FloatVectorDescriptor>, private val query: ProximityQuery<*>, private val context: QueryContext) : Retriever<Model3DContent, FloatVectorDescriptor> {
companion object {
private const val MAXIMUM_DISTANCE = 1.0f
fun scoringFunction(retrieved: Retrieved) : Float {
Expand All @@ -33,12 +33,10 @@ class SphericalHarmonicsRetriever(override val field: Schema.Field<Model3DConten
}

override fun toFlow(scope: CoroutineScope): Flow<Retrieved> {
val k = this.context.getProperty(this.field.fieldName, "limit")?.toIntOrNull() ?: 1000 //TODO get limit
val returnDescriptor = this.context.getProperty(this.field.fieldName, "returnDescriptor")?.toBooleanStrictOrNull() ?: false

val reader = this.field.getReader()
val query = ProximityQuery(value = this.query.vector, k = k, distance = Distance.EUCLIDEAN, fetchVector = returnDescriptor)
return flow {
reader.getAll(query).forEach {
reader.getAll(this@SphericalHarmonicsRetriever.query).forEach {
it.addAttribute(ScoreAttribute(scoringFunction(it)))
emit(it)
}
Expand Down

0 comments on commit f3b77fb

Please sign in to comment.