//Rasterize without facies counts computation std::vector<Geovalue> HalfEllipsoid::rasterize( int node_id, GsTLGridProperty *propTi, float angle ) { int i,j,k; cursor_->coords( node_id, i, j, k ); location_3d<int> cen(i, j, k); int ii,jj,kk; std::vector<Geovalue> gbRaster; // rasterize with ellipsim-type approach {for ( ii = -rmax_; ii <= rmax_; ii++ ) { {for ( jj = -rmax_; jj <= rmax_; jj++ ) { if ( lower_half_ == 1 ) { for ( kk = -rmin_; kk <= 0; kk++ ) { //if( cursor_->check_triplet(i+ii,j+jj,k+kk) ) { location_3d<int> loc( i+ii, j+jj, k+kk ); do_rotation( loc, cen, angle, gbRaster, propTi ); //} } } else { for ( kk = rmin_; kk >= 0; kk-- ) { //if( cursor_->check_triplet(i+ii,j+jj,k+kk) ) { location_3d<int> loc( i+ii, j+jj, k+kk ); do_rotation( loc, cen, angle, gbRaster, propTi ); //} } } }} }} return gbRaster; }
int insert(ROOT *r, int data) { NODE *new_node, *root = *r; int left_h = -1, right_h = -1; int diff,rotation_type; //tree is empty if(root == NULL) { new_node = (NODE *)malloc(sizeof(NODE)); new_node->info = data; new_node->height = 0; new_node->left = new_node->right = NULL; *r = new_node; return 0; } if(root->left) left_h = root->left->height; if(root->right) right_h = root->right->height; if(compare(data, root->info)<0) { left_h = insert(&(root->left), data); rotation_type = find_rotation_type(root->info, root->left->info, data); } else if(compare(data, root->info)>0) { right_h = insert(&(root->right), data); rotation_type = find_rotation_type(root->info, root->right->info, data); } else { printf("Value repeated"); return -1; } diff = left_h-right_h; if(diff>1 || diff<-1) { printf("Tree is Un-Balanced at node data %d ", root->info); if(rotation_type == 1) printf("required LL rotation\n"); if(rotation_type == 2) printf("required RL rotation\n"); if(rotation_type == 3) printf("required LR rotation\n"); if(rotation_type == 4) printf("required RR rotation\n"); //this call is for doing rotation do_rotation(r,rotation_type); printf("rotation done successfully\n"); root = *r; } return set_height(root); }
//Rasterize with built rotation using equation of rotated ellipse //Also computes the facies proportions within the rotated raster std::vector<Geovalue> HalfEllipsoid::rasterize( int node_id, GsTLGridProperty *propTi, float angle, std::vector<float> &facies_props ) { int i,j,k; cursor_->coords( node_id, i, j, k ); location_3d<int> cen(i, j, k); //Initialize vector of facies proportions facies_props.insert( facies_props.begin(), min_overlap_.size(), 0.0 ); int total_nodes = 0; int ii,jj,kk; std::vector<Geovalue> gbRaster; // rasterize with ellipsim-type approach --> with rotation {for ( ii = -rmax_; ii <= rmax_; ii++ ) { {for ( jj = -rmax_; jj <= rmax_; jj++ ) { if ( lower_half_ == 1 ) { for ( kk = -rmin_; kk <= 0; kk++ ) { location_3d<int> loc( i+ii, j+jj, k+kk ); do_rotation( loc, cen, angle, gbRaster, propTi, facies_props, total_nodes ); } } else { for ( kk = rmin_; kk >= 0; kk-- ) { location_3d<int> loc( i+ii, j+jj, k+kk ); do_rotation( loc, cen, angle, gbRaster, propTi, facies_props, total_nodes ); } } }} }} //Compute facies proportions for ( int i=0; i<facies_props.size(); i++ ) { facies_props[i] /= total_nodes; } return gbRaster; }
struct avlnode* avl_insert(struct avltree *tree, void *item) { struct avlnode *node, *parent; struct avlnode **nodep; /* do insertion */ parent = NULL; nodep = &tree->root; while ((node = *nodep)) { int32_t i = tree->item_compare(item, node->item); if (i <= 0) { parent = node; nodep = &node->left; } else if (i > 0) { parent = node; nodep = &node->right; } else { return node; } } node = safe_malloc(sizeof(struct avlnode)); avl_nodeinit(node, item, parent); *nodep = node; if (!parent) { tree->head = node; tree->tail = node; }else if (parent->left == node) { struct avlnode *prev = parent->prev; node->prev = prev; node->next = parent; parent->prev = node; if (prev) { prev->next = node; } else { tree->head = node; } } else { struct avlnode *next = parent->next; node->next = next; node->prev = parent; parent->next = node; if (next) { next->prev = node; } else { tree->tail = node; } } do_rotation(tree, parent); return node; }
void avl_remove_node(struct avltree *tree, struct avlnode *node) { struct avlnode *parent, *right, *left, *prev, *next, *replace; while (1) { // no left son if (!node->left) { // modify tree stucture parent = node->parent; right = node->right; if (!parent) { tree->root = right; } else if (parent->left == node) { parent->left = right; } else { parent->right= right; } if (right) { right->parent = parent; } // modify double linked structure prev = node->prev; next = node->next; if (next) { next->prev = prev; } else { tree->tail = prev; } if (prev) { prev->next = next; } else { tree->head = next; } break; } else // no right son if (!node->right) { // modify tree structure parent = node->parent; left = node->left; if (!parent) { tree->root = left; } else if (parent->left == node) { parent->left = left; } else { parent->right= left; } if (left) { left->parent = parent; } // modify double linked structure prev = node->prev; next = node->next; if (next) { next->prev = prev; } else { tree->tail = prev; } if (prev) { prev->next = next; } else { tree->head = next; } break; } replace = node->prev; node->item = replace->item; tree->move_item(replace->item, replace, node); node = replace; } do_rotation(tree, parent); free(node); }