Commit 32b87b8b authored by Larsen, Matthew's avatar Larsen, Matthew Committed by Kitware Robot
Browse files

Merge topic 'the_robot_made_me_do_this_to_fix_things'

b9326c20 force update the images
b4877cf7 fix conversion warning
cac09110

 fix rendering depths and divide by zero

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !2419
parents 21eac99c b9326c20
version https://git-lfs.github.com/spec/v1
oid sha256:b4f049b4f0e79a27ebbdab187325db55653abe2ce661c8f1d2f3fcb413e3b961
size 10883
oid sha256:785051d9773c4a0ced2701de3499f9cd948da2a4c846a5187e30dfb5cb0783cb
size 10830
version https://git-lfs.github.com/spec/v1
oid sha256:8c22f2d4e19191ff05d9dc52ea740269fcdfe129b9d100ea8db6d4cbb989b161
size 9652
oid sha256:1d990b5f0e9ef27e4e5f87f4c62c4f9974992506521f32bd5901ac6670e71bfa
size 9656
version https://git-lfs.github.com/spec/v1
oid sha256:74995441b8f0c0c19b16d45c489932958784bb3f32c65fd274985b3ecfcc87d6
size 19885
oid sha256:54e09a09c97a20627e54c835d2d488bc9f692ef1315122ab60241c006ab78813
size 19742
version https://git-lfs.github.com/spec/v1
oid sha256:573927195d4a2dbcc5f92b9f443dcdeaa30b0e27c77da3563bf91064b6d037ad
size 31339
oid sha256:e1472e6002ca4ad4012e0c9f067f8254290fabe93c82713a4994ad97a7fdbdfc
size 31218
version https://git-lfs.github.com/spec/v1
oid sha256:db2f033837778828b54f398bbc9df180eb8da425cb29025c13e3930aa9c02da3
size 71673
oid sha256:5ff6d72bd325ffe0fb3b22bfdc294b6d674384afd662290424bb77634202b4ef
size 71150
version https://git-lfs.github.com/spec/v1
oid sha256:a20e53e0ed56502d9a821fcceef2c0b34e71d2a5748519fd55352c3824582675
size 37150
oid sha256:24c71e8846fe62e6f6eefdb72c9729639061af80bf9d3453d35c8c6838de9174
size 37162
version https://git-lfs.github.com/spec/v1
oid sha256:a2147c3e30227d41dca5b6b18a1df6474ffe7f4fd6a72614979c5245299c973a
size 51846
oid sha256:b4c905ec76e72513519515ec41cf5efd34490b98255ee7465f8b6746fcff41e5
size 51865
......@@ -286,7 +286,7 @@ void Camera::ResetToBounds(const vtkm::Bounds& dataBounds,
vtkm::Float32 diagonalLength = vtkm::Magnitude(totalExtent);
this->SetPosition(center + directionOfProjection * diagonalLength * 1.0f);
this->SetFieldOfView(60.0f);
this->SetClippingRange(0.1f * diagonalLength, diagonalLength * 10.0f);
this->SetClippingRange(0.1f * diagonalLength, diagonalLength * 5.0f);
// Reset for 2D camera
this->SetViewRange2D(db);
......
......@@ -27,11 +27,13 @@ namespace internal
class SurfaceConverter : public vtkm::worklet::WorkletMapField
{
vtkm::Matrix<vtkm::Float32, 4, 4> ViewProjMat;
bool Is3d;
public:
VTKM_CONT
SurfaceConverter(const vtkm::Matrix<vtkm::Float32, 4, 4> viewProjMat)
SurfaceConverter(const vtkm::Matrix<vtkm::Float32, 4, 4> viewProjMat, bool is3d)
: ViewProjMat(viewProjMat)
, Is3d(is3d)
{
}
......@@ -51,7 +53,18 @@ public:
ColorBufferPortalType& colorBuffer,
const vtkm::Id& index) const
{
vtkm::Vec<Precision, 3> intersection = origin + inDepth * dir;
vtkm::Vec<Precision, 3> intersection;
// For reasons I can't explain atm, the view direction
// is different for for 2d and 3d so that it matches the
// gl depth buffer values for annotations
if (Is3d)
{
intersection = origin + inDepth * dir;
}
else
{
intersection = origin + inDepth * (-dir);
}
vtkm::Vec4f_32 point;
point[0] = static_cast<vtkm::Float32>(intersection[0]);
point[1] = static_cast<vtkm::Float32>(intersection[1]);
......@@ -105,7 +118,8 @@ VTKM_CONT void WriteToCanvas(const vtkm::rendering::raytracing::Ray<Precision>&
vtkm::MatrixMultiply(camera.CreateProjectionMatrix(canvas->GetWidth(), canvas->GetHeight()),
camera.CreateViewMatrix());
vtkm::worklet::DispatcherMapField<SurfaceConverter>(SurfaceConverter(viewProjMat))
bool is3d = camera.GetMode() == vtkm::rendering::Camera::MODE_3D;
vtkm::worklet::DispatcherMapField<SurfaceConverter>(SurfaceConverter(viewProjMat, is3d))
.Invoke(rays.PixelIdx,
colors,
rays.Distance,
......
......@@ -55,6 +55,11 @@ void LineRenderer::RenderLine(const vtkm::Vec3f_64& 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;
const vtkm::Id xStart = x0;
const vtkm::Id yStart = y0;
const vtkm::Float32 pdist = vtkm::Sqrt(vtkm::Float32(dx * dx) + vtkm::Float32(dy * dy));
auto colorPortal =
vtkm::rendering::Canvas::ColorBufferType(Canvas->GetColorBuffer()).WritePortal();
auto depthPortal =
......@@ -63,9 +68,19 @@ void LineRenderer::RenderLine(const vtkm::Vec3f_64& point0,
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]);
vtkm::Float32 deltaX = static_cast<vtkm::Float32>(x0 - xStart);
vtkm::Float32 deltaY = static_cast<vtkm::Float32>(y0 - yStart);
// Depth is wrong, but its far less wrong that it used to be.
// These depth values are in screen space, which have been
// potentially tranformed by a perspective correction.
// To interpolated the depth correctly, there must be a perspective correction.
// I haven't looked, but the wireframmer probably suffers from this too.
// Additionally, this should not happen on the CPU. Annotations take
// far longer than the the geometry.
vtkm::Float32 t = pdist == 0.f ? 1.0f : vtkm::Sqrt(deltaX * deltaX + deltaY * deltaY) / pdist;
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;
vtkm::Vec4f_32 currentColor = colorPortal.Get(index);
vtkm::Float32 currentZ = depthPortal.Get(index);
......@@ -85,6 +100,7 @@ void LineRenderer::RenderLine(const vtkm::Vec3f_64& point0,
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
// Matt: this is correct. Interpolation is wrong
depth = currentZ;
}
......
......@@ -379,7 +379,7 @@ public:
: MinScalar(minScalar)
{
Normalize = true;
if (minScalar > maxScalar)
if (minScalar >= maxScalar)
{
// support the scalar renderer
Normalize = false;
......
......@@ -366,7 +366,7 @@ public:
: MinScalar(minScalar)
{
Normalize = true;
if (minScalar > maxScalar)
if (minScalar >= maxScalar)
{
// support the scalar renderer
Normalize = false;
......
......@@ -28,7 +28,7 @@ void RayOperations::MapCanvasToRays(Ray<vtkm::Float32>& rays,
(void)valid; // this can be a false negative for really tiny spatial domains.
vtkm::worklet::DispatcherMapField<detail::RayMapCanvas>(
detail::RayMapCanvas(inverse, width, height, camera.GetPosition()))
.Invoke(rays.PixelIdx, rays.MaxDistance, canvas.GetDepthBuffer());
.Invoke(rays.PixelIdx, rays.MaxDistance, rays.Origin, canvas.GetDepthBuffer());
}
}
}
......
......@@ -70,12 +70,13 @@ public:
DoubleInvWidth = 2.f / static_cast<vtkm::Float32>(width);
}
using ControlSignature = void(FieldIn, FieldInOut, WholeArrayIn);
using ExecutionSignature = void(_1, _2, _3);
using ControlSignature = void(FieldIn, FieldInOut, FieldIn, WholeArrayIn);
using ExecutionSignature = void(_1, _2, _3, _4);
template <typename Precision, typename DepthPortalType>
VTKM_EXEC void operator()(const vtkm::Id& pixelId,
Precision& maxDistance,
const Vec<Precision, 3>& origin,
const DepthPortalType& depths) const
{
vtkm::Vec4f_32 position;
......@@ -94,7 +95,8 @@ public:
p[0] = position[0] / position[3];
p[1] = position[1] / position[3];
p[2] = position[2] / position[3];
p = p - Origin;
p = p - origin;
maxDistance = vtkm::Magnitude(p);
}
......
......@@ -277,6 +277,7 @@ void RayTracer::RenderOnDevice(Ray<Precision>& rays)
logger->AddLogData("shapes", NumberOfShapes);
logger->AddLogData("num_rays", rays.NumRays);
size_t numShapes = Intersectors.size();
if (NumberOfShapes > 0)
{
......
......@@ -257,7 +257,7 @@ public:
: MinScalar(minScalar)
{
Normalize = true;
if (minScalar > maxScalar)
if (minScalar >= maxScalar)
{
// support the scalar renderer
Normalize = false;
......
......@@ -251,7 +251,7 @@ public:
: MinScalar(minScalar)
{
Normalize = true;
if (minScalar > maxScalar)
if (minScalar >= maxScalar)
{
// support the scalar renderer
Normalize = false;
......@@ -315,7 +315,7 @@ public:
: MinScalar(minScalar)
{
Normalize = true;
if (minScalar > maxScalar)
if (minScalar >= maxScalar)
{
// support the scalar renderer
Normalize = false;
......
Supports Markdown
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