def testCompute(): graph = tuttle.Graph() n = [ tuttle.NodeInit( "tuttle.exrreader", filename="TuttleOFX-data/image/openexr/DisplayWindow/t##.exr"), tuttle.NodeInit("tuttle.invert"), tuttle.NodeInit("tuttle.gamma", master=.5), tuttle.NodeInit("tuttle.jpegwriter", filename=".tests/fromExr/output-####.jpg"), ] nodes = graph.addConnectedNodes(n) procOptions = tuttle.ComputeOptions() procGraph = tuttle.ProcessGraph(procOptions, graph, []) print "before compute" outputCache = tuttle.MemoryCache() timeRange = tuttle.TimeRange(1, 16, 10) print "setup" procGraph.setup() print "beginSequence" procGraph.beginSequence(timeRange) for time in xrange(timeRange._begin, timeRange._end, timeRange._step): print "time:", time procGraph.setupAtTime(time) procGraph.processAtTime(outputCache, time) print "endSequence" procGraph.endSequence() print "after compute"
def computeNode(self, node, frame): """ Computes the node (displayed in the viewer) at the frame indicated. """ buttleData = ButtleDataSingleton().get() graphTuttle = buttleData.getGraph().getGraphTuttle() #Get the output where we save the result self._tuttleImageCache = tuttle.MemoryCache() if buttleData.getVideoIsPlaying(): # if a video is playing processGraph = buttleData.getProcessGraph() processGraph.setupAtTime(frame) processGraph.processAtTime(self._tuttleImageCache, frame) else: # if it's an image only processOptions = tuttle.ComputeOptions(int(frame)) processGraph = tuttle.ProcessGraph(processOptions, graphTuttle, [node]) processGraph.setup() timeRange = tuttle.TimeRange(frame, frame, 1) # buttleData.getTimeRange() processGraph.beginSequence(timeRange) processGraph.setupAtTime(frame) processGraph.processAtTime(self._tuttleImageCache, frame) processGraph.endSequence() self._computedImage = self._tuttleImageCache.get(0) #Add the computedImage to the map hashMap = tuttle.NodeHashContainer() graphTuttle.computeGlobalHashAtTime(hashMap, frame) hasCode = hashMap.getHash(node, frame) #Max 15 computedImages saved in memory if hasCode not in buttleData._mapNodeNameToComputedImage.keys( ) and len(buttleData._mapNodeNameToComputedImage) < 15: buttleData._mapNodeNameToComputedImage.update( {hasCode: self._computedImage}) elif hasCode not in buttleData._mapNodeNameToComputedImage.keys( ) and len(buttleData._mapNodeNameToComputedImage) >= 15: #Delete a computed image from the memory (random) buttleData._mapNodeNameToComputedImage.popitem() buttleData._mapNodeNameToComputedImage.update( {hasCode: self._computedImage}) return self._computedImage
def launchProcessGraph(self): buttleData = ButtleDataSingleton().get() #Get the name of the currentNode of the viewer node = buttleData.getCurrentViewerNodeName() # initialization of the process graph graph = buttleData.getGraph().getGraphTuttle() # timeRange between the frames of beginning and end (first frame, last frame, step) timeRange = tuttle.TimeRange(self._frame, self._nbFrames, 1) self._processOptions = tuttle.ComputeOptions(self._frame, self._nbFrames, 1) processGraph = tuttle.ProcessGraph(self._processOptions, graph, [node]) processGraph.setup() processGraph.beginSequence(timeRange) # communicate processGraph to buttleData buttleData.setProcessGraph(processGraph) buttleData.setVideoIsPlaying(True)
def run(self, parser): """ Process the do operation. """ # Parse command-line args, unknown = parser.parse_known_args() # Set sam log level self.setLogLevel(args.verbose) # set tuttle host log level tuttle.core().getFormatter().setLogLevel(args.verbose) # Clear plugin cache if args.rebuildPluginCache: tuttle.core().getPluginCache().clearPluginFiles() # preload OFX plugins if args.noPluginCache: tuttle.core().preload(False) else: tuttle.core().preload(True) # sam-do --nodes if args.nodes: self._displayPlugins() exit(0) # sam-do --file-formats if args.fileFormats: self._displayFileFormats() exit(0) # sam-do --help if self._isCommandLineAskForHelp(args.inputs, unknown): self._displayCommandLineHelp(parser) exit(0) # Check sam-do command line if self._isCommandLineInvalid(args.inputs, unknown): self._displayCommandLineHelp(parser) exit(1) # Add unknown options to the command line to process args.inputs.extend(unknown) # Split command line splitCmd = samDoUtils.SplitCmd(args.inputs, args.noRecursivity) graphsWithNodes = [] for splitCmdGraph in splitCmd.getGraphs(): self.logger.debug('Create the following tuttle graph: \n' + str(splitCmdGraph)) try: graphsWithNodes.append(self._getTuttleGraph(splitCmdGraph)) except Exception as e: self.logger.error('Cannot create tuttle graph') self.logger.debug('\n' + str(splitCmdGraph)) self.logger.debug(e) if not graphsWithNodes: self.logger.error('No tuttle graph to compute.') exit(1) error = 0 # Compute the corresponding tuttle graphs for graph, nodes in graphsWithNodes: # Options of process options = tuttle.ComputeOptions() # sam-do --ranges if args.ranges is not None: self._setTimeRanges(options, args.ranges) # sam-do --continue-on-error options.setContinueOnError(args.continueOnError) # sam-do --stop-on-missing-files options.setContinueOnMissingFile(not args.stopOnMissingFiles) # Set progress handle ranges = options.getTimeRanges() if not len(ranges): # get time domaine try: timeDomain = nodes[0].asImageEffectNode( ).computeTimeDomain() ranges = [] ranges.append( tuttle.TimeRange(int(timeDomain.min), int(timeDomain.max), 1)) except Exception as e: # the first added node has no filename set pass progress = samDoUtils.ProgressHandle(ranges) options.setProgressHandle(progress) if not nodes: self.logger.warning('No tuttle nodes to compute') continue # Connect and compute try: graph.compute(nodes[-1], options) except Exception as e: self.logger.error('Tuttle graph computation has failed.') self.logger.debug(e) error = 1 self.logger.info('Memory usage: ' + str(int(samUtils.memoryUsageResource())) + 'KB') exit(error)