예제 #1
0
def communityOrientationStats():
    """
    Calculate the orientation of all bacilli as the dot product from each of the Euclidean 
    basis vectors in R^3.
    
    :@rtype: tuple
    :@return: 
    """
    bdots = [[],[],[]]
    fdots = [[],[],[]]
    sRes = []
    bacilli = []
    filaments = []
    #lengths = []
    xbasis = Vec3f(1,0,0)
    ybasis = Vec3f(0,1,0)
    zbasis = Vec3f(0,0,1)
    
    for i, bact in enumerate(DataStore.Bacteria()):
        blen = len(bact.Markers)
        if blen == 2:
            bacilli.append(DataStore.BacteriaActors()[i])
            v = bact.Markers[0] - bact.Markers[1]
            #lengths.append(v.length())
            v.normalize()
            bdots[0].append(xbasis.dot(v))
            bdots[1].append(ybasis.dot(v))
            bdots[2].append(zbasis.dot(v))
        # calculate filament orientations b/t each two markers
        if blen > 2:
            filaments.append(i)
            _, _, _, splinePoints = generateSpline(bact.Markers)
            sRes.append(len(splinePoints) - 1)  # -1 b/c we're using every pair, not every point
            sMarkers = [Vec3f(point) for point in splinePoints]
            for j in range(len(sMarkers)-1):
                v = sMarkers[j] - sMarkers[j+1]
                v.normalize()
                fdots[0].append(xbasis.dot(v))
                fdots[1].append(ybasis.dot(v))
                fdots[2].append(zbasis.dot(v))
            
            
    
#    data = np.hstack((np.array(angles).T, np.array(lengths)[:,np.newaxis]))
#    writeCSV(data, ['x','y','z','len'], 'olen.csv')

    return bacilli, filaments, bdots, fdots, sRes
예제 #2
0
 def _createFilamentSpline(self, markers):
     profileData = vtk.vtkPolyData()
     points, scalars, t, sList = generateSpline(markers)
     fradius = self.actor_radius * 1.5
     
     # Create the polyline.
     lines = vtk.vtkCellArray()
     lines.InsertNextCell(len(sList))
     for i in range(len(sList)):
         lines.InsertCellPoint(i)
      
     profileData.SetPoints(points)
     profileData.SetLines(lines)
     profileData.GetPointData().SetScalars(scalars)
     
     # Add thickness to the resulting line.
     profileTubes = vtk.vtkTubeFilter()
     profileTubes.SetNumberOfSides(20)
     profileTubes.SetInput(profileData)
     profileTubes.SetRadius(fradius)
         
     profileMapper = vtk.vtkPolyDataMapper()
     profileMapper.SetInput(profileTubes.GetOutput())
     profileMapper.SetScalarRange(0,t)
     profileMapper.ScalarVisibilityOff()
     
     profile = vtk.vtkActor()
     profile.SetMapper(profileMapper)
     profile.GetProperty().SetDiffuseColor(self.color.r, self.color.g, self.color.b)
 #    profile.GetProperty().SetSpecular(.3)
 #    profile.GetProperty().SetSpecularPower(30)
 
     markers[0].GetProperty().SetDiffuseColor(self.color.r, self.color.g, self.color.b)
     markers[-1].GetProperty().SetDiffuseColor(self.color.r, self.color.g, self.color.b)
 
     # Add capping spheres
     filament = vtk.vtkAssembly()
     filament.AddPart(self.CreateMarker(Vec3f(markers[0].GetCenter()), fradius))
     filament.AddPart(profile)
     filament.AddPart(self.CreateMarker(Vec3f(markers[-1].GetCenter()), fradius))
     
     return filament