def interpolate_points_to_spline_no_tangency(list_of_points, filter_pts=True, closed=False, tolerance=TOLERANCE): ''' GeomAPI_Interpolate is buggy: need to use `fix` in order to get the right points in... ''' def fix(li, _type): '''function factory for 1-dimensional TCol* types''' pts = _type(1, len(li)) for n, i in enumerate(li): pts.SetValue(n + 1, i) pts.thisown = False return pts if filter_pts: list_of_points = filter_points_by_distance(list_of_points, 0.1) fixed_points = fix(list_of_points, TColgp_HArray1OfPnt) try: interp = GeomAPI_Interpolate(fixed_points.GetHandle(), closed, tolerance) interp.Perform() if interp.IsDone(): return interp.Curve() except RuntimeError: # the exception was unclear raise RuntimeError('FAILED TO INTERPOLATE THE POINTS')
def interpolate_points_to_spline(list_of_points, start_tangent, end_tangent, filter_pts=True, tolerance=TOLERANCE): ''' GeomAPI_Interpolate is buggy: need to use `fix` in order to get the right points in... ''' def fix(li, _type): '''function factory for 1-dimensional TCol* types''' pts = _type(1, len(li)) for n, i in enumerate(li): pts.SetValue(n + 1, i) pts.thisown = False return pts if filter_pts: list_of_points = filter_points_by_distance(list_of_points, 0.1) fixed_points = fix(list_of_points, TColgp_HArray1OfPnt) try: interp = GeomAPI_Interpolate(fixed_points.GetHandle(), False, tolerance) interp.Load(start_tangent, end_tangent, False) interp.Perform() if interp.IsDone(): return interp.Curve() except RuntimeError: print("Failed to interpolate the shown points")
def interpolate_points_vectors_to_spline(list_of_points, list_of_vectors, vector_mask=None, tolerance=TOLERANCE): ''' build a curve from a set of points and vectors the vectors describe the tangent vector at the corresponding point ''' # GeomAPI_Interpolate is buggy: need to use `fix` in order to # get the right points in... assert len(list_of_points) == len( list_of_vectors), 'vector and point list not of same length' def fix(li, _type): '''function factory for 1-dimensional TCol* types''' pts = _type(1, len(li)) for n, i in enumerate(li): pts.SetValue(n + 1, i) pts.thisown = False return pts if vector_mask is not None: assert len(vector_mask) == len( list_of_points ), 'length vector mask is not of length points list nor []' else: vector_mask = [True for i in range(len(list_of_points))] fixed_mask = fix(vector_mask, TColStd_HArray1OfBoolean) fixed_points = fix(list_of_points, TColgp_HArray1OfPnt) fixed_vectors = fix(list_of_vectors, TColgp_Array1OfVec) try: interp = GeomAPI_Interpolate(fixed_points.GetHandle(), False, tolerance) interp.Load(fixed_vectors, fixed_mask.GetHandle(), False) interp.Perform() if interp.IsDone(): return interp.Curve() except RuntimeError: # the exception was unclear raise RuntimeError('FAILED TO INTERPOLATE THE POINTS')