Exemple #1
0
    def _get_opc(self, vertices, faces, triverts):
        """Calculates and returns OPC, list of patches, and list of polygons sorted into color bins by XY aspect."""
        self.vnormal, self.fnormal = normcore.computenormal(vertices, faces, triverts, self.vert_tri_dict)
        
        flatfaces = array([i for i, norm in enumerate(self.fnormal) if (norm[0:1] == 0).all()], dtype=int)
        orientation_map = array([self._xydegrees(norm[1],norm[0]) for norm in self.fnormal])
    
        color_map = array([self._sort_to_colors(aspect_theta) for aspect_theta in orientation_map])
        color_map[flatfaces] = '#000000'
            
        pairdict = defaultdict(list) #lists per vertex all possible pairs of polygons that include that vertex 
        for vertex, faces in self.vert_tri_dict.iteritems():
            pairdict[vertex] = self._pair_faces(faces)
            
        adjacent_face_pairs = self._adjacent_face_pairs(pairdict)    
        
        same_color_pairs = [pair for pair in adjacent_face_pairs if color_map[pair[0]] == color_map[pair[1]]]
        
        color_face_dict = defaultdict(list) # lists adjacent polygon pairs for each color bin
        for item in same_color_pairs:
            color_face_dict[color_map[item[0]]].append(item)
         
        colorlist = ['#FF0000','#964B00','#FFFF00','#00FFFF','#0000FF','#90EE90','#014421','#FFC0CB']
            
        patches = [self._build_patches(color_face_dict[color]) for color in colorlist]

        patches = [self._cull_small_patches(subpat,self.min_patch_size) for subpat in patches]
        
        opc = sum([len(subpat) for subpat in patches])
           
        return [opc, patches, color_map]               
Exemple #2
0
    def calcdne(self):
        """Method for calculating surface Dirichlet normal energy and populating instance variables."""
        # creation of dictionary of vertex keys and face values     
        self._get_vert_tri_dict()
        
        # optional implicit smooth of mesh
        if self.dosmooth == 1:
            self.Mesh = pcopy(self.Mesh)
            self.Mesh.vertices = implicitfair.smooth(self.Mesh.vertices, self.Mesh.faces, int(self.smoothit), float(self.smoothstep), self.vert_tri_dict)
            if self.Mesh.vertices == "!":
                print "Cholesky error"
                return "!"    

        # creation of array of vertices per edge
        self._get_edge_verts()
        # list of boundary faces
        self._get_boundary_faces()
        
        # arrays of normalized face normals and vertex normals approximated from adjacent faces
        self.vnormal, self.fnormal = normcore.computenormal(self.Mesh.vertices, self.Mesh.faces, self.Mesh.triverts, self.vert_tri_dict)
        # array of e(p) and face area for polygons across mesh
        
        self._energize_surface()
        
        self._sumdne()
 def test_computenormal(self):
     varray = array([[0.0, 0.0, 0.0],
                     [2.0, 0.0, 0.0],
                     [0.0, 2.0, 0.0],
                     [2.0, 2.0, 0.0],
                     [1.0, 1.0, 2.0]])
     farray = array([[0, 1, 2],
                     [1, 3, 2],
                     [0, 1, 4],
                     [1, 3, 4],
                     [2, 0, 4],
                     [3, 2, 4]])
     
     fvarray = [varray[verts] for verts in farray]
     
     vfarray = {0: [0, 2, 4], 1: [0, 1, 2, 3], 2: [0, 1, 4, 5], 3: [1, 3, 5], 4: [2, 3, 4, 5]}
     
     solution_normals = [array([[-0.3926533 , -0.3926533 ,  0.83165304],
                                [ 0.28315849, -0.28315849,  0.91632011],
                                [-0.28315849,  0.28315849,  0.91632011],
                                [ 0.3926533 ,  0.3926533 ,  0.83165304],
                                [ 0.0       ,  0.0       ,  1.0       ]]), 
                         array([[ 0.0       ,  0.0       ,  1.0       ],
                                [ 0.0       ,  0.0       ,  1.0       ],
                                [ 0.0       , -0.89442719,  0.4472136 ],
                                [ 0.89442719,  0.0       ,  0.4472136 ],
                                [-0.89442719,  0.0       ,  0.4472136 ],
                                [ 0.0       ,  0.89442719,  0.4472136 ]])]
     
     test_normals = normcore.computenormal(varray, farray, fvarray, vfarray)
     
     self.assertTrue(allclose(test_normals[0], solution_normals[0]), msg = "Approximated vertex normals not calculated as expected from reference pyramid mesh.")
     self.assertTrue(allclose(test_normals[1], solution_normals[1]), msg = "Polygon face normals not calculated as expected from reference pyramid mesh.")