I have a file format (.STL, stereo lithography, the structure is standard and can not be changed. Not to be confused with standard template library) that uses a 50 byte data structure. Reading from the HD directly leads to wrong data being read as 50 bytes is not a multiple of 4.
Out of the entire 50 byte structure, I only need 36 of those bytes. The method I am using right now to extract the data is to manually offset the read position of the file to the point where the next set of data begins, read off the 36 bytes into a temporary variable and then dump the data in the temporary variable into it's proper position on the array.
Here's the code chunk:
threePoints* output = new threePoints [numTriangles]; // create an array to hold the entire file
threePoints* temp = new threePoints [1]; // temp variable to pull data out of each "cell"
// extract each triangle individualy
for (int i = 0; i < numTriangles; i++)
{
stlFile.seekg (96 + i * 50, ios::beg); //read vertex data and put them into tempoary array
// offset = 80 header + 4 #triangles + 12 normal vector
stlFile.read(reinterpret_cast<char*>(temp), (36)); // read the next 36 data blocks into holder, 3 points * 3 axis * 4 bytes per float
output[i] = temp[0]; // dump values in holder into proper array
}
This method works but is slow. How would I go about doing this to make it faster and more efficiently?
Edit: I know manually disabling the byte alignment would solve this problem but I need to use the resulting array intensively and iterate over it many times. I've been told that disabling byte alignment can result in performance issues, thus i avoided it.