mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 01:49:02 +00:00
Fixes to rendering. Attempt at getting VR
This commit is contained in:
parent
727bb9f22f
commit
fd613f2c84
@ -11,6 +11,12 @@
|
||||
#include <vtkm/cont/EnvironmentTracker.h>
|
||||
#include <vtkm/rendering/View3D.h>
|
||||
|
||||
#ifdef VTKM_ENABLE_MPI
|
||||
#include <mpi.h>
|
||||
#include <vtkm/thirdparty/diy/diy.h>
|
||||
#include <vtkm/thirdparty/diy/mpi-cast.h>
|
||||
#endif
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace rendering
|
||||
@ -49,6 +55,8 @@ void View3D::Paint()
|
||||
return;
|
||||
|
||||
this->Compositor.SetCompositeMode(vtkm::rendering::compositing::Compositor::Z_BUFFER_SURFACE);
|
||||
//volume render
|
||||
this->Compositor.SetCompositeMode(vtkm::rendering::compositing::Compositor::VIS_ORDER_BLEND);
|
||||
/*
|
||||
auto colors = (this->GetCanvas().GetColorBuffer().WritePortal().GetArray())[0][0];
|
||||
auto depths = (this->GetCanvas().GetDepthBuffer().WritePortal().GetArray());
|
||||
@ -82,13 +90,46 @@ void View3D::Paint()
|
||||
|
||||
void View3D::RenderScreenAnnotations()
|
||||
{
|
||||
if (this->GetScene().GetNumberOfActors() > 0)
|
||||
vtkm::Range scalarRange;
|
||||
|
||||
int numActors = this->GetScene().GetNumberOfActors();
|
||||
if (numActors > 0)
|
||||
scalarRange = this->GetScene().GetActor(0).GetScalarRange();
|
||||
|
||||
int totNumActors = numActors;
|
||||
|
||||
/*
|
||||
#ifdef VTKM_ENABLE_MPI
|
||||
auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator();
|
||||
|
||||
vtkm::Float64 minVal = scalarRange.Min, maxVal = scalarRange.Max;
|
||||
|
||||
MPI_Comm mpiComm = vtkmdiy::mpi::mpi_cast(comm.handle());
|
||||
int totNumActors = 0;
|
||||
vtkm::Float64 minVal_res = 0, maxVal_res = 0;
|
||||
MPI_Reduce(&numActors, &totNumActors, 1, MPI_INT, MPI_SUM, 0, mpiComm);
|
||||
MPI_Reduce(&minVal, &minVal_res, 1, MPI_DOUBLE, MPI_MIN, 0, mpiComm);
|
||||
MPI_Reduce(&maxVal, &maxVal_res, 1, MPI_DOUBLE, MPI_MAX, 0, mpiComm);
|
||||
if (comm.rank() != 0)
|
||||
return;
|
||||
|
||||
scalarRange.Min = minVal_res;
|
||||
scalarRange.Max = maxVal_res;
|
||||
#endif
|
||||
|
||||
std::cout<<"totNumActors= "<<totNumActors<<" range= "<<scalarRange<<std::endl;
|
||||
|
||||
//DRP
|
||||
//This assumes that rank 0 has an actor!!
|
||||
*/
|
||||
|
||||
if (totNumActors > 0)
|
||||
{
|
||||
this->GetCanvas().BeginTextRenderingBatch();
|
||||
this->GetWorldAnnotator().BeginLineRenderingBatch();
|
||||
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
||||
this->ColorBarAnnotation.SetFieldName(this->GetScene().GetActor(0).GetScalarField().GetName());
|
||||
this->ColorBarAnnotation.SetRange(this->GetScene().GetActor(0).GetScalarRange(), 5);
|
||||
this->ColorBarAnnotation.SetRange(scalarRange, 5);
|
||||
this->ColorBarAnnotation.SetColorTable(this->GetScene().GetActor(0).GetColorTable());
|
||||
this->ColorBarAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
@ -99,8 +140,39 @@ void View3D::RenderScreenAnnotations()
|
||||
|
||||
void View3D::RenderWorldAnnotations()
|
||||
{
|
||||
this->GetCanvas().BeginTextRenderingBatch();
|
||||
vtkm::Bounds bounds = this->GetScene().GetSpatialBounds();
|
||||
|
||||
#ifdef VTKM_ENABLE_MPI
|
||||
//For parallel, get the collective bounds.
|
||||
auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator();
|
||||
|
||||
vtkm::Float64 mins[3], maxs[3], mins_res[3], maxs_res[3];
|
||||
mins[0] = bounds.X.Min;
|
||||
mins[1] = bounds.Y.Min;
|
||||
mins[2] = bounds.Z.Min;
|
||||
maxs[0] = bounds.X.Max;
|
||||
maxs[1] = bounds.Y.Max;
|
||||
maxs[2] = bounds.Z.Max;
|
||||
|
||||
//DRP
|
||||
//what if a scene has NO actors??
|
||||
|
||||
MPI_Comm mpiComm = vtkmdiy::mpi::mpi_cast(comm.handle());
|
||||
MPI_Reduce(mins, mins_res, 3, MPI_DOUBLE, MPI_MIN, 0, mpiComm);
|
||||
MPI_Reduce(maxs, maxs_res, 3, MPI_DOUBLE, MPI_MAX, 0, mpiComm);
|
||||
if (comm.rank() != 0)
|
||||
return;
|
||||
|
||||
bounds.X.Min = mins_res[0];
|
||||
bounds.Y.Min = mins_res[1];
|
||||
bounds.Z.Min = mins_res[2];
|
||||
bounds.X.Max = maxs_res[0];
|
||||
bounds.Y.Max = maxs_res[1];
|
||||
bounds.Z.Max = maxs_res[2];
|
||||
|
||||
#endif
|
||||
|
||||
this->GetCanvas().BeginTextRenderingBatch();
|
||||
vtkm::Float64 xmin = bounds.X.Min, xmax = bounds.X.Max;
|
||||
vtkm::Float64 ymin = bounds.Y.Min, ymax = bounds.Y.Max;
|
||||
vtkm::Float64 zmin = bounds.Z.Min, zmax = bounds.Z.Max;
|
||||
|
@ -176,10 +176,62 @@ void TestRenderComposite()
|
||||
*/
|
||||
}
|
||||
|
||||
void TestVolumeRenderComposite()
|
||||
{
|
||||
using vtkm::rendering::CanvasRayTracer;
|
||||
using vtkm::rendering::MapperVolume;
|
||||
|
||||
auto comm = vtkm::cont::EnvironmentTracker::GetCommunicator();
|
||||
|
||||
int numBlocks = comm.size() * 1;
|
||||
int rank = comm.rank();
|
||||
int dsPerRank = 1;
|
||||
|
||||
vtkm::rendering::Camera camera;
|
||||
camera.SetLookAt(vtkm::Vec3f_32(1.0, 0.5, 0.5));
|
||||
camera.SetViewUp(vtkm::make_Vec(0.f, 1.f, 0.f));
|
||||
camera.SetClippingRange(1.f, 10.f);
|
||||
camera.SetFieldOfView(60.f);
|
||||
camera.SetPosition(vtkm::Vec3f_32(-2, 1.75, 1.75));
|
||||
vtkm::cont::ColorTable colorTable("inferno");
|
||||
|
||||
colorTable.AddPointAlpha(0.0, .01f);
|
||||
colorTable.AddPointAlpha(1.0, .01f);
|
||||
|
||||
// Background color:
|
||||
vtkm::rendering::Color bg(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
vtkm::rendering::Scene scene;
|
||||
int width = 512, height = 512;
|
||||
CanvasRayTracer canvas(width, height);
|
||||
|
||||
for (int i = 0; i < dsPerRank; i++)
|
||||
{
|
||||
//Create a sequence of datasets along the X direction.
|
||||
std::string fieldName = "tangle";
|
||||
vtkm::source::Tangle tangle;
|
||||
vtkm::Vec3f pt(rank * dsPerRank + i, 0, 0);
|
||||
if (rank == 1)
|
||||
std::cout << "PT= " << pt << std::endl;
|
||||
tangle.SetPointDimensions({ 50, 50, 50 });
|
||||
tangle.SetOrigin(pt);
|
||||
vtkm::cont::DataSet ds = tangle.Execute();
|
||||
|
||||
vtkm::rendering::Actor actor(
|
||||
ds.GetCellSet(), ds.GetCoordinateSystem(), ds.GetField(fieldName), colorTable);
|
||||
scene.AddActor(actor);
|
||||
}
|
||||
|
||||
vtkm::rendering::View3D view(scene, MapperVolume(), canvas, camera, bg);
|
||||
view.Paint();
|
||||
|
||||
canvas.SaveAs("result.png");
|
||||
}
|
||||
|
||||
void RenderTests()
|
||||
{
|
||||
// TestImageComposite();
|
||||
TestRenderComposite();
|
||||
//TestRenderComposite();
|
||||
TestVolumeRenderComposite();
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
Loading…
Reference in New Issue
Block a user