Ejemplo n.º 1
0
def hacher_diffuseur(volume, surface, coupe_2, coupe_1="coordx=65", retourner_normal_plan=False):
    """teste sur DIFFUSEUR RADIAL seulement
    fonction qui retourne un plan perpendiculaire a surface, generalement celle de l'aubage
    
    coupe_1 et coupe_2 sont les Extractions effectuees pour trouver le point sur surface
        qui servira de centre pour le plan
        typiquement coupe_1 = "coordx=65", coupe_2 = "coordr=158"
    
    la normale au plan est alors determinee par un produit scalaire entre 
        le vecteur iHat du repere et le vecteur normal a la surface en ce point
    
    surface est converti en polydata si besoin
    """
    surface = convertir_en_polydata(surface, calculer_vecteur_normal = True)
    
    ligne = Extraction(input = surface, formule_extraction = coupe_1).get_output()
    point = Extraction(input = ligne, formule_extraction = coupe_2,
        ).get_output()
    if point.GetNumberOfPoints() == 0:
        raise IOError, "impossible de trouver le point central du plan"
    normal = get_vtk_array_as_numpy_array(input = point, nom_array = 'Normals')[0, :]
    coords = get_vtk_array_as_numpy_array(input = point, nom_array = 'coords')[0, :]
    
    normal_plan = numpy.cross([1, 0, 0], normal)
    
    plan = vtk.vtkPlane()
    plan.SetOrigin(coords)
    plan.SetNormal(normal_plan)
    
    coupe = vtk.vtkCutter()
    coupe.SetCutFunction(plan)
    
    if not isinstance(volume, vtk.vtkMultiBlockDataSet):
        coupe.SetInput(volume)
        coupe.Update()
        output = coupe.GetOutput()
    else:
        output = appliquer_sur_multibloc(coupe, volume)
    
    if retourner_normal_plan:
        return output, normal_plan
    else:
        return output
Ejemplo n.º 2
0
def trouver_col(volume, bloc_aubage, nb_aubes, coupe="coordx=65", formule_extraction_surface_aubage="j=jmin"):
    """POUR DIFFUSEUR RADIAL SEULEMENT - extension a programmer
    fonction qui retourne un plan correspondant au col
    
    
    nb_aubes est le nombre d'aubes correspondant 
    a la grille consideree. Ce nombre est utilise pour determiner la position
    de l'aube voisine.
    
    coupe est la coupe a effectuer pour obtenir un profil 2d a partir du 3d
    et determiner la ligne du col, support du plan au col
    """
    surface = Extraction(input = bloc_aubage, 
        formule_extraction = formule_extraction_surface_aubage,
        calculer_vecteur_normal = 1).get_output()
    
    ligne = Extraction(input = surface, formule_extraction = coupe).get_output()
    coords = get_vtk_array_as_numpy_array(input = ligne, nom_array = 'coords')
    coordr = numpy.sqrt(coords[:, 1] ** 2 + coords[:, 2] ** 2)
    
    coords_ba = coords[numpy.argmin(coordr), :]
    angle_rotation = 2 * numpy.pi / nb_aubes
    coords_ba = [
        coords_ba[0], 
        coords_ba[1] * numpy.cos(angle_rotation) - coords_ba[2] * numpy.sin(angle_rotation), 
        coords_ba[2] * numpy.cos(angle_rotation) + coords_ba[1] * numpy.sin(angle_rotation)
        ]
    dist_ba = numpy.sqrt(numpy.sum((coords - coords_ba) ** 2, axis = 1))
    
    coords_col = coords[dist_ba.argmin(), :]
    vect_col = coords_ba - coords_col
    normal = numpy.cross([1, 0, 0], vect_col) / numpy.linalg.norm(vect_col)
    
    plan = vtk.vtkPlane()
    plan.SetOrigin(coords_ba)
    plan.SetNormal(normal)
    
    coupe = vtk.vtkCutter()
    coupe.SetCutFunction(plan)
    
    volume_duplique = dupliquer_canal(volume, angle_rotation * 180. / numpy.pi)
    
    plan = appliquer_sur_multibloc(coupe, volume_duplique)
    
    plan = merge_multibloc(plan)
    
    coords = get_vtk_array_as_numpy_array(plan, 'coords')
    #calcul pour exclure les exterieurs du plan, et ne garder que le col
    data = numpy.dot(coords[:, 1:] - coords_col[1:], 
        vect_col[1:]) / numpy.linalg.norm(vect_col) ** 2
    data = numpy_support.numpy_to_vtk(data, deep = 1)
    data.SetName("dist")
    plan.GetPointData().AddArray(data)
    
    plan = set_scalaires_actifs(plan, "dist")
    
    select = vtk.vtkThreshold()
    select.SetInput(plan)
    select.ThresholdBetween(1e-6, 1 - 1e-6)
    select.Update()
    col = select.GetOutput()
    return col