Esempio n. 1
0
    def orient(self):
        """
        Orient this SimplicialMesh. If the  manifold is of the same dimension as the
        embedding (e.g. triangle mesh in 2D, tet mesh in 3D) then the resultant mesh
        will be oriented so that the simplices have positive volume.
        
        If the mesh is not orientable an Exception is raised.
        """

        
        if self.manifold_dimension() == 0:
            #0-dimensional manifold is alway oriented
            return
        
        if self.manifold_dimension() == self.embedding_dimension():
            #orient w/ positive volumes
            num_flips = 0
            elements = self['elements']
            vertices = self['vertices']
            
            for row in elements:
                pts = vertices[row]
                if signed_volume(pts) < 0:
                    num_flips += 1
                    temp = row[0]
                    row[0] = row[1]
                    row[1] = temp
            print("Flipped",num_flips,"simplices")
            return

        raise NotImplementedError
    
        simplex_to_index = {}
        for index,row in enumerate(self['elements']):
            simplex_to_index[simplex(row)] = index
        
        faces = self.skeleton(self.manifold_dimension() - 1)
        face_to_simplex = dict.fromkeys(faces,set())
        for simplex,index in simplex_to_index.keys():
            for b in simplex.boundary():
                face_to_simplex[b].add(index)
            
        simplex_neigbors = [[]]*len(self['elements'])
        for simplex,index in simplex_to_index.keys():            
            for b in simplex.boundary():
                simplex_neigbors[index].append(face_to_simplex[b] - set([index]))
        
        print(simplex_neighbors)
Esempio n. 2
0
    def orient(self):
        """
        Orient this SimplicialMesh. If the  manifold is of the same dimension as the
        embedding (e.g. triangle mesh in 2D, tet mesh in 3D) then the resultant mesh
        will be oriented so that the simplices have positive volume.
        
        If the mesh is not orientable an Exception is raised.
        """

        
        if self.manifold_dimension() == 0:
            #0-dimensional manifold is alway oriented
            return
        
        if self.manifold_dimension() == self.embedding_dimension():
            #orient w/ positive volumes
            num_flips = 0
            elements = self['elements']
            vertices = self['vertices']
            
            for row in elements:
                pts = vertices[row]
                if signed_volume(pts) < 0:
                    num_flips += 1
                    temp = row[0]
                    row[0] = row[1]
                    row[1] = temp
            print "Flipped",num_flips,"simplices"
            return

        raise NotImplementedError
    
        simplex_to_index = {}
        for index,row in enumerate(self['elements']):
            simplex_to_index[simplex(row)] = index
        
        faces = self.skeleton(self.manifold_dimension() - 1)
        face_to_simplex = dict.fromkeys(faces,set())
        for simplex,index in simplex_to_index.iterkeys():
            for b in simplex.boundary():
                face_to_simplex[b].add(index)
            
        simplex_neigbors = [[]]*len(self['elements'])
        for simplex,index in simplex_to_index.iterkeys():            
            for b in simplex.boundary():
                simplex_neigbors[index].append(face_to_simplex[b] - set([index]))
        
        print simplex_neighbors
Esempio n. 3
0
    def compute_primal_volume(self,dim):
        """Compute the volume of all simplices for a given dimension

        If the top simplex is of the same dimension as its embedding,
        the signed volume is computed.        
        """
        data = self[dim]
        data.primal_volume = zeros((data.num_simplices,))

        if dim == self.embedding_dimension():
            for i,s in enumerate(self.simplices):
                pts = self.vertices[s,:]            
                data.primal_volume[i] = signed_volume(pts)
        else:

            for i,s in enumerate(data.simplices):
                pts = self.vertices[s,:]            
                data.primal_volume[i] = unsigned_volume(pts)