Example #1
0
def vtk_mc_test():

    #set_trace()
    dicesize = 16.
    exname = "udice_vec"  # "blend_example2"
    import example_objects
    iobj = example_objects.make_example_vectorized(exname, dicesize)
    (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-22, +20., 0.8)

    from example_objects import cyl4
    iobj, (RANGE_MIN, RANGE_MAX, STEPSIZE) = cyl4()

    from stl_tests import make_mc_values_grid
    numpy_array = make_mc_values_grid(iobj,
                                      RANGE_MIN,
                                      RANGE_MAX,
                                      STEPSIZE,
                                      old=False)
    gridvals = numpy_array

    #gridvals = make_npy_file_dice()
    verts, faces = vtk_mc(gridvals, (RANGE_MIN, RANGE_MAX, STEPSIZE))
    print("MC calculated")
    sys.stdout.flush()

    from mesh_utils import mesh_invariant
    mesh_invariant(faces)

    #from stl_tests import make_mc_mesh_scikit
    #verts, faces = make_mc_mesh_scikit(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE)

    display_simple_using_mayavi_vf1(verts, faces)
def prepare():
    ifunc, (RANGE_MIN, RANGE_MAX, STEPSIZE) = getifunc()

    from stl_tests import make_mc_values_grid
    gridvals = make_mc_values_grid(ifunc,
                                   RANGE_MIN,
                                   RANGE_MAX,
                                   STEPSIZE,
                                   old=False)
    verts, facets = vtk_mc(gridvals, (RANGE_MIN, RANGE_MAX, STEPSIZE))
    return verts, facets
Example #3
0
def make_npy_file_dice():
    dicesize = 16.
    exname = "udice_vec"  # "blend_example2"
    import example_objects
    iobj = example_objects.make_example_vectorized(exname, dicesize)

    from stl_tests import make_mc_values_grid
    (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-22, +20., 0.8)
    #Caution: The only place in which old=True #fixme #todo
    assert False, "Caution: The only place in which old=True. Use old=False or the new form"
    numpy_array = make_mc_values_grid(iobj,
                                      RANGE_MIN,
                                      RANGE_MAX,
                                      STEPSIZE,
                                      old=True)
    return numpy_array
Example #4
0
#             un = c
#         else:
#             un = vectorized.CrispUnion(un, c)
#     return un

#print ifunc

from stl_tests import make_mc_values_grid
from vtk_mc import vtk_mc

#ifunc, (RANGE_MIN, RANGE_MAX, STEPSIZE) = getifunc()

from stl_tests import make_mc_values_grid
gridvals = make_mc_values_grid(ifunc,
                               RANGE_MIN,
                               RANGE_MAX,
                               STEPSIZE,
                               old=False)
print np.sum(gridvals.ravel() < 0)
#exit()
verts, facets = vtk_mc(gridvals, (RANGE_MIN, RANGE_MAX, STEPSIZE))
#return verts, facets

#print verts
#print facets
#exit()

display_simple_using_mayavi_2([
    (verts, facets),
],
                              pointcloud_list=[],
    def check_meshs(self, iobj, objname=None):

        """Do the algorithm and then do the test"""
        if iobj is not None:
            (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.2)
            curvature_epsilon = 1. / 1000.
            VERTEX_RELAXATION_ITERATIONS_COUNT = 1
            SUBDIVISION_ITERATIONS_COUNT = 1

            if objname == "cyl4":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32 / 2, +32 / 2, 1.92 / 4.0)

            elif objname == "french_fries" or objname == "rods":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.11)  # 0.05

            elif objname == "bowl_15_holes":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.15)

            elif objname == "cyl3":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32 / 2, +32 / 2, 1.92 / 4.0)

            elif objname == "cyl1":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-16, +32, 1.92 * 0.2 * 10 / 2.0)

            from stl_tests import make_mc_values_grid
            gridvals = make_mc_values_grid(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE, old=False)
            vertex, faces = vtk_mc(gridvals, (RANGE_MIN, RANGE_MAX, STEPSIZE))
            sys.stderr.write("MC calculated.")
            sys.stdout.flush()

            from ohtake_belyaev_demo_subdivision_projection_qem import process2_vertex_resampling_relaxation
            from ohtake_belyaev_demo_subdivision_projection_qem import compute_average_edge_length, set_centers_on_surface__ohtake_v3s
            from ohtake_belyaev_demo_subdivision_projection_qem import compute_centroid_gradients, vertices_apply_qem3, do_subdivision

            for i in range(VERTEX_RELAXATION_ITERATIONS_COUNT):
                vertex, faces_not_used, centroids = process2_vertex_resampling_relaxation(vertex, faces, iobj)
                assert not np.any(np.isnan(vertex.ravel()))  # fails
                sys.stderr.write("Vertex relaxation applied.")
                sys.stdout.flush()

            average_edge = compute_average_edge_length(vertex, faces)

            old_centroids = np.mean(vertex[faces[:], :], axis=1)

            new_centroids = old_centroids.copy()

            set_centers_on_surface__ohtake_v3s(iobj, new_centroids, average_edge)

            # neighbour_faces_of_vertex
            vertex_neighbours_list = mesh_utils.make_neighbour_faces_of_vertex(faces)
            centroid_gradients = compute_centroid_gradients(new_centroids, iobj)

            new_vertex_qem = \
                vertices_apply_qem3(vertex, faces, new_centroids, vertex_neighbours_list, centroid_gradients)

            for i in range(SUBDIVISION_ITERATIONS_COUNT):

                print "subdivision:"
                vertex, facets = do_subdivision(new_vertex_qem, faces, iobj, curvature_epsilon)
                global trace_subdivided_facets  # third implicit output

                print "subdivision done."

            """Testing the mesh correctness"""
            check_mesh(facets)
def demo_combination_plus_qem():
    """ Now with QEM """
    curvature_epsilon = 1. / 1000.  # a>eps  1/a > 1/eps = 2000
    # curvature_epsilon = 1. / 10000.
    VERTEX_RELAXATION_ITERATIONS_COUNT = 0
    SUBDIVISION_ITERATIONS_COUNT = 0  # 2  # 5+4

    from example_objects import make_example_vectorized
    object_name = "cube_with_cylinders"  # "sphere_example" #or "rcube_vec" work well #"ell_example1"#"cube_with_cylinders"#"ell_example1"  " #"rdice_vec" #"cube_example"
    iobj = make_example_vectorized(object_name)

    (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.2)
    if object_name == "cube_with_cylinders" or object_name == "twist_object" or object_name == "french_fries" or object_name == "rdice_vec" or object_name == "rods" or object_name == "bowl_15_holes":
        VERTEX_RELAXATION_ITERATIONS_COUNT = 1

    if object_name == "cyl4":
        (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32 / 2, +32 / 2, 1.92 / 4.0)

    elif object_name == "french_fries" or object_name == "rods":
        (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.11)  # 0.05

    elif object_name == "bowl_15_holes":
        (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.15)

    elif object_name == "cyl3":
        (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32 / 2, +32 / 2, 1.92 / 4.0)

    elif object_name == "cyl1":
        (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-16, +32, 1.92 * 0.2 * 10 / 2.0)

    from stl_tests import make_mc_values_grid
    gridvals = make_mc_values_grid(iobj,
                                   RANGE_MIN,
                                   RANGE_MAX,
                                   STEPSIZE,
                                   old=False)
    verts, facets = vtk_mc(gridvals, (RANGE_MIN, RANGE_MAX, STEPSIZE))
    print("MC calculated.")
    sys.stdout.flush()

    # display_simple_using_mayavi_2([(verts, facets), ],
    #    pointcloud_list=[],
    #    mayavi_wireframe=[False], opacity=[1], gradients_at=None, separate=False, gradients_from_iobj=None,
    #    minmax=(RANGE_MIN, RANGE_MAX))
    # exit()

    for i in range(VERTEX_RELAXATION_ITERATIONS_COUNT):
        verts, facets_not_used, centroids = process2_vertex_resampling_relaxation(
            verts, facets, iobj)
        assert not np.any(np.isnan(verts.ravel()))  # fails
        print("Vertex relaxation applied.")
        sys.stdout.flush()

    average_edge = compute_average_edge_length(verts, facets)

    old_centroids = np.mean(verts[facets[:], :], axis=1)

    new_centroids = old_centroids.copy()

    set_centers_on_surface__ohtake_v3s_002(iobj, new_centroids, average_edge)

    # neighbour_faces_of_vertex
    vertex_neighbours_list = mesh_utils.make_neighbour_faces_of_vertex(facets)
    centroid_gradients = compute_centroid_gradients(new_centroids, iobj)

    new_verts_qem = \
        vertices_apply_qem3(verts, facets, new_centroids, vertex_neighbours_list, centroid_gradients)

    verts_before_qem = verts

    highlighted_vertices = np.array([131, 71, 132])  # np.arange(100, 200)
    hv = new_verts_qem[highlighted_vertices, :]

    total_subdivided_facets = []
    for i in range(SUBDIVISION_ITERATIONS_COUNT):
        e_array, which_facets = compute_facets_subdivision_curvatures(
            new_verts_qem, facets, iobj, curvature_epsilon)

        # which_facets = np.arange(facets.shape[0])[e_array > curvature_epsilon]
        print "Curvature epsilon:", curvature_epsilon, "which facets need to be subdivided", which_facets.shape

        verts4_subdivided, facets3_subdivided = subdivide_multiple_facets(
            new_verts_qem, facets, which_facets)
        global trace_subdivided_facets  # third implicit output

        verts, facets = verts4_subdivided, facets3_subdivided
        print("Subdivision applied.")
        sys.stdout.flush()
        # total_subdivided_facets += trace_subdivided_facets  # old face indices remain valid

        # new_verts_qem_alpha = (new_verts_qem * alpha + verts * (1-alpha))

        highlighted_vertices = np.array([131, 71, 132])  # np.arange(100, 200)
        hv = verts[highlighted_vertices, :]

    chosen_facet_indices = np.array(total_subdivided_facets, dtype=int)

    # move the following code into subdivide_multiple_facets() (?)
    if chosen_facet_indices.size == 0:
        chosen_subset_of_facets = np.zeros((0, ), dtype=int)
    else:
        chosen_subset_of_facets = facets[chosen_facet_indices, :]

    # display_simple_using_mayavi_2([(new_verts_final, facets), (new_verts_qem, facets), ],
    #    pointcloud_list=[hv], pointcloud_opacity=0.2,
    #    mayavi_wireframe=[False, True], opacity=[0.2, 0.5, 0.9], gradients_at=None, separate=False, gradients_from_iobj=None,
    #    minmax=(RANGE_MIN, RANGE_MAX))
    # exit()
    #
    display_simple_using_mayavi_2([
        (verts_before_qem, facets),
        (new_verts_qem, facets),
    ],
                                  pointcloud_list=[hv],
                                  pointcloud_opacity=0.2,
                                  mayavi_wireframe=[False, False],
                                  opacity=[0.4 * 0, 1, 0.9],
                                  gradients_at=None,
                                  separate=False,
                                  gradients_from_iobj=None,
                                  minmax=(RANGE_MIN, RANGE_MAX))
    def check_centroids_projection(self, iobj, objname=None):
        TOLERANCE = 0.00001
        # TOLERANCE = 0.7 to pass the test for every object
        """Do the centroids projection """
        if iobj is not None:
            VERTEX_RELAXATION_ITERATIONS_COUNT = 0
            (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.2)
            if objname == "cube_with_cylinders" or objname == "twist_object" or objname == "french_fries" or objname == "rdice_vec" or objname == "rods" or objname == "bowl_15_holes":
                VERTEX_RELAXATION_ITERATIONS_COUNT = 1

            if objname == "cyl4":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32 / 2, +32 / 2, 1.92 / 4.0)

            elif objname == "french_fries" or objname == "rods":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.11)  # 0.05

            elif objname == "bowl_15_holes":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-3, +5, 0.15)

            elif objname == "cyl3":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-32 / 2, +32 / 2, 1.92 / 4.0)

            elif objname == "cyl1":
                (RANGE_MIN, RANGE_MAX, STEPSIZE) = (-16, +32, 1.92 * 0.2 * 10 / 2.0)

            from stl_tests import make_mc_values_grid
            gridvals = make_mc_values_grid(iobj, RANGE_MIN, RANGE_MAX, STEPSIZE, old=False)
            vertex, faces = vtk_mc(gridvals, (RANGE_MIN, RANGE_MAX, STEPSIZE))
            sys.stderr.write("MC calculated.")
            sys.stdout.flush()

            from ohtake_belyaev_demo_subdivision_projection_qem import process2_vertex_resampling_relaxation, compute_average_edge_length, set_centers_on_surface__ohtake_v3s

            from ohtake_belyaev_demo_subdivision_projection_qem import compute_centroid_gradients, vertices_apply_qem3

            for i in range(VERTEX_RELAXATION_ITERATIONS_COUNT):
                vertex, faces_not_used, centroids = process2_vertex_resampling_relaxation(vertex, faces, iobj)
            assert not np.any(np.isnan(vertex.ravel()))  # fails
            sys.stderr.write("Vertex relaxation applied.")
            sys.stdout.flush()

            # projection
            average_edge = compute_average_edge_length(vertex, faces)

            old_centroids = np.mean(vertex[faces[:], :], axis=1)
            check_vector3_vectorized(old_centroids)

            new_centroids = old_centroids.copy()

            set_centers_on_surface__ohtake_v3s(iobj, new_centroids, average_edge)

            vertex_neighbours_list = mesh_utils.make_neighbour_faces_of_vertex(faces)
            centroid_gradients = compute_centroid_gradients(new_centroids, iobj)

            new_vertex_qem = \
                vertices_apply_qem3(vertex, faces, new_centroids, vertex_neighbours_list, centroid_gradients)

            check_vector3_vectorized(new_vertex_qem)
            # checking if the projection is correct by calling the implicitFunction
            f = iobj.implicitFunction(new_vertex_qem)

            # Two ways of doing this test, in the first one we strictly consider that the test fail if one value is superior
            # to the tolerance and in the second we print the numbere of point who fail the test

            Number_of_point_who_fail = True

            if Number_of_point_who_fail is True:
                fail = 0
                for i in range(new_vertex_qem.shape[0]):
                    if math.fabs(f[i]) > TOLERANCE:
                        fail += 1
                print objname, "Number of points:", new_centroids.shape[0], "Number of points who fails the test:", fail

            else:
                for i in range(new_vertex_qem.shape[0]):
                    print "Fail the test", math.fabs(f[i])
                    self.assertTrue(math.fabs(f[i]) < TOLERANCE)