-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
317 additions
and
182 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data_path = '/orion/downloads/AdversarialTexture/data' |
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
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
Empty file.
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,64 @@ | ||
from ctypes import * | ||
import numpy as np | ||
Sens = cdll.LoadLibrary('./Rasterizer/libSens.so') | ||
|
||
def LoadSens(filename): | ||
print(filename) | ||
Sens.Parse(c_char_p(filename.encode('utf8'))) | ||
depth_width = Sens.DW() | ||
depth_height = Sens.DH() | ||
color_width = Sens.CW() | ||
color_height = Sens.CH() | ||
frames = Sens.Frames() | ||
depths = np.zeros((frames, depth_height, depth_width), dtype='float32') | ||
colors = np.zeros((frames, color_height, color_width, 3), dtype='uint8') | ||
cam2worlds = np.zeros((frames, 4, 4), dtype='float32') | ||
intrinsic = np.zeros((4,4), dtype='float32') | ||
|
||
Sens.GetData(c_void_p(depths.ctypes.data), c_void_p(colors.ctypes.data), c_void_p(cam2worlds.ctypes.data), c_void_p(intrinsic.ctypes.data)) | ||
Sens.Clear() | ||
depths = np.nan_to_num(depths) | ||
return colors, depths, cam2worlds, intrinsic | ||
|
||
def LoadOBJ(filename): | ||
lines = [l.strip() for l in open(filename)] | ||
V = [] | ||
VT = [] | ||
VN = [] | ||
F = [] | ||
FT = [] | ||
FN = [] | ||
for l in lines: | ||
words = [w for w in l.split(' ') if w != ''] | ||
if words[0] == 'v': | ||
V.append([float(words[1]), float(words[2]), float(words[3])]) | ||
elif words[0] == 'vt': | ||
VT.append([float(words[1]), float(words[2])]) | ||
elif words[0] == 'vn': | ||
VN.append([float(words[1]), float(words[2]), float(words[3])]) | ||
elif words[0] == 'f': | ||
f = [] | ||
ft = [] | ||
fn = [] | ||
for j in range(1, 4): | ||
w = words[j].split('/') | ||
f.append(int(w[0])-1) | ||
ft.append(int(w[1])-1) | ||
fn.append(int(w[2])-1) | ||
F.append(f) | ||
FT.append(ft) | ||
FN.append(fn) | ||
|
||
V = np.array(V, dtype='float32') | ||
VT = np.array(VT, dtype='float32') | ||
VN = np.array(VN, dtype='float32') | ||
F = np.array(F, dtype='int32') | ||
FT = np.array(FT, dtype='int32') | ||
FN = np.array(FN, dtype='int32') | ||
|
||
return V, F, VT, FT, VN, FN | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
LoadSens(sys.argv[1]) | ||
V,F,VT,FT,_,_ = LoadOBJ(sys.argv[2]) |
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,20 @@ | ||
from ctypes import * | ||
import numpy as np | ||
Painter = cdll.LoadLibrary('./Rasterizer/libPainter.so') | ||
|
||
def ProjectPaint(points, normals, point_colors, color, depth, world2cam, intrinsic): | ||
Painter.ProjectPaint(c_void_p(points.ctypes.data), c_void_p(normals.ctypes.data), c_void_p(point_colors.ctypes.data), | ||
c_void_p(color.ctypes.data), c_void_p(depth.ctypes.data), c_void_p(world2cam.ctypes.data), c_void_p(intrinsic.ctypes.data), | ||
c_int(points.shape[0]), c_int(depth.shape[1]), c_void_p(depth.shape[0]), c_void_p(color.shape[1]), c_void_p(color.shape[0])) | ||
|
||
def PaintToTexturemap(texturemap, point_colors, coords): | ||
Painter.PaintToTexturemap(c_void_p(texturemap.ctypes.data), c_void_p(point_colors.ctypes.data), c_void_p(coords.ctypes.data), | ||
c_int(point_colors.shape[0]), c_int(texturemap.shape[1]), c_int(texturemap.shape[0])) | ||
|
||
def PaintToViewNorm(points_cam, normals_cam, mask, depth, coords, textureToImage): | ||
Painter.PaintToViewNorm(c_void_p(textureToImage.ctypes.data), c_void_p(points_cam.ctypes.data), c_void_p(normals_cam.ctypes.data), c_void_p(mask.ctypes.data), | ||
c_void_p(depth.ctypes.data), c_void_p(coords.ctypes.data), c_int(points_cam.shape[0]), c_int(mask.shape[0]), c_int(mask.shape[1]), c_int(textureToImage.shape[1])) | ||
|
||
def PaintToView(points_cam, mask, depth, coords, textureToImage): | ||
Painter.PaintToView(c_void_p(textureToImage.ctypes.data), c_void_p(points_cam.ctypes.data), c_void_p(mask.ctypes.data), | ||
c_void_p(depth.ctypes.data), c_void_p(coords.ctypes.data), c_int(points_cam.shape[0]), c_int(mask.shape[0]), c_int(mask.shape[1]), c_int(textureToImage.shape[1])) |
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,45 @@ | ||
from ctypes import * | ||
import numpy as np | ||
import os | ||
libpath = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
Rasterizer = cdll.LoadLibrary(libpath + '/Rasterizer/libRasterizer.so') | ||
|
||
def RasterizeTexture(VT, FT, height, width): | ||
color = np.zeros((height,width,3), dtype='float32') | ||
zbuffer = np.zeros((height, width), dtype='float32') | ||
findices = np.zeros((height, width), dtype='int32') | ||
findices[:,:] = -1 | ||
Rasterizer.RasterizeTexture(c_void_p(VT.ctypes.data), c_void_p(FT.ctypes.data), c_void_p(color.ctypes.data), | ||
c_void_p(zbuffer.ctypes.data), c_void_p(findices.ctypes.data), c_int(FT.shape[0]), width, height) | ||
|
||
return color, findices | ||
|
||
|
||
def RasterizeImage(V, F, width, height, intrinsic, world2cam): | ||
vweights = np.zeros((height, width, 3), dtype='float32') | ||
findices = np.zeros((height, width), dtype='int32') | ||
zbuffer = np.zeros((height, width), dtype='float32') | ||
findices[:,:] = -1 | ||
Rasterizer.RasterizeImage(c_void_p(V.ctypes.data), c_void_p(F.ctypes.data), c_void_p(world2cam.ctypes.data), c_void_p(intrinsic.ctypes.data), | ||
c_void_p(vweights.ctypes.data), c_void_p(zbuffer.ctypes.data), c_void_p(findices.ctypes.data), c_int(F.shape[0]), c_int(width), c_int(height)) | ||
return vweights, findices | ||
|
||
def GeneratePoints(V, F, VN, FN, vweights, findices): | ||
num_points = np.sum(findices >= 0) | ||
points = np.zeros((num_points, 3), dtype='float32') | ||
normals = np.zeros((num_points, 3), dtype='float32') | ||
coords = np.zeros((num_points, 2), dtype='int32') | ||
Rasterizer.GenerateTextiles(c_void_p(V.ctypes.data), c_void_p(F.ctypes.data), c_void_p(VN.ctypes.data), c_void_p(FN.ctypes.data), | ||
c_void_p(points.ctypes.data), c_void_p(normals.ctypes.data), c_void_p(coords.ctypes.data), | ||
c_void_p(findices.ctypes.data), c_void_p(vweights.ctypes.data), c_int(findices.shape[1]), c_int(findices.shape[0])) | ||
return points, normals, coords | ||
|
||
def RenderUV(vweights, findices, VT, FT): | ||
uv = np.zeros((vweights.shape[0], vweights.shape[1], 3), dtype='float32') | ||
#void RenderUV(glm::vec3* uv, glm::vec3* vweights, int* findices, glm::vec2* VT, glm::ivec3* FT, int width, int height) | ||
|
||
Rasterizer.RenderUV(c_void_p(uv.ctypes.data), c_void_p(vweights.ctypes.data), c_void_p(findices.ctypes.data), | ||
c_void_p(VT.ctypes.data), c_void_p(FT.ctypes.data), | ||
c_int(uv.shape[1]), c_int(uv.shape[0])) | ||
return uv |
Oops, something went wrong.