Exemplo n.º 1
0
    def test_3d_open(self):
        self.start()

        v3d_file = None
        try:

            with gxv.View_3d.new('test_3d', overwrite=True) as v:
                v3d_file = v.map.file_name
                with gxg.Draw(v, '2D stuff') as g:
                    draw_2d_stuff(g)

            self.assertRaises(gxv.ViewException, gxv.View_3d.open, 'bogus')

            with gxv.View_3d.open(v3d_file) as v:
                v.new_drawing_plane('vertical', rotation=(90.0, 0, 0))
                with gxg.Draw(v, '2D stuff vertical', plane='vertical') as g:
                    g.rectangle(v.extent_clip)
                    draw_2d_stuff(g)

                with gxg.Draw_3d(v, '3D stuff') as g:
                    g.box_3d(((20, 10, -10), (80, 50, 30)),
                             pen=g.new_pen(line_color='R255G100B50'))

            self.crc_map(v3d_file)

        finally:
            if v3d_file:
                gxmap.delete_files(v3d_file)
Exemplo n.º 2
0
    def test_draw_surface_3d(self):

        verts = np.array([[0, 0, 0],
                          [5, 0, 0],
                          [5, 5, 0],
                          [0, 3, 5],
                          [2.5, 2, 10],
                          [-3, 6, 8],
                          [-4, 0, 12]], dtype=np.float64)
        faces = np.array([[0, 1, 2],
                          [0, 2, 3],
                          [3, 2, 4],
                          [1, 2, 4],
                          [3, 4, 5],
                          [6, 4, 5]], dtype=np.int32)

        with gxv.View_3d.new() as v3d:
            v3d_file = v3d.file_name
            with gxg.Draw_3d(v3d, 'Surface') as g:
                verts = verts[faces].reshape(-1, 3)
                vx, vy, vz = gxvv.vvset_from_np(verts)
                vf1, vf2, vf3 = gxvv.vvset_from_np(faces)
                normals = gxg.vertex_normals_np(faces, verts)
                nx, ny, nz = gxvv.vvset_from_np(normals[faces].reshape(-1, 3))

                # using a constant color does not complain
                v3d.gxview.draw_surface_3d_ex('test',
                                              vx.gxvv, vy.gxvv, vz.gxvv,
                                              nx.gxvv, ny.gxvv, nz.gxvv,
                                              gxapi.GXVV.null(), gxg.C_GREY,
                                              vf1.gxvv, vf2.gxvv, vf3.gxvv,
                                              v3d.coordinate_system.gxipj)

                # using an array color raises invalid number of colour if we pass colours/vertex
                color = np.array([gxg.C_GREY for i in range(vx.length)])
                color_vv = gxvv.GXvv(color, dtype=np.int32)
                try:
                    v3d.gxview.draw_surface_3d_ex('test2',
                                                  vx.gxvv, vy.gxvv, vz.gxvv,
                                                  nx.gxvv, ny.gxvv, nz.gxvv,
                                                  color_vv.gxvv, gxg.C_GREY,
                                                  vf1.gxvv, vf2.gxvv, vf3.gxvv,
                                                  v3d.coordinate_system.gxipj)

                except gxapi.GXAPIError as e:
                    print(str(e))

                    # and if pass colours/face it asserts
                    color = np.array([gxg.C_GREY for i in range(faces.shape[0])])
                    color_vv = gxvv.GXvv(color, dtype=np.int32)
                    v3d.gxview.draw_surface_3d_ex('test2',
                                                  vx.gxvv, vy.gxvv, vz.gxvv,
                                                  nx.gxvv, ny.gxvv, nz.gxvv,
                                                  color_vv.gxvv, gxg.C_GREY,
                                                  vf1.gxvv, vf2.gxvv, vf3.gxvv,
                                                  v3d.coordinate_system.gxipj)
Exemplo n.º 3
0
    def test_3dview(self):
        self.start()

        v3d_file = None

        try:

            with gxv.View_3d.new('test_3d', overwrite=True) as v:
                v3d_file = v.file_name
                self.assertTrue(v3d_file.lower().endswith('.geosoft_3dv'))
                self.assertEqual(v.name, 'test_3d')
                self.assertEqual(v.map.name, 'test_3d')

                with gxg.Draw(v, '2D stuff') as g:
                    draw_2d_stuff(g)

                v.new_drawing_plane('plane_0')
                self.assertEqual(v.current_3d_drawing_plane, 'plane_0')
                self.assertRaises(gxv.ViewException, v.new_drawing_plane,
                                  'plane_0')

                v.new_drawing_plane('vertical', rotation=(90.0, 0, 0))
                self.assertEqual(v.current_3d_drawing_plane, 'vertical')
                with gxg.Draw(v, '2D stuff vertical', plane='vertical') as g:
                    g.rectangle(v.extent_clip)
                    draw_2d_stuff(g)

                with gxg.Draw_3d(v, '3D stuff') as g:
                    g.box_3d(((20, 10, -10), (80, 50, 30)),
                             pen=g.new_pen(line_color='R255G100B50'))

                self.assertTrue('Plane' in v.plane_list)
                self.assertTrue('plane_0' in v.plane_list)
                self.assertTrue('vertical' in v.plane_list)
                self.assertEqual(v.plane_number('Plane'), 0)
                self.assertEqual(v.plane_name('vertical'), 'vertical')
                self.assertEqual(v.plane_name(2), 'vertical')
                self.assertRaises(gxv.ViewException, v.plane_number, 'bogus')
                self.assertRaises(gxv.ViewException, v.plane_number, -1)
                self.assertRaises(gxv.ViewException, v.plane_name, 3)
                self.assertRaises(gxv.ViewException, v.plane_name, 'bogus')
                self.assertEqual(v.get_class_name('Plane'), 'vertical')

            self.crc_map(v3d_file)

        finally:
            if v3d_file:
                gxmap.delete_files(v3d_file)
Exemplo n.º 4
0
def t3():
    verts = np.array([[0, 0, 0],
                      [5, 0, 0],
                      [5, 5, 0],
                      [0, 3, 5],
                      [2.5, 2, 10],
                      [-3, 6, 8],
                      [-4, 0, 12]], dtype=np.float64)
    faces = np.array([[0, 1, 2],
                      [0, 2, 3],
                      [3, 2, 4],
                      [1, 2, 4],
                      [3, 4, 5],
                      [6, 4, 5]], dtype=np.int32)

    with gxview.View_3d.new() as v3d:
        v3d_file = v3d.file_name
        with gxgrp.Draw_3d(v3d, 'Surface') as g:
            g.surface(faces, verts)
    image_file = gxmap.Map.open(v3d_file).image_file(pix_width=800)
    pass
Exemplo n.º 5
0
    def test_3d_map(self):
        self.start()

        v3d_file = None
        map_file = None
        try:

            with gxmap.Map.new() as map:
                map_file = map.file_name
                with gxv.View.open(map, '*base') as v:
                    with gxg.Draw(v, 'edge') as g:
                        g.rectangle(v.extent_clip)

            with gxv.View_3d.new('test_3d', overwrite=True) as v:
                v3d_file = v.map.file_name
                with gxg.Draw(v, '2D stuff') as g:
                    draw_2d_stuff(g)
                v.new_drawing_plane('vertical', rotation=(90.0, 0, 0))
                with gxg.Draw(v, '2D stuff vertical', plane='vertical') as g:
                    g.rectangle(v.extent_clip)
                    draw_2d_stuff(g)

                with gxg.Draw_3d(v, '3D stuff') as g:
                    g.box_3d(((20, 10, -10), (80, 50, 30)),
                             pen=g.new_pen(line_color='R255G100B50'))

                with gxmap.Map.open(map_file) as map:
                    map.create_linked_3d_view(v, 'linked_view')

            self.crc_map(map_file)

        finally:
            if v3d_file:
                gxmap.delete_files(v3d_file)
            if map_file:
                gxmap.delete_files(map_file)
Exemplo n.º 6
0
import geosoft.gxpy.view as gxv
import geosoft.gxpy.group as gxg
import geosoft.gxpy.vv as gxvv

gxc = gx.GXpy()

verts = np.array([[0, 0, 0], [5, 0, 0], [5, 5, 0], [0, 3, 5], [2.5, 2, 10],
                  [-3, 6, 8], [-4, 0, 12]],
                 dtype=np.float64)
faces = np.array(
    [[0, 1, 2], [0, 2, 3], [3, 2, 4], [1, 2, 4], [3, 4, 5], [6, 4, 5]],
    dtype=np.int32)

with gxv.View_3d.new() as v3d:
    v3d_file = v3d.file_name
    with gxg.Draw_3d(v3d, 'Surface') as g:
        verts = verts[faces].reshape(-1, 3)
        vx, vy, vz = gxvv.vvset_from_np(verts)
        vf1, vf2, vf3 = gxvv.vvset_from_np(faces)
        normals = gxg.vertex_normals_np(faces, verts)
        nx, ny, nz = gxvv.vvset_from_np(normals[faces].reshape(-1, 3))

        # using a constant color does not complain
        v3d.gxview.draw_surface_3d_ex('test', vx.gxvv, vy.gxvv, vz.gxvv,
                                      nx.gxvv, ny.gxvv, nz.gxvv,
                                      gxapi.GXVV.null(), gxg.C_GREY, vf1.gxvv,
                                      vf2.gxvv, vf3.gxvv,
                                      v3d.coordinate_system.gxipj)

        # using an array color raises invalid number of colour if we pass colours/vertex
        color = np.array([gxg.C_GREY for i in range(vx.length)])