Summary of the invention
The three-dimensional pipeline Real-time modeling set method and system based on GPU high-performance calculation that the object of the present invention is to provide a kind of,
It aims to solve the problem that in the prior art for performance bottleneck problem existing for the three-dimensional visualization of magnanimity pipeline data, realizes lift line
Three-dimensional visualization performance accelerates the modeling work of magnanimity pipeline data, lift scheme fineness and modeling speed.
To reach above-mentioned technical purpose, the present invention provides a kind of three-dimensional pipelines based on GPU high-performance calculation to build in real time
Mould method, the described method comprises the following steps:
S1, the coordinate range for obtaining workspace count all pipe point datas in coordinate range;
S2, the pipe point data and pipeline model isodisperse are transmitted to GPU by CPU, pipe point data is stored to complete
Office's memory, pipeline model isodisperse is stored to constant memory;
Thread block number, Thread Count and dimension in S3, setting GPU, execute kernel function, execute one by per thread
The section vertex coordinates data of pipeline section generates;
S4, using vertex buffer object pattern, the pipeline model in workspace is rendered by OpenGL;
S5, when workspace coordinate range change when, repaint the pipeline model in work at present area coordinate range.
Preferably, the coordinate range concrete operations for obtaining workspace are that workspace screen coordinate is converted into the world to sit
Mark, and then obtain coordinate range.
Preferably, the section vertex coordinates data of the pipeline model is stored into the global storage of GPU.
The present invention also provides a kind of three-dimensional pipeline Real-time modeling set system based on GPU high-performance calculation, the system packet
It includes:
Workspace pipe point statistical module counts all pipe points in coordinate range for obtaining the coordinate range of workspace
Data;
Data transmission module will be managed for the pipe point data and pipeline model isodisperse to be transmitted to GPU by CPU
Point data is stored to global storage, and pipeline model isodisperse is stored to constant memory;
Model vertices computing module executes kernel function, leads to for thread block number, Thread Count and dimension in GPU to be arranged
Cross the section vertex coordinates data generation that per thread executes a root canal section;
Model rendering module, for utilizing vertex buffer object pattern, by OpenGL to the pipeline mould in workspace
Type is rendered;
Model refresh module, for repainting work at present area coordinate range when the change of the coordinate range of workspace
Interior pipeline model.
Preferably, the coordinate range of the workspace is obtained by the way that workspace screen coordinate is converted into world coordinates.
Preferably, the section vertex coordinates data of pipeline model is stored into the global storage of GPU.
Specific embodiment
In order to clearly illustrate the technical characterstic of this programme, below by specific embodiment, and its attached drawing is combined, to this
Invention is described in detail.Following disclosure provides many different embodiments or example is used to realize different knots of the invention
Structure.In order to simplify disclosure of the invention, hereinafter the component of specific examples and setting are described.In addition, the present invention can be with
Repeat reference numerals and/or letter in different examples.This repetition is that for purposes of simplicity and clarity, itself is not indicated
Relationship between various embodiments and/or setting is discussed.It should be noted that illustrated component is not necessarily to scale in the accompanying drawings
It draws.Present invention omits the descriptions to known assemblies and treatment technology and process to avoid the present invention is unnecessarily limiting.
It is real-time that it is provided for the embodiments of the invention a kind of three-dimensional pipeline based on GPU high-performance calculation with reference to the accompanying drawing
Modeling method and system are described in detail.
As shown in Figure 1, the embodiment of the invention discloses a kind of three-dimensional pipeline Real-time modeling set side based on GPU high-performance calculation
Method, comprising the following steps:
S1, the coordinate range for obtaining workspace count all pipe point datas in coordinate range;
S2, the pipe point data and pipeline model isodisperse are transmitted to GPU by CPU, pipe point data is stored to complete
Office's memory, pipeline model isodisperse is stored to constant memory;
Thread block, Thread Count and dimension in S3, setting GPU, execute kernel function, execute a root canal by per thread
The section apex coordinate of section generates;
S4, using vertex buffer object pattern, the pipeline model in workspace is rendered by OpenGL;
S5, when workspace coordinate range change when, repaint the pipeline model in work at present area coordinate range.
Existing pipeline three-dimensional modeling is usually that approximatioss is used to carry out three-dimensional modeling to pipeline, is stored in pipeline tables of data
It is the vertex coordinates data at pipeline both ends, and in three-dimensional pipeline system, three-dimensional pipeline model is indicated using cylindrical surface, that is, is adopted
With multiple continuous quadrangles come approximate representation cylindrical surface, as shown in Figure 2.It is micro- that equal portions are carried out respectively to the both ends cross section of pipeline
Point, isodisperse N oneself can be configured.The sophistication and model formation speed of coefficient N decision model.N is bigger, modelling effect
It is more true to nature, but consequent is the reduction of system modelling performance.Therefore the selection of N value needs to measure model fidelity and modeling
Performance.And in the operation of three-dimensional pipeline system, it needs to generate whole vertex datas, and data are passed in memory, by
It is limited in memory size, so as to cause big data quantity model in display, software operation is slow.
In embodiments of the present invention, using the high-performance calculation characteristic of GPU, the coordinate range shown according to current screen,
By being counted to all pipe points within the scope of changing coordinates, by obtained in CPU each pipe point coordinate data and
Pipeline model isodisperse is transmitted to GPU, pipeline section section vertex coordinates data is generated in GPU, and by carrying out to pipeline section model
Rendering, shows all pipeline models within the scope of changing coordinates in screen.
In three-dimensional pipeline system, the coordinate range of workspace is obtained, counts all pipes points within the scope of changing coordinates
According to.By the way that screen coordinate is converted into world coordinates, to obtain coordinate range.The above-mentioned pipe point data got is passed to
The generation that pipeline section section vertex coordinates data is carried out in GPU, i.e., be mapped to the per thread on GPU for every root canal section, i.e., in GPU
End generates task using the vertex data that per thread executes a root canal section.Pipe point data is stored into GPU global storage,
Pipeline model isodisperse is stored into constant memory.
Apex coordinate is calculated into kernel function as a Grid, includes several Block in Grid, includes in Block
Several Thread set the number and dimension of Block and Thread, then design kernel function.
Calling the form of kernel function in a program is kernel<<<block,thread>>>, block and thread
The number of Thread Count in the thread block and block set before being respectively.According to such thread tissue in program process
Mode executes.It is mapped to corresponding thread according to different thread indexes, system assigns it to difference according to Thread Id
Stream handle group in, each stream handle group further assigns it on different stream handles, thus per thread
It is carried out calculating task.After same a collection of pipeline data complete calculating task, to prevent corrupt data, GPU by _
Syncthreads () is synchronous to be waited, and after all threads complete calculating task, next batch data is read in and calculated.
There is the characteristic of cache due to being always on memory not only, and single value is supported to be broadcast to each line in thread beam
Journey, therefore when pipeline section section vertex coordinates data generates, the pipeline model isodisperse being stored in constant memory can be broadcast to
The per thread of parallel computation, when cache hit occurs, all threads in thread beam can all obtain accessed data, because
This can significantly save bandwidth, improve access speed.
The pipeline section section vertex coordinates data that parallel computation generates is stored in global storage, OpenGL will be generated
Pipeline section section vertex coordinates data be sent to driver and rendered, without transferring data to CPU again, can reduce
Data communication between CPU and GPU shortens runing time.
Pipeline section section vertex coordinates data is reflected OpenGL Buffer object using vertex buffer object pattern
It is mapped in the datarams of GPU, coordinate data is written to Buffer object, OpenGL is transferred to use, is realized to workspace screen
In all pipeline sections model rendering.
When the operation such as being translated and being rotated by mouse, the world coordinates range in workspace changes, weight
It is new that our times coordinate range is obtained by screen coordinate, and count all pipe points in our times coordinate range.By
Above-mentioned pipe point coordinate data is obtained in CPU, is re-transmitted to generation and model that GPU carries out pipeline section section vertex coordinates data
Rendering, and carry out refreshing in the screen of workspace and show, to realize the Real-time modeling set of pipeline.
The embodiment of the present invention utilizes the high-performance calculation characteristic of GPU, the coordinate range shown according to current screen, by right
All pipe points within the scope of changing coordinates are counted, by obtaining each pipe point coordinate data and pipeline mould in CPU
Type isodisperse is transmitted to GPU, pipeline section section vertex coordinates data is generated in GPU, and by rendering to pipeline section model,
All pipeline models within the scope of changing coordinates are shown in screen.It is operated with translation and rotation of mouse etc., can be real-time
Refresh the pipeline model within the scope of changing coordinates, realizes the Real-time modeling set of three-dimensional pipeline.Solves three-dimensional pipeline in the prior art
The problem of cannot achieve high model accuracy in Real-time modeling set, realization carry out magnanimity pipeline data using GPU high-performance calculation
Real-time modeling set, since the data volume that CPU is transmitted to GPU is small, and the generation and storage of pipeline section section vertex data are all at the end GPU
It realizes, the data communication between CPU and GPU can be effectively reduced, shorten runing time.Realize lift line three-dimensional visualization
Can, accelerate the modeling work of magnanimity pipeline data, lift scheme fineness and modeling speed.
As shown in figure 3, the embodiment of the invention also discloses a kind of three-dimensional pipeline Real-time modeling set based on GPU high-performance calculation
System, the system comprises:
Workspace pipe point statistical module counts all pipe points in coordinate range for obtaining the coordinate range of workspace
Data;
Data transmission module will be managed for the pipe point data and pipeline model isodisperse to be transmitted to GPU by CPU
Point data is stored to global storage, and pipeline model isodisperse is stored to constant memory;
Model vertices computing module executes kernel function, passes through for thread block in GPU, Thread Count and dimension to be arranged
The section vertex coordinates data that per thread executes a root canal section generates;
Model rendering module, for utilizing vertex buffer object pattern, by OpenGL to the pipeline mould in workspace
Type is rendered;
Model refresh module, for repainting work at present area coordinate range when the change of the coordinate range of workspace
Interior pipeline model.
In three-dimensional pipeline system, the coordinate range of workspace is obtained, counts all pipes points within the scope of changing coordinates
According to.By the way that screen coordinate is converted into world coordinates, to obtain coordinate range.The above-mentioned pipe point data got is passed to
The generation that pipeline section section vertex coordinates data is carried out in GPU, i.e., be mapped to the per thread on GPU for every root canal section, i.e., in GPU
End generates task using the vertex data that per thread executes a root canal section.Pipe point data is stored into GPU global storage,
Pipeline model isodisperse is stored into constant memory.
Apex coordinate is calculated into kernel function as a Grid, includes several Block in Grid, includes in Block
Several Thread set the number and dimension of Block and Thread, then design kernel function.It calls in a program
The form of kernel function is kernel<<<block,thread>>>, block and thread are the line set before respectively
The number of Thread Count in journey block and block.It is executed in program process according to such thread organizational form.According to difference
Thread index be mapped to corresponding thread, system is assigned it to according to Thread Id in different stream handle groups, each
Stream handle group further assigns it on different stream handles, so that per thread is carried out calculating task.Same
After a collection of pipeline data complete calculating task, to prevent corrupt data, GPU owns by _ synchronous the waiting of syncthreads ()
After thread completes calculating task, next batch data is read in and is calculated.
There is the characteristic of cache due to being always on memory not only, and single value is supported to be broadcast to each line in thread beam
Journey, therefore when pipeline section section vertex coordinates data generates, the pipeline model isodisperse being stored in constant memory can be broadcast to
The per thread of parallel computation, when cache hit occurs, all threads in thread beam can all obtain accessed data, because
This can significantly save bandwidth, improve access speed.
The pipeline section section vertex coordinates data that parallel computation generates is stored in global storage, OpenGL will be generated
Pipeline section section vertex coordinates data be sent to driver and rendered, without transferring data to CPU again, can reduce
Data communication between CPU and GPU shortens runing time.
Pipeline section section vertex coordinates data is reflected OpenGL Buffer object using vertex buffer object pattern
It is mapped in the datarams of GPU, coordinate data is written to Buffer object, OpenGL is transferred to use, is realized to workspace screen
In all pipeline sections model rendering.
When the operation such as being translated and being rotated by mouse, the world coordinates range in workspace changes, weight
It is new that our times coordinate range is obtained by screen coordinate, and count all pipe points in our times coordinate range.By
Above-mentioned pipe point coordinate data is obtained in CPU, is re-transmitted to generation and model that GPU carries out pipeline section section vertex coordinates data
Rendering, and carry out refreshing in the screen of workspace and show, to realize the Real-time modeling set of pipeline.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all in essence of the invention
Made any modifications, equivalent replacements, and improvements etc., should all be included in the protection scope of the present invention within mind and principle.