Beispiel #1
0
 def compute_triangulation(self):
   self.triangulation = iso_surface.triangulation(
     self.rho, self.positive_iso_level,
     map_extent=(1,1,1),
     from_here=self.from_here,
     to_there=self.to_there,
     periodic=self.periodic,
     ascending_normal_direction=False)
Beispiel #2
0
 def compute_triangulation(self):
   self.triangulation = iso_surface.triangulation(
     self.rho, self.positive_iso_level,
     map_extent=(1,1,1),
     from_here=self.from_here,
     to_there=self.to_there,
     periodic=self.periodic,
     ascending_normal_direction=False)
Beispiel #3
0
 def get_scene_data (self, rotation_center) :
   triangles = []
   r = self.radius
   c = rotation_center
   min = [ c[x] - float(r) for x in [0, 1, 2] ]
   max = [ c[x] + float(r) for x in [0, 1, 2] ]
   map_boundaries_cart = flex.vec3_double([min,max])
   bounds = self.unit_cell.fractionalize(sites_cart=map_boundaries_cart)
   rho = self.map.real_map()
   for iso_level in self.iso_levels :
     triangulation = iso_surface.triangulation(rho,
                               iso_level,
                               map_extent=(1,1,1),
                               from_here=bounds[0],
                               to_there=bounds[1],
                               periodic=True,
                               ascending_normal_direction=False
                             )
     triangles.append(triangulation)
   return map_scene(triangles, self.orthogonaliser, self.colors)
  def run(self, iso_level, from_here, to_there,
          verbose=0):
    """ Test triangulation of the iso-surface at the given iso-level """
    f = self.func

    if verbose:
      print "Testing %s" % f.__class__.__name__

    # triangulation of the iso-surface of the map
    t0 = time.time()
    s = iso_surface.triangulation(
      self.map, iso_level,
      map_extent=(1,1,1),
      from_here=from_here, to_there=to_there,
      periodic=self.periodic,
      lazy_normals=self.lazy_normals,
      ascending_normal_direction = not self.descending_normals)
    self.triangulation = s
    t1 = time.time()
    if verbose:
      print "iso-surface triangulation per se: %f s" % (t1-t0)

    # make sure there is something to test!!
    assert s.vertices.size() > 0

    outside = [ v for v in s.vertices
                if not(s.from_here <= v <=  s.to_there) ]
    assert not outside

    # the value of f on the vertices v shall be close to iso_level
    deltas = flex.double()
    for v in s.vertices:
      val = f(v)
      deltas.append(abs((val - iso_level)/iso_level))
    assert (deltas > 0.07).count(True) == 0

    # consistency check on the triangulation
    degenerates = []
    for v1, v2, v3 in s.triangles:
      assert v1 != v2 and v2 != v3 and v3 != v1
      for a,b in ((v1,v2), (v2,v3), (v3,v1)):
        if s.vertices[a] == s.vertices[b]: degenerates.append((a,b))
    if verbose:
      if degenerates:
        print "Degenerate edges for the isosurface of %s:" % f
        print degenerates
    self.degenerate_edges = degenerates

    # triangle edges and vertices
    edges = {}
    vertices = {}
    for v1,v2,v3 in s.triangles:
      vertices.update({v1:1, v2:1, v3:1})
      for a,b in ((v1,v2), (v2,v3), (v3,v1)):
        if a < b: e = (a,b)
        else: e = (b,a)
        edges[e] = edges.setdefault(e,0) + 1
    assert len(vertices) == len(s.vertices)
    missing = [ i for i in xrange(len(s.vertices)) if i not in vertices ]
    assert not missing, missing
    d = abs(matrix.col(self.grid_cell))
    bad_edge_multiplicities = []
    for e,p in edges.iteritems():
      v0, v1 = s.vertices[e[0]], s.vertices[e[1]]
      # conservative bound: edges shall be inscribed on voxel faces
      # this is just to catch vertex indexing errors resulting in edges
      # spanning several voxels
      d1 = abs(matrix.col(v0) - matrix.col(v1))
      assert d1 <= d or approx_equal(d1, d, eps=1e-3)
      assert p in (1,2)
      if not self.is_near_boundary(v0, v1):
        if p == 1:
          bad_edge_multiplicities.append((e[0], e[1]))
    assert not bad_edge_multiplicities

    # consistency check on the normals
    assert len(s.normals) == len(s.vertices)
    for i,v,n in zip(xrange(len(s.vertices)), s.vertices, s.normals):
      v, n = matrix.col(v), matrix.col(n)
      abs_n = abs(n)
      if abs_n == 0:
        for edge in degenerates:
          if i in edge: break
        else:
          raise "zero normal not on a vertex at the end of a degenerate edge"
      else:
        assert abs(abs(n) - 1) < 1e-12
        outward = v + 0.05*n
        inward  = v - 0.05*n
        if s.ascending_normal_direction:
          assert f(outward) > iso_level > f(inward), i
        else:
          assert f(outward) < iso_level < f(inward), i