Ejemplo n.º 1
0
void FileSystemOperator::LoadPreSavedContents() {
  struct dirent *entry;
  DIR *directory_handler = opendir(target_directory_path_.c_str());

  // Load all annotation file data in the specified directory
  while ((entry = readdir(directory_handler)) != NULL) {
    // Get entry's status (file name, permission...etc)
    struct stat status;
    std::string absolute_path = target_directory_path_ + std::string(entry->d_name);

    if (stat(absolute_path.c_str(), &status) == 0 &&
        S_ISREG(status.st_mode)) { // This entry is surely nomal file
      LabelData loaded_data;

      // Open this xml file
      TiXmlDocument xml_document(absolute_path);
      xml_document.LoadFile();

      // Parse its contents and insert into the structure
      TiXmlElement* root = xml_document.FirstChildElement("annotation");

      TiXmlElement* folder = root->FirstChildElement("folder");
      loaded_data.folder_name = std::string(folder->GetText());

      TiXmlElement* file = root->FirstChildElement("filename");
      loaded_data.file_name = std::string(file->GetText());

      TiXmlElement* size = root->FirstChildElement("size");
      TiXmlElement* width = size->FirstChildElement("width");
      TiXmlElement* height = size->FirstChildElement("height");
      TiXmlElement* depth = size->FirstChildElement("depth");
      loaded_data.width = std::atoi(width->GetText());
      loaded_data.height = std::atoi(height->GetText());
      loaded_data.depth = std::atoi(depth->GetText());

      TiXmlElement* object = root->FirstChildElement("object");
      TiXmlElement* name = object->FirstChildElement("name");
      loaded_data.state = static_cast<LightState>(std::atoi(name->GetText()));

      TiXmlElement* bounding_box = object->FirstChildElement("bndbox");
      TiXmlElement* x_min = bounding_box->FirstChildElement("xmin");
      TiXmlElement* y_min = bounding_box->FirstChildElement("ymin");
      TiXmlElement* x_max = bounding_box->FirstChildElement("xmax");
      TiXmlElement* y_max = bounding_box->FirstChildElement("ymax");
      loaded_data.x_start = std::atoi(x_min->GetText());
      loaded_data.y_start = std::atoi(y_min->GetText());
      loaded_data.x_end = std::atoi(x_max->GetText());
      loaded_data.y_end = std::atoi(y_max->GetText());

      // Insert loaded data into list
      int file_id = GetFileIDFromFilePath(entry->d_name);
      label_data_list_[file_id] = loaded_data;
    }
  }
}
Ejemplo n.º 2
0
void Plugin::loadCurrentProgramXml(File* file)
{
    //load program from file
    XmlDocument xml_document(*file);
    XmlElement* xml_state = xml_document.getDocumentElement();
    if (xml_state != 0) {
        program_bank->loadProgramFromXml(current_program, xml_state);
        setCurrentProgram(current_program);
        delete xml_state;
        editor_program_update_pending = true;
    }
}
Ejemplo n.º 3
0
int main(int argc, char* argv[])
{
  boost::filesystem::path ncl_file;
  {
    boost::program_options::options_description description
      ("Allowed options");
    description.add_options()
      ("help", "produce this help message")
      ("ncl", boost::program_options::value<std::string>(), "NCL file to play");

    boost::program_options::variables_map vm;
    boost::program_options::store(boost::program_options::parse_command_line(argc, argv, description), vm);
    boost::program_options::notify(vm);

    if(vm.count("help"))
    {
      std::cout << description << std::endl;
      return 1;
    }

    if(vm.count("ncl"))
      ncl_file = vm["ncl"].as<std::string>();
    else
    {
      std::cout << description << std::endl;
      return 1;
    }
  }
    
  if(boost::filesystem::exists(ncl_file))
  {
    ::xmlParserCtxtPtr parser_context = ::xmlNewParserCtxt();
    ::xmlDocPtr xmldoc = ::xmlCtxtReadFile(parser_context, ncl_file.string().c_str(), 0, 0);
    if(!xmldoc)
    {
      std::cout << "File " << ncl_file.string() << " could not be XML parsed" << std::endl;
      return -1;
    }
    
    gntl::parser::libxml2::dom::xml_document xml_document(xmldoc);
    gntl::parser::libxml2::dom::document root_document(xml_document.root());
    print_media_sources(root_document);
  }
  else
  {
    std::cout << "File " << ncl_file.string() << " could not be found" << std::endl;
    return -1;
  }  
}