mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-07 02:49:12 +00:00
Merge topic 'Rendering-Scaling-Fix'
2dd00acf Removing hold over cmake change. 58deb3eb Fixing View1d and View2d x scaling. Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !840
This commit is contained in:
commit
67336251a8
@ -73,7 +73,10 @@ vtkm::Matrix<vtkm::Float32, 4, 4> Camera::Camera2DStruct::CreateViewMatrix() con
|
||||
vtkm::Vec<vtkm::Float32, 3> position = lookAt;
|
||||
position[2] = 1.f;
|
||||
vtkm::Vec<vtkm::Float32, 3> up(0, 1, 0);
|
||||
return MatrixHelpers::ViewMatrix(position, lookAt, up);
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> V = MatrixHelpers::ViewMatrix(position, lookAt, up);
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> scaleMatrix = MatrixHelpers::CreateScale(this->XScale, 1, 1);
|
||||
V = vtkm::MatrixMultiply(scaleMatrix, V);
|
||||
return V;
|
||||
}
|
||||
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> Camera::Camera2DStruct::CreateProjectionMatrix(
|
||||
|
@ -297,6 +297,23 @@ public:
|
||||
this->SetViewUp(vtkm::Vec<vtkm::Float32, 3>(viewUp));
|
||||
}
|
||||
|
||||
/// \brief The xscale of the camera
|
||||
///
|
||||
/// The xscale forces the 2D curves to be full-frame
|
||||
///
|
||||
/// Setting the xscale changes the mode to 2D.
|
||||
///
|
||||
VTKM_CONT
|
||||
vtkm::Float32 GetXScale() const { return this->Camera2D.XScale; }
|
||||
VTKM_CONT
|
||||
void SetXScale(vtkm::Float32 xscale)
|
||||
{
|
||||
this->SetModeTo2D();
|
||||
this->Camera2D.XScale = xscale;
|
||||
}
|
||||
VTKM_CONT
|
||||
void SetXScale(vtkm::Float64 xscale) { this->SetXScale(static_cast<vtkm::Float32>(xscale)); }
|
||||
|
||||
/// \brief The field of view angle
|
||||
///
|
||||
/// The field of view defines the angle (in degrees) that are visible from
|
||||
|
@ -110,6 +110,19 @@ struct MatrixHelpers
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static VTKM_CONT vtkm::Matrix<vtkm::Float32, 4, 4> CreateScale(const vtkm::Float32 x,
|
||||
const vtkm::Float32 y,
|
||||
const vtkm::Float32 z)
|
||||
{
|
||||
vtkm::Matrix<vtkm::Float32, 4, 4> matrix;
|
||||
vtkm::MatrixIdentity(matrix);
|
||||
matrix[0][0] = x;
|
||||
matrix[1][1] = y;
|
||||
matrix[2][2] = z;
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static VTKM_CONT vtkm::Matrix<vtkm::Float32, 4, 4> TrackballMatrix(vtkm::Float32 p1x,
|
||||
vtkm::Float32 p1y,
|
||||
vtkm::Float32 p2x,
|
||||
|
@ -52,14 +52,22 @@ void View1D::Paint()
|
||||
{
|
||||
this->GetCanvas().Activate();
|
||||
this->GetCanvas().Clear();
|
||||
this->SetupForWorldSpace();
|
||||
|
||||
// we always want to start with a curve being full-frame
|
||||
if (this->GetCamera().GetMode() == Camera::MODE_2D)
|
||||
{
|
||||
vtkm::Float32 left, right, bottom, top;
|
||||
this->GetCamera().GetViewRange2D(left, right, bottom, top);
|
||||
this->GetCamera().SetXScale((static_cast<vtkm::Float32>(this->GetCanvas().GetWidth())) /
|
||||
(static_cast<vtkm::Float32>(this->GetCanvas().GetHeight())) *
|
||||
(top - bottom) / (right - left));
|
||||
}
|
||||
|
||||
this->SetupForWorldSpace();
|
||||
this->GetScene().Render(this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
||||
this->RenderWorldAnnotations();
|
||||
|
||||
this->SetupForScreenSpace();
|
||||
this->RenderScreenAnnotations();
|
||||
|
||||
this->GetCanvas().Finish();
|
||||
}
|
||||
|
||||
|
@ -50,14 +50,22 @@ void View2D::Paint()
|
||||
{
|
||||
this->GetCanvas().Activate();
|
||||
this->GetCanvas().Clear();
|
||||
this->SetupForWorldSpace();
|
||||
|
||||
// we always want to start with a curve being full-frame
|
||||
if (this->GetCamera().GetMode() == Camera::MODE_2D)
|
||||
{
|
||||
vtkm::Float32 left, right, bottom, top;
|
||||
this->GetCamera().GetViewRange2D(left, right, bottom, top);
|
||||
this->GetCamera().SetXScale((static_cast<vtkm::Float32>(this->GetCanvas().GetWidth())) /
|
||||
(static_cast<vtkm::Float32>(this->GetCanvas().GetHeight())) *
|
||||
(top - bottom) / (right - left));
|
||||
}
|
||||
|
||||
this->SetupForWorldSpace();
|
||||
this->GetScene().Render(this->GetMapper(), this->GetCanvas(), this->GetCamera());
|
||||
this->RenderWorldAnnotations();
|
||||
|
||||
this->SetupForScreenSpace();
|
||||
this->RenderScreenAnnotations();
|
||||
|
||||
this->GetCanvas().Finish();
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
// this software.
|
||||
//============================================================================
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
@ -26,6 +27,7 @@
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View1D.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
@ -41,6 +43,7 @@ void RenderTests()
|
||||
typedef vtkm::rendering::View2D V2;
|
||||
typedef vtkm::rendering::View1D V1;
|
||||
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::rendering::ColorTable colorTable("thermal");
|
||||
|
||||
@ -56,6 +59,19 @@ void RenderTests()
|
||||
maker.Make1DUniformDataSet0(), "pointvar", "uniform1D.pnm");
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
maker.Make1DExplicitDataSet0(), "pointvar", "expl1D.pnm");
|
||||
|
||||
vtkm::cont::DataSet ds = maker.Make1DUniformDataSet0();
|
||||
const int nVerts = ds.GetField(0).GetData().GetNumberOfValues();
|
||||
vtkm::Float32 vars[nVerts];
|
||||
float smallVal = 1.000;
|
||||
for (int i = 0; i <= nVerts; i++)
|
||||
{
|
||||
vars[i] = smallVal;
|
||||
smallVal += .01;
|
||||
}
|
||||
dsf.AddPointField(ds, "smallScaledXAxis", vars, nVerts);
|
||||
vtkm::rendering::testing::Render<M, C, V1>(
|
||||
ds, "smallScaledXAxis", "uniform1DSmallScaledXAxis.pnm");
|
||||
}
|
||||
} //namespace
|
||||
|
||||
|
@ -17,8 +17,8 @@
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||
#include <vtkm/cont/DeviceAdapter.h>
|
||||
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
@ -27,6 +27,7 @@
|
||||
#include <vtkm/rendering/Color.h>
|
||||
#include <vtkm/rendering/MapperGL.h>
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
#include <vtkm/rendering/View1D.h>
|
||||
#include <vtkm/rendering/View2D.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
#include <vtkm/rendering/testing/RenderTest.h>
|
||||
@ -41,7 +42,7 @@
|
||||
namespace
|
||||
{
|
||||
static const vtkm::Id WIDTH = 512, HEIGHT = 512;
|
||||
static vtkm::Id which = 0, NUM_DATASETS = 4;
|
||||
static vtkm::Id which = 0, NUM_DATASETS = 5;
|
||||
static bool done = false;
|
||||
static bool batch = false;
|
||||
|
||||
@ -65,7 +66,9 @@ void RenderTests()
|
||||
typedef vtkm::rendering::CanvasGL CanvasType;
|
||||
typedef vtkm::rendering::View3D View3DType;
|
||||
typedef vtkm::rendering::View2D View2DType;
|
||||
typedef vtkm::rendering::View1D View1DType;
|
||||
|
||||
vtkm::cont::DataSetFieldAdd dsf;
|
||||
vtkm::cont::testing::MakeTestDataSet maker;
|
||||
vtkm::rendering::ColorTable colorTable("thermal");
|
||||
|
||||
@ -74,24 +77,40 @@ void RenderTests()
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSetKeyCallback(window, keyCallback);
|
||||
|
||||
CanvasType canvas[4] = {
|
||||
CanvasType(512, 512), CanvasType(512, 512), CanvasType(512, 512), CanvasType(512, 512)
|
||||
};
|
||||
vtkm::rendering::Scene scene[4];
|
||||
vtkm::cont::DataSet ds[4];
|
||||
MapperType mapper[4];
|
||||
vtkm::rendering::Camera camera[4];
|
||||
CanvasType canvas[5] = { CanvasType(512, 512),
|
||||
CanvasType(512, 512),
|
||||
CanvasType(512, 512),
|
||||
CanvasType(512, 512),
|
||||
CanvasType(512, 512) };
|
||||
vtkm::rendering::Scene scene[5];
|
||||
vtkm::cont::DataSet ds[5];
|
||||
MapperType mapper[5];
|
||||
vtkm::rendering::Camera camera[5];
|
||||
|
||||
ds[0] = maker.Make3DRegularDataSet0();
|
||||
ds[1] = maker.Make3DRectilinearDataSet0();
|
||||
ds[2] = maker.Make3DExplicitDataSet4();
|
||||
ds[3] = maker.Make2DRectilinearDataSet0();
|
||||
//create 1D uniform DS with tiny Y axis
|
||||
vtkm::cont::DataSet tinyDS = maker.Make1DUniformDataSet0();
|
||||
const int nVerts = tinyDS.GetField(0).GetData().GetNumberOfValues();
|
||||
vtkm::Float32 vars[nVerts];
|
||||
float smallVal = 1.000;
|
||||
for (int i = 0; i <= nVerts; i++)
|
||||
{
|
||||
vars[i] = smallVal;
|
||||
smallVal += .01;
|
||||
}
|
||||
dsf.AddPointField(tinyDS, "smallScaledXAxis", vars, nVerts);
|
||||
ds[4] = tinyDS;
|
||||
tinyDS.PrintSummary(std::cerr);
|
||||
|
||||
std::string fldNames[4];
|
||||
std::string fldNames[5];
|
||||
fldNames[0] = "pointvar";
|
||||
fldNames[1] = "pointvar";
|
||||
fldNames[2] = "pointvar";
|
||||
fldNames[3] = "pointvar";
|
||||
fldNames[4] = "smallScaledXAxis";
|
||||
|
||||
for (int i = 0; i < NUM_DATASETS; i++)
|
||||
{
|
||||
@ -99,8 +118,21 @@ void RenderTests()
|
||||
ds[i].GetCoordinateSystem(),
|
||||
ds[i].GetField(fldNames[i].c_str()),
|
||||
colorTable));
|
||||
vtkm::rendering::testing::SetCamera<View3DType>(camera[i],
|
||||
ds[i].GetCoordinateSystem().GetBounds());
|
||||
if (i < 3)
|
||||
{
|
||||
vtkm::rendering::testing::SetCamera<View3DType>(camera[i],
|
||||
ds[i].GetCoordinateSystem().GetBounds());
|
||||
}
|
||||
else if (i == 3)
|
||||
{
|
||||
vtkm::rendering::testing::SetCamera<View2DType>(camera[i],
|
||||
ds[i].GetCoordinateSystem().GetBounds());
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::rendering::testing::SetCamera<View1DType>(
|
||||
camera[i], ds[i].GetCoordinateSystem().GetBounds(), ds[i].GetField(fldNames[i].c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
View3DType view3d0(
|
||||
@ -109,9 +141,10 @@ void RenderTests()
|
||||
scene[1], mapper[1], canvas[1], camera[1], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View3DType view3d2(
|
||||
scene[2], mapper[2], canvas[2], camera[2], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
|
||||
View2DType view2d(
|
||||
View2DType view2d0(
|
||||
scene[3], mapper[3], canvas[3], camera[3], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
View1DType view1d0(
|
||||
scene[4], mapper[4], canvas[4], camera[4], vtkm::rendering::Color(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
|
||||
while (!glfwWindowShouldClose(window) && !done)
|
||||
{
|
||||
@ -124,7 +157,10 @@ void RenderTests()
|
||||
else if (which == 2)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View3DType>(view3d2, "expl3D.pnm");
|
||||
else if (which == 3)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View2DType>(view2d, "rect2D.pnm");
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View2DType>(view2d0, "rect2D.pnm");
|
||||
else if (which == 4)
|
||||
vtkm::rendering::testing::Render<MapperType, CanvasType, View1DType>(
|
||||
view1d0, "uniform1DSmallScaledXAxis.pnm");
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
if (batch)
|
||||
|
Loading…
Reference in New Issue
Block a user