Use the properties of Python VTK implicit functions to select and cut data
2022-01-31 18:15:24 【Pie Da Da Xing】
This is my participation 11 The fourth of the yuegengwen challenge 15 God , Check out the activity details ：2021 One last more challenge
VTK,（visualizationtoolkit） It is a free software system with open resources , Mainly used in 3D computer graphics 、 Image processing and visualization .Vtk It is designed and implemented on the basis of object-oriented principle , Its kernel uses C++ Built , Contains about 250,000 Line code ,2000 Multiple classes , There are also several conversion interfaces , So it's free to pass Java,Tcl/Tk and Python Use of various languages vtk.
This paper mainly introduces how to use the properties of implicit functions to select and cut data , In particular, how to use the area separation attribute to select data .
Using implicit functions to select or extract data means selecting cells and points located in a specific area of the function （ And related attribute data ）. To determine the point x-y-z Whether it is located in an area , We just need to calculate the point and check the coordinate symbol of the result . If all points of the cell are in the region , Then the unit is located in this area . here , Two ellipses are used in combination to select voxels in the volume dataset . Be careful , Extracting data usually changes the structure of the data set . In this case , The input type is image dataset , The output type is unstructured grid dataset .
Main function introduction
vtkQuadricClustering Is a class for cutting triangles , Get an approximate Geometry . Its input is vtkPolyData Data of type , Can handle all types of polygonal meshes , Its speed is very fast . It can quickly cut large mesh models , And supports mesh clip reduction （ utilize startAppend, Append, endAppend Method ）, This avoids loading the entire model into memory . For large network models , It has good effect , But when the grid gets smaller , The triangulation effect is not very good , It needs to be combined with other methods .
vtk.vtkSampleFunction yes VTK An implicit function in represents a class , It can be used to sample the surface point by point at equal intervals .
vtkShrinkFilter Shrink the cells that make up any dataset of its centroid . The average position of cell points is used as the centroid of the calculation unit . Atrophy interrupts the result of another cell . The output of this filter is a generic dataset type vtkUnstructuredGrid.
import vtk def main(): colors = vtk.vtkNamedColors() ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) quadric = vtk.vtkQuadric() quadric.SetCoefficients(0.5, 1, 0.2, 0, 0.1, 0, 0, 0.2, 0, 0) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(50, 50, 50) sample.SetImplicitFunction(quadric) sample.ComputeNormalsOff() trans = vtk.vtkTransform() trans.Scale(1, 0.5, 0.333) sphere = vtk.vtkSphere() sphere.SetRadius(0.25) sphere.SetTransform(trans) trans2 = vtk.vtkTransform() trans2.Scale(0.25, 0.5, 1.0) sphere2 = vtk.vtkSphere() sphere2.SetRadius(0.25) sphere2.SetTransform(trans2) booleanUnion = vtk.vtkImplicitBoolean() booleanUnion.AddFunction(sphere) booleanUnion.AddFunction(sphere2) booleanUnion.SetOperationType(0) # boolean Union extract = vtk.vtkExtractGeometry() extract.SetInputConnection(sample.GetOutputPort()) extract.SetImplicitFunction(booleanUnion) shrink = vtk.vtkShrinkFilter() shrink.SetInputConnection(extract.GetOutputPort()) shrink.SetShrinkFactor(0.5) dataMapper = vtk.vtkDataSetMapper() dataMapper.SetInputConnection(shrink.GetOutputPort()) dataActor = vtk.vtkActor() dataActor.SetMapper(dataMapper) # outline outline = vtk.vtkOutlineFilter() outline.SetInputConnection(sample.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(0, 0, 0) # take actor Add to window , And set the size of the relevant window # ren1.AddActor(outlineActor) ren1.AddActor(dataActor) ren1.SetBackground(colors.GetColor3d("SlateGray")) renWin.SetWindowName('ExtractData') renWin.Render() ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(30) renWin.Render() iren.Start() if __name__ == '__main__': main() Copy code
give the result as follows ：
author[Pie Da Da Xing],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Python - convert Matplotlib image to numpy Array or PIL Image
- Python and Java crawl personal blog information and export it to excel
- Using class decorators in Python
- Untested Python code is not far from crashing
- Python efficient derivation (8)
- Python requests Library
- leetcode 2047. Number of Valid Words in a Sentence（python）
- leetcode 2027. Minimum Moves to Convert String（python）
- How IOS developers learn Python Programming 5 - data types 2
- leetcode 1971. Find if Path Exists in Graph（python）
guess what you like
leetcode 1984. Minimum Difference Between Highest and Lowest of K Scores（python）
Python interface automation test framework (basic) -- basic syntax
Detailed explanation of Python derivation
Python reptile lesson 2-9 Chinese monster database. It is found that there is a classification of color (he) desire (Xie) monsters during operation
A brief note on the method of creating Python virtual environment in Intranet Environment
[worth collecting] for Python beginners, sort out the common errors of beginners + Python Mini applet! (code attached)
[Python souvenir book] two people in one room have three meals and four seasons: 'how many years is it only XX years away from a hundred years of good marriage' ~?? Just come in and have a look.
The unknown side of Python functions
Python based interface automation test project, complete actual project, with source code sharing
A python artifact handles automatic chart color matching
- Python crawls the map of Gaode and the weather conditions of each city
- leetcode 1275. Find Winner on a Tic Tac Toe Game（python）
- leetcode 2016. Maximum Difference Between Increasing Elements（python）
- Run through Python date and time processing (Part 2)
- Application of urllib package in Python
- Django API Version (II)
- Python utility module playsound
- Database addition, deletion, modification and query of Python Sqlalchemy basic operation
- Tiobe November programming language ranking: Python surpasses C language to become the first! PHP is about to fall out of the top ten?
- Learn how to use opencv and python to realize face recognition!
- Using OpenCV and python to identify credit card numbers
- Principle of Python Apriori algorithm (11)
- Python AI steals your voice in 5 seconds
- A glance at Python's file processing (Part 1)
- Python cloud cat
- Python crawler actual combat, pyecharts module, python data analysis tells you which goods are popular on free fish~
- Using pandas to implement SQL group_ concat
- How IOS developers learn Python Programming 8 - set type 3
- windows10+apache2. 4 + Django deployment
- Django parser
- leetcode 1560. Most Visited Sector in a Circular Track（python）
- leetcode 1995. Count Special Quadruplets（python）
- How to program based on interfaces using Python
- leetcode 1286. Iterator for Combination（python）
- leetcode 1418. Display Table of Food Orders in a Restaurant （python）
- Python Matplotlib drawing histogram
- Python development foundation summary (VII) database + FTP + character coding + source code security
- Python modular package management and import mechanism
- Django serialization (II)
- Python dataloader error "dataloader worker (PID XXX) is killed by signal" solution
- apache2. 4 + Django + windows 10 Automated Deployment
- leetcode 1222. Queens That Can Attack the King（python）
- leetcode 1387. Sort Integers by The Power Value （python）
- Tiger sniffing 24-hour praise device, a case with a crawler skill, python crawler lesson 7-9
- Python object oriented programming 01: introduction classes and objects
- Baidu Post: high definition Python
- Python Matplotlib drawing contour map
- Python crawler actual combat, requests module, python realizes IMDB movie top data visualization
- Python classic: explain programming and development from simple to deep and step by step
- Python implements URL availability monitoring and instant push