Skip to content

Commit

Permalink
fix code for conversion to double vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Jun 14, 2022
1 parent f93566d commit 3831541
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 490 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ install (FILES
${CMAKE_CURRENT_BINARY_DIR}/fastvoxel.py
DESTINATION fastvoxel/)

add_executable(fastvoxel ${FASTVOXEL_SOURCES})

if(WIN32)
#install(CODE "
Expand Down
File renamed without changes.
62 changes: 62 additions & 0 deletions demo/test_import_ply.py
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()
68 changes: 68 additions & 0 deletions demo/test_triangle_feed.py
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()
2 changes: 1 addition & 1 deletion fastvoxel/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .fastvoxel import vec3,ivec3,TriangleScalarFieldCreator
from .fastvoxel import dvec3, ivec3, TriangleScalarFieldCreator
192 changes: 0 additions & 192 deletions fastvoxel/fastvoxel.py

This file was deleted.

Loading

0 comments on commit 3831541

Please sign in to comment.