void ImageStackDirectoryDatasource::readMetaDataFile(boost::filesystem::path metaDataFileName)
    {
        boost::property_tree::ptree xmlTree;
        read_xml(metaDataFileName.string(), xmlTree);
        std::vector<ImageLocation> tempImageLocations;
        std::vector<MetaDataNode> tempProjectionProperties;
        for(auto it = xmlTree.begin(); it != xmlTree.end(); ++it)
        {
            if(it->first == "projection")
            {
                std::string filename = it->second.get_child("image").get<std::string>("<xmlattr>.filename");
                tempImageLocations.push_back(ImageLocation(filename));
                auto props = this->parseProjectionProperties(it->second);
                props.nodename = it->first;
                tempProjectionProperties.push_back(props);
            }
            if(it->first == "projectionstack")
            {
                auto props = this->parseProjectionProperties(it->second);
                props.nodename = it->first;
                std::string filename = it->second.get_child("image").get<std::string>("<xmlattr>.filename");
                unsigned int numberOfImages = ImageDeserializer::getNumberOfImagesInStack((directory / filename).string());
                for(unsigned int i = 0; i < numberOfImages; i++)
                {
                    tempImageLocations.push_back(ImageLocation(filename, i));
                    tempProjectionProperties.push_back(props);
                }
            }
        }
        std::unordered_map<float, unsigned int> tiltAngleToIndex;
        std::unordered_map<float, unsigned int> tiltAngleProjectionCount;
        for(unsigned int i = 0; i < tempProjectionProperties.size(); ++i)
        {
            
            float tiltAngle = tempProjectionProperties[i].tiltAngle;
            auto findIt = tiltAngleToIndex.find(tiltAngle);
            if(findIt == tiltAngleToIndex.end())
            {
                // Without the temporary variable, there seems to be a memory corruption on linux,
                // but I did not find the real cause
                unsigned int currentIndex = (unsigned int)tiltAngleToIndex.size();
                tiltAngleToIndex[tiltAngle] = currentIndex;
                tiltAngleProjectionCount[tiltAngle] = 0;
            }
            HyperStackIndex index(tiltAngleToIndex[tiltAngle], tiltAngleProjectionCount[tiltAngle]++);
            imageLocations[index] = tempImageLocations[i];
            metaDataNodes[index] = tempProjectionProperties[i];
        }

        if(this->isEveryTiltAngleUnique())
        {
            this->convertToOneDimension();
            this->resolution = this->getProjectionImage(HyperStackIndex(0))->getResolution();
        }
        else
        {
            this->resolution = this->getProjectionImage(HyperStackIndex(0, 0))->getResolution();
        }

        auto baseScannerGeometry = createScannerGeometry( xmlTree.get_child("geometry") );
        this->satRotator.setBaseScannerGeometry(baseScannerGeometry);
    }
Example #2
0
void SceneImporter::load(const std::string& filename)
{
	read_xml(filename, pt);
}
Example #3
0
//parse the RSS feed which is xml, get each items, generate element for new item and insert into elementList
void RssStreamInput::generateElementByRss(std::string& rssXmlContent)
{
	boost::property_tree::ptree pt;  
	stringstream ss; 
	ss << rssXmlContent;
	read_xml(ss, pt);
	boost::property_tree::ptree channelPt;
	channelPt = pt.get_child("rss.channel");
	std::string linkurl = channelPt.get_child("link").data();
	
	std::vector<std::string> titleVector; // save the titles in the RSS feed page
	std::vector<std::string> linkVector;  // save the links in the RSS feed page
	
	//mark if the newest title we processed is still in this RSS feed page  
	bool isProcessedNewestTitleStillInThisPage = false;

	std::string processedNewestTitle;
	std::map<std::string, std::string >::iterator it = this->urlTitleMap.find(linkurl);
	if(it != this->urlTitleMap.end())
	{
		processedNewestTitle = it->second;
	}
	else
	{
		processedNewestTitle = "";
	}

	BOOST_FOREACH(boost::property_tree::ptree::value_type &v1, channelPt)
	{
		if(v1.first=="item")
		{
			
			boost::property_tree::ptree itemPt = v1.second;
			//get the title and link for each item
			std::string title;
			std::string link;
			title = itemPt.get_child("title").data();
			link = itemPt.get_child("link").data();
			//save title and link 
			titleVector.push_back(title);
			linkVector.push_back(link);
			//see if any exists
			if(processedNewestTitle == title)
			{
				isProcessedNewestTitleStillInThisPage = true;
			}
		}
	}
	//if new titles exist, generate corresponding elements
	if(isProcessedNewestTitleStillInThisPage == false)
	{//no title has been processed, generate element for each one
		int number = titleVector.size();
		for( int i = number-1; i >=0 ; i--)//reverse scan, we scan from the oldest to the newest
		{
			std::string title = titleVector[i];
			std::string link = linkVector[i];
			DocumentBuilder builder;
			builder.append("title",title);
			builder.append("link",link);
			Document document = builder.obj();
			Element element;
			element.document = document;
			element.id = DocumentIdentifierGenerator::generateNewDocumentIdentifier();
			element.timestamp = TimestampGenerator::getCurrentTime();
			this->rssElementList.push_back(element);
		}
	}
	else
	{//we have processed some titles in this page, generate element for the new titles
		int number = titleVector.size();
		bool isProccesdNewsetTitleMeet = false;
		for( int i = number-1; i >=0 ; i--)//reverse scan, we scan from the oldest to the newest
		{
			std::string title = titleVector[i];
			std::string link = linkVector[i];
			if(isProccesdNewsetTitleMeet == true)
			{// during the scan of the titles from the oldest to the newest, the one which we have processed before is passed
			 // then the titles after are all new titles, we should generate element for them each.
				DocumentBuilder builder;
				builder.append("title",title);
				builder.append("link",link);
				Document document = builder.obj();
				Element element;
				element.document = document;
				element.id = DocumentIdentifierGenerator::generateNewDocumentIdentifier();
				element.timestamp = TimestampGenerator::getCurrentTime();
				element.masterTag = false;
				this->rssElementList.push_back(element);
			}
		
			if(title == processedNewestTitle)
			{
				isProccesdNewsetTitleMeet = true;
			}
		}
	}
	//update processedNewestTitle
	if(this->urlTitleMap[linkurl] != titleVector.front())
	{
		this->urlTitleMap[linkurl] = titleVector.front();
		isUrlTitleMapValueChanged = true;
	}
	
}
Example #4
0
void
pcl::gpu::people::PersonAttribs::readPersonXMLConfig (std::istream& is)
{
  boost::property_tree::ptree pt;
  read_xml(is,pt);
}
Example #5
0
    }

    return result;
}

header_buffer_type read_xml(const char* test_id) {
    std::string input = read_file(test_id);
    return parse_xml(input);
}

// =============================================

TEST_CASE("Reading OSM XML 100") {

    SECTION("Direct") {
        header_buffer_type r = read_xml("100-correct_but_no_data");

        REQUIRE(r.header.get("generator") == "testdata");
        REQUIRE(0 == r.buffer.committed());
        REQUIRE(! r.buffer);
    }

    SECTION("Using Reader") {
        osmium::io::Reader reader{filename("100-correct_but_no_data")};

        const osmium::io::Header header{reader.header()};
        REQUIRE(header.get("generator") == "testdata");

        osmium::memory::Buffer buffer = reader.read();
        REQUIRE(0 == buffer.committed());
        REQUIRE(! buffer);
Example #6
0
void PluginManager::init() {
  static const std::string plugin_config_file("./plugins.xml");
  std::string current_path = directory_conf();

  std::string full_path = current_path + "/" + plugin_config_file;

  BOOST_LOG_TRIVIAL(trace) << "Loading plugin configuration file from "
                           << full_path;
  try {
    read_xml(full_path, _pt);
  } catch (...) {
    BOOST_LOG_TRIVIAL(error) << "Can not load configuration file from "
                             << full_path;
    return;
  }

  // iterate configuration for configured plugins
  BOOST_LOG_TRIVIAL(trace) << "Target load plugins...";
  for (pt::ptree::value_type &node : _pt.get_child("plugins")) {
    if (node.first == "plugin") {
      std::string name(node.second.get<std::string>("name"));
      std::string path(current_path + "/" +
                       node.second.get<std::string>("path"));
      BOOST_LOG_TRIVIAL(trace) << "Module Name: " << name
                               << " Module Path: " << path;

      SharedLibrary libHandle(path, name);
      BOOST_LOG_TRIVIAL(trace) << "Loading library " << libHandle.GetFilePath();

      try {
        libHandle.Load();
      } catch (...) {
        BOOST_LOG_TRIVIAL(error) << "Error when loading plugin library " << path
                                 << name;
      }
    }
  }

  // iterate to every module and get service references
  std::vector<Module *> modules = ModuleRegistry::GetModules();

  BOOST_LOG_TRIVIAL(trace) << "Print existing plugins... ";
  for (Module *module : modules) {
    BOOST_LOG_TRIVIAL(trace)
        << "Module Name: " << module->GetName()
        << " Module ID: " << module->GetModuleId()
        << " Status: " << (module->IsLoaded() ? "LOADED" : "UNLOADED");

    if (module->IsLoaded()) {
      ModuleContext *context = module->GetModuleContext();
      std::vector<ServiceReference<IoTInfoProvider>> services =
          context->GetServiceReferences<IoTInfoProvider>(
              "(type=IoTInfoProvider)");

      BOOST_LOG_TRIVIAL(trace) << "Find  " << services.size()
                               << " provider references";
      for (ServiceReference<IoTInfoProvider> &value : services) {
        IoTInfoProvider *provider = context->GetService<IoTInfoProvider>(value);
        if (std::find(this->begin(), this->end(), provider) == this->end()) {
          this->push_back(provider);
        }
      }
    }
  }

  BOOST_LOG_TRIVIAL(trace) << "Total " << this->size() << " providers loaded";
}
Example #7
0
static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )

{
        int error = 0;
	/* Obtain properties of frame */
	mlt_properties properties = MLT_FRAME_PROPERTIES( frame );

	/* Obtain the producer for this frame */
	producer_ktitle self = mlt_properties_get_data( properties, "producer_kdenlivetitle", NULL );
	
	/* Obtain properties of producer */
	mlt_producer producer = &self->parent;
	mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
	
	if ( mlt_properties_get_int( properties, "rescale_width" ) > 0 )
		*width = mlt_properties_get_int( properties, "rescale_width" );
	if ( mlt_properties_get_int( properties, "rescale_height" ) > 0 )
		*height = mlt_properties_get_int( properties, "rescale_height" );
	
	mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) );

	/* Allocate the image */
	if ( mlt_properties_get_int( producer_props, "force_reload" ) ) {
		if ( mlt_properties_get_int( producer_props, "force_reload" ) > 1 ) read_xml( producer_props );
		mlt_properties_set_int( producer_props, "force_reload", 0 );
		drawKdenliveTitle( self, frame, *format, *width, *height, mlt_frame_original_position( frame ), 1 );
	}
	else
	{
		drawKdenliveTitle( self, frame, *format, *width, *height, mlt_frame_original_position( frame ), 0 );
	}
	// Get width and height (may have changed during the refresh)
	*width = mlt_properties_get_int( properties, "width" );
	*height = mlt_properties_get_int( properties, "height" );
	*format = self->format;

	if ( self->current_image )
	{
		// Clone the image and the alpha
		int image_size = mlt_image_format_size( self->format, self->current_width, self->current_height, NULL );
		uint8_t *image_copy = mlt_pool_alloc( image_size );
		// We use height-1 because mlt_image_format_size() uses height + 1.
		// XXX Remove -1 when mlt_image_format_size() is changed.
		memcpy( image_copy, self->current_image,
			mlt_image_format_size( self->format, self->current_width, self->current_height - 1, NULL ) );
		// Now update properties so we free the copy after
		mlt_frame_set_image( frame, image_copy, image_size, mlt_pool_release );
		// We're going to pass the copy on
		*buffer = image_copy;

		// Clone the alpha channel
		if ( self->current_alpha )
		{
			image_copy = mlt_pool_alloc( self->current_width * self->current_height );
			memcpy( image_copy, self->current_alpha, self->current_width * self->current_height );
			mlt_frame_set_alpha( frame, image_copy, self->current_width * self->current_height, mlt_pool_release );
		}
	}
	else
	{
		error = 1;
	}

	mlt_service_unlock( MLT_PRODUCER_SERVICE( producer ) );

	return error;
}
int CConfig::loadConfig(const char* filename)
{
  read_xml(filename, pt);
  
  // load tree path
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.treepath")) {
    std::cout << str.get() << std::endl;
    treepath = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load number of tree
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.ntree")) {
    std::cout << integer << std::endl;
    ntrees = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load patch width
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.pwidth")) {
    std::cout << integer << std::endl;
    p_width = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load patch height
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.pheight")) {
    std::cout << integer << std::endl;
    p_height = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load test image path
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.imgpath")) {
    std::cout << str.get() << std::endl;
    impath = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load image name list
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.imgnamelist")) {
    std::cout << str.get() << std::endl;
    imfiles = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load extruct feature flag
  if (boost::optional<bool> boolean
      = pt.get_optional<bool>("root.efeatures")) {
    std::cout << boolean << std::endl;
    xtrFeature = *boolean;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load image scales
  std::cout << "kokomade" << std::endl;
  scales.resize(0);
  BOOST_FOREACH (const boost::property_tree::ptree::value_type& child,
pt.get_child("root.scales")) {
    const float value = boost::lexical_cast<float>(child.second.data());
    scales.push_back(value);
    
    std::cout << value << std::endl;
  }
  for (int i;i < scales.size(); ++i)
    std::cout << i << ": " << scales.at(i) << std::endl;
  float value_temp = 1;
  scales.clear();
  scales.push_back(value_temp);

  ratios.clear();
  ratios.push_back(value_temp);
  ratios.push_back(value_temp);

  // // load image ratios
  ratios.resize(0);
  BOOST_FOREACH (const boost::property_tree::ptree::value_type& child, pt.get_child("root.ratio")) {
    const float value = boost::lexical_cast<float>(child.second.data());
    ratios.push_back(value);
    
    std::cout << value << std::endl;
  }
  for (int i;i < ratios.size(); ++i)
    std::cout << i << ": " << ratios.at(i) << std::endl;

// load output path
if (boost::optional<std::string> str
    = pt.get_optional<std::string>("root.outpath")) {
  std::cout << str.get() << std::endl;
  outpath = *str;
 }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load scale factor for output imae
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.sfactor")) {
    std::cout << integer << std::endl;
    out_scale = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }


  // load training image name list
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.traindataname")) {
    std::cout << str.get() << std::endl;
    traindatafile = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }
  
  // load training image folder
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.trainimgpath")) {
    std::cout << str.get() << std::endl;
    trainpath = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load scale factor for output imae
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.trainimagepertree")) {
    std::cout << integer << std::endl;
    imagePerTree = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }
  
  // load scale factor for output imae
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.minsample")) {
    std::cout << integer << std::endl;
    min_sample = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load scale factor for output imae
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.maxdepth")) {
    std::cout << integer << std::endl;
    max_depth = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }
  
  // load scale factor for output imae
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.featurechannel")) {
    std::cout << integer << std::endl;
    featureChannel = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load scale factor for output imae
  if (boost::optional<double> variableDouble
      = pt.get_optional<double>("root.patchratio")) {
    std::cout << variableDouble << std::endl;
    patchRatio = *variableDouble;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }
  
  // load scale factor for output imae
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.stride")) {
    std::cout << integer << std::endl;
    stride = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load offset of tree name
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.offTree")) {
    std::cout << integer << std::endl;
    off_tree = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load test data folder
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.testpath")) {
    std::cout << str.get() << std::endl;
    testPath = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load test data file name
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.testdataname")) {
    std::cout << str.get() << std::endl;
    testData = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load test data file name
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.classdatabasename")) {
    std::cout << str.get() << std::endl;
    classDatabaseName = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load offset of tree name
  if (boost::optional<int> integer
      = pt.get_optional<int>("root.learningmode")) {
    std::cout << integer << std::endl;
    learningMode = *integer;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load training image name list
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.traindatalistname")) {
    std::cout << str.get() << std::endl;
    traindatalist = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  // load testing image name list
  if (boost::optional<std::string> str
      = pt.get_optional<std::string>("root.testdatalistname")) {
    std::cout << str.get() << std::endl;
    testdatalist = *str;
  }
  else {
    std::cout << "root.str is nothing" << std::endl;
  }

  return 0; 
}
Example #9
0
void read_xml(std::istream & in, PTree & p)
{
	read_xml(in, p, std::string());
}
Example #10
0
File: xml.cpp Project: spolitov/lib
void read_xml(const wchar_t * path, boost::property_tree::wptree & out)
{
    read_xml(boost::filesystem::wpath(path), out);
}
Example #11
0
File: xml.cpp Project: spolitov/lib
void read_xml(const std::wstring & path, boost::property_tree::wptree & out)
{
    read_xml(boost::filesystem::wpath(path), out);
}
Example #12
0
File: xml.cpp Project: spolitov/lib
void read_xml(const boost::filesystem::wpath & path, boost::property_tree::wptree & out)
{
    boost::filesystem::ifstream inp(path, std::ios::binary);
    read_xml(inp, out);
}
/******************************************************************************
MODULE:  generate_stack

PURPOSE:  Generates the CSV stack file for the input list of XML files.

RETURN VALUE:
Type = int
Value           Description
-----           -----------
ERROR           An error occurred during processing of the files
SUCCESS         Processing was successful

PROJECT:  Land Satellites Data System Science Research and Development (LSRD)
at the USGS EROS

HISTORY:
Date          Programmer       Reason
----------    ---------------  -------------------------------------
03/12/2014    Gail Schmidt     Original Development

NOTES:
******************************************************************************/
int main (int argc, char *argv[])
{
    bool verbose;              /* verbose flag for printing messages */
    char FUNC_NAME[] = "main"; /* function name */
    char errmsg[STR_SIZE];     /* error message */
    char **xml_infile = NULL; /* array to hold list of input XML filenames */
    char *list_infile=NULL;    /* file containing the temporal list of
                                  reflectance products to be processed */
    char *stack_file=NULL;     /* output CSV file for the XML stack */

    int i;                     /* looping variable */
    int retval;                /* return status */
    int curr_line;             /* counter of the current line */
    int nlines;                /* number of lines in the input temporal list */
    int nfiles;                /* number of actual files in the input list */
    int count;                 /* count of items read from file */

    Ba_scene_meta_t scene_meta; /* structure to contain the desired metadata
                                   for the current XML file */
    FILE *list_fptr=NULL;      /* output file pointer for list of files */
    FILE *stack_fptr=NULL;     /* output file pointer for CSV stack */

    printf ("Generating CSV stack file ...\n");

    /* Read the command-line arguments, including the name of the input
       list of files and the output file to write the stack */
    retval = get_args (argc, argv, &list_infile, &stack_file, &verbose);
    if (retval != SUCCESS)
    {   /* get_args already printed the error message */
        exit (ERROR);
    }

    /* Provide user information if verbose is turned on */
    if (verbose)
    {
        printf ("  Input list file: %s\n", list_infile);
        printf ("  Output stack file: %s\n", stack_file);
    }

    /* Open the input list of reflectance files */
    list_fptr = fopen (list_infile, "r");
    if (list_fptr == NULL)
    {
        sprintf (errmsg, "Unable to open the input temporal list file: %s",
            list_infile);
        error_handler (true, FUNC_NAME, errmsg);
        exit (ERROR);
    }

    /* Determine the maximum number of reflectance files in the input file.
       Note the first scanf grabs lines with text.  If that fails, the second
       scanf grabs empty lines.  We'll count all of them for now and then only
       read the non-empty lines. */
    nlines = 0;
    while (EOF != (fscanf (list_fptr, "%*[^\n]"), fscanf (list_fptr, "%*c"))) 
        nlines++;

    /* Allocate memory for the list of filenames */
    xml_infile = (char **) calloc (nlines, sizeof (char *));
    if (xml_infile != NULL)
    {
        for (i = 0; i < nlines; i++)
        {
            xml_infile[i] = (char *) calloc (STR_SIZE, sizeof (char));
            if (xml_infile[i] == NULL)
            {
                sprintf (errmsg, "Error allocating memory for array of %d "
                    "strings to hold the list of XML filenames.", nlines);
                error_handler (true, FUNC_NAME, errmsg);
                fclose (list_fptr);
                exit (ERROR);
            }
        }
    }
    else
    {
        sprintf (errmsg, "Error allocating memory for array of %d strings "
            "to hold the list of reflectance filenames.", nlines);
        error_handler (true, FUNC_NAME, errmsg);
        fclose (list_fptr);
        exit (ERROR);
    }

    /* Read the list of XML files in the input file */
    rewind (list_fptr);
    curr_line = 0;
    for (i = 0; i < nlines; i++)
    {
        count = fscanf (list_fptr, "%s[^\n]", &xml_infile[curr_line][0]);
        if (count == EOF)
            break;
        else if (count == 0)
        { /* blank line so skip and move to the next; don't count the line */
            fscanf (list_fptr, "%*c");
        }
        else
            curr_line++;
    }

    /* Set the nfiles counter if to the actual number of files in the input
       list; this might be different than the count of lines from earlier */
    nfiles = curr_line;

    /* Close the input file */
    fclose (list_fptr);

    /* Open the output CSV stack file */
    stack_fptr = fopen (stack_file, "w");
    if (stack_fptr == NULL)
    {
        sprintf (errmsg, "Unable to open the output CSV stack file: %s",
            stack_file);
        error_handler (true, FUNC_NAME, errmsg);
        exit (ERROR);
    }

    /* Write the header for the stack file */
    fprintf (stack_fptr, "file, year, season, month, day, julian, path, row, "
        "satellite, west, east, north, south, nrow, ncol, dx, dy, utm_zone\n");

    /* Loop through each of the input files, read the metadata, and write to
       the stack file */
    if (verbose)
        printf ("Input list file contains %d filenames\n", nfiles);
    for (i = 0; i < nfiles; i++)
    {
        if (verbose)
            printf ("\nProcessing current file %d: %s\n", i, xml_infile[i]);

        /* Process the current file */
        retval = read_xml (xml_infile[i], &scene_meta);
        if (retval != SUCCESS)
        {  /* trouble processing this file so skip and go to the next one */
            sprintf (errmsg, "Error processing file %s.  Skipping and moving "
                "to the next file.", xml_infile[i]);
            error_handler (false, FUNC_NAME, errmsg);
            continue;
        }

        /* Write the stack information */
        fprintf (stack_fptr, "%s, %d, %s, %d, %d, %d, %d, %d, %s, "
            "%lf, %lf, %lf, %lf, %d, %d, %f, %f, %d\n",
            scene_meta.filename, scene_meta.acq_date.year, scene_meta.season,
            scene_meta.acq_date.month, scene_meta.acq_date.day,
            scene_meta.acq_date.doy, scene_meta.wrs_path, scene_meta.wrs_row,
            scene_meta.satellite, scene_meta.bounding_coords[ESPA_WEST],
            scene_meta.bounding_coords[ESPA_EAST],
            scene_meta.bounding_coords[ESPA_NORTH],
            scene_meta.bounding_coords[ESPA_SOUTH],
            scene_meta.nlines, scene_meta.nsamps,
            scene_meta.pixel_size[0], scene_meta.pixel_size[1],
            scene_meta.utm_zone);
    }

    /* Close the output files */
    fclose (stack_fptr);

    /* Free the filename pointers */
    for (i = 0; i < nlines; i++)
        free (xml_infile[i]);
    free (xml_infile);

    free (list_infile);
    free (stack_file);

    /* Indicate successful completion of processing */
    printf ("Stack file generation complete!\n");
    exit (SUCCESS);
}
Example #14
0
int main (int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd("Postp-process results of the LIE approach",
                       ' ', "0.1");
    TCLAP::ValueArg<std::string> arg_out_pvd("o", "output-file",
                                          "the name of the new PVD file", true,
                                          "", "path");
    cmd.add(arg_out_pvd);
    TCLAP::ValueArg<std::string> arg_in_pvd("i", "input-file",
                                         "the original PVD file name", true,
                                         "", "path");
    cmd.add(arg_in_pvd);

    cmd.parse(argc, argv);

    auto const in_pvd_filename = arg_in_pvd.getValue();
    auto const in_pvd_file_dir = BaseLib::extractPath(in_pvd_filename);
    auto const out_pvd_filename = arg_out_pvd.getValue();
    auto const out_pvd_file_dir = BaseLib::extractPath(out_pvd_filename);
    INFO("start reading the PVD file %s", in_pvd_filename.c_str());
    boost::property_tree::ptree pt;
    read_xml(arg_in_pvd.getValue(), pt,  boost::property_tree::xml_parser::trim_whitespace);

    for (auto& dataset : pt.get_child("VTKFile.Collection"))
    {
        if (dataset.first != "DataSet")
            continue;

        // read VTU with simulation results
        auto const org_vtu_filename = dataset.second.get<std::string>("<xmlattr>.file");
        INFO("processing %s...", (in_pvd_file_dir + org_vtu_filename).c_str());

        std::unique_ptr<MeshLib::Mesh const> mesh(
            MeshLib::IO::readMeshFromFile(in_pvd_file_dir + org_vtu_filename));

        // post-process
        std::vector<MeshLib::Element*> vec_matrix_elements;
        std::vector<int> vec_fracture_mat_IDs;
        std::vector<std::vector<MeshLib::Element*>> vec_fracture_elements;
        std::vector<std::vector<MeshLib::Element*>> vec_fracture_matrix_elements;
        std::vector<std::vector<MeshLib::Node*>> vec_fracture_nodes;
        ProcessLib::LIE::getFractureMatrixDataInMesh(
            *mesh, vec_matrix_elements, vec_fracture_mat_IDs, vec_fracture_elements,
            vec_fracture_matrix_elements, vec_fracture_nodes);

        ProcessLib::LIE::PostProcessTool post(
            *mesh, vec_fracture_nodes, vec_fracture_matrix_elements);

        // create a new VTU file and update XML
        auto const dest_vtu_filename = "post_" + org_vtu_filename;
        INFO("create %s", (out_pvd_file_dir + dest_vtu_filename).c_str());
        MeshLib::IO::writeMeshToFile(post.getOutputMesh(), out_pvd_file_dir + dest_vtu_filename);

        dataset.second.put("<xmlattr>.file", dest_vtu_filename);
    }

    // save into the new PVD file
    INFO("save into the new PVD file %s", out_pvd_filename.c_str());
    boost::property_tree::xml_writer_settings<std::string> settings('\t', 1);
    write_xml(arg_out_pvd.getValue(), pt, std::locale(), settings);

    return EXIT_SUCCESS;
}