Commit e0b1edb4 authored by Matt Larsen's avatar Matt Larsen Committed by Kitware Robot
Browse files

Merge topic 'support_log_plots'

39abcb99 fixing compile errors
655412fc

 adding support for log plots with the wireframer
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1014
parents 1d58eeaa 39abcb99
......@@ -42,6 +42,7 @@ class MakeTestDataSet
public:
// 1D uniform datasets.
vtkm::cont::DataSet Make1DUniformDataSet0();
vtkm::cont::DataSet Make1DUniformDataSet1();
// 1D explicit datasets.
vtkm::cont::DataSet Make1DExplicitDataSet0();
......@@ -92,6 +93,20 @@ inline vtkm::cont::DataSet MakeTestDataSet::Make1DUniformDataSet0()
return dataSet;
}
//Make another simple 1D dataset.
inline vtkm::cont::DataSet MakeTestDataSet::Make1DUniformDataSet1()
{
vtkm::cont::DataSetBuilderUniform dsb;
const vtkm::Id nVerts = 6;
vtkm::cont::DataSet dataSet = dsb.Create(nVerts);
vtkm::cont::DataSetFieldAdd dsf;
vtkm::Float32 var[nVerts] = { 1.0e3f, 5.e5f, 2.e8f, 1.e10f, 2e12f, 3e15f };
dsf.AddPointField(dataSet, "pointvar", var, nVerts);
return dataSet;
}
inline vtkm::cont::DataSet MakeTestDataSet::Make1DExplicitDataSet0()
{
const int nVerts = 5;
......
......@@ -40,12 +40,52 @@ namespace rendering
namespace
{
class CreateConnectivity : public vtkm::worklet::WorkletMapField
{
public:
VTKM_CONT
CreateConnectivity() {}
typedef void ControlSignature(FieldIn<>, WholeArrayOut<>);
typedef void ExecutionSignature(_1, _2);
template <typename ConnPortalType>
VTKM_EXEC void operator()(const vtkm::Id& i, ConnPortalType& connPortal) const
{
connPortal.Set(i * 2 + 0, i);
connPortal.Set(i * 2 + 1, i + 1);
}
}; // conn
struct ConnFunctor
{
template <typename Device>
VTKM_CONT bool operator()(Device,
vtkm::cont::ArrayHandleCounting<vtkm::Id>& iter,
vtkm::cont::ArrayHandle<vtkm::Id>& conn)
{
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
vtkm::worklet::DispatcherMapField<CreateConnectivity, Device>(CreateConnectivity())
.Invoke(iter, conn);
return true;
}
};
class Convert1DCoordinates : public vtkm::worklet::WorkletMapField
{
private:
bool LogY;
bool LogX;
public:
VTKM_CONT
Convert1DCoordinates() {}
Convert1DCoordinates(bool logY, bool logX)
: LogY(logY)
, LogX(logX)
{
}
typedef void ControlSignature(FieldIn<>,
FieldIn<vtkm::TypeListTagScalarAll>,
......@@ -69,11 +109,39 @@ public:
outCoord[0] = inCoord[0];
outCoord[1] = static_cast<vtkm::Float32>(scalar);
outCoord[2] = 0.f;
if (LogY)
{
outCoord[1] = vtkm::Log10(outCoord[1]);
}
if (LogX)
{
outCoord[0] = vtkm::Log10(outCoord[0]);
}
// all lines have the same color
fieldOut = 1.f;
}
}; // convert coords
struct ConvertFunctor
{
template <typename Device, typename CoordType, typename ScalarType>
VTKM_CONT bool operator()(Device,
CoordType coords,
ScalarType scalars,
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 3>>& outCoords,
vtkm::cont::ArrayHandle<vtkm::Float32>& outScalars,
bool logY,
bool logX)
{
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
vtkm::worklet::DispatcherMapField<Convert1DCoordinates, Device>(
Convert1DCoordinates(logY, logX))
.Invoke(coords, scalars, outCoords, outScalars);
return true;
}
};
#if defined(VTKM_MSVC)
#pragma warning(push)
#pragma warning(disable : 4127) //conditional expression is constant
......@@ -276,22 +344,24 @@ void MapperWireframer::RenderCells(const vtkm::cont::DynamicCellSet& inCellSet,
//
// Convert the cell set into something we can draw
//
vtkm::worklet::DispatcherMapField<Convert1DCoordinates, vtkm::cont::DeviceAdapterTagSerial>(
Convert1DCoordinates())
.Invoke(coords.GetData(), inScalarField.GetData(), newCoords, newScalars);
vtkm::cont::TryExecute(ConvertFunctor(),
coords.GetData(),
inScalarField.GetData(),
newCoords,
newScalars,
this->LogarithmY,
this->LogarithmX);
actualCoords = vtkm::cont::CoordinateSystem("coords", newCoords);
actualField =
vtkm::cont::Field(inScalarField.GetName(), vtkm::cont::Field::ASSOC_POINTS, newScalars);
vtkm::Id numCells = cellSet.GetNumberOfCells();
vtkm::cont::ArrayHandle<vtkm::Id> conn;
vtkm::cont::ArrayHandleCounting<vtkm::Id> iter =
vtkm::cont::make_ArrayHandleCounting(vtkm::Id(0), vtkm::Id(1), numCells);
conn.Allocate(numCells * 2);
auto connPortal = conn.GetPortalControl();
for (int i = 0; i < numCells; ++i)
{
connPortal.Set(i * 2 + 0, i);
connPortal.Set(i * 2 + 1, i + 1);
}
vtkm::cont::TryExecute(ConnFunctor(), iter, conn);
vtkm::cont::CellSetSingleType<> newCellSet("cells");
newCellSet.Fill(newCoords.GetNumberOfValues(), vtkm::CELL_SHAPE_LINE, 2, conn);
......
......@@ -130,6 +130,10 @@ void RenderTests()
colors.push_back(vtkm::rendering::Color(0.f, 1.f, 0.f));
vtkm::rendering::testing::Render<M, C, V1>(
maker.Make1DUniformDataSet0(), fields, colors, "lines1D.pnm");
//test log y
vtkm::rendering::Color red = vtkm::rendering::Color::red;
vtkm::rendering::testing::Render<M, C, V1>(
maker.Make1DUniformDataSet1(), "pointvar", red, "linesLogY1D.pnm", true);
}
} //namespace
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment