Esempio n. 1
0
	void objects_iterator_breadth::add_nodes( const std::vector< Object_Parent >& objects, size_t depth )
	{
		if( objects.empty() )
			return; // be lazy!

		std::vector<Object_Parent> child_objects;

		
		for( size_t idx = 0; idx < objects.size(); ++idx )
		{
			const Object_Parent& infos = objects[idx];
			add_node( ObjectTreeNodeInfos( infos.object, infos.parent, depth, idx ) );
			
			if( infos.object->children() ) // collect all the children at the same next depth level
			{
				const auto& children = infos.object->children()->object();
				for( const auto& child_object : children )
				{
					Object_Parent child_infos;
					child_infos.object = &child_object;
					child_infos.parent = infos.object;
					child_objects.push_back( child_infos );

				};
			}

		}

		if( !child_objects.empty() ) // go to the next depth level
			add_nodes( child_objects, depth + 1 );
	}
Esempio n. 2
0
/**
 * devtree_update
 *
 */
static void
devtree_update(void)
{
    int rc;
    unsigned int wa[1024];
    unsigned int *op;

    say(DEBUG, "Updating device_tree\n");
    if (add_phandles("/proc/device-tree",""))
        return;

    /* First 16 bytes of work area must be initialized to zero */
    memset(wa, 0x00, 16);

    do {
        rc = rtas_update_nodes((char *)wa, 1);
        if (rc && rc != 1) {
            say(DEBUG, "Error %d from rtas_update_nodes()\n", rc);
            return;
        }

        say(DEBUG, "successful rtas_update_nodes (more %d)\n", rc);

        op = wa+4;

        while (*op & 0xFF000000) {
            unsigned int i;
            say(DEBUG, "op %p, *op %8.8x\n", op, *op);

            for (i = 0; i < (*op & 0x00FFFFFF); i++)
                say(DEBUG, "   %8.8x\n",op[i+1]);

            switch (*op & 0xFF000000) {
            case 0x01000000:
                del_nodes(op+1, *op & 0x00FFFFFF);
                break;

            case 0x02000000:
                update_nodes(op+1, *op & 0x00FFFFFF);
                break;

            case 0x03000000:
                add_nodes(op+1, *op & 0x00FFFFFF);
                break;

            case 0x00000000:
                /* End */
                break;

            default:
                say(DEBUG, "Unknown update_nodes op %8.8x\n",
                    *op);
            }
            op += 1 + (*op & 0x00FFFFFF);
        }
    } while (rc == 1);

    say(DEBUG, "leaving\n");
}
Esempio n. 3
0
void BlenderSync::sync_world(bool update_all)
{
	Background *background = scene->background;
	Background prevbackground = *background;

	BL::World b_world = b_scene.world();

	if(world_recalc || update_all || b_world.ptr.data != world_map) {
		Shader *shader = scene->shaders[scene->default_background];
		ShaderGraph *graph = new ShaderGraph();

		/* create nodes */
		if(b_world && b_world.use_nodes() && b_world.node_tree()) {
			BL::ShaderNodeTree b_ntree(b_world.node_tree());

			add_nodes(scene, b_data, b_scene, graph, b_ntree);
		}
		else if(b_world) {
			ShaderNode *closure, *out;

			closure = graph->add(new BackgroundNode());
			closure->input("Color")->value = get_float3(b_world.horizon_color());
			out = graph->output();

			graph->connect(closure->output("Background"), out->input("Surface"));
		}

		/* AO */
		if(b_world) {
			BL::WorldLighting b_light = b_world.light_settings();

			if(b_light.use_ambient_occlusion())
				background->ao_factor = b_light.ao_factor();
			else
				background->ao_factor = 0.0f;

			background->ao_distance = b_light.distance();
		}

		shader->set_graph(graph);
		shader->tag_update(scene);
	}

	PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");

	/* when doing preview render check for BI's transparency settings,
	 * this is so because bledner's preview render routines are not able
	 * to tweak all cycles's settings depending on different circumstances
	 */
	if(b_engine.is_preview() == false)
		background->transparent = get_boolean(cscene, "film_transparent");
	else
		background->transparent = b_scene.render().alpha_mode() == BL::RenderSettings::alpha_mode_TRANSPARENT;

	background->use = render_layer.use_background;

	if(background->modified(prevbackground))
		background->tag_update(scene);
}
Esempio n. 4
0
unsigned int
add_root_node ( char* path, dir_node* slot ) {
  unsigned int sum = 0;
  dir_node* root_node;
  root_node = create_root_dir_node(path, dir_cluster);
  assert(root_node);
  int root_fd = dirfd(root_node->dir_ptr);
  cbt_insert(&cbt, root_node->path, &root_fd);
  z_dir(path, "dir add");
  return add_nodes(root_node, slot);
}
Esempio n. 5
0
  ////
  //// class HypothesesBuilder
  ////
  HypothesesGraph* HypothesesBuilder::build() const {
    // construct an empty HypothesesGraph with all desired additional 
    // properties added
    HypothesesGraph* graph = construct();
    // add object nodes and set node properties
    graph = add_nodes(graph);
    // connect object nodes and set edge properties
    graph = add_edges(graph);

    return graph;
  }
void CommandAddRefs::find_nodes_in_ways() {
    m_vout << "Reading source file to find nodes in ways...\n";

    osmium::io::Reader reader(m_source_file, osmium::osm_entity_bits::way);
    while (osmium::memory::Buffer buffer = reader.read()) {
        for (auto it = buffer.begin<osmium::Way>(); it != buffer.end<osmium::Way>(); ++it) {
            if (m_way_ids.count(it->id())) {
                add_nodes(*it);
            }
        }
    }
    reader.close();
}
Esempio n. 7
0
void BlenderSync::sync_world(bool update_all)
{
	Background *background = scene->background;
	Background prevbackground = *background;

	BL::World b_world = b_scene.world();

	if(world_recalc || update_all || b_world.ptr.data != world_map) {
		Shader *shader = scene->shaders[scene->default_background];
		ShaderGraph *graph = new ShaderGraph();

		/* create nodes */
		if(b_world && b_world.use_nodes() && b_world.node_tree()) {
			PtrSockMap sock_to_node;
			BL::ShaderNodeTree b_ntree(b_world.node_tree());

			add_nodes(scene, b_data, b_scene, graph, b_ntree, sock_to_node);
		}
		else if(b_world) {
			ShaderNode *closure, *out;

			closure = graph->add(new BackgroundNode());
			closure->input("Color")->value = get_float3(b_world.horizon_color());
			out = graph->output();

			graph->connect(closure->output("Background"), out->input("Surface"));
		}

		/* AO */
		if(b_world) {
			BL::WorldLighting b_light = b_world.light_settings();

			if(b_light.use_ambient_occlusion())
				background->ao_factor = b_light.ao_factor();
			else
				background->ao_factor = 0.0f;

			background->ao_distance = b_light.distance();
		}

		shader->set_graph(graph);
		shader->tag_update(scene);
	}

	PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
	background->transparent = get_boolean(cscene, "film_transparent");
	background->use = render_layer.use_background;

	if(background->modified(prevbackground))
		background->tag_update(scene);
}
Esempio n. 8
0
	void objects_iterator_depth::add_nodes( const aosl::Object_list& objects, const aosl::Object* parent, size_t depth )
	{
		const auto& object_list = objects.object();
		
		size_t idx = 0;
		for( const auto& object : object_list )
		{
			add_node( ObjectTreeNodeInfos( &object, parent, depth, idx ) );

			if( object.children() )
				add_nodes( *object.children(), &object, depth + 1 );

			++idx;
		};
	}
Esempio n. 9
0
	void objects_iterator_breadth::build( const aosl::Object_list& root_objects )
	{
		std::vector< Object_Parent > root_object_infos;
		const auto& root_object_list = root_objects.object();

		for( const auto& root_object : root_object_list )
		{
			Object_Parent infos;
			infos.object = &root_object;
			infos.parent = nullptr;
			root_object_infos.push_back( infos );
		};

		add_nodes( root_object_infos, 0 );

	}
Esempio n. 10
0
void BlenderSync::sync_lamps(bool update_all)
{
	shader_map.set_default(scene->shaders[scene->default_light]);

	/* lamp loop */
	BL::BlendData::lamps_iterator b_lamp;

	for(b_data.lamps.begin(b_lamp); b_lamp != b_data.lamps.end(); ++b_lamp) {
		Shader *shader;
		
		/* test if we need to sync */
		if(shader_map.sync(&shader, *b_lamp) || update_all) {
			ShaderGraph *graph = new ShaderGraph();

			/* create nodes */
			if(b_lamp->use_nodes() && b_lamp->node_tree()) {
				shader->name = b_lamp->name().c_str();

				PtrSockMap sock_to_node;
				BL::ShaderNodeTree b_ntree(b_lamp->node_tree());

				add_nodes(scene, b_data, b_scene, graph, b_ntree, sock_to_node);
			}
			else {
				ShaderNode *closure, *out;
				float strength = 1.0f;

				if(b_lamp->type() == BL::Lamp::type_POINT ||
				   b_lamp->type() == BL::Lamp::type_SPOT ||
				   b_lamp->type() == BL::Lamp::type_AREA)
				{
					strength = 100.0f;
				}

				closure = graph->add(new EmissionNode());
				closure->input("Color")->value = get_float3(b_lamp->color());
				closure->input("Strength")->value.x = strength;
				out = graph->output();

				graph->connect(closure->output("Emission"), out->input("Surface"));
			}

			shader->set_graph(graph);
			shader->tag_update(scene);
		}
	}
}
Esempio n. 11
0
unsigned int
add_nodes (dir_node* root, dir_node* slot) {
  struct dirent* ent;
  unsigned int sum = 0;
  while ( (ent = readdir(root->dir_ptr)) ) {
    assert(ent);
    if ( ent->d_type == DT_DIR  ) {
      dir_node* node;
      node = create_dir_node(ent, root, slot);
      assert(node);
      int fd = dirfd(node->dir_ptr);

      sum++;
      cbt_insert(&cbt, node->path, &fd);
      z_dir(slot[fd].path, "dir add");
      sum += add_nodes(node, slot);
    } else {
      unsigned int namelen, p_namelen;
      char * d_name = ent->d_name;
      char * p_name = root->path;
      namelen = strlen(d_name);
      p_namelen = strlen(p_name);
      char* path = NULL;
      path = malloc(namelen + p_namelen + 2);
      assert(path);
      sprintf(path, "%s/%s", p_name, d_name);
      if ( !cbt_contains(&cbt, path)) {
        int fd = open(path, O_NONBLOCK|O_RDONLY);
        if ( fd < 0 ) {
           printf("%s open error %s\n", path, strerror(errno));
           abort();
        }
        ev_io_init(&dir_watcher[fd], file_cb, fd, EV_LIBUV_KQUEUE_HACK);
        ev_io_start(loop, &dir_watcher[fd]);
        assert(empty_dir_node(&dir_cluster[fd]));
        memset(&dir_cluster[fd], 0, sizeof(dir_node));
        dir_cluster[fd].path = path;
        cbt_insert(&cbt, path, &fd);
        z_dir(path, "file add");
      } else {
        free(path);
      }
    }
  }
  return sum;
}
Esempio n. 12
0
static void add_nodes(Scene *scene,
                      BL::RenderEngine b_engine,
                      BL::BlendData b_data,
                      BL::Scene b_scene,
                      ShaderGraph *graph,
                      BL::ShaderNodeTree b_ntree)
{
	static const ProxyMap empty_proxy_map;
	add_nodes(scene,
	          b_engine,
	          b_data,
	          b_scene,
	          graph,
	          b_ntree,
	          empty_proxy_map,
	          empty_proxy_map);
}
Esempio n. 13
0
unsigned int
insert_nodes ( dir_node* root,     /* root of tree to be inserted*/
               dir_node* parent,   /* inserted subtree's parent */
               dir_node* slot) {   /* operate on this heap */
  unsigned sum = 0;
  assert(!empty_dir_node(root));
  assert(parent);

  DIR* root_dirp = root->dir_ptr;
  int root_fd = dirfd(root_dirp);
  root->parent = parent;
  sum++;
  cbt_insert(&cbt, root->path, &root_fd);
  z_dir(root->path, "dir add");
  sum += add_nodes(root, slot);
  return sum;
}
void BlenderSync::sync_lamps(bool update_all)
{
	shader_map.set_default(scene->default_light);

	/* lamp loop */
	BL::BlendData::lamps_iterator b_lamp;

	for(b_data.lamps.begin(b_lamp); b_lamp != b_data.lamps.end(); ++b_lamp) {
		Shader *shader;

		/* test if we need to sync */
		if(shader_map.sync(&shader, *b_lamp) || update_all) {
			ShaderGraph *graph = new ShaderGraph();

			/* create nodes */
			if(b_lamp->use_nodes() && b_lamp->node_tree()) {
				shader->name = b_lamp->name().c_str();

				BL::ShaderNodeTree b_ntree(b_lamp->node_tree());

				add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
			}
			else {
				float strength = 1.0f;

				if(b_lamp->type() == BL::Lamp::type_POINT ||
				   b_lamp->type() == BL::Lamp::type_SPOT ||
				   b_lamp->type() == BL::Lamp::type_AREA)
				{
					strength = 100.0f;
				}

				EmissionNode *emission = new EmissionNode();
				emission->color = get_float3(b_lamp->color());
				emission->strength = strength;
				graph->add(emission);

				ShaderNode *out = graph->output();
				graph->connect(emission->output("Emission"), out->input("Surface"));
			}

			shader->set_graph(graph);
			shader->tag_update(scene);
		}
	}
}
Esempio n. 15
0
void BlenderSync::sync_materials(bool update_all)
{
	shader_map.set_default(scene->shaders[scene->default_surface]);

	/* material loop */
	BL::BlendData::materials_iterator b_mat;

	for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) {
		Shader *shader;

		/* test if we need to sync */
		if(shader_map.sync(&shader, *b_mat) || update_all) {
			ShaderGraph *graph = new ShaderGraph();

			shader->name = b_mat->name().c_str();
			shader->pass_id = b_mat->pass_index();

			/* create nodes */
			if(b_mat->use_nodes() && b_mat->node_tree()) {
				BL::ShaderNodeTree b_ntree(b_mat->node_tree());

				add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
			}
			else {
				ShaderNode *closure, *out;

				closure = graph->add(new DiffuseBsdfNode());
				closure->input("Color")->value = get_float3(b_mat->diffuse_color());
				out = graph->output();

				graph->connect(closure->output("BSDF"), out->input("Surface"));
			}

			/* settings */
			PointerRNA cmat = RNA_pointer_get(&b_mat->ptr, "cycles");
			shader->use_mis = get_boolean(cmat, "sample_as_light");
			shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow");
			shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
			shader->volume_sampling_method = (VolumeSampling)RNA_enum_get(&cmat, "volume_sampling");
			shader->volume_interpolation_method = (VolumeInterpolation)RNA_enum_get(&cmat, "volume_interpolation");

			shader->set_graph(graph);
			shader->tag_update(scene);
		}
	}
}
Esempio n. 16
0
void CommandAddRefs::read_input_files() {
    m_vout << "Reading input files...\n";
    for (const std::string& file_name : m_input_filenames) {
        osmium::io::Reader reader(file_name, osmium::osm_entity_bits::object);
        while (osmium::memory::Buffer buffer = reader.read()) {
            for (auto it = buffer.begin<osmium::OSMObject>(); it != buffer.end<osmium::OSMObject>(); ++it) {
                if (it->type() == osmium::item_type::node) {
                    m_node_ids.insert(it->id());
                } else if (it->type() == osmium::item_type::way) {
                    m_way_ids.insert(it->id());
                    add_nodes(static_cast<const osmium::Way&>(*it));
                } else if (it->type() == osmium::item_type::relation) {
                    m_relation_ids.insert(it->id());
                    add_members(static_cast<const osmium::Relation&>(*it));
                }
            }
        }
        reader.close();
    }
}
Esempio n. 17
0
/* Build the training set using the supplied genetic code */
void build_training_set(struct _node *nodes, struct _training *tinf, struct
                        _summary *statistics, unsigned char *seq, unsigned
                        char *rseq, unsigned char *useq, int slen, int
                        *num_node, int closed, int cross_gaps) {

    int nn = 0, ipath = 0;

    /***********************************************************************
      Find all the potential starts and stops, sort them, and create a 
      comprehensive list of nodes for dynamic programming.
    ***********************************************************************/
    if(*num_node > 0) zero_nodes(nodes, *num_node);
    nn = add_nodes(seq, rseq, useq, slen, nodes, closed, cross_gaps,
                   tinf->trans_table);
    *num_node = nn;
    qsort(nodes, nn, sizeof(struct _node), &compare_nodes);

    /***********************************************************************
      Scan all the ORFS looking for a potential GC bias in a particular
      codon position.  This information will be used to acquire a good
      initial set of genes.
    ***********************************************************************/
    record_gc_frame_bias(tinf, seq, slen, nodes, nn);

    /***********************************************************************
      Do an initial dynamic programming routine with just the GC frame
      bias used as a scoring function.  This will get an initial set of 
      genes to train on. 
    ***********************************************************************/
    record_overlapping_starts(nodes, nn, tinf->st_wt, 0);
    ipath = dprog(nodes, nn, tinf, 0);

    /***********************************************************************
      Gather dicodon statistics for the training set.  Score the entire set
      of nodes.                               
    ***********************************************************************/
    calc_dicodon_gene(tinf, seq, rseq, slen, nodes, ipath);
    raw_coding_score(seq, rseq, slen, nodes, nn, tinf->trans_table, tinf->gc,
                     tinf->gene_dc);
    calc_avg_training_gene_lens(nodes, ipath, statistics);
}
static void add_nodes(Scene *scene, BL::BlendData b_data, BL::Scene b_scene, ShaderGraph *graph, BL::ShaderNodeTree b_ntree,
                      const ProxyMap &proxy_input_map, const ProxyMap &proxy_output_map)
{
	/* add nodes */
	BL::ShaderNodeTree::nodes_iterator b_node;
	PtrInputMap input_map;
	PtrOutputMap output_map;
	
	BL::Node::inputs_iterator b_input;
	BL::Node::outputs_iterator b_output;

	/* find the node to use for output if there are multiple */
	bool found_active_output = false;
	BL::ShaderNode output_node(PointerRNA_NULL);

	for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
		if (is_output_node(*b_node)) {
			BL::ShaderNodeOutputMaterial b_output_node(*b_node);

			if(b_output_node.is_active_output()) {
				output_node = b_output_node;
				found_active_output = true;
				break;
			}
			else if(!output_node.ptr.data && !found_active_output) {
				output_node = b_output_node;
			}
		}
	}

	/* add nodes */
	for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
		if (b_node->mute() || b_node->is_a(&RNA_NodeReroute)) {
			/* replace muted node with internal links */
			BL::Node::internal_links_iterator b_link;
			for (b_node->internal_links.begin(b_link); b_link != b_node->internal_links.end(); ++b_link) {
				ProxyNode *proxy = new ProxyNode(convert_socket_type(b_link->to_socket()));
				
				input_map[b_link->from_socket().ptr.data] = proxy->inputs[0];
				output_map[b_link->to_socket().ptr.data] = proxy->outputs[0];
				
				graph->add(proxy);
			}
		}
		else if (b_node->is_a(&RNA_ShaderNodeGroup) || b_node->is_a(&RNA_NodeCustomGroup)) {
			
			BL::ShaderNodeTree b_group_ntree(PointerRNA_NULL);
			if (b_node->is_a(&RNA_ShaderNodeGroup))
				b_group_ntree = BL::ShaderNodeTree(((BL::NodeGroup)(*b_node)).node_tree());
			else
				b_group_ntree = BL::ShaderNodeTree(((BL::NodeCustomGroup)(*b_node)).node_tree());
			ProxyMap group_proxy_input_map, group_proxy_output_map;
			
			/* Add a proxy node for each socket
			 * Do this even if the node group has no internal tree,
			 * so that links have something to connect to and assert won't fail.
			 */
			for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
				ProxyNode *proxy = new ProxyNode(convert_socket_type(*b_input));
				graph->add(proxy);
				
				/* register the proxy node for internal binding */
				group_proxy_input_map[b_input->identifier()] = proxy;
				
				input_map[b_input->ptr.data] = proxy->inputs[0];
				
				set_default_value(proxy->inputs[0], *b_node, *b_input, b_data, b_ntree);
			}
			for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
				ProxyNode *proxy = new ProxyNode(convert_socket_type(*b_output));
				graph->add(proxy);
				
				/* register the proxy node for internal binding */
				group_proxy_output_map[b_output->identifier()] = proxy;
				
				output_map[b_output->ptr.data] = proxy->outputs[0];
			}
			
			if (b_group_ntree)
				add_nodes(scene, b_data, b_scene, graph, b_group_ntree, group_proxy_input_map, group_proxy_output_map);
		}
		else if (b_node->is_a(&RNA_NodeGroupInput)) {
			/* map each socket to a proxy node */
			for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
				ProxyMap::const_iterator proxy_it = proxy_input_map.find(b_output->identifier());
				if (proxy_it != proxy_input_map.end()) {
					ProxyNode *proxy = proxy_it->second;
					
					output_map[b_output->ptr.data] = proxy->outputs[0];
				}
			}
		}
		else if (b_node->is_a(&RNA_NodeGroupOutput)) {
			BL::NodeGroupOutput b_output_node(*b_node);
			/* only the active group output is used */
			if (b_output_node.is_active_output()) {
				/* map each socket to a proxy node */
				for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
					ProxyMap::const_iterator proxy_it = proxy_output_map.find(b_input->identifier());
					if (proxy_it != proxy_output_map.end()) {
						ProxyNode *proxy = proxy_it->second;
						
						input_map[b_input->ptr.data] = proxy->inputs[0];
						
						set_default_value(proxy->inputs[0], *b_node, *b_input, b_data, b_ntree);
					}
				}
			}
		}
		else {
			ShaderNode *node = NULL;

			if (is_output_node(*b_node)) {
				if (b_node->ptr.data == output_node.ptr.data) {
					node = graph->output();
				}
			}
			else {
				node = add_node(scene, b_data, b_scene, graph, b_ntree, BL::ShaderNode(*b_node));
			}
			
			if(node) {
				/* map node sockets for linking */
				for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
					ShaderInput *input = node_find_input_by_name(node, *b_node, *b_input);
					input_map[b_input->ptr.data] = input;
					
					set_default_value(input, *b_node, *b_input, b_data, b_ntree);
				}
				for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
					ShaderOutput *output = node_find_output_by_name(node, *b_node, *b_output);
					output_map[b_output->ptr.data] = output;
				}
			}
		}
	}

	/* connect nodes */
	BL::NodeTree::links_iterator b_link;

	for(b_ntree.links.begin(b_link); b_link != b_ntree.links.end(); ++b_link) {
		/* get blender link data */
		BL::NodeSocket b_from_sock = b_link->from_socket();
		BL::NodeSocket b_to_sock = b_link->to_socket();

		ShaderOutput *output = 0;
		ShaderInput *input = 0;
		
		PtrOutputMap::iterator output_it = output_map.find(b_from_sock.ptr.data);
		if (output_it != output_map.end())
			output = output_it->second;
		PtrInputMap::iterator input_it = input_map.find(b_to_sock.ptr.data);
		if (input_it != input_map.end())
			input = input_it->second;

		/* either node may be NULL when the node was not exported, typically
		 * because the node type is not supported */
		if(output && input)
			graph->connect(output, input);
	}
}
Esempio n. 19
0
void BlenderSync::sync_world(bool update_all)
{
	Background *background = scene->background;
	Background prevbackground = *background;

	BL::World b_world = b_scene.world();

	if(world_recalc || update_all || b_world.ptr.data != world_map) {
		Shader *shader = scene->shaders[scene->default_background];
		ShaderGraph *graph = new ShaderGraph();

		/* create nodes */
		if(b_world && b_world.use_nodes() && b_world.node_tree()) {
			BL::ShaderNodeTree b_ntree(b_world.node_tree());

			add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);

			/* volume */
			PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
			shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume");
			shader->volume_sampling_method = (VolumeSampling)RNA_enum_get(&cworld, "volume_sampling");
			shader->volume_interpolation_method = (VolumeInterpolation)RNA_enum_get(&cworld, "volume_interpolation");
		}
		else if(b_world) {
			ShaderNode *closure, *out;

			closure = graph->add(new BackgroundNode());
			closure->input("Color")->value = get_float3(b_world.horizon_color());
			out = graph->output();

			graph->connect(closure->output("Background"), out->input("Surface"));
		}

		if(b_world) {
			/* AO */
			BL::WorldLighting b_light = b_world.light_settings();

			if(b_light.use_ambient_occlusion())
				background->ao_factor = b_light.ao_factor();
			else
				background->ao_factor = 0.0f;

			background->ao_distance = b_light.distance();

			/* visibility */
			PointerRNA cvisibility = RNA_pointer_get(&b_world.ptr, "cycles_visibility");
			uint visibility = 0;

			visibility |= get_boolean(cvisibility, "camera")? PATH_RAY_CAMERA: 0;
			visibility |= get_boolean(cvisibility, "diffuse")? PATH_RAY_DIFFUSE: 0;
			visibility |= get_boolean(cvisibility, "glossy")? PATH_RAY_GLOSSY: 0;
			visibility |= get_boolean(cvisibility, "transmission")? PATH_RAY_TRANSMIT: 0;
			visibility |= get_boolean(cvisibility, "scatter")? PATH_RAY_VOLUME_SCATTER: 0;

			background->visibility = visibility;
		}
		else {
			background->ao_factor = 0.0f;
			background->ao_distance = FLT_MAX;
		}

		shader->set_graph(graph);
		shader->tag_update(scene);
		background->tag_update(scene);
	}

	PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");

	/* when doing preview render check for BI's transparency settings,
	 * this is so because Blender's preview render routines are not able
	 * to tweak all cycles's settings depending on different circumstances
	 */
	if(b_engine.is_preview() == false)
		background->transparent = get_boolean(cscene, "film_transparent");
	else
		background->transparent = b_scene.render().alpha_mode() == BL::RenderSettings::alpha_mode_TRANSPARENT;

	background->use_shader = render_layer.use_background_shader;
	background->use_ao = render_layer.use_background_ao;

	if(background->modified(prevbackground))
		background->tag_update(scene);
}
Esempio n. 20
0
	void objects_iterator_depth::build( const aosl::Object_list& root_objects )
	{
		add_nodes( root_objects, nullptr, 0 );
		
	}
Esempio n. 21
0
static void add_nodes(Scene *scene, BL::BlendData b_data, BL::Scene b_scene, ShaderGraph *graph, BL::ShaderNodeTree b_ntree, PtrSockMap& sockets_map)
{
	/* add nodes */
	BL::ShaderNodeTree::nodes_iterator b_node;
	PtrNodeMap node_map;
	PtrSockMap proxy_map;

	for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
		if(b_node->mute()) {
			BL::Node::inputs_iterator b_input;
			BL::Node::outputs_iterator b_output;
			bool found_match = false;

			/* this is slightly different than blender logic, we just connect a
			 * single pair for of input/output, but works ok for the node we have */
			for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
				if(b_input->is_linked()) {
					for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
						if(b_output->is_linked() && b_input->type() == b_output->type()) {
							ProxyNode *proxy = new ProxyNode(convert_socket_type(b_input->type()), convert_socket_type(b_output->type()));
							graph->add(proxy);

							proxy_map[b_input->ptr.data] = SocketPair(proxy, proxy->inputs[0]->name);
							proxy_map[b_output->ptr.data] = SocketPair(proxy, proxy->outputs[0]->name);
							found_match = true;

							break;
						}
					}
				}

				if(found_match)
					break;
			}
		}
		else if(b_node->is_a(&RNA_NodeGroup)) {
			/* add proxy converter nodes for inputs and outputs */
			BL::NodeGroup b_gnode(*b_node);
			BL::ShaderNodeTree b_group_ntree(b_gnode.node_tree());
			if (!b_group_ntree)
				continue;

			BL::Node::inputs_iterator b_input;
			BL::Node::outputs_iterator b_output;
			
			PtrSockMap group_sockmap;
			
			for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
				ShaderSocketType extern_type = convert_socket_type(b_input->type());
				ShaderSocketType intern_type = convert_socket_type(b_input->group_socket().type());
				ShaderNode *proxy = graph->add(new ProxyNode(extern_type, intern_type));
				
				/* map the external node socket to the proxy node socket */
				proxy_map[b_input->ptr.data] = SocketPair(proxy, proxy->inputs[0]->name);
				/* map the internal group socket to the proxy node socket */
				group_sockmap[b_input->group_socket().ptr.data] = SocketPair(proxy, proxy->outputs[0]->name);
				
				/* default input values of the group node */
				set_default_value(proxy->inputs[0], *b_input, b_data, b_group_ntree);
			}
			
			for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
				ShaderSocketType extern_type = convert_socket_type(b_output->type());
				ShaderSocketType intern_type = convert_socket_type(b_output->group_socket().type());
				ShaderNode *proxy = graph->add(new ProxyNode(intern_type, extern_type));
				
				/* map the external node socket to the proxy node socket */
				proxy_map[b_output->ptr.data] = SocketPair(proxy, proxy->outputs[0]->name);
				/* map the internal group socket to the proxy node socket */
				group_sockmap[b_output->group_socket().ptr.data] = SocketPair(proxy, proxy->inputs[0]->name);
				
				/* default input values of internal, unlinked group outputs */
				set_default_value(proxy->inputs[0], b_output->group_socket(), b_data, b_group_ntree);
			}
			
			add_nodes(scene, b_data, b_scene, graph, b_group_ntree, group_sockmap);
		}
		else {
			ShaderNode *node = add_node(scene, b_data, b_scene, graph, b_ntree, BL::ShaderNode(*b_node));
			
			if(node) {
				BL::Node::inputs_iterator b_input;
				
				node_map[b_node->ptr.data] = node;
				
				for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
					SocketPair pair = node_socket_map_pair(node_map, *b_node, *b_input);
					ShaderInput *input = pair.first->input(pair.second.c_str());
					
					assert(input);
					
					/* copy values for non linked inputs */
					set_default_value(input, *b_input, b_data, b_ntree);
				}
			}
		}
	}

	/* connect nodes */
	BL::NodeTree::links_iterator b_link;

	for(b_ntree.links.begin(b_link); b_link != b_ntree.links.end(); ++b_link) {
		/* get blender link data */
		BL::Node b_from_node = b_link->from_node();
		BL::Node b_to_node = b_link->to_node();

		BL::NodeSocket b_from_sock = b_link->from_socket();
		BL::NodeSocket b_to_sock = b_link->to_socket();

		SocketPair from_pair, to_pair;

		/* links without a node pointer are connections to group inputs/outputs */

		/* from sock */
		if(b_from_node) {
			if (b_from_node.mute() || b_from_node.is_a(&RNA_NodeGroup))
				from_pair = proxy_map[b_from_sock.ptr.data];
			else
				from_pair = node_socket_map_pair(node_map, b_from_node, b_from_sock);
		}
		else
			from_pair = sockets_map[b_from_sock.ptr.data];

		/* to sock */
		if(b_to_node) {
			if (b_to_node.mute() || b_to_node.is_a(&RNA_NodeGroup))
				to_pair = proxy_map[b_to_sock.ptr.data];
			else
				to_pair = node_socket_map_pair(node_map, b_to_node, b_to_sock);
		}
		else
			to_pair = sockets_map[b_to_sock.ptr.data];

		/* either node may be NULL when the node was not exported, typically
		 * because the node type is not supported */
		if(from_pair.first && to_pair.first) {
			ShaderOutput *output = from_pair.first->output(from_pair.second.c_str());
			ShaderInput *input = to_pair.first->input(to_pair.second.c_str());

			graph->connect(output, input);
		}
	}
}
Esempio n. 22
0
int main(int argc, char *argv[])
{
    static const advgetopt::getopt::option options[] = {
        {
            '\0',
            0,
            NULL,
            NULL,
            "Usage: dep2graph [-<opt>] <package> ...",
            advgetopt::getopt::help_argument
        },
        {
            '\0',
            0,
            "admindir",
            "var/lib/wpkg",
            "define the administration directory (i.e. wpkg database folder), default is /var/lib/wpkg",
            advgetopt::getopt::required_argument
        },
        {
            '\0',
            0,
            "instdir",
            "",
            "specify the installation directory, where files get unpacked, by default the root is used",
            advgetopt::getopt::required_argument
        },
        {
            '\0',
            0,
            "root",
            "/",
            "define the root directory (i.e. where everything is installed), default is /",
            advgetopt::getopt::required_argument
        },
        {
            'o',
            0,
            "output",
            NULL,
            "define a filename where the final PNG is saved",
            advgetopt::getopt::required_argument
        },
        {
            'f',
            0,
            "filename",
            NULL,
            NULL, // hidden argument in --help screen
            advgetopt::getopt::default_multiple_argument
        },
        {
            'h',
            0,
            "help",
            NULL,
            "print this help message",
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            "help-nobr",
            NULL,
            NULL,
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            "version",
            NULL,
            "show the version of deb2graph",
            advgetopt::getopt::no_argument
        },
        {
            'v',
            0,
            "verbose",
            NULL,
            "print additional information as available",
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            "license",
            NULL,
            "displays the license of this tool",
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            "licence", // French spelling
            NULL,
            NULL, // hidden argument in --help screen
            advgetopt::getopt::no_argument
        },
        {
            '\0',
            0,
            NULL,
            NULL,
            NULL,
            advgetopt::getopt::end_of_options
        }
    };

    std::vector<std::string> configuration_files;
    advgetopt::getopt opt(argc, argv, options, configuration_files, "");

    if(opt.is_defined("help") || opt.is_defined("help-nobr"))
    {
        opt.usage(opt.is_defined("help-nobr") ? advgetopt::getopt::no_error_nobr : advgetopt::getopt::no_error, "Usage: deb2graph [-<opt>] <package> ...");
        /*NOTREACHED*/
    }

    if(opt.is_defined("version"))
    {
        printf("%s\n", debian_packages_version_string());
        exit(1);
    }

    if(opt.is_defined("license") || opt.is_defined("licence"))
    {
        license::license();
        exit(1);
    }

    bool verbose(opt.is_defined("verbose"));

    // get the size, if zero it's undefined
    int max(opt.size("filename"));
    if(max == 0)
    {
        opt.usage(advgetopt::getopt::error, "at least one debian package must be specified on the command line");
        /*NOTREACHED*/
    }

    // all these directories have a default if not specified on the command line
    manager.set_root_path(opt.get_string("root"));
    manager.set_inst_path(opt.get_string("instdir"));
    manager.set_database_path(opt.get_string("admindir"));
    manager.set_control_file_state(std::shared_ptr<wpkg_control::control_file::control_file_state_t>(new wpkg_control::control_file::contents_control_file_state_t));

    // start creating the .dot file
    dot.create(memfile::memory_file::file_format_other);
    dot.printf("digraph {\nrankdir=BT;\nlabel=\"Debian Package Dependency Graph\";\n");

    node_names_t nodes;
    node_names_t deps; // dependencies not found on the command line

    // load all the packages
    dot.printf("/* Explicit Packages */\n");
    for(int i = 0; i < max; ++i)
    {
        std::string package_filename(opt.get_string("filename", i));
        // avoid adding the exact same package more than once
        if(verbose)
        {
            printf("Package \"%s\" loaded.\n", package_filename.c_str());
        }
        manager.load_package(package_filename);
        std::string package(manager.get_field(package_filename, "Package"));
        package_info_t info;
        info.f_package = package;
        info.f_filename = package_filename;
        info.f_nodecount = node_count;
        nodes.push_back(info);
        std::string version(manager.get_field(package_filename, "Version"));
        std::string architecture(manager.get_field(package_filename, "Architecture"));
        dot.printf("n%d [label=\"%s %s\\n%s\",shape=box];\n", node_count, package.c_str(), version.c_str(), architecture.c_str());
        ++node_count;
    }

    // edges font size to small
    dot.printf("edge [fontsize=8,fontcolor=\"#990033\",color=\"#cccccc\"];\n");

    // use the dependency fields to define all the nodes of the graph
    dot.printf("edge [style=dashed];\n");
    add_nodes(nodes, deps, "Build-Depends");
    dot.printf("edge [style=bold,color=\"#8888ff\"];\n");
    add_nodes(nodes, deps, "Pre-Depends");
    dot.printf("edge [style=solid,color=\"#aaaaaa\"];\n");
    add_nodes(nodes, deps, "Depends");
    dot.printf("edge [color=\"#ff8888\"];\n");
    add_nodes(nodes, deps, "Breaks");
    dot.printf("edge [style=bold,arrowhead=tee];\n");
    add_nodes(nodes, deps, "Conflicts");

    // close the digraph
    dot.printf("}\n");

    dot.write_file("deb2graph.dot");

    std::string cmd("dot -Tsvg deb2graph.dot >");
    if(opt.is_defined("output"))
    {
        cmd += opt.get_string("output");
    }
    else
    {
        cmd += "deb2graph.svg";
    }

    const int status = system(cmd.c_str());
    if( status == -1 )
    {
        // TODO: Add a message here stating the command could not be launched...
        return 1;
    }

    return status;
}
Esempio n. 23
0
void process_input(char *input, struct Graph *g){
    int i = 0;
    char name_a[50];
    char name_b[50];
    char type[5];
    sscanf(input, "%s %s %s", type, name_a, name_b);
    if(!strcmp(type,"new")){
        add_new_node(name_a, g);
    }
    else if(!strcmp(type,"link")){
        add_new_link(name_a, name_b, g);
    }
    else if(!strcmp(type,"out")){
        print_outgoing_nodes(name_a, g);
    }
    else if(!strcmp(type,"in")){
        print_incoming_nodes(name_a, g);
    }
    else if(!strcmp(type,"wn")){
        write_data_prompt(name_a, g);
    }
    else if(!strcmp(type,"rn")){
        read_data(name_a, g);
    }
    else if(!strcmp(type, "all")){
        print_graph(g);
    }
    else if(!strcmp(type,"wl")){
        write_link_data_prompt(name_a, name_b, g);
    }
    else if(!strcmp(type,"rl")){
        read_link_data(name_a, name_b, g);
    }
    else if(!strcmp(type, "path")){
        // printf("Hey");
        test_for_path(name_a, name_b, g);
    }
    else if(!strcmp(type, "save")){
        save_to_disk(g, name_a);
    }
    else if(!strcmp(type, "load")){
        read_from_disk(name_a, g);
    }
    else if(!strcmp(type, "getl")){
        get_links(g);
        // all links (node pairs) with X data
    }
    else if(!strcmp(type, "getn")){
        get_nodes(g);
        // all nodes with X data
    }
    else if(!strcmp(type, "add")){
        add_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "div")){
        divide_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "sub")){
        subtract_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "mult")){
        multiply_nodes(name_a, name_b, g);
    }
    else if(!strcmp(type, "cmd")){
        run_command(name_a, g);
    }
    else if(!strcmp(type, "id")){
        long long_val;
        long_val = strtol(name_a, NULL, 10);
        int id = (int) long_val;
        struct Node *node; 
        node = get_node_by_id(id, g);
        if(!strcmp(node->name, "NULL")){
            printf("{ \"error\": \"No node with id %d\" }\n", id);
            free(node->name);
            free(node);
        } else {
            printf("{ \"id: %d, \"name\": \"%s\", \"data\": \"%s\" }\n", id, node->name, node->data);
        }
    }
}