mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 01:49:02 +00:00
cleanup Camera
This commit is contained in:
parent
d660a53b8d
commit
ca1fe424cd
@ -153,7 +153,6 @@ void Camera::GetRealViewport(vtkm::Id screenWidth,
|
|||||||
vtkm::Float32 daspect =
|
vtkm::Float32 daspect =
|
||||||
(this->Camera2D.Right - this->Camera2D.Left) / (this->Camera2D.Top - this->Camera2D.Bottom);
|
(this->Camera2D.Right - this->Camera2D.Left) / (this->Camera2D.Top - this->Camera2D.Bottom);
|
||||||
daspect *= this->Camera2D.XScale;
|
daspect *= this->Camera2D.XScale;
|
||||||
//cerr << "waspect="<<waspect << " \tdaspect="<<daspect<<endl;
|
|
||||||
|
|
||||||
//needed as center is a constant value
|
//needed as center is a constant value
|
||||||
#if defined(VTKM_MSVC)
|
#if defined(VTKM_MSVC)
|
||||||
|
@ -102,12 +102,12 @@ ScalarRenderer::Result ScalarRenderer::Render(const vtkm::rendering::Camera& cam
|
|||||||
vtkm::cont::Timer timer;
|
vtkm::cont::Timer timer;
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
//
|
|
||||||
// Create rays
|
// Create rays
|
||||||
//
|
|
||||||
vtkm::rendering::raytracing::Camera cam;
|
vtkm::rendering::raytracing::Camera cam;
|
||||||
cam.SetParameters(camera, this->Internals->Width, this->Internals->Height);
|
cam.SetParameters(camera, this->Internals->Width, this->Internals->Height);
|
||||||
|
|
||||||
|
// FIXME: rays are created with an unused Buffers.at(0), that ChannelBuffer
|
||||||
|
// also has wrong number of channels, thus allocates memory that is wasted.
|
||||||
vtkm::rendering::raytracing::Ray<vtkm::Float32> rays;
|
vtkm::rendering::raytracing::Ray<vtkm::Float32> rays;
|
||||||
cam.CreateRays(rays, this->Internals->ShapeBounds);
|
cam.CreateRays(rays, this->Internals->ShapeBounds);
|
||||||
rays.Buffers.at(0).InitConst(0.f);
|
rays.Buffers.at(0).InitConst(0.f);
|
||||||
@ -117,12 +117,10 @@ ScalarRenderer::Result ScalarRenderer::Render(const vtkm::rendering::Camera& cam
|
|||||||
std::map<std::string, vtkm::Range> rangeMap;
|
std::map<std::string, vtkm::Range> rangeMap;
|
||||||
for (vtkm::Id i = 0; i < numFields; ++i)
|
for (vtkm::Id i = 0; i < numFields; ++i)
|
||||||
{
|
{
|
||||||
vtkm::cont::Field field = this->Internals->DataSet.GetField(i);
|
const auto& field = this->Internals->DataSet.GetField(i);
|
||||||
vtkm::cont::ArrayHandle<vtkm::Range> ranges;
|
if (field.GetData().GetNumberOfComponents() == 1)
|
||||||
ranges = field.GetRange();
|
|
||||||
vtkm::Id comps = ranges.GetNumberOfValues();
|
|
||||||
if (comps == 1)
|
|
||||||
{
|
{
|
||||||
|
auto ranges = field.GetRange();
|
||||||
rangeMap[field.GetName()] = ranges.ReadPortal().Get(0);
|
rangeMap[field.GetName()] = ranges.ReadPortal().Get(0);
|
||||||
this->Internals->Tracer.AddField(field);
|
this->Internals->Tracer.AddField(field);
|
||||||
}
|
}
|
||||||
@ -153,7 +151,6 @@ ScalarRenderer::Result ScalarRenderer::Render(const vtkm::rendering::Camera& cam
|
|||||||
raytracing::ChannelBuffer<vtkm::Float32> depthExpanded =
|
raytracing::ChannelBuffer<vtkm::Float32> depthExpanded =
|
||||||
depthChannel.ExpandBuffer(rays.PixelIdx, expandSize, Internals->DefaultValue);
|
depthChannel.ExpandBuffer(rays.PixelIdx, expandSize, Internals->DefaultValue);
|
||||||
|
|
||||||
|
|
||||||
Result result;
|
Result result;
|
||||||
result.Width = Internals->Width;
|
result.Width = Internals->Width;
|
||||||
result.Height = Internals->Height;
|
result.Height = Internals->Height;
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include <vtkm/cont/Algorithm.h>
|
#include <vtkm/cont/Algorithm.h>
|
||||||
#include <vtkm/cont/ErrorBadValue.h>
|
#include <vtkm/cont/ErrorBadValue.h>
|
||||||
#include <vtkm/cont/Timer.h>
|
#include <vtkm/cont/Timer.h>
|
||||||
#include <vtkm/cont/TryExecute.h>
|
|
||||||
|
|
||||||
#include <vtkm/rendering/raytracing/Camera.h>
|
#include <vtkm/rendering/raytracing/Camera.h>
|
||||||
#include <vtkm/rendering/raytracing/Logger.h>
|
#include <vtkm/rendering/raytracing/Logger.h>
|
||||||
@ -88,9 +87,9 @@ public:
|
|||||||
vtkm::Normalize(nlook);
|
vtkm::Normalize(nlook);
|
||||||
}
|
}
|
||||||
|
|
||||||
VTKM_EXEC inline vtkm::Float32 rcp(vtkm::Float32 f) const { return 1.0f / f; }
|
VTKM_EXEC static inline vtkm::Float32 rcp(vtkm::Float32 f) { return 1.0f / f; }
|
||||||
|
|
||||||
VTKM_EXEC inline vtkm::Float32 rcp_safe(vtkm::Float32 f) const
|
VTKM_EXEC static inline vtkm::Float32 rcp_safe(vtkm::Float32 f)
|
||||||
{
|
{
|
||||||
return rcp((fabs(f) < 1e-8f) ? 1e-8f : f);
|
return rcp((fabs(f) < 1e-8f) ? 1e-8f : f);
|
||||||
}
|
}
|
||||||
@ -260,15 +259,18 @@ public:
|
|||||||
vtkm::Float32 _h = static_cast<vtkm::Float32>(height) * (vt - vb) / 2.f;
|
vtkm::Float32 _h = static_cast<vtkm::Float32>(height) * (vt - vb) / 2.f;
|
||||||
vtkm::Vec2f_32 minPoint(left, bottom);
|
vtkm::Vec2f_32 minPoint(left, bottom);
|
||||||
vtkm::Vec2f_32 maxPoint(right, top);
|
vtkm::Vec2f_32 maxPoint(right, top);
|
||||||
|
|
||||||
|
// pixel size in world coordinate
|
||||||
vtkm::Vec2f_32 delta = maxPoint - minPoint;
|
vtkm::Vec2f_32 delta = maxPoint - minPoint;
|
||||||
//delta[0] /= vtkm::Float32(width);
|
|
||||||
//delta[1] /= vtkm::Float32(height);
|
|
||||||
delta[0] /= vtkm::Float32(_w);
|
delta[0] /= vtkm::Float32(_w);
|
||||||
delta[1] /= vtkm::Float32(_h);
|
delta[1] /= vtkm::Float32(_h);
|
||||||
|
|
||||||
PixelDelta[0] = delta[0];
|
PixelDelta[0] = delta[0];
|
||||||
PixelDelta[1] = delta[1];
|
PixelDelta[1] = delta[1];
|
||||||
PixelDelta[2] = 0.f;
|
PixelDelta[2] = 0.f;
|
||||||
|
|
||||||
|
// "first" ray starts at the bottom-lower corner, with half pixel offset. All other
|
||||||
|
// pixels will be one pixel size (i.e. PixelData) apart.
|
||||||
vtkm::Vec2f_32 startOffset = minPoint + delta / 2.f;
|
vtkm::Vec2f_32 startOffset = minPoint + delta / 2.f;
|
||||||
StartOffset[0] = startOffset[0];
|
StartOffset[0] = startOffset[0];
|
||||||
StartOffset[1] = startOffset[1];
|
StartOffset[1] = startOffset[1];
|
||||||
@ -294,6 +296,7 @@ public:
|
|||||||
rayDirX = 0.f;
|
rayDirX = 0.f;
|
||||||
rayDirY = 0.f;
|
rayDirY = 0.f;
|
||||||
rayDirZ = 1.f;
|
rayDirZ = 1.f;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Pixel subset is the pixels in the 2d viewport
|
// Pixel subset is the pixels in the 2d viewport
|
||||||
// not where the rays might intersect data like
|
// not where the rays might intersect data like
|
||||||
@ -302,14 +305,13 @@ public:
|
|||||||
int i = vtkm::Int32(idx) % SubsetWidth;
|
int i = vtkm::Int32(idx) % SubsetWidth;
|
||||||
int j = vtkm::Int32(idx) / SubsetWidth;
|
int j = vtkm::Int32(idx) / SubsetWidth;
|
||||||
|
|
||||||
vtkm::Vec3f_32 pos;
|
vtkm::Vec3f_32 pos{ vtkm::Float32(i), vtkm::Float32(j), 0.f };
|
||||||
pos[0] = vtkm::Float32(i);
|
|
||||||
pos[1] = vtkm::Float32(j);
|
|
||||||
pos[2] = 0.f;
|
|
||||||
vtkm::Vec3f_32 origin = StartOffset + pos * PixelDelta;
|
vtkm::Vec3f_32 origin = StartOffset + pos * PixelDelta;
|
||||||
rayOriginX = origin[0];
|
rayOriginX = origin[0];
|
||||||
rayOriginY = origin[1];
|
rayOriginY = origin[1];
|
||||||
rayOriginZ = origin[2];
|
rayOriginZ = origin[2];
|
||||||
|
|
||||||
i += Minx;
|
i += Minx;
|
||||||
j += Miny;
|
j += Miny;
|
||||||
pixelIndex = static_cast<vtkm::Id>(j * w + i);
|
pixelIndex = static_cast<vtkm::Id>(j * w + i);
|
||||||
@ -347,11 +349,13 @@ public:
|
|||||||
{
|
{
|
||||||
vtkm::Float32 thx = tanf((fovX * vtkm::Pi_180f()) * .5f);
|
vtkm::Float32 thx = tanf((fovX * vtkm::Pi_180f()) * .5f);
|
||||||
vtkm::Float32 thy = tanf((fovY * vtkm::Pi_180f()) * .5f);
|
vtkm::Float32 thy = tanf((fovY * vtkm::Pi_180f()) * .5f);
|
||||||
|
|
||||||
vtkm::Vec3f_32 ru = vtkm::Cross(look, up);
|
vtkm::Vec3f_32 ru = vtkm::Cross(look, up);
|
||||||
vtkm::Normalize(ru);
|
vtkm::Normalize(ru);
|
||||||
|
|
||||||
vtkm::Vec3f_32 rv = vtkm::Cross(ru, look);
|
vtkm::Vec3f_32 rv = vtkm::Cross(ru, look);
|
||||||
vtkm::Normalize(rv);
|
vtkm::Normalize(rv);
|
||||||
|
|
||||||
delta_x = ru * (2 * thx / (float)w);
|
delta_x = ru * (2 * thx / (float)w);
|
||||||
delta_y = rv * (2 * thy / (float)h);
|
delta_y = rv * (2 * thy / (float)h);
|
||||||
|
|
||||||
@ -364,6 +368,7 @@ public:
|
|||||||
delta_y[1] = delta_y[1] / _zoom;
|
delta_y[1] = delta_y[1] / _zoom;
|
||||||
delta_y[2] = delta_y[2] / _zoom;
|
delta_y[2] = delta_y[2] / _zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlook = look;
|
nlook = look;
|
||||||
vtkm::Normalize(nlook);
|
vtkm::Normalize(nlook);
|
||||||
}
|
}
|
||||||
@ -378,14 +383,15 @@ public:
|
|||||||
Precision& rayDirZ,
|
Precision& rayDirZ,
|
||||||
vtkm::Id& pixelIndex) const
|
vtkm::Id& pixelIndex) const
|
||||||
{
|
{
|
||||||
vtkm::Vec<Precision, 3> ray_dir(rayDirX, rayDirY, rayDirZ);
|
auto i = vtkm::Int32(idx) % SubsetWidth;
|
||||||
int i = vtkm::Int32(idx) % SubsetWidth;
|
auto j = vtkm::Int32(idx) / SubsetWidth;
|
||||||
int j = vtkm::Int32(idx) / SubsetWidth;
|
|
||||||
i += Minx;
|
i += Minx;
|
||||||
j += Miny;
|
j += Miny;
|
||||||
// Write out the global pixelId
|
// Write out the global pixelId
|
||||||
pixelIndex = static_cast<vtkm::Id>(j * w + i);
|
pixelIndex = static_cast<vtkm::Id>(j * w + i);
|
||||||
ray_dir = nlook + delta_x * ((2.f * Precision(i) - Precision(w)) / 2.0f) +
|
|
||||||
|
vtkm::Vec<Precision, 3> ray_dir = nlook +
|
||||||
|
delta_x * ((2.f * Precision(i) - Precision(w)) / 2.0f) +
|
||||||
delta_y * ((2.f * Precision(j) - Precision(h)) / 2.0f);
|
delta_y * ((2.f * Precision(j) - Precision(h)) / 2.0f);
|
||||||
// avoid some numerical issues
|
// avoid some numerical issues
|
||||||
for (vtkm::Int32 d = 0; d < 3; ++d)
|
for (vtkm::Int32 d = 0; d < 3; ++d)
|
||||||
@ -393,12 +399,10 @@ public:
|
|||||||
if (ray_dir[d] == 0.f)
|
if (ray_dir[d] == 0.f)
|
||||||
ray_dir[d] += 0.0000001f;
|
ray_dir[d] += 0.0000001f;
|
||||||
}
|
}
|
||||||
Precision dot = vtkm::Dot(ray_dir, ray_dir);
|
vtkm::Normalize(ray_dir);
|
||||||
Precision sq_mag = vtkm::Sqrt(dot);
|
rayDirX = ray_dir[0];
|
||||||
|
rayDirY = ray_dir[1];
|
||||||
rayDirX = ray_dir[0] / sq_mag;
|
rayDirZ = ray_dir[2];
|
||||||
rayDirY = ray_dir[1] / sq_mag;
|
|
||||||
rayDirZ = ray_dir[2] / sq_mag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // class perspective ray gen
|
}; // class perspective ray gen
|
||||||
@ -909,7 +913,7 @@ VTKM_CONT void Camera::UpdateDimensions(Ray<Precision>& rays,
|
|||||||
else if (ortho2D)
|
else if (ortho2D)
|
||||||
{
|
{
|
||||||
// 2D rendering has a viewport that represents the area of the canvas where the image
|
// 2D rendering has a viewport that represents the area of the canvas where the image
|
||||||
// is drawn. Thus, we have to create rays cooresponding to that region of the
|
// is drawn. Thus, we have to create rays corresponding to that region of the
|
||||||
// canvas, so annotations are correctly rendered
|
// canvas, so annotations are correctly rendered
|
||||||
vtkm::Float32 vl, vr, vb, vt;
|
vtkm::Float32 vl, vr, vb, vt;
|
||||||
this->CameraView.GetRealViewport(this->GetWidth(), this->GetHeight(), vl, vr, vb, vt);
|
this->CameraView.GetRealViewport(this->GetWidth(), this->GetHeight(), vl, vr, vb, vt);
|
||||||
|
@ -30,8 +30,6 @@ namespace detail
|
|||||||
class RayStatusFilter : public vtkm::worklet::WorkletMapField
|
class RayStatusFilter : public vtkm::worklet::WorkletMapField
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VTKM_CONT
|
|
||||||
RayStatusFilter() {}
|
|
||||||
using ControlSignature = void(FieldIn, FieldInOut);
|
using ControlSignature = void(FieldIn, FieldInOut);
|
||||||
using ExecutionSignature = void(_1, _2);
|
using ExecutionSignature = void(_1, _2);
|
||||||
VTKM_EXEC
|
VTKM_EXEC
|
||||||
@ -205,7 +203,7 @@ public:
|
|||||||
{
|
{
|
||||||
vtkm::Vec<UInt8, 1> maskValues;
|
vtkm::Vec<UInt8, 1> maskValues;
|
||||||
maskValues[0] = RAY_ACTIVE;
|
maskValues[0] = RAY_ACTIVE;
|
||||||
vtkm::UInt8 statusUInt8 = static_cast<vtkm::UInt8>(RAY_ACTIVE);
|
auto statusUInt8 = static_cast<vtkm::UInt8>(RAY_ACTIVE);
|
||||||
vtkm::cont::ArrayHandle<vtkm::UInt8> masks;
|
vtkm::cont::ArrayHandle<vtkm::UInt8> masks;
|
||||||
|
|
||||||
vtkm::worklet::DispatcherMapField<Mask<vtkm::UInt8>> dispatcher{ (
|
vtkm::worklet::DispatcherMapField<Mask<vtkm::UInt8>> dispatcher{ (
|
||||||
|
@ -98,7 +98,7 @@ struct RenderTestOptions
|
|||||||
bool LogX = false;
|
bool LogX = false;
|
||||||
bool LogY = false;
|
bool LogY = false;
|
||||||
|
|
||||||
std::string Title = "";
|
std::string Title;
|
||||||
vtkm::Float32 TitleScale = 0.075f;
|
vtkm::Float32 TitleScale = 0.075f;
|
||||||
vtkm::Vec2f_32 TitlePosition = { -0.11f, 0.92f };
|
vtkm::Vec2f_32 TitlePosition = { -0.11f, 0.92f };
|
||||||
vtkm::Float32 TitleAngle = 0;
|
vtkm::Float32 TitleAngle = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user