Пример #1
0
        void add(const T& begin_node, const T& end_node) // add arc
        {
          if(begin_node == end_node)
          {
            return;
          }

          size_t aId = 0;
          size_t bId = 0;

          node_ptr aTestResult = is_node(begin_node);
          if(aTestResult.get()->is_null())
          {
            node_ptr pNode = node_ptr(new node<T>(begin_node));
            aId = pNode->id;
            pNode->null = false;
            if(pNode->id > matrix_size)
            {
              std::ostringstream msg;
              msg << "node id " << pNode->id << " is greater than maximum matrix size " << matrix_size << "!";
              throw std::invalid_argument(msg.str()); // TODO: add test for that
            }
            this->storage.push_back(pNode);
          }
          else
          {
            aId = aTestResult->id;
          }

          node_ptr bTestResult = is_node(end_node);
          if(bTestResult.get()->is_null())
          {
            node_ptr pNode = node_ptr(new node<T>(end_node));
            bId = pNode->id;
            pNode->null = false;
            if(pNode->id >matrix_size)
            {
              std::ostringstream msg;
              msg << "node id " << pNode->id << " is greater than maximum matrix size " << matrix_size << "!";
              throw std::invalid_argument(msg.str()); // TODO: add test for that
            }
            this->storage.push_back(pNode);
          }
          else
          {
            bId = bTestResult->id;
          }
          matrix2D.at(aId).at(bId) = 1;
          matrix2D.at(bId).at(aId) = 1;
        }
Пример #2
0
        void add(const T& begin_node, const T& end_node) // add arc
        {
          if(begin_node == end_node)
          {
            return;
          }

          size_t aId = 0;
          size_t bId = 0;

          node_ptr aTestResult = is_node(begin_node);
          if(aTestResult.get()->is_null())
          {
            node_ptr pNode = node_ptr(new node<T>(begin_node));
            aId = pNode->id;
            pNode->null = false;
            this->storage.push_back(pNode);
            adjectedListsVec.push_back(list_ptr(new std::list<T>));
          }
          else
          {
            aId = aTestResult->id;
          }

          node_ptr bTestResult = is_node(end_node);
          if(bTestResult.get()->is_null())
          {
            node_ptr pNode = node_ptr(new node<T>(end_node));
            bId = pNode->id;
            pNode->null = false;
            this->storage.push_back(pNode);
            adjectedListsVec.push_back(list_ptr(new std::list<T>));
          }
          else
          {
            bId = bTestResult->id;
          }

          adjectedListsVec[aId]->push_back(bId);
          adjectedListsVec[aId]->unique();

          adjectedListsVec[bId]->push_back(aId);
          adjectedListsVec[bId]->unique();

          assert(this->storage.size() == adjectedListsVec.size());
        }	
Пример #3
0
int main (int argc, char **argv)
{
    OSG::osgInit(argc, argv);


    // Test getting pointers
    OSG::NodeRecPtr node_rptr = OSG::Node::create();
#ifdef OSG_MT_FIELDCONTAINERPTRX
    OSG::Node* node_cptr = get_pointer(node_rptr);
#else
//    OSG::Node* node_cptr = node_ptr;
#endif
    
#ifdef OSG_MT_FIELDCONTAINERPTRX
    OSG::NodeRecPtr node_rptr1(OSG::Node::create());
    node_cptr = get_pointer(node_rptr1);
#endif

   // Test Weak ref count ptrs
   {
      OSG::NodeRecPtr node_ptr(OSG::Node::create());
      OSG::NodeWeakPtr node_weak(node_ptr);
      OSG_ASSERT(NULL != node_ptr);
      OSG_ASSERT(NULL != node_weak);

      node_ptr = NULL;

      OSG_ASSERT(NULL == node_ptr);
      OSG_ASSERT(NULL == node_weak);
    }

   {
      OSG::NodeMTRecPtr node_ptr(OSG::Node::create());
      OSG::NodeMTWeakPtr node_weak(node_ptr);
      OSG_ASSERT(NULL != node_ptr);
      OSG_ASSERT(NULL != node_weak);

      node_ptr = NULL;

      OSG_ASSERT(NULL == node_ptr);
      OSG_ASSERT(NULL == node_weak);
    }

    node_rptr = NULL;
}
Пример #4
0
node_ptr node::get_child(const std::string& key)
{
	const child_range range = get_child_range(key);
	if(range.first == range.second) {
		return node_ptr();
	} else {
		return range.first->second;
	}
}
Пример #5
0
 boost::shared_ptr<node<T> > is_node(const T& value) const
 {
   for(typename std::vector<node_ptr>::const_iterator it = storage.begin(); it != storage.end(); ++it)
   {
     if((*it)->value == value)
     {
       return *it;
     }
   }
   return node_ptr(new node<T>(NULL, true)); // NULL object idiom
 }
Пример #6
0
NodeSharedPtr MLNetwork::add_node(const ActorSharedPtr& actor, const LayerSharedPtr& layer) {
	NodeSharedPtr check = get_node(actor,layer);
	if (check) return NULL;
	node_id id = ++max_node_id;
	NodeSharedPtr node_ptr(new node(id,actor,layer));
	nodes.insert(id,node_ptr);
	sidx_nodes_by_layer[layer->id].insert(id,node_ptr);
	cidx_node_by_actor_and_layer[actor->id][layer->id] = node_ptr;
	sidx_nodes_by_actor[actor->id].insert(id,node_ptr);
	return node_ptr;
}
Пример #7
0
    inline void hash_buckets<A, G>::clear_bucket(bucket_ptr b)
    {
        node_ptr node_it = b->next_;
        b->next_ = node_ptr();

        while(node_it) {
            node_ptr node_to_delete = node_it;
            node_it = node_it->next_;
            delete_node(node_to_delete);
        }
    }
Пример #8
0
typename tree< T , A >::NodePtr_t
tree< T , A >::alloc_node( NodePtr_t left  /*= 0*/
                          , NodePtr_t right /*= 0*/
                          , NodePtr_t child /*= 0*/
                          )
{
    NodePtr_t node_ptr( NodeAllocator_t( allocator_ ).allocate( 1 ) );
    node_ptr->left = left;
    node_ptr->right = right;
    node_ptr->child = child;
    return node_ptr;
}
Пример #9
0
	std::map<int, block_ptr> XML::build(std::istream *is, script::Script &script) {
		parse(is);
		node_ptr scriptRoot(root->first_node("scripts")->first_node("script"), null_deleter());
		getVars(script.variables_);
		getPoints(script.points_, script.devices_);
		std::map<int, block_ptr> startingBlocks;
		
		for (int i = 0; scriptRoot; scriptRoot.reset(scriptRoot->next_sibling(), null_deleter()), ++i) {
			block_ptr b(getChildren(node_ptr(scriptRoot->first_node(), null_deleter())));
			startingBlocks.insert(std::pair<int, block_ptr>(i, b));
		}
		return startingBlocks;
	}
Пример #10
0
// locate node based on path (NO XPATH YET!!!)
node_ptr node::find_child(const string& path)
{
	node_ptr result(shared_from_this());
	
	vector<string> pv;
	ba::split(pv, path, ba::is_any_of("/"));
	
	if (path.size() == 0)
		return result; // ?

	vector<string>::iterator p = pv.begin();
	if (p->length() == 0)
		++p;
	
	if (p == pv.end())
		return node_ptr();
	
	while (p != pv.end() and result)
	{
		bool found = false;
		for (node::iterator n = result->begin(); n != result->end(); ++n)
		{
			if (n->name() == *p)
			{
				++p;
				result = n->shared_from_this();
				found = true;
				break;
			}
		}
		
		if (not found)
			result = node_ptr();
	}
	
	return result;
}
Пример #11
0
typename tree< T , A >::iterator
tree< T , A >::
insert_after( iterator it , const value_type & copy /*= value_type()*/ )
{
    NodePtr_t node_ptr( root_ );
    if ( get_node_ptr( it ) != root_ ) {
        NodePtr_t _S = get_node_ptr( it );
        node_ptr = alloc_node( _S , _S->right , 0 );
        allocator_.construct( & node_ptr->value , copy );
        if ( _S->right != 0 )
            _S->right->left = node_ptr;
        _S->right = node_ptr;
        ++size_;
    } // if
    return iterator( node_ptr );
}
Пример #12
0
std::unique_ptr<MeshBase>
SphereSurfaceMeshGenerator::generate()
{
  // Have MOOSE construct the correct libMesh::Mesh object using Mesh block and CLI parameters.
  auto mesh = _mesh->buildMeshBaseObject();
  mesh->set_mesh_dimension(2);
  mesh->set_spatial_dimension(3);

  const Sphere sphere(_center, _radius);

  // icosahedron points (using golden ratio rectangle construction)
  const Real phi = (1.0 + std::sqrt(5.0)) / 2.0;
  const Real X = std::sqrt(1.0 / (phi * phi + 1.0));
  const Real Z = X * phi;
  const Point vdata[12] = {{-X, 0.0, Z},
                           {X, 0.0, Z},
                           {-X, 0.0, -Z},
                           {X, 0.0, -Z},
                           {0.0, Z, X},
                           {0.0, Z, -X},
                           {0.0, -Z, X},
                           {0.0, -Z, -X},
                           {Z, X, 0.0},
                           {-Z, X, 0.0},
                           {Z, -X, 0.0},
                           {-Z, -X, 0.0}};
  for (unsigned int i = 0; i < 12; ++i)
    mesh->add_point(vdata[i] * _radius + _center, i);

  // icosahedron faces
  const unsigned int tindices[20][3] = {{0, 4, 1},  {0, 9, 4},  {9, 5, 4},  {4, 5, 8},  {4, 8, 1},
                                        {8, 10, 1}, {8, 3, 10}, {5, 3, 8},  {5, 2, 3},  {2, 7, 3},
                                        {7, 10, 3}, {7, 6, 10}, {7, 11, 6}, {11, 0, 6}, {0, 1, 6},
                                        {6, 1, 10}, {9, 0, 11}, {9, 11, 2}, {9, 2, 5},  {7, 2, 11}};
  for (unsigned int i = 0; i < 20; ++i)
  {
    Elem * elem = mesh->add_elem(new Tri3);
    elem->set_node(0) = mesh->node_ptr(tindices[i][0]);
    elem->set_node(1) = mesh->node_ptr(tindices[i][1]);
    elem->set_node(2) = mesh->node_ptr(tindices[i][2]);
  }

  // we need to prepare distributed meshes before using refinement
  if (!mesh->is_replicated())
    mesh->prepare_for_use(/*skip_renumber =*/false);

  // Now we have the beginnings of a sphere.
  // Add some more elements by doing uniform refinements and
  // popping nodes to the boundary.
  MeshRefinement mesh_refinement(*mesh);

  // Loop over the elements, refine, pop nodes to boundary.
  for (unsigned int r = 0; r < _depth; ++r)
  {
    mesh_refinement.uniformly_refine(1);

    auto it = mesh->active_nodes_begin();
    const auto end = mesh->active_nodes_end();

    for (; it != end; ++it)
    {
      Node & node = **it;
      node = sphere.closest_point(node);
    }
  }

  // Flatten the AMR mesh to get rid of inactive elements
  MeshTools::Modification::flatten(*mesh);

  return dynamic_pointer_cast<MeshBase>(mesh);
}
Пример #13
0
	bin_index_t::node_ptr bin_index_t::create_node(const std::string& base_dir,size_t key_len) const
	{
		return node_ptr(new mix_node(*this,base_dir,key_len));
	}
Пример #14
0
 inline BOOST_DEDUCED_TYPENAME hash_buckets<A, G>::node_ptr
     hash_buckets<A, G>::bucket_begin(std::size_t num) const
 {
     return buckets_ ? get_bucket(num)->next_ : node_ptr();
 }