7#include <hrleDomain.hpp>
8#include <hrleFillDomainWithSignedDistance.hpp>
9#include <hrleVectorType.hpp>
13#include <vcLogger.hpp>
14#include <vcSmartPointer.hpp>
16#define LS_DOMAIN_SERIALIZATION_VERSION 0
20using namespace viennacore;
28template <
class T,
int D>
class Domain {
35 typedef typename std::vector<std::pair<hrleVectorType<hrleIndexType, D>,
T>>
45 int levelSetWidth = 1;
54 static constexpr T POS_VALUE = std::numeric_limits<T>::max();
55 static constexpr T NEG_VALUE = std::numeric_limits<T>::lowest();
58 Domain(hrleCoordType gridDelta = 1.0) {
59 hrleIndexType gridMin[
D], gridMax[
D];
61 for (
unsigned i = 0; i <
D; ++i) {
64 boundaryCons[i] = BoundaryType::INFINITE_BOUNDARY;
67 grid =
GridType(gridMin, gridMax, gridDelta, boundaryCons);
72 hrleCoordType gridDelta = 1.0) {
73 hrleIndexType gridMin[
D], gridMax[
D];
74 for (
unsigned i = 0; i <
D; ++i) {
75 gridMin[i] = std::floor(bounds[2 * i] / gridDelta);
76 gridMax[i] = std::ceil(bounds[2 * i + 1] / gridDelta);
79 grid =
GridType(gridMin, gridMax, gridDelta, boundaryConditions);
83 Domain(std::vector<hrleCoordType> bounds,
84 std::vector<unsigned> boundaryConditions,
85 hrleCoordType gridDelta = 1.0) {
87 for (
unsigned i = 0; i <
D; ++i) {
88 boundaryCons[i] =
static_cast<BoundaryType>(boundaryConditions[i]);
91 SmartPointer<Domain<T, D>>::New(bounds.data(), boundaryCons, gridDelta);
98 BoundaryType *boundaryConditions, hrleCoordType gridDelta = 1.0) {
100 SmartPointer<Domain<T, D>>::New(bounds, boundaryConditions, gridDelta);
102 hrleFillDomainWithSignedDistance(domain, pointData,
T(
NEG_VALUE),
114 void finalize(
int newWidth) { levelSetWidth = newWidth; }
122 grid = passedDomain->grid;
123 domain.deepCopy(grid, passedDomain->domain);
124 levelSetWidth = passedDomain->levelSetWidth;
125 pointData = passedDomain->pointData;
133 hrleFillDomainWithSignedDistance(domain, pointData,
T(
NEG_VALUE),
171 return voidPointMarkers;
175 void print(std::ostream &out = std::cout) {
176 out <<
"Grid pointer: " << &grid << std::endl;
177 out <<
"lsDomain: " << &domain << std::endl;
178 out <<
"DomainSegments: " << std::endl;
180 out << &(domain.getDomainSegment(i)) << std::endl;
188 stream <<
"lsDomain";
192 stream.write(&formatVersion, 1);
195 grid.serialize(stream);
198 domain.serialize(stream);
202 const uint32_t width = levelSetWidth;
203 stream.write(
reinterpret_cast<const char *
>(&width),
sizeof(uint32_t));
207 char hasPointData = (pointData.
empty()) ? 0 : 1;
208 stream.write(&hasPointData, 1);
209 if (hasPointData == 1) {
220 stream.read(identifier, 8);
221 if (std::string(identifier).compare(0, 8,
"lsDomain")) {
222 Logger::getInstance()
224 "Reading Domain from stream failed. Header could not be found.")
231 stream.read(&formatVersion, 1);
233 Logger::getInstance()
235 "Reading Domain of version " + std::to_string(formatVersion) +
236 " with reader of version " +
243 grid.deserialize(stream);
249 domain.deserialize(stream);
253 stream.read(
reinterpret_cast<char *
>(&width),
sizeof(uint32_t));
254 levelSetWidth = width;
258 stream.read(&hasPointData, 1);
259 if (hasPointData == 1) {
Class containing all information about the level set, including the dimensions of the domain,...
Definition lsDomain.hpp:28
hrleGrid< D > GridType
Definition lsDomain.hpp:32
Domain(PointValueVectorType pointData, hrleCoordType *bounds, BoundaryType *boundaryConditions, hrleCoordType gridDelta=1.0)
initialise Domain with domain size "bounds", filled with point/value pairs in pointData
Definition lsDomain.hpp:97
PointData< T > PointDataType
Definition lsDomain.hpp:38
static constexpr T NEG_VALUE
Definition lsDomain.hpp:55
T ValueType
Definition lsDomain.hpp:31
void clearMetaData()
Definition lsDomain.hpp:160
void deepCopy(const SmartPointer< Domain< T, D > > passedDomain)
copy all values of "passedDomain" to this Domain
Definition lsDomain.hpp:121
unsigned getNumberOfSegments() const
returns the number of segments, the levelset is split into. This is useful for algorithm parallelisat...
Definition lsDomain.hpp:150
void finalize()
this function finalizes the levelset, so it is ready for use by other algorithms
Definition lsDomain.hpp:118
void print(std::ostream &out=std::cout)
prints basic information and all memebers of the levelset structure
Definition lsDomain.hpp:175
Domain(hrleCoordType gridDelta=1.0)
initalise an empty infinite Domain
Definition lsDomain.hpp:58
hrleDomain< T, D > DomainType
Definition lsDomain.hpp:33
Domain(std::vector< hrleCoordType > bounds, std::vector< unsigned > boundaryConditions, hrleCoordType gridDelta=1.0)
Definition lsDomain.hpp:83
std::vector< bool > VoidPointMarkersType
Definition lsDomain.hpp:39
void finalize(int newWidth)
this function sets a new levelset width and finalizes the levelset, so it is ready for use by other a...
Definition lsDomain.hpp:114
Domain(SmartPointer< Domain > passedDomain)
Definition lsDomain.hpp:110
static constexpr T POS_VALUE
Definition lsDomain.hpp:54
const DomainType & getDomain() const
Definition lsDomain.hpp:146
VoidPointMarkersType & getVoidPointMarkers()
get reference to the voidPoints markers for all points
Definition lsDomain.hpp:168
const VoidPointMarkersType & getVoidPointMarkers() const
Definition lsDomain.hpp:170
BoundaryConditionEnum< D > BoundaryType
Definition lsDomain.hpp:34
const PointDataType & getPointData() const
Definition lsDomain.hpp:165
PointDataType & getPointData()
get reference to point data saved in the level set
Definition lsDomain.hpp:163
Domain(hrleCoordType *bounds, BoundaryType *boundaryConditions, hrleCoordType gridDelta=1.0)
Definition lsDomain.hpp:71
DomainType & getDomain()
get const reference to the underlying hrleDomain data structure
Definition lsDomain.hpp:144
Domain(GridType passedGrid)
Definition lsDomain.hpp:106
int getLevelSetWidth() const
Definition lsDomain.hpp:155
std::istream & deserialize(std::istream &stream)
Deserialize Domain from binary stream.
Definition lsDomain.hpp:217
GridType & getGrid()
get mutable reference to the grid on which the level set is defined
Definition lsDomain.hpp:141
const GridType & getGrid() const
get reference to the grid on which the levelset is defined
Definition lsDomain.hpp:138
unsigned getNumberOfPoints() const
returns the number of defined points
Definition lsDomain.hpp:153
std::vector< std::pair< hrleVectorType< hrleIndexType, D >, T > > PointValueVectorType
Definition lsDomain.hpp:36
std::ostream & serialize(std::ostream &stream)
Serializes the Domain into a binary stream.
Definition lsDomain.hpp:186
std::vector< std::array< T, D > > NormalVectorType
Definition lsDomain.hpp:37
void setLevelSetWidth(int width)
Definition lsDomain.hpp:157
void insertPoints(PointValueVectorType pointData, bool sort=true)
re-initalise Domain with the point/value pairs in pointData This is similar to lsFromMesh with the di...
Definition lsDomain.hpp:132
static constexpr int dimensions
Definition lsDomain.hpp:51
This class holds data associated with points in space.
Definition lsPointData.hpp:20
void clear()
Delete all data stored in this object.
Definition lsPointData.hpp:272
std::ostream & serialize(std::ostream &stream)
Serialize PointData into a binary stream.
Definition lsPointData.hpp:283
bool empty()
Return whether this object is empty.
Definition lsPointData.hpp:280
std::istream & deserialize(std::istream &stream)
Deserialize PointData from a binary stream.
Definition lsPointData.hpp:346
#define LS_DOMAIN_SERIALIZATION_VERSION
Definition lsDomain.hpp:16
#define PRECOMPILE_PRECISION_DIMENSION(className)
Definition lsPreCompileMacros.hpp:24
Definition lsAdvect.hpp:46
typename hrleGrid< D >::boundaryType BoundaryConditionEnum
Definition lsDomain.hpp:24
constexpr int D
Definition pyWrap.cpp:65
double T
Definition pyWrap.cpp:63