VTK example for surface to mesh model - Thanks Gudni!

This commit is contained in:
D Fournier
2016-01-15 16:49:27 -08:00
parent 44b7dd184f
commit c3c96a5bd8
10 changed files with 256430 additions and 4 deletions
+81 -3
View File
@@ -389,9 +389,87 @@ def read_GOCAD_ts(tsfile):
line = fid.readline()
vrtx = []
# Run down all the vertices and save in array
while re.match('VRTX',line):
l_input = line.split('\s')
vrtx = np.vstack([vrtx,l_input[1]])
l_input = re.split('[\s*]',line)
temp = np.array(l_input[2:5])
vrtx.append(temp.astype(np.float))
# Read next line
line = fid.readline()
return vrtx
vrtx = np.asarray(vrtx)
# Run down the list of triangles
trgl = []
# Run down all the vertices and save in array
while re.match('TRGL',line):
l_input = re.split('[\s*]',line)
temp = np.array(l_input[1:4])
trgl.append(temp.astype(np.int))
# Read next line
line = fid.readline()
trgl = np.asarray(trgl)
return vrtx, trgl
def gocad2vtk(gcFile,mesh):
""""
Function to read gocad polystructure file and output indexes of mesh with in the structure.
"""
import vtk, vtk.util.numpy_support as npsup
vrtx, trgl = read_GOCAD_ts(gcFile)
# Adjust the index
trgl = trgl - 1
# Make vtk pts
ptsvtk = vtk.vtkPoints()
ptsvtk.SetData(npsup.numpy_to_vtk(vrtx,deep=1))
# Make the polygon connection
polys = vtk.vtkCellArray()
for face in trgl:
poly = vtk.vtkPolygon()
poly.GetPointIds().SetNumberOfIds(len(face))
for nrv, vert in enumerate(face):
poly.GetPointIds().SetId(nrv,vert)
polys.InsertNextCell(poly)
# Make the polydata, structure of connections and vrtx
polyData = vtk.vtkPolyData()
polyData.SetPoints(ptsvtk)
polyData.SetPolys(polys)
# Make implicit func
ImpDistFunc = vtk.vtkImplicitPolyDataDistance()
ImpDistFunc.SetInput(polyData)
# Convert the mesh
vtkMesh = vtk.vtkRectilinearGrid()
vtkMesh.SetDimensions(mesh.nNx,mesh.nNy,mesh.nNz)
vtkMesh.SetXCoordinates(npsup.numpy_to_vtk(mesh.vectorNx,deep=1))
vtkMesh.SetYCoordinates(npsup.numpy_to_vtk(mesh.vectorNy,deep=1))
vtkMesh.SetZCoordinates(npsup.numpy_to_vtk(mesh.vectorNz,deep=1))
# Add indexes
vtkInd = npsup.numpy_to_vtk(np.arange(mesh.nC),deep=1)
vtkInd.SetName('Index')
vtkMesh.GetCellData().AddArray(vtkInd)
extractImpDistRectGridFilt = vtk.vtkExtractGeometry() # Object constructor
extractImpDistRectGridFilt.SetImplicitFunction(ImpDistFunc) #
extractImpDistRectGridFilt.SetInputData(vtkMesh)
extractImpDistRectGridFilt.ExtractBoundaryCellsOn()
extractImpDistRectGridFilt.ExtractInsideOn()
# Executing the pipe
extractImpDistRectGridFilt.Update()
insideGrid = extractImpDistRectGridFilt.GetOutput()
# Return the indexes inside
return npsup.vtk_to_numpy(insideGrid.GetCellData().GetArray('Index'))
+2 -1
View File
@@ -48,7 +48,8 @@ ndata = rxLoc.shape[0]
# Load GOCAD surf
tsfile = 'SphereA.ts'
vrtx = PF.BaseMag.read_GOCAD_ts(tsfile)
[vrtx, trgl] = PF.BaseMag.read_GOCAD_ts(tsfile)
#%% Run forward modeling
# Compute forward model using integral equation
d = PF.Magnetics.Intgrl_Fwr_Data(mesh,B,M,rxLoc,model,actv,'tmi')
+76
View File
@@ -0,0 +1,76 @@
import os
home_dir = '.\Test_tria_2_grid'
inpfile = 'PYMAG3C_fwr.inp'
dsep = '\\'
os.chdir(home_dir)
#%%
from SimPEG import np, sp, Utils, mkvc, Maps
import vtk, vtk.util.numpy_support as npsup
import simpegPF as PF
import pylab as plt
## New scripts to be added to basecode
#from fwr_MAG_data import fwr_MAG_data
#from read_MAGfwr_inp import read_MAGfwr_inp
#%%
# Read input file
# Load mesh file
mesh = Utils.meshutils.readUBCTensorMesh('Mesh_2p5m.msh')
# Load GOCAD surf
tsfile = 'Crown.ts'
#[vrtx, trgl] = PF.BaseMag.read_GOCAD_ts(tsfile)
indx = PF.BaseMag.gocad2vtk(tsfile,mesh)
model= np.zeros(mesh.nC)
model[indx]=1
Utils.meshutils.writeUBCTensorModel('VTKout.dat',mesh,model)
# Load model file
#model = Utils.meshutils.readUBCTensorModel(modfile,mesh)
# Load in topofile or create flat surface
#==============================================================================
# if topofile == 'null':
#
# actv = np.ones(mesh.nC)
#
# else:
# topo = np.genfromtxt(topofile,skip_header=1)
# actv = PF.Magnetics.getActiveTopo(mesh,topo,'N')
#
#
# Utils.writeUBCTensorModel('nullcell.dat',mesh,actv)
#
# # Load in observation file
# [B,M,dobs] = PF.BaseMag.readUBCmagObs(obsfile)
#
# rxLoc = dobs[:,0:3]
# #rxLoc[:,2] += 5 # Temporary change for test
# ndata = rxLoc.shape[0]
#==============================================================================
#%% Run forward modeling
# Compute forward model using integral equation
#==============================================================================
# d = PF.Magnetics.Intgrl_Fwr_Data(mesh,B,M,rxLoc,model,actv,'tmi')
#
# # Form data object with coordinates and write to file
# wd = np.zeros((ndata,1))
#
# # Save forward data to file
# PF.Magnetics.writeUBCobs(home_dir + dsep + 'FWR_data.dat',B,M,rxLoc,d,wd)
#==============================================================================
+56
View File
@@ -0,0 +1,56 @@
GOCAD TSurf 1
HEADER {
name:Crown
*solid*color:1 0.447059 0.337255 1
ivolmap:false
imap:false
painted:on
*painted*variable:normal
last_selected_folder:3D property
vectors3d:true
*vectors3d*arrow:true
*vectors3d*color:0.0980392 0.0980392 0.439216 1
*vectors3d*arrow_size:5
}
GOCAD_ORIGINAL_COORDINATE_SYSTEM
NAME Default
AXIS_NAME "X" "Y" "Z"
AXIS_UNIT "m" "m" "m"
ZPOSITIVE Elevation
END_ORIGINAL_COORDINATE_SYSTEM
PROPERTY_CLASS_HEADER Z {
is_z:on
}
PROPERTY_CLASS_HEADER vector3d {
pclip:99
low_clip:-0.9956403
high_clip:0.9905306
}
TFACE
VRTX 1 17.898199081420898 -24.1842041015625 -70.548362731933594
VRTX 2 -24.411655426025391 -24.1842041015625 -69.894088745117188
VRTX 3 17.898199081420898 25.8157958984375 -70.548362731933594
VRTX 4 -24.411655426025391 25.8157958984375 -69.894088745117188
VRTX 5 16.807741165161133 25.8157958984375 -9.4825878143310547
VRTX 6 -4.565277099609375 -24.1842041015625 -28.674692153930664
VRTX 7 16.807741165161133 -24.1842041015625 -9.4825878143310547
VRTX 8 -24.629745483398438 -24.1842041015625 -12.972057342529297
VRTX 9 -24.629745483398438 25.8157958984375 -12.972057342529297
VRTX 10 -4.565277099609375 25.8157958984375 -28.674692153930664
TRGL 8 6 9
TRGL 7 1 5
TRGL 1 2 3
TRGL 9 6 10
TRGL 10 7 5
TRGL 2 8 4
TRGL 5 1 3
TRGL 3 2 4
TRGL 10 5 3
TRGL 4 9 10
TRGL 7 6 1
TRGL 6 2 1
TRGL 4 10 3
TRGL 4 8 9
TRGL 8 2 6
TRGL 6 7 10
END
+5
View File
@@ -0,0 +1,5 @@
20 20 20
0 0 0
0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50
0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50
0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50
@@ -0,0 +1,5 @@
80 40 40
-100.00 -50.00 0.00
2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50
2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50
2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50 2.50
+157
View File
@@ -0,0 +1,157 @@
GOCAD TSurf 1
HEADER {
name:SphereA_test
*solid*color:#00ffff
ivolmap:false
imap:false
painted:on
*painted*variable:normal
mesh:true
}
GOCAD_ORIGINAL_COORDINATE_SYSTEM
NAME Default
AXIS_NAME "X" "Y" "Z"
AXIS_UNIT "m" "m" "m"
ZPOSITIVE Elevation
END_ORIGINAL_COORDINATE_SYSTEM
PROPERTY_CLASS_HEADER Z {
is_z:on
}
PROPERTY_CLASS_HEADER vector3d {
low_clip:-1
high_clip:1
pclip:99
}
TFACE
VRTX 1 -2.2919261455535889 -19.314384460449219 -17.626590728759766
VRTX 2 6.6298894882202148 -23.695545196533203 -28.910013198852539
VRTX 3 -15.073513984680176 -19.314384460449219 -38.307632446289063
VRTX 4 -12.506924629211426 -11.605335235595703 -51.606067657470703
VRTX 5 -19.863996505737305 -8.0631170272827148 -46.194423675537109
VRTX 6 -22.580167770385742 3.788722038269043 -23.29432487487793
VRTX 7 -11.330929756164551 -18.19896125793457 -20.47222900390625
VRTX 8 6.5996670722961426 -16.974418640136719 -50.459728240966797
VRTX 9 -17.014554977416992 -8.2651615142822266 -16.98731803894043
VRTX 10 21.977100372314453 -7.0079841613769531 -23.695110321044922
VRTX 11 17.244131088256836 0 -15.232500076293945
VRTX 12 13.95079517364502 10.135844230651855 -51.434154510498047
VRTX 13 22.229457855224609 -8.2651615142822266 -41.241447448730469
VRTX 14 -5.8128781318664551 14.548799514770508 -13.851467132568359
VRTX 15 9.7651596069335937 -2.9769551753997803 -56.153919219970703
VRTX 16 -13.742574691772461 5.0091938972473145 -53.607688903808594
VRTX 17 -13.711102485656738 20.304235458374023 -28.35902214050293
VRTX 18 -7.821871280670166 -18.734676361083984 -47.922031402587891
VRTX 19 13.062463760375977 21.316003799438477 -33.333328247070313
VRTX 20 -14.062309265136719 4.0251598358154297 -13.05897045135498
VRTX 21 24.778470993041992 2.9769551753997803 -31.861873626708984
VRTX 22 20.487052917480469 13.627725601196289 -37.756645202636719
VRTX 23 -6.8588962554931641 -4.9832801818847656 -9.8147735595703125
VRTX 24 9.4985036849975586 16.97282600402832 -49.040065765380859
VRTX 25 19.077316284179688 3.788722038269043 -49.040065765380859
VRTX 26 -24.44097900390625 -4.9556803703308105 -31.578392028808594
VRTX 27 15.63094425201416 11.356545448303223 -17.468194961547852
VRTX 28 2.7494394779205322 22.420015335083008 -22.619619369506836
VRTX 29 5.0962982177734375 -4.9596676826477051 -9.3660707473754883
VRTX 30 -2.6028509140014648 18.735876083374023 -49.679340362548828
VRTX 31 7.3593044281005859 6.6037797927856445 -10.371823310852051
VRTX 32 -21.796012878417969 -12.156011581420898 -31.861873626708984
VRTX 33 -5.0962982177734375 -4.9596676826477051 -57.300586700439453
VRTX 34 18.269777297973633 -16.974418640136719 -31.577091217041016
VRTX 35 -19.291585922241211 15.273146629333496 -28.910013198852539
VRTX 36 -23.036630630493164 3.6853373050689697 -42.318424224853516
VRTX 37 8.4685440063476562 9.8534049987792969 -11.974625587463379
VRTX 38 16.887338638305664 -14.301387786865234 -44.964668273925781
VRTX 39 10.637019157409668 -16.68756103515625 -18.056575775146484
VRTX 40 -4.8257155418395996 24.485654830932617 -34.804782867431641
VRTX 41 -21.789302825927734 12.130206108093262 -35.089565277099609
VRTX 42 -9.5504827499389648 18.734676361083984 -46.853691101074219
VRTX 43 -2.6198656558990479 8.0631160736083984 -56.851882934570312
VRTX 44 -0.90874701738357544 -24.94017219543457 -34.8037109375
VRTX 45 -15.073513984680176 19.314384460449219 -38.307632446289063
TRGL 31 29 11
TRGL 7 3 44
TRGL 36 41 45
TRGL 35 41 6
TRGL 22 24 19
TRGL 45 41 35
TRGL 14 23 31
TRGL 30 43 42
TRGL 39 2 34
TRGL 17 35 14
TRGL 20 9 23
TRGL 2 38 34
TRGL 26 5 32
TRGL 43 30 24
TRGL 11 10 21
TRGL 21 13 25
TRGL 19 28 27
TRGL 36 16 5
TRGL 19 40 28
TRGL 12 43 24
TRGL 1 44 2
TRGL 2 44 8
TRGL 9 32 7
TRGL 22 12 24
TRGL 6 26 9
TRGL 11 29 39
TRGL 33 18 4
TRGL 6 9 20
TRGL 10 34 13
TRGL 33 16 43
TRGL 34 38 13
TRGL 10 11 39
TRGL 35 6 20
TRGL 38 15 25
TRGL 42 36 45
TRGL 27 28 37
TRGL 5 4 3
TRGL 21 25 22
TRGL 16 36 42
TRGL 30 42 40
TRGL 25 15 12
TRGL 33 43 15
TRGL 4 18 3
TRGL 26 32 9
TRGL 13 38 25
TRGL 40 42 45
TRGL 19 27 22
TRGL 14 31 37
TRGL 40 17 28
TRGL 41 26 6
TRGL 43 12 15
TRGL 22 25 12
TRGL 14 20 23
TRGL 8 18 33
TRGL 10 13 21
TRGL 11 21 27
TRGL 40 45 17
TRGL 40 19 24
TRGL 30 40 24
TRGL 1 7 44
TRGL 38 8 15
TRGL 5 3 32
TRGL 2 8 38
TRGL 16 4 5
TRGL 14 35 20
TRGL 17 14 28
TRGL 27 37 11
TRGL 37 31 11
TRGL 33 4 16
TRGL 41 36 26
TRGL 29 1 39
TRGL 8 44 18
TRGL 3 18 44
TRGL 15 8 33
TRGL 22 27 21
TRGL 1 2 39
TRGL 9 7 23
TRGL 45 35 17
TRGL 34 10 39
TRGL 7 1 23
TRGL 36 5 26
TRGL 28 14 37
TRGL 23 1 29
TRGL 32 3 7
TRGL 43 16 42
TRGL 31 23 29
END
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,48 @@
-24.629745 -24.184204 -12.972057
-4.565277 -24.184204 -28.674692
-24.629745 25.815796 -12.972057
16.807741 -24.184204 -9.482588
17.898199 -24.184204 -70.548363
16.807741 25.815796 -9.482588
17.898199 -24.184204 -70.548363
-24.411655 -24.184204 -69.894089
17.898199 25.815796 -70.548363
-24.629745 25.815796 -12.972057
-4.565277 -24.184204 -28.674692
-4.565277 25.815796 -28.674692
-4.565277 25.815796 -28.674692
16.807741 -24.184204 -9.482588
16.807741 25.815796 -9.482588
-24.411655 -24.184204 -69.894089
-24.629745 -24.184204 -12.972057
-24.411655 25.815796 -69.894089
16.807741 25.815796 -9.482588
17.898199 -24.184204 -70.548363
17.898199 25.815796 -70.548363
17.898199 25.815796 -70.548363
-24.411655 -24.184204 -69.894089
-24.411655 25.815796 -69.894089
-4.565277 25.815796 -28.674692
16.807741 25.815796 -9.482588
17.898199 25.815796 -70.548363
-24.411655 25.815796 -69.894089
-24.629745 25.815796 -12.972057
-4.565277 25.815796 -28.674692
16.807741 -24.184204 -9.482588
-4.565277 -24.184204 -28.674692
17.898199 -24.184204 -70.548363
-4.565277 -24.184204 -28.674692
-24.411655 -24.184204 -69.894089
17.898199 -24.184204 -70.548363
-24.411655 25.815796 -69.894089
-4.565277 25.815796 -28.674692
17.898199 25.815796 -70.548363
-24.411655 25.815796 -69.894089
-24.629745 -24.184204 -12.972057
-24.629745 25.815796 -12.972057
-24.629745 -24.184204 -12.972057
-24.411655 -24.184204 -69.894089
-4.565277 -24.184204 -28.674692
-4.565277 -24.184204 -28.674692
16.807741 -24.184204 -9.482588
-4.565277 25.815796 -28.674692
File diff suppressed because it is too large Load Diff