2017-04-20 15:06:00 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-04-20 15:06:00 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
2022-08-01 12:00:46 +00:00
|
|
|
#include <vtkm/Particle.h>
|
2017-04-20 15:06:00 +00:00
|
|
|
#include <vtkm/cont/DataSet.h>
|
2019-10-07 20:49:13 +00:00
|
|
|
#include <vtkm/cont/Initialize.h>
|
2022-07-25 14:01:13 +00:00
|
|
|
#include <vtkm/filter/flow/Streamline.h>
|
2020-04-30 12:12:04 +00:00
|
|
|
#include <vtkm/io/VTKDataSetReader.h>
|
|
|
|
#include <vtkm/io/VTKDataSetWriter.h>
|
2017-04-20 15:06:00 +00:00
|
|
|
|
2019-08-28 15:14:30 +00:00
|
|
|
// Example computing streamlines.
|
|
|
|
// An example vector field is available in the vtk-m data directory: magField.vtk
|
|
|
|
// Example usage:
|
|
|
|
// this will advect 200 particles 50 steps using a step size of 0.01
|
|
|
|
//
|
|
|
|
// Particle_Advection <path-to-data-dir>/magField.vtk vec 200 50 0.01 output.vtk
|
|
|
|
//
|
|
|
|
|
2019-08-28 11:48:20 +00:00
|
|
|
int main(int argc, char** argv)
|
2017-04-20 15:06:00 +00:00
|
|
|
{
|
2019-10-07 20:49:13 +00:00
|
|
|
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
|
|
|
auto config = vtkm::cont::Initialize(argc, argv, opts);
|
|
|
|
|
|
|
|
if (argc < 8)
|
2017-04-20 15:06:00 +00:00
|
|
|
{
|
2019-10-08 14:22:29 +00:00
|
|
|
std::cerr << "Usage: " << argv[0]
|
|
|
|
<< "dataFile varName numSeeds numSteps stepSize outputFile [options]" << std::endl;
|
|
|
|
std::cerr << "where options are: " << std::endl << config.Usage << std::endl;
|
2019-08-28 11:48:20 +00:00
|
|
|
return -1;
|
2017-04-20 15:06:00 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 11:48:20 +00:00
|
|
|
std::string dataFile = argv[1];
|
|
|
|
std::string varName = argv[2];
|
|
|
|
vtkm::Id numSeeds = std::stoi(argv[3]);
|
|
|
|
vtkm::Id numSteps = std::stoi(argv[4]);
|
|
|
|
vtkm::FloatDefault stepSize = std::stof(argv[5]);
|
|
|
|
std::string outputFile = argv[6];
|
2017-04-25 03:53:54 +00:00
|
|
|
|
2019-08-28 11:48:20 +00:00
|
|
|
vtkm::cont::DataSet ds;
|
2017-07-12 02:22:28 +00:00
|
|
|
|
2019-08-28 15:14:30 +00:00
|
|
|
if (dataFile.find(".vtk") != std::string::npos)
|
2017-05-10 17:38:42 +00:00
|
|
|
{
|
2020-04-30 12:12:04 +00:00
|
|
|
vtkm::io::VTKDataSetReader rdr(dataFile);
|
2019-08-28 11:48:20 +00:00
|
|
|
ds = rdr.ReadDataSet();
|
2017-05-10 17:38:42 +00:00
|
|
|
}
|
2019-08-28 11:48:20 +00:00
|
|
|
else
|
2017-07-07 17:36:31 +00:00
|
|
|
{
|
2019-08-28 11:48:20 +00:00
|
|
|
std::cerr << "Unsupported data file: " << dataFile << std::endl;
|
|
|
|
return -1;
|
2017-07-07 17:36:31 +00:00
|
|
|
}
|
2017-04-21 18:51:36 +00:00
|
|
|
|
2019-08-28 15:14:30 +00:00
|
|
|
//create seeds randomly placed withing the bounding box of the data.
|
2019-08-28 11:48:20 +00:00
|
|
|
vtkm::Bounds bounds = ds.GetCoordinateSystem().GetBounds();
|
2020-08-26 13:36:09 +00:00
|
|
|
std::vector<vtkm::Particle> seeds;
|
2017-07-07 17:36:31 +00:00
|
|
|
|
2019-12-19 14:56:05 +00:00
|
|
|
for (vtkm::Id i = 0; i < numSeeds; i++)
|
2017-07-07 17:36:31 +00:00
|
|
|
{
|
2020-08-26 13:36:09 +00:00
|
|
|
vtkm::Particle p;
|
2019-08-28 11:48:20 +00:00
|
|
|
vtkm::FloatDefault rx = (vtkm::FloatDefault)rand() / (vtkm::FloatDefault)RAND_MAX;
|
|
|
|
vtkm::FloatDefault ry = (vtkm::FloatDefault)rand() / (vtkm::FloatDefault)RAND_MAX;
|
|
|
|
vtkm::FloatDefault rz = (vtkm::FloatDefault)rand() / (vtkm::FloatDefault)RAND_MAX;
|
2022-12-13 18:10:13 +00:00
|
|
|
p.SetPosition({ static_cast<vtkm::FloatDefault>(bounds.X.Min + rx * bounds.X.Length()),
|
|
|
|
static_cast<vtkm::FloatDefault>(bounds.Y.Min + ry * bounds.Y.Length()),
|
|
|
|
static_cast<vtkm::FloatDefault>(bounds.Z.Min + rz * bounds.Z.Length()) });
|
|
|
|
p.SetID(i);
|
2019-08-28 11:48:20 +00:00
|
|
|
seeds.push_back(p);
|
2017-07-07 17:36:31 +00:00
|
|
|
}
|
2020-07-16 16:32:32 +00:00
|
|
|
auto seedArray = vtkm::cont::make_ArrayHandle(seeds, vtkm::CopyFlag::Off);
|
2017-04-21 18:51:36 +00:00
|
|
|
|
2019-08-28 11:48:20 +00:00
|
|
|
//compute streamlines
|
2022-07-25 14:01:13 +00:00
|
|
|
vtkm::filter::flow::Streamline streamline;
|
2017-04-20 15:06:00 +00:00
|
|
|
|
2019-08-28 11:48:20 +00:00
|
|
|
streamline.SetStepSize(stepSize);
|
|
|
|
streamline.SetNumberOfSteps(numSteps);
|
|
|
|
streamline.SetSeeds(seedArray);
|
2019-04-09 13:52:53 +00:00
|
|
|
|
2019-08-28 11:48:20 +00:00
|
|
|
streamline.SetActiveField(varName);
|
|
|
|
auto output = streamline.Execute(ds);
|
2017-07-07 17:36:31 +00:00
|
|
|
|
2020-04-30 12:12:04 +00:00
|
|
|
vtkm::io::VTKDataSetWriter wrt(outputFile);
|
2019-08-28 11:48:20 +00:00
|
|
|
wrt.WriteDataSet(output);
|
2017-07-07 17:36:31 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-04-20 15:06:00 +00:00
|
|
|
}
|