Beispiel #1
0
 def simulate(self):
     """ Runs the particle simulation. Simulates one time step, dt, of the particle motion.
         Calculates the force between each pair of particles and updates particles' motion accordingly
     """
     # Main simulation loop
     for i in range(self.iterations):
         for a in self.particles:
             if a.fixed: continue
             ftot = vector(0,0,0) # total force acting on particle a
             for b in self.particles:
                 if a.negligible and b.negligible or a==b: continue
                 ab = a.pos - b.pos
                 ftot += ((K_COULOMB * a.charge * b.charge) / mag2(ab)) * norm(ab)
             a.vel += ftot / a.mass * self.dt # update velocity and position of a
             a.pos += a.vel * self.dt
             a.vtk_actor.pos(a.pos)
         if vp:
             vp.render(zoom=1.2)
             vp.camera.Azimuth(0.1) # rotate camera
Beispiel #2
0
    def _func(self, pars):
        self.params = pars

        d2sum, n = 0.0, self.source.N()
        srcpts = self.source.polydata().GetPoints()
        mpts = self.msource.polydata().GetPoints()
        rng = range(0,n, int(n/self.subsample))
        for i in rng:
            p1 = srcpts.GetPoint(i)
            p2 = self.transform(p1)
            tp = self.target.closestPoint(p2)
            d2sum += mag2(p2-tp)
            mpts.SetPoint(i, p2)

        d2sum /= len(rng)
        if d2sum<self.chi2:
            if d2sum<self.chi2*0.99: 
                print ( 'Emin ->', d2sum )
            self.chi2 = d2sum
        return d2sum
Beispiel #3
0
scals = np.abs(coords[:, 2])  # let the scalar be the z of point itself
fact = 1. / (bins - 1)  # conversion factor btw the 2 ranges

vp = Plotter(verbose=0)
vp.ztitle = 'z == scalar value'
cloud = vp.points(coords)

# fill the vtkImageData object
pb = ProgressBar(0, bins, c=4)
for iz in pb.range():
    pb.print()
    for iy in range(bins):
        for ix in range(bins):

            pt = vector(ix, iy, iz) * fact
            closestPointsIDs = cloud.closestPoint(pt, N=5, returnIds=True)

            num, den = 0, 0
            for i in closestPointsIDs:  # work out RBF manually on N points
                invdist = 1 / (mag2(coords[i] - pt) + 1e-06)
                num += scals[i] * invdist
                den += invdist
            img.SetScalarComponentFromFloat(ix, iy, iz, 0, num / den)

#vp.write(img, 'imgcube.tif') # or .vti

# set colors and transparencies along the scalar range
vol = Volume(img, c=['r', 'g', 'b'], alphas=[0.4, 0.8])  #vtkVolume
act = vp.points(coords / fact)
vp.show([vol, act], viewup='z')
Beispiel #4
0
# Align 2 shapes and for each vertex of the first draw
# and arrow to the closest point of the second.
# The source transformation is saved in actor.transform
#  rigid=True doesn't allow scaling
#
from vtkplotter import Plotter, printc, mag2
from vtkplotter.analysis import align

vp = Plotter(verbose=0, axes=4)

limb = vp.load('data/270.vtk', alpha=0.3)
rim = vp.load('data/270_rim.vtk')
rim.color('r').lineWidth(4)

arim = align(rim, limb, iters=100, rigid=True)
arim.color('g').lineWidth(4)
vp.actors.append(arim)

d = 0
prim = arim.coordinates()
for p in prim:
    cpt = limb.closestPoint(p)
    vp.arrow(p, cpt, c='g')
    d += mag2(p - cpt)  # square of residual distance

printc('ave. squared distance =', d / len(prim), c='g')

vp.show()