Ejemplo n.º 1
0
 def testDuplicatedPoints(self):
     v = STLParser()
     v.parse('data/ship.stl')
     self.assertEqual(2484, len(v.getPoints()))
     np = NodePare()
     np.addPoints(v.getPoints())
     np.parePoints()
     self.assertEqual(575, len(np.getParedPoints()))
Ejemplo n.º 2
0
    def testConvert(self):
        v = STLParser()
        v.parse('data/pelvis_minimal.stl')
        nodes = v.getPoints(pared=True)
        self.assertEqual(13, len(nodes))
        elements = v.getElements(zero_based=False, pared=True)
        self.assertEquals([1, 4, 2], elements[1])
        mesh = {'nodes': nodes, 'elements': elements}

        convert(mesh, define_faces=True)
Ejemplo n.º 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)
Ejemplo n.º 4
0
 def _loadMaleMesh(self, resources_path):
     mp = STLParser()
     mp.parse(os.path.join(resources_path, 'data', 'pelvis_male_236mm.stl'))
     nodes_start = mp.getPoints(pared=True)
     elements = mp.getElements(zero_based=False, pared=True)
     mp.parse(os.path.join(resources_path, 'data', 'pelvis_male_324mm.stl'))
     nodes_end = mp.getPoints(pared=True)
     createMeshTime(self._male_coordinate_field, nodes_start, 236, nodes_end, 324, elements)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def testParse2(self):
        v = STLParser()
        test_filename = os.path.join(file_path, 'data/ship.zip')
        self.assertTrue(v.canParse(test_filename))
        v.parse(test_filename)

        self.assertEqual(828, len(v.getElements()))
Ejemplo n.º 7
0
    def testParse3(self):
        v = STLParser()
        test_filename = os.path.join(file_path, 'data/pelvis.stl')
        self.assertTrue(v.canParse(test_filename))
        v.parse(test_filename)

        self.assertEqual(52272, len(v.getElements()))
Ejemplo n.º 8
0
 def testDuplicatedPoints(self):
     v = STLParser()
     v.parse(os.path.join(file_path, 'data/ship.stl'))
     self.assertEqual(2484, len(v.getPoints()))
     np = NodePare()
     np.addPoints(v.getPoints())
     np.parePoints()
     self.assertEqual(575, len(np.getParedPoints()))
Ejemplo n.º 9
0
    def testConvert(self):
        v = STLParser()
        v.parse('data/pelvis_minimal.stl')
        nodes = v.getPoints(pared=True)
        self.assertEqual(13, len(nodes))
        elements = v.getElements(zero_based=False, pared=True)
        self.assertEquals([1, 4, 2], elements[1])
        mesh = {'nodes': nodes, 'elements': elements}

        convert(mesh, define_faces=True)
Ejemplo n.º 10
0
    def testParse1(self):
        v = STLParser()
        v.parse(os.path.join(file_path, 'data/ship.stl'))

        self.assertEqual(828, len(v.getElements()))
Ejemplo n.º 11
0
 def testExistence(self):
     v = STLParser()
     self.assertRaises(IOError, v.parse, 'file that doesnt exist')
Ejemplo n.º 12
0
 def testZeroBased(self):
     v = STLParser()
     v.parse('data/pelvis_minimal.stl')
     self.assertEqual(33, len(v.getPoints()))
     elements = v.getElements(zero_based=False)
     self.assertEquals([4, 5, 6], elements[1])
Ejemplo n.º 13
0
    def testParse4(self):
        v = STLParser()
        v.parse('data/pelvis.zip')        

        self.assertEqual(52272, len(v.getElements())) 
Ejemplo n.º 14
0
 def testParedZeroBased(self):
     v = STLParser()
     v.parse(os.path.join(file_path, 'data/pelvis_minimal.stl'))
     self.assertEqual(33, len(v.getPoints()))
     elements = v.getElements(zero_based=False, pared=True)
     self.assertEquals([1, 4, 2], elements[1])
Ejemplo n.º 15
0
 def testParedZeroBased(self):
     v = STLParser()
     v.parse('data/pelvis_minimal.stl')
     self.assertEqual(33, len(v.getPoints()))
     elements = v.getElements(zero_based=False, pared=True)
     self.assertEquals([1, 4, 2], elements[1])
Ejemplo n.º 16
0
 def testPared(self):
     v = STLParser()
     v.parse('data/pelvis_minimal.stl')
     self.assertEqual(13, len(v.getPoints(pared=True)))
     elements = v.getElements(pared=True)
     self.assertEquals([0, 3, 1], elements[1])
Ejemplo n.º 17
0
    def testParse4(self):
        v = STLParser()
        v.parse(os.path.join(file_path, 'data/pelvis.zip'))

        self.assertEqual(52272, len(v.getElements()))
Ejemplo n.º 18
0
    def testParse2(self):
        v = STLParser()
        v.parse('data/ship.zip')

        self.assertEqual(828, len(v.getElements()))
Ejemplo n.º 19
0
 def testPared(self):
     v = STLParser()
     v.parse(os.path.join(file_path, 'data/pelvis_minimal.stl'))
     self.assertEqual(13, len(v.getPoints(pared=True)))
     elements = v.getElements(pared=True)
     self.assertEquals([0, 3, 1], elements[1])
Ejemplo n.º 20
0
    def testParse4(self):
        v = STLParser()
        v.parse('data/pelvis.zip')

        self.assertEqual(52272, len(v.getElements()))
Ejemplo n.º 21
0
 def testFailingModelInVersion000400(self):
     v = STLParser()
     v.parse(os.path.join(file_path, 'data/amazing_alveoli_minimal.stl'))
     self.assertEqual(310188, len(v.getPoints()))
     elements = v.getElements(zero_based=False, pared=True)
     self.assertEquals([4, 1, 3], elements[1])
Ejemplo n.º 22
0
    def testParse2(self):
        v = STLParser()
        v.parse('data/ship.zip')        

        self.assertEqual(828, len(v.getElements()))