Example #1
0
void clsRasterData::readASCFile(string ascFileName)
{
	utils util;
	if(!util.FileExists(ascFileName)) 
		throw ModelException("clsRasterData","readASCFile","The file " + ascFileName + " does not exist or has not read permission.");

	StatusMessage(("read " + ascFileName + "...").c_str());

	ifstream rasterFile(ascFileName.c_str());
	string tmp;
	float noData;
	int rows,cols;
	float tempFloat;
	vector<float> values;
	vector<int> positionRows;
	vector<int> positionCols;

	//read header
	rasterFile >> tmp >> cols;
	m_headers[GetUpper(tmp)] = float(cols);
	rasterFile >> tmp >> rows;
	m_headers[GetUpper(tmp)] = float(rows);
	rasterFile >> tmp >> tempFloat;
	m_headers[GetUpper(tmp)] = tempFloat;
	rasterFile >> tmp >> tempFloat;
	m_headers[GetUpper(tmp)] = tempFloat;
	rasterFile >> tmp >> tempFloat;
	m_headers[GetUpper(tmp)] = tempFloat;
	//rasterFile >> tmp >> tempFloat;
	//m_headers[tmp] = tempFloat;
	rasterFile >> tmp >> noData;
	m_headers[GetUpper(tmp)] = noData;

	//get all valid values
	tempFloat = noData;
	for (int i = 0; i < rows; ++i)
	{
		for (int j = 0; j < cols; ++j)
		{
			rasterFile >> tempFloat;
			if(tempFloat == noData) continue;
			values.push_back(tempFloat);
			positionRows.push_back(i);
			positionCols.push_back(j);
		}
	}
	rasterFile.close();

	//create float array
	m_nRows = values.size();
	m_rasterData = new float[m_nRows];
	m_rasterPositionData = new float*[m_nRows];
	for (int i = 0; i < m_nRows; ++i)
	{
		m_rasterData[i] = values.at(i);
		m_rasterPositionData[i] = new float[2];
		m_rasterPositionData[i][0] = float(positionRows.at(i));
		m_rasterPositionData[i][1] = float(positionCols.at(i));
	}
}
Example #2
0
const sf::FloatRect Scale::GetSliderRect() const {
	auto slider_length = Context::Get().GetEngine().GetProperty<float>( "SliderLength", shared_from_this() );
	auto slider_width = (GetOrientation() == Orientation::HORIZONTAL) ? GetAllocation().height : GetAllocation().width;
	auto adjustment = GetAdjustment();
	auto current_value = adjustment->GetValue();
	auto value_range = adjustment->GetUpper() - adjustment->GetLower() - adjustment->GetPageSize();

	if( GetOrientation() == Orientation::HORIZONTAL ) {
		auto slider_x = (GetAllocation().width - slider_length) * (current_value - adjustment->GetLower()) / value_range;
		auto slider_y = (GetAllocation().height - slider_width) / 2.f;

		return sf::FloatRect( slider_x, slider_y, slider_length, slider_width );
	}

	auto slider_x = (GetAllocation().width - slider_width) / 2.f;
	auto slider_y = (GetAllocation().height - slider_length) * (1 - ((current_value - adjustment->GetLower()) / value_range));

	return sf::FloatRect( slider_x, slider_y, slider_width, slider_length );
}