def setup_pipeline(self): """Override this method so that it *creates* the tvtk pipeline. """ v = self.volume = tvtk.Volume() vp = self._volume_property = tvtk.VolumeProperty() self._ctf = ctf = default_CTF(0, 255) self._otf = otf = default_OTF(0, 255) vp.set_color(ctf) vp.set_scalar_opacity(otf) vp.shade = True vp.interpolation_type = 'linear' v.property = vp v.on_trait_change(self.render) vp.on_trait_change(self.render) available_mappers = find_volume_mappers() if is_volume_pro_available(): self._mapper_types.append('VolumeProMapper') available_mappers.append('VolumeProMapper') self._available_mapper_types = available_mappers if 'FixedPointVolumeRayCastMapper' in available_mappers: self._mapper_types.append('FixedPointVolumeRayCastMapper') self.actors.append(v)
def make_test_table(lut=False): from ctf import ColorTransferFunction, PiecewiseFunction if lut: table = tvtk.LookupTable() table.table_range = (255, 355) return table, None, None else: table = tvtk.VolumeProperty() ctf = ColorTransferFunction() mins, maxs = 255, 355 ds = (maxs-mins)/4.0 try: ctf.range = (mins, maxs) except Exception: # VTK versions < 5.2 don't seem to need this. pass ctf.add_rgb_point(mins, 0.00, 0.0, 1.00) ctf.add_rgb_point(mins+ds, 0.25, 0.5, 0.75) ctf.add_rgb_point(mins+2*ds, 0.50, 1.0, 0.50) ctf.add_rgb_point(mins+3*ds, 0.75, 0.5, 0.25) ctf.add_rgb_point(maxs, 1.00, 0.0, 0.00) otf = PiecewiseFunction() otf.add_point(255, 0.0) otf.add_point(355, 0.2) table.set_color(ctf) table.set_scalar_opacity(otf) return table, ctf, otf
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)
def make_volume_prop(mins=255, maxs=355): """Make a volume property for the testing.""" table = tvtk.VolumeProperty() ctf = ColorTransferFunction() ds = (maxs - mins) / 4.0 try: ctf.range = (mins, maxs) except Exception: # VTK versions < 5.2 don't seem to need this. pass ctf.add_rgb_point(mins, 0.00, 0.0, 1.00) ctf.add_rgb_point(mins + ds, 0.25, 0.5, 0.75) ctf.add_rgb_point(mins + 2 * ds, 0.50, 1.0, 0.50) ctf.add_rgb_point(mins + 3 * ds, 0.75, 0.5, 0.25) ctf.add_rgb_point(maxs, 1.00, 0.0, 0.00) otf = PiecewiseFunction() otf.add_point(mins, 0.0) otf.add_point(maxs, 0.2) table.set_color(ctf) table.set_scalar_opacity(otf) return table, ctf, otf