25# include "bitpit_operators.hpp"
26# include "bitpit_patchkernel.hpp"
27# include "bitpit_surfunstructured.hpp"
28# include "bitpit_volcartesian.hpp"
29# include "bitpit_voloctree.hpp"
30# include "bitpit_volunstructured.hpp"
32# include "levelSetCommon.hpp"
33# include "levelSetKernel.hpp"
34# include "levelSetCartesianKernel.hpp"
35# include "levelSetComplementObject.hpp"
36# include "levelSetOctreeKernel.hpp"
37# include "levelSetObject.hpp"
38# include "levelSetProxyObject.hpp"
39# include "levelSetBooleanObject.hpp"
40# include "levelSetSegmentationObject.hpp"
41# include "levelSetMaskObject.hpp"
42# include "levelSetUnstructuredKernel.hpp"
44# include "levelSet.hpp"
85 m_expectedFillIn = expectedFillIn ;
89 m_signedDistance = true ;
91 m_forceSignPropagation =
false;
92 m_signPropagationEnabled =
false;
115 assert(m_kernel &&
"LevelSet::setMesh() must be called prior to LevelSet::update()");
118 bool updated = m_kernel->update( adaptionData ) ;
124 for(
int id : m_orderedObjectsIds){
126 object->update( adaptionData ) ;
146 return m_narrowBandSize;
166 m_narrowBandSize = std::max(size, 0.);
169 for (
auto &objectEntry : m_objects) {
187 throw std::runtime_error (
"Mesh can be set just once.");
194 m_kernel = std::unique_ptr<LevelSetKernel>(
new LevelSetOctreeKernel(*octree, m_expectedFillIn));
198 throw std::runtime_error (
"Unable to create the levelset kernel. Mesh type non supported.");
202 for(
int id : m_orderedObjectsIds){
204 object->setKernel(m_kernel.get());
221 return registerObject(std::move(
object));
236 return registerObject(std::move(
object));
252 return registerObject(std::move(
object));
265 auto surfUnstructured = std::unique_ptr<SurfUnstructured>(
dynamic_cast<SurfUnstructured *
>(segmentation.release())) ;
266 if (!surfUnstructured) {
267 throw std::runtime_error (
"Segmentation type not supported");
272 return registerObject(std::move(
object));
286 if (!surfUnstructured) {
287 throw std::runtime_error (
"Segmentation type not supported");
292 return registerObject(std::move(
object));
307 if (!surfUnstructured) {
308 throw std::runtime_error (
"Segmentation type not supported");
313 return registerObject(std::move(
object));
325 assert(m_kernel &&
" levelset: setMesh must be called before adding a mask object ");
327 auto object = std::unique_ptr<LevelSetObject>(
new LevelSetMaskObject(
id, list, *m_kernel->getMesh()));
329 return registerObject(std::move(
object));
343 assert(m_kernel &&
" levelset: setMesh must be called before adding a mask object ");
345 auto object = std::unique_ptr<LevelSetObject>(
new LevelSetMaskObject(
id, list, refInterface, invert, *m_kernel->getMesh()));
347 return registerObject(std::move(
object));
358 return registerObject(std::move(
object));
366int LevelSet::registerObject( std::unique_ptr<LevelSetObject> &&
object ) {
369 int id =
object->getId();
371 id = m_objectIdentifierGenerator.
generate();
378 object->setDefaultLevelSetSigndness(m_signedDistance);
379 object->setNarrowBandSize(m_narrowBandSize);
380 if (m_forceSignPropagation) {
381 if (m_signPropagationEnabled) {
390 object->setKernel(m_kernel.get());
394 m_objects[id] = std::move(
object) ;
395 registerObjectId(
id);
396 incrementObjectsReferenceCount(
id);
405 m_orderedObjectsIds.clear();
406 m_objectIdentifierGenerator.
reset();
417 return unregisterObject(
id,
false);
430bool LevelSet::unregisterObject(
int id,
bool force) {
435 decrementObjectsReferenceCount(
id);
436 unregisterObjectId(
id);
437 m_objectIdentifierGenerator.
trash(
id);
452 auto objectItr = m_objects.find(
id) ;
453 if( objectItr == m_objects.end() ){
478void LevelSet::registerObjectId(
int id ) {
486 std::vector<int>::iterator idItr;
488 std::vector<int>::iterator orderedIdsBegin = m_orderedObjectsIds.begin();
489 std::vector<int>::iterator orderedIdsEnd = m_orderedObjectsIds.end();
491 for (idItr = orderedIdsBegin; idItr != orderedIdsEnd; ++idItr) {
492 int candidateId = *idItr ;
499 idItr = m_orderedObjectsIds.end();
502 m_orderedObjectsIds.insert(idItr,
id) ;
513void LevelSet::unregisterObjectId(
int id){
516 std::vector<int>::iterator orderedIdsBegin = m_orderedObjectsIds.begin();
517 std::vector<int>::iterator orderedIdsEnd = m_orderedObjectsIds.end();
519 std::vector<int>::iterator idItr = std::find(orderedIdsBegin, orderedIdsEnd,
id);
520 assert(idItr != orderedIdsEnd);
521 m_orderedObjectsIds.erase(idItr);
529void LevelSet::incrementObjectsReferenceCount(
int parentId) {
531 const LevelSetObject *parentObject =
getObjectPtr(parentId);
532 if( parentObject->isPrimary() ){
536 if(
const LevelSetProxyBaseObject *parentProxyObject =
dynamic_cast<const LevelSetProxyBaseObject *
>(parentObject) ){
537 for (
int sourceObjectId : parentProxyObject->getSourceObjectIds() ){
538 getObjectPtr(sourceObjectId)->incrementReferenceCount();
548void LevelSet::decrementObjectsReferenceCount(
int parentId) {
550 const LevelSetObject *parentObject =
getObjectPtr(parentId);
551 if( parentObject->isPrimary() ){
555 if(
const LevelSetProxyBaseObject *parentProxyObject =
dynamic_cast<const LevelSetProxyBaseObject *
>(parentObject) ){
556 for (
int sourceObjectId : parentProxyObject->getSourceObjectIds() ){
557 getObjectPtr(sourceObjectId)->decrementReferenceCount();
570 return getObject<LevelSetObject>(
id);
579 return getObjectPtr<LevelSetObject>(
id);
587 return getObjectPtrs<LevelSetObject>();
595 return m_objects.size() ;
603 std::vector<int> ids ;
604 ids.reserve(m_objects.size()) ;
605 for(
const auto &entry : m_objects) {
606 ids.push_back(entry.first) ;
624 m_objectIdentifierGenerator.
dump(stream);
625 for(
const auto &
object : m_objects ){
626 object.second->dump( stream ) ;
644 m_objectIdentifierGenerator.
restore(stream);
645 for(
const auto &
object : m_objects ){
646 object.second->restore( stream ) ;
657 m_signedDistance = flag;
675 m_forceSignPropagation =
true;
676 m_signPropagationEnabled = flag;
679 for (
auto &objectEntry : m_objects) {
681 if (m_forceSignPropagation) {
682 if (m_signPropagationEnabled) {
706double LevelSet::getSizeNarrowBand()
const{
725void LevelSet::setSizeNarrowBand(
double size){
734void LevelSet::compute(){
747void LevelSet::compute(
int id ){
762void LevelSet::compute(
const std::vector<int> &ids ){
780void LevelSet::update(
const std::vector<adaption::Info> &adaptionData,
int id){
784 log::warning() <<
" It is not possible to update the levelset for a specific objects." << std::endl;
785 log::warning() <<
" Levelset will be computed for all the objects." << std::endl;
801void LevelSet::update(
const std::vector<adaption::Info> &adaptionData,
const std::vector<int> &ids ){
805 log::warning() <<
" It is not possible to update the levelset for a specific objects." << std::endl;
806 log::warning() <<
" Levelset will be computed for all the objects." << std::endl;
void setAssigned(id_type id)
void restore(std::istream &stream)
void dump(std::ostream &stream) const
Implements LevelSetKernel for cartesian meshes.
Implements the levelset around a set of cells or interfaces of the kernel.
Interface class for all objects with respect to whom the levelset function may be computed.
void setCellBulkEvaluationMode(LevelSetBulkEvaluationMode evaluationMode)
virtual bool isPrimary() const
void setNarrowBandSize(double size)
std::size_t getReferenceCount() const
Implements LevelSetKernel for octree meshes.
Implements visitor pattern fo segmentated geometries.
Implements LevelSetKernel for unstructured meshes.
LevelSetObject & getObject(int) const
void setNarrowBandSize(double size=0)
void setPropagateSign(bool)
int getObjectCount() const
void restore(std::istream &)
LevelSetObject * getObjectPtr(int) const
void setMesh(VolumeKernel *mesh)
std::vector< LevelSetObject * > getObjectPtrs() const
std::vector< int > getObjectIds() const
void update(const std::vector< adaption::Info > &adaptionData)
void dump(std::ostream &) const
double getNarrowBandSize() const
LevelSet(LevelSetFillIn expectedFillIn=LevelSetFillIn::SPARSE)
void partition(const std::vector< adaption::Info > &)
int addObject(LevelSetBooleanOperation, int, int, int id=levelSetDefaults::OBJECT)
bool isObjectRemovable(int)
The SurfUnstructured class defines an unstructured surface triangulation.
The SurfaceKernel class provides an interface for defining surface patches.
The VolCartesian defines a Cartesian patch.
The VolOctree defines a Octree patch.
The VolUnstructured class defines a dummy unstructured volume patch.
The VolumeKernel class provides an interface for defining volume patches.
void write(std::ostream &stream, const std::vector< bool > &container)
void read(std::istream &stream, std::vector< bool > &container)
#define BITPIT_UNUSED(variable)
@ SIGN_PROPAGATION
Sign is propagated from the narrow band, no other data will be evaluated.
@ NONE
No data is evaluated.
Logger & warning(log::Visibility defaultVisibility)