Example #1
0
        /// <summary>
        /// Get the image with a specific image index.
        /// </summary>
        /// <param name="nIdx">Specifies the image index.</param>
        /// <param name="bLoadDataCriteria">Specifies whether or not to load the data criteria along with the image.</param>
        /// <param name="bLoadDebugData">Specifies whether or not to load the debug data with the image.</param>
        /// <param name="loadMethod">Specifies the image loading method used.</param>
        /// <returns>If found, the image is returned.</returns>
        public SimpleDatum GetImage(int nIdx, bool bLoadDataCriteria, bool bLoadDebugData, IMAGEDB_LOAD_METHOD loadMethod)
        {
            SimpleDatum sd = m_rgImages[nIdx];

            if (sd == null)
            {
                if (m_refreshManager != null)
                {
                    while (nIdx > 0 && m_rgImages[nIdx] == null)
                    {
                        nIdx--;
                    }

                    sd = m_rgImages[nIdx];

                    if (sd == null)
                    {
                        throw new Exception("No images should be null when using LoadLimit loading!");
                    }
                }
                else
                {
                    if (!m_evtRunning.WaitOne(0) && (loadMethod != IMAGEDB_LOAD_METHOD.LOAD_ON_DEMAND && loadMethod != IMAGEDB_LOAD_METHOD.LOAD_ON_DEMAND_NOCACHE))
                    {
                        Load((loadMethod == IMAGEDB_LOAD_METHOD.LOAD_ON_DEMAND_BACKGROUND) ? true : false);
                    }

                    sd = directLoadImage(nIdx);
                    if (sd == null)
                    {
                        throw new Exception("The image is still null yet should have loaded!");
                    }

                    if (loadMethod == IMAGEDB_LOAD_METHOD.LOAD_ON_DEMAND)
                    {
                        m_rgImages[nIdx] = sd;
                    }
                }
            }

            // Double check that the conditional data has loaded (if needed).
            if (bLoadDataCriteria || bLoadDebugData)
            {
                m_factory.LoadRawData(sd, bLoadDataCriteria, bLoadDebugData);
            }

            return(sd);
        }
Example #2
0
        /// <summary>
        /// Returns the image based on its label and image selection method.
        /// </summary>
        /// <param name="nIdx">Specifies the image index to use when loading sequentially.</param>
        /// <param name="labelSelectionMethod">Specifies the label selection method.</param>
        /// <param name="imageSelectionMethod">Specifies the image selection method.</param>
        /// <param name="log">Specifies the Log for status output.</param>
        /// <param name="bLoadDataCriteria">Specifies to load the data criteria data (default = false).</param>
        /// <param name="bLoadDebugData">Specifies to load the debug data (default = false).</param>
        /// <returns>The SimpleDatum containing the image is returned.</returns>
        public SimpleDatum GetImage(int nIdx, IMGDB_LABEL_SELECTION_METHOD labelSelectionMethod, IMGDB_IMAGE_SELECTION_METHOD imageSelectionMethod, Log log, bool bLoadDataCriteria = false, bool bLoadDebugData = false)
        {
            lock (m_syncObj)
            {
                SimpleDatum[] rgImages = m_rgImages;

                if (m_nLoadLimit > 0 && m_rgImagesLimitLoaded.Count == m_nLoadLimit)
                {
                    rgImages = m_rgImagesLimitLoaded.ToArray();
                }

                if (rgImages.Length == 0)
                {
                    throw new Exception("There are no images in the dataset '" + m_src.Name + "' to select from!");
                }

                SimpleDatum sd = null;

                if ((labelSelectionMethod & IMGDB_LABEL_SELECTION_METHOD.RANDOM) == IMGDB_LABEL_SELECTION_METHOD.RANDOM)
                {
                    if (m_rgLabelSet.Count == 0)
                    {
                        throw new Exception("There are no label specified in the Labels table for the dataset '" + m_src.Name + "'!");
                    }

                    LabelSet labelSet = getLabelSet(labelSelectionMethod);
                    sd = labelSet.GetImage(nIdx, imageSelectionMethod);
                }

                int nImageIdx = 0;

                if (sd == null)
                {
                    sd = LabelSet.GetImage(rgImages, rgImages.Length, nIdx, m_random, imageSelectionMethod, ref m_nLastIdx, ref m_nFixedIndex, out nImageIdx);
                }


                //-----------------------------------------
                //  Handle dynamic loading of the image.
                //-----------------------------------------

                bool bRawDataLoaded = false;

                if (sd == null)
                {
                    int nRetries = 1;

                    if ((imageSelectionMethod & IMGDB_IMAGE_SELECTION_METHOD.RANDOM) == IMGDB_IMAGE_SELECTION_METHOD.RANDOM)
                    {
                        nRetries = 5;
                    }

                    for (int i = 0; i < nRetries; i++)
                    {
                        sd = m_factory.LoadImageAt(nImageIdx, bLoadDataCriteria, bLoadDebugData);
                        if (sd != null)
                        {
                            bRawDataLoaded = true;
                            Add(nImageIdx, sd);
                            break;
                        }

                        if (i < nRetries - 1)
                        {
                            nImageIdx = m_random.Next(rgImages.Length);
                        }
                    }

                    if (sd == null)
                    {
                        log.WriteLine("WARNING! The dataset needs to be re-indexed. Could not find the image at index " + nImageIdx.ToString() + " - attempting several random queries to get an image.");
                    }
                }

                if (!bRawDataLoaded)
                {
                    m_factory.LoadRawData(sd, bLoadDebugData, bLoadDataCriteria);
                }

                return(sd);
            }
        }