Exemplo n.º 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!"
Exemplo n.º 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!"