Exemplo n.º 1
0
class MeshParser(object):

    def __init__(self):
        self._parser = None

    def parse(self, filename, use_parser=None):
        if use_parser is None:
            # Try and determine which parser to use.
            vtk_parser = VTKParser()
            stl_parser = STLParser()
            vrml_parser = VRMLParser()
            if filename.endswith('.vtk'):
                if vtk_parser.canParse(filename):
                    self._parser = vtk_parser
                else:
                    raise TypeError('Could not parse mesh as vtk mesh: {0}'.format(filename))
            elif filename.endswith('.stl'):
                if stl_parser.canParse(filename):
                    self._parser = stl_parser
                else:
                    raise TypeError('Could not parse mesh as stl mesh: {0}'.format(filename))
            elif filename.endswith('.wrl'):
                if vrml_parser.canParse(filename):
                    self._parser = vrml_parser
                else:
                    raise TypeError('Could not parse mesh as vrml mesh: {0}'.format(filename))
            else:
                if vtk_parser.canParse(filename):
                    self._parser = vtk_parser
                elif stl_parser.canParse(filename):
                    self._parser = stl_parser
                elif vrml_parser.canParse(filename):
                    self._parser = vrml_parser
                else:
                    raise TypeError('Could not determine type of mesh to parse for filename: {0}'.format(filename))
        else:
            lower = use_parser.lowercase()
            if lower == 'vrml':
                self._parser = VRMLParser()
            elif lower == 'stk':
                self._parser = STLParser()
            elif lower == 'vtk':
                self._parser = VTKParser()
            else:
                raise NotImplementedError('A parser for the value: "{0}" has not been implemented.'.format(use_parser))

        self._parser.parse(filename)

    def getPoints(self, pared=False):
        return self._parser.getPoints(pared=pared)

    def getElements(self, zero_based=True, pared=False):
        return self._parser.getElements(zero_based=zero_based, pared=pared)
Exemplo n.º 2
0
    def testParse2(self):
        v = VTKParser()
        v.parse('data/cardiac_jelly.vtk')

        self.assertEqual(1170, len(v.getPoints()))
        self.assertEqual(2314, len(v.getElements()))
Exemplo n.º 3
0
 def testParse1(self):
     v = VTKParser()
     v.parse('data/cardiac_jelly.vtk')
Exemplo n.º 4
0
class MeshParser(object):
    def __init__(self):
        self._parser = None

    def parse(self, filename, use_parser=None):
        if use_parser is None:
            # Try and determine which parser to use.
            vtk_parser = VTKParser()
            stl_parser = STLParser()
            vrml_parser = VRMLParser()
            if filename.endswith('.vtk'):
                if vtk_parser.canParse(filename):
                    self._parser = vtk_parser
                else:
                    raise TypeError(
                        'Could not parse mesh as vtk mesh: {0}'.format(
                            filename))
            elif filename.endswith('.stl'):
                if stl_parser.canParse(filename):
                    self._parser = stl_parser
                else:
                    raise TypeError(
                        'Could not parse mesh as stl mesh: {0}'.format(
                            filename))
            elif filename.endswith('.wrl'):
                if vrml_parser.canParse(filename):
                    self._parser = vrml_parser
                else:
                    raise TypeError(
                        'Could not parse mesh as vrml mesh: {0}'.format(
                            filename))
            else:
                if vtk_parser.canParse(filename):
                    self._parser = vtk_parser
                elif stl_parser.canParse(filename):
                    self._parser = stl_parser
                elif vrml_parser.canParse(filename):
                    self._parser = vrml_parser
                else:
                    raise TypeError(
                        'Could not determine type of mesh to parse for filename: {0}'
                        .format(filename))
        else:
            lower = use_parser.lowercase()
            if lower == 'vrml':
                self._parser = VRMLParser()
            elif lower == 'stk':
                self._parser = STLParser()
            elif lower == 'vtk':
                self._parser = VTKParser()
            else:
                raise NotImplementedError(
                    'A parser for the value: "{0}" has not been implemented.'.
                    format(use_parser))

        self._parser.parse(filename)

    def getPoints(self, pared=False):
        return self._parser.getPoints(pared=pared)

    def getElements(self, zero_based=True, pared=False):
        return self._parser.getElements(zero_based=zero_based, pared=pared)
Exemplo n.º 5
0
    def testParse2(self):
        v = VTKParser()
        v.parse('data/cardiac_jelly.vtk')

        self.assertEqual(1170, len(v.getPoints()))
        self.assertEqual(2314, len(v.getElements()))
Exemplo n.º 6
0
 def testParse1(self):
     v = VTKParser()
     v.parse('data/cardiac_jelly.vtk')
Exemplo n.º 7
0
 def testParse1(self):
     v = VTKParser()
     test_filename = os.path.join(file_path, 'data/cardiac_jelly.vtk')
     self.assertTrue(v.canParse(test_filename))
     v.parse(test_filename)