Пример #1
0
        /// <summary>
        /// Compares all the featurevectors in the database with each other.
        /// </summary>
        /// <param name="size">The size of best number of elements.</param>
        /// <returns>A <see cref="QueryResult"/> array which contains the K-best similair
        /// matches from the entire database for these entries.</returns>
        public QueryResult[] InternalCompare(QuerySize size)
        {
            ANN HNSW = new ANN(features);

            ConcurrentBag <QueryResult> results = new ConcurrentBag <QueryResult>();

            Parallel.ForEach(VectorDictionary, pair => {
                string name          = pair.Key;
                FeatureVector vector = pair.Value;
                string clazz         = Settings.FileManager.ClassByShapeName(name);
                int count            = QuerySizeToInt(size, clazz);

                results.Add(HNSW.RunANNQuery(name, vector, count));
            });

            return(results.ToArray());
        }
Пример #2
0
        /// <summary>
        /// Compares the given meshes with all the saved meshes in this <see cref="FeatureManager"/>
        /// and returns all the meshes ordered by the similarity.
        /// </summary>
        /// <param name="meshes">The mesh that should be compared with all other meshes
        /// in the database.</param>
        /// <returns>A <see cref="QueryResult"/> array which contains the K-best similair
        /// matches from the entire database for these entries.</returns>
        public QueryResult[] CalculateResults(QuerySize size, IEnumerable <MeshEntry> meshes)
        {
            if (meshes == null)
            {
                throw new ArgumentNullException(nameof(meshes));
            }

            ANN HNSW = new ANN(features);

            ConcurrentBag <QueryResult> results = new ConcurrentBag <QueryResult>();

            Parallel.ForEach(meshes, entry => {
                FeatureVector queryVector = CreateVector(entry);
                queryVector = NormaliseVector(queryVector);
                int count   = QuerySizeToInt(size, entry.Class);
                results.Add(HNSW.RunANNQuery(entry.Name,
                                             queryVector,
                                             count));
            });

            QueryResult[] array = results.ToArray();
            Array.Sort(array);
            return(array);
        }