Example #1
0
    def RequestInformation(self, request, inInfoVec, outInfoVec):
        """Tell ParaView our output extents match the surface, not the subsurface."""
        from vtkmodules.vtkCommonExecutionModel import vtkStreamingDemandDrivenPipeline as sddp

        iin = inInfoVec[1].GetInformationObject(0)
        outInfoVec.GetInformationObject(0).Set(sddp.WHOLE_EXTENT(),
                                               iin.Get(sddp.WHOLE_EXTENT()), 6)
        return 1
Example #2
0
 def RequestInformation(self, request: str, inInfo: vtkInformation,
                        outInfo: vtkInformation) -> int:
     input_src = vtkImageData.GetData(inInfo[0])
     ext = input_src.GetExtent()
     o_info = outInfo.GetInformationObject(0)
     o_info.Set(vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT(), ext, 6)
     return 1
Example #3
0
 def update_info(self, input_src: vtkInformation,
                 outInfo: vtkInformation) -> None:
     spacing = compute_spacing(self._layer_thickness, self._resolution)
     bounds = np.array(input_src.GetBounds())
     img_dim = compute_dim(bounds, spacing)
     outInfo.Set(vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT(),
                 (0, img_dim[0] - 1, 0, img_dim[1] - 1, 0, img_dim[2] - 1),
                 6)
Example #4
0
def SetOutputWholeExtent(algorithm, extent):
    """
    Convenience method to help set the WHOLE_EXTENT() in RequestInformation.
    Commonly used by programmable filters. The arguments are the algorithm
    and a tuple/list with 6 elements (xmin, xmax, ymin, ymax, zmin, zmax).

    Example use::

        import visocyte.util
        # The output will be of dimensions 10, 1, 1
        visocyte.util.SetOutputWholeExtent(algorithm, (0, 9, 0, 0, 0, 0)
    """
    if len(extent) != 6:
        raise "Expected a sequence of length 6"
    from vtkmodules.vtkCommonExecutionModel import vtkStreamingDemandDrivenPipeline
    algorithm.GetExecutive().GetOutputInformation(0).Set(vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT(), extent[0], extent[1], extent[2],extent[3], extent[4], extent[5])
Example #5
0
 def RequestInformation(self, request, inVector, outVector):
     for outputPort in range(self.GetNumberOfOutputPorts()):
         oi = outVector.GetInformationObject(outputPort)
         if (self._outputType != vtkConstants.VTK_UNSTRUCTURED_GRID):
             dims = (0, 0, 0)
             if (self._outputType == vtkConstants.VTK_IMAGE_DATA):
                 dims = (self._node["coordsets/" + self._coords +
                                    "/dims/i"],
                         self._node["coordsets/" + self._coords +
                                    "/dims/j"],
                         self._node["coordsets/" + self._coords +
                                    "/dims/k"])
                 origin = (self._node["coordsets/" + self._coords +
                                      "/origin/x"],
                           self._node["coordsets/" + self._coords +
                                      "/origin/y"],
                           self._node["coordsets/" + self._coords +
                                      "/origin/z"])
                 spacing = (self._node["coordsets/" + self._coords +
                                       "/spacing/dx"],
                            self._node["coordsets/" + self._coords +
                                       "/spacing/dy"],
                            self._node["coordsets/" + self._coords +
                                       "/spacing/dz"])
                 oi.Set(vtkDataObject.ORIGIN(), origin, 3)
                 oi.Set(vtkDataObject.SPACING(), spacing, 3)
                 (self._whole_extent, self._extent) = extents_uniform(
                     self._node, self._comm, self._mpi_size, self._mpi_rank,
                     self._topology)
             elif (self._outputType == vtkConstants.VTK_RECTILINEAR_GRID):
                 (self._whole_extent, self._extent) = extents_rectilinear(
                     self._node, self._comm, self._mpi_size, self._mpi_rank,
                     self._topology)
             elif (self._outputType == vtkConstants.VTK_STRUCTURED_GRID):
                 dims = (self._node["topologies/" + self._topology +
                                    "/elements/dims/i"] + 1,
                         self._node["topologies/" + self._topology +
                                    "/elements/dims/j"] + 1,
                         self._node["topologies/" + self._topology +
                                    "/elements/dims/k"] + 1)
                 self._extent = (0, dims[0] - 1, 0, dims[1] - 1, 0,
                                 dims[2] - 1)
                 self._whole_extent = self._extent
             oi.Set(vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT(),
                    self._whole_extent, 6)
         oi.Set(vtkAlgorithm.CAN_HANDLE_PIECE_REQUEST(), 1)
     return 1
Example #6
0
    def RequestUpdateExtent(self, request, inInfoVec, outInfoVec):
        """Override the default algorithm for updating extents to handle the
        surface and subsurface models, which have different dimensionality.

        Take the requested (downstream) extent and intersect it with the
        available (upstream) extents; use that as the request rather than
        blindly copying the request upstream.
        """
        from vtkmodules.vtkCommonExecutionModel import vtkStreamingDemandDrivenPipeline as sddp

        # Determine the port requesting an update from us:
        reqPort = request.Get(sddp.FROM_OUTPUT_PORT())
        # Get that port's information and the extents it is requesting:
        outInfo = self.GetOutputInformation(reqPort)
        esrc = outInfo.Get(sddp.UPDATE_EXTENT())

        # Slice the extents into tuples holding the lo and hi indices:
        losrc = esrc[0:6:2]
        hisrc = esrc[1:6:2]
        np = self.GetNumberOfInputPorts()
        for port in range(np):
            # Loop over all the input connections and set their update extents:
            nc = self.GetNumberOfInputConnections(port)
            for connection in range(nc):
                inInfo = self.GetInputInformation(port, connection)
                # Set UPDATE_EXTENT to be the intersection of the input
                # port's WHOLE_EXTENT with the output port's UPDATE_EXTENT.
                #
                # NB/FIXME: Really this is incorrect. If reqPort is 1, then
                #   someone is asking for an update of the 2-d surface grid
                #   and they could conceivably need the entire 3-d subsurface
                #   grid that overlaps the surface grid in x and y...
                etgt = inInfo.Get(sddp.WHOLE_EXTENT())
                lotgt = etgt[0:6:2]
                hitgt = etgt[1:6:2]
                lodst = [int(max(x)) for x in zip(losrc, lotgt)]
                hidst = [int(min(x)) for x in zip(hisrc, hitgt)]
                edst = [val for tup in zip(lodst, hidst) for val in tup]
                inInfo.Set(sddp.UPDATE_EXTENT(), tuple(edst), 6)
        return 1
Example #7
0
    def ResetTkImageViewer(self):
        # Reset: Set window level to show all values
        viewer = self._ImageViewer
        input = viewer.GetInput()
        if (input == None):
            return

        # Get the extent in viewer
        z = viewer.GetZSlice()

        input.UpdateInformation()
        info = input.GetOutputInformation(0)
        ext = info.Get(vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT())
        ext[4] = z
        ext[5] = z
        input.Update(0, 1, 0, ext)

        (low,high) = input.GetScalarRange()

        viewer.SetColorWindow(high - low)
        viewer.SetColorLevel((high + low) * 0.5)

        self.Render()