我的创作纪念日

系列文章目录

前言

在使用osg时候vs2019报错:
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C1083 无法打开包括文件: “osg/Config”: No such file or directory Groundtest E:\osg\work\Groundtest_wang\Groundtest\OSG\OpenSceneGraph-3.4.1-vs2017-x64\include\osg\Export 17

严重性 代码 说明 项目 文件 行 禁止显示状态
警告 C4819 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 Groundtest E:\osg\work\Groundtest_wang\Groundtest\main.cpp 1

在这里插入图片描述

一、错误原因

#include<osg/Config>
找不到config文件

二、解决

1.引入头文件

错误的包含文件路径:
E:\osg\work\Groundtest_wang\Groundtest\OSG\OpenSceneGraph-3.4.1-vs2017-x64\include

正确的包含文件路径:
E:\osg\work\Groundtest_wang\Groundtest\OSG\OpenSceneGraph-3.4.1-vs2017-x64\build\include

2.读入数据

using namespace std;
using namespace Gdiplus;

int main()
{
	//首先定义文件的输出位置
	string result_location = "E:\\osg\\work\\Groundtest_wang\\Groundtest\\output\\huailai20220414\\";
	//输入气象参数
	Weather weather;
	ifstream fin;
	double data;
	fin.open("E:\\osg\\work\\Groundtest_wang\\Groundtest\\input\\20210408xiugai.txt");
	int k = 0;
	while (1)
	{
		if (fin.eof())
		{
			break;
		}
		else
		{
			fin >> data;
			fin >> data;
			weather.vec_AirT.push_back(data);
			fin >> data;
			weather.vec_Rh.push_back(data);
			fin >> data;
			weather.vec_WindvSpeed.push_back(data);
			fin >> data;
			weather.vec_Solar.push_back(data);
			//cout << k << endl;
			k += 1;
		}
	}
	weather.altitude;//地物所在的海拔

	//读取osg地形文件
	string osgpath = "E:\\osg\\work\\Groundtest_wang\\Groundtest\\model\\huailai_dem(1).osg";
	MeshAnalyzer meshanalyzer;
	meshanalyzer.ReadModel(osgpath, scenechar);

	//输入仿真参数
	CalcPara calcpara;
	//cout << "请输入时间步长(时间步长指的是多长时间计算一次,单位为s):";
	cin >> calcpara.timeStep;
	//cout << "请输入时间步数(时间步数指的是总共需要计算多少时间步):";
	cin >> calcpara.stepNum;
	//cout << "请输入仿真精度:";
	cin >> calcpara.iterPreci;
	//cout << "请输入保存时间间隔(保存时间间隔指的是多长时间输出一次温度场的文件,单位为min):";
	cin >> calcpara.saveTime;

	SolarDirection Solardirection;
	//输入地理位置
	int latitude_d, latitude_m, longitude_d, longitude_m;
	double latitude, longitude;

	cin >> latitude_d;

	cin >> latitude_m;

	cin >> longitude_d;

	cin >> longitude_m;
	latitude = (latitude_d + latitude_m * 1.0 / 60) * radian;//纬度值
	longitude = longitude_d + longitude_m * 1.0 / 60;//经度值

	//输入时间参数
	//这里在做示例计算的时候为从某一天的0:00分到23:59分
	int year, month, day, hour, minute, second;
	second = 0;
	HAS.clear();
	HAS.resize(calcpara.stepNum);
	for (int i = 0; i < calcpara.stepNum; i++)
	{
		HAS.at(i).clear();
		HAS.at(i).resize(2);
	}
	//cout << "请输入计算的年份(公历):";
	cin >> year;
	//cout << "请输入计算的月份为该年份的那一月(公历):";
	cin >> month;
	//cout << "请输入计算为该月份的哪一天(公历):";
	cin >> day;
	int i = 0;
	for (hour = 0; hour < 24; hour++)
	{
		for (minute = 0; minute < 60; minute++)
		{
			HAS.at(i).at(0) = Solardirection.H(latitude, longitude, year, month, day, hour, minute, second);
			HAS.at(i).at(1) = Solardirection.As(latitude, longitude, year, month, day, hour, minute, second);
			i += 1;
		}
	}

	SolarPrecent.clear();
	for (int j = 0; j < scenechar.TargetNum; j++)
	{
		for (int k = 0; k < scenechar.vecTarget.at(j).vertexNum; k++)
		{
			scenechar.vecTarget.at(j).vertexchars.at(k).Solar.clear();
		}
	}

	Shadow_mapping shadowmapping;
	string SolarLocation = "E:\\osg\\work\\Groundtest_wang\\Groundtest\\output\\huailai20220414\\Solar\\huailaisolar220413.txt";
	shadowmapping.CalAndSaveRet(osgpath, SolarLocation);
	shadowmapping.run();
	//这里按照时间保存太阳辐射的文件
	//上面的SolarLocation是在一个文件里面保存了每个时间步的各点接收的太阳辐射的百分比
	//现在按照保存时间来保存各点的实际太阳辐射
	//这里是根据实际的太阳辐射×接受辐射百分比将各点的辐射传输到结构体中
	for (int i = 0; i < scenechar.TargetNum; i++)
	{
		for (int j = 0; j < scenechar.vecTarget.at(i).vertexNum; j++)
		{
			for (int l = 0; l < calcpara.stepNum; l++)
			{
				scenechar.vecTarget.at(i).vertexchars.at(j).Solar.at(l) *= weather.vec_Solar.at(l);
			}
		}
	}
	//输出太阳辐射
	vector<string> result_location_Solar(calcpara.stepNum * int(calcpara.timeStep) / (int(calcpara.saveTime * 60)));
	for (int l = 0; l < calcpara.stepNum * int(calcpara.timeStep) / (int(calcpara.saveTime * 60)); l++)
	{
		result_location_Solar.at(l) = result_location + "Solar\\" + to_string(l) + ".txt";
		ofstream out_Solar;
		out_Solar.open(result_location_Solar.at(l));
		for (int i = 0; i < scenechar.TargetNum; i++)
		{
			out_Solar << scenechar.TargetName.at(i) << endl;
			for (int j = 0; j < scenechar.vecTarget.at(i).vertexNum; j++)
			{
				out_Solar << scenechar.vecTarget.at(i).vertexchars.at(j).Solar.at(l * int(calcpara.saveTime * 60) / int(calcpara.timeStep)) << " ";
			}
			out_Solar << endl;
		}
		out_Solar.close();
	}
	//以上已经输出了各点在保存时刻的太阳辐射

	//以下根据png图片确定各点的材料性质
	//因为地物的osg模型只划分了一块,所以这里设定一个材料
	GdiplusStartupInput gdiplusstartupinput;
	ULONG_PTR gdiplustoken;
	GdiplusStartup(&gdiplustoken, &gdiplusstartupinput, nullptr);

	wstring infilename(L"E:\\osg\\work\\Groundtest_wang\\Groundtest\\model\\huailai.png");
	string outfilename("colar.txt");
	//读图片
	Bitmap* bmp = new Bitmap(infilename.c_str());
	UINT height = bmp->GetHeight();
	UINT width = bmp->GetWidth();

	Color color;
	ofstream fout(outfilename.c_str());


	//这里也可以不输出RGB值的文件,一般来说按照osg文件划分part时,有几个part对应几个RGB值
	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{
			bmp->GetPixel(x, y, &color);
			fout << x << " " << y << " " << (int)color.GetRed() << " " << (int)color.GetGreen() << " " << (int)color.GetBlue() << " " << endl;

		}
	}


	fout.close();
	delete bmp;
	GdiplusShutdown(gdiplustoken);

	//因为此地物背景没有划分好part,是将整个地物认为是一整块,所有这里将所有的点视为同一种材料

	for (int i = 0; i < scenechar.TargetNum; i++)
	{
		//对于所有的地物来说,边界条件都是2,也就是说所有的内边界都是恒温,具体的温度随时间和经纬度确定
		scenechar.vecTarget.at(i).Boundary_Conditions = 2;
		scenechar.vecTarget.at(i).innerpara.inner_T = 20;
		for (int j = 0; j < scenechar.vecTarget.at(i).vertexNum; j++)
		{
			//假设对应的材料为裸土
			//对于裸土来说需要的材质参数为表面材质的层数,表面的发射率,吸收率,各层的热导率,密度,比热容,以及各层的厚度,节点数,含水量,
			//这里设置为类型5是指在计算时采用裸土的材质进行计算,这里假设地表只有一层水泥,水泥的热导率为0.3,密度为1900,比热为837,表面发射率为0.956,吸收率为0.75,水泥公路的厚度为18~21cm,这里取20cm
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.m_type = 5;
			//
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.layerNum = 1;
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Abso = 0.75;
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Emsi = 0.956;
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Cond.push_back(0.3);
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Den.push_back(1900);
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Cp.push_back(837);
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.nodeNum.push_back(20);
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Thick.push_back(0.2);
			scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Moisture_content = 0.08;
		}
	}
	Scene_Calculate scenecharcalculate;
	vector<vector<vector<double>>> temp1(scenechar.TargetNum);
	for (int i = 0; i < scenechar.TargetNum; i++)
	{
		//这个20是指整个场景的初始化温度
		scenecharcalculate.SceneTempCompute(scenechar.vecTarget.at(i), weather, calcpara, temp1.at(i), 20);
	}

	//输出温度值
	vector<string> result_location_Temp(calcpara.stepNum * int(calcpara.timeStep) / (int(calcpara.saveTime * 60)));
	for (int l = 0; l < calcpara.stepNum * int(calcpara.timeStep) / (int(calcpara.saveTime * 60)); l++)
	{
		result_location_Temp.at(l) = result_location + "Temp\\" + to_string(l) + ".txt";
		ofstream out_Temp;
		out_Temp.open(result_location_Temp.at(l), ios::out | ios::app);
		for (int i = 0; i < scenechar.TargetNum; i++)
		{
			out_Temp << scenechar.TargetName.at(i) << endl;
			for (int j = 0; j < scenechar.vecTarget.at(i).vertexNum; j++)
			{
				out_Temp << scenechar.vecTarget.at(i).vertexchars.at(j).vertex.x() << " " << scenechar.vecTarget.at(i).vertexchars.at(j).vertex.y() << " " << scenechar.vecTarget.at(i).vertexchars.at(j).vertex.y() << " " << temp1.at(i).at(j).at(l) << endl;
			}

		}
		out_Temp.close();
	}
	//上面完成了裸土下温度场的计算

	//下面是植被温度的计算
	//for (int i = 0; i < scenechar.TargetNum; i++)
	//{
	//	//对于所有的地物来说,边界条件都是2,也就是说所有的内边界都是恒温,具体的温度随时间和经纬度确定
	//	scenechar.vecTarget.at(i).Boundary_Conditions = 2;
	//	scenechar.vecTarget.at(i).innerpara.inner_T = 20;
	//	for (int j = 0; j < scenechar.vecTarget.at(i).vertexNum; j++)
	//	{
	//		//假设对应的材料为植被
	//		//对于植被来说需要的材质参数为植被的表面发射率和吸收率,还有节点数量和空间步长,植被高度和叶面积指数
	//		//这里设置为类型4是指在计算时采用植被的材质进行计算
	//		scenechar.vecTarget.at(i).vertexchars.at(j).structpara.m_type = 4;
	//		
	//		scenechar.vecTarget.at(i).vertexchars.at(j).structpara.layerNum = 1;
	//		scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Abso = 0.8;
	//		scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Emsi = 0.96;
	//		scenechar.vecTarget.at(i).vertexchars.at(j).structpara.nodeNum.push_back(20);
	//		scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Thick.push_back(0.01);
	//		scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Vegetation_height = 0.15;
	//		scenechar.vecTarget.at(i).vertexchars.at(j).structpara.Leaf_area_index = 6.5;
	//	}
	//}
	//Scene_Calculate scenecharcalculate;
	//vector<vector<vector<double>>> temp1(scenechar.TargetNum);
	//for (int i = 0; i < scenechar.TargetNum; i++)
	//{
	//	//这个20是指整个场景的初始化温度
	//	scenecharcalculate.SceneTempCompute(scenechar.vecTarget.at(i), weather, calcpara, temp1.at(i), 20);
	//}

	输出温度值
	//vector<string> result_location_Temp(calcpara.stepNum * int(calcpara.timeStep) / (int(calcpara.saveTime * 60)));
	//for (int l = 0; l < calcpara.stepNum * int(calcpara.timeStep) / (int(calcpara.saveTime * 60)); l++)
	//{
	//	result_location_Temp.at(l) = result_location + "Temp\\" + to_string(l) + ".txt";
	//	ofstream out_Temp;
	//	out_Temp.open(result_location_Temp.at(l), ios::out | ios::app);
	//	for (int i = 0; i < scenechar.TargetNum; i++)
	//	{
	//		out_Temp << scenechar.TargetName.at(i) << endl;
	//		for (int j = 0; j < scenechar.vecTarget.at(i).vertexNum; j++)
	//		{
	//			out_Temp << scenechar.vecTarget.at(i).vertexchars.at(j).vertex.x() << " " << scenechar.vecTarget.at(i).vertexchars.at(j).vertex.y() << " " << scenechar.vecTarget.at(i).vertexchars.at(j).vertex.y() << " " << temp1.at(i).at(j).at(l) << endl;
	//		}

	//	}
	//	out_Temp.close();
	//}

	//下面是水体的计算
	/*for (int i = 0; i < scenechar.targetnum; i++)
	{
		//对于所有的地物来说,边界条件都是2,也就是说所有的内边界都是恒温,具体的温度随时间和经纬度确定
		scenechar.vectarget.at(i).boundary_conditions = 2;
		scenechar.vectarget.at(i).innerpara.inner_t = 20;
		for (int j = 0; j < scenechar.vectarget.at(i).vertexnum; j++)
		{
			//假设对应的材料为水体
			//对于裸土来说需要的材质参数为水体,需要水体的衰减系数和水体计算时的空间步长
			//一般来说水体计算是衰减系数夏天为0.4,冬天为0.7
			scenechar.vectarget.at(i).vertexchars.at(j).structpara.m_type = 3;
			scenechar.vectarget.at(i).vertexchars.at(j).structpara.m_spacestep.push_back(0.01);

		}
	}
	scene_calculate scenecharcalculate;
	vector<vector<vector<double>>> temp1(scenechar.targetnum);
	for (int i = 0; i < scenechar.targetnum; i++)
	{
		//这个20是指整个场景的初始化温度
		scenecharcalculate.scenetempcompute(scenechar.vectarget.at(i), weather, calcpara, temp1.at(i), 20);
	}

	//输出温度值
	vector<string> result_location_temp(calcpara.stepnum * int(calcpara.timestep) / (int(calcpara.savetime * 60)));
	for (int l = 0; l < calcpara.stepnum * int(calcpara.timestep) / (int(calcpara.savetime * 60)); l++)
	{
		result_location_temp.at(l) = result_location + "temp\\" + to_string(l) + ".txt";
		ofstream out_temp;
		out_temp.open(result_location_temp.at(l), ios::out | ios::app);
		for (int i = 0; i < scenechar.targetnum; i++)
		{
			out_temp << scenechar.targetname.at(i) << endl;
			for (int j = 0; j < scenechar.vectarget.at(i).vertexnum; j++)
			{
				out_temp << scenechar.vectarget.at(i).vertexchars.at(j).vertex.x() << " " << scenechar.vectarget.at(i).vertexchars.at(j).vertex.y() << " " << scenechar.vectarget.at(i).vertexchars.at(j).vertex.y() << " " << temp1.at(i).at(j).at(l) << endl;
			}

		}
		out_temp.close();
	}*/
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值