Ok, I’ve kind of let this thread die. Both because I have been busy, and the posts I have made haven’t been very clear.
Today I hope to put that back on track.
- Challenges thus far.
Mainly, I have a lack of a reliable mesh which I know exists in the file. There are commercial software which can convert the mesh data in the .cdt to .stl format or view/analyze the file. The two I have access to give different results as follows.
-“Dental Shaper for Rhino” gives a mesh which is 1.3% larger in every dimension thank does the “Delcam Exchange viewer”
-“Dental Shaper for Rhino” gives a different domain and range for the x coordinates (although the mesh is not mirrored) so this indicates a funky coordinate system convention in one of the softwares (either the file originator, dental shaper or delcam exchangee).
- Even with this challenge, let’s assume that either Delcam Exchange or Dental Shaper is correct and look for just the vertex coordinate data.
Here we see the discrepancy in the bounding box sise, and the x coordinate sytem…
Delcam Bounding Box: [x:[-14.75, -1.25], y:[1.25,17.45] z:[.025, 3.70]]
Rhino Bounding Box: [x:[1.27, 14.99], y:[1.27,17.73] z:[.025, 3.76]]
-Assume that normal data and vertex data are both stored as 32Floats.
-Assume that the normals are normalized, meaning the maximum float value in any of the normal vectors is 1.
Here is the script I use to look for all the floating point values in the .CDT file with an absolute value greater than 1 and less than 17.73. That should exclude any of the the normal data, and account for the discrepancy in the x axis bounding box.
import bpy
import struct
import math
#Load the file
file = 'C:/patmo.cdt'
CDT = open(file,'rb')
cdt = CDT.read()
#Load the info from the .stl object imported int Blender
ob = bpy.data.objects['DentalShaper']
me = ob.data
#count all the floating point numbers in the .stl with abs
# greater than 1
xs = [abs(v.co[0]) for v in me.vertices if abs(v.co[0])>1]
ys = [abs(v.co[1]) for v in me.vertices if abs(v.co[0])>1]
zs = [abs(v.co[2]) for v in me.vertices if abs(v.co[0])>1]
n_floats = len(xs) + len(ys) + len(zs)
#isolate the maximum
maximum = max([max(xs),max(ys),max(zs)])
print(maximum)
#Byte in the .cdt file which we suspect the data begins
#eg, right before 55AA55AAField0_1
beg = 11348
end = 1189059 #is the ending byte of "Field0_8"
#32 bit Floating point numbers are 4 bytes long
chunk = 4
steps = math.floor((end - beg)/chunk) #this should be an integer, but just in case
#keep track of the total number we find.
total_floats = 0
#try offset of 0,1,2,3 to find every possible float value
for offset in range(0,4):
#add space and identify the offset
print(' ')
print('The offset is ' + str(offset))
#we could just count, but memory is cheap, so i will store
#for later use.
possible = []
#upack the file in 4 byte chunks, starting at the 55AA55AA
for i in range(0,steps):
a = beg + offset + i*chunk
b = a + chunk
#use little endian floating point
j = struct.unpack('<f',cdt[a:b])[0]
J = abs(j)
#test to see is the value is valid
if J < maximum and J > 1:
#keep track of it if it is
possible.append(j)
#display how many possible floating point values we think we have
L = len(possible)
total_floats += L
print(L)
print('the total number of valid float values in the stl file is ' + str(n_floats))
print('the total number of valid float values in the cdt file is ' + str(total_floats))
The results are as follows:
- Approximately 4700 to 4800 float values are found at each offset
- 18507 floating point numbers in the .stl coordinates w/ an absolute value >1
- 19115 floating point numbers in the .cdt file w/ an absolute value >1
- A difference of 608
So, pretty good results. 608/18507 is only 3% “extra” floating point values in the .cdt file which I think is probably just random error in the sense that I am unpacking all the data in 4 byte chunks…now, I need to examine the spacing between said numbers!!