vtk-m/vtkm/Particle.h

111 lines
3.2 KiB
C
Raw Normal View History

//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_Particle_h
#define vtk_m_Particle_h
2019-10-01 17:33:12 +00:00
#include <vtkm/Bitset.h>
namespace vtkm
{
2019-10-01 17:33:12 +00:00
//Bit field describing the status:
class ParticleStatus : public vtkm::Bitset<vtkm::UInt8>
{
2019-10-01 17:33:12 +00:00
public:
VTKM_EXEC_CONT ParticleStatus()
{
this->SetOk();
this->ClearTerminate();
}
VTKM_EXEC_CONT void SetOk() { this->set(SUCCESS_BIT); }
VTKM_EXEC_CONT bool CheckOk() const { return this->test(SUCCESS_BIT); }
VTKM_EXEC_CONT void SetFail() { this->reset(SUCCESS_BIT); }
VTKM_EXEC_CONT bool CheckFail() const { return !this->test(SUCCESS_BIT); }
VTKM_EXEC_CONT void SetTerminate() { this->set(TERMINATE_BIT); }
VTKM_EXEC_CONT void ClearTerminate() { this->reset(TERMINATE_BIT); }
VTKM_EXEC_CONT bool CheckTerminate() const { return this->test(TERMINATE_BIT); }
VTKM_EXEC_CONT void SetSpatialBounds() { this->set(SPATIAL_BOUNDS_BIT); }
VTKM_EXEC_CONT void ClearSpatialBounds() { this->reset(SPATIAL_BOUNDS_BIT); }
VTKM_EXEC_CONT bool CheckSpatialBounds() const { return this->test(SPATIAL_BOUNDS_BIT); }
VTKM_EXEC_CONT void SetTemporalBounds() { this->set(TEMPORAL_BOUNDS_BIT); }
VTKM_EXEC_CONT void ClearTemporalBounds() { this->reset(TEMPORAL_BOUNDS_BIT); }
VTKM_EXEC_CONT bool CheckTemporalBounds() const { return this->test(TEMPORAL_BOUNDS_BIT); }
VTKM_EXEC_CONT void SetTookAnySteps() { this->set(TOOK_ANY_STEPS_BIT); }
VTKM_EXEC_CONT void ClearTookAnySteps() { this->reset(TOOK_ANY_STEPS_BIT); }
VTKM_EXEC_CONT bool CheckTookAnySteps() const { return this->test(TOOK_ANY_STEPS_BIT); }
private:
2019-10-09 19:28:42 +00:00
static constexpr vtkm::Id SUCCESS_BIT = 0;
static constexpr vtkm::Id TERMINATE_BIT = 1;
static constexpr vtkm::Id SPATIAL_BOUNDS_BIT = 2;
static constexpr vtkm::Id TEMPORAL_BOUNDS_BIT = 3;
static constexpr vtkm::Id TOOK_ANY_STEPS_BIT = 4;
};
2019-10-10 12:43:39 +00:00
inline VTKM_CONT std::ostream& operator<<(std::ostream& s, const vtkm::ParticleStatus& status)
2019-10-01 17:33:12 +00:00
{
s << "[" << status.CheckOk() << " " << status.CheckTerminate() << " "
<< status.CheckSpatialBounds() << " " << status.CheckTemporalBounds() << "]";
return s;
}
class Particle
{
public:
VTKM_EXEC_CONT
Particle()
: Pos()
, ID(-1)
, NumSteps(0)
2019-10-01 17:33:12 +00:00
, Status()
, Time(0)
{
}
VTKM_EXEC_CONT
Particle(const vtkm::Particle& p)
: Pos(p.Pos)
, ID(p.ID)
, NumSteps(p.NumSteps)
, Status(p.Status)
, Time(p.Time)
{
}
VTKM_EXEC_CONT
Particle(const vtkm::Vec3f& p,
2019-10-01 17:33:12 +00:00
const vtkm::Id& id,
const vtkm::Id& numSteps = 0,
const vtkm::ParticleStatus& status = vtkm::ParticleStatus(),
const vtkm::FloatDefault& time = 0)
: Pos(p)
, ID(id)
, NumSteps(numSteps)
, Status(status)
, Time(time)
{
}
vtkm::Vec3f Pos;
vtkm::Id ID;
vtkm::Id NumSteps;
2019-10-01 17:33:12 +00:00
vtkm::ParticleStatus Status;
vtkm::FloatDefault Time;
};
}
#endif // vtk_m_Particle_h