FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
parametric_surface_with_defects.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file parametric_surface_with_defects.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-07-14
7 @brief Parametric surface with defects.@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 illustrates some of the things that can go wrong when generating parametric surfaces. We dump two version of the tessellation -- one with
33 quads and one with triangles. This allows us to better illustrate how some defects show up.
34 - Quads that are not plainer.
35 Look closely at the rectangular tessellation, and note the "rectangles" appear to be broken in across the diagonal -- at least that's how they appear in
36 most tools including Paraview & meshlab.
37 - At the poles, the rectangular cells of the tree map to three distinct points instead of four.
38 This means for the rectangular tessellation, the rectangles at the poles are degenerate! Then converting from tree to cell complex, these quads are
39 removed because they are degenerate. This is not an issue for the triangular tessellation (FANS).
40 - The v=0 edge meets up with the v=1 edge.
41 Because we have chk_point_unique set to true for the cell complex object, the duplicate points are "welded" together when the points are added. This
42 results in a seamless edge.
43*/
44/*******************************************************************************************************************************************************.H.E.**/
45/** @cond exj */
46
47////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48#include <numbers> /* C++ math constants C++20 */
49
50////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51#include "MR_rect_tree.hpp"
52#include "MR_cell_cplx.hpp"
53#include "MR_rt_to_cc.hpp"
54
55////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
56typedef mjr::tree15b2d3rT tt_t;
57typedef mjr::MRccT5 cc_t;
58typedef mjr::MR_rt_to_cc<tt_t, cc_t> tc_t;
59
60////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61tt_t::rrpt_t par_sphere(tt_t::drpt_t xvec) {
62 double u = std::numbers::pi/4 * xvec[0] + std::numbers::pi/4;
63 double v = std::numbers::pi * xvec[1] + std::numbers::pi;
64 return { std::sin(u)*std::cos(v),
65 std::sin(u)*std::sin(v),
66 std::cos(u)
67 };
68}
69
70////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
71int main() {
72 tt_t tree;
73 cc_t ccplx;
74
75 /* Uniform sampling */
76 tree.refine_grid(6, par_sphere);
77
78
79 /* First we dump a tessellation made of triangles */
80 tc_t::construct_geometry_fans(ccplx,
81 tree,
82 2,
83 {{tc_t::val_src_spc_t::FRANGE, 0},
84 {tc_t::val_src_spc_t::FRANGE, 1},
85 {tc_t::val_src_spc_t::FRANGE, 2}});
86 ccplx.create_named_datasets({"u", "v", "x(u,v)", "y(u,v)", "z(u,v)"});
87 ccplx.dump_cplx(5);
88 ccplx.write_xml_vtk("parametric_surface_with_defects-tri.vtu", "parametric_surface_with_defects-tri");
89
90 /* Next we dump a tessellation made of rectangles */
91 ccplx.clear(); // We need to clear out the old contents first!
92 tc_t::construct_geometry_rects(ccplx,
93 tree,
94 2,
95 {{tc_t::val_src_spc_t::FRANGE, 0},
96 {tc_t::val_src_spc_t::FRANGE, 1},
97 {tc_t::val_src_spc_t::FRANGE, 2}});
98 ccplx.create_named_datasets({"u", "v", "x(u,v)", "y(u,v)", "z(u,v)"});
99 ccplx.dump_cplx(5);
100 ccplx.write_xml_vtk("parametric_surface_with_defects-rect.vtu", "parametric_surface_with_defects-rect");
101}
102/** @endcond */
int main()