std::ostream& OcTreeNodePCL::writeBinary(std::ostream &s) const{ // 2 bits for each children, 8 children per node -> 16 bits std::bitset<8> child1to4; std::bitset<8> child5to8; // 10 : child is free node // 01 : child is occupied node // 00 : child is unkown node // 11 : child has children // speedup: only set bits to 1, rest is init with 0 anyway, // can be one logic expression per bit for (unsigned int i=0; i<4; i++) { if (childExists(i)) { const OcTreeNodePCL* child = this->getChild(i); if (child->hasChildren()) { child1to4[i*2] = 1; child1to4[i*2+1] = 1; } else if (child->isOccupied()) { child1to4[i*2] = 0; child1to4[i*2+1] = 1; } else { child1to4[i*2] = 1; child1to4[i*2+1] = 0; } } else { child1to4[i*2] = 0; child1to4[i*2+1] = 0; } } for (unsigned int i=0; i<4; i++) { if (childExists(i+4)) { const OcTreeNodePCL* child = this->getChild(i+4); if (child->hasChildren()) { child5to8[i*2] = 1; child5to8[i*2+1] = 1; } else if (child->isOccupied()) { child5to8[i*2] = 0; child5to8[i*2+1] = 1; } else { child5to8[i*2] = 1; child5to8[i*2+1] = 0; } } else { child5to8[i*2] = 0; child5to8[i*2+1] = 0; } } // std::cout << "wrote: " // << child1to4.to_string<char,std::char_traits<char>,std::allocator<char> >() << " " // << child5to8.to_string<char,std::char_traits<char>,std::allocator<char> >() << std::endl; char child1to4_char = (char) child1to4.to_ulong(); char child5to8_char = (char) child5to8.to_ulong(); s.write((char*)&child1to4_char, sizeof(char)); s.write((char*)&child5to8_char, sizeof(char)); // write children's children for (unsigned int i=0; i<8; i++) { if (childExists(i)) { const OcTreeNodePCL* child = this->getChild(i); if (child->hasChildren()) { child->writeBinary(s); } } } return s; }
void srs_env_model::EModelTreeNode::setAverageChildColor() { int mr(0), mg(0), mb(0), ma(0); int c(0); for (int i = 0; i < 8; i++) { if (childExists(i) && getChild(i)->isColorSet()) { mr += getChild(i)->r(); mg += getChild(i)->g(); mb += getChild(i)->b(); ma += getChild(i)->a(); ++c; } } if (c) { mr /= c; mg /= c; mb /= c; ma /= c; m_r = mr; m_g = mg; m_b = mb; m_a = ma; setColor((unsigned char) mr, (unsigned char) mg, (unsigned char) mb, (unsigned char) ma); } else { // no child had a color other than white setColor((unsigned char) 255, (unsigned char) 255, (unsigned char) 255, (unsigned char) 255); } }
float OcTreeNode::getMaxChildLogOdds() const{ float max = -std::numeric_limits<float>::max(); for (unsigned int i=0; i<8; i++) { if (childExists(i)) { float l = getChild(i)->getLogOdds(); if (l > max) max = l; } } return max; }
double OcTreeNode::getMeanChildLogOdds() const{ double mean = 0; char c = 0; for (unsigned int i=0; i<8; i++) { if (childExists(i)) { mean += getChild(i)->getOccupancy(); c++; } } if (c) mean /= (double) c; return log(mean/(1-mean)); }
// node implementation -------------------------------------- std::ostream& ColorOcTreeNode::writeValue (std::ostream &s) const { // 1 bit for each children; 0: empty, 1: allocated std::bitset<8> children; for (unsigned int i=0; i<8; i++) { if (childExists(i)) children[i] = 1; else children[i] = 0; } char children_char = (char) children.to_ulong(); // write node data s.write((const char*) &value, sizeof(value)); // occupancy s.write((const char*) &color, sizeof(Color)); // color s.write((char*)&children_char, sizeof(char)); // child existence // write existing children for (unsigned int i=0; i<8; ++i) if (children[i] == 1) this->getChild(i)->writeValue(s); return s; }
ColorOcTreeNode::Color ColorOcTreeNode::getAverageChildColor() const { int mr(0), mg(0), mb(0); int c(0); for (int i=0; i<8; i++) { if (childExists(i) && getChild(i)->isColorSet()) { mr += getChild(i)->getColor().r; mg += getChild(i)->getColor().g; mb += getChild(i)->getColor().b; ++c; } } if (c) { mr /= c; mg /= c; mb /= c; return Color((unsigned char) mr, (unsigned char) mg, (unsigned char) mb); } else { // no child had a color other than white return Color(255, 255, 255); } }
namespace U2 { FindPatternWidgetSavableTab::FindPatternWidgetSavableTab(QWidget *wrappedWidget, MWMDIWindow *contextWindow) : U2SavableWidget(wrappedWidget, contextWindow) { SAFE_POINT(NULL != qobject_cast<FindPatternWidget *>(wrappedWidget), "Invalid widget provided", ); } FindPatternWidgetSavableTab::~FindPatternWidgetSavableTab() { U2WidgetStateStorage::saveWidgetState(*this); widgetStateSaved = true; } void FindPatternWidgetSavableTab::setChildValue(const QString &childId, const QVariant &value) { SAFE_POINT(childExists(childId), "Child widget expected", ); QVariant result = value; if (regionWidgetIds.contains(childId)){ bool ok = false; int intVal = value.toInt(&ok); FindPatternWidget *parentWidget = qobject_cast<FindPatternWidget*>(wrappedWidget); SAFE_POINT(parentWidget != NULL, "Wrong casting", ) int sequenceLength = parentWidget->getTargetSequnceLength(); SAFE_POINT(ok, "Invalid conversion to int", ); CHECK(regionWidgetIds.size() == 2, ); if(intVal > sequenceLength){ if (childId == regionWidgetIds.at(1)) { result = QVariant(sequenceLength); } else { result = QVariant(1); }