FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
surface_plot_edge.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_plot_edge.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-07-16
7 @brief Surface with an undefined regions.@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 Surface plots are frequently complicated by regions upon which the function singular or undefined. These functions often behave quite poorly on the
33 boundaries of such regions. For this example we consider @f$f(x, y)=\sqrt{1-x^2-y^2}@f$ -- the upper half of the unit sphere. Outside the unit circle this
34 function is complex. As we approach the unit circle from the center, the derivative approaches infinity.
35
36 Right now this example illustrates two things:
37
38 - How to drive up the sample rate near NaNs.
39 - How to repair triangles containing NaNs.
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.1, -1.1},
67 { 1.1, 1.1});
68 cc_t ccplx;
69
70 // Sample a uniform grid across the domain
71 tree.refine_grid(5, half_sphere);
72
73 /* half_sphere produces NaNs outside the unit circle.
74 We can refine cells that cross the unit circle using refine_recursive_if_cell_vertex_is_nan */
75 tree.refine_recursive_if_cell_vertex_is_nan(7, half_sphere);
76
77 /* We can acheive the same result via refine_leaves_recursive_cell_pred & cell_vertex_is_nan. */
78 // tree.refine_leaves_recursive_cell_pred(6, half_sphere, [&tree](int i) { return (tree.cell_vertex_is_nan(i)); });
79
80 /* We can acheive similar results by refining on the unit curcle via an SDF -- See surface_plot_corner.cpp */
81
82 /* Balance the three to the traditional level of 1 (no cell borders a cell more than half it's size) */
83 tree.balance_tree(1, half_sphere);
84
85 tree.dump_tree(10);
86
87 /* 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. */
88 tc_t::construct_geometry_fans(ccplx,
89 tree,
90 2,
91 {{tc_t::val_src_spc_t::FDOMAIN, 0},
92 {tc_t::val_src_spc_t::FDOMAIN, 1},
93 {tc_t::val_src_spc_t::FRANGE, 0}},
94 half_sphere
95 );
96
97 ccplx.create_named_datasets({"x", "y", "f(x,y)"},
98 {{"NORMALS", {0, 1, 2}}});
99
100 ccplx.dump_cplx(10);
101
102 ccplx.write_xml_vtk("surface_plot_edge.vtu", "surface_plot_edge");
103}
104/** @endcond */
int main()