/
vgpixels.py
143 lines (113 loc) · 3.97 KB
/
vgpixels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import matplotlib.pyplot as plt
import numpy as np
import sys
from matplotlib.gridspec import GridSpec
import colordiff
from fileio.filehandler import FileHandler
from model.boundaryaccuratemodel import BoundaryAccurateModel
from model.hybridmodel import HybridModel
from model.splinemodel import SplineModel
from model.voxelmodel import VoxelModel
from plotting.pixelplotter import PixelPlotter
from voxelcriterion.geometriccriterion import GeometricCriterion
from dataset import Dataset
from hybridrenderer import HybridRenderer
from renderer import Renderer
from screen import Screen
from splineplane import SplinePlane
from texture import Texture2D
modelChoice = int(sys.argv[1])
texDimSize = int(sys.argv[2])
numPixels = 100
figsize = [8, 0.5]
aspectRatio = numPixels / 50.0
fig = plt.figure(figsize=figsize)
gs = GridSpec(1, 1)
ax = fig.add_subplot(gs[0, 0])
figdiff = plt.figure(figsize=figsize)
gsdiff = GridSpec(1, 1)
axdiff = figdiff.add_subplot(gsdiff[0, 0])
figratio = plt.figure(figsize=figsize)
gsratio = GridSpec(1, 1)
axratio = figratio.add_subplot(gsratio[0, 0])
dataset = Dataset(1, 1, 2)
splineInterval = np.array([0.0, 1.0])
eye = np.array([-1.2, 0.65])
pixelX = -0.5
screenTop = 0.9
screenBottom = 0.2
screen = Screen(pixelX, screenTop, screenBottom, numPixels)
refIntersectTolerance = 1e-5
refTolerance = 1e-5
voxTolerance = 1e-5
viewRayDelta = 0.005
phi = dataset.phi
rho = dataset.rho
tf = dataset.tf
refPhiPlane = SplinePlane(phi, splineInterval, refIntersectTolerance)
boundingBox = refPhiPlane.createBoundingBox()
refSplineModel = SplineModel(tf, refPhiPlane, rho, refTolerance)
directSplineModel = SplineModel(tf, refPhiPlane, rho)
voxelModel = None
voxelWidth = boundingBox.getHeight() / float(texDimSize)
criterion = GeometricCriterion(screen.pixelWidth, voxelWidth)
if modelChoice != 0:
samplingScalars = refSplineModel.generateScalarMatrix(boundingBox, texDimSize, texDimSize, voxTolerance)
texture = Texture2D(samplingScalars)
voxelModel = VoxelModel(tf, texture, boundingBox)
model = None
name = ''
if modelChoice == 0:
# Direct
model = directSplineModel
name = 'Direct'
elif modelChoice == 1:
# Voxel
model = voxelModel
name = 'Voxel{}'.format(texDimSize)
elif modelChoice == 2:
# Boundary accurate
model = BoundaryAccurateModel(tf, directSplineModel, voxelModel)
name = 'Ba{}'.format(texDimSize)
elif modelChoice == 3:
# Hybrid (Direct/Voxelized)
model = HybridModel(tf, directSplineModel, voxelModel, criterion)
name = 'Hybrid{}'.format(texDimSize)
elif modelChoice == 4:
# Hybrid (Direct/Boundary accurate)
baModel = BoundaryAccurateModel(tf, directSplineModel, voxelModel)
model = HybridModel(tf, directSplineModel, baModel, criterion)
name = 'BaHybrid{}'.format(texDimSize)
ratios = None
if modelChoice == 3 or modelChoice == 4:
renderer = HybridRenderer(eye, screen)
renderResult = renderer.render(model, viewRayDelta)
ratios = renderResult.ratios
else:
renderer = Renderer(eye, screen)
renderResult = renderer.render(model, viewRayDelta)
colors = renderResult.colors
fileHandler = FileHandler()
fileHandler.setFiledir('output/vgresults')
refObj = fileHandler.load('reference.pkl')
refColors = refObj.renderResult.colors
colorDiffs = colordiff.compare(refColors, colors)
p = PixelPlotter(ax)
p.plotPixelColors(colors)
ax.set_aspect(aspectRatio)
pdiff = PixelPlotter(axdiff)
pdiff.plotPixelColorDiffs(colorDiffs)
axdiff.set_aspect(aspectRatio)
fig.tight_layout()
figdiff.tight_layout()
plt.figure(fig.number)
plt.savefig("output/vg/pixels{}.pdf".format(name), format="pdf", transparent=True)
plt.figure(figdiff.number)
plt.savefig("output/vg/pixels{}Diff.pdf".format(name), format="pdf", transparent=True)
if modelChoice == 3 or modelChoice == 4:
pratio = PixelPlotter(axratio)
pratio.plotRatios(ratios)
axratio.set_aspect(aspectRatio)
figratio.tight_layout()
plt.figure(figratio.number)
plt.savefig("output/vg/pixels{}Ratio.pdf".format(name), format="pdf", transparent=True)