示例#1
0
    def __createImageDescription(self, scene, renderFile):
        '''
            Initializes the instance of @see: ImageDescription class 
            and saves it into file
        '''

        # creating the object
        name = renderFile.replace(".py", self.generatorDescription.outputFormat)

        translate = scene.camera.translate
        rotate = scene.camera.rotate

        img = ImageDescription(name=name,
                               x=translate[0],
                               y=translate[1],
                               z=translate[2],
                               p=rotate[0],
                               q=rotate[1],
                               r=rotate[2],
                               points=[])

        self.logger.debug("Image description object created \n'%s'" % img)

        # saving to file
        fileName = renderFile.replace(".py", ".imd")
        fileName = fileName.replace("scripts", self.generatorDescription.outputFolder)

        writer = ImageDescriptionWriter()
        with open(fileName, 'w') as fileStream :
            writer.write(stream=fileStream, imageDescription=img)

        self.logger.info("Image description written to '%s'" % fileName)
    def testOutputWithAllElement(self):
        '''
        tests if the output stream is good when parameters passed 
        are good
        '''
        # get the image description and the writer
        imageDesc = ImageDescription(self.name, self.x, self.y, self.z,
                                     self.p, self.q, self.r, self.points)
        imageWriter = ImageDescriptionWriter()

        #get the string steam
        with open(self.fileName, 'r+') as fileStream:
            imageWriter.write(fileStream, imageDesc)

        # read this file
        with open(self.fileName, 'r+') as fileStream:
            allLines = ''.join(fileStream.readlines())
            fileStream.close()

        self.assertEqual(self.expectedString, allLines , "Provided strings should be identical")