mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Depth no considered with annotations. Fix for volume renderer. Consistent color blending.
This commit is contained in:
parent
b420a4b3d2
commit
c57fad48ee
@ -159,6 +159,9 @@ void AxisAnnotation3D::Render(const Camera& camera,
|
||||
this->Labels[i]->SetPosition(vtkm::Float32(tickPos[0] - tickSize[0]),
|
||||
vtkm::Float32(tickPos[1] - tickSize[1]),
|
||||
vtkm::Float32(tickPos[2] - tickSize[2]));
|
||||
vtkm::Vec<vtkm::Float32, 3> pp(vtkm::Float32(tickPos[0] - tickSize[0]),
|
||||
vtkm::Float32(tickPos[1] - tickSize[1]),
|
||||
vtkm::Float32(tickPos[2] - tickSize[2]));
|
||||
this->Labels[i]->SetAlignment(TextAnnotation::HCenter, TextAnnotation::VCenter);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ struct ClearBuffers : public vtkm::worklet::WorkletMapField
|
||||
color[3] = 0.f;
|
||||
// The depth is set to slightly larger than 1.0f, ensuring this color value always fails a
|
||||
// depth check
|
||||
depth = 1.001f;
|
||||
depth = VTKM_DEFAULT_CANVAS_DEPTH;
|
||||
}
|
||||
}; // struct ClearBuffers
|
||||
|
||||
@ -581,7 +581,8 @@ void Canvas::AddText(const vtkm::Matrix<vtkm::Float32, 4, 4>& transform,
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const
|
||||
const std::string& text,
|
||||
const vtkm::Float32& depth) const
|
||||
{
|
||||
if (!Internals->FontTexture.IsValid())
|
||||
{
|
||||
@ -593,7 +594,7 @@ void Canvas::AddText(const vtkm::Matrix<vtkm::Float32, 4, 4>& transform,
|
||||
|
||||
vtkm::rendering::Canvas* self = const_cast<vtkm::rendering::Canvas*>(this);
|
||||
TextRenderer fontRenderer(self, Internals->Font, Internals->FontTexture);
|
||||
fontRenderer.RenderText(transform, scale, anchor, color, text);
|
||||
fontRenderer.RenderText(transform, scale, anchor, color, text, depth);
|
||||
}
|
||||
|
||||
void Canvas::AddText(const vtkm::Vec<vtkm::Float32, 2>& position,
|
||||
@ -612,7 +613,7 @@ void Canvas::AddText(const vtkm::Vec<vtkm::Float32, 2>& position,
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> transform =
|
||||
vtkm::MatrixMultiply(translationMatrix, vtkm::MatrixMultiply(scaleMatrix, rotationMatrix));
|
||||
|
||||
this->AddText(transform, scale, anchor, color, text);
|
||||
this->AddText(transform, scale, anchor, color, text, 0.f);
|
||||
}
|
||||
|
||||
void Canvas::AddText(vtkm::Float32 x,
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include <vtkm/rendering/ColorTable.h>
|
||||
#include <vtkm/rendering/Texture2D.h>
|
||||
|
||||
#define VTKM_DEFAULT_CANVAS_DEPTH 1.001f
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
@ -188,7 +190,8 @@ public:
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const;
|
||||
const std::string& text,
|
||||
const vtkm::Float32& depth) const;
|
||||
|
||||
|
||||
friend class AxisAnnotation2D;
|
||||
|
@ -263,7 +263,8 @@ void CanvasGL::AddText(const vtkm::Vec<vtkm::Float32, 2>& position,
|
||||
vtkm::Float32 windowAspect,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const
|
||||
const std::string& text,
|
||||
const vtkm::Float32& vtkmNotUsed(depth)) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(position[0], position[1], 0);
|
||||
|
@ -82,7 +82,8 @@ protected:
|
||||
vtkm::Float32 windowAspect,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const override;
|
||||
const std::string& text,
|
||||
const vtkm::Float32& depth = 0.f) const override;
|
||||
|
||||
private:
|
||||
vtkm::rendering::BitmapFont Font;
|
||||
|
@ -68,7 +68,6 @@ public:
|
||||
{
|
||||
vtkm::Vec<Precision, 3> intersection = origin + inDepth * dir;
|
||||
vtkm::Vec<vtkm::Float32, 4> point;
|
||||
|
||||
point[0] = static_cast<vtkm::Float32>(intersection[0]);
|
||||
point[1] = static_cast<vtkm::Float32>(intersection[1]);
|
||||
point[2] = static_cast<vtkm::Float32>(intersection[2]);
|
||||
@ -91,11 +90,12 @@ public:
|
||||
// blend the mapped color with existing canvas color
|
||||
vtkm::Vec<vtkm::Float32, 4> inColor = colorBuffer.Get(pixelIndex);
|
||||
|
||||
vtkm::Float32 alpha = inColor[3] * (1.f - color[3]);
|
||||
// if transparency exists, all alphas have been pre-multiplied
|
||||
vtkm::Float32 alpha = (1.f - color[3]);
|
||||
color[0] = color[0] + inColor[0] * alpha;
|
||||
color[1] = color[1] + inColor[1] * alpha;
|
||||
color[2] = color[2] + inColor[2] * alpha;
|
||||
color[3] = alpha + color[3];
|
||||
color[3] = inColor[3] * alpha + color[3];
|
||||
|
||||
// clamp
|
||||
for (vtkm::Int32 i = 0; i < 4; ++i)
|
||||
|
@ -65,21 +65,43 @@ void LineRenderer::RenderLine(const vtkm::Vec<vtkm::Float64, 3>& point0,
|
||||
vtkm::Id dx = vtkm::Abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
|
||||
vtkm::Id dy = -vtkm::Abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
|
||||
vtkm::Id err = dx + dy, err2 = 0;
|
||||
vtkm::rendering::Canvas::ColorBufferType::PortalControl colorPortal =
|
||||
auto colorPortal =
|
||||
vtkm::rendering::Canvas::ColorBufferType(Canvas->GetColorBuffer()).GetPortalControl();
|
||||
vtkm::rendering::Canvas::DepthBufferType::PortalControl depthPortal =
|
||||
auto depthPortal =
|
||||
vtkm::rendering::Canvas::DepthBufferType(Canvas->GetDepthBuffer()).GetPortalControl();
|
||||
vtkm::Vec<vtkm::Float32, 4> colorC = color.Components;
|
||||
|
||||
while (x0 >= 0 && x0 < Canvas->GetWidth() && y0 >= 0 && y0 < Canvas->GetHeight())
|
||||
{
|
||||
vtkm::Float32 t = (dx == 0) ? 1.0f : (static_cast<vtkm::Float32>(x0) - p0[0]) / (p1[0] - p0[0]);
|
||||
t = vtkm::Min(1.f, vtkm::Max(0.f, t));
|
||||
vtkm::Float32 z = vtkm::Lerp(z0, z1, t);
|
||||
vtkm::Id index = y0 * Canvas->GetWidth() + x0;
|
||||
if (depthPortal.Get(index) > z)
|
||||
vtkm::Vec<vtkm::Float32, 4> currentColor = colorPortal.Get(index);
|
||||
vtkm::Float32 currentZ = depthPortal.Get(index);
|
||||
bool blend = currentColor[3] < 1.f && z > currentZ;
|
||||
if (currentZ > z || blend)
|
||||
{
|
||||
depthPortal.Set(index, z);
|
||||
colorPortal.Set(index, colorC);
|
||||
vtkm::Vec<vtkm::Float32, 4> writeColor = colorC;
|
||||
vtkm::Float32 depth = z;
|
||||
|
||||
if (blend)
|
||||
{
|
||||
// If there is any transparency, all alphas
|
||||
// have been pre-mulitplied
|
||||
vtkm::Float32 alpha = (1.f - currentColor[3]);
|
||||
writeColor[0] = currentColor[0] + colorC[0] * alpha;
|
||||
writeColor[1] = currentColor[1] + colorC[1] * alpha;
|
||||
writeColor[2] = currentColor[2] + colorC[2] * alpha;
|
||||
writeColor[3] = 1.f * alpha + currentColor[3]; // we are always drawing opaque lines
|
||||
// keep the current z. Line z interpolation is not accurate
|
||||
depth = currentZ;
|
||||
}
|
||||
|
||||
depthPortal.Set(index, depth);
|
||||
colorPortal.Set(index, writeColor);
|
||||
}
|
||||
|
||||
if (x0 == x1 && y0 == y1)
|
||||
{
|
||||
break;
|
||||
|
@ -69,7 +69,6 @@ void TextAnnotationBillboard::Render(const vtkm::rendering::Camera& camera,
|
||||
vtkm::MatrixMultiply(projectionMatrix, viewMatrix), this->Position);
|
||||
|
||||
canvas.SetViewToScreenSpace(camera, true);
|
||||
|
||||
MatrixType translateMatrix =
|
||||
vtkm::Transform3DTranslate(screenPos[0], screenPos[1], -screenPos[2]);
|
||||
|
||||
@ -98,7 +97,10 @@ void TextAnnotationBillboard::Render(const vtkm::rendering::Camera& camera,
|
||||
VectorType right = vtkm::Transform3DVector(fullTransformMatrix, VectorType(1, 0, 0));
|
||||
VectorType up = vtkm::Transform3DVector(fullTransformMatrix, VectorType(0, 1, 0));
|
||||
|
||||
worldAnnotator.AddText(origin, right, up, this->Scale, this->Anchor, this->TextColor, this->Text);
|
||||
// scale depth from (1, -1) to (0, 1);
|
||||
vtkm::Float32 depth = screenPos[2] * .5f + .5f;
|
||||
worldAnnotator.AddText(
|
||||
origin, right, up, this->Scale, this->Anchor, this->TextColor, this->Text, depth);
|
||||
|
||||
canvas.SetViewToWorldSpace(camera, true);
|
||||
}
|
||||
|
@ -35,34 +35,43 @@ namespace internal
|
||||
struct RenderBitmapFont : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
using ColorBufferType = vtkm::rendering::Canvas::ColorBufferType;
|
||||
using DepthBufferType = vtkm::rendering::Canvas::DepthBufferType;
|
||||
using FontTextureType = vtkm::rendering::Canvas::FontTextureType;
|
||||
|
||||
typedef void ControlSignature(FieldIn<>, FieldIn<>, ExecObject, WholeArrayInOut<>);
|
||||
typedef void ExecutionSignature(_1, _2, _3, _4);
|
||||
typedef void ControlSignature(FieldIn<>,
|
||||
FieldIn<>,
|
||||
ExecObject,
|
||||
WholeArrayInOut<>,
|
||||
WholeArrayInOut<>);
|
||||
typedef void ExecutionSignature(_1, _2, _3, _4, _5);
|
||||
using InputDomain = _1;
|
||||
|
||||
VTKM_CONT
|
||||
RenderBitmapFont() {}
|
||||
|
||||
VTKM_CONT
|
||||
RenderBitmapFont(const vtkm::Vec<vtkm::Float32, 4>& color, vtkm::Id width, vtkm::Id height)
|
||||
RenderBitmapFont(const vtkm::Vec<vtkm::Float32, 4>& color,
|
||||
vtkm::Id width,
|
||||
vtkm::Id height,
|
||||
vtkm::Float32 depth)
|
||||
: Color(color)
|
||||
, Width(width)
|
||||
, Height(height)
|
||||
, Depth(depth)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ColorBufferPortal, typename FontTexture>
|
||||
template <typename ColorBufferPortal, typename FontTexture, typename DepthBufferPortal>
|
||||
VTKM_EXEC void operator()(const vtkm::Vec<vtkm::Float32, 4>& screenCoords,
|
||||
const vtkm::Vec<vtkm::Float32, 4>& textureCoords,
|
||||
const FontTexture& fontTexture,
|
||||
ColorBufferPortal& colorBuffer) const
|
||||
ColorBufferPortal& colorBuffer,
|
||||
DepthBufferPortal& depthBuffer) const
|
||||
{
|
||||
vtkm::Float32 x0 = Clamp(screenCoords[0], 0.0f, static_cast<vtkm::Float32>(Width - 1));
|
||||
vtkm::Float32 x1 = Clamp(screenCoords[2], 0.0f, static_cast<vtkm::Float32>(Width - 1));
|
||||
vtkm::Float32 y0 = Clamp(screenCoords[1], 0.0f, static_cast<vtkm::Float32>(Height - 1));
|
||||
vtkm::Float32 y1 = Clamp(screenCoords[3], 0.0f, static_cast<vtkm::Float32>(Height - 1));
|
||||
|
||||
// For crisp text rendering, we sample the font texture at points smaller than the pixel
|
||||
// sizes. Here we sample at increments of 0.25f, and scale the reported intensities accordingly
|
||||
vtkm::Float32 dx = x1 - x0, dy = y1 - y0;
|
||||
@ -75,28 +84,43 @@ struct RenderBitmapFont : public vtkm::worklet::WorkletMapField
|
||||
vtkm::Float32 u = vtkm::Lerp(textureCoords[0], textureCoords[2], tu);
|
||||
vtkm::Float32 v = vtkm::Lerp(textureCoords[1], textureCoords[3], tv);
|
||||
vtkm::Float32 intensity = fontTexture.GetColor(u, v)[0] * 0.25f;
|
||||
Plot(x, y, intensity, colorBuffer);
|
||||
Plot(x, y, intensity, colorBuffer, depthBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ColorBufferPortal>
|
||||
template <typename ColorBufferPortal, typename DepthBufferPortal>
|
||||
void Plot(vtkm::Float32 x,
|
||||
vtkm::Float32 y,
|
||||
vtkm::Float32 intensity,
|
||||
ColorBufferPortal& colorBuffer) const
|
||||
ColorBufferPortal& colorBuffer,
|
||||
DepthBufferPortal& depthBuffer) const
|
||||
{
|
||||
vtkm::Id index =
|
||||
static_cast<vtkm::Id>(vtkm::Round(y)) * Width + static_cast<vtkm::Id>(vtkm::Round(x));
|
||||
vtkm::Vec<vtkm::Float32, 4> srcColor = colorBuffer.Get(index);
|
||||
vtkm::Float32 currentDepth = depthBuffer.Get(index);
|
||||
bool swap = Depth > currentDepth;
|
||||
|
||||
intensity = intensity * Color[3];
|
||||
vtkm::Float32 inverseIntensity = 1.0f - intensity;
|
||||
vtkm::Float32 alpha = srcColor[3] * inverseIntensity;
|
||||
vtkm::Vec<vtkm::Float32, 4> color = intensity * Color;
|
||||
color[3] = intensity;
|
||||
vtkm::Vec<vtkm::Float32, 4> front = color;
|
||||
vtkm::Vec<vtkm::Float32, 4> back = srcColor;
|
||||
|
||||
if (swap)
|
||||
{
|
||||
front = srcColor;
|
||||
back = color;
|
||||
}
|
||||
|
||||
vtkm::Vec<vtkm::Float32, 4> blendedColor;
|
||||
blendedColor[0] = Color[0] * intensity + srcColor[0] * alpha;
|
||||
blendedColor[1] = Color[1] * intensity + srcColor[1] * alpha;
|
||||
blendedColor[2] = Color[2] * intensity + srcColor[2] * alpha;
|
||||
blendedColor[3] = alpha + intensity;
|
||||
vtkm::Float32 alpha = (1.f - front[3]);
|
||||
blendedColor[0] = front[0] + back[0] * alpha;
|
||||
blendedColor[1] = front[1] + back[1] * alpha;
|
||||
blendedColor[2] = front[2] + back[2] * alpha;
|
||||
blendedColor[3] = back[3] * alpha + front[3];
|
||||
|
||||
colorBuffer.Set(index, blendedColor);
|
||||
}
|
||||
|
||||
@ -109,11 +133,13 @@ struct RenderBitmapFont : public vtkm::worklet::WorkletMapField
|
||||
vtkm::Vec<vtkm::Float32, 4> Color;
|
||||
vtkm::Id Width;
|
||||
vtkm::Id Height;
|
||||
vtkm::Float32 Depth;
|
||||
}; // struct RenderBitmapFont
|
||||
|
||||
struct RenderBitmapFontExecutor
|
||||
{
|
||||
using ColorBufferType = vtkm::rendering::Canvas::ColorBufferType;
|
||||
using DepthBufferType = vtkm::rendering::Canvas::DepthBufferType;
|
||||
using FontTextureType = vtkm::rendering::Canvas::FontTextureType;
|
||||
using ScreenCoordsArrayHandle = vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Id, 4>>;
|
||||
using TextureCoordsArrayHandle = vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 4>>;
|
||||
@ -124,13 +150,16 @@ struct RenderBitmapFontExecutor
|
||||
const FontTextureType& fontTexture,
|
||||
const vtkm::Vec<vtkm::Float32, 4>& color,
|
||||
const ColorBufferType& colorBuffer,
|
||||
const DepthBufferType& depthBuffer,
|
||||
vtkm::Id width,
|
||||
vtkm::Id height)
|
||||
vtkm::Id height,
|
||||
vtkm::Float32 depth)
|
||||
: ScreenCoords(screenCoords)
|
||||
, TextureCoords(textureCoords)
|
||||
, FontTexture(fontTexture)
|
||||
, ColorBuffer(colorBuffer)
|
||||
, Worklet(color, width, height)
|
||||
, DepthBuffer(depthBuffer)
|
||||
, Worklet(color, width, height, depth)
|
||||
{
|
||||
}
|
||||
|
||||
@ -141,7 +170,7 @@ struct RenderBitmapFontExecutor
|
||||
|
||||
vtkm::worklet::DispatcherMapField<RenderBitmapFont, Device> dispatcher(Worklet);
|
||||
dispatcher.Invoke(
|
||||
ScreenCoords, TextureCoords, FontTexture.GetExecObject<Device>(), ColorBuffer);
|
||||
ScreenCoords, TextureCoords, FontTexture.GetExecObject<Device>(), ColorBuffer, DepthBuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -149,6 +178,7 @@ struct RenderBitmapFontExecutor
|
||||
TextureCoordsArrayHandle TextureCoords;
|
||||
FontTextureType FontTexture;
|
||||
ColorBufferType ColorBuffer;
|
||||
DepthBufferType DepthBuffer;
|
||||
RenderBitmapFont Worklet;
|
||||
}; // struct RenderBitmapFontExecutor
|
||||
} // namespace internal
|
||||
@ -201,7 +231,8 @@ void TextRenderer::RenderText(const vtkm::Matrix<vtkm::Float32, 4, 4>& transform
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text)
|
||||
const std::string& text,
|
||||
const vtkm::Float32& depth)
|
||||
{
|
||||
vtkm::Float32 textWidth = this->Font.GetTextWidth(text);
|
||||
vtkm::Float32 fx = -(0.5f + 0.5f * anchor[0]) * textWidth;
|
||||
@ -246,8 +277,10 @@ void TextRenderer::RenderText(const vtkm::Matrix<vtkm::Float32, 4, 4>& transform
|
||||
FontTexture,
|
||||
color.Components,
|
||||
Canvas->GetColorBuffer(),
|
||||
Canvas->GetDepthBuffer(),
|
||||
Canvas->GetWidth(),
|
||||
Canvas->GetHeight()));
|
||||
Canvas->GetHeight(),
|
||||
depth));
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
@ -64,7 +64,8 @@ public:
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text);
|
||||
const std::string& text,
|
||||
const vtkm::Float32& depth = 0.f);
|
||||
|
||||
private:
|
||||
const vtkm::rendering::Canvas* Canvas;
|
||||
|
@ -54,7 +54,8 @@ void WorldAnnotator::AddText(const vtkm::Vec<vtkm::Float32, 3>& origin,
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const
|
||||
const std::string& text,
|
||||
const vtkm::Float32 depth) const
|
||||
{
|
||||
vtkm::Vec<vtkm::Float32, 3> n = vtkm::Cross(right, up);
|
||||
vtkm::Normalize(n);
|
||||
@ -62,7 +63,7 @@ void WorldAnnotator::AddText(const vtkm::Vec<vtkm::Float32, 3>& origin,
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> transform = MatrixHelpers::WorldMatrix(origin, right, up, n);
|
||||
transform = vtkm::MatrixMultiply(Canvas->GetModelView(), transform);
|
||||
transform = vtkm::MatrixMultiply(Canvas->GetProjection(), transform);
|
||||
Canvas->AddText(transform, scale, anchor, color, text);
|
||||
Canvas->AddText(transform, scale, anchor, color, text, depth);
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::rendering
|
||||
|
@ -67,7 +67,8 @@ public:
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const;
|
||||
const std::string& text,
|
||||
const vtkm::Float32 depth = 0.f) const;
|
||||
|
||||
VTKM_CONT
|
||||
void AddText(vtkm::Float32 originX,
|
||||
|
@ -78,7 +78,8 @@ void WorldAnnotatorGL::AddText(const vtkm::Vec<vtkm::Float32, 3>& origin,
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const
|
||||
const std::string& text,
|
||||
const vtkm::Float32 vtkmNotUsed(depth)) const
|
||||
{
|
||||
|
||||
vtkm::Vec<vtkm::Float32, 3> n = vtkm::Cross(right, up);
|
||||
|
@ -50,7 +50,8 @@ public:
|
||||
vtkm::Float32 scale,
|
||||
const vtkm::Vec<vtkm::Float32, 2>& anchor,
|
||||
const vtkm::rendering::Color& color,
|
||||
const std::string& text) const override;
|
||||
const std::string& text,
|
||||
const vtkm::Float32 depth = 0.f) const override;
|
||||
|
||||
private:
|
||||
BitmapFont Font;
|
||||
|
@ -340,16 +340,18 @@ public:
|
||||
InverseDeltaScalar = minScalar;
|
||||
}
|
||||
typedef void ControlSignature(FieldIn<>,
|
||||
FieldIn<>,
|
||||
FieldIn<>,
|
||||
FieldIn<>,
|
||||
WholeArrayInOut<>,
|
||||
WholeArrayIn<ScalarRenderingTypes>);
|
||||
typedef void ExecutionSignature(_1, _2, _3, _4, _5, WorkIndex);
|
||||
typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6, WorkIndex);
|
||||
|
||||
template <typename ScalarPortalType, typename ColorBufferType>
|
||||
VTKM_EXEC void operator()(const vtkm::Vec<vtkm::Float32, 3>& rayDir,
|
||||
const vtkm::Vec<vtkm::Float32, 3>& rayOrigin,
|
||||
const vtkm::Float32& minDistance,
|
||||
const vtkm::Float32& maxDistance,
|
||||
ColorBufferType& colorBuffer,
|
||||
ScalarPortalType& scalars,
|
||||
const vtkm::Id& pixelIndex) const
|
||||
@ -370,7 +372,8 @@ public:
|
||||
}
|
||||
//get the initial sample position;
|
||||
vtkm::Vec<vtkm::Float32, 3> sampleLocation;
|
||||
sampleLocation = rayOrigin + (0.0001f + minDistance) * rayDir;
|
||||
vtkm::Float32 distance = 0.00001f + minDistance;
|
||||
sampleLocation = rayOrigin + distance * rayDir;
|
||||
/*
|
||||
7----------6
|
||||
/| /|
|
||||
@ -399,7 +402,7 @@ public:
|
||||
vtkm::Vec<vtkm::Float32, 3> invSpacing(0.f, 0.f, 0.f);
|
||||
|
||||
|
||||
while (Locator.IsInside(sampleLocation))
|
||||
while (Locator.IsInside(sampleLocation) && distance < maxDistance)
|
||||
{
|
||||
vtkm::Float32 mint = vtkm::Min(tx, vtkm::Min(ty, tz));
|
||||
vtkm::Float32 maxt = vtkm::Max(tx, vtkm::Max(ty, tz));
|
||||
@ -464,6 +467,7 @@ public:
|
||||
color[2] = color[2] + sampleColor[2] * sampleColor[3];
|
||||
color[3] = sampleColor[3] + color[3];
|
||||
//advance
|
||||
distance += SampleDistance;
|
||||
sampleLocation = sampleLocation + SampleDistance * rayDir;
|
||||
|
||||
//this is linear could just do an addition
|
||||
@ -523,16 +527,18 @@ public:
|
||||
InverseDeltaScalar = minScalar;
|
||||
}
|
||||
typedef void ControlSignature(FieldIn<>,
|
||||
FieldIn<>,
|
||||
FieldIn<>,
|
||||
FieldIn<>,
|
||||
WholeArrayInOut<>,
|
||||
WholeArrayIn<ScalarRenderingTypes>);
|
||||
typedef void ExecutionSignature(_1, _2, _3, _4, _5, WorkIndex);
|
||||
typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6, WorkIndex);
|
||||
|
||||
template <typename ScalarPortalType, typename ColorBufferType>
|
||||
VTKM_EXEC void operator()(const vtkm::Vec<vtkm::Float32, 3>& rayDir,
|
||||
const vtkm::Vec<vtkm::Float32, 3>& rayOrigin,
|
||||
const vtkm::Float32& minDistance,
|
||||
const vtkm::Float32& maxDistance,
|
||||
ColorBufferType& colorBuffer,
|
||||
const ScalarPortalType& scalars,
|
||||
const vtkm::Id& pixelIndex) const
|
||||
@ -551,7 +557,8 @@ public:
|
||||
return; //TODO: Compact? or just image subset...
|
||||
//get the initial sample position;
|
||||
vtkm::Vec<vtkm::Float32, 3> sampleLocation;
|
||||
sampleLocation = rayOrigin + (0.0001f + minDistance) * rayDir;
|
||||
vtkm::Float32 distance = 0.0001f + minDistance;
|
||||
sampleLocation = rayOrigin + distance * rayDir;
|
||||
|
||||
/*
|
||||
7----------6
|
||||
@ -571,7 +578,7 @@ public:
|
||||
vtkm::Vec<vtkm::Float32, 3> bottomLeft(0.f, 0.f, 0.f);
|
||||
vtkm::Vec<vtkm::Float32, 3> invSpacing(0.f, 0.f, 0.f);
|
||||
vtkm::Vec<vtkm::Id, 3> cell(0, 0, 0);
|
||||
while (Locator.IsInside(sampleLocation))
|
||||
while (Locator.IsInside(sampleLocation) && distance < maxDistance)
|
||||
{
|
||||
vtkm::Float32 mint = vtkm::Min(tx, vtkm::Min(ty, tz));
|
||||
vtkm::Float32 maxt = vtkm::Max(tx, vtkm::Max(ty, tz));
|
||||
@ -605,6 +612,7 @@ public:
|
||||
color[2] = color[2] + sampleColor[2] * alpha;
|
||||
color[3] = alpha + color[3];
|
||||
//advance
|
||||
distance += SampleDistance;
|
||||
sampleLocation = sampleLocation + SampleDistance * rayDir;
|
||||
|
||||
if (color[3] >= 1.f)
|
||||
@ -690,7 +698,7 @@ public:
|
||||
|
||||
minDistance = vtkm::Max(
|
||||
vtkm::Max(vtkm::Max(vtkm::Min(ymin, ymax), vtkm::Min(xmin, xmax)), vtkm::Min(zmin, zmax)),
|
||||
0.f);
|
||||
minDistance);
|
||||
vtkm::Float32 exitDistance =
|
||||
vtkm::Min(vtkm::Min(vtkm::Max(ymin, ymax), vtkm::Max(xmin, xmax)), vtkm::Max(zmin, zmax));
|
||||
maxDistance = vtkm::Min(maxDistance, exitDistance);
|
||||
@ -819,7 +827,12 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray<P
|
||||
vtkm::Float32(ScalarRange.Max),
|
||||
SampleDistance,
|
||||
locator))
|
||||
.Invoke(rays.Dir, rays.Origin, rays.MinDistance, rays.Buffers.at(0).Buffer, *ScalarField);
|
||||
.Invoke(rays.Dir,
|
||||
rays.Origin,
|
||||
rays.MinDistance,
|
||||
rays.MaxDistance,
|
||||
rays.Buffers.at(0).Buffer,
|
||||
*ScalarField);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -829,7 +842,12 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray<P
|
||||
vtkm::Float32(ScalarRange.Max),
|
||||
SampleDistance,
|
||||
locator))
|
||||
.Invoke(rays.Dir, rays.Origin, rays.MinDistance, rays.Buffers.at(0).Buffer, *ScalarField);
|
||||
.Invoke(rays.Dir,
|
||||
rays.Origin,
|
||||
rays.MinDistance,
|
||||
rays.MaxDistance,
|
||||
rays.Buffers.at(0).Buffer,
|
||||
*ScalarField);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -845,7 +863,12 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray<P
|
||||
vtkm::Float32(ScalarRange.Max),
|
||||
SampleDistance,
|
||||
locator))
|
||||
.Invoke(rays.Dir, rays.Origin, rays.MinDistance, rays.Buffers.at(0).Buffer, *ScalarField);
|
||||
.Invoke(rays.Dir,
|
||||
rays.Origin,
|
||||
rays.MinDistance,
|
||||
rays.MaxDistance,
|
||||
rays.Buffers.at(0).Buffer,
|
||||
*ScalarField);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -856,7 +879,12 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray<P
|
||||
vtkm::Float32(ScalarRange.Max),
|
||||
SampleDistance,
|
||||
locator))
|
||||
.Invoke(rays.Dir, rays.Origin, rays.MinDistance, rays.Buffers.at(0).Buffer, *ScalarField);
|
||||
.Invoke(rays.Dir,
|
||||
rays.Origin,
|
||||
rays.MinDistance,
|
||||
rays.MaxDistance,
|
||||
rays.Buffers.at(0).Buffer,
|
||||
*ScalarField);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user