FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
hello_MRaster.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_MRaster.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-07-13
7 @brief Minimal example for MR_rect_tree/MR_cell_cplx/MR_rt_to_cc and MRaster.@EOL
8 @keywords surface plot 2d 3d color
9 @std C++23
10 @copyright
11 @parblock
12 Copyright (c) 2024, Mitchell Jay Richling <http://www.mitchr.me/> All rights reserved.
13
14 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
15
16 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
17
18 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
19 and/or other materials provided with the distribution.
20
21 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
22 without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 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
29 DAMAGE.
30 @endparblock
31 @filedetails
32 This example is almost identical to hello_world.cpp except:
33 - We use MRaster to generate a color pallet (MRaster has a great many pallets: https://richmit.github.io/mraster/ColorSchemes.html)
34 - We directly embed the colors into the resulting MR_cell_cplx
35 - We identify the color vector in the .VTU file.
36*/
37/*******************************************************************************************************************************************************.H.E.**/
38/** @cond exj */
39
40////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41#include "MR_rect_tree.hpp"
42#include "MR_cell_cplx.hpp"
43#include "MR_rt_to_cc.hpp"
44#include "MRcolor.hpp"
45
46////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47typedef mjr::tree15b2d4rT tt_t;
48typedef mjr::MRccT5 cc_t;
49typedef mjr::MR_rt_to_cc<tt_t, cc_t> tc_t;
50typedef mjr::color3c64F ct_t; // This is a 3 channel color with 64-bit floating point channels (i.e. a 192-bit color type)
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 ct_t c = ct_t::csPLYviridis::c((z+0.87)/1.87);
59 return {z, c.getRed(), c.getGreen(), c.getBlue()}; // We can grab the raw channel values with functions like getRed() because the channels are doubles.
60} // If we had used an integer channel color (like color3c8b), we would have needed to use getRed_dbl().
61
62
63////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64int main() {
65 tt_t tree({-2.1, -2.1},
66 { 2.1, 2.1});
67 cc_t ccplx;
68
69 tree.refine_grid(7, damp_cos_wave);
70
71 tc_t::construct_geometry_fans(ccplx,
72 tree,
73 2,
74 {{tc_t::val_src_spc_t::FDOMAIN, 0},
75 {tc_t::val_src_spc_t::FDOMAIN, 1},
76 {tc_t::val_src_spc_t::FRANGE, 0}});
77 ccplx.create_named_datasets({"x", "y", "f(x,y)", "c_r(x,y)", "c_g(x,y)", "c_b(x,y)"},
78 {{"COLORS", {3, 4, 5}}});
79
80 ccplx.write_xml_vtk("hello_MRaster.vtu", "hello_MRaster");
81}
82/** @endcond */
int main()