Exemplo n.º 1
0
def run(filename=None):
    """Create a dummy pipeline and save the coprocessing state in the filename
        specified, if any, else dumps it out on stdout."""

    from visocyte import simple, servermanager
    wavelet = simple.Wavelet(registrationName="Wavelet1")
    contour = simple.Contour()
    display = simple.Show()
    view = simple.Render()
    # create a new 'Parallel PolyData Writer'
    parallelPolyDataWriter0 = simple.ParallelPolyDataWriter()

    viewname = servermanager.ProxyManager().GetProxyName("views", view.SMProxy)
    script = DumpPipeline(
        export_rendering=True,
        simulation_input_map={"Wavelet1": "input"},
        screenshot_info={viewname: ['image.png', '1', '1', '2', '400', '400']},
        cinema_tracks={},
        cinema_arrays={})
    if filename:
        f = open(filename, "w")
        f.write(script)
        f.close()
    else:
        print("# *** Generated Script Begin ***")
        print(script)
        print("# *** Generated Script End ***")
Exemplo n.º 2
0
 def get_proxy_label(self, xmlgroup, xmlname):
     pxm = servermanager.ProxyManager()
     prototype = pxm.GetPrototypeProxy(xmlgroup, xmlname)
     if not prototype:
         # a bit of a hack but we assume that there's a stub of some
         # writer that's not available in this build but is available
         # with the build used by the simulation code (probably through a plugin)
         # this stub must have the proper name in the coprocessing hints
         print("WARNING: Could not find %s writer in %s" \
             "XML group. This is not a problem as long as the writer is available with " \
             "the Visocyte build used by the simulation code." % (xmlname, xmlgroup))
         ctor = servermanager._make_name_valid(xmlname)
     else:
         ctor = servermanager._make_name_valid(prototype.GetXMLLabel())
     # TODO: use servermanager.ProxyManager().NewProxy() instead
     # we create the writer proxy such that it is not registered with the
     # VisocytePipelineController, so its state is not sent to Visocyte Live.
     return "servermanager.%s.%s" % (xmlgroup, ctor)
Exemplo n.º 3
0
"""This is a test to test the visocyte proxy manager API."""

import visocyte
visocyte.compatibility.major = 3
visocyte.compatibility.minor = 4
from visocyte import servermanager


def Error(message):
    raise Exception("ERROR: %s" % message)


servermanager.Connect()
pxm = servermanager.ProxyManager()

p1 = servermanager.sources.SphereSource()
p2 = servermanager.sources.ConeSource()
p3 = servermanager.sources.ArrowSource()

pxm.RegisterProxy("sources", "source1_2", p1)
pxm.RegisterProxy("sources", "source1_2", p2)
pxm.RegisterProxy("sources", "source2", p2)
pxm.RegisterProxy("filters", "s1", p1)
pxm.RegisterProxy("filters", "s2", p2)
pxm.RegisterProxy("filters", "s2", p3)
pxm.RegisterProxy("filters", "s3", p3)

iter = pxm.__iter__()
for proxy in iter:
    print("%s.%s ==> %s" %
          (iter.GetGroup(), iter.GetKey(), proxy.GetXMLName()))
Exemplo n.º 4
0
def getProxyAsPipelineNode(id, view=None):
    """
    Create a representation for that proxy so it can be used within a pipeline
    browser.
    """
    pxm = servermanager.ProxyManager()
    proxy = idToProxy(id)
    rep = simple.GetDisplayProperties(proxy)
    nbActiveComp = 1

    pointData = []
    searchArray = ('POINTS' == rep.ColorArrayName[0]) and (len(
        rep.ColorArrayName[1]) > 0)

    if servermanager.ActiveConnection.GetNumberOfDataPartitions() > 1:
        info = {                  \
        'lutId': 'vtkProcessId_1', \
        'name': 'vtkProcessId',     \
        'size': 1,                   \
        'range': [0, servermanager.ActiveConnection.GetNumberOfDataPartitions()-1] }
        pointData.append(info)

    # FIXME seb
    # dataInfo = rep.GetRepresentedDataInformation()
    # pointData = dataInfo.GetPointDataInformation()
    # cellData = dataInfo.GetCellDataInformation()
    # for idx in pointData.GetNumberOfArrays():
    #     info = pointData.GetArrayInformation(idx)
    #     nbComponents = info.GetNumberOfComponents()
    #     if searchArray and array.Name == rep.ColorArrayName:
    #         nbActiveComp = nbComponents
    #     rangeOn = (nbComponents == 3 if -1 else 0)
    #     info = {                                      \
    #     'lutId': info.GetName() + '_' + str(nbComponents), \
    #     'name': info.GetName,                             \
    #     'size': nbComponents,                            \
    #     'range': info.GetRange(rangeOn) }
    #     pointData.append(info)

    for array in proxy.GetPointDataInformation():
        nbComponents = array.GetNumberOfComponents()
        if searchArray and array.Name == rep.ColorArrayName[1]:
            nbActiveComp = nbComponents
        rangeOn = (nbComponents == 1 if 0 else -1)
        info = {                                      \
        'lutId': array.Name + '_' + str(nbComponents), \
        'name': array.Name,                             \
        'size': nbComponents,                            \
        'range': array.GetRange(rangeOn) }
        pointData.append(info)

    cellData = []
    searchArray = ('CELLS' == rep.ColorArrayName[0]) and (len(
        rep.ColorArrayName[1]) > 0)
    for array in proxy.GetCellDataInformation():
        nbComponents = array.GetNumberOfComponents()
        if searchArray and array.Name == rep.ColorArrayName[1]:
            nbActiveComp = nbComponents
        rangeOn = (nbComponents == 1 if 0 else -1)
        info = {                                      \
        'lutId': array.Name + '_' + str(nbComponents), \
        'name': array.Name,                             \
        'size': nbComponents,                            \
        'range': array.GetRange(rangeOn) }
        cellData.append(info)

    state = getProxyAsState(proxy.GetGlobalID())
    showScalarbar = 1 if view and vtkSMPVRepresentationProxy.IsScalarBarVisible(
        rep.SMProxy, view.SMProxy) else 0

    repName = 'Hide'
    if rep.Visibility == 1:
        repName = rep.Representation

    return { 'proxy_id'  : proxy.GetGlobalID(),                               \
             'name'      : pxm.GetProxyName("sources", proxy),                \
             'bounds'    : proxy.GetDataInformation().GetBounds(),            \
             'pointData' : pointData,                                         \
             'cellData'  : cellData,                                          \
             'activeData': str(rep.ColorArrayName[0]) + ':' + str(rep.ColorArrayName[1]), \
             'diffuseColor'  : str(rep.DiffuseColor),                         \
             'showScalarBar' : showScalarbar,                                 \
             'representation': repName,                                       \
             'state'         : state,                                         \
             'children'      : [] }
Exemplo n.º 5
0
 def setUp(self):
     self.pxm = servermanager.ProxyManager()
Exemplo n.º 6
0
def DumpPipeline(export_rendering, simulation_input_map, screenshot_info,
                 cinema_tracks, cinema_arrays, enable_live_viz,
                 live_viz_frequency):
    """Method that will dump the current pipeline and return it as a string trace.

    export_rendering
      boolean telling if we want to export rendering

    simulation_input_map
      string->string map with key being the proxyname while value being the
      simulation input name.

    screenshot_info
      map with information about screenshots

      * key -> view proxy name

      * value -> [filename, writefreq, fitToScreen, magnification, width, height,
        cinemacamera options]

    cinema_tracks
      map with information about cinema tracks to record

      * key -> proxy name

      * value -> argument ranges

    cinema_arrays
      map with information about value arrays to be exported

      * key -> proxy name

      * value -> list of array names

    enable_live_viz
      boolean telling if we want to enable Catalyst Live connection

    live_viz_frequency
      integer telling how often to update Live connection. only used if
      enable_live_viz is True
    """

    # reset the global variables.
    reset_cpstate_globals()

    cpstate_globals.export_rendering = export_rendering
    cpstate_globals.simulation_input_map = simulation_input_map
    cpstate_globals.screenshot_info = screenshot_info
    cpstate_globals.cinema_tracks = cinema_tracks
    cpstate_globals.cinema_arrays = cinema_arrays
    cpstate_globals.enable_live_viz = enable_live_viz
    cpstate_globals.live_viz_frequency = live_viz_frequency

    # Initialize the write frequency map
    for key in cpstate_globals.simulation_input_map.values():
        cpstate_globals.write_frequencies[key] = []

    # Start trace
    filter = cpstate_filter_proxies_to_serialize()
    smtrace.RealProxyAccessor.register_create_callback(cp_hook)
    state = smstate.get_state(filter=filter, raw=True)
    smtrace.RealProxyAccessor.unregister_create_callback(cp_hook)

    # add in the new style writer proxies
    state = state + NewStyleWriters().make_trace()

    # iterate over all views that were saved in state and update write requencies
    if export_rendering:
        pxm = servermanager.ProxyManager()
        for key, vtuple in screenshot_info.items():
            view = pxm.GetProxy("views", key)
            if not view: continue
            image_write_frequency = int(vtuple[1])
            # Locate which simulation input this write is connected to, if any. If so,
            # we update the write_frequencies datastructure accordingly.
            sim_inputs = locate_simulation_inputs_for_view(view)
            for sim_input_name in sim_inputs:
                if not image_write_frequency in cpstate_globals.write_frequencies:
                    cpstate_globals.write_frequencies[sim_input_name].append(
                        image_write_frequency)
                    cpstate_globals.write_frequencies[sim_input_name].sort()

                if not sim_input_name in cpstate_globals.channels_needed:
                    cpstate_globals.channels_needed.append(sim_input_name)

    if enable_live_viz:
        for key in simulation_input_map:
            sim_input_name = simulation_input_map[key]
            if not live_viz_frequency in cpstate_globals.write_frequencies:
                cpstate_globals.write_frequencies[sim_input_name].append(
                    live_viz_frequency)
                cpstate_globals.write_frequencies[sim_input_name].sort()

            if not sim_input_name in cpstate_globals.channels_needed:
                cpstate_globals.channels_needed.append(sim_input_name)

    pxm = servermanager.ProxyManager()
    arrays = {}
    for channel_name in cpstate_globals.channels_needed:
        arrays[channel_name] = []
        p = pxm.GetProxy("sources", channel_name)
        if p:
            for i in range(p.GetPointDataInformation().GetNumberOfArrays()):
                arrays[channel_name].append(
                    [p.GetPointDataInformation().GetArray(i).GetName(), 0])
            for i in range(p.GetCellDataInformation().GetNumberOfArrays()):
                arrays[channel_name].append(
                    [p.GetCellDataInformation().GetArray(i).GetName(), 1])

    # Create global fields values
    pipelineClassDef = "\n"
    pipelineClassDef += "# ----------------------- CoProcessor definition -----------------------\n\n"

    # Create the resulting string that will contains the pipeline definition
    pipelineClassDef += "def CreateCoProcessor():\n"
    pipelineClassDef += "  def _CreatePipeline(coprocessor, datadescription):\n"
    pipelineClassDef += "    class Pipeline:\n"

    # add the traced code.
    for original_line in state:
        for line in original_line.split("\n"):
            if line.find("import *") != -1 or \
                line.find("#### import the simple") != -1:
                continue
            if line:
                pipelineClassDef += "      " + line + "\n"
            else:
                pipelineClassDef += "\n"
    pipelineClassDef += "    return Pipeline()\n"
    pipelineClassDef += "\n"
    pipelineClassDef += "  class CoProcessor(coprocessing.CoProcessor):\n"
    pipelineClassDef += "    def CreatePipeline(self, datadescription):\n"
    pipelineClassDef += "      self.Pipeline = _CreatePipeline(self, datadescription)\n"
    pipelineClassDef += "\n"
    pipelineClassDef += "  coprocessor = CoProcessor()\n"
    pipelineClassDef += "  # these are the frequencies at which the coprocessor updates.\n"
    pipelineClassDef += "  freqs = " + str(
        cpstate_globals.write_frequencies) + "\n"
    pipelineClassDef += "  coprocessor.SetUpdateFrequencies(freqs)\n"
    if arrays:
        pipelineClassDef += "  if requestSpecificArrays:\n"
        for channel_name in arrays:
            pipelineClassDef += "    arrays = " + str(
                arrays[channel_name]) + "\n"
            pipelineClassDef += "    coprocessor.SetRequestedArrays('" + channel_name + "', arrays)\n"
    pipelineClassDef += "  coprocessor.SetInitialOutputOptions(timeStepToStartOutputAt,forceOutputAtFirstCall)\n"
    pipelineClassDef += "\n"
    pipelineClassDef += "  if rootDirectory:\n"
    pipelineClassDef += "      coprocessor.SetRootDirectory(rootDirectory)\n"
    pipelineClassDef += "\n"
    pipelineClassDef += "  if make_cinema_table:\n"
    pipelineClassDef += "      coprocessor.EnableCinemaDTable()\n"
    pipelineClassDef += "\n"
    pipelineClassDef += "  return coprocessor\n"
    return pipelineClassDef
Exemplo n.º 7
0
    def make_trace(self):
        """gather trace for the writer proxies that are not in the trace pipeline but
        rather in the new export state.

        aDIOSWriter1 = servermanager.writers.ADIOSWriter(Input=wavelet1)
        coprocessor.RegisterWriter(aDIOSWriter1, filename='filename.vta', freq=1, paddingamount=0)
        """
        res = []
        res.append("")
        res.append("# Now any catalyst writers")
        pxm = servermanager.ProxyManager()
        globalepxy = pxm.GetProxy("export_global", "catalyst")
        exports = pxm.GetProxiesInGroup(
            "export_writers")  #todo should use ExportDepot
        for x in exports:
            xs = x[0]
            pxy = pxm.GetProxy('export_writers', xs)
            if not pxy.HasAnnotation('enabled'):
                continue

            xmlname = pxy.GetXMLName()
            if xmlname == "Cinema image options":
                # skip the array and property export information we stuff in this proxy
                continue

            inputname = xs.split('|')[0].lower().replace("*", "")
            writername = xs.split('|')[1]

            xmlgroup = pxy.GetXMLGroup()

            padding_amount = globalepxy.GetProperty(
                "FileNamePadding").GetElement(0)
            write_frequency = pxy.GetProperty("WriteFrequency").GetElement(0)
            filename = pxy.GetProperty("CatalystFilePattern").GetElement(0)

            sim_inputs = locate_simulation_inputs(pxy)
            for sim_input_name in sim_inputs:
                if not write_frequency in cpstate_globals.write_frequencies[
                        sim_input_name]:
                    cpstate_globals.write_frequencies[sim_input_name].append(
                        write_frequency)
                    cpstate_globals.write_frequencies[sim_input_name].sort()

                if not sim_input_name in cpstate_globals.channels_needed:
                    cpstate_globals.channels_needed.append(sim_input_name)

            prototype = pxm.GetPrototypeProxy(xmlgroup, xmlname)
            if not prototype:
                varname = self.__make_name(xmlname)
            else:
                varname = self.__make_name(prototype.GetXMLLabel())
            f = "%s = servermanager.writers.%s(Input=%s)" % (
                varname, writername, inputname)
            res.append(f)
            if self.__make_temporal_script:
                f = "STP.RegisterWriter(%s, '%s', tp_writers)" % (varname,
                                                                  filename)
            else:
                f = "coprocessor.RegisterWriter(%s, filename='%s', freq=%s, paddingamount=%s)" % (
                    varname, filename, write_frequency, padding_amount)
            res.append(f)
            res.append("")
        if len(res) == 2:
            return []  # don't clutter output if there are no writers
        return res