Ejemplo n.º 1
0
def withIcospheres(time_window=None):
  with open(os.path.join(baseDir, csvFilename), 'r') as csvfile:
    reader = csv.reader(csvfile, delimiter=',', quotechar='"')
    header = reader.next()
    peaks = [RealPoint.wrap(imap(float, peak.split('::'))) for peak in islice(header, 1, None)]
    # Template icosahedron
    ico = MeshMaker.createIcosahedron(2, radius)
    # Share lists of Point3f across all timepoints
    icos = [MeshMaker.copyTranslated(ico, peak.getFloatPosition(0), peak.getFloatPosition(1) , peak.getFloatPosition(2)) for peak in peaks]
    #
    univ = Image3DUniverse(512, 512)
    instants = TreeMap()
    #
    rows = reader if time_window is None else islice(reader, time_window[0], time_window[1])
    for row in rows:
      # Values mapped to 0-1: Color3f takes 3 values in domain [0, 1].
      # So: ensure the value is inside [minimum, maximum] range, then rezero by subtracting minimum, and divide by span (maximum - minimum)
      values = ((min(max(float(v), minimum), maximum) - minimum) / span for v in islice(row, 1, None))
      meshes = [CustomTriangleMesh(mesh, Color3f(v, v, v), 0)
                for v, mesh in izip(values, icos)]
      ci = ContentInstant(str(row[0]))
      ci.display(CustomMultiMesh(meshes)) # each mesh has its color
      ci.setLocked(True)
      print row[0]
      instants.put(int(row[0]), ci)
    
    print "n instants:", instants.size()
    univ.addContent(Content("deltaF/F", instants, False))
    univ.show()
    univ.updateStartAndEndTime(0, len(instants) -1)