本文整理汇总了C++中node::SPtr类的典型用法代码示例。如果您正苦于以下问题:C++ SPtr类的具体用法?C++ SPtr怎么用?C++ SPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkDeprecatedAttribute
void checkDeprecatedAttribute()
{
EXPECT_MSG_EMIT(Deprecated) ;
std::stringstream scene ;
scene << "<?xml version='1.0'?>"
"<Node name='Root' gravity='0 -9.81 0' time='0' animate='0' > \n"
" <OglLabel name='label1' color='contrast' printLog='true'/> \n"
"</Node> \n" ;
Node::SPtr root = SceneLoaderXML::loadFromMemory ("testscene",
scene.str().c_str(),
scene.str().size()) ;
ASSERT_NE(nullptr, root.get()) ;
root->init(ExecParams::defaultInstance()) ;
BaseObject* lm = root->getObject("label1") ;
ASSERT_NE(nullptr, lm) ;
OglLabel* ogllabel = dynamic_cast<OglLabel*>(lm);
ASSERT_NE(nullptr, ogllabel) ;
EXPECT_TRUE(ogllabel->d_selectContrastingColor.getValue()) ;
EXPECT_EQ(RGBAColor::fromFloat(1,1,1,1), ogllabel->d_color.getValue()) ;
}
示例2: addNew
typename Component::SPtr addNew( Node::SPtr parentNode, std::string name="" )
{
typename Component::SPtr component = New<Component>();
parentNode->addObject(component);
component->setName(parentNode->getName()+"_"+name);
return component;
}
示例3: fileOpen
void SofaModeler::fileOpen(std::string filename)
{
if ( sofa::helper::system::DataRepository.findFile ( filename ) )
{
filename = sofa::helper::system::DataRepository.getFile ( filename );
openPath = sofa::helper::system::SetDirectory::GetParentDir(filename.c_str());
Node::SPtr root = NULL;
root = down_cast<sofa::simulation::Node>( sofa::simulation::getSimulation()->load(filename.c_str()).get() );
if (root)
{
createTab();
fileNew(root.get());
sceneTab->setCurrentIndex(sceneTab->count()-1);
graph->setFilename(filename);
changeTabName(graph,QString(sofa::helper::system::SetDirectory::GetFileName(filename.c_str()).c_str()));
changeNameWindow(graph->getFilename());
QAction* act = windowMenu->addAction(graph->getFilename().c_str());
mapWindow.insert(std::make_pair(act, tabGraph));
recentlyOpenedFilesManager.openFile(filename);
}
}
displayHelpModeler();
}
示例4: checkAttributes
void checkAttributes()
{
std::stringstream scene ;
scene << "<?xml version='1.0'?>"
"<Node name='Root' gravity='0 -9.81 0' time='0' animate='0' > \n"
" <OglLabel name='label1'/> \n"
"</Node> \n" ;
Node::SPtr root = SceneLoaderXML::loadFromMemory ("testscene",
scene.str().c_str(),
scene.str().size()) ;
ASSERT_NE(root.get(), nullptr) ;
root->init(ExecParams::defaultInstance()) ;
BaseObject* lm = root->getObject("label1") ;
ASSERT_NE(lm, nullptr) ;
/// List of the supported attributes the user expect to find
/// This list needs to be updated if you add an attribute.
vector<string> attrnames = {
"prefix", "label", "suffix", "x", "y", "fontsize", "color",
"selectContrastingColor", "updateLabelEveryNbSteps",
"visible"};
for(auto& attrname : attrnames)
EXPECT_NE( lm->findData(attrname), nullptr ) << "Missing attribute with name '" << attrname << "'." ;
}
示例5: buildNodeFromBaseElement
Node::SPtr GraphModeler::buildNodeFromBaseElement(Node::SPtr node,xml::BaseElement *elem, bool saveHistory)
{
const bool displayWarning=true;
Node::SPtr newNode = Node::create("");
//Configure the new Node
configureElement(newNode.get(), elem);
if (newNode->getName() == "Group")
{
//We can't use the parent node, as it is null
if (!node) return NULL;
//delete newNode;
newNode = node;
}
else
{
// if (node)
{
//Add as a child
addNode(node,newNode,saveHistory);
}
}
typedef xml::BaseElement::child_iterator<> elem_iterator;
for (elem_iterator it=elem->begin(); it != elem->end(); ++it)
{
if (std::string(it->getClass()) == std::string("Node"))
{
buildNodeFromBaseElement(newNode, it,true);
}
else
{
const ComponentLibrary *component = sofaLibrary->getComponent(it->getType());
//Configure the new Component
const std::string templateAttribute("template");
std::string templatename;
templatename = it->getAttribute(templateAttribute, "");
const ClassEntry::SPtr info = component->getEntry();
BaseObject::SPtr newComponent=addComponent(newNode, info, templatename, saveHistory,displayWarning);
if (!newComponent) continue;
configureElement(newComponent.get(), it);
QTreeWidgetItem* itemGraph = graphListener->items[newComponent.get()];
std::string name=itemGraph->text(0).toStdString();
std::string::size_type pos = name.find(' ');
if (pos != std::string::npos) name.resize(pos);
name += " ";
name+=newComponent->getName();
itemGraph->setText(0,name.c_str());
}
}
newNode->clearWarnings();
return newNode;
}
示例6: build
OSG::NodeTransitPtr OSGSofaShadowGraph::build(
Node::SPtr root,
bool ignoreLights )
{
_scene = NULL;
_chunkOverrideGroup = NULL;
_shadowStage = NULL;
VisualParams* vparams = VisualParams::defaultInstance();
OSG::NodeUnrecPtr shadowStageNode;
_chunkOverrideGroup = OSG::ChunkOverrideGroup::create();
_scene = OSG::makeNodeFor(_chunkOverrideGroup);
sofa::simulation::OSGVisualUpdateVisitor vm_visitor( vparams);
vm_visitor.setChunkOverrideGroupNode(_scene);
// get lights
if (!ignoreLights)
{
if (!_shadowStage)
_shadowStage = OSG::ShadowStage::create();
_shadowStage->setMapSize(1024);
_shadowStage->setShadowSmoothness(0.5f);
_shadowStage->setShadowMode(OSG::ShadowStage::NO_SHADOW);
_shadowStage->setAutoSearchForLights(true);
shadowStageNode = OSG::makeNodeFor(_shadowStage);
sofa::simulation::OSGLightVisitor light_visitor( vparams);
//light_visitor.setTurnOffLights(ignoreLights);
light_visitor.setOSG2Parent(_scene);
light_visitor.setOSG2ShadowStage(_shadowStage);
light_visitor.setAttachNode(_scene);
root->execute(&light_visitor);
if (light_visitor.getAttachNode())
{
vm_visitor.setOSG2Parent(light_visitor.getAttachNode());
root->execute(&vm_visitor);
}
}
else
{
vm_visitor.setOSG2Parent(_scene);
root->execute(&vm_visitor);
}
if (shadowStageNode && !ignoreLights)
{
shadowStageNode->addChild(_scene);
return OSG::NodeTransitPtr(shadowStageNode);
}
return OSG::NodeTransitPtr(_scene);
}
示例7: loadFromAFileForNonRigid
void loadFromAFileForNonRigid(){
string scene =
"<?xml version='1.0'?>"
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > "
" <MechanicalObject position='0 0 0'/> "
" <UniformMass filename='BehaviorModels/card.rigid'/> "
"</Node> " ;
Node::SPtr root = SceneLoaderXML::loadFromMemory ("loadFromAValidFile",
scene.c_str(), (int)scene.size()) ;
root->init(ExecParams::defaultInstance()) ;
}
示例8: loadFromAnInvalidPathname
void loadFromAnInvalidPathname(){
string scene =
"<?xml version='1.0'?>"
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > "
" <MechanicalObject position='0 0 0'/> "
" <UniformMass filename='invalid_uniformmatrix.txt'/> "
"</Node> " ;
Node::SPtr root = SceneLoaderXML::loadFromMemory ("loadFromAnInValidFile",
scene.c_str(), (int)scene.size()) ;
root->init(ExecParams::defaultInstance()) ;
}
示例9: createRootNode
Node::SPtr createRootNode(Simulation::SPtr s, const std::string& name,
const std::map<std::string, std::string>& params)
{
Node::SPtr root = s->createNewNode(name) ;
BaseObjectDescription desc(name.c_str(), "Node");
for(auto& kv : params)
{
desc.setAttribute(kv.first.c_str(), kv.second);
}
root->parse(&desc) ;
return root ;
}
示例10: processXML
/// Load a scene from a file
Node::SPtr SceneLoaderXML::processXML(xml::BaseElement* xml, const char *filename)
{
loadSucceed = true;
if ( xml==NULL )
{
return NULL;
}
sofa::core::ExecParams* params = sofa::core::ExecParams::defaultInstance();
// We go the the current file's directory so that all relative path are correct
helper::system::SetDirectory chdir ( filename );
// Temporarily set the numeric formatting locale to ensure that
// floating-point values are interpreted correctly by tinyXML. (I.e. the
// decimal separator is a dot '.').
helper::system::TemporaryLocale locale(LC_NUMERIC, "C");
sofa::simulation::xml::NodeElement* nodeElt = dynamic_cast<sofa::simulation::xml::NodeElement *>(xml);
if( nodeElt==NULL )
{
std::cerr << "LOAD ERROR: XML Root Node is not an Element."<<std::endl;
loadSucceed = false;
std::exit(EXIT_FAILURE);
}
else if( !(nodeElt->init()) )
{
std::cerr << "LOAD ERROR: Node initialization failed."<<std::endl;
loadSucceed = false;
}
core::objectmodel::BaseNode* baseroot = xml->getObject()->toBaseNode();
if ( baseroot == NULL )
{
std::cerr << "LOAD ERROR: Objects initialization failed."<<std::endl;
loadSucceed = false;
return NULL;
}
Node::SPtr root = down_cast<Node> ( baseroot );
// Find the Simulation component in the scene
FindByTypeVisitor<Simulation> findSimu(params);
findSimu.execute(root.get());
if( !findSimu.found.empty() )
setSimulation( findSimu.found[0] );
return root;
}
示例11: processNodeBottomUp
void DeleteVisitor::processNodeBottomUp(Node* node)
{
while (!node->child.empty())
{
Node::SPtr child = *node->child.begin();
node->removeChild(child);
child.reset();
}
while (!node->object.empty())
{
core::objectmodel::BaseObject::SPtr object = *node->object.begin();
node->removeObject(object);
object.reset();
}
}
示例12: createObject
BaseObject::SPtr createObject(Node::SPtr parent, BaseObjectDescription& desc)
{
/// Create the object.
BaseObject::SPtr obj = ObjectFactory::getInstance()->createObject(parent.get(), &desc);
if (obj==nullptr)
{
std::stringstream msg;
msg << "Component '" << desc.getName() << "' of type '" << desc.getAttribute("type","") << "' failed:" << msgendl ;
for (std::vector< std::string >::const_iterator it = desc.getErrors().begin(); it != desc.getErrors().end(); ++it)
msg << " " << *it << msgendl ;
msg_error(parent.get()) << msg.str() ;
return nullptr;
}
return obj ;
}
示例13: testNoParameter
void testNoParameter()
{
EXPECT_MSG_EMIT(Error) ;
std::stringstream scene ;
scene << "<?xml version='1.0'?>"
"<Node name='Root' gravity='0 -9.81 0' time='0' animate='0' > \n"
" <RequiredPlugin /> \n"
"</Node> \n" ;
Node::SPtr root = SceneLoaderXML::loadFromMemory ("testscene",
scene.str().c_str(),
scene.str().size()) ;
ASSERT_NE(root.get(), nullptr) ;
root->init(ExecParams::defaultInstance()) ;
}
示例14: loadFromAFileForRigid
void loadFromAFileForRigid(){
string scene =
"<?xml version='1.0'?>"
"<Node name='Root' gravity='0 0 0' time='0' animate='0' > "
" <MechanicalObject template='Rigid3' position='0 0 0 1 0 0 1 0 0 0 1 0 0 1'/> "
" <UniformMass filename='BehaviorModels/card.rigid'/> "
"</Node> " ;
Node::SPtr root = SceneLoaderXML::loadFromMemory ("loadFromAValidFile",
scene.c_str(), (int)scene.size()) ;
root->init(ExecParams::defaultInstance()) ;
UniformMassRigid* mass = root->getTreeObject<UniformMassRigid>() ;
EXPECT_TRUE( mass != nullptr ) ;
if(mass!=nullptr){
EXPECT_EQ( mass->getMass(), 40.0 ) ;
EXPECT_EQ( mass->getTotalMass(), 80.0 ) ;
}
}
示例15: RemoveNode
void QSofaListView::RemoveNode()
{
if( object_.type == typeNode)
{
emit Lock(true);
Node::SPtr node = object_.ptr.Node;
if ( node == node->getRoot() )
{
if ( QMessageBox::warning ( this, "Removing root", "root node cannot be removed" ) )
return;
}
else
{
node->detachFromGraph();
node->execute<simulation::DeleteVisitor>(sofa::core::ExecParams::defaultInstance());
emit NodeRemoved();
}
emit Lock(false);
}
}