# Path: pymicro/core/global_variables.py
# XDMF_FIELD_TYPE = {1: 'Scalar', 2: 'Vector', 3: 'Vector', 6: 'Tensor6',
#                    9: 'Tensor'}
# 
# XDMF_IMAGE_GEOMETRY = {'3DImage': 'ORIGIN_DXDYDZ', '2DImage': 'ORIGIN_DXDY'}
# 
# XDMF_IMAGE_TOPOLOGY = {'3DImage': '3DCoRectMesh', '2DImage': '2DCoRectMesh'}
# 
# Path: pymicro/core/global_variables.py
# SD_GROUP_TYPES = ['Group', '2DImage', '3DImage', '2DMesh', '3DMesh']
# 
# SD_GRID_GROUPS = ['2DImage', '3DImage', '2DMesh', '3DMesh', 'emptyImage',
#                   'emptyMesh']
# 
# SD_IMAGE_GROUPS = {2:'2DImage', 3:'3DImage', 0:'emptyImage', -1:'Image'}
# 
# SD_MESH_GROUPS = {2:'2DMesh', 3:'3DMesh', 0:'emptyMesh', -1:'Mesh'}


import os
import subprocess
import shutil
import numpy as np
import tables
import lxml.builder
import BasicTools.Containers.UnstructuredMeshCreationTools as UMCT
            import re
        import BasicTools.Containers.ElementNames as EN
        import BasicTools.Containers.ElementNames as EN
from lxml import etree
from pathlib import Path
from BasicTools.Containers.ConstantRectilinearMesh import (
    ConstantRectilinearMesh)
from BasicTools.Containers.UnstructuredMesh import (UnstructuredMesh,
                                                    AllElements)
from BasicTools.Containers.MeshBase import MeshBase
from BasicTools.IO.XdmfTools import XdmfName,XdmfNumber
from pymicro.core.global_variables import (XDMF_FIELD_TYPE,
                                           XDMF_IMAGE_GEOMETRY,
                                           XDMF_IMAGE_TOPOLOGY)
from pymicro.core.global_variables import (SD_GROUP_TYPES, SD_GRID_GROUPS,
                                           SD_IMAGE_GROUPS, SD_MESH_GROUPS)
        from BasicTools.IO.UniversalReader import ReadMesh
        """Write grid geometry and topoly in xdmf tree/file."""
        # add 1 to each dimension to get grid dimension (from cell number to
        # point number --> XDMF indicates Grid points)
        image_type = self._get_image_type(image_object)
        # Get image dimension with reverted shape to compensate for Paraview
        # X,Y,Z indexing convention
        Dimension_tmp = image_object.GetDimensions()
        Spacing_tmp = image_object.GetSpacing()
        Origin_tmp = image_object.GetOrigin()
        if len(Dimension_tmp) == 2:
            Dimension_tmp = Dimension_tmp[[1,0]]
            Spacing_tmp = Spacing_tmp[[1,0]]
            Origin_tmp = Origin_tmp[[1,0]]
        elif len(Dimension_tmp) == 3:
            Dimension_tmp = Dimension_tmp[[2,1,0]]
            Spacing_tmp = Spacing_tmp[[2,1,0]]
            Origin_tmp = Origin_tmp[[2,1,0]]
        Dimension = self._np_to_xdmf_str(Dimension_tmp)
        Spacing = self._np_to_xdmf_str(Spacing_tmp)
        Origin = self._np_to_xdmf_str(Origin_tmp)
        Dimensionality = str(image_object.GetDimensionality())
        self._verbose_print('Updating xdmf tree...', line_break=False)
        # Creatge Grid element
        image_xdmf = etree.Element(_tag='Grid', Name=imagename,
                                   GridType='Uniform')
        # Create Topology element
        Topotype = XDMF_IMAGE_TOPOLOGY[image_type]
        topology_xdmf = etree.Element(_tag='Topology', TopologyType=Topotype,
                                      Dimensions=Dimension)
        # Create Geometry element

# Path: pymicro/core/global_variables.py
# XDMF_FIELD_TYPE = {1: 'Scalar', 2: 'Vector', 3: 'Vector', 6: 'Tensor6',
#                    9: 'Tensor'}
# 
# XDMF_IMAGE_GEOMETRY = {'3DImage': 'ORIGIN_DXDYDZ', '2DImage': 'ORIGIN_DXDY'}
# 
# XDMF_IMAGE_TOPOLOGY = {'3DImage': '3DCoRectMesh', '2DImage': '2DCoRectMesh'}
# 
# Path: pymicro/core/global_variables.py
# SD_GROUP_TYPES = ['Group', '2DImage', '3DImage', '2DMesh', '3DMesh']
# 
# SD_GRID_GROUPS = ['2DImage', '3DImage', '2DMesh', '3DMesh', 'emptyImage',
#                   'emptyMesh']
# 
# SD_IMAGE_GROUPS = {2:'2DImage', 3:'3DImage', 0:'emptyImage', -1:'Image'}
# 
# SD_MESH_GROUPS = {2:'2DMesh', 3:'3DMesh', 0:'emptyMesh', -1:'Mesh'}


# Path: pymicro/core/samples.py
import os
import subprocess
import shutil
import numpy as np
import tables
import lxml.builder
import BasicTools.Containers.UnstructuredMeshCreationTools as UMCT
            import re
        import BasicTools.Containers.ElementNames as EN
        import BasicTools.Containers.ElementNames as EN
from lxml import etree
from pathlib import Path
from BasicTools.Containers.ConstantRectilinearMesh import (
    ConstantRectilinearMesh)
from BasicTools.Containers.UnstructuredMesh import (UnstructuredMesh,
                                                    AllElements)
from BasicTools.Containers.MeshBase import MeshBase
from BasicTools.IO.XdmfTools import XdmfName,XdmfNumber
from pymicro.core.global_variables import (XDMF_FIELD_TYPE,
                                           XDMF_IMAGE_GEOMETRY,
                                           XDMF_IMAGE_TOPOLOGY)
from pymicro.core.global_variables import (SD_GROUP_TYPES, SD_GRID_GROUPS,
                                           SD_IMAGE_GROUPS, SD_MESH_GROUPS)
        from BasicTools.IO.UniversalReader import ReadMesh

        """Write grid geometry and topoly in xdmf tree/file."""
        # add 1 to each dimension to get grid dimension (from cell number to
        # point number --> XDMF indicates Grid points)
        image_type = self._get_image_type(image_object)
        # Get image dimension with reverted shape to compensate for Paraview
        # X,Y,Z indexing convention
        Dimension_tmp = image_object.GetDimensions()
        Spacing_tmp = image_object.GetSpacing()
        Origin_tmp = image_object.GetOrigin()
        if len(Dimension_tmp) == 2:
            Dimension_tmp = Dimension_tmp[[1,0]]
            Spacing_tmp = Spacing_tmp[[1,0]]
            Origin_tmp = Origin_tmp[[1,0]]
        elif len(Dimension_tmp) == 3:
            Dimension_tmp = Dimension_tmp[[2,1,0]]
            Spacing_tmp = Spacing_tmp[[2,1,0]]
            Origin_tmp = Origin_tmp[[2,1,0]]
        Dimension = self._np_to_xdmf_str(Dimension_tmp)
        Spacing = self._np_to_xdmf_str(Spacing_tmp)
        Origin = self._np_to_xdmf_str(Origin_tmp)
        Dimensionality = str(image_object.GetDimensionality())
        self._verbose_print('Updating xdmf tree...', line_break=False)
        # Creatge Grid element
        image_xdmf = etree.Element(_tag='Grid', Name=imagename,
                                   GridType='Uniform')
        # Create Topology element
        Topotype = XDMF_IMAGE_TOPOLOGY[image_type]
        topology_xdmf = etree.Element(_tag='Topology', TopologyType=Topotype,
                                      Dimensions=Dimension)
        # Create Geometry element

        Geotype = XDMF_IMAGE_GEOMETRY[image_type]