示例#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)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    def testParse2(self):
        v = VTKParser()
        v.parse('data/cardiac_jelly.vtk')

        self.assertEqual(1170, len(v.getPoints()))
        self.assertEqual(2314, len(v.getElements()))
示例#5
0
 def testParse1(self):
     v = VTKParser()
     v.parse('data/cardiac_jelly.vtk')
示例#6
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)
示例#7
0
 def testExistence(self):
     v = VTKParser()
     self.assertRaises(IOError, v.parse, 'file that doesnt exist')
示例#8
0
    def testParse2(self):
        v = VTKParser()
        v.parse('data/cardiac_jelly.vtk')

        self.assertEqual(1170, len(v.getPoints()))
        self.assertEqual(2314, len(v.getElements()))
示例#9
0
 def testParse1(self):
     v = VTKParser()
     v.parse('data/cardiac_jelly.vtk')
示例#10
0
 def testBinaryFormat(self):
     v = VTKParser()
     self.assertRaises(NotImplementedError, v.parse, os.path.join(file_path, 'data/fake_binary_format.vtk'))
示例#11
0
 def testOldFormat(self):
     v = VTKParser()
     test_filename = os.path.join(file_path, 'data/old_format.vtk')
     self.assertFalse(v.canParse(test_filename))
     self.assertRaises(SyntaxError, v.parse, test_filename)
示例#12
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)