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;
27template <
class T,
int D>
class Domain {
34 typedef typename std::vector<std::pair<hrleVectorType<hrleIndexType, D>,
T>>
44 int levelSetWidth = 1;
53 static constexpr T POS_VALUE = std::numeric_limits<T>::max();
54 static constexpr T NEG_VALUE = std::numeric_limits<T>::lowest();
57 Domain(hrleCoordType gridDelta = 1.0) {
58 hrleIndexType gridMin[
D], gridMax[
D];
60 for (
unsigned i = 0; i <
D; ++i) {
63 boundaryCons[i] = BoundaryType::INFINITE_BOUNDARY;
66 grid =
GridType(gridMin, gridMax, gridDelta, boundaryCons);
71 hrleCoordType gridDelta = 1.0) {
72 hrleIndexType gridMin[
D], gridMax[
D];
73 for (
unsigned i = 0; i <
D; ++i) {
74 gridMin[i] = std::floor(bounds[2 * i] / gridDelta);
75 gridMax[i] = std::ceil(bounds[2 * i + 1] / gridDelta);
78 grid =
GridType(gridMin, gridMax, gridDelta, boundaryConditions);
82 Domain(std::vector<hrleCoordType> bounds,
83 std::vector<unsigned> boundaryConditions,
84 hrleCoordType gridDelta = 1.0) {
86 for (
unsigned i = 0; i <
D; ++i) {
87 boundaryCons[i] =
static_cast<BoundaryType>(boundaryConditions[i]);
90 SmartPointer<Domain<T, D>>::New(bounds.data(), boundaryCons, gridDelta);
97 BoundaryType *boundaryConditions, hrleCoordType gridDelta = 1.0) {
99 SmartPointer<Domain<T, D>>::New(bounds, boundaryConditions, gridDelta);
101 hrleFillDomainWithSignedDistance(domain, pointData,
T(
NEG_VALUE),
113 void finalize(
int newWidth) { levelSetWidth = newWidth; }
121 grid = passedDomain->grid;
122 domain.deepCopy(grid, passedDomain->domain);
123 levelSetWidth = passedDomain->levelSetWidth;
124 pointData = passedDomain->pointData;
132 hrleFillDomainWithSignedDistance(domain, pointData,
T(
NEG_VALUE),
170 return voidPointMarkers;
174 void print(std::ostream &out = std::cout) {
175 out <<
"Grid pointer: " << &grid << std::endl;
176 out <<
"lsDomain: " << &domain << std::endl;
177 out <<
"DomainSegments: " << std::endl;
179 out << &(domain.getDomainSegment(i)) << std::endl;
187 stream <<
"lsDomain";
191 stream.write(&formatVersion, 1);
194 grid.serialize(stream);
197 domain.serialize(stream);
201 const uint32_t width = levelSetWidth;
202 stream.write(
reinterpret_cast<const char *
>(&width),
sizeof(uint32_t));
206 char hasPointData = (pointData.empty()) ? 0 : 1;
207 stream.write(&hasPointData, 1);
208 if (hasPointData == 1) {
209 pointData.serialize(stream);
219 stream.read(identifier, 8);
220 if (std::string(identifier).compare(0, 8,
"lsDomain")) {
221 Logger::getInstance()
223 "Reading Domain from stream failed. Header could not be found.")
230 stream.read(&formatVersion, 1);
232 Logger::getInstance()
234 "Reading Domain of version " + std::to_string(formatVersion) +
235 " with reader of version " +
242 grid.deserialize(stream);
248 domain.deserialize(stream);
252 stream.read(
reinterpret_cast<char *
>(&width),
sizeof(uint32_t));
253 levelSetWidth = width;
257 stream.read(&hasPointData, 1);
258 if (hasPointData == 1) {
260 pointData.deserialize(stream);
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:96
static constexpr T NEG_VALUE
Definition lsDomain.hpp:54
T ValueType
Definition lsDomain.hpp:30
void clearMetaData()
Definition lsDomain.hpp:159
hrleGrid< D > GridType
Definition lsDomain.hpp:31
void deepCopy(const SmartPointer< Domain< T, D > > passedDomain)
copy all values of "passedDomain" to this Domain
Definition lsDomain.hpp:120
unsigned getNumberOfSegments() const
returns the number of segments, the levelset is split into. This is useful for algorithm parallelisat...
Definition lsDomain.hpp:149
void finalize()
this function finalizes the levelset, so it is ready for use by other algorithms
Definition lsDomain.hpp:117
void print(std::ostream &out=std::cout)
prints basic information and all memebers of the levelset structure
Definition lsDomain.hpp:174
Domain(hrleCoordType gridDelta=1.0)
initalise an empty infinite Domain
Definition lsDomain.hpp:57
std::vector< bool > VoidPointMarkersType
Definition lsDomain.hpp:38
PointData< T > PointDataType
Definition lsDomain.hpp:37
Domain(std::vector< hrleCoordType > bounds, std::vector< unsigned > boundaryConditions, hrleCoordType gridDelta=1.0)
Definition lsDomain.hpp:82
std::vector< std::array< T, D > > NormalVectorType
Definition lsDomain.hpp:36
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:113
Domain(SmartPointer< Domain > passedDomain)
Definition lsDomain.hpp:109
static constexpr T POS_VALUE
Definition lsDomain.hpp:53
BoundaryConditionEnum BoundaryType
Definition lsDomain.hpp:33
const DomainType & getDomain() const
Definition lsDomain.hpp:145
VoidPointMarkersType & getVoidPointMarkers()
get reference to the voidPoints markers for all points
Definition lsDomain.hpp:167
const VoidPointMarkersType & getVoidPointMarkers() const
Definition lsDomain.hpp:169
const PointDataType & getPointData() const
Definition lsDomain.hpp:164
PointDataType & getPointData()
get reference to point data saved in the level set
Definition lsDomain.hpp:162
hrleDomain< T, D > DomainType
Definition lsDomain.hpp:32
Domain(hrleCoordType *bounds, BoundaryType *boundaryConditions, hrleCoordType gridDelta=1.0)
Definition lsDomain.hpp:70
DomainType & getDomain()
get const reference to the underlying hrleDomain data structure
Definition lsDomain.hpp:143
Domain(GridType passedGrid)
Definition lsDomain.hpp:105
int getLevelSetWidth() const
Definition lsDomain.hpp:154
std::istream & deserialize(std::istream &stream)
Deserialize Domain from binary stream.
Definition lsDomain.hpp:216
GridType & getGrid()
get mutable reference to the grid on which the level set is defined
Definition lsDomain.hpp:140
std::vector< std::pair< hrleVectorType< hrleIndexType, D >, T > > PointValueVectorType
Definition lsDomain.hpp:35
const GridType & getGrid() const
get reference to the grid on which the levelset is defined
Definition lsDomain.hpp:137
unsigned getNumberOfPoints() const
returns the number of defined points
Definition lsDomain.hpp:152
std::ostream & serialize(std::ostream &stream)
Serializes the Domain into a binary stream.
Definition lsDomain.hpp:185
void setLevelSetWidth(int width)
Definition lsDomain.hpp:156
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:131
static constexpr int dimensions
Definition lsDomain.hpp:50
This class holds data associated with points in space.
Definition lsPointData.hpp:20
#define LS_DOMAIN_SERIALIZATION_VERSION
Definition lsDomain.hpp:16
#define PRECOMPILE_PRECISION_DIMENSION(className)
Definition lsPreCompileMacros.hpp:24
Definition lsAdvect.hpp:37
hrleBoundaryType BoundaryConditionEnum
Definition lsDomain.hpp:23
constexpr int D
Definition pyWrap.cpp:66
double T
Definition pyWrap.cpp:64