46 subNodeTypes_ |= (0x1 << octant);
53 subNodeTypes_ &= ~(0x1 << octant);
62 treeElem<Type>* treeNodePtr
66 subNodes_[octant] = treeNodePtr;
75 treeElem<Type>* treeLeafPtr
79 subNodes_[octant] = treeLeafPtr;
90 if ((type < 0) || (type > 3))
92 FatalErrorIn(
"treeNode<Type>::setVolType(const label, const label)")
93 <<
"Type " << type <<
" not within range 0..3" <<
endl;
97 volType_ &= ~(0x3 << 2*octant);
100 volType_ |= (type << 2*octant);
104 template <
class Type>
107 for (label i=0; i<n; i++)
115 template <
class Type>
126 static const char* functionName =
127 "treeNode<Type>::findLeafLineOctant"
128 "(const int, const Type&, const label, const vector&,"
129 " point&, const point&)";
133 space(
Pout, 2*level);
134 Pout<<
"findLeafLineOctant : bb:" << this->bb()
135 <<
" start:" << start
137 <<
" mid:" << midpoint()
138 <<
" Searching octant:" << octant
142 if (subNodes()[octant])
147 const treeNode<Type>* subNodePtr = getNodePtr(octant);
149 if (subNodePtr->bb().contains(direction, start))
152 const treeLeaf<Type>* subLeafPtr = subNodePtr->findLeafLine
162 space(
Pout, 2*level);
163 Pout<<
"findLeafLineOctant : bb:" << this->bb()
164 <<
" returning from sub treeNode"
165 <<
" with start:" << start <<
" subLeaf:"
166 << long(subLeafPtr) <<
endl;
174 <<
"Sub node " << subNodePtr->bb()
175 <<
" at octant " << octant
176 <<
" does not contain start " << start
183 const treeLeaf<Type>* subLeafPtr = getLeafPtr(octant);
185 if (subLeafPtr->bb().contains(direction, start))
191 !subLeafPtr->bb().intersects
200 <<
"Sub leaf contains start " << start
201 <<
" but line does not intersect its bb "
209 space(
Pout, 2*level);
210 Pout<<
"findLeafLineOctant : returning from intersecting"
211 <<
" treeLeaf " << subLeafPtr->bb()
212 <<
" with start:" << start <<
" subLeaf:"
213 << long(subLeafPtr) <<
endl;
221 <<
"Sub leaf " << subLeafPtr->bb()
222 <<
" at octant " << octant
223 <<
" does not contain start " << start
231 const treeBoundBox emptyBb = this->bb().subBbox(midpoint(), octant);
233 if (emptyBb.contains(direction, start))
237 space(
Pout, 2*level);
238 Pout<<
"findLeafLineOctant : Empty node. Octant:" << octant
239 <<
" start:" << start
240 <<
" bb:" << this->bb()
241 <<
" emptyBb:" << emptyBb <<
endl;
257 <<
"Empty node contains start " << start
258 <<
" but line does not intersect its (calculated)"
260 <<
endl <<
"This might be due to truncation error"
267 space(
Pout, 2*level);
268 Pout<<
"findLeafLineOctant : returning from intersecting with"
269 <<
" empty " << emptyBb
270 <<
" with start:" << start <<
" subLeaf:" << 0 <<
endl;
278 <<
"Empty node " << emptyBb
279 <<
" at octant " << octant
280 <<
" does not contain start " << start
286 <<
"Octant " << octant <<
" of cube " << this->bb()
287 <<
" does not contain start " << start
297 template <
class Type>
306 for (label octantI=0; octantI<8; octantI++)
308 subNodes_[octantI] = NULL;
315 template <
class Type>
324 template <
class Type>
327 for (
int octant=0; octant<8; octant++)
329 if (subNodes()[octant])
333 delete getNodePtr(octant);
337 delete getLeafPtr(octant);
347 template <
class Type>
359 Pout<<
"treeNode::distributing " << indices.
size() <<
endl;
363 for (label octant=0; octant<8; octant++)
365 if (subNodes()[octant])
367 printNode(
Pout, level);
370 "treeNode<Type>::distribute(const label, octree<Type>&, "
371 "const Type&, const labelList&)"
372 ) <<
"subNode already available at octant:" << octant
379 this->bb().subBbox(midpoint(), octant),
384 setLeafPtr(octant, subLeafPtr);
392 const label shapei = indices[i];
394 for (label octant=0; octant<8; octant++)
398 if (shapes.overlaps(shapei, leafPtr->
bb()))
403 Pout<<
"inserting " << shapei;
414 for (label octant=0; octant<8; octant++)
418 if (subLeafPtr->
size() == 0)
421 setLeafPtr(octant, NULL);
435 Pout<<
"end of treeNode::distribute" <<
endl;
441 template <
class Type>
447 const label refineLevel
453 Pout<<
"treeNode::redistribute with level:" << level
454 <<
" refineLevel:" << refineLevel <<
endl;
458 if (level < refineLevel)
460 for (label octant=0; octant<8; octant++)
462 if (subNodes()[octant])
466 getNodePtr(octant)->redistribute
483 Pout<<
"treeNode::redistribute : now at correct level" <<
endl;
487 for (label octant=0; octant<8; octant++)
489 if (subNodes()[octant])
495 "treeNode<Type>::redistribute(const int, octree& top,"
496 "const int, const treeBoundBox&)"
497 ) <<
"found treeNode instead of treeLeaf" <<
endl
511 if (newSubPtr && (newSubPtr != leafPtr))
519 <<
" entries" <<
endl;
527 setNodePtr(octant, newSubPtr);
535 Pout<<
"end of treeNode::redistribute for correct level" <<
endl;
542 Pout<<
"return from treeNode::redistribute with bb:" << this->bb()
549 template <
class Type>
560 Pout<<
"treeNode::setSubNodeType with level:" << level
561 <<
" bb:" << this->bb() <<
endl;
566 for (label octant=0; octant<8; octant++)
570 if (subNodes()[octant])
574 subType = getNodePtr(octant)->setSubNodeType
583 subType = getLeafPtr(octant)->setSubNodeType
597 subType = shapes.getSampleType(top, subBb.
midpoint());
603 Pout<<
"treeNode::setSubNodeType : setting octant with bb:"
604 << this->bb().subBbox(midpoint(), octant)
607 setVolType(octant, subType);
615 else if (subType != myType)
624 Pout<<
"return from treeNode::setSubNodeType with type:"
626 <<
" bb:" << this->bb() <<
endl;
634 template <
class Type>
646 Pout<<
"treeNode::getSampleType with level:" << level
647 <<
" bb:" << this->bb() <<
" sample:" << sample <<
endl;
653 label octant = this->bb().subOctant(midpoint(), sample, onEdge);
655 label type = getVolType(octant);
660 if (subNodes()[octant])
665 type = getNodePtr(octant)->getSampleType
676 type = getLeafPtr(octant)->getSampleType
690 "treeNode<Type>::getSampleType"
691 "(const label, octree<Type>&, const Type&, const point&)"
692 ) <<
"Empty node bb:" << this->bb().subBbox(midpoint(), octant)
693 <<
" has non-mixed type:"
703 "treeNode<Type>::getSampleType"
704 "(const label, octree<Type>&, const Type&, const point&)"
705 ) <<
"Type is MIXED when searching for " << sample
706 <<
" at level " << this->bb() <<
endl
707 <<
"This probably is because the octree has not been constructed"
714 Pout<<
"return from treeNode::getSampleType with type:"
716 <<
" bb:" << this->bb()
717 <<
" sample:" << sample <<
endl;
723 template <
class Type>
734 label octant = this->bb().subOctant(midpoint(), sample, onEdge);
736 if (subNodes()[octant])
741 return getNodePtr(octant)->
find(shapes, sample);
746 return getLeafPtr(octant)->find(shapes, sample);
753 template <
class Type>
761 bool changed =
false;
764 label sampleOctant = this->bb().subOctant(midpoint(), sample, onEdge);
769 for (label octantI=0; octantI<8; octantI++)
775 octant = sampleOctant;
777 else if (octantI == sampleOctant)
786 if (subNodes()[octant])
827 template <
class Type>
839 Pout<<
"In findNearest with sample:" << sample <<
" cube:"
840 << this->bb() <<
" tightest:" << tightest <<
endl;
843 bool changed =
false;
846 label sampleOctant = this->bb().subOctant(midpoint(), sample, onEdge);
851 for (label octantI=0; octantI<8; octantI++)
857 octant = sampleOctant;
859 else if (octantI == sampleOctant)
868 if (subNodes()[octant])
911 Pout<<
"Exiting findNearest for sample:" << sample <<
" cube:"
912 << this->bb() <<
" tightestI:" << tightestI <<
endl;
919 template <
class Type>
930 bool changed =
false;
933 label sampleOctant = this->bb().subOctant(midpoint(), ln.
centre(), onEdge);
938 for (label octantI=0; octantI<8; octantI++)
944 octant = sampleOctant;
946 else if (octantI == sampleOctant)
955 if (subNodes()[octant])
1002 template <
class Type>
1010 bool changed =
false;
1011 bool onEdge =
false;
1013 label sampleOctant = this->bb().subOctant
1023 for (label octantI=0; octantI<8; octantI++)
1029 octant = sampleOctant;
1031 else if (octantI == sampleOctant)
1040 if (subNodes()[octant])
1050 changed |= subNodePtr->
findBox(shapes, box, elements);
1061 changed |= subLeafPtr->
findBox(shapes, box, elements);
1072 template <
class Type>
1083 space(
Pout, 2*level);
1084 Pout<<
"findLeafLine : bb:" << this->bb() <<
" mid:" << midpoint()
1085 <<
" start:" << start <<
endl;
1088 scalar typDim = this->bb().avgDim();
1090 const vector direction = end - start;
1100 if (!this->bb().contains(direction, start))
1104 space(
Pout, 2*level);
1105 Pout<<
"findLeafLine : Start not inside bb " << this->bb()
1106 <<
". Returning with start:" << start <<
" subLeaf:"
1113 if ((
mag(start - end)/typDim) < SMALL)
1117 space(
Pout, 2*level);
1118 Pout<<
"findLeafLine : start equals end"
1119 <<
". Returning with start:" << start <<
" subLeaf:"
1131 bool onEdge =
false;
1132 label octant = this->bb().subOctant
1134 midpoint(), direction, start, onEdge
1153 space(
Pout, 2*level);
1154 Pout<<
"findLeafLine : Found treeLeaf"
1155 <<
". Returning with start:" << start <<
" subLeaf:"
1156 << long(leafPtr) <<
endl;
1168 "treeNode<Type>::findLeafLine"
1169 "(const label, octree<Type>&, point&,"
1171 ) <<
"Did not leave bb " << this->bb()
1172 <<
" after " << iter
1173 <<
" iterations of updating starting point."
1174 <<
"start:" << start <<
" end:" << end
1181 template <
class Type>
1189 for (label octant=0; octant<8; octant++)
1191 if (subNodes()[octant])
1197 subNodePtr->
findLeaves(leafArray, leafIndex);
1203 leafArray[leafIndex++] = subLeafPtr;
1210 template <
class Type>
1218 for (label octant=0; octant<8; octant++)
1220 if (subNodes()[octant])
1226 subNodePtr->
findLeaves(leafArray, leafIndex);
1232 leafArray[leafIndex++] = subLeafPtr;
1239 template <
class Type>
1248 os <<
"node:" << this->bb() <<
endl;
1250 for (label octant=0; octant<8; octant++)
1252 label type = getVolType(octant);
1256 if (!subNodes_[octant])
1259 os << octant <<
":" << typeString <<
" : null" <<
endl;
1261 else if (isNode(octant))
1264 os << octant <<
":" << typeString <<
" : node" <<
endl;
1265 getNodePtr(octant)->printNode(os, level+1);
1270 os << octant <<
":" << typeString <<
" : leaf" <<
endl;
1279 template <
class Type>
1289 label midVertNo = vertNo;
1290 os <<
"v " << midPoint.
x() <<
" " << midPoint.
y() <<
" "
1291 << midPoint.
z() <<
endl;
1294 for (label octant=0; octant<8; octant++)
1296 if (subNodes_[octant])
1303 os <<
"v " << subMidPoint.x() <<
" " << subMidPoint.y() <<
" "
1304 << subMidPoint.z() <<
endl;
1305 os <<
"l " << midVertNo + 1<<
" " << vertNo + 1 <<
endl;
1308 nodePtr->
writeOBJ(os, level+1, vertNo);
1315 os <<
"v " << subMidPoint.x() <<
" " << subMidPoint.y() <<
" "
1316 << subMidPoint.z() <<
endl;
1317 os <<
"l " << midVertNo + 1<<
" " << vertNo + 1 <<
endl;
1329 template <
class Type>
1332 for (label octant = 0; octant < 8; octant++)
1334 oc.subNodes_[octant] = NULL;
1345 for (label octant = 0; octant < nPtrs; octant++)
1366 is.
check(
"Istream& operator>>(Istream&, treeNode&)");
1372 template <
class Type>
1379 for (label octant = 0; octant < 8; octant++)
1381 if (tn.subNodes_[octant])
1383 if (tn.isNode(octant) || tn.getLeafPtr(octant)->indices().size())
1395 for (label octant = 0; octant < 8; octant++)
1397 if (tn.subNodes_[octant])
1399 if (tn.isNode(octant))
1407 else if (tn.getLeafPtr(octant)->indices().size())
1412 os << token::SPACE << octant + treeNode<Type>::leafOffset