Ejemplo n.º 1
0
	FileWatcher::FailedToWatchFileException::FailedToWatchFileException(const boost::filesystem::path& path, const std::string& why)
		: std::runtime_error("FailedToWatchFile: " + path.string() + " Why: " + why)
	{}
Ejemplo n.º 2
0
Bundle2::Bundle2(const boost::filesystem::path& fileName, bool loadGeometry):
	version_(BUNDLE_VERSION), poiFirstFrame_(0) {
	// Opening file
	H5::H5File bundleFile;
	bundleFile.openFile(fileName.string(), H5F_ACC_RDONLY);
	loadParameters(bundleFile);

	// Loading POI
	H5::Group poiGroup = bundleFile.openGroup("/POI");

	hsize_t count;
	H5::Attribute attr = poiGroup.openAttribute("count");
	attr.read(H5::PredType::NATIVE_HSIZE, &count);
	attr.close();

	for(size_t frame = 0; frame < count; ++frame) {
		cout.flush();

		const std::string frameGroupName = boost::str(boost::format("Frame %1$04d") % frame);
		H5::Group frameGroup = poiGroup.openGroup(frameGroupName);

		addPOIFrame();
		for(size_t camera = 0; camera < numCameras_; ++camera)
			poi_[poi_.size() - 1][camera].load(frameGroup, camera);

		frameGroup.close();
	}

	poiGroup.close();

	// Loading frames
	H5::Group bundleGroup = bundleFile.openGroup("/Bundle");

	H5::Group framesGroup = bundleGroup.openGroup("Frames");

	attr = framesGroup.openAttribute("count");
	attr.read(H5::PredType::NATIVE_HSIZE, &count);
	attr.close();

	for(size_t frame = 0; frame < count; ++frame) {
		Frame* f = new Frame(framesGroup, frame, numCameras_);
		frames_.push_back(f);
	}

	framesGroup.close();

	// Loading tracks
	H5::DataSet tracksDataset = bundleGroup.openDataSet("Tracks");

	hsize_t tracksDim[2];
	H5::DataSpace tracksDS = tracksDataset.getSpace();
	tracksDS.getSimpleExtentDims(tracksDim);
	tracksDS.close();

	for(size_t i = 0; i < tracksDim[0]; ++i) {
		size_t j = addTrack();
		tracks_[j]->load(tracksDataset, frames_, i);
	}

	tracksDataset.close();

	bundleGroup.close();

	if(loadGeometry && checkGeometry_(bundleFile)) loadGeometry_(bundleFile);

	bundleFile.close();
}
Ejemplo n.º 3
0
		static evaluation parse(const boost::filesystem::path& p)
		{
			evaluation e = parse_filename(p.filename().string());
			parse_file(e, p.string());
			return e;
		}
Ejemplo n.º 4
0
void OMW::Engine::addZipResource (const boost::filesystem::path& path)
{
    mOgre->getRoot()->addResourceLocation (path.string(), "Zip",
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, false);
}
Ejemplo n.º 5
0
QString boostPathToQString(const boost::filesystem::path &path)
{
    return QString::fromStdString(path.string());
}
void SaveOpticalFlowMap( boost::filesystem::path opticalFlowMapPath, cv::Mat opticalFlowMap )
{
    std::ofstream file( opticalFlowMapPath.native_file_string().c_str(), std::ios::binary );
    file.write( (char*)opticalFlowMap.data, opticalFlowMap.rows * opticalFlowMap.cols * sizeof( cv::Vec2f ) );
    file.close();
}
Ejemplo n.º 7
0
inline const std::string as_string(const boost::filesystem::path & path) {
	return path.string();
}
Ejemplo n.º 8
0
 BufferBuilder::BufferBuilder(boost::filesystem::path& file, size_t fileSize, unsigned int bufferCount, size_t cacheSize) :
 STR_FILE(file.string()), FILE_SIZE(fileSize), BUFFER_COUNT(bufferCount), CACHE_SIZE(cacheSize)
 { }
Ejemplo n.º 9
0
void
archive_t::deploy(const fs::path& prefix) {
    archive * target = archive_write_disk_new();
    archive_entry * entry = NULL;

    int rv = ARCHIVE_OK;

    int flags = ARCHIVE_EXTRACT_TIME |
                ARCHIVE_EXTRACT_PERM |
                ARCHIVE_EXTRACT_ACL |
                ARCHIVE_EXTRACT_FFLAGS |
                ARCHIVE_EXTRACT_SECURE_NODOTDOT;

    archive_write_disk_set_options(target, flags);
    archive_write_disk_set_standard_lookup(target);
    
    while(true) {
        rv = archive_read_next_header(m_archive, &entry);
        
        if(rv == ARCHIVE_EOF) {
            break;
        } else if(rv != ARCHIVE_OK) {
            throw archive_error_t(m_archive);
        }

        fs::path path = archive_entry_pathname(entry);

        // NOTE: Prepend the target path to the stored file path
        // in order to unpack it into the right place.
        archive_entry_set_pathname(entry, (prefix / path).string().c_str());

        rv = archive_write_header(target, entry);
        
        if(rv != ARCHIVE_OK) {
            throw archive_error_t(target);
        } else if(archive_entry_size(entry) > 0) {
            extract(m_archive, target);
        }
    }

    rv = archive_write_finish_entry(target);

    if(rv != ARCHIVE_OK) {
        throw archive_error_t(target);
    }

    // NOTE: The reported count is off by one for some reason.
    size_t count = archive_file_count(m_archive) - 1;

    COCAINE_LOG_INFO(
        m_log,
        "archive type: %s, extracted %d %s to '%s'",
        type(),
        count,
        count == 1 ? "file" : "files",
        prefix.string()
    );

    archive_write_close(target);
    archive_write_finish(target);
}
Ejemplo n.º 10
0
 NotADirException(const boost::filesystem::path& p)
     : std::runtime_error(p.string() + " Is not a directory") {}
Ejemplo n.º 11
0
void make_cpp_file(const std::string & content, const fs::path & path)
{
    std::ofstream f { path.string() };
    f << content;
}
Ejemplo n.º 12
0
			std::string get_filename() const { return module_.filename().string(); }
Ejemplo n.º 13
0
			LPVOID load_proc(std::string name) {
				if (handle_ == NULL)
					throw dll_exception("Failed to load process since module is not loaded: " + module_.filename().string());
				LPVOID ep = GetProcAddress(handle_, name.c_str());
				return ep;
			}
Ejemplo n.º 14
0
DataFileIndexer::DataFileIndexer(const boost::filesystem::path &data_file, 
								 const unsigned int _events_per_block,
								 const unsigned int multiplication_factor_per_level,
								 const int number_of_indexing_threads) : events_per_block(_events_per_block) {
	uri = "ldobinary:file://" + data_file.string();
	
	// I hate myself for this
	char *uri_temp = new char[uri.length() + 1];
	strncpy(uri_temp, uri.c_str(), uri.length() + 1);
	session = scarab_session_connect(uri_temp);
	delete [] uri_temp;

	
	{
		std::vector<boost::shared_ptr<EventBlock> > event_blocks;
		{
			number_of_events = 0;
			
			std::vector<unsigned int> event_codes_in_block;
			MonkeyWorksTime max_time = MIN_MONKEY_WORKS_TIME();
			MonkeyWorksTime min_time = MAX_MONKEY_WORKS_TIME();
			long int previous_datum_location = scarab_tell(session);
			
			ScarabDatum *datum = NULL;
			while(datum = scarab_read(session)) {
				event_codes_in_block.push_back(DataFileUtilities::getScarabEventCode(datum));
				
				const MonkeyWorksTime event_time = DataFileUtilities::getScarabEventTime(datum);
				max_time = max_time > event_time ? max_time : event_time;
				min_time = min_time < event_time ? min_time : event_time;
				
				number_of_events++; 
				//std::cout << number_of_events << " ";
				
				if(number_of_events % events_per_block == 0) { 
					std::sort(event_codes_in_block.begin(), event_codes_in_block.end());
					event_codes_in_block.erase(std::unique(event_codes_in_block.begin(), 
														   event_codes_in_block.end()), 
											   event_codes_in_block.end());
					std::cout << "indexing block " << event_blocks.size() << " .. time : " << min_time << "LL - " << max_time << "LL" << std::endl;

					//				cerr << "new event block : num events : " << event_codes_in_block.size() << endl;
					boost::shared_ptr<EventBlock> new_event_block = boost::shared_ptr<EventBlock>(new EventBlock(previous_datum_location, min_time, max_time, event_codes_in_block));
					event_blocks.push_back(new_event_block);
					
					event_codes_in_block.clear();
					max_time = MIN_MONKEY_WORKS_TIME();
					min_time = MAX_MONKEY_WORKS_TIME();
					previous_datum_location = scarab_tell(session);
				}			
				scarab_free_datum(datum);
			}
			
			// add in the remainder blocks
			boost::shared_ptr<EventBlock> new_event_block = boost::shared_ptr<EventBlock>(new EventBlock(previous_datum_location, min_time, max_time, event_codes_in_block));
			event_blocks.push_back(new_event_block);
			//std::cout << "size " << event_blocks.size();
			
		}
		
		
		{
			// build the tree
			int events_per_node = events_per_block;
			int number_of_levels = 1;
			while(events_per_node < number_of_events) {
				number_of_levels++;
				events_per_node *= multiplication_factor_per_level;
			}
			
			std::vector <boost::shared_ptr<EventBlock> > blocks_at_next_level = event_blocks;
			for(int i = 1; i < number_of_levels; ++i) {
				std::vector <boost::shared_ptr<EventBlock> > blocks_at_current_level;
				
				std::vector<boost::shared_ptr<EventBlock> >::const_iterator j = blocks_at_next_level.begin();
				while(j != blocks_at_next_level.end()) {
					std::vector <boost::shared_ptr<EventBlock> > children;					
					for(int k = 0; k < multiplication_factor_per_level && j != blocks_at_next_level.end(); ++k) {
						children.push_back(*j);
						++j;
					}
					boost::shared_ptr<EventBlock> new_block = boost::shared_ptr<EventBlock>(new EventBlock(children));
					blocks_at_current_level.push_back(new_block);
				}
				
				blocks_at_next_level = blocks_at_current_level;
			}
			
			if(blocks_at_next_level.size() != 1) {
				//badness
				std::cerr << "something went wrong...please abort and try again" << std::endl;
				throw new std::exception;
			}
			root = blocks_at_next_level.at(0);
		}
	}
}
Ejemplo n.º 15
0
flowcell::Layout FastqFlowcell::createFilteredFlowcell(
    const std::string &tilesFilter,
    const boost::filesystem::path &baseCallsDirectory,
    const bool compressed,
    const unsigned laneNumberMax,
    const unsigned readNameLength,
    std::string useBasesMask,
    const bool allowVariableFastqLength,
    const std::string &seedDescriptor,
    const unsigned seedLength,
    const reference::ReferenceMetadataList &referenceMetadataList,
    unsigned &firstPassSeeds)
{

    FastqPathPairList flowcellFilePaths = findFastqPathPairs(compressed, laneNumberMax, baseCallsDirectory);
    if (flowcellFilePaths.empty())
    {
        const boost::format message = boost::format("\n   *** Could not find any fastq lanes in: %s ***\n") %
            baseCallsDirectory;
        BOOST_THROW_EXCEPTION(common::InvalidOptionException(message.str()));
    }

    FastqFlowcellInfo flowcellInfo = parseFastqFlowcellInfo(flowcellFilePaths, allowVariableFastqLength, readNameLength);

    std::vector<unsigned int> readLengths;
    if (flowcellInfo.readLengths_.first)
    {
        readLengths.push_back(flowcellInfo.readLengths_.first);
    }
    if (flowcellInfo.readLengths_.second)
    {
        readLengths.push_back(flowcellInfo.readLengths_.second);
    }

    if ("default" == useBasesMask)
    {
        if (readLengths.size() == 1)
        {
            useBasesMask = "y*n";
        }
        else if (readLengths.size() == 2)
        {
            useBasesMask = "y*n,y*n";
        }
        else
        {
            const boost::format message =
                boost::format("\n   *** Could not guess the use-bases-mask for '%s', please supply the explicit value ***\n") %
                baseCallsDirectory.string();
            BOOST_THROW_EXCEPTION(common::InvalidOptionException(message.str()));
        }
    }

    std::vector<unsigned int> readFirstCycles;

    ParsedUseBasesMask parsedUseBasesMask;
    alignment::SeedMetadataList seedMetadataList;
    if (!readLengths.empty())
    {
        parsedUseBasesMask = parseUseBasesMask(readFirstCycles, readLengths, seedLength, useBasesMask, baseCallsDirectory);
        seedMetadataList = parseSeedDescriptor(parsedUseBasesMask.dataReads_, seedDescriptor, seedLength, firstPassSeeds);
    }

    flowcell::Layout fc(baseCallsDirectory,
                        flowcell::Layout::Fastq,
                        flowcell::FastqFlowcellData(compressed),
                        laneNumberMax,
                        flowcellInfo.readNameLength_,
                        std::vector<unsigned>(),
                        parsedUseBasesMask.dataReads_,
                        seedMetadataList, flowcellInfo.flowcellId_);

    std::string regexString(tilesFilter);
    std::replace(regexString.begin(), regexString.end(), ',', '|');
    boost::regex re(regexString);
    BOOST_FOREACH(const unsigned int lane, flowcellInfo.getLanes())
    {
        std::string laneString((boost::format("s_%d") % lane).str());
        if (boost::regex_search(laneString, re))
        {
            fc.addTile(lane, 1);
        }
    }

    return fc;
}
void
geoprojectEditMadrid(boost::filesystem::path & geoproj_path, const std::vector<double> & dvs, int seed)
{
    pugi::xml_document doc;
    pugi::xml_parse_result result = doc.load_file(geoproj_path.c_str());
    //// Parameters - Self-Influence Neighbourhood Rules
    // Arable land (Function Class 1)
    // From ARAble land to ARAble land
    double araara1 = dvs[0];
    double araara2 = dvs[1];
    double araara3 = dvs[2];
    // Permanent crops (Function Class 2)
    // From PERmanent crops to PERmanent crops
    double perper1 = dvs[3];
    double perper2 = dvs[4];
    double perper3 = dvs[5];
	// Pastures (Function Class 3)
	// From PAStures to PAStures
	double paspas1 = dvs[6];
	double paspas2 = dvs[7];
	double paspas3 = dvs[8];
    // Agricultural areas (Function Class 4)
    // From AGRicultural areas to AGRicultural areas
    double agragr1 = dvs[9];
    double agragr2 = dvs[10];
    double agragr3 = dvs[11];
    // Residential (Function Class 5)
    // From RESidential to RESidential
    double resres1 = dvs[12];
    double resres2 = dvs[13];
    double resres3 = dvs[14];
    // Industry & commerce (Function class 6)
    // From INDustry & commerce to INDustry & commerce
    double indind1 = dvs[15];
    double indind2 = dvs[16];
    double indind3 = dvs[17];
	// Recreation areas (Function class 7)
	// From RECreation areas to RECreation areas
	double recrec1 = dvs[18];
	double recrec2 = dvs[19];
	double recrec3 = dvs[20];
	// Forest (Function class 8)
	// From FORest to FORest
	double forfor1 = dvs[21];
	double forfor2 = dvs[22];
	double forfor3 = dvs[23];

    //// Parameters - Interaction Neighbourhood Rules
    // Arable land (Function Class 1)
	// From NATural areas to ARAble land
	double natara1 = dvs[24];
	double natara2 = dvs[25];
	double natara3 = dvs[26];
	// From From PERmanent crops to ARAble land
	double perara1 = dvs[27];
	double perara2 = dvs[28];
	double perara3 = dvs[29];
	// From PAStures to ARAble land
	double pasara1 = dvs[30];
	double pasara2 = dvs[31];
	double pasara3 = dvs[32];
    // From AGRicultural areas to ARAble land
	double agrara1 = dvs[33];
	double agrara2 = dvs[34];
	double agrara3 = dvs[35];
	// From RESidential to ARAble land
	double resara1 = dvs[36];
	double resara2 = dvs[37];
	double resara3 = dvs[38];
    // From INDustry & commerce to ARAble land
    double indara1 = dvs[39];
    double indara2 = dvs[40];
    double indara3 = dvs[41];
    // From RECreation areas to ARAble land
    double recara1 = dvs[42];
    double recara2 = dvs[43];
    double recara3 = dvs[44];
    // From FORest to ARAble land
    double forara1 = dvs[45];
    double forara2 = dvs[46];
    double forara3 = dvs[47];
	// From ROAd & rail to ARAble land
	double roaara1 = dvs[48];
	double roaara2 = dvs[49];
	double roaara3 = dvs[50];
	// From PORt area to ARAble land
	double porara1 = dvs[51];
	double porara2 = dvs[52];
	double porara3 = dvs[53];
    // From AIRports to ARAble land
    double airara1 = dvs[54];
    double airara2 = dvs[55];
    double airara3 = dvs[56];
    // From MINe and dump sites to ARAble land
    double minara1 = dvs[57];
    double minara2 = dvs[58];
    double minara3 = dvs[59];
    // From FREsh water to ARAble land
    double freara1 = dvs[60];
    double freara2 = dvs[61];
    double freara3 = dvs[62];
	// From MARine water to ARAble land
	double marara1 = dvs[63];
	double marara2 = dvs[64];
	double marara3 = dvs[65];

    // Permanent crops (Function Class 2)
    // From NATural areas to PERmanent crops
    double natper1 = dvs[66];
    double natper2 = dvs[67];
    double natper3 = dvs[68];
	// From ARAble land to PERmanent crops
	double araper1 = dvs[69];
	double araper2 = dvs[70];
	double araper3 = dvs[71];
	// From PAStures to PERmanent crops
	double pasper1 = dvs[72];
	double pasper2 = dvs[73];
	double pasper3 = dvs[74];
    // From AGRicultural areas to PERmanent crops
    double agrper1 = dvs[75];
    double agrper2 = dvs[76];
    double agrper3 = dvs[77];
	// From RESidential to PERmanent crops
	double resper1 = dvs[78];
	double resper2 = dvs[79];
	double resper3 = dvs[80];
    // From INDustry & commerce to PERmanent crops
    double indper1 = dvs[81];
    double indper2 = dvs[82];
    double indper3 = dvs[83];
    // From RECreation areas to PERmanent crops
    double recper1 = dvs[84];
    double recper2 = dvs[85];
    double recper3 = dvs[86];
    // From FORest to PERmanent crops
    double forper1 = dvs[87];
    double forper2 = dvs[88];
    double forper3 = dvs[89];
	// From ROAd & rail to PERmanent crops
	double roaper1 = dvs[90];
	double roaper2 = dvs[91];
	double roaper3 = dvs[92];
	// From PORt area to PERmanent crops
	double porper1 = dvs[93];
	double porper2 = dvs[94];
	double porper3 = dvs[95];
    // From AIRports to PERmanent crops
    double airper1 = dvs[96];
    double airper2 = dvs[97];
    double airper3 = dvs[98];
    // From MINe & dump sites to PERmanent crops
    double minper1 = dvs[99];
    double minper2 = dvs[100];
    double minper3 = dvs[101];
    // From FREsh water to PERmanent crops
    double freper1 = dvs[102];
    double freper2 = dvs[103];
    double freper3 = dvs[104];
	// From MARine water to PERmanent crops
	double marper1 = dvs[105];
	double marper2 = dvs[106];
	double marper3 = dvs[107];

	// Pastures (Function Class 3)
	// From NATural areas to PAStures
	double natpas1 = dvs[108];
	double natpas2 = dvs[109];
	double natpas3 = dvs[110];
	// From ARAble land to PAStures
	double arapas1 = dvs[111];
	double arapas2 = dvs[112];
	double arapas3 = dvs[113];
	// From PERmanent crops to PAStures
	double perpas1 = dvs[114];
	double perpas2 = dvs[115];
	double perpas3 = dvs[116];
	// From AGRicultural areas to PAStures
	double agrpas1 = dvs[117];
	double agrpas2 = dvs[118];
	double agrpas3 = dvs[119];
	// From RESidential to PAStures
	double respas1 = dvs[120];
	double respas2 = dvs[121];
	double respas3 = dvs[122];
	// From INDustry & commerce to PAStures
	double indpas1 = dvs[123];
	double indpas2 = dvs[124];
	double indpas3 = dvs[125];
	// From RECreation areas to PAStures
	double recpas1 = dvs[126];
	double recpas2 = dvs[127];
	double recpas3 = dvs[128];
	// From FORest to PAStures
	double forpas1 = dvs[129];
	double forpas2 = dvs[130];
	double forpas3 = dvs[131];
	// From ROAd & rail to PAStures
	double roapas1 = dvs[132];
	double roapas2 = dvs[133];
	double roapas3 = dvs[134];
	// From PORt area to PAStures
	double porpas1 = dvs[135];
	double porpas2 = dvs[136];
	double porpas3 = dvs[137];
	// From AIRports to PAStures
	double airpas1 = dvs[138];
	double airpas2 = dvs[139];
	double airpas3 = dvs[140];
	// From MINe & dump sites to PAStures
	double minpas1 = dvs[141];
	double minpas2 = dvs[142];
	double minpas3 = dvs[143];
	// From FREsh water to PAStures
	double frepas1 = dvs[144];
	double frepas2 = dvs[145];
	double frepas3 = dvs[146];
	// From MARine water to PAStures
	double marpas1 = dvs[147];
	double marpas2 = dvs[148];
	double marpas3 = dvs[149];
	
    // Agricultural areas (Function Class 4)
	// From NATural areas to AGRicultural areas
	double natagr1 = dvs[150];
	double natagr2 = dvs[151];
	double natagr3 = dvs[152];
	// From ARAble land to AGRicultural areas
	double araagr1 = dvs[153];
	double araagr2 = dvs[154];
	double araagr3 = dvs[155];
	// From PERmanent crops to AGRicultural areas
	double peragr1 = dvs[156];
	double peragr2 = dvs[157];
	double peragr3 = dvs[158];
    // From PAStures to AGRicultural areas
    double pasagr1 = dvs[159];
    double pasagr2 = dvs[160];
    double pasagr3 = dvs[161];
    // From RESidential to AGRicultural areas
    double resagr1 = dvs[162];
    double resagr2 = dvs[163];
    double resagr3 = dvs[164];
	// From INDustry & commerce to AGRicultural areas
	double indagr1 = dvs[165];
	double indagr2 = dvs[166];
	double indagr3 = dvs[167];
    // From RECreation areas to AGRicultural areas
    double recagr1 = dvs[168];
    double recagr2 = dvs[169];
    double recagr3 = dvs[170];
    // From FORest to AGRicultural areas
    double foragr1 = dvs[171];
    double foragr2 = dvs[172];
    double foragr3 = dvs[173];
	// From ROAd & rail to AGRicultural areas
	double roaagr1 = dvs[174];
	double roaagr2 = dvs[175];
	double roaagr3 = dvs[176];
	// From PORt area to AGRicultural areas
	double poragr1 = dvs[177];
	double poragr2 = dvs[178];
	double poragr3 = dvs[179];
    // From AIRports to AGRicultural areas
    double airagr1 = dvs[180];
    double airagr2 = dvs[181];
    double airagr3 = dvs[182];
    // From MINe & dump sites to AGRicultural areas
    double minagr1 = dvs[183];
    double minagr2 = dvs[184];
    double minagr3 = dvs[185];
    // From FREsh water to AGRicultural areas
    double freagr1 = dvs[186];
    double freagr2 = dvs[187];
    double freagr3 = dvs[188];
	// From MARine water to AGRicultural areas
	double maragr1 = dvs[189];
	double maragr2 = dvs[190];
	double maragr3 = dvs[191];

    // Residential (Function Class 5)
	// From NATural areas to RESidential
	double natres1 = dvs[192];
	double natres2 = dvs[193];
	double natres3 = dvs[194];
	// From ARAble land to RESidential
	double arares1 = dvs[195];
	double arares2 = dvs[196];
	double arares3 = dvs[197];
	// From PERmanent crops to RESidential
	double perres1 = dvs[198];
	double perres2 = dvs[199];
	double perres3 = dvs[200];
    // From PAStures to RESidential
    double pasres1 = dvs[201];
    double pasres2 = dvs[202];
    double pasres3 = dvs[203];
    // From AGRicultural areas to RESidential
    double agrres1 = dvs[204];
    double agrres2 = dvs[205];
    double agrres3 = dvs[206];
	// From INDustry & commerce to RESidential
	double indres1 = dvs[207];
	double indres2 = dvs[208];
	double indres3 = dvs[209];
    // From RECreation areas to RESidential
    double recres1 = dvs[210];
    double recres2 = dvs[211];
    double recres3 = dvs[212];
    // From FORest to RESidential
    double forres1 = dvs[213];
    double forres2 = dvs[214];
    double forres3 = dvs[215];
	// From ROAd & rail to RESidential
	double roares1 = dvs[216];
	double roares2 = dvs[217];
	double roares3 = dvs[218];
	// From PORt area to RESidential
	double porres1 = dvs[219];
	double porres2 = dvs[220];
	double porres3 = dvs[221];
    // From AIRports to RESidential
    double airres1 = dvs[222];
    double airres2 = dvs[223];
    double airres3 = dvs[224];
    // From MINe & dump sites to RESidential
    double minres1 = dvs[225];
    double minres2 = dvs[226];
    double minres3 = dvs[227];
    // From FREsh water to RESidential
    double freres1 = dvs[228];
    double freres2 = dvs[229];
    double freres3 = dvs[230];
	// From MARine water to RESidential
	double marres1 = dvs[231];
	double marres2 = dvs[232];
	double marres3 = dvs[233];

    // Industry & commerce (Function class 6)
	// From NATural areas to INDustry & commerce
	double natind1 = dvs[234];
	double natind2 = dvs[235];
	double natind3 = dvs[236];
	// From ARAble land to INDustry & commerce
	double araind1 = dvs[237];
	double araind2 = dvs[238];
	double araind3 = dvs[239];
	// From PERmanent crops to INDustry & commerce
	double perind1 = dvs[240];
	double perind2 = dvs[241];
	double perind3 = dvs[242];
    // From PAStures to INDustry & commerce
    double pasind1 = dvs[243];
    double pasind2 = dvs[244];
    double pasind3 = dvs[245];
	// From AGRicultural areas to INDustry & commerce
	double agrind1 = dvs[246];
	double agrind2 = dvs[247];
	double agrind3 = dvs[248];
	// From RESidential to INDustry & commerce
	double resind1 = dvs[249];
	double resind2 = dvs[250];
	double resind3 = dvs[251];
    // From RECreation areas to INDustry & commerce
    double recind1 = dvs[252];
    double recind2 = dvs[253];
    double recind3 = dvs[254];
    // From FORest to INDustry & commerce
    double forind1 = dvs[255];
    double forind2 = dvs[256];
    double forind3 = dvs[257];
	// From ROAd & rail to INDustry & commerce
	double roaind1 = dvs[258];
	double roaind2 = dvs[259];
	double roaind3 = dvs[260];
	// From PORt area to INDustry & commerce
	double porind1 = dvs[261];
	double porind2 = dvs[262];
	double porind3 = dvs[263];
    // From AIRports to INDustry & commerce
    double airind1 = dvs[264];
    double airind2 = dvs[265];
    double airind3 = dvs[266];
    // From MINe & dump sites to INDustry & commerce
    double minind1 = dvs[267];
    double minind2 = dvs[268];
    double minind3 = dvs[269];
    // From FREsh water to INDustry & commerce
    double freind1 = dvs[270];
    double freind2 = dvs[271];
    double freind3 = dvs[272];
	// From MARine water to INDustry & commerce
	double marind1 = dvs[273];
	double marind2 = dvs[274];
	double marind3 = dvs[275];

	// Recreation areas (Function class 7)
	// From NATural areas to RECreation areas
	double natrec1 = dvs[276];
	double natrec2 = dvs[277];
	double natrec3 = dvs[278];
	// From ARAble land to RECreation areas
	double ararec1 = dvs[279];
	double ararec2 = dvs[280];
	double ararec3 = dvs[281];
	// From PERmanent crops to RECreation areas
	double perrec1 = dvs[282];
	double perrec2 = dvs[283];
	double perrec3 = dvs[284];
	// From PAStures to RECreation areas
	double pasrec1 = dvs[285];
	double pasrec2 = dvs[286];
	double pasrec3 = dvs[287];
	// From AGRicultural areas to RECreation areas
	double agrrec1 = dvs[288];
	double agrrec2 = dvs[289];
	double agrrec3 = dvs[290];
	// From RESidential to RECreation areas
	double resrec1 = dvs[291];
	double resrec2 = dvs[292];
	double resrec3 = dvs[293];
	// From INDusty & commerce to RECreation areas
	double indrec1 = dvs[294];
	double indrec2 = dvs[295];
	double indrec3 = dvs[296];
	// From FORest to RECreation areas
	double forrec1 = dvs[297];
	double forrec2 = dvs[298];
	double forrec3 = dvs[299];
	// From ROAd & rail to RECreation areas
	double roarec1 = dvs[300];
	double roarec2 = dvs[301];
	double roarec3 = dvs[302];
	// From PORt area to RECreation areas
	double porrec1 = dvs[303];
	double porrec2 = dvs[304];
	double porrec3 = dvs[305];
	// From AIRports to RECreation areas
	double airrec1 = dvs[306];
	double airrec2 = dvs[307];
	double airrec3 = dvs[308];
	// From MINe & dump sites to RECreation areas
	double minrec1 = dvs[309];
	double minrec2 = dvs[310];
	double minrec3 = dvs[311];
	// From FREsh water to RECreation areas
	double frerec1 = dvs[312];
	double frerec2 = dvs[313];
	double frerec3 = dvs[314];
	// From MARine water to RECreation areas
	double marrec1 = dvs[315];
	double marrec2 = dvs[316];
	double marrec3 = dvs[317];

	// Forest (class 8)
	// From NATural areas to FORest
	double natfor1 = dvs[318];
	double natfor2 = dvs[319];
	double natfor3 = dvs[320];
	// From ARAble land to FORest
	double arafor1 = dvs[321];
	double arafor2 = dvs[322];
	double arafor3 = dvs[323];
	// From PERmanent crops to FORest
	double perfor1 = dvs[324];
	double perfor2 = dvs[325];
	double perfor3 = dvs[326];
	// From PAStures to FORest
	double pasfor1 = dvs[327];
	double pasfor2 = dvs[328];
	double pasfor3 = dvs[329];
	// From AGRicultural areas to FORest
	double agrfor1 = dvs[330];
	double agrfor2 = dvs[331];
	double agrfor3 = dvs[332];
	// From RESidential to FORest
	double resfor1 = dvs[333];
	double resfor2 = dvs[334];
	double resfor3 = dvs[335];
	// From INDusty & commerce to FORest
	double indfor1 = dvs[336];
	double indfor2 = dvs[337];
	double indfor3 = dvs[338];
	// From RECreation areas to FORest
	double recfor1 = dvs[339];
	double recfor2 = dvs[340];
	double recfor3 = dvs[341];
	// From ROAd & rail to FORest
	double roafor1 = dvs[342];
	double roafor2 = dvs[343];
	double roafor3 = dvs[344];
	// From PORt area to FORest
	double porfor1 = dvs[345];
	double porfor2 = dvs[346];
	double porfor3 = dvs[347];
	// From AIRports to FORest
	double airfor1 = dvs[348];
	double airfor2 = dvs[349];
	double airfor3 = dvs[350];
	// From MINe & dump sites to FORest
	double minfor1 = dvs[351];
	double minfor2 = dvs[352];
	double minfor3 = dvs[353];
	// From FREsh water to FORest
	double frefor1 = dvs[354];
	double frefor2 = dvs[355];
	double frefor3 = dvs[356];
	// From MARine water to EXTensive grasslands
	double marfor1 = dvs[357];
	double marfor2 = dvs[358];
	double marfor3 = dvs[359];

    //// Parameters - Accessibility distance decay
    // ARAble land
    double aramdd = dvs[360];
	// PERmanent crops
	double permdd = dvs[361];
	// PAStures
	double pasmdd = dvs[362];
    // AGRicultural areas
    double agrmdd = dvs[363];
    // RESidential
    double resmdd = dvs[364];
    // INDustry & commerce
    double indmdd = dvs[365];
	// RECreation areas
	double recmdd = dvs[366];
	// FORest
	double formdd = dvs[367];
    //// Parameters - Accessibility Weights
    // ARAble land
    double aramwe = dvs[368];
	// PERmanent crops
	double permwe = dvs[369];
	// PAStures
	double pasmwe = dvs[370];
    // AGRicultural areas
    double agrmwe = dvs[371];
    // RESidential
    double resmwe = dvs[372];
    // INDustry & commerce
    double indmwe = dvs[373];
	// RECreation areas
	double recmwe = dvs[374];
	// FORest
	double formwe = dvs[375];

	//	%Amend Self-influence Neighbourhood Rules
    // Arable land
    setExpRuleMadrid(doc, 2, 1, araara1, araara2, araara3);
	// Permanent crops
	setExpRuleMadrid(doc, 3, 2, perper1, perper2, perper3);
	// Pastures
	setExpRuleMadrid(doc, 4, 3, paspas1, paspas2, paspas3);
    // Agricultural areas
    setExpRuleMadrid(doc, 5, 4, agragr1, agragr2, agragr3);
    // Residential
    setExpRuleMadrid(doc, 6, 5, resres1, resres2, resres3);
    // Industry & commerce
    setExpRuleMadrid(doc, 7, 6, indind1, indind2, indind3);
	// Recreation areas
    setExpRuleMadrid(doc, 8, 7, recrec1, recrec2, recrec3);
	// Forest
	setExpRuleMadrid(doc, 9, 8, forfor1, forfor2, forfor3);
	
    //	%Amend Iteraction Neighbourhood Rules
    // Arable land
	setExpRuleMadrid(doc, 1, 1, natara1, natara2, natara3);
	setExpRuleMadrid(doc, 3, 1, perara1, perara2, perara3);
	setExpRuleMadrid(doc, 4, 1, pasara1, pasara1, pasara3);
	setExpRuleMadrid(doc, 5, 1, agrara1, agrara2, agrara3);
	setExpRuleMadrid(doc, 6, 1, resara1, resara2, resara3);
    setExpRuleMadrid(doc, 7, 1, indara1, indara2, indara3);
    setExpRuleMadrid(doc, 8, 1, recara1, recara2, recara3);
    setExpRuleMadrid(doc, 9, 1, forara1, forara2, forara3);
	setExpRuleMadrid(doc, 10, 1, roaara1, roaara2, roaara3);
	setExpRuleMadrid(doc, 11, 1, porara1, porara2, porara3);
    setExpRuleMadrid(doc, 12, 1, airara1, airara2, airara3);
    setExpRuleMadrid(doc, 13, 1, minara1, minara2, minara3);
    setExpRuleMadrid(doc, 14, 1, freara1, freara2, freara3);
    setExpRuleMadrid(doc, 15, 1, marara1, marara2, marara3);
	// Permanent crops
	setExpRuleMadrid(doc, 1, 2, natper1, natper2, natper3);
	setExpRuleMadrid(doc, 2, 2, araper1, araper2, araper3);
	setExpRuleMadrid(doc, 4, 2, pasper1, pasper1, pasper3);
	setExpRuleMadrid(doc, 5, 2, agrper1, agrper2, agrper3);
	setExpRuleMadrid(doc, 6, 2, resper1, resper2, resper3);
    setExpRuleMadrid(doc, 7, 2, indper1, indper2, indper3);
    setExpRuleMadrid(doc, 8, 2, recper1, recper2, recper3);
    setExpRuleMadrid(doc, 9, 2, forper1, forper2, forper3);
	setExpRuleMadrid(doc, 10, 2, roaper1, roaper2, roaper3);
	setExpRuleMadrid(doc, 11, 2, porper1, porper2, porper3);
    setExpRuleMadrid(doc, 12, 2, airper1, airper2, airper3);
    setExpRuleMadrid(doc, 13, 2, minper1, minper2, minper3);
    setExpRuleMadrid(doc, 14, 2, freper1, freper2, freper3);
    setExpRuleMadrid(doc, 15, 2, marper1, marper2, marper3);
	// Pastures
	setExpRuleMadrid(doc, 1, 3, natpas1, natpas2, natpas3);
	setExpRuleMadrid(doc, 2, 3, arapas1, arapas2, arapas3);
	setExpRuleMadrid(doc, 3, 3, perpas1, perpas2, perpas3);
	setExpRuleMadrid(doc, 5, 3, agrpas1, agrpas2, agrpas3);
	setExpRuleMadrid(doc, 6, 3, respas1, respas2, respas3);
    setExpRuleMadrid(doc, 7, 3, indpas1, indpas2, indpas3);
    setExpRuleMadrid(doc, 8, 3, recpas1, recpas2, recpas3);
    setExpRuleMadrid(doc, 9, 3, forpas1, forpas2, forpas3);
	setExpRuleMadrid(doc, 10, 3, roapas1, roapas2, roapas3);
	setExpRuleMadrid(doc, 11, 3, porpas1, porpas2, porpas3);
    setExpRuleMadrid(doc, 12, 3, airpas1, airpas2, airpas3);
    setExpRuleMadrid(doc, 13, 3, minpas1, minpas2, minpas3);
    setExpRuleMadrid(doc, 14, 3, frepas1, frepas2, frepas3);
    setExpRuleMadrid(doc, 15, 3, marpas1, marpas2, marpas3);
	// Agricultural areas
	setExpRuleMadrid(doc, 1, 4, natagr1, natagr2, natagr3);
	setExpRuleMadrid(doc, 2, 4, araagr1, araagr2, araagr3);
	setExpRuleMadrid(doc, 3, 4, peragr1, peragr2, peragr3);
	setExpRuleMadrid(doc, 4, 4, pasagr1, pasagr2, pasagr3);
	setExpRuleMadrid(doc, 6, 4, resagr1, resagr2, resagr3);
    setExpRuleMadrid(doc, 7, 4, indagr1, indagr2, indagr3);
    setExpRuleMadrid(doc, 8, 4, recagr1, recagr2, recagr3);
    setExpRuleMadrid(doc, 9, 4, foragr1, foragr2, foragr3);
	setExpRuleMadrid(doc, 10, 4, roaagr1, roaagr2, roaagr3);
	setExpRuleMadrid(doc, 11, 4, poragr1, poragr2, poragr3);
    setExpRuleMadrid(doc, 12, 4, airagr1, airagr2, airagr3);
    setExpRuleMadrid(doc, 13, 4, minagr1, minagr2, minagr3);
    setExpRuleMadrid(doc, 14, 4, freagr1, freagr2, freagr3);
    setExpRuleMadrid(doc, 15, 4, maragr1, maragr2, maragr3);
	// Residential
	setExpRuleMadrid(doc, 1, 5, natres1, natres2, natres3);
	setExpRuleMadrid(doc, 2, 5, arares1, arares2, arares3);
	setExpRuleMadrid(doc, 3, 5, perres1, perres2, perres3);
	setExpRuleMadrid(doc, 4, 5, pasres1, pasres2, pasres3);
	setExpRuleMadrid(doc, 5, 5, agrres1, agrres2, agrres3);
    setExpRuleMadrid(doc, 7, 5, indres1, indres2, indres3);
    setExpRuleMadrid(doc, 8, 5, recres1, recres2, recres3);
    setExpRuleMadrid(doc, 9, 5, forres1, forres2, forres3);
	setExpRuleMadrid(doc, 10, 5, roares1, roares2, roares3);
	setExpRuleMadrid(doc, 11, 5, porres1, porres2, porres3);
    setExpRuleMadrid(doc, 12, 5, airres1, airres2, airres3);
    setExpRuleMadrid(doc, 13, 5, minres1, minres2, minres3);
    setExpRuleMadrid(doc, 14, 5, freres1, freres2, freres3);
    setExpRuleMadrid(doc, 15, 5, marres1, marres2, marres3);
	// Industry & commerce
	setExpRuleMadrid(doc, 1, 6, natind1, natind2, natind3);
	setExpRuleMadrid(doc, 2, 6, araind1, araind2, araind3);
	setExpRuleMadrid(doc, 3, 6, perind1, perind2, perind3);
	setExpRuleMadrid(doc, 4, 6, pasind1, pasind2, pasind3);
	setExpRuleMadrid(doc, 5, 6, agrind1, agrind2, agrind3);
    setExpRuleMadrid(doc, 6, 6, resind1, resind2, resind3);
    setExpRuleMadrid(doc, 8, 6, recind1, recind2, recind3);
    setExpRuleMadrid(doc, 9, 6, forind1, forind2, forind3);
	setExpRuleMadrid(doc, 10, 6, roaind1, roaind2, roaind3);
	setExpRuleMadrid(doc, 11, 6, porind1, porind2, porind3);
    setExpRuleMadrid(doc, 12, 6, airind1, airind2, airind3);
    setExpRuleMadrid(doc, 13, 6, minind1, minind2, minind3);
    setExpRuleMadrid(doc, 14, 6, freind1, freind2, freind3);
    setExpRuleMadrid(doc, 15, 6, marind1, marind2, marind3);
	// Recreation areas
	setExpRuleMadrid(doc, 1, 7, natrec1, natrec2, natrec3);
	setExpRuleMadrid(doc, 2, 7, ararec1, ararec2, ararec3);
	setExpRuleMadrid(doc, 3, 7, perrec1, perrec2, perrec3);
	setExpRuleMadrid(doc, 4, 7, pasrec1, pasrec2, pasrec3);
	setExpRuleMadrid(doc, 5, 7, agrrec1, agrrec2, agrrec3);
    setExpRuleMadrid(doc, 6, 7, resrec1, resrec2, resrec3);
    setExpRuleMadrid(doc, 7, 7, indrec1, indrec2, indrec3);
    setExpRuleMadrid(doc, 9, 7, forrec1, forrec2, forrec3);
	setExpRuleMadrid(doc, 10, 7, roarec1, roarec2, roarec3);
	setExpRuleMadrid(doc, 11, 7, porrec1, porrec2, porrec3);
    setExpRuleMadrid(doc, 12, 7, airrec1, airrec2, airrec3);
    setExpRuleMadrid(doc, 13, 7, minrec1, minrec2, minrec3);
    setExpRuleMadrid(doc, 14, 7, frerec1, frerec2, frerec3);
    setExpRuleMadrid(doc, 15, 7, marrec1, marrec2, marrec3);
	// Forest
	setExpRuleMadrid(doc, 1, 8, natfor1, natfor2, natfor3);
	setExpRuleMadrid(doc, 2, 8, arafor1, arafor2, arafor3);
	setExpRuleMadrid(doc, 3, 8, perfor1, perfor2, perfor3);
	setExpRuleMadrid(doc, 4, 8, pasfor1, pasfor2, pasfor3);
	setExpRuleMadrid(doc, 5, 8, agrfor1, agrfor2, agrfor3);
    setExpRuleMadrid(doc, 6, 8, resfor1, resfor2, resfor3);
    setExpRuleMadrid(doc, 7, 8, indfor1, indfor2, indfor3);
    setExpRuleMadrid(doc, 8, 8, recfor1, recfor2, recfor3);
	setExpRuleMadrid(doc, 10, 8, roafor1, roafor2, roafor3);
	setExpRuleMadrid(doc, 11, 8, porfor1, porfor2, porfor3);
    setExpRuleMadrid(doc, 12, 8, airfor1, airfor2, airfor3);
    setExpRuleMadrid(doc, 13, 8, minfor1, minfor2, minfor3);
    setExpRuleMadrid(doc, 14, 8, frefor1, frefor2, frefor3);
    setExpRuleMadrid(doc, 15, 8, marfor1, marfor2, marfor3);

//        % Amend Accessibility
//    % Main roads distance decay
    setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/DistanceDecay/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[1]", aramdd);
	setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/DistanceDecay/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[2]", permdd);
	setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/DistanceDecay/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[3]", pasmdd);
	setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/DistanceDecay/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[4]", agrmdd);
    setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/DistanceDecay/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[5]", resmdd);
    setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/DistanceDecay/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[6]", indmdd);
	setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/DistanceDecay/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[7]", recmdd);
	setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/DistanceDecay/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[8]", formdd);
//     % Main roads weights
    setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/Weight/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[1]", aramwe);
    setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/Weight/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[2]", permwe);
	setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/Weight/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[3]", pasmwe);
    setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/Weight/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[4]", agrmwe);
    setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/Weight/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[5]", resmwe);
    setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/Weight/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[6]", indmwe);
	setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/Weight/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[7]", recmwe);
	setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Accessibility\"]/AccessibilityWithZABlock/Weight/value[@time=\"1990-Jan-01 00:00:00\"]/vector/elem[1]/vector/elem[8]", formwe);

    setAllValuesXMLNodeMadrid(doc, "/GeonamicaSimulation/model/modelBlocks/modelBlock[@library=\"\" and @name=\"MB_Land_use_model\"]/CompositeModelBlock/modelBlocks/modelBlock[@library=\"CAModel.dll\" and @name=\"MB_Total_potential\"]/TotalPotentialBlock/Seed", seed);


    doc.save_file(geoproj_path.c_str());
}
Ejemplo n.º 17
0
bool SpriteSet::load(fs::path const& filename)
{	
	//cerr << "Loading sprite set: " << filename.native_file_string() << endl;
	
	BITMAP *tempBitmap = gfx.loadBitmap(filename.native_file_string().c_str(), 0, true);
	
	if (!tempBitmap)
		return false;
		
	LocalSetColorConversion cc(COLORCONV_NONE);
	LocalSetColorDepth cd(bitmap_color_depth(tempBitmap));

	if ( (tempBitmap->w > 1) && (tempBitmap->h > 1) )
	{
		int lastY = 1;
		int pivotY = -1;
		angleCount = 0;
		
		for (int y = 1; y < tempBitmap->h; ++y)
		{
			if( gfx.compareRGB(getpixel(tempBitmap,0,y),makecol(255,0,0)) ) // Red pixel marks the pivot of the sprite
			{
				pivotY = y-lastY;
			}
			else if( gfx.compareRGB(getpixel(tempBitmap,0,y), 0) || y == tempBitmap->h - 1 )
			{
				++angleCount;
				
				int lastX = 1;
				int pivotX = -1;
				frameCount = 0;
				
				for (int x = 1; x < tempBitmap->w; ++x)
				{
					// Pivot again but for X axis
					if( gfx.compareRGB(getpixel(tempBitmap,x,0), makecol(255,0,0)) )
					{
						pivotX = x-lastX;
					}
					else if(gfx.compareRGB(getpixel(tempBitmap,x,0), 0) || x == tempBitmap->w - 1 )
					{
						BITMAP* spriteFrame = create_bitmap(x-lastX+1, y-lastY+1);
						blit(tempBitmap, spriteFrame, lastX, lastY, 0, 0, spriteFrame->w, spriteFrame->h);
						//m_frames.back().push_back(new Sprite( spriteFrame, pivotX, pivotY ) );
						m_frames.push_back(new Sprite( spriteFrame, pivotX, pivotY ) );
						++frameCount;
						
						pivotX = -1;
						
						lastX = x + 1;
					}
				}

				pivotY = -1;
				lastY = y + 1;
			}
		}
			
		// Fill the other 180º with the sprites but mirrored.

	}

	destroy_bitmap(tempBitmap);
	
	m_angleFactor = (angleCount - 1) * 2;
	m_halfAngleDivisonSize = (1 << 15) / angleCount / 2;

	return true;
}
Ejemplo n.º 18
0
    void writeAbundances(ExpLib& alnLib,
                         boost::filesystem::path& fname,
                         std::string headerComments) {
        using sailfish::math::LOG_0;
        using sailfish::math::LOG_1;

        std::unique_ptr<std::FILE, int (*)(std::FILE *)> output(std::fopen(fname.c_str(), "w"), std::fclose);

        fmt::print(output.get(), "{}", headerComments);
        fmt::print(output.get(), "# Name\tLength\tTPM\tFPKM\tNumReads\n");


        auto& refs = alnLib.transcripts();
        auto numMappedReads = alnLib.numMappedReads();
        const double logBillion = std::log(1000000000.0);
        const double million = 1000000.0;
        const double logNumFragments = std::log(static_cast<double>(numMappedReads));
        auto clusters = alnLib.clusterForest().getClusters();
        size_t clusterID = 0;
        for(auto cptr : clusters) {

            double logClusterMass = cptr->logMass();
            double logClusterCount = std::log(static_cast<double>(cptr->numHits()));

            if (logClusterMass == LOG_0) {
                std::cerr << "Warning: cluster " << clusterID << " has 0 mass!\n";
            }

            bool requiresProjection{false};

            auto& members = cptr->members();
            size_t clusterSize{0};
            for (auto transcriptID : members) {
                Transcript& t = refs[transcriptID];
                t.uniqueCounts = t.uniqueCount();
                t.totalCounts = t.totalCount();
                //clusterCount += t.totalCounts;
            }

            for (auto transcriptID : members) {
                Transcript& t = refs[transcriptID];
                double logTranscriptMass = t.mass(false);
                if (logTranscriptMass == LOG_0) {
                    t.projectedCounts = 0;
                } else {
                    double logClusterFraction = logTranscriptMass - logClusterMass;
                    t.projectedCounts = std::exp(logClusterFraction + logClusterCount);
                    requiresProjection |= t.projectedCounts > static_cast<double>(t.totalCounts) or
                        t.projectedCounts < static_cast<double>(t.uniqueCounts);
                }
                ++clusterSize;
            }

            if (clusterSize > 1 and requiresProjection) {
                cptr->projectToPolytope(refs);
            }
            ++clusterID;
        }

        auto& transcripts_ = refs;
        double tfracDenom{0.0};
        for (auto& transcript : transcripts_) {
            tfracDenom += (transcript.projectedCounts / numMappedReads) / transcript.RefLength;
        }

        // Now posterior has the transcript fraction
        for (auto& transcript : transcripts_) {
            double logLength = std::log(transcript.RefLength);
            double fpkmFactor = std::exp(logBillion - logLength - logNumFragments);
            double count = transcript.projectedCounts;
            //double countTotal = transcripts_[transcriptID].totalCounts;
            //double countUnique = transcripts_[transcriptID].uniqueCounts;
            double fpkm = count > 0 ? fpkmFactor * count : 0.0;
            double npm = (transcript.projectedCounts / numMappedReads);
            double tfrac = (npm / transcript.RefLength) / tfracDenom;
            double tpm = tfrac * million;

            fmt::print(output.get(), "{}\t{}\t{}\t{}\t{}\n",
                    transcript.RefName, transcript.RefLength,
                    tpm, fpkm, count);
        }

    }
void SaveImage( boost::filesystem::path path, cv::Mat image )
{
    cv::imwrite( path.native_file_string(), image );
}
void
tc_simple_wchar()
{
    using dotconf::Document ;
    using dotconf::Item ;
    utf8_to_oem conv( locale , console_cp_name );
    std::auto_ptr< const Document > doc_ptr ;
    try {
        const wchar_t * fname = L"Простой документ.conf" ;
        const fs::path test_path ( testdir_path / fname );
        const std::wstring testfile_str ( test_path.wstring() );
        BOOST_TEST_MESSAGE( i18n("Test file path") << ": " << conv(testfile_str) );
        doc_ptr.reset( new Document( testfile_str ) );
    } catch( const dotconf::SyntaxError & error ) {
        BOOST_FAIL( error.what() << " in position " << error.textpos );
    } catch( const std::exception & error ) {
        BOOST_FAIL( error.what() );
    } catch(...) {
        BOOST_FAIL( i18n("Unknown exception") );
    }
    BOOST_REQUIRE( 0 != doc_ptr.get() );
    const Document::Items_t & items = *doc_ptr;
    BOOST_REQUIRE( !items.empty() );
    Document::const_iterator it = items.begin();
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_comment("# Simple config file") );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_param("simpleParam") );
    BOOST_REQUIRE( items.has_child( it ) );
    it = items.get_child( it );
    BOOST_CHECK_EQUAL( *it , Item::create_value("simpleValue") );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
    it = items.next_sibling( items.get_parent( it ) );
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_param("strParam") );
    BOOST_REQUIRE( items.has_child( it ) );
    it = items.get_child( it );
    BOOST_CHECK_EQUAL( *it , Item::create_value("string value") );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
    it = items.next_sibling( items.get_parent( it ) );
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_param("textParam") );
    BOOST_REQUIRE( items.has_child( it ) );
    it = items.get_child( it );
    BOOST_CHECK_EQUAL( *it , Item::create_value
        ("Line 1 of big text param value...\n"
         "Line 2 of text parameter value...\n"
         "Line 3 (last) of text parameter value.") );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
    it = items.next_sibling( items.get_parent( it ) );
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_param("vectorParam") );
    BOOST_REQUIRE( items.has_child( it ) );
    it = items.get_child( it );
    BOOST_CHECK_EQUAL( *it , Item::create_value("value1") );
    BOOST_CHECK_EQUAL( *++it , Item::create_value("value2") );
    BOOST_CHECK_EQUAL( *++it , Item::create_value("value3") );
    BOOST_CHECK_EQUAL( *++it , Item::create_value("value4") );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
    it = items.next_sibling( items.get_parent( it ) );
    BOOST_REQUIRE( items.end() != it );
    BOOST_CHECK_EQUAL( *it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK_EQUAL( *++it , Item::create_node("Node1") );
    BOOST_CHECK( !items.has_child( it ) );
    BOOST_CHECK_EQUAL( *++it , Item::create_endl() );
    BOOST_CHECK( items.next_sibling( it ) == items.end() );
} // tc_simple_wchar
Ejemplo n.º 21
0
void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path)
{
    mOgre->getRoot()->addResourceLocation (path.string(), "FileSystem",
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
}
Ejemplo n.º 22
0
	bool start(const boost::filesystem::path &root) override
 	{
		if (running_) {
			if (root_ == root) {
				return true;
			} else {
				return false;
			}
		}

		SECURITY_ATTRIBUTES sa = {};

		sa.nLength = sizeof(sa);
		sa.bInheritHandle = TRUE;

		cancel_event_ = ::CreateEventW(&sa, TRUE, FALSE, nullptr);

		if (cancel_event_ == nullptr) {
			return false;
		}

		HANDLE hstdout_read = nullptr;
		HANDLE hstdout_write = nullptr;
		HANDLE hstderr_write = nullptr;

		if (::CreatePipe(&hstdout_read, &hstdout_write, &sa, 0) == FALSE) {
			return false;
		}

		if (::DuplicateHandle(
			::GetCurrentProcess(), hstdout_write, ::GetCurrentProcess(), &hstderr_write,
			0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE)
		{
			::CloseHandle(hstdout_read);
			::CloseHandle(hstdout_write);
			return false;
		}

		if (::DuplicateHandle(
			::GetCurrentProcess(), hstdout_read, ::GetCurrentProcess(), &hstdout_,
			0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE)
		{
			::CloseHandle(hstdout_read);
			::CloseHandle(hstdout_write);
			::CloseHandle(hstderr_write);
			return false;
		}

		STARTUPINFOW si = {};

		si.cb = sizeof(STARTUPINFOW);
		si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
		si.hStdOutput = hstdout_write;
		si.hStdError = hstderr_write;
		si.wShowWindow = SW_HIDE;

		PROCESS_INFORMATION pi = {};

		std::wstring command = L'\"' + (get_exe_path().remove_filename() / L"console-helper.exe").wstring();

		command += L"\" ";
		command += std::to_wstring(reinterpret_cast<std::uintptr_t>(cancel_event_));
		command += L' ';
		command += L"jupyter notebook --no-browser ";
		command += L"--notebook-dir=\"";
		command += root.wstring();
		command += L'\"';

		auto result = ::CreateProcessW(
			nullptr,
			const_cast<LPWSTR>(command.c_str()),
			nullptr,
			nullptr,
			TRUE,
			CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP,
			nullptr,
			nullptr,
			&si,
			&pi);

		::CloseHandle(hstdout_read);
		::CloseHandle(hstdout_write);
		::CloseHandle(hstderr_write);

		if (result == FALSE) {
			::CloseHandle(hstdout_);
			return false;
		}

		running_ = true;
		helper_process_ = pi.hProcess;

		char buf_array[256];
		DWORD read;

		std::string buf;

		const char *text = "The Jupyter Notebook is running at: ";
		auto text_len = ::strlen(text);

		for (;;) {
			if (::ReadFile(hstdout_, (LPVOID)buf_array, 255, &read, nullptr) == FALSE) {
				return false;
			}

			buf_array[read] = '\0';
			buf += buf_array;

			auto pos = buf.find(text);

			if (pos != std::string::npos) {
				pos += text_len;

				auto pos_end = buf.find_first_of("\r\n", pos);

				if (pos_end != std::string::npos) {
					auto s = buf.substr(pos + 7, pos_end - pos - 7);
					pos = s.find(':');
					pos_end = s.find('/', pos);
					auto aa = s.substr(pos + 1, pos_end - pos - 1);
					if (pos != std::string::npos && pos_end != std::string::npos) {
						try {
							port_ = static_cast<unsigned short>(std::stoul(s.substr(pos + 1, pos_end - pos - 1)));
						} catch (std::exception &e) {
							stop();
							throw e;
						}
					}
					break;
				}
			}
		}

		return port_ != 0;
	}
Ejemplo n.º 23
0
 virtual void load(const boost::filesystem::path& filepath, int& index)
 {
   std::cout << "Loading content file " << filepath.string() << std::endl;
   mListener.setLabel(MyGUI::TextIterator::toTagsString(filepath.string()));
 }
Ejemplo n.º 24
0
Archivo: tumor.cpp Proyecto: masahi/stf
int main(int argc, char *argv[])
{
    po::options_description opt("option");
    opt.add_options()
        ("data_dir", po::value<string>()->default_value("HG"))
        ("max_box_size", po::value<int>()->default_value(31))
        ;

    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, opt), vm);
    po::notify(vm);

    const fs::path data_dir(vm["data_dir"].as<string>());
    fs::directory_iterator dir_iter(data_dir);

    const int n_classes = 5;
    const int n_mr_channels = 4;
    const int n_components = 5;
    const int n_trees = 8;
    const int n_features = 100;
    const int n_thres = 10;
    const int max_depth = 10;
    std::vector<double> prior(n_classes);

    std::vector<GMM<double>> gmms(n_classes, GMM<double>(n_components));
    RandomForest<SpatialFeature> forest(n_classes, n_trees, n_features, n_thres, max_depth);

    {
        std::vector<VolumeVector<short>> mr_data;
        VolumeVector<short> gts;
        VolumeVector<unsigned char> masks;
        std::vector<std::vector<double>> gmm_data(n_classes);
        std::vector<int> counts(n_classes, 0);
        int total_voxel = 0;

        int c = 0;
        const int n_training_instances = 5;
        for (; dir_iter != fs::directory_iterator(); ++dir_iter, ++c)
        {
            if (c == n_training_instances) break;
            const fs::path instance(dir_iter->path());
            std::cout << instance.string() << std::endl;
            total_voxel += addInstance(instance, mr_data, masks, gts, gmm_data, counts);
        }

        for (int i = 0; i < n_classes; ++i)
        {
            prior[i] = static_cast<double>(counts[i]) / total_voxel;
        }

        const int n_threads = 8;
        omp_set_num_threads(n_threads);

#pragma omp parallel for
        for (int i = 0; i < n_classes; ++i)
        {
            const int rows = gmm_data[i].size() / n_mr_channels;
            const Matrix<double> X = ConstMatrixMapper<double>(&gmm_data[i][0], n_mr_channels, rows).transpose();
            gmms[i].train(X);
        }

        DataSet data(mr_data.size());

#pragma omp parallel for
        for (int i = 0; i < mr_data.size(); ++i)
        {
            int width, height, depth;
            std::tie(width, height, depth) = getVolumeDimension<short>(mr_data[i][0]);
            std::vector<double> prob(n_classes);

            const auto spacing = gts[i]->GetSpacing();
            const auto origin = gts[i]->GetOrigin();

            std::vector<VolumePtr<double>> gmm_volumes(n_classes);
            for (int j = 0; j < n_classes; ++j)
            {
                gmm_volumes[j] = createVolume<double>(width, height, depth, spacing, origin);
                gmm_volumes[j]->FillBuffer(0);
            }

            VolumeVector<int> integral_mr_volumes(n_mr_channels);
            for (int j = 0; j < n_mr_channels; ++j)
            {
                integral_mr_volumes[j] = createVolume<int>(width, height, depth, spacing, origin);
                integral_mr_volumes[j]->FillBuffer(0);
            }

            VolumeVector<double> integral_gmm_volumes(n_classes);
            for (int j = 0; j < n_classes; ++j)
            {
                integral_gmm_volumes[j] = createVolume<double>(width, height, depth, spacing, origin);
                integral_gmm_volumes[j]->FillBuffer(0);
            }

            VolumePtr<unsigned int> integral_n_voxels = createVolume<unsigned int>(width, height, depth, spacing, origin);
            integral_n_voxels->FillBuffer(0);

            for (int z = 0; z < depth; ++z)
            {
                for (int y = 0; y < height; ++y)
                {
                    for (int x = 0; x < width; ++x)
                    {
                        itk::Index<3> index;
                        index[0] = x;
                        index[1] = y;
                        index[2] = z;

                        bool inside = true;
                        if (masks[i]->GetPixel(index) == 0) inside = false;

                        unsigned int cum_sum_n_voxels = (inside ? 1: 0);
                        std::vector<int> cum_sum_mr(n_mr_channels, 0);
                        std::vector<double> cum_sum_gmm(n_classes, 0);

                        if(inside)
                        {
                            Vector<double> X(n_mr_channels);
                            for (int c = 0; c < n_mr_channels; ++c)
                            {
                                const short v = mr_data[i][c]->GetPixel(index);
                                X(c) = static_cast<double>(v);
                                cum_sum_mr[c] = v;
                            }
                            double normalizer = 0;
                            for (int j = 0; j < n_classes; ++j)
                            {
                                const double p = gmms[j].evaluate(X) * prior[j];
                                prob[j] = p;
                                normalizer += p;
                            }

                            for (int j = 0; j < n_classes; ++j)
                            {
                                const double v = prob[j] / normalizer;
                                gmm_volumes[j]->SetPixel(index, v);
                                cum_sum_gmm[j] = v;
                            }
                        }

#define ACCUMULATE(ox, oy, oz, op) \
    itk::Offset<3> offset; \
    offset[0] = ox; \
    offset[1] = oy; \
    offset[2] = oz; \
    cum_sum_n_voxels op##= integral_n_voxels->GetPixel(index + offset); \
    for (int c = 0; c < n_mr_channels; ++c)\
                        {\
    cum_sum_mr[c] op##= integral_mr_volumes[c]->GetPixel(index + offset); \
                    }\
    for (int c = 0; c < n_classes; ++c)\
                        {\
    cum_sum_gmm[c] op##= integral_gmm_volumes[c]->GetPixel(index + offset); \
                    }

                        if (x > 0)
                        {
                            ACCUMULATE(-1, 0, 0, +)
                        }
                        if (y > 0)
                        {
                            ACCUMULATE(0, -1, 0, +)
                        }
                        if (z > 0)
                        {
                            ACCUMULATE(0, 0, -1, +)
                        }
                        if (x > 0 && y > 0)
                        {
                            ACCUMULATE(-1, -1, 0, -)
                        }
                        if (y > 0 && z > 0)
                        {
                            ACCUMULATE(0, -1, -1, -)
                        }
                        if (x > 0 && z > 0)
                        {
                            ACCUMULATE(-1, 0, -1, -)
                        }
Ejemplo n.º 25
0
void Bundle2::saveGeometry(const boost::filesystem::path& fileName) const {
	H5::H5File bundleFile;
	bundleFile.openFile(fileName.string(), H5F_ACC_RDWR);

	H5::Group rootGroup = bundleFile.openGroup("/");

	// If the group "Geometry" exists, delete it!
	if(checkGeometry_(bundleFile)) {
		rootGroup.unlink("Geometry");
	}

	// Creating group Geometry
	H5::Group geometryGroup = rootGroup.createGroup("Geometry");

	// Saving poses
	const hsize_t posesChunkDim[] = { 3, 12 };
	H5::DSetCreatPropList posesPropList;
	posesPropList.setLayout(H5D_CHUNKED);
	posesPropList.setChunk(2, posesChunkDim);
	posesPropList.setDeflate(9);

	const hsize_t posesMaxDim[] = { H5S_UNLIMITED, 12 };
	const hsize_t posesCurDim[] = { frames_.size(), 12 };
	H5::DataSpace posesDS(2, posesCurDim, posesMaxDim);

	H5::DataSet posesDataSet = geometryGroup.createDataSet("Poses", H5::PredType::IEEE_F64LE, posesDS, posesPropList);

	double* posesData = (double*)malloc(frames_.size()*12*sizeof(double));
	size_t i = 0;
	for(deque<Frame*>::const_iterator it = frames_.begin(); it != frames_.end(); it++) {
		posesData[i*12] = (*it)->pose()->t().x();
		posesData[i*12 + 1] = (*it)->pose()->t().y();
		posesData[i*12 + 2] = (*it)->pose()->t().z();

		core::Matrix<double> R = (*it)->pose()->R();
		posesData[i*12 + 3] = R[0][0];
		posesData[i*12 + 4] = R[1][0];
		posesData[i*12 + 5] = R[2][0];
		posesData[i*12 + 6] = R[0][1];
		posesData[i*12 + 7] = R[1][1];
		posesData[i*12 + 8] = R[2][1];
		posesData[i*12 + 9] = R[0][2];
		posesData[i*12 + 10] = R[1][2];
		posesData[i*12 + 11] = R[2][2];

		++i;
	}

	posesDataSet.write((const void*)posesData, H5::PredType::NATIVE_DOUBLE, H5::DataSpace::ALL, H5::DataSpace::ALL);
	free((void*)posesData);
	posesDataSet.close();
	posesDS.close();

	// Saving points
	const hsize_t pointsChunkDim[] = {10, 3};
	H5::DSetCreatPropList pointsPropList;
	pointsPropList.setLayout(H5D_CHUNKED);
	pointsPropList.setChunk(2, pointsChunkDim);
	pointsPropList.setDeflate(9);

	const hsize_t pointsMaxDim[] = { H5S_UNLIMITED, 3 };
	const hsize_t pointsCurDim[] = { tracks_.size(), 3 };
	H5::DataSpace pointsDS(2, pointsCurDim, pointsMaxDim);

	H5::DataSet pointsDataSet = geometryGroup.createDataSet("Points", H5::PredType::IEEE_F64LE, pointsDS, pointsPropList);

	double* pointsData = (double*)malloc(tracks_.size()*3*sizeof(double));

	i = 0;
	for(deque<Track*>::const_iterator it = tracks_.begin(); it != tracks_.end(); it++) {
		pointsData[i*3] = (*it)->point()->coords().x();
		pointsData[i*3 + 1] = (*it)->point()->coords().y();
		pointsData[i*3 + 2] = (*it)->point()->coords().z();

		++i;
	}

	pointsDataSet.write((const void*)pointsData, H5::PredType::NATIVE_DOUBLE, H5::DataSpace::ALL, H5::DataSpace::ALL);
	free((void*)pointsData);
	pointsDataSet.close();
	pointsDS.close();

	// Saving inlier information
	const hsize_t inliersChunkDim[] = { 3 };
	H5::DSetCreatPropList inliersPropList;
	inliersPropList.setLayout(H5D_CHUNKED);
	inliersPropList.setChunk(1, inliersChunkDim);
	inliersPropList.setDeflate(9);

	const hsize_t inliersMaxDim[] = { H5S_UNLIMITED };
	const hsize_t inliersCurDim[] = { frames_.size() };
	H5::DataSpace inliersDS(1, inliersCurDim, inliersMaxDim);

	H5::VarLenType inliersType(&H5::PredType::STD_U8LE);

	H5::DataSet inliersDataSet = geometryGroup.createDataSet("Inliers", inliersType, inliersDS, inliersPropList);

	i = 0;
	for(deque<Frame*>::const_iterator it = frames_.begin(); it != frames_.end(); it++) {
		hvl_t inliersLine;

        size_t inliersLineSize = 0;
        for(size_t j = 0; j < (*it)->size(); ++j) {
            View& v = (**it)[j];
            for(unsigned int cam = 0; cam < v.numCameras(); ++cam) {
                if(v.inCamera(cam)) ++inliersLineSize;
            }
        }

		inliersLine.len = inliersLineSize;
		inliersLine.p = malloc(inliersLineSize*sizeof(unsigned char));

        size_t k = 0;
		for(size_t j = 0; j < (*it)->size(); ++j) {
            View& v = (**it)[j];
            for(unsigned int cam = 0; cam < v.numCameras(); ++cam) {
                if(v.inCamera(cam)) {
                    ((unsigned char*)(inliersLine.p))[k] = v.ray(cam).inlier()?1:0;
                    ++k;
                }
            }
        }

		const hsize_t dsOffset[] = { i };
		const hsize_t dsCount[] = { 1 };
		H5::DataSpace inliersCurDS = inliersDataSet.getSpace();
		inliersCurDS.selectHyperslab(H5S_SELECT_SET, dsCount, dsOffset);

		const hsize_t memDim[] = { 1 };
		H5::DataSpace memDS(1, memDim, memDim);

		H5::VarLenType memType(&H5::PredType::NATIVE_UCHAR);

		inliersDataSet.write((const void*)&inliersLine, memType, memDS, inliersCurDS);

		memType.close();
		memDS.close();
		inliersCurDS.close();

		free(inliersLine.p);

		++i;
	}

	inliersDataSet.close();
	inliersType.close();
	inliersDS.close();

	// Saving curves
	if(!curves_.empty()) {
		const hsize_t chunkDim[] = { 5 };
		H5::DSetCreatPropList propList;
		propList.setLayout(H5D_CHUNKED);
		propList.setChunk(1, chunkDim);
		propList.setDeflate(9);

		H5::VarLenType curveDatasetType(&H5::PredType::STD_U64LE);

		hsize_t curvesDim[] = { curves_.size() };
		hsize_t curvesMaxDim[] = { H5S_UNLIMITED };
		H5::DataSpace curvesDataspace(1, curvesDim, curvesMaxDim);

		H5::DataSet curvesDataset = geometryGroup.createDataSet("Curves", curveDatasetType, curvesDataspace, propList);

		for(size_t i = 0; i < curves_.size(); ++i) {
			hvl_t curveLine;

			curveLine.len = curves_[i].size();
			curveLine.p = malloc(curves_[i].size()*sizeof(size_t));

			for(size_t j = 0; j < curves_[i].size(); ++j) ((size_t*)(curveLine.p))[j] = curves_[i].track(j);

			const hsize_t dsOffset[] = { i };
			const hsize_t dsCount[] = { 1 };
			H5::DataSpace curDS = curvesDataset.getSpace();
			curDS.selectHyperslab(H5S_SELECT_SET, dsCount, dsOffset);

			const hsize_t memDim[] = { 1 };
			H5::DataSpace memDS(1, memDim, memDim);

			H5::VarLenType memType(&H5::PredType::NATIVE_HSIZE);

			curvesDataset.write((const void*)&curveLine, memType, memDS, curDS);

			memType.close();
			memDS.close();
			curDS.close();

			free(curveLine.p);
 		}

		curvesDataset.close();
		curvesDataspace.close();
		curveDatasetType.close();
		propList.close();
	}

	geometryGroup.close();
	rootGroup.close();
	bundleFile.close();
}
Ejemplo n.º 26
0
      uri::string_type operator () (const boost::filesystem::path &path) const {
	return path.string();
      }
Ejemplo n.º 27
0
// Bundle management
void Bundle2::save(const boost::filesystem::path& fileName) const {
	// Creating HDF5 file
	H5::H5File bundleFile(fileName.string(), H5F_ACC_TRUNC);
	storeParameters(bundleFile);

	H5::DataSpace scalar;

	// Saving POI
	H5::Group poiGroup = bundleFile.createGroup("/POI");

	H5::Attribute attr = poiGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar);
	hsize_t count = poi_.size();
	attr.write(H5::PredType::NATIVE_HSIZE, &count);
	attr.close();

	for(size_t frame = 0; frame < poi_.size(); ++frame) {
		const std::string frameGroupName = boost::str(boost::format("Frame %1$04d") % frame);
		H5::Group frameGroup = poiGroup.createGroup(frameGroupName);

		count = poi_[frame].size();
		attr = frameGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar);
		attr.write(H5::PredType::NATIVE_HSIZE, &count);
		attr.close();

		for(size_t camera = 0; camera < poi_[frame].size(); ++camera)
			poi_[frame][camera].save(frameGroup, camera);

		frameGroup.close();
	}

	poiGroup.close();

	// Saving key frames
	H5::Group bundleGroup = bundleFile.createGroup("/Bundle");

	H5::Group framesGroup = bundleGroup.createGroup("Frames");

	count = frames_.size();
	attr = framesGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar);
	attr.write(H5::PredType::NATIVE_HSIZE, &count);
	attr.close();

	for(deque<Frame*>::const_iterator it = frames_.begin(); it != frames_.end(); it++) {
		(*it)->save(framesGroup);
	}

	framesGroup.close();

	// Saving tracks
	const hsize_t chunkDim[] = { 2, 1 };
	H5::DSetCreatPropList propList;
	propList.setLayout(H5D_CHUNKED);
	propList.setChunk(2, chunkDim);
	propList.setDeflate(9);

	H5::VarLenType tracksDatasetType(&H5::PredType::STD_U64LE);

	hsize_t tracksDim[] = { tracks_.size(), 2 };
    hsize_t tracksMaxDim[] = { H5S_UNLIMITED, 2 };
	H5::DataSpace tracksDataspace(2, tracksDim, tracksMaxDim);

	H5::DataSet tracksDataset = bundleGroup.createDataSet("Tracks", tracksDatasetType, tracksDataspace, propList);

	for(size_t i = 0; i < tracks_.size(); ++i)
		tracks_[i]->save(tracksDataset, i);

	tracksDataset.close();
	tracksDataspace.close();
	tracksDatasetType.close();
	propList.close();

	bundleGroup.close();

	scalar.close();
	bundleFile.close();
}
Ejemplo n.º 28
0
 virtual void load(const boost::filesystem::path& filepath, int& index)
 {
   std::cout << "Loading content file " << filepath.string() << std::endl;
   mListener.setLabel(filepath.string());
 }
Ejemplo n.º 29
0
void
archive_t::deploy(const std::string& prefix_) {
    const fs::path prefix = prefix_;

    archive* target = archive_write_disk_new();
    archive_entry* entry = nullptr;

    int rv = ARCHIVE_OK;

    int flags = ARCHIVE_EXTRACT_TIME |
                ARCHIVE_EXTRACT_SECURE_SYMLINKS |
                ARCHIVE_EXTRACT_SECURE_NODOTDOT;

    archive_write_disk_set_options(target, flags);
    archive_write_disk_set_standard_lookup(target);

    while(true) {
        rv = archive_read_next_header(m_archive, &entry);

        if(rv == ARCHIVE_EOF) {
            break;
        } else if(rv != ARCHIVE_OK) {
            throw archive_error_t(m_archive);
        }

        const fs::path pathname = prefix / archive_entry_pathname(entry);

        // NOTE: Prepend the target path to the stored file path
        // in order to unpack it into the right place.
        archive_entry_set_pathname(entry, pathname.string().c_str());

        if(archive_entry_hardlink(entry)) {
            const fs::path hardlink = prefix / archive_entry_hardlink(entry);

            // NOTE: This entry might be a hardlink to some other file, for example
            // due to tar file deduplication mechanics. We need to update this path as well.
            archive_entry_set_hardlink(entry, hardlink.string().c_str());
        }

        COCAINE_LOG_DEBUG(m_log, "extracting %s", pathname);

        rv = archive_write_header(target, entry);

        if(rv != ARCHIVE_OK) {
            throw archive_error_t(target);
        } else if(archive_entry_size(entry) > 0) {
            extract(m_archive, target);
        }

        rv = archive_write_finish_entry(target);

        if(rv != ARCHIVE_OK) {
            throw archive_error_t(target);
        }
    }

    archive_write_close(target);

#if ARCHIVE_VERSION_NUMBER < 3000000
    archive_write_finish(target);
#else
    archive_write_free(target);
#endif

    const size_t count = archive_file_count(m_archive);

    COCAINE_LOG_INFO(m_log, "extracted %d %s", count, count == 1 ? "file" : "files");
}
Ejemplo n.º 30
0
Status readFile(
    const fs::path& path,
    size_t size,
    size_t block_size,
    bool dry_run,
    bool preserve_time,
    std::function<void(std::string& buffer, size_t size)> predicate) {
  auto handle = OpenReadableFile(path);
  if (handle.fd < 0) {
    return Status(1, "Cannot open file for reading: " + path.string());
  }

  struct stat file;
  if (fstat(handle.fd, &file) < 0) {
    return Status(1, "Cannot access path: " + path.string());
  }

  off_t file_size = file.st_size;
  if (file_size == 0 && size > 0) {
    file_size = static_cast<off_t>(size);
  }

  // Apply the max byte-read based on file/link target ownership.
  off_t read_max = (file.st_uid == 0)
                       ? FLAGS_read_max
                       : std::min(FLAGS_read_max, FLAGS_read_user_max);
  if (file_size > read_max) {
    VLOG(1) << "Cannot read " << path << " size exceeds limit: " << file_size
            << " > " << read_max;
    return Status(1, "File exceeds read limits");
  }

  if (dry_run) {
    // The caller is only interested in performing file read checks.
    boost::system::error_code ec;
    return Status(0, fs::canonical(path, ec).string());
  }

  struct timeval times[2];
#if defined(__linux__)
  TIMESPEC_TO_TIMEVAL(&times[0], &file.st_atim);
  TIMESPEC_TO_TIMEVAL(&times[1], &file.st_mtim);
#else
  TIMESPEC_TO_TIMEVAL(&times[0], &file.st_atimespec);
  TIMESPEC_TO_TIMEVAL(&times[1], &file.st_mtimespec);
#endif

  if (file_size == 0) {
    off_t total_bytes = 0;
    ssize_t part_bytes = 0;
    do {
      auto part = std::string(4096, '\0');
      part_bytes = read(handle.fd, &part[0], block_size);
      if (part_bytes > 0) {
        total_bytes += part_bytes;
        if (total_bytes >= read_max) {
          return Status(1, "File exceeds read limits");
        }
        //        content += part.substr(0, part_bytes);
        predicate(part, part_bytes);
      }
    } while (part_bytes > 0);
  } else {
    auto content = std::string(file_size, '\0');
    read(handle.fd, &content[0], file_size);
    predicate(content, file_size);
  }

  // Attempt to restore the atime and mtime before the file read.
  if (preserve_time && !FLAGS_disable_forensic) {
    futimes(handle.fd, times);
  }
  return Status(0, "OK");
}