int main() { int dev_fd = open(DEVICE_NAME, O_RDONLY); if (dev_fd >= 0) { if (!get_status(dev_fd)) enable_sensor(dev_fd, 1); } else { printf("Light sensor swith has not found.\n"); } double sum_light = 0; int count_light = 0; char * device = get_device("lightsensor-level"); if (device) { printf("devices: %s\n", device); char one_dev[128] = "/dev/input/"; char * read_pos = device; while (read_pos < (device + strlen(device))) { char * end_pos = read_pos; while ( *end_pos != 0 && *end_pos != ' ') end_pos ++; strncpy(one_dev + strlen("/dev/input/"), read_pos, min_value(127, end_pos - read_pos)); one_dev[strlen("/dev/input/") + min_value(127, end_pos - read_pos) - 1] = 0; read_pos = end_pos + 1; int input_fd = open(one_dev, O_RDONLY); if (input_fd >= 0) { printf("Try use:'%s'\n", one_dev); sum_light += get_abs_value(input_fd); count_light ++; } else { printf("Cant access to '%s'\n", one_dev); } } free(device); } else { printf("Light sensor has not found.\n"); } int cam_value = v4l_cam_value("/dev/video0"); if (cam_value >= 0) { printf("v4l value = %d\n", cam_value); sum_light += cam_value; count_light ++; } if (count_light) { sum_light = sum_light / count_light; } printf("Light value = %d lux\n", cam_value); update_lights(sum_light); // flashlight // /sys/class/leds/flashlight/brightness // 0 - none // 1 - bottom // 2 - top // 3 - both }
double min_value(t_tree tree, double min) { if (!tree) return (min); if (tree->value < min) min = tree->value; if (tree->left) return (min_value(tree->left, min)); if (tree->right) return (min_value(tree->right, min)); }
int isStackSortable(int * array, int len) { if(len < 3) { return TRUE ; } int max_index = max_value(array, len) ; int left_max ; int right_min ; if(max_index == 0) { left_max = 0 ; right_min = array[min_value(array+1,len-1) + 1] ; if(left_max > right_min) { return FALSE ; } return isStackSortable(array+1, len-1) ; } if(max_index == (len-1) ) { left_max = array[max_value(array,len-1)]; right_min = array[len-1] ; if(left_max > right_min) { return FALSE ; } return isStackSortable(array, len-1) ; } left_max = array[max_value(array,max_index)] ; right_min = array[min_value(array+max_index+1,(len -max_index - 1) )+ max_index+1] ; if(left_max > right_min) { return FALSE ; } int left = isStackSortable(array,max_index) ; int right = isStackSortable(array+max_index+1,(len-max_index-1)) ; if(left == TRUE && right == TRUE) { return TRUE ; } else { return FALSE ; } }
void find_meeting_schedule(int slots[][],int n){ //Busy slot Tracker(in which meeting can't be arranged at any cost) in four variables int from=0,to=0; int i; int temp_from,temp_to; for(i=0;i<n;i++){ temp_from=convert_to_minute(slot[i][0],slot[i][1]); temp_to=convert_to_minute(slot[i][2],slot[i][3]); if(temp_from>temp_to){ printf("Slots not in order"); return; } //is this first busy slot?if yes! store busy schedule in four variables declared above if(i==0){ from=temp_from; to=temp_to; continue;} if(temp_from<=to)from=min_value(from,temp_from); else {meeting_from=from;meeting_to=temp_from;} if(temp_to>=from)to=max_value(to,temp_to); else {meeting_to=from;meeting_to=temp_from;} } }
bool is_bst1(tree_node* T) { /* Returns true if a binary tree is a binary search tree. */ if(T!=NULL) { bool is_leaf = (T->left ==NULL) && (T->right == NULL); if(is_leaf) return true; if(max_value(T) <= T->data && T->right !=NULL) return false; if(min_value(T) > T->data && T->left!=NULL) return false; if(!is_bst1(T->left)) return false; if(!is_bst1(T->right)) return false; return true; } else return true; }
position* TicTacToeState::get_move() { position* p = NULL; // Initialize random seed srand (time(NULL)); // Get a random number for a move int r = rand() % 10; // esay mode will have 70% random moves // hard mode will have 50% random moves // impossivle mode will no random moves if ((mode == "easy" && r >= 3) || (mode == "hard" && r >= 5) ) index = rand() % actions.size(); else { unsigned int depth = 0; // 'O' always tries to minimize the value // 'X' always tries to maximize the value if (player == p2_symbol) min_value(depth); else max_value(depth); } p = &actions[index]; return p; }
npy_int64 get_daytime_conversion_factor(int index1, int index2) { if (daytime_conversion_factor_matrix == NULL) { initialize_daytime_conversion_factor_maxtrix(); } return daytime_conversion_factor_matrix[min_value(index1, index2)][max_value(index1, index2)]; }
int min_value(bst *b) { if(!b) return INT_MIN; if(!b->left) return b->val; return min_value(b->left); }
double btree_get_min_value(t_tree tree) { double min; if (!tree) return (0); min = tree->value; return (min_value(tree, min)); }
/* Used to build and send any type of packet as a part of a session */ int session_send_data(session_t *session, char *data) { /* Holders for the Data send and the ack packets */ char d_pkt[PKT_SIZE_DATA]; char d_ack[PKT_SIZE_DATA_ACK]; data_ack_pkt *d_ack_t; int recv_packet_len; int error; task *task_t; int ret = 0; while (session->no_of_packets) { build_pkt_data(session, data, d_pkt); /* Send the data packet. Size = header + data */ task_t = session_send_packet(session, d_pkt, 11 + min_value(MAX_FRAME_SIZE, session->no_of_bytes), &error); while (1) { ret = session_receive_packet(session, d_ack, &recv_packet_len, &error); if (ret == PROPER_PACKET) { d_ack_t = (data_ack_pkt *) d_ack; /* Check of we got the correct packet type and the expected sequence sequence number */ if (d_ack_t->type == PKT_TYPE_DATA_ACK && d_ack_t->exp_frame_number == session->next_frame_number + 1) { log_mesg("Expected ACK %d\n", d_ack_t->exp_frame_number); /* One packet sent properly */ session->no_of_packets--; session->no_of_bytes-=MAX_FRAME_SIZE; /* Update the sequence number */ session->next_frame_number++; delete_task(task_t); break; } else { continue; } } else if (ret == WIRELESS_DOWN) { continue; } else if (ret == SERVER_CRASH) { delete_task(task_t); return -1; } } } return 0; }
int is_bst(bst *b) { if(!b || (!b->left && !b->right) ) return 1; int min = min_value(b->left); int max = max_depth(b->right); if( !( b->val >= min && b->val < max)) return 0; return is_bst(b->left) && is_bst(b->right); }
UStatus ua_sensors_orientation_get_min_value( UASensorsOrientation* sensor, float* value) { if (sensor == NULL || value == NULL) return U_STATUS_ERROR; ALOGI("%s():%d", __PRETTY_FUNCTION__, __LINE__); auto s = static_cast<ubuntu::application::sensors::Sensor*>(sensor); *value = s->min_value(); return U_STATUS_SUCCESS; }
/* Build a data packet */ void build_pkt_data (session_t *session, char *data, char *packet) { data_pkt dpkt_t; dpkt_t.type = PKT_TYPE_DATA; dpkt_t.session_id = session->session_id; dpkt_t.length = min_value(MAX_FRAME_SIZE, session->no_of_bytes); dpkt_t.seq_num = session->next_frame_number; data += session->next_frame_number * MAX_FRAME_SIZE; memcpy(&dpkt_t.data, data, dpkt_t.length); log_mesg("Buildinf DATA packet Type : %d Session : %d Length %d Seq_num %d Data pointer %d\n", dpkt_t.type, dpkt_t.session_id, dpkt_t.length, dpkt_t.seq_num, session->next_frame_number * MAX_FRAME_SIZE); memcpy(packet, &dpkt_t, PKT_SIZE_DATA); }
/* * Main function for testing min_value()... */ int main(int argc, char** argv) { printf("min_value(-1) minimum is %d\n", min_value(-1)); printf("min_value(100,12,99,-1) minimum is %d\n", min_value(100,12,99,-1)); printf("min_value(3,12,15,-1) minimum is %d\n", min_value(3,12,15,-1)); printf("min_value(90,80,70,-1) minimum is %d\n", min_value(90,80,70,-1)); printf("min_value(-1) minimum is %d\n", min_value(-1)); printf("min_value(1,0,1,0,-1) minimum is %d\n", min_value(1,0,1,0,-1)); return (EXIT_SUCCESS); }
int main(void){ LL t,empty,full; int n,i; scanf("%lld",&t); while(t--){ scanf("%lld %lld",&empty,&full); scanf("%d",&n); for(i=0;i<n;i++){ scanf("%lld %lld",p+i,w+i); } LL val = min_value(empty,full,n); if(val>=0) printf("The minimum amount of money in the piggy-bank is %lld.",val); else printf("This is impossible."); printf("\n"); } return 0; }
int max_value(char piece1, char piece2, int a, int b, char **board, int currstate) { int utility=terminal_test(board), x, y, minimax=-100000, temp, cont=0; //if bottom of tree reached if (terminal_test(board)!=INCOMPLETE) { //return utility value of the board return utility; } for (x=0; x<3; x++) { for (y=0; y<3; y++) { //for each successor of the current board if (board[x][y]==BLANK) { board[x][y]=piece1; //get minimax value of its successor temp=min_value(piece2, piece1, a, b, board, 0); //find maximum of all minimax values of its successors if (temp>minimax) { minimax=temp; cont = 1; } //if minimax value of a successor >= beta of its predecessor, if (minimax>=b) { //skip this node since predecessor will never choose this node board[x][y]=BLANK; return minimax; } a=max(a, minimax); //if current state's successor minimax is the maximum value so far if (currstate && cont) { //assign corresponding x- and y- coordinates comp_x=x; comp_y=y; } board[x][y]=BLANK; } } } return minimax; }
/* * Parse list input devices from /proc/bus/input/devices */ char * get_device(const char * dev_name) { int fd = open("/proc/bus/input/devices", O_RDONLY); if (fd < 0) { printf("can't get input list\n"); return NULL; } struct stat sb; int file_size = 0; if (fstat(fd, &sb) != 1) { file_size = sb.st_size; } if (!file_size) file_size = 256; char* buffer = malloc(file_size + 1); int read_done = 0; int res = 0; while ((res = read(fd, buffer + read_done, 256)) > 0) { read_done += res; if ((read_done + 256) > file_size) { buffer = realloc(buffer, file_size + 256); file_size += 256; } } close(fd); buffer[read_done + 1] = 0; if (res < 0) { printf("can't read\n"); return NULL; } file_size = read_done; char name[129] = {0}; char device[129] = {0}; char * read_pos = buffer; while (read_pos < buffer + file_size) { char* end_pos = read_pos; // get end of line while ((end_pos < buffer + file_size) && (*end_pos != '\n')) end_pos ++; // check name if ((end_pos - read_pos) >= strlen("N: Name=")) { if (strncmp(read_pos, "N: Name=", strlen("N: Name=")) == 0) { read_pos += strlen("N: Name="); if (*read_pos == '"') read_pos ++; strncpy(name, read_pos, min_value(128, end_pos - read_pos)); name[min_value(128, end_pos - read_pos)] = 0; if (name[min_value(128, end_pos - read_pos) -1] == '"') name[min_value(128, end_pos - read_pos) -1] = 0; read_pos = end_pos; //skip final \n if(read_pos < (buffer + file_size)) read_pos ++; continue; } } // check handler if ((end_pos - read_pos) >= strlen("H: Handlers=")) { if (strncmp(read_pos, "H: Handlers=", strlen("H: Handlers=")) == 0) { read_pos += strlen("H: Handlers="); strncpy(device, read_pos, min_value(128, end_pos - read_pos)); device[min_value(128, end_pos - read_pos)] = 0; read_pos = end_pos; //skip final \n if(read_pos < (buffer + file_size)) read_pos ++; continue; } } if (((end_pos - read_pos) >= 1 && *read_pos == '\n') || ((end_pos - read_pos) == 0)) { if (strcmp(dev_name, name) == 0) { free(buffer); return strdup(device); } name[0] = 0; device[0] = 0; if(read_pos < (buffer + file_size)) read_pos ++; continue; } read_pos = end_pos + 1; } free(buffer); return NULL; }
bool Loader_obj::load_model_data(Model& mdl, QString path){ QStringList pathlist = path.split("/",QString::KeepEmptyParts); //KeepEmptyParts QString model_name = pathlist.last(); //LOAD MESH DATA QFile file(path); if (!file.open (QIODevice::ReadOnly)) { qDebug(" Model import: Error 1: Model file could not be loaded..."); return false; } QTextStream stream ( &file ); QString line; QString mtllib; QString current_mesh; QMap<QString,QVector<int> >mesh_faces; QMap<QString,QString> mesh_mtl; QMap<QString,Material* > mtln_mtl; QVector<Vector3> model_vertices; QVector<Vector3> model_vertex_normals; QVector<Vector3> model_vertex_texture_coordinates; while( !stream.atEnd() ) { line = stream.readLine(); QStringList list = line.split(QRegExp("\\s+"),QString::SkipEmptyParts); //SkipEmptyParts if(!list.empty()){ if(list.first() == "mtllib"){ mtllib = list.last(); } else if(list.first() == "v"){ model_vertices.append(Vector3( list.value(1).toFloat(), list.value(2).toFloat(), list.value(3).toFloat())); } else if(list.first() == "vn"){ model_vertex_normals.append(Vector3( list.value(1).toFloat(), list.value(2).toFloat(), list.value(3).toFloat())); } else if(list.first() == "vt"){ model_vertex_texture_coordinates.append(Vector3( list.value(1).toFloat(), list.value(2).toFloat(), list.value(3).toFloat())); } else if(list.first() == "g"){ current_mesh = list.value(1); } else if(list.first() == "usemtl"){ mesh_mtl[current_mesh] = list.value(1); } else if(list.first() == "f"){ QStringList face_part_1_list = list.value(1).split("/",QString::SkipEmptyParts); //SkipEmptyParts QStringList face_part_2_list = list.value(2).split("/",QString::SkipEmptyParts); //SkipEmptyParts QStringList face_part_3_list = list.value(3).split("/",QString::SkipEmptyParts); //SkipEmptyParts mesh_faces[current_mesh].append(face_part_1_list.value(0).toInt()); mesh_faces[current_mesh].append(face_part_1_list.value(1).toInt()); mesh_faces[current_mesh].append(face_part_1_list.value(2).toInt()); mesh_faces[current_mesh].append(face_part_2_list.value(0).toInt()); mesh_faces[current_mesh].append(face_part_2_list.value(1).toInt()); mesh_faces[current_mesh].append(face_part_2_list.value(2).toInt()); mesh_faces[current_mesh].append(face_part_3_list.value(0).toInt()); mesh_faces[current_mesh].append(face_part_3_list.value(1).toInt()); mesh_faces[current_mesh].append(face_part_3_list.value(2).toInt()); } } } file.close(); //LOAD MTL DATA pathlist.removeAt(pathlist.length()-1); QString mtl_path = pathlist.join("/") + "/" + mtllib; QString tex_path = pathlist.join("/") + "/"; QFile mtlfile(mtl_path); if (!mtlfile.open (QIODevice::ReadOnly)) { qDebug(" Model import: Error 2: Model material file could not be loaded..."); return false; } QTextStream mtlstream ( &mtlfile ); QString mtlline; QString current_mtl; QMap<QString,Vector3> mtl_ambient_c; //Ka QMap<QString,Vector3> mtl_diffuse_c; //Kd QMap<QString,Vector3> mtl_specular_c; //Ks QMap<QString,float> mtl_specular_ns; //Ns QMap<QString,float> mtl_transparency_d; //d QMap<QString,float> mtl_transparency_tr; //Tr QMap<QString,Vector3> mtl_transparency_tf; //Tf QMap<QString,QString> mtl_ambient_map; //map_Ka QMap<QString,QString> mtl_diffuse_map; //map_Kd QMap<QString,QString> mtl_specular_map; //map_Ks QMap<QString,QString> mtl_bump_map; //map_bump QMap<QString,int> mtl_illumination; //illum //stream while( !mtlstream.atEnd() ) { mtlline = mtlstream.readLine(); QStringList list = mtlline.split(QRegExp("\\s+"),QString::SkipEmptyParts); //SkipEmptyParts if(!list.empty()){ if(list.first() == "newmtl"){ current_mtl = list.last(); } else if(list.first() == "Ka"){ mtl_ambient_c[current_mtl] = Vector3(list.value(1).toFloat(), list.value(2).toFloat(), list.value(3).toFloat()); } else if(list.first() == "Kd"){ mtl_diffuse_c[current_mtl] = Vector3(list.value(1).toFloat(), list.value(2).toFloat(), list.value(3).toFloat()); } else if(list.first() == "Ks"){ mtl_specular_c[current_mtl] = Vector3(list.value(1).toFloat(), list.value(2).toFloat(), list.value(3).toFloat()); } else if(list.first() == "Ns"){ mtl_specular_ns[current_mtl] = list.value(1).toFloat(); } else if(list.first() == "d"){ mtl_transparency_d[current_mtl] = list.value(1).toFloat(); } else if(list.first() == "Tr"){ mtl_transparency_tr[current_mtl] = list.value(1).toFloat(); } else if(list.first() == "Tf"){ mtl_transparency_tf[current_mtl] = Vector3(list.value(1).toFloat(), list.value(2).toFloat(), list.value(3).toFloat()); } else if(list.first() == "map_Ka"){ mtl_ambient_map[current_mtl] = list.value(1).split("\\",QString::SkipEmptyParts).last().toUtf8(); } else if(list.first() == "map_Kd"){ mtl_diffuse_map[current_mtl] = list.value(1).split("\\",QString::SkipEmptyParts).last().toUtf8(); } else if(list.first() == "map_Ks"){ mtl_specular_map[current_mtl] = list.value(1).split("\\",QString::SkipEmptyParts).last().toUtf8(); } else if((list.first() == "map_bump") || (list.first() == "bump")){ mtl_bump_map[current_mtl] = list.value(1).split("\\",QString::SkipEmptyParts).last().toUtf8(); } else if(list.first() == "illum"){ mtl_illumination[current_mtl] = list.value(1).toInt(); } } } //stream end //CREATE MTLS (if needed...) //using diffues mat cause its the major map used (other maps are optional)... QList<QString> mtl_names = mtl_diffuse_c.keys(); for(int i = 0; i < mtl_names.length(); i++){ Material* mtl = new Material(mtl_names.value(i),tex_path); mtl->set_ambient_c(mtl_ambient_c[mtl_names.value(i)]); mtl->set_diffuse_c(mtl_diffuse_c[mtl_names.value(i)]); mtl->set_specular_c(mtl_specular_c[mtl_names.value(i)]); mtl->set_specular_ns(mtl_specular_ns[mtl_names.value(i)]); mtl->set_transparency_d(mtl_transparency_d[mtl_names.value(i)]); mtl->set_transparency_tr(mtl_transparency_tr[mtl_names.value(i)]); mtl->set_transparency_tf(mtl_transparency_tf[mtl_names.value(i)]); mtl->set_ambient_map_name(mtl_ambient_map[mtl_names.value(i)]); mtl->set_diffuse_map_name(mtl_diffuse_map[mtl_names.value(i)]); mtl->set_specular_map_name(mtl_specular_map[mtl_names.value(i)]); mtl->set_bump_map_name(mtl_bump_map[mtl_names.value(i)]); mtl->set_illumination(mtl_illumination[mtl_names.value(i)]); //init texture maps //as this function gets called in a thread we need to do this in main... /* mtl->load_ambient_map(tex_path + mtl_ambient_map[mtl_names.value(i)]); mtl->load_diffuse_map(tex_path + mtl_diffuse_map[mtl_names.value(i)]); mtl->load_specular_map(tex_path + mtl_specular_map[mtl_names.value(i)]); mtl->load_bump_map(tex_path + mtl_bump_map[mtl_names.value(i)]); */ mtl->set_ambient_map_path(tex_path + mtl_ambient_map[mtl_names.value(i)]); mtl->set_diffuse_map_path(tex_path + mtl_diffuse_map[mtl_names.value(i)]); mtl->set_specular_map_path(tex_path + mtl_specular_map[mtl_names.value(i)]); mtl->set_bump_map_path(tex_path + mtl_bump_map[mtl_names.value(i)]); mtl->loadData(); /* qDebug(" MTL ambient m: " + mtl->get_ambient_map_name().toUtf8()); qDebug(" MTL diffuse m: " + mtl->get_diffuse_map_name().toUtf8()); qDebug(" MTL specular m: " + mtl->get_specular_map_name().toUtf8()); qDebug(" MTL bump m: " + mtl->get_bump_map_name().toUtf8()); */ mtln_mtl[mtl_names.value(i)] = mtl; } //CREATE MESHS (if needed...) //QMap<QString,QVector<QVector3D> > mesh_faces; //QMap<QString,QString> mesh_mtl; //QVector<QVector3D> model_vertices; //QVector<QVector3D> model_vertex_normals; //QVector<QVector3D> model_vertex_texture_coordinates; //using mesh_mtl to iterate ... QList<QString> mesh_names = mesh_mtl.keys(); for(int i = 0; i < mesh_names.length(); i++){ //min/max vertex pos on all 3 axis GLfloat v_min_x = 0.0f; GLfloat v_max_x = 0.0f; GLfloat v_min_y = 0.0f; GLfloat v_max_y = 0.0f; GLfloat v_min_z = 0.0f; GLfloat v_max_z = 0.0f; int triangle_count = mesh_faces[mesh_names.value(i)].size() / 3 / 3; //qDebug(" Triangles: %i",triangle_count); GLfloat* vertices = new GLfloat[mesh_faces[mesh_names.value(i)].size()]; GLfloat* texcoords = new GLfloat[mesh_faces[mesh_names.value(i)].size()]; //should be wrong ... 108/3*2 is right ... GLfloat* normals = new GLfloat[mesh_faces[mesh_names.value(i)].size()]; //qDebug("Mesh..."); for(int j = 0; j < mesh_faces[mesh_names.value(i)].size(); j+=9){ // 1 v/vt/vn 2 v/vt/vn 3 v/vt/vn // v Vector3 vertex1 = model_vertices.value(mesh_faces[mesh_names.value(i)].value(j) -1); vertices[j] = (GLfloat) vertex1.x(); vertices[j+1] = (GLfloat) vertex1.y(); vertices[j+2] = (GLfloat) vertex1.z(); Vector3 vertex2 = model_vertices.value(mesh_faces[mesh_names.value(i)].value(j+3)-1); vertices[3+j] = (GLfloat) vertex2.x(); vertices[3+j+1] = (GLfloat) vertex2.y(); vertices[3+j+2] = (GLfloat) vertex2.z(); Vector3 vertex3 = model_vertices.value(mesh_faces[mesh_names.value(i)].value(j+6)-1); vertices[6+j] = (GLfloat) vertex3.x(); vertices[6+j+1] = (GLfloat) vertex3.y(); vertices[6+j+2] = (GLfloat) vertex3.z(); //get the min/max vertex pos on all 3 axis //x axis v_min_x = min_value(v_min_x,vertex1.x()); v_min_x = min_value(v_min_x,vertex2.x()); v_min_x = min_value(v_min_x,vertex3.x()); v_max_x = max_value(v_max_x,vertex1.x()); v_max_x = max_value(v_max_x,vertex2.x()); v_max_x = max_value(v_max_x,vertex3.x()); //y axis v_min_y = min_value(v_min_y,vertex1.y()); v_min_y = min_value(v_min_y,vertex2.y()); v_min_y = min_value(v_min_y,vertex3.y()); v_max_y = max_value(v_max_y,vertex1.y()); v_max_y = max_value(v_max_y,vertex2.y()); v_max_y = max_value(v_max_y,vertex3.y()); //z axis v_min_z = min_value(v_min_z,vertex1.z()); v_min_z = min_value(v_min_z,vertex2.z()); v_min_z = min_value(v_min_z,vertex3.z()); v_max_z = max_value(v_max_z,vertex1.z()); v_max_z = max_value(v_max_z,vertex2.z()); v_max_z = max_value(v_max_z,vertex3.z()); // vt (t value inverted) Vector3 texcoord1 = model_vertex_texture_coordinates.value(mesh_faces[mesh_names.value(i)].value(j+1)-1); texcoords[j] = (GLfloat) texcoord1.x(); texcoords[j+1] = (GLfloat) -texcoord1.y(); texcoords[j+2] = (GLfloat) texcoord1.z(); Vector3 texcoord2 = model_vertex_texture_coordinates.value(mesh_faces[mesh_names.value(i)].value(j+4)-1); texcoords[3+j] = (GLfloat) texcoord2.x(); texcoords[3+j+1] = (GLfloat) -texcoord2.y(); texcoords[3+j+2] = (GLfloat) texcoord2.z(); Vector3 texcoord3 = model_vertex_texture_coordinates.value(mesh_faces[mesh_names.value(i)].value(j+7)-1); texcoords[6+j] = (GLfloat) texcoord3.x(); texcoords[6+j+1] = (GLfloat) -texcoord3.y(); texcoords[6+j+2] = (GLfloat) texcoord3.z(); // vn Vector3 normal1 = model_vertex_normals.value(mesh_faces[mesh_names.value(i)].value(j+2)-1); normal1.normalize(); //normalize normals[j] = (GLfloat) normal1.x(); normals[j+1] = (GLfloat) normal1.y(); normals[j+2] = (GLfloat) normal1.z(); Vector3 normal2 = model_vertex_normals.value(mesh_faces[mesh_names.value(i)].value(j+5)-1); normal2.normalize(); //normalize normals[3+j] = (GLfloat) normal2.x(); normals[3+j+1] = (GLfloat) normal2.y(); normals[3+j+2] = (GLfloat) normal2.z(); Vector3 normal3 = model_vertex_normals.value(mesh_faces[mesh_names.value(i)].value(j+8)-1); normal3.normalize(); //normalize normals[6+j] = (GLfloat) normal3.x(); normals[6+j+1] = (GLfloat) normal3.y(); normals[6+j+2] = (GLfloat) normal3.z(); } Vector3 vert1(v_min_x, v_min_y, v_min_z); Vector3 vert2(v_max_x, v_max_y, v_max_z); Vector3 bounding_sphere_pos((v_min_x + v_max_x)/2.0f, (v_min_y + v_max_y)/2.0f, (v_min_z + v_max_z)/2.0f); double bounding_sphere_radius = vert1.distance(vert2) / 2.0f; //bounding_sphere_radius = 10.0; //Create Mesh and add it to the Mesh-list of the model. Mesh* mesh = new Mesh(mesh_names.value(i), triangle_count, vertices, texcoords, normals, mtln_mtl.value(mesh_mtl.value(mesh_names.value(i)))); mesh->setBoundingSpherePos(bounding_sphere_pos); mesh->setBoundingSphereRadius(bounding_sphere_radius); //meshs.append(mesh); mdl.add_mesh(mesh); } mdl.set_path(path); return true; }
/* dfs: * * Current scheme adds articulation point to first non-trivial child * block. If none exists, it will be added to its parent's block, if * non-trivial, or else given its own block. * * FIX: * This should be modified to: * - allow user to specify which block gets a node, perhaps on per-node basis. * - if an articulation point is not used in one of its non-trivial blocks, * dummy edges should be added to preserve biconnectivity * - turn on user-supplied blocks. * */ static void dfs(Agraph_t * g, Agnode_t * n, circ_state * state, int isRoot) { Agedge_t *e; Agnode_t *curtop; LOWVAL(n) = VAL(n) = state->orderCount++; stackPush(state->bcstack, n); for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) { Agnode_t *neighbor = e->head; if (neighbor == n) neighbor = e->tail; if (neighbor == PARENT(n)) continue; if (VAL(neighbor)) { LOWVAL(n) = min_value(LOWVAL(n), VAL(neighbor)); continue; } if (!stackCheck(state->bcstack, n)) { stackPush(state->bcstack, n); } PARENT(neighbor) = n; curtop = top(state->bcstack); dfs(g, neighbor, state, 0); LOWVAL(n) = min_value(LOWVAL(n), LOWVAL(neighbor)); if (LOWVAL(neighbor) >= VAL(n)) { block_t *block = NULL; Agnode_t *np; if (top(state->bcstack) != curtop) do { np = stackPop(state->bcstack); if (!BCDONE(np)) { if (!block) block = makeBlock(g, state); addNode(block, np); } } while (np != n); if (block) { /* If block != NULL, it's not empty */ if (isRoot && (BLOCK(n) == block)) insertBlock(&state->bl, block); else appendBlock(&state->bl, block); } if ((LOWVAL(n) < VAL(n)) && (!stackCheck(state->bcstack, n))) { stackPush(state->bcstack, n); } } } if ((LOWVAL(n) == VAL(n)) && !BCDONE(n)) { block_t *block = makeBlock(g, state); stackPop(state->bcstack); addNode(block, n); if (isRoot) insertBlock(&state->bl, block); else appendBlock(&state->bl, block); } }
/** * Max of alpha beta * * @param game_state the current game tree state * @param depth the depth of the tree * @param alpha * @param beta * @return a utility value */ static int max_value( struct GameNode * game_state, int depth, int alpha, int beta ) { time_t current_time; time( ¤t_time ); if( ( (current_time - timer) > THINKING_TIME - 1 ) || cutoff_test( game_state->state, depth ) || memory_usage() > MEMORYSIZE ) { return eval( game_state->state ); } struct ListNode * current_b; ++depth; int v = INT_MIN; int min_val; struct List * a = actions( game_state->state ); /* get possible actions */ /* iterate over all moves */ struct ListNode * current = a->head; while( current != NULL ) { /* create new game node */ struct State * state = result( game_state->state, current->data ); struct GameNode * node = new_game_node( state, game_state ); add_child_game_node( game_state, node ); /* find max value */ min_val = min_value( node, depth, alpha, beta ); if( min_val > v ) { game_state->best_util_val = v; //game_state->best_move = current->data; if( game_state->best_move != NULL ) Free( game_state->best_move, sizeof( struct Move ) ); game_state->best_move = clone_move( current->data ); } v = max( v, min_val ); if( v >= beta ) { //game_state->best_move = current->data; if( game_state->best_move != NULL ) Free( game_state->best_move, sizeof( struct Move ) ); game_state->best_move = clone_move( current->data ); /* free list of actions except for best move */ current_b = a->head; while( current_b != NULL ) { //if( compare_move( current_b->data, game_state->best_move ) == 0 ) Free( current_b->data, sizeof( struct Move ) ); current_b = current_b->next; } delete_list( &a ); return v; } alpha = max( alpha, v ); current = current->next; } /* free list of actions */ current_b = a->head; while( current_b != NULL ) { //if( compare_move( current_b->data, game_state->best_move ) == 0 ) Free( current_b->data, sizeof( struct Move ) ); current_b = current_b->next; } delete_list( &a ); return v; }
void hsv_h_filter(FILTER_DESC *filter_desc) { // http://en.wikipedia.org/wiki/HSL_and_HSV // http://cs.haifa.ac.il/hagit/courses/ist/Lectures/Demos/ColorApplet2/t_convert.html PARAM_LIST *p_list = NULL; NEURON_LAYER_LIST *n_list = NULL; NEURON_LAYER *nl_output = NULL, *nl_input = NULL; int nl_number, p_number; int xo, yo, wi, hi, wo, ho; int r, g, b, max, min; double h, delta; // Checks the Neuron Layers Number for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++) ; // Checks the Parameters Number for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++) ; if (p_number != 1) { Erro ("Error: Wrong number of parameters. The blue_mask_filter must have no parameters.", "", ""); return; } // Gets the Input Neuron Layer nl_input = filter_desc->neuron_layer_list->neuron_layer; // Gets the Filter Output nl_output = filter_desc->output; // Input-Output width wi = nl_input->dimentions.x; hi = nl_input->dimentions.y; wo = nl_output->dimentions.x; ho = nl_output->dimentions.y; if (wi != wo || hi != ho) { Erro ("Error: Input and output layers on blue_channel_mask filter must have the same 2D size.", "", ""); return; } for (yo = 0; yo < ho; yo++) { for (xo = 0; xo < wo; xo++) { r = RED(nl_input->neuron_vector[xo + yo * wo].output.ival); g = GREEN(nl_input->neuron_vector[xo + yo * wo].output.ival); b = BLUE(nl_input->neuron_vector[xo + yo * wo].output.ival); max = max_value(r, g, b); min = min_value(r, g, b); if ((max != 0) && (max != min)) { delta = (double) max - (double) min; if (r == max) h = (double) (g - b) / delta; // between yellow & magenta else if (g == max) h = 2.0 + (double) (b - r) / delta; // between cyan & yellow else h = 4.0 + (double) (r - g) / delta; // between magenta & cyan h *= 60.0; // degrees if (h < 0.0) h += 360.0; nl_output->neuron_vector[xo + yo * wo].output.ival = (int) (255.0 * (h / 360.0) + 0.5); } else nl_output->neuron_vector[xo + yo * wo].output.ival = 0; } } }