def export_layers(destinationPath, camera): view = simple.GetRenderView() fp = tuple(view.CameraFocalPoint) cp = tuple(view.CameraPosition) vu = tuple(view.CameraViewUp) sceneDescription = { 'size': tuple(view.ViewSize), 'light': ['intensity'], # 'normal', intensity 'camera': { 'CameraViewUp': vu, 'CameraPosition': cp, 'CameraFocalPoint': fp }, 'scene': [] } for key, value in py2to3.iteritems(simple.GetSources()): add_scene_item(sceneDescription, key[0], value, view) # Generate export dsb = CompositeDataSetBuilder(destinationPath, sceneDescription, camera, {}, {}, view) dsb.start() dsb.writeData() dsb.stop(compress=False)
def vtk_itk_type_map(): """Set up mappings between VTK image types and available ITK image types.""" global _vtk_to_itk_types if _vtk_to_itk_types is None: import itk _vtk_to_itk_types = {} type_map = { 'vtkUnsignedCharArray': 'UC3', 'vtkCharArray': 'SC3', 'vtkUnsignedShortArray': 'US3', 'vtkShortArray': 'SS3', 'vtkUnsignedIntArray': 'UI3', 'vtkIntArray': 'SI3', 'vtkFloatArray': 'F3', 'vtkDoubleArray': 'D3' } for (vtk_type, image_type) in py2to3.iteritems(type_map): try: _vtk_to_itk_types[vtk_type] = getattr(itk.Image, image_type) except AttributeError: pass return _vtk_to_itk_types
def export_contours_geometry(destinationPath, **kwargs): view = simple.GetRenderView() sceneDescription = {'scene': []} for key, value in py2to3.iteritems(simple.GetSources()): if key[0] == 'Contour': add_scene_item(sceneDescription, key[0], value, view) count = 1 for item in sceneDescription['scene']: item['name'] += ' (%d)' % count count += 1 if count > 1: contour = sceneDescription['scene'][0]['source'] sections = {'LookupTables': get_source_lookuptable_section(contour)} # Create geometry Builder dsb = VTKGeometryDataSetBuilder(destinationPath, sceneDescription, {}, sections) dsb.start() dsb.writeData(0) dsb.stop() # Patch data range patch_data_range(destinationPath) else: print('Can not export Contour(s) geometry without at least a Contour.')
def get_contour(): for key, value in py2to3.iteritems(simple.GetSources()): if 'FlyingEdges' in key[0]: return value if 'Contour' in key[0]: return value return None
def export_layers(destinationPath, camera): view = simple.GetRenderView() fp = tuple(view.CameraFocalPoint) cp = tuple(view.CameraPosition) vu = tuple(view.CameraViewUp) sceneDescription = { 'size': tuple(view.ViewSize), 'light': ['intensity'], # 'normal', intensity 'camera': { 'CameraViewUp': vu, 'CameraPosition': cp, 'CameraFocalPoint': fp }, 'scene': [] } for key, value in py2to3.iteritems(simple.GetSources()): add_scene_item(sceneDescription, key[0], value, view) # Generate export dsb = CompositeDataSetBuilder( destinationPath, sceneDescription, camera, {}, {}, view) dsb.start() dsb.writeData() dsb.stop(compress=False)
def export_contours_geometry(destinationPath, **kwargs): view = simple.GetRenderView() sceneDescription = {'scene': []} for key, value in py2to3.iteritems(simple.GetSources()): if key[0] == 'Contour': add_scene_item(sceneDescription, key[0], value, view) count = 1 for item in sceneDescription['scene']: item['name'] += ' (%d)' % count count += 1 if count > 1: contour = sceneDescription['scene'][0]['source'] sections = { 'LookupTables': get_source_lookuptable_section(contour) } # Create geometry Builder dsb = VTKGeometryDataSetBuilder(destinationPath, sceneDescription, {}, sections) dsb.start() dsb.writeData(0) dsb.stop() # Patch data range patch_data_range(destinationPath) else: print('Can not export Contour(s) geometry without at least a Contour.')
def export_contour_exploration_geometry(destinationPath, **kwargs): values = [int(v) for v in kwargs['multiValue'].split(',')] contour = None for key, value in py2to3.iteritems(simple.GetSources()): if key[0] == 'Contour': contour = value if contour: sections = {'LookupTables': get_source_lookuptable_section(contour)} scalarName = simple.GetRepresentation(contour).ColorArrayName[1] originalValue = [v for v in contour.Value] sceneDescription = { 'scene': [{ 'name': 'Contour', 'source': contour, 'colors': { scalarName: { 'constant': 0, 'location': 'POINT_DATA' } } }] } dsb = VTKGeometryDataSetBuilder(destinationPath, sceneDescription, {}, sections) dsb.getDataHandler().registerArgument(priority=1, name='contour', values=values, ui='slider', loop='modulo') dsb.start() scalarContainer = sceneDescription['scene'][0]['colors'][scalarName] for contourValue in dsb.getDataHandler().contour: contour.Value = [contourValue] scalarContainer['constant'] = contourValue dsb.writeData() dsb.stop() # Patch data range patch_data_range(destinationPath) # Reset to original state contour.Value = originalValue else: print('Can not export Contour geometry without Contour(s)')
def vtk_cast_map(): """Set up mapping between VTK array numeric types to VTK numeric types that correspond to supported ITK numeric ctypes supported by the ITK wrapping.""" global _vtk_cast_types if _vtk_cast_types is None: import itk _vtk_cast_types = {} # Map from VTK array type to list of possible types to which they can be # converted, listed in order of preference based on representability # and memory size required. import vtk type_map = { vtk.VTK_UNSIGNED_CHAR: [ 'unsigned char', 'unsigned short', 'unsigned int', 'unsigned long', 'signed short', 'signed int', 'signed long', 'float', 'double' ], vtk.VTK_CHAR: [ 'signed char', 'signed short', 'signed int', 'signed long', 'float', 'double' ], vtk.VTK_SIGNED_CHAR: [ 'signed char', 'signed short', 'signed int', 'signed long', 'float', 'double' ], vtk.VTK_UNSIGNED_SHORT: [ 'unsigned short', 'unsigned int', 'unsigned long', 'signed int', 'signed long', 'float', 'double' ], vtk.VTK_SHORT: [ 'signed short', 'signed int', 'signed long', 'float', 'double' ], vtk.VTK_UNSIGNED_INT: [ 'unsigned int', 'unsigned long', 'signed long', 'float', 'double' ], vtk.VTK_INT: [ 'signed int', 'signed long', 'float', 'double' ], vtk.VTK_FLOAT: [ 'float', 'double' ], vtk.VTK_DOUBLE: [ 'double', 'float' ] } # Map ITK ctype back to VTK type ctype_to_vtk = { 'unsigned char': vtk.VTK_UNSIGNED_CHAR, 'signed char': vtk.VTK_CHAR, 'unsigned short': vtk.VTK_UNSIGNED_SHORT, 'signed short': vtk.VTK_SHORT, 'unsigned int': vtk.VTK_UNSIGNED_INT, 'signed int': vtk.VTK_INT, 'unsigned long': vtk.VTK_UNSIGNED_LONG, 'signed long': vtk.VTK_LONG, 'float': vtk.VTK_FLOAT, 'double': vtk.VTK_DOUBLE } # Import build options from ITK. Explicitly reference itk.Vector so # that the itk::Vector type information is available when # itk.BuildOptions is imported, otherwise we get an exception when # importing itkBuildOptions. This is a workaround for a bug in ITK. itk.Vector import itkBuildOptions # Select the best supported type available in the wrapping. for (vtk_type, possible_image_types) in py2to3.iteritems(type_map): type_map[vtk_type] = None for possible_type in possible_image_types: if itk.ctype(possible_type) in itkBuildOptions.SCALARS: _vtk_cast_types[vtk_type] = ctype_to_vtk[possible_type] break return _vtk_cast_types
def get_trivial_producer(): for key, value in py2to3.iteritems(simple.GetSources()): if 'TrivialProducer' in key[0]: return value return None