mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Remove Width and Height from Camera
The width and height are maintained out of necessity by the canvas. A second copy was maintained by the camera, which was only used for computing the aspect ratio and similar metrics for projections. Having to maintain the width/height in two places is a bit of a hassle and provides the opportunity for bugs if they get out of sync. Instead, have the width/height managed in one place (the canvas) and pass them as parameters as necessary.
This commit is contained in:
parent
b01e8391b4
commit
0769b96bf3
@ -75,14 +75,14 @@ void mouseMove(int x, int y)
|
||||
//std::cout<<"MOUSE MOVE: "<<x<<" "<<y<<std::endl;
|
||||
|
||||
//Map to XY
|
||||
y = view->Camera.Height-y;
|
||||
y = static_cast<int>(view->Canvas.Height-y);
|
||||
|
||||
if (lastx != -1 && lasty != -1)
|
||||
{
|
||||
vtkm::Float32 x1 = ((lastx*2.0f)/view->Camera.Width) - 1.0f;
|
||||
vtkm::Float32 y1 = ((lasty*2.0f)/view->Camera.Height) - 1.0f;
|
||||
vtkm::Float32 x2 = ((x*2.0f)/view->Camera.Width) - 1.0f;
|
||||
vtkm::Float32 y2 = ((y*2.0f)/view->Camera.Height) - 1.0f;
|
||||
vtkm::Float32 x1 = ((lastx*2.0f)/view->Canvas.Width) - 1.0f;
|
||||
vtkm::Float32 y1 = ((lasty*2.0f)/view->Canvas.Height) - 1.0f;
|
||||
vtkm::Float32 x2 = ((x*2.0f)/view->Canvas.Width) - 1.0f;
|
||||
vtkm::Float32 y2 = ((y*2.0f)/view->Canvas.Height) - 1.0f;
|
||||
|
||||
if (buttonStates[0] == GLUT_DOWN)
|
||||
{
|
||||
@ -119,8 +119,7 @@ void mouseCall(int button, int state, int vtkmNotUsed(x), int vtkmNotUsed(y))
|
||||
}
|
||||
|
||||
void Set3DView(vtkm::rendering::Camera &camera,
|
||||
const vtkm::cont::CoordinateSystem &coords,
|
||||
vtkm::Int32 w, vtkm::Int32 h)
|
||||
const vtkm::cont::CoordinateSystem &coords)
|
||||
{
|
||||
vtkm::Bounds coordsBounds =
|
||||
coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
@ -139,8 +138,6 @@ void Set3DView(vtkm::rendering::Camera &camera,
|
||||
camera.Camera3d.FieldOfView = 60.f;
|
||||
camera.NearPlane = 1.f;
|
||||
camera.FarPlane = 100.f;
|
||||
camera.Width = w;
|
||||
camera.Height = h;
|
||||
}
|
||||
|
||||
// Compute and render an isosurface for a uniform grid example
|
||||
@ -164,7 +161,7 @@ main(int argc, char* argv[])
|
||||
const vtkm::cont::CoordinateSystem coords = ds.GetCoordinateSystem();
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
Set3DView(camera, coords, W, H);
|
||||
Set3DView(camera, coords);
|
||||
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
vtkm::rendering::CanvasGL canvas(bg);
|
||||
|
@ -43,8 +43,8 @@ class Camera
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Int32 &width,
|
||||
vtkm::Int32 &height,
|
||||
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Id &width,
|
||||
vtkm::Id &height,
|
||||
vtkm::Float32 &nearPlane,
|
||||
vtkm::Float32 &farPlane)
|
||||
{
|
||||
@ -140,8 +140,6 @@ public:
|
||||
Camera3D Camera3d;
|
||||
Camera2D Camera2d;
|
||||
|
||||
vtkm::Int32 Width;
|
||||
vtkm::Int32 Height;
|
||||
vtkm::Float32 NearPlane;
|
||||
vtkm::Float32 FarPlane;
|
||||
|
||||
@ -153,8 +151,6 @@ public:
|
||||
VTKM_CONT_EXPORT
|
||||
Camera(ViewTypeEnum vtype=Camera::VIEW_3D)
|
||||
: ViewType(vtype),
|
||||
Width(-1),
|
||||
Height(-1),
|
||||
NearPlane(0.f),
|
||||
FarPlane(1.f),
|
||||
ViewportLeft(-1.f),
|
||||
@ -177,21 +173,22 @@ public:
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix()
|
||||
vtkm::Matrix<vtkm::Float32,4,4> CreateProjectionMatrix(vtkm::Id screenWidth,
|
||||
vtkm::Id screenHeight)
|
||||
{
|
||||
if (this->ViewType == Camera::VIEW_3D)
|
||||
{
|
||||
return this->Camera3d.CreateProjectionMatrix(
|
||||
this->Width, this->Height, this->NearPlane, this->FarPlane);
|
||||
screenWidth, screenHeight, this->NearPlane, this->FarPlane);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::Float32 size = vtkm::Abs(this->Camera2d.Top - this->Camera2d.Bottom);
|
||||
vtkm::Float32 left,right,bottom,top;
|
||||
this->GetRealViewport(left,right,bottom,top);
|
||||
this->GetRealViewport(screenWidth,screenHeight,left,right,bottom,top);
|
||||
vtkm::Float32 aspect =
|
||||
(static_cast<vtkm::Float32>(this->Width)*(right-left)) /
|
||||
(static_cast<vtkm::Float32>(this->Height)*(top-bottom));
|
||||
(static_cast<vtkm::Float32>(screenWidth)*(right-left)) /
|
||||
(static_cast<vtkm::Float32>(screenHeight)*(top-bottom));
|
||||
|
||||
return this->Camera2d.CreateProjectionMatrix(
|
||||
size, this->NearPlane, this->FarPlane, aspect);
|
||||
@ -199,7 +196,8 @@ public:
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void GetRealViewport(vtkm::Float32 &left, vtkm::Float32 &right,
|
||||
void GetRealViewport(vtkm::Id screenWidth, vtkm::Id screenHeight,
|
||||
vtkm::Float32 &left, vtkm::Float32 &right,
|
||||
vtkm::Float32 &bottom, vtkm::Float32 &top)
|
||||
{
|
||||
if (this->ViewType == Camera::VIEW_3D)
|
||||
@ -211,8 +209,8 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::Float32 maxvw = (this->ViewportRight-this->ViewportLeft) * static_cast<vtkm::Float32>(this->Width);
|
||||
vtkm::Float32 maxvh = (this->ViewportTop-this->ViewportBottom) * static_cast<vtkm::Float32>(this->Height);
|
||||
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;
|
||||
|
@ -83,7 +83,8 @@ public:
|
||||
{
|
||||
vtkm::Float32 oglP[16], oglM[16];
|
||||
|
||||
MatrixHelpers::CreateOGLMatrix(camera.CreateProjectionMatrix(), oglP);
|
||||
MatrixHelpers::CreateOGLMatrix(
|
||||
camera.CreateProjectionMatrix(this->Width, this->Height), oglP);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(oglP);
|
||||
MatrixHelpers::CreateOGLMatrix(camera.CreateViewMatrix(), oglM);
|
||||
@ -124,18 +125,21 @@ public:
|
||||
if (clip)
|
||||
{
|
||||
vtkm::Float32 vl, vr, vb, vt;
|
||||
camera.GetRealViewport(vl,vr,vb,vt);
|
||||
vtkm::Float32 _x = static_cast<vtkm::Float32>(camera.Width)*(1.f+vl)/2.f;
|
||||
vtkm::Float32 _y = static_cast<vtkm::Float32>(camera.Height)*(1.f+vb)/2.f;
|
||||
vtkm::Float32 _w = static_cast<vtkm::Float32>(camera.Width)*(vr-vl)/2.f;
|
||||
vtkm::Float32 _h = static_cast<vtkm::Float32>(camera.Height)*(vt-vb)/2.f;
|
||||
camera.GetRealViewport(this->Width, this->Height, vl,vr,vb,vt);
|
||||
vtkm::Float32 _x = static_cast<vtkm::Float32>(this->Width)*(1.f+vl)/2.f;
|
||||
vtkm::Float32 _y = static_cast<vtkm::Float32>(this->Height)*(1.f+vb)/2.f;
|
||||
vtkm::Float32 _w = static_cast<vtkm::Float32>(this->Width)*(vr-vl)/2.f;
|
||||
vtkm::Float32 _h = static_cast<vtkm::Float32>(this->Height)*(vt-vb)/2.f;
|
||||
|
||||
glViewport(static_cast<int>(_x), static_cast<int>(_y),
|
||||
static_cast<int>(_w), static_cast<int>(_h));
|
||||
glViewport(static_cast<GLint>(_x), static_cast<GLint>(_y),
|
||||
static_cast<GLsizei>(_w), static_cast<GLsizei>(_h));
|
||||
}
|
||||
else
|
||||
{
|
||||
glViewport(0,0, camera.Width, camera.Height);
|
||||
glViewport(0,
|
||||
0,
|
||||
static_cast<GLsizei>(this->Width),
|
||||
static_cast<GLsizei>(this->Height));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ public:
|
||||
virtual void EndScene()
|
||||
{
|
||||
}
|
||||
virtual void SetCanvas(Canvas *vtkmNotUsed(surface))
|
||||
virtual void SetCanvas(Canvas *vtkmNotUsed(canvas))
|
||||
{
|
||||
}
|
||||
protected:
|
||||
|
@ -76,7 +76,7 @@ public:
|
||||
|
||||
const vtkm::cont::DynamicArrayHandleCoordinateSystem dynamicCoordsHandle = coords.GetData();
|
||||
vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Id, 4> > indices;
|
||||
this->Tracer.GetCamera().SetParameters(camera);
|
||||
this->Tracer.GetCamera().SetParameters(camera, *this->Canvas);
|
||||
vtkm::Id numberOfTriangles;
|
||||
|
||||
vtkm::Bounds dataBounds = coords.GetBounds(DeviceAdapter());
|
||||
|
@ -88,7 +88,7 @@ public:
|
||||
vtkm::cont::CellSetStructured<3> cellSetStructured3D = cellset.Cast<vtkm::cont::CellSetStructured<3> >();
|
||||
//vtkm::cont::ArrayHandleUniformPointCoordinates vertices;
|
||||
//vertices = dynamicCoordsHandle.Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
|
||||
this->Tracer.GetCamera().SetParameters(camera);
|
||||
this->Tracer.GetCamera().SetParameters(camera, *this->Canvas);
|
||||
this->Tracer.SetData(coords,
|
||||
scalarField,
|
||||
coordsBounds,
|
||||
|
@ -123,12 +123,12 @@ public:
|
||||
XPos = ox;
|
||||
YPos = oy;
|
||||
}
|
||||
virtual void Render(Camera &camera,
|
||||
virtual void Render(Camera &vtkmNotUsed(camera),
|
||||
WorldAnnotator &,
|
||||
Canvas &canvas)
|
||||
{
|
||||
vtkm::Float32 WindowAspect = vtkm::Float32(camera.Width) /
|
||||
vtkm::Float32(camera.Height);
|
||||
vtkm::Float32 WindowAspect = vtkm::Float32(canvas.Width) /
|
||||
vtkm::Float32(canvas.Height);
|
||||
|
||||
canvas.AddText(XPos,YPos,
|
||||
Scale,
|
||||
@ -168,7 +168,7 @@ public:
|
||||
{
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> V, P;
|
||||
V = camera.CreateViewMatrix();
|
||||
P = camera.CreateProjectionMatrix();
|
||||
P = camera.CreateProjectionMatrix(canvas.Width, canvas.Height);
|
||||
|
||||
vtkm::Vec<vtkm::Float32,4> p4w(XPos,YPos,ZPos,1);
|
||||
vtkm::Vec<vtkm::Float32,4> p4s =
|
||||
@ -185,7 +185,7 @@ public:
|
||||
T = MatrixHelpers::TranslateMatrix(psx,psy,-psz);
|
||||
|
||||
vtkm::Float32 WindowAspect =
|
||||
vtkm::Float32(camera.Width) / vtkm::Float32(camera.Height);
|
||||
vtkm::Float32(canvas.Width) / vtkm::Float32(canvas.Height);
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> SW;
|
||||
SW = MatrixHelpers::ScaleMatrix(1.f/WindowAspect, 1, 1);
|
||||
@ -195,7 +195,7 @@ public:
|
||||
//if view type == 2D?
|
||||
{
|
||||
vtkm::Float32 vl, vr, vb, vt;
|
||||
camera.GetRealViewport(vl,vr,vb,vt);
|
||||
camera.GetRealViewport(canvas.Width,canvas.Height,vl,vr,vb,vt);
|
||||
vtkm::Float32 xs = (vr-vl);
|
||||
vtkm::Float32 ys = (vt-vb);
|
||||
SV = MatrixHelpers::ScaleMatrix(2.f/xs, 2.f/ys, 1);
|
||||
|
@ -273,6 +273,7 @@ public:
|
||||
vtkm::Float32 viewportTop;
|
||||
vtkm::Float32 viewportBottom;
|
||||
this->Camera.GetRealViewport(
|
||||
this->Canvas.Width, this->Canvas.Height,
|
||||
viewportLeft, viewportRight, viewportBottom, viewportTop);
|
||||
|
||||
this->HorizontalAxisAnnotation.SetColor(vtkm::rendering::Color(1,1,1));
|
||||
|
@ -241,14 +241,15 @@ public:
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
void SetParameters(const vtkm::rendering::Camera &camera)
|
||||
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->SetHeight(camera.Height);
|
||||
this->SetWidth(camera.Width);
|
||||
this->SetHeight(static_cast<vtkm::Int32>(canvas.Height));
|
||||
this->SetWidth(static_cast<vtkm::Int32>(canvas.Width));
|
||||
this->CameraView = camera;
|
||||
}
|
||||
|
||||
@ -266,7 +267,6 @@ public:
|
||||
this->IsResDirty = true;
|
||||
this->Height = height;
|
||||
this->SetFieldOfView(this->FovX);
|
||||
this->CameraView.Height = this->Height;
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,7 +289,6 @@ public:
|
||||
this->IsResDirty = true;
|
||||
this->Width = width;
|
||||
this->SetFieldOfView(this->FovX);
|
||||
this->CameraView.Width = this->Width;
|
||||
}
|
||||
}
|
||||
|
||||
@ -435,7 +434,7 @@ public:
|
||||
this->SubsetWidth,
|
||||
this->SubsetMinX,
|
||||
this->SubsetMinY,
|
||||
this->CameraView.CreateProjectionMatrix(),
|
||||
this->CameraView.CreateProjectionMatrix(canvas->Width, canvas->Height),
|
||||
this->SubsetWidth * this->SubsetHeight) )
|
||||
.Invoke( this->FrameBuffer,
|
||||
distances,
|
||||
@ -622,7 +621,7 @@ private:
|
||||
|
||||
//Update our ViewProjection matrix
|
||||
this->ViewProjectionMat
|
||||
= vtkm::MatrixMultiply(this->CameraView.CreateProjectionMatrix(),
|
||||
= vtkm::MatrixMultiply(this->CameraView.CreateProjectionMatrix(this->Width, this->Height),
|
||||
this->CameraView.CreateViewMatrix());
|
||||
|
||||
//Find the pixel footprint
|
||||
|
@ -31,8 +31,7 @@
|
||||
namespace {
|
||||
|
||||
void Set3DView(vtkm::rendering::Camera &camera,
|
||||
const vtkm::cont::CoordinateSystem &coords,
|
||||
vtkm::Int32 w, vtkm::Int32 h)
|
||||
const vtkm::cont::CoordinateSystem &coords)
|
||||
{
|
||||
vtkm::Bounds coordsBounds = coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
//set up a default view
|
||||
@ -50,8 +49,6 @@ void Set3DView(vtkm::rendering::Camera &camera,
|
||||
camera.Camera3d.FieldOfView = 60.f;
|
||||
camera.NearPlane = 1.f;
|
||||
camera.FarPlane = 100.f;
|
||||
camera.Width = w;
|
||||
camera.Height = h;
|
||||
/*
|
||||
std::cout<<"Camera3d: pos: "<<camera.camera3d.pos<<std::endl;
|
||||
std::cout<<" lookAt: "<<camera.camera3d.lookAt<<std::endl;
|
||||
@ -75,8 +72,6 @@ void Set2DView(vtkm::rendering::Camera &camera,
|
||||
camera.Camera2d.Top = static_cast<vtkm::Float32>(coordsBounds.Y.Max);
|
||||
camera.NearPlane = 1.f;
|
||||
camera.FarPlane = 100.f;
|
||||
camera.Width = w;
|
||||
camera.Height = h;
|
||||
|
||||
// Give it some space for other annotations like a color bar
|
||||
camera.ViewportLeft = -.7f;
|
||||
@ -102,7 +97,7 @@ void Render3D(const vtkm::cont::DataSet &ds,
|
||||
vtkm::rendering::MapperGL<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> mapper;
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
Set3DView(camera, coords, W, H);
|
||||
Set3DView(camera, coords);
|
||||
|
||||
vtkm::rendering::Scene scene;
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
|
@ -30,8 +30,7 @@
|
||||
namespace {
|
||||
|
||||
void Set3DView(vtkm::rendering::Camera &camera,
|
||||
const vtkm::cont::CoordinateSystem &coords,
|
||||
vtkm::Int32 w, vtkm::Int32 h)
|
||||
const vtkm::cont::CoordinateSystem &coords)
|
||||
{
|
||||
vtkm::Bounds coordsBounds =
|
||||
coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
@ -50,14 +49,11 @@ void Set3DView(vtkm::rendering::Camera &camera,
|
||||
camera.Camera3d.FieldOfView = 60.f;
|
||||
camera.NearPlane = 1.f;
|
||||
camera.FarPlane = 100.f;
|
||||
camera.Width = w;
|
||||
camera.Height = h;
|
||||
|
||||
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;
|
||||
std::cout<<" w/h: "<<camera.Width<<"/"<<camera.Height<<std::endl;
|
||||
}
|
||||
|
||||
void Render(const vtkm::cont::DataSet &ds,
|
||||
@ -70,7 +66,7 @@ void Render(const vtkm::cont::DataSet &ds,
|
||||
vtkm::rendering::MapperRayTracer<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> mapper;
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
Set3DView(camera, coords, W, H);
|
||||
Set3DView(camera, coords);
|
||||
|
||||
vtkm::rendering::Scene scene;
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
|
@ -31,8 +31,7 @@
|
||||
namespace {
|
||||
|
||||
void Set3DView(vtkm::rendering::Camera &camera,
|
||||
const vtkm::cont::CoordinateSystem &coords,
|
||||
vtkm::Int32 w, vtkm::Int32 h)
|
||||
const vtkm::cont::CoordinateSystem &coords)
|
||||
{
|
||||
vtkm::Bounds coordsBounds =
|
||||
coords.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
@ -51,14 +50,11 @@ void Set3DView(vtkm::rendering::Camera &camera,
|
||||
camera.Camera3d.FieldOfView = 60.f;
|
||||
camera.NearPlane = 1.f;
|
||||
camera.FarPlane = 100.f;
|
||||
camera.Width = w;
|
||||
camera.Height = h;
|
||||
|
||||
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;
|
||||
std::cout<<" w/h: "<<camera.Width<<"/"<<camera.Height<<std::endl;
|
||||
}
|
||||
|
||||
void Render(const vtkm::cont::DataSet &ds,
|
||||
@ -71,7 +67,7 @@ void Render(const vtkm::cont::DataSet &ds,
|
||||
vtkm::rendering::MapperVolume<VTKM_DEFAULT_DEVICE_ADAPTER_TAG> mapper;
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
Set3DView(camera, coords, W, H);
|
||||
Set3DView(camera, coords);
|
||||
|
||||
vtkm::rendering::ColorTable colorTable(ctName);
|
||||
colorTable.AddAlphaControlPoint(0.0f, .01f);
|
||||
|
Loading…
Reference in New Issue
Block a user