예제 #1
0
    def main(self, surf_coord, surf_topo, faces_csv, vertices_csv,
             vertexlimits_csv):
        F = LoadFaces.fromParent(self).setInput(surf_topo).run().getOutput(
            'faces')
        F = numpy.array(F, int)
        with open(faces_csv, 'w') as fp:
            for line in F:
                fp.write(','.join([str(v) for v in line]) + '\n')

        V = LoadVertices.fromParent(self).setInput(surf_coord).run().getOutput(
            'vertices')
        V = numpy.array(V, float)
        with open(vertices_csv, 'w') as fp:
            for line in V:
                fp.write(','.join([str(v) for v in line]) + '\n')

        minmax = [
            ','.join([str(v) for v in V.min(axis=0)]),
            ','.join([str(v) for v in V.max(axis=0)])
        ]
        with open(vertexlimits_csv, 'w') as fp:
            fp.write('\n'.join(minmax))

        return FancyDict(faces_csv=faces_csv,
                         vertices_csv=vertices_csv,
                         vertexlimits_csv=vertexlimits_csv)
예제 #2
0
  def main(self,surf_coord,surf_topo,faces_csv,vertices_csv,vertexlimits_csv):
    F = LoadFaces.fromParent(self).setInput(surf_topo).run().getOutput('faces')
    F = numpy.array(F,int)
    with open(faces_csv,'w') as fp:
      for line in F:
        fp.write(','.join([str(v) for v in line])+'\n')
    
    V = LoadVertices.fromParent(self).setInput(surf_coord).run().getOutput('vertices')
    V = numpy.array(V,float)
    with open(vertices_csv,'w') as fp:
      for line in V:
        fp.write(','.join([str(v) for v in line])+'\n')

    minmax = [
      ','.join([str(v) for v in V.min(axis=0)]),
      ','.join([str(v) for v in V.max(axis=0)])
    ]
    with open(vertexlimits_csv,'w') as fp:
      fp.write('\n'.join(minmax))

    return FancyDict(
      faces_csv = faces_csv,
      vertices_csv = vertices_csv,
      vertexlimits_csv = vertexlimits_csv
    )
예제 #3
0
  def main(self,gm_vertices_csv,wm_vertices_csv,mid_vertices_csv,mid_vertexlimits_csv,wm_pct):
    V_gm = LoadVertices.fromParent(self).setInput(gm_vertices_csv).run().getOutput('vertices')
    V_gm = numpy.array(V_gm,float)

    V_wm = LoadVertices.fromParent(self).setInput(wm_vertices_csv).run().getOutput('vertices')
    V_wm = numpy.array(V_wm,float)
    
    V = V_gm*(1-0.01*wm_pct)+V_wm*0.01*wm_pct
    with open(mid_vertices_csv,'w') as fp:
      for line in V:
        fp.write(','.join([str(v) for v in line])+'\n')

    minmax = [
      ','.join([str(v) for v in V.min(axis=0)]),
      ','.join([str(v) for v in V.max(axis=0)])
    ]
    with open(mid_vertexlimits_csv,'w') as fp:
      fp.write('\n'.join(minmax))

    return FancyDict(
      mid_vertices_csv = mid_vertices_csv,
      mid_vertexlimits_csv = mid_vertexlimits_csv
    )
예제 #4
0
  def main(self,vertices_csv,faces_csv,datavolume_nii,paintmode):
    V = LoadVertices.fromParent(self).setInput(vertices_csv).run().getOutput('vertices')
    if paintmode=='F':
      F = LoadFaces.fromParent(self).setInput(faces_csv).requestOutput('faces')
      X = FaceCenters.fromParent(self).setInput(F,V).requestOutput('centers')
    elif paintmode=='V':
      X = V
    elif paintmode=='FV':
      F = LoadFaces.fromParent(self).setInput(faces_csv).run().getOutput('faces')
      X = FaceVertexCenters.fromParent(self).setInput(F,V).requestOutput('centers')
    else:
      raise RuntimeError('Invalid paintmode "{}".'.format(paintmode))
    nii = nibabel.load(datavolume_nii)
    affine = nii.get_header().get_sform()
    dataVolume = nii.get_data()
    indexedPoints = IndexedPoints.fromParent(self).setInput(
      X,affine
    )
    labelsFromVolume = LabelsFromVolume.fromParent(self).setInput(
      labelVolume = dataVolume,
      points = indexedPoints.requestOutput('points'),
      bgIndex = 0
    )
    meshdata = labelsFromVolume.run().getOutput('labels').tolist()
    meshdata = [str(v) for v in meshdata]
    if paintmode == 'FV':
      offset = numpy.cumsum([0]+[len(line) for line in F])
      meshdata = [','.join(labels[offset[i]:offset[i+1]]) for i in range(0,len(F))]

    meshdata_csv = self.tempfile('meshdata.csv')
    with open(meshdata_csv,'w') as fp:
      fp.write('\n'.join(meshdata))
    
    minmax = numpy.array(V,float)
    minmax = [
      ','.join([str(v) for v in minmax.min(axis=0)]),
      ','.join([str(v) for v in minmax.max(axis=0)])
    ]
    vertexlimits_csv = self.tempfile('vertexlimits.csv')
    with open(vertexlimits_csv,'w') as fp:
      fp.write('\n'.join(minmax))

    return FancyDict(
      vertexlimits_csv = vertexlimits_csv,
      meshdata_csv = meshdata_csv
    )
예제 #5
0
  def main(self,space,mesh,deformation,labelvolume,labelnames,name2value,colormap,colorlimits,spacesroot,jsonrpc2):
    spacesFolder = '{}/{}'.format(spacesroot,space)
    with open( '{}/config.json'.format(spacesFolder) ) as fp:
      spaceConfig = json.load(fp)
    meshConfig = spaceConfig['meshes'][mesh]['deformations']['fiducial']

    facesFile = None
    verticesFile = None
    faceLabels = None
    label2value = None
    label2rgb = None
    if labelvolume:
      nii = nibabel.load(labelvolume)
      hdr = nii.get_header()
      img = nii.get_data()
      sform = hdr.get_sform()
      bgIndex = 0

      facesFile = '{}/meshes/{}'.format(spacesFolder,meshConfig['faces'])
      verticesFile = '{}/meshes/{}'.format(spacesFolder,meshConfig['vertices'])
      F = LoadFaces.fromParent(self).setInput(facesFile).requestOutput('faces')
      V = LoadVertices.fromParent(self).setInput(verticesFile).requestOutput('vertices')
      X = FaceCenters.fromParent(self).setInput(F,V).requestOutput('centers')
      faceCenters = IndexedPoints.fromParent(self).setInput(X,sform).requestOutput('points')
      faceLabels = LabelsFromVolume.fromParent(self).setInput(
        labelVolume = img,
        points = faceCenters,
        bgIndex = bgIndex
      ).run().requestOutput('labels')
      with open(self.tempfile('facelabels.csv'),'w') as fp:
        fp.write('\n'.join([str(v) for v in faceLabels]))      
      
      getLabelValues = GetLabelValues.fromParent(self).setInput(faceLabels,labelnames,name2value,colormap,colorlimits)
      label2value = getLabelValues.requestOutput('label2value')
      label2rgb = getLabelValues.requestOutput('label2rgb')
      colormap = getLabelValues.requestOutput('colormap')
    
    meshConfig = spaceConfig['meshes'][mesh]['deformations'][deformation]
    deformedVerticesFile = '{}/meshes/{}'.format(spacesFolder,meshConfig['vertices'])
    deformedFacesFile = '{}/meshes/{}'.format(spacesFolder,meshConfig['faces'])
    if deformedVerticesFile != verticesFile: 
      V = LoadVertices.fromParent(self).setInput(deformedVerticesFile).requestOutput('vertices')
    if deformedFacesFile != facesFile: 
      F = LoadFaces.fromParent(self).setInput(deformedFacesFile).requestOutput('faces')
    if labelnames:
      with open(labelnames) as fp:
        labelnames = json.load(fp)
    
    generateX3D = GenerateX3D.fromParent(self).setInput(
      vertices = V,
      faces = F,
      facelabels = faceLabels,
      label2rgb = label2rgb,
      label2name = labelnames,
      label2value = label2value,
      colormap = colormap
    )
    return FancyDict(
      x3dfile = generateX3D.requestOutput('x3dfile'),
      x3dviewer = generateX3D.requestOutput('x3dviewer'),
      x3d_files = generateX3D.requestOutput('x3dviewer_files')
    )
예제 #6
0
    def main(self, space, mesh, deformation, labelvolume, labelnames,
             name2value, colormap, colorlimits, spacesroot, jsonrpc2):
        spacesFolder = '{}/{}'.format(spacesroot, space)
        with open('{}/config.json'.format(spacesFolder)) as fp:
            spaceConfig = json.load(fp)
        meshConfig = spaceConfig['meshes'][mesh]['deformations']['fiducial']

        facesFile = None
        verticesFile = None
        faceLabels = None
        label2value = None
        label2rgb = None
        if labelvolume:
            nii = nibabel.load(labelvolume)
            hdr = nii.get_header()
            img = nii.get_data()
            sform = hdr.get_sform()
            bgIndex = 0

            facesFile = '{}/meshes/{}'.format(spacesFolder,
                                              meshConfig['faces'])
            verticesFile = '{}/meshes/{}'.format(spacesFolder,
                                                 meshConfig['vertices'])
            F = LoadFaces.fromParent(self).setInput(facesFile).requestOutput(
                'faces')
            V = LoadVertices.fromParent(self).setInput(
                verticesFile).requestOutput('vertices')
            X = FaceCenters.fromParent(self).setInput(
                F, V).requestOutput('centers')
            faceCenters = IndexedPoints.fromParent(self).setInput(
                X, sform).requestOutput('points')
            faceLabels = LabelsFromVolume.fromParent(self).setInput(
                labelVolume=img, points=faceCenters,
                bgIndex=bgIndex).run().requestOutput('labels')
            with open(self.tempfile('facelabels.csv'), 'w') as fp:
                fp.write('\n'.join([str(v) for v in faceLabels]))

            getLabelValues = GetLabelValues.fromParent(self).setInput(
                faceLabels, labelnames, name2value, colormap, colorlimits)
            label2value = getLabelValues.requestOutput('label2value')
            label2rgb = getLabelValues.requestOutput('label2rgb')
            colormap = getLabelValues.requestOutput('colormap')

        meshConfig = spaceConfig['meshes'][mesh]['deformations'][deformation]
        deformedVerticesFile = '{}/meshes/{}'.format(spacesFolder,
                                                     meshConfig['vertices'])
        deformedFacesFile = '{}/meshes/{}'.format(spacesFolder,
                                                  meshConfig['faces'])
        if deformedVerticesFile != verticesFile:
            V = LoadVertices.fromParent(self).setInput(
                deformedVerticesFile).requestOutput('vertices')
        if deformedFacesFile != facesFile:
            F = LoadFaces.fromParent(self).setInput(
                deformedFacesFile).requestOutput('faces')
        if labelnames:
            with open(labelnames) as fp:
                labelnames = json.load(fp)

        generateX3D = GenerateX3D.fromParent(self).setInput(
            vertices=V,
            faces=F,
            facelabels=faceLabels,
            label2rgb=label2rgb,
            label2name=labelnames,
            label2value=label2value,
            colormap=colormap)
        return FancyDict(
            x3dfile=generateX3D.requestOutput('x3dfile'),
            x3dviewer=generateX3D.requestOutput('x3dviewer'),
            x3d_files=generateX3D.requestOutput('x3dviewer_files'))