mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge topic 'logistic'
61522fde7 Add #includes and explicitly identify the field name. 1bad28a3e Logistic map as an example of how to use the ImageWriter. Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Nickolas Davis <nadavi@sandia.gov> Merge-request: !2385
This commit is contained in:
commit
18a6b12509
@ -24,6 +24,7 @@ if(VTKm_ENABLE_EXAMPLES)
|
||||
add_subdirectory(histogram)
|
||||
add_subdirectory(ising)
|
||||
add_subdirectory(lagrangian)
|
||||
add_subdirectory(logistic_map)
|
||||
add_subdirectory(mesh_quality)
|
||||
add_subdirectory(multi_backend)
|
||||
add_subdirectory(oscillator)
|
||||
|
16
examples/logistic_map/CMakeLists.txt
Normal file
16
examples/logistic_map/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
##============================================================================
|
||||
## Copyright (c) Kitware, Inc.
|
||||
## All rights reserved.
|
||||
## See LICENSE.txt for details.
|
||||
##
|
||||
## This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
## PURPOSE. See the above copyright notice for more information.
|
||||
##============================================================================
|
||||
cmake_minimum_required(VERSION 3.12...3.19 FATAL_ERROR)
|
||||
project(LogisticMap CXX)
|
||||
|
||||
find_package(VTKm REQUIRED QUIET)
|
||||
|
||||
add_executable(LogisticMap LogisticMap.cxx)
|
||||
target_link_libraries(LogisticMap PRIVATE vtkm_io)
|
65
examples/logistic_map/LogisticMap.cxx
Normal file
65
examples/logistic_map/LogisticMap.cxx
Normal file
@ -0,0 +1,65 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <vtkm/cont/DataSetBuilderUniform.h>
|
||||
#include <vtkm/io/ImageWriterPNG.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
size_t height = 1800;
|
||||
size_t width = height * 1.618;
|
||||
vtkm::cont::DataSetBuilderUniform dsb;
|
||||
vtkm::cont::DataSet ds = dsb.Create(vtkm::Id2(width, height));
|
||||
|
||||
std::vector<double> x(width, 0.5);
|
||||
|
||||
double rmin = 2.9;
|
||||
for (size_t i = 0; i < width; ++i)
|
||||
{
|
||||
double r = rmin + (4.0 - rmin) * i / (width - 1);
|
||||
int n = 0;
|
||||
// 2048 should be enough iterations to be "converged";
|
||||
// though of course the iterations actually don't all converge but cycle or are chaotic.
|
||||
while (n++ < 2048)
|
||||
{
|
||||
x[i] = r * x[i] * (1 - x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vtkm::Vec4f v(1.0, 0.5, 0.0, 0.0);
|
||||
std::vector<vtkm::Vec4f> pixelValues(width * height, vtkm::Vec4f(0, 0, 0, 0));
|
||||
size_t iterates = 0;
|
||||
// We don't need more iterates than pixels of height,
|
||||
// by the pigeonhole principle.
|
||||
while (iterates++ < height)
|
||||
{
|
||||
for (size_t i = 0; i < width; ++i)
|
||||
{
|
||||
double r = rmin + (4.0 - rmin) * i / (width - 1);
|
||||
double y = x[i];
|
||||
assert(y >= 0 && y <= 1);
|
||||
size_t j = std::round(y * (height - 1));
|
||||
pixelValues[j * width + i] = v;
|
||||
x[i] = r * x[i] * (1 - x[i]);
|
||||
}
|
||||
}
|
||||
|
||||
std::string colorFieldName = "pixels";
|
||||
ds.AddPointField(colorFieldName, pixelValues);
|
||||
std::string filename = "logistic.png";
|
||||
vtkm::io::ImageWriterPNG writer(filename);
|
||||
writer.WriteDataSet(ds, colorFieldName);
|
||||
std::cout << "Now open " << filename << "\n";
|
||||
}
|
Loading…
Reference in New Issue
Block a user