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

        renderer = Renderer(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)
        voxelModels = 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)

            voxelModels[i] = VoxelModel(tf, scalarTexture, boundingBox)

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

        for i, texSize in enumerate(self.texDimSizes):
            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!"
示例#2
0
    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!"
示例#3
0
    def run(self, rhoNo=1, phiNo=0, tfNo=1):
        dataset = Dataset(rhoNo, phiNo, tfNo)
        texDimSize = 128

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

        rho = dataset.rho
        phi = dataset.phi
        tf = dataset.tf
        phiPlane = SplinePlane(phi, self.splineInterval, self.intersectTolerance)

        boundingBox = phiPlane.createBoundingBox()

        plotter = Plotter(self.splineInterval)
        refSplinePlotter = plotter.refSplineModelPlotter
        directSplinePlotter = plotter.directSplineModelPlotter
        voxelPlotter = plotter.voxelModelPlotter
        paramPlotter = plotter.paramPlotter

        refSplinePlotter.plotGrid(phi.evaluate, 10, 10)
        directSplinePlotter.plotGrid(phi.evaluate, 10, 10)

        paramPlotter.plotGrid(10, 10)
        paramPlotter.plotScalarField(rho, tf)

        refSplinePlotter.plotBoundingBox(boundingBox)
        directSplinePlotter.plotBoundingBox(boundingBox)
        voxelPlotter.plotBoundingBox(boundingBox)

        # Creating models
        refSplineModel = SplineModel(tf, phiPlane, rho, self.refTolerance)
        directSplineModel = SplineModel(tf, phiPlane, rho)

        samplingScalars = refSplineModel.generateScalarMatrix(boundingBox, texDimSize, texDimSize,
                                                              self.voxelizationTolerance)
        #voxelPlotter.plotScalars(samplingScalars, boundingBox)

        scalarTexture = Texture2D(samplingScalars)
        plotter.plotScalarTexture(scalarTexture)

        voxelModel = VoxelModel(tf, scalarTexture, boundingBox)

        choice = 0

        if choice == 0:
            model = voxelModel
            modelType = ModelType.VOXEL
        elif choice == 1:
            model = BoundaryAccurateModel(tf, directSplineModel, voxelModel)
            modelType = ModelType.BOUNDARYACCURATE
        elif choice == 2:
            voxelWidth = boundingBox.getHeight() / float(texDimSize)
            criterion = GeometricCriterion(self.screen.pixelWidth, voxelWidth)
            model = HybridModel(tf, directSplineModel, voxelModel, criterion)
            modelType = ModelType.HYBRID
        else:
            lodTextures = [scalarTexture]

            size = texDimSize / 2
            while size >= 2:
                scalars = refSplineModel.generateScalarMatrix(boundingBox, size, size, self.voxelizationTolerance)
                lodTextures.append(Texture2D(scalars))
                size /= 2

            model = VoxelLodModel(tf, lodTextures, boundingBox, self.screen.pixelWidth)
            modelType = ModelType.VOXEL

        # Rendering
        refRenderData = RenderData(ModelType.REFERENCE, self.viewRayDeltaRef)
        refRenderData.renderResult = renderer.render(refSplineModel, self.viewRayDeltaRef, refSplinePlotter)

        directRenderData = RenderData(ModelType.DIRECT, self.viewRayDelta)
        directRenderData.renderResult = renderer.render(directSplineModel, self.viewRayDelta, directSplinePlotter)

        renderData = RenderData(modelType, self.viewRayDelta, texSize=texDimSize)
        renderData.renderResult = renderer.render(model, self.viewRayDelta, voxelPlotter)

        # Plotting
        refPixelColors = refRenderData.renderResult.colors
        directPixelColors = directRenderData.renderResult.colors
        pixelColors = renderData.renderResult.colors

        plotter.pixelReferencePlot.plotPixelColors(refPixelColors)
        plotter.pixelDirectPlot.plotPixelColors(directPixelColors)
        plotter.pixelVoxelizedPlot.plotPixelColors(pixelColors)

        directDiffs = colordiff.compare(refPixelColors, directPixelColors)
        diffs = colordiff.compare(refPixelColors, pixelColors)

        plotter.pixelDirectDiffPlot.plotPixelColorDiffs(directDiffs)
        plotter.pixelVoxelizedDiffPlot.plotPixelColorDiffs(diffs)

        plotter.draw()

        # Printing
        directSummary = Summary(directRenderData, directDiffs)
        directSummary.printData()

        print ""

        summary = Summary(renderData, diffs)
        summary.printData()
示例#4
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)