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

view forces

parent bdf8df71
No related branches found
No related tags found
No related merge requests found
......@@ -281,6 +281,28 @@ class SurfMesh:
self.mapper = mapper
self.actor = actor
def add_vectors(self, vectors):
darray = vtk.vtkDoubleArray()
darray.SetNumberOfComponents(3)
darray.SetName("forces")
points = self.polydata.GetPoints()
darray.SetNumberOfValues(points.GetNumberOfPoints())
# manually compute vmin,vmax
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
darray.Modified()
print(f'range={darray.GetRange()}')
print(f'vmin, vmax={(vmin,vmax)}')
self.polydata.GetPointData().AddArray(darray)
self.polydata.GetPointData().SetActiveVectors("forces")
@staticmethod
def load(off_file, vertices=True):
fullpath = os.path.join(os.path.dirname(__file__), off_file)
......@@ -288,6 +310,56 @@ class SurfMesh:
mesh = SurfMesh(nodes, tris, vertices)
return mesh
class Arrows:
def __init__(self, polydata):
arrow = vtk.vtkArrowSource()
# VTK Default Parameters
arrow.SetTipResolution(6)
arrow.SetTipRadius(0.1)
arrow.SetTipLength(0.35)
arrow.SetShaftResolution(6)
arrow.SetShaftRadius(0.03)
glyph = vtk.vtkGlyph3D()
glyph.SetSourceConnection(arrow.GetOutputPort())
glyph.SetVectorModeToUseVector()
glyph.SetColorModeToColorByVector()
glyph.SetScaleModeToScaleByVector()
glyph.SetScaleFactor(10.0)
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)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
self.arrow = arrow
self.glyph = glyph
self.mapper = mapper
self.actor = actor
# ------------------------------------------------------------------------------
class View:
......
......@@ -10,19 +10,32 @@ if __name__=="__main__":
muscle = SurfMesh.load('loadings/muscle.ply')
muscleF = SurfMesh.load('loadings/muscleF.off')
# create vector field
focalnodes, _ = load_msh('loadings/muscleF.off')
nodes, tris = load_msh('loadings/muscle.ply')
loads = create_uniform_loads(nodes, tris, \
total_force=10., target=focalnodes[0])
muscle.add_vectors(loads)
forces = Arrows(muscle.polydata)
view = View()
view.addActors(surface.actor)
# view.addActors(surface.actor)
view.addActors(muscle.actor)
view.addActors(muscleF.actor)
view.addActors(forces.actor)
surface.actor.GetProperty().SetPointSize(0.0)
surface.actor.GetProperty().RenderPointsAsSpheresOff ()
surface.actor.GetProperty().SetRepresentationToSurface()
# surface.actor.GetProperty().SetPointSize(0.0)
# surface.actor.GetProperty().RenderPointsAsSpheresOff ()
# surface.actor.GetProperty().SetRepresentationToSurface()
# surface.actor.GetProperty().SetOpacity(0.5)
muscle.mapper.SetResolveCoincidentTopologyToPolygonOffset()
muscle.actor.GetProperty().SetColor( colors.GetColor3d('red') )
# muscle.actor.GetProperty().EdgeVisibilityOn()
muscle.actor.GetProperty().SetOpacity(0.5)
muscle.actor.GetProperty().EdgeVisibilityOn()
muscle.actor.GetProperty().SetPointSize(1.0)
muscleF.actor.GetProperty().SetPointSize(15.0)
......
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