Figure 10 shows an example surface that is mappable. The nodes on the boundary of the surface are used as input to the surface mapper. As shown in Figure 10 the loop is ordered counter-clockwise when viewed from a positive position on the surface normal.
Figure 10: Mapper input
The following code snippets show how the CMLSurfMapper object is used to generate a mapped mesh on a surface.
// read input file int i_ints = 0; int j_ints = 0; int num_points = 0; double *points = NULL; // array allocated in read_loop_file if (!read_loop_file(i_ints, j_ints, num_points, points)) { exit(EXIT_FAILURE); }
First, the input is read from a file. (Input could just as easily be from a program that meshed the edges.) The routine read_loop_file() returns the number of intervals, i_ints and j_ints, and the total number of points on the boundary, num_points. For the surface in Figure 10, the values are 5, 3 and 16. The points array holds all of the coordinates of the input points. The size of points is 3 * num_points. The first 3 entries in the array will be the x, y, and z coordinates of the first point, the next 3 entries will be the x, y, and z coordinates of the second point, and so on.
// mesh the surface
int *quads = NULL;
int new_points = 0;
int num_quads = 0;
if (ret_value) {
MySurfEval geom_eval;
CMLSurfMapper surf_mapper(&geom_eval);
ret_value = surf_mapper.set_boundary_mesh(i_ints+1, j_ints+1, points);
if (!ret_value) {
printf("Failed setting boundary mesh!\n");
}
// delete memory allocated in read_loop_file
delete [] points;
points = NULL;
// generate the mesh
if (ret_value) {
ret_value = surf_mapper.generate_mesh(new_points, num_quads);
if (!ret_value) {
printf("Failed generating mesh!\n");
}
}
The input is sent to the mapper using the CMLSurfMapper::set_boundary_mesh() function. The first two parameters are the number of points in the i- and j-directions. The number of points in each direction is one more than the number of intervals in each direction. Then the mesh is generated by calling the CMLSurfMapper::generate_mesh() function.
// allocate memory to accept quad mesh and retrieve it
if (ret_value) {
quads = new int [num_quads * 4];
points = new double [new_points * 3];
if (quads == NULL || points == NULL) {
printf("Failed allocating memory to receive mesh!\n");
ret_value = false;
}
}
if (ret_value) {
ret_value = surf_mapper.get_mesh(new_points, points, num_quads, quads);
if (!ret_value) {
printf("Failed reading quad mesh!\n");
}
}
This next part shows how the mesh is retrieved from CMLSurfMapper. Memory is allocated for the generated nodes and quads. For the example in Figure 10, new_points is 24, and num_quads is 15. Both of these values are returned during the call to CMLSurfMapper::generate_mesh(). The points array will hold the nodal coordinates of the resulting nodes and quads array will hold the connectivity of the resulting quads. The format for points will be the same as for the input nodes.
The format for quads will be as follows. The first four entries in quads will be the indices of the nodes making up quad number 1, the second four entries in quads will be the indices of the nodes making up quad number 2, and so on. The node numbering for each quad will be counter-clockwise around the quad when viewed from a positive position on the surface normal. The nodes and quads are retrieved using the funciton CMLSurfMapper::get_mesh().
// write output file if (ret_value) { ret_value = write_quad_file(new_points, points, num_quads, quads); } // delete remaining arrays delete [] points; delete [] quads; exit(ret_value ? EXIT_SUCCESS : EXIT_FAILURE); }
Finally, a call to write_quad_file() writes the quadrilateral mesh to an output file. The next two lines delete the allocated memory and exit the program. Figure 11 shows the resulting mesh for the example in Figure 10.
Figure 11: Mapper output
CAMAL 5.2-0 documentation created on 1 Jun 2010
Comments to csimsoft.com