FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
surface_branch_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 surface_branch_glue.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-07-16
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 In surface_plot_edge.cpp we encountered the unit sphere defined by the zeros of @f$1^2=x^2+y^2+z^2@f$, and the related function
33 @f$f(x,y)=\sqrt{1-x^2-y^2}@f$ obtained by "solving" for @f$z@f$. Note that if @f$z=f(x, y)@f$, then both @f$z@f$ and @f$-z@f$ satisfy the original equation.
34 While the square root function is positive by definition, we might wish to think of @f$f(x, y)@f$ as a multi-valued function with two branches -- a
35 positive one and a negative one.
36
37 In simple cases like this, where the two branches are reflections across an axis plane, we can use MR_cell_cplx::mirror() to mirror the geometry and seal up
38 any holes. This is really the only change from surface_plot_edge.cpp.
39
40*/
41/*******************************************************************************************************************************************************.H.E.**/
42/** @cond exj */
43
44////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45#include "MR_rect_tree.hpp"
46#include "MR_cell_cplx.hpp"
47#include "MR_rt_to_cc.hpp"
48
49////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50typedef mjr::tree15b2d1rT tt_t;
51typedef mjr::MRccT5 cc_t;
52typedef mjr::MR_rt_to_cc<tt_t, cc_t> tc_t;
53
54////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
55tt_t::rrpt_t half_sphere(tt_t::drpt_t xvec) {
56 double m = xvec[0] * xvec[0] + xvec[1] * xvec[1];
57 if (m > 1) {
58 return std::numeric_limits<double>::quiet_NaN();
59 } else {
60 return std::sqrt(1-m);
61 }
62}
63
64////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65int main() {
66 tt_t tree({-1.2, -1.2},
67 { 1.2, 1.2});
68 cc_t ccplx;
69
70 // Sample a uniform grid across the domain
71 tree.refine_grid(5, half_sphere);
72
73 /* Refine near the edge */
74 tree.refine_recursive_if_cell_vertex_is_nan(6, half_sphere);
75
76 tree.dump_tree(10);
77
78 /* 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. */
79 tc_t::construct_geometry_fans(ccplx,
80 tree,
81 2,
82 {{tc_t::val_src_spc_t::FDOMAIN, 0},
83 {tc_t::val_src_spc_t::FDOMAIN, 1},
84 {tc_t::val_src_spc_t::FRANGE, 0}},
85 half_sphere
86 );
87
88 ccplx.create_named_datasets({"x", "y", "f(x,y)"},
89 {{"NORMALS", {0, 1, 2}}});
90
91 /* This is the magic. We add new cells with the third element of each point data vector negated. */
92 ccplx.mirror({0, 0, 1});
93
94 ccplx.dump_cplx(10);
95
96 ccplx.write_xml_vtk("surface_branch_glue.vtu", "surface_branch_glue");
97 ccplx.write_legacy_vtk("surface_branch_glue.vtk", "surface_branch_glue");
98 ccplx.write_ply("surface_branch_glue.ply", "surface_branch_glue");
99}
100/** @endcond */
int main()