FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
ear_surface.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.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-07-14
7 @brief Sampling for an implicit surface.@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 is very similar to implicit_surface.cpp; however, instead of extracting a surface from a quad tessellation of a hexahedrona we extract the
33 surface from a tessellation of a pyramids. Why use pyramids instead of hexahedrona? In the example implicit_surface.cpp all of the underlying cells are
34 the same size, and thus no gaps occur in the extracted level set (the surface). In this example we have cells that vary a great deal in size.
35
36 This example demonstrates scratch made cell predicates, and uses them to increse sample resolution on parts of the surface that are particularly difficlut
37 to extract.
38
39 This surface is defined by the zeros of the following polynomial
40
41 @f[ x^2-y^2*z^2+z^3 @f]
42*/
43/*******************************************************************************************************************************************************.H.E.**/
44/** @cond exj */
45
46////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47#include "MR_rect_tree.hpp"
48#include "MR_cell_cplx.hpp"
49#include "MR_rt_to_cc.hpp"
50
51////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52typedef mjr::tree15b3d1rT tt_t;
53typedef mjr::MRccT9 cc_t;
54typedef mjr::MR_rt_to_cc<tt_t, cc_t> tc_t;
55
56////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57tt_t::rrpt_t isf(tt_t::drpt_t xvec) {
58 double x = xvec[0];
59 double y = xvec[1];
60 double z = xvec[2];
61 return x*x-y*y*z*z+z*z*z;
62}
63
64
65////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66tt_t::rrpt_t besdf(tt_t::drpt_t xvec) {
67 double x = xvec[0];
68 double y = xvec[1];
69 double z = xvec[2];
70 return x*(z-y*y); // Inner ear edge
71}
72
73
74////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75int main() {
76 tt_t tree;
77 cc_t ccplx;
78
79 /* Initial uniform sample */
80 tree.refine_grid(3, isf);
81
82 /* Refine near surface */
83 tree.refine_leaves_recursive_cell_pred(6, isf, [&tree](tt_t::diti_t i) { return (tree.cell_cross_sdf(i, isf)); });
84
85 /* Refine between the ears. Could have also just refined on x=0 plane. */
86 tree.refine_leaves_recursive_cell_pred(8, isf, [&tree](tt_t::diti_t i) { auto x = tree.diti_to_drpt(i); return (std::abs(x[1])<0.5) && (tree.cell_cross_sdf(i, besdf)); });
87
88 /* Refine on the x-y plane */
89 tree.refine_leaves_recursive_cell_pred(7, isf, [&tree](tt_t::diti_t i) { return (tree.cell_near_domain_level(i, 2, 0.0, 1.0e-6)); });
90
91 /* Balance the tree */
92 tree.balance_tree(1, isf);
93
94 tree.dump_tree(5);
95
96 /* Convert our tree to a cell complex. Note that we use an SDF to export only cells that contain our surface */
97 tc_t::construct_geometry_fans(ccplx,
98 tree,
99 tree.get_leaf_cells_pred(tree.ccc_get_top_cell(), [&tree](tt_t::diti_t i) { return (tree.cell_cross_sdf(i, isf)); }),
100 3,
101 {{tc_t::val_src_spc_t::FDOMAIN, 0},
102 {tc_t::val_src_spc_t::FDOMAIN, 1},
103 {tc_t::val_src_spc_t::FDOMAIN, 2}});
104
105 /* Name the data points */
106 ccplx.create_named_datasets({"x", "y", "z", "f(x,y,z)"});
107
108 /* Display some data about the cell complex */
109 ccplx.dump_cplx(5);
110
111 /* Write out our cell complex */
112 ccplx.write_xml_vtk("ear_surface.vtu", "ear_surface");
113}
114/** @endcond */
int main()