コード例 #1
0
    def test_obj_geometry_02(self):
        """tests the ascii shuttle model"""
        log = get_logger(level='warning', encoding='utf-8')
        obj_filename = os.path.join(model_path, 'shuttle.obj')
        obj_filename2 = os.path.join(model_path, 'shuttle2.obj')

        model = read_obj(obj_filename, log=log)
        model.write_obj(obj_filename2)
        model2 = read_obj(obj_filename2, log=log)
        os.remove(obj_filename2)
コード例 #2
0
    def load_obj_geometry(self, obj_filename, name='main', plot=True):
        """
        The entry point for OBJ geometry loading.

        Parameters
        ----------
        obj_filename : str
            the obj filename to load
        name : str
            the name of the "main" actor for the GUI
        plot : bool; default=True
            should the model be generated or should we wait until
            after the results are loaded
        """
        skip_reading = self._remove_old_obj_geometry(obj_filename)
        if skip_reading:
            return

        log = self.gui.log
        self.gui.eid_maps[name] = {}
        self.gui.nid_maps[name] = {}
        model = read_obj(obj_filename, log=log, debug=False)
        self.model_type = 'obj'
        nodes = model.nodes
        nelements = model.nelements

        self.gui.nnodes = model.nnodes
        self.gui.nelements = nelements

        grid = self.gui.grid
        grid.Allocate(self.gui.nelements, 1000)

        assert nodes is not None
        #nnodes = nodes.shape[0]

        mmax = nodes.max(axis=0)
        mmin = nodes.min(axis=0)
        dim_max = (mmax - mmin).max()
        xmax, ymax, zmax = mmax
        xmin, ymin, zmin = mmin
        log.info("xmin=%s xmax=%s dx=%s" % (xmin, xmax, xmax - xmin))
        log.info("ymin=%s ymax=%s dy=%s" % (ymin, ymax, ymax - ymin))
        log.info("zmin=%s zmax=%s dz=%s" % (zmin, zmax, zmax - zmin))
        self.gui.create_global_axes(dim_max)
        points = numpy_to_vtk_points(nodes)

        #assert elements.min() == 0, elements.min()

        tri_etype = 5  # vtkTriangle().GetCellType()
        #self.create_vtk_cells_of_constant_element_type(grid, elements, etype)
        quad_etype = 9  # vtk.vtkQuad().GetCellType()

        tris = model.tri_faces
        quads = model.quad_faces
        if len(tris):
            for eid, element in enumerate(tris):
                elem = vtk.vtkTriangle()
                elem.GetPointIds().SetId(0, element[0])
                elem.GetPointIds().SetId(1, element[1])
                elem.GetPointIds().SetId(2, element[2])
                grid.InsertNextCell(tri_etype, elem.GetPointIds())
        if len(quads):
            for eid, element in enumerate(quads):
                elem = vtk.vtkQuad()
                elem.GetPointIds().SetId(0, element[0])
                elem.GetPointIds().SetId(1, element[1])
                elem.GetPointIds().SetId(2, element[2])
                elem.GetPointIds().SetId(3, element[3])
                grid.InsertNextCell(quad_etype, elem.GetPointIds())

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):  # pragma: no cover
            grid.Update()

        self.gui.scalar_bar_actor.VisibilityOn()
        self.gui.scalar_bar_actor.Modified()

        self.gui.isubcase_name_map = {1: ['OBJ', '']}
        cases = OrderedDict()
        ID = 1
        form, cases, icase, node_ids, element_ids = self._fill_obj_geometry_objects(
            cases, ID, nodes, nelements, model)
        self.gui.node_ids = node_ids
        self.gui.element_ids = element_ids
        self.gui._finish_results_io2(form, cases)