diff --git a/vtkm/rendering/raytracing/VolumeRendererStructured.cxx b/vtkm/rendering/raytracing/VolumeRendererStructured.cxx index 120e60b91..0e903dba0 100644 --- a/vtkm/rendering/raytracing/VolumeRendererStructured.cxx +++ b/vtkm/rendering/raytracing/VolumeRendererStructured.cxx @@ -9,13 +9,13 @@ //============================================================================ #include -#include "vtkm/cont/CellLocatorRectilinearGrid.h" -#include "vtkm/cont/CellLocatorUniformGrid.h" +#include #include -#include #include #include #include +#include +#include #include #include #include @@ -44,12 +44,11 @@ template class LocatorAdopterBase { private: + const Derived* self = static_cast(this); + public: VTKM_EXEC - inline bool IsInside(const vtkm::Vec3f_32& point) const - { - return static_cast(this)->Locator.IsInside(point); - } + inline bool IsInside(const vtkm::Vec3f_32& point) const { return self->Locator.IsInside(point); } // Assumes point inside the data set VTKM_EXEC @@ -59,7 +58,6 @@ public: vtkm::Vec3f_32& parametric) const { vtkm::Id cellId{}; - auto self = static_cast(this); self->Locator.FindCell(point, cellId, parametric); cell = self->Conn.FlatToLogicalToIndex(cellId); self->ComputeInvSpacing(cell, point, invSpacing, parametric); @@ -68,28 +66,27 @@ public: VTKM_EXEC inline void GetCellIndices(const vtkm::Id3& cell, vtkm::Vec& cellIndices) const { - cellIndices = static_cast(this)->Conn.GetIndices(cell); + cellIndices = self->Conn.GetIndices(cell); } VTKM_EXEC inline vtkm::Id GetCellIndex(const vtkm::Id3& cell) const { - return static_cast(this)->Conn.LogicalToFlatToIndex(cell); + return self->Conn.LogicalToFlatToIndex(cell); } VTKM_EXEC inline void GetPoint(const vtkm::Id& index, vtkm::Vec3f_32& point) const { - BOUNDS_CHECK(static_cast(this)->Coordinates, index); - point = static_cast(this)->Coordinates.Get(index); + BOUNDS_CHECK(self->Coordinates, index); + point = self->Coordinates.Get(index); } VTKM_EXEC inline void GetMinPoint(const vtkm::Id3& cell, vtkm::Vec3f_32& point) const { - const vtkm::Id pointIndex = - static_cast(this)->Conn.LogicalToFlatFromIndex(cell); - point = static_cast(this)->Coordinates.Get(pointIndex); + const vtkm::Id pointIndex = self->Conn.LogicalToFlatFromIndex(cell); + point = self->Coordinates.Get(pointIndex); } }; @@ -102,12 +99,28 @@ private: using DefaultConstHandle = typename DefaultHandle::ReadPortalType; using CartesianConstPortal = typename CartesianArrayHandle::ReadPortalType; - DefaultConstHandle CoordPortals[3]; CartesianConstPortal Coordinates; vtkm::exec::ConnectivityStructured Conn; vtkm::exec::CellLocatorRectilinearGrid Locator; + DefaultConstHandle CoordPortals[3]; + + VTKM_EXEC + inline void ComputeInvSpacing(vtkm::Id3& cell, + const vtkm::Vec3f_32&, + vtkm::Vec3f_32& invSpacing, + vtkm::Vec3f_32&) const + { + vtkm::Vec3f_32 p0{ CoordPortals[0].Get(cell[0]), + CoordPortals[1].Get(cell[1]), + CoordPortals[2].Get(cell[2]) }; + vtkm::Vec3f_32 p1{ CoordPortals[0].Get(cell[0] + 1), + CoordPortals[1].Get(cell[1] + 1), + CoordPortals[2].Get(cell[2] + 1) }; + invSpacing = 1.f / (p1 - p0); + } + public: RectilinearLocatorAdopter(const CartesianArrayHandle& coordinates, vtkm::cont::CellSetStructured<3>& cellset, @@ -124,21 +137,6 @@ public: CoordPortals[1] = Coordinates.GetSecondPortal(); CoordPortals[2] = Coordinates.GetThirdPortal(); } - - VTKM_EXEC - inline void ComputeInvSpacing(vtkm::Id3& cell, - const vtkm::Vec3f_32&, - vtkm::Vec3f_32& invSpacing, - vtkm::Vec3f_32&) const - { - vtkm::Vec3f_32 p0{ CoordPortals[0].Get(cell[0]), - CoordPortals[1].Get(cell[1]), - CoordPortals[2].Get(cell[2]) }; - vtkm::Vec3f_32 p1{ CoordPortals[0].Get(cell[0] + 1), - CoordPortals[1].Get(cell[1] + 1), - CoordPortals[2].Get(cell[2] + 1) }; - invSpacing = 1.f / (p1 - p0); - } }; // class RectilinearLocatorAdopter template @@ -149,12 +147,22 @@ private: using UniformArrayHandle = vtkm::cont::ArrayHandleUniformPointCoordinates; using UniformConstPortal = typename UniformArrayHandle::ReadPortalType; - vtkm::Vec3f_32 InvSpacing; UniformConstPortal Coordinates; vtkm::exec::ConnectivityStructured Conn; vtkm::exec::CellLocatorUniformGrid Locator; + vtkm::Vec3f_32 InvSpacing{ 0, 0, 0 }; + + VTKM_EXEC + inline void ComputeInvSpacing(vtkm::Id3&, + const vtkm::Vec3f_32&, + vtkm::Vec3f_32& invSpacing, + vtkm::Vec3f_32&) const + { + invSpacing = InvSpacing; + } + public: UniformLocatorAdopter(const UniformArrayHandle& coordinates, vtkm::cont::CellSetStructured<3>& cellset, @@ -172,15 +180,6 @@ public: InvSpacing[1] = 1.f / spacing[1]; InvSpacing[2] = 1.f / spacing[2]; } - - VTKM_EXEC - inline void ComputeInvSpacing(vtkm::Id3&, - const vtkm::Vec3f_32&, - vtkm::Vec3f_32& invSpacing, - vtkm::Vec3f_32&) const - { - invSpacing = InvSpacing; - } }; // class UniformLocatorAdopter } //namespace @@ -356,13 +355,7 @@ public: distance += SampleDistance; sampleLocation = sampleLocation + SampleDistance * rayDir; - // parametric coordinate within the cell for the new sample location - // TODO: this is essentially a WorldToParametric coordinate transform, how can we use the rest of VTKm - // to do it? The goal is to abstract and remove invSpacing, which is different from Uniform and Rectilinear - // grid. parametric = (sampleLocation - bottomLeft) * invSpacing; - // FIXME: what's wrong with the following? - // parametric += SampleDistance * rayDir * invSpacing; } color[0] = vtkm::Min(color[0], 1.f); @@ -491,7 +484,7 @@ public: scalar0 = vtkm::Float32(scalars.Get(cellId)); vtkm::Float32 normalizedScalar = (scalar0 - MinScalar) * InverseDeltaScalar; - vtkm::Id colorIndex = + auto colorIndex = static_cast(normalizedScalar * static_cast(ColorMapSize)); if (colorIndex < 0) colorIndex = 0; @@ -517,7 +510,6 @@ public: distance += SampleDistance; sampleLocation = sampleLocation + SampleDistance * rayDir; - // parametric coordinate within the cell for the new sample location parametric = (sampleLocation - bottomLeft) * invSpacing; } @@ -548,7 +540,7 @@ class CalcRayStart : public vtkm::worklet::WorkletMapField public: VTKM_CONT - CalcRayStart(const vtkm::Bounds boundingBox) + explicit CalcRayStart(const vtkm::Bounds boundingBox) { Xmin = static_cast(boundingBox.X.Min); Xmax = static_cast(boundingBox.X.Max); @@ -559,10 +551,10 @@ public: } VTKM_EXEC - vtkm::Float32 rcp(vtkm::Float32 f) const { return 1.0f / f; } + static vtkm::Float32 rcp(vtkm::Float32 f) { return 1.0f / f; } VTKM_EXEC - vtkm::Float32 rcp_safe(vtkm::Float32 f) const { return rcp((fabs(f) < 1e-8f) ? 1e-8f : f); } + static vtkm::Float32 rcp_safe(vtkm::Float32 f) { return rcp((fabs(f) < 1e-8f) ? 1e-8f : f); } using ControlSignature = void(FieldIn, FieldOut, FieldInOut, FieldInOut, FieldIn); using ExecutionSignature = void(_1, _2, _3, _4, _5); @@ -573,12 +565,12 @@ public: vtkm::Float32& maxDistance, const vtkm::Vec& rayOrigin) const { - vtkm::Float32 dirx = static_cast(rayDir[0]); - vtkm::Float32 diry = static_cast(rayDir[1]); - vtkm::Float32 dirz = static_cast(rayDir[2]); - vtkm::Float32 origx = static_cast(rayOrigin[0]); - vtkm::Float32 origy = static_cast(rayOrigin[1]); - vtkm::Float32 origz = static_cast(rayOrigin[2]); + auto dirx = static_cast(rayDir[0]); + auto diry = static_cast(rayDir[1]); + auto dirz = static_cast(rayDir[2]); + auto origx = static_cast(rayOrigin[0]); + auto origy = static_cast(rayOrigin[1]); + auto origz = static_cast(rayOrigin[2]); vtkm::Float32 invDirx = rcp_safe(dirx); vtkm::Float32 invDiry = rcp_safe(diry);