Пример #1
0
void merge_interactive_selection(const nodes_t& Nodes, const UpdatePolicyT& UpdatePolicy, const k3d::selection::records& InteractiveSelection)
{
	for(nodes_t::const_iterator node = Nodes.begin(); node != Nodes.end(); ++node)
	{
		if(classes::MeshInstance() != (*node)->factory().factory_id())
			continue;

		imesh_selection_sink* const mesh_selection_sink = dynamic_cast<imesh_selection_sink*>(*node);
		if(!mesh_selection_sink)
			continue;

		imesh_source* const mesh_source = dynamic_cast<imesh_source*>(*node);
		if(!mesh_source)
			continue;

		const k3d::mesh* const mesh = boost::any_cast<k3d::mesh*>(mesh_source->mesh_source_output().property_internal_value());
		if(!mesh)
			continue;

		const k3d::selection::set current_selection =
			boost::any_cast<k3d::selection::set>(mesh_selection_sink->mesh_selection_sink_input().property_internal_value());

		property::set_internal_value(mesh_selection_sink->mesh_selection_sink_input(), UpdatePolicy(*node, *mesh, current_selection, InteractiveSelection));
		property::set_internal_value(**node, "show_component_selection", true);
	}
}
Пример #2
0
 void do_insert_data(T data, Envelope<double> const& box, node * n, unsigned int& depth)
 {
    if (++depth >= max_depth_)
    {
       n->cont_.push_back(data);
    }
    else 
    {
       Envelope<double> const& node_extent = n->extent();
       Envelope<double> ext[4];
       split_box(node_extent,ext);		
       for (int i=0;i<4;++i)
       {
          if (ext[i].contains(box))
          {
             if (!n->children_[i])
             {
                nodes_.push_back(new node(ext[i]));
                n->children_[i]=&nodes_.back();
             }
             do_insert_data(data,box,n->children_[i],depth);
             return;
          }
       }
       n->cont_.push_back(data);
    }
 }
Пример #3
0
	void TORRENT_EXTRA_EXPORT write_nodes_entry(entry& r, nodes_t const& nodes)
	{
		bool ipv6_nodes = false;
		entry& n = r["nodes"];
		std::back_insert_iterator<std::string> out(n.string());
		for (nodes_t::const_iterator i = nodes.begin()
			, end(nodes.end()); i != end; ++i)
		{
			if (!i->addr().is_v4())
			{
				ipv6_nodes = true;
				continue;
			}
			std::copy(i->id.begin(), i->id.end(), out);
			write_endpoint(udp::endpoint(i->addr(), i->port()), out);
		}

		if (ipv6_nodes)
		{
			entry& p = r["nodes2"];
			std::string endpoint;
			for (nodes_t::const_iterator i = nodes.begin()
				, end(nodes.end()); i != end; ++i)
			{
				if (!i->addr().is_v6()) continue;
				endpoint.resize(18 + 20);
				std::string::iterator out = endpoint.begin();
				std::copy(i->id.begin(), i->id.end(), out);
				out += 20;
				write_endpoint(udp::endpoint(i->addr(), i->port()), out);
				endpoint.resize(out - endpoint.begin());
				p.list().push_back(entry(endpoint));
			}
		}
	}
Пример #4
0
 void clear () 
 {
    Envelope<double> ext = root_->extent_;
    nodes_.clear();
    nodes_.push_back(new node(ext));
    root_ = &nodes_[0];
 }
Пример #5
0
void tree::write_tree( ostream& os ) const
{
    for( const_iterator i = nodes.begin(),
                        e = nodes.end();
         i != e; ++i )
    {
        i->write_value( os );
        if( const inner_node* p = dynamic_cast<const inner_node*>( &*i ) )
            p->write_tree( os );
    }
}
Пример #6
0
size_t tree::size() const
{
    size_t res = 1;

    for( const_iterator i = nodes.begin(),
                        e = nodes.end();
         i != e; ++i )
    {
        res += i->node_size();
    }

    return res;
}
void xml_formatter::write_way(const element_info &elem, const nodes_t &nodes,
                              const tags_t &tags) {
  writer->start("way");
  write_common(elem);

  for (nodes_t::const_iterator itr = nodes.begin(); itr != nodes.end(); ++itr) {
    writer->start("nd");
    writer->attribute("ref", *itr);
    writer->end();
  }

  write_tags(tags);

  writer->end();
}
Пример #8
0
void json_formatter::write_way(const element_info &elem, const nodes_t &nodes,
                               const tags_t &tags) {
  writer->start_object();

  write_common(elem);
  writer->object_key("nds");
  writer->start_array();
  for (nodes_t::const_iterator itr = nodes.begin(); itr != nodes.end(); ++itr) {
    writer->entry_int(*itr);
  }
  writer->end_array();

  write_tags(tags);

  writer->end_object();
}
Пример #9
0
 explicit quad_tree(Envelope<double> const& ext, 
                    unsigned int max_depth = 8, 
                    double ratio = 0.55) 
    : max_depth_(max_depth),
      ratio_(ratio)
 {
    nodes_.push_back(new node(ext));
    root_ = &nodes_[0];
 }
Пример #10
0
tree::iterator tree::find( const string& match )
{
    for( iterator i = nodes.begin(),
                  e = nodes.end();
         i != e; ++i )
    {
        if( i->description() == match )
            return i;

        if( inner_node* p = dynamic_cast<inner_node*>( &*i ) )
        {
            iterator j = p->find( match );
            if( j != p->child_end() )
                return j;
        }
        
    }

    return child_end();
}
Пример #11
0
void str2node2 (const std::string& str, nodes_t& node)
{
    //assert the node-id of a new node's parent is less than it
    std::vector < std::string > tokens;
    tokenize<std::string>(str, std::back_inserter(tokens));
    unsigned int len = tokens.size() / 2;
    node.resize (len);
    std::vector <int> sibling (len);
    for (unsigned int i=0; i<len; ++i){
        node[i].val = SingleString::get()->getPointer(tokens[2*i]);
        node[i].sibling = -1;
        node[i].child = -1;
        const int parent = atoi(tokens[2*i + 1].c_str()) -1;
        node[i].parent = parent;
        sibling[i] = -1;
        const unsigned int here = i;
        if (parent!=-1){
            if (node[parent].child == -1) node[parent].child = here;
            if (sibling[parent] != -1) node[sibling[parent]].sibling = here;
            sibling[parent] = here;
        };
    };
}
Пример #12
0
inline tree::const_iterator tree::child_end() const
{
    return nodes.end();
}
Пример #13
0
inline tree::iterator tree::child_end()
{
    return nodes.end();
}
Пример #14
0
inline tree::const_iterator tree::child_begin() const
{
    return nodes.begin();
}
Пример #15
0
inline tree::iterator tree::child_begin()
{
    return nodes.begin();
}
Пример #16
0
void str2node (const std::string& str, nodes_t& node)
{
    try {
            unsigned int len = str.size();
            unsigned int size = 0;
            std::string buf = "";
            std::vector <std::string> tmp;

            for (unsigned int i = 0; i < len; i++) {
                if (str[i] == '(' || str[i] == ')') {
                if (! buf.empty()) {
                tmp.push_back (buf);
                buf = "";
                ++size;
                }
                if (str[i] == ')') tmp.push_back (")");
                } else if (str[i] == '\t' || str[i] == ' ') { 	  // do nothing
                } else {
                buf += str[i];
                }
            }

        if (! buf.empty()) throw 2;

        node.resize (size);
        std::vector <int> sibling (size);
        for (unsigned int i = 0; i < size; ++i) {
            node[i].parent = -1;
            node[i].child = -1;
            node[i].sibling = -1;
            sibling[i] = -1;
        }

        std::vector <int> sr;
        unsigned int id = 0;
        int top = 0;

        for (unsigned int i = 0; i < tmp.size(); ++i) {
            if (tmp[i] == ")") {
                top = sr.size()-1;
                if (top < 1) continue;
                unsigned int child  = sr[top];
                unsigned int parent = sr[top-1];
                node[child].parent = parent;
                if (node[parent].child == -1) node[parent].child = child;
                if (sibling[parent] != -1) node[sibling[parent]].sibling = child;
                sibling[parent] = child;
                sr.resize (top);
            } else {
                node[id].val = SingleString::get()->getPointer(tmp[i]);
                sr.push_back (id);
                id++;
            }
        }
        return;
    }
    catch (const int) {
        std::cerr << "Fatal: parse error << [" << str << "]\n";
        std::exit (-1);
    }
}
Пример #17
0
 iterator end()
 {
    return  nodes_.end();
 }
Пример #18
0
inline void tree::add_child( node* n )
{
    nodes.push_back( n );
}
Пример #19
0
 // helper function
 void insert_node(nodes_t& nodes, id_t const& name) {
   nodes.insert(name);
 }
Пример #20
0
 iterator begin()
 {
    return nodes_.begin();
 }
Пример #21
0
 const_iterator begin() const
 {
    return nodes_.begin();
 }
Пример #22
0
void modify_selected_meshes(document_state& DocumentState, iplugin_factory* Modifier)
{
	return_if_fail(Modifier);
	idocument& document = DocumentState.document();
	if (Modifier->implements(typeid(imulti_mesh_sink)))
	{ // Mesh modifier taking multiple inputs
		uint_t count = 0;
		ipipeline::dependencies_t dependencies;
		const nodes_t selected_nodes = selection::state(DocumentState.document()).selected_nodes();
		// Create the node
		inode* multi_sink = pipeline::create_node(document, *Modifier);
		record_state_change_set changeset(document, string_cast(boost::format(_("Add Modifier %1%")) % Modifier->name()), K3D_CHANGE_SET_CONTEXT);
		nodes_t nodes_to_delete;
		for(nodes_t::const_iterator node = selected_nodes.begin(); node != selected_nodes.end(); ++node)
		{
			imesh_sink* const mesh_sink = dynamic_cast<imesh_sink*>(*node);
			if(!mesh_sink)
				continue;
			imatrix_sink* const matrix_sink = dynamic_cast<imatrix_sink*>(*node);

			iproperty* source_mesh = document.pipeline().dependency(mesh_sink->mesh_sink_input());
			if (!source_mesh)
				continue;
			
			if (matrix_sink) // Insert a transform node
			{
				iproperty* const source_transformation = document.pipeline().dependency(matrix_sink->matrix_sink_input());
				if (source_transformation)
				{
					inode* transform_points = plugin::create<inode>("TransformPoints", document, unique_name(document.nodes(), "TransformPoints"));
					return_if_fail(transform_points);
					imatrix_sink* transform_points_matrix_sink = dynamic_cast<imatrix_sink*>(transform_points);
					return_if_fail(transform_points_matrix_sink);
					imesh_sink* transform_points_mesh_sink = dynamic_cast<imesh_sink*>(transform_points);
					return_if_fail(transform_points_mesh_sink);
					dependencies.insert(std::make_pair(&transform_points_matrix_sink->matrix_sink_input(), source_transformation));
					dependencies.insert(std::make_pair(&transform_points_mesh_sink->mesh_sink_input(), source_mesh));
					imesh_source* transform_points_mesh_source = dynamic_cast<imesh_source*>(transform_points);
					return_if_fail(transform_points_mesh_source);
					source_mesh = &transform_points_mesh_source->mesh_source_output();
					imesh_selection_sink* selection_sink = dynamic_cast<imesh_selection_sink*>(transform_points);
					return_if_fail(selection_sink);
					property::set_internal_value(selection_sink->mesh_selection_sink_input(), k3d::geometry::selection::create(1.0));
				}
			}
			++count;
			// Create a new user property
			std::stringstream name, label;
			name << "input_mesh" << count;
			label << "Input Mesh " << count;
			iproperty* sink = property::get(*multi_sink, name.str());
			if (!sink)
				sink = property::create<mesh*>(*multi_sink, name.str(), label.str(), "", static_cast<mesh*>(0));
			// Store the connection
			dependencies.insert(std::make_pair(sink, source_mesh));
			// Delete the input node
			nodes_to_delete.push_back(*node);
		}
		document.pipeline().set_dependencies(dependencies);
		delete_nodes(document, nodes_to_delete);
		// Give nodes a chance to initialize their property values based on their inputs, if any ...
		if(ireset_properties* const reset_properties = dynamic_cast<ireset_properties*>(multi_sink))
			reset_properties->reset_properties();

		panel::mediator(DocumentState.document()).set_focus(*multi_sink);
	}
	else
	{ // Normal mesh modifier
		nodes_t new_modifiers;
	
		const nodes_t selected_nodes = selection::state(DocumentState.document()).selected_nodes();
		for(nodes_t::const_iterator node = selected_nodes.begin(); node != selected_nodes.end(); ++node)
		{
			new_modifiers.push_back(modify_mesh(DocumentState, **node, Modifier));
			assert_warning(new_modifiers.back());
		}
	
		// Show the new modifier properties if only one was processed
		if(selected_nodes.size() == 1)
		{
			panel::mediator(DocumentState.document()).set_focus(*new_modifiers.front());
		}
		else // otherwise connect all parameter properties to the first node and show that one
		{
			iproperty_collection* first_property_collection = dynamic_cast<iproperty_collection*>(new_modifiers.front());
			if (first_property_collection)
			{
				// Get the in-and output property names, to exclude them from the connections
				imesh_sink* const modifier_sink = dynamic_cast<imesh_sink*>(new_modifiers.front());
				return_if_fail(modifier_sink);
				imesh_source* const modifier_source = dynamic_cast<imesh_source*>(new_modifiers.front());
				return_if_fail(modifier_source);
				const std::string sink_name = modifier_sink->mesh_sink_input().property_name();
				const std::string source_name = modifier_source->mesh_source_output().property_name();
				
				ipipeline::dependencies_t dependencies;
				const iproperty_collection::properties_t& first_properties = first_property_collection->properties();
				nodes_t::iterator modifier = new_modifiers.begin();
				++modifier;
				for (modifier; modifier != new_modifiers.end(); ++modifier)
				{
					iproperty_collection* property_collection = dynamic_cast<iproperty_collection*>(*modifier);
					return_if_fail(property_collection);
					const iproperty_collection::properties_t& properties = property_collection->properties();
					iproperty_collection::properties_t::const_iterator property = properties.begin();
					for (iproperty_collection::properties_t::const_iterator first_property = first_properties.begin(); first_property != first_properties.end(); ++first_property)
					{
						return_if_fail(property != properties.end());
						return_if_fail((*property)->property_name() == (*first_property)->property_name());
						if ((*property)->property_name() == sink_name || (*property)->property_name() == source_name || (*property)->property_name() == "name")
						{
							++property;
							continue;
						}
						dependencies.insert(std::make_pair(*property, *first_property));
						++property;
					}
				}
				document.pipeline().set_dependencies(dependencies);
				panel::mediator(DocumentState.document()).set_focus(*new_modifiers.front());
			}
		}
	}
}
Пример #23
0
inline void tree::remove( iterator n )
{
    BOOST_ASSERT( n != nodes.end() );
    nodes.erase( n );
}
Пример #24
0
 void swap( tree& r )               
     { nodes.swap( r.nodes ); } 
Пример #25
0
 const_iterator end() const
 {
    return  nodes_.end();
 }