Exemple #1
0
  def execute(self,obj,event):
    start = time.time()
    self.ball.Modified()
    self.ball.Update()
    rate = 1/(time.time() - start)
    #print rate

    iren = obj
    iren.GetRenderWindow().Render()
    
    if (self.timer_count % 500 == 0):
      print "collision"
      
      cm = self.ball.GetCollisionModel()
      normals = cm.GetCellNormals()
      cid = 26
      cps = [14,5,6]
      cn = normals.GetTuple3(cid)
      for i in cps:
        pn = cm.GetPointNormals().GetTuple3(i)
        c = vtkesqui.vtkCollision()
        c.SetObjectId(0)
        c.SetModelId(0)
        c.SetCellId(cid)
        c.SetCellNormal(cn)
        c.SetPointId(i)
        c.SetPoint(cm.GetOutput().GetPoint(i))
        d = 0.2*random.random()
        dsp = [0.0,0.0,0.0]
        j = 0
        for n in pn:
          dsp[j] = d*n
          j = j+1

        c.SetPointDisplacement(dsp)
        c.SetDistance(d)

        cm.AddCollision(c)

    self.timer_count += 1
input = sphere.GetOutput()
source = vtk.vtkPolyData()
source.DeepCopy(input)

#Model input mesh will be adapted to the source
model = vtkesqui.vtkCollisionModel()
model.SetId(0)
model.SetInput(input)
model.SetRadius(0.02)
model.DisplayCollisionsOn()
model.Initialize()

#Insert a few collisions to the model
p = [12, 23, 14, 25]
for i in p:
  c = vtkesqui.vtkCollision()
  c.SetModelId(0)
  c.SetPointId(i)
  c.SetDistance(random.random()*0.5)
  model.AddCollision(c)

model.Update()

ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Display model output (smoothed polydata)
actor = model.GetActor()