Boundary * findBoundary(const std::vector < Node * > & n) { if (n.size() == 1) return findBoundary(*n[0]); else if (n.size() == 2) return findBoundary(*n[0], *n[1]); else if (n.size() == 3) return findBoundary(*n[0], *n[1], *n[2]); else if (n.size() == 4) return findBoundary(*n[0], *n[1], *n[2], *n[3]); std::vector < std::set< Boundary * > > bs(n.size()); for (uint i = 0; i < n.size(); i ++) bs[i] = n[i]->boundSet(); std::set < Boundary * > common; intersectionSet(common, bs); return findBoundary_(common); }
SeedFeature::SeedFeature( const ImageOverSegmentation & ios, const VectorXf & obj_param ) { Image rgb_im = ios.image(); const RMatrixXs & s = ios.s(); const int Ns = ios.Ns(), W = rgb_im.W(), H = rgb_im.H(); // Initialize various values VectorXf area = bin( s, 1, [&](int x, int y){ return 1.f; } ); VectorXf norm = (area.array()+1e-10).cwiseInverse(); pos_ = norm.asDiagonal() * bin( s, 6, [&](int i, int j){ float x=1.0*i/(W-1)-0.5,y=1.0*j/(H-1)-0.5; return makeArray<6>( x, y, x*x, y*y, fabs(x), fabs(y) ); } ); if (N_DYNAMIC_COL) { Image lab_im; rgb2lab( lab_im, rgb_im ); col_ = norm.asDiagonal() * bin( s, 6, [&](int x, int y){ return makeArray<6>( rgb_im(y,x, 0), rgb_im(y,x,1), rgb_im(y,x,2), lab_im(y,x,0), lab_im(y,x,1), lab_im(y,x,2) ); } ); } const int N_GEO = sizeof(EDGE_P)/sizeof(EDGE_P[0]); for( int i=0; i<N_GEO; i++ ) gdist_.push_back( GeodesicDistance(ios.edges(),ios.edgeWeights().array().pow(EDGE_P[i])+1e-3) ); // Compute the static features static_f_ = RMatrixXf::Zero( Ns, N_STATIC_F ); int o=0; // Add the position features static_f_.block( 0, o, Ns, N_STATIC_POS ) = pos_.leftCols( N_STATIC_POS ); o += N_STATIC_POS; // Add the geodesic features if( N_STATIC_GEO >= N_GEO ) { RMatrixXu8 bnd = findBoundary( s ); RMatrixXf mask = (bnd.array() == 0).cast<float>()*1e10; for( int i=0; i<N_GEO; i++ ) static_f_.col( o++ ) = gdist_[i].compute( mask ); for( int j=1; (j+1)*N_GEO<=N_STATIC_GEO; j++ ) { mask = (bnd.array() != j).cast<float>()*1e10; for( int i=0; i<N_GEO; i++ ) static_f_.col( o++ ) = gdist_[i].compute( mask ); } } if( N_STATIC_EDGE ) { RMatrixXf edge_map = DirectedSobel().detect( ios.image() ); for( int j=0; j<s.rows(); j++ ) for( int i=0; i<s.cols(); i++ ) { const int id = s(j,i); int bin = edge_map(j,i)*N_STATIC_EDGE; if ( bin < 0 ) bin = 0; if ( bin >= N_STATIC_EDGE ) bin = N_STATIC_EDGE-1; static_f_(id,o+bin) += norm[id]; } o += N_STATIC_EDGE; } if( N_OBJ_F>1 ) static_f_.col(o++) = (computeObjFeatures(ios)*obj_param).transpose(); // Initialize the dynamic features dynamic_f_ = RMatrixXf::Zero( Ns, N_DYNAMIC_F ); n_ = 0; min_dist_ = RMatrixXf::Ones(Ns,5)*10; var_ = RMatrixXf::Zero(Ns,6); }
Boundary * findCommonBoundary(const Cell & c1, const Cell & c2){ for (Index i = 0; i < c1.boundaryCount(); i ++){ Boundary * b = findBoundary(c1.boundaryNodes(i)); if ((b->leftCell() == &c1 && b->rightCell() == &c2) || (b->leftCell() == &c2 && b->rightCell() == &c1)){ return b; } } return NULL; }
void kdtree::createTree(vector<glm::vec3> *ver,vector<unsigned int> *idx){ if(verIdx->size()<=1){//cannot split anymore mesh=(*verIdx)[0]; return; } sort(ver,idx,depth); findBoundary(ver,idx,depth); lc=new kdtree(depth+1,lxmax,lxmin,lymax,lymin,lzmax,lzmin,lcVerIdx); rc=new kdtree(depth+1,rxmax,rxmin,rymax,rymin,rzmax,rzmin,rcVerIdx); lc->createTree(ver,idx); rc->createTree(ver,idx); //cout<<"!"<<endl; }
void getBoundaryFlags(int *boundary, const shards::CellTopology cell, const int *element) { int subcell_verts[4], nids; const int dim = cell.getDimension(); const int nside = cell.getSideCount(); for (int i=0;i<nside;++i) { Orientation::getElementNodeMap(subcell_verts, nids, cell, element, dim-1, i); if (!findBoundary(boundary[i], subcell_verts, nids)) { TEUCHOS_TEST_FOR_EXCEPTION( true, std::runtime_error, ">>> ERROR (Intrepid::HGRAD_TRI_Cn::Test 04): " \ "Side node is not found"); } } }
int getmultipartword( entry *iEntry, char **stquery, char *boundary, int length ) { char *inS, *tmp1, *tmp2, *endStr; int i, j, k; if ( strlen( *stquery ) < ( 2 * strlen( boundary ) ) ) { return 1; } if ( ( tmp1 = strstr( ( char * ) * stquery, boundary ) ) == NULL ) { webErrorExit( "No Beginning Boundary Found In Field:", 0 ); } if ( ( endStr = findBoundary( ( char * )( tmp1 + 1 ), boundary, length ) ) == NULL ) { webErrorExit( "No Ending Boundary Found In Field:", 0 ); } *( endStr - 2 ) = '\0'; /* why are we doing this ?? */ if ( ( tmp2 = strstr( tmp1, "name=\"" ) ) == NULL ) { webErrorExit( "No Name Found In Field", 0 ); } tmp2 += 6; tmp1 = strchr( tmp2, '\"' ); *tmp1 = '\0'; tmp1++; strcpy( iEntry->name, tmp2 ); if ( ( int )( strstr( tmp1, "filename" ) != NULL && strstr( tmp1, "filename" ) - tmp1 ) < 5 ) { /* this is a file - skip two lines*/ while ( *tmp1 != '\n' ) { tmp1++; } tmp1++; while ( *tmp1 != '\n' ) { tmp1++; } tmp1++; /** looks like this is needed **/ if ( strstr( iEntry->name, "filename" ) != NULL ) { tmp1++; tmp1++; } /** looks like this is needed **/ iEntry->size = ( int )( endStr - tmp1 ); iEntry->fstr = NULL; iEntry->val = ( char * ) malloc( iEntry->size ); memcpy( iEntry->val, tmp1, iEntry->size ); iEntry->size -= 2; } else { /** looks like this is needed ** tmp1++; tmp1++; ** looks like this is needed **/ iEntry->val = ( char * ) malloc( strlen( tmp1 ) + 3 ); iEntry->fstr = NULL; strcpy( iEntry->val, tmp1 ); iEntry->size = strlen( iEntry->val ); } *stquery = endStr; return 0; }
boost::tribool RequestParser::consume(Request& req, char input) { switch (m_state) { case method_start: if (!isChar(input) || isCtl(input) || isTspecial(input)) { return false; } else { m_state = method; req.method.push_back(input); return boost::indeterminate; } case method: if (input == ' ') { m_state = uri; return boost::indeterminate; } else if (!isChar(input) || isCtl(input) || isTspecial(input)) { return false; } else { req.method.push_back(input); return boost::indeterminate; } case uri: if (input == ' ') { m_state = http_version_h; return boost::indeterminate; } else if (isCtl(input)) { return false; } else { req.uri.push_back(input); return boost::indeterminate; } case http_version_h: if (input == 'H') { m_state = http_version_t_1; return boost::indeterminate; } else { return false; } case http_version_t_1: if (input == 'T') { m_state = http_version_t_2; return boost::indeterminate; } else { return false; } case http_version_t_2: if (input == 'T') { m_state = http_version_p; return boost::indeterminate; } else { return false; } case http_version_p: if (input == 'P') { m_state = http_version_slash; return boost::indeterminate; } else { return false; } case http_version_slash: if (input == '/') { req.httpVersionMajor = 0; req.httpVersionMinor = 0; m_state = http_version_major_start; return boost::indeterminate; } else { return false; } case http_version_major_start: if (isDigit(input)) { req.httpVersionMajor = req.httpVersionMajor * 10 + input - '0'; m_state = http_version_major; return boost::indeterminate; } else { return false; } case http_version_major: if (input == '.') { m_state = http_version_minor_start; return boost::indeterminate; } else if (isDigit(input)) { req.httpVersionMajor = req.httpVersionMajor * 10 + input - '0'; return boost::indeterminate; } else { return false; } case http_version_minor_start: if (isDigit(input)) { req.httpVersionMinor = req.httpVersionMinor * 10 + input - '0'; m_state = http_version_minor; return boost::indeterminate; } else { return false; } case http_version_minor: if (input == '\r') { m_state = expecting_newline_1; return boost::indeterminate; } else if (isDigit(input)) { req.httpVersionMinor = req.httpVersionMinor * 10 + input - '0'; return boost::indeterminate; } else { return false; } case expecting_newline_1: if (input == '\n') { m_state = header_line_start; return boost::indeterminate; } else { return false; } case header_line_start: if (input == '\r') { m_state = expecting_newline_3; return boost::indeterminate; } else if (!req.headers.empty() && (input == ' ' || input == '\t')) { m_state = header_lws; return boost::indeterminate; } else if (!isChar(input) || isCtl(input) || isTspecial(input)) { return false; } else { req.headers.push_back(Header()); req.headers.back().name.push_back(input); m_state = header_name; return boost::indeterminate; } case header_lws: if (input == '\r') { m_state = expecting_newline_2; return boost::indeterminate; } else if (input == ' ' || input == '\t') { return boost::indeterminate; } else if (isCtl(input)) { return false; } else { m_state = header_value; req.headers.back().value.push_back(input); return boost::indeterminate; } case header_name: if (input == ':') { m_state = space_before_header_value; return boost::indeterminate; } else if (!isChar(input) || isCtl(input) || isTspecial(input)) { return false; } else { req.headers.back().name.push_back(input); return boost::indeterminate; } case space_before_header_value: if (input == ' ') { m_state = header_value; return boost::indeterminate; } else { return false; } case header_value: if (input == '\r') { m_state = expecting_newline_2; return boost::indeterminate; } else if (isCtl(input)) { return false; } else { req.headers.back().value.push_back(input); return boost::indeterminate; } case expecting_newline_2: if (input == '\n') { m_state = header_line_start; return boost::indeterminate; } else { return false; } case expecting_newline_3: { if(input == '\n') { req.headerIsReady = true; if(req.method == "POST") { // gonna read by chunk the rest findBoundary(req); if(req.boundary == "") { return false; } else { m_state = postData_boundary; return boost::indeterminate; } } else { // GET, PUT, etc.. return true; } } else { return false; } } case postData_boundary: { if(input == '\r') { m_state = postData_headerLine1; } return boost::indeterminate; } case postData_headerLine1: { if(input == '\r') { m_state = postData_headerLine2; } return boost::indeterminate; } case postData_headerLine2: { if(input == '\r') { m_state = postData_headerEmptyLineR; } return boost::indeterminate; } case postData_headerEmptyLineR: { if(input == '\r') { m_state = postData_headerEmptyLineN; } return boost::indeterminate; } case postData_headerEmptyLineN: { if(input == '\n') { m_state = postData_rawData; } return boost::indeterminate; } case postData_rawData: { if(m_postDataBuffer.size() == req.boundary.length()) { char topChar = m_postDataBuffer.front(); m_postDataBuffer.pop_front(); m_postDataBuffer.push_back(input); req.postChunk[req.postChunkSize] = topChar; req.postChunkSize++; if(isPostDataBufferIsEnd(req)) { return true; } } else { m_postDataBuffer.push_back(input); } return boost::indeterminate; } default: return false; } }