Esempio n. 1
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        # Using composition to include the visual element of the GUI.
        self.ui = Ui_GlyphExportDlg()
        self.ui.setupUi(self)
        '''Initialise a sceneviewer for viewing'''
        self._context = Context('glyph_export')
        self.ui.sceneviewerwidget.setContext(self._context)
        self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))
        self.resize(620, 440)
        self._context.getGlyphmodule().defineStandardGlyphs()

        self._default_region = self._context.getDefaultRegion()
        '''This set the prefix for the files to be exported'''
        self._prefix = 'GlyphExport'
        '''Read the file with the following function'''
        self.readMesh()
        '''Create material which is used to colour the to be exported surfaces'''
        self.createMaterial()
        '''Create surface graphics which will be viewed and exported'''
        self.createSurfaceGraphics()
        '''Create glyph graphics which will be viewed and exported'''
        self.createGlyphGraphics()
        '''Export glyph into JSON format'''
        self.ui.sceneviewerwidget.graphicsInitialized.connect(
            self.exportWebGLJson)
class SemiAutoModel(object):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        self._context = Context('heartsurface')
        glyph_module = self._context.getGlyphmodule()
        glyph_module.defineStandardGlyphs()
        material_module = self._context.getMaterialmodule()
        material_module.defineStandardMaterials()
        self.clear()
        
    def clear(self):
        self._region = None
        self._image_data = None
        
    def initialize(self):
        self._region = self._context.createRegion()
        
    def getRegion(self):
        return self._region
    
    def getContext(self):
        return self._context
    
    def getPointCloud(self):
        return []
    
    def setImageData(self, image_data):
        self._image_data = image_data
Esempio n. 3
0
def write_ex(file_name, data, options=None):
    context = Context("Neurolucida")
    region = context.getDefaultRegion()

    load(region, data, options)

    region.writeFile(file_name)
    def __init__(self):
        self._context = Context("LungModelView")
        self._logger = self._context.getLogger()
        self._initialize()

        self._leftRegion = self.setRegion('leftRegion')
        self._rightRegion = self.setRegion('rightRegion')
        self._leftAirwayRegion = self.setRegion('leftAirwayRegion')
        self._rightAirwayRegion = self.setRegion('rightAirwayRegion')
        self._leftArteryRegion = self.setRegion('leftArteryRegion')
        self._rightArteryRegion = self.setRegion('rightArteryRegion')
        self._leftVeinRegion = self.setRegion('leftVeinRegion')
        self._rightVeinRegion = self.setRegion('rightVeinRegion')

        regions = {
            self._leftRegion.getName(): self._leftRegion,
            self._rightRegion.getName(): self._rightRegion,
            self._leftAirwayRegion.getName(): self._leftAirwayRegion,
            self._rightAirwayRegion.getName(): self._rightAirwayRegion,
            self._leftArteryRegion.getName(): self._leftArteryRegion,
            self._rightArteryRegion.getName(): self._rightArteryRegion,
            self._leftVeinRegion.getName(): self._leftVeinRegion,
            self._rightVeinRegion.getName(): self._rightVeinRegion
        }

        self._meshModel = MeshModel(regions, self._materialModule,
                                    self._context)
Esempio n. 5
0
    def test_mousecolonsegment1(self):
        """
        Test creation of mouse colon segment scaffold.
        """
        options = MeshType_3d_colonsegment1.getDefaultOptions("Mouse 1")
        context = Context("Test")
        region = context.getDefaultRegion()
        self.assertTrue(region.isValid())
        annotationGroups = MeshType_3d_colonsegment1.generateBaseMesh(region, options)
        self.assertEqual(7, len(annotationGroups))

        fieldmodule = region.getFieldmodule()
        self.assertEqual(RESULT_OK, fieldmodule.defineAllFaces())
        mesh3d = fieldmodule.findMeshByDimension(3)
        self.assertEqual(160, mesh3d.getSize())
        coordinates = fieldmodule.findFieldByName("coordinates").castFiniteElement()
        self.assertTrue(coordinates.isValid())
        flatCoordinates = fieldmodule.findFieldByName("flat coordinates").castFiniteElement()
        self.assertTrue(flatCoordinates.isValid())

        with ChangeManager(fieldmodule):
            one = fieldmodule.createFieldConstant(1.0)
            faceMeshGroup = createFaceMeshGroupExteriorOnFace(fieldmodule, Element.FACE_TYPE_XI3_1)
            surfaceAreaField = fieldmodule.createFieldMeshIntegral(one, coordinates, faceMeshGroup)
            surfaceAreaField.setNumbersOfPoints(4)
            flatSurfaceAreaField = fieldmodule.createFieldMeshIntegral(one, flatCoordinates, faceMeshGroup)
            flatSurfaceAreaField.setNumbersOfPoints(4)

        fieldcache = fieldmodule.createFieldcache()
        result, surfaceArea = surfaceAreaField.evaluateReal(fieldcache, 1)
        self.assertEqual(result, RESULT_OK)
        self.assertAlmostEqual(surfaceArea, 468.17062489996886, delta=1.0E-6)
        result, flatSurfaceArea = flatSurfaceAreaField.evaluateReal(fieldcache, 1)
        self.assertEqual(result, RESULT_OK)
        self.assertAlmostEqual(flatSurfaceArea, surfaceArea, delta=1.0E-3)
Esempio n. 6
0
    def __init__(self, ex_data_file, location, identifier):
        self._context = Context('DataTrimmer')
        self._region = self._context.createRegion()
        self._region.setName('TrimRegion')
        self._field_module = self._region.getFieldmodule()
        self._ex_filename = ex_data_file
        self._location = location
        self._identifier = identifier
        self._output_filename = None
        self._coordinate_field = None
        self._mesh = None
        self._groups = None
        self._group_fields = None
        self._group_dct = None
        self._settings = {}
        #  read the EX Zinc data file
        self._initialise_ex_data(ex_data_file)
        self._load_settings()
        self._material_module = self._context.getMaterialmodule()
        self._initialise_glyph_material()
        self._init_graphics_module()
        self._initialise_tessellation(12)
        self._scene_change_callback = None

        self._initialise_scene()
    def __init__(self, parent=None):
        '''
        Initiaise the MaterialsAndTextureDlg first calling the QWidget __init__ function.
        '''
        QtGui.QWidget.__init__(self, parent)

        # Using composition to include the visual element of the GUI.
        self.ui = Ui_MaterialsAndTextureDlg()
        self.ui.setupUi(self)

        self._context = Context('selection')
        self.ui.sceneviewerwidget.setContext(self._context)

        self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))
        self.resize(620, 440)
        self._prefix = "MaterialsAndTexture"

        self._regions = []

        default_region = self._context.getDefaultRegion()
        for i in range(1, 6):
            region_name = 'region_' + str(i)
            region = default_region.createChild(region_name)
            self._regions.append(region)

        self.createMaterial()
        self.createMaterialUsingImageField()
        self.createFiniteElements()
        self.createSurfaceGraphics()
        ''' the following function exports the camera settings'''
        self.ui.sceneviewerwidget.graphicsInitialized.connect(
            self.exportWebGLJson)
Esempio n. 8
0
    def create_fibre_values(self, out_file="fibre_values_spheroidal.txt"):
        """takes an .exfile document, extracts the prolate spheroidal coordinates at each nodes and write them in
		order into a new file. The function works by creating a node iterator from the nodeset wich contains all
		nodes """
        if os.path.isfile("/tmp/" + out_file):
            os.remove("/tmp/" + out_file)
        out = open(out_file, "w+")
        context = Context("heart")
        region = context.getDefaultRegion()
        region.readFile(self.in_file)
        fieldmodule = region.getFieldmodule()
        field = fieldmodule.findFieldByName("fibres")
        cache = fieldmodule.createFieldcache()
        node_set = fieldmodule.findNodesetByName("nodes")

        mesh = fieldmodule.findMeshByDimension(3)
        ele_iter = mesh.createElementiterator()
        node_iter = node_set.createNodeiterator()  #create the node iterator
        counter = 0
        node = node_iter.next()

        while node.isValid():
            cache.setNode(
                node)  #sets the fieldcache-position to the current node
            result, out_values = field.evaluateReal(
                cache, 3
            )  #evaluates real coordinates at the current position of cache
            if result == ZINC_OK:
                out.write(
                    str(out_values[0]) + " " + str(out_values[1]) + " " +
                    str(out_values[2]) + "\r\n")
            else:
                break
            node = node_iter.next()
            counter += 1
Esempio n. 9
0
    def create_node_connectivity(self, out_file="connectivity.txt"):
        if os.path.isfile("/tmp/" + out_file):
            os.remove("/tmp/" + out_file)
        out = open(out_file, "w+")
        context = Context("heart")
        region = context.getDefaultRegion()
        region.readFile(self.in_file)
        fieldmodule = region.getFieldmodule()
        field = fieldmodule.findFieldByName("coordinates")
        cache = fieldmodule.createFieldcache()
        mesh = fieldmodule.findMeshByDimension(3)
        ele_iter = mesh.createElementiterator()

        #d_ds1 = mesh.getChartDifferentialoperator(1, 2)
        #print(d_ds1.isValid())
        counter = 0
        element = ele_iter.next()
        ele_template = element.getElementfieldtemplate(field, 1)
        n = ele_template.getNumberOfLocalNodes()
        while element.isValid():
            for i in range(1, n + 1):

                current_node = element.getNode(ele_template, i)
                cache.setElement(element)
                #test = field.evaluateDerivative(d_ds1, cache, 1)
                #print(test)
                local_index = current_node.getIdentifier()
                out.write(str(local_index) + " ")
            out.write("\r\n")
            element = ele_iter.next()
            ele_template = element.getElementfieldtemplate(field, 1)
Esempio n. 10
0
    def find_standard_elements(self,):
        """
        Returns the standard element numbers in mesh (ie meshes that have 8 nodes per element

        """

        context = Context("Scaffold")
        region = context.getDefaultRegion()
        result = region.readFile(self.input_mesh)
        if result != ZINC_OK:
            raise ValueError('Error loading mesh in {0}'.format(self.input_mesh))

        field_module = region.getFieldmodule()
        mesh = field_module.findMeshByDimension(self.dim)
        coordinates = field_module.findFieldByName('coordinates')
        # Store elements in a dict
        el_iter = mesh.createElementiterator()
        elemDict = dict()
        element = el_iter.next()
        elem_list = []
        while element.isValid():
            elem_list.append(int(element.getIdentifier()))
            elemDict[int(element.getIdentifier())] = element
            element = el_iter.next()
        mesh_elements = elemDict

        for elem in elem_list:
            mesh_element = mesh_elements[elem]
            eft = mesh_element.getElementfieldtemplate(coordinates, -1)  # assumes all components same
            nodeIdentifiers = zinc_utils.getElementNodeIdentifiers8Node(mesh_element, eft)
            a=1
 def __init__(self):
     '''
     Constructor
     '''
     self._context = Context('surfacefit')
     materialmodule = self._context.getMaterialmodule()
     materialmodule.beginChange()
     materialmodule.defineStandardMaterials()
     self._surfaceMaterial = materialmodule.createMaterial()
     self._surfaceMaterial.setName('fit-surface')
     self._surfaceMaterial.setAttributeReal3(Material.ATTRIBUTE_AMBIENT,
                                             [0.7, 0.7, 1.0])
     self._surfaceMaterial.setAttributeReal3(Material.ATTRIBUTE_DIFFUSE,
                                             [0.7, 0.7, 1.0])
     self._surfaceMaterial.setAttributeReal3(Material.ATTRIBUTE_SPECULAR,
                                             [0.5, 0.5, 0.5])
     self._surfaceMaterial.setAttributeReal(Material.ATTRIBUTE_ALPHA, 0.5)
     self._surfaceMaterial.setAttributeReal(Material.ATTRIBUTE_SHININESS,
                                            0.3)
     materialmodule.endChange()
     glyphmodule = self._context.getGlyphmodule()
     glyphmodule.defineStandardGlyphs()
     tessellationmodule = self._context.getTessellationmodule()
     defaultTessellation = tessellationmodule.getDefaultTessellation()
     defaultTessellation.setRefinementFactors([12])
     self._location = None
     self._zincModelFile = None
     self._zincPointCloudFile = None
     self._pointCloudData = None
     self._filterTopErrorProportion = 0.9
     self._filterNonNormalProjectionLimit = 0.99
     self._enableLoadPreviousSolution = False
     self.clear()
class SemiAutoModel(object):
    '''
    classdocs
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self._context = Context('heartsurface')
        glyph_module = self._context.getGlyphmodule()
        glyph_module.defineStandardGlyphs()
        material_module = self._context.getMaterialmodule()
        material_module.defineStandardMaterials()
        self.clear()

    def clear(self):
        self._region = None
        self._image_data = None

    def initialize(self):
        self._region = self._context.createRegion()

    def getRegion(self):
        return self._region

    def getContext(self):
        return self._context

    def getPointCloud(self):
        return []

    def setImageData(self, image_data):
        self._image_data = image_data
Esempio n. 13
0
    def __init__(self, filename, field_info, output_filename):
        self._context = Context("AddField")
        self._region = self._context.getDefaultRegion()
        self._region.readFile(filename)

        self._output_file = output_filename

        self._add_field(field_info)
Esempio n. 14
0
class AxisViewerDlg(QtGui.QWidget):
    '''
    Create a subclass of QWidget for our application.  We could also have derived this 
    application from QMainWindow to give us a menu bar among other things, but a
    QWidget is sufficient for our purposes.
    '''
    
    def __init__(self, parent=None):
        '''
        Initiaise the AxisViewerDlg first calling the QWidget __init__ function.
        '''
        QtGui.QWidget.__init__(self, parent)
 
        # create instance of Zinc Context from which all other objects are obtained
        self._context = ZincContext("Axis Viewer");

        # set up standard materials and glyphs so we can use them elsewhere
        # define standard materials first as some coloured glyphs use them
        materialmodule = self._context.getMaterialmodule()
        materialmodule.defineStandardMaterials()
        # this example uses a standard axes glyph hence need the following:
        glyphmodule = self._context.getGlyphmodule()
        glyphmodule.defineStandardGlyphs()

        # Using composition to include the visual element of the GUI.
        self.ui = Ui_AxisViewerDlg()
        self.ui.setupUi(self)
        # Must pass the context to the ZincWidget to set it up
        self.ui._zincwidget.setContext(self._context)
        self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))
        self.resize(620, 440)

        # set up content for this application
        self.setupAxes()
        # AxisViewerDlg end

    # AxisViewerDlg.setupAxes start
    def setupAxes(self):
        region = self._context.getDefaultRegion()
        # Graphics for visualising a region belong to its scene      
        scene = region.getScene()
        
        # Call beginChange() to stop scene change messages being sent while
        # making multiple changes to scene or its graphics.
        # It's very important to call endChange() at the end!
        scene.beginChange()
        
        # Create Points graphics in scene and visualise with unit-sized solid 3-D axes
        graphics = scene.createGraphicsPoints()
        attributes = graphics.getGraphicspointattributes()
        attributes.setGlyphShapeType(Glyph.SHAPE_TYPE_AXES_SOLID)
        # Note: default base size of 0.0 would make axes invisible!
        attributes.setBaseSize([1.0])

        # Restart scene messaging and inform clients of changes.
        # This ultimately triggers a redraw in the Zinc Widget.
        scene.endChange()
 def __init__(self, location, identifier):
     self._location = location
     self._identifier = identifier
     self._filenameStem = os.path.join(self._location, self._identifier)
     self._context = Context("MeshGenerator")
     self._initialise()
     self._region = self._context.createRegion()
     self._generator_model = MeshGeneratorModel(self._region, self._materialmodule)
     self._plane_model = MeshPlaneModel(self._region)
Esempio n. 16
0
def define_standard_graphics_objects(context: Context):
    """
    Defines Zinc standard objects for use in graphics, including
    a number of graphical materials and glyphs.
    """
    glyphmodule = context.getGlyphmodule()
    glyphmodule.defineStandardGlyphs()
    materialmodule = context.getMaterialmodule()
    materialmodule.defineStandardMaterials()
class AxisViewerDlg(QtGui.QWidget):
    '''
    Create a subclass of QWidget for our application.  We could also have derived this 
    application from QMainWindow to give us a menu bar among other things, but a
    QWidget is sufficient for our purposes.
    '''
    def __init__(self, parent=None):
        '''
        Initiaise the AxisViewerDlg first calling the QWidget __init__ function.
        '''
        QtGui.QWidget.__init__(self, parent)

        # create instance of Zinc Context from which all other objects are obtained
        self._context = ZincContext("Axis Viewer")

        # set up standard materials and glyphs so we can use them elsewhere
        # define standard materials first as some coloured glyphs use them
        materialmodule = self._context.getMaterialmodule()
        materialmodule.defineStandardMaterials()
        # this example uses a standard axes glyph hence need the following:
        glyphmodule = self._context.getGlyphmodule()
        glyphmodule.defineStandardGlyphs()

        # Using composition to include the visual element of the GUI.
        self.ui = Ui_AxisViewerDlg()
        self.ui.setupUi(self)
        # Must pass the context to the ZincWidget to set it up
        self.ui._zincwidget.setContext(self._context)
        self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))
        self.resize(620, 440)

        # set up content for this application
        self.setupAxes()
        # AxisViewerDlg end

    # AxisViewerDlg.setupAxes start
    def setupAxes(self):
        region = self._context.getDefaultRegion()
        # Graphics for visualising a region belong to its scene
        scene = region.getScene()

        # Call beginChange() to stop scene change messages being sent while
        # making multiple changes to scene or its graphics.
        # It's very important to call endChange() at the end!
        scene.beginChange()

        # Create Points graphics in scene and visualise with unit-sized solid 3-D axes
        graphics = scene.createGraphicsPoints()
        attributes = graphics.getGraphicspointattributes()
        attributes.setGlyphShapeType(Glyph.SHAPE_TYPE_AXES_SOLID)
        # Note: default base size of 0.0 would make axes invisible!
        attributes.setBaseSize([1.0])

        # Restart scene messaging and inform clients of changes.
        # This ultimately triggers a redraw in the Zinc Widget.
        scene.endChange()
 def __init__(self):
     '''
     Constructor
     '''
     self._context = Context('heartsurface')
     glyph_module = self._context.getGlyphmodule()
     glyph_module.defineStandardGlyphs()
     material_module = self._context.getMaterialmodule()
     material_module.defineStandardMaterials()
     self.clear()
    def __init__(self, parent=None):
        '''
        Call the super class init functions, create a Zinc context and set the scene viewer handle to None.
        '''

        QtOpenGL.QGLWidget.__init__(self, parent)
        # Create a Zinc context from which all other objects can be derived either directly or indirectly.
        # Each context requires a unique name to reference it.
        self._context = Context("finiteelementcreation")
        self._scene_viewer = None
Esempio n. 20
0
    def __init__(self):
        self._context = Context('Segmentation')
        self._undo_redo_stack = QtGui.QUndoStack()

        self.defineStandardMaterials()
        self._createModeMaterials()
        self.defineStandardGlyphs()

        self._image_model = ImageModel(self._context)
        self._node_model = NodeModel(self._context)
Esempio n. 21
0
    def __init__(self, parent=None):
        '''
        Call the super class init functions, create a Zinc context and set the scene viewer handle to None.
        '''

        QtOpenGL.QGLWidget.__init__(self, parent)
        # Create a Zinc context from which all other objects can be derived either directly or indirectly.
        #print(opencmiss.zinc.__version__)
        self._context = Context("axisviewer")
        self._scene_viewer = None
def export_to_web_gl_json(mesh_description):
    """
        Export graphics into JSON formats. Returns an array containing the
   string buffers for each export

    :param mesh_description:
    :return:
    """
    context = Context('web_gl')

    if isinstance(mesh_description, dict):
        region_description = mesh_description['_region_description']
        scene_description = mesh_description['_scene_description']
        time_array = mesh_description['_epochs']
        start_time = time_array[0]
        end_time = time_array[-1]
        epoch_count = len(time_array)
    else:
        region_description = mesh_description.get_region_description()
        scene_description = mesh_description.get_scene_description()
        start_time = mesh_description.get_start_time()
        end_time = mesh_description.get_end_time()
        epoch_count = mesh_description.get_epoch_count()

    region = context.createRegion()
    scene = region.getScene()

    _read_region_description(region, region_description)
    _read_scene_description(scene, scene_description)

    tessellation_module = scene.getTessellationmodule()
    default_tessellation = tessellation_module.getDefaultTessellation()
    default_tessellation.setRefinementFactors([4, 4, 1])
    tessellation_module.setDefaultTessellation(default_tessellation)

    stream_information = scene.createStreaminformationScene()
    stream_information.setIOFormat(stream_information.IO_FORMAT_THREEJS)
    stream_information.setInitialTime(start_time)
    stream_information.setFinishTime(end_time)
    stream_information.setNumberOfTimeSteps(epoch_count)
    stream_information.setOutputTimeDependentVertices(1)

    # Get the total number of graphics in a scene/region that can be exported
    number = stream_information.getNumberOfResourcesRequired()
    resources = []
    # Write out each graphics into a json file which can be rendered with our
    # WebGL script
    for i in range(number):
        resources.append(stream_information.createStreamresourceMemory())
    scene.write(stream_information)

    # Store all the resources in a buffer
    resource_buffer = [resources[i].getBuffer()[1] for i in range(number)]

    return resource_buffer
Esempio n. 23
0
class Scene(object):
    def __init__(self):
        self._context = Context("Scene")
        self._initialize()

    def getContext(self):
        return self._context

    def getScene(self):
        return self._context.getDefaultRegion().getScene()

    def _initialize(self):
        tess = self._context.getTessellationmodule().getDefaultTessellation()
        tess.setRefinementFactors(12)

        self._materialModule = self._context.getMaterialmodule()
        self._materialModule.defineStandardMaterials()

        material = self._materialModule.createMaterial()
        material.setName('solidBlue')
        material.setManaged(True)
        material.setAttributeReal3(Material.ATTRIBUTE_AMBIENT, [0.0, 0.2, 0.6])
        material.setAttributeReal3(Material.ATTRIBUTE_DIFFUSE, [0.0, 0.7, 1.0])
        material.setAttributeReal3(Material.ATTRIBUTE_EMISSION,
                                   [0.0, 0.0, 0.0])
        material.setAttributeReal3(Material.ATTRIBUTE_SPECULAR,
                                   [0.1, 0.1, 0.1])
        material.setAttributeReal(Material.ATTRIBUTE_SHININESS, 0.2)

        material = self._materialModule.createMaterial()
        material.setName('transBlue')
        material.setManaged(True)
        material.setAttributeReal3(Material.ATTRIBUTE_AMBIENT, [0.0, 0.2, 0.6])
        material.setAttributeReal3(Material.ATTRIBUTE_DIFFUSE, [0.0, 0.7, 1.0])
        material.setAttributeReal3(Material.ATTRIBUTE_EMISSION,
                                   [0.0, 0.0, 0.0])
        material.setAttributeReal3(Material.ATTRIBUTE_SPECULAR,
                                   [0.1, 0.1, 0.1])
        material.setAttributeReal(Material.ATTRIBUTE_ALPHA, 0.3)
        material.setAttributeReal(Material.ATTRIBUTE_SHININESS, 0.2)

        material = self._materialModule.createMaterial()
        material.setName('solidTissue')
        material.setManaged(True)
        material.setAttributeReal3(Material.ATTRIBUTE_AMBIENT, [0.9, 0.7, 0.5])
        material.setAttributeReal3(Material.ATTRIBUTE_DIFFUSE, [0.9, 0.7, 0.5])
        material.setAttributeReal3(Material.ATTRIBUTE_EMISSION,
                                   [0.0, 0.0, 0.0])
        material.setAttributeReal3(Material.ATTRIBUTE_SPECULAR,
                                   [0.2, 0.2, 0.3])
        material.setAttributeReal(Material.ATTRIBUTE_ALPHA, 1.0)
        material.setAttributeReal(Material.ATTRIBUTE_SHININESS, 0.2)

        glyphmodule = self._context.getGlyphmodule()
        glyphmodule.defineStandardGlyphs()
Esempio n. 24
0
 def initialise(self):
     '''
     Ensure scene or other objects from old context are not in use before calling
     '''
     self._context = Context("SimpleViz")
     # set up standard materials and glyphs so we can use them elsewhere
     materialmodule = self._context.getMaterialmodule()
     materialmodule.defineStandardMaterials()
     glyphmodule = self._context.getGlyphmodule()
     glyphmodule.defineStandardGlyphs()
     self._rootRegion = self._context.createRegion()
Esempio n. 25
0
    def __init__(self, filename, output_filename, scale, marker_type='nodes'):
        self._context = Context("TrasformMesh")
        self._region = self._context.getDefaultRegion()
        self._region.readFile(filename)

        self._output_file = output_filename

        self._marker_type = marker_type

        self._scale = scale
        self._scale_geometry()
Esempio n. 26
0
 def __init__(self, location, identifier):
     '''
     Constructor
     '''
     self._location = location
     self._identifier = identifier
     self._filenameStem = os.path.join(self._location, self._identifier)
     self._context = Context("MeshGenerator")
     tess = self._context.getTessellationmodule().getDefaultTessellation()
     tess.setRefinementFactors(12)
     self._sceneChangeCallback = None
     # set up standard materials and glyphs so we can use them elsewhere
     self._materialmodule = self._context.getMaterialmodule()
     self._materialmodule.defineStandardMaterials()
     solid_blue = self._materialmodule.createMaterial()
     solid_blue.setName('solid_blue')
     solid_blue.setManaged(True)
     solid_blue.setAttributeReal3(Material.ATTRIBUTE_AMBIENT, [ 0.0, 0.2, 0.6 ])
     solid_blue.setAttributeReal3(Material.ATTRIBUTE_DIFFUSE, [ 0.0, 0.7, 1.0 ])
     solid_blue.setAttributeReal3(Material.ATTRIBUTE_EMISSION, [ 0.0, 0.0, 0.0 ])
     solid_blue.setAttributeReal3(Material.ATTRIBUTE_SPECULAR, [ 0.1, 0.1, 0.1 ])
     solid_blue.setAttributeReal(Material.ATTRIBUTE_SHININESS , 0.2)
     trans_blue = self._materialmodule.createMaterial()
     trans_blue.setName('trans_blue')
     trans_blue.setManaged(True)
     trans_blue.setAttributeReal3(Material.ATTRIBUTE_AMBIENT, [ 0.0, 0.2, 0.6 ])
     trans_blue.setAttributeReal3(Material.ATTRIBUTE_DIFFUSE, [ 0.0, 0.7, 1.0 ])
     trans_blue.setAttributeReal3(Material.ATTRIBUTE_EMISSION, [ 0.0, 0.0, 0.0 ])
     trans_blue.setAttributeReal3(Material.ATTRIBUTE_SPECULAR, [ 0.1, 0.1, 0.1 ])
     trans_blue.setAttributeReal(Material.ATTRIBUTE_ALPHA , 0.3)
     trans_blue.setAttributeReal(Material.ATTRIBUTE_SHININESS , 0.2)
     glyphmodule = self._context.getGlyphmodule()
     glyphmodule.defineStandardGlyphs()
     self._deleteElementRanges = []
     self._scale = [ 1.0, 1.0, 1.0 ]
     self._settings = {
         'meshTypeName' : '',
         'meshTypeOptions' : { },
         'deleteElementRanges' : '',
         'scale' : '*'.join(STRING_FLOAT_FORMAT.format(value) for value in self._scale),
         'displayAxes' : True,
         'displayElementNumbers' : True,
         'displayLines' : True,
         'displayNodeDerivatives' : False,
         'displayNodeNumbers' : True,
         'displaySurfaces' : True,
         'displaySurfacesExterior' : True,
         'displaySurfacesTranslucent' : True,
         'displaySurfacesWireframe' : False,
         'displayXiAxes' : False
     }
     self._discoverAllMeshTypes()
     self._loadSettings()
     self._generateMesh()
Esempio n. 27
0
    def export_vtk(self, filename):

        context = Context("Scaffold")
        region = context.getDefaultRegion()
        result = region.readFile(self.input_mesh)
        if result != ZINC_OK:
            raise ValueError('Error loading mesh in {0}'.format(self.input_mesh))

        from scaffoldmaker.utils.exportvtk import ExportVtk
        export = ExportVtk(region, 'test')
        export.writeFile(filename)
Esempio n. 28
0
 def setupZinc(self):
     self.zincContext = Context(str('Radiation'))
     #Zinc viewer setup
     self.mvLayout = QtWidgets.QVBoxLayout(self.graphicsHost)
     self.mvLayout.setSpacing(0)
     self.mvLayout.setContentsMargins(0,0,0,0)
     self.mvLayout.setObjectName("mvLayout")
     self.meshWindow = SceneviewerWidget(self.graphicsHost)
     self.meshWindow.setContext(self.zincContext)
     self.mvLayout.addWidget(self.meshWindow)
     self.meshWindow.graphicsInitialized.connect(self.setBackgroundColor)
Esempio n. 29
0
 def test_field_coordinates(self):
     """
     Test creation of finite element coordinates field.
     """
     context = Context("test")
     region = context.createRegion()
     fieldmodule = region.getFieldmodule()
     coordinates = findOrCreateFieldCoordinates(fieldmodule)
     self.assertTrue(coordinates.isValid())
     self.assertEqual(3, coordinates.getNumberOfComponents())
     self.assertTrue(coordinates.isManaged())
     self.assertTrue(coordinates.isTypeCoordinate())
Esempio n. 30
0
    def test_cylinder1(self):
        """
        Test creation of cylinder scaffold.
        """
        scaffold = MeshType_3d_solidcylinder1
        parameterSetNames = scaffold.getParameterSetNames()
        self.assertEqual(parameterSetNames, ["Default"])
        options = scaffold.getDefaultOptions("Default")
        self.assertEqual(12, len(options))
        self.assertEqual(4, options.get("Number of elements across major"))
        self.assertEqual(4, options.get("Number of elements across minor"))
        self.assertEqual(0, options.get("Number of elements across shell"))
        self.assertEqual(1,
                         options.get("Number of elements across transition"))
        self.assertEqual(1, options.get("Number of elements along"))
        self.assertEqual(1.0,
                         options.get("Shell element thickness proportion"))
        context = Context("Test")
        region = context.getDefaultRegion()
        self.assertTrue(region.isValid())
        annotationGroups = scaffold.generateMesh(region, options)
        self.assertEqual(0, len(annotationGroups))
        fieldmodule = region.getFieldmodule()
        mesh3d = fieldmodule.findMeshByDimension(3)
        self.assertEqual(12, mesh3d.getSize())
        mesh2d = fieldmodule.findMeshByDimension(2)
        self.assertEqual(52, mesh2d.getSize())
        mesh1d = fieldmodule.findMeshByDimension(1)
        self.assertEqual(73, mesh1d.getSize())
        nodes = fieldmodule.findNodesetByFieldDomainType(
            Field.DOMAIN_TYPE_NODES)
        self.assertEqual(34, nodes.getSize())
        datapoints = fieldmodule.findNodesetByFieldDomainType(
            Field.DOMAIN_TYPE_DATAPOINTS)
        self.assertEqual(0, datapoints.getSize())

        # check coordinates range, cylinder volume
        coordinates = fieldmodule.findFieldByName(
            "coordinates").castFiniteElement()
        self.assertTrue(coordinates.isValid())
        minimums, maximums = evaluateFieldNodesetRange(coordinates, nodes)
        assertAlmostEqualList(self, minimums, [-1.0, -1.0, 0.0], 1.0E-6)
        assertAlmostEqualList(self, maximums, [1.0, 1.0, 3.0], 1.0E-6)
        with ChangeManager(fieldmodule):
            one = fieldmodule.createFieldConstant(1.0)
            volumeField = fieldmodule.createFieldMeshIntegral(
                one, coordinates, mesh3d)
            volumeField.setNumbersOfPoints(3)
        fieldcache = fieldmodule.createFieldcache()
        result, volume = volumeField.evaluateReal(fieldcache, 1)
        self.assertEqual(result, RESULT_OK)
        self.assertAlmostEqual(volume, 9.414866630615249, delta=1.0E-3)
    def __init__(self, input_scaffold_file, groups):
        self._context = Context('ScaffoldGroupManager')
        self._region = self._context.createRegion()
        self._region.setName('GroupManagerRegion')
        self._field_module = self._region.getFieldmodule()
        self._scaffold_file = input_scaffold_file
        self._model_coordinates_field = None
        self._output_filename = None
        self._groups = groups

        self._load()
        for group in groups["groups"]:
            self._manage_groups(group)
 def __init__(self,
              xi1Elements=4,
              xi2Elements=1,
              xi3Elements=1,
              timepoints=1):
     '''
     Constructor
     '''
     self.context = Context('Tube')
     self.lengthElements = xi2Elements
     self.circumferentialElements = xi1Elements
     self.wallElements = xi3Elements
     self.numberOfTimePoints = timepoints
class PlainModelViewerWidget(QtGui.QWidget):

    def __init__(self, parent=None):
        super(PlainModelViewerWidget, self).__init__(parent)
        self._ui = Ui_PlainModelViewerWidget()
        self._ui.setupUi(self)

        self._context = Context('view')
        self._setupZinc()

        self._callback = None
        self._model_data = None

        self._makeConnections()

    def _setupZinc(self):
        self._zinc = self._ui.widgetZinc
        self._zinc.setContext(self._context)
        self._defineStandardMaterials()
        self._defineStandardGlyphs()

    def _makeConnections(self):
        self._ui.pushButtonDone.clicked.connect(self._doneButtonClicked)

    def _doneButtonClicked(self):
        self._callback()

    def registerDoneExecution(self, callback):
        self._callback = callback

    def setModelData(self, model_data):
        self._model_data = model_data
        self._visualise()

    def _defineStandardGlyphs(self):
        '''
        Helper method to define the standard glyphs
        '''
        glyph_module = self._context.getGlyphmodule()
        glyph_module.defineStandardGlyphs()

    def _defineStandardMaterials(self):
        '''
        Helper method to define the standard materials.
        '''
        material_module = self._context.getMaterialmodule()
        material_module.defineStandardMaterials()

    def _visualise(self):
        ''' Read model data
Esempio n. 34
0
    def __init__(self, parent=None):
        '''
        Initiaise the AxisViewerDlg first calling the QWidget __init__ function.
        '''
        QtGui.QWidget.__init__(self, parent)
 
        # create instance of Zinc Context from which all other objects are obtained
        self._context = ZincContext("Axis Viewer");

        # set up standard materials and glyphs so we can use them elsewhere
        # define standard materials first as some coloured glyphs use them
        materialmodule = self._context.getMaterialmodule()
        materialmodule.defineStandardMaterials()
        # this example uses a standard axes glyph hence need the following:
        glyphmodule = self._context.getGlyphmodule()
        glyphmodule.defineStandardGlyphs()

        # Using composition to include the visual element of the GUI.
        self.ui = Ui_AxisViewerDlg()
        self.ui.setupUi(self)
        # Must pass the context to the ZincWidget to set it up
        self.ui._zincwidget.setContext(self._context)
        self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))
        self.resize(620, 440)

        # set up content for this application
        self.setupAxes()
    def __init__(self, parent=None):
        '''
        Initiaise the MaterialsAndTextureDlg first calling the QWidget __init__ function.
        '''
        QtGui.QWidget.__init__(self, parent)
        
        # Using composition to include the visual element of the GUI.
        self.ui = Ui_MaterialsAndTextureDlg()
        self.ui.setupUi(self)
        
        self._context = Context('selection')
        self.ui.sceneviewerwidget.setContext(self._context)
        
        self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))
        self.resize(620, 440)
        self._prefix = "MaterialsAndTexture"
        
        self._regions = []
        
        default_region = self._context.getDefaultRegion()
        for i in range(1, 6):
            region_name = 'region_' + str(i)
            region = default_region.createChild(region_name)
            self._regions.append(region)

        self.createMaterial()
        self.createMaterialUsingImageField()
        self.createFiniteElements()
        self.createSurfaceGraphics()

        ''' the following function exports the camera settings'''
        self.ui.sceneviewerwidget.graphicsInitialized.connect(self.exportWebGLJson)
    def __init__(self, parent=None):
        '''
        Initialise the ZincViewGraphics first calling the QMainWindow __init__ function.
        '''
        QtGui.QMainWindow.__init__(self, parent)

        # create instance of Zinc Context from which all other objects are obtained
        self._context = ZincContext("ZincViewGraphics");

        # set up standard materials for colouring graphics
        self._context.getMaterialmodule().defineStandardMaterials()
        # set up standard glyphs, graphics to show at points e.g. spheres, arrows
        self._context.getGlyphmodule().defineStandardGlyphs()

        # Load the user interface controls
        self._ui = Ui_ZincViewGraphics()
        self._ui.setupUi(self)
        self._makeConnections()
        # Must pass the Context to the Zinc SceneviewerWidget
        self._ui.sceneviewerWidget.setContext(self._context)
        # must set other sceneviewer defaults once graphics are initialised
        self._ui.sceneviewerWidget.graphicsInitialized.connect(self._graphicsInitialized)

        # read the model and create some graphics to see it:
        self.setupModel()
 def __init__(self):
     '''
     Constructor
     '''
     self._context = Context('surfacefit')
     materialmodule = self._context.getMaterialmodule()
     materialmodule.beginChange()
     materialmodule.defineStandardMaterials()
     self._surfaceMaterial = materialmodule.createMaterial()
     self._surfaceMaterial.setName('fit-surface')
     self._surfaceMaterial.setAttributeReal3(Material.ATTRIBUTE_AMBIENT, [0.7, 0.7, 1.0])
     self._surfaceMaterial.setAttributeReal3(Material.ATTRIBUTE_DIFFUSE, [0.7, 0.7, 1.0])
     self._surfaceMaterial.setAttributeReal3(Material.ATTRIBUTE_SPECULAR, [0.5, 0.5, 0.5])
     self._surfaceMaterial.setAttributeReal(Material.ATTRIBUTE_ALPHA, 0.5)
     self._surfaceMaterial.setAttributeReal(Material.ATTRIBUTE_SHININESS, 0.3)
     materialmodule.endChange()
     glyphmodule = self._context.getGlyphmodule()
     glyphmodule.defineStandardGlyphs()
     tessellationmodule = self._context.getTessellationmodule()
     defaultTessellation = tessellationmodule.getDefaultTessellation()
     defaultTessellation.setRefinementFactors([12])
     self._location = None
     self._zincModelFile = None
     self._zincPointCloudFile = None
     self._pointCloudData = None
     self._filterTopErrorProportion = 0.9
     self._filterNonNormalProjectionLimit = 0.99
     self.clear()
Esempio n. 38
0
    def __init__(self):
        super(PelvisModel, self).__init__()
        self._context = Context("pelvis")
        glyph_module = self._context.getGlyphmodule()
        glyph_module.defineStandardGlyphs()
        material_module = self._context.getMaterialmodule()
        material_module.defineStandardMaterials()

        self._time_keeper = self._context.getTimekeepermodule().getDefaultTimekeeper()
        self._time_keeper.setMaximumTime(324)
        self._time_keeper.setMinimumTime(236)
        self._nodes_start = []
        self._nodes_end = []
        self._elements = []


        self._command = ['node', os.environ['IMU_BLE']]
        self._process = None
        self._stdout_reader = None
        self._timer = QtCore.QTimer()
        self._timer.setInterval(10)
        self._timer.timeout.connect(self._readData)
        self._timer_active = False

        # First create coordinate field
        self._male_region = self._context.getDefaultRegion().createSubregion("male")
        self._setupMaleRegion(self._male_region)
        self._female_region = self._context.getDefaultRegion().createSubregion("female")
        self._setupFemaleRegion(self._female_region)
Esempio n. 39
0
 def __init__(self, parent = None):
     '''
     Call the super class init functions, create a Zinc context and set the scene viewer handle to None.
     '''
     
     QtOpenGL.QGLWidget.__init__(self, parent)
     # Create a Zinc context from which all other objects can be derived either directly or indirectly.
     #print(opencmiss.zinc.__version__)
     self._context = Context("axisviewer")
     self._scene_viewer = None
Esempio n. 40
0
    def __init__(self):
        self._context = Context('Segmentation')
        self._undo_redo_stack = QtGui.QUndoStack()

        self.defineStandardMaterials()
        self._createModeMaterials()
        self.defineStandardGlyphs()

        self._image_model = ImageModel(self._context)
        self._node_model = NodeModel(self._context)
Esempio n. 41
0
 def __init__(self, parent = None):
     '''
     Call the super class init functions, create a Zinc context and set the scene viewer handle to None.
     '''
     
     QtOpenGL.QGLWidget.__init__(self, parent)
     # Create a Zinc context from which all other objects can be derived either directly or indirectly.
     # Each context requires a unique name to reference it.
     self._context = Context("finiteelementcreation")
     self._scene_viewer = None
 def __init__(self):
     '''
     Constructor
     '''
     self._context = Context('heartsurface')
     glyph_module = self._context.getGlyphmodule()
     glyph_module.defineStandardGlyphs()
     material_module = self._context.getMaterialmodule()
     material_module.defineStandardMaterials()
     self.clear()
Esempio n. 43
0
 def __init__(self, parent = None):
     '''
     Call the super class init functions, create a Zinc context and set the scene viewer handle to None.
     '''
     
     QtOpenGL.QGLWidget.__init__(self, parent)
     # Create a Zinc context from which all other objects can be derived either directly or indirectly.
     self._context = Context("autosegmenter")
     self._scene_viewer = None
     self._imageDataLocation = None
 def __init__(self):
     '''
     Constructor
     '''
     self._context = Context('heartsurface')
     self.defineStandardMaterials()
     self.defineStandardGlyphs()
     self._region = None
     self._image_model = ImageModel(self._context)
     self._node_model = NodeModel(self._context)
     self._location = None
Esempio n. 45
0
 def __init__(self):
     '''
     Constructor
     '''
     self._context = Context('hearttransform')
     self.defineStandardMaterials()
     self.defineStandardGlyphs()
     self._location = None
     self._region = None
     self._image_model = ImageModel(self._context)
     self._transform_model = TransformModel(self._context)
Esempio n. 46
0
 def __init__(self, context_name):
     '''
     Constructor
     '''
     self._context = Context(context_name)
     self._timeKeeper = self._context.getTimekeepermodule().getDefaultTimekeeper()
     glyph_module = self._context.getGlyphmodule()
     glyph_module.defineStandardGlyphs()
     material_module = self._context.getMaterialmodule()
     material_module.defineStandardMaterials()
     self._setupSpectrum()
     self.clear()
    def __init__(self, parent=None):
        super(PlainModelViewerWidget, self).__init__(parent)
        self._ui = Ui_PlainModelViewerWidget()
        self._ui.setupUi(self)

        self._context = Context('view')
        self._setupZinc()

        self._callback = None
        self._model_data = None

        self._makeConnections()
Esempio n. 48
0
def main():
    '''
    The entry point for the application, handle application arguments.
    '''
    # Create the context
    context = Context("image")
    
    # Name of the file we intend to read in.
    image_name = 'drawing.png'
    
    # Get a handle to the root region
    default_region = context.getDefaultRegion()
    
    # The field module allows us to create a field image to 
    # store the image data into.
    field_module = default_region.getFieldmodule()
    
    # Create an image field, we don't specify the domain here for this
    # field even though it is a source field.  A temporary xi source field
    # is created for us.
    image_field = field_module.createFieldImage()
    image_field.setName('texture')
    
    # Create a stream information object that we can use to read the 
    # image file from the disk
    stream_information = image_field.createStreaminformationImage()
    # Set the format for the image we want to read
    stream_information.setFileFormat(stream_information.FILE_FORMAT_PNG)
    # We are reading in a file from the local disk so our resource is a file.
    stream_information.createStreamresourceFile(image_name)
    
    # Actually read in the image file into the image field.
    ret = image_field.read(stream_information)
    if ret == 1: # CMISS_OK has  the literal value 1
        print('Image successfully read into image field.')
    else:
        print('Error: failed to read image into image field.')
 def __init__(self, context_name):
     '''
     Constructor
     '''
     self._context = Context(context_name)
     self._timeKeeper = self._context.getTimekeepermodule().getDefaultTimekeeper()
     glyphmodule = self._context.getGlyphmodule()
     glyphmodule.defineStandardGlyphs()
     materialmodule = self._context.getMaterialmodule()
     materialmodule.defineStandardMaterials()
     tessellationmodule = self._context.getTessellationmodule()
     default_tessellation = tessellationmodule.getDefaultTessellation()
     default_tessellation.setMinimumDivisions(12)
     self._setupSpectrum()
     self.clear()
    def __init__(self):
        self._coordinate_description = None
        self._file_location = None
        self._location = None
        self._context = Context("MeshImage")
        defineStandardVisualisationTools(self._context)

        self._image_model = ImageModel(self._context)
        # First create coordinate field
        self._elements = None
        self._nodes = None
        self._rotation_axis = [0, 1, 0]
        self._reference_normal = [0, 0, 1]
        self._region = self._context.getDefaultRegion()
        self._coordinate_field = createFiniteElementField(self._region)
        self._plane = self._setupDetectionPlane(self._region, self._coordinate_field)
        self._iso_scalar_field = createIsoScalarField(self._region, self._coordinate_field, self._plane)
        self._visibility_field = createVisibilityFieldForPlane(self._region, self._coordinate_field, self._plane)
Esempio n. 51
0
    def __init__(self, numberOfFrames,samplepointsPerElement=1):
        '''
        Load mesh and setup for model
        '''
        self.context = Context('heart')
        self.numberOfFrames = numberOfFrames
        self.samplepointsPerElement = samplepointsPerElement 
        region = self.context.getDefaultRegion()
        sir = region.createStreaminformationRegion()
        self.times = range(numberOfFrames)
        path = os.path.abspath(__file__)
        dirPath = os.path.dirname(path)
        for t in self.times:    
            tfile = sir.createStreamresourceFile(os.path.join(dirPath,'heartmodel.exnode'))
            sir.setResourceAttributeReal(tfile,sir.ATTRIBUTE_TIME,t)
        sir.createStreamresourceFile(os.path.join(dirPath,'globalhermiteparam.exelem'))       
        region.read(sir)
        
        self.region = region.findChildByName('heart')
        fieldModule = self.region.getFieldmodule()
      
        self.prolateSpheroidalCoordinatesField = fieldModule.findFieldByName('coordinates').castFiniteElement()
        #Hold on to the nodes
        nodeset = fieldModule.findNodesetByName('nodes')
        nodeIterator = nodeset.createNodeiterator()
        self.nodes = dict()
        node = nodeIterator.next()
            
        while node.isValid():
            ni = node.getIdentifier()
            self.nodes[ni] = node
            node = nodeIterator.next()

        # Hold on to elements to get boundary    
        mesh = fieldModule.findMeshByDimension(3)
        ei   = mesh.createElementiterator()
        self.elemDict = dict()
        elem = ei.next()
        while elem.isValid():
            self.elemDict[elem.getIdentifier()] = elem
            elem = ei.next()        
        logging.info("Created LV Model")
Esempio n. 52
0
    def __init__(self, parent=None):
        '''
        Initiaise the ZincView first calling the QWidget __init__ function.
        '''
        QtGui.QMainWindow.__init__(self, parent)

        self._context = ZincContext("ZincView");
        # set up standard materials and glyphs so we can use them elsewhere
        materialmodule = self._context.getMaterialmodule()
        materialmodule.defineStandardMaterials()
        glyphmodule = self._context.getGlyphmodule()
        glyphmodule.defineStandardGlyphs()
        
        # Using composition to include the visual element of the GUI.
        self.ui = Ui_ZincView()
        self.ui.setupUi(self)
        self.ui.sceneviewerwidget.setContext(self._context)
        self.ui.sceneviewerwidget.graphicsInitialized.connect(self._graphicsInitialized)
        self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))
        self._maximumClippingDistance = 1
Esempio n. 53
0
 def __init__(self, parent=None):
     '''
     Initiaise the MaterialsDlg first calling the QWidget __init__ function.
     '''
     QtGui.QWidget.__init__(self, parent)
     
     # Using composition to include the visual element of the GUI.
     self._ui = Ui_SelectionDlg()
     self._ui.setupUi(self)
     self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))
     self.resize(620, 440)
     
     self._context = Context('selection')
     self._ui.zincWidget.setContext(self._context)
     
     # Define some standard glyphs and materials
     self._ui.zincWidget.defineStandardGlyphs()
     self._ui.zincWidget.defineStandardMaterials()
     
     self._readCube()
     self._showCube()
Esempio n. 54
0
    def __init__(self, parent=None):
        '''
        Initiaise the ReadMeshDlg first calling the QWidget __init__ function.
        '''
        QtGui.QWidget.__init__(self, parent)

        # create instance of Zinc Context from which all other objects are obtained
        self._context = ZincContext("ModelViewer");
        # set up standard materials and glyphs so we can use them elsewhere
        self._materialmodule = self._context.getMaterialmodule()
        self._materialmodule.defineStandardMaterials()
        self._glyphmodule = self._context.getGlyphmodule()
        self._glyphmodule.defineStandardGlyphs()

        # improve tessellation quality
        tessellationmodule = self._context.getTessellationmodule()
        defaultTessellation = tessellationmodule.getDefaultTessellation()
        defaultTessellation.setMinimumDivisions([6])

        default_region = self._context.getDefaultRegion()
        timekeepermodule = self._context.getTimekeepermodule()
        self._timekeeper = timekeepermodule.getDefaultTimekeeper()
        
        # create region to load mesh into
        self._region = default_region.createChild('myregion')

        # read the model and create some graphics to see it
        self.readMesh()
        self.createSurfaceGraphics()

        # Using composition to include the visual element of the GUI.
        self.ui = Ui_ReadMeshDlg()
        self.ui.setupUi(self)
        # Must pass the context to the ZincWidget for it to work
        self.ui._zincwidget.setContext(self._context)
        self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))

        # set up callbacks for changes in the time slider
        self.ui.timeSlider.valueChanged.connect(self.timeChanged)
        self.resize(620, 440)
Esempio n. 55
0
    def __init__(self, trc_data):
        super(MOCAPViewer, self).__init__()
        self._trc_data = trc_data
        self._ui = Ui_MOCAPViewer()
        self._ui.setupUi(self)

        self._nodes = []
        self._labels = self._trc_data['Labels'][2:]
        frame_min = self._trc_data['Frame#'][0]
        frame_max = self._trc_data['Frame#'][-1]
        time_min = self._trc_data['Time'][0]
        time_max = self._trc_data['Time'][-1]

        self._ui.horizontalSlider.setMinimum(frame_min)
        self._ui.horizontalSlider.setMaximum(frame_max)

        self._ui.spinBox.setValue(10)

        self._context = Context('MOCAP')
        glyphmodule = self._context.getGlyphmodule()
        glyphmodule.defineStandardGlyphs()
        materialmodule = self._context.getMaterialmodule()
        materialmodule.defineStandardMaterials()
        self._ui.sceneviewerWidget.setContext(self._context)

        self._timer = QtCore.QTimer(self)
        self._timeKeeper = self._context.getTimekeepermodule().getDefaultTimekeeper()
        self._timeKeeper.setMinimumTime(time_min)
        self._timeKeeper.setMaximumTime(time_max)

        self._region = self._context.getDefaultRegion()
        self._createScene(self._region)
        self._graphics = None


        self._populateListWidget()
        self._makeConnections()
Esempio n. 56
0
    def generateMesh(self,numtimepoints,zregion=None):
        """
        :param zregion: Zinc region to define model in. Must be empty.
        :param moptions: Dict containing options. See getDefaultOptions().
        :return: None
        """
        region = zregion
        if zregion is None:
            ctx = Context('gen')
            region = ctx.getDefaultRegion()
            self.context = ctx
           
        self.region = region
        self.numTimePoints = numtimepoints
        elementsCountUp = 5
        elementsCountAround = 6
        useCrossDerivatives = False

        fm = region.getFieldmodule()
        fm.beginChange()
        #Get time list
        timeSequence = fm.getMatchingTimesequence(range(numtimepoints))
        
        
        coordinates = fm.createFieldFiniteElement(3)
        coordinates.setName('coordinates')
        coordinates.setManaged(True)
        coordinates.setTypeCoordinate(True)
        coordinates.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN)
        coordinates.setComponentName(1, 'x')
        coordinates.setComponentName(2, 'y')
        coordinates.setComponentName(3, 'z')

        nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
        nodetemplateApex = nodes.createNodetemplate()
        nodetemplateApex.defineField(coordinates)
        nodetemplateApex.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_VALUE, 1)
        nodetemplateApex.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS1, 1)
        nodetemplateApex.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS2, 1)
        if useCrossDerivatives:
            nodetemplate = nodes.createNodetemplate()
            nodetemplate.defineField(coordinates)
            nodetemplate.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_VALUE, 1)
            nodetemplate.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS1, 1)
            nodetemplate.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS2, 1)
            nodetemplate.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D2_DS1DS2, 1)
        else:
            nodetemplate = nodetemplateApex

        nodetemplate.setTimesequence(coordinates,timeSequence)
        self.coordinates = coordinates
        mesh = fm.findMeshByDimension(2)
        bicubicHermiteBasis = fm.createElementbasis(2, Elementbasis.FUNCTION_TYPE_CUBIC_HERMITE)

        eft = mesh.createElementfieldtemplate(bicubicHermiteBasis)
        if not useCrossDerivatives:
            for n in range(4):
                eft.setFunctionNumberOfTerms(n*4 + 4, 0)

        # Apex1: collapsed on xi1 = 0
        eftApex1 = mesh.createElementfieldtemplate(bicubicHermiteBasis)
        eftApex1.setNumberOfLocalNodes(3)
        eftApex1.setNumberOfLocalScaleFactors(4)
        for s in range(4):
            si = s + 1
            sid = (s // 2)*100 + s + 1  # add 100 for different 'version'
            eftApex1.setScaleFactorType(si, Elementfieldtemplate.SCALE_FACTOR_TYPE_NODE_GENERAL)
            eftApex1.setScaleFactorIdentifier(si, sid)
        # basis node 1 -> local node 1
        eftApex1.setTermNodeParameter(1, 1, 1, Node.VALUE_LABEL_VALUE, 1)
        # 0 terms = zero parameter for d/dxi1 basis
        eftApex1.setFunctionNumberOfTerms(2, 0)
        # 2 terms for d/dxi2 via general linear map:
        eftApex1.setFunctionNumberOfTerms(3, 2)
        eftApex1.setTermNodeParameter(3, 1, 1, Node.VALUE_LABEL_D_DS1, 1)
        eftApex1.setTermScaling(3, 1, [1])
        eftApex1.setTermNodeParameter(3, 2, 1, Node.VALUE_LABEL_D_DS2, 1)
        eftApex1.setTermScaling(3, 2, [2])
        # 0 terms = zero parameter for cross derivative 1 2
        eftApex1.setFunctionNumberOfTerms(4, 0)
        # basis node 2 -> local node 1
        eftApex1.setTermNodeParameter(5, 1, 1, Node.VALUE_LABEL_VALUE, 1)
        # 0 terms = zero parameter for d/dxi1 basis
        eftApex1.setFunctionNumberOfTerms(6, 0)
        # 2 terms for d/dxi2 via general linear map:
        eftApex1.setFunctionNumberOfTerms(7, 2)
        eftApex1.setTermNodeParameter(7, 1, 1, Node.VALUE_LABEL_D_DS1, 1)
        eftApex1.setTermScaling(7, 1, [3])
        eftApex1.setTermNodeParameter(7, 2, 1, Node.VALUE_LABEL_D_DS2, 1)
        eftApex1.setTermScaling(7, 2, [4])
        # 0 terms = zero parameter for cross derivative 1 2
        eftApex1.setFunctionNumberOfTerms(8, 0)
        # basis nodes 3, 4 -> regular local nodes 2, 3
        for bn in range(2,4):
            fo = bn*4
            ni = bn
            eftApex1.setTermNodeParameter(fo + 1, 1, ni, Node.VALUE_LABEL_VALUE, 1)
            eftApex1.setTermNodeParameter(fo + 2, 1, ni, Node.VALUE_LABEL_D_DS1, 1)
            eftApex1.setTermNodeParameter(fo + 3, 1, ni, Node.VALUE_LABEL_D_DS2, 1)
            if useCrossDerivatives:
                eftApex1.setTermNodeParameter(fo + 4, 1, ni, Node.VALUE_LABEL_D2_DS1DS2, 1)
            else:
                eftApex1.setFunctionNumberOfTerms(fo + 4, 0)


        elementtemplate = mesh.createElementtemplate()
        elementtemplate.setElementShapeType(Element.SHAPE_TYPE_SQUARE)
        elementtemplate.defineField(coordinates, -1, eft)
        elementtemplateApex1 = mesh.createElementtemplate()
        elementtemplateApex1.setElementShapeType(Element.SHAPE_TYPE_SQUARE)
        elementtemplateApex1.defineField(coordinates, -1, eftApex1)

        cache = fm.createFieldcache()

        # create nodes
        nodeIdentifier = 1
        radiansPerElementAround = 2.0*np.pi/elementsCountAround
        radiansPerElementUp = np.pi/elementsCountUp/2.0
        x = [ 0.0, 0.0, 0.0 ]
        dx_ds1 = [ 0.0, 0.0, 0.0 ]
        dx_ds2 = [ 0.0, 0.0, 0.0 ]
        zero = [ 0.0, 0.0, 0.0 ]
        radius = 0.5
        self.Nodes = dict()
        # create apex1 node
        node = nodes.createNode(nodeIdentifier, nodetemplateApex)
        self.apexNode = node
        self.coordinates = coordinates
        self.radiansPerElementUp = radiansPerElementUp
        cache.setNode(node)
        self.Nodes[nodeIdentifier] = node
        coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1, [ 0.0, 0.0, -radius ])
        coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1, [ 0.0, radius*radiansPerElementUp, 0.0 ])
        coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1, [ radius*radiansPerElementUp, 0.0, 0.0 ])
        nodeIdentifier = nodeIdentifier + 1

        # create regular rows between apexes
        for n2 in range(1, elementsCountUp):
            radiansUp = n2*radiansPerElementUp
            cosRadiansUp = np.cos(radiansUp);
            sinRadiansUp = np.sin(radiansUp);
            for n1 in range(elementsCountAround):
                radiansAround = n1*radiansPerElementAround
                cosRadiansAround = np.cos(radiansAround)
                sinRadiansAround = np.sin(radiansAround)
                x = [
                    radius*cosRadiansAround*sinRadiansUp,
                    radius*sinRadiansAround*sinRadiansUp,
                    -radius*cosRadiansUp
                ]
                dx_ds1 = [
                    radius*-sinRadiansAround*sinRadiansUp*radiansPerElementAround,
                    radius*cosRadiansAround*sinRadiansUp*radiansPerElementAround,
                    0.0
                ]
                dx_ds2 = [
                    radius*cosRadiansAround*cosRadiansUp*radiansPerElementUp,
                    radius*sinRadiansAround*cosRadiansUp*radiansPerElementUp,
                    radius*sinRadiansUp*radiansPerElementUp
                ]
                node = nodes.createNode(nodeIdentifier, nodetemplate)
                cache.setNode(node)
                self.Nodes[nodeIdentifier] = node
                coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1, x)
                coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1, dx_ds1)
                coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS2, 1, dx_ds2)
                if useCrossDerivatives:
                    coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D2_DS1DS2, 1, zero)
                nodeIdentifier = nodeIdentifier + 1

        # create elements
        elementIdentifier = 1
        # create Apex1 elements, editing eft scale factor identifiers around apex
        # scale factor identifiers follow convention of offsetting by 100 for each 'version'
        bni1 = 1
        for e1 in range(elementsCountAround):
            va = e1
            vb = (e1 + 1)%elementsCountAround
            eftApex1.setScaleFactorIdentifier(1, va*100 + 1)
            eftApex1.setScaleFactorIdentifier(2, va*100 + 2)
            eftApex1.setScaleFactorIdentifier(3, vb*100 + 1)
            eftApex1.setScaleFactorIdentifier(4, vb*100 + 2)
            # redefine field in template for changes to eftApex1:
            elementtemplateApex1.defineField(coordinates, -1, eftApex1)
            element = mesh.createElement(elementIdentifier, elementtemplateApex1)
            bni2 = e1 + 2
            bni3 = (e1 + 1)%elementsCountAround + 2
            nodeIdentifiers = [ bni1, bni2, bni3 ]
            element.setNodesByIdentifier(eftApex1, nodeIdentifiers)
            # set general linear map coefficients
            radiansAround = e1*radiansPerElementAround
            radiansAroundNext = ((e1 + 1)%elementsCountAround)*radiansPerElementAround
            scalefactors = [
                np.sin(radiansAround), np.cos(radiansAround), np.sin(radiansAroundNext), np.cos(radiansAroundNext)
            ]
            element.setScaleFactors(eftApex1, scalefactors)
            elementIdentifier = elementIdentifier + 1

        # create regular rows between apexes
        for e2 in range(elementsCountUp - 2):
            for e1 in range(elementsCountAround):
                element = mesh.createElement(elementIdentifier, elementtemplate)
                bni1 = e2*elementsCountAround + e1 + 2
                bni2 = e2*elementsCountAround + (e1 + 1)%elementsCountAround + 2
                nodeIdentifiers = [ bni1, bni2, bni1 + elementsCountAround, bni2 + elementsCountAround ]
                element.setNodesByIdentifier(eft, nodeIdentifiers)
                elementIdentifier = elementIdentifier + 1

        fm.defineAllFaces()
        fm.endChange()
Esempio n. 57
0
class SelectionDlg(QtGui.QWidget):
    '''
    Create a subclass of QWidget for our application.  We could also have derived this 
    application from QMainApplication to give us a menu bar among other things, but a
    QWidget is sufficient for our purposes.
    '''
    
    def __init__(self, parent=None):
        '''
        Initiaise the MaterialsDlg first calling the QWidget __init__ function.
        '''
        QtGui.QWidget.__init__(self, parent)
        
        # Using composition to include the visual element of the GUI.
        self._ui = Ui_SelectionDlg()
        self._ui.setupUi(self)
        self.setWindowIcon(QtGui.QIcon(":/cmiss_icon.ico"))
        self.resize(620, 440)
        
        self._context = Context('selection')
        self._ui.zincWidget.setContext(self._context)
        
        # Define some standard glyphs and materials
        self._ui.zincWidget.defineStandardGlyphs()
        self._ui.zincWidget.defineStandardMaterials()
        
        self._readCube()
        self._showCube()
        
    def _readCube(self):
        '''
        Read in a basic cube mesh from an exformat file.
        '''
        region = self._context.getDefaultRegion()
        region.readFile('cube.exformat')
    
    def _showCube(self):
        '''
        Show the cube with surfaces and node points.
        '''
        region = self._context.getDefaultRegion()
        scene = region.getScene()
        field_module = region.getFieldmodule()
        finite_element_field = field_module.findFieldByName('coordinates')
        
        material_module = self._context.getMaterialmodule()
        blue_material = material_module.findMaterialByName('blue')
        red_material = material_module.findMaterialByName('red')
        gold_material = material_module.findMaterialByName('gold')
        silver_material = material_module.findMaterialByName('silver')
        yellow_material = material_module.findMaterialByName('yellow')
        green_material = material_module.findMaterialByName('green')
    
        # We use the beginChange and endChange to wrap any immediate changes this will
        # streamline the rendering of the scene.
        scene.beginChange()
        
        lines = scene.createGraphicsLines()
        lines.setCoordinateField(finite_element_field)
        lines.setMaterial(yellow_material)
        lines.setSelectedMaterial(green_material)

        surface = scene.createGraphicsSurfaces()
        surface.setCoordinateField(finite_element_field)
        surface.setMaterial(blue_material)
        surface.setSelectedMaterial(red_material)
        
        
        nodes = scene.createGraphicsPoints()
        nodes.setCoordinateField(finite_element_field)
        nodes.setFieldDomainType(finite_element_field.DOMAIN_TYPE_NODES)
        nodes.setMaterial(gold_material)
        nodes.setSelectedMaterial(silver_material)
        attributes = nodes.getGraphicspointattributes()
        attributes.setGlyphShapeType(Glyph.SHAPE_TYPE_SPHERE)
        attributes.setBaseSize(0.1)
        
        # Let the scene render the scene.
        scene.endChange()
Esempio n. 58
0
class MOCAPViewer(QtGui.QWidget):

    def __init__(self, trc_data):
        super(MOCAPViewer, self).__init__()
        self._trc_data = trc_data
        self._ui = Ui_MOCAPViewer()
        self._ui.setupUi(self)

        self._nodes = []
        self._labels = self._trc_data['Labels'][2:]
        frame_min = self._trc_data['Frame#'][0]
        frame_max = self._trc_data['Frame#'][-1]
        time_min = self._trc_data['Time'][0]
        time_max = self._trc_data['Time'][-1]

        self._ui.horizontalSlider.setMinimum(frame_min)
        self._ui.horizontalSlider.setMaximum(frame_max)

        self._ui.spinBox.setValue(10)

        self._context = Context('MOCAP')
        glyphmodule = self._context.getGlyphmodule()
        glyphmodule.defineStandardGlyphs()
        materialmodule = self._context.getMaterialmodule()
        materialmodule.defineStandardMaterials()
        self._ui.sceneviewerWidget.setContext(self._context)

        self._timer = QtCore.QTimer(self)
        self._timeKeeper = self._context.getTimekeepermodule().getDefaultTimekeeper()
        self._timeKeeper.setMinimumTime(time_min)
        self._timeKeeper.setMaximumTime(time_max)

        self._region = self._context.getDefaultRegion()
        self._createScene(self._region)
        self._graphics = None


        self._populateListWidget()
        self._makeConnections()

    def _makeConnections(self):
        self._ui.listWidget.itemClicked.connect(self._labelClicked)
        self._ui.listWidget.itemChanged.connect(self._labelChanged)
        self._ui.sceneviewerWidget.graphicsInitialized.connect(self._sceneviewerReady)
        self._ui.pushButtonPlay.clicked.connect(self._playClicked)
        self._ui.spinBox.valueChanged.connect(self._sizeChanged)
        self._ui.horizontalSlider.valueChanged.connect(self._timeChanged)
        self._timer.timeout.connect(self._timeIncrement)

    def _playClicked(self):
        text = self._ui.pushButtonPlay.text()
        if text == '&Play':
            self._timer.start(10)
            self._ui.pushButtonPlay.setText('&Stop')
        else:
            self._timer.stop()
            self._ui.pushButtonPlay.setText('&Play')

    def _timeIncrement(self):
        time_increment = 1
        current_value = self._ui.horizontalSlider.value()
        current_value += time_increment
        if current_value >= self._ui.horizontalSlider.maximum():
            current_value = self._ui.horizontalSlider.minimum()

        self._ui.horizontalSlider.setValue(current_value)

    def _sizeChanged(self, value):
        scene = self._region.getScene()
        scene.beginChange()
        for graphics in self._graphics:
            attributes = graphics.getGraphicspointattributes()
            attributes.setBaseSize(value)
        scene.endChange()

    def _timeChanged(self, frame_index):
        time = self._trc_data['Time'][frame_index - 1]
        self._timeKeeper.setTime(time)

    def _sceneviewerReady(self):
        self._graphics = createNodeGraphics(self._region)
        self._ui.sceneviewerWidget.viewAll()

    def getTRCData(self):
        return self._trc_data

    def _getNodeForLabel(self, label):
        index = self._labels.index(label)
        node = self._nodes[index]

        return node

    def _labelClicked(self, item):
        # Set node selected.
        node = self._getNodeForLabel(item.text())
        nodeset = node.getNodeset()
        selection_group = self._ui.sceneviewerWidget._selectionGroup#getSelectionGroup()
        nodegroup = selection_group.getFieldNodeGroup(nodeset)
        if not nodegroup.isValid():
            nodegroup = selection_group.createFieldNodeGroup(nodeset)

        group = nodegroup.getNodesetGroup()
        if not group.containsNode(node):
            group.removeAllNodes()
            group.addNode(node)

    def _labelChanged(self, item):

        row = self._ui.listWidget.row(item)
        node = self._getNodeForLabel(self._labels[row])

        new_text = str(item.text())
        old_text = self._labels[row]

        fieldmodule = self._region.getFieldmodule()
        fieldcache = fieldmodule.createFieldcache()

        fieldmodule.beginChange()

        fieldcache.setNode(node)
        self._string_field.assignString(fieldcache, new_text)
        self._labels[row] = new_text
        self._trc_data[new_text] = self._trc_data.pop(old_text)
        self._trc_data['Labels'][row + 2] = new_text

        fieldmodule.endChange()

    def _populateListWidget(self):
        self._ui.listWidget.addItems(self._labels)
        for index in xrange(self._ui.listWidget.count()):
            item = self._ui.listWidget.item(index)
            item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)

    def _createScene(self, region):
        coordinate_field = createFiniteElementField(region)
        self._string_field = createStoredStringField(region)
        fieldmodule = region.getFieldmodule()
        fieldmodule.beginChange()
        nodeset = fieldmodule.findNodesetByName('nodes')
        node_template = nodeset.createNodetemplate()

        time = self._trc_data['Time']
        ts = fieldmodule.getMatchingTimesequence(0)
        for index, t in enumerate(time):
            ts.setTime(index + 1, t),

        # Set the finite element coordinate field for the nodes to use
        node_template.defineField(coordinate_field)
        node_template.defineField(self._string_field)
        node_template.setTimesequence(coordinate_field, ts)
        fieldcache = fieldmodule.createFieldcache()

        for label in self._labels:
            node_coordinates = self._trc_data[label]
            node = nodeset.createNode(-1, node_template)
            self._nodes.append(node)
            # Set the node coordinates, first set the field cache to use the current node
            fieldcache.setNode(node)
            for index, t in enumerate(time):
                fieldcache.setTime(t)
                # Pass in floats as an array
                coordinate_field.assignReal(fieldcache, node_coordinates[index])
                self._string_field.assignString(fieldcache, label)

        fieldmodule.endChange()
class MeshImageModel(object):

    def __init__(self):
        self._coordinate_description = None
        self._file_location = None
        self._location = None
        self._context = Context("MeshImage")
        defineStandardVisualisationTools(self._context)

        self._image_model = ImageModel(self._context)
        # First create coordinate field
        self._elements = None
        self._nodes = None
        self._rotation_axis = [0, 1, 0]
        self._reference_normal = [0, 0, 1]
        self._region = self._context.getDefaultRegion()
        self._coordinate_field = createFiniteElementField(self._region)
        self._plane = self._setupDetectionPlane(self._region, self._coordinate_field)
        self._iso_scalar_field = createIsoScalarField(self._region, self._coordinate_field, self._plane)
        self._visibility_field = createVisibilityFieldForPlane(self._region, self._coordinate_field, self._plane)

    def load_mesh(self, mesh):
        self._nodes = mesh['points']
        self._elements = mesh['elements']
        self._createMesh(self._nodes, self._elements)
        extents = calculateExtents(self._nodes)
        mid_point = [(extents[1] + extents[0])/2.0, (extents[3] + extents[2])/2.0, (extents[5] + extents[4])/2.0]
        self._plane.setRotationPoint(mid_point)

    def load_images(self, images_dir):
        self._image_model.setImageData(images_dir)

    def clear(self):
        return
        self._image_model.clear()
        self._region = None

    def initialise(self):
        # return
        # self._region = self._context.createRegion()
        self._image_model.initialise(self._region)

    def getImageModel(self):
        return self._image_model

    def getContext(self):
        return self._context

    def getCoordinateField(self):
        return self._coordinate_field

    def getRegion(self):
        return self._region

    def getVisibilityField(self):
        return self._visibility_field

    def getImageRegionNames(self):
        return self._image_model.getRegionNames()

    def setImageRegionVisibility(self, region_name, state):
        self._image_model.setRegionVisibility(region_name, state)

    def getIsoScalarField(self):
        return self._iso_scalar_field

    def setRotationAngle(self, angle):
        c = cos(angle*pi/180.0)
        s = sin(angle*pi/180.0)
        C = 1 - c
        x = self._rotation_axis[0]
        y = self._rotation_axis[1]
        z = self._rotation_axis[2]

        Q = [[x*x*C+c,   x*y*C-z*c, x*z*C+y*s],
             [y*x*C+z*s, y*y*C+c,   y*z*C-x*s ],
             [z*x*C-y*s, z*y*C+x*s, z*z*C+c]]

        n = mxvectormult(Q, self._reference_normal)

        self._plane.setNormal(n)

    def _setupDetectionPlane(self, region, coordinate_field):
        '''
        Adds a single finite element to the region and keeps a handle to the
        fields created for the finite element in the following attributes(
        self-documenting names):
            '_coordinate_field'
            '_scale_field'
            '_scaled_coordinate_field'
            '_iso_scalar_field'
        '''
        fieldmodule = region.getFieldmodule()
        fieldmodule.beginChange()

        plane = ZincPlane(fieldmodule)

        fieldmodule.endChange()

        return plane

    def _createMesh(self, nodes, elements):
        """
        Create a mesh from data extracted from a VRML file.
        The nodes are given as a list of coordinates and the elements
        are given as a list of indexes into the node list..
        """
        # First create all the required nodes
        createNodes(self._coordinate_field, self._nodes)
        # then define elements using a list of node indexes
        createElements(self._coordinate_field, self._elements)
        # Define all faces also
        fieldmodule = self._coordinate_field.getFieldmodule()
        fieldmodule.defineAllFaces()