Loading...
Searching...
No Matches
levelSet.tpp
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_TPP__
26# define __BITPIT_LEVELSET_TPP__
27
28namespace bitpit{
29
37template<typename LevelSetSourceObject>
38int LevelSet::addObjectComplement( int sourceId, int id ) {
39
40 const LevelSetSourceObject *sourceObject = getObjectPtr<LevelSetSourceObject>(sourceId) ;
41 if (!sourceObject) {
42 throw std::runtime_error("The type of the object does not match the type of the complement object!");
43 }
44
45 auto object = std::unique_ptr<LevelSetObject>(new LevelSetComplementObject<LevelSetSourceObject>(id, sourceObject));
46
47 return registerObject(std::move(object));
48};
49
59template<typename LevelSetSourceObject>
60int LevelSet::addObject( LevelSetBooleanOperation operation, int id1, int id2, int id ) {
61
62 const LevelSetObject *object1 = getObjectPtr<LevelSetSourceObject>(id1) ;
63 if (!object1) {
64 throw std::runtime_error("The type of the object does not match the type of the boolean object!");
65 }
66
67 const LevelSetObject *object2 = getObjectPtr<LevelSetSourceObject>(id2) ;
68 if (!object2) {
69 throw std::runtime_error("The type of the object does not match the type of the boolean object!");
70 }
71
72 auto object = std::unique_ptr<LevelSetObject>(new LevelSetBooleanObject<LevelSetSourceObject>(id, operation, object1, object2));
73
74 return registerObject(std::move(object));
75}
76
85template<typename LevelSetSourceObject>
86int LevelSet::addObject( LevelSetBooleanOperation operation, const std::vector<int> &ids, int id ) {
87
88 std::vector<const LevelSetSourceObject*> objects;
89 for( int id : ids){
90 const LevelSetSourceObject *object = getObjectPtr<LevelSetSourceObject>(id) ;
91 if (!object) {
92 throw std::runtime_error("The type of the object does not match the type of the boolean object!");
93 }
94
95 objects.push_back( object );
96 }
97
98 auto object = std::unique_ptr<LevelSetObject>(new LevelSetBooleanObject<LevelSetSourceObject>(id, operation, objects));
99
100 return registerObject(std::move(object));
101}
102
109template<typename T>
110T & LevelSet::getObject( int id) const{
111 return dynamic_cast<T &>(*m_objects.at(id)) ;
112}
113
120template<typename T>
121T * LevelSet::getObjectPtr( int id) const{
122 return dynamic_cast<T *>(m_objects.at(id).get()) ;
123}
124
129template<typename T>
130std::vector<T *> LevelSet::getObjectPtrs( ) const{
131 std::vector<T *> objects;
132 objects.reserve(m_objects.size());
133 for(const auto &entry : m_objects){
134 T *object = getObjectPtr(entry.first) ;
135 if(object){
136 objects.push_back( object ) ;
137 }
138 }
139
140 return objects;
141}
142
143}
144
145#endif
Class which deals with boolean operation between two 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.
LevelSetObject & getObject(int) const
Definition levelSet.cpp:569
int addObjectComplement(int, int id=levelSetDefaults::OBJECT)
Definition levelSet.tpp:38
LevelSetObject * getObjectPtr(int) const
Definition levelSet.cpp:578
std::vector< LevelSetObject * > getObjectPtrs() const
Definition levelSet.cpp:586
int addObject(LevelSetBooleanOperation, int, int, int id=levelSetDefaults::OBJECT)
Definition levelSet.tpp:60
--- layout: doxygen_footer ---