Reading in cloud compare sbf binary files using C++, does not give me the expected output
Posted: Wed Jun 17, 2020 7:11 pm
I ran into a problem and was hoping to get some suggestions. I am working with a binary file from a software called Cloud Compare. The binary file has the contents described here, https://www.cloudcompare.org/doc/wiki/i ... ?title=SBF. The goal is to read in this file; correctly display the content onto the terminal; and then write the content onto a new file thus creating a duplicate. However, the issue is that the content displayed on the terminal is not correct ( ex. point count (NP) does not give the correct number ). I have tried reading in the contents of the input binary file in two ways.
Method 1:
// Read Header Data, takes up 64 bytes
char* dbfbuff = new char[2];
unsigned long long int np;
unsigned short int ns;
std::vector<double> xyz_shift; xyz_shift.resize(3);
char* unused_buffer = new char[28];
readFile.read(dbfbuff, 2);
std::cout << dbfbuff << std::endl;
std::cout << "After reading in header flag: " << readFile.tellg() << " bytes" << std::endl;
readFile.read((char*) &np, sizeof(unsigned long long int));
std::cout << "NP: " << np << std::endl;
std::cout << "After reading in NP: " << readFile.tellg() << " bytes" << std::endl;
Method 2:
std::stringstream ss;
ss << readFile.rdbuf();
long readSize = 0;
uint16_t dbfbuff;
uint64_t t2;
size_t np;
uint16_t ns;
ss >> dbfbuff;
readSize += sizeof(uint16_t);
std::cout << dbfbuff << std::endl;
std::cout << "After reading in header flag: " << readSize << " bytes" << std::endl;
ss >> t2;
np = static_cast<size_t>(t2);
readSize += sizeof(uint64_t);
std::cout << t2 << std::endl;
std::cout << "After reading in NP: " << readSize << " bytes" << std::endl;
An example of the issue Is that for method 1, the output for point count (NP) is a very very large positive number whereas for method 2 the output is a very small positive number, but the actual value should be in the millions. Do you have any suggestions for reading in the data from the binary file? Thank you for your time!
Cheers,
Daniel Mendez
Method 1:
// Read Header Data, takes up 64 bytes
char* dbfbuff = new char[2];
unsigned long long int np;
unsigned short int ns;
std::vector<double> xyz_shift; xyz_shift.resize(3);
char* unused_buffer = new char[28];
readFile.read(dbfbuff, 2);
std::cout << dbfbuff << std::endl;
std::cout << "After reading in header flag: " << readFile.tellg() << " bytes" << std::endl;
readFile.read((char*) &np, sizeof(unsigned long long int));
std::cout << "NP: " << np << std::endl;
std::cout << "After reading in NP: " << readFile.tellg() << " bytes" << std::endl;
Method 2:
std::stringstream ss;
ss << readFile.rdbuf();
long readSize = 0;
uint16_t dbfbuff;
uint64_t t2;
size_t np;
uint16_t ns;
ss >> dbfbuff;
readSize += sizeof(uint16_t);
std::cout << dbfbuff << std::endl;
std::cout << "After reading in header flag: " << readSize << " bytes" << std::endl;
ss >> t2;
np = static_cast<size_t>(t2);
readSize += sizeof(uint64_t);
std::cout << t2 << std::endl;
std::cout << "After reading in NP: " << readSize << " bytes" << std::endl;
An example of the issue Is that for method 1, the output for point count (NP) is a very very large positive number whereas for method 2 the output is a very small positive number, but the actual value should be in the millions. Do you have any suggestions for reading in the data from the binary file? Thank you for your time!
Cheers,
Daniel Mendez