Extract Structured with Offset

Added code for giving ExtractStructured an offset value. Unit tests
three different 3D cases and a 3D case.
This commit is contained in:
Steven Walton 2019-05-24 17:15:28 -07:00
parent 56598ebfa5
commit c7bd79e789
2 changed files with 262 additions and 47 deletions

@ -172,8 +172,13 @@ private:
return vtkm::cont::make_ArrayHandleCounting(start, stride, count);
}
<<<<<<< HEAD
static DynamicCellSetStructured MakeCellSetStructured(const vtkm::Id3& dimensions,
const vtkm::Id3 offset)
=======
static DynamicCellSetStructured MakeCellSetStructured(const vtkm::Id3& dimensions,
const vtkm::Id3 offset)
>>>>>>> be71f52... Extract Structured with Offset
{
int dimensionality = 0;
vtkm::Id xyz[3];
@ -257,6 +262,7 @@ public:
{
// Verify input parameters
vtkm::Vec<vtkm::Id, Dimensionality> ptdim(cellset.GetPointDimensions());
<<<<<<< HEAD
<<<<<<< HEAD
vtkm::Id3 offset_vec(0, 0, 0);
vtkm::Id3 globalOffset(0, 0, 0);
@ -266,6 +272,10 @@ public:
this->SampleRate = vtkm::Id3(sampleRate[0], 1, 1);
this->InputDimensions = vtkm::Id3(ptdim[0], 1, 1);
>>>>>>> fcddeb5... Maybe right?
=======
vtkm::Id3 offset_vec(0, 0, 0);
vtkm::Id3 globalOffset(0, 0, 0);
>>>>>>> be71f52... Extract Structured with Offset
switch (Dimensionality)
{
@ -302,6 +312,7 @@ public:
}
this->InputDimensionality = Dimensionality;
<<<<<<< HEAD
<<<<<<< HEAD
if (includeOffset)
{
@ -446,28 +457,128 @@ public:
//this->VOI.Z.Max = vtkm::Min(this->InputDimensions[2], voi.Z.Max);
>>>>>>> fcddeb5... Maybe right?
=======
=======
>>>>>>> be71f52... Extract Structured with Offset
if (includeOffset)
{
offset_vec = cellset.GetGlobalPointIndexStart();
if (voi.X.Min < offset_vec[0])
this->VOI.X.Min = vtkm::Max(vtkm::Id(0), offset_vec[0]);
if (voi.X.Max < offset_vec[0])
this->VOI.X.Max = vtkm::Min(this->InputDimensions[0], offset_vec[0]);
if (Dimensionality >= 2)
vtkm::Id3 tmpDims(0, 0, 0);
vtkm::Vec<vtkm::Id, Dimensionality> tmpOffset_vec = cellset.GetGlobalPointIndexStart();
for (int i = 0; i < Dimensionality; ++i)
{
if (voi.Y.Min < offset_vec[1])
this->VOI.Y.Min = vtkm::Max(vtkm::Id(0), offset_vec[1]);
if (voi.Y.Max < offset_vec[1])
this->VOI.Y.Max = vtkm::Min(this->InputDimensions[1], offset_vec[1]);
if (Dimensionality == 3)
tmpDims[i] = ptdim[i];
offset_vec[i] = tmpOffset_vec[i];
}
if (offset_vec[0] >= voi.X.Min)
{
globalOffset[0] = offset_vec[0];
this->VOI.X.Min = offset_vec[0];
if (globalOffset[0] + ptdim[0] < voi.X.Max)
{
if (voi.Z.Min < offset_vec[2])
this->VOI.Z.Min = vtkm::Max(vtkm::Id(0), offset_vec[2]);
if (voi.Z.Max < offset_vec[2])
this->VOI.Z.Max = vtkm::Min(this->InputDimensions[2], offset_vec[2]);
// Start from our GPIS (start point) up to the length of the
// dimensions (if that is within VOI)
this->VOI.X.Max = globalOffset[0] + ptdim[0];
}
else
{
// If it isn't within the voi we set our dimensions from the
// GPIS up to the VOI.
tmpDims[0] = voi.X.Max - globalOffset[0];
}
}
else if (offset_vec[0] < voi.X.Min)
{
if (offset_vec[0] + ptdim[0] < voi.X.Min)
{
// If we're out of bounds we set the dimensions to 0. This
// causes a return of DynamicCellSetStructured
tmpDims[0] = 0;
}
else
{
// If our GPIS is less than VOI min, but our dimensions
// include the VOI we go from the minimal value that we
// can up to how far has been specified.
globalOffset[0] = voi.X.Min;
this->VOI.X.Min = voi.X.Min;
if (globalOffset[0] + ptdim[0] < voi.X.Max)
{
this->VOI.X.Max = globalOffset[0] + ptdim[0];
}
else
{
tmpDims[0] = voi.X.Max - globalOffset[0];
}
}
}
if (Dimensionality >= 2 && offset_vec[1] > voi.Y.Min)
{
globalOffset[1] = offset_vec[1];
this->VOI.Y.Min = offset_vec[1];
if (globalOffset[1] + ptdim[1] < voi.Y.Max)
{
this->VOI.Y.Max = globalOffset[1] + ptdim[1];
}
else
{
tmpDims[1] = voi.Y.Max - globalOffset[1];
}
}
else if (Dimensionality >= 2 && offset_vec[1] < voi.Y.Min)
{
if (offset_vec[1] + ptdim[1] < voi.Y.Min)
{
tmpDims[1] = 0;
}
else
{
globalOffset[1] = voi.Y.Min;
this->VOI.Y.Min = voi.Y.Min;
if (globalOffset[1] + ptdim[1] < voi.Y.Max)
{
this->VOI.Y.Max = globalOffset[1] + ptdim[1];
}
else
{
tmpDims[1] = voi.Y.Max - globalOffset[1];
}
}
}
if (Dimensionality == 3 && offset_vec[2] > voi.Z.Min)
{
globalOffset[2] = offset_vec[2];
this->VOI.Z.Min = offset_vec[2];
if (globalOffset[2] + ptdim[2] < voi.Z.Max)
{
this->VOI.Z.Max = globalOffset[2] + ptdim[2];
}
else
{
tmpDims[2] = voi.Z.Max - globalOffset[2];
}
}
else if (Dimensionality == 3 && offset_vec[2] < voi.Z.Min)
{
if (offset_vec[2] + ptdim[2] < voi.Z.Min)
{
tmpDims[2] = 0;
}
else
{
globalOffset[2] = voi.Z.Min;
this->VOI.Z.Min = voi.Z.Min;
if (globalOffset[2] + ptdim[2] < voi.Z.Max)
{
this->VOI.Z.Max = globalOffset[2] + ptdim[2];
}
else
{
tmpDims[2] = voi.Z.Max - globalOffset[2];
}
}
}
this->OutputDimensions = vtkm::Id3(tmpDims[0], tmpDims[1], tmpDims[2]);
}
<<<<<<< HEAD
else // includeOffset = false
{
this->VOI.X.Min = vtkm::Max(vtkm::Id(0), voi.X.Min);
@ -516,6 +627,54 @@ public:
this->OutputDimensions[i] = ((voiDims[i] + this->SampleRate[i] - 1) / this->SampleRate[i]) +
((includeBoundary && ((voiDims[i] - 1) % this->SampleRate[i])) ? 1 : 0);
}
=======
this->VOI.X.Min = vtkm::Max(vtkm::Id(0), voi.X.Min);
this->VOI.X.Max = vtkm::Min(this->InputDimensions[0] + globalOffset[0], voi.X.Max);
this->VOI.Y.Min = vtkm::Max(vtkm::Id(0), voi.Y.Min);
this->VOI.Y.Max = vtkm::Min(this->InputDimensions[1] + globalOffset[1], voi.Y.Max);
this->VOI.Z.Min = vtkm::Max(vtkm::Id(0), voi.Z.Min);
this->VOI.Z.Max = vtkm::Min(this->InputDimensions[2] + globalOffset[2], voi.Z.Max);
if (!this->VOI.IsNonEmpty()) // empty VOI
{
vtkm::Id xyz[3] = { 0, 0, 0 };
switch (Dimensionality)
{
case 1:
{
vtkm::cont::CellSetStructured<1> outCs;
outCs.SetPointDimensions(xyz[0]);
return outCs;
}
case 2:
{
vtkm::cont::CellSetStructured<2> outCs;
outCs.SetPointDimensions(vtkm::Id2(xyz[0], xyz[1]));
return outCs;
}
case 3:
{
vtkm::cont::CellSetStructured<3> outCs;
outCs.SetPointDimensions(vtkm::Id3(xyz[0], xyz[1], xyz[2]));
return outCs;
}
default:
return DynamicCellSetStructured();
}
}
//
if (!includeOffset)
{
// compute output dimensions
this->OutputDimensions = vtkm::Id3(1);
vtkm::Id3 voiDims = this->VOI.Dimensions();
for (int i = 0; i < Dimensionality; ++i)
{
this->OutputDimensions[i] = ((voiDims[i] + this->SampleRate[i] - 1) / this->SampleRate[i]) +
((includeBoundary && ((voiDims[i] - 1) % this->SampleRate[i])) ? 1 : 0);
}
>>>>>>> be71f52... Extract Structured with Offset
}
this->ValidPoints = vtkm::cont::make_ArrayHandleCartesianProduct(
@ -548,7 +707,11 @@ public:
if (includeOffset)
{
<<<<<<< HEAD
return MakeCellSetStructured(this->OutputDimensions, globalOffset);
=======
return MakeCellSetStructured(this->OutputDimensions, globalOffset);
>>>>>>> be71f52... Extract Structured with Offset
}
return MakeCellSetStructured(this->OutputDimensions);
}
@ -589,6 +752,7 @@ private:
ExtractStructured* Worklet;
const vtkm::RangeId3* VOI;
const vtkm::Id3* SampleRate;
const vtkm::Id3* GlobalPointIndexStart;
bool IncludeBoundary;
bool IncludeOffset;
DynamicCellSetStructured* Output;

@ -24,6 +24,10 @@
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
//#include <typeinfo>
//#include <vtkm/cont/DynamicCellSet.h>
//#include <memory>
using vtkm::cont::testing::MakeTestDataSet;
class TestingExtractStructured
@ -304,6 +308,7 @@ public:
using CellSetType = vtkm::cont::CellSetStructured<3>;
>>>>>>> 6cacc28... Pushing for Abhishek (Don't merge)
<<<<<<< HEAD
<<<<<<< HEAD
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
CellSetType cs = outCellSet.Cast<CellSetType>();
@ -319,6 +324,9 @@ public:
CellSetType cellSet;
//dataSet.GetCellSet(0).CopyTo(cellSet);
>>>>>>> 43cabfc... Maybe closer
=======
CellSetType cellSet;
>>>>>>> be71f52... Extract Structured with Offset
CellSetType cellSet;
=======
@ -331,60 +339,46 @@ public:
const vtkm::Int32 Dimensionality = 3;
bool includeBoundary = false;
bool includeOffset = false;
cellSet.SetPointDimensions(vtkm::make_Vec(10, 0, 0));
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10));
vtkm::Vec<vtkm::Id, Dimensionality> ptdim(cellSet.GetPointDimensions());
// Extract subset
vtkm::worklet::ExtractStructured worklet;
// worklet.Run(cellset, voi, sample rate, ...)
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
//CellSetType cellStruct = outCellSet.Cast<CellSetType>();
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), no_offset));
auto t4 = cellSet.GetGlobalPointIndexStart();
auto t5 = cellSet.GetPointDimensions();
vtkm::Id3 cellDims =
outCellSet.Cast<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
////vtkm::Id3 cellDims = outCellSet.GetSchedulingRange(vtkm::TopologyElementTagCell());
//vtkm::Id3 cellDims = cellStruct.GetCellDimensions();
//vtkm::Id3 cellDims = cellSet.GetCellDimensions();
//CellSetType cs = dynamic_cells.Cast<CellSetType>();
includeOffset = true;
outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
cellSet.SetGlobalPointIndexStart(test_offset);
VTKM_TEST_ASSERT(test_equal(cellSet.GetPointDimensions(), test_offset));
auto t1 = cellSet.GetPointDimensions();
auto t2 = cellSet.GetGlobalPointIndexStart();
//auto t9 = outCellSet.Cast<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
vtkm::Id3 cellDims2 = cellSet.GetCellDimensions();
//auto t3 = cellSet.GetGlobalPointDimensions();
std::cout << " " << std::endl;
outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
cellDims = outCellSet.Cast<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
CellSetType cs = outCellSet.Cast<CellSetType>();
cellDims = cs.GetPointDimensions();
VTKM_TEST_ASSERT(test_equal(cellDims, new_dims));
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), test_offset));
}
void TestOffset3D2() const
{
std::cout << "Testing Offset 3D-2" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DRectilinearDataSet0();
CellSetType cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::RangeId3 range(15, 20, 0, 10, 0, 10);
vtkm::Id3 sample(1, 1, 1);
vtkm::Id3 test_dims(5, 10, 10);
vtkm::Id3 gpis(10, 0, 0);
vtkm::Id3 test_offset(15, 0, 0);
const vtkm::Int32 Dimensionality = 3;
bool includeBoundary = false;
bool includeOffset = true;
cellSet.SetPointDimensions(vtkm::make_Vec(10, 0, 0));
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10));
cellSet.SetGlobalPointIndexStart(gpis);
vtkm::Vec<vtkm::Id, Dimensionality> ptdim(cellSet.GetPointDimensions());
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
<<<<<<< HEAD
cellSet.SetGlobalPointIndexStart(test_offset);
auto test = cellSet.GetPointDimensions();
VTKM_TEST_ASSERT(test_equal(cellSet.GetPointDimensions(), test_offset));
@ -421,16 +415,68 @@ public:
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), test_offset));
=======
>>>>>>> bdd013b... Getting there with ES
=======
CellSetType cs = outCellSet.Cast<CellSetType>();
vtkm::Id3 cellDims = cs.GetPointDimensions();
VTKM_TEST_ASSERT(test_equal(cellDims, test_dims));
VTKM_TEST_ASSERT(test_equal(cs.GetGlobalPointIndexStart(), test_offset));
>>>>>>> be71f52... Extract Structured with Offset
}
/*
void TestOffset3D3() const
{
std::cout << "Ehhh" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DRectilinearDataSet0();
CellSetType cellset = dynamic_cells.Cast<CellSetStructured<3>>();
std::cout << "Testing Offset 3D-3" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<3>;
CellSetType cellSet;
vtkm::RangeId3 range(100, 110, 0, 10, 0, 10);
vtkm::Id3 sample(1, 1, 1);
vtkm::Id3 test_dims(0, 0, 0);
const vtkm::Int32 Dimensionality = 3;
bool includeBoundary = false;
bool includeOffset = true;
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10, 10));
vtkm::Vec<vtkm::Id, Dimensionality> ptdim(cellSet.GetPointDimensions());
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
CellSetType cs = outCellSet.Cast<CellSetType>();
VTKM_TEST_ASSERT(test_equal(cs.GetPointDimensions(), test_dims));
}
void TestOffset2D() const
{
std::cout << "Testing offset 2D" << std::endl;
using CellSetType = vtkm::cont::CellSetStructured<2>;
CellSetType cellSet;
// RangeID3 and subsample
vtkm::RangeId3 range(5, 15, 0, 10, 0, 1);
vtkm::Id3 sample(1, 1, 1);
vtkm::Id2 test_offset(10, 0);
vtkm::Id2 no_offset(0, 0);
vtkm::Id2 new_dims(5, 10);
const vtkm::Int32 Dimensionality = 2;
bool includeBoundary = false;
bool includeOffset = true;
cellSet.SetPointDimensions(vtkm::make_Vec(10, 10));
vtkm::Vec<vtkm::Id, Dimensionality> ptdim(cellSet.GetPointDimensions());
vtkm::worklet::ExtractStructured worklet;
auto outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), no_offset));
vtkm::Id2 cellDims =
outCellSet.Cast<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
includeOffset = true;
cellSet.SetGlobalPointIndexStart(test_offset);
outCellSet = worklet.Run(cellSet, range, sample, includeBoundary, includeOffset);
cellDims = outCellSet.Cast<CellSetType>().GetSchedulingRange(vtkm::TopologyElementTagCell());
CellSetType cs = outCellSet.Cast<CellSetType>();
cellDims = cs.GetPointDimensions();
VTKM_TEST_ASSERT(test_equal(cellDims, new_dims));
VTKM_TEST_ASSERT(test_equal(cellSet.GetGlobalPointIndexStart(), test_offset));
}
*/
void operator()() const
{
@ -441,11 +487,16 @@ public:
TestRectilinear3D();
TestOffset3D1();
TestOffset3D2();
<<<<<<< HEAD
<<<<<<< HEAD
TestOffset3D3();
TestOffset2D();
=======
>>>>>>> 6cacc28... Pushing for Abhishek (Don't merge)
=======
TestOffset3D3();
TestOffset2D();
>>>>>>> be71f52... Extract Structured with Offset
}
};