Skip to content
Snippets Groups Projects
Commit c4ba6d2c authored by Boman Romain's avatar Boman Romain
Browse files

fix vector colours and fix Pt.normalize function

parent b73540ac
No related branches found
No related tags found
No related merge requests found
......@@ -145,8 +145,11 @@ class Pt:
return self.__mul__(scalar)
def __abs__(self):
return math.sqrt(self*self)
def normalize(self):
def normalized(self):
return self / abs(self)
def normalize(self):
n = self.normalized()
self.x = n.x
def cross(self, pt):
return Pt([self.x[1]*pt.x[2] - self.x[2]*pt.x[1], \
self.x[2]*pt.x[0] - self.x[0]*pt.x[2], \
......@@ -161,15 +164,15 @@ class Pt:
def scale_loads(loads, total_force):
"""scales the loads so that their sum is total_force
"""scale the loads so that their sum is total_force
"""
# computes the total force
# compute the total force
totf = Pt([0,0,0])
for f in loads:
totf = totf + f
print(f'\t|force| = {abs(totf)} (before scaling)')
# scales the forces to get the correct sum
# scale the forces to get the correct sum
scalingf = total_force/abs(totf)
print(f'\tscaling factor = {scalingf}')
for i in range(len(loads)):
......@@ -289,16 +292,16 @@ class SurfMesh:
darray.SetNumberOfValues(points.GetNumberOfPoints())
# manually compute vmin,vmax
vmin=+1.0e10
vmax=-1.0e10
# vmin=+1.0e10
# vmax=-1.0e10
for i,v in enumerate(vectors):
darray.InsertTuple3(i, v.x[0], v.x[1], v.x[2] )
n = abs(v)
if n<vmin: vmin=n
if n>vmax: vmax=n
# if n<vmin: vmin=n
# if n>vmax: vmax=n
darray.Modified()
print(f'range={darray.GetRange()}')
print(f'vmin, vmax={(vmin,vmax)}')
# print(f'range={darray.GetRange(-1)}')
# print(f'vmin, vmax={(vmin,vmax)}')
self.polydata.GetPointData().AddArray(darray)
self.polydata.GetPointData().SetActiveVectors("forces")
......@@ -331,24 +334,12 @@ class Arrows:
glyph.SetInputData(polydata)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(glyph.GetOutputPort())
mapper.ScalarVisibilityOn()
# lut = vtk.vtkLookupTable()
# lut.SetNumberOfColors(16)
# lut.SetHueRange(0., 0.667)
# lut.SetTableRange(0, 1) # valeurs bidons -> pas d'infl sur la texture
# lut.Build()
# mapper.SetLookupTable(lut)
mapper.SetScalarRange(0.004, 0.039)
vmin, vmax = polydata.GetPointData().GetVectors().GetRange(-1) # -1=norm
mapper.SetScalarRange(vmin, vmax)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
......
NOFF
1 0 0
-2.0 1.0 -1.0
-1.1 0.2 -0.2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment