MRPTree v0.5.0.0 examples 0.5.0.0
MR 2^P Trees (MRPTree)
Loading...
Searching...
No Matches
hello_world_regular.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file hello_world_regular.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-09-16
7 @brief Minimal example for MR_rect_tree with regular sampling.@EOL
8 @keywords surface plot 2d 3d
9 @std C++23
10 @see
11 @copyright
12 @parblock
13 Copyright (c) 2024, Mitchell Jay Richling <http://www.mitchr.me/> All rights reserved.
14
15 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
16
17 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
18
19 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
20 and/or other materials provided with the distribution.
21
22 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
23 without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 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
30 DAMAGE.
31 @endparblock
32 @filedetails
33
34 This program writes a simple tabular file containing the tree's data -- one sample per line with space separated coordinates and values. These
35 may be interrupted as points in 3D, and graphed by tools like GNU Plot. On Windows running MSYS2, the following command sequence will produce a
36 graph on the screen:
37
38 make hello_world_regular
39 ./hello_world_regular.exe
40 gnuplot.exe ../examples/hello_world_regular.gp
41
42*/
43/*******************************************************************************************************************************************************.H.E.**/
44/** @cond exj */
45
46////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47#include "MR_rect_tree.hpp"
48
49////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50typedef mjr::tree15b2d1rT tt_t;
51
52////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53tt_t::rrpt_t damp_cos_wave(tt_t::drpt_t xvec) {
54 double x = xvec[0];
55 double y = xvec[1];
56 double d = x*x+y*y;
57 double z = std::exp(-d/4)*std::cos(4*std::sqrt(d));
58 return z;
59}
60
61////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62int main() {
63 tt_t tree({-2.1, -2.1},
64 { 2.1, 2.1});
65
66 /* Do a regular grid smaple on the rectangle */
67 tree.refine_grid(4, damp_cos_wave);
68
69 /* Dump points to a file */
70 tree.dump_tree_datafile("hello_world_regular.tab");
71}
72/** @endcond */