StrLineEval line;
line.set_start_coordinates(0,0,0);
line.set_end_coordinates(1,0,0);
// mesh the curve
int *edges = NULL;
int num_points_out = 0;
CMLEdgeMesher edge_mesher(&line);
if (!edge_mesher.generate_mesh_uniform(20, num_points_out)) {
printf("Failed edge meshing\n");
exit(EXIT_FAILURE);
}
First, a straight line evaluator object (StrLineEval) is instantiated. It is a subclass of the pure virtual CMLCurveEval class. It extends from a start point of (0,0,0) to an end point of (1,0,0). After a few lines, a CMLEdgeMesher object is instantiated with the line object as its argument, and it is used to generate a uniform mesh.
double *points = new double[num_points_out*3]; ret_value = edge_mesher.get_mesh(num_points_out, points); if (!ret_value) { printf("Failed getting mesh"); delete [] points; points = NULL; exit(EXIT_FAILURE); }
If mesh generation was successful, memory is allocated to receive the new points. A call to get_mesh() retrieves the points.
// write output file
int num_edges = num_points_out - 1;
if (ret_value) {
int *edges = new int[num_edges*2];
int i;
int k = 0;
for (i = 0; i < num_edges; i++) {
edges[k] = i+1;
edges[k+1] = i+2;
k += 2;
}
ret_value = write_edge_file(num_points_out, points, num_edges, edges);
}
Finally, edges generated from the point indices and the points are written to a file.
The second code snippet shows an example of how to create a curve mesh where the node spacing is biased to one side of curve. This will give the effect of the spacing gradually getting larger or smaller as you move along the curve. The parameters are the number of intervals, the bias factor (the length of each segment will be the length of the previous segment times the bias facor), whether the biasing happens on both ends of the curve, whether the biasing starts at the start of the curve or the end of the curve, and the number of points out.
CMLEdgeMesher edge_mesher(&line); if (!edge_mesher.generate_mesh_biased_ratio(20, 2, false, true, num_points_out)) { printf("Failed edge meshing\n"); exit(EXIT_FAILURE); }
This example is the same before and after this code segment as the first example except that the line extends from (0,0,0) to (2,0,0). The only other difference is the routine called to generate the mesh. Here, CMLEdgeMesher::generate_mesh_biased_ratio() is used instead of CMLEdgeMesher::generate_mesh_uniform().
There are various other ways to specify biasing on the curve mesh. These are described in the CMLEdgeMesher documentation.
CAMAL 5.2-0 documentation created on 1 Jun 2010
Comments to csimsoft.com