bool indri::index::DiskKeyfileVocabularyIterator::nextEntry(const char *skipTo) {

  assert(skipTo!=NULL);

  if (_justStartedIteration) {
    // position the iterator at the first
    // item that matches...
    _justStartedIteration=false;

    // get an iterator to the first term here
    indri::file::BulkTreeIterator *findIterator=_bulkTree.findFirst(skipTo);
    if (!findIterator) return false;

    // replace the current iterator with the new one
    if (_bulkIterator) delete _bulkIterator;
    _bulkIterator=findIterator;
    if (!_readData()) return false;

  } else {
    // get the next item...
    // assume all items w/ the same prefix are clumped together
    _bulkIterator->nextEntry();
    if (!_readData()) return false;
  }

  // make sure we're not at the end
  if (_bulkIterator->finished()) {
    return false;
  }

  // get the current entry
  indri::index::DiskTermData* thisEntry=currentEntry();
  if (!thisEntry) return false;

  // make sure we're still in the patten
  if (strstr(thisEntry->termData->term, skipTo)==thisEntry->termData->term) {
    return true;
  }

  // just to be certain - check the next entry...
  // read the next item...
  _bulkIterator->nextEntry();
  if (!_readData()) return false;
        
  // ensure we're not finished
  if (_bulkIterator->finished()) return false;

  // get the next entry...
  thisEntry=currentEntry();
  if (!thisEntry) return false;

  // check it.
  if (strstr(thisEntry->termData->term, skipTo)==thisEntry->termData->term) {
    return true;
  }

  // ok - I'm satisfied that we're done...
  return false;
}
Exemplo n.º 2
0
QStringList QZipFile::filenames()
{
    QStringList result;
    gotoFirstEntry();
    do {
        QZipFileEntry info = currentEntry();
        if (info.isValid())
            result << info.name();
    } while (nextEntry());

    return result;
}
const BundleDescriptorReader::BundleContainer BundleDescriptorReader::createBundles(const ::boost::filesystem::path& location) throw(RuntimeException)
{
    // Normalizes the path.
    ::boost::filesystem::path normalizedPath(location);
    normalizedPath.normalize();

    // Asserts that the repository is a valid directory path.
    if(::boost::filesystem::exists(normalizedPath) == false || ::boost::filesystem::is_directory(normalizedPath) == false)
    {
        throw RuntimeException("'" + normalizedPath.string() + "': not a directory.");
    }

    // Walk through the repository entries.
    BundleContainer bundles;
    ::boost::filesystem::directory_iterator   currentEntry(normalizedPath);
    ::boost::filesystem::directory_iterator   endEntry;
    for(; currentEntry != endEntry; ++currentEntry)
    {
        ::boost::filesystem::path entryPath = *currentEntry;

        if(::boost::filesystem::is_directory(entryPath))
        {
            try
            {
                SPTR( ::fwRuntime::Bundle ) bundle = BundleDescriptorReader::createBundle(entryPath);
                if(bundle)
                {
                    bundles.push_back( bundle );
                }
            }
            catch(const RuntimeException& runtimeException)
            {
                OSLM_INFO( "'"<< entryPath.string() << "': skipped. " << runtimeException.what() );
            }
        }
    }
    return bundles;
}
void ImagePositionPatientSorterTest::simpleApplication()
{
    ::fwMedData::SeriesDB::sptr seriesDB = ::fwMedData::SeriesDB::New();

    const std::string filename           = "01-CT-DICOM_LIVER";
    const ::boost::filesystem::path path = ::fwTest::Data::dir() / "fw4spl/Patient/Dicom/DicomDB" / filename;

    CPPUNIT_ASSERT_MESSAGE("The dicom directory '" + path.string() + "' does not exist",
                           ::boost::filesystem::exists(path));

    // Read DicomSeries
    ::fwGdcmIO::reader::SeriesDB::sptr reader = ::fwGdcmIO::reader::SeriesDB::New();
    reader->setObject(seriesDB);
    reader->setFolder(path);
    CPPUNIT_ASSERT_NO_THROW(reader->readDicomSeries());
    CPPUNIT_ASSERT_EQUAL(size_t(1), seriesDB->size());

    // Retrieve DicomSeries
    ::fwMedData::DicomSeries::sptr dicomSeries = ::fwMedData::DicomSeries::dynamicCast((*seriesDB)[0]);
    CPPUNIT_ASSERT(dicomSeries);
    std::vector< ::fwMedData::DicomSeries::sptr > dicomSeriesContainer;
    dicomSeriesContainer.push_back(dicomSeries);

    // Apply filter
    ::fwDicomIOFilter::IFilter::sptr filter = ::fwDicomIOFilter::factory::New(
        "::fwDicomIOFilter::sorter::ImagePositionPatientSorter");
    CPPUNIT_ASSERT(filter);
    ::fwDicomIOFilter::helper::Filter::applyFilter(dicomSeriesContainer, filter, true);
    CPPUNIT_ASSERT_EQUAL(size_t(1), dicomSeriesContainer.size());
    dicomSeries = dicomSeriesContainer[0];

    // Create the list of files
    std::vector< std::string > filenames;
    ::boost::filesystem::directory_iterator currentEntry(path);
    ::boost::filesystem::directory_iterator endEntry;
    for(; currentEntry != endEntry; ++currentEntry)
    {
        const ::boost::filesystem::path entryPath = *currentEntry;
        if (::boost::filesystem::is_regular_file(entryPath))
        {
            filenames.push_back(entryPath.string());
        }
    }

    // Read the instance number of each file
    ::gdcm::Scanner scanner;
    scanner.AddTag(::gdcm::Tag(0x0020, 0x0032));    // ImagePositionPatient
    scanner.AddTag(::gdcm::Tag(0x0020, 0x0037));    // ImageOrientationPatient
    CPPUNIT_ASSERT(scanner.Scan(filenames));

    // Loop through instance number
    ::gdcm::Directory::FilenamesType keys = scanner.GetKeys();
    ::gdcm::Directory::FilenamesType::const_iterator itFilename;
    double oldPosition = -1;
    for(itFilename = keys.begin(); itFilename != keys.end(); ++itFilename)
    {
        const std::string filename = itFilename->c_str();

        // Retrieve image position patient
        std::string imagePositionPatientStr = scanner.GetValue(filename.c_str(), ::gdcm::Tag(0x0020, 0x0032));
        ::boost::algorithm::trim(imagePositionPatientStr);
        CPPUNIT_ASSERT(!imagePositionPatientStr.empty());
        std::vector<std::string> imagePositionPatient;
        ::boost::split(imagePositionPatient, imagePositionPatientStr, ::boost::is_any_of("\\"));
        CPPUNIT_ASSERT_EQUAL(size_t(3), imagePositionPatient.size());

        // Retrieve image orientation patient
        std::string imageOrientationPatientStr = scanner.GetValue(filename.c_str(), ::gdcm::Tag(0x0020, 0x0037));
        ::boost::algorithm::trim(imageOrientationPatientStr);
        CPPUNIT_ASSERT(!imagePositionPatientStr.empty());
        std::vector<std::string> imageOrientationPatient;
        ::boost::split(imageOrientationPatient, imageOrientationPatientStr, ::boost::is_any_of("\\"));
        CPPUNIT_ASSERT_EQUAL(size_t(6), imageOrientationPatient.size());

        fwVec3d imagePosition;
        imagePosition[0] = ::boost::lexical_cast<double>(imagePositionPatient[0]);
        imagePosition[1] = ::boost::lexical_cast<double>(imagePositionPatient[1]);
        imagePosition[2] = ::boost::lexical_cast<double>(imagePositionPatient[2]);

        fwVec3d imageOrientationU;
        imageOrientationU[0] = ::boost::lexical_cast<double>(imageOrientationPatient[0]);
        imageOrientationU[1] = ::boost::lexical_cast<double>(imageOrientationPatient[1]);
        imageOrientationU[2] = ::boost::lexical_cast<double>(imageOrientationPatient[2]);

        fwVec3d imageOrientationV;
        imageOrientationV[0] = ::boost::lexical_cast<double>(imageOrientationPatient[3]);
        imageOrientationV[1] = ::boost::lexical_cast<double>(imageOrientationPatient[4]);
        imageOrientationV[2] = ::boost::lexical_cast<double>(imageOrientationPatient[5]);

        //Compute Z direction (cross product)
        fwVec3d zVector = ::fwMath::cross(imageOrientationU, imageOrientationV);

        //Compute dot product to get the position
        double position = ::fwMath::dot(imagePosition, zVector);

        // Check that the position is bigger that the previous one
        std::stringstream ss;
        ss << position << " is not lower than " << oldPosition;
        CPPUNIT_ASSERT_MESSAGE(ss.str(), position > oldPosition);
        oldPosition = position;
    }
}