Esempio n. 1
0
 def test_rescale_ctf(self):
     """Test rescaling a CTF."""
     # Expected data.
     evp, ectf, eotf = make_volume_prop(0.0, 1.0)
     edata = save_ctfs(evp)
     # Rescaled data.
     ctf, otf = rescale_ctfs(self.vp, (0.0, 1.0))
     data = save_ctfs(self.vp)
     # check that both the data are identical.
     self.assertEqual(edata, data)
Esempio n. 2
0
 def test_rescale_ctf(self):
     """Test rescaling a CTF."""
     # Expected data.
     evp, ectf, eotf = make_volume_prop(0.0, 1.0)
     edata = save_ctfs(evp)
     # Rescaled data.
     ctf, otf = rescale_ctfs(self.vp, (0.0, 1.0))
     data = save_ctfs(self.vp)
     # check that both the data are identical.
     self.assertEqual(edata, data)
Esempio n. 3
0
 def test_save_load_ctf(self):
     """Test saving and loading of a CTF."""
     # Create a default ctf, save it.
     data = save_ctfs(self.vp)
     # load it into another volume property,
     mvp = tvtk.VolumeProperty()
     ctf = load_ctfs(data, mvp)
     # get the data from the new one
     mdata = save_ctfs(mvp)
     # check that both the data are identical.
     self.assertEqual(mdata, data)
Esempio n. 4
0
 def test_save_load_ctf(self):
     """Test saving and loading of a CTF."""
     # Create a default ctf, save it.
     data = save_ctfs(self.vp)
     # load it into another volume property,
     mvp = tvtk.VolumeProperty()
     ctf = load_ctfs(data, mvp)
     # get the data from the new one
     mdata = save_ctfs(mvp)
     # check that both the data are identical.
     self.assertEqual(mdata, data)
Esempio n. 5
0
    def _vmin_changed(self):
        vmin = self.vmin
        vmax = self.vmax
        range_min, range_max = self._target.current_range
        if vmin is None:
            vmin = range_min
        if vmax is None:
            vmax = range_max

        # Change the opacity function
        from enthought.tvtk.util.ctf import PiecewiseFunction, save_ctfs
       
        otf = PiecewiseFunction()
        if range_min < vmin:
            otf.add_point(range_min, 0.)
        if range_max > vmax:
            otf.add_point(range_max, 0.2)
        otf.add_point(vmin, 0.)
        otf.add_point(vmax, 0.2)
        self._target._otf = otf
        self._target._volume_property.set_scalar_opacity(otf)
        if self.color is None and not self.__ctf_rescaled and \
                        ( (self.vmin is not None) or (self.vmax is not None) ):
            # FIXME: We don't use 'rescale_ctfs' because it screws up the nodes.
            def _rescale_value(x):
                nx = (x - range_min)/(range_max - range_min)
                return vmin + nx*(vmax - vmin)
            # The range of the existing ctf can vary. 
            scale_min, scale_max = self._target._ctf.range
            def _rescale_node(x):
                nx = (x - scale_min)/(scale_max - scale_min)
                return range_min + nx*(range_max - range_min)
            if hasattr(self._target._ctf, 'nodes'):
                rgb = list()
                for value in self._target._ctf.nodes:
                    r, g, b = \
                            self._target._ctf.get_color(value)
                    rgb.append((_rescale_node(value), r, g, b))
            else:
                rgb = save_ctfs(self._target.volume_property)['rgb']

            from enthought.tvtk.util.ctf import ColorTransferFunction
            ctf = ColorTransferFunction()
            try:
                ctf.range = (range_min, range_max)
            except Exception:
                # VTK versions < 5.2 don't seem to need this.
                pass
            rgb.sort()
            v = rgb[0]
            ctf.add_rgb_point(range_min, v[1], v[2], v[3])
            for v in rgb:
                ctf.add_rgb_point(_rescale_value(v[0]), v[1], v[2], v[3])
            ctf.add_rgb_point(range_max, v[1], v[2], v[3])

            self._target._ctf = ctf
            self._target._volume_property.set_color(ctf)
            self.__ctf_rescaled = True

        self._target.update_ctf = True
Esempio n. 6
0
 def __get_pure_state__(self):
     d = super(Volume, self).__get_pure_state__()
     d['ctf_state'] = save_ctfs(self._volume_property)
     for name in ('current_range', '_ctf', '_otf'):
         d.pop(name, None)
     return d