Example #1
0
def test_proj_ohtak1():
    """ Tests projection of centroids using Ohtake's original method. Projects point-wise.
    Repeats points by applying a small perturbation.
    Blend disc object.
    Uses a high resolution MC for checking the new projected points (black dots).
    The original centroids are shon in red.
    The failed projections are shown in Yello. Their number is writtn in output (9 points)"""

    from stl_tests import make_mc_mesh_scikit

    exname = "blend_example2_discs"  # "blend_example2"
    import example_objects
    iobj = example_objects.make_example_vectorized(exname, 8.0)

    #(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-2.*8, +4.*8, 0.4*8/5)
    (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-16, +32, 0.64*3*2/2)
    verts, faces = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE)

    print verts.shape, faces.shape

    average_edge = STEPSIZE

    # verts = optimise_mesh(verts, faces, iobj)

    c3 = np.mean(verts[faces[:], :], axis=1)
    # add extra points
    c3 = np.concatenate((c3, c3+STEPSIZE*0.1, c3+STEPSIZE*(-0.1)), axis=0)
    c3 = np.concatenate((c3,), axis=0)
    centroids = np.concatenate((c3, np.ones((c3.shape[0], 1))), axis=1)


    new_centroids = centroids.copy()
    set_centers_on_surface__ohtake(iobj, new_centroids, average_edge)

    print
    #print np.arange(nones_map.shape[0])[np.logical_not(nones_map)].shape
    print np.sum(np.logical_not(nones_map)), "(success)  + ", np.sum(nones_map), " (failed)"
    new_centroids2 = new_centroids[np.logical_not(nones_map), :]

    #todo: Use "None" for non-converging ones. (and visualise them)

    #(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-16, +32, 0.64*3*2/2)
    #verts2, faces2 = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE * 0.2/2.0) #15 million!
    verts2, faces2 = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE * 0.2)


    #m = m2stl_mesh(verts, faces)
    #if ACTUALLY_SAVE:
    #    m.save('implicit6-blend.stl')  # wow

    centroids_failed = centroids[nones_map, :]  #green ones

    #display_simple_using_mayavi_([(verts, faces), (verts2, faces2)], [centroids, new_centroids2], minmax=(RANGE_MIN, RANGE_MAX))
    #display_simple_using_mayavi_([(verts, faces), (verts2, faces2)], [centroids, new_centroids2, centroids_failed], minmax=(RANGE_MIN, RANGE_MAX))
    #display_simple_using_mayavi_([(verts, faces), (verts2, faces2)], [centroids_failed, new_centroids2], minmax=(RANGE_MIN, RANGE_MAX))
    #best:
    #display_simple_using_mayavi_([(verts, faces), (verts2, faces2)], [centroids, new_centroids], minmax=(RANGE_MIN, RANGE_MAX))
    display_simple_using_mayavi_([(verts, faces), (verts2, faces2)], [centroids, new_centroids, centroids_failed], minmax=(RANGE_MIN, RANGE_MAX))
Example #2
0
    def load_example(self, example_name="ell_example1", res=1):
        """
            res: controls step size of mc grid
            example_name: name of example to build, available names can be
            found in the file example_objects
        """
        print "[Start] Loading example:  %s" % example_name + ' ...'
        from example_objects import make_example_vectorized
        from stl_tests import make_mc_mesh_scikit
        exname = example_name
        self.iobj = make_example_vectorized(exname)
        self.register_function(self.iobj.implicitFunction)
        self.register_gradient(self.iobj.implicitGradient)

        (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-2., 2., 0.1 / res)  # non-spiky!!

        self.vertices, self.faces = make_mc_mesh_scikit(
            self.iobj, RANGE_MIN, RANGE_MAX, STEPSIZE)
        self.centroids = np.mean(self.vertices[self.faces[:], :], axis=1)
        self.centroids = np.c_[self.centroids,
                               np.ones((len(self.centroids), 1))]
        self.triangles = self.vertices[self.faces]
        self.build_neighbours()
        self.name = exname
        self.lamda = calc_avg_triangle_length(self.triangles) / 2
        print "[End] Loading example:  %s" % example_name + ' .'
Example #3
0
def test_profiler():
    #use for profiling only
    exname = "blend_example2_discs"  # "blend_example2"
    import example_objects
    iobj = example_objects.make_example_vectorized(exname, 8.0)
    (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-16, +32, 0.64*3*2/2)
    verts, faces = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE)
    print verts.shape, faces.shape
    average_edge = STEPSIZE
    c3 = np.mean(verts[faces[:], :], axis=1)
    c3 = np.concatenate( (c3,c3+STEPSIZE*0.1,c3+STEPSIZE*(-0.1)), axis=0)
    centroids = np.concatenate((c3, np.ones((c3.shape[0], 1))), axis=1)
    nones_map = centroids[:,0]*0 > 100
    new_centroids = centroids.copy()
    set_centers_on_surface__ohtake(iobj, new_centroids, average_edge, nones_map)
    new_centroids2 = new_centroids[np.logical_not(nones_map),:]
    verts2, faces2 = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE * 0.2/1.0)
Example #4
0
def cyl_test_example1():

    print("started")
    sys.stdout.flush()


    # c = cyl1()
    #(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-16, +32, 1.92 * 0.2 * 10/ 2.0)

    #c, (RANGE_MIN, RANGE_MAX, STEPSIZE) = cyl2()
    ##(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32, +32, 1.92 / 4.0*1.5/ 1.5)
    # #takes 15 sec!

    c, (RANGE_MIN, RANGE_MAX, STEPSIZE) = cyl3()
    ##(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32, +32, 1.92 / 4.0)   #15 sec!  2.5 millions voxels
    #(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32/2, +32/2, 1.92 / 4.0)  # 2.5 sec!

    # spiral cage
    #c, (RANGE_MIN, RANGE_MAX, STEPSIZE) = cyl4()
    #(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32/2, +32/2, 1.92 / 4.0)

    c, dims = cyl4()
    (RANGE_MIN, RANGE_MAX, STEPSIZE) = dims

    print("made the function")
    sys.stdout.flush()

    from stl_tests import make_mc_mesh_scikit
    with Timer() as t:
        # @profile
        verts, faces = make_mc_mesh_scikit(c, RANGE_MIN, RANGE_MAX, STEPSIZE)
    print("made MC : done within ", t.interval)  # takes 15 sec!!
    sys.stdout.flush()

    ACTUALLY_SAVE = False
    #from stl_tests import optimise_mesh
    #verts = optimise_mesh(verts, faces, c)
    #Does not work yet
    from stl_tests import m2stl_mesh
    m = m2stl_mesh(verts, faces)
    if ACTUALLY_SAVE:
        m.save('stl/cage.stl')  # wow

    from mesh_utils import mesh_invariant
    mesh_invariant(faces)

    from ohtake_surface_projection import display_simple_using_mayavi_

    print("mayavi start")
    sys.stdout.flush()

    display_simple_using_mayavi_([(verts, faces), ], [], minmax=(RANGE_MIN, RANGE_MAX))

    print("mayavi done")
    sys.stdout.flush()
Example #5
0
def test_search1():
    import math
    from stl_tests import make_mc_mesh_scikit

    dicesize = 8.
    exname = "udice_vec"
    import example_objects
    iobj = example_objects.make_example_vectorized(exname, dicesize)

    (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-11, +10., 0.8)  # non-spiky!!
    verts, faces = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE)

    verts = my_process_1(verts, faces, iobj)

    from stl_tests import display_simple_using_mayavi_vf1
    display_simple_using_mayavi_vf1(verts, faces)
    print(np.min(verts.ravel()), np.max(verts.ravel()))

    plot_stlmesh(m)
Example #6
0
def test_proj_ohtak2():

    from stl_tests import make_mc_mesh_scikit

    exname = "french_fries_vectorized"
    import example_objects
    iobj = example_objects.make_example_vectorized(exname, 8.0)

    #(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-2.*8, +4.*8, 0.4*8/5)
    #(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-16, +32, 0.64*3*2/2)
    (RANGE_MIN, RANGE_MAX,
     STEPSIZE) = (-2 * 8, +4 * 8, 0.64 * 3 * 2 / 2 / 4. * 8 * 0.2
                  )  # / 8.   #0.768
    #STEPSIZE2 = STEPSIZE * 0.2
    STEPSIZE, STEPSIZE2 = (1.5, 0.384)

    verts, faces = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE)

    print verts.shape, faces.shape

    average_edge = STEPSIZE

    # verts = optimise_mesh(verts, faces, iobj)

    c3_0 = np.mean(verts[faces[:], :], axis=1)
    # add extra points
    offsets = [0]
    print c3_0.shape
    #offsets = [0,+0.1,-0.1]
    #c3 = np.concatenate((c3, c3+STEPSIZE*0.1, c3+STEPSIZE*(-0.1)), axis=0)
    c3 = np.zeros((0, 3))
    for x in offsets:
        c3 = np.concatenate((
            c3,
            c3_0 + STEPSIZE * x,
        ), axis=0)
    #c3 = np.concatenate((c3,), axis=0)
    centroids = np.concatenate((c3, np.ones((c3.shape[0], 1))), axis=1)

    nones_map = centroids[:, 0] * 0 > 100
    new_centroids = centroids.copy()

    set_centers_on_surface__ohtake(iobj, new_centroids, average_edge,
                                   nones_map)

    print
    #print np.arange(nones_map.shape[0])[np.logical_not(nones_map)].shape
    print np.sum(np.logical_not(nones_map)), "(success)  + ", np.sum(
        nones_map), " (failed)"
    new_centroids2 = new_centroids[np.logical_not(nones_map), :]

    #todo: Use "None" for non-converging ones. (and visualise them)

    if False:
        #(RANGE_MIN, RANGE_MAX, STEPSIZE) = (-16, +32, 0.64*3*2/2)
        #verts2, faces2 = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE * 0.2/2.0) #15 million!
        verts2, faces2 = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX,
                                             STEPSIZE2)
    verts2, faces2 = None, None

    #m = m2stl_mesh(verts, faces)
    #if ACTUALLY_SAVE:
    #    m.save('implicit6-blend.stl')  # wow

    centroids_failed = centroids[nones_map, :]  #green ones

    #display_simple_using_mayavi_([(verts, faces), (verts2, faces2)], [centroids, new_centroids2], minmax=(RANGE_MIN, RANGE_MAX))
    #display_simple_using_mayavi_([(verts, faces), (verts2, faces2)], [centroids, new_centroids2, centroids_failed], minmax=(RANGE_MIN, RANGE_MAX))
    #display_simple_using_mayavi_([(verts, faces), (verts2, faces2)], [centroids_failed, new_centroids2], minmax=(RANGE_MIN, RANGE_MAX))
    #best:
    #display_simple_using_mayavi_([(verts, faces), (verts2, faces2)], [centroids, new_centroids], minmax=(RANGE_MIN, RANGE_MAX))
    display_simple_using_mayavi_([(verts, faces), (verts2, faces2)],
                                 [centroids, new_centroids, centroids_failed],
                                 minmax=(RANGE_MIN, RANGE_MAX))