Loading...
Searching...
No Matches
levelSetSegmentationObject.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25# ifndef __BITPIT_LEVELSET_SEGMENTATION_OBJECT_HPP__
26# define __BITPIT_LEVELSET_SEGMENTATION_OBJECT_HPP__
27
28#include "levelSetCartesianKernel.hpp"
29#include "levelSetBooleanObject.hpp"
30#include "levelSetBooleanObject.tpp"
31#include "levelSetCommon.hpp"
32#include "levelSetComplementObject.hpp"
33#include "levelSetComplementObject.tpp"
34#include "levelSetKernel.hpp"
35#include "levelSetObject.hpp"
36
37#include "bitpit_common.hpp"
38#include "bitpit_surfunstructured.hpp"
39#include "bitpit_volcartesian.hpp"
40#include "bitpit_voloctree.hpp"
41
42# include <array>
43# include <vector>
44# include <unordered_set>
45# include <unordered_map>
46
47namespace bitpit{
48
49class SurfaceSkdTree;
50
52
53public:
56
57 BITPIT_PUBLIC_API static const double DEFAULT_FEATURE_ANGLE;
58
64 LevelSetSegmentationSurfaceInfo(std::unique_ptr<const SurfUnstructured> &&surface, double featureAngle, LevelSetSurfaceSmoothing surfaceSmoothing = LevelSetSurfaceSmoothing::LOW_ORDER);
65
66 const SurfUnstructured & getSurface() const;
67 void setSurface(std::unique_ptr<const SurfUnstructured> &&surface, double featureAngle = DEFAULT_FEATURE_ANGLE);
68 void setSurface(const SurfUnstructured *surface, double featureAngle = DEFAULT_FEATURE_ANGLE);
69 void setSurface(const SurfUnstructured *surface, double featureAngle, LevelSetSurfaceSmoothing surfaceSmoothing);
70
71 const SurfaceSkdTree & getSearchTree() const;
72
73 double getFeatureAngle() const;
75
76 double evalDistance(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, bool signedDistance, std::array<double, 3> *distanceVector) const;
77 double evalDistance(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, bool signedDistance) const;
78 std::array<double, 3> evalDistanceVector(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr) const;
79
80 std::array<double, 3> evalNormal(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr) const;
81 std::array<double,3> evalPseudoNormal(const SurfUnstructured::CellConstIterator &segmentIterator, const double *lambda) const;
82
83 void evalProjection(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
84 void evalProjection(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint) const;
85 std::array<double, 3> evalProjection(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, double *lambda) const;
86
87private:
88 typedef std::pair<long, int> SegmentVertexKey;
89
90 const SurfUnstructured *m_surface;
91 std::unique_ptr<const SurfUnstructured> m_ownedSurface;
92 double m_featureAngle;
93 LevelSetSurfaceSmoothing m_surfaceSmoothing;
94
95 std::unique_ptr<SurfaceSkdTree> m_searchTree;
96
97 PiercedStorage<std::size_t> m_segmentVertexOffset;
98
99 mutable PiercedStorage<bool> m_segmentNormalsValid;
100 mutable PiercedStorage<std::array<double,3>> m_segmentNormalsStorage;
101 mutable PiercedStorage<bool> m_unlimitedVertexNormalsValid;
102 mutable PiercedStorage<std::array<double,3>> m_unlimitedVertexNormalsStorage;
103 mutable std::vector<bool> m_limitedSegmentVertexNormalValid;
104 mutable std::unordered_map<SegmentVertexKey, std::array<double,3>, utils::hashing::hash<SegmentVertexKey>> m_limitedSegmentVertexNormalStorage;
105
106 void evalProjectionOnVertex(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
107 void evalHighOrderProjectionOnLine(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
108 void evalHighOrderProjectionOnTriangle(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
109 void evalHighOrderProjectionOnPolygon(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
110 void evalHighOrderProjection(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
111
112 void evalLowOrderProjectionOnLine(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
113 void evalLowOrderProjectionOnTriangle(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
114 void evalLowOrderProjectionOnPolygon(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
115 void evalLowOrderProjection(const std::array<double, 3> &point, const SegmentConstIterator &segmentItr, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
116
117 std::array<double,3> computePseudoNormal( const SurfUnstructured::CellConstIterator &segmentIterator, const double *lambda ) const;
118 std::array<double,3> computeSurfaceNormal( const SurfUnstructured::CellConstIterator &segmentIterator, const double *lambda ) const;
119
120 std::array<double,3> computeSegmentNormal( const SurfUnstructured::CellConstIterator &segmentIterator ) const;
121 std::array<double,3> computeSegmentEdgeNormal(const SegmentConstIterator &segmentItr, int edge, bool limited ) const;
122 std::array<double,3> computeSegmentVertexNormal( const SurfUnstructured::CellConstIterator &segmentIterator, int vertex, bool limited ) const;
123
124};
125
127
128public:
129 BITPIT_PUBLIC_API static const double AUTOMATIC_SEARCH_RADIUS;
130
132
134
135 LevelSetFieldset getSupportedFields() const override;
136
137 const SurfUnstructured & evalCellSurface(long id) const;
138 long evalCellSupport(long id, double searchRadius = AUTOMATIC_SEARCH_RADIUS) const;
139 int evalCellPart(long id) const;
140 std::array<double,3> evalCellNormal(long id, bool signedLevelSet) const;
141
142 const SurfUnstructured & evalSurface(const std::array<double,3> &point) const;
143 long evalSupport(const std::array<double,3> &point) const;
144 long evalSupport(const std::array<double,3> &point, double searchRadius) const;
145 int evalPart(const std::array<double,3> &point) const;
146 std::array<double,3> evalNormal(const std::array<double,3> &point, bool signedLevelSet) const;
147 void evalProjection(const std::array<double,3> &point, bool signedLevelSet, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
148
149 BITPIT_DEPRECATED(int getPart(long cellId) const);
150 BITPIT_DEPRECATED(std::array<double BITPIT_COMMA 3> getNormal(long cellId) const);
151 BITPIT_DEPRECATED(long getSupport(long cellId) const);
152 BITPIT_DEPRECATED(double getSurfaceFeatureSize(long cellId) const);
153
154 BITPIT_DEPRECATED(int getPart(const std::array<double,3> &point) const);
155 BITPIT_DEPRECATED(std::array<double BITPIT_COMMA 3> getNormal(const std::array<double,3> &point) const);
156 BITPIT_DEPRECATED(long getSupport(const std::array<double,3> &point) const);
157 BITPIT_DEPRECATED(double getSurfaceFeatureSize(const std::array<double,3> &point) const);
158
159protected:
161
163 std::size_t createFieldCellCache(LevelSetField field, std::size_t cacheId = CellCacheCollection::NULL_CACHE_ID) override;
164 void fillFieldCellCache(LevelSetField field, long id) override;
166
168
169 virtual const SurfUnstructured & _evalCellSurface(long id) const = 0;
170 virtual int _evalCellPart(long id) const;
171 virtual std::array<double,3> _evalCellNormal(long id, bool signedLevelSet) const = 0;
172 virtual long _evalCellSupport(long id, double searchRadius = AUTOMATIC_SEARCH_RADIUS) const = 0;
173
174 virtual const SurfUnstructured & _evalSurface(const std::array<double,3> &point) const = 0;
175 virtual int _evalPart(const std::array<double,3> &point) const;
176 virtual long _evalSupport(const std::array<double,3> &point) const = 0;
177 virtual long _evalSupport(const std::array<double,3> &point, double searchRadius) const = 0;
178 virtual void _evalProjection(const std::array<double,3> &point, bool signedLevelSet, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const = 0;
179
180 void addVTKOutputData(LevelSetField field, const std::string &objectName) override;
181 std::string getVTKOutputFieldName(LevelSetField field) const override;
182 void flushVTKOutputData(std::fstream &stream, VTKFormat format, LevelSetField field) const override;
184};
185
187
188public:
190 LevelSetSegmentationObject(int, std::unique_ptr<const SurfUnstructured> &&surface, double featureAngle = 2. * BITPIT_PI);
191 LevelSetSegmentationObject(int, const SurfUnstructured *surface, double featureAngle = 2. * BITPIT_PI);
192 LevelSetSegmentationObject(int, const SurfUnstructured *surface, double featureAngle, LevelSetSurfaceSmoothing surfaceSmoothing);
195
196 bool empty() const override;
197
198 LevelSetSegmentationObject * clone() const override;
199
200 const SurfUnstructured & getSurface() const;
201 void setSurface(std::unique_ptr<const SurfUnstructured> &&surface, bool force = false);
202 void setSurface(std::unique_ptr<const SurfUnstructured> &&surface, double featureAngle, bool force = false);
203 void setSurface(const SurfUnstructured *surface, bool force = false);
204 void setSurface(const SurfUnstructured *surface, double featureAngle, bool force = false);
205 void setSurface(const SurfUnstructured *surface, double featureAngle, LevelSetSurfaceSmoothing surfaceSmoothing, bool force = false);
206
207 const SurfaceSkdTree & getSearchTree() const;
208
209 double getFeatureAngle() const;
211
214
215protected:
216 void fillCellLocationCache() override;
217 void fillCellLocationCache(const std::vector<adaption::Info> &adaptionData) override;
219
220 short _evalCellSign(long id) const override;
221 double _evalCellValue(long id, bool signedLevelSet) const override;
222 std::array<double,3> _evalCellGradient(long id, bool signedLevelSet) const override;
223 const SurfUnstructured & _evalCellSurface(long id) const override;
224 long _evalCellSupport(long id, double searchRadius = AUTOMATIC_SEARCH_RADIUS) const override;
225 std::array<double,3> _evalCellNormal(long id, bool signedLevelSet) const override;
226
227 short _evalSign(const std::array<double,3> &point) const override;
228 double _evalValue(const std::array<double,3> &point, bool signedLevelSet) const override;
229 std::array<double,3> _evalGradient(const std::array<double,3> &point, bool signedLevelSet) const override;
230 const SurfUnstructured & _evalSurface(const std::array<double,3> &point) const override;
231 long _evalSupport(const std::array<double,3> &point) const override;
232 long _evalSupport(const std::array<double,3> &point, double searchRadius) const override;
233 void _evalProjection(const std::array<double,3> &point, bool signedLevelSet, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const override;
234
235private:
236 std::unique_ptr<LevelSetSegmentationSurfaceInfo> m_surfaceInfo;
237
238 void fillCartesianCellZoneCache();
239
240 short _evalSign(const std::array<double,3> &point, long support) const;
241 double _evalValue(const std::array<double,3> &point, long support, bool signedLevelSet) const;
242 std::array<double,3> _evalGradient(const std::array<double,3> &point, long support, bool signedLevelSet) const;
243 void _evalProjection(const std::array<double,3> &point, long support, bool signedLevelSet, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const;
244
245};
246
247template<>
249
250public:
252 LevelSetBooleanObject(int, LevelSetBooleanOperation, const std::vector<const LevelSetSegmentationBaseObject *> &);
253
255
256protected:
257 const SurfUnstructured & _evalCellSurface(long id) const override;
258 long _evalCellSupport(long id, double searchRadius = AUTOMATIC_SEARCH_RADIUS) const override;
259 int _evalCellPart(long id) const override;
260 std::array<double,3> _evalCellNormal(long id, bool signedLevelSet) const override;
261
262 const SurfUnstructured & _evalSurface(const std::array<double,3> &point) const override;
263 long _evalSupport(const std::array<double,3> &point) const override;
264 long _evalSupport(const std::array<double,3> &point, double searchRadius) const override;
265 int _evalPart(const std::array<double,3> &point) const override;
266 void _evalProjection(const std::array<double,3> &point, bool signedLevelSet, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const override;
267
268};
269
270template<>
272
273public:
275
277
278protected:
279 const SurfUnstructured & _evalCellSurface(long id) const override;
280 long _evalCellSupport(long id, double searchRadius = AUTOMATIC_SEARCH_RADIUS) const override;
281 int _evalCellPart(long id) const override;
282 std::array<double,3> _evalCellNormal(long id, bool signedLevelSet) const override;
283
284 const SurfUnstructured & _evalSurface(const std::array<double,3> &point) const override;
285 long _evalSupport(const std::array<double,3> &point) const override;
286 long _evalSupport(const std::array<double,3> &point, double searchRadius) const override;
287 int _evalPart(const std::array<double,3> &point) const override;
288 void _evalProjection(const std::array<double,3> &point, bool signedLevelSet, std::array<double, 3> *projectionPoint, std::array<double, 3> *projectionNormal) const override;
289
290};
291
292// Typedefs for compatibility with older versions
294
295}
296
297#endif
Base class which deals with boolean operation between two LevelSetObjects.
Class which deals with boolean operation between two LevelSetObjects.
Base class that allows to evaluate the complement of a LevelSetObjects.
Class that allows to evaluate the complement of a LevelSetObjects.
Interface class for all objects with respect to whom the levelset function may be computed.
void fillFieldCellCache(LevelSetField field, const std::vector< long > &cellIds)
virtual void flushVTKOutputData(std::fstream &stream, VTKFormat format, LevelSetField field) const
virtual std::size_t createFieldCellCache(LevelSetField field, std::size_t cacheId=CellCacheCollection::NULL_CACHE_ID)
Implements visitor pattern fo segmentated geometries.
void evalProjection(const std::array< double, 3 > &point, bool signedLevelSet, std::array< double, 3 > *projectionPoint, std::array< double, 3 > *projectionNormal) const
void fillFieldCellCache(LevelSetField field, long id) override
void flushVTKOutputData(std::fstream &stream, VTKFormat format, LevelSetField field) const override
std::array< double, 3 > evalNormal(const std::array< double, 3 > &point, bool signedLevelSet) const
const SurfUnstructured & evalSurface(const std::array< double, 3 > &point) const
LevelSetFieldset getSupportedFields() const override
std::array< double BITPIT_COMMA 3 > getNormal(long cellId) const
LevelSetIntersectionStatus _intersectSurface(long, double distance, LevelSetIntersectionMode=LevelSetIntersectionMode::FAST_FUZZY) const override
virtual int _evalPart(const std::array< double, 3 > &point) const
void addVTKOutputData(LevelSetField field, const std::string &objectName) override
std::array< double, 3 > evalCellNormal(long id, bool signedLevelSet) const
std::size_t createFieldCellCache(LevelSetField field, std::size_t cacheId=CellCacheCollection::NULL_CACHE_ID) override
int evalPart(const std::array< double, 3 > &point) const
long evalCellSupport(long id, double searchRadius=AUTOMATIC_SEARCH_RADIUS) const
static BITPIT_PUBLIC_API const double AUTOMATIC_SEARCH_RADIUS
long evalSupport(const std::array< double, 3 > &point) const
const SurfUnstructured & evalCellSurface(long id) const
std::string getVTKOutputFieldName(LevelSetField field) const override
Implements visitor pattern fo segmentated geometries.
const SurfUnstructured & _evalSurface(const std::array< double, 3 > &point) const override
LevelSetSegmentationObject * clone() const override
long _evalCellSupport(long id, double searchRadius=AUTOMATIC_SEARCH_RADIUS) const override
LevelSetCellLocation fillCellGeometricNarrowBandLocationCache(long id) override
long _evalSupport(const std::array< double, 3 > &point) const override
short _evalSign(const std::array< double, 3 > &point) const override
std::array< double, 3 > _evalGradient(const std::array< double, 3 > &point, bool signedLevelSet) const override
double _evalCellValue(long id, bool signedLevelSet) const override
std::array< double, 3 > _evalCellGradient(long id, bool signedLevelSet) const override
LevelSetSurfaceSmoothing getSurfaceSmoothing() const
double _evalValue(const std::array< double, 3 > &point, bool signedLevelSet) const override
void setSurface(std::unique_ptr< const SurfUnstructured > &&surface, bool force=false)
const SurfUnstructured & getSurface() const
std::array< double, 3 > _evalCellNormal(long id, bool signedLevelSet) const override
const SurfUnstructured & _evalCellSurface(long id) const override
void _evalProjection(const std::array< double, 3 > &point, bool signedLevelSet, std::array< double, 3 > *projectionPoint, std::array< double, 3 > *projectionNormal) const override
void evalProjection(const std::array< double, 3 > &point, const SegmentConstIterator &segmentItr, std::array< double, 3 > *projectionPoint, std::array< double, 3 > *projectionNormal) const
double evalDistance(const std::array< double, 3 > &point, const SegmentConstIterator &segmentItr, bool signedDistance, std::array< double, 3 > *distanceVector) const
std::array< double, 3 > evalDistanceVector(const std::array< double, 3 > &point, const SegmentConstIterator &segmentItr) const
void setSurface(std::unique_ptr< const SurfUnstructured > &&surface, double featureAngle=DEFAULT_FEATURE_ANGLE)
std::array< double, 3 > evalNormal(const std::array< double, 3 > &point, const SegmentConstIterator &segmentItr) const
static BITPIT_PUBLIC_API const double DEFAULT_FEATURE_ANGLE
LevelSetSurfaceSmoothing getSurfaceSmoothing() const
std::array< double, 3 > evalPseudoNormal(const SurfUnstructured::CellConstIterator &segmentIterator, const double *lambda) const
Iterator for the class PiercedStorage.
Metafunction for generating a pierced storage.
The SurfUnstructured class defines an unstructured surface triangulation.
The SurfaceSkdTree implements a Bounding Volume Hierarchy tree for surface patches.
VTKFormat
Definition VTK.hpp:92
#define BITPIT_DEPRECATED(func)
Definition compiler.hpp:87
--- layout: doxygen_footer ---