Loading [MathJax]/extensions/tex2jax.js
FuncViz examples
Generalized bitree/quadtree/octree library
All Files Functions
surface_plot_step.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_step.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-07-16
7 @brief Surface with a step discontinuity along a curve.@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 The function illustrated here is defined on the entire plan, but has a step discontinuity on the unit circle. Except on the unit circle, the function's
33 derivative is zero. If we sample on a uniform grid, some of the resulting polygons will have vertexes both inside and outside the unit circle -- they cross
34 over the discontinuity! When drawn we get a continuous surface with a circular bump! It should look like the x-y plane has a circle cut out that is
35 hovering one unit above the plane.
36
37 - How to drive up the sample rate near a particular SDF -- so that we get higher resolution where the surface meets the plane.
38 - How to delete triangles that cross over a discontinuity -- via an SDF.
39*/
40/*******************************************************************************************************************************************************.H.E.**/
41/** @cond exj */
42
43////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44#include "MR_rect_tree.hpp"
45#include "MR_cell_cplx.hpp"
46#include "MR_rt_to_cc.hpp"
47
48////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49typedef mjr::tree15b2d1rT tt_t;
50typedef mjr::MRccT5 cc_t;
51typedef mjr::MR_rt_to_cc<tt_t, cc_t> tc_t;
52
53////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54
55tt_t::rrpt_t hover_circle(tt_t::drpt_t xvec) {
56 return (xvec[0] * xvec[0] + xvec[1] * xvec[1] < 1);
57}
58
59////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60tt_t::src_t unit_circle_sdf(tt_t::drpt_t xvec) {
61 double m = xvec[0] * xvec[0] + xvec[1] * xvec[1];
62 return (1-m);
63}
64
65////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66int main() {
67 tt_t tree({-1.5, -1.5},
68 { 1.5, 1.5});
69 cc_t ccplx;
70
71 /* Here is another way to get fine samples on the circle, but with a SDF this time. */
72 tree.refine_grid(5, hover_circle);
73
74 /* Increase sample resolution on the unit circle. Here we do that with an SDF. */
75 tree.refine_leaves_recursive_cell_pred(7, hover_circle, [&tree](int i) { return (tree.cell_cross_sdf(i, unit_circle_sdf)); });
76
77 /* Balance the three to the traditional level of 1 (no cell borders a cell more than half it's size) */
78 tree.balance_tree(1, hover_circle);
79
80 /* Take a peek at the raw tree data */
81 tree.dump_tree(10);
82
83 /* Generate a cell complex from the tree samples */
84 tc_t::construct_geometry_fans(ccplx,
85 tree,
86 2,
87 {{tc_t::val_src_spc_t::FDOMAIN, 0},
88 {tc_t::val_src_spc_t::FDOMAIN, 1},
89 {tc_t::val_src_spc_t::FRANGE, 0}});
90
91 /* The single argument form of create_named_datasets() allows us to easily name data points. */
92 ccplx.create_named_datasets({"x", "y", "f(x,y)"});
93
94 /* Take a look at the generated cell complex */
95 ccplx.dump_cplx(10);
96
97 /* Cut out the tiny triangles on the unit circle! */
98 tc_t::cull_cc_cells_on_domain_sdf_boundry(ccplx, unit_circle_sdf);
99
100 /* We can do the above directly with MR_cell_cplx::cull_cells(). If you rewrote unit_circle_sdf(), you don't need to nest lambdas... */
101 // ccplx.cull_cells([&ccplx](cc_t::cell_verts_t c){ return ccplx.cell_near_sdf_boundry(c,
102 // [](cc_t::node_data_t pd) { return (tc_t::tsdf_to_csdf(unit_circle_sdf,
103 // pd));
104 // });
105 // });
106
107 /* Notice how it changed after the fold */
108 ccplx.dump_cplx(10);
109
110 ccplx.write_xml_vtk("surface_plot_step.vtu", "surface_plot_step");
111}
112/** @endcond */
int main()