Exemplo n.º 1
0
    def __init__(self):
        self.splineInterval = [0.0, 1.0]

        screenBottom = np.array([-0.5, 0.2])
        screenTop = np.array([-0.5, 0.9])
        numPixels = 100
        self.screen = Screen(screenBottom, screenTop, numPixels)
        self.eye = np.array([-1.2, 0.65])

        self.viewRayDelta = 0.0005
        self.refTolerance = 1e-5

        self.voxelizationTolerance = 1e-5

        self.texDimSizes = np.array([8, 16, 32, 64, 128, 256, 512, 1024])
        self.numTextures = len(self.texDimSizes)

        self.numFiles = 0
        self.fileHandler = FileHandler()
Exemplo n.º 2
0
    def __init__(self):
        self.splineInterval = [0.0, 1.0]

        screenBottom = np.array([-0.5, 0.2])
        screenTop = np.array([-0.5, 0.9])
        numPixels = 10
        self.screen = Screen(screenBottom, screenTop, numPixels)
        self.eye = np.array([-1.2, 0.65])

        self.viewRayDelta = 1e-2
        self.viewRayDeltaRef = 1e-5
        self.refTolerance = 1e-5

        self.voxelizationTolerance = 1e-5

        self.autoDelta = True

        self.texDimSizes = np.array([64,128,192,256,320])#,384,448,512,576,640,704,768,896,1024])#,1152,1280,1408,1536,1664,1792,1920,2048])
        self.numTextures = len(self.texDimSizes)

        self.numFiles = 0
        self.fileHandler = FileHandler()
Exemplo n.º 3
0
    def __init__(self):
        self.splineInterval = [0.0, 1.0]

        screenBottom = np.array([-0.5, 0.2])
        screenTop = np.array([-0.5, 0.9])
        numPixels = 100
        self.screen = Screen(screenBottom, screenTop, numPixels)
        self.eye = np.array([-1.2, 0.65])

        self.refTolerance = 1e-5

        self.voxelizationTolerance = 1e-5

        self.viewRayDeltaRef = 0.0005
        self.viewRayDeltas = np.array([0.128, 0.064, 0.032, 0.016, 0.008, 0.004, 0.002, 0.001])

        self.allMethods = False
        self.texDimSize = 128
        self.numTextures = 1

        self.numFiles = 0
        self.fileHandler = FileHandler()
Exemplo n.º 4
0
class Main2:
    def __init__(self):
        self.splineInterval = [0.0, 1.0]

        screenBottom = np.array([-0.5, 0.2])
        screenTop = np.array([-0.5, 0.9])
        numPixels = 100
        self.screen = Screen(screenBottom, screenTop, numPixels)
        self.eye = np.array([-1.2, 0.65])

        self.viewRayDelta = 1e-2
        self.refTolerance = 1e-5

        self.voxelizationTolerance = 1e-5

        self.autoDelta = True

        self.texDimSizes = np.array([8, 16, 32, 64, 128, 256, 512, 1024])
        self.numTextures = len(self.texDimSizes)

        self.numFiles = 0
        self.fileHandler = FileHandler()

    @staticmethod
    def filedir(dataset):
        return 'output/results/{},{},{}'.format(dataset.rhoNumber, dataset.phiNumber, dataset.tfNumber)

    def save(self, dataset, obj):
        filedir = self.filedir(dataset)
        filename = '{0:03d}'.format(self.numFiles)

        self.fileHandler.setFiledir(filedir)
        self.fileHandler.save(obj, filename)

        self.numFiles += 1

    def run(self, rhoNo=1, phiNo=1, tfNo=1):
        dataset = Dataset(rhoNo, phiNo, tfNo)
        self.numFiles = 0

        renderer = Renderer(self.eye, self.screen)
        hybridRenderer = HybridRenderer(self.eye, self.screen)

        numTextures = self.numTextures

        rho = dataset.rho
        phi = dataset.phi
        tf = dataset.tf
        phiPlane = SplinePlane(phi, self.splineInterval, 1e-5)

        boundingBox = phiPlane.createBoundingBox()

        viewRayDeltaRef = boundingBox.getWidth() / (self.texDimSizes[-1]*2) / 2.0

        refSplineModel = SplineModel(tf, phiPlane, rho, self.refTolerance)
        directSplineModel = SplineModel(tf, phiPlane, rho)
        voxelModels = np.empty(numTextures, dtype=object)
        baModels = np.empty(numTextures, dtype=object)
        hybridModels = np.empty(numTextures, dtype=object)
        baHybridModels = np.empty(numTextures, dtype=object)

        for i in range(numTextures):
            texDimSize = self.texDimSizes[i]

            if voxelio.exist(dataset, texDimSize, texDimSize):
                samplingScalars = voxelio.read(dataset, texDimSize, texDimSize)
                print "Read {}x{} texture data from file".format(texDimSize, texDimSize)
            else:
                samplingScalars = refSplineModel.generateScalarMatrix(boundingBox, texDimSize, texDimSize,
                                                                      self.voxelizationTolerance)
                voxelio.write(dataset, samplingScalars)
                print "Wrote {}x{} texture data to file".format(texDimSize, texDimSize)

            scalarTexture = Texture2D(samplingScalars)

            voxelWidth = boundingBox.getWidth() / float(texDimSize)
            voxelHeight = boundingBox.getHeight() / float(texDimSize)
            criterion = GeometricCriterion(self.screen.pixelWidth, voxelWidth, voxelHeight)

            voxelModels[i] = VoxelModel(tf, scalarTexture, boundingBox)
            baModels[i] = BoundaryAccurateModel(tf, directSplineModel, voxelModels[i])
            hybridModels[i] = HybridModel(tf, directSplineModel, voxelModels[i], criterion)
            baHybridModels[i] = HybridModel(tf, directSplineModel, baModels[i], criterion)

        printflush("Rendering reference... ")
        renderData = RenderData(ModelType.REFERENCE, viewRayDeltaRef)
        renderData.renderResult = renderer.render(refSplineModel, viewRayDeltaRef)
        self.save(dataset, renderData)
        print "Done!"

        if not self.autoDelta:
            printflush("Rendering direct... ")
            renderData = RenderData(ModelType.DIRECT, self.viewRayDelta)
            renderData.renderResult = renderer.render(directSplineModel, self.viewRayDelta)
            self.save(dataset, renderData)
            print "Done!"

        for i, texSize in enumerate(self.texDimSizes):
            if self.autoDelta:
                voxelWidth = boundingBox.getWidth() / float(texSize)
                delta = voxelWidth/2.0

                printflush("Rendering direct...")
                renderData = RenderData(ModelType.DIRECT, delta)
                renderData.renderResult = renderer.render(directSplineModel, delta)
                self.save(dataset, renderData)
                print "Done!"
            else:
                delta = self.viewRayDelta

            printflush("Rendering voxelized ({0}x{0})...".format(texSize))
            renderData = RenderData(ModelType.VOXEL, delta=delta, texSize=texSize)
            renderData.renderResult = renderer.render(voxelModels[i], delta)
            self.save(dataset, renderData)
            print "Done!"

            printflush("Rendering boundary accurate ({0}x{0})...".format(texSize))
            renderData = RenderData(ModelType.BOUNDARYACCURATE, delta=delta, texSize=texSize)
            renderData.renderResult = renderer.render(baModels[i], delta)
            self.save(dataset, renderData)
            print "Done!"

            printflush("Rendering hybrid ({0}x{0})...".format(texSize))
            renderData = RenderData(ModelType.HYBRID, delta=delta, texSize=texSize)
            renderData.renderResult = hybridRenderer.render(hybridModels[i], delta)
            self.save(dataset, renderData)
            print "Done!"

            printflush("Rendering hybrid (boundary accurate) ({0}x{0})...".format(texSize))
            renderData = RenderData(ModelType.BAHYBRID, delta=delta, texSize=texSize)
            renderData.renderResult = hybridRenderer.render(baHybridModels[i], delta)
            self.save(dataset, renderData)
            print "Done!"

    def createSummaries(self, dataset):
        result = []

        for i in range(ModelType._COUNT):
            result.append([])

        filedir = self.filedir(dataset)
        self.fileHandler.setFiledir(filedir)

        files = self.fileHandler.findAll()
        refObj = self.fileHandler.load(files[0])

        for i in range(1, len(files)):
            obj = self.fileHandler.load(files[i])

            colorDiffs = colordiff.compare(refObj.renderResult.colors, obj.renderResult.colors)
            summary = Summary(obj, colorDiffs)
            result[obj.modelType].append(summary)

        return result

    def duplicateDirectSummary(self, summaries):
        summary = summaries[ModelType.DIRECT][0]

        for i in range(self.numTextures - 1):
            summaries[ModelType.DIRECT].append(summary)

    def plotGraphs(self, rhoNo=1, phiNo=1, tfNo=1):
        dataset = Dataset(rhoNo, phiNo, tfNo)
        graphFigure = GraphFigure(self.texDimSizes)

        summaries = self.createSummaries(dataset)

        if len(summaries[ModelType.DIRECT]) == 1:
            self.duplicateDirectSummary(summaries)

        graphFigure.graphSummaries(summaries[ModelType.DIRECT], 'Direct')
        graphFigure.graphSummaries(summaries[ModelType.VOXEL], 'Voxel')
        graphFigure.graphSummaries(summaries[ModelType.BOUNDARYACCURATE], 'Boundary accurate')
        graphFigure.graphSummaries(summaries[ModelType.HYBRID], 'Hybrid')
        graphFigure.graphSummaries(summaries[ModelType.BAHYBRID], 'Hybrid (BA)')
        graphFigure.show()

    def plotPixels(self, rhoNo=1, phiNo=1, tfNo=1):
        dataset = Dataset(rhoNo, phiNo, tfNo)
        pixelFigure = PixelFigure(self.texDimSizes)

        directPixels = []
        voxelPixels = []
        baPixels = []
        hybridPixels = []
        hybridVoxelRatios = []
        baHybridPixels = []
        baHybridVoxelRatios = []

        filedir = self.filedir(dataset)
        self.fileHandler.setFiledir(filedir)

        files = self.fileHandler.findAll()
        refObj = self.fileHandler.load(files[0])
        refPixels = refObj.renderResult.colors
        pixelFigure.refPixelsPlot.plotPixelColors(refPixels)

        for i in range(1, len(files)):
            obj = self.fileHandler.load(files[i])
            objPixels = obj.renderResult.colors

            if obj.modelType == ModelType.DIRECT:
                directPixels.append(objPixels)
            elif obj.modelType == ModelType.VOXEL:
                voxelPixels.append(objPixels)
            elif obj.modelType == ModelType.BOUNDARYACCURATE:
                baPixels.append(objPixels)
            elif obj.modelType == ModelType.HYBRID:
                hybridPixels.append(objPixels)
                hybridVoxelRatios.append(obj.renderResult.ratios)
            elif obj.modelType == ModelType.BAHYBRID:
                baHybridPixels.append(objPixels)
                baHybridVoxelRatios.append(obj.renderResult.ratios)

        if len(directPixels) == 1:
            pixels = directPixels[0]
            colorDiffs = colordiff.compare(refPixels, pixels)

            pixelFigure.directPixelsPlot.plotPixelColors(pixels)
            pixelFigure.directDiffsPlot.plotPixelColorDiffs(colorDiffs)

        for i in range(len(voxelPixels)):
            pixels = voxelPixels[i]
            colorDiffs = colordiff.compare(refPixels, pixels)
            pixelFigure.voxelPixelsPlots[i].plotPixelColors(pixels)
            pixelFigure.voxelDiffsPlots[i].plotPixelColorDiffs(colorDiffs)

            pixels = baPixels[i]
            colorDiffs = colordiff.compare(refPixels, pixels)
            pixelFigure.baPixelsPlots[i].plotPixelColors(pixels)
            pixelFigure.baDiffsPlots[i].plotPixelColorDiffs(colorDiffs)

            pixels = hybridPixels[i]
            colorDiffs = colordiff.compare(refPixels, pixels)
            pixelFigure.hybridPixelsPlots[i].plotPixelColors(pixels)
            pixelFigure.hybridDiffsPlots[i].plotPixelColorDiffs(colorDiffs)
            pixelFigure.hybridVoxelRatioPlots[i].plotRatios(hybridVoxelRatios[i])

        pixelFigure.show()

    def printSummary(self, rhoNo=1, phiNo=1, tfNo=1):
        dataset = Dataset(rhoNo, phiNo, tfNo)
        summaries = self.createSummaries(dataset)

        for modelSummaries in summaries:
            for modelSummary in modelSummaries:
                modelSummary.printData()
                print ""
Exemplo n.º 5
0
    ModelType.VOXEL : 'Voxelized',
    ModelType.BOUNDARYACCURATE : 'Boundary accurate',
    ModelType.HYBRID : 'Hybrid (direct/voxelized)',
    ModelType.BAHYBRID : 'Hybrid (direct/boundary accurate)'
}


figs = []
gss = []
axs = []
plotters = []
legendFig = plt.figure(figsize=[6, 6])

dataset = Dataset(rhoNo, phiNo, tfNo)

fileHandler = FileHandler()
fileHandler.setFiledir('output/results/{},{},{}'.format(rhoNo, phiNo, tfNo))

summaries = summary.createSummaries(fileHandler, dataset)

texDimSizes = []
viewRayDeltas = np.array([0.128, 0.064, 0.032, 0.016, 0.008, 0.004, 0.002, 0.001])

for voxelSummary in summaries[ModelType.VOXEL]:
    texDimSizes.append(voxelSummary.renderData.texSize)

for i in range(3):
    fig = plt.figure(figsize=[6, 6])
    gs = GridSpec(1, 1)
    ax = fig.add_subplot(gs[0, 0])
    ax.set_xscale('log', basex=2)
Exemplo n.º 6
0
screenBottom = 0.2
screen = Screen(pixelX, screenTop, screenBottom, numPixels)

refIntersectTolerance = 1e-5
refTolerance = 1e-5
viewRayDeltaRef = 1e-5

phi = dataset.phi
rho = dataset.rho
tf = dataset.tf
refPhiPlane = SplinePlane(phi, splineInterval, refIntersectTolerance)

refSplineModel = SplineModel(tf, refPhiPlane, rho, refTolerance)

renderer = Renderer(eye, screen)
renderData = RenderData(ModelType.REFERENCE, viewRayDeltaRef)
renderData.renderResult = renderer.render(refSplineModel, viewRayDeltaRef)

fileHandler = FileHandler()
fileHandler.setFiledir('output/vgresults')
fileHandler.save(renderData, 'reference')

pref = PixelPlotter(axref)
pref.plotPixelColors(renderData.renderResult.colors)
axref.set_aspect(aspectRatio)

figref.tight_layout()

plt.figure(figref.number)
plt.savefig("output/vg/pixelsReference.pdf", format="pdf", transparent=True)
Exemplo n.º 7
0
class Main2:
    def __init__(self):
        self.splineInterval = [0.0, 1.0]

        screenBottom = np.array([-0.5, 0.2])
        screenTop = np.array([-0.5, 0.9])
        numPixels = 100
        self.screen = Screen(screenBottom, screenTop, numPixels)
        self.eye = np.array([-1.2, 0.65])

        self.refTolerance = 1e-5

        self.voxelizationTolerance = 1e-5

        self.viewRayDeltaRef = 0.0005
        self.viewRayDeltas = np.array([0.128, 0.064, 0.032, 0.016, 0.008, 0.004, 0.002, 0.001])

        self.allMethods = False
        self.texDimSize = 128
        self.numTextures = 1

        self.numFiles = 0
        self.fileHandler = FileHandler()

    @staticmethod
    def filedir(dataset):
        return 'output/results/{},{},{}'.format(dataset.rhoNumber, dataset.phiNumber, dataset.tfNumber)

    def save(self, dataset, obj):
        filedir = self.filedir(dataset)
        filename = '{0:03d}'.format(self.numFiles)

        self.fileHandler.setFiledir(filedir)
        self.fileHandler.save(obj, filename)

        self.numFiles += 1

    def run(self, rhoNo=1, phiNo=1, tfNo=1):
        dataset = Dataset(rhoNo, phiNo, tfNo)
        self.numFiles = 0

        renderer = Renderer(self.eye, self.screen)
        hybridRenderer = HybridRenderer(self.eye, self.screen)

        numTextures = self.numTextures

        rho = dataset.rho
        phi = dataset.phi
        tf = dataset.tf
        phiPlane = SplinePlane(phi, self.splineInterval, 1e-5)

        boundingBox = phiPlane.createBoundingBox()

        refSplineModel = SplineModel(tf, phiPlane, rho, self.refTolerance)
        directSplineModel = SplineModel(tf, phiPlane, rho)
        voxelModels = np.empty(numTextures, dtype=object)
        baModels = np.empty(numTextures, dtype=object)
        hybridModels = np.empty(numTextures, dtype=object)
        baHybridModels = np.empty(numTextures, dtype=object)

        for i in range(numTextures):
            texDimSize = self.texDimSize

            if voxelio.exist(dataset, texDimSize, texDimSize):
                samplingScalars = voxelio.read(dataset, texDimSize, texDimSize)
                print "Read {}x{} texture data from file".format(texDimSize, texDimSize)
            else:
                samplingScalars = refSplineModel.generateScalarMatrix(boundingBox, texDimSize, texDimSize,
                                                                      self.voxelizationTolerance)
                voxelio.write(dataset, samplingScalars)
                print "Wrote {}x{} texture data to file".format(texDimSize, texDimSize)

            scalarTexture = Texture2D(samplingScalars)

            voxelWidth = boundingBox.getHeight() / float(texDimSize)
            criterion = GeometricCriterion(self.screen.pixelWidth, voxelWidth)

            voxelModels[i] = VoxelModel(tf, scalarTexture, boundingBox)
            baModels[i] = BoundaryAccurateModel(tf, directSplineModel, voxelModels[i])
            hybridModels[i] = HybridModel(tf, directSplineModel, voxelModels[i], criterion)
            baHybridModels[i] = HybridModel(tf, directSplineModel, baModels[i], criterion)

        printflush("Rendering reference... ")
        renderData = RenderData(ModelType.REFERENCE, self.viewRayDeltaRef)
        renderData.renderResult = renderer.render(refSplineModel, self.viewRayDeltaRef)
        self.save(dataset, renderData)
        print "Done!"

        for delta in self.viewRayDeltas:
            texSize = self.texDimSize

            printflush("Rendering direct (delta = {})...".format(delta))
            renderData = RenderData(ModelType.DIRECT, delta)
            renderData.renderResult = renderer.render(directSplineModel, delta)
            self.save(dataset, renderData)
            print "Done!"

            printflush("Rendering voxelized (delta = {})...".format(delta))
            renderData = RenderData(ModelType.VOXEL, delta=delta, texSize=texSize)
            renderData.renderResult = renderer.render(voxelModels[i], delta)
            self.save(dataset, renderData)
            print "Done!"

            if self.allMethods:
                printflush("Rendering boundary accurate (delta = {})...".format(delta))
                renderData = RenderData(ModelType.BOUNDARYACCURATE, delta=delta, texSize=texSize)
                renderData.renderResult = renderer.render(baModels[i], delta)
                self.save(dataset, renderData)
                print "Done!"

                printflush("Rendering hybrid (delta = {})...".format(delta))
                renderData = RenderData(ModelType.HYBRID, delta=delta, texSize=texSize)
                renderData.renderResult = hybridRenderer.render(hybridModels[i], delta)
                self.save(dataset, renderData)
                print "Done!"

                printflush("Rendering hybrid (delta = {})...".format(delta))
                renderData = RenderData(ModelType.BAHYBRID, delta=delta, texSize=texSize)
                renderData.renderResult = hybridRenderer.render(baHybridModels[i], delta)
                self.save(dataset, renderData)
                print "Done!"

    def createSummaries(self, dataset):
        result = []

        for i in range(ModelType._COUNT):
            result.append([])

        filedir = self.filedir(dataset)
        self.fileHandler.setFiledir(filedir)

        files = self.fileHandler.findAll()
        refObj = self.fileHandler.load(files[0])

        for i in range(1, len(files)):
            obj = self.fileHandler.load(files[i])

            colorDiffs = colordiff.compare(refObj.renderResult.colors, obj.renderResult.colors)
            summary = Summary(obj, colorDiffs)
            result[obj.modelType].append(summary)

        return result

    def duplicateDirectSummary(self, summaries):
        summary = summaries[ModelType.DIRECT][0]

        for i in range(self.numTextures - 1):
            summaries[ModelType.DIRECT].append(summary)

    def plotGraphs(self, rhoNo=1, phiNo=1, tfNo=1):
        dataset = Dataset(rhoNo, phiNo, tfNo)
        graphFigure = GraphFigure(self.viewRayDeltas, True)

        summaries = self.createSummaries(dataset)

        if len(summaries[ModelType.DIRECT]) == 1:
            self.duplicateDirectSummary(summaries)

        graphFigure.graphSummaries(summaries[ModelType.DIRECT], 'Direct')
        graphFigure.graphSummaries(summaries[ModelType.VOXEL], 'Voxel')

        if self.allMethods:
            graphFigure.graphSummaries(summaries[ModelType.BOUNDARYACCURATE], 'Boundary accurate')
            graphFigure.graphSummaries(summaries[ModelType.HYBRID], 'Hybrid')
            graphFigure.graphSummaries(summaries[ModelType.BAHYBRID], 'Hybrid (BA)')

        graphFigure.show()

    def printSummary(self, rhoNo=1, phiNo=1, tfNo=1):
        dataset = Dataset(rhoNo, phiNo, tfNo)
        summaries = self.createSummaries(dataset)

        for modelSummaries in summaries:
            for modelSummary in modelSummaries:
                modelSummary.printData()
                print ""
Exemplo n.º 8
0
    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()