FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
implicit_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 implicit_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_curve_2d.cpp; however, instead of extracting a curve from a triangulation of a surface, this time we extract a
33 surface from a quad tessellation of a hexahedron. In addition to what we demonstrate with implicit_curve_2d.cpp, this example also demonstrates:
34
35 - How to use an SDF to identify cells that contain the level set
36 - How to export only a subset of cells
37*/
38/*******************************************************************************************************************************************************.H.E.**/
39/** @cond exj */
40
41////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42#include "MR_rect_tree.hpp"
43#include "MR_cell_cplx.hpp"
44#include "MR_rt_to_cc.hpp"
45
46////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47typedef mjr::tree15b3d1rT tt_t;
48typedef mjr::MRccT5 cc_t;
49typedef mjr::MR_rt_to_cc<tt_t, cc_t> tc_t;
50
51////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52tt_t::rrpt_t isf(tt_t::drpt_t xvec) {
53 double x = xvec[0];
54 double y = xvec[1];
55 double z = xvec[2];
56 return x*x*y+y*y*x-z*z*z-1;
57}
58
59////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60int main() {
61 tt_t tree({-2.3, -2.3, -2.3},
62 { 2.3, 2.3, 2.3});
63 cc_t ccplx;
64
65 /* Initial uniform sample */
66 tree.refine_grid(4, isf);
67
68 /* Refine near surface */
69 tree.refine_leaves_recursive_cell_pred(6, isf, [&tree](tt_t::diti_t i) { return (tree.cell_cross_sdf(i, isf)); });
70
71 tree.dump_tree(5);
72
73 /* Convert our tree to a cell complex. Note that we use an SDF to export only cells that contain our surface */
74 tc_t::construct_geometry_rects(ccplx,
75 tree,
76 tree.get_leaf_cells_pred(tree.ccc_get_top_cell(), [&tree](tt_t::diti_t i) { return (tree.cell_cross_sdf(i, isf)); }),
77 3,
78 {{tc_t::val_src_spc_t::FDOMAIN, 0},
79 {tc_t::val_src_spc_t::FDOMAIN, 1},
80 {tc_t::val_src_spc_t::FDOMAIN, 2}});
81
82 /* Name the data points */
83 ccplx.create_named_datasets({"x", "y", "z", "f(x,y,z)"});
84
85 /* Display some data about the cell complex */
86 ccplx.dump_cplx(5);
87
88 /* Write out our cell complex */
89 ccplx.write_xml_vtk("implicit_surface.vtu", "implicit_surface");
90}
91/** @endcond */
int main()