Example #1
0
// ツリーを作る
Neuron* create_tree(float traning_data[135][4], char traning_result[135][20]) {
    
    int i;
    int node_num;
    Neuron *root, *nearest, *new_node;
    node_num = 0;
    root = create_node(traning_data[0], traning_result[0], node_num);
    for (i = 1; i<135; i++) {
        //      rootのもつ子ノードと比較しe[i][j]との距離が最も近いものを探索する
        nearest = test(traning_data[i], root);
        //      winnerが葉ノードであったとき
        if (is_leaf(nearest)) {
            node_num++;
            new_node = create_node(nearest->weight, nearest->result, node_num);
            connect_node(new_node, nearest);
        }
        node_num++;
        new_node = create_node(traning_data[i], traning_result[i], node_num);
        connect_node(new_node, nearest);
        update(nearest);
    }
    
    return root;
    
}
Example #2
0
void cli_node_list(int sock, struct node_list_packet *nlp, struct node_list_entry *entries) {
	pthread_mutex_t mutex;
	int next = 0;
	
	pthread_mutex_lock(&peer_list_mutex);
	for (unsigned int i = 0; i < nlp->count; i++) {
		next = 0;
		for (unsigned int j = 0; j < peers.size(); j++) {
			if (peers[j].addr == entries[i].addr && peers[j].port == entries[i].port)
				next = 1;
		}

		if (next)
			continue;

		peers.push_back(entries[i]);
		peer_srv_socks.push_back(-1);
		peer_cli_socks.push_back(-1);
		peer_locks.push_back(mutex);
		pthread_mutex_init(&peer_locks.back(), NULL);

		connect_node(peers.size() - 1);
	}
	pthread_mutex_unlock(&peer_list_mutex);
}
Example #3
0
// Connects every 2 nodes in the shortest path.
void build_path(struct point* tail, struct node* startnode){
    while(startnode->child){
        struct point* temp = connect_node(tail, startnode, startnode->child);
        startnode = startnode->child;
        tail = temp;
    }
    tail->next = NULL; 
}
Example #4
0
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static MatItem *mat_livedb_add_mat_element(Main *bmain, bContext *C, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to, MatItem **_item, char* file_path, float x_pos, float *y_pos)
{
    MatItem          *ptr;
    MatItem          *item = *_item;
    char             tex_file_name[1024];

    bNodeSocket             *sock;

    switch (item->type) {
        case MAT_LDB_VALUE_TYPE_EMPTY: {
            *_item = (MatItem*)((char*)item + item->size);
            break;
        }
        case MAT_LDB_VALUE_TYPE_FLINK: {
            ptr = (MatItem*) ((char*)item - item->uint_vector[0]);
            mat_livedb_add_mat_element(bmain, C, ntree, node_to, 0, &ptr, file_path, 0, 0);

            *_item = (MatItem*)((char*)item + item->size);
            break;
        }
        case MAT_LDB_VALUE_TYPE_NLINK: {
            bNode *linked_node = *((bNode**) ((MatItem*)((char*)item - item->uint_vector[0]))->data);

            connect_node(bmain, ntree, linked_node, node_to, sock_to);

            *_item = (MatItem*)((char*)item + item->size);
            break;
        }
        case MAT_LDB_VALUE_TYPE_NODE: {
            if(sock_to->type == SOCK_FLOAT && sock_to->default_value && !strcmp(item->data, "ShaderNodeOctFloatTex")) {
                item = (MatItem*)((char*)item + item->size);

                ((bNodeSocketValueFloat*)sock_to->default_value)->value = item->float_vector[0];

                *_item = (MatItem*)((char*)item + item->size);
            }
            else if(sock_to->type == SOCK_RGBA && sock_to->default_value && !strcmp(item->data, "ShaderNodeOctRGBSpectrumTex")) {
                item = (MatItem*)((char*)item + item->size);

                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[0] = item->float_vector[0];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[1] = item->float_vector[1];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[2] = item->float_vector[2];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[3] = item->float_vector[3];

                *_item = (MatItem*)((char*)item + item->size);
            }
            else {
                float   cur_y_pos;
                int     node_height     = U.widget_unit;
                bool    childs_present  = false;
                bNode   *node_fr        = nodeAddNode(C, ntree, item->data);

                connect_node(bmain, ntree, node_fr, node_to, sock_to);

                *_item = (MatItem*)((char*)item + item->size);
                ptr = *_item;

                *((bNode**)item->data) = node_fr;

                if(node_fr->type == SH_NODE_OCT_IMAGE_TEX || node_fr->type == SH_NODE_OCT_FLOAT_IMAGE_TEX || node_fr->type == SH_NODE_OCT_ALPHA_IMAGE_TEX) {
                    mat_livedb_add_mat_element(bmain, C, ntree, node_fr, 0, &ptr, file_path, 0, 0);
                    node_height += (U.widget_unit * 2.5);
                }

                node_fr->locx = x_pos - node_fr->width - LDB_NODES_H_GAP;
                node_fr->locy = cur_y_pos = *y_pos;

                for (sock = node_fr->inputs.first; sock; sock = sock->next) {
                    if(!sock) continue;
                    if(!childs_present) childs_present = true;
                    node_height += U.widget_unit;

                    mat_livedb_add_mat_element(bmain, C, ntree, node_fr, sock, &ptr, file_path, node_fr->locx, &cur_y_pos);
                }

                if(node_fr->type == SH_NODE_OCT_GRADIENT_TEX) {
                    mat_livedb_add_mat_element(bmain, C, ntree, node_fr, 0, &ptr, file_path, 0, 0);
                    node_height += (U.widget_unit * 2.5);
                }

                *_item = ptr;

                *y_pos -= (node_height + LDB_NODES_V_GAP);
                if(childs_present) *y_pos = (*y_pos < cur_y_pos ? *y_pos : cur_y_pos);
            }
            break;
        }
        case MAT_LDB_VALUE_TYPE_INT:
            if(sock_to->default_value)
                ((bNodeSocketValueInt*)sock_to->default_value)->value = item->int_vector[0];

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_INT2:
            if(sock_to->default_value) {
                ((bNodeSocketValueVector*)sock_to->default_value)->value[0] = item->int_vector[0];
                ((bNodeSocketValueVector*)sock_to->default_value)->value[1] = item->int_vector[1];
            }

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_INT3:
            if(sock_to->default_value) {
                ((bNodeSocketValueVector*)sock_to->default_value)->value[0] = item->int_vector[0];
                ((bNodeSocketValueVector*)sock_to->default_value)->value[1] = item->int_vector[1];
                ((bNodeSocketValueVector*)sock_to->default_value)->value[2] = item->int_vector[2];
            }

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_INT4:
            if(sock_to->default_value) {
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[0] = item->int_vector[0];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[1] = item->int_vector[1];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[2] = item->int_vector[2];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[3] = item->int_vector[3];
            }

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_FLOAT:
            if(sock_to->default_value)
                ((bNodeSocketValueFloat*)sock_to->default_value)->value = item->float_vector[0];

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_FLOAT2:
            if(sock_to->default_value) {
                ((bNodeSocketValueVector*)sock_to->default_value)->value[0] = item->float_vector[0];
                ((bNodeSocketValueVector*)sock_to->default_value)->value[1] = item->float_vector[1];
            }

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_FLOAT3:
            if(sock_to->default_value) {
                ((bNodeSocketValueVector*)sock_to->default_value)->value[0] = item->float_vector[0];
                ((bNodeSocketValueVector*)sock_to->default_value)->value[1] = item->float_vector[1];
                ((bNodeSocketValueVector*)sock_to->default_value)->value[2] = item->float_vector[2];
            }

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_FLOAT4:
            if(sock_to->default_value) {
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[0] = item->float_vector[0];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[1] = item->float_vector[1];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[2] = item->float_vector[2];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[3] = item->float_vector[3];
            }

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_BOOL:
            if(sock_to->default_value)
                ((bNodeSocketValueBoolean*)sock_to->default_value)->value = item->int_vector[0];

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_STRING:
            if(sock_to->default_value)
                strcpy(((bNodeSocketValueString*)sock_to->default_value)->value, item->data);

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_COLOR:
            if(sock_to->default_value) {
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[0] = item->float_vector[0];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[1] = item->float_vector[1];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[2] = item->float_vector[2];
                ((bNodeSocketValueRGBA*)sock_to->default_value)->value[3] = item->float_vector[3];
            }

            *_item = (MatItem*)((char*)item + item->size);
            break;
        case MAT_LDB_VALUE_TYPE_FILE: {
            char* file_name;
            FILE *file;
            struct Image *ima = (struct Image*)node_to->id;

            file_name = item->data + sizeof(uint32_t);

            if(file_name[0]) {
                strcpy(tex_file_name, file_path);
                strcat(tex_file_name, file_name);

                file = BLI_fopen(tex_file_name, "rb");
                if(!file) {
                    file = BLI_fopen(tex_file_name, "wb");
                    if(file) {
                        if(!fwrite(item->data + sizeof(uint32_t) + strlen(file_name) + 1, *((uint32_t*)item->data), 1, file)) {
                        }
                        fclose(file);
                    }
                }
                else fclose(file);
            }
            else tex_file_name[0] = 0;

            if(!ima)
                node_to->id = (struct ID*)BKE_image_load_exists(tex_file_name);

            *_item = (MatItem*)((char*)item + item->size);
            break;
        }
        case MAT_LDB_VALUE_TYPE_RAMP: {
            char* file_name;
            FILE *file;
            struct ColorBand *coba = (struct ColorBand*)node_to->storage;

            RampItem *ramp_item = (RampItem*)item->data;

            if(coba && ramp_item->pos_cnt > 1) {
                int i;
                coba->tot = ramp_item->pos_cnt;
                for(i = 0; i < ramp_item->pos_cnt; ++i) {
                    coba->data[i].pos   = ramp_item->pos_data[i * 4 + 0];
                    coba->data[i].r     = ramp_item->pos_data[i * 4 + 1];
                    coba->data[i].g     = ramp_item->pos_data[i * 4 + 2];
                    coba->data[i].b     = ramp_item->pos_data[i * 4 + 3];
                    coba->data[i].a     = 1.0;
                }
            }

            *_item = (MatItem*)((char*)item + item->size);
            break;
        }
        default:
            break;
    }
    return *_item;
} /* mat_livedb_add_mat_element */