Hide Camera private parts

With only a few exceptions for simple structures, we do not expose the
members of classes. Instead, we provide accessor methods. Do this for
Camera as well as add some helper methods.
This commit is contained in:
Kenneth Moreland 2016-06-03 17:27:03 -06:00
parent 0769b96bf3
commit 55af901f60
7 changed files with 405 additions and 160 deletions

@ -124,20 +124,8 @@ void Set3DView(vtkm::rendering::Camera &camera,
vtkm::Bounds coordsBounds =
coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
//set up a default view
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds.X.Length());
totalExtent[1] = vtkm::Float32(coordsBounds.Y.Length());
totalExtent[2] = vtkm::Float32(coordsBounds.Z.Length());
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
vtkm::Normalize(totalExtent);
camera = vtkm::rendering::Camera(vtkm::rendering::Camera::VIEW_3D);
camera.Camera3d.Position = totalExtent * (mag * 2.f);
camera.Camera3d.Up = vtkm::Vec<vtkm::Float32,3>(0.f, 1.f, 0.f);
camera.Camera3d.LookAt = totalExtent * (mag * .5f);
camera.Camera3d.FieldOfView = 60.f;
camera.NearPlane = 1.f;
camera.FarPlane = 100.f;
camera = vtkm::rendering::Camera();
camera.ResetToBounds(coordsBounds);
}
// Compute and render an isosurface for a uniform grid example

@ -19,8 +19,10 @@
//============================================================================
#ifndef vtk_m_rendering_Camera_h
#define vtk_m_rendering_Camera_h
#include <vtkm/Bounds.h>
#include <vtkm/Math.h>
#include <vtkm/Matrix.h>
#include <vtkm/Range.h>
#include <vtkm/VectorAnalysis.h>
#include <vtkm/rendering/MatrixHelpers.h>
@ -29,24 +31,31 @@ namespace rendering {
class Camera
{
class Camera3D
struct Camera3DStruct
{
public:
VTKM_CONT_EXPORT
Camera3D() : FieldOfView(0.f), XPan(0), YPan(0), Zoom(1)
Camera3DStruct()
: LookAt(0.0f, 0.0f, 0.0f),
Position(0.0f, 0.0f, 1.0f),
ViewUp(0.0f, 1.0f, 0.0f),
FieldOfView(60.0f),
XPan(0.0f),
YPan(0.0f),
Zoom(1.0f)
{}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix()
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix() const
{
return MatrixHelpers::ViewMatrix(this->Position, this->LookAt, this->Up);
return MatrixHelpers::ViewMatrix(this->Position, this->LookAt, this->ViewUp);
}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Id &width,
vtkm::Id &height,
vtkm::Float32 &nearPlane,
vtkm::Float32 &farPlane)
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Id width,
vtkm::Id height,
vtkm::Float32 nearPlane,
vtkm::Float32 farPlane) const
{
vtkm::Matrix<vtkm::Float32,4,4> matrix;
vtkm::MatrixIdentity(matrix);
@ -77,24 +86,25 @@ class Camera
}
vtkm::Vec<vtkm::Float32,3> Up;
vtkm::Vec<vtkm::Float32,3> LookAt;
vtkm::Vec<vtkm::Float32,3> Position;
vtkm::Vec<vtkm::Float32,3> ViewUp;
vtkm::Float32 FieldOfView;
vtkm::Float32 XPan;
vtkm::Float32 YPan;
vtkm::Float32 Zoom;
};
class Camera2D
struct Camera2DStruct
{
public:
VTKM_CONT_EXPORT
Camera2D() : Left(0.f), Right(0.f), Top(0.f), Bottom(0.f), XScale(1.f)
Camera2DStruct()
: Left(-1.0f), Right(1.0f), Bottom(-1.0f), Top(1.0f), XScale(1.0f)
{}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix()
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix() const
{
vtkm::Vec<vtkm::Float32,3> lookAt((this->Left + this->Right)/2.f,
(this->Top + this->Bottom)/2.f,
@ -106,10 +116,10 @@ class Camera
}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Float32 &size,
vtkm::Float32 &near,
vtkm::Float32 &far,
vtkm::Float32 &aspect)
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Float32 size,
vtkm::Float32 near,
vtkm::Float32 far,
vtkm::Float32 aspect) const
{
vtkm::Matrix<vtkm::Float32,4,4> matrix(0.f);
vtkm::Float32 left = -size/2.f * aspect;
@ -129,68 +139,56 @@ class Camera
vtkm::Float32 Left;
vtkm::Float32 Right;
vtkm::Float32 Top;
vtkm::Float32 Bottom;
vtkm::Float32 Top;
vtkm::Float32 XScale;
};
public:
enum ViewTypeEnum { VIEW_2D, VIEW_3D };
ViewTypeEnum ViewType;
Camera3D Camera3d;
Camera2D Camera2d;
vtkm::Float32 NearPlane;
vtkm::Float32 FarPlane;
vtkm::Float32 ViewportLeft;
vtkm::Float32 ViewportRight;
vtkm::Float32 ViewportBottom;
vtkm::Float32 ViewportTop;
enum ModeEnum { MODE_2D, MODE_3D };
VTKM_CONT_EXPORT
Camera(ViewTypeEnum vtype=Camera::VIEW_3D)
: ViewType(vtype),
NearPlane(0.f),
FarPlane(1.f),
ViewportLeft(-1.f),
ViewportRight(1.f),
ViewportBottom(-1.f),
ViewportTop(1.f)
Camera(ModeEnum vtype=Camera::MODE_3D)
: Mode(vtype),
NearPlane(0.01f),
FarPlane(1000.0f),
ViewportLeft(-1.0f),
ViewportRight(1.0f),
ViewportBottom(-1.0f),
ViewportTop(1.0f)
{}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix()
vtkm::Matrix<vtkm::Float32,4,4> CreateViewMatrix() const
{
if (this->ViewType == Camera::VIEW_3D)
if (this->Mode == Camera::MODE_3D)
{
return this->Camera3d.CreateViewMatrix();
return this->Camera3D.CreateViewMatrix();
}
else
{
return this->Camera2d.CreateViewMatrix();
return this->Camera2D.CreateViewMatrix();
}
}
VTKM_CONT_EXPORT
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Id screenWidth,
vtkm::Id screenHeight)
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(
vtkm::Id screenWidth, vtkm::Id screenHeight) const
{
if (this->ViewType == Camera::VIEW_3D)
if (this->Mode == Camera::MODE_3D)
{
return this->Camera3d.CreateProjectionMatrix(
return this->Camera3D.CreateProjectionMatrix(
screenWidth, screenHeight, this->NearPlane, this->FarPlane);
}
else
{
vtkm::Float32 size = vtkm::Abs(this->Camera2d.Top - this->Camera2d.Bottom);
vtkm::Float32 size = vtkm::Abs(this->Camera2D.Top - this->Camera2D.Bottom);
vtkm::Float32 left,right,bottom,top;
this->GetRealViewport(screenWidth,screenHeight,left,right,bottom,top);
vtkm::Float32 aspect =
(static_cast<vtkm::Float32>(screenWidth)*(right-left)) /
(static_cast<vtkm::Float32>(screenHeight)*(top-bottom));
return this->Camera2d.CreateProjectionMatrix(
return this->Camera2D.CreateProjectionMatrix(
size, this->NearPlane, this->FarPlane, aspect);
}
}
@ -198,9 +196,9 @@ public:
VTKM_CONT_EXPORT
void GetRealViewport(vtkm::Id screenWidth, vtkm::Id screenHeight,
vtkm::Float32 &left, vtkm::Float32 &right,
vtkm::Float32 &bottom, vtkm::Float32 &top)
vtkm::Float32 &bottom, vtkm::Float32 &top) const
{
if (this->ViewType == Camera::VIEW_3D)
if (this->Mode == Camera::MODE_3D)
{
left = this->ViewportLeft;
right = this->ViewportRight;
@ -212,8 +210,8 @@ public:
vtkm::Float32 maxvw = (this->ViewportRight-this->ViewportLeft) * static_cast<vtkm::Float32>(screenWidth);
vtkm::Float32 maxvh = (this->ViewportTop-this->ViewportBottom) * static_cast<vtkm::Float32>(screenHeight);
vtkm::Float32 waspect = maxvw / maxvh;
vtkm::Float32 daspect = (this->Camera2d.Right - this->Camera2d.Left) / (this->Camera2d.Top - this->Camera2d.Bottom);
daspect *= this->Camera2d.XScale;
vtkm::Float32 daspect = (this->Camera2D.Right - this->Camera2D.Left) / (this->Camera2D.Top - this->Camera2D.Bottom);
daspect *= this->Camera2D.XScale;
//cerr << "waspect="<<waspect << " \tdaspect="<<daspect<<endl;
const bool center = true; // if false, anchor to bottom-left
if (waspect > daspect)
@ -253,7 +251,7 @@ public:
VTKM_CONT_EXPORT
vtkm::Vec<vtkm::Float32, 3>
MultVector(const vtkm::Matrix<vtkm::Float32,4,4> &matrix, vtkm::Vec<vtkm::Float32, 3> &v)
MultVector(const vtkm::Matrix<vtkm::Float32,4,4> &matrix, vtkm::Vec<vtkm::Float32, 3> &v) const
{
vtkm::Vec<vtkm::Float32,4> v4(v[0],v[1],v[2], 1);
v4 = vtkm::MatrixMultiply(matrix, v4);
@ -263,52 +261,362 @@ public:
return v;
}
/// \brief The mode of the camera (2D or 3D).
///
/// \c vtkm::Camera can be set to a 2D or 3D mode. 2D mode is used for
/// looking at data in the x-y plane. 3D mode allows the camera to be
/// positioned anywhere and pointing at any place in 3D.
///
VTKM_CONT_EXPORT
vtkm::rendering::Camera::ModeEnum GetMode() const
{
return this->Mode;
}
VTKM_CONT_EXPORT
void SetMode(vtkm::rendering::Camera::ModeEnum mode)
{
this->Mode = mode;
}
VTKM_CONT_EXPORT
void SetModeTo3D()
{
this->SetMode(vtkm::rendering::Camera::MODE_3D);
}
VTKM_CONT_EXPORT
void SetModeTo2D()
{
this->SetMode(vtkm::rendering::Camera::MODE_2D);
}
/// \brief The clipping range of the camera.
///
/// The clipping range establishes the near and far clipping planes. These
/// clipping planes are parallel to the viewing plane. The planes are defined
/// by simply specifying the distance from the viewpoint. Renderers can (and
/// usually do) remove any geometry closer than the near plane and further
/// than the far plane.
///
/// For precision purposes, it is best to place the near plane as far away as
/// possible (while still being in front of any geometry). The far plane
/// usually has less effect on the depth precision, so can be placed well far
/// behind the geometry.
///
VTKM_CONT_EXPORT
vtkm::Range GetClippingRange() const
{
return vtkm::Range(this->NearPlane, this->FarPlane);
}
VTKM_CONT_EXPORT
void SetClippingRange(vtkm::Float32 nearPlane, vtkm::Float32 farPlane)
{
this->NearPlane = nearPlane;
this->FarPlane = farPlane;
}
VTKM_CONT_EXPORT
void SetClippingRange(const vtkm::Range &nearFarRange)
{
this->SetClippingRange(static_cast<vtkm::Float32>(nearFarRange.Min),
static_cast<vtkm::Float32>(nearFarRange.Max));
}
/// \brief The viewport of the projection
///
/// The projection of the camera can be offset to be centered around a subset
/// of the rendered image. This is established with a "viewport," which is
/// defined by the left/right and bottom/top of this viewport. The values of
/// the viewport are relative to the rendered image's bounds. The left and
/// bottom of the image are at -1 and the right and top are at 1.
///
VTKM_CONT_EXPORT
void GetViewport(vtkm::Float32 &left,
vtkm::Float32 &right,
vtkm::Float32 &bottom,
vtkm::Float32 &top) const
{
left = this->ViewportLeft;
right = this->ViewportRight;
bottom = this->ViewportBottom;
top = this->ViewportTop;
}
VTKM_CONT_EXPORT
vtkm::Bounds GetViewport() const
{
return vtkm::Bounds(this->ViewportLeft,
this->ViewportRight,
this->ViewportBottom,
this->ViewportTop,
0.0,
0.0);
}
VTKM_CONT_EXPORT
void SetViewport(vtkm::Float32 left,
vtkm::Float32 right,
vtkm::Float32 bottom,
vtkm::Float32 top)
{
this->ViewportLeft = left;
this->ViewportRight = right;
this->ViewportBottom = bottom;
this->ViewportTop = top;
}
VTKM_CONT_EXPORT
void SetViewport(const vtkm::Bounds &viewportBounds)
{
this->SetViewport(static_cast<vtkm::Float32>(viewportBounds.X.Min),
static_cast<vtkm::Float32>(viewportBounds.X.Max),
static_cast<vtkm::Float32>(viewportBounds.Y.Min),
static_cast<vtkm::Float32>(viewportBounds.Y.Max));
}
/// \brief The focal point the camera is looking at in 3D mode
///
/// When in 3D mode, the camera is set up to be facing the \c LookAt
/// position. If \c LookAt is set, the mode is changed to 3D mode.
///
VTKM_CONT_EXPORT
const vtkm::Vec<vtkm::Float32,3> &GetLookAt() const
{
return this->Camera3D.LookAt;
}
VTKM_CONT_EXPORT
void SetLookAt(const vtkm::Vec<vtkm::Float32,3> &lookAt)
{
this->SetModeTo3D();
this->Camera3D.LookAt = lookAt;
}
/// \brief The spatial position of the camera in 3D mode
///
/// When in 3D mode, the camera is modeled to be at a particular location. If
/// \c Position is set, the mode is changed to 3D mode.
///
VTKM_CONT_EXPORT
const vtkm::Vec<vtkm::Float32,3> &GetPosition() const
{
return this->Camera3D.Position;
}
VTKM_CONT_EXPORT
void SetPosition(const vtkm::Vec<vtkm::Float32,3> &position)
{
this->SetModeTo3D();
this->Camera3D.Position = position;
}
/// \brief The up orientation of the camera in 3D mode
///
/// When in 3D mode, the camera is modeled to be at a particular location and
/// looking at a particular spot. The view up vector orients the rotation of
/// the image so that the top of the image is in the direction pointed to by
/// view up. If \c ViewUp is set, the mode is changed to 3D mode.
///
VTKM_CONT_EXPORT
const vtkm::Vec<vtkm::Float32,3> &GetViewUp() const
{
return this->Camera3D.ViewUp;
}
VTKM_CONT_EXPORT
void SetViewUp(const vtkm::Vec<vtkm::Float32,3> &viewUp)
{
this->SetModeTo3D();
this->Camera3D.ViewUp = viewUp;
}
/// \brief The field of view angle
///
/// The field of view defines the angle (in degrees) that are visible from
/// the camera position.
///
/// Setting the field of view changes the mode to 3D.
///
VTKM_CONT_EXPORT
vtkm::Float32 GetFieldOfView() const
{
return this->Camera3D.FieldOfView;
}
VTKM_CONT_EXPORT
void SetFieldOfView(vtkm::Float32 fov)
{
this->SetModeTo3D();
this->Camera3D.FieldOfView = fov;
}
/// \brief Pans the camera in 3D mode.
///
/// Panning the camera in this way changes the mode to 3D.
///
VTKM_CONT_EXPORT
void Pan3D(vtkm::Float32 dx, vtkm::Float32 dy)
{
//std::cout<<"Pan3d: "<<dx<<" "<<dy<<std::endl;
this->Camera3d.XPan += dx;
this->Camera3d.YPan += dy;
this->SetModeTo3D();
this->Camera3D.XPan += dx;
this->Camera3D.YPan += dy;
}
VTKM_CONT_EXPORT
void Pan3D(vtkm::Vec<vtkm::Float32,2> direction)
{
this->Pan3D(direction[0], direction[1]);
}
/// \brief Zooms the camera in or out
///
/// Zooming the camera scales everything in the image up or down. Positive
/// zoom makes the geometry look bigger or closer. Negative zoom has the
/// opposite effect. A zoom of 0 has no effect.
///
/// Zooming the camera changes the mode to 3D.
///
VTKM_CONT_EXPORT
void Zoom3D(vtkm::Float32 zoom)
{
vtkm::Float32 factor = powf(4, zoom);
//std::cout<<"Zoom3D: "<<zoom<<" --> "<<factor<<std::endl;
this->Camera3d.Zoom *= factor;
this->Camera3d.XPan *= factor;
this->Camera3d.YPan *= factor;
this->SetModeTo3D();
vtkm::Float32 factor = vtkm::Pow(4.0f, zoom);
this->Camera3D.Zoom *= factor;
this->Camera3D.XPan *= factor;
this->Camera3D.YPan *= factor;
}
/// \brief Moves the camera as if a point was dragged along a sphere.
///
/// \c TrackballRotate takes the normalized screen coordinates (in the range
/// -1 to 1) and rotates the camera around the \c LookAt position. The rotation
/// first projects the points to a sphere around the \c LookAt position. The
/// camera is then rotated as if the start point was dragged to the end point
/// along with the world.
///
/// \c TrackballRotate changes the mode to 3D.
///
VTKM_CONT_EXPORT
void TrackballRotate(vtkm::Float32 x1, vtkm::Float32 y1, vtkm::Float32 x2, vtkm::Float32 y2)
void TrackballRotate(vtkm::Float32 startX,
vtkm::Float32 startY,
vtkm::Float32 endX,
vtkm::Float32 endY)
{
vtkm::Matrix<vtkm::Float32,4,4> R1 = MatrixHelpers::TrackballMatrix(x1,y1, x2,y2);
vtkm::Matrix<vtkm::Float32,4,4> rotate =
MatrixHelpers::TrackballMatrix(startX,startY, endX,endY);
//Translate matrix
vtkm::Matrix<vtkm::Float32,4,4> T1 = MatrixHelpers::TranslateMatrix(-this->Camera3d.LookAt);
vtkm::Matrix<vtkm::Float32,4,4> translate =
MatrixHelpers::TranslateMatrix(-this->Camera3D.LookAt);
//Translate matrix
vtkm::Matrix<vtkm::Float32,4,4> T2 = MatrixHelpers::TranslateMatrix(this->Camera3d.LookAt);
vtkm::Matrix<vtkm::Float32,4,4> inverseTranslate =
MatrixHelpers::TranslateMatrix(this->Camera3D.LookAt);
vtkm::Matrix<vtkm::Float32,4,4> V1 = this->CreateViewMatrix();
V1(0,3) = 0;
V1(1,3) = 0;
V1(2,3) = 0;
vtkm::Matrix<vtkm::Float32,4,4> view = this->CreateViewMatrix();
view(0,3) = 0;
view(1,3) = 0;
view(2,3) = 0;
vtkm::Matrix<vtkm::Float32,4,4> V2 = vtkm::MatrixTranspose(V1);
vtkm::Matrix<vtkm::Float32,4,4> inverseView = vtkm::MatrixTranspose(view);
//MM = T2 * V2 * R1 * V1 * T1;
vtkm::Matrix<vtkm::Float32,4,4> MM;
MM = vtkm::MatrixMultiply(T2,
vtkm::MatrixMultiply(V2,
vtkm::MatrixMultiply(R1,
vtkm::MatrixMultiply(V1,T1))));
this->Camera3d.Position = MultVector(MM, this->Camera3d.Position);
this->Camera3d.LookAt = MultVector(MM, this->Camera3d.LookAt);
this->Camera3d.Up = MultVector(MM, this->Camera3d.Up);
//fullTransform = inverseTranslate * inverseView * rotate * view * translate
vtkm::Matrix<vtkm::Float32,4,4> fullTransform;
fullTransform = vtkm::MatrixMultiply(
inverseTranslate, vtkm::MatrixMultiply(
inverseView, vtkm::MatrixMultiply(
rotate, vtkm::MatrixMultiply(
view,translate))));
this->Camera3D.Position = MultVector(fullTransform, this->Camera3D.Position);
this->Camera3D.LookAt = MultVector(fullTransform, this->Camera3D.LookAt);
this->Camera3D.ViewUp = MultVector(fullTransform, this->Camera3D.ViewUp);
}
/// \brief Set up the camera to look at geometry
///
/// \c ResetToBounds takes a \c Bounds structure containing the bounds in
/// 3D space that contain the geometry being rendered. This method sets up
/// the camera so that it is looking at this region in space. The view
/// direction is preserved.
///
VTKM_CONT_EXPORT
void ResetToBounds(const vtkm::Bounds &dataBounds)
{
vtkm::Vec<vtkm::Float32,3> directionOfProjection =
this->GetPosition() - this->GetLookAt();
vtkm::Normalize(directionOfProjection);
vtkm::Vec<vtkm::Float32,3> center = dataBounds.Center();
this->SetLookAt(center);
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(dataBounds.X.Length());
totalExtent[1] = vtkm::Float32(dataBounds.Y.Length());
totalExtent[2] = vtkm::Float32(dataBounds.Z.Length());
vtkm::Float32 diagonalLength = vtkm::Magnitude(totalExtent);
this->SetPosition(center + directionOfProjection * diagonalLength * 1.0f);
this->SetFieldOfView(60.0f);
this->SetClippingRange(1.0f, diagonalLength*10.0f);
}
/// \brief The viewable region in the x-y plane
///
/// When the camera is in 2D, it is looking at some region of the x-y plane.
/// The region being looked at is defined by the range in x (determined by
/// the left and right sides) and by the range in y (determined by the bottom
/// and top sides).
///
/// \c SetViewRange2D changes the camera mode to 2D.
///
VTKM_CONT_EXPORT
void GetViewRange2D(vtkm::Float32 &left,
vtkm::Float32 &right,
vtkm::Float32 &bottom,
vtkm::Float32 &top) const
{
left = this->Camera2D.Left;
right = this->Camera2D.Right;
bottom = this->Camera2D.Bottom;
top = this->Camera2D.Top;
}
VTKM_CONT_EXPORT
vtkm::Bounds GetViewRange2D() const
{
return vtkm::Bounds(this->Camera2D.Left,
this->Camera2D.Right,
this->Camera2D.Bottom,
this->Camera2D.Top,
0.0,
0.0);
}
VTKM_CONT_EXPORT
void SetViewRange2D(vtkm::Float32 left,
vtkm::Float32 right,
vtkm::Float32 bottom,
vtkm::Float32 top)
{
this->SetModeTo2D();
this->Camera2D.Left = left;
this->Camera2D.Right = right;
this->Camera2D.Bottom = bottom;
this->Camera2D.Top = top;
}
VTKM_CONT_EXPORT
void SetViewRange2D(const vtkm::Range &xRange,
const vtkm::Range &yRange)
{
this->SetViewRange2D(static_cast<vtkm::Float32>(xRange.Min),
static_cast<vtkm::Float32>(xRange.Max),
static_cast<vtkm::Float32>(yRange.Min),
static_cast<vtkm::Float32>(yRange.Max));
}
VTKM_CONT_EXPORT
void SetViewRange2D(const vtkm::Bounds &viewRange)
{
this->SetViewRange2D(viewRange.X, viewRange.Y);
}
private:
ModeEnum Mode;
Camera3DStruct Camera3D;
Camera2DStruct Camera2D;
vtkm::Float32 NearPlane;
vtkm::Float32 FarPlane;
vtkm::Float32 ViewportLeft;
vtkm::Float32 ViewportRight;
vtkm::Float32 ViewportBottom;
vtkm::Float32 ViewportTop;
};
}} // namespace vtkm::rendering

@ -159,9 +159,11 @@ public:
this->BoxAnnotation.SetExtents(this->Scene.GetSpatialBounds());
this->BoxAnnotation.Render(this->Camera, this->WorldAnnotator);
bool xtest = this->Camera.Camera3d.LookAt[0] > this->Camera.Camera3d.Position[0];
bool ytest = this->Camera.Camera3d.LookAt[1] > this->Camera.Camera3d.Position[1];
bool ztest = this->Camera.Camera3d.LookAt[2] > this->Camera.Camera3d.Position[2];
vtkm::Vec<vtkm::Float32,3> lookAt = this->Camera.GetLookAt();
vtkm::Vec<vtkm::Float32,3> position = this->Camera.GetPosition();
bool xtest = lookAt[0] > position[0];
bool ytest = lookAt[1] > position[1];
bool ztest = lookAt[2] > position[2];
const bool outsideedges = true; // if false, do closesttriad
if (outsideedges)

@ -244,10 +244,10 @@ public:
void SetParameters(const vtkm::rendering::Camera &camera,
const vtkm::rendering::CanvasRayTracer &canvas)
{
this->SetUp(camera.Camera3d.Up);
this->SetLookAt(camera.Camera3d.LookAt);
this->SetPosition(camera.Camera3d.Position);
this->SetFieldOfView(camera.Camera3d.FieldOfView);
this->SetUp(camera.GetViewUp());
this->SetLookAt(camera.GetLookAt());
this->SetPosition(camera.GetPosition());
this->SetFieldOfView(camera.GetFieldOfView());
this->SetHeight(static_cast<vtkm::Int32>(canvas.Height));
this->SetWidth(static_cast<vtkm::Int32>(canvas.Width));
this->CameraView = camera;
@ -345,7 +345,7 @@ public:
if(newFOVY != this->FovY) { this->IsViewDirty = true; }
this->FovX = newFOVX;
this->FovY = newFOVY;
this->CameraView.Camera3d.FieldOfView = this->FovX;
this->CameraView.SetFieldOfView(this->FovX);
}
VTKM_CONT_EXPORT

@ -35,27 +35,8 @@ void Set3DView(vtkm::rendering::Camera &camera,
{
vtkm::Bounds coordsBounds = coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
//set up a default view
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds.X.Max - coordsBounds.X.Min);
totalExtent[1] = vtkm::Float32(coordsBounds.Y.Max - coordsBounds.Y.Min);
totalExtent[2] = vtkm::Float32(coordsBounds.Z.Max - coordsBounds.Z.Min);
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
vtkm::Normalize(totalExtent);
camera = vtkm::rendering::Camera(vtkm::rendering::Camera::VIEW_3D);
camera.Camera3d.Position = totalExtent * (mag * 2.f);
camera.Camera3d.Up = vtkm::Vec<vtkm::Float32,3>(0.f, 1.f, 0.f);
camera.Camera3d.LookAt = totalExtent * (mag * .5f);
camera.Camera3d.FieldOfView = 60.f;
camera.NearPlane = 1.f;
camera.FarPlane = 100.f;
/*
std::cout<<"Camera3d: pos: "<<camera.camera3d.pos<<std::endl;
std::cout<<" lookAt: "<<camera.camera3d.lookAt<<std::endl;
std::cout<<" up: "<<camera.camera3d.up<<std::endl;
std::cout<<" near/far/fov: "<<camera.nearPlane<<"/"<<camera.farPlane<<" "<<camera.camera3d.fieldOfView<<std::endl;
std::cout<<" w/h: "<<camera.width<<"/"<<camera.height<<std::endl;
*/
camera = vtkm::rendering::Camera();
camera.ResetToBounds(coordsBounds);
}
void Set2DView(vtkm::rendering::Camera &camera,

@ -35,25 +35,8 @@ void Set3DView(vtkm::rendering::Camera &camera,
vtkm::Bounds coordsBounds =
coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
//set up a default view
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds.X.Length());
totalExtent[1] = vtkm::Float32(coordsBounds.Y.Length());
totalExtent[2] = vtkm::Float32(coordsBounds.Z.Length());
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
vtkm::Normalize(totalExtent);
camera = vtkm::rendering::Camera(vtkm::rendering::Camera::VIEW_3D);
camera.Camera3d.Position = totalExtent * (mag * 2.f);
camera.Camera3d.Up = vtkm::Vec<vtkm::Float32,3>(0.f, 1.f, 0.f);
camera.Camera3d.LookAt = totalExtent * (mag * .5f);
camera.Camera3d.FieldOfView = 60.f;
camera.NearPlane = 1.f;
camera.FarPlane = 100.f;
std::cout<<"Camera3d: pos: "<<camera.Camera3d.Position<<std::endl;
std::cout<<" lookAt: "<<camera.Camera3d.LookAt<<std::endl;
std::cout<<" up: "<<camera.Camera3d.Up<<std::endl;
std::cout<<" near/far/fov: "<<camera.NearPlane<<"/"<<camera.FarPlane<<" "<<camera.Camera3d.FieldOfView<<std::endl;
camera = vtkm::rendering::Camera();
camera.ResetToBounds(coordsBounds);
}
void Render(const vtkm::cont::DataSet &ds,

@ -36,25 +36,8 @@ void Set3DView(vtkm::rendering::Camera &camera,
vtkm::Bounds coordsBounds =
coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
//set up a default view
vtkm::Vec<vtkm::Float32,3> totalExtent;
totalExtent[0] = vtkm::Float32(coordsBounds.X.Length());
totalExtent[1] = vtkm::Float32(coordsBounds.Y.Length());
totalExtent[2] = vtkm::Float32(coordsBounds.Z.Length());
vtkm::Float32 mag = vtkm::Magnitude(totalExtent);
vtkm::Normalize(totalExtent);
camera = vtkm::rendering::Camera(vtkm::rendering::Camera::VIEW_3D);
camera.Camera3d.Position = totalExtent * (mag * 2.f);
camera.Camera3d.Up = vtkm::Vec<vtkm::Float32,3>(0.f, 1.f, 0.f);
camera.Camera3d.LookAt = totalExtent * (mag * .5f);
camera.Camera3d.FieldOfView = 60.f;
camera.NearPlane = 1.f;
camera.FarPlane = 100.f;
std::cout<<"Camera3d: pos: "<<camera.Camera3d.Position<<std::endl;
std::cout<<" lookAt: "<<camera.Camera3d.LookAt<<std::endl;
std::cout<<" up: "<<camera.Camera3d.Up<<std::endl;
std::cout<<" near/far/fov: "<<camera.NearPlane<<"/"<<camera.FarPlane<<" "<<camera.Camera3d.FieldOfView<<std::endl;
camera = vtkm::rendering::Camera();
camera.ResetToBounds(coordsBounds);
}
void Render(const vtkm::cont::DataSet &ds,