コード例 #1
0
        private BinaryHierarchicalNode build(FreakMatchPointSetStack.Item[] features, FreakFeaturePoint i_center, int[] i_indices, int num_indices)
        {
            int t = mBinarykMedoids.k();

            if (t < this.mMinFeaturePerNode)
            {
                t = this.mMinFeaturePerNode;
            }
            if (num_indices <= t)
            {
                FreakMatchPointSetStack.Item[] index = intArray2FeaturePointArray(features, i_indices);
                return(new BinaryHierarchicalNode(this.nextNodeId(), i_center, true, index, null));
            }
            SortedDictionary <int, List <int> > cluster_map = new SortedDictionary <int, List <int> >();

            // Perform clustering
            // Get a list of features for each cluster center
            int[] assignment = this.mBinarykMedoids.assign(features, i_indices, num_indices);

            // ASSERT(assignment.size() == num_indices, "Assignment size wrong");
            for (int i = 0; i < num_indices; i++)
            {
                // ASSERT(assignment[i] != -1, "Assignment is invalid");
                // ASSERT(assignment[i] < num_indices, "Assignment out of range");
                // ASSERT(indices[assignment[i]] < num_features, "Assignment out of range");

                List <int> li;
                if (!cluster_map.ContainsKey(i_indices[assignment[i]]))
                {
                    li = new List <int>();
                    cluster_map.Add(i_indices[assignment[i]], li);
                }
                else
                {
                    li = cluster_map[i_indices[assignment[i]]];
                }
                li.Add(i_indices[i]);
            }

            // If there is only 1 cluster then make this node a leaf
            if (cluster_map.Count == 1)
            {
                FreakMatchPointSetStack.Item[] index = intArray2FeaturePointArray(features, i_indices);
                return(new BinaryHierarchicalNode(this.nextNodeId(), i_center, true, index, null));
            }
            int n = 0;

            BinaryHierarchicalNode[] cl = new BinaryHierarchicalNode[cluster_map.Count];
            // Create a new node for each cluster center
            foreach (KeyValuePair <int, List <int> > l in cluster_map)
            {
                int first = l.Key;

                // Recursively build the tree
                int[] v = ArrayUtils.toIntArray_impl(l.Value, 0, l.Value.Count);
                cl[n] = this.build(features, features[first], v, v.Length);
                n++;
            }
            return(new BinaryHierarchicalNode(this.nextNodeId(), i_center, false, null, cl));
        }
コード例 #2
0
        public static NyARNftIsetFile loadFromIsetFile(byte[] i_src, int i_file_format)
        {
            switch (i_file_format)
            {
            case FILE_FORMAT_ARTK_V5:
            {
                IsetFileDataParserV5 iset  = new IsetFileDataParserV5(i_src);
                ReferenceImage[]     items = new ReferenceImage[iset.num_of_iset];
                //1stIset
                double dpi    = iset.getImageDpi();
                int[]  images = ArrayUtils.toIntArray_impl(iset.image);
                items[0] = new ReferenceImage(iset.image_size.w, iset.image_size.h, dpi, images);
                //2nd to end
                for (int i = 1; i < iset.num_of_iset; i++)
                {
                    items[i] = new ReferenceImage(iset.image_size.w, iset.image_size.h, images, dpi, iset.sub_dpis[i - 1]);
                }
                return(new NyARNftIsetFile(items));
            }

            case FILE_FORMAT_ARTK_V4:
            {
                IsetFileDataParserV4 iset  = new IsetFileDataParserV4(i_src);
                ReferenceImage[]     items = new ReferenceImage[iset.ar2image.Length];
                for (int i = 0; i < items.Length; i++)
                {
                    IsetFileDataParserV4.AR2ImageT tmp = iset.ar2image[i];
                    items[i] = new ReferenceImage(tmp.width, tmp.height, tmp.dpi, ArrayUtils.toIntArray_impl(tmp.img));
                }
                return(new NyARNftIsetFile(items));
            }

            case FILE_FORMAT_ARTK_V5RAW:
            {
                IsetFileDataParserV5Raw iset  = new IsetFileDataParserV5Raw(i_src);
                ReferenceImage[]        items = new ReferenceImage[iset.dpis.Length];
                //1stIset
                int[] images = ArrayUtils.toIntArray_impl(iset.image);
                items[0] = new ReferenceImage(iset.image_width, iset.image_height, iset.dpis[0], images);
                //2nd to end
                for (int i = 1; i < iset.dpis.Length; i++)
                {
                    items[i] = new ReferenceImage(iset.image_width, iset.image_height, images, iset.dpis[0], iset.dpis[i]);
                }
                return(new NyARNftIsetFile(items));
            }

            default:
                throw new NyARRuntimeException();
            }
        }