def _dryRender(self, uniqueCmds, regions, force): """Determines how many files will be rendered. :param uniqueCmds: list of commands which are to be rendered :param force: if forced rerendering :param regions: list of regions assigned to the commands """ count = 0 for cmd, region in zip(uniqueCmds, regions): filename = GetFileFromCmd(self._tempDir, cmd, region) if not force and os.path.exists(filename) and \ self._mapFilesPool.GetSize(HashCmd(cmd, region)) == (self.imageWidth, self.imageHeight): continue count += 1 Debug.msg(3, "BitmapProvider._dryRender: {c} files to be rendered".format(c=count)) return count
def Unload(self): """Unloads currently loaded data. Needs to be called before setting new data. """ Debug.msg(2, "BitmapProvider.Unload") if self._cmdsForComposition: for cmd, region in zip(self._uniqueCmds, self._regionsForUniqueCmds): del self._mapFilesPool[HashCmd(cmd, region)] for cmdList, region in zip(self._cmdsForComposition, self._regions): del self._bitmapPool[HashCmds(cmdList, region)] self._uniqueCmds = [] self._cmdsForComposition = [] self._opacities = [] self._regions = [] self._regionsForUniqueCmds = [] if self._cmds3D: self._cmds3D = [] self._regionFor3D = None
def Render(self, cmdList, regions, regionFor3D, bgcolor, force, nprocs): """Renders all maps and stores files. :param cmdList: list of rendering commands to run :param regions: regions for 2D rendering assigned to commands :param regionFor3D: region for setting 3D view :param bgcolor: background color as a tuple of 3 values 0 to 255 :param force: if True reload all data, otherwise only missing data :param nprocs: number of procs to be used for rendering """ Debug.msg(3, "BitmapRenderer.Render") count = 0 # Variables for parallel rendering proc_count = 0 proc_list = [] queue_list = [] cmd_list = [] filteredCmdList = [] for cmd, region in zip(cmdList, regions): if cmd[0] == "m.nviz.image": region = None filename = GetFileFromCmd(self._tempDir, cmd, region) if (not force and os.path.exists(filename) and self._mapFilesPool.GetSize(HashCmd( cmd, region)) == (self.imageWidth, self.imageHeight)): # for reference counting self._mapFilesPool[HashCmd(cmd, region)] = filename continue filteredCmdList.append((cmd, region)) mapNum = len(filteredCmdList) stopped = False self._isRendering = True for cmd, region in filteredCmdList: count += 1 # Queue object for interprocess communication q = Queue() # The separate render process if cmd[0] == "m.nviz.image": p = Process( target=RenderProcess3D, args=( self.imageWidth, self.imageHeight, self._tempDir, cmd, regionFor3D, bgcolor, q, ), ) else: p = Process( target=RenderProcess2D, args=( self.imageWidth, self.imageHeight, self._tempDir, cmd, region, bgcolor, q, ), ) p.start() queue_list.append(q) proc_list.append(p) cmd_list.append((cmd, region)) proc_count += 1 # Wait for all running processes and read/store the created images if proc_count == nprocs or count == mapNum: for i in range(len(cmd_list)): proc_list[i].join() filename = queue_list[i].get() self._mapFilesPool[HashCmd(cmd_list[i][0], cmd_list[i][1])] = filename self._mapFilesPool.SetSize( HashCmd(cmd_list[i][0], cmd_list[i][1]), (self.imageWidth, self.imageHeight), ) proc_count = 0 proc_list = [] queue_list = [] cmd_list = [] self.renderingContinues.emit(current=count, text=_("Rendering map layers")) if self._stopRendering: self._stopRendering = False stopped = True break self._isRendering = False return not stopped