Disclosure of Invention
In view of the above, the invention provides a carotid artery lumen geometric model construction system based on CTA images, which solves the problems in the background art.
In order to achieve the above purpose, the present invention adopts the following technical scheme:
a neck arterial lumen geometric model construction system based on CTA image comprises a data import module, a volume data clipping module, an interactive neck arterial lumen segmentation module, a 3D model construction module, a model processing module, a model clipping module, a boundary detection module, an entrance filling module and an STL file export module;
the data importing module is used for automatically importing carotid artery CTA image data from a folder appointed by a user and converting the carotid artery CTA image data into three-dimensional data;
the body data clipping module clips the imported three-dimensional body data VolumeData according to the clipping range selected by the user, and generates clipped child data;
the interactive carotid lumen segmentation module is used for automatically and manually segmenting the carotid lumen based on the subvolume data through user interaction;
The 3D model construction module is used for extracting surface grids from the segmented data to generate three-dimensional surface data so as to construct a preliminary three-dimensional geometric model;
the model processing module is used for carrying out smoothing processing on the obtained preliminary three-dimensional geometric model;
The model clipping module clips the preliminary three-dimensional geometric model through a user interactive selection plane;
the boundary detection module is used for identifying the boundary and the hole of the preliminary three-dimensional geometric model by analyzing the boundary of the grid;
the entrance filling module is used for filling the opening of the preliminary three-dimensional geometric model, extracting vertexes of the boundary of the three-dimensional geometric model, calculating a plane, filling a closed boundary area by a constraint Delaunay triangulation method, and generating a new patch to fill the opening;
and the STL file export module converts the processed three-dimensional geometric model data according to the STL file format and stores the data in ASCII codes.
Optionally, the workflow of the data importing module is as follows:
User selecting DICOM folder, wherein the user triggers folder selecting operation through the button of opening CTA file; at this time, the system pops up a folder selection dialog box, allowing the user to select a folder containing the DICOM file, after the user selects the folder, the system will acquire the path of the folder, and save it to the variable folderPath;
Reading DICOM data, namely using dicomread functions to read DICOM files from a folder path folderPath by a system, listing and reading all files meeting the conditions by the system if the selected folder contains the DICOM files, and extracting meta information in each DICOM file by the system in the reading process;
Processing DICOM data, namely judging whether the data is a multi-frame DICOM sequence by a system after the DICOM data is read, and if the data is the multi-frame DICOM sequence, sequencing a plurality of files according to InstanceNumber or SliceLocation by the system and stacking the files into three-dimensional volume data VolumeData;
Displaying data preview, namely after importing data, displaying slices of three-dimensional data by using orthosliceViewer by a system;
Updating the interface control, namely dynamically updating the slider control on the main interface according to the imported VolumeData size by the system.
Optionally, the workflow of the volume data clipping module is as follows:
Acquiring a cutting range, namely setting the cutting range of the data by a user through sliding the sliders at two ends of xRangeSlider, yRangeSlider, zRangeSlider on a graphical user interface after the data is imported;
Cutting the volume data, namely cutting VolumeData by the system by using xRange, yRange and zRange set by a user after the cutting range is set by the user to obtain sub-volume data subVolume;
The clipping results are displayed-the system displays the sub-volume data subVolume using orthosliceViewer.
Optionally, the workflow of the interactive carotid lumen segmentation module is:
Initializing and loading data, namely when a user firstly calls the module, the input data is child data subVolume, the system pops out a new interface, and firstly, the left side of the interface carries out preliminary binarization processing on the data according to initial thresholds thLow and thHigh to display a preliminary mask;
threshold adjustment and mask update, wherein after a user inputs a frame adjustment threshold through thLow and thHigh and clicks an update threshold button, the system regenerates a mask according to the new threshold;
The 3D region growing step, namely, selecting a seed point from a currently displayed slice by a user through clicking a region growing button, and determining the seed point through a carriage return key, wherein the seed point is used as a starting point of the region growing step, and the system uses a breadth-first searching method to carry out the region growing according to the position of the seed point and a current mask to obtain the whole region communicated with the seed point;
cutting to the mask, namely clicking a 'cutting to mask' button after a user is satisfied with the segmentation result, and cutting the volume data and the mask to a minimum bounding box of the mask;
mask preview, in all operations, the user always looks at the current mask situation in the 3D view in the lower right corner;
Export and end-user exports the segmentation result to MATLAB work area for subsequent processing.
Optionally, the workflow of the 3D model building module is:
Generating a three-dimensional surface by extracting a surface grid from the three-dimensional mask data ExportedMask by using isosurface functions, calculating an equivalent surface of the three-dimensional volume data by isosurface functions according to a set threshold value, and returning surface and vertex data on the surface, wherein the generated surface data and vertex data are used for constructing a three-dimensional geometric body;
simplifying the three-dimensional surface by using a reducepatch function and simplifying the surface by using a simplification proportion to obtain simplified surface data F2 and simplified vertex data V2;
Saving the simplified three-dimensional model as an STL file;
Presenting the exported STL model by reading the exported STL file using stlread functions, popping up a new graphical window to present the three-dimensional model, and allowing the user to interactively view the different perspectives of the model.
Optionally, the workflow of the model processing module is as follows:
Default smoothing, namely performing iterative smoothing on the input V2 and F2 by using SurfaceSmooth functions by using a module to obtain smoothed vertex data V_ smoothed after the processing is finished;
The manual processing comprises the steps of popping up an interface window after default smooth processing, and dividing a left 3D drawing area and a right operation panel in the window;
the system uses patchSmooth function to smooth the current model according to the global smooth factor set by the user based on weighted average method and update the vertex data;
The grid simplifying operation, in which a user adjusts the simplifying degree through a grid simplifying comparison slide bar and clicks a button of 'redrawing grid (reducepatch)', a system call reducepatch algorithm performs simplifying processing on the face data and the vertex data of the current model, and updated model data is displayed in a graphic window in real time;
and (3) recovering and exporting, namely if the user is not satisfied with the editing result, clicking a 'recovering original grid' button to recover the model data to an initial state, clicking a 'exporting grid (F, V) to a working area' button to export the finally edited model data to a MATLAB working area.
Optionally, the workflow of the model clipping module is as follows:
Initializing a graphical interface, namely when the clipping module is activated, firstly popping up an interface, wherein the interface comprises two areas:
The left display area is used for displaying the three-dimensional geometric model, drawing initial display of the grid through a patch function, and generating a model by vertex data and face data of the grid;
The right side operation panel comprises four input boxes for a user to input coordinates of four points required by a cutting plane and simultaneously provides buttons for determining the plane, cutting a model and reversely cutting the model;
plane definition and creation:
The user inputs four points of the plane, namely, in the initial condition, the four points (point 1, point2, point3 and point 4) of the clipping plane are predefined, after the user clicks a 'determine plane' button, the system calculates the equation of the plane according to the four points, and draws the plane in a left display area;
Calculating plane equation, namely calculating normal vector of the plane through the selected four points, and then calculating the plane equation by using the normal vector and the selected points;
drawing a plane, namely generating a grid in a region where the plane is positioned by using meshgrid functions according to the plane equation obtained by calculation, and calculating the z value of each point on the region;
Cutting model:
when a user clicks a 'cut' button, the geometric model is divided into two parts according to a plane shown on the left side;
Reverse cutting:
The function of the reverse clipping button is reverse to normal clipping, after the user clicks the button, the system will execute the same steps as clipping but will keep the opposite part to clipping model, and the result of the reverse clipping operation will update F_final and V_final as well and save to the working area.
Optionally, the workflow of the boundary detection module is as follows:
Extracting information of all sides from the grid F_final through a detect_mesh_boundary_and_holes function, sorting and de-duplicating all sides to obtain independent boundary sides, sequentially connecting adjacent vertexes until returning to a starting point by traversing the independent boundary sides to form a complete boundary, sorting in a descending order according to the quantity of the vertexes of the boundary, printing the quantity of the detected boundary, and popping up a graphic window to check the detected boundary.
Optionally, the working flow of the entrance filling module is as follows:
extracting boundary vertexes, namely acquiring vertex indexes loopIdx of each boundary, and extracting coordinates loopVerts of the boundary vertexes from a global vertex set V_final;
Calculating a best fit plane, namely calculating the mass center of the boundary vertex, and analyzing the main direction of the calculation plane by using a main component to determine a direction vector and a normal vector in the plane;
projecting each boundary vertex relative to the plane, calculating two-dimensional coordinates of the boundary vertex, and generating a two-dimensional coordinate set uv;
Performing Delaunay triangulation and mapping back to global coordinates, namely performing constraint Delaunay triangulation on the two-dimensional projection point set, screening effective triangles, and mapping vertex indexes of the two-dimensional triangles back to the global vertex coordinates V_final to obtain a new patch and filling polygons;
combining the filling patches with the original grid, namely storing the filling patches corresponding to each boundary into an F_patch, and combining the filling patches with the patches of the original grid to generate a new patch set F_new;
and displaying the result, namely displaying the filled grid by using a graphical interface.
Optionally, the workflow of the STL file export module is:
Opening the file and writing header information, namely using fopen to open STL file file_model. STL of default path, writing file header solidmodel, marking file start;
Traversing the triangle patches and writing data, namely acquiring three vertex coordinates corresponding to each triangle patch, wherein the indexes of the vertexes correspond to V_final through F_new, extracting three-dimensional coordinates (V1, V2 and V3) of the three vertexes of each triangle, calculating a vector, and writing normal vector and vertex data of each triangle by using fprintf;
Writing the tail and closing the file-writing endsolidmodel at the tail of the file, marking the end of the STL file, and then closing the file using fclose.
Compared with the prior art, the invention discloses a neck arterial lumen geometric model building system based on CTA images, which comprises modules of data import, volume data cutting, interactive neck arterial lumen segmentation, 3D model building, model processing, model cutting, boundary detection, entrance and exit filling, STL file export and the like, and the modules have definite work procedures. The invention solves the problems that the existing geometric modeling method depends on commercial software, has high cost, legal risk, complex operation flow, low speed and the like, can simply, conveniently, efficiently and accurately construct the carotid geometric model, and provides powerful support for carotid hydrodynamic analysis research and diagnosis of atherosclerosis, aneurysms and other diseases.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The embodiment of the invention discloses a neck arterial lumen geometric model building system based on a CTA image, which comprises a data importing module, a volume data clipping module, an interactive neck arterial lumen segmentation module, a 3D model building module, a model processing module, a model clipping module, a boundary detection module, an entrance filling module and an STL file exporting module;
the data importing module is used for automatically importing carotid artery CTA image data from a folder appointed by a user and converting the carotid artery CTA image data into three-dimensional data;
the body data clipping module clips the imported three-dimensional body data VolumeData according to the clipping range selected by the user, and generates clipped child data;
the interactive carotid lumen segmentation module is used for automatically and manually segmenting the carotid lumen based on the subvolume data through user interaction;
The 3D model construction module is used for extracting surface grids from the segmented data to generate three-dimensional surface data so as to construct a preliminary three-dimensional geometric model;
the model processing module is used for carrying out smoothing processing on the obtained preliminary three-dimensional geometric model;
The model clipping module clips the preliminary three-dimensional geometric model through a user interactive selection plane;
the boundary detection module is used for identifying the boundary and the hole of the preliminary three-dimensional geometric model by analyzing the boundary of the grid;
the entrance filling module is used for filling the opening of the preliminary three-dimensional geometric model, extracting vertexes of the boundary of the three-dimensional geometric model, calculating a plane, filling a closed boundary area by a constraint Delaunay triangulation method, and generating a new patch to fill the opening;
and the STL file export module converts the processed three-dimensional geometric model data according to the STL file format and stores the data in ASCII codes.
The following describes each module in detail:
Data importing module
The main function of the module is to automatically import carotid CTA (computed tomography) image data from a folder designated by a user and convert the carotid CTA image data into three-dimensional volume data for subsequent operation. The method comprises the following specific steps:
1.1 user selection of DICOM folder
First, the user triggers the folder selection operation through the "open CTA file" button on the interface. At this point, the system pops up a folder selection dialog allowing the user to select a folder containing DICOM files. After the user selects a folder, the system obtains the path of the folder and saves the path to variable folderPath.
1.2 Reading DICOM data
The system reads the DICOM file from the folder using dicomread functions from the folder path folderPath. If the selected folder contains DICOM files, the system will list and read all eligible files. During the reading process, the system will extract meta information in each DICOM file, such as pixel spacing PixelSpacing, slice thickness SLICETHICKNESS, etc., and store it in VolumeInfo.
1.3 Processing DICOM data
After the DICOM data is read, the system determines whether the data is a multi-frame DICOM sequence. In the case of a multi-frame DICOM sequence, the system sorts the files by InstanceNumber or SliceLocation and stacks them into three-dimensional volume data VolumeData.
1.4 Display data previews
After importing the data, the system will display slices of the three-dimensional data using orthosliceViewer (as shown in FIG. 2). Thus, the user can intuitively view the imported CTA data, and the user can view different sections through the yellow lines in the slider map.
1.5 Update interface control
The system dynamically updates the slider control (xRangeSlider, yRangeSlider, zRangeSlider) on the main interface (as shown in FIG. 1) based on the imported VolumeData sizes (i.e., number of rows, columns, and slices of data). The sliders are respectively used for setting a data cutting range, and the minimum value and the maximum value of the sliders are automatically adjusted according to the size VolumeData so as to ensure that a user can select a reasonable cutting interval.
Volume data clipping module
The main function of the volume data clipping module is to clip the imported three-dimensional volume data VolumeData according to the clipping range selected by the user, and generate clipped sub-volume data subVolume. The module can dynamically adjust the child data according to the clipping range set by the user. The specific flow is as follows:
2.1 obtaining the clipping Range
After the data is imported, the user sets the clipping range of the data by sliding the sliders at two ends of xRangeSlider, yRangeSlider, zRangeSlider on the graphical user interface. These sliders correspond to the x-axis (column), y-axis (row) and z-axis (slice) directions of the data, respectively. These values are saved in xRange, yRange and zRange variables.
2.2 Clipping volume data
After the user sets the clipping range, the system clips VolumeData using xRange, yRange and zRange set by the user, resulting in child data subVolume. subVolume is clipped child data, containing the user selected region. It is a subset of VolumeData, the size being determined by the clipping range set by the user.
2.3 Displaying the clipping results
The system uses orthosliceViewer to display the subvolume data subVolume, as shown in fig. 3, so that the user can see a multi-slice view of subVolume, conveniently and intuitively viewing the data.
Interactive carotid artery lumen segmentation module
The main function of the interactive carotid lumen segmentation module is to automatically and manually segment the carotid lumen based on the subvolume data subVolume through user interaction. The module combines the technologies of threshold segmentation, manual editing masking, region growing and the like, provides a real-time three-dimensional preview function, and is convenient for users to accurately adjust and modify segmentation results. The specific flow is as follows:
3.1 initialization and data Loading
When the user first invokes the module, the data entered is child data subVolume. The system pops up a new interface (as shown in fig. 4), and the left side of the interface firstly carries out preliminary binarization processing on the data according to initial thresholds thLow and thHigh to display a preliminary mask. At this point, all voxels in the subvolume data subVolume that meet the threshold range will be marked as true, with the remainder being false. The upper right corner of the interface is an operation area, the lower right corner of the interface can preview the 3D mask view, and a user can rotate to view.
3.2 Threshold adjustment and mask update
After the user enters the box adjustment threshold through thLow and thHigh and clicks the "update threshold" button, the system regenerates the mask according to the new threshold. The updated mask will be displayed on the current slice and the 3D mask view will be updated simultaneously.
3.3 Manual editing mask
When the user wishes to make fine adjustments to the automatic segmentation results, the manual editing mode may be entered via a "manually add mask" or "manually erase mask" button. The system allows the user to add or erase mask areas on the current slice by way of free sketching.
The freely delineated region is immediately applied to the current slice and the 3D view is updated. By manual editing, the user can precisely adjust the segmentation result.
3.43D region growth
By clicking the "region growing" button, the user can select a seed point in the currently displayed slice, and the seed point is determined by the enter key. The seed point is used as a starting point of region growth, and the system uses a Breadth First Search (BFS) method to perform region growth according to the position of the seed point and the current mask to obtain the whole region communicated with the seed point.
The results of the region growing will be incorporated into the current mask, resulting in updated segmentation results and simultaneous updating of the slice display and 3D view.
The updated segmentation results may continue to manually edit the mask and 3D region growing operations multiple times until a user-satisfactory effect is achieved.
3.5 Clipping to mask
When the user is satisfied with the segmentation result, the user may click on the "cut to mask" button, cutting the volume data and mask to the mask's minimum bounding box. The clipping operation reduces the size of the data to a minimum region containing all true voxels, thereby eliminating redundant blank regions and reducing the calculation amount of subsequent processing.
The cut data is updated to the system and the range of the slicing slide bar is updated, so that the follow-up operation is ensured to be carried out in the cut area.
3.63D mask preview
In all operations, the user can always view the current mask situation in the lower right 3D view. The view generates a 3D isosurface through isosurface, which helps the user to intuitively see the three-dimensional effect of the mask. If the mask area is empty, the system will display a hint in the 3D view.
3.7 Derivation and end
The user can export the segmentation results (masks and data) to the MATLAB work area for subsequent processing. After clicking the "export mask to workspace" button, the current mask will be saved as ExportedMask for subsequent use by other modules.
3D model construction module
The module may convert the three-dimensional mask data ExportedMask into a model suitable for three-dimensional modeling and simulation and export into an STL file.
4.1 Generating a three-dimensional surface:
A isosurface function is used to extract the surface mesh from the three-dimensional mask data ExportedMask. The isosurface function calculates the iso-surface (surface) of the three-dimensional volumetric data from the set threshold (typically 0.5) and returns the surface and vertex data on the surface. The generated face data (F) and vertex data (V) are used to construct a three-dimensional geometry. Surface data (Faces) of the three-dimensional surface, representing that each triangle surface is connected by three vertices. Vertex data (Vertices) representing the three-dimensional coordinates of each vertex of the surface.
4.2 Simplifying the three-dimensional surface:
Since isosurface functions can generate very complex surface meshes, containing too many faces and vertices, simplification of these meshes is often required. The surface is simplified by reducepatch functions using a reduction ratio (e.g., 0.5, 50% of the surface is retained) to obtain reduced surface data F2 and reduced vertex data V2. The reducepatch function can effectively reduce redundant surfaces, maintain the basic shape of the surface and optimize subsequent calculation and storage.
4.3 Saving the simplified three-dimensional model as an STL file:
The reduced three-dimensional surface data is saved as an STL file format using stlwrite functions. STL format is widely used in 3D printing and CAD tools. The file name defaults to ExportedMask _ surface. Stl, modifications may be made as desired.
4.4 Shows derived STL model:
The derived STL file is read using stlread functions, and a new graphical window is popped up to reveal the three-dimensional model (as shown in fig. 5). And allows the user to interactively view different perspectives of the model.
Model processing module
The main purpose of the module is to smooth the preliminary three-dimensional geometric model obtained by the previous steps so as to eliminate the irregularity and noise on the surface of the model and improve the geometric shape. The specific flow and key variables are described as follows:
5.1 default smooth handling
The module defaults smooth processing at first, specifically uses SurfaceSmooth function to carry out iterative smooth processing to input V2 and F2, and its core idea is that the neighborhood information of each vertex is utilized, the positions of the vertices are adjusted by calculating the normal vector and the area weight of the adjacent surface, so that the whole grid tends to smooth, and local sharp and noise is reduced. Damping factor (DampingFactor) is used in the process to suppress oscillations, ensuring that the vertex movement is within the allowed range until either a preset displacement tolerance (default 0.02) is met or a maximum number of iterations (default 100) is reached. After the processing is completed, smoothed vertex data v_ smoothed is obtained.
5.2 Manual handling
After the module defaults to smooth, an interface window (as shown in fig. 6) is popped up, in which a left 3D drawing area and a right operation panel are divided. In the operation panel, a slide bar and buttons for parameters such as global smoothness, grid simplification, etc. are set. The default smooth model data (F2, V_ smoothed) is displayed on the left 3D plot area using the patch function.
5.3 Global smooth operation
The user adjusts the smoothing parameters via the global smoothing factor slider and clicks the "global smoothing" button. The system uses patchSmooth functions to smooth the current model according to the global smoothness factor set by the user based on a weighted average method, and updates vertex data.
After the processing is completed, the graphic window displays the updated model, and the user can intuitively see the change before and after the smoothing.
5.4 Grid reduction operations
The user adjusts the degree of simplification by the grid simplification vs. the slider bar and clicks the "redraw grid (reducepatch)" button.
And the system call reducepatch algorithm simplifies the surface data and the vertex data of the current model, reduces redundant surfaces and vertices and improves the calculation efficiency of the model.
The updated model data is displayed in real time in the graphical window.
5.5 Recovery and export
If the user is not satisfied with the editing result, the user can click on the 'restore original grid' button to restore the model data to the initial state.
The user may also click on the export grid (F, V) to workspace button to export the final edited model data (EDITEDFACES, EDITEDVERTICES) to MATLAB workspace.
Model cutting module
The module tailors the three-dimensional geometric model by user-interactively selecting a plane. The user can define a plane by specifying four points, and then divide or crop the model into desired portions using the plane. The module provides three functions, namely, determining a plane, a clipping model and a reverse clipping model, and updating and displaying an operation result in real time in a left graphical interface.
6.1. Initializing a graphical interface
When the cropping module is activated, an interface is first popped up (as shown in FIG. 7). The interface contains two regions:
and the left display area is used for displaying the three-dimensional geometric model and drawing initial display of the grid through the patch function. Vertex data and face data of the mesh are used to generate a model.
The right side operation panel comprises four input boxes for the user to input the coordinates of four points needed by the clipping plane, and simultaneously provides buttons of 'determining plane', 'clipping model', 'reverse clipping model'.
6.2. Plane definition and creation
The user inputs four points of the plane-initially, four points of the clipping plane (point 1, point2, point3, point 4) are already predefined. The user can modify the coordinate values of the points, and after clicking the 'determine plane' button, the system calculates the equation of the plane according to the four points, and draws the plane in the left display area.
Plane equation calculation by selecting four points, firstly calculating the normal vector of the plane, and then calculating the plane equation by using the normal vector and the selected points. The standard form of the plane equation is ax+by+cz=d, where (a, b, c) is the normal vector and d is a constant term.
Drawing a plane, namely generating a grid in a region where the plane is located by using meshgrid functions according to the plane equation obtained by calculation, and calculating the z value of each point on the region. The plane is then drawn using surf functions.
6.3. Cutting model
When the user clicks the "crop" button, the geometric model (EDITEDFACES, EDITEDVERTICES) is split into two parts according to the plane shown on the left.
6.3.1 Clipping triangles
The signed distances of the three vertices of each triangle to the plane are calculated.
The polygons are clipped using clipPolygonWithPlane functions. The function processes each vertex according to the plane position, if one vertex is above the plane, the vertex is reserved, otherwise, the intersection point is calculated by interpolation according to the intersection point formula and added into the cut polygon, and then the polygon is converted into a plurality of triangles.
6.3.2 Judgment of reserved portion
For each vertex, its signed distance to the plane is calculated. By this distance, it is determined whether the vertex is above or below the plane. If the distance is greater than or equal to zero, the vertex is above the plane, otherwise, the vertex is below the plane. If the "clip" button, the portion above the plane remains.
Multiple cuts can be made by setting different planes.
After each clipping is completed, the system automatically saves the clipped new face data F_final and vertex data V_final to a working area for subsequent operation.
6.4. Reverse cutting
The function of the "reverse crop" button is to reverse the normal crop. After the user clicks this button, the system will perform the same steps as clipping, but will leave the opposite part of the clipping model. The result of the reverse clipping operation also updates F_final and V_final and saves to the workspace.
Boundary detection module
The module identifies the boundaries and holes of the model by analyzing the boundaries of the mesh. By computing the boundary information in the triangular mesh, the module can accurately find the topology of all the boundaries and holes and return a list of boundaries and holes.
All side information is extracted from the grid F final by the detect_mesh_boundary_and_holes function. The edges are ordered and de-duplicated to obtain independent boundary edges. By traversing these independent edges, adjacent vertices are connected in turn until they return to the starting point, forming a complete boundary. Only boundaries containing at least three different vertices are considered valid boundaries. The valid boundaries are added to the boundaries list. And sorting in descending order according to the number of the vertexes of the boundary. boundaries is a list containing all valid boundaries, each represented by a set of vertex indices. And prints the number of detected boundaries while popup graphical windows view the detected boundaries (as shown in fig. 8). The vertex coordinates of each boundary are plotted with different colors (red, green, blue, etc.) and line widths (2).
The correct model will contain 3 borders-one inlet, two outlets of the carotid artery.
Entrance filling module
The module is filled at the opening (boundary) of the mould. By extracting vertices of the boundary, computing planes, and filling the closed boundary region by the constrained Delaunay triangulation method, new patches are generated to fill the openings.
8.1 Extracting boundary vertices the vertex index loopIdx for each boundary is obtained and the coordinates loopVerts for these vertices are extracted from the global vertex set v_final.
8.2 Calculating a best fit plane by calculating the centroid of the boundary vertices and calculating the principal direction of the plane using Principal Component Analysis (PCA), determining the direction vector and the normal vector in the plane. PCA provides a plane in which the first two principal components (direction vectors) define the direction in the plane, and the third principal component is the normal vector. These direction vectors will be used to project points in three-dimensional space onto a plane.
8.3 Projecting three-dimensional vertices into a plane, projecting each boundary vertex relative to the plane, calculating its two-dimensional coordinates, and generating a two-dimensional set of coordinates uv.
And 8.4, performing Delaunay triangulation and mapping back to global coordinates, namely performing constraint Delaunay triangulation on the two-dimensional projection point set, screening effective triangles, and mapping vertex indexes of the two-dimensional triangles back to the global vertex coordinates V_final to obtain a new patch and filling polygons.
8.5 Combining the filled dough sheet with the original grid:
And storing the filling patches corresponding to each boundary into the F_patch, and combining the filling patches with patches of the original grid to generate a new patch set F_new.
8.6 Shows the results:
the filled grid is displayed using a graphical interface in which the original grid is displayed in a translucent blue color. The filled dough piece is highlighted in red (as shown in fig. 9).
STL file export module
The module is used for converting the processed three-dimensional grid data (comprising the vertex and the patch information) according to the STL file format and storing the three-dimensional grid data in ASCII codes.
9.1 Opening the file and writing header information:
STL file file_model. STL of default path (current working folder) is opened using fopen and written into file header solidmodel, marking the start of the file.
9.2 Traversing triangle patches and writing data:
For each triangular patch (each row in f_new), three vertex coordinates corresponding to the patch are obtained, and the indices of the vertices correspond to v_final through f_new. For each triangle, three-dimensional coordinates (v 1, v2, v 3) of its three vertices are extracted. Calculate the normal vector and write the normal vector and vertex data for each triangle using fprintf.
9.3 Write tail and close file:
writing endsolidmodel at the tail of the file, marking the end of the STL file, and closing the file by using fclose to ensure the storage integrity of the file.
In the present specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, and identical and similar parts between the embodiments are all enough to refer to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.