Tile::Tile(GLuint shader_id, int x, int z) { glGenVertexArrays(1, &vao); glGenBuffers(1, &vbo); glGenBuffers(1, &ebo); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); GLuint posAttrib = glGetAttribLocation(shader_id, "position_model"); GLuint norAttrib = glGetAttribLocation(shader_id, "normal_model"); GLuint texAttrib = glGetAttribLocation(shader_id, "texcoord"); GLuint colAttrib = glGetAttribLocation(shader_id, "color"); glEnableVertexAttribArray(posAttrib); glEnableVertexAttribArray(norAttrib); glEnableVertexAttribArray(texAttrib); glEnableVertexAttribArray(colAttrib); glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 11*sizeof(float), 0 ); glVertexAttribPointer(norAttrib, 3, GL_FLOAT, GL_FALSE, 11*sizeof(float), (void*)(3*sizeof(float))); glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 11*sizeof(float), (void*)(6*sizeof(float))); glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 11*sizeof(float), (void*)(8*sizeof(float))); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glEnable(GL_PRIMITIVE_RESTART); glPrimitiveRestartIndex((TILE_SIZE+1)*(TILE_SIZE+1)+TILE_SIZE); reload_vbo = false; reload_ebo = false; needs_rebuild = false; needs_gen = true; show = false; lod(0); set_xz(x,z); update_vertices(); update_indices(); }
/*! Compute the two parameters \f$(\rho, \theta)\f$ of the line. \param I : Image in which the line appears. */ void vpMeLine::computeRhoTheta(const vpImage<unsigned char>& I) { //rho = -c ; //theta = atan2(a,b) ; rho = fabs(c); theta = atan2(b,a) ; while (theta >= M_PI) theta -=M_PI ; while (theta < 0) theta +=M_PI ; if(_useIntensityForRho){ /* while(theta < -M_PI) theta += 2*M_PI ; while(theta >= M_PI) theta -= 2*M_PI ; // If theta is between -90 and -180 get the equivalent // between 0 and 90 if(theta <-M_PI/2) { theta += M_PI ; rho *= -1 ; } // If theta is between 90 and 180 get the equivalent // between 0 and -90 if(theta >M_PI/2) { theta -= M_PI ; rho *= -1 ; } */ // convention pour choisir le signe de rho int i,j ; i = vpMath::round((PExt[0].ifloat + PExt[1].ifloat )/2) ; j = vpMath::round((PExt[0].jfloat + PExt[1].jfloat )/2) ; int end = false ; int incr = 10 ; int i1=0,i2=0,j1=0,j2=0 ; unsigned char v1=0,v2=0 ; int width_ = (int)I.getWidth(); int height_ = (int)I.getHeight(); update_indices(theta,i,j,incr,i1,i2,j1,j2); if(i1<0 || i1>=height_ || i2<0 || i2>=height_ || j1<0 || j1>=width_ || j2<0 || j2>=width_){ double rho_lim1 = fabs((double)i/cos(theta)); double rho_lim2 = fabs((double)j/sin(theta)); double co_rho_lim1 = fabs(((double)(height_-i))/cos(theta)); double co_rho_lim2 = fabs(((double)(width_-j))/sin(theta)); double rho_lim = std::min(rho_lim1,rho_lim2); double co_rho_lim = std::min(co_rho_lim1,co_rho_lim2); incr = (int)std::floor(std::min(rho_lim,co_rho_lim)); if(incr<INCR_MIN){ vpERROR_TRACE("increment is too small") ; throw(vpTrackingException(vpTrackingException::fatalError, "increment is too small")) ; } update_indices(theta,i,j,incr,i1,i2,j1,j2); } while (!end) { end = true; unsigned int i1_ = static_cast<unsigned int>(i1); unsigned int j1_ = static_cast<unsigned int>(j1); unsigned int i2_ = static_cast<unsigned int>(i2); unsigned int j2_ = static_cast<unsigned int>(j2); v1=I[i1_][j1_]; v2=I[i2_][j2_]; if (abs(v1-v2) < 1) { incr-- ; end = false ; if (incr==1) { std::cout << "In CStraightLine::GetParameters() " ; std::cout << " Error Tracking " << abs(v1-v2) << std::endl ; } } update_indices(theta,i,j,incr,i1,i2,j1,j2); } if (theta >=0 && theta <= M_PI/2) { if (v2 < v1) { theta += M_PI; rho *= -1; } } else { double jinter; jinter = -c/b; if (v2 < v1) { theta += M_PI; if (jinter > 0) { rho *= -1; } } else { if (jinter < 0) { rho *= -1; } } } if (vpDEBUG_ENABLE(2)) { vpImagePoint ip, ip1, ip2; ip.set_i( i ); ip.set_j( j ); ip1.set_i( i1 ); ip1.set_j( j1 ); ip2.set_i( i2 ); ip2.set_j( j2 ); vpDisplay::displayArrow(I, ip, ip1, vpColor::green) ; vpDisplay::displayArrow(I, ip, ip2, vpColor::red) ; } } }
int lowess(const ContainerType& x, const ContainerType& y, double frac, // parameter f int nsteps, ValueType delta, ContainerType& ys, ContainerType& resid_weights, // vector rw ContainerType& weights // vector res ) { bool fit_ok; size_t ns, n(x.size()); if (n < 2) { ys[0] = y[0]; return 1; } // how many points around estimation point should be used for regression: // at least two, at most n points size_t tmp = (size_t)(frac * (double)n); ns = std::max(std::min(tmp, n), (size_t)2); // robustness iterations for (int iter = 1; iter <= nsteps + 1; iter++) { // start of array in C++ at 0 / in FORTRAN at 1 // last: index of prev estimated point // i: index of current point size_t i(0), last(-1), nleft(0), nright(ns -1); // Fit all data points y[i] until the end of the array do { // Identify the neighborhood around the current x[i] // -> get the nearest ns points update_neighborhood(x, n, i, nleft, nright); // Calculate weights and apply fit (original lowest function) fit_ok = lowest(x, y, n, x[i], ys[i], nleft, nright, weights, (iter > 1), resid_weights); // if something went wrong during the fit, use y[i] as the // fitted value at x[i] if (!fit_ok) ys[i] = y[i]; // If we skipped some points (because of how delta was set), go back // and fit them by linear interpolation. if (last < i - 1) { interpolate_skipped_fits(x, i, last, ys); } // Update the last fit counter to indicate we've now fit this point. // Find the next i for which we'll run a regression. update_indices(x, n, delta, i, last, ys); } while (last < n - 1); // compute current residuals for (i = 0; i < n; i++) { weights[i] = y[i] - ys[i]; } // compute robustness weights except last time if (iter > nsteps) break; calculate_residual_weights(n, weights, resid_weights); } return 0; }