Exemple #1
0
def pRepos(ren,objName):
    tag = "%s_%s" % (ren[0],objName)
    
    try:
        vis.register(ren,objName)
    except:
        vis.polyRm(ren,objName)
        vis.register(ren,objName)
        
    vtkName = Repository.ExportToVtk(objName)
    Map = [None]*2
    Map[0] = "p_map_"+tag
    Map[1] = vtk.vtkPolyDataMapper()
    Map[1].SetInputData(vtkName)
    Map[1].ScalarVisibilityOff()
    
    act = [None]*2
    act[0] = "p_act_"+tag
    act[1] = vtk.vtkActor()
    act[1].SetMapper(Map[1])
    act[1].GetProperty().SetColor(1,0,0)
    
    vis.renAddActor(ren,act)
    vis.render(ren)
    #vis.interact(ren)
    setattr(vis,Map[0], Map)
    setattr(vis,act[0],act)
    return act
Exemple #2
0
def polyShowCellIds(ren,obj):

  #@c Show the cell ids of a given poly object in a renderer
  #@a ren: renderer
  #@a obj: object name
  if isinstance(obj,list):
      tag = "%s_%s" % (ren[0],obj[0])
  elif isinstance(obj,str):
      tag = "%s_%s" % (ren[0],obj)
  else:
      raise ValueError("Argument type unsupported.")
  
  try:
      vis.polyUnshowCellIds(ren,obj)
  except:
      pass
    
  lmap = [None]*2
  lmap[0] = "p_lmapc_"+tag
  labels = [None]*2
  labels[0] = "p_labelsc_"+tag  
  ids = [None]*2
  ids[0] = "p_cellids_"+tag
  
  filt = vtk.vtkCellCenters()
  if isinstance(obj,list):
        filt.SetInputDataObject(obj[1])
  else:
        vtkPoly = Repository.ExportToVtk(obj)
        filt.SetInputDataObject(vtkPoly)
  filt.Update()
  ids[1] = filt.GetOutput()
  
  lmap[1] = vtk.vtkLabeledDataMapper()
  lmap[1].SetLabelModeToLabelIds()
  lmap[1].SetInputDataObject(ids[1])
  lmap[1].SetLabelFormat("%g")
  labels[1] = vtk.vtkActor2D()
  labels[1].SetMapper(lmap[1])
  ren[1].AddActor2D(labels[1])
  
  vis.render(ren)
  setattr(vis,lmap[0],lmap)
  setattr(vis,labels[0],labels)
  return 
Exemple #3
0
def polyShowScalarValues(ren,obj):

  #@c Show the scalar values for object in renderer
  #@a ren: renderer
  #@a obj: object name
  if isinstance(obj,list):
      tag = "%s_%s" % (ren[0],obj[0])
  elif isinstance(obj,str):
      tag = "%s_%s" % (ren[0],obj)
  else:
      raise ValueError("Argument type unsupported.")
  
  try:
      vis.polyUnshowScalarValues(ren,obj)
  except:
      pass
      
  lmap = [None]*2
  lmap[0] = "p_lmap_"+tag
  labels = [None]*2
  labels[0] = "p_labels_"+tag  
  
  lmap[1] = vtk.vtkLabeledDataMapper()
  lmap[1].SetLabelModeToLabelScalars()
  if isinstance(obj,list):
        lmap[1].SetInputDataObject(obj[1])
  else:
        vtkPoly = Repository.ExportToVtk(obj)
        lmap[1].SetInputDataObject(vtkPoly)
  lmap[1].SetLabelFormat("%g")
  
  labels[1] = vtk.vtkActor2D()
  labels[1].SetMapper(lmap[1])
  ren[1].AddActor2D(labels[1])
  
  vis.render(ren)
  setattr(vis,lmap[0],lmap)
  setattr(vis,labels[0],labels)
  return
def vis_imgRepos(ren , imgObj):
    try:
        vis_imgRm(ren)
    except:
        pass
    vis_imgInit(ren)
    if Repository.Type(imgObj) != "StructuredPts":
        raise ValueError("Object is not an imgae")
    vimg = Repository.ExportToVtk(imgObj)
    vorig = vimg.GetOrigin()
    vspc = vimg.GetSpacing()
    vdims = vimg.GetExtent()
    irng = vimg.GetScalarRange()
    
    if (vdims[4]!=vdims[5]+vdims[0]!=vdims[1]+vdims[2]!=vdims[3]):
        raise ValueError("image is not planar")
        return
        
    #logical image dims:
    ldims = []    
    ldims.append(vdims[1]-vdims[0]+1)
    ldims.append(vdims[3]-vdims[2]+1)
    ldims.append(vdims[5]-vdims[4]+1)
    
    #Physical image dimensions (spatial extent covered by pixels):
    pdims = []
    pdims.append(ldims[0]*vspc[0])
    pdims.append(ldims[1]*vspc[1])
    pdims.append(ldims[2]*vspc[2])
    
    # Physical origin of the physical extent:
    porig = []
    porig.append(vorig[0]-0.5*vspc[0])
    porig.append(vorig[1]-0.5*vspc[1])
    porig.append(vorig[2]-0.5*vspc[2])
        
    txt = getattr(vis, 'vis_img_texture_'+ren[0])
    plane = getattr(vis, 'vis_img_plane_' + ren[0])
    vmap = getattr(vis, 'vis_img_map_' + ren[0])
    actor = getattr(vis, 'vis_img_actor_'+ren[0])
    lookupGrayscale = getattr(vis, 'vis_img_g8bitGrayscaleLUT_'+ren[0])
    lookupColor = getattr(vis, 'vis_img_gBlueToRedLUT_'+ren[0])
    

    txt[1].SetInputDataObject(vimg)
    txt[1].SetLookupTable(lookupGrayscale[1])
    txt[1].RepeatOff()
    
    
    plane[1].SetOrigin(porig[0],porig[1],0.)
    plane[1].SetPoint1(porig[0]+pdims[0],porig[1],0.)       
    plane[1].SetPoint2(porig[0], pdims[1]+porig[1],0.)
    
    plane[1].SetNormal(0.,0.,1.)
    plane[1].Push(-0.01)
        
    vmap[1].SetScalarRange(irng[0], irng[1])
    lookupGrayscale[1].SetTableRange(irng[0], irng[1])
    lookupColor[1].SetTableRange(irng[0], irng[1])
    
    ren[1].AddActor(actor[1])
    vis.render(ren)
    
    return
Exemple #5
0
def mesh_writeCompleteMesh(meshName, solidName, prefix, outdir):
    global guiMMvars
    global gFilenames
    solid = Solid.pySolidModel()
    solid.GetModel(solidName)
    kernel = solid.GetKernel()

    mesh = MeshObject.pyMeshObject()
    mesh.GetMesh(meshName)

    try:
        os.mkdir(outdir + '/mesh-surfaces')
        os.mkdir(outdir + '/misc')
    except:
        pass

    ug = "myug"
    pd = "mypd"
    facepd = "myfacepd"

    try:
        Repository.Delete(ug)
    except:
        pass
    try:
        Repository.Delete(pd)
    except:
        pass
    try:
        Repository.Delete(facepd)
    except:
        pass

    if (kernel == "PolyData" and guiMMvars['meshGenerateVolumeMesh'] != 1):
        pass
    else:
        mesh.GetUnstructuredGrid(ug)
        ugwriter = vtk.vtkXMLUnstructuredGridWriter()
        ugwriter.SetCompressorTypeToZLib()
        ugwriter.EncodeAppendedDataOff()
        ugwriter.SetInputDataObject(Repository.ExportToVtk(ug))
        ugwriter.SetFileName(outdir + '/' + prefix + '.mesh.vtu')
        ugwriter.Write()
        del ugwriter

    mesh.GetPolyData(pd)

    pdwriter = vtk.vtkXMLPolyDataWriter()
    pdwriter.SetCompressorTypeToZLib()
    pdwriter.EncodeAppendedDataOff()
    pdwriter.SetInputDataObject(Repository.ExportToVtk(pd))
    pdwriter.SetFileName(outdir + '/' + prefix + '.exterior.vtp')
    pdwriter.Write()

    foundWall = 0
    appender = vtk.vtkAppendPolyData()
    appender.UserManagedInputsOff()

    foundStent = 0
    Sappender = vtk.vtkAppendPolyData()
    Sappender.UserManagedInputsOff()

    name_to_identifier = {}
    identifier_to_name = {}
    facestr = mesh.GetModelFaceInfo()
    facename = ""
    for faceinfo in facestr.split("  "):
        faceinfo = faceinfo.replace(" ", "")
        faceinfo = faceinfo.replace("{", "")
        faceinfo = faceinfo.replace("}", "")
        i = faceinfo[0]
        ident = faceinfo[1]
        if (kernel == "Parasolid"):
            try:
                facename = faceinfo[2]
            except:
                pass
        elif (kernel == "Discrete"):
            global gDiscreteModelFaceNames
            try:
                facename = gDiscreteModelFaceNames[i]
            except:
                pass
        elif (kernel == "PolyData"):
            global gPolyDataFaceNames
            try:
                facename = gPolyDataFaceNames[i]
            except:
                pass
        else:
            raise ValueError("ERROR: invalid solid kernel" + kernel)
            return
        if (facename == ""):
            facename = "missing_" + i + "\_" + ident
        elif ("noname" in facename.lower()):
            print(facename + " is not being written because it has no_name")
        else:
            name_to_identifier[facename] = ident
            identifier_to_name[ident] = facename
            try:
                Repository.Delete(facepd)
            except:
                pass
        try:
            mesh.GetFacePolyData(facepd, int(i))
        except:
            print("Warning face %s not found, skipping face" % i)
            pass
        pdwriter.SetInputDataObject(Repository.ExportToVtk(facepd))
        pdwriter.SetFileName(outdir + '/mesh-surfaces/' + facename + '.vtp')
        pdwriter.Write()
        if "wall" in facename:
            foundWall = 1
            appender.AddInputData(Repository.ExportToVtk(facepd))
        if "stent" in facename:
            foundStent = 1
            appender.AddInputData(Repository.ExportToVtk(facepd))
        try:
            Repository.Delete(facepd)
        except:
            pass

    if (foundWall):
        appender.Update()
        cleaner = vtk.vtkCleanPolyData()
        cleaner.PointMergingOn()
        cleaner.PieceInvariantOff()
        cleaner.SetInputDataObject(appender.GetOutput())
        cleaner.Update()
        pdwriter.SetFileName(outdir + '/walls_combined.vtp')
        pdwriter.SetInputDataObject(cleaner.GetOutput())
        pdwriter.Write()
        del cleaner
        del appender

    if (foundStent):
        Sappender.Update()
        Scleaner = vtk.vtkCleanPolyData()
        Scleaner.PointMergingOn()
        Scleaner.PieceInvariantOff()
        Scleaner.SetInputDataObject(Sappender.GetOutput())
        Scleaner.Update()
        pdwriter.SetFileName(outdir + '/stent_combined.vtp')
        pdwriter.SetInputDataObject(Scleaner.GetOutput())
        del pdwriter
        del Scleaner
    del Sappender

    #$mesh WriteMetisAdjacency -file $outdir/$prefix.xadj
    #mesh_kernel = mesh.GetKernel()
    #if (mesh_kernel == "TetGen"):
    #  gFilenames['tet_mesh_script_file'] = outdir+ "/" + prefix
    #  guiMMcreateTetGenScriptFile
    #elif (mesh_kernel == "MeshSim"):
    #  gFilenames['mesh_script_file'] = outdir + "/" + prefix
    #  guiMMcreateMeshSimScriptFile
    #  mesh.WriteMesh(outdir+'/'+prefix+'.sms')

    try:
        Repository.Delete(ug)
    except:
        pass
    try:
        Repository.Delete(pd)
    except:
        pass
    try:
        Repository.Delete(facepd)
    except:
        pass
Exemple #6
0
def vis_volRepos(ren, objName):
    if Repository.Exists(objName) == 0:
        raise ValueError("ERROR:  Object does not exist.")
        return
    if Repository.Type(objName) != "StructuredPts":
        raise TypeError("Incorrect object type.")
        return
    caster = [None] * 2
    opacityTransferFunction = [None] * 2
    colorTransferFunction = [None] * 2
    gradientTransferFunction = [None] * 2
    volumeProperty = [None] * 2
    volumeMapper = [None] * 2
    compositeFunction = [None] * 2
    outline = [None] * 2
    outlineMapper = [None] * 2
    outlineProperty = [None] * 2
    lod = [None] * 2

    caster[0] = "vis_vol_caster_" + objName
    opacityTransferFunction[0] = "vis_vol_opacityTransferFunction_" + objName
    colorTransferFunction[0] = "vis_vol_colorTransferFunction_" + objName
    gradientTransferFunction[0] = "vis_vol_gradientTransferFunction_" + objName
    volumeProperty[0] = "vis_vol_volumeProperty_" + objName
    volumeMapper[0] = "vis_vol_volumeMapper_" + objName
    compositeFunction[0] = "vis_vol_compositeFunction_" + objName
    outline[0] = "vis_vol_outline_" + objName
    outlineMapper[0] = "vis_vol_outlineMapper_" + objName
    outlineProperty[0] = "vis_vol_outlineProperty_" + objName
    lod[0] = "vis_vol_lod_" + objName

    caster[1] = vtk.vtkImageCast()
    caster[1].SetOutputScalarTypeToUnsignedShort()
    caster[1].SetInputDataObject(Repository.ExportToVtk(objName))
    caster[1].Update()

    # Create transfer functions for opacity and color
    opacityTransferFunction[1] = vtk.vtkPiecewiseFunction()
    opacityTransferFunction[1].AddPoint(0, 0.)
    opacityTransferFunction[1].AddPoint(80, 0.)
    opacityTransferFunction[1].AddPoint(128, 0.5)
    opacityTransferFunction[1].AddPoint(150, 0.9)
    opacityTransferFunction[1].AddPoint(350, 1.0)

    colorTransferFunction[1] = vtk.vtkColorTransferFunction()
    colorTransferFunction[1].AddRGBPoint(0, 0, 0, 0)
    colorTransferFunction[1].AddRGBPoint(350, 1, 1, 1)

    gradientTransferFunction[1] = vtk.vtkPiecewiseFunction()
    gradientTransferFunction[1].AddPoint(0, 1.0)
    gradientTransferFunction[1].AddPoint(1, 1.0)
    gradientTransferFunction[1].AddPoint(255, 1.0)
    gradientTransferFunction[1].AddPoint(512, 1.0)

    # Create properties, mappers, volume actors, and ray cast function
    volumeProperty[1] = vtk.vtkVolumeProperty()
    volumeProperty[1].SetColor(colorTransferFunction[1])
    volumeProperty[1].SetScalarOpacity(opacityTransferFunction[1])
    volumeProperty[1].SetGradientOpacity(gradientTransferFunction[1])
    volumeProperty[1].SetInterpolationTypeToLinear()

    volumeMapper[1] = vtk.vtkSmartVolumeMapper()
    volumeMapper[1].SetInputDataObject(caster[1].GetOutput())

    lod[1] = vtk.vtkVolume()
    lod[1].SetProperty(volumeProperty[1])
    lod[1].SetMapper(volumeMapper[1])

    ren[1].AddViewProp(lod[1])

    setattr(vis, caster[0], caster)
    setattr(vis, opacityTransferFunction[0], opacityTransferFunction)
    setattr(vis, colorTransferFunction[0], colorTransferFunction)
    setattr(vis, gradientTransferFunction[0], gradientTransferFunction)
    setattr(vis, volumeProperty[0], volumeProperty)
    setattr(vis, volumeMapper[0], volumeMapper)
    setattr(vis, compositeFunction[0], compositeFunction)
    setattr(vis, outline[0], outline)
    setattr(vis, outlineMapper[0], outlineMapper)
    setattr(vis, outlineProperty[0], outlineProperty)
    setattr(vis, lod[0], lod)
    vis.renfun.render(ren)
    return lod
Exemple #7
0
    Vmean = Vbar*(1.0+math.sin(2*math.pi*t/T))
    area = math.pi*radius*radius
    pts.append([t, -Vmean*area])
    
terms = Math.FFT(pts, 2,256)
try:
    Repository.Delete('outflow')
except:
    pass
    
import os
import stat
os.chmod(fullrundir+'/mesh-complete/mesh-surfaces', 0o777)
Repository.ReadXMLPolyData('outflow',fullrundir+'/mesh-complete/mesh-surfaces/outlet.vtp')
numPts = Geom.NumPts('outflow')
outflowObj = Repository.ExportToVtk('outflow')
outflowScalars = outflowObj.GetPointData().GetScalars()

print ("Reading simulation results: " + resfn)
resReader = vtk.vtkXMLUnstructuredGridReader()
resReader.SetFileName(resfn)
resReader.Update()

# now calculate flow rate for each time point
countem = 0

for stepnum in simstepnumlist:
    time = tlist[countem]
    countem = countem+1
    myVectors = vtk.vtkFloatArray()
    myVectors.SetNumberOfComponents(3)