2015-09-11 21:16:23 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Copyright 2014 Sandia Corporation.
|
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
|
|
|
// Copyright 2014 Los Alamos National Security.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
2015-09-29 14:25:27 +00:00
|
|
|
#include <vtkm/cont/ArrayHandleCast.h>
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
|
|
|
#include <vtkm/cont/Timer.h>
|
2015-11-10 17:26:47 +00:00
|
|
|
#include <vtkm/io/reader/VTKDataSetReader.h>
|
|
|
|
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
2015-09-29 14:25:27 +00:00
|
|
|
|
|
|
|
#include <vtkm/worklet/Clip.h>
|
|
|
|
|
2015-09-11 21:16:23 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
typedef vtkm::Vec<vtkm::Float32, 3> FloatVec3;
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2015-11-10 17:26:47 +00:00
|
|
|
if (argc < 4)
|
2015-09-11 21:16:23 +00:00
|
|
|
{
|
|
|
|
std::cout << "Usage: " << std::endl
|
|
|
|
<< "$ " << argv[0]
|
2015-11-10 17:26:47 +00:00
|
|
|
<< " <input_vtk_file> [fieldName] <isoval> <output_vtk_file>"
|
2015-09-11 21:16:23 +00:00
|
|
|
<< std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
|
2015-12-16 16:18:52 +00:00
|
|
|
std::cout << "Device Adapter Name: "
|
|
|
|
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
2015-09-11 21:16:23 +00:00
|
|
|
<< std::endl;
|
|
|
|
|
2015-11-10 17:26:47 +00:00
|
|
|
vtkm::io::reader::VTKDataSetReader reader(argv[1]);
|
|
|
|
vtkm::cont::DataSet input = reader.ReadDataSet();
|
|
|
|
|
|
|
|
vtkm::cont::Field scalarField = (argc == 5) ?
|
|
|
|
input.GetField(argv[2]) :
|
|
|
|
input.GetField(0);
|
2015-09-11 21:16:23 +00:00
|
|
|
|
2016-10-20 20:54:08 +00:00
|
|
|
vtkm::Float32 clipValue = std::stof(argv[argc - 2]);
|
2016-08-12 16:38:58 +00:00
|
|
|
vtkm::worklet::Clip clip;
|
2015-09-11 21:16:23 +00:00
|
|
|
|
|
|
|
vtkm::cont::Timer<DeviceAdapter> total;
|
|
|
|
vtkm::cont::Timer<DeviceAdapter> timer;
|
|
|
|
vtkm::cont::CellSetExplicit<> outputCellSet =
|
2015-11-10 17:26:47 +00:00
|
|
|
clip.Run(input.GetCellSet(0),
|
|
|
|
scalarField.GetData().ResetTypeList(vtkm::TypeListTagScalarAll()),
|
2016-08-12 16:38:58 +00:00
|
|
|
clipValue,
|
|
|
|
DeviceAdapter());
|
2015-09-11 21:16:23 +00:00
|
|
|
vtkm::Float64 clipTime = timer.GetElapsedTime();
|
|
|
|
|
2015-11-10 17:26:47 +00:00
|
|
|
vtkm::cont::DataSet output;
|
|
|
|
output.AddCellSet(outputCellSet);
|
|
|
|
|
2015-09-11 21:16:23 +00:00
|
|
|
timer.Reset();
|
|
|
|
vtkm::cont::DynamicArrayHandle coords =
|
2016-08-12 16:38:58 +00:00
|
|
|
clip.ProcessField(input.GetCoordinateSystem(0), DeviceAdapter());
|
2015-09-11 21:16:23 +00:00
|
|
|
vtkm::Float64 processCoordinatesTime = timer.GetElapsedTime();
|
2016-03-23 15:14:55 +00:00
|
|
|
output.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coords));
|
2015-11-10 17:26:47 +00:00
|
|
|
|
2015-09-11 21:16:23 +00:00
|
|
|
timer.Reset();
|
2015-11-10 17:26:47 +00:00
|
|
|
for (vtkm::Id i = 0; i < input.GetNumberOfFields(); ++i)
|
|
|
|
{
|
|
|
|
vtkm::cont::Field inField = input.GetField(i);
|
|
|
|
if (inField.GetAssociation() != vtkm::cont::Field::ASSOC_POINTS)
|
|
|
|
{
|
|
|
|
continue; // clip only supports point fields for now.
|
|
|
|
}
|
|
|
|
vtkm::cont::DynamicArrayHandle data =
|
2016-08-12 16:38:58 +00:00
|
|
|
clip.ProcessField(inField.GetData().ResetTypeList(vtkm::TypeListTagAll()),
|
|
|
|
DeviceAdapter());
|
2016-03-23 15:14:55 +00:00
|
|
|
output.AddField(vtkm::cont::Field(inField.GetName(),
|
2015-11-10 17:26:47 +00:00
|
|
|
vtkm::cont::Field::ASSOC_POINTS, data));
|
|
|
|
}
|
2015-09-11 21:16:23 +00:00
|
|
|
vtkm::Float64 processScalarsTime = timer.GetElapsedTime();
|
|
|
|
|
|
|
|
vtkm::Float64 totalTime = total.GetElapsedTime();
|
|
|
|
|
|
|
|
std::cout << "Timings: " << std::endl
|
|
|
|
<< "clip: " << clipTime << std::endl
|
|
|
|
<< "process coordinates: " << processCoordinatesTime << std::endl
|
|
|
|
<< "process scalars: " << processScalarsTime << std::endl
|
|
|
|
<< "Total: " << totalTime << std::endl;
|
|
|
|
|
2016-03-17 15:13:25 +00:00
|
|
|
vtkm::io::writer::VTKDataSetWriter writer(argv[argc - 1]);
|
|
|
|
writer.WriteDataSet(output);
|
2015-09-11 21:16:23 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|