コード例 #1
1
ファイル: meshInit.py プロジェクト: fayhot/gradworks
def obb(opts,argv):
	poly = nv.readVTK(argv[0])
	obb = vtk.vtkOBBTree()
	obb.SetMaxLevel(10)
	obb.SetNumberOfCellsPerNode(5)
	obb.AutomaticOn()
	sfilt = vtk.vtkSpatialRepresentationFilter()
	sfilt.SetSpatialRepresentation(obb)
	sfilt.SetInput(poly)
	sfilt.Update()
	nv.writeVTK(argv[1],sfilt.GetOutput())
コード例 #2
0
ファイル: meshInit.py プロジェクト: fayhot/gradworks
def concomp(opts, argv):
	p = nv.readVTK(argv[0])
	c = vtk.vtkPolyDataConnectivityFilter()
	c.SetInput(p)
	c.SetExtractionModeToLargestRegion()
	c.Update()
	d = vtk.vtkCleanPolyData()
	d.SetInput(c.GetOutput())
	d.Update()
	p = d.GetOutput()
	nv.writeVTK(argv[1],p)
コード例 #3
0
ファイル: meshInit.py プロジェクト: kerwinzxc/gradworks
def icp(opts, args):
    v1 = nv.readVTK(args[0])
    v2 = nv.readVTK(args[1])
    icp = vtk.vtkIterativeClosestPointTransform()
    icp.SetSource(v2)
    icp.SetTarget(v1)
    icp.StartByMatchingCentroidsOn()
    icp.SetMaximumNumberOfIterations(500)
    icp.SetMaximumNumberOfLandmarks(20000)
    tx = icp.GetLandmarkTransform()
    tx.SetModeToRigidBody()
    icp.Update()
    tx = icp.GetLandmarkTransform()
    txf = vtk.vtkTransformPolyDataFilter()
    txf.SetInput(v2)
    txf.SetTransform(tx)
    txf.Update()
    v3 = txf.GetOutput()
    nv.writeVTK(args[2], v3)
    return
コード例 #4
0
ファイル: meshInit.py プロジェクト: fayhot/gradworks
def icp(opts,args):
	v1 = nv.readVTK(args[0])
	v2 = nv.readVTK(args[1])
	icp = vtk.vtkIterativeClosestPointTransform()
	icp.SetSource(v2)
	icp.SetTarget(v1)
	icp.StartByMatchingCentroidsOn()
	icp.SetMaximumNumberOfIterations(500)
	icp.SetMaximumNumberOfLandmarks(20000)
	tx = icp.GetLandmarkTransform()
	tx.SetModeToRigidBody()
	icp.Update()
	tx = icp.GetLandmarkTransform()
	txf = vtk.vtkTransformPolyDataFilter()
	txf.SetInput(v2)
	txf.SetTransform(tx)
	txf.Update()
	v3 = txf.GetOutput()
	nv.writeVTK(args[2], v3)
	return
コード例 #5
0
ファイル: meshInit.py プロジェクト: kerwinzxc/gradworks
def concomp(opts, argv):
    p = nv.readVTK(argv[0])
    c = vtk.vtkPolyDataConnectivityFilter()
    c.SetInput(p)
    c.SetExtractionModeToLargestRegion()
    c.Update()
    d = vtk.vtkCleanPolyData()
    d.SetInput(c.GetOutput())
    d.Update()
    p = d.GetOutput()
    nv.writeVTK(argv[1], p)
コード例 #6
0
ファイル: meshInit.py プロジェクト: kerwinzxc/gradworks
def obb(opts, argv):
    poly = nv.readVTK(argv[0])
    obb = vtk.vtkOBBTree()
    obb.SetMaxLevel(10)
    obb.SetNumberOfCellsPerNode(5)
    obb.AutomaticOn()
    sfilt = vtk.vtkSpatialRepresentationFilter()
    sfilt.SetSpatialRepresentation(obb)
    sfilt.SetInput(poly)
    sfilt.Update()
    nv.writeVTK(argv[1], sfilt.GetOutput())
コード例 #7
0
def main(opts, argv):
  inputvtk = argv[0]
  outputvtk = argv[1]

  inVTK = nv.readVTK(inputvtk);
  if (opts.sep == "0"):
    csvreader = csv.reader(open(opts.csvfile, "r"))
  elif (opts.sep == "1"):
    csvreader = csv.reader(open(opts.csvfile, "r"), delimiter=',')
  elif (opts.sep == "2"):
    csvreader = csv.reader(open(opts.csvfile, "r"), delimiter='\t')
  


  first = csvreader.next()
  if (opts.header):
    header = first
    first = csvreader.next()

  if (opts.names != ""):
    header = opts.names.split(",")

  print header
  
  nCols = len(first)
  nPoints = inVTK.GetNumberOfPoints() 

  data = np.zeros([nPoints,nCols])
  for k in range(0,nCols):
    data[0,k] = float(first[k])

  print "# points:", nPoints
  for j in range(1,nPoints):
    print j
    first = csvreader.next()
    for k in range(0,nCols):
      data[j,k] = float(first[k])

  for k in range(0,nCols):
    arr = vtkDoubleArray()
    if (len(header) > 0):
      arr.SetName(header[k])
    arr.SetNumberOfTuples(nPoints)
    for j in range(0,nPoints):
      arr.SetValue(j,data[j,k])
    inVTK.GetPointData().AddArray(arr)
    
  nv.writeVTK(outputvtk, inVTK)
コード例 #8
0
def removeAttributes(opts, args):
  print args
  inputvtk = args[0]
  outputvtk = args[1]

  inVTK = nv.readVTK(inputvtk);
  nArrays = inVTK.GetPointData().GetNumberOfArrays()
  arrayNames = []
  for k in range(0,nArrays):
    arrayNames.append(inVTK.GetPointData().GetArrayName(k))

  print arrayNames
  for name in arrayNames:
    inVTK.GetPointData().RemoveArray(name)

  nv.writeVTK(outputvtk, inVTK)
コード例 #9
0
def removeAttributes(opts, args):
    print args
    inputvtk = args[0]
    outputvtk = args[1]

    inVTK = nv.readVTK(inputvtk)
    nArrays = inVTK.GetPointData().GetNumberOfArrays()
    arrayNames = []
    for k in range(0, nArrays):
        arrayNames.append(inVTK.GetPointData().GetArrayName(k))

    print arrayNames
    for name in arrayNames:
        inVTK.GetPointData().RemoveArray(name)

    nv.writeVTK(outputvtk, inVTK)
コード例 #10
0
ファイル: meshInit.py プロジェクト: fayhot/gradworks
def principalAxes(opts, argv):
	p = nv.readVTK(argv[0])
	for i in range(0,p.GetNumberOfPoints()):
		s = p.GetPoint(i)
		s = (-s[0],-s[1],s[2])
		p.GetPoints().SetPoint(i,s)
	#g = vtk.vtkUnstructuredGrid()
	#g.SetPoints(vtk.vtkPoints())
	pOBB = OBB()
	vtk.vtkOBBTree.ComputeOBB(p.GetPoints(), pOBB.corner, pOBB.m1, pOBB.m2, pOBB.m3, pOBB.sz)
	#pOBB.MakeCube(g)
	translateToMean(p,pOBB.Center(),-1)
	pR = pOBB.AxisAlign()
	print pR
	pOut = transform(p,pR)
	nv.writeVTK(argv[1], pOut)
	writeITKTransform(argv[2], pR, np.asarray((255,255,79)) - pOBB.Center(), pOBB.Center())
コード例 #11
0
def main(opts, argv):
    inputvtk = argv[0]
    outputvtk = argv[1]

    inVTK = nv.readVTK(inputvtk)
    if (opts.sep == "0"):
        csvreader = csv.reader(open(opts.csvfile, "r"))
    elif (opts.sep == "1"):
        csvreader = csv.reader(open(opts.csvfile, "r"), delimiter=',')
    elif (opts.sep == "2"):
        csvreader = csv.reader(open(opts.csvfile, "r"), delimiter='\t')

    first = csvreader.next()
    if (opts.header):
        header = first
        first = csvreader.next()

    if (opts.names != ""):
        header = opts.names.split(",")

    print header

    nCols = len(first)
    nPoints = inVTK.GetNumberOfPoints()

    data = np.zeros([nPoints, nCols])
    for k in range(0, nCols):
        data[0, k] = float(first[k])

    print "# points:", nPoints
    for j in range(1, nPoints):
        print j
        first = csvreader.next()
        for k in range(0, nCols):
            data[j, k] = float(first[k])

    for k in range(0, nCols):
        arr = vtkDoubleArray()
        if (len(header) > 0):
            arr.SetName(header[k])
        arr.SetNumberOfTuples(nPoints)
        for j in range(0, nPoints):
            arr.SetValue(j, data[j, k])
        inVTK.GetPointData().AddArray(arr)

    nv.writeVTK(outputvtk, inVTK)
コード例 #12
0
ファイル: meshInit.py プロジェクト: fayhot/gradworks
def normalHistogram(opts,argv):
	poly = nv.readVTK(argv[0])
	normfilt = vtk.vtkPolyDataNormals()
	normfilt.ConsistencyOn()
	normfilt.AutoOrientNormalsOn()
	normfilt.ComputeCellNormalsOn()
	normfilt.SetInput(poly)
	normfilt.SetFeatureAngle(90)
	normfilt.Update()
	poly = normfilt.GetOutput()
	nv.writeVTK("nrom.vtk", poly)
	normals = poly.GetCellData().GetArray("Normals", vtk.mutable(0))
	normMap = vtk.vtkUnstructuredGrid()
	normMap.SetPoints(vtk.vtkPoints())
	normPts = normMap.GetPoints()
	for i in range(0, normals.GetNumberOfTuples()):
		norm = [0,0,0]
		normals.GetTuple(i, norm)
		normPts.InsertNextPoint(norm)
	nv.writeVTK(argv[1], normMap)
コード例 #13
0
ファイル: meshInit.py プロジェクト: kerwinzxc/gradworks
def normalHistogram(opts, argv):
    poly = nv.readVTK(argv[0])
    normfilt = vtk.vtkPolyDataNormals()
    normfilt.ConsistencyOn()
    normfilt.AutoOrientNormalsOn()
    normfilt.ComputeCellNormalsOn()
    normfilt.SetInput(poly)
    normfilt.SetFeatureAngle(90)
    normfilt.Update()
    poly = normfilt.GetOutput()
    nv.writeVTK("nrom.vtk", poly)
    normals = poly.GetCellData().GetArray("Normals", vtk.mutable(0))
    normMap = vtk.vtkUnstructuredGrid()
    normMap.SetPoints(vtk.vtkPoints())
    normPts = normMap.GetPoints()
    for i in range(0, normals.GetNumberOfTuples()):
        norm = [0, 0, 0]
        normals.GetTuple(i, norm)
        normPts.InsertNextPoint(norm)
    nv.writeVTK(argv[1], normMap)
コード例 #14
0
ファイル: meshInit.py プロジェクト: kerwinzxc/gradworks
def principalAxes(opts, argv):
    p = nv.readVTK(argv[0])
    for i in range(0, p.GetNumberOfPoints()):
        s = p.GetPoint(i)
        s = (-s[0], -s[1], s[2])
        p.GetPoints().SetPoint(i, s)
    #g = vtk.vtkUnstructuredGrid()
    #g.SetPoints(vtk.vtkPoints())
    pOBB = OBB()
    vtk.vtkOBBTree.ComputeOBB(p.GetPoints(), pOBB.corner, pOBB.m1, pOBB.m2,
                              pOBB.m3, pOBB.sz)
    #pOBB.MakeCube(g)
    translateToMean(p, pOBB.Center(), -1)
    pR = pOBB.AxisAlign()
    print pR
    pOut = transform(p, pR)
    nv.writeVTK(argv[1], pOut)
    writeITKTransform(argv[2], pR,
                      np.asarray((255, 255, 79)) - pOBB.Center(),
                      pOBB.Center())