Commit b49d273b by Kai Westerkamp

join tool

parent 39e3877b
Pipeline #282 passed with stage
in 28 seconds
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"asset": {
"version": "0.0"
},
"geometricError": 0,
"root": {
"boundingVolume": {
"sphere": [
0,
0,
0,
5
]
},
"geometricError": 0,
"refine": "add",
"children": [
{
"transform": [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 50.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
],
"boundingVolume": {
"sphere": [
0,
0,
0,
5
]
},
"geometricError": 0,
"content": {
"url": "Cloud.pnts"
}
}
]
}
}
...@@ -103,6 +103,50 @@ float degreeToRadian(float degree) { ...@@ -103,6 +103,50 @@ float degreeToRadian(float degree) {
return (float) (degree*M_PI / 180.0f); return (float) (degree*M_PI / 180.0f);
} }
void convertTxtToPnts()
{
std::vector<glm::vec3> pointsConvert;
std::vector<unsigned char> colorsConvert;
for (int i = 0; i < 4; i++) {
std::ifstream myfile;
char buffer[256];
// make sure it's big enough
snprintf(buffer, sizeof(buffer), "SmallTowers/pnts_2 - Cloud_%06d.txt", i);
myfile.open(buffer, std::ios::in);
if (!myfile)
{
continue;
}
std::cout << "Reading File: " << buffer << std::endl;
glm::vec3 tempvec;
int r, g, b;
while (!myfile.eof()) // To get you all the lines.
{
myfile >> tempvec.x >> tempvec.y >> tempvec.z >> r >> g >> b;
pointsConvert.push_back(tempvec);
colorsConvert.push_back(r);
colorsConvert.push_back(g);
colorsConvert.push_back(b);
//std::cout << tempvec.x << " " << tempvec.y << " " << tempvec.z << " "<< r << " " <<g << " " << b << std::endl;
}
myfile.close();
}
writePTNS(pointsConvert, colorsConvert, "SmallTowers/Cloud.pnts");
}
void DrawCoordinateSystem() { void DrawCoordinateSystem() {
...@@ -446,6 +490,34 @@ void processCurrentFrameForExport() { ...@@ -446,6 +490,34 @@ void processCurrentFrameForExport() {
} }
void writePTNS(std::vector<glm::vec3> exportpoints, std::vector<unsigned char> exportColors, const char* filename) {
pntsHeader header;
size_t pointArrayByteSize = exportpoints.size() * sizeof(glm::vec3);
std::cout << "writing File: Number of Points:" << exportpoints.size();
size_t coloArrayByteSize = exportColors.size() * sizeof(unsigned char);
header.featureTableByteLenght = pointArrayByteSize + coloArrayByteSize;
std::ostringstream os;
os << "{\"POINTS_LENGTH\":" << (exportpoints.size()) << ", \"POSITION\" : {\"byteOffset\":0}, \"RGB\" : {\"byteOffset\":" << pointArrayByteSize << "}}";
std::string json = os.str();
header.featureTableJSONByteLenght = json.size();
header.byteLenght = 28 /*header*/ + header.featureTableJSONByteLenght + header.featureTableByteLenght;
std::cout << " File Size in byte" << header.byteLenght << std::endl;
std::ofstream myfile;
myfile.open(filename, std::ios::out | std::ios::binary);
myfile.write((char*)&header, 28);
myfile << json;
myfile.write(reinterpret_cast<const char*>(&exportpoints[0]), pointArrayByteSize);
myfile.write(reinterpret_cast<const char*>(&exportColors[0]), coloArrayByteSize);
//myfile <<
myfile.close();
}
void writePointCloud() { void writePointCloud() {
if (points.size() == 0) { if (points.size() == 0) {
std::cout << "No points, scipping File write" << std::endl; std::cout << "No points, scipping File write" << std::endl;
...@@ -472,32 +544,11 @@ void writePointCloud() { ...@@ -472,32 +544,11 @@ void writePointCloud() {
exportpoints.push_back(glm::vec3(0.0f, 0.0f, i / 1000.0f)); exportpoints.push_back(glm::vec3(0.0f, 0.0f, i / 1000.0f));
}*/ }*/
writePTNS(exportpoints, colors, "example.pnts");
pntsHeader header; }
size_t pointArrayByteSize = exportpoints.size() * sizeof(glm::vec3);
std::cout<< "writing File: Number of Points:" << exportpoints.size() ;
size_t coloArrayByteSize = colors.size() * sizeof(unsigned char);
header.featureTableByteLenght = pointArrayByteSize + coloArrayByteSize;
std::ostringstream os;
os << "{\"POINTS_LENGTH\":" << (exportpoints.size() ) << ", \"POSITION\" : {\"byteOffset\":0}, \"RGB\" : {\"byteOffset\":" << pointArrayByteSize << "}}";
std::string json = os.str();
header.featureTableJSONByteLenght = json.size();
header.byteLenght = 28 /*header*/ + header.featureTableJSONByteLenght + header.featureTableByteLenght;
std::cout << " File Size in byte" << header.byteLenght <<std::endl;
std::ofstream myfile;
myfile.open("example.pnts", std::ios::out | std::ios::binary);
myfile.write((char*)&header, 28);
myfile << json;
myfile.write(reinterpret_cast<const char*>(&exportpoints[0]), pointArrayByteSize);
myfile.write(reinterpret_cast<const char*>(&colors[0]), coloArrayByteSize);
//myfile <<
myfile.close();
}
void rotateCamera() { void rotateCamera() {
static double angle = 0.; static double angle = 0.;
...@@ -718,6 +769,9 @@ void keyPressed(unsigned char key, int x, int y) ...@@ -718,6 +769,9 @@ void keyPressed(unsigned char key, int x, int y)
break; break;
case 'p': case 'p':
FrameTranslation = glm::vec3(0.0, 0.0, 0.0); FrameTranslation = glm::vec3(0.0, 0.0, 0.0);
case 'b':
convertTxtToPnts();
break; break;
case 27: // Escape key case 27: // Escape key
exit(0); exit(0);
......
...@@ -47,6 +47,9 @@ void reshapeFunction(int width, int height); ...@@ -47,6 +47,9 @@ void reshapeFunction(int width, int height);
void printVector(glm::vec3 vector); void printVector(glm::vec3 vector);
float degreeToRadian(float degree); float degreeToRadian(float degree);
void convertTxtToPnts();
void writePTNS(std::vector<glm::vec3> exportpoints, std::vector<unsigned char> exportColors, const char* filename);
struct pntsHeader { struct pntsHeader {
unsigned char magic[4] = { 'p','n','t','s' }; unsigned char magic[4] = { 'p','n','t','s' };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment