Commit 33af0fec authored by Matt Larsen's avatar Matt Larsen
Browse files

composing ray tracer and volume renderer is successful. Still need a strategy...

composing ray tracer and volume renderer is successful. Still need a strategy for the background color.
parent 8e5f309e
......@@ -87,6 +87,7 @@ set(sources
raytracing/ChannelBuffer.cxx
raytracing/Logger.cxx
raytracing/RayTracer.cxx
raytracing/RayOperations.cxx
raytracing/VolumeRendererStructured.cxx
)
......@@ -129,6 +130,7 @@ set(device_sources
raytracing/Camera.cxx
raytracing/ChannelBuffer.cxx
raytracing/VolumeRendererStructured.cxx
raytracing/RayOperations.cxx
raytracing/RayTracer.cxx
)
......
......@@ -98,7 +98,7 @@ public:
}
typedef void ControlSignature(FieldIn<>,
WholeArrayIn<>,
WholeArrayInOut<>,
FieldIn<>,
FieldIn<>,
FieldIn<>,
......@@ -132,15 +132,16 @@ public:
vtkm::Float32 depth = newpoint[2];
depth = 0.5f * (-depth) + 0.5f;
depth = 0.5f * (depth) + 0.5f;
vtkm::Vec<vtkm::Float32, 4> color;
color[0] = static_cast<vtkm::Float32>(colorBufferIn.Get(index * 4 + 0));
color[1] = static_cast<vtkm::Float32>(colorBufferIn.Get(index * 4 + 1));
color[2] = static_cast<vtkm::Float32>(colorBufferIn.Get(index * 4 + 2));
color[3] = static_cast<vtkm::Float32>(colorBufferIn.Get(index * 4 + 3));
vtkm::Float32 existingDepth = depthBuffer.Get(pixelIndex);
//vtkm::Float32 existingDepth = depthBuffer.Get(pixelIndex);
//std::cout<<" in "<<inDepth<<" "<<depth;;
depthBuffer.Set(pixelIndex, depth);
colorBuffer.Set(pixelIndex, color);
}
......
......@@ -22,12 +22,12 @@
#include <vtkm/cont/Timer.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/cont/internal/SimplePolymorphicContainer.h>
#include <vtkm/rendering/CanvasRayTracer.h>
#include <vtkm/rendering/internal/RunTriangulator.h>
#include <vtkm/rendering/raytracing/Camera.h>
#include <vtkm/rendering/raytracing/Logger.h>
#include <vtkm/rendering/raytracing/RayOperations.h>
#include <vtkm/rendering/raytracing/RayTracer.h>
namespace vtkm
......@@ -99,7 +99,10 @@ void MapperRayTracer::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
vtkm::rendering::raytracing::Camera& cam = this->Internals->Tracer.GetCamera();
cam.SetParameters(camera, *this->Internals->Canvas);
this->Internals->RayCamera.SetParameters(camera, *this->Internals->Canvas);
this->Internals->RayCamera.CreateRays(this->Internals->Rays, coords);
raytracing::RayOperations::MapCanvasToRays(
this->Internals->Rays, camera, *this->Internals->Canvas);
vtkm::Bounds dataBounds = coords.GetBounds();
......
......@@ -27,6 +27,7 @@
#include <vtkm/rendering/raytracing/Camera.h>
#include <vtkm/rendering/raytracing/Logger.h>
#include <vtkm/rendering/raytracing/RayOperations.h>
#include <vtkm/rendering/raytracing/VolumeRendererStructured.h>
#include <sstream>
......@@ -115,8 +116,9 @@ void MapperVolume::RenderCells(const vtkm::cont::DynamicCellSet& cellset,
rayCamera.SetParameters(camera, *this->Internals->Canvas);
rayCamera.CreateRays(rays, coords);
rays.Buffers.at(0).InitConst(0.f);
raytracing::RayOperations::MapCanvasToRays(rays, camera, *this->Internals->Canvas);
if (this->Internals->SampleDistance != DEFAULT_SAMPLE_DISTANCE)
{
......
......@@ -20,6 +20,10 @@
#ifndef vtk_m_rendering_raytracing_Ray_Operations_h
#define vtk_m_rendering_raytracing_Ray_Operations_h
#include <vtkm/Matrix.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/rendering/Camera.h>
#include <vtkm/rendering/CanvasRayTracer.h>
#include <vtkm/rendering/raytracing/ChannelBufferOperations.h>
#include <vtkm/rendering/raytracing/Ray.h>
#include <vtkm/rendering/raytracing/Worklets.h>
......@@ -51,6 +55,71 @@ public:
}
}; //class RayStatusFileter
class RayMapMaxDistances : public vtkm::worklet::WorkletMapField
{
protected:
vtkm::Matrix<vtkm::Float32, 4, 4> InverseProjection;
vtkm::Id Width;
vtkm::Float32 DoubleInvHeight;
vtkm::Float32 DoubleInvWidth;
public:
VTKM_CONT
RayMapMaxDistances(const vtkm::Matrix<vtkm::Float32, 4, 4>& inverseProjection,
const vtkm::Id width,
const vtkm::Id height)
: InverseProjection(inverseProjection)
, Width(width)
{
VTKM_ASSERT(width > 0);
VTKM_ASSERT(height > 0);
DoubleInvHeight = 2.f / static_cast<vtkm::Float32>(height);
DoubleInvWidth = 2.f / static_cast<vtkm::Float32>(width);
}
typedef void ControlSignature(FieldIn<>,
FieldInOut<>,
WholeArrayIn<>,
WholeArrayInOut<>,
WholeArrayIn<>);
typedef void ExecutionSignature(_1, _2, _3, _4, _5, WorkIndex);
template <typename Precision,
typename DepthPortalType,
typename RayColorType,
typename ColorBufferType>
VTKM_EXEC void operator()(const vtkm::Id& pixelId,
Precision& maxDistance,
const DepthPortalType& depths,
RayColorType& outColors,
const ColorBufferType inColors,
const vtkm::Id& index) const
{
vtkm::Vec<vtkm::Float32, 4> position;
position[0] = static_cast<vtkm::Float32>(pixelId % Width);
position[1] = static_cast<vtkm::Float32>(pixelId / Width);
position[2] = static_cast<vtkm::Float32>(depths.Get(pixelId));
position[3] = 1;
// transform into normalized device coordinates (-1,1)
position[0] = position[0] * DoubleInvWidth - 1.f;
position[1] = position[1] * DoubleInvHeight - 1.f;
position[2] = 2.f * position[2] - 1.f;
position = vtkm::MatrixMultiply(InverseProjection, position);
//for(vtkm::Int32 i = 0; i < 4; ++i)
//{
// position[] /= position[3];
//}
maxDistance = -position[2] / position[3];
vtkm::Vec<vtkm::Float32, 4> inColor = inColors.Get(pixelId);
std::cout << "$" << inColor;
outColors.Set(index * 4 + 0, inColor[0]);
outColors.Set(index * 4 + 1, inColor[1]);
outColors.Set(index * 4 + 2, inColor[2]);
outColors.Set(index * 4 + 3, inColor[3]);
}
}; //class RayMapMinDistances
} // namespace detail
class RayOperations
......@@ -75,6 +144,10 @@ public:
.Invoke(rays.HitIdx, rays.Status);
}
static void MapCanvasToRays(Ray<vtkm::Float32>& rays,
const vtkm::rendering::Camera& camera,
const vtkm::rendering::CanvasRayTracer& canvas);
template <typename Device, typename T>
static vtkm::Id RaysInMesh(Ray<T>& rays, Device)
{
......
......@@ -764,7 +764,7 @@ public:
const PointPortalType& points) const
{
Precision closestDistance = maxDistance;
distance = -1;
distance = maxDistance;
hitIndex = -1;
Precision dirx = rayDir[0];
Precision diry = rayDir[1];
......
......@@ -364,8 +364,11 @@ public:
BOUNDS_CHECK(colorBuffer, pixelIndex * 4 + 3);
color[3] = colorBuffer.Get(pixelIndex * 4 + 3);
std::cout << color << " ";
if (minDistance == -1.f)
{
return; //TODO: Compact? or just image subset...
}
//get the initial sample position;
vtkm::Vec<vtkm::Float32, 3> sampleLocation;
sampleLocation = rayOrigin + (0.0001f + minDistance) * rayDir;
......@@ -654,11 +657,12 @@ public:
VTKM_EXEC
vtkm::Float32 rcp_safe(vtkm::Float32 f) const { return rcp((fabs(f) < 1e-8f) ? 1e-8f : f); }
typedef void ControlSignature(FieldIn<>, FieldOut<>, FieldOut<>, FieldIn<>);
typedef void ExecutionSignature(_1, _2, _3, _4);
typedef void ControlSignature(FieldIn<>, FieldOut<>, FieldInOut<>, FieldInOut<>, FieldIn<>);
typedef void ExecutionSignature(_1, _2, _3, _4, _5);
template <typename Precision>
VTKM_EXEC void operator()(const vtkm::Vec<Precision, 3>& rayDir,
vtkm::Float32& minDistance,
vtkm::Float32& distance,
vtkm::Float32& maxDistance,
const vtkm::Vec<Precision, 3>& rayOrigin) const
{
......@@ -688,12 +692,19 @@ public:
minDistance = vtkm::Max(
vtkm::Max(vtkm::Max(vtkm::Min(ymin, ymax), vtkm::Min(xmin, xmax)), vtkm::Min(zmin, zmax)),
0.f);
maxDistance =
vtkm::Float32 exitDistance =
vtkm::Min(vtkm::Min(vtkm::Max(ymin, ymax), vtkm::Max(xmin, xmax)), vtkm::Max(zmin, zmax));
maxDistance = vtkm::Min(maxDistance, exitDistance);
if (maxDistance < minDistance)
{
//std::cout<<" & "<<maxDistance<<" <"<<minDistance<<" "<<exitDistance<<">";
minDistance = -1.f; //flag for miss
}
else
{
distance = minDistance;
std::cout << " | " << maxDistance << " <" << minDistance << " " << exitDistance << ">";
}
}
}; //class CalcRayStart
......@@ -844,7 +855,7 @@ void VolumeRendererStructured::RenderOnDevice(vtkm::rendering::raytracing::Ray<P
vtkm::cont::Timer<Device> timer;
vtkm::worklet::DispatcherMapField<CalcRayStart, Device>(CalcRayStart(this->SpatialExtent))
.Invoke(rays.Dir, rays.MinDistance, rays.MaxDistance, rays.Origin);
.Invoke(rays.Dir, rays.MinDistance, rays.Distance, rays.MaxDistance, rays.Origin);
vtkm::Float64 time = timer.GetElapsedTime();
logger->AddLogData("calc_ray_start", time);
......
......@@ -26,6 +26,7 @@ vtkm_declare_headers(${headers})
set(unit_tests
UnitTestMapperConnectivity.cxx
UnitTestMultiMapper.cxx
UnitTestMapperRayTracer.cxx
UnitTestMapperVolume.cxx
)
......
......@@ -125,6 +125,49 @@ void Render(const vtkm::cont::DataSet& ds,
ViewType view(scene, mapper, canvas, camera, vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
Render<MapperType, CanvasType, ViewType>(view, outputFile);
}
template <typename MapperType1, typename MapperType2, typename CanvasType, typename ViewType>
void MultiMapperRender(const vtkm::cont::DataSet& ds1,
const vtkm::cont::DataSet& ds2,
const std::string& fieldNm,
const vtkm::rendering::ColorTable& colorTable1,
const vtkm::rendering::ColorTable& colorTable2,
const std::string& outputFile)
{
MapperType1 mapper1;
MapperType2 mapper2;
CanvasType canvas(512, 512);
vtkm::Bounds totalBounds =
ds1.GetCoordinateSystem().GetBounds() + ds2.GetCoordinateSystem().GetBounds();
///vtkm::rendering::Actor(ds2.GetCellSet(), ds2.GetCoordinateSystem(), ds2.GetField(fieldNm)));
vtkm::rendering::Camera camera;
SetCamera<ViewType>(camera, totalBounds);
canvas.SetBackgroundColor(vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 0.0f));
canvas.Clear();
mapper1.SetCanvas(&canvas);
mapper1.SetActiveColorTable(colorTable1);
mapper2.SetCanvas(&canvas);
mapper2.SetActiveColorTable(colorTable2);
const vtkm::cont::Field field1 = ds1.GetField(fieldNm);
vtkm::Range range1;
field1.GetRange(&range1);
const vtkm::cont::Field field2 = ds2.GetField(fieldNm);
vtkm::Range range2;
field2.GetRange(&range2);
mapper1.RenderCells(
ds1.GetCellSet(), ds1.GetCoordinateSystem(), field1, colorTable1, camera, range1);
canvas.SaveAs("test.pnm");
mapper2.RenderCells(
ds2.GetCellSet(), ds2.GetCoordinateSystem(), field2, colorTable2, camera, range2);
canvas.SaveAs(outputFile);
}
}
}
} // namespace vtkm::rendering::testing
......
......@@ -40,6 +40,8 @@ void RenderTests()
vtkm::cont::testing::MakeTestDataSet maker;
vtkm::rendering::ColorTable colorTable("thermal");
colorTable.AddAlphaControlPoint(0.0, .01);
colorTable.AddAlphaControlPoint(1.0, .01);
vtkm::rendering::testing::Render<M, C, V3>(
maker.Make3DRegularDataSet0(), "pointvar", colorTable, "reg3D.pnm");
......
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