mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Add Actor and Scene to rendering library
Also took away some unnecessary templates.
This commit is contained in:
parent
05fe2a0619
commit
d4afc12add
136
vtkm/rendering/Actor.cxx
Normal file
136
vtkm/rendering/Actor.cxx
Normal file
@ -0,0 +1,136 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//
|
||||
// Copyright 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
|
||||
#include <vtkm/Assert.h>
|
||||
#include <vtkm/cont/TryExecute.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
struct Actor::InternalsType
|
||||
{
|
||||
vtkm::cont::DynamicCellSet Cells;
|
||||
vtkm::cont::CoordinateSystem Coordinates;
|
||||
vtkm::cont::Field ScalarField;
|
||||
vtkm::rendering::ColorTable ColorTable;
|
||||
|
||||
vtkm::Range ScalarRange;
|
||||
vtkm::Bounds SpatialBounds;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
InternalsType(const vtkm::cont::DynamicCellSet &cells,
|
||||
const vtkm::cont::CoordinateSystem &coordinates,
|
||||
const vtkm::cont::Field &scalarField,
|
||||
const vtkm::rendering::ColorTable &colorTable)
|
||||
: Cells(cells),
|
||||
Coordinates(coordinates),
|
||||
ScalarField(scalarField),
|
||||
ColorTable(colorTable)
|
||||
{ }
|
||||
};
|
||||
|
||||
struct Actor::RangeFunctor
|
||||
{
|
||||
vtkm::rendering::Actor::InternalsType *Internals;
|
||||
const vtkm::cont::CoordinateSystem &Coordinates;
|
||||
const vtkm::cont::Field &ScalarField;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
RangeFunctor(vtkm::rendering::Actor *self,
|
||||
const vtkm::cont::CoordinateSystem &coordinates,
|
||||
const vtkm::cont::Field &scalarField)
|
||||
: Internals(self->Internals.get()),
|
||||
Coordinates(coordinates),
|
||||
ScalarField(scalarField)
|
||||
{ }
|
||||
|
||||
template<typename Device>
|
||||
VTKM_CONT_EXPORT
|
||||
bool operator()(Device)
|
||||
{
|
||||
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||
|
||||
this->ScalarField.GetRange(&this->Internals->ScalarRange, Device());
|
||||
this->Internals->SpatialBounds = this->Coordinates.GetBounds(Device());
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Actor::Actor(const vtkm::cont::DynamicCellSet &cells,
|
||||
const vtkm::cont::CoordinateSystem &coordinates,
|
||||
const vtkm::cont::Field &scalarField,
|
||||
const vtkm::rendering::ColorTable &colorTable)
|
||||
: Internals(new InternalsType(cells, coordinates, scalarField, colorTable))
|
||||
{
|
||||
VTKM_ASSERT(scalarField.GetData().GetNumberOfComponents() == 1);
|
||||
|
||||
RangeFunctor functor(this, coordinates, scalarField);
|
||||
vtkm::cont::TryExecute(functor);
|
||||
}
|
||||
|
||||
void Actor::Render(vtkm::rendering::Mapper &mapper,
|
||||
vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Camera &camera) const
|
||||
{
|
||||
mapper.SetCanvas(&canvas);
|
||||
mapper.SetActiveColorTable(this->Internals->ColorTable);
|
||||
mapper.RenderCells(this->Internals->Cells,
|
||||
this->Internals->Coordinates,
|
||||
this->Internals->ScalarField,
|
||||
this->Internals->ColorTable,
|
||||
camera,
|
||||
this->Internals->ScalarRange);
|
||||
}
|
||||
|
||||
const vtkm::cont::DynamicCellSet &Actor::GetCells() const
|
||||
{
|
||||
return this->Internals->Cells;
|
||||
}
|
||||
|
||||
const vtkm::cont::CoordinateSystem &Actor::GetCoordiantes() const
|
||||
{
|
||||
return this->Internals->Coordinates;
|
||||
}
|
||||
|
||||
const vtkm::cont::Field &Actor::GetScalarField() const
|
||||
{
|
||||
return this->Internals->ScalarField;
|
||||
}
|
||||
|
||||
const vtkm::rendering::ColorTable &Actor::GetColorTable() const
|
||||
{
|
||||
return this->Internals->ColorTable;
|
||||
}
|
||||
|
||||
const vtkm::Range &Actor::GetScalarRange() const
|
||||
{
|
||||
return this->Internals->ScalarRange;
|
||||
}
|
||||
|
||||
const vtkm::Bounds &Actor::GetSpatialBounds() const
|
||||
{
|
||||
return this->Internals->SpatialBounds;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -20,10 +20,15 @@
|
||||
#ifndef vtk_m_rendering_Actor_h
|
||||
#define vtk_m_rendering_Actor_h
|
||||
|
||||
#include <vtkm/Assert.h>
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
#include <vector>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/shared_ptr.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
@ -31,49 +36,41 @@ namespace rendering {
|
||||
class Actor
|
||||
{
|
||||
public:
|
||||
//Actor(points, cells, field, colortable) {}
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_RENDERING_EXPORT
|
||||
Actor(const vtkm::cont::DynamicCellSet &cells,
|
||||
const vtkm::cont::CoordinateSystem &coordinates,
|
||||
const vtkm::cont::Field &scalarField,
|
||||
const vtkm::rendering::ColorTable &colorTable =
|
||||
vtkm::rendering::ColorTable("default"))
|
||||
: Cells(cells),
|
||||
Coordinates(coordinates),
|
||||
ScalarField(scalarField),
|
||||
ColorTable(colorTable)
|
||||
{
|
||||
VTKM_ASSERT(scalarField.GetData().GetNumberOfComponents() == 1);
|
||||
vtkm::rendering::ColorTable("default"));
|
||||
|
||||
scalarField.GetRange(&this->ScalarRange,
|
||||
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
this->SpatialBounds =
|
||||
coordinates.GetBounds(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
void Render(vtkm::rendering::Mapper &mapper,
|
||||
vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Camera &camera) const;
|
||||
|
||||
template<typename MapperType, typename CanvasType>
|
||||
VTKM_CONT_EXPORT
|
||||
void Render(MapperType &mapper,
|
||||
CanvasType &canvas,
|
||||
const vtkm::rendering::Camera &camera) const
|
||||
{
|
||||
mapper.SetCanvas(&canvas);
|
||||
mapper.SetActiveColorTable(this->ColorTable);
|
||||
mapper.RenderCells(this->Cells,
|
||||
this->Coordinates,
|
||||
this->ScalarField,
|
||||
this->ColorTable,
|
||||
camera,
|
||||
this->ScalarRange);
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
const vtkm::cont::DynamicCellSet &GetCells() const;
|
||||
|
||||
vtkm::cont::DynamicCellSet Cells;
|
||||
vtkm::cont::CoordinateSystem Coordinates;
|
||||
vtkm::cont::Field ScalarField;
|
||||
vtkm::rendering::ColorTable ColorTable;
|
||||
VTKM_RENDERING_EXPORT
|
||||
const vtkm::cont::CoordinateSystem &GetCoordiantes() const;
|
||||
|
||||
vtkm::Range ScalarRange;
|
||||
vtkm::Bounds SpatialBounds;
|
||||
VTKM_RENDERING_EXPORT
|
||||
const vtkm::cont::Field &GetScalarField() const;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
const vtkm::rendering::ColorTable &GetColorTable() const;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
const vtkm::Range &GetScalarRange() const;
|
||||
|
||||
VTKM_RENDERING_EXPORT
|
||||
const vtkm::Bounds &GetSpatialBounds() const;
|
||||
|
||||
private:
|
||||
struct InternalsType;
|
||||
boost::shared_ptr<InternalsType> Internals;
|
||||
|
||||
struct RangeFunctor;
|
||||
};
|
||||
|
||||
}} //namespace vtkm::rendering
|
||||
|
@ -45,6 +45,7 @@ set(headers
|
||||
)
|
||||
|
||||
set(sources
|
||||
Actor.cxx
|
||||
AxisAnnotation.cxx
|
||||
AxisAnnotation2D.cxx
|
||||
AxisAnnotation3D.cxx
|
||||
@ -59,6 +60,7 @@ set(sources
|
||||
Mapper.cxx
|
||||
MapperRayTracer.cxx
|
||||
MapperVolume.cxx
|
||||
Scene.cxx
|
||||
|
||||
internal/RunTriangulator.cxx
|
||||
)
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
namespace vtkm {
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
|
||||
VTKM_THIRDPARTY_PRE_INCLUDE
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
VTKM_THIRDPARTY_POST_INCLUDE
|
||||
|
||||
namespace vtkm {
|
||||
|
82
vtkm/rendering/Scene.cxx
Normal file
82
vtkm/rendering/Scene.cxx
Normal file
@ -0,0 +1,82 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//
|
||||
// Copyright 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/rendering/Scene.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
|
||||
struct Scene::InternalsType
|
||||
{
|
||||
std::vector<vtkm::rendering::Actor> Actors;
|
||||
};
|
||||
|
||||
Scene::Scene()
|
||||
: Internals(new InternalsType)
|
||||
{ }
|
||||
|
||||
void Scene::AddActor(const vtkm::rendering::Actor &actor)
|
||||
{
|
||||
this->Internals->Actors.push_back(actor);
|
||||
}
|
||||
|
||||
const vtkm::rendering::Actor &Scene::GetActor(vtkm::IdComponent index) const
|
||||
{
|
||||
return this->Internals->Actors[static_cast<std::size_t>(index)];
|
||||
}
|
||||
|
||||
vtkm::IdComponent Scene::GetNumberOfActors() const
|
||||
{
|
||||
return static_cast<vtkm::IdComponent>(this->Internals->Actors.size());
|
||||
}
|
||||
|
||||
void Scene::Render(vtkm::rendering::Mapper &mapper,
|
||||
vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Camera &camera) const
|
||||
{
|
||||
mapper.StartScene();
|
||||
for (vtkm::IdComponent actorIndex = 0;
|
||||
actorIndex < this->GetNumberOfActors();
|
||||
actorIndex++)
|
||||
{
|
||||
const vtkm::rendering::Actor &actor = this->GetActor(actorIndex);
|
||||
actor.Render(mapper, canvas, camera);
|
||||
}
|
||||
mapper.EndScene();
|
||||
}
|
||||
|
||||
vtkm::Bounds Scene::GetSpatialBounds() const
|
||||
{
|
||||
vtkm::Bounds bounds;
|
||||
for (vtkm::IdComponent actorIndex = 0;
|
||||
actorIndex < this->GetNumberOfActors();
|
||||
actorIndex++)
|
||||
{
|
||||
// accumulate all Actors' spatial bounds into the scene spatial bounds
|
||||
bounds.Include(this->GetActor(actorIndex).GetSpatialBounds());
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::rendering
|
@ -20,9 +20,12 @@
|
||||
#ifndef vtk_m_rendering_Scene_h
|
||||
#define vtk_m_rendering_Scene_h
|
||||
|
||||
#include <vtkm/rendering/vtkm_rendering_export.h>
|
||||
|
||||
#include <vtkm/rendering/Actor.h>
|
||||
#include <vtkm/rendering/Camera.h>
|
||||
#include <vector>
|
||||
#include <vtkm/rendering/Canvas.h>
|
||||
#include <vtkm/rendering/Mapper.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace rendering {
|
||||
@ -30,59 +33,29 @@ namespace rendering {
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
VTKM_CONT_EXPORT
|
||||
void AddActor(const vtkm::rendering::Actor &actor)
|
||||
{
|
||||
this->Actors.push_back(actor);
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
Scene();
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
const vtkm::rendering::Actor &GetActor(vtkm::IdComponent index) const
|
||||
{
|
||||
return this->Actors[static_cast<std::size_t>(index)];
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
void AddActor(const vtkm::rendering::Actor &actor);
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
vtkm::IdComponent GetNumberOfActors() const
|
||||
{
|
||||
return static_cast<vtkm::IdComponent>(this->Actors.size());
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
const vtkm::rendering::Actor &GetActor(vtkm::IdComponent index) const;
|
||||
|
||||
Scene() {}
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::IdComponent GetNumberOfActors() const;
|
||||
|
||||
template<typename MapperType, typename CanvasType>
|
||||
VTKM_CONT_EXPORT
|
||||
void Render(MapperType &mapper,
|
||||
CanvasType &canvas,
|
||||
vtkm::rendering::Camera &camera) const
|
||||
{
|
||||
mapper.StartScene();
|
||||
for (vtkm::IdComponent actorIndex = 0;
|
||||
actorIndex < this->GetNumberOfActors();
|
||||
actorIndex++)
|
||||
{
|
||||
const vtkm::rendering::Actor &actor = this->GetActor(actorIndex);
|
||||
actor.Render(mapper, canvas, camera);
|
||||
}
|
||||
mapper.EndScene();
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
void Render(vtkm::rendering::Mapper &mapper,
|
||||
vtkm::rendering::Canvas &canvas,
|
||||
const vtkm::rendering::Camera &camera) const;
|
||||
|
||||
vtkm::Bounds GetSpatialBounds() const
|
||||
{
|
||||
vtkm::Bounds bounds;
|
||||
for (vtkm::IdComponent actorIndex = 0;
|
||||
actorIndex < this->GetNumberOfActors();
|
||||
actorIndex++)
|
||||
{
|
||||
// accumulate all Actors' spatial bounds into the scene spatial bounds
|
||||
bounds.Include(this->GetActor(actorIndex).SpatialBounds);
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
VTKM_RENDERING_EXPORT
|
||||
vtkm::Bounds GetSpatialBounds() const;
|
||||
|
||||
private:
|
||||
std::vector<vtkm::rendering::Actor> Actors;
|
||||
struct InternalsType;
|
||||
boost::shared_ptr<InternalsType> Internals;
|
||||
};
|
||||
}} //namespace vtkm::rendering
|
||||
|
||||
|
@ -273,8 +273,8 @@ public:
|
||||
if (this->GetScene().GetNumberOfActors() > 0)
|
||||
{
|
||||
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
||||
this->ColorBarAnnotation.SetRange(this->GetScene().GetActor(0).ScalarRange, 5);
|
||||
this->ColorBarAnnotation.SetColorTable(this->GetScene().GetActor(0).ColorTable);
|
||||
this->ColorBarAnnotation.SetRange(this->GetScene().GetActor(0).GetScalarRange(), 5);
|
||||
this->ColorBarAnnotation.SetColorTable(this->GetScene().GetActor(0).GetColorTable());
|
||||
this->ColorBarAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
@ -476,10 +476,10 @@ public:
|
||||
if (scene.GetNumberOfActors() > 0)
|
||||
{
|
||||
//this->ColorBarAnnotation.SetAxisColor(vtkm::rendering::Color(1,1,1));
|
||||
this->ColorBarAnnotation.SetRange(scene.GetActor(0).ScalarRange.Min,
|
||||
scene.GetActor(0).ScalarRange.Max,
|
||||
this->ColorBarAnnotation.SetRange(scene.GetActor(0).GetScalarRange().Min,
|
||||
scene.GetActor(0).GetScalarRange().Max,
|
||||
5);
|
||||
this->ColorBarAnnotation.SetColorTable(scene.GetActor(0).ColorTable);
|
||||
this->ColorBarAnnotation.SetColorTable(scene.GetActor(0).GetColorTable());
|
||||
this->ColorBarAnnotation.Render(
|
||||
this->GetCamera(), this->GetWorldAnnotator(), this->GetCanvas());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user