/* virtual */ void av::osg::Sphere::evaluateLocalSideEffect() { MatrixTransform::evaluateLocalSideEffect(); LOG_TRACE(logger) << "evaluateLocalSideEffect()"; if(mRadiusChanged) { AVANGO_LOG(logger, av::logging::TRACE, boost::str(boost::format("evaluateLocalSideEffect(): got new Radius %1%") % Radius.getValue())); mSphere->setRadius(Radius.getValue()); mShapeDrawable->dirtyDisplayList(); mShapeDrawable->dirtyBound(); mRadiusChanged = false; } if(mDetailRatioChanged) { AVANGO_LOG(logger, av::logging::TRACE, boost::str(boost::format("evaluateLocalSideEffect(): got new DetailRatio %1%") % DetailRatio.getValue())); mHints->setDetailRatio(DetailRatio.getValue()); mShapeDrawable->dirtyDisplayList(); mShapeDrawable->dirtyBound(); mDetailRatioChanged = false; } if(mColorChanged) { AVANGO_LOG(logger, av::logging::TRACE, boost::str(boost::format("evaluateLocalSideEffect(): got new Color %1%") % &Color.getValue())); mShapeDrawable.get()->setColor(Color.getValue()); mColorChanged = false; } }
/* virtual */ void av::gua::NetTransform::setSharedContainersCB(const MFContainer::SetValueEvent& event) { for ( SharedContainerMap::iterator shared_container_iter = mSharedContainerMap.begin(); shared_container_iter != mSharedContainerMap.end(); ++shared_container_iter) { if (!shared_container_iter->second->SharedContainers.isEmpty()) { shared_container_iter->second->SharedContainers.clear(); } } for (MFContainer::ContainerType::const_iterator container_iter = event.getValue().begin(); container_iter != event.getValue().end(); ++container_iter) { Link<FieldContainer> container = *container_iter; AV_ASSERT(container.isValid()); if (container->isDistributed()) { AV_ASSERT(container->netNode() == static_cast<NetNode*>(this)); SharedContainerMap::iterator distributor = mSharedContainerMap.find(container->netCreator()); if (distributor != mSharedContainerMap.end()) { distributor->second->SharedContainers.add1Value(container); } else { AVANGO_LOG(logger, av::logging::WARN, boost::str(boost::format("cannot find field container @0x%1% (created by '%2%') in shared container map") % container.getPtr() % container->netCreator())); container.getPtr(), container->netCreator(); } } else { AVANGO_LOG(logger, av::logging::WARN, " object is not distributed !"); } } }
/* virtual */ void av::osg::Group::getChildrenCB(const av::osg::MFNode::GetValueEvent& event) { av::osg::MFNode::ContainerType &children(*event.getValuePtr()); children.clear(); int num_children = mOsgGroup->getNumChildren(); children.reserve(num_children); for (int ch = 0; ch < num_children; ++ch) { ::osg::Node *osg_child = mOsgGroup->getChild(ch); if (osg_child != 0) { av::osg::Node *node = av::osg::get_from_osg_object<av::osg::Node>(osg_child); if (node != 0) { children.push_back(node); } else { AVANGO_LOG(logger, av::logging::INFO, "getChildrenCB: found user data at a child that doesn't reference an av::osg::Node."); } } else { AVANGO_LOG(logger, av::logging::WARN, "getChildrenCB: null osg child found!"); } } }
/* virtual */ void av::osg::Geode::getDrawablesCB(const av::osg::MFDrawable::GetValueEvent& event) { av::osg::MFDrawable::ContainerType &drawables(*event.getValuePtr()); drawables.clear(); int num_drawables = mOsgGeode->getNumDrawables(); drawables.reserve(num_drawables); for (int d = 0; d < num_drawables; ++d) { ::osg::Drawable *osg_drawable = mOsgGeode->getDrawable(d); if (osg_drawable != 0) { av::osg::Drawable *drawable = av::osg::get_from_osg_object<av::osg::Drawable>(osg_drawable); if (drawable != 0) { drawables.push_back(drawable); } else { AVANGO_LOG(logger, av::logging::INFO, "getDrawablesCB: found user data that doesn't reference an av::osg::Drawable."); } } else { AVANGO_LOG(logger, av::logging::WARN, "getDrawableCB: null osg drawable found!"); } } }
/* virtual */ void av::osg::Group::setChildrenCB(const av::osg::MFNode::SetValueEvent& event) { int num_children = mOsgGroup->getNumChildren(); // Remove (but do not delete) all children that are av::osg::Nodes. // Children of type ::osg::Node are not affected. for (int ch = num_children-1; ch >= 0 ; --ch) { ::osg::Node *osg_child = mOsgGroup->getChild(ch); if (osg_child != 0) { ObjectLink *av_child_link = dynamic_cast<ObjectLink*>(osg_child->getUserData()); if (av_child_link != 0 && av_child_link->getObject() != 0) { mOsgGroup->removeChild(osg_child); } } else { AVANGO_LOG(logger, av::logging::WARN, "setChildrenCB: null osg child found!"); } } // Add new children set const av::osg::MFNode::ContainerType &children(event.getValue()); std::vector<av::Link<av::osg::Node> >::const_iterator ch_it; for (ch_it = children.begin(); ch_it != children.end(); ++ch_it) { if (ch_it->isValid() && ch_it->getPtr()->getOsgNode() != 0) { if (!mOsgGroup->addChild(ch_it->getPtr()->getOsgNode())) AVANGO_LOG(logger, av::logging::WARN, "setChildrenCB: couldn't insert child!"); } else { AVANGO_LOG(logger, av::logging::WARN, "setChildrenCB: invalid child to add found!"); } } }
/* virtual */ void av::osg::Geode::setDrawablesCB(const av::osg::MFDrawable::SetValueEvent& event) { int num_drawables = mOsgGeode->getNumDrawables(); // Remove (but do not delete) all drawables that are av::osg::Drawable. // Drawables of type ::osg::Drawable are not affected. for (int d = num_drawables-1; d >= 0 ; --d) { ::osg::Drawable *osg_drawable = mOsgGeode->getDrawable(d); if (osg_drawable != 0) { ObjectLink *av_drawable_link = dynamic_cast<ObjectLink*>(osg_drawable->getUserData()); if (av_drawable_link != 0 && av_drawable_link->getObject() != 0) { mOsgGeode->removeDrawable(osg_drawable); } } else { AVANGO_LOG(logger, av::logging::WARN, "setDrawableCB: null osg drawable found!"); } } // Add new drawables set const av::osg::MFDrawable::ContainerType &drawables(event.getValue()); std::vector<av::Link<av::osg::Drawable> >::const_iterator d_it; for (d_it = drawables.begin(); d_it != drawables.end(); ++d_it) { if (d_it->isValid() && d_it->getPtr()->getOsgDrawable() != 0) { if (!mOsgGeode->addDrawable(d_it->getPtr()->getOsgDrawable())) AVANGO_LOG(logger, av::logging::WARN, "setDrawableCB: couldn't insert drawable!"); } else { AVANGO_LOG(logger, av::logging::WARN, "setDrawableCB: invalid drawable to add found!"); } } }
/* virtual */ void av::osg::Sphere::fieldHasChangedLocalSideEffect(const av::Field& field) { MatrixTransform::fieldHasChangedLocalSideEffect(field); AVANGO_LOG(logger, av::logging::TRACE, "fieldHasChangedLocalSideEffect()"); if(&field == &Radius) { AVANGO_LOG(logger, av::logging::TRACE, boost::str(boost::format("fieldHadChangedLocalSideEffect(): Radius changed to %1%") % Radius.getValue())); mRadiusChanged = true; } if(&field == &DetailRatio) { AVANGO_LOG(logger, av::logging::TRACE, boost::str(boost::format("fieldHadChangedLocalSideEffect(): DetailRatio changed to %1%") % DetailRatio.getValue())); mDetailRatioChanged = true; } if(&field == &Color) { AVANGO_LOG(logger, av::logging::TRACE, boost::str(boost::format("fieldHadChangedLocalSideEffect(): Color changed to %1%") % &Color.getValue())); mColorChanged = true; } }
void av::osg::TriangleContainer::updateMode() { mModeFieldHasChanged = false; unsigned inMode = Mode.getValue(); // todo: there should be a much more elegant way doing this. think! if(inMode == GL_TRIANGLES || inMode == GL_TRIANGLE_STRIP || inMode == GL_TRIANGLE_FAN || inMode == GL_POINTS || inMode == GL_LINES || inMode == GL_LINE_STRIP || inMode == GL_LINE_LOOP || inMode == GL_QUADS || inMode == GL_QUAD_STRIP || inMode == GL_POLYGON) { Mode.setValue(inMode); update(); } else AVANGO_LOG(logger, av::logging::WARN, "Mode type not supported"); }
/* virtual */ void av::gua::NetTransform::fieldHasChangedLocalSideEffect(const Field& field) { TransformNode::fieldHasChangedLocalSideEffect(field); if (&field == &Groupname) { if (Groupname.getValue().size()) { AVANGO_LOG(logger, av::logging::TRACE, boost::str(boost::format("fpNetDCS::fieldHasChangedLocalSideEffect: joining net-group '%1%'.") % Groupname.getValue().c_str())); // if the groupname is not empty try to join join(Groupname.getValue()); // Name.setValue(Groupname.getValue()); } else { // get the hell out of here leave(); } } }
/* virtual */ void av::gua::NetTransform::_join(const std::string& fragment) { NetID group_id(fragment, NetID::sNetGroupRootNode); registerWellKnown(this, group_id); mGroupMap.insert(fragment); // register SharedContainerHolder Link<SharedContainerHolder> container_holder = new SharedContainerHolder; NetID container_holder_id(fragment, NetID::sNetGroupContainerHolder); registerWellKnown(container_holder.getPtr(), container_holder_id); mSharedContainerMap[fragment] = container_holder; sharedContainersChanged(); #ifdef AVANGO_DEBUG AVANGO_LOG(logger, logging::TRACE, boost::str(boost::format("_join: added group node %1% for: %2%]") % group_id % fragment)); #endif }
void av::osg::TriangleContainer::updateVertexBuffer() { unsigned int numEle = Vertices.getValue().size(); // check if we have enough points for a triangle if(numEle < 3) { AVANGO_LOG(logger, av::logging::WARN, "Not enough points to create triangle"); return; } ::osg::ref_ptr<::osg::Vec3Array> vertexBuffer = new ::osg::Vec3Array(numEle); MFVec3::ContainerType::const_iterator it = Vertices.getValue().begin(); unsigned int count = 0; for(; it != Vertices.getValue().end(); ++it) { (*vertexBuffer)[count] = (*it); // std::cout << "#: " << count << ' ' << (*it).x() << ' ' << (*it).y() << ' ' << (*it).z() << std::endl; count++; } mTriangleCount = count / 3; getOsgGeometry()->setVertexArray(vertexBuffer.get()); if(getOsgGeometry()->getNumPrimitiveSets()) // first geometry? getOsgGeometry()->setPrimitiveSet(0, new ::osg::DrawArrays(Mode.getValue(), 0, numEle)); else getOsgGeometry()->addPrimitiveSet(new ::osg::DrawArrays(Mode.getValue(), 0, numEle)); ::osg::StateSet* state_set = getOsgGeometry()->getOrCreateStateSet(); ::osg::Point* osg_point = new ::osg::Point(); osg_point->setSize(PointSize.getValue()); state_set->setAttribute(osg_point); mVecFieldHasChanged = false; }