45 else if (type == MIXED)
49 else if (type == INSIDE)
53 else if (type == OUTSIDE)
75 scalar
sign = geomNormal & vec;
95 const label minNLevels,
96 const scalar maxLeafRatio,
97 const scalar maxShapeRatio
103 maxLeafRatio_(maxLeafRatio),
104 maxShapeRatio_(maxShapeRatio),
105 minNLevels_(minNLevels),
111 endConstIter_(*
this, -1)
115 setNodes(nNodes() + 1);
117 const label nShapes = shapes_.size();
120 for (label i = 0; i < nShapes; i++)
128 Pout<<
"octree : --- Start of Level " << deepestLevel_
131 topNode_->distribute(0, *
this, shapes_, indices);
136 Pout<<
"octree : --- End of Level " << deepestLevel_
153 label oldNLeaves = -1;
154 label oldNNodes = -1;
158 (deepestLevel_ <= minNLevels_)
160 (nEntries() > maxLeafRatio * nLeaves())
161 && (nEntries() < maxShapeRatio * nShapes)
165 if (deepestLevel_ >= maxNLevels)
169 Pout<<
"octree : exiting since maxNLevels "
170 << maxNLevels <<
" reached" <<
endl;
175 if ((oldNLeaves == nLeaves()) && (oldNNodes == nNodes()))
179 Pout<<
"octree : exiting since nLeaves and nNodes do not change"
186 Pout<<
"octree : --- Start of Level " << deepestLevel_
190 oldNLeaves = nLeaves();
191 oldNNodes = nNodes();
193 topNode_->redistribute
205 Pout<<
"octree : --- End of Level " << deepestLevel_
215 Pout<<
"octree : Constructed octree in = "
221 topNode_->setSubNodeType(0, *
this, shapes_);
225 Pout<<
"octree : Added node information to octree in = "
234 template <
class Type>
243 template <
class Type>
246 return topNode_->getSampleType(0, *
this, shapes_, sample);
250 template <
class Type>
253 return topNode_->find(shapes_, sample);
257 template <
class Type>
264 return topNode_->findTightest
273 template <
class Type>
281 label tightestI = -1;
285 Pout<<
"octree::findNearest : searching for nearest for "
286 <<
"sample:" << sample
287 <<
" tightest:" << tightest <<
endl;
290 topNode_->findNearest
301 Pout<<
"octree::findNearest : found nearest for "
302 <<
"sample:" << sample <<
" with "
303 <<
" tightestI:" << tightestI
304 <<
" tightest:" << tightest
305 <<
" tightestDist:" << tightestDist
313 template <
class Type>
323 label tightestI = -1;
324 linePoint =
point(-GREAT, -GREAT, -GREAT);
325 shapePoint =
point(GREAT, GREAT, GREAT);
327 topNode_->findNearest
341 template <
class Type>
347 topNode_->findBox(shapes_, bb, elements);
349 return elements.
toc();
353 template <
class Type>
356 const point& treeStart,
363 const vector dir(treeEnd - treeStart);
366 point start(treeStart);
395 label index = indices[elemI];
398 bool hit = shapes().intersects(index, start, end, pt);
403 scalar s = (pt - treeStart) & dir;
427 start = leafIntPoint;
434 template <
class Type>
451 const treeLeaf<Type>* leafPtr = findLeafLine(p, end, leafIntPoint);
463 const vector edgeVec(end - p);
469 label index = indices[elemI];
472 bool hit = shapes().intersects
504 template <
class Type>
516 Pout<<
"octree::findLeafLine : searching for shapes on line "
518 <<
" end:" << end <<
endl;
522 if (octreeBb_.contains(start))
524 leafIntPoint = start;
528 if (!octreeBb_.intersects(start, end, leafIntPoint))
532 Pout<<
"octree::findLeafLine : start outside domain but does"
533 <<
" not intersect : start:"
541 Pout<<
"octree::findLeafLine : start propagated to inside"
543 << leafIntPoint <<
endl;
558 Pout<<
"returning from octree::findLeafLine with "
559 <<
"leafIntersection:" << leafIntPoint
560 <<
" leafPtr:" << long(leafPtr) <<
endl;
567 template <
class Type>
574 scalar minx = octreeBb_.min().x();
575 scalar miny = octreeBb_.min().y();
576 scalar minz = octreeBb_.min().z();
578 scalar maxx = octreeBb_.max().x();
579 scalar maxy = octreeBb_.max().y();
580 scalar maxz = octreeBb_.max().z();
582 os <<
"v " << minx <<
" " << miny <<
" " << minz <<
endl;
583 os <<
"v " << maxx <<
" " << miny <<
" " << minz <<
endl;
584 os <<
"v " << maxx <<
" " << maxy <<
" " << minz <<
endl;
585 os <<
"v " << minx <<
" " << maxy <<
" " << minz <<
endl;
587 os <<
"v " << minx <<
" " << miny <<
" " << maxz <<
endl;
588 os <<
"v " << maxx <<
" " << miny <<
" " << maxz <<
endl;
589 os <<
"v " << maxx <<
" " << maxy <<
" " << maxz <<
endl;
590 os <<
"v " << minx <<
" " << maxy <<
" " << maxz <<
endl;
593 os <<
"l " << vertNo + 1 <<
" " << vertNo + 2 <<
endl;
594 os <<
"l " << vertNo + 2 <<
" " << vertNo + 3 <<
endl;
595 os <<
"l " << vertNo + 3 <<
" " << vertNo + 4 <<
endl;
596 os <<
"l " << vertNo + 4 <<
" " << vertNo + 1 <<
endl;
599 os <<
"l " << vertNo + 5 <<
" " << vertNo + 6 <<
endl;
600 os <<
"l " << vertNo + 6 <<
" " << vertNo + 7 <<
endl;
601 os <<
"l " << vertNo + 7 <<
" " << vertNo + 8 <<
endl;
602 os <<
"l " << vertNo + 8 <<
" " << vertNo + 5 <<
endl;
605 os <<
"l " << vertNo + 1 <<
" " << vertNo + 5 <<
endl;
606 os <<
"l " << vertNo + 2 <<
" " << vertNo + 6 <<
endl;
607 os <<
"l " << vertNo + 3 <<
" " << vertNo + 7 <<
endl;
608 os <<
"l " << vertNo + 4 <<
" " << vertNo + 8 <<
endl;
612 topNode_->writeOBJ(os, 1, vertNo);
616 template <
class Type>
619 os <<
"Statistics after iteration " << deepestLevel() <<
':' <<
endl
620 <<
" nShapes :" << shapes().size() <<
endl
621 <<
" nNodes :" << nNodes() <<
endl
622 <<
" nLeaves :" << nLeaves() <<
endl
623 <<
" nEntries :" << nEntries() <<
endl;
625 if (nLeaves() && shapes().size())
628 <<
" Cells per leaf :"
629 << scalar(nEntries())/nLeaves()
631 <<
" Every cell in :"
632 << scalar(nEntries())/shapes().size() <<
" cubes"
641 template <
class Type>
645 curLeaf_(oc.nLeaves())
652 template <
class Type>
660 leaves_.setSize(oc.nLeaves());
663 octree_.topNode()->findLeaves(leaves_, leafIndex);
665 if (leafIndex != oc.nLeaves())
669 "octree::iterator::iterator"
672 <<
"Traversal of tree returns : " << leafIndex <<
endl
673 <<
"Statistics of octree say : " << oc.nLeaves() <<
endl
680 template <
class Type>
683 if ((curLeaf_ < 0) && (iter.curLeaf_ >= 0))
687 "octree::iterator::operator="
690 <<
"lhs : " << curLeaf_ <<
endl
691 <<
"rhs : " << iter.curLeaf_ <<
endl
694 curLeaf_ = iter.curLeaf_;
698 template <
class Type>
702 (curLeaf_ >= 0 ? curLeaf_ : octree_.nLeaves());
704 (iter.curLeaf_ >= 0 ? iter.curLeaf_ : iter.octree_.
nLeaves());
706 return index1 == index2;
710 template <
class Type>
717 template <
class Type>
720 return *leaves_[curLeaf_];
724 template <
class Type>
733 template <
class Type>
743 template <
class Type>
751 template <
class Type>
762 template <
class Type>
766 curLeaf_(oc.nLeaves())
773 template <
class Type>
776 const octree<Type>& oc,
785 leaves_.setSize(oc.nLeaves());
788 octree_.topNode()->findLeaves(leaves_, leafIndex);
790 if (leafIndex != oc.nLeaves())
794 "octree::const_iterator::const_iterator"
797 <<
"Traversal of tree returns : " << leafIndex <<
endl
798 <<
"Statistics of octree say : " << oc.nLeaves() <<
endl
805 template <
class Type>
808 if ((curLeaf_ < 0) && (iter.curLeaf_ >= 0))
812 "octree::const_iterator::operator="
813 "(const const_iterator&)"
815 <<
"lhs : " << curLeaf_ <<
endl
816 <<
"rhs : " << iter.curLeaf_ <<
endl
819 curLeaf_ = iter.curLeaf_;
820 curLeaf_ = iter.curLeaf_;
824 template <
class Type>
831 (curLeaf_ >= 0 ? curLeaf_ : octree_.nLeaves());
833 (iter.curLeaf_ >= 0 ? iter.curLeaf_ : iter.octree_.nLeaves());
835 return index1 == index2;
839 template <
class Type>
840 bool Foam::octree<Type>::const_iterator::operator!=
849 template <
class Type>
852 return *leaves_[curLeaf_];
856 template <
class Type>
865 template <
class Type>
875 template <
class Type>
883 template <
class Type>
891 template <
class Type>
899 template <
class Type>
909 template <
class Type>