본문 바로가기
STL/stl - plot하기 (pyvista)

pyvista 자료형인 PolyData 에서 사용가능한 메소드들

by 만다린망고 2021. 11. 8.
반응형

pyvista에서 stl을 생성하거나, point cloud를 생성하거나, stl 을 불러올 때 사용하는 메소드는 pv.PolyData 입니다. PolyData에서 사용가능한 메소드들을 살펴봅시다. 

먼저 PolyData 를 하나 생성하였습니다. 

import numpy as np
import pyvista as pv

# mesh points
vertices = np.array([[0, 0, 0],
                     [1, 0, 0],
                     [1, 1, 0],
                     [0, 1, 0],
                     [0.5, 0.5, -1]])

# mesh faces
faces = np.hstack([[4, 0, 1, 2, 3],  # square
                   [3, 0, 1, 4],     # triangle
                   [3, 1, 2, 4]])    # triangle

mesh = pv.PolyData(vertices, faces)

 

dir 함수를 이용하여 사용 가능한 메소드를 확인해봅시다.

>>> dir(mesh) 
['ALL_PIECES_EXTENT', 'AddCellReference', 'AddObserver', 'AddReferenceToCell', 'Allocate', 'AllocateCellGhostArray', 'AllocateCopy', 'AllocateEstimate', 'AllocateExact', 
'AllocatePointGhostArray', 'AllocateProportional', 'AttributeTypes', 'BOUNDING_BOX', 
'BreakOnError', 'BuildCellLocator', 'BuildCells', 'BuildLinks', 'BuildLocator', 'BuildPointLocator', 'CELL', 'CELL_DATA_FIELD', 'CELL_DATA_VECTOR', 'CheckAttributes', 'ComputeBounds', 'CopyAttributes', 'CopyCells', 'CopyInformationFromPipeline', 'CopyInformationToPipeline', 'CopyStructure', 'Crop', 'DATA_EXTENT', 'DATA_EXTENT_TYPE', 'DATA_NUMBER_OF_GHOST_LEVELS', 'DATA_NUMBER_OF_PIECES', 'DATA_OBJECT', 'DATA_OBJECT_FIELD', 'DATA_PIECE_NUMBER', 'DATA_TIME_STEP', 'DATA_TYPE_NAME', 'DIRECTION', 'DataHasBeenGenerated', 'DebugOff', 'DebugOn', 'DeepCopy', 'DeleteCell', 'DeleteCells', 'DeleteLinks', 'DeletePoint', 'EDGE', 'EDGE_DATA_VECTOR', 'ERR_INCORRECT_FIELD', 'ERR_NON_MANIFOLD_STAR', 'ERR_NO_SUCH_FIELD', 'EditableOff', 'EditableOn', 'FIELD', 'FIELD_ACTIVE_ATTRIBUTE', 'FIELD_ARRAY_TYPE', 'FIELD_ASSOCIATION', 'FIELD_ASSOCIATION_CELLS', 'FIELD_ASSOCIATION_EDGES', 'FIELD_ASSOCIATION_NONE', 'FIELD_ASSOCIATION_POINTS', 'FIELD_ASSOCIATION_POINTS_THEN_CELLS', 'FIELD_ASSOCIATION_ROWS', 'FIELD_ASSOCIATION_VERTICES', 
'FIELD_ATTRIBUTE_TYPE', 'FIELD_NAME', 'FIELD_NUMBER_OF_COMPONENTS', 'FIELD_NUMBER_OF_TUPLES', 'FIELD_OPERATION', 'FIELD_OPERATION_MODIFIED', 'FIELD_OPERATION_PRESERVED', 
'FIELD_OPERATION_REINTERPOLATED', 'FIELD_OPERATION_REMOVED', 'FIELD_RANGE', 'FastDelete', 'FieldAssociations', 'FieldDataType', 'FieldOperations', 'FindAndGetCell', 'FindCell', 'FindPoint', 'GenerateGhostArray', 'GetActiveFieldInformation', 'GetActualMemorySize', 'GetAddressAsString', 'GetAssociationTypeAsString', 'GetAssociationTypeFromString', 'GetAttributeTypeForArray', 'GetAttributes', 'GetAttributesAsFieldData', 'GetBounds', 'GetCell', 'GetCellBounds', 'GetCellData', 'GetCellEdgeNeighbors', 'GetCellGhostArray', 'GetCellLocator', 'GetCellNeighbors', 'GetCellPoints', 'GetCellType', 'GetCellTypes', 'GetCenter', 'GetClassName', 'GetCommand', 'GetData', 'GetDataObjectType', 'GetDataReleased', 'GetDebug', 'GetEditable', 'GetExtentType', 'GetFieldData', 'GetGhostArray', 'GetGhostLevel', 'GetGlobalReleaseDataFlag', 'GetGlobalWarningDisplay', 'GetInformation', 'GetLength', 'GetLines', 'GetMTime', 'GetMaxCellSize', 'GetMeshMTime', 'GetNamedFieldInformation', 'GetNumberOfCells', 'GetNumberOfElements', 'GetNumberOfGenerationsFromBase', 'GetNumberOfGenerationsFromBaseType', 'GetNumberOfLines', 'GetNumberOfPieces', 'GetNumberOfPoints', 'GetNumberOfPolys', 'GetNumberOfStrips', 'GetNumberOfVerts', 'GetPiece', 'GetPoint', 'GetPointCells', 'GetPointData', 'GetPointGhostArray', 'GetPointLocator', 'GetPoints', 'GetPolys', 'GetReferenceCount', 'GetScalarFieldCriticalIndex', 'GetScalarRange', 'GetStrips', 'GetUpdateTime', 'GetVerts', 'GlobalReleaseDataFlagOff', 'GlobalReleaseDataFlagOn', 'GlobalWarningDisplayOff', 'GlobalWarningDisplayOn', 'HasAnyBlankCells', 'HasAnyBlankPoints', 'HasAnyGhostCells', 'HasAnyGhostPoints', 'HasObserver', 'Initialize', 'InitializeObjectBase', 'InsertNextCell', 'InsertNextLinkedCell', 'InsertNextLinkedPoint', 'InvokeEvent', 'IsA', 'IsEdge', 'IsPointUsedByCell', 'IsTriangle', 'IsTypeOf', 'MAXIMUM', 'MINIMUM', 'Modified', 'NUMBER_OF_ASSOCIATIONS', 'NUMBER_OF_ATTRIBUTE_TYPES', 'NeedToBuildCells', 'NewCellIterator', 'NewInstance', 'ORIGIN', 'PIECE_EXTENT', 'POINT', 'POINT_DATA_FIELD', 'POINT_DATA_VECTOR', 'POINT_THEN_CELL', 'PrepareForNewData', 'REGULAR_POINT', 'ROW', 'Register', 
'ReleaseData', 'RemoveAllObservers', 'RemoveCellReference', 'RemoveDeletedCells', 'RemoveGhostCells', 'RemoveNamedFieldInformation', 'RemoveObserver', 'RemoveObservers', 
'RemoveReferenceToCell', 'ReplaceCell', 'ReplaceCellPoint', 'ReplaceLinkedCell', 'Reset', 'ResizeCellList', 'ReverseCell', 'SADDLE', 'SIL', 'SPACING', 'SafeDownCast', 'SetActiveAttribute', 'SetActiveAttributeInfo', 'SetCellLocator', 'SetCellOrderAndRationalWeights', 'SetDebug', 'SetEditable', 'SetFieldData', 'SetGlobalReleaseDataFlag', 'SetGlobalWarningDisplay', 'SetInformation', 'SetLines', 'SetPointDataActiveScalarInfo', 'SetPointLocator', 'SetPoints', 'SetPolys', 'SetReferenceCount', 'SetStrips', 'SetVerts', 'ShallowCopy', 'Squeeze', 'UnRegister', 'UpdateCellGhostArrayCache', 'UpdatePointGhostArrayCache', 'VERTEX', 'VERTEX_DATA_VECTOR', '_WRITERS', '__add__', '__annotations__', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__setstate__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__this__', '__vtkname__', '__weakref__', '_activate_texture', '_active_scalars_info', '_active_tensors_info', '_active_vectors_info', '_boolean', '_clip_with_function', '_connectivity_array', '_from_file', '_get_attrs', '_ipython_key_completions_', '_last_active_scalars_name', '_make_vertex_cells', '_offset_array', '_post_file_load_processing', '_repr_html_', '_textures', 'active_normals', 'active_scalars', 
'active_scalars_info', 'active_scalars_name', 'active_t_coords', 'active_tensors', 'active_tensors_info', 'active_tensors_name', 'active_vectors', 'active_vectors_info', 
'active_vectors_name', 'actual_memory_size', 'add_field_array', 'add_field_data', 'area', 'array_names', 'arrows', 'association_bitarray_names', 'boolean_add', 'boolean_cut', 'boolean_difference', 'boolean_intersection', 'boolean_union', 'bounds', 'cast_to_unstructured_grid', 'cell_arrays', 'cell_bounds', 'cell_centers', 'cell_data', 'cell_data_to_point_data', 'cell_n_points', 'cell_normals', 'cell_points', 'cell_type', 'center', 'center_of_mass', 'clean', 'clear_arrays', 'clear_cell_arrays', 'clear_cell_data', 'clear_data', 'clear_field_arrays', 'clear_field_data', 'clear_point_arrays', 
'clear_point_data', 'clear_textures', 'clip', 'clip_box', 'clip_closed_surface', 'clip_scalar', 'clip_surface', 'collision', 'compute_arc_length', 'compute_cell_quality', 'compute_cell_sizes', 'compute_derivative', 'compute_implicit_distance', 'compute_normals', 'connectivity', 'contour', 'copy', 'copy_attributes', 'copy_meta_from', 'copy_structure', 'ctp', 'curvature', 'decimate', 'decimate_boundary', 'decimate_pro', 'deep_copy', 'delaunay_2d', 'delaunay_3d', 'edge_mask', 'elevation', 'extent', 'extract_all_edges', 'extract_cells', 'extract_feature_edges', 'extract_geometry', 'extract_largest', 'extract_points', 'extract_surface', 'extrude', 'extrude_rotate', 'face_normals', 'faces', 'field_arrays', 'field_data', 'fill_holes', 'find_closest_cell', 'find_closest_point', 'flip_normal', 'flip_normals', 'flip_x', 'flip_y', 'flip_z', 'geodesic', 'geodesic_distance', 'get_array', 'get_array_association', 'get_data_range', 'glyph', 'head', 'interpolate', 'intersection', 'is_all_triangles', 'length', 'lines', 'memory_address', 'merge', 'multi_ray_trace', 'n_arrays', 'n_cells', 'n_faces', 'n_lines', 'n_open_edges', 'n_points', 'n_verts', 'number_of_cells', 'number_of_faces', 'number_of_points', 'obbTree', 'outline', 'outline_corners', 'overwrite', 'plot', 'plot_boundaries', 'plot_curvature', 'plot_normals', 'plot_over_circular_arc', 'plot_over_circular_arc_normal', 'plot_over_line', 'point_arrays', 'point_data', 'point_data_to_cell_data', 'point_normals', 'points', 'points_to_double', 'probe', 'project_points_to_plane', 'ptc', 'ray_trace', 'reconstruct_surface', 'reflect', 'remove_cells', 'remove_points', 'rename_array', 'ribbon', 'rotate_vector', 'rotate_x', 'rotate_y', 'rotate_z', 'sample', 'sample_over_circular_arc', 'sample_over_circular_arc_normal', 'sample_over_line', 'save', 'scale', 'select_enclosed_points', 'set_active_scalars', 'set_active_tensors', 'set_active_vectors', 'shallow_copy', 'shrink', 'slice', 'slice_along_axis', 'slice_along_line', 'slice_orthogonal', 'smooth', 'split_bodies', 'streamlines', 'streamlines_evenly_spaced_2D', 'streamlines_from_source', 'strip', 'subdivide', 'subdivide_adaptive', 'surface_indices', 't_coords', 'texture_map_to_plane', 'texture_map_to_sphere', 'textures', 'threshold', 'threshold_percent', 'transform', 'translate', 'triangulate', 'tube', 'vectors', 'verts', 'volume', 'warp_by_scalar', 'warp_by_vector']


자주 쓸만한 메소드는 아래와 같습니다. 

points : vertices 출력
face_normals : face의 법선벡터

n_points : 점의 수

n_cells : 셀의 수(face 수)


transform : transform 하기

transform 예시

>>> transform_matrix = np.array([[1, 0, 0, 50],
...                              [0, 1, 0, 100],
...                              [0, 0, 1, 200],
...                              [0, 0, 0, 1]])
>>> transformed = mesh.transform(transform_matrix)

 

cell_points : 각 셀(face)를 구성하는 점 출력

 

cell_points 예시

   >>> mesh.cell_points(0)  # doctest:+SKIP
    [[896.99401855  48.76010132  82.26560211]
     [906.59301758  48.76010132  80.74520111]
     [907.53900146  55.49020004  83.65809631]]

 

반응형

댓글