FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
ear_surface_glue.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file ear_surface_glue.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-08-18
7 @brief Mirroring & gluing surfaces together.@EOL
8 @std C++23
9 @copyright
10 @parblock
11 Copyright (c) 2024, Mitchell Jay Richling <http://www.mitchr.me/> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 DAMAGE.
29 @endparblock
30 @filedetails
31
32 This example illustrates the same object as ear_surface.cpp, but uses a different strategy to generate the triangulation. For reference, the surface we
33 are interested in is defined by the zeros of the following polynomial:
34
35 @f[ x^2-y^2*z^2+z^3 @f]
36
37 In ear_surface.cpp we used a mesh of cubes covering a 3D region, and extracted the triangulation as a contour surface. In this example, we solve this equation
38 for @f$x@f$ giving us two surfaces:
39
40 @f[ +z\cdot\sqrt{y^2-z} @f]
41 @f[ -z\cdot\sqrt{y^2-z} @f]
42
43 As in the example surface_plot_edge.cpp, we use the NaN solver to flesh the surface out so that it hits the X plane. And as in surface_branch_glue.cpp, we
44 then glue the two surfaces together.
45*/
46/*******************************************************************************************************************************************************.H.E.**/
47/** @cond exj */
48
49////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50#include "MR_rect_tree.hpp"
51#include "MR_cell_cplx.hpp"
52#include "MR_rt_to_cc.hpp"
53
54////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
55typedef mjr::tree15b2d1rT tt_t;
56typedef mjr::MRccT5 cc_t;
57typedef mjr::MR_rt_to_cc<tt_t, cc_t> tc_t;
58
59////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60tt_t::rrpt_t ear_yz(tt_t::drpt_t xvec) {
61 tt_t::src_t y = xvec[0];
62 tt_t::src_t z = xvec[1];
63 tt_t::src_t m = y*y-z;
64 if (m < 0) {
65 return std::numeric_limits<double>::quiet_NaN();
66 } else {
67 return std::sqrt(m)*z;
68 }
69}
70
71////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
72int main() {
73 tt_t tree;
74 cc_t ccplx;
75
76 // Sample a uniform grid across the domain
77 tree.refine_grid(7, ear_yz);
78
79 /* Refine near the edge */
80 tree.refine_recursive_if_cell_vertex_is_nan(8, ear_yz);
81
82 tree.dump_tree(10);
83
84 /* By passing half_sphere() to the construct_geometry_fans() we enable broken edges (an edge with one good point and one NaN) to be repaired. */
85 tc_t::construct_geometry_fans(ccplx,
86 tree,
87 2,
88 {{tc_t::val_src_spc_t::FRANGE, 0},
89 {tc_t::val_src_spc_t::FDOMAIN, 0},
90 {tc_t::val_src_spc_t::FDOMAIN, 1}},
91 ear_yz
92 );
93
94 ccplx.create_named_datasets({"y", "z", "x=f(x,z)"});
95
96 /* This is the magic. We add new cells with the third element of each point data vector negated. */
97 ccplx.mirror({0, 0, 1}, 1.0e-5);
98
99 ccplx.dump_cplx(10);
100
101 ccplx.write_xml_vtk("ear_surface_glue.vtu", "ear_surface_glue");
102}
103/** @endcond */
int main()