-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix code for conversion to double vectors
- Loading branch information
Showing
21 changed files
with
312 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import fastvoxel as fv | ||
import numpy as np | ||
import time | ||
|
||
|
||
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 (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 + 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() | ||
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) | ||
|
||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- coding: cp1252 -*- | ||
import numpy as np | ||
import fastvoxel as fv | ||
import time | ||
|
||
boxmin = fv.dvec3(0, 0, 0) | ||
boxmax = fv.dvec3(5, 5, 5) | ||
|
||
voxelizator = fv.TriangleScalarFieldCreator(0.5) | ||
|
||
voxelizator.first_step_params(boxmin, boxmax) | ||
# Définition des 8 sommets du cube | ||
sommets = [fv.dvec3(5.0, 0.0, 0.0), | ||
fv.dvec3(0.0, 0.0, 0.0), | ||
fv.dvec3(0.0, 5.0, 0.0), | ||
fv.dvec3(5.0, 5.0, 0.0), | ||
fv.dvec3(0.0, 5.0, 5.0), | ||
fv.dvec3(5.0, 5.0, 5.0), | ||
fv.dvec3(0.0, 0.0, 5.0), | ||
fv.dvec3(5.0, 0.0, 5.0) | ||
] | ||
# 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.dvec3(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], | ||
[100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], | ||
[100, 102, 102, 102, 102, 102, 102, 102, 102, 102, 100], | ||
[100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]], dtype=np.short) | ||
print("Copy matrix ok ?", (pieceof[:, :, pieceof.shape[2] // 2] == expected_res).all()) | ||
|
||
# import matplotlib.pyplot as plt | ||
# from pylab import show | ||
# plt.matshow(pieceof[:,:,0],fignum=2) | ||
# show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .fastvoxel import vec3,ivec3,TriangleScalarFieldCreator | ||
from .fastvoxel import dvec3, ivec3, TriangleScalarFieldCreator |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.