def run(): resolution = 0.1 doplot = True doexportvtk = False if doexportvtk: resolution = 0.5 deb = time.time() # Init Voxelisation with precision in meter voxelizator = fv.TriangleScalarFieldCreator(resolution) # Load PLY polygonal file voxelizator.load_ply_model("elmia.ply") print("Process done in %f sec" % (time.time() - deb)) # Extract the cell i,j,k values corresponding to position in meter (a position in the volume to extract) cellid = voxelizator.get_cell_id_by_coord(fv.dvec3(7, -0.5, 1)) # Get the corresponding volume id elmiavol = voxelizator.get_matrix_value(cellid) # Extract Boundary of this volume minv = fv.ivec3() maxv = fv.ivec3() voxelizator.get_cell_value_boundaries(minv, maxv, elmiavol) minv -= fv.ivec3(1, 1, 1) maxv += fv.ivec3(1, 1, 1) extract_shape = maxv - minv print("Matrix Size is %ix%ix%i" % (extract_shape[0], extract_shape[1], extract_shape[2])) # Plotting if doplot: print("voxelizator.get_first_volume_index():", voxelizator.get_first_volume_index()) nbmarkers = voxelizator.get_first_volume_index( ) + voxelizator.get_volume_count() # Create a matrix to extract only an Y slice of the 3D voxelisation (saves lot of memory) pieceof = np.zeros((extract_shape[0], 1, extract_shape[2]), dtype=np.short) # Transfer data from voxel to numpy matrix data_filt = np.arange(nbmarkers, dtype=np.short) data_filt[voxelizator.get_first_volume_index( ):] = -1 # Set -1 to all volumes data_filt[elmiavol] = 0 # Set 0 to air voxelizator.copy_matrix_filtered(pieceof, minv + fv.ivec3(0, cellid[1], 0), data_filt) import matplotlib.pyplot as plt from matplotlib import cm from pylab import show, colorbar p = plt.matshow(np.rot90(pieceof[:, 0, :]), fignum=2, cmap=cm.get_cmap('jet', nbmarkers)) colorbar(p, ticks=range(nbmarkers)) show()
def run(): resolution=0.1 doplot=True doexportvtk=False if doexportvtk: resolution=0.5 deb=time.time() #Init Voxelisation with precision in meter voxelizator=fv.TriangleScalarFieldCreator(resolution) #Load PLY polygonal file voxelizator.load_ply_model("elmia.ply") print "Process done in %f sec" % (time.time()-deb) #Extract the cell i,j,k values corresponding to position in meter (a position in the volume to extract) cellid=voxelizator.get_cell_id_by_coord(vec3(7,-0.5,1)) #Get the corresponding volume id elmiavol=voxelizator.get_matrix_value(cellid) #Extract Boundary of this volume minv=fv.ivec3() maxv=fv.ivec3() voxelizator.get_cell_value_boundaries(minv,maxv,elmiavol) minv-=fv.ivec3(1,1,1) maxv+=fv.ivec3(1,1,1) extract_shape=maxv-minv print "Matrix Size is %ix%ix%i" % (extract_shape[0],extract_shape[1],extract_shape[2]) #Plotting if doplot: print "voxelizator.get_first_volume_index():",voxelizator.get_first_volume_index() nbmarkers=voxelizator.get_first_volume_index()+voxelizator.get_volume_count() #Create a matrix to extract only an Y slice of the 3D voxelisation (save lot of memory) pieceof=np.zeros((extract_shape[0],1,extract_shape[2]),dtype=np.short) #Transfer data from voxel to numpy matrix data_filt=np.arange(nbmarkers,dtype=np.short) data_filt[voxelizator.get_first_volume_index():]=-1 #Set -1 to all volumes data_filt[elmiavol]=0 #Set 0 to air voxelizator.copy_matrix_filtered(pieceof,minv+ivec3(0,cellid[1],0),data_filt) import matplotlib.pyplot as plt from matplotlib import cm from pylab import show,colorbar p=plt.matshow(np.rot90(pieceof[:,0,:]),fignum=2,cmap=cm.get_cmap('jet', nbmarkers)) colorbar(p,ticks=range(nbmarkers)) show() elif doexportvtk: from evtk.hl import imageToVTK #Create a matrix to extract only an Y slice of the 3D voxelisation (save lot of memory) pieceof=np.zeros((extract_shape[0],extract_shape[1],extract_shape[2]),dtype=np.short) #Transfer data from voxel to numpy matrix voxelizator.copy_matrix(pieceof,minv) imageToVTK(r"C:\tmp\elmia",cellData = {"materials" : np.array(pieceof,dtype="float32")}) time.sleep(1)
def __getitem__(self, key): if len(key)!=3: raise(NotImplementedError("Only 3 dimensional matrix get value supported")) get_origin_pos=[0,0,0] get_destination_pos=[0,0,0] single_dim=[slice(None),slice(None),slice(None)] has_single=False for dim in range(3): if type(key[dim]) is slice: #Range range_get=key[dim].indices(self.shape[dim]) get_origin_pos[dim]=range_get[0] get_destination_pos[dim]=range_get[1] else: #get only one item has_single=True single_dim[dim]=0 get_origin_pos[dim]=key[dim] get_destination_pos[dim]=key[dim]+1 ret_shape=tuple(list(as_long_array(get_destination_pos)-as_long_array(get_origin_pos))) ret_value=np.empty(shape=ret_shape,dtype=self.dtype) vget_origin_pos=ivec3(get_origin_pos[0],get_origin_pos[1],get_origin_pos[2]) if self._filter is None: self._fastvoxel.copy_matrix(ret_value,vget_origin_pos+self._vrange_beg) else: self._fastvoxel.copy_matrix_filtered(ret_value,vget_origin_pos+self._vrange_beg,self._filter) if not has_single: return ret_value else: return ret_value[tuple(single_dim)]
def __init__(self,fastvoxel,shape=None,range_beg=None): self._fastvoxel=fastvoxel self.dtype=np.short if shape is None: shape=(fastvoxel.get_domain_size(),fastvoxel.get_domain_size(),fastvoxel.get_domain_size()) self.shape=shape if range_beg is None: range_beg=(0,0,0) self._vrange_beg=ivec3(range_beg[0],range_beg[1],range_beg[2]) self._filter=None
] #Définition des 12 faces triangulaire du cube # [ sommetA, sommetB, sommetC, idencombrement, idmateriau, idrecepteursurf ] faces = [[0, 1, 2, -1, 66, -1], [0, 2, 3, -1, 66, -1], [2, 4, 5, -1, 100, -1], [2, 5, 3, -1, 100, -1], [2, 6, 4, -1, 100, -1], [2, 1, 6, -1, 100, -1], [1, 0, 7, -1, 100, -1], [6, 1, 7, -1, 100, -1], [0, 3, 5, -1, 100, -1], [7, 0, 5, -1, 100, -1], [7, 5, 4, -1, 66, -1], [6, 7, 4, -1, 66, -1]] for facedata in faces: voxelizator.second_step_pushtri(sommets[facedata[0]], sommets[facedata[1]], sommets[facedata[2]], facedata[4]) voxelizator.third_step_volumescreator() cellid = voxelizator.get_cell_id_by_coord(fv.vec3(2.5, 2.5, 2.5)) cubevol = voxelizator.get_matrix_value(cellid) minv = fv.ivec3() maxv = fv.ivec3() voxelizator.get_cell_value_boundaries(minv, maxv, cubevol) minv -= fv.ivec3(1, 1, 1) maxv += fv.ivec3(1, 1, 1) extract_shape = maxv - minv pieceof = np.zeros((extract_shape[0], extract_shape[1], extract_shape[2]), dtype=np.short) voxelizator.copy_matrix(pieceof, minv) expected_res = np.asarray( [[100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100],
[2, 1, 6, -1, 100, -1], [1, 0, 7, -1, 100, -1], [6, 1, 7, -1, 100, -1], [0, 3, 5, -1, 100, -1], [7, 0, 5, -1, 100, -1], [7, 5, 4, -1, 66, -1], [6, 7, 4, -1, 66, -1] ] for facedata in faces: voxelizator.second_step_pushtri(sommets[facedata[0]], sommets[facedata[1]], sommets[facedata[2]],facedata[4]) voxelizator.third_step_volumescreator() cellid=voxelizator.get_cell_id_by_coord(fv.vec3(2.5,2.5,2.5)) cubevol=voxelizator.get_matrix_value(cellid) minv=fv.ivec3() maxv=fv.ivec3() voxelizator.get_cell_value_boundaries(minv,maxv,cubevol) minv-=fv.ivec3(1,1,1) maxv+=fv.ivec3(1,1,1) extract_shape=maxv-minv pieceof=np.zeros((extract_shape[0],extract_shape[1],extract_shape[2]),dtype=np.short) voxelizator.copy_matrix(pieceof,minv) expected_res=np.asarray([[100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], [100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100],