char* U2G(const char* utf8)
{
int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1);
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);
len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
char* str = new char[len + 1];
memset(str, 0, len + 1);
WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
if (wstr) delete[] wstr;
return str;
}
char* G2U(const char* gb2312)
{
int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1);
MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
char* str = new char[len + 1];
memset(str, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
if (wstr) delete[] wstr;
return str;
}
int main(int argc, char* argv[])
{
if (argc < 2) {
std::cout << "USAGE: (Block**** - AT - export undistorted photos) folder" << std::endl;
return -1;
}
std::string output_folder = "F:\\MVS_projects\\ISPRS\\rathaus\\rathaus_cc\\Block_5 - AT - export undistorted photos";
std::string camera_folder = output_folder + "/smart3D空三相机外参";
std::string images_folder = output_folder + "/smart3D转ACMP的无畸变影像";
std::string ply_path = output_folder + "/smart3D特征点云.ply";
std::string georegis_path = output_folder + "/geo_registered.txt";
std::vector<PointPLY> PointCloud;
PointCloud.clear();
if (_access(georegis_path.c_str(), 0) == 0)
{
if (remove(georegis_path.c_str()) == 0)
{
std::cout << georegis_path << "已删除" << std::endl;
}
}
TiXmlDocument* myDocument = new TiXmlDocument();
myDocument->LoadFile("F:\\MVS_projects\\ISPRS\\rathaus\\rathaus_cc\\Block_5 - AT - final - export.xml");
TiXmlElement* rootElement = myDocument->RootElement();
cout << rootElement->Value() << endl;
TiXmlHandle hRoot(rootElement);
TiXmlElement* nodeElem = hRoot.FirstChild("Block").Element();
cout << nodeElem->Value() << endl;
TiXmlElement* PhotogroupElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").Element();
cout << PhotogroupElem->Value() << endl;
TiXmlElement* ImageDimensionsElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").FirstChild("ImageDimensions").Element();
cout << ImageDimensionsElem->Value() << endl;
TiXmlElement* WidthElem = ImageDimensionsElem->FirstChild("Width")->ToElement();
cout << WidthElem->Value() << ": " << WidthElem->GetText() << std::endl;
TiXmlElement* HeightElem = ImageDimensionsElem->FirstChild("Height")->ToElement();
cout << HeightElem->Value() << ": " << HeightElem->GetText() << std::endl;
TiXmlElement* FocalLengthElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").FirstChild("FocalLength").Element();
cout << FocalLengthElem->Value() << ": " << FocalLengthElem->GetText() << std::endl;
TiXmlElement* SensorSizeElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").FirstChild("SensorSize").Element();
cout << SensorSizeElem->Value() << ": " << SensorSizeElem->GetText() << std::endl;
TiXmlElement* PhotoElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").FirstChild("Photo").Element();
cout << PhotoElem->Value() << endl;
string lines;
stringstream ss;
double value;
vector<double> R, C;
int image_id;
double neardepth, fardepth;
double width, height, focal_mm, sensorsize, fxy;
PointPLY tmpPoint;
double xyz, rgb;
vector<Image> ImageList;
ImageList.clear();
ss.clear();
ss.str(WidthElem->GetText());
ss >> width;
ss.clear();
ss.str(HeightElem->GetText());
ss >> height;
ss.clear();
ss.str(FocalLengthElem->GetText());
ss >> focal_mm;
ss.clear();
ss.str(SensorSizeElem->GetText());
ss >> sensorsize;
fxy = focal_mm * width / sensorsize;
while (PhotoElem) {
R.clear();
C.clear();
TiXmlElement* IdElement = PhotoElem->FirstChild("Id")->ToElement();
std::cout << "Image_Id" << " : " << IdElement->GetText() << std::endl;
ss.clear();
ss.str(IdElement->GetText());
ss >> image_id;
TiXmlElement* ImagePathElement = PhotoElem->FirstChild("ImagePath")->ToElement();
std::cout << "ImagePath" << " : " << U2G(ImagePathElement->GetText()) << std::endl;
string image_name = U2G(ImagePathElement->GetText());
image_name = image_name.substr(image_name.find_last_of('\\') + 1);
cout << image_name << endl;
Image img;
img.ID = image_id;
img.name = image_name;
ImageList.emplace_back(img);
TiXmlElement* RotationElement = PhotoElem->FirstChild("Pose")->FirstChild("Rotation")->ToElement();
TiXmlElement* CenterElement = PhotoElem->FirstChild("Pose")->FirstChild("Center")->ToElement();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
string M_ = "M_" + std::to_string(i) + std::to_string(j);
TiXmlElement* M_Element = RotationElement->FirstChild(M_.data())->ToElement();
std::cout << M_ << ": " << M_Element->GetText() << std::endl;
lines = M_Element->GetText();
ss.clear();
ss.str(lines);
ss >> value;
R.emplace_back(value);
}
}
TiXmlElement* C_Element = CenterElement->FirstChild("x")->ToElement();
std::cout << " x : " << C_Element->GetText() << std::endl;
ss.clear();
ss.str(C_Element->GetText());
ss >> value;
C.emplace_back(value);
C_Element = CenterElement->FirstChild("y")->ToElement();
std::cout << " y : " << C_Element->GetText() << std::endl;
ss.clear();
ss.str(C_Element->GetText());
ss >> value;
C.emplace_back(value);
C_Element = CenterElement->FirstChild("z")->ToElement();
std::cout << " z : " << C_Element->GetText() << std::endl;
ss.clear();
ss.str(C_Element->GetText());
ss >> value;
C.emplace_back(value);
TiXmlElement* NearDepthElement = PhotoElem->FirstChild("NearDepth")->ToElement();
std::cout << " NearDepth: " << NearDepthElement->GetText() << std::endl;
ss.clear();
ss.str(NearDepthElement->GetText());
ss >> neardepth;
TiXmlElement* FarDepthElement = PhotoElem->FirstChild("FarDepth")->ToElement();
std::cout << " FarDepth: " << FarDepthElement->GetText() << std::endl;
ss.clear();
ss.str(FarDepthElement->GetText());
ss >> fardepth;
std::cout << std::endl;
Outputgeotxt(georegis_path, image_name, C);
OutputCam(camera_folder, image_id, R, C, neardepth, fardepth, width, height, fxy);
PhotoElem = PhotoElem->NextSiblingElement();
}
int max = 1000;
TiXmlElement* TiePointElem = hRoot.FirstChild("Block").FirstChild("TiePoints").FirstChild("TiePoint").Element();
cout << "开始读取" << TiePointElem->Value() << endl;
while (TiePointElem) {
TiXmlElement* PositionElem = TiePointElem->FirstChild("Position")->ToElement();
TiXmlElement* XYZ_Element = PositionElem->FirstChild("x")->ToElement();
std::cout << " X: " << XYZ_Element->GetText() << std::endl;
ss.clear();
ss.str(XYZ_Element->GetText());
ss >> xyz;
tmpPoint.coord.x = xyz;
XYZ_Element = PositionElem->FirstChild("y")->ToElement();
std::cout << " Y: " << XYZ_Element->GetText() << std::endl;
ss.clear();
ss.str(XYZ_Element->GetText());
ss >> xyz;
tmpPoint.coord.y = xyz;
XYZ_Element = PositionElem->FirstChild("z")->ToElement();
std::cout << " Z: " << XYZ_Element->GetText() << std::endl;
ss.clear();
ss.str(XYZ_Element->GetText());
ss >> xyz;
tmpPoint.coord.z = xyz;
TiXmlElement* ColorElement = TiePointElem->FirstChild("Color")->ToElement();
TiXmlElement* RGB_Element = ColorElement->FirstChild("Red")->ToElement();
std::cout << " R: " << RGB_Element->GetText() << std::endl;
ss.clear();
ss.str(RGB_Element->GetText());
ss >> rgb;
tmpPoint.color.x = 255 * rgb;
RGB_Element = ColorElement->FirstChild("Green")->ToElement();
std::cout << " G: " << RGB_Element->GetText() << std::endl;
ss.clear();
ss.str(RGB_Element->GetText());
ss >> rgb;
tmpPoint.color.y = 255 * rgb;
RGB_Element = ColorElement->FirstChild("Blue")->ToElement();
std::cout << " B: " << RGB_Element->GetText() << std::endl;
ss.clear();
ss.str(RGB_Element->GetText());
ss >> rgb;
tmpPoint.color.z = 255 * rgb;
PointCloud.emplace_back(tmpPoint);
TiePointElem = TiePointElem->NextSiblingElement();
}
StoreColorPlyFileBinaryPointCloud(ply_path, PointCloud);
}
int main(int argc, char* argv[])
{
TiXmlDocument* myDocument = new TiXmlDocument();
myDocument->LoadFile("IceBearTest - AT - export.xml");
TiXmlElement* rootElement = myDocument->RootElement();
cout << rootElement->Value() << endl;
TiXmlHandle hRoot(rootElement);
TiXmlElement* nodeElem = hRoot.FirstChild("Block").Element();
cout << nodeElem->Value() << endl;
TiXmlElement* PhotogroupElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").Element();
cout << PhotogroupElem->Value() << endl;
TiXmlElement* ImageDimensionsElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").FirstChild("ImageDimensions").Element();
cout << ImageDimensionsElem->Value() << endl;
TiXmlElement* WidthElem = ImageDimensionsElem->FirstChild("Width")->ToElement();
cout << WidthElem->Value() << ": " << WidthElem->GetText() << std::endl;
TiXmlElement* HeightElem = ImageDimensionsElem->FirstChild("Height")->ToElement();
cout << HeightElem->Value() << ": " << HeightElem->GetText() << std::endl;
TiXmlElement* FocalLengthElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").FirstChild("FocalLength").Element();
cout << FocalLengthElem->Value() << ": " << FocalLengthElem->GetText() << std::endl;
TiXmlElement* SensorSizeElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").FirstChild("SensorSize").Element();
cout << SensorSizeElem->Value() << ": " << SensorSizeElem->GetText() << std::endl;
TiXmlElement* PhotoElem = hRoot.FirstChild("Block").FirstChild("Photogroups").FirstChild("Photogroup").FirstChild("Photo").Element();
cout << PhotoElem->Value() << endl;
string lines;
double value;
vector<double> K, R, t;
int tmp1;
while (PhotoElem) {
TiXmlElement* IdElement = PhotoElem->FirstChild("Id")->ToElement();
std::cout << "Image_Id" << " : " << IdElement->GetText() << std::endl;
TiXmlElement* ImagePathElement = PhotoElem->FirstChild("ImagePath")->ToElement();
std::cout << "ImagePath" << " : " << U2G(ImagePathElement->GetText()) << std::endl;
string colmap_id = U2G(ImagePathElement->GetText());
colmap_id = colmap_id.substr(colmap_id.find_last_of('\\') + 1);
cout << colmap_id << endl;
TiXmlElement* RotationElement = PhotoElem->FirstChild("Pose")->FirstChild("Rotation")->ToElement();
TiXmlElement* CenterElement = PhotoElem->FirstChild("Pose")->FirstChild("Center")->ToElement();
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
string M_ = "M_" + std::to_string(i) + std::to_string(j);
TiXmlElement* M_Element = RotationElement->FirstChild(M_.data())->ToElement();
std::cout << M_ << ": " << M_Element->GetText() << std::endl;
lines = M_Element->GetText();
cout << lines << endl;
stringstream ss(lines);
ss >> value;
R.emplace_back(value);
}
}
TiXmlElement* C_Element = CenterElement->FirstChild("x")->ToElement();
std::cout << " x : " << C_Element->GetText() << std::endl;
C_Element = CenterElement->FirstChild("y")->ToElement();
std::cout << " y : " << C_Element->GetText() << std::endl;
C_Element = CenterElement->FirstChild("z")->ToElement();
std::cout << " z : " << C_Element->GetText() << std::endl;
TiXmlElement* NearDepthElement = PhotoElem->FirstChild("NearDepth")->ToElement();
std::cout << " NearDepth: " << NearDepthElement->GetText() << std::endl;
TiXmlElement* FarDepthElement = PhotoElem->FirstChild("FarDepth")->ToElement();
std::cout << " FarDepth: " << FarDepthElement->GetText() << std::endl;
std::cout << std::endl;
PhotoElem = PhotoElem->NextSiblingElement();
}
TiXmlElement* TiePointElem = hRoot.FirstChild("Block").FirstChild("TiePoints").FirstChild("TiePoint").Element();
cout << "开始读取" << TiePointElem->Value() << endl;
while (TiePointElem) {
TiXmlElement* PositionElem = TiePointElem->FirstChild("Position")->ToElement();
TiXmlElement* XYZ_Element = PositionElem->FirstChild("x")->ToElement();
std::cout << " X: " << XYZ_Element->GetText() << std::endl;
XYZ_Element = PositionElem->FirstChild("y")->ToElement();
std::cout << " Y: " << XYZ_Element->GetText() << std::endl;
XYZ_Element = PositionElem->FirstChild("z")->ToElement();
std::cout << " Z: " << XYZ_Element->GetText() << std::endl;
TiXmlElement* ColorElem = TiePointElem->FirstChild("Color")->ToElement();
TiXmlElement* MeasurementElem = TiePointElem->FirstChild("Measurement")->ToElement();
while (MeasurementElem) {
TiXmlElement* PhotoIdElement = MeasurementElem->FirstChild("PhotoId")->ToElement();
std::cout << " PhotoId: " << PhotoIdElement->GetText() << std::endl;
TiXmlElement* xy_Element = MeasurementElem->FirstChild("x")->ToElement();
std::cout << " x: " << xy_Element->GetText() << std::endl;
xy_Element = MeasurementElem->FirstChild("y")->ToElement();
std::cout << " y: " << xy_Element->GetText() << std::endl;
MeasurementElem = MeasurementElem->NextSiblingElement();
}
TiePointElem = TiePointElem->NextSiblingElement();
}
}