2016-08-31 23:28:41 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2016-08-31 23:28:41 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/rendering/Actor.h>
|
|
|
|
|
2023-11-07 00:42:43 +00:00
|
|
|
#include <vtkm/Assert.h>
|
|
|
|
#include <vtkm/cont/BoundsCompute.h>
|
|
|
|
#include <vtkm/cont/FieldRangeCompute.h>
|
2016-08-31 23:28:41 +00:00
|
|
|
#include <vtkm/cont/TryExecute.h>
|
2022-01-04 22:38:18 +00:00
|
|
|
#include <vtkm/cont/UnknownCellSet.h>
|
2016-08-31 23:28:41 +00:00
|
|
|
|
2023-06-01 17:28:49 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace rendering
|
|
|
|
{
|
2016-08-31 23:28:41 +00:00
|
|
|
|
|
|
|
struct Actor::InternalsType
|
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
vtkm::cont::PartitionedDataSet Data;
|
|
|
|
std::string CoordinateName;
|
|
|
|
std::string FieldName;
|
|
|
|
vtkm::cont::Field::Association FieldAssociation;
|
|
|
|
|
2018-01-18 18:55:15 +00:00
|
|
|
vtkm::cont::ColorTable ColorTable;
|
2016-08-31 23:28:41 +00:00
|
|
|
|
|
|
|
vtkm::Range ScalarRange;
|
|
|
|
vtkm::Bounds SpatialBounds;
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2023-11-07 00:42:43 +00:00
|
|
|
InternalsType(const vtkm::cont::PartitionedDataSet partitionedDataSet,
|
2023-11-07 20:52:05 +00:00
|
|
|
const std::string coordinateName,
|
2023-11-07 00:42:43 +00:00
|
|
|
const std::string fieldName,
|
|
|
|
const vtkm::rendering::Color& color)
|
2023-11-07 20:52:05 +00:00
|
|
|
: Data(partitionedDataSet)
|
|
|
|
, CoordinateName(coordinateName)
|
2023-11-07 00:42:43 +00:00
|
|
|
, FieldName(fieldName)
|
2023-11-07 20:52:05 +00:00
|
|
|
, ColorTable(vtkm::Range{ 0, 1 }, color.Components, color.Components)
|
2023-11-07 00:42:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT
|
|
|
|
InternalsType(const vtkm::cont::PartitionedDataSet partitionedDataSet,
|
2023-11-07 20:52:05 +00:00
|
|
|
const std::string coordinateName,
|
2023-11-07 00:42:43 +00:00
|
|
|
const std::string fieldName,
|
|
|
|
const vtkm::cont::ColorTable& colorTable = vtkm::cont::ColorTable::Preset::Default)
|
2023-11-07 20:52:05 +00:00
|
|
|
: Data(partitionedDataSet)
|
|
|
|
, CoordinateName(coordinateName)
|
2023-11-07 00:42:43 +00:00
|
|
|
, FieldName(fieldName)
|
2017-05-18 14:29:41 +00:00
|
|
|
, ColorTable(colorTable)
|
|
|
|
{
|
|
|
|
}
|
2016-08-31 23:28:41 +00:00
|
|
|
};
|
|
|
|
|
2023-11-07 20:52:05 +00:00
|
|
|
Actor::Actor(const vtkm::cont::DataSet dataSet,
|
|
|
|
const std::string coordinateName,
|
|
|
|
const std::string fieldName)
|
2023-11-07 00:42:43 +00:00
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
vtkm::cont::PartitionedDataSet partitionedDataSet(dataSet);
|
|
|
|
this->Internals = std::make_unique<InternalsType>(partitionedDataSet, coordinateName, fieldName);
|
2023-11-07 00:42:43 +00:00
|
|
|
this->Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Actor::Actor(const vtkm::cont::DataSet dataSet,
|
2023-11-07 20:52:05 +00:00
|
|
|
const std::string coordinateName,
|
2023-11-07 00:42:43 +00:00
|
|
|
const std::string fieldName,
|
|
|
|
const vtkm::rendering::Color& color)
|
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
vtkm::cont::PartitionedDataSet partitionedDataSet(dataSet);
|
|
|
|
this->Internals =
|
|
|
|
std::make_unique<InternalsType>(partitionedDataSet, coordinateName, fieldName, color);
|
2023-11-07 00:42:43 +00:00
|
|
|
this->Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Actor::Actor(const vtkm::cont::DataSet dataSet,
|
2023-11-07 20:52:05 +00:00
|
|
|
const std::string coordinateName,
|
2023-11-07 00:42:43 +00:00
|
|
|
const std::string fieldName,
|
|
|
|
const vtkm::cont::ColorTable& colorTable)
|
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
vtkm::cont::PartitionedDataSet partitionedDataSet(dataSet);
|
|
|
|
this->Internals =
|
|
|
|
std::make_unique<InternalsType>(partitionedDataSet, coordinateName, fieldName, colorTable);
|
2023-11-07 00:42:43 +00:00
|
|
|
this->Init();
|
|
|
|
}
|
|
|
|
|
2023-11-07 20:52:05 +00:00
|
|
|
Actor::Actor(const vtkm::cont::PartitionedDataSet dataSet,
|
|
|
|
const std::string coordinateName,
|
|
|
|
const std::string fieldName)
|
|
|
|
: Internals(new InternalsType(dataSet, coordinateName, fieldName))
|
2023-11-07 00:42:43 +00:00
|
|
|
{
|
|
|
|
this->Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Actor::Actor(const vtkm::cont::PartitionedDataSet dataSet,
|
2023-11-07 20:52:05 +00:00
|
|
|
const std::string coordinateName,
|
2023-11-07 00:42:43 +00:00
|
|
|
const std::string fieldName,
|
|
|
|
const vtkm::rendering::Color& color)
|
2023-11-07 20:52:05 +00:00
|
|
|
: Internals(new InternalsType(dataSet, coordinateName, fieldName, color))
|
2023-11-07 00:42:43 +00:00
|
|
|
{
|
|
|
|
this->Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Actor::Actor(const vtkm::cont::PartitionedDataSet dataSet,
|
2023-11-07 20:52:05 +00:00
|
|
|
const std::string coordinateName,
|
2023-11-07 00:42:43 +00:00
|
|
|
const std::string fieldName,
|
|
|
|
const vtkm::cont::ColorTable& colorTable)
|
2023-11-07 20:52:05 +00:00
|
|
|
: Internals(new InternalsType(dataSet, coordinateName, fieldName, colorTable))
|
2023-11-07 00:42:43 +00:00
|
|
|
{
|
|
|
|
this->Init();
|
|
|
|
}
|
|
|
|
|
2022-01-04 22:38:18 +00:00
|
|
|
Actor::Actor(const vtkm::cont::UnknownCellSet& cells,
|
2018-01-18 18:55:15 +00:00
|
|
|
const vtkm::cont::CoordinateSystem& coordinates,
|
|
|
|
const vtkm::cont::Field& scalarField)
|
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
vtkm::cont::DataSet dataSet;
|
|
|
|
dataSet.SetCellSet(cells);
|
|
|
|
dataSet.AddCoordinateSystem(coordinates);
|
|
|
|
dataSet.AddField(scalarField);
|
|
|
|
this->Internals =
|
|
|
|
std::make_unique<InternalsType>(dataSet, coordinates.GetName(), scalarField.GetName());
|
|
|
|
this->Init();
|
2018-01-18 18:55:15 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 22:38:18 +00:00
|
|
|
Actor::Actor(const vtkm::cont::UnknownCellSet& cells,
|
2017-07-28 17:31:19 +00:00
|
|
|
const vtkm::cont::CoordinateSystem& coordinates,
|
|
|
|
const vtkm::cont::Field& scalarField,
|
|
|
|
const vtkm::rendering::Color& color)
|
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
vtkm::cont::DataSet dataSet;
|
|
|
|
dataSet.SetCellSet(cells);
|
|
|
|
dataSet.AddCoordinateSystem(coordinates);
|
|
|
|
dataSet.AddField(scalarField);
|
|
|
|
this->Internals =
|
|
|
|
std::make_unique<InternalsType>(dataSet, coordinates.GetName(), scalarField.GetName(), color);
|
|
|
|
this->Init();
|
2017-07-28 17:31:19 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 22:38:18 +00:00
|
|
|
Actor::Actor(const vtkm::cont::UnknownCellSet& cells,
|
2017-05-26 17:53:28 +00:00
|
|
|
const vtkm::cont::CoordinateSystem& coordinates,
|
|
|
|
const vtkm::cont::Field& scalarField,
|
2018-01-18 18:55:15 +00:00
|
|
|
const vtkm::cont::ColorTable& colorTable)
|
2017-07-28 17:31:19 +00:00
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
vtkm::cont::DataSet dataSet;
|
|
|
|
dataSet.SetCellSet(cells);
|
|
|
|
dataSet.AddCoordinateSystem(coordinates);
|
|
|
|
dataSet.AddField(scalarField);
|
|
|
|
this->Internals = std::make_unique<InternalsType>(
|
|
|
|
dataSet, coordinates.GetName(), scalarField.GetName(), colorTable);
|
|
|
|
this->Init();
|
2017-07-28 17:31:19 +00:00
|
|
|
}
|
|
|
|
|
2023-06-02 16:32:44 +00:00
|
|
|
Actor::Actor(const Actor& rhs)
|
|
|
|
: Internals(nullptr)
|
|
|
|
{
|
|
|
|
// rhs might have been moved, its Internal would be nullptr
|
|
|
|
if (rhs.Internals)
|
|
|
|
Internals = std::make_unique<InternalsType>(*rhs.Internals);
|
|
|
|
}
|
|
|
|
|
|
|
|
Actor& Actor::operator=(const Actor& rhs)
|
|
|
|
{
|
|
|
|
// both *this and rhs might have been moved.
|
|
|
|
if (!rhs.Internals)
|
|
|
|
{
|
|
|
|
Internals.reset();
|
|
|
|
}
|
|
|
|
else if (!Internals)
|
|
|
|
{
|
|
|
|
Internals = std::make_unique<InternalsType>(*rhs.Internals);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*Internals = *rhs.Internals;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2023-06-01 17:28:49 +00:00
|
|
|
Actor::Actor(vtkm::rendering::Actor&&) noexcept = default;
|
|
|
|
Actor& Actor::operator=(Actor&&) noexcept = default;
|
2023-06-02 16:32:44 +00:00
|
|
|
Actor::~Actor() = default;
|
2023-06-01 17:28:49 +00:00
|
|
|
|
2023-11-07 00:42:43 +00:00
|
|
|
void Actor::Init()
|
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
this->Internals->SpatialBounds = vtkm::cont::BoundsCompute(this->Internals->Data);
|
2023-11-07 00:42:43 +00:00
|
|
|
this->Internals->ScalarRange =
|
2023-11-07 20:52:05 +00:00
|
|
|
vtkm::cont::FieldRangeCompute(this->Internals->Data, this->Internals->FieldName)
|
2023-11-07 00:42:43 +00:00
|
|
|
.ReadPortal()
|
|
|
|
.Get(0);
|
|
|
|
}
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
void Actor::Render(vtkm::rendering::Mapper& mapper,
|
|
|
|
vtkm::rendering::Canvas& canvas,
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::rendering::Camera& camera) const
|
2016-08-31 23:28:41 +00:00
|
|
|
{
|
|
|
|
mapper.SetCanvas(&canvas);
|
|
|
|
mapper.SetActiveColorTable(this->Internals->ColorTable);
|
2023-11-07 20:52:05 +00:00
|
|
|
mapper.RenderCellsPartitioned(this->Internals->Data,
|
|
|
|
this->Internals->FieldName,
|
|
|
|
this->Internals->ColorTable,
|
|
|
|
camera,
|
|
|
|
this->Internals->ScalarRange);
|
2016-08-31 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-07 00:42:43 +00:00
|
|
|
|
2022-01-04 22:38:18 +00:00
|
|
|
const vtkm::cont::UnknownCellSet& Actor::GetCells() const
|
2016-08-31 23:28:41 +00:00
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
return this->Internals->Data.GetPartition(0).GetCellSet();
|
2016-08-31 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2023-11-08 00:31:57 +00:00
|
|
|
vtkm::cont::CoordinateSystem Actor::GetCoordinates() const
|
2016-08-31 23:28:41 +00:00
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
return this->Internals->Data.GetPartition(0).GetCoordinateSystem(this->Internals->CoordinateName);
|
2016-08-31 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::cont::Field& Actor::GetScalarField() const
|
2016-08-31 23:28:41 +00:00
|
|
|
{
|
2023-11-07 20:52:05 +00:00
|
|
|
return this->Internals->Data.GetPartition(0).GetField(this->Internals->FieldName);
|
2016-08-31 23:28:41 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 18:55:15 +00:00
|
|
|
const vtkm::cont::ColorTable& Actor::GetColorTable() const
|
2016-08-31 23:28:41 +00:00
|
|
|
{
|
|
|
|
return this->Internals->ColorTable;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::Range& Actor::GetScalarRange() const
|
2016-08-31 23:28:41 +00:00
|
|
|
{
|
|
|
|
return this->Internals->ScalarRange;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
const vtkm::Bounds& Actor::GetSpatialBounds() const
|
2016-08-31 23:28:41 +00:00
|
|
|
{
|
|
|
|
return this->Internals->SpatialBounds;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
void Actor::SetScalarRange(const vtkm::Range& scalarRange)
|
2017-02-09 23:38:40 +00:00
|
|
|
{
|
|
|
|
this->Internals->ScalarRange = scalarRange;
|
|
|
|
}
|
2016-08-31 23:28:41 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::rendering
|