Пример #1
0
        /// <summary>
        /// Returns the next image in the Index set based on the selection criteria.
        /// </summary>
        /// <param name="type">Specifies the selection type (e.g. RANDOM, SEQUENTIAL).</param>
        /// <param name="nLabel">Optionally, specifies a label (default = null).</param>
        /// <param name="bBoosted">Optionally, specifies to query boosted images (default = false).</param>
        /// <param name="nDirectIdx">Optionally, specifies to query the image at this index (only applies when type = DIRECT).</param>
        /// <returns>The next image index is returned.</returns>
        public virtual int?GetNextImage(Index.SELECTION_TYPE type, int?nLabel = null, bool bBoosted = false, int nDirectIdx = -1)
        {
            if (m_nLoadLimit == 0)
            {
                Index idx = GetIndex(nLabel, bBoosted);
                return(idx.GetNext(type));
            }
            else
            {
                if (type != Index.SELECTION_TYPE.RANDOM)
                {
                    throw new Exception("Only RANDOM selections are valid when using LoadLimit > 0.");
                }

                if (nLabel.HasValue)
                {
                    throw new Exception("Label selections are not valid when using LoadLimit > 0");
                }

                if (bBoosted != false)
                {
                    throw new Exception("Boosted qeruies are not valid when using LoadLimit > 0.");
                }

                if (nDirectIdx != -1)
                {
                    throw new Exception("DirectIndex queries are not valid when using LoadLimit > 0.");
                }

                return(m_random.Next(m_nLoadLimit));
            }
        }
Пример #2
0
        /// <summary>
        /// Returns the next image in the Index set based on the selection criteria.
        /// </summary>
        /// <param name="imgSel">Specifies the image selection method used.</param>
        /// <param name="nLabel">Optionally, specifies a label (default = null).</param>
        /// <param name="nDirectIdx">Optionally, specifies to query the image at this index (only applies when type = DIRECT).</param>
        /// <returns></returns>
        public int?GetNextImage(IMGDB_IMAGE_SELECTION_METHOD imgSel, int?nLabel, int nDirectIdx)
        {
            if (!nLabel.HasValue && imgSel == IMGDB_IMAGE_SELECTION_METHOD.NONE && nDirectIdx >= 0)
            {
                return(GetNextImage(Index.SELECTION_TYPE.DIRECT, null, false, nDirectIdx));
            }

            Index.SELECTION_TYPE selType = Index.SELECTION_TYPE.RANDOM;
            bool bBoosted = false;

            if ((imgSel & IMGDB_IMAGE_SELECTION_METHOD.RANDOM) != IMGDB_IMAGE_SELECTION_METHOD.RANDOM)
            {
                selType = Index.SELECTION_TYPE.SEQUENTIAL;

                // When using PAIR, advance to the next item.
                if ((imgSel & IMGDB_IMAGE_SELECTION_METHOD.PAIR) == IMGDB_IMAGE_SELECTION_METHOD.PAIR)
                {
                    GetNextImage(selType, nLabel, bBoosted, -1);
                }
            }

            if ((imgSel & IMGDB_IMAGE_SELECTION_METHOD.BOOST) == IMGDB_IMAGE_SELECTION_METHOD.BOOST)
            {
                bBoosted = true;
            }

            return(GetNextImage(selType, nLabel, bBoosted, -1));
        }
        public int?GetNextLabel(Index.SELECTION_TYPE type, int?nLabel, bool bRemove = false)
        {
            if (m_rgIdx.Count == 0)
            {
                return(null);
            }

            if (nLabel.HasValue)
            {
                return(nLabel.Value);
            }
            else if (type == Index.SELECTION_TYPE.SEQUENTIAL)
            {
                int nIdx = m_rgIdx[m_nIdx];

                m_nIdx++;
                if (m_nIdx >= m_rgIdx.Count)
                {
                    m_nIdx = 0;
                }

                return(m_rgIdxToLabelMap[nIdx]);
            }
            else
            {
                lock (m_objSync)
                {
                    int nIdxLoc = 0;

                    // Reload on the fly if empty.
                    if (m_rgIdx.Count == 0)
                    {
                        for (int i = 0; i < m_rgLabels.Length; i++)
                        {
                            if (m_rgLabels[i].Count > 0)
                            {
                                m_rgIdx.Add(i);
                            }
                        }
                    }

                    int nIdx = m_rgIdx[nIdxLoc];

                    if (m_rgIdx.Count > 1)
                    {
                        nIdxLoc = m_randomLabel.Next(0, m_rgIdx.Count - 1, true);
                        nIdx    = m_rgIdx[nIdxLoc];
                    }

                    if (bRemove)
                    {
                        m_rgIdx.RemoveAt(nIdxLoc);
                    }

                    return(m_rgIdxToLabelMap[nIdx]);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Returns the next label in the Index set selected based on the selection criteria.
        /// </summary>
        /// <param name="type">Specifies the selection type (e.g. RANDOM, SEQUENTIAL).</param>
        /// <param name="bBoosted">Optionally, specifies to use label sets of boosted images (default = false).</param>
        /// <returns>The next label index is returned.</returns>
        public virtual int?GetNextLabel(Index.SELECTION_TYPE type, bool bBoosted = false)
        {
            LabelIndex rgIdx = (bBoosted) ? m_rgLabelsBoosted : m_rgLabels;

            if (rgIdx.Count == 0)
            {
                return(null);
            }

            return(rgIdx.GetNextLabel(type, null, false));
        }
Пример #5
0
        public Index GetNextIndex(Index.SELECTION_TYPE type, int?nLabel, bool bRemove = false)
        {
            nLabel = GetNextLabel(type, nLabel, bRemove);
            if (!nLabel.HasValue)
            {
                return(null);
            }

            int nIdx = m_rgLabelToIdxMap[nLabel.Value];

            return(m_rgLabels[nIdx]);
        }
Пример #6
0
        /// <summary>
        /// Returns the next label in the Index set selected based on the selection criteria.
        /// </summary>
        /// <param name="lblSel">Specifies the label selection method used.</param>
        /// <returns>The next label index is returned.</returns>
        public int?GetNextLabel(IMGDB_LABEL_SELECTION_METHOD lblSel)
        {
            Index.SELECTION_TYPE selType = Index.SELECTION_TYPE.RANDOM;
            bool bBoost = false;

            if ((lblSel & IMGDB_LABEL_SELECTION_METHOD.RANDOM) != IMGDB_LABEL_SELECTION_METHOD.RANDOM)
            {
                selType = Index.SELECTION_TYPE.SEQUENTIAL;
            }

            if ((lblSel & IMGDB_LABEL_SELECTION_METHOD.BOOST) == IMGDB_LABEL_SELECTION_METHOD.BOOST)
            {
                bBoost = true;
            }

            return(GetNextLabel(selType, bBoost));
        }
Пример #7
0
        public int?GetNextLabel(Index.SELECTION_TYPE type, int?nLabel, bool bRemove = false)
        {
            if (m_rgIdx.Count == 0)
            {
                return(null);
            }

            if (nLabel.HasValue)
            {
                return(nLabel.Value);
            }
            else if (type == Index.SELECTION_TYPE.SEQUENTIAL)
            {
                int nIdx = m_rgIdx[m_nIdx];

                m_nIdx++;
                if (m_nIdx >= m_rgIdx.Count)
                {
                    m_nIdx = 0;
                }

                return(m_rgIdxToLabelMap[nIdx]);
            }
            else
            {
                lock (m_objSync)
                {
                    int nIdxLoc = 0;
                    int nIdx    = m_rgIdx[nIdxLoc];

                    if (m_rgIdx.Count > 1)
                    {
                        nIdxLoc = m_random.Next(m_rgIdx.Count);
                        nIdx    = m_rgIdx[nIdxLoc];
                    }

                    if (bRemove)
                    {
                        m_rgIdx.RemoveAt(nIdxLoc);
                    }

                    return(m_rgIdxToLabelMap[nIdx]);
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Returns the next label in the Index set selected based on the selection criteria.
        /// </summary>
        /// <param name="type">Specifies the selection type (e.g. RANDOM, SEQUENTIAL).</param>
        /// <param name="bBoosted">Optionally, specifies to use label sets of boosted images (default = false).</param>
        /// <returns>The next label index is returned.</returns>
        public override int?GetNextLabel(Index.SELECTION_TYPE type, bool bBoosted = false)
        {
            LabelIndex rgIdx = (bBoosted) ? m_rgLabelsBoosted : m_rgLabels;

            if (rgIdx.Count == 0)
            {
                return(null);
            }

            int?nIdx = rgIdx.GetNextLabel(type, null, m_bUseUniqueLabelIndexes);

            if (rgIdx.IsEmpty)
            {
                rgIdx.ReLoad();
            }

            return(nIdx);
        }
Пример #9
0
        /// <summary>
        /// Returns the next image in the Index set based on the selection criteria.
        /// </summary>
        /// <param name="type">Specifies the selection type (e.g. RANDOM, SEQUENTIAL).</param>
        /// <param name="nLabel">Optionally, specifies a label (default = null).</param>
        /// <param name="bBoosted">Optionally, specifies to query boosted images (default = false).</param>
        /// <param name="nDirectIdx">Optionally, specifies to query the image at this index (only applies when type = DIRECT).</param>
        /// <returns>The next image index is returned.</returns>
        public override int?GetNextImage(Index.SELECTION_TYPE type, int?nLabel = null, bool bBoosted = false, int nDirectIdx = -1)
        {
            int?nIdx = null;

            if (m_master.LoadLimit > 0)
            {
                nIdx = base.GetNextImage(type, nLabel, bBoosted, nDirectIdx);
            }
            else
            {
                Index idx;
                if (type == Index.SELECTION_TYPE.DIRECT)
                {
                    if (nDirectIdx < 0)
                    {
                        throw new Exception("Invalid direct index, must be >= 0.");
                    }

                    idx  = GetIndex(null, false);
                    nIdx = idx.GetIndex(nDirectIdx);
                }
                else
                {
                    idx = GetIndex(nLabel, bBoosted);
                    if (idx == null)
                    {
                        SetIndex(m_master.GetIndex(nLabel, bBoosted).Clone(), nLabel, bBoosted);
                        idx  = GetIndex(nLabel, bBoosted);
                        nIdx = idx.GetNext(type, m_bUseUniqueImageIndexes);
                    }
                    else
                    {
                        nIdx = idx.GetNext(type, m_bUseUniqueImageIndexes);
                        if (idx.IsEmpty)
                        {
                            SetIndex(m_master.GetIndex(nLabel, bBoosted).Clone(), nLabel, bBoosted);
                        }
                    }
                }
            }

            return(nIdx);
        }