39 #ifndef OPENVDB_TOOLS_SIGNEDFLOODFILL_HAS_BEEN_INCLUDED 40 #define OPENVDB_TOOLS_SIGNEDFLOODFILL_HAS_BEEN_INCLUDED 42 #include <boost/utility/enable_if.hpp> 45 #include <boost/static_assert.hpp> 46 #include <boost/type_traits/is_floating_point.hpp> 47 #include <boost/type_traits/is_signed.hpp> 72 template<
typename TreeOrLeafManagerT>
75 size_t grainSize = 1,
Index minLevel = 0);
96 template<
typename TreeOrLeafManagerT>
99 TreeOrLeafManagerT& tree,
100 const typename TreeOrLeafManagerT::ValueType& outsideWidth,
101 const typename TreeOrLeafManagerT::ValueType& insideWidth,
102 bool threaded =
true,
103 size_t grainSize = 1,
110 template<
typename TreeOrLeafManagerT>
114 typedef typename TreeOrLeafManagerT::ValueType
ValueT;
115 typedef typename TreeOrLeafManagerT::RootNodeType
RootT;
116 typedef typename TreeOrLeafManagerT::LeafNodeType
LeafT;
117 BOOST_STATIC_ASSERT(boost::is_floating_point<ValueT>::value || boost::is_signed<ValueT>::value);
120 : mOutside(ValueT(math::
Abs(tree.background())))
121 , mInside(ValueT(math::
negative(mOutside)))
122 , mMinLevel(minLevel)
127 : mOutside(ValueT(math::
Abs(outsideValue)))
128 , mInside(ValueT(math::
negative(math::
Abs(insideValue))))
129 , mMinLevel(minLevel)
136 if (LeafT::LEVEL < mMinLevel)
return;
138 #ifndef OPENVDB_2_ABI_COMPATIBLE 139 if (!leaf.allocate())
return;
141 const typename LeafT::NodeMaskType& valueMask = leaf.getValueMask();
143 typename LeafT::ValueType* buffer =
144 const_cast<typename LeafT::ValueType*
>(&(leaf.getFirstValue()));
146 const Index first = valueMask.findFirstOn();
147 if (first < LeafT::SIZE) {
148 bool xInside = buffer[first]<0, yInside = xInside, zInside = xInside;
149 for (
Index x = 0; x != (1 << LeafT::LOG2DIM); ++x) {
150 const Index x00 = x << (2 * LeafT::LOG2DIM);
151 if (valueMask.isOn(x00)) xInside = buffer[x00] < 0;
153 for (
Index y = 0; y != (1 << LeafT::LOG2DIM); ++y) {
154 const Index xy0 = x00 + (y << LeafT::LOG2DIM);
155 if (valueMask.isOn(xy0)) yInside = buffer[xy0] < 0;
157 for (
Index z = 0; z != (1 << LeafT::LOG2DIM); ++z) {
158 const Index xyz = xy0 + z;
159 if (valueMask.isOn(xyz)) {
160 zInside = buffer[xyz] < 0;
162 buffer[xyz] = zInside ? mInside : mOutside;
168 leaf.fill(buffer[0] < 0 ? mInside : mOutside);
173 template<
typename NodeT>
176 if (NodeT::LEVEL < mMinLevel)
return;
178 const typename NodeT::NodeMaskType& childMask = node.getChildMask();
180 typename NodeT::UnionType* table =
const_cast<typename NodeT::UnionType*
>(node.getTable());
182 const Index first = childMask.findFirstOn();
183 if (first < NodeT::NUM_VALUES) {
184 bool xInside = table[first].getChild()->getFirstValue()<0;
185 bool yInside = xInside, zInside = xInside;
186 for (
Index x = 0; x != (1 << NodeT::LOG2DIM); ++x) {
187 const int x00 = x << (2 * NodeT::LOG2DIM);
188 if (childMask.isOn(x00)) xInside = table[x00].getChild()->getLastValue()<0;
190 for (
Index y = 0; y != (1 << NodeT::LOG2DIM); ++y) {
191 const Index xy0 = x00 + (y << NodeT::LOG2DIM);
192 if (childMask.isOn(xy0)) yInside = table[xy0].getChild()->getLastValue()<0;
194 for (
Index z = 0; z != (1 << NodeT::LOG2DIM); ++z) {
195 const Index xyz = xy0 + z;
196 if (childMask.isOn(xyz)) {
197 zInside = table[xyz].getChild()->getLastValue()<0;
199 table[xyz].setValue(zInside ? mInside : mOutside);
205 const ValueT v = table[0].getValue()<0 ? mInside : mOutside;
206 for (
Index i = 0; i < NodeT::NUM_VALUES; ++i) table[i].setValue(v);
213 if (RootT::LEVEL < mMinLevel)
return;
214 typedef typename RootT::ChildNodeType ChildT;
216 std::map<Coord, ChildT*> nodeKeys;
217 typename RootT::ChildOnIter it = root.beginChildOn();
218 for (; it; ++it) nodeKeys.insert(std::pair<Coord, ChildT*>(it.getCoord(), &(*it)));
219 static const Index DIM = RootT::ChildNodeType::DIM;
223 typename std::map<Coord, ChildT*>::const_iterator b = nodeKeys.begin(), e = nodeKeys.end();
224 if ( b == e )
return;
225 for (
typename std::map<Coord, ChildT*>::const_iterator a = b++; b != e; ++a, ++b) {
226 Coord d = b->first - a->first;
227 if (d[0]!=0 || d[1]!=0 || d[2]==
Int32(DIM))
continue;
228 const ValueT fill[] = { a->second->getLastValue(), b->second->getFirstValue() };
229 if (!(fill[0] < 0) || !(fill[1] < 0))
continue;
231 for (; c[2] != b->first[2]; c[2] += DIM) root.addTile(c, mInside,
false);
233 root.setBackground(mOutside,
false);
237 const ValueT mOutside, mInside;
238 const Index mMinLevel;
242 template<
typename TreeOrLeafManagerT>
244 typename boost::enable_if_c<
245 boost::is_floating_point<typename TreeOrLeafManagerT::ValueType>::value ||
246 boost::is_signed<typename TreeOrLeafManagerT::ValueType>::value,
void>::type
248 typename TreeOrLeafManagerT::ValueType outsideValue,
249 typename TreeOrLeafManagerT::ValueType insideValue,
260 template <
typename TreeOrLeafManagerT>
262 typename boost::disable_if_c<
263 boost::is_floating_point<typename TreeOrLeafManagerT::ValueType>::value ||
264 boost::is_signed<typename TreeOrLeafManagerT::ValueType>::value,
void>::type
266 const typename TreeOrLeafManagerT::ValueType&,
267 const typename TreeOrLeafManagerT::ValueType&,
273 "signedFloodFill is supported only for signed value grids");
278 template <
typename TreeOrLeafManagerT>
281 TreeOrLeafManagerT& tree,
282 const typename TreeOrLeafManagerT::ValueType& outsideValue,
283 const typename TreeOrLeafManagerT::ValueType& insideValue,
288 doSignedFloodFill(tree, outsideValue, insideValue, threaded, grainSize, minLevel);
292 template <
typename TreeOrLeafManagerT>
299 const typename TreeOrLeafManagerT::ValueType v = tree.root().background();
307 #endif // OPENVDB_TOOLS_RESETBACKGROUND_HAS_BEEN_INCLUDED
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Coord Abs(const Coord &xyz)
Definition: Coord.h:254
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
void foreachBottomUp(const NodeOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that applies a user-supplied functor to all the nodes in the tree.
Definition: NodeManager.h:492
NodeManager produces linear arrays of all tree nodes allowing for efficient threading and bottom-up p...
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:48
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Exceptions.h:91
Definition: Exceptions.h:39
To facilitate threading over the nodes of a tree, cache node pointers in linear arrays, one for each level of the tree.
Definition: NodeManager.h:57
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
int32_t Int32
Definition: Types.h:59
Index32 Index
Definition: Types.h:57