Modeling Irregular Shapes: How to Import Curve Data and Loft a Solid

September 20, 2017

Irregular shapes can come in several different formats. For example, we have previously discussed importing STL files and NASTRAN® meshes into the COMSOL Multiphysics® software. These formats are common when working with scanned biological data. In this blog series, we will look at different ways of handling irregular shapes in COMSOL Multiphysics.

An Example of an Irregular Shape: The Human Head

One possible format when working with scanned data is text files with coordinate data from images of slices produced by an MRI or CT scan. In this example, let’s look at a case where we have a number of files or cross-sectional coordinates from different planes of a human head. Each coordinate file represents a curve of the outer surface of the head in that particular plane.

In short, the procedure includes:

  • Creating curve objects of each of the text files
  • Partitioning the edges of the curves to make sure that the points are aligned in the loft direction
  • Lofting the curves into a solid
  • Hiding unnecessary edges to produce a consistent shape

Now, let’s look at each step in more detail.

Importing Curves

To be able to import a text file in the Interpolation Curve feature, the coordinates need to be organized in the Sectionwise format. This is a native format of COMSOL Multiphysics in which the text file is organized to format one section with coordinates, one with the element connectivity, and one with data columns. The first two sections are needed here, while the data columns can be omitted when using this format for geometry creation. Below is an example of a file in the Sectionwise format:

     %Coordinates
     One to three columns containing x, y (optional), and 
     z (optional)
     %Elements
     Triangulation where each row contains the row indices of the
     points in the Coordinates section that make up one element
     (triangular in 2D, tetrahedral in 3D)
     %Data (funname)
     Column of data values for each point

In this example, we have 17 text files containing coordinate data from the 3D object. One Interpolation Curve feature per text file is added, which gives 17 curve objects in total. The Closed curve setting is used to ensure that the created curve objects are indeed closed and that the first- and second-order derivatives are continuous everywhere. In COMSOL Multiphysics, lofting a closed curve produces a solid object, while lofting an open curve produces a surface. The Relative tolerance is increased to 0.001 or 0.01 to produce a smoother representation of the curve. With the default tolerance (which is 0), the curves have a more jagged shape. In this example, the top of the head is represented by a point.

A screenshot of the settings for the Interpolation Curve feature in COMSOL Multiphysics® and an image showing the outer shell of a human head represented by curves.
The Settings window for the Interpolation Curve feature (left) and all of the curves representing the outer shell of a head (right). The Relative tolerance is increased to 0.001 or 0.01 to produce a smoother representation. The Closed curve setting ensures that the curve becomes closed and has continuous first- and second-order derivatives everywhere.

Considerations for Lofting Solids

Now that we have the curve objects that define the outline of each cross section of the head, we can create the solid shape with the Loft operation. The Loft operation is one of the geometry modeling tools included in the Design Module, which you can read about in this introductory blog post. Before setting up the Loft operation, we need to make sure that the curve objects are suitable as profiles for lofting. Lofting curves or surfaces to a solid requires the different profiles to have the same number of edges and points. The exception is the first and last objects (called the start and end profiles), which can be points, as is the case for the top of the head in this example.

A closed interpolation curve has two vertices, but it is not possible to choose their positions. So, the criterion mentioned above — to have the same number of edges and points of the intermediate objects — is already fulfilled, as all of the created curves have two edges. However, where these points are placed on the profile objects is also important. When the loft works its way through the curves, it connects all of the points with edges in the direction of the loft. If the points are not positioned along a fairly straight line, the resulting surfaces might become distorted. Therefore, we often need to partition the edges further to accomplish a good representation of all of the surfaces. To do this, we can use two different procedures: creating curves from data and lofting them into an object.

Partitioning the Edges of Curves

How to partition the edges and which features to use for this purpose is not an exact science, but something for which you use some trial and error and decide based on what looks best after a visual inspection. Here, we use the Partition Objects and Partition Edges features. The advantage of using the Partition Objects operation is that this option allows multiple curve objects to be partitioned at locations defined by the points of intersection with a selected plane. As some of the interpolation curves already contain points that are fairly well aligned on the front and back of this human head example, a Work plane is added at y = 0 to create more points along the same imaginary lines.

A screenshot of the settings used for the Partition Objects feature, which is useful for modeling irregular shapes, and a human head model with curve objects that are partitioned at two places via a work plane.
Partitioning some of the curves using a Work plane at y = 0. The settings for the Partition Objects feature (left). The curve objects highlighted in blue (right) are partitioned at two places using the work plane, which is pictured as a gray sheet with a rectangular grid.

The Partition Edges feature partitions selected edges based on either specified relative arc lengths or by projecting one or several vertices. As we want the vertices to line up fairly well when lofting curves, projecting vertices is a good option. However, for some edges, it is better to specify a relative arc length to have more control over where the vertex is created.

Screenshots of the partition Edges Settings window with Vertex projection specification and arc length specification as well as an image showing the edges selected for a vertex projection in the human head model.
The Settings windows for the Partition Edges features, showing both the Vertex projection (left) and the Arc length (middle) specification types, and the edges selected for a vertex projection (right).

To verify that the geometry objects have the same amount of edges and points, we click the Select Objects button above the Graphics window, select a curve object in the Graphics window, and then click the Measure button in either the Geometry or Mesh tab. The output of this measurement is written to the Messages log.

Lofting the Solid

Now that the points are roughly aligned, it is time to create the solid. The Loft feature contains many options, but we only use the most straightforward procedure here: adding all of the curve objects and the point on the top of the head in the Profile objects list. The start and end profiles are determined automatically by the Loft operation. As shown in the left image below, there are many collapsed sections (highlighted in blue) that can be used to fine-tune the loft; for example, to specify the direction of the loft. The collapsed sections are not used in this example.

A screenshot of the settings window for the Loft operation and an image of the solid head model after lofting the solid.
The Settings window of the Loft operation (left), showing the input Profile objects, which is the only input used in this example. The right image shows the resulting solid head.

Surface Partitioning

A surface or solid object lofted from closed continuous profile curves has at least two seams that go through the vertices of the profile curves, creating two face partitions. More seams may be introduced by the operation, depending on the alignment of the vertices on the different curves. If the profile curves have discontinuous tangents, additional seams are introduced and go through these points. No additional seams are introduced when using the default setting Face partitioning: Minimal in the Loft operation (see the image above), as is the case in this example.

If we want the lofted surface to be more partitioned — for example, to assign boundary conditions — the partitioning options Column and Grid can be used. The first option divides the surface along each vertex in the profile curves, while the latter also adds the profile curves. Yet another possibility is to use the different Partitions operations available in the Geometry ribbon. On the other hand, if we want to have a more clean appearance, we can use Virtual Operations to create composite faces. Ignore Edges is one of the features that can be used for this purpose, but Form Composite Faces also gives the same end result.

A screenshot of the settings for the Ignore Edges operation and an image of the final geometry of a human head after smoothing the edges.
By adding the edges shown in the previous image to an Ignore Edges operation (left), the final geometry gets a smooth and nice look (right).

Learn Different Approaches for Modeling Irregular Shapes

This blog post has discussed the possibility of creating curves from coordinate data and then lofting these curves into a solid object. Upcoming posts in this blog series will discuss other possible formats as well as approaches for handling irregular shapes in COMSOL Multiphysics.

Download the file used to create the example featured here:

NASTRAN is a registered trademark of NASA.

Categories


Comments (9)

Leave a Comment
Log In | Registration
Loading...
峰 程
峰 程
September 21, 2017

Hi. It is a useful blog about building geometry and there is something I can not understand.
In the section of “Partitioning the Edges of Curves”, you did not partition all of the curves.
Is it not necessary?
And what is the trick to pick the curves to be partitioned?
Thank you.

Hanna Gothäll
Hanna Gothäll
September 26, 2017 COMSOL Employee

Great to hear that the blog post is of use to you! There are two criteria to fulfill: (1) The vertices should be positioned along a fairly straight line in the sweep direction. (2) The curves need to have the same number of vertices. The number of vertices will be modified for the curves until both criteria are both fulfilled.

Feel free to send in your MPH file to support@comsol.com and we can give more specific advice on how to select the curves to partition.

Xuewei Zhao
Xuewei Zhao
October 7, 2017

Hi. This blog is very helpful for me. Now I have another issue. Which software can give the text files containing the coordinate data of the curves? In addition, for the case of my work, the solid has a close inner surface. Can you give me some advices? Thanks a lot!

Hanna Gothäll
Hanna Gothäll
October 18, 2017 COMSOL Employee

The Sectionwise format is a format which is native of COMSOL Multiphysics. However, by inspecting a text file exported from COMSOL Multiphysics, you might be able to create a script which can translate your data to this format. For surfaces, you could import DXF files into 2D Workplanes. There are other possibilities as well, so please send in your question along with your files to COMSOL Support, support@comsol.com, so that we can look into your specific case.

Xuewei Zhao
Xuewei Zhao
October 18, 2017

Hanna Gothäll@
Thank you for your reply. Sorry, I did not described my problem in detail.
I will built a geometry model of an irregular-shape food (dumpling) which is composed of two domains, i.e. core and wrapper. After MRI or CT scans (I have not do this work), series of 2D images will be obtained. I want to built a geometrical model of the dumpling according the procedure suggested in your above blog. The Sectionwise text files containing the (x, y, z) coordinates of the inner and outer boundary curves are necessary for building the geometry. I do not know how to get the Sectionwise format files form the MRI or CT images. I guess that Matlab (with image processing toolbox) live-linked with COMSOL was used in your procedure. But, I know very little about Matlab. Can you tell me the steps for obtaining the Sectionwise text files?

Xuewei Zhao
Xuewei Zhao
October 18, 2017

Hanna Gothäll@
Thank you for your reply. Sorry, I did not described my problem in detail.
After MRI or CT scans (I have not do this work), series of 2D images will be obtained. I want to built a geometrical model of the dumpling (a chinese food, which is composed of two domains, i.e. core and wrapper) according the procedure suggested in your above blog. The Sectionwise text files containing the (x, y, z) coordinates of the inner and outer boundary curves are necessary for building the geometry. I do not know how to get the Sectionwise format files form the MRI or CT images. I guess that Matlab (with image processing toolbox) live-linked with COMSOL was used in your procedure. But, I know very little about Matlab. Can you tell me the steps for obtaining the Sectionwise text files?

Hanna Gothäll
Hanna Gothäll
October 23, 2017 COMSOL Employee

To get the data files for this blog post, I exported the data of contour plots to text files on the Sectionwise format.

Shisir Mia
Shisir Mia
May 5, 2018

Hi, at present I am using Comsol 5.2 , so if you share the compatible loft_head.mph file for Comsol 5.2 to me. I will be very grateful to you. Thanks in advance…

Hanna Gothäll
Hanna Gothäll
May 9, 2018 COMSOL Employee

Hi Shisir,
Unfortunately, the model file associated with this blog post is not available in version 5.2. Sorry for the inconvenience

EXPLORE COMSOL BLOG