bool KdTreeAccel::intersect(const Ray &inRay, DifferentialGeometry* queryPoint, const KdAccelNode* node, Float* tHit, Float* rayEpsilon) const { //Compute initial parametric range of ray inside kd-tree extent Float tmin, tmax, rayEp;//temprary DifferentialGeometry result if (!node->bbox.intersectP(inRay, &tmin, &tmax)) { return false; } //prepare to traversal kd-tree for ray Vector3f invDir(1.0 / inRay.d.x, 1.0 / inRay.d.y, 1.0 / inRay.d.z); //Traversal kd-tree node in order of ray bool isHit = false; if (node != nullptr) { //if hit outside the box, think it's used for later use if (inRay.tmax < tmin) { return isHit; } if (node->isLeaf()) { DifferentialGeometry* tmpQuery = new DifferentialGeometry(); Float hitDist; for (int i = 0; i < node->primIndex.size(); ++i) { int idx = node->primIndex[i]; if (primitives[idx]->intersectP(inRay)) { if (primitives[idx]->intersect(inRay, tmpQuery, &hitDist, &rayEp)) { if (hitDist < *tHit && inRange(hitDist, tmin, tmax)) { *queryPoint = *tmpQuery; *tHit = hitDist; *rayEpsilon = rayEp; queryPoint->shape = primitives[idx]; isHit = true; } } } } delete tmpQuery; } else//if hit interior node { /*process interior node*/ //calculate parametric distance from ray to split plane int axis = node->flags; Float tsplit = (node->split - inRay.o[axis]) * invDir[axis]; //get children node for ray const KdAccelNode* nearChild; const KdAccelNode* farChild; bool belowFisrt = ((inRay.o[axis] < node->split) || (inRay.o[axis] == node->split && inRay.d[axis] < 0)); if (belowFisrt) { nearChild = node->belowNode; farChild = node->aboveNode; } else { nearChild = node->aboveNode; farChild = node->belowNode; } if (tsplit > tmax || tsplit <= 0) { isHit = intersect(inRay, queryPoint, nearChild, tHit, rayEpsilon); } else if (tsplit < tmin) { isHit = intersect(inRay, queryPoint, farChild, tHit, rayEpsilon); } else { isHit = intersect(inRay, queryPoint, nearChild, tHit, rayEpsilon); if (!isHit) { isHit = intersect(inRay, queryPoint, farChild, tHit, rayEpsilon); } } // nearChild = nullptr; // farChild = nullptr; } } return isHit; }
int find_opt_fr(struct DotList *dots, int id, struct perm_pt *st, int w_sid, int w_fid, int h_sid, int h_fid, struct r_list *rp1, int num_rp1, struct r_list *rp2, int num_rp2, int *rp1_id, int *rp2_id, FILE *fp) { int i = 0; int min_score = 1000; int max_id = -1; bool *is_x; int *sd; int d = 0; struct gap_list gps; int temp_score = 0; int start, mid1 = -1, mid2 = -1, end; float *d_rate; float min_rate = 100; int len1 = 0, len2 = 0, len = 0, m_th = 0; int op_len = 0, op_len_x = 0, op_len_y = 0; int closeness = 0; struct I temp; int y_cur = 0, y_old = 0; int *id1, *id2; is_x = (bool *) ckalloc(sizeof(bool)); sd = (int *) ckalloc(sizeof(int)); d_rate = (float *) ckalloc(sizeof(float)); id1 = (int *) ckalloc(sizeof(int)); id2 = (int *) ckalloc(sizeof(int)); *rp1_id = -1; *rp2_id = -1; *id1 = -1; *id2 = -1; gps.type = -1; gps.id1 = -1; gps.id2 = -1; gps.x1 = 0; gps.x2 = 1; gps.y1 = 0; gps.y2 = 1; strcpy(gps.name1, ""); strcpy(gps.name2, ""); if( w_sid < h_sid ) { start = w_sid; if( w_fid < h_sid ) { mid1 = w_fid; mid2 = h_sid; end = h_fid; } else { if( w_fid < h_fid ) end = h_fid; else end = w_fid; } } else { start = h_sid; if( h_fid < w_sid ) { mid1 = h_fid; mid2 = w_sid; end = w_fid; } else { if( h_fid < w_fid ) end = w_fid; else end = h_fid; } } // m_x and m_y save the coordinated of the initial alignment before getting chained for( i = start; i <= end; i++ ) { if( st[i].id == id ) {} else if( (strcmp(dots[st[i].id].name1, dots[id].name1) != 0) || (strcmp(dots[st[i].id].name2, dots[id].name2) != 0) ) {} else if( dots[st[i].id].x.lower > dots[id].x.lower ) {} else if( dots[st[i].id].x.lower > dots[id].m_x.lower ) {} else if( (dots[st[i].id].sign == 0) && (dots[st[i].id].y.lower > dots[id].y.lower )) {} else if( (dots[st[i].id].sign == 1) && (dots[st[i].id].y.lower < dots[id].y.lower )) {} else if( subset(dots[st[i].id].m_x, dots[id].x) || subset(dots[st[i].id].m_y, dots[id].y) || subset(dots[id].m_x, dots[st[i].id].x) || subset(dots[id].m_y, dots[st[i].id].y) ) {} else if( (mid1 != -1) && (i > mid1) && (i < mid2)) {} else { // is_x of 'distance' function is true if x region is larger if((dots[st[i].id].sign != 2) && (dots[st[i].id].sign == dots[id].sign) && ((d = distance(dots, st[i].id, id, is_x, sd)) <= MDIS_THRESHOLD)) { len1 = width(dots[st[i].id].x); len2 = width(dots[id].x); if( len1 > len2 ) len = len2; else len = len1; if( (len1 >= LG_TH) && (len2 >= LG_TH ) ) m_th = L_M_TH; else m_th = M_TH; if((*sd) <= len) { op_len = 0; op_len_x = 0; op_len_y = 0; if( proper_overlap(dots[st[i].id].x, dots[id].x) == true ) { op_len_x = width(intersect(dots[st[i].id].x, dots[id].x)); op_len = op_len_x; } if( proper_overlap(dots[st[i].id].y, dots[id].y) == true ) { op_len_y = width(intersect(dots[st[i].id].y, dots[id].y)); if( op_len < op_len_y ) op_len = op_len_y; } if( ((*sd) > m_th) || (op_len > m_th) ) { if( (strict_almost_equal(dots[st[i].id].x, dots[id].x) == true) || (strict_almost_equal(dots[st[i].id].y, dots[id].y) == true) ) { gps.type = -1; } else if( ((closeness = compute_closeness(dots, st[i].id, id)) <= C_OP_TH) && ((*sd) > m_th) && (proper_overlap(dots[st[i].id].x, dots[id].x) == true) && (proper_overlap(dots[st[i].id].y, dots[id].y) == true )) { gps = define_gap(dots, st[i].id, id, d, *sd, *is_x); } else if( ((*sd) > m_th) && (proper_overlap(dots[st[i].id].x, dots[id].x) == true) && (proper_overlap(dots[st[i].id].y, dots[id].y) == true )) { gps.type = -1; } else if((proper_overlap(dots[st[i].id].x, dots[id].x) == true) && (proper_overlap(dots[st[i].id].y, dots[id].y) == true )) { temp = intersect(dots[st[i].id].x, dots[id].x); if( dots[id].sign == 0 ) { y_cur = dots[id].y.lower; y_old = find_yloc_one(dots[st[i].id], fp, temp.lower-dots[st[i].id].x.lower, NO_GAP_INC); } else if( dots[id].sign == 1 ) { y_cur = find_yloc_one(dots[st[i].id], fp, temp.lower-dots[st[i].id].x.lower, NO_GAP_INC); y_old = dots[id].y.upper; } if( y_old >= y_cur ) { gps = define_gap_new_type(dots, st[i].id, id, false); if( gps.type == -1 ) gps = define_gap_new_type(dots, st[i].id, id, true); } else if( y_old < y_cur ) { gps = define_gap_new_type(dots, st[i].id, id, true); if( gps.type == -1 ) gps = define_gap_new_type(dots, st[i].id, id, false); } } else if( proper_overlap(dots[st[i].id].x, dots[id].x) == true ) { gps = define_gap_new_type(dots, st[i].id, id, true); } else if( proper_overlap(dots[st[i].id].y, dots[id].y) == true ) { gps = define_gap_new_type(dots, st[i].id, id, false); } else gps.type = -1; } else if( ((closeness = compute_closeness(dots, st[i].id, id)) > C_OP_TH) && (proper_overlap(dots[st[i].id].x, dots[id].x) == true) && (proper_overlap(dots[st[i].id].y, dots[id].y) == true )) { closeness = compute_closeness(dots, st[i].id, id); temp = intersect(dots[st[i].id].x, dots[id].x); if( dots[id].sign == 0 ) { y_cur = dots[id].y.lower; y_old = find_yloc_one(dots[st[i].id], fp, temp.lower-dots[st[i].id].x.lower, NO_GAP_INC); } else if( dots[id].sign == 1 ) { y_cur = find_yloc_one(dots[st[i].id], fp, temp.lower-dots[st[i].id].x.lower, NO_GAP_INC); y_old = dots[id].y.upper; } if( y_old >= y_cur ) { gps = define_gap_new_type(dots, st[i].id, id, false); if( gps.type == -1 ) gps = define_gap_new_type(dots, st[i].id, id, true); } else if( y_old < y_cur ) { gps = define_gap_new_type(dots, st[i].id, id, true); if( gps.type == -1 ) gps = define_gap_new_type(dots, st[i].id, id, false); } } else if( (check_candi(dots, id, st[i].id, *is_x) == false) && ( (*sd) > TD_TH)) gps.type = -1; else { if( (proper_overlap(dots[st[i].id].x, dots[id].x) == true) && (proper_overlap(dots[st[i].id].y, dots[id].y) == true ) ) { gps = define_gap(dots, st[i].id, id, d, *sd, *is_x); } else if( proper_overlap(dots[st[i].id].x, dots[id].x) == true ) { gps = define_gap_new_type(dots, st[i].id, id, true); } else if( proper_overlap(dots[st[i].id].y, dots[id].y) == true ) { gps = define_gap_new_type(dots, st[i].id, id, false); } else gps = define_gap(dots, st[i].id, id, d, *sd, *is_x); } if((gps.type == -1) || (gps.type == 3)) // this gap is meaningless { } else { gps.rp_id1 = -1; gps.rp_id2 = -1; if( abs(gps.y2 - gps.y1) < ERR_LG_TH ) { gps.type = 0; } temp_score = get_score(dots, gps, d_rate, rp1, num_rp1, rp2, num_rp2, id1, id2, fp); if( temp_score == -1 ) { if( (gps.type == 21) || (gps.type == 22) ) { if( gps.type == 21 ) { gps = define_gap_new_type(dots, st[i].id, id, false); } else if( gps.type == 22 ) { gps = define_gap_new_type(dots, st[i].id, id, true); } if((gps.type == -1) || (gps.type == 3)) {}// this gap is meaningless else temp_score = get_score(dots, gps, d_rate, rp1, num_rp1, rp2, num_rp2, id1, id2, fp); } } if( temp_score != -1 ) { if( min_score > temp_score ) { min_score = temp_score; max_id = st[i].id; *rp1_id = *id1; *rp2_id = *id2; } else if( min_score == temp_score ) { if( (*d_rate) <= min_rate ) { min_rate = (*d_rate); min_score = temp_score; max_id = st[i].id; *rp1_id = *id1; *rp2_id = *id2; } } } } } } } } free(id1); free(id2); free(d_rate); free(sd); free(is_x); if( max_id == -1 ) { return(-1); } else { return(max_id); } }
//============================================================================== // Rect Rect intersection //============================================================================== bool GLMath::intersect(Rect r1, Rect r2) { return intersect(r1.p1, r2) && intersect(Vector2f(r1.p1.x, r1.p2.y), r2) && intersect(Vector2f(r1.p2.x, r1.p1.y), r2) && intersect(r1.p2, r2); }
bool Line::isParallel(const Line &b) const { Point t; return !intersect(b, t); }
bool AABB::doesIntersect(const Ray& ray) { int dummy_idx=0;return intersect(ray,dummy_idx)!=-1.f; }
void raySelect(int mouseX, int mouseY){ int objNumb; // indicate how many objects in the scene //SG has two children (one child is a translation at child(0) and the other is nodeModel at child(1)). All objects are linked to NodeTransform objNumb = SG->rootNode->children->at(0)->children->size(); printf("objNumb is %d\n", objNumb); bool hitRes[objNumb]; //array to store the hit result of each object Vector3D currentNear, currentFar; //temp vertex to store the current node near and far vertex; bool currentHitRes = false; // temp bool to store the hit result float nearestDis = 0.0;//use this temp variable to store the shortest distance with the ray origin int nearObj = 0;// use this temp variable to store the children index and it is about the nearest object within the hitted ones //use for loop to check if the ray hits each object or not for (int i = 0; i < objNumb; i++) { //pointer "currentNode" points to the current object; copy current object near vertex to the temp "near" vertex SG->goToParent(); SG->goToChild(i); currentNear = SG->currentNode->nodeNear; //copy object's far vertex to the temp "far" vertex currentFar = SG->currentNode->nodeFar; printf("currentNear x, y, z is %f,%f,%f\n", currentNear.x, currentNear.y, currentNear.z); printf("currentFar x, y, z is %f,%f,%f\n", currentFar.x, currentFar.y, currentFar.z); //compare near and far vertex first, because after transform, near would be far and far be near float dNear = getDis(currentNear, mouseX, mouseY); float dFar = getDis(currentFar, mouseX, mouseY); printf("dNear is %f\n", dNear); printf("dFar is %f\n", dFar); if (dNear > dFar) { currentFar = SG->currentNode->nodeNear; currentNear = SG->currentNode->nodeFar; } //use intersect func to check if there is a hit currentHitRes = intersect(currentNear, currentFar, mouseX, mouseY); //use currentDis to store the distance with the near and ray origin float currentDis; if (currentHitRes == true) { printf("have Intersection!!!\n"); currentDis = getDis(currentNear, mouseX, mouseY); }else{ printf("no Intersection!!!\n"); } if ((currentDis < nearestDis) && (currentHitRes == true)) { nearestDis = currentDis; nearObj = i; printf("current nearest distance is %f\n", nearestDis); printf("current nearest object is %d\n", nearObj); } //store the hit result to the array hitRes[i] = currentHitRes; } printf("nearest object is child %d\n", nearObj); //after the for loop, we could get the shortest distance between the nearest object and the ray origin. And get the index of the child "nearObj" //then move the pointer "currentNode" points to this child[nearObj] SG->goToRoot(); SG->goToChild(0);//go to the Transform node SG->goToChild(nearObj);// go to the nearest object where it is located at the childfren vector and the "currentNode" is pointing to it }
/** This is achieved by taking all the geometric information of the MultiGridManagement2D * and intersecting it with the coarsestDomain. All the intersecting parts * are kept on the new MultiGridManagement2D. */ MultiGridManagement2D extractManagement(MultiGridManagement2D management, Box2D coarsestDomain, bool crop){ std::auto_ptr<MultiGridManagement2D> result; if (crop){ result = std::auto_ptr<MultiGridManagement2D>(new MultiGridManagement2D(coarsestDomain, management.getNumLevels(), management.getOverlapWidth(), management.getReferenceLevel())); } else { result = std::auto_ptr<MultiGridManagement2D>(new MultiGridManagement2D(management.getBoundingBox(0), management.getNumLevels(), management.getOverlapWidth(), management.getReferenceLevel())); } // erase the bulk added by default by the constructor result->bulks[0].erase(result->bulks[0].begin()); MultiScaleManager* scaleManager = result->scaleManager->clone(); // every level must contain the informations intersected with coarsestDomain for (plint iLevel=0; iLevel<management.getNumLevels(); ++iLevel){ Box2D rescaledBox = scaleManager->scaleBox(coarsestDomain,iLevel); // boundingBoxes result->boundingBoxes[iLevel] = rescaledBox; if (iLevel< management.getNumLevels()-1){ // coarseGridInterfaces for (pluint iInterface=0; iInterface<management.coarseGridInterfaces.size(); ++iInterface){ Box2D intersection; if (intersect(rescaledBox,management.coarseGridInterfaces[iLevel][iInterface],intersection)){ result->coarseGridInterfaces[iLevel].push_back(intersection); // copy also the orientation and direction for coarse grids result->coarseInterfaceOrientations[iLevel].push_back( Array<plint,2>(management.coarseInterfaceOrientations[iLevel][iInterface])); } } } if (iLevel > 0) { // fineGridInterfaces for (pluint iInterface=0; iInterface<management.coarseGridInterfaces.size(); ++iInterface){ Box2D intersection; if (intersect(rescaledBox,management.fineGridInterfaces[iLevel][iInterface],intersection)){ result->fineGridInterfaces[iLevel].push_back(intersection); // copy also the orientation and direction for fine grids result->fineInterfaceOrientations[iLevel].push_back( Array<plint,2>(management.fineInterfaceOrientations[iLevel][iInterface])); } } } // bulk for (pluint iBox=0; iBox<management.bulks[iLevel].size(); ++iBox){ Box2D intersection; // verify if the bulk is contained if (intersect(rescaledBox,management.bulks[iLevel][iBox],intersection)){ result->bulks[iLevel].push_back(intersection); // copy also the mpi process associated result->mpiProcess[iLevel].push_back(management.mpiProcess[iLevel][iBox]); } } } delete scaleManager; return *result; }
//! returns whether the 2 line segments intersected bool intersect(const lineseg3 &l1, const lineseg3 &l2, float *time) { if (intersect((line3)l1, (line3)l2, time) && *time >= 0 && *time <= 1) return true; return false; }
//understand the edge vertex computation from [email protected] //ASSUMPTION: eye is along z-axis //vo: volume vertex coords model-space coords //tx: texture vertex coords tex-space coords //axis: axis to slice along world-space coords void vRenderer::renderTexture3D(float sampleFrequency,GLdouble mv[16],float vo[8][3],float tx[8][3],float axis[3]) { float rv[8][3]; //the rotated volume (may include a scale) float maxval = -10; //(tmp) float minval = 10; int minvert = 0, maxvert = 0; GLdouble mvinv[16]; int i, j, k; inverseMatrix(mvinv, mv); //invert model view matrix for(i=0; i<8; ++i){ translateV3(rv[i], mv, vo[i]); //get the rotated vol coords //now get the max and min z in view space if(maxval < MAX(maxval, rv[i][2])){ maxval = MAX(maxval, rv[i][2]); maxvert = i; } if(minval > MIN(minval, rv[i][2])){ minval = MIN(minval, rv[i][2]); minvert = i; //determine the starting corner for slicing } } //find the slice plane point 'sp' (initial) and the slice plane normal 'sn' //sp is the slice starting point, simply the vertex farthest from the eye float sp[3] = {vo[minvert][0], vo[minvert][1], vo[minvert][2]}; // float sp[3] = {vo[maxvert][0], vo[maxvert][1], vo[maxvert][2]}; float vpn[3]; vpn[0] = axis[0]; vpn[1] = axis[1]; vpn[2] = axis[2]; //now calculate sn which is the normalized vpn in the model space //ie where the orginal slices are stored float sn[3]; translateV3(sn, mvinv, vpn); //move vpn to sn (model space); //now normalize this float normsn = (float)sqrt(sn[0]*sn[0] + sn[1]*sn[1] + sn[2]*sn[2]); //normalize sn[0]/=normsn; sn[1]/=normsn; sn[2]/=normsn; //now find the distance we need to slice (|max_vertex - min_vertex|) float maxd[3] = {0, 0, maxval}; //(tmp) only use z-coord (view space) float mind[3] = {0, 0, minval}; //(tmp) ditto (view space) float maxv[3], minv[3]; //(tmp) translateV3(maxv, mvinv, maxd); //translate back to model space translateV3(minv, mvinv, mind); //ditto maxv[0] -= minv[0]; //subtract maxv[1] -= minv[1]; maxv[2] -= minv[2]; //now take the norm of this vector... we have the distance to be sampled //this distance is in the world space float dist = (float)sqrt(maxv[0]*maxv[0] + maxv[1]*maxv[1] + maxv[2]*maxv[2]); #if defined(ADDCGGL) || defined(ADDARBGL) glColor4f(1.0f,1.0f,1.0f,0.01); #else glColor4f(1.0f,1.0f,1.0f,0.1); #endif GlErr("vRenderer","drawVA"); //distance between samples float sampleSpacing = 1.0 / (myVolume->maxDim* sampleFrequency); float del[3] = {sn[0]*sampleSpacing, sn[1]*sampleSpacing, sn[2]*sampleSpacing}; int samples = (int)((dist) / sampleSpacing);//(total distance to be sam //highly un-optimized!!!!!!!!! float poly[6][3]; // for edge intersections float tcoord[6][3]; // for texture intersections float tpoly[6][3]; // for transformed edge intersections int edges; // total number of edge intersections //the dep texture should be scaled glBindTexture(GL_TEXTURE_3D, myVolume->texName); //sp:slice plane point //sn:the slice dirn to cut thru the volume //the above 2 are in world coord space for(i = 0 ; i < samples; ++i){ //for each slice //increment the slice plane point by the slice distance // sp[0] -= del[0]; // sp[1] -= del[1]; // sp[2] -= del[2]; sp[0] += del[0]; sp[1] += del[1]; sp[2] += del[2]; edges = 0; //now check each edge of the volume for intersection with.. //the plane defined by sp & sn //front bottom edge edges += intersect(vo[0], vo[1], tx[0], tx[1], rv[0], rv[1], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //front left edge edges += intersect(vo[0], vo[2], tx[0], tx[2], rv[0], rv[2], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //front right edge edges += intersect(vo[1], vo[3], tx[1], tx[3], rv[1], rv[3], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //left bottom edge edges += intersect(vo[4], vo[0], tx[4], tx[0], rv[4], rv[0], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //right bottom edge edges += intersect(vo[1], vo[5], tx[1], tx[5], rv[1], rv[5], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //front top edge edges += intersect(vo[2], vo[3], tx[2], tx[3], rv[2], rv[3], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //back bottom edge edges += intersect(vo[4], vo[5], tx[4], tx[5], rv[4], rv[5], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //back left edge edges += intersect(vo[4], vo[6], tx[4], tx[6], rv[4], rv[6], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //back right edge edges += intersect(vo[5], vo[7], tx[5], tx[7], rv[5], rv[7], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //back top edge edges += intersect(vo[6], vo[7], tx[6], tx[7], rv[6], rv[7], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //left top edge edges += intersect(vo[2], vo[6], tx[2], tx[6], rv[2], rv[6], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); //right top edge edges += intersect(vo[3], vo[7], tx[3], tx[7], rv[3], rv[7], sp, sn, poly[edges], tcoord[edges], tpoly[edges]); // B.M.E. Moret & H.D. Shapiro "P to NP" pp. 453 float dx, dy, tt ,theta, cen[2]; //tt= TempTheta cen[0] = cen[1] = 0.0; int next; //rather than swap 3 arrays, only one? int order[6] ={0,1,2,3,4,5}; // order[6] could be an extreemly inefficient way to do this for(j=0; j<edges; ++j){ //find the center of the points cen[0] += tpoly[j][0]; cen[1] += tpoly[j][1]; } //by averaging cen[0]/= edges; cen[1]/= edges; for(j=0; j<edges; ++j){ //for each vertex theta = -10; //find one with largest angle from center.. next = j; for (k= j; k<edges; ++k){ //... and check angle made between other edges dx = tpoly[order[k]][0] - cen[0]; dy = tpoly[order[k]][1] - cen[1]; if( (dx == 0) && (dy == 0)){ //same as center? next = k; cout << "what teh " << endl; break; //out of this for-loop } tt = dy/(ABS(dx) + ABS(dy)); //else compute theta [0-4] if( dx < 0.0 ) tt = (float)(2.0 - tt); //check quadrants 2&3 else if( dy < 0.0 ) tt = (float)(4.0 + tt); //quadrant 4 if( theta <= tt ){ //grab the max theta next = k; theta = tt; } } //end for(k) angle checking // i am using 'tt' as a temp // swap polygon vertex ( is this better than another branch?) // I am not sure wich is worse: swapping 3 vectors for every edge // or: using an array to index into another array??? hmmm.... // should have payed more attention in class int tmp = order[j]; order[j] = order[next]; order[next] = tmp; } //end for(j) edge /angle sort renderSlice(edges, tcoord, poly, order); //}//end else compute convex hull }// end for(i) each slice //now draw each slice view }
void _findNodes( const Ray &t, std::list < SceneNode * > &list, SceneNode *exclude, bool full, Octree *octant ) { if ( !full ) { AxisAlignedBox obox; octant -> _getCullBounds( &obox ); Intersection isect = intersect( t, obox ); if ( isect == OUTSIDE ) return ; full = ( isect == INSIDE ); } NodeList::iterator it = octant -> mNodes.begin(); while ( it != octant -> mNodes.end() ) { OctreeNode * on = ( *it ); if ( on != exclude ) { if ( full ) { list.push_back( on ); } else { Intersection nsect = intersect( t, on -> _getWorldAABB() ); if ( nsect != OUTSIDE ) { list.push_back( on ); } } } ++it; } Octree* child; if ( (child=octant -> mChildren[ 0 ][ 0 ][ 0 ]) != 0 ) _findNodes( t, list, exclude, full, child ); if ( (child=octant -> mChildren[ 1 ][ 0 ][ 0 ]) != 0 ) _findNodes( t, list, exclude, full, child ); if ( (child=octant -> mChildren[ 0 ][ 1 ][ 0 ]) != 0 ) _findNodes( t, list, exclude, full, child ); if ( (child=octant -> mChildren[ 1 ][ 1 ][ 0 ]) != 0 ) _findNodes( t, list, exclude, full, child ); if ( (child=octant -> mChildren[ 0 ][ 0 ][ 1 ]) != 0 ) _findNodes( t, list, exclude, full, child ); if ( (child=octant -> mChildren[ 1 ][ 0 ][ 1 ]) != 0 ) _findNodes( t, list, exclude, full, child ); if ( (child=octant -> mChildren[ 0 ][ 1 ][ 1 ]) != 0 ) _findNodes( t, list, exclude, full, child ); if ( (child=octant -> mChildren[ 1 ][ 1 ][ 1 ]) != 0 ) _findNodes( t, list, exclude, full, child ); }
/*! Computes the dominator tree from a CFG using algorithm __*/ void PostdominatorTree::computeDT() { int end_node = blocksToIndex[cfg->get_exit_block()]; bool changed = true; p_dom[end_node] = end_node; report( " Computing tree" ); while (changed) { changed = false; // post-order for (int b_ind = 0; b_ind < (int)blocks.size(); b_ind++) { if (b_ind == end_node) continue; ir::ControlFlowGraph::iterator b = blocks[b_ind]; assert(!b->successors.empty()); int new_pdom = 0; bool processed = false; ir::ControlFlowGraph::pointer_iterator succ_it = b->successors.begin(); for (; succ_it != b->successors.end(); ++succ_it) { int p = blocksToIndex[*succ_it]; assert(p<(int)p_dom.size()); if (p_dom[p] != -1) { if( !processed ) { new_pdom = p; processed = true; } else { new_pdom = intersect(p, new_pdom); } } } if( processed ) { if (p_dom[b_ind] != new_pdom) { p_dom[b_ind] = new_pdom; changed = true; } } } } dominated.resize(blocks.size()); for (int n = 0; n < (int)blocks.size(); n++) { if (p_dom[n] >= 0) { dominated[p_dom[n]].push_back(n); } } report(" Computing frontiers") frontiers.resize(blocks.size()); for (int b_ind = 0; b_ind < (int)blocks.size(); b_ind++) { ir::ControlFlowGraph::iterator block = blocks[b_ind]; if(block->successors.size() < 2) continue; typedef std::unordered_set<int> BasicBlockSet; BasicBlockSet blocksWithThisBlockInTheirFrontier; for (auto successor : block->successors) { auto runner = successor; while (runner != getPostDominator(block)) { blocksWithThisBlockInTheirFrontier.insert( blocksToIndex[runner]); runner = getPostDominator(runner); } } for (auto frontierBlock : blocksWithThisBlockInTheirFrontier) { frontiers[b_ind].push_back(frontierBlock); } } }
// this flavor centers potential intersections recursively. In contrast, '2' may inadvertently // chase intersections near quadratic ends, requiring odd hacks to find them. static void intersect(const SkDCubic& cubic1, double t1s, double t1e, const SkDCubic& cubic2, double t2s, double t2e, double precisionScale, SkIntersections& i) { i.upDepth(); SkDCubic c1 = cubic1.subDivide(t1s, t1e); SkDCubic c2 = cubic2.subDivide(t2s, t2e); SkSTArray<kCubicToQuadSubdivisionDepth, double, true> ts1; // OPTIMIZE: if c1 == c2, call once (happens when detecting self-intersection) c1.toQuadraticTs(c1.calcPrecision() * precisionScale, &ts1); SkSTArray<kCubicToQuadSubdivisionDepth, double, true> ts2; c2.toQuadraticTs(c2.calcPrecision() * precisionScale, &ts2); double t1Start = t1s; int ts1Count = ts1.count(); for (int i1 = 0; i1 <= ts1Count; ++i1) { const double tEnd1 = i1 < ts1Count ? ts1[i1] : 1; const double t1 = t1s + (t1e - t1s) * tEnd1; SkReduceOrder s1; int o1 = quadPart(cubic1, t1Start, t1, &s1); double t2Start = t2s; int ts2Count = ts2.count(); for (int i2 = 0; i2 <= ts2Count; ++i2) { const double tEnd2 = i2 < ts2Count ? ts2[i2] : 1; const double t2 = t2s + (t2e - t2s) * tEnd2; if (&cubic1 == &cubic2 && t1Start >= t2Start) { t2Start = t2; continue; } SkReduceOrder s2; int o2 = quadPart(cubic2, t2Start, t2, &s2); #if ONE_OFF_DEBUG char tab[] = " "; if (tLimits1[0][0] >= t1Start && tLimits1[0][1] <= t1 && tLimits1[1][0] >= t2Start && tLimits1[1][1] <= t2) { SkDebugf("%.*s %s t1=(%1.9g,%1.9g) t2=(%1.9g,%1.9g)", i.depth()*2, tab, __FUNCTION__, t1Start, t1, t2Start, t2); SkIntersections xlocals; xlocals.allowNear(false); intersectWithOrder(s1.fQuad, o1, s2.fQuad, o2, xlocals); SkDebugf(" xlocals.fUsed=%d\n", xlocals.used()); } #endif SkIntersections locals; locals.allowNear(false); intersectWithOrder(s1.fQuad, o1, s2.fQuad, o2, locals); int tCount = locals.used(); for (int tIdx = 0; tIdx < tCount; ++tIdx) { double to1 = t1Start + (t1 - t1Start) * locals[0][tIdx]; double to2 = t2Start + (t2 - t2Start) * locals[1][tIdx]; // if the computed t is not sufficiently precise, iterate SkDPoint p1 = cubic1.ptAtT(to1); SkDPoint p2 = cubic2.ptAtT(to2); if (p1.approximatelyEqual(p2)) { // FIXME: local edge may be coincident -- experiment with not propagating coincidence to caller // SkASSERT(!locals.isCoincident(tIdx)); if (&cubic1 != &cubic2 || !approximately_equal(to1, to2)) { if (i.swapped()) { // FIXME: insert should respect swap i.insert(to2, to1, p1); } else { i.insert(to1, to2, p1); } } } else { double offset = precisionScale / 16; // FIME: const is arbitrary: test, refine double c1Bottom = tIdx == 0 ? 0 : (t1Start + (t1 - t1Start) * locals[0][tIdx - 1] + to1) / 2; double c1Min = SkTMax(c1Bottom, to1 - offset); double c1Top = tIdx == tCount - 1 ? 1 : (t1Start + (t1 - t1Start) * locals[0][tIdx + 1] + to1) / 2; double c1Max = SkTMin(c1Top, to1 + offset); double c2Min = SkTMax(0., to2 - offset); double c2Max = SkTMin(1., to2 + offset); #if ONE_OFF_DEBUG SkDebugf("%.*s %s 1 contains1=%d/%d contains2=%d/%d\n", i.depth()*2, tab, __FUNCTION__, c1Min <= tLimits1[0][1] && tLimits1[0][0] <= c1Max && c2Min <= tLimits1[1][1] && tLimits1[1][0] <= c2Max, to1 - offset <= tLimits1[0][1] && tLimits1[0][0] <= to1 + offset && to2 - offset <= tLimits1[1][1] && tLimits1[1][0] <= to2 + offset, c1Min <= tLimits2[0][1] && tLimits2[0][0] <= c1Max && c2Min <= tLimits2[1][1] && tLimits2[1][0] <= c2Max, to1 - offset <= tLimits2[0][1] && tLimits2[0][0] <= to1 + offset && to2 - offset <= tLimits2[1][1] && tLimits2[1][0] <= to2 + offset); SkDebugf("%.*s %s 1 c1Bottom=%1.9g c1Top=%1.9g c2Bottom=%1.9g c2Top=%1.9g" " 1-o=%1.9g 1+o=%1.9g 2-o=%1.9g 2+o=%1.9g offset=%1.9g\n", i.depth()*2, tab, __FUNCTION__, c1Bottom, c1Top, 0., 1., to1 - offset, to1 + offset, to2 - offset, to2 + offset, offset); SkDebugf("%.*s %s 1 to1=%1.9g to2=%1.9g c1Min=%1.9g c1Max=%1.9g c2Min=%1.9g" " c2Max=%1.9g\n", i.depth()*2, tab, __FUNCTION__, to1, to2, c1Min, c1Max, c2Min, c2Max); #endif intersect(cubic1, c1Min, c1Max, cubic2, c2Min, c2Max, offset, i); #if ONE_OFF_DEBUG SkDebugf("%.*s %s 1 i.used=%d t=%1.9g\n", i.depth()*2, tab, __FUNCTION__, i.used(), i.used() > 0 ? i[0][i.used() - 1] : -1); #endif if (tCount > 1) { c1Min = SkTMax(0., to1 - offset); c1Max = SkTMin(1., to1 + offset); double c2Bottom = tIdx == 0 ? to2 : (t2Start + (t2 - t2Start) * locals[1][tIdx - 1] + to2) / 2; double c2Top = tIdx == tCount - 1 ? to2 : (t2Start + (t2 - t2Start) * locals[1][tIdx + 1] + to2) / 2; if (c2Bottom > c2Top) { SkTSwap(c2Bottom, c2Top); } if (c2Bottom == to2) { c2Bottom = 0; } if (c2Top == to2) { c2Top = 1; } c2Min = SkTMax(c2Bottom, to2 - offset); c2Max = SkTMin(c2Top, to2 + offset); #if ONE_OFF_DEBUG SkDebugf("%.*s %s 2 contains1=%d/%d contains2=%d/%d\n", i.depth()*2, tab, __FUNCTION__, c1Min <= tLimits1[0][1] && tLimits1[0][0] <= c1Max && c2Min <= tLimits1[1][1] && tLimits1[1][0] <= c2Max, to1 - offset <= tLimits1[0][1] && tLimits1[0][0] <= to1 + offset && to2 - offset <= tLimits1[1][1] && tLimits1[1][0] <= to2 + offset, c1Min <= tLimits2[0][1] && tLimits2[0][0] <= c1Max && c2Min <= tLimits2[1][1] && tLimits2[1][0] <= c2Max, to1 - offset <= tLimits2[0][1] && tLimits2[0][0] <= to1 + offset && to2 - offset <= tLimits2[1][1] && tLimits2[1][0] <= to2 + offset); SkDebugf("%.*s %s 2 c1Bottom=%1.9g c1Top=%1.9g c2Bottom=%1.9g c2Top=%1.9g" " 1-o=%1.9g 1+o=%1.9g 2-o=%1.9g 2+o=%1.9g offset=%1.9g\n", i.depth()*2, tab, __FUNCTION__, 0., 1., c2Bottom, c2Top, to1 - offset, to1 + offset, to2 - offset, to2 + offset, offset); SkDebugf("%.*s %s 2 to1=%1.9g to2=%1.9g c1Min=%1.9g c1Max=%1.9g c2Min=%1.9g" " c2Max=%1.9g\n", i.depth()*2, tab, __FUNCTION__, to1, to2, c1Min, c1Max, c2Min, c2Max); #endif intersect(cubic1, c1Min, c1Max, cubic2, c2Min, c2Max, offset, i); #if ONE_OFF_DEBUG SkDebugf("%.*s %s 2 i.used=%d t=%1.9g\n", i.depth()*2, tab, __FUNCTION__, i.used(), i.used() > 0 ? i[0][i.used() - 1] : -1); #endif c1Min = SkTMax(c1Bottom, to1 - offset); c1Max = SkTMin(c1Top, to1 + offset); #if ONE_OFF_DEBUG SkDebugf("%.*s %s 3 contains1=%d/%d contains2=%d/%d\n", i.depth()*2, tab, __FUNCTION__, c1Min <= tLimits1[0][1] && tLimits1[0][0] <= c1Max && c2Min <= tLimits1[1][1] && tLimits1[1][0] <= c2Max, to1 - offset <= tLimits1[0][1] && tLimits1[0][0] <= to1 + offset && to2 - offset <= tLimits1[1][1] && tLimits1[1][0] <= to2 + offset, c1Min <= tLimits2[0][1] && tLimits2[0][0] <= c1Max && c2Min <= tLimits2[1][1] && tLimits2[1][0] <= c2Max, to1 - offset <= tLimits2[0][1] && tLimits2[0][0] <= to1 + offset && to2 - offset <= tLimits2[1][1] && tLimits2[1][0] <= to2 + offset); SkDebugf("%.*s %s 3 c1Bottom=%1.9g c1Top=%1.9g c2Bottom=%1.9g c2Top=%1.9g" " 1-o=%1.9g 1+o=%1.9g 2-o=%1.9g 2+o=%1.9g offset=%1.9g\n", i.depth()*2, tab, __FUNCTION__, 0., 1., c2Bottom, c2Top, to1 - offset, to1 + offset, to2 - offset, to2 + offset, offset); SkDebugf("%.*s %s 3 to1=%1.9g to2=%1.9g c1Min=%1.9g c1Max=%1.9g c2Min=%1.9g" " c2Max=%1.9g\n", i.depth()*2, tab, __FUNCTION__, to1, to2, c1Min, c1Max, c2Min, c2Max); #endif intersect(cubic1, c1Min, c1Max, cubic2, c2Min, c2Max, offset, i); #if ONE_OFF_DEBUG SkDebugf("%.*s %s 3 i.used=%d t=%1.9g\n", i.depth()*2, tab, __FUNCTION__, i.used(), i.used() > 0 ? i[0][i.used() - 1] : -1); #endif } // intersect(cubic1, c1Min, c1Max, cubic2, c2Min, c2Max, offset, i); // FIXME: if no intersection is found, either quadratics intersected where // cubics did not, or the intersection was missed. In the former case, expect // the quadratics to be nearly parallel at the point of intersection, and check // for that. } } t2Start = t2; } t1Start = t1; } i.downDepth(); }
/** * Implementation of TA^B_{rec} * Algorithm is described in http://www.cgg.cvut.cz/~havran/phdthesis.html */ Intersection KdTreePrimitiveManager::intersectWithPrims(const Ray& ray) const { StackElem stack[64]; Node* far; Node* cur = m_root; floating a, b, t; int en = 0, ex = 1, tmp; if (!intersectAabb(m_bbox, ray, a, b)) { return {}; } stack[en].t = a; stack[en].pb = ray.origin(); if (a >= 0.0) { stack[en].pb += ray.dir() * a; } stack[ex].t = b; stack[ex].pb = ray.origin() + ray.dir() * b; stack[ex].node = nullptr; while (cur != nullptr) { while (cur->m_axis < 3) { const float split = cur->m_split; uint8_t axis = cur->m_axis; if (stack[en].pb[axis] < split) { if (stack[ex].pb[axis] < split) { cur = cur->m_left; continue; } far = cur->m_right; cur = cur->m_left; } else { if (stack[ex].pb[axis] > split) { cur = cur->m_right; continue; } far = cur->m_left; cur = cur->m_right; } t = (split - ray.origin(axis)) / ray.dir(axis); tmp = ex; ++ex; if (ex == en) ++ex; stack[ex].prev = tmp; stack[ex].t = t; stack[ex].node = far; stack[ex].pb[axis] = split; axis = (axis + 1) % 3; stack[ex].pb[axis] = ray.origin(axis) + t * ray.dir(axis); axis = (axis + 1) % 3; stack[ex].pb[axis] = ray.origin(axis) + t * ray.dir(axis); } { Intersection intr; for (PrimPtr* ptr = cur->prims (); *ptr; ++ ptr, ++ icount) { auto prim = *ptr; prim->intersect(ray, intr); if (intr.hasIntersections()) { if (intr.dist() < stack[en].t - epsilon || intr.dist() > stack[ex].t + epsilon) { intr.nullPrimitive(); } } } if (intr.hasIntersections()) { return intr; } } en = ex; cur = stack[ex].node; ex = stack[en].prev; } return {}; }
void filter_gff_lists(struct g_list *genes1, int num_genes1, struct exons_list *exons1, int num_exons1, int type) { int i = 0, j = 0; struct I cur, tmp; int sid = 0, eid = 0; cur = assign_I(0, 1); tmp = assign_I(0, 1); if( type == SGD ) { for( i = 0; i < num_genes1; i++ ) { sid = genes1[i].cdsStart; eid = genes1[i].cdsEnd; if( exons1[sid].reg.lower < exons1[eid].reg.upper ) { cur = assign_I(exons1[sid].reg.lower, exons1[eid].reg.upper); } else { if( genes1[i].strand == '-' ) { cur = assign_I(exons1[eid].reg.lower, exons1[sid].reg.upper); } else { fatalf("check exons list for %s,%s:%d-%d\n", genes1[i].gname, genes1[i].sname, genes1[i].txStart, genes1[i].txEnd); } } // cur = assign_I(genes1[i].txStart, genes1[i].txEnd); // if( (width(cur) < MIN_ORF_BASES) && (strstr(genes1[i].info, "Dubious") != 0) ) if( (genes1[i].txStart <= 0) || (genes1[i].txEnd <= 0) ) { genes1[i].type = REDUN; } else if( width(cur) < MIN_ORF_BASES ) { genes1[i].type = REDUN; } else if( genes1[i].type == REDUN ) {} else { j = i+1; if( j < num_genes1 ) { sid = genes1[j].cdsStart; eid = genes1[j].cdsEnd; if( exons1[sid].reg.lower < exons1[eid].reg.upper ) { tmp = assign_I(exons1[sid].reg.lower, exons1[eid].reg.upper); } else { if( genes1[j].strand == '-' ) { tmp = assign_I(exons1[eid].reg.lower, exons1[sid].reg.upper); } else { fatalf("check exons list for %s,%s:%d-%d\n", genes1[j].gname, genes1[j].sname, genes1[i].txStart, genes1[j].txEnd); } } // tmp = assign_I(genes1[j].txStart, genes1[j].txEnd); } while( (j < num_genes1) && (proper_overlap(cur, tmp) == true) ) { if( width(tmp) < MIN_ORF_BASES ) { genes1[j].type = REDUN; } else if( genes1[j].type == REDUN ) {} else { if( width(intersect(cur, tmp)) >= MIN_BASES ) { if( (strstr(genes1[i].info, "Verified") != 0) || (strstr(genes1[i].info, "Uncharacterized") != 0) ) { if(strstr(genes1[j].info, "Dubious") != 0 ) { // if( genes1[j].strand == genes1[i].strand ) { genes1[j].type = REDUN; // } } } else if( strstr(genes1[i].info, "Dubious") != 0 ) { if( (strstr(genes1[j].info, "Verified") != 0) || (strstr(genes1[j].info, "Uncharacterized") != 0) ) { // if( genes1[j].strand == genes1[i].strand ) { genes1[i].type = REDUN; // } } else if( strstr(genes1[j].info, "Dubious") != 0 ) { if(width(tmp) < width(cur)) { // if( genes1[j].strand == genes1[i].strand ) { genes1[j].type = REDUN; // } } else if(width(tmp) >= width(cur)) { // if( genes1[j].strand == genes1[i].strand ) { genes1[i].type = REDUN; // } } } } } } j++; if( j < num_genes1 ) { sid = genes1[j].cdsStart; eid = genes1[j].cdsEnd; if( exons1[sid].reg.lower < exons1[eid].reg.upper ) { tmp = assign_I(exons1[sid].reg.lower, exons1[eid].reg.upper); } else { if( genes1[j].strand == '-' ) { tmp = assign_I(exons1[eid].reg.lower, exons1[sid].reg.upper); } else { fatalf("check exons list for %s,%s:%d-%d\n", genes1[j].gname, genes1[j].sname, genes1[i].txStart, genes1[j].txEnd); } } // tmp = assign_I(genes1[j].txStart, genes1[j].txEnd); } } } } } else if( type == MAKER ) { for( i = 0; i < num_genes1; i++ ) { sid = genes1[i].cdsStart; eid = genes1[i].cdsEnd; if( exons1[sid].reg.lower < exons1[eid].reg.upper ) { cur = assign_I(exons1[sid].reg.lower, exons1[eid].reg.upper); } else { if( genes1[i].strand == '-' ) { cur = assign_I(exons1[eid].reg.lower, exons1[sid].reg.upper); } else { fatalf("check exons list for %s,%s:%d-%d\n", genes1[i].gname, genes1[i].sname, genes1[i].txStart, genes1[i].txEnd); } } // cur = assign_I(genes1[i].txStart, genes1[i].txEnd); // if( (width(cur) < MIN_ORF_BASES) && (strcmp(genes1[i].gname, "UNDEF") == 0) ) if( (genes1[i].type == REDUN) || (genes1[i].type == MATCH) || (genes1[i].type == PARTIAL) ) { genes1[i].type = REDUN; } else if( width(cur) < MIN_ORF_BASES ) { genes1[i].type = REDUN; } else { j = i+1; if( j < num_genes1 ) { sid = genes1[j].cdsStart; eid = genes1[j].cdsEnd; if( exons1[sid].reg.lower < exons1[eid].reg.upper ) { tmp = assign_I(exons1[sid].reg.lower, exons1[eid].reg.upper); } else { if( genes1[j].strand == '-' ) { tmp = assign_I(exons1[eid].reg.lower, exons1[sid].reg.upper); } else { fatalf("check exons list for %s,%s:%d-%d\n", genes1[j].gname, genes1[j].sname, genes1[i].txStart, genes1[j].txEnd); } } // tmp = assign_I(genes1[j].txStart, genes1[j].txEnd); } while( (j < num_genes1) && (proper_overlap(cur, tmp) == true) ) { if( (genes1[j].type == REDUN) || (genes1[j].type == MATCH) || (genes1[j].type == PARTIAL) ) { genes1[j].type = REDUN; } else if( width(cur) < MIN_ORF_BASES ) { genes1[j].type = REDUN; } else { // if( (width(intersect(cur, tmp)) >= MIN_BASES) && (genes1[i].strand == genes1[j].strand) ) { if( width(intersect(cur, tmp)) >= MIN_BASES ) { if(width(tmp) < width(cur)) { genes1[j].type = REDUN; } else if(width(tmp) >= width(cur)) { genes1[i].type = REDUN; } } } j++; if( j < num_genes1 ) { sid = genes1[j].cdsStart; eid = genes1[j].cdsEnd; if( exons1[sid].reg.lower < exons1[eid].reg.upper ) { tmp = assign_I(exons1[sid].reg.lower, exons1[eid].reg.upper); } else { if( genes1[j].strand == '-' ) { tmp = assign_I(exons1[eid].reg.lower, exons1[sid].reg.upper); } else { fatalf("check exons list for %s,%s:%d-%d\n", genes1[j].gname, genes1[j].sname, genes1[i].txStart, genes1[j].txEnd); } } // tmp = assign_I(genes1[j].txStart, genes1[j].txEnd); } } } } } else if ( type == MULTI_CDS ) { for( i = 0; i < num_genes1; i++ ) { if( genes1[i].exonCount >= 2 ) { } else { genes1[i].type = REDUN; } } } else { fatalf("Unsupported type: %d\n", type); } }
GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(State* state, GrBatch* batch) { // Check if there is a Batch Draw we can batch with by linearly searching back until we either // 1) check every draw // 2) intersect with something // 3) find a 'blocker' // Experimentally we have found that most batching occurs within the first 10 comparisons. static const int kMaxLookback = 10; int i = 0; batch->setPipeline(state->getPipeline()); GrRenderTarget* rt = state->getPipeline()->getRenderTarget(); GrBATCH_INFO("Re-Recording (%s, B%u)\n" "\tRenderTarget %p\n" "\tBounds (%f, %f, %f, %f)\n", batch->name(), batch->uniqueID(), rt, batch->bounds().fLeft, batch->bounds().fRight, batch->bounds().fTop, batch->bounds().fBottom); #if GR_BATCH_SPEW SkDebugf("\tColorStages:\n"); for (int i = 0; i < state->getPipeline()->numColorFragmentStages(); i++) { SkDebugf("\t\t%s\n", state->getPipeline()->getColorStage(i).processor()->name()); } SkDebugf("\tCoverageStages:\n"); for (int i = 0; i < state->getPipeline()->numCoverageFragmentStages(); i++) { SkDebugf("\t\t%s\n", state->getPipeline()->getCoverageStage(i).processor()->name()); } SkDebugf("\tXP: %s\n", state->getPipeline()->getXferProcessor()->name()); #endif GrBATCH_INFO("\tOutcome:\n"); if (!this->cmdBuffer()->empty()) { GrTargetCommands::CmdBuffer::ReverseIter reverseIter(*this->cmdBuffer()); do { if (Cmd::kDrawBatch_CmdType == reverseIter->type()) { DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get()); if (previous->fBatch->pipeline()->getRenderTarget() != rt) { GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", previous->fBatch->name(), previous->fBatch->uniqueID()); break; } // We cannot continue to search backwards if the render target changes if (previous->fBatch->combineIfPossible(batch)) { GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", previous->fBatch->name(), previous->fBatch->uniqueID()); return NULL; } if (intersect(previous->fBatch->bounds(), batch->bounds())) { GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", previous->fBatch->name(), previous->fBatch->uniqueID()); break; } } else if (Cmd::kClear_CmdType == reverseIter->type()) { Clear* previous = static_cast<Clear*>(reverseIter.get()); // We cannot continue to search backwards if the render target changes if (previous->renderTarget() != rt) { GrBATCH_INFO("\t\tBreaking because of Clear's Rendertarget change\n"); break; } // We set the color to illegal if we are doing a discard. if (previous->fColor == GrColor_ILLEGAL || intersect(batch->bounds(), previous->fRect)) { GrBATCH_INFO("\t\tBreaking because of Clear intersection\n"); break; } } else { GrBATCH_INFO("\t\tBreaking because of other %08x\n", reverseIter->type()); // TODO temporary until we can navigate the other types of commands break; } } while (reverseIter.previous() && ++i < kMaxLookback); #if GR_BATCH_SPEW if (!reverseIter.get()) { GrBATCH_INFO("\t\tNo more commands to try and batch with\n"); } else if (i >= kMaxLookback) { GrBATCH_INFO("\t\tReached max lookback %d\n", i); } #endif } #if GR_BATCH_SPEW else { GrBATCH_INFO("\t\tBreaking because empty command buffer\n"); } #endif return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (state, batch, this->batchTarget())); }
int main(int argc, char **argv) { /* code add by andrew GONG for reading file from command line argument */ point p[N]; point q[N]; point array[V]; unsigned int G[V][V]; point s = {0, 0}; point t = {0, 0}; int i, j, k; int press; i = j = k = 0; press = 0; for (i = 0; i < N; i++) { p[i].x = p[i].y = 0; q[i].x = q[i].y = 0; } if(argc != 2) { printf("usage:%s filename", argv[0]); } else { FILE *file = fopen(argv[1], "r"); if(file == 0) { printf("Could not open file!\n"); } else { i = 0; printf("%s\n", argv[1]); while(!feof(file)) { if(fscanf(file, "S (%d, %d) (%d, %d)\n", &p[i].x, &p[i].y, &q[i].x, &q[i].y) != 4) { break; } else { i++; } } } fclose(file); } /* opening display: basic connection to X Server */ if( (display_ptr = XOpenDisplay(display_name)) == NULL ) { printf("Could not open display. \n"); exit(-1); } printf("Connected to X server %s\n", XDisplayName(display_name)); screen_num = DefaultScreen(display_ptr); screen_ptr = DefaultScreenOfDisplay(display_ptr); color_map = XDefaultColormap(display_ptr, screen_num); display_width = DisplayWidth(display_ptr, screen_num); display_height = DisplayHeight(display_ptr, screen_num); printf("Width %d, Height %d, Screen Number %d\n", display_width, display_height, screen_num); /* creating the window */ border_width = 10; win_x = 0; win_y = 0; win_width = display_width/2; win_height = (unsigned int) (win_width / 1.7); /* rectangular window */ win= XCreateSimpleWindow(display_ptr, RootWindow(display_ptr, screen_num), win_x, win_y, win_width, win_height, border_width, BlackPixel(display_ptr, screen_num), WhitePixel(display_ptr, screen_num)); /* now try to put it on screen, this needs cooperation of window manager */ size_hints = XAllocSizeHints(); wm_hints = XAllocWMHints(); class_hints = XAllocClassHint(); if( size_hints == NULL || wm_hints == NULL || class_hints == NULL ) { printf("Error allocating memory for hints. \n"); exit(-1); } size_hints -> flags = PPosition | PSize | PMinSize ; size_hints -> min_width = 60; size_hints -> min_height = 60; XStringListToTextProperty(&win_name_string, 1, &win_name); XStringListToTextProperty(&icon_name_string, 1, &icon_name); wm_hints -> flags = StateHint | InputHint ; wm_hints -> initial_state = NormalState; wm_hints -> input = False; class_hints -> res_name = "x_use_example"; class_hints -> res_class = "examples"; XSetWMProperties(display_ptr, win, &win_name, &icon_name, argv, argc, size_hints, wm_hints, class_hints); /* what events do we want to receive */ XSelectInput(display_ptr, win, ExposureMask | StructureNotifyMask | ButtonPressMask); /* finally: put window on screen */ XMapWindow(display_ptr, win); XFlush(display_ptr); /* create graphics context, so that we may draw in this window */ gc = XCreateGC(display_ptr, win, valuemask, &gc_values); XSetForeground(display_ptr, gc, BlackPixel(display_ptr, screen_num)); XSetLineAttributes(display_ptr, gc, 2, LineSolid, CapRound, JoinRound); /* and three other graphics contexts, to draw in yellow and red and grey */ gc_yellow = XCreateGC( display_ptr, win, valuemask, &gc_yellow_values); XSetLineAttributes(display_ptr, gc_yellow, 2, LineSolid, CapRound, JoinRound); if(XAllocNamedColor(display_ptr, color_map, "yellow", &tmp_color1, &tmp_color2 ) == 0) {printf("failed to get color yellow\n"); exit(-1); } else XSetForeground(display_ptr, gc_yellow, tmp_color1.pixel); gc_red = XCreateGC(display_ptr, win, valuemask, &gc_red_values); /* XSetLineAttributes(display_ptr, gc_red, 6, LineSolid, CapRound, JoinRound); */ if( XAllocNamedColor(display_ptr, color_map, "red", &tmp_color1, &tmp_color2) == 0 ) {printf("failed to get color red\n"); exit(-1);} else XSetForeground(display_ptr, gc_red, tmp_color1.pixel); gc_grey = XCreateGC(display_ptr, win, valuemask, &gc_grey_values); if( XAllocNamedColor(display_ptr, color_map, "light grey", &tmp_color1, &tmp_color2) == 0) {printf("failed to get color grey\n"); exit(-1);} else XSetForeground(display_ptr, gc_grey, tmp_color1.pixel); /* and now it starts: the event loop */ while(1) { XNextEvent( display_ptr, &report ); switch(report.type) { case Expose: /* (re-)draw the example figure. This event happens * each time some part ofthe window gets exposed (becomes visible) */ /* print all the obstacles */ for (i = 0; i < N; i++) { if (p[i].x != 0 && p[i].y != 0 && q[i].x != 0 && q[i].y !=0) { XDrawLine(display_ptr, win, gc, p[i].x, p[i].y, q[i].x, q[i].y); } } break; case ConfigureNotify: /* This event happens when the user changes the size of the window */ win_width = report.xconfigure.width; win_height = report.xconfigure.height; break; /* This event happens when the user pushes a mouse button. I draw * a circle to show the point where it happened, but do not save * the position; so when the next redraw event comes, these circles * disappear again. */ case ButtonPress: { int x, y; x = report.xbutton.x; y = report.xbutton.y; /* read point s, t */ if (press == 0) { s.x = report.xbutton.x; s.y = report.xbutton.y; } else if (press == 1) { t.x = report.xbutton.x; t.y = report.xbutton.y; } press += 1; if (report.xbutton.button == Button1) XFillArc(display_ptr, win, gc_red, x - win_height/40, y - win_height/40, win_height / 20, win_height / 20, 0, 360*64); else XFillArc(display_ptr, win, gc_yellow, x - win_height / 40, y - win_height / 40, win_height / 20, win_height / 20, 0, 360*64); printf("%d, %d, %d, %d\n", s.x, s.y, t.x, t.y); printf("press = %d\n", press); if (press == 2) { XFlush(display_ptr); /* construction graph G *s is the first point and t is the last point */ array[0].x = s.x; array[0].y = s.y; array[V-1].x = t.x; array[V-1].y = t.y; for (i = 1; i < V-1; i++) { if ( i <= N ) { array[i].x = p[i-1].x; array[i].y = p[i-1].y; } else if (i > N) { array[i].x = q[i-N-1].x; array[i].y = q[i-N-1].y; } } for (i = 0; i < V; i++) { int j; for(j = 0; j < V; j++) { if (( array[i].x == 0 && array[i].y == 0 ) || ( array[j].x == 0 && array[j].y == 0)) { G[i][j] = INT_MAX; } else { G[i][j] = distant(array[i],array[j]); } for (k = 0; k < N; k++) { if (p[k].x != 0 && p[k].y != 0 && q[k].x != 0 && q[k].y != 0 && array[i].x !=0 && array[i].y !=0 && intersect( array[i], array[j], p[k], q[k])) { G[i][j] = INT_MAX; } } } } dijkstra(G, 0, array); } } break; default: /* this is a catch-all for other events; it does not do anything. *One could look at the report type to see what the event was */ break; } } exit(0); }
bool check(const Line &u, const Line &v, const Line &w) { return w.include(intersect(u, v)); }
PlaneTriResult planeTriIntersection(const float *plane, // the plane equation in Ax+By+Cz+D format const float *triangle, // the source triangle. unsigned int tstride, // stride in bytes of the input and output triangles float epsilon, // the co-planer epsilon value. float *front, // the triangle in front of the unsigned int &fcount, // number of vertices in the 'front' triangle float *back, // the triangle in back of the plane unsigned int &bcount) // the number of vertices in the 'back' triangle. { fcount = 0; bcount = 0; const char *tsource = (const char *)triangle; // get the three vertices of the triangle. const float *p1 = (const float *)(tsource); const float *p2 = (const float *)(tsource + tstride); const float *p3 = (const float *)(tsource + tstride * 2); PlaneTriResult r1 = getSidePlane(p1, plane, epsilon); // compute the side of the plane each vertex is on PlaneTriResult r2 = getSidePlane(p2, plane, epsilon); PlaneTriResult r3 = getSidePlane(p3, plane, epsilon); if (r1 == r2 && r1 == r3) // if all three vertices are on the same side of the plane. { if (r1 == PTR_FRONT) // if all three are in front of the plane, then copy to the 'front' output triangle. { add(p1, front, tstride, fcount); add(p2, front, tstride, fcount); add(p3, front, tstride, fcount); } else { add(p1, back, tstride, bcount); // if all three are in 'abck' then copy to the 'back' output triangle. add(p2, back, tstride, bcount); add(p3, back, tstride, bcount); } return r1; // if all three points are on the same side of the plane return result } // ok.. we need to split the triangle at the plane. // First test ray segment P1 to P2 if (r1 == r2) // if these are both on the same side... { if (r1 == PTR_FRONT) { add(p1, front, tstride, fcount); add(p2, front, tstride, fcount); } else { add(p1, back, tstride, bcount); add(p2, back, tstride, bcount); } } else { float split[3]; // split the point intersect(p1, p2, split, plane); if (r1 == PTR_FRONT) { add(p1, front, tstride, fcount); add(split, front, tstride, fcount); add(split, back, tstride, bcount); add(p2, back, tstride, bcount); } else { add(p1, back, tstride, bcount); add(split, back, tstride, bcount); add(split, front, tstride, fcount); add(p2, front, tstride, fcount); } } // Next test ray segment P2 to P3 if (r2 == r3) // if these are both on the same side... { if (r3 == PTR_FRONT) { add(p3, front, tstride, fcount); } else { add(p3, back, tstride, bcount); } } else { float split[3]; // split the point intersect(p2, p3, split, plane); if (r3 == PTR_FRONT) { add(split, front, tstride, fcount); add(split, back, tstride, bcount); add(p3, front, tstride, fcount); } else { add(split, front, tstride, fcount); add(split, back, tstride, bcount); add(p3, back, tstride, bcount); } } // Next test ray segment P3 to P1 if (r3 != r1) // if these are both on the same side... { float split[3]; // split the point intersect(p3, p1, split, plane); if (r1 == PTR_FRONT) { add(split, front, tstride, fcount); add(split, back, tstride, bcount); } else { add(split, front, tstride, fcount); add(split, back, tstride, bcount); } } return PTR_SPLIT; }
/*{{{ shape -- reshape a window to specified dimensions*/ int shape(int x, int y, int dx, int dy) { int sx, sy, w, h; WINDOW *win; if (dx > 0) { sx = x; w = dx; } else { sx = x + dx; w = -dx; } if (dy > 0) { sy = y; h = dy; } else { sy = y + dy; h = -dy; } if (sx < 0) sx = 0; if (sx + w >= BIT_WIDE(screen)) w = BIT_WIDE(screen) - sx; if (sy + h >= BIT_HIGH(screen)) h = BIT_HIGH(screen) - sy; if (w < 2 * ACTIVE(borderwid) + ACTIVE(font)->head.wide * MIN_X || h < 2 * ACTIVE(borderwid) + ACTIVE(font)->head.high * MIN_Y) return (-1); #ifdef MGR_ALIGN alignwin(screen, &sx, &w, ACTIVE(borderwid)); #endif /* remove current window position */ save_win(active); erase_win(ACTIVE(border)); clip_bad(active); /* invalidate clip lists */ /* redraw remaining windows */ repair(active); /* adjust window state */ ACTIVE(x0) = sx; ACTIVE(y0) = sy; bit_destroy(ACTIVE(window)); bit_destroy(ACTIVE(border)); ACTIVE(border) = bit_create(screen, sx, sy, w, h); ACTIVE(window) = bit_create(ACTIVE(border), ACTIVE(borderwid), ACTIVE(borderwid), w - ACTIVE(borderwid) * 2, h - ACTIVE(borderwid) * 2); for (win = ACTIVE(next); win != (WINDOW *)0; win = W(next)) { if (W(flags) & W_ACTIVE && intersect(active, win)) save_win(win); } CLEAR(ACTIVE(window), PUTOP(BIT_CLR, ACTIVE(style))); border(active, BORDER_THIN); bit_blit(ACTIVE(border), 0, 0, BIT_WIDE(ACTIVE(save)) - ACTIVE(borderwid), BIT_HIGH(ACTIVE(save)) - ACTIVE(borderwid), BIT_SRC, ACTIVE(save), 0, 0); /* make sure character cursor is in a good spot */ if (ACTIVE(x) > BIT_WIDE(ACTIVE(window))) { ACTIVE(x) = 0; ACTIVE(y) += ((int)(ACTIVE(font)->head.high)); } if (ACTIVE(y) > BIT_HIGH(ACTIVE(window))) { #ifdef WIERD ACTIVE(y) = BIT_HIGH(ACTIVE(window)); scroll(ACTIVE(window), 0, BIT_HIGH(ACTIVE(window)), ((int)(ACTIVE(font)->head.high)), SWAPCOLOR(ACTIVE(style))); bit_blit(ACTIVE(window), 0, BIT_HIGH(ACTIVE(window)) - ((int)(ACTIVE(font)->head.high)), BIT_WIDE(ACTIVE(save)), ((int)(ACTIVE(font)->head.high)), BIT_SRC, ACTIVE(save), ACTIVE(borderwid), BIT_HIGH(ACTIVE(save)) - ((int)(ACTIVE(font)->head.high)) - ACTIVE(borderwid)); #else ACTIVE(y) = BIT_HIGH(ACTIVE(window)) - ((int)(ACTIVE(font)->head.high)); #endif } bit_destroy(ACTIVE(save)); ACTIVE(save) = (BITMAP *)0; /* invalidate clip lists */ clip_bad(active); un_covered(); set_size(active); return (0); }
static void find_maximum_aspect_rectangle (Rectangle *r, Point points[4], gint p) { Point a = points[ p % 4]; /* 0 1 2 3 */ Point b = points[(p + 1) % 4]; /* 1 2 3 0 */ Point c = points[(p + 2) % 4]; /* 2 3 0 1 */ Point d = points[(p + 3) % 4]; /* 3 0 1 2 */ Point i1; /* intersection point */ Point i2; /* intersection point */ Point i3; /* intersection point */ if (intersect_x (b, c, a, &i1)) { i2.x = i1.x + 1.0 * r->aspect; i2.y = i1.y + 1.0; if (intersect (d, a, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (a, b, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (c, d, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); i2.x = i1.x - 1.0 * r->aspect; i2.y = i1.y + 1.0; if (intersect (d, a, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (a, b, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (c, d, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); } if (intersect_y (b, c, a, &i1)) { i2.x = i1.x + 1.0 * r->aspect; i2.y = i1.y + 1.0; if (intersect (d, a, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (a, b, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (c, d, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); i2.x = i1.x - 1.0 * r->aspect; i2.y = i1.y + 1.0; if (intersect (d, a, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (a, b, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (c, d, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); } if (intersect_x (c, d, a, &i1)) { i2.x = i1.x + 1.0 * r->aspect; i2.y = i1.y + 1.0; if (intersect (d, a, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (a, b, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (b, c, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); i2.x = i1.x - 1.0 * r->aspect; i2.y = i1.y + 1.0; if (intersect (d, a, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (a, b, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (b, c, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); } if (intersect_y (c, d, a, &i1)) { i2.x = i1.x + 1.0 * r->aspect; i2.y = i1.y + 1.0; if (intersect (d, a, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (a, b, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (b, c, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); i2.x = i1.x - 1.0 * r->aspect; i2.y = i1.y + 1.0; if (intersect (d, a, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (a, b, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); if (intersect (b, c, i1, i2, &i3)) add_rectangle (points, r, i1, i3, i1, i3); } }
bool Quadrangle::overlap(Quadrangle q) { return isIn(q) || intersect(q) || q.isIn(*this) || q.intersect(*this); }
bool intersect(const Ray& _ray, const Cylinder& _cylinder, bool _capsule, Intersection* _intersection) { float axis[3]; bx::vec3Sub(axis, _cylinder.m_end, _cylinder.m_pos); float rc[3]; bx::vec3Sub(rc, _ray.m_pos, _cylinder.m_pos); float normal[3]; bx::vec3Cross(normal, _ray.m_dir, axis); const float len = bx::vec3Norm(normal, normal); const float dist = bx::fabsolute(bx::vec3Dot(rc, normal) ); if (dist > _cylinder.m_radius) { return false; } float vo[3]; bx::vec3Cross(vo, rc, axis); const float t0 = -bx::vec3Dot(vo, normal) / len; bx::vec3Cross(vo, normal, axis); bx::vec3Norm(vo, vo); const float rsq = bx::fsq(_cylinder.m_radius); const float ddoto = bx::vec3Dot(_ray.m_dir, vo); const float ss = t0 - bx::fabsolute(bx::fsqrt(rsq - bx::fsq(dist) ) / ddoto); float point[3]; getPointAt(point, _ray, ss); const float axisLen = bx::vec3Norm(axis, axis); const float pdota = bx::vec3Dot(_cylinder.m_pos, axis); const float height = bx::vec3Dot(point, axis) - pdota; if (height > 0.0f && height < axisLen) { if (NULL != _intersection) { const float t1 = height / axisLen; float pointOnAxis[3]; bx::vec3Lerp(pointOnAxis, _cylinder.m_pos, _cylinder.m_end, t1); bx::vec3Move(_intersection->m_pos, point); float tmp[3]; bx::vec3Sub(tmp, point, pointOnAxis); bx::vec3Norm(_intersection->m_normal, tmp); _intersection->m_dist = ss; } return true; } if (_capsule) { const float rdota = bx::vec3Dot(_ray.m_pos, axis); const float pp = rdota - pdota; const float t1 = pp / axisLen; float pointOnAxis[3]; bx::vec3Lerp(pointOnAxis, _cylinder.m_pos, _cylinder.m_end, t1); float axisToRay[3]; bx::vec3Sub(axisToRay, _ray.m_pos, pointOnAxis); if (_cylinder.m_radius < bx::vec3Length(axisToRay) && 0.0f > ss) { return false; } Sphere sphere; sphere.m_radius = _cylinder.m_radius; bx::vec3Move(sphere.m_center, 0.0f >= height ? _cylinder.m_pos : _cylinder.m_end ); return intersect(_ray, sphere, _intersection); } Plane plane; float pos[3]; if (0.0f >= height) { bx::vec3Neg(plane.m_normal, axis); bx::vec3Move(pos, _cylinder.m_pos); } else { bx::vec3Move(plane.m_normal, axis); bx::vec3Move(pos, _cylinder.m_end); } plane.m_dist = -bx::vec3Dot(pos, plane.m_normal); Intersection tmpIntersection; _intersection = NULL != _intersection ? _intersection : &tmpIntersection; if (intersect(_ray, plane, _intersection) ) { float tmp[3]; bx::vec3Sub(tmp, pos, _intersection->m_pos); return bx::vec3Dot(tmp, tmp) <= rsq; } return false; }
inline void t_sorted_clip_list::intersect( t_quadtree_node& parent_node, t_screen_rect const & query_area , t_rect_list & result, int depth) { //to find all the rects that intersect with the given rectangle, we walk the tree //-if the query_area contains the full extent, then return the entire list of rects //-check the query_area against each node starting with the parent. //-if the query_area interects or is contained wihin a child area walk down that // childs nodes // a)if intersect, walk down child node // b)if contained, walk only down this child node, all others can be ignored intersect_rect( parent_node, query_area, result ); depth++; if (depth > m_sub_division_level) return; //query for containment ( early out )/////////////////////////////////////////////// //stop search if containment is found. if (m_quadtree_array[parent_node.node_a].area.contains( query_area ) == true) { intersect( m_quadtree_array[parent_node.node_a], query_area, result, depth ); return; } if (m_quadtree_array[parent_node.node_b].area.contains( query_area ) == true) { intersect( m_quadtree_array[parent_node.node_b], query_area, result, depth ); return; } if (m_quadtree_array[parent_node.node_c].area.contains( query_area ) == true) { intersect( m_quadtree_array[parent_node.node_c], query_area, result, depth ); return; } if (m_quadtree_array[parent_node.node_d].area.contains( query_area ) == true) { intersect( m_quadtree_array[parent_node.node_d], query_area, result, depth ); return; } //query each child_node///////////////////////////////////////////////////////////// if (::intersect(m_quadtree_array[parent_node.node_a].area, query_area)==true) { intersect( m_quadtree_array[parent_node.node_a], query_area, result, depth ); } if (::intersect(m_quadtree_array[parent_node.node_b].area, query_area)==true) { intersect( m_quadtree_array[parent_node.node_b], query_area, result, depth ); } if (::intersect(m_quadtree_array[parent_node.node_c].area, query_area)==true) { intersect( m_quadtree_array[parent_node.node_c], query_area, result, depth ); } if (::intersect(m_quadtree_array[parent_node.node_d].area, query_area)==true) { intersect( m_quadtree_array[parent_node.node_d], query_area, result, depth ); } return; }
bool Warp::accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc_, ProgressCallback *cb)const { Point src_tl=param_src_tl.get(Point()); Point src_br=param_src_br.get(Point()); Point dest_tl=param_dest_tl.get(Point()); Point dest_tr=param_dest_tr.get(Point()); Point dest_bl=param_dest_bl.get(Point()); Point dest_br=param_dest_br.get(Point()); Real horizon=param_horizon.get(Real()); bool clip=param_clip.get(bool()); SuperCallback stageone(cb,0,9000,10000); SuperCallback stagetwo(cb,9000,10000,10000); RendDesc renddesc(renddesc_); // Untransform the render desc if(!cairo_renddesc_untransform(cr, renddesc)) return false; Real pw=(renddesc.get_w())/(renddesc.get_br()[0]-renddesc.get_tl()[0]); Real ph=(renddesc.get_h())/(renddesc.get_br()[1]-renddesc.get_tl()[1]); if(cb && !cb->amount_complete(0,10000)) return false; Point tl(renddesc.get_tl()); Point br(renddesc.get_br()); Rect bounding_rect; Rect render_rect(tl,br); Rect clip_rect(Rect::full_plane()); Rect dest_rect(dest_tl,dest_br); dest_rect.expand(dest_tr).expand(dest_bl); Real zoom_factor(1.0); // Quick exclusion clip, if necessary if(clip && !intersect(render_rect,dest_rect)) { cairo_save(cr); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_restore(cr); return true; } { Rect other(render_rect); if(clip) other&=dest_rect; Point min(other.get_min()); Point max(other.get_max()); bool init_point_set=false; // Point trans_point[4]; Point p; // Real trans_z[4]; Real z,minz(10000000000000.0f),maxz(0); //! \todo checking the 4 corners for 0<=z<horizon*2 and using //! only 4 corners which satisfy this condition isn't the //! right thing to do. It's possible that none of the 4 //! corners fall within that range, and yet content of the //! tile does. p=transform_forward(min); z=transform_backward_z(p); if(z>0 && z<horizon*2) { if(init_point_set) bounding_rect.expand(p); else bounding_rect=Rect(p); init_point_set=true; maxz=std::max(maxz,z); minz=std::min(minz,z); } p=transform_forward(max); z=transform_backward_z(p); if(z>0 && z<horizon*2) { if(init_point_set) bounding_rect.expand(p); else bounding_rect=Rect(p); init_point_set=true; maxz=std::max(maxz,z); minz=std::min(minz,z); } swap(min[1],max[1]); p=transform_forward(min); z=transform_backward_z(p); if(z>0 && z<horizon*2) { if(init_point_set) bounding_rect.expand(p); else bounding_rect=Rect(p); init_point_set=true; maxz=std::max(maxz,z); minz=std::min(minz,z); } p=transform_forward(max); z=transform_backward_z(p); if(z>0 && z<horizon*2) { if(init_point_set) bounding_rect.expand(p); else bounding_rect=Rect(p); init_point_set=true; maxz=std::max(maxz,z); minz=std::min(minz,z); } if(!init_point_set) { cairo_save(cr); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_restore(cr); return true; } zoom_factor=(1+(maxz-minz)); } #ifdef ACCEL_WARP_IS_BROKEN return Layer::accelerated_cairorender(context,cr,quality,renddesc, cb); #else /*swap(tl[1],br[1]); bounding_rect .expand(transform_forward(tl)) .expand(transform_forward(br)) ; swap(tl[1],br[1]);*/ //synfig::warning("given window: [%f,%f]-[%f,%f] %dx%d",tl[0],tl[1],br[0],br[1],renddesc.get_w(),renddesc.get_h()); //synfig::warning("Projected: [%f,%f]-[%f,%f]",bounding_rect.get_min()[0],bounding_rect.get_min()[1],bounding_rect.get_max()[0],bounding_rect.get_max()[1]); // If we are clipping, then go ahead and clip to the // source rectangle if(clip) clip_rect&=Rect(src_tl,src_br); // Bound ourselves to the bounding rectangle of // what is under us clip_rect&=context.get_full_bounding_rect();//.expand_x(abs(zoom_factor/pw)).expand_y(abs(zoom_factor/ph)); bounding_rect&=clip_rect; Point min_point(bounding_rect.get_min()); Point max_point(bounding_rect.get_max()); // we're going to divide by the difference of these pairs soon; // if they're the same, we'll be dividing by zero, and we don't // want to do that! // \todo what should we do in this case? if (min_point[0] == max_point[0]) max_point[0] += 0.001; if (min_point[1] == max_point[1]) max_point[1] += 0.001; if(tl[0]>br[0]) { tl[0]=max_point[0]; br[0]=min_point[0]; } else { br[0]=max_point[0]; tl[0]=min_point[0]; } if(tl[1]>br[1]) { tl[1]=max_point[1]; br[1]=min_point[1]; } else { br[1]=max_point[1]; tl[1]=min_point[1]; } const int tmp_d(max(renddesc.get_w(),renddesc.get_h())); Real src_pw=(tmp_d*zoom_factor)/(br[0]-tl[0]); Real src_ph=(tmp_d*zoom_factor)/(br[1]-tl[1]); RendDesc desc(renddesc); desc.clear_flags(); //desc.set_flags(RendDesc::PX_ASPECT); desc.set_tl(tl); desc.set_br(br); desc.set_wh(ceil_to_int(src_pw*(br[0]-tl[0])),ceil_to_int(src_ph*(br[1]-tl[1]))); //synfig::warning("surface to render: [%f,%f]-[%f,%f] %dx%d",desc.get_tl()[0],desc.get_tl()[1],desc.get_br()[0],desc.get_br()[1],desc.get_w(),desc.get_h()); if(desc.get_w()==0 && desc.get_h()==0) { cairo_save(cr); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_restore(cr); return true; } // Recalculate the pixel widths for the src renddesc src_pw=(desc.get_w())/(desc.get_br()[0]-desc.get_tl()[0]); src_ph=(desc.get_h())/(desc.get_br()[1]-desc.get_tl()[1]); cairo_surface_t* source=cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA, desc.get_w(),desc.get_h()); cairo_surface_t* surface=cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA,renddesc.get_w(), renddesc.get_h()); cairo_t* subcr=cairo_create(source); cairo_scale(subcr, 1/desc.get_pw(), 1/desc.get_ph()); cairo_translate(subcr, -desc.get_tl()[0], -desc.get_tl()[1]); if(!context.accelerated_cairorender(subcr,quality,desc,&stageone)) return false; cairo_destroy(subcr); int surfacew, surfaceh, sourcew, sourceh; CairoSurface csurface(surface); CairoSurface csource(source); csurface.map_cairo_image(); csource.map_cairo_image(); surfacew=csurface.get_w(); surfaceh=csurface.get_h(); sourcew=csource.get_w(); sourceh=csource.get_h(); CairoSurface::pen pen(csurface.begin()); // Do the warp { int x,y; float u,v; Point point,tmp; for(y=0,point[1]=renddesc.get_tl()[1];y<surfaceh;y++,pen.inc_y(),pen.dec_x(x),point[1]+=1.0/ph) { for(x=0,point[0]=renddesc.get_tl()[0];x<surfacew;x++,pen.inc_x(),point[0]+=1.0/pw) { tmp=transform_forward(point); const float z(transform_backward_z(tmp)); if(!clip_rect.is_inside(tmp) || !(z>0 && z<horizon)) { csurface[y][x]=Color::alpha(); continue; } u=(tmp[0]-tl[0])*src_pw; v=(tmp[1]-tl[1])*src_ph; if(u<0 || v<0 || u>=sourcew || v>=sourceh || isnan(u) || isnan(v)) csurface[y][x]=context.get_cairocolor(tmp); else { // CUBIC if(quality<=4) csurface[y][x]=csource.cubic_sample_cooked(u,v); // INTEPOLATION_LINEAR else if(quality<=6) csurface[y][x]=csource.linear_sample_cooked(u,v); else // NEAREST_NEIGHBOR csurface[y][x]=csource[floor_to_int(v)][floor_to_int(u)]; } } if((y&31)==0 && cb) { if(!stagetwo.amount_complete(y,surfaceh)) return false; } } } #endif if(cb && !cb->amount_complete(10000,10000)) return false; csurface.unmap_cairo_image(); csource.unmap_cairo_image(); cairo_surface_destroy(source); cairo_save(cr); cairo_translate(cr, renddesc.get_tl()[0], renddesc.get_tl()[1]); cairo_scale(cr, renddesc.get_pw(), renddesc.get_ph()); cairo_set_source_surface(cr, surface, 0, 0); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_restore(cr); cairo_surface_destroy(surface); return true; }
/** * Compute recursivly the color contribution of one ray. * @param currentRay the ray whose contribution is computed. * @return the color associated with the ray contribution. */ glm::vec3 Scene::getColor(const ray::Ray & currentRay) { glm::vec3 color(0,0,0); scene::Intersection inter; if(intersect(currentRay,inter)) { glm::vec3 pointHit=inter.getPoint(); glm::vec3 normalHit=inter.getNormal(); glm::vec3 incident = currentRay.getDirection(); materials::Material * materialHit=inter.getMaterial(); float alpha = 1.0; // Part 1 : Light contribution for(iterator_light it=begin_light(); it!=end_light();++it) { glm::vec3 direction=(*it)->getPosition()-pointHit; ray::ShadowRay shadowRay(pointHit,direction,0.001, getCamera()->getFarPlan(),1); scene::Intersection dummyInter; ray::ShadowRay dummyRay(shadowRay); float attenuation = 0.0; while(intersect(shadowRay,dummyInter)) { shadowRay.setOrigin(dummyInter.getPoint()); attenuation+=1-dummyInter.getMaterial()->getTransmissionAttenuation(); if(attenuation >= 1.0) { attenuation=1.0; break; } } glm::vec3 matColor= materialHit->computeBRDF(shadowRay, normalHit); glm::vec3 lightColor=(*it)->powerAt(pointHit); glm::vec3 lightContribution=componentProduct(matColor, lightColor); lightContribution = glm::clamp(lightContribution, glm::vec3(0),glm::vec3(1)); alpha = materialHit->getTransmissionAttenuation(); color+=(1-attenuation)*(1-alpha)*lightContribution; } // Part 2 : Other rays // 2 steps : computing ray direction then getting color recursively if(currentRay.getBounces() > 0) { float coeff=fabs(glm::dot(currentRay.getDirection(),normalHit)); // Reflexion ray if(coeff*materialHit->getReflexionAttenuation()>EPSILON) { ray::ReflexionRay reflexionRay(pointHit,glm::reflect(incident,normalHit), 0.001,getCamera()->getFarPlan(), currentRay.getBounces()-1); color+=coeff*materialHit->getReflexionAttenuation()* getColor(reflexionRay); } // Transmission ray float alpha = materialHit->getTransmissionAttenuation(); alpha*=coeff; if(alpha>EPSILON) { glm::vec3 dummyVec = glm::dot(incident,normalHit) * normalHit - incident; float sinT1 = glm::dot(dummyVec,dummyVec); float cosT1 = sqrt(fabs(1-sinT1*sinT1)); float eta12 = currentRay.getMRI()/materialHit->getMRI(); float c = 1-eta12*eta12*sinT1*sinT1; c = (c>0) ? c : 0; float dF1 = (eta12 * cosT1 - sqrt(c)); glm::vec3 transmittedDirection = eta12 * incident + (dF1 * normalHit); transmittedDirection = glm::normalize(transmittedDirection); ray::TransmissionRay transmittedRay(pointHit, transmittedDirection, 0.001, getCamera()->getFarPlan(), currentRay.getBounces()-1, (eta12==1.0) ? 1.0 : materialHit->getMRI() ); color+=alpha*getColor(transmittedRay); } } } return color; }
bool CollisionBox::AABB_POINT(CollisionBox &CB1, CollisionBox &CB2) { return (intersect((CB1.Position + CB1.ColBox + CB1.ColOffset), (CB1.Position - CB1.ColBox + CB1.ColOffset), CB2.Position)); }
void MaizeDetector::processLaserScan( const sensor_msgs::LaserScan::ConstPtr& laser_scan) { float rthetamean = 0, rrhomean = 0, lthetamean = 0, lrhomean = 0, theta = 0, rho = 0; double x0 = 0, y0 = 0, a, b; int lmc = 0, rmc = 0; static int right_count = 0; static int left_count = 0; clearRawImage(); tf::TransformListener listener_; sensor_msgs::PointCloud cloud; try { projector_.projectLaser(*laser_scan, cloud); // projector_.transformLaserScanToPointCloud("base_link",*laser_scan,cloud,listener_); } catch (tf::TransformException& e) { std::cout << e.what(); return; } //ROS_INFO("Got it right"); int size = cloud.points.size(); for (int i = 0; i < size; i++) { //if (((abs(cloud.points[i].y))-((cloud.points[i].x-300)*0.5))<0.65) { if (abs((cloud.points[i].y))<0.65 && cloud.points[i].x >0 ) { point1.x = ((int)(cloud.points[i].x * 50) + 300); point1.y = ((int)(cloud.points[i].y * 50) + 300); point2.x = point1.x-4; point2.y = point1.y; cvLine(rawData_, point1, point2, CV_RGB(255,255,255), 3, CV_AA, 0); } } cvCvtColor(rawData_, workingImg_, CV_BGR2GRAY); cvDilate(rawData_,rawData_,NULL,6); cvErode(rawData_,rawData_,NULL,4); lines_ = cvHoughLines2(workingImg_, storage_, CV_HOUGH_STANDARD, 1, CV_PI/ 180, 60, 0, 0); //lines_ = cvHoughLines2(workingImg_, storage_, CV_HOUGH_PROBABILISTIC, 1, CV_PI/360, 30, 10, 30); for(int i = 0; i < MIN(lines_->total,20); i++){ //for (int i = 0; i < MIN(lines_->total,15); i++) { float* line = (float*) cvGetSeqElem(lines_, i); rho = line[0]; theta = line[1]; a = cos(theta); b = sin(theta); x0 = a * rho; y0 = b * rho; point1.x = cvRound(x0 + 600 * (-b)); point1.y = cvRound(y0 + 600 * (a)); point2.x = cvRound(x0 - 600 * (-b)); point2.y = cvRound(y0 - 600 * (a)); point3.x = 300, point3.y = 300; point4.x = 300, point4.y = 600; point5.x = 300, point5.y = 0; //cvLine(rawData_, point1, point2, CV_RGB(255,0,0), 1, CV_AA,0); cvLine(rawData_, point3, point4, CV_RGB(0,0,255), 1, CV_AA, 0); cvLine(rawData_, point3, point5, CV_RGB(0,0,255), 1, CV_AA, 0); if (intersect(point1, point2, point3, point4)) { { rrhomean += rho; rthetamean += theta; rmc++; //cvLine(workingImg_, point1, point2, CV_RGB(0,0,255), 1, CV_AA,0); } } else if (intersect(point1, point2, point3, point5)) { { lrhomean += rho; lthetamean += theta; lmc++; //cvLine(workingImg_, point1, point2, CV_RGB(255,255,255), 1,CV_AA, 0); } } } theta = lthetamean / lmc; rho = lrhomean / lmc; a = cos(theta); b = sin(theta); x0 = a * rho; y0 = b * rho; point1.x = cvRound(x0 + 600 * (-b)), point1.y = cvRound(y0 + 600 * (a)); point2.x = cvRound(x0 - 600 * (-b)), point2.y = cvRound(y0 - 600 * (a)); //cvLine(rawData_, point1, point2, CV_RGB(255,0,0), 3, CV_AA, 0); point4.x = 300; point4.y = 300; point5.x = point4.x + 800 * sin(CV_PI - (theta - CV_PI / 2)); point5.y = point4.y + 800 * cos(CV_PI - (theta - CV_PI / 2)); cvLine(rawData_, point5, point4, CV_RGB(255,255,255), 1, CV_AA, 0); rows_.header.stamp = ros::Time::now(); rows_.leftvalid = false; rows_.rightvalid = false; //detect valid lines if (intersect(point1, point2, point4, point5)) { right_distance_ = sqrt(((intersection_.y - 300) * (intersection_.y- 300)) + ((intersection_.x - 300) * (intersection_.x - 300)))* 2; right_angle_ = (theta) - CV_PI / 2; right_count++; right_angle_rolling_mean_[right_count%10] = right_angle_; right_dist_rolling_mean_[right_count%10] = right_distance_; right_angle_ = 0; right_distance_ = 0; for(int i=0;i < 10;i++){ right_angle_ += right_angle_rolling_mean_[i]; right_distance_ += right_dist_rolling_mean_[i]; } right_angle_ = right_angle_/10; right_distance_ = right_distance_ /10; ROS_WARN("right_distance_: %f",right_distance_); cvLine(rawData_, point1, point2, CV_RGB(0,255,0), 1, CV_AA, 0); marker_r.header.frame_id = "/laser_front_link"; marker_r.header.stamp = ros::Time::now(); marker_r.ns = "kf_shapes"; // Set the marker type. Initially this is CUBE, and cycles between that and SPHERE, ARROW, and CYLINDER marker_r.type = visualization_msgs::Marker::CUBE; // Set the marker action. Options are ADD and DELETE marker_r.action = visualization_msgs::Marker::ADD; // Set the pose of the marker. This is a full 6DOF pose relative to the frame/time specified in the header marker_r.id = 2; geometry_msgs::Quaternion pose_quat = tf::createQuaternionMsgFromYaw(right_angle_); marker_r.pose.position.x = 0; marker_r.pose.position.y = -((float) right_distance_) / 100; marker_r.pose.position.z = 0; marker_r.pose.orientation = pose_quat; // Set the scale of the marker -- 1x1x1 here means 1m on a side marker_r.scale.x = 10.0; marker_r.scale.y = 0.1; marker_r.scale.z = 0.5; marker_r.color.r = 0.0f; marker_r.color.g = 1.0f; marker_r.color.b = 0.0f; marker_r.color.a = 0.5; marker_r.lifetime = ros::Duration(.1); marker_r_pub.publish(marker_r); // Set the color -- be sure to set alpha to something non-zero! // Publish the marker rows_.rightvalid = true; rows_.rightdistance = ((float) right_distance_) / 100; rows_.rightangle = right_angle_; }else{ rows_.rightvalid = false; rows_.rightdistance = 0; rows_.rightangle = 0; } theta = rthetamean / rmc; rho = rrhomean / rmc; a = cos(theta); b = sin(theta); x0 = a * rho; y0 = b * rho; point1.x = cvRound(x0 + 600 * (-b)), point1.y = cvRound(y0 + 600 * (a)); point2.x = cvRound(x0 - 600 * (-b)), point2.y = cvRound(y0 - 600 * (a)); point4.x = 300; point4.y = 300; point5.x = point4.x - 800 * sin(CV_PI - (theta - CV_PI / 2)); point5.y = point4.y - 800 * cos(CV_PI - (theta - CV_PI / 2)); cvLine(rawData_, point5, point4, CV_RGB(255,255,255), 1, CV_AA, 0); //detect valid lines if (intersect(point1, point2, point4, point5)) { left_distance_ = sqrt(((intersection_.y - 300) * (intersection_.y- 300)) + ((intersection_.x - 300) * (intersection_.x - 300)))* 2; left_angle_ = (theta) - CV_PI / 2; left_count++; left_angle_rolling_mean_[left_count%10] = left_angle_; left_dist_rolling_mean_[left_count%10] = left_distance_; left_angle_ = 0; left_distance_ = 0; for(int i=0;i < 10;i++){ left_angle_ += left_angle_rolling_mean_[i]; left_distance_ += left_dist_rolling_mean_[i]; } left_angle_ = left_angle_/10; left_distance_ = left_distance_ /10; ROS_WARN("left_distance_: %f",left_distance_); marker_r.id = 1; geometry_msgs::Quaternion pose_quat = tf::createQuaternionMsgFromYaw(left_angle_); marker_r.color.r = 0.0f; marker_r.color.g = 0.0f; marker_r.color.b = 1.0f; marker_r.pose.position.x = 0; marker_r.pose.position.y = ((float) left_distance_) / 100; marker_r.pose.position.z = 0; marker_r.pose.orientation = pose_quat; marker_r_pub.publish(marker_r); //rolling_mean_[count%10] = right_angle_; //left_angle_ = 0; //for(int i=0;i < 10;i++){ // left_angle_ += rolling_mean_[i]; //} //right_angle_ = right_angle_/10; cvLine(rawData_, point1, point2, CV_RGB(0,255,255), 1, CV_AA, 0); rows_.leftvalid = true; rows_.leftdistance = ((float) left_distance_) / 100; rows_.leftangle = left_angle_; }else{ rows_.leftvalid = false; rows_.leftdistance = 0; rows_.leftangle = 0; } if (rows_.leftvalid && rows_.rightvalid){ e_angle = (rows_.leftangle + rows_.rightangle) / 2; e_distance = (rows_.leftdistance - rows_.rightdistance); row_dist_est =( (rows_.leftdistance + rows_.rightdistance) + row_dist_est)/2; ROS_INFO("2ROWS row_dist_est %f, e_dist %f",row_dist_est,e_distance); rows_.error_angle = e_angle; rows_.error_distance = e_distance; rows_.var = 5^2; marker_r.id = 3; geometry_msgs::Quaternion pose_quat = tf::createQuaternionMsgFromYaw(e_angle); marker_r.color.r = 0.0f; marker_r.color.g = 1.0f; marker_r.color.b = 1.0f; marker_r.pose.orientation = pose_quat; marker_r.pose.position.x = 0; marker_r.pose.position.y = (e_distance); marker_r.pose.position.z = 0; marker_r_pub.publish(marker_r); }else if (rows_.leftvalid && !rows_.rightvalid){ e_angle = (rows_.leftangle); e_distance = 0;//row_dist_est/2-(rows_.leftdistance); //ROS_INFO("e_angle %f, e_dist %f",e_angle,e_distance); rows_.error_angle = e_angle; rows_.error_distance = e_distance;//e_distance-(0.75/2); rows_.var = 10^2; marker_r.id = 3; ROS_INFO("LEFTROW row_dist_est %f, e_dist %f",row_dist_est,e_distance); geometry_msgs::Quaternion pose_quat = tf::createQuaternionMsgFromYaw(e_angle); marker_r.color.r = 0.0f; marker_r.color.g = 1.0f; marker_r.color.b = 1.0f; marker_r.pose.orientation = pose_quat; marker_r.pose.position.x = 0; marker_r.pose.position.y = (e_distance); marker_r.pose.position.z = 0; marker_r_pub.publish(marker_r); }else if (!rows_.leftvalid && rows_.rightvalid){ e_angle = (rows_.rightangle); e_distance = 0;//row_dist_est/2-(rows_.rightdistance); //ROS_INFO("e_angle %f, e_dist %f",e_angle,e_distance); ROS_INFO("LRIGHTROW row_dist_est %f, e_dist %f",row_dist_est,e_distance); rows_.error_angle = (0.75/2)-e_angle; rows_.error_distance = e_distance;//e_distance-(0.75/2); rows_.var = 10^2; marker_r.id = 3; geometry_msgs::Quaternion pose_quat = tf::createQuaternionMsgFromYaw(e_angle); marker_r.color.r = 0.0f; marker_r.color.g = 1.0f; marker_r.color.b = 1.0f; marker_r.pose.orientation = pose_quat; marker_r.pose.position.x = 0; marker_r.pose.position.y = (e_distance); marker_r.pose.position.z = 0; marker_r_pub.publish(marker_r); }else{ e_angle = 0; e_distance = 0; ROS_INFO("e_angle %f, e_dist %f",e_angle,e_distance); ROS_INFO("NOROW row_dist_est %f, e_dist %f",row_dist_est,e_distance); rows_.error_angle = e_angle; rows_.error_distance = e_distance; rows_.var = 4000^2; marker_r.id = 3; geometry_msgs::Quaternion pose_quat = tf::createQuaternionMsgFromYaw(e_angle); marker_r.color.r = 0.0f; marker_r.color.g = 1.0f; marker_r.color.b = 1.0f; marker_r.pose.orientation = pose_quat; marker_r.pose.position.x = 0; marker_r.pose.position.y = (e_distance); marker_r.pose.position.z = 0; marker_r_pub.publish(marker_r); } //cvLine(rawData_, cvPoint(0,300+150), cvPoint(600,300+150), CV_RGB(255,255,255), 1, CV_AA, 0); //cvLine(rawData_, cvPoint(0,300-150), cvPoint(600,300-150), CV_RGB(255,255,255), 1, CV_AA, 0); row_pub.publish(rows_); //cvShowImage("TEST", rawData_); //cvWaitKey(10); //pc_pub.publish(cloud); }
inline bool intersect(const Hittable& a, const Hittable& b) { return intersect(a.getCsucslista(),b.getCsucslista()); }
int main() { cout << intersect({0,2},{1,1}) << "\n"; cout << arc({0,1},cd(1,0),cd(0,1)) << "\n"; cout << on({0,1},1) << "\n"; }
bool KdTreeAccel::intersect(const Ray &inRay, DifferentialGeometry* queryPoint, Float* tHit, Float* rayEpsilon) const { return intersect(inRay, queryPoint, root, tHit, rayEpsilon); }