Пример #1
0
    def update_pipeline(self):
        """Override this method so that it *updates* the tvtk pipeline
        when data upstream is known to have changed.

        This method is invoked (automatically) when any of the inputs
        sends a `pipeline_changed` event.
        """
        mm = self.module_manager
        if mm is None:
            return

        src = mm.source
        self.configure_connection(self.stream_tracer, src.outputs[0])
        self.seed.inputs = [src]

        # Setup the radius/width of the tube/ribbon filters based on
        # given input.
        if self._first:
            dsh = DataSetHelper(src.outputs[0])
            b = dsh.get_bounds()
            l = [(b[1] - b[0]), (b[3] - b[2]), (b[5] - b[4])]
            length = sqrt(l[0] * l[0] + l[1] * l[1] + l[2] * l[2])
            self.ribbon_filter.width = length * 0.0075
            self.tube_filter.radius = length * 0.0075
            self._first = False

        self._streamline_type_changed(self.streamline_type)
        # Set the LUT for the mapper.
        self.actor.set_lut(mm.scalar_lut_manager.lut)

        self.pipeline_changed = True
    def update_pipeline(self):
        """Override this method so that it *updates* the tvtk pipeline
        when data upstream is known to have changed.

        This method is invoked (automatically) when any of the inputs
        sends a `pipeline_changed` event.
        """
        if len(self.inputs) == 0:
            return
        inp = self.inputs[0].outputs[0]
        w = self.widget
        self.configure_input(w, inp)
        dsh = DataSetHelper(self.inputs[0].outputs[0])
        b = dsh.get_bounds()
        self._bounds = list(b)
        if self._first:
            w.place_widget(b)
            self._first = False

        # If the dataset is effectively 2D switch to using the line
        # widget since that works best.
        l = [(b[1] - b[0]), (b[3] - b[2]), (b[5] - b[4])]
        max_l = max(l)
        for i, x in enumerate(l):
            if x / max_l < 1.0e-6:
                w = self.widget = self.widget_list[1]
                w.clamp_to_bounds = True
                w.align = ['z_axis', 'z_axis', 'y_axis'][i]
                break

        # Set our output.
        w.get_poly_data(self.poly_data)
        self.outputs = [self.poly_data]

        self.pipeline_changed = True
Пример #3
0
    def update_pipeline(self):
        """Override this method so that it *updates* the tvtk pipeline
        when data upstream is known to have changed.

        This method is invoked (automatically) when the input fires a
        `pipeline_changed` event.
        """
        if len(self.inputs) == 0 or len(self.inputs[0].outputs) == 0:
            return
        inp = self.inputs[0].outputs[0]
        w = self.widget
        self.configure_input(w, inp)
        if self._first:
            dsh = DataSetHelper(self.inputs[0].outputs[0])
            self._bounds = dsh.get_bounds()
            w.place_widget(*self._bounds)
            self.origin = dsh.get_center()
            self._first = False
        else:
            n = self.normal
            # A hack to update the widget when data changes upstream.
            # This is perhaps a VTK bug, not sure.
            self.normal = n[0], n[1], n[2] + 0.001
            self.normal = n

        # Just pass the inputs back out.  This may trigger a pipeline
        # changed downstream if it does not then fire a data_changed.
        if self.outputs != [inp]:
            self.outputs = [inp]
        else:
            self.data_changed = True
Пример #4
0
    def update_pipeline(self):
        """Override this method so that it *updates* the tvtk pipeline
        when data upstream is known to have changed.

        This method is invoked (automatically) when the input fires a
        `pipeline_changed` event.
        """
        if len(self.inputs) == 0 or len(self.inputs[0].outputs) == 0:
            return
        inp = self.inputs[0].outputs[0]
        w = self.widget
        self.configure_input(w, inp)
        if self._first:
            dsh = DataSetHelper(self.inputs[0].outputs[0])
            self._bounds = dsh.get_bounds()
            w.place_widget(*self._bounds)
            self.origin = dsh.get_center()
            self._first = False
        else:
            n = self.normal
            # A hack to update the widget when data changes upstream.
            # This is perhaps a VTK bug, not sure.
            self.normal = n[0], n[1], n[2] + 0.001
            self.normal = n

        # Just pass the inputs back out.  This may trigger a pipeline
        # changed downstream if it does not then fire a data_changed.
        if self.outputs != [inp]:
            self.outputs = [inp]
        else:
            self.data_changed = True
    def update_pipeline(self):
        """Override this method so that it *updates* the tvtk pipeline
        when data upstream is known to have changed.

        This method is invoked (automatically) when any of the inputs
        sends a `pipeline_changed` event.
        """
        if len(self.inputs) == 0:
            return
        inp = self.inputs[0].outputs[0]
        w = self.widget
        self.configure_input(w, inp)

        dsh = DataSetHelper(self.inputs[0].outputs[0])
        self._bounds = dsh.get_bounds()

        if self._first:
            w.place_widget(self._bounds)
            self._first = False

        # Set our output.
        if self.outputs != [inp]:
            self.outputs = [inp]
        else:
            self.data_changed = True

        self.pipeline_changed = True
Пример #6
0
    def update_pipeline(self):
        """Override this method so that it *updates* the tvtk pipeline
        when data upstream is known to have changed.

        This method is invoked (automatically) when any of the inputs
        sends a `pipeline_changed` event.
        """
        mm = self.module_manager
        if mm is None:
            return

        src = mm.source
        self.configure_connection(self.stream_tracer, src.outputs[0])
        self.seed.inputs = [src]

        # Setup the radius/width of the tube/ribbon filters based on
        # given input.
        if self._first:
            dsh = DataSetHelper(src.outputs[0])
            b = dsh.get_bounds()
            l = [(b[1]-b[0]), (b[3]-b[2]), (b[5]-b[4])]
            length = sqrt(l[0]*l[0] + l[1]*l[1] + l[2]*l[2])
            self.ribbon_filter.width = length*0.0075
            self.tube_filter.radius = length*0.0075
            self._first = False

        self._streamline_type_changed(self.streamline_type)
        # Set the LUT for the mapper.
        self.actor.set_lut(mm.scalar_lut_manager.lut)

        self.pipeline_changed = True
Пример #7
0
 def _extent_changed(self):
     """ Code to modify the extents for
     """
     axes = self._target
     axes.axes.use_data_bounds = False
     axes.axes.bounds = self.extent
     if self.ranges is None:
         dsh = DataSetHelper(axes.module_manager.source.outputs[0])
         axes.axes.ranges = dsh.get_bounds()
 def test_get_range_works_for_VTKNoneArray(self):
     id_ = tvtk.ImageData(dimensions=(2, 2, 1), origin=(0, 0, 0),
                          spacing=(1, 1, 1))
     id_.point_data.scalars = np.arange(4, dtype=float)
     dsh = DataSetHelper(id_)
     self.assertFalse(dsh._composite)
     self.assertEqual(dsh.get_range(), (None, [0., 1.]))
     # XXX there is some wackiness here, no idea why this changes!
     self.assertEqual(dsh.get_range(), ('point_scalars', [0., 3.]))
Пример #9
0
 def _extent_changed(self):
     """ Code to modify the extents for
     """
     axes = self._target
     axes.axes.use_data_bounds = False
     axes.axes.bounds = self.extent
     if self.ranges is None:
         dsh = DataSetHelper(axes.module_manager.source.outputs[0])
         axes.axes.ranges = dsh.get_bounds()
Пример #10
0
 def _get_data_range(self):
     """Returns the range of the input scalar data."""
     dsh = DataSetHelper(self.inputs[0].outputs[0])
     name, rng = dsh.get_range('scalars', 'point')
     if name is not None:
         return rng
     else:
         name, rng = dsh.get_range('scalars', 'cell')
         if name is None:
             return []
         else:
             return rng
Пример #11
0
 def _get_data_range(self):
     """Returns the range of the input scalar data."""
     dsh = DataSetHelper(self.inputs[0].outputs[0])
     name, rng = dsh.get_range('scalars', 'point')
     if name is not None:
         return rng
     else:
         name, rng = dsh.get_range('scalars', 'cell')
         if name is None:
             return []
         else:
             return rng
Пример #12
0
    def _setup_current_range(self):
        mm = self.module_manager
        # Set the default name and range for our lut.
        lm = self.lut_manager
        slm = mm.scalar_lut_manager
        lm.trait_set(default_data_name=slm.default_data_name,
                     default_data_range=slm.default_data_range)

        # Set the current range.
        dataset = mm.source.get_output_dataset()
        dsh = DataSetHelper(dataset)
        name, rng = dsh.get_range('scalars', 'point')
        if name is None:
            error('No scalars in input data!')
            rng = (0, 255)

        if self.current_range != rng:
            self.current_range = rng
Пример #13
0
    def _setup_current_range(self):
        mm = self.module_manager
        # Set the default name and range for our lut.
        lm = self.lut_manager
        slm = mm.scalar_lut_manager
        lm.trait_set(default_data_name=slm.default_data_name,
                     default_data_range=slm.default_data_range)

        # Set the current range.
        dataset = mm.source.get_output_dataset()
        dsh = DataSetHelper(dataset)
        name, rng = dsh.get_range('scalars', 'point')
        if name is None:
            error('No scalars in input data!')
            rng = (0, 255)

        if self.current_range != rng:
            self.current_range = rng
    def test_get_range_works_for_multiblock_datasets(self):
        # Given
        id1 = self._make_data()
        id2 = self._make_data(factor=2.0)

        mb = tvtk.MultiBlockDataSet()
        mb.set_block(0, id1)
        mb.set_block(1, id2)

        # When
        dsh = DataSetHelper(mb)

        # Then
        name, rng = dsh.get_range('scalars', 'point')
        self.assertEqual(name, 'ps')
        self.assertEqual(rng, [0.0, 6.0])

        name, rng = dsh.get_range('scalars', 'cell')
        self.assertEqual(name, 'cs')
        self.assertEqual(rng, [0.0, 3.0])

        name, rng = dsh.get_range('vectors', 'point')
        self.assertEqual(name, 'pv')
        self.assertEqual(rng, [0.0, np.sqrt(3.0)*2.0])

        name, rng = dsh.get_range('vectors', 'cell')
        self.assertEqual(name, 'cv')
        self.assertEqual(rng, [0.0, np.sqrt(3.0)])
Пример #15
0
    def update(self):
        """Update any internal data.

        This is invoked when the source changes or when there are
        pipeline/data changes upstream.
        """
        if len(self.source.outputs) == 0:
            return

        input = self.source.outputs[0]
        helper = DataSetHelper(input)

        self._setup_scalar_data(helper)
        self._setup_vector_data(helper)
    def test_get_range_works_for_simple_datasets(self):
        # Given
        id = self._make_data()

        # When
        dsh = DataSetHelper(id)

        # Then
        name, rng = dsh.get_range('scalars', 'point')
        self.assertEqual(name, 'ps')
        self.assertEqual(rng, [0.0, 3.0])

        name, rng = dsh.get_range('scalars', 'cell')
        self.assertEqual(name, 'cs')
        self.assertEqual(rng, [0.0, 1.5])

        name, rng = dsh.get_range('vectors', 'point')
        self.assertEqual(name, 'pv')
        self.assertEqual(rng, [0.0, np.sqrt(3.0)])

        name, rng = dsh.get_range('vectors', 'cell')
        self.assertEqual(name, 'cv')
        self.assertEqual(rng, [0.0, np.sqrt(3.0)*0.5])