### C++ Main Function for Surface Meshing Example Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/markdowns/cm2_triamesh_quadmesh_tutorials.md This C++ code demonstrates the setup for meshing a specific parametric surface using the 'surface' class. It initializes surface parameters, registers mesh libraries, defines the surface boundary points, and applies initial meshing to the contour. ```cpp 111 int main() { | const | DoubleVec2 | PO(0. , -0.5) | ; | --- | --- | --- | --- | | const | DoubleVec2 | P1(1 · , -0.5) | ; | const | DoubleVec2 | P2(1 . , +0.5) ; | | const | DoubleVec2 | P3(0 · , +0.5) ; | | DoubleMat | | pos; | | UIntVec | | indicesG, indices; | | DoubleVec | | Us; | | UIntMat | | connectE2, connectM; | | DoubleVec | | sizesG, sizes; | | const | double | Lx (10.) ; | | const | double | Ly(6.0) ; | | const | double | h0 (0.25) ; | | surface | | S(Lx, Ly, 0.5) ; 11 The parametric surface to be | meshed. 11 UNLOCK THE DLLs. triamesh_aniso: :registration("Licensed to SMART Inc. " "B657DA67QZ01") ; , triamesh_iso: : registration("Licensed to SMART Inc. " "F53EA108BCWX") ; , pos . push_back(P0) ; pos · push_back (P1) ; pos · push_back (P2) ; pos . push_back (P3) ; 11 GEOMETRIC SUPPORT FOR THE EXTERNAL CONTOUR. meshtools1d : : mesh_straight(pos, ⊙ , 1, 1 . /100 · , 1. /100 · , false, indicesG) ; indicesG.pop_back() ; meshtools1d: : mesh_straight(pos, 1, 2, 1 · /100 · , 1 . /100 · , false, indicesG) ; indicesG.pop_back() ; ``` -------------------------------- ### Include Headers and Setup Namespace Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/markdowns/cm2_surfremesh_tutorials.md Includes necessary headers for CM2 mesh tools and surface remeshing, and sets up the CM2 namespace for easier access to library functions. This is a common setup for CM2 SurfRemesh applications. ```cpp #include "meshtools.h" #include "surfremesh_t3.h" #include "surfremesh_q4.h" using namespace cm2; ``` -------------------------------- ### Example Usage: Generating Quadratic Elements Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/markdowns/cm2_surfmesh_tutorials.md A C++ code example demonstrating how to configure and run the mesher to generate quadratic elements with specific settings. ```APIDOC ## Mesher Configuration Example ### Description This example shows how to set up the `surfmesh_q4::mesher` to generate T6/Q9 elements with a target chordal error and element size. ### Code Snippet ```cpp #include "stdafx.h" #include // Assuming necessary headers and namespaces are included/defined elsewhere // using namespace surfmesh_q4; // using namespace meshtools2d; static void display_hdl (void*, unsigned, const char* msg) { std::cout << msg; } int main() { surfmesh_q4::mesher the_mesher; surfmesh_q4::mesher::data_type data; // UNLOCK THE DLL (Example license string) surfmesh_q4::registration("Licensed to SMART Inc · "F5BEA10ABCWX"); // DEFINE SETTINGS AND RUN THE MESHER. the_mesher.settings.high_order_type = 2; // T6/Q9 elements the_mesher.settings.max_chordal_error = -0.40; // Target max distance of 2% the_mesher.settings.target_h = 0.006; // Element size setting the_mesher.run("bearing.iges", data); // Run mesher on input file // SOME OUTPUT INFO (OPTIONAL) data.print_info(&display_hdl); // VISUALIZATION (OPTIONAL) UIntMat connectM; connectM.copy(data.connectM); meshtools2d::convert_into_linear(connectM_); // MEDIT can't process quadratic elements. meshtools::medit_output("out.mesh", data.pos, connectM_, CM2_FACE_MIX, data.colors); return 0; } ``` ### Explanation - `the_mesher.settings.high_order_type = 2;` configures the mesher to generate 6-node triangles (T6) and 9-node quadrangles (Q9). - `the_mesher.settings.max_chordal_error = -0.40;` sets the maximum allowed chordal error, aiming for a 2% distance. - `the_mesher.settings.target_h = 0.006;` specifies a target element size. - `data.print_info(&display_hdl);` prints mesh information using a provided display handler. - For visualization with MEDIT, quadratic elements are converted to linear using `meshtools2d::convert_into_linear` before outputting to `out.mesh`. ``` -------------------------------- ### Main Meshing and Node Merging Example Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_triamesh_quadmesh_tutorials.html This C++ example demonstrates setting up geometric points, defining contours, meshing segments, merging duplicated nodes, running the 2D mesher, and outputting the result to a MEDIT file. It handles shared boundaries by merging nodes before the main 2D meshing process. ```cpp int main() { const DoubleVec2 PO (0., 0.), P1(10. , 0.), P2(10. , 2.) , P3(8. , 2.) ; const DoubleVec2 P4 (2. , 2.), P5(0. , 2.) , P6(10. , 10. ) , P7(0. , 10.) ; const DoubleVec2 P8 (2., 8.) , P9 (8. , 8.) ; const unsigned N(4) ; DoubleMat pos; UIntMat connectB; 11 UNLOCK THE DLL. triamesh_iso::registration("Licensed to SMART Inc. " "F53EA108BCWX") ; 11 VERTICES POINTS. pos . push_back (PO) ; pos . push_back(P1) ; pos . push_back (P2) ; pos . push_back (P3) ; pos . push_back (P4) ; pos . push_back(P5) ; pos . push_back (P6) ; pos . push_back (P7) ; pos . push_back(P8) ; pos . push_back (P9) ; 11 BOTTOM RECTANGLE POSITIVE (I.E. COUNTER-CLOCKWISE) · mesh_segment (pos, connectB, 日, 1, N) ; mesh_segment(pos, connectB, 1, 2, N) ; mesh_segment (pos, connectB, 2, 3, N) ; mesh_segment (pos, connectB, 3, 4, N) ; mesh_segment(pos, connectB, 4, 5, N) ; mesh_segment(pos, connectB, 5, 日, N) ; 11 TOP HORSE-SHOE POSITIVE (I. E. COUNTER-CLOCKWISE) · mesh_segment (pos, connectB, 2, 6, N) ; mesh_segment(pos, connectB, 6, 7, N) ; mesh_segment (pos, connectB, 7, 5, N) ; mesh_segment (pos, connectB, 5, 4, N) · mesh_segment (pos, connectB, 4, 8, N) · mesh_segment (pos, connectB, 8, 9, N) ; mesh_segment(pos, connectB, 9, 3, N) ; mesh_segment (pos, connectB, 3, 2, N) ; 11 INNER SQUARE POSITIVE (I. E. COUNTER-CLOCKWISE) · mesh_segment (pos, connectB, 3, 9, N) ; mesh_segment(pos, connectB, 9, 8, N) ; mesh_segment (pos, connectB, 8, 4, N) ; mesh_segment (pos, connectB, 4, 3, N) ; 11 MERGE TOGETHER DUPLICATED NODES. meshtools::merge (pos, connectB, /*tol=>*/ 1E-6, /*merge_type=>*/ 0) ; 11 THE 2D MESH. triamesh_iso::mesher the_mesher; triamesh_iso::mesher::data_ type data (pos, connectB) ; the_mesher .run(data) ; 11 VISUALIZATION. meshtools::medit_output("out.mesh" , data.pos, data.connectM, CM2_FACET3) ; return 0; 11 main } ``` -------------------------------- ### Example Mesher Initialization and Run - C++ Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/structcm2_1_1triamesh__aniso_1_1mesher_1_1settings__type.html Demonstrates how to initialize the mesher, set custom display and pass-through handlers, and then run the meshing process. This example shows associating a 'window_type' instance with the mesher callbacks. ```cpp // Assuming mesher, data_type, and window_type are defined elsewhere // mesher my_mesher; // data_type my_mesh_data(pos, connectB); // window_type my_window; // A window instance. // my_mesher.settings.display_hdl = &my_display_hdl; // Assuming my_display_hdl is defined // my_mesher.settings.pass_thru = static_cast(&my_window); // my_mesher.run(my_mesh_data); // Will call my_display_hdl if set ``` -------------------------------- ### Example Display Handler Implementation Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_triamesh_quadmesh_reference_manual.html Provides an example implementation of a display handler function. This function casts the pass-through pointer to a window type and calls its 'show' method to display the message. It's intended for user-defined message handling during meshing. ```c++ void my_display_handler (void* pass_thru, unsigned level, const char* msg) { window_type* my_window = static_cast(pass_thru); my_window->show(msg); } ``` -------------------------------- ### Initialize and Run Quadmesh Iso Mesher Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/structcm2_1_1quadmesh__iso_1_1mesher_1_1settings__type.html This snippet demonstrates how to initialize a quadmesh_iso mesher, configure its settings, and run the meshing process with provided data. It shows the instantiation of the mesher, data structure, and the assignment of a display handler and pass-through pointer to the mesher's settings before executing the run method. ```C++ window_type* my_window = static_cast([pass_thru](#a84ecbb784cfeaa0793e4527d641dafe4)); my_window->show(msg); } [mesher](classcm2_1_1quadmesh__iso_1_1mesher.html#a07f528772a72f2806703ccb6aea82ab8) my_mesher; [data_type](structcm2_1_1quadmesh__iso_1_1mesher_1_1data__type.html) my_mesh_data(pos, connectB); window_type my_window; // A window instance. my_mesher.[settings](classcm2_1_1quadmesh__iso_1_1mesher.html#af47212543d21687f29fff5ae01525d94).[display_hdl](#a126a43f094797a58856ca97850906143) = &my_display_hdl; my_mesher.[settings](classcm2_1_1quadmesh__iso_1_1mesher.html#af47212543d21687f29fff5ae01525d94).[pass_thru](#a84ecbb784cfeaa0793e4527d641dafe4) = static_cast(&my_window); my_mesher.[run](classcm2_1_1quadmesh__iso_1_1mesher.html#a23163417dc5cd2125573065bacc060b5)(my_mesh_data); // Will call my_display_hdl. ``` -------------------------------- ### Get Input Skeleton Edges for 2D Remesher Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3dr01_8cpp-example.html Provides a matrix of skeleton edges that can be used to force specific partitioning in the 2D remeshing algorithm. This input helps guide the remeshing process. ```cpp UIntMat skeleton_edges_in ``` -------------------------------- ### get_sorted_order Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/namespacecm2_1_1meshtools.html Gets the order of elements based on their values and the starting indices for each distinct value. ```APIDOC ## get_sorted_order ### Description Gets the order of elements according to their values. This function is useful for gathering elements by similar color (subdomain) in mesh generation. ### Method Not applicable (function signature) ### Endpoint Not applicable (function signature) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (0) Returns 0 on success. #### Response Example ``` 0 ``` ### Error Handling Returns a negative value in case of error. Returned value = -k => the k-th argument had an illegal value. ### Postcondition `order.size()` == `values.size()`. `xOrder.size()` == max value in `values` + 1. ``` -------------------------------- ### Initialize Mesher and Data Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_triamesh_quadmesh_reference_manual.html Demonstrates the initialization of the CM2 mesher and its associated data structure. This setup is necessary before calling the meshing functions, and it includes the creation of a window object for display handling. ```c++ cm2::triamesh_iso::mesher my_mesher; cm2::triamesh_iso::mesher::data_type my_data(pos, connectB); window_type my_window; // A “window” instance. ``` -------------------------------- ### cm2::meshtools::unique_indices Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3d24_8cpp-example.html Gets the unique values in a vector of indices. This utility function is useful for data cleaning and processing. ```APIDOC ## POST /meshtools/unique_indices ### Description Gets the unique values in a vector of indices. ### Method POST ### Endpoint /meshtools/unique_indices ### Parameters #### Request Body - **indices_src** (UIntVec) - Required - The input vector of indices. - **remove_indices** (UIntVec) - Optional - A vector of indices to remove before finding unique values. Defaults to an empty vector. ### Request Example ```json { "indices_src": [1, 2, 2, 3, 4, 4, 4], "remove_indices": [2, 4] } ``` ### Response #### Success Response (200) - **indices_tar** (UIntVec) - The vector containing unique indices. #### Response Example ```json { "indices_tar": [1, 3] } ``` ``` -------------------------------- ### Initialize and Configure Mesher (C++) Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_tetramesh_tutorials.html Initializes the CM2 mesher and sets up data structures for meshing operations. This code snippet demonstrates the initial setup, including unlocking the software license and preparing the boundary mesh for a background mesh calculation. It sets up a cube boundary with a specified number of background mesh elements. ```C++ int main() { const double L(4.), h0(0.5), h1(0.1); DoubleMat pos; UIntVec indices; UIntMat connectB1, connectB2, BGM, connectM2; DoubleVec sizes; unsigned N, N_BGM, n; double w, h; tetramesh_iso::mesher the_mesher; tetramesh_iso::mesher::data_type dataTH; // UNLOCK THE DLL. tetramesh_iso::registration("Licensed to SMART Inc.", "F53EA108BCWX"); // THE BOUNDARY OF THE BACKGROUND MESH N_BGM = unsigned(std::max(L/h0, L/h1)); cube_boundary(L, N_BGM, pos, connectB1); ``` -------------------------------- ### Get Input Colors from 2D Remesher Data Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3dr01_8cpp-example.html Retrieves the patch IDs (colors) of the initial elements before remeshing. This information is stored as a UIntVec. ```cpp UIntVec colors_in ``` -------------------------------- ### C++ Example: Setting Up and Running Mesher with Progress Handler Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_surfremesh_reference_manual.html Demonstrates initializing the CM2 mesher and setting up a progress bar interrupt handler. The pass_thru parameter is used to pass a pointer to the window instance for displaying progress. ```cpp cm2::surfremesh_t3::mesher my_mesher; cm2::surfremesh_t3::mesher::data_type my_data(pos, connectB); window_type my_window; // A window instance. my_window.init(...); // Initialize the window somehow. my_mesher.settings.interrupt_hdl = &my_interrupt_handler; my_mesher.settings.pass_thru = static_cast(&my_window); my_mesher.run(my_data); // Will call my_interrupt_handler with “my_window” // in pass_thru parameter. ``` -------------------------------- ### Get 3D Surface Remesher Settings (surfremesh_t3) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3dr01_8cpp-example.html Retrieves the settings for the 3D surface remesher. These settings control the behavior and parameters of the remeshing process. ```cpp settings_type settings ``` -------------------------------- ### Initialize and Run Triamesh Iso Mesher Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh2d09b_8cpp-example.html This snippet demonstrates how to initialize mesh data, set mesher properties, and run the meshing process. It involves assigning vertex positions and connectivity information, then executing the mesher to generate the mesh. ```cpp meshtools1d::indices_to_connectE2(indices, connectE2); // THE 2-D MESH. { data.pos = pos; data.connectB = connectE2; mesher.run(data); data.print_info(&display_hdl); data.extract(pos, connectM); print_footer(data.nods, data.nefs, data.total_time, data.speed); } // OUTPUT FOR VISUALISATION. meshtools::vizir_output("T3.mesh", pos, connectM, CM2_FACET3); ``` -------------------------------- ### Get Input Skeleton Colors for 2D Remesher Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3dr01_8cpp-example.html Retrieves the skeleton line IDs (colors) of the input skeleton edges before remeshing. This information is stored as a UIntVec. ```cpp UIntVec skeleton_colors_in ``` -------------------------------- ### CM2 QuadMesh Iso Mesher Execution and Data Handling Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh2d01_8cpp-example.html Details on running the mesher and accessing its output data. ```APIDOC ## CM2 QuadMesh Iso Mesher Execution and Data ### Description This section covers the execution of the mesher and how to retrieve and utilize the generated mesh data. ### Method N/A (Execution and data access via member functions) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## `cm2::quadmesh_iso::mesher::run` ### Description Initiates the meshing process using the configured settings and provided data. ### Method `void run(data_type &data) const` ### Endpoint N/A ## `cm2::quadmesh_iso::mesher::data_type` ### Description Structure holding the mesh data generated by the `quadmesh_iso::mesher`. ### Fields - **`nods`** (unsigned): Number of nodes in the final mesh. - **`nefs`** (unsigned): Number of elements in the final mesh. - **`print_info(display_handler_type hdl)`**: Prints mesh information using a display handler. - **`extract(pos, connectM)`**: Extracts mesh data into `pos` and `connectM`. - **`total_time`** (double): Total time taken for meshing. - **`speed`** (double): Meshing speed in elements per second. ## Outputting Mesh Data ### Description Functions for outputting the generated mesh data into different file formats. ### Functions - **`meshtools::vizir_output(filename, pos, connectM, FE_type)`**: Outputs mesh data to a Vizir file. - **`meshtools::vtk_output(filename, pos, connectM, FE_type)`**: Outputs mesh data to a VTK file. ### Example Usage ```cpp char filename[64]; // Output for Vizir ::strcpy(filename, mesh_type); ::strcat(filename, ".mesh"); meshtools::vizir_output(filename, pos, connectM, FE_type); // Output for VTK ::strcpy(filename, mesh_type); ::strcat(filename, ".vtk"); meshtools::vtk_output(filename, pos, connectM, FE_type); ``` ``` -------------------------------- ### Get Number of Columns in Dense 2D Container (C++) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh2db06_8cpp-example.html Returns the number of columns in a `dense2D` container. This is a const member function, meaning it does not modify the state of the object. ```cpp size_type cols() const ``` -------------------------------- ### Anisotropic Meshing Setup in C++ Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_tetramesh_tutorials.html This C++ code demonstrates the setup and execution of anisotropic 3D meshing using the tetramesh_aniso library. It involves defining mesh parameters, creating boundary meshes via extrusion and translation, defining anisotropic metrics, and finally running the mesher. The code includes setting up the mesher, providing mesh data including connectivity and metrics, and extracting the resulting mesh. ```C++ #include "stdafx.h" int main() { const double L0(10.), L1(100.); const unsigned N0(10), N1(10); DoubleMat pos; UIntVec indices; UIntMat connectE, connectB1, connectB2, connectB; UIntMat connectM, connectM2; DoubleMat metrics; double D0, D1; // UNLOCK THE DLL. tetramesh_aniso::registration("Licensed to SMART Inc.","F53EA108BCWX"); // BOUNDARY 2D MESH. meshtools2d::extrude_translate(pos, DoubleVec3(0.), DoubleVec3(0., L0, 0.), N0, indices); meshtools2d::indices_to_connectE2(indices, connectE); meshtools2d::extrude_translate_T3(pos, connectE, DoubleVec3(L0, 0., 0.], N0, 2, connectB); meshtools::copy_mesh(pos, connectB1, connectB); meshtools2d::flip_T3(connectB1); meshtools::translate(pos, DoubleVec3(0., 0., L1), connectB1); connectB.push_back(connectB1); connectB1.clear(); meshtools2d::extrude_translate_T3(pos, connectE, DoubleVec3(0., 0., L1), N1, 2, connectB1); meshtools::copy_mesh(pos, connectB2, connectB1); meshtools::rotate(pos, DoubleVec3(L0/2, L0/2, L1/2), DoubleVec3(0,0,M_PI/2), connectB2); connectB1.push_back(connectB2); meshtools::copy_mesh(pos, connectB2, connectB1); meshtools::rotate(pos, DoubleVec3(L0/2, L0/2, L1/2), DoubleVec3(0., 0., M_PI), connectB2); connectB1.push_back(connectB2); connectB.push_back(connectB1); meshtools::merge(pos, connectB, /*tol=>*/ 1E-6, /*merge_type=>*/ 0); // METRICS. metrics.resize(6, pos.cols(), 0.); D0 = 1. / ((L0 / N0) * (L0 / N0)); D1 = 1. / ((L1 / N1) * (L1 / N1)); for (size_t n = 0; n < pos.cols(); ++n) { metrics(0,n) = D0; // Mxx metrics(1,n) = 0.0; // Mxy metrics(2,n) = D0; // Myy = Mxx metrics(3,n) = 0.0; // Mxz metrics(4,n) = 0.0; // Myz metrics(5,n) = D1; // Mzz } // 3D MESH. tetramesh_aniso::mesher the_mesher; tetramesh_aniso::mesher::data_type data(pos, connectB); the_mesher.settings.compute_Qh_flag = true; data.metrics = metrics; the_mesher.run(data); data.extract(pos, connectM); data.print_info(&display_hdl); // MESH VISUALISATION. meshtools::clip(pos, connectM, DoubleVec3(L0/2 +1E-6, L0/2 +1E-6, 0.], ``` -------------------------------- ### Get Number of Triangles in Final Mesh (2D Remesher) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3dr01_8cpp-example.html Retrieves the total number of triangular elements present in the final mesh generated by the 2D remesher. This is stored as an unsigned integer. ```cpp unsigned nefs_T3 ``` -------------------------------- ### Quadmesh Iso Mesher Operations Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh2d03_8cpp-example.html This snippet illustrates the process of using the quadmesh iso mesher. It covers initializing data, setting metrics, configuring mesher settings for all-quad or mixed meshes, enabling background mesh and Qh flags, running the mesher, and extracting results. ```cpp cm2::quadmesh_iso::mesher::data_type data(pos, connectE2); data.isolated_nodes.push_back(4); // The node at center. data.metrics = sizes; quadmesher.settings.all_quad_flag = (FE_type == CM2_FACEQ4); quadmesher.settings.use_default_background_mesh_flag = use_background_mesh; quadmesher.settings.compute_Qh_flag = true; quadmesher.run(data); data.print_info(&display_hdl); data.extract(pos, connectM); print_footer(data.nods, data.nefs, data.total_time, data.speed); ``` -------------------------------- ### Get Number of Quads in Final Mesh (2D Remesher) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3dr01_8cpp-example.html Retrieves the total number of quadrilateral elements present in the final mesh generated by the 2D remesher. This is stored as an unsigned integer. ```cpp unsigned nefs_Q4 ``` -------------------------------- ### C++: Create Background Mesh and Size Map for Meshing Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_triamesh_quadmesh_tutorials.html This C++ code demonstrates how to set up a background mesh and a corresponding size map for the CM2 meshing library. It initializes vertices, creates a structured background mesh, calculates node sizes based on a sinusoidal function, and then runs the mesher. Finally, it outputs the resulting mesh to a file. ```cpp #include "stdafx.h" int main() { const double L(4.), h0 (0. 25) , h1 (0. 05) ; DoubleMat pos; UIntVec indices; UIntMat connectE2, connectT3, BGM; DoubleVec sizes; unsigned n; double W, h; // UNLOCK THE DLL. triamesh_iso::registration("Licensed to SMART Inc. " "F53EA108BCWX"); // VERTICES AND LINE MESHES. pos.push_back(DoubleVec2(-L/2, -L/2)); pos.push_back(DoubleVec2 (+L/2, -L/2)); pos.push_back(DoubleVec2 (+L/2, +L/2)); pos.push_back(DoubleVec2 (-L/2, +L/2)); meshtools1d::mesh_straight(pos, 0, 1, h0, h0, true, indices); indices.pop_back(); meshtools1d::mesh_straight(pos, 1, 2, h0, h0, true, indices); indices.pop_back(); meshtools1d::mesh_straight(pos, 2, 3, h0, h0, true, indices); indices.pop_back(); meshtools1d::mesh_straight(pos, 3, 0, h0, h0, true, indices); meshtools1d::indices_to_connectE2(indices, connectE2); // THE BACKGROUND MESH. n = unsigned(L/h1); indices.clear(); meshtools1d::mesh_straight(pos, 0, 1, n, indices); indices.pop_back(); meshtools1d::mesh_straight(pos, 1, 2, n, indices); indices.pop_back(); meshtools1d::mesh_straight(pos, 2, 3, n, indices); indices.pop_back(); meshtools1d::mesh_straight(pos, 3, 0, n, indices); meshtools2d::mesh_struct_T3(pos, indices, n, true, BGM); // THE METRICS ON THE BACKGROUND MESH. indices.clear(); meshtools::unique_indices(indices, BGM); sizes.resize(pos.cols(), 0.); // Null value for nodes not in BGM. for (size_t i = 0; i < indices.size(); ++i) { n = indices[i]; W = std::max(std::fabs(pos(0, n)), L / 2.); h = std::cos(8. * M_PI * W / L) * (h0 - h1) / 2. + (h0 + h1) / 2.; sizes[n] = h; } // THE 2D MESH. triamesh_iso::mesher the_mesher; triamesh_iso::mesher::data_type data(pos, connectE2); data.background_mesh = BGM; data.metrics = sizes; the_mesher.run(data); // VISUALIZATION. meshtools::medit_output("out.mesh", data.pos, data.connectM, CM2_FACET3); return 0; } // main ``` -------------------------------- ### Get Skeleton Colors from 2D Remesher Data Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3dr01_8cpp-example.html Retrieves the skeleton line IDs (colors) of the skeleton edges in the final mesh generated by the 2D remesher. This information is stored as a UIntVec. ```cpp UIntVec skeleton_colors ``` -------------------------------- ### Retrieve Element Counts and Print Info Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3dr01_8cpp-example.html Gets the number of Q4 and T3 elements and prints mesh information. This provides a summary of the mesh's topological composition and performance metrics. ```cpp nq = dataR.nefs_Q4(); nt = dataR.nefs_T3(); dataR.print_info(&display_hdl); print_footer(dataR.nods(), dataR.nefs(), dataR.total_time(), dataR.speed()); ``` -------------------------------- ### C++ Mesher Initialization and Execution Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_triamesh_quadmesh_reference_manual.html This C++ code demonstrates the basic initialization and execution of a CM2 mesher. It sets up display and pass-through handlers and then calls the run method with mesh data. The example highlights how the display handler and interrupt handler (if set) are invoked during the meshing process. ```cpp my_window.init(...); // Initialize the window somehow. my_mesher.settings.display_hdl = &my_display_handler; my_mesher.settings.pass_thru = static_cast(&my_window); my_mesher.run(my_data); // Will call my_display_hdl with “my_window” // in pass_thru parameter. ``` -------------------------------- ### Initialize and Run Triamesh Iso Mesher Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh2di07_8cpp-example.html Initializes a triamesh_iso mesher with position and connectivity data, sets subdomain forcing, runs the meshing process, and prints information about the generated mesh. ```cpp cm2::triamesh_iso::data_type dataT3(pos, connectE2); mesherT3.settings.subdomains_forcing = +1; mesherT3.run(dataT3); dataT3.print_info(&display_hdl); ``` -------------------------------- ### Get beginning segment iterator for symmetric_fixed (C++) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/math1/html/symmetric__fixed_8h_source.html This function returns an iterator pointing to the beginning of the segments in the symmetric_fixed matrix. It constructs a segment_type object starting at index 0. ```C++ INLINE segment_type seg_begin() { return segment_type(*this, 0); } ``` -------------------------------- ### Get Number of Nodes (C++) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/structcm2_1_1surfmesh__q4_1_1mesher_1_1data__type.html Returns the total number of nodes in the final mesh. This is an unsigned integer output. It is defined in surfmesher_q4.h and an example is available in tmsh3ds01.cpp. ```cpp unsigned cm2::surfmesh_q4::mesher::data_type::nods // Number of nodes in the final mesh. // Mode = OUT. // Examples tmsh3ds01.cpp // Definition at line 843 of file surfmesher_q4.h. ``` -------------------------------- ### Get constant beginning segment iterator for symmetric_fixed (C++) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/math1/html/symmetric__fixed_8h_source.html This const function returns a constant iterator pointing to the beginning of the segments. It creates a const_segment_type object starting at index 0. ```C++ INLINE const_segment_type seg_begin() const { return const_segment_type(*this, 0); } ``` -------------------------------- ### Initialize CM2 MeshTools SDK and Search Functionality Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh2db02_8cpp-example.html Initializes the search box and code folding functionalities for the CM2 MeshTools SDK documentation. It also sets up the search functionality and navigates the initial menu. ```javascript var searchBox = new SearchBox("searchBox", "search/",'.html'); $(function() { codefold.init(); }); $(function() { initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); }); $(function(){initNavTree('tmsh2db02_8cpp-example.html','',''); }); ``` -------------------------------- ### C++ Example: 3D Mesher with Background Mesh Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/tmsh3d24_8cpp-example.html This C++ code snippet demonstrates how to utilize the cm2::tetramesh_iso::mesher for 3D tetrahedral meshing. It shows the setup and execution process, including defining a background mesh and applying custom size metrics derived from it. The function takes parameters for cube side length, mesh size variations, and cycles between boundaries and the center. ```C++ #include "stdafx.h" #include "tests\_tmsh3d.h" /* This is an example of background mesh with the tetra mesher. Here, the background mesh covers the whole domain and supports a sinus variation of the metric in the three directions. \param[in] L Side length of the cube. \param[in] h0 Mesh size max. \param[in] h1 Mesh size min. \param[in] W Number of size cycles between outer boundary and centre. */ void TMSH3D24::run (double L, double h0, double h1, unsigned W) { const unsigned N(unsigned(L/h0)); // The discretization for the outer surface. const unsigned N_BGM(unsigned(std::max(L/h0, L/h1))); // The discretization for the background mesh. DoubleMat pos; UIntVec indices; UIntMat connectS1, connectS2, BGM; DoubleVec sizes; size_t n; double w, h; [cm2::tetramesh_iso::mesher](classcm2_1_1tetramesh__iso_1_1mesher.html) mesher; [cm2::tetramesh_iso::mesher::data_type](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html) dataTH; print_header("TMSH3D24 - CUBE WITH BACKGROUND MESH"); // THE BACKGROUND MESH. [cm2::meshtools2d::mesh_parallelepiped_T3](namespacecm2_1_1meshtools2d.html#a06d3bece83b9a88b455b107e3dbe146b)(pos, DoubleVec3(-0.5*L), DoubleVec3(+0.5*L), // Cube centered at (0, 0, 0). N_BGM, N_BGM, N_BGM, /*pattern=>*/ 2, connectS1); dataTH.[pos](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#ac877fec692b8b1526ee912f47b875a09) = pos; dataTH.[connectB](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#ac50adee88ade8ec539e71ef944304b9b) = connectS1; mesher.[run](classcm2_1_1tetramesh__iso_1_1mesher.html#a836210cd008c652b8e8ec0bf597f5083)(dataTH); dataTH.[print_info](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#a7ff3ae03baf0f39ecffacea42d5484b7)(&display_hdl); dataTH.[extract](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#a70b5c48dd2f31db7b6e51fb28c2f0443)(pos, BGM); // THE METRICS ON THE BACKGROUND MESH. [cm2::meshtools::unique_indices](namespacecm2_1_1meshtools.html#a921327fd4efdd055ce60ad1a9008ab22)(indices, BGM); sizes.resize(pos.cols(), 0.); for (size_t i = 0; i < indices.size(); ++i) { n = indices[i]; w = vecscal::max_norm(pos.seg(n)); h = 0.5*(h0+h1) + ::cos(4.*M_PI*W*w/L) * 0.5*(h0-h1); sizes[n] = h; } // THE BOUNDARY TRIANGLE MESH. [cm2::meshtools2d::mesh_parallelepiped_T3](namespacecm2_1_1meshtools2d.html#a06d3bece83b9a88b455b107e3dbe146b)(pos, DoubleVec3(-0.5*L), DoubleVec3(+0.5*L), // Cube centered at (0, 0, 0). N, N, N, /*pattern=>*/ 2, connectS2); // THE 3-D MESH. dataTH.[pos](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#ac877fec692b8b1526ee912f47b875a09) = pos; dataTH.[connectB](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#ac50adee88ade8ec539e71ef944304b9b) = connectS2; dataTH.[background_mesh](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#a289500f6c94328c01135f18569af69fd) = BGM; dataTH.[metrics](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#a92fad6796ae88fe04e03928a58de48ee) = sizes; mesher.[settings](classcm2_1_1tetramesh__iso_1_1mesher.html#a4d0d7851cf34da7c3113de0715cef0fa).[compute_Qh_flag](structcm2_1_1tetramesh__iso_1_1mesher_1_1settings__type.html#abcea710bd4b9d17727911f6d87a32137) = true; mesher.[run](classcm2_1_1tetramesh__iso_1_1mesher.html#a836210cd008c652b8e8ec0bf597f5083)(dataTH); dataTH.[print_info](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#a7ff3ae03baf0f39ecffacea42d5484b7)(&display_hdl); // OUTPUT FOR VISUALISATION UIntMat connectTH; [cm2::meshtools::clip](namespacecm2_1_1meshtools.html#a04c247e337b30b596c89eaa387606a10)(dataTH.[pos](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#ac877fec692b8b1526ee912f47b875a09), dataTH.[connectM](structcm2_1_1tetramesh__iso_1_1mesher_1_1data__type.html#ab537a0591aabc6032626e8395569b30e), DoubleVec3(-1E-6), DoubleVec3(0., 0., -1), connectTH); // clip out Z > 0 ``` -------------------------------- ### Get Number of Triangular Elements (C++) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/structcm2_1_1surfmesh__q4_1_1mesher_1_1data__type.html Returns the number of triangular elements in the final mesh. This is an unsigned integer output. It is defined in surfmesher_q4.h and an example is available in tmsh3ds01.cpp. ```cpp unsigned cm2::surfmesh_q4::mesher::data_type::nefs_T // Number of triangles in the final mesh. // Mode = OUT. // Examples tmsh3ds01.cpp // Definition at line 836 of file surfmesher_q4.h. ``` -------------------------------- ### C++: Initialize and Run CM2 SurfMesh T3/Q4 Mesher Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_surfmesh_tutorials.html Initializes the CM2 SurfMesh T3/Q4 mesher, sets meshing parameters (fix_tolerance, min_h, target_h), runs the mesher on an IGES file, and prints mesh information. The display_hdl function is used for optional output. This code demonstrates basic meshing setup and execution. ```cpp #include "stdafx.h" #include // Simple optional display handler. static void display_hdl (void*, unsigned, const char* msg) { std::cout << msg; } int main() { surfmesh_t3::mesher the_mesher; surfmesh_t3::mesher::data_type data; // UNLOCK THE DLL. surfmesh_t3::registration("Licensed to SMART Inc. " "F5BEA10ABCWX"); , // DEFINE SETTINGS AND RUN THE MESHER. the_mesher.settings.fix_tolerance = 5E-6; // Absolute val. the_mesher.settings.min_h = -0.1; // Relative val. the_mesher.settings.target_h = 0.003; the_mesher.run("bearing.iges" , data); // SOME OUTPUT INFO (OPTIONAL) . data.print_info(&display_hdl); // VISUALIZATION (OPTIONAL) . meshtools::medit_output("out.mesh" , data.pos, data.connectM, CM2_FACET3); return 0; } // main ``` -------------------------------- ### Get Number of Quadrilateral Elements (C++) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/structcm2_1_1surfmesh__q4_1_1mesher_1_1data__type.html Returns the number of quadrilateral elements in the final mesh. This is an unsigned integer output. It is defined in surfmesher_q4.h and an example is available in tmsh3ds01.cpp. ```cpp unsigned cm2::surfmesh_q4::mesher::data_type::nefs_Q // Number of quads in the final mesh. // Mode = OUT. // Examples tmsh3ds01.cpp // Definition at line 829 of file surfmesher_q4.h. ``` -------------------------------- ### Initialize and Run Mesher with STEP File Source: https://github.com/soilspoon/cm2-doc/blob/main/manuals/htmls/cm2_surfmesh_tutorials.html This C++ code snippet demonstrates how to initialize the CM2 mesher, set a target mesh size, disable chordal error control, and run the meshing process on a STEP file. It also includes optional steps for printing mesh information and exporting the mesh to MEDIT format. ```C++ #include "stdafx.h" #include #include #include // Simple optional display handler. static void display_hdl (void*, unsigned, const char* msg) { std::cout << msg; } int main() { surfmesh_t3::mesher the_mesher; surfmesh_t3::mesher::data_type data; // UNLOCK THE DLL. surfmesh_t3::registration("Licensed to SMART Inc. " "F5BEA10ABCWX"); // DEFINE SETTINGS AND RUN THE MESHER. the_mesher.settings.target_h = 0.2; the_mesher.settings.chordal_control_type = 0; // Disable chordal error control. the_mesher.run("link_rod.step" , data); // SOME OUTPUT INFO (OPTIONAL) . data.print_info(&display_hdl); // VISUALIZATION (OPTIONAL) . meshtools::medit_output("out.mesh" , data.pos, data.connectM, CM2_FACET3); return 0; } // main ``` -------------------------------- ### Get Number of Mesh Elements (C++) Source: https://github.com/soilspoon/cm2-doc/blob/main/doc/meshtools/html/structcm2_1_1surfmesh__q4_1_1mesher_1_1data__type.html Returns the total number of elements in the final mesh. This is an unsigned integer output. It is defined in surfmesher_q4.h and an example is available in tmsh3ds01.cpp. ```cpp unsigned cm2::surfmesh_q4::mesher::data_type::nefs // Number of elements in the final mesh. // Mode = OUT. // Examples tmsh3ds01.cpp // Definition at line 822 of file surfmesher_q4.h. ```