- merged in the Autolevelling branch and made some PEP8 changes to the bilinearInterpolator.py file
This commit is contained in:
parent
3ba000a097
commit
5de1701b3d
|
@ -15,11 +15,13 @@ CHANGELOG for FlatCAM beta
|
||||||
- In Excellon Object UI fixed the milling geometry generation
|
- In Excellon Object UI fixed the milling geometry generation
|
||||||
- updated the translations strings to the changes in the source code
|
- updated the translations strings to the changes in the source code
|
||||||
- some strings changed
|
- some strings changed
|
||||||
|
- made the Properties checkbox in the Object UI into a checkable button and added to it an icon
|
||||||
- fixed crash on using shortcut for creating a new Document Object
|
- fixed crash on using shortcut for creating a new Document Object
|
||||||
- fixed Cutout Tool to work with the endxy parameter
|
- fixed Cutout Tool to work with the endxy parameter
|
||||||
- added the exclusion parameters for Drilling Tool to the Preferences area
|
- added the exclusion parameters for Drilling Tool to the Preferences area
|
||||||
- cascaded_union() method will be deprecated in Shapely 1.8 in favor of unary_union; replaced the usage of cascaded_union with unary_union in all the app
|
- cascaded_union() method will be deprecated in Shapely 1.8 in favor of unary_union; replaced the usage of cascaded_union with unary_union in all the app
|
||||||
- added some strings to the translatable strings and updated the translation strings
|
- added some strings to the translatable strings and updated the translation strings
|
||||||
|
- merged in the Autolevelling branch and made some PEP8 changes to the bilinearInterpolator.py file
|
||||||
|
|
||||||
20.10.2020
|
20.10.2020
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import csv
|
# import csv
|
||||||
import math
|
import math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
class bilinearInterpolator():
|
|
||||||
|
class bilinearInterpolator:
|
||||||
"""
|
"""
|
||||||
This class takes a collection of 3-dimensional points from a .csv file.
|
This class takes a collection of 3-dimensional points from a .csv file.
|
||||||
It contains a bilinear interpolator to find unknown points within the grid.
|
It contains a bilinear interpolator to find unknown points within the grid.
|
||||||
|
@ -15,10 +16,7 @@ class bilinearInterpolator():
|
||||||
Constructor takes a file with a .csv extension and creates an evenly-spaced 'ideal' grid from the data points.
|
Constructor takes a file with a .csv extension and creates an evenly-spaced 'ideal' grid from the data points.
|
||||||
This is done to get around any floating point errors that may exist in the data
|
This is done to get around any floating point errors that may exist in the data
|
||||||
"""
|
"""
|
||||||
def __init__(
|
def __init__(self, pointsFile):
|
||||||
self,
|
|
||||||
pointsFile
|
|
||||||
):
|
|
||||||
|
|
||||||
self.pointsFile = pointsFile
|
self.pointsFile = pointsFile
|
||||||
self.points = np.loadtxt(self.pointsFile, delimiter=',')
|
self.points = np.loadtxt(self.pointsFile, delimiter=',')
|
||||||
|
@ -28,8 +26,8 @@ class bilinearInterpolator():
|
||||||
|
|
||||||
# generate ideal grid to match actually probed points -- this is due to floating-point error issues
|
# generate ideal grid to match actually probed points -- this is due to floating-point error issues
|
||||||
idealGrid = ([
|
idealGrid = ([
|
||||||
[(x,y) for x in np.linspace(self.xMin,self.xMax,self.xCount, True)]
|
[(x, y) for x in np.linspace(self.xMin, self.xMax, self.xCount, True)]
|
||||||
for y in np.linspace(self.yMin,self.yMax,self.yCount, True)
|
for y in np.linspace(self.yMin, self.yMax, self.yCount, True)
|
||||||
])
|
])
|
||||||
|
|
||||||
self._probedGrid = [[0] * self.yCount for i in range(0, self.xCount)]
|
self._probedGrid = [[0] * self.yCount for i in range(0, self.xCount)]
|
||||||
|
@ -41,7 +39,7 @@ class bilinearInterpolator():
|
||||||
for probed in self.points:
|
for probed in self.points:
|
||||||
# find closest point in ideal grid that corresponds to actual tested point
|
# find closest point in ideal grid that corresponds to actual tested point
|
||||||
# put z value in correct index
|
# put z value in correct index
|
||||||
sqDist = pow(probed[0] - idealPoint[0], 2) + pow(probed[1] - idealPoint[1],2)
|
sqDist = pow(probed[0] - idealPoint[0], 2) + pow(probed[1] - idealPoint[1], 2)
|
||||||
if sqDist <= minSqDist:
|
if sqDist <= minSqDist:
|
||||||
minSqDist = sqDist
|
minSqDist = sqDist
|
||||||
indexX = rowIndex
|
indexX = rowIndex
|
||||||
|
@ -49,13 +47,13 @@ class bilinearInterpolator():
|
||||||
closestProbed = probed
|
closestProbed = probed
|
||||||
self.probedGrid[indexY][indexX] = closestProbed
|
self.probedGrid[indexY][indexX] = closestProbed
|
||||||
|
|
||||||
"""
|
|
||||||
Bilinear interpolation method to determine unknown z-values within grid of known z-values.
|
|
||||||
|
|
||||||
NOTE: If one axis is outside the grid, linear interpolation is used instead.
|
|
||||||
If both axes are outside of the grid, the z-value of the closest corner of the grid is returned.
|
|
||||||
"""
|
|
||||||
def Interpolate(self, point):
|
def Interpolate(self, point):
|
||||||
|
"""
|
||||||
|
Bilinear interpolation method to determine unknown z-values within grid of known z-values.
|
||||||
|
|
||||||
|
NOTE: If one axis is outside the grid, linear interpolation is used instead.
|
||||||
|
If both axes are outside of the grid, the z-value of the closest corner of the grid is returned.
|
||||||
|
"""
|
||||||
lin = False
|
lin = False
|
||||||
|
|
||||||
if point[0] < self.xMin:
|
if point[0] < self.xMin:
|
||||||
|
@ -68,8 +66,8 @@ class bilinearInterpolator():
|
||||||
ix1 = math.floor((point[0] - self.xMin)/self.xSpacing)
|
ix1 = math.floor((point[0] - self.xMin)/self.xSpacing)
|
||||||
ix2 = math.ceil((point[0] - self.xMin)/self.xSpacing)
|
ix2 = math.ceil((point[0] - self.xMin)/self.xSpacing)
|
||||||
|
|
||||||
def interpolatePoint(p1, p2, p, axis):
|
def interpolatePoint(p1, p2, pt, axis):
|
||||||
return (p2[2]*(p[axis] - p1[axis]) + p1[2]*(p2[axis] - p[axis]))/(p2[axis] - p1[axis])
|
return (p2[2]*(pt[axis] - p1[axis]) + p1[2]*(p2[axis] - pt[axis]))/(p2[axis] - p1[axis])
|
||||||
|
|
||||||
if point[1] < self.yMin:
|
if point[1] < self.yMin:
|
||||||
if lin:
|
if lin:
|
||||||
|
@ -78,11 +76,12 @@ class bilinearInterpolator():
|
||||||
elif point[1] > self.yMax:
|
elif point[1] > self.yMax:
|
||||||
if lin:
|
if lin:
|
||||||
return self.probedGrid[ix1][self.yCount - 1][2]
|
return self.probedGrid[ix1][self.yCount - 1][2]
|
||||||
return interpolatePoint(self.probedGrid[ix1][self.yCount - 1], self.probedGrid[ix2][self.yCount - 1], point, 0)
|
return interpolatePoint(
|
||||||
|
self.probedGrid[ix1][self.yCount - 1], self.probedGrid[ix2][self.yCount - 1], point, 0)
|
||||||
else:
|
else:
|
||||||
iy1 = math.floor((point[1] - self.yMin)/self.ySpacing)
|
iy1 = math.floor((point[1] - self.yMin)/self.ySpacing)
|
||||||
iy2 = math.ceil((point[1] - self.yMin)/self.ySpacing)
|
iy2 = math.ceil((point[1] - self.yMin)/self.ySpacing)
|
||||||
#if x was at an extrema, but y was not, perform linear interpolation on x axis
|
# if x was at an extrema, but y was not, perform linear interpolation on x axis
|
||||||
if lin:
|
if lin:
|
||||||
return interpolatePoint(self.probedGrid[ix1][iy1], self.probedGrid[ix1][iy2], point, 1)
|
return interpolatePoint(self.probedGrid[ix1][iy1], self.probedGrid[ix1][iy2], point, 1)
|
||||||
|
|
||||||
|
@ -104,7 +103,7 @@ class bilinearInterpolator():
|
||||||
|
|
||||||
r1 = specialDiv(point[0]-x1, x2-x1)*Q21 + specialDiv(x2-point[0], x2-x1)*Q11
|
r1 = specialDiv(point[0]-x1, x2-x1)*Q21 + specialDiv(x2-point[0], x2-x1)*Q11
|
||||||
r2 = specialDiv(point[0]-x1, x2-x1)*Q22 + specialDiv(x2-point[0], x2-x1)*Q12
|
r2 = specialDiv(point[0]-x1, x2-x1)*Q22 + specialDiv(x2-point[0], x2-x1)*Q12
|
||||||
p = specialDiv(point[1]-y1, y2-y1)*r2 + specialDiv(y2-point[1], y2-y1)*r1
|
p = specialDiv(point[1]-y1, y2-y1)*r2 + specialDiv(y2-point[1], y2-y1)*r1
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
@ -124,4 +123,4 @@ class bilinearInterpolator():
|
||||||
axisRange = axisMax - axisMin
|
axisRange = axisMax - axisMin
|
||||||
axisCount = round((axisRange/axisSpacing) + 1)
|
axisCount = round((axisRange/axisSpacing) + 1)
|
||||||
|
|
||||||
return axisMin, axisMax, axisSpacing, axisCount
|
return axisMin, axisMax, axisSpacing, axisCount
|
Loading…
Reference in New Issue