Source code for msml.sortdef

# region gplv3preamble
# The Medical Simulation Markup Language (MSML) - Simplifying the biomechanical modeling workflow
#
# MSML has been developed in the framework of 'SFB TRR 125 Cognition-Guided Surgery'
#
# If you use this software in academic work, please cite the paper:
# S. Suwelack, M. Stoll, S. Schalck, N.Schoch, R. Dillmann, R. Bendl, V. Heuveline and S. Speidel,
# The Medical Simulation Markup Language (MSML) - Simplifying the biomechanical modeling workflow,
# Medicine Meets Virtual Reality (MMVR) 2014
#
# Copyright (C) 2013-2014 see Authors.txt
#
# If you have any questions please feel free to contact us at suwelack@kit.edu
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# endregion

"""This modules include the base definition of both the sort hierarchies.

"""

__author__ = 'Alexander Weigl'
__date__ = '2014-02-21'


[docs]class Sort(object): """A sort is a mixture from an physical and a _logical data type. It provides the function of sort comparison. """ def __init__(self, physical, logical=None): # assert physical is not None self._physical = physical self._logical = logical def __eq__(self, other): if other is self: return True if isinstance(other, Sort): return other._logical == self._logical and self._physical == other._physical return False def __lt__(self, other): if not other or other is self: return False def _compare(p, q): if q is None or p is None: return True else: return issubclass(p, q) return _compare(self.physical, other.physical) \ and _compare(self.logical, other.logical) def __gt__(self, other): return other < self def __ge__(self, other): return self == other or self > other def __le__(self, other): return self == other or self < other def __str__(self): return "<Sort: %s, %s>" % (self.physical, self._logical) def __repr__(self): return "Sort(%s,%s)" % (self.physical, self._logical) @property def physical(self): """The physical data type :return: """ return self._physical @physical.setter def physical(self, fmt): if not fmt: assert isinstance(fmt, type) self._physical = fmt @property def logical(self): """the _logical data type""" return self._logical @logical.setter def logical(self, tp): assert isinstance(tp, type) self._logical = tp # ################################################ # # Logical Type Hierarchy #
[docs]class MSMLLTop(object): """Top of the _logical hierarchy""" pass
[docs]class Index(MSMLLTop): pass
[docs]class Indices(MSMLLTop): pass
[docs]class IndexSet(MSMLLTop): pass
[docs]class NodeSet(IndexSet): pass
[docs]class FaceSet(IndexSet): pass
[docs]class ElementSet(IndexSet): pass
[docs]class Mesh(MSMLLTop): pass
[docs]class VolumeMesh(Mesh): pass
[docs]class TetrahedralVolume(VolumeMesh): pass
[docs]class HexahedralVolume(VolumeMesh): pass
[docs]class QuadraticTetrahedral(VolumeMesh): pass
[docs]class SurfaceMesh(Mesh): pass
[docs]class TriangularSurface(SurfaceMesh): pass
[docs]class SquareSurface(SurfaceMesh): pass
[docs]class QuadraticTriangularSurface(SurfaceMesh): pass
[docs]class Image(MSMLLTop): pass
[docs]class Image2D(Image): pass
[docs]class Image3D(Image): pass
[docs]class SegmentationImage3D(Image3D): pass
[docs]class VectorImage3D(Image3D): pass
[docs]class PhysicalQuantities(MSMLLTop): pass
[docs]class Scalar(PhysicalQuantities): pass
[docs]class VonMisesStress(Scalar): pass
[docs]class Vector(PhysicalQuantities): pass
[docs]class Displacement(Vector): pass
[docs]class Position(Vector): pass
[docs]class Force(Vector): pass
[docs]class Velocity(Vector): pass
[docs]class Tensor(PhysicalQuantities): pass
[docs]class Stress(PhysicalQuantities): pass # ######################################################### # # # Physical Hierarchy
[docs]class MSMLPhysicalTop(object): pass
[docs]class InMemory(MSMLPhysicalTop): pass
[docs]class MSMLFloat(float, MSMLPhysicalTop): pass
[docs]class MSMLInt(int, MSMLPhysicalTop): pass # class MSMLBool(bool, MSMLPhysicalTop): pass
[docs]class MSMLUInt(int, MSMLPhysicalTop): pass
[docs]class MSMLString(str, MSMLPhysicalTop): pass
[docs]class MSMLListUI(list, MSMLPhysicalTop): pass
[docs]class MSMLListI(list, MSMLPhysicalTop): pass
[docs]class MSMLListF(list, MSMLPhysicalTop): pass
[docs]class GenericMesh(MSMLPhysicalTop): def __init__(self, vertices, cell_sizes, connectivity): self._vertices = vertices self._connectivity = connectivity self._cell_sizes = cell_sizes @property def vertices(self): return self._vertices @vertices.setter def vertices(self, value): self._vertices = value @property def cell_sizes(self): return self._cell_sizes @cell_sizes.setter def cell_sizes(self, value): self._cell_sizes = value @property def connectivity(self): return self._connectivity @connectivity.setter def connectivity(self, value): self._connectivity = value
[docs]class InFile(str, MSMLPhysicalTop): pass
[docs]class PNG(InFile): pass
[docs]class TXT(InFile): pass
[docs]class ContainerFile(InFile): pass # """A container file is built from a filename and a partname # """ # def __init__(self, filename, partname=None): # if not partname: # try: # self.filename, self.partname = filename.split(";") # except: # self.filename = filename # self.partname = None # else: # self.filename = filename # self.partname = partname # # def __str__(self): # return "<%s: %s;%s>" % (type(self).__name__, self.filename,self.partname)
[docs]class VTK(ContainerFile): pass
[docs]class VTU(VTK): pass
[docs]class VTI(VTK): pass
[docs]class VTP(VTK): pass
[docs]class STL(InFile): pass
[docs]class DICOM(ContainerFile): pass
[docs]class HDF5(ContainerFile): pass
[docs]class ctx(ContainerFile): pass
[docs]class vdx(ContainerFile): pass