/////////////////////////////////////////////////////////////////////////////// /// \brief Prints out a string using this font, beginning with the baseline /// at the origin. /// /// \param text The string to print. /// \param color The base color to modulate by the font texture. void TextureFont::print(const std::string& text, const color4& color) const { vec2 cursor; // where the current character should be drawn F32 scale_x = 1.0f / texture_.getDimensions().x; F32 scale_y = 1.0f / texture_.getDimensions().y; for (char c : text) { const TextureFontCharacter& ch = (*this)[c]; // vertices vec2 top_left(cursor + ch.character_offset); vec2 bottom_right(top_left.x + ch.texture_dimensions.x, top_left.y - ch.texture_dimensions.y); vec2 tex_top_left(ch.texture_offset); vec2 tex_bottom_right(tex_top_left + ch.texture_dimensions); tex_top_left.x *= scale_x; tex_bottom_right.x *= scale_x; tex_top_left.y *= scale_y; tex_bottom_right.y *= scale_y; cursor.x += ch.character_advance; texture_.enable(GL_MODULATE); glColor4fv(glm::value_ptr(color)); glBegin(GL_QUADS); glTexCoord2fv(glm::value_ptr(tex_top_left)); glVertex2fv(glm::value_ptr(top_left)); glTexCoord2f(tex_top_left.x, tex_bottom_right.y); glVertex2f(top_left.x, bottom_right.y); glTexCoord2fv(glm::value_ptr(tex_bottom_right)); glVertex2fv(glm::value_ptr(bottom_right)); glTexCoord2f(tex_bottom_right.x, tex_top_left.y); glVertex2f(bottom_right.x, top_left.y); glEnd(); texture_.disable(); } }
void detectAndRecognize( Mat frame, Ptr<FaceRecognizer> model ) { std::vector<Rect> faces; Mat frame_gray; cvtColor( frame, frame_gray, CV_BGR2GRAY ); //equalizeHist( frame_gray, frame_gray ); //-- Detect faces face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) ); //faces.push_back(Rect(Point(0,0),Size(frame.cols,frame.rows))); for( size_t i = 0; i < faces.size(); i++ ) { Point bottom_right(faces[i].x + faces[i].width,faces[i].y + faces[i].height); Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 ); ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 ); Mat to_rec = frame_gray( faces[i] ); cv::resize(to_rec,to_rec,cv::Size(NORM_IMG_WIDTH,NORM_IMG_HEIGHT)); #ifdef DO_EQUALIZE equalizeHist(to_rec,to_rec); #endif #ifdef FACE_DEBUG Mat rgb_to_rec; cvtColor( to_rec, rgb_to_rec, CV_GRAY2BGR ); drawAonB(rgb_to_rec,frame,bottom_right/*+Point(0,NORM_IMG_HEIGHT)*/); #endif int predictLabel=-1; double confidence=0.; predictLabel=model->predict(to_rec); //printf("confidence: %lf\n",confidence); if(predictLabel==-1) continue; string class_name=g_trainer.label(predictLabel); Mat avatar=imread(string("data/")+class_name+"/"+class_name+".avatar"); #ifndef FACE_DEBUG drawAonB(avatar,frame,bottom_right); #endif // if(!avatar.empty()) // { // int w=min(max(frame.cols-1-bottom_right.x,0),avatar.cols), // h=min(max(frame.rows-1-bottom_right.y,0),avatar.rows); // cv::Rect avatar_roi( bottom_right, cv::Size(w,h)); // avatar(Rect(Point(0,0),Size(w,h))).copyTo( frame(avatar_roi) ); // } putText(frame,class_name,bottom_right,FONT_HERSHEY_SIMPLEX, 1.5, cvScalar(250,20,10),3); } //-- Show what you got imshow( CAPTURE_WND_NAME, frame ); }
worksheet::const_iterator worksheet::cend() const { auto dimensions = calculate_dimension(); auto past_end_row_index = dimensions.get_bottom_right().get_row() + 1; cell_reference bottom_left(dimensions.get_top_left().get_column_index(), past_end_row_index); cell_reference bottom_right(dimensions.get_bottom_right().get_column_index(), past_end_row_index); return const_iterator(*this, range_reference(bottom_left, bottom_right), major_order::row); }
// rotate_large constructs the containing bounding box of all 4 // corners after rotating them. It therefore guarantees that all // original content is contained within, but also slightly enlarges the box. void TBOX::rotate_large(const FCOORD& vec) { ICOORD top_left(bot_left.x(), top_right.y()); ICOORD bottom_right(top_right.x(), bot_left.y()); top_left.rotate(vec); bottom_right.rotate(vec); rotate(vec); TBOX box2(top_left, bottom_right); *this += box2; }
/** * From given list of configurations, convert them into affine matrices. * But filter out all the rectangles that are out of the given boundaries. **/ vector<Mat> FAsTMatch::configsToAffine( vector<MatchConfig>& configs, vector<bool>& insiders ) { int no_of_configs = static_cast<int>(configs.size()); vector<Mat> affines( no_of_configs ); /* The boundary, between -10 to image size + 10 */ Point2d top_left( -10., -10. ); Point2d bottom_right( image.cols + 10, image.rows + 10 ); /* These are for the calculations of affine transformed corners */ int r1x = 0.5 * ( templ.cols - 1), r1y = 0.5 * ( templ.rows - 1), r2x = 0.5 * ( image.cols - 1), r2y = 0.5 * ( image.rows - 1); Mat corners = (Mat_<float>(3, 4) << 1-(r1x+1), templ.cols-(r1x+1), templ.cols-(r1x+1), 1-(r1x+1), 1-(r1y+1), 1-(r1y+1) , templ.rows-(r1y+1), templ.rows-(r1y+1), 1.0 , 1.0 , 1.0 , 1.0 ); Mat transl = (Mat_<float>(4, 2) << r2x + 1, r2y + 1, r2x + 1, r2y + 1, r2x + 1, r2y + 1, r2x + 1, r2y + 1 ); insiders.assign( no_of_configs, false ); /* Convert each configuration to corresponding affine transformation matrix */ tbb::parallel_for( 0, no_of_configs, 1, [&](int i) { Mat affine = configs[i].getAffineMatrix(); /* Check if our affine transformed rectangle still fits within our boundary */ Mat affine_corners = (affine * corners).t(); affine_corners = affine_corners + transl; if( WITHIN( affine_corners.at<Point2f>(0), top_left, bottom_right) && WITHIN( affine_corners.at<Point2f>(1), top_left, bottom_right) && WITHIN( affine_corners.at<Point2f>(2), top_left, bottom_right) && WITHIN( affine_corners.at<Point2f>(3), top_left, bottom_right) ) { affines[i] = affine; insiders[i] = true; } }); /* Filter out empty affine matrices (which initially don't fit within the preset boundary) */ /* It's done this way, so that I could parallelize the loop */ vector<Mat> result; for( int i = 0; i < no_of_configs; i++ ) { if( insiders[i] ) result.push_back( affines[i] ); } return result; }
/** * \brief Do one step in the progression of the item. * \param elapsed_time Elapsed time since the last call. */ void bear::camera_on_object::progress_fit_items ( bear::universe::time_type elapsed_time ) { unsigned int nb_objects(0); bear::universe::position_type top_left(get_center_of_mass()); bear::universe::position_type bottom_right(get_center_of_mass()); handle_list::const_iterator it; handle_list remaining_objects; for ( it = m_objects.begin(); it != m_objects.end(); ++it ) if ( (*it).get() != NULL ) { if ( (*it)->get_left() < top_left.x ) top_left.x = (*it)->get_left(); if ( (*it)->get_right() > bottom_right.x ) bottom_right.x = (*it)->get_right(); if ( (*it)->get_top() > top_left.y ) top_left.y = (*it)->get_top(); if ( (*it)->get_bottom() < bottom_right.y ) bottom_right.y = (*it)->get_bottom(); ++nb_objects; remaining_objects.push_back(*it); } std::swap(m_objects, remaining_objects); if ( nb_objects != 0 ) { universe::position_type center((top_left + bottom_right) /2); adjust_position( center , elapsed_time ); universe::size_type r_init = get_default_size().x / get_default_size().y; universe::coordinate_type w(bottom_right.x - top_left.x + 200); universe::coordinate_type h(top_left.y - bottom_right.y + 200*r_init); if ( w > h*r_init ) set_wanted_size(universe::size_box_type(w, w/r_init)); else set_wanted_size(universe::size_box_type(h*r_init, h)); } } // camera_on_object::progress_fit_items()
void initialize() override { const auto size = windowDimensions(); linear_scale<float, float> window_scale(0, 1000, 0, size.x); linear_scale<float, float> lower_bottom(0, size.x, 5 * size.y / 6, 5 * size.y / 6); linear_scale<float, float> lower_top(0, size.x, 2 * size.y / 3, size.y / 6); linear_scale<float, float> upper_bottom(0, size.x, size.y / 3, 5 * size.y / 6); linear_scale<float, float> upper_top(0, size.x, size.y / 6, size.y / 6); linear_scale<float, float> x_scale(0, std::sqrt(size.x), 0, size.x); linear_color_scale<float> color_scale(0, size.x, sf::Color(128, 128, 128), sf::Color::Black); linear_scale<float, float> size_scale(0, size.x, 1, 6); const unsigned num_rects(15); sf::RectangleShape rect(sf::Vector2f(window_scale(100), window_scale(20))); rect.setOrigin(window_scale(50), window_scale(10)); rect.setFillColor(sf::Color::Black); rect.setOutlineColor(sf::Color::White); rect.setOutlineThickness(window_scale(-1)); sf::Vector2f top_left(0, 0); sf::Vector2f bottom_right(std::sqrt(size.x), size.y); maxProgress(num_rects); for(unsigned i = 0; i < num_rects; ++i) { float x = x_scale(randuniform(0, std::sqrt(size.x))); float scale = size_scale(x); rect.setScale(scale, scale); rect.setOutlineThickness(window_scale(-1)/scale); float y = linear_scale<float, float>(0, size.y, upper_top(x), upper_bottom(x))(randuniform(0, size.y)); rect.setFillColor(color_scale(x)); rect.setPosition(x, y); rects.push_back(rect); addProgress(0.5); y = linear_scale<float, float>(0, size.y, lower_top(x), lower_bottom(x))(randuniform(0, size.y)); rect.setFillColor(sf::Color::Black); rect.setPosition(x, y); rects.push_back(rect); addProgress(0.5); } std::sort(rects.begin(), rects.end(), [](const sf::RectangleShape& lhs, const sf::RectangleShape& rhs) { return lhs.getPosition().x > rhs.getPosition().x; }); }
glm::ivec2 MRegion::bottom_left() const { return glm::ivec2(top_left().x, bottom_right().y); }
void MyRendererTFEditor_TFE::paintEvent( QPaintEvent * ) { QPainter painter( this ); painter.setRenderHint( QPainter::Antialiasing, false ); int s_w = this->size().width(); int s_h = this->size().height(); std::vector < TFEMarker > mrks; // remove isomarker for convienence TFEMarkers tfe_markers = m_tfe_markers; for( int i = 0 ; i < tfe_markers.markers.size() ; ) if( tfe_markers.markers.at( i ).b_iso ) tfe_markers.delMarker( i ); else i++; mrks = tfe_markers.markers; // paint tranfer function indirectly via tf markers for( int i = 0 ; i < mrks.size() - 1 ; i++ ) { QPoint bottom_left( rescale( m_display_min, m_display_max, mrks.at( i ).x, 0.0, 1.0 ) * s_w, s_h ); QPoint top_left( rescale( m_display_min, m_display_max, mrks.at( i ).x, 0.0, 1.0 ) * s_w, ( 1 - mrks.at( i ).color_right.alphaF() ) * s_h ); QPoint bottom_right( rescale( m_display_min, m_display_max, mrks.at( i+1 ).x, 0.0, 1.0 ) * s_w, s_h ); QPoint top_right( rescale( m_display_min, m_display_max, mrks.at( i+1 ).x, 0.0, 1.0 ) * s_w, ( 1 - mrks.at( i+1 ).color_left.alphaF() ) * s_h ); QPoint points[] = { top_right, bottom_right, bottom_left, top_left }; QLinearGradient gradient( bottom_left, bottom_right ); gradient.setColorAt( 0, mrks.at( i ).color_right ); gradient.setColorAt( 1, mrks.at( i+1 ).color_left ); painter.setPen( Qt::transparent ); painter.setBrush( gradient ); painter.drawPolygon( points, 4 ); } // paint histogram //for( int i = 0 ; i < TF_SIZE ; i++ ) //{ // int x_rescaled = int(rescale( 0, s_w - 1, i, m_display_min * ( TF_SIZE - 1 ), m_display_max * ( TF_SIZE - 1 ) )); // // // paint histogram // painter.setPen( QColor( 185, 185, 185, 75 ) ); // painter.drawLine( QLineF( i, // s_h, // i, // s_h - m_histogram[x_rescaled] * s_h ) ); //} painter.setRenderHint( QPainter::Antialiasing, true ); mrks = m_tfe_markers.markers; // paint markers for( int i = 1 ; i < mrks.size() - 1 ; i++ ) { float rect_center_x = ( rescale( m_display_min, m_display_max, mrks.at(i).x, 0.0, 1.0 ) * s_w ); float rect_center_y; QColor color_marker; int size_mark = 3; // paint vertical lines for iso marker if( mrks.at( i ).b_iso ) { painter.setRenderHint( QPainter::Antialiasing, false ); painter.setPen( QColor( 0, 0, 0, 50 ) ); painter.drawLine( QLineF( rect_center_x - 1, s_h, rect_center_x - 1, 0 ) ); painter.drawLine( QLineF( rect_center_x + 1, s_h, rect_center_x + 1, 0 ) ); painter.setPen( mrks.at( i ).color_left ); painter.drawLine( QLineF( rect_center_x, s_h, rect_center_x, 0 ) ); painter.setRenderHint( QPainter::Antialiasing, true ); } // draw markers rect_center_y = ( s_h - mrks.at(i).color_left.alpha() * s_h / 255.0 ); color_marker = mrks.at(i).color_left; color_marker.setAlpha( 255 ); if( mrks.at(i).color_left == mrks.at(i).color_right ) { painter.setPen( Qt::black ); painter.setBrush( Qt::NoBrush ); painter.drawEllipse( QRectF( rect_center_x - size_mark - 1, rect_center_y - size_mark - 1, 2*size_mark + 3 , 2*size_mark + 3 ) ); painter.setPen( color_marker ); painter.setBrush( QBrush( color_marker ) ); painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); } else { painter.setPen( Qt::black ); painter.setBrush( Qt::NoBrush ); painter.drawEllipse( QRectF( rect_center_x - size_mark - 1, rect_center_y - size_mark - 1, 2*size_mark + 3 , 2*size_mark + 3 ) ); painter.setPen( color_marker ); painter.setBrush( QBrush( color_marker ) ); painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); rect_center_y = ( s_h - mrks.at(i).color_right.alpha() * s_h / 255.0 ); color_marker = mrks.at(i).color_right; color_marker.setAlpha( 255 ); painter.setPen( Qt::black ); painter.setBrush( Qt::NoBrush ); painter.drawEllipse( QRectF( rect_center_x - size_mark - 1, rect_center_y - size_mark - 1, 2*size_mark + 3 , 2*size_mark + 3 ) ); painter.setPen( color_marker ); painter.setBrush( QBrush( color_marker ) ); painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); } } // draw white circle around selected marker if( m_tfe_marker_selected != 0 ) { float rect_center_x = rescale( m_display_min, m_display_max, mrks.at(m_tfe_marker_selected).x, 0.0, 1.0 ) * s_w; float rect_center_y; int size_mark = 5; painter.setPen( QColor( 0, 0, 0, 50 ) ); painter.setBrush( Qt::NoBrush ); rect_center_y = s_h - mrks.at(m_tfe_marker_selected).color_left.alpha() * s_h / 255.0; if( mrks.at( m_tfe_marker_selected ).color_left == mrks.at( m_tfe_marker_selected ).color_right ) painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); else { painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); rect_center_y = s_h - mrks.at(m_tfe_marker_selected).color_right.alpha() * s_h / 255.0; painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); } } // draw translucent white divisions int count_divisions; count_divisions = 20; for( int i = 1; i < count_divisions; i++ ) { float tenth = s_w / float( count_divisions ); painter.setPen( QColor( 255, 255, 255, 65 ) ); painter.drawLine( QLineF( tenth * i, 0, tenth * i, s_h ) ); painter.drawText( QPoint( tenth* i + 4, s_h - 3 ), tr( "%1" ).arg( m_display_min + ( m_display_max - m_display_min ) * i / count_divisions, 0, 'f', 2 ) ); } count_divisions = 5; for( int i = 1; i < count_divisions; i++ ) { float fourth = s_h / float( count_divisions ); painter.setPen( QColor( 255, 255, 255, 65 ) ); painter.drawLine( QLineF( 0, fourth * i, s_w, fourth * i ) ); } // paint black rectangular border painter.setRenderHint( QPainter::Antialiasing, false ); painter.setPen( QColor( 0, 0, 0, 50 ) ); painter.setBrush( Qt::NoBrush ); painter.drawRect( 0, 0, s_w - 1, s_h - 1 ); }
osg::Node* createSubloadWall(osg::BoundingBox& bb) { osg::Group* group = new osg::Group; // left hand side of bounding box. osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMin(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMax(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax()); osg::Vec3 center((bb.xMax()+bb.xMin())*0.5f,bb.yMax(),(bb.zMin()+bb.zMax())*0.5f); float height = bb.zMax()-bb.zMin(); // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,1.0f); (*texcoords)[1].set(0.0f,0.0f); (*texcoords)[2].set(1.0f,0.0f); (*texcoords)[3].set(1.0f,1.0f); geom->setTexCoordArray(0,texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,-1.0f,0.0f); geom->setNormalArray(normals); geom->setNormalBinding(osg::Geometry::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); geom->setColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); // create the text label. osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); text->setFont("fonts/arial.ttf"); text->setPosition(center); text->setCharacterSize(height*0.03f); text->setAlignment(osgText::Text::CENTER_CENTER); text->setAxisAlignment(osgText::Text::XZ_PLANE); osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON); group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. group->setUpdateCallback(new ImageUpdateCallback(texture,text)); return group; }
double Camera::bbToDetection(const Vector<double>& bbox, Vector<double>& pos3D, double ConvertScale, double& dist) { // pos3D.clearContent(); pos3D.setSize(3); double x = bbox(0); double y = bbox(1); double w = bbox(2); double h = bbox(3); // bottom_left and bottom_right are the point of the BBOX Vector<double> bottom_left(3, 1.0); bottom_left(0) = x + w/2.0; bottom_left(1) = y + h; Vector<double> bottom_right(3, 1.0); bottom_right(0) = x + w; bottom_right(1) = y + h; Vector<double> ray_bot_left_1; Vector<double> ray_bot_left_2; Vector<double> ray_bot_right_1; Vector<double> ray_bot_right_2; // Backproject through base point getRay(bottom_left, ray_bot_left_1, ray_bot_left_2); getRay(bottom_right, ray_bot_right_1, ray_bot_right_2); Vector<double> gpPointLeft; Vector<double> gpPointRight; // Intersect with ground plane intersectPlane(GPN_, GPD_, ray_bot_left_1, ray_bot_left_2, gpPointLeft); intersectPlane(GPN_, GPD_, ray_bot_right_1, ray_bot_right_2, gpPointRight); // Find top point Vector<double> ray_top_1; Vector<double> ray_top_2; Vector<double> aux(3, 1.0); aux(0) = x; aux(1) = y; getRay(aux, ray_top_1, ray_top_2); // Vertical plane through base points + normal Vector<double> point3; point3 = gpPointLeft; point3 -= (GPN_); Vector<double> vpn(3,0.0); Vector<double> diffGpo1Point3; Vector<double> diffGpo2Point3; diffGpo1Point3 = gpPointLeft; diffGpo1Point3 -=(point3); diffGpo2Point3 = gpPointRight; diffGpo2Point3 -= point3; vpn = cross(diffGpo1Point3,diffGpo2Point3); double vpd = (-1.0)*DotProduct(vpn, point3); Vector<double> gpPointTop; intersectPlane(vpn, vpd, ray_top_1, ray_top_2, gpPointTop); // Results gpPointTop -= gpPointLeft; // Compute Size double dSize = gpPointTop.norm(); // Compute Distance aux = t_; aux -= gpPointLeft; dist = aux.norm(); dist = dist * ConvertScale; if(gpPointLeft(2) < t_(2)) dist = dist * (-1.0); // Compute 3D Position of BBOx double posX = gpPointLeft(0) * ConvertScale; double posY = gpPointLeft(1) * ConvertScale; double posZ = gpPointLeft(2) * ConvertScale; pos3D(0) = (posX); pos3D(1) = (posY); pos3D(2) = (posZ); return dSize * ConvertScale; }
//! Creates a bounding box encompassing the vector to \a p bounding_box (const point< T >& p) { tl_ = top_left (point< T > (), p); br_ = bottom_right (point< T > (), p); }
int MRegion::height() const { return top_left().y - bottom_right().y; }
int MRegion::width() const { return bottom_right().x - top_left().x; }
//------------------------------------------------------------------------------ void Background2D::OnResize() { calculateScreenScale(); for( unsigned int i = 0; i < m_Tiles.size(); ++i ) { Tile &tile( m_Tiles[ i ] ); Ogre::Vector2 top_left ( tile.x, -tile.y ); Ogre::Vector2 top_right( tile.x + tile.width, top_left.y ); Ogre::Vector2 bottom_right( top_right.x, -( tile.y + tile.height ) ); Ogre::Vector2 bottom_left( top_left.x, bottom_right.y ); virtualScreenToWorldSpace( top_left ); virtualScreenToWorldSpace( top_right ); virtualScreenToWorldSpace( bottom_right ); virtualScreenToWorldSpace( bottom_left ); float new_x1 = top_left.x; float new_y1 = top_left.y; float new_x2 = top_right.x; float new_y2 = top_right.y; float new_x3 = bottom_right.x; float new_y3 = bottom_right.y; float new_x4 = bottom_left.x; float new_y4 = bottom_left.y; Ogre::HardwareVertexBufferSharedPtr vertex_buffer; if( m_Tiles[ i ].blending == QGears::B_ALPHA ) { vertex_buffer = m_AlphaVertexBuffer; } else if( m_Tiles[ i ].blending == QGears::B_ADD ) { vertex_buffer = m_AddVertexBuffer; } float* writeIterator = ( float* )vertex_buffer->lock( Ogre::HardwareBuffer::HBL_NORMAL ); writeIterator += m_Tiles[ i ].start_vertex_index * TILE_VERTEX_INDEX_SIZE; *writeIterator++ = new_x1; *writeIterator++ = new_y1; writeIterator += 7; *writeIterator++ = new_x2; *writeIterator++ = new_y2; writeIterator += 7; *writeIterator++ = new_x3; *writeIterator++ = new_y3; writeIterator += 7; ///* *writeIterator++ = new_x1; *writeIterator++ = new_y1; writeIterator += 7; *writeIterator++ = new_x3; *writeIterator++ = new_y3; writeIterator += 7; //*/ *writeIterator++ = new_x4; *writeIterator++ = new_y4; vertex_buffer->unlock(); } applyScroll(); }
osg::Node* createRectangle(osg::BoundingBox& bb, const std::string& filename) { osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMin(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMax(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax()); // create geometry osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f, 0.0f); (*texcoords)[1].set(1.0f, 0.0f); (*texcoords)[2].set(1.0f, 1.0f); (*texcoords)[3].set(0.0f, 1.0f); geom->setTexCoordArray(0,texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,-1.0f,0.0f); geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4)); // disable display list so our modified tex coordinates show up geom->setUseDisplayList(false); // load image osg::ref_ptr<osg::Image> img = osgDB::readRefImageFile(filename); // setup texture osg::TextureRectangle* texture = new osg::TextureRectangle(img); osg::TexMat* texmat = new osg::TexMat; texmat->setScaleByTextureRectangleSize(true); // setup state osg::StateSet* state = geom->getOrCreateStateSet(); state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); state->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); // turn off lighting state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); // install 'update' callback osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); geode->setUpdateCallback(new TexturePanCallback(texmat)); return geode; }
//------------------------------------------------------------------------------ void Background2D::AddTile( const int x, const int y, const int width, const int height, const float depth, const float u1, const float v1, const float u2, const float v2, const Blending blending ) { Ogre::RenderOperation render_op; Ogre::HardwareVertexBufferSharedPtr vertex_buffer; unsigned int max_vertex_count; if( blending == QGears::B_ALPHA ) { render_op = m_AlphaRenderOp; vertex_buffer = m_AlphaVertexBuffer; max_vertex_count = m_AlphaMaxVertexCount; } else if( blending == QGears::B_ADD ) { render_op = m_AddRenderOp; vertex_buffer = m_AddVertexBuffer; max_vertex_count = m_AddMaxVertexCount; } else { LOG_ERROR( "Unknown blending type." ); return; } if( render_op.vertexData->vertexCount + TILE_VERTEX_COUNT > max_vertex_count ) { LOG_ERROR( "Max number of tiles reached. Can't create more than " + Ogre::StringConverter::toString( max_vertex_count / TILE_VERTEX_COUNT ) + " tiles." ); return; } Tile tile; tile.x = x; tile.y = y; tile.width = width; tile.height = height; tile.start_vertex_index = render_op.vertexData->vertexCount; tile.blending = blending; size_t index( m_Tiles.size() ); m_Tiles.push_back( tile ); Ogre::Vector2 top_left ( x, -y ); Ogre::Vector2 top_right( x + width, top_left.y ); Ogre::Vector2 bottom_right( top_right.x, -( y + height ) ); Ogre::Vector2 bottom_left( top_left.x, bottom_right.y ); virtualScreenToWorldSpace( top_left ); virtualScreenToWorldSpace( top_right ); virtualScreenToWorldSpace( bottom_right ); virtualScreenToWorldSpace( bottom_left ); float new_x1 = top_left.x; float new_y1 = top_left.y; float new_x2 = top_right.x; float new_y2 = top_right.y; float new_x3 = bottom_right.x; float new_y3 = bottom_right.y; float new_x4 = bottom_left.x; float new_y4 = bottom_left.y; float* writeIterator = ( float* )vertex_buffer->lock( Ogre::HardwareBuffer::HBL_NORMAL ); writeIterator += render_op.vertexData->vertexCount * TILE_VERTEX_INDEX_SIZE; *writeIterator++ = new_x1; *writeIterator++ = new_y1; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u1; *writeIterator++ = v1; *writeIterator++ = new_x2; *writeIterator++ = new_y2; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u2; *writeIterator++ = v1; *writeIterator++ = new_x3; *writeIterator++ = new_y3; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u2; *writeIterator++ = v2; *writeIterator++ = new_x1; *writeIterator++ = new_y1; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u1; *writeIterator++ = v1; *writeIterator++ = new_x3; *writeIterator++ = new_y3; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u2; *writeIterator++ = v2; *writeIterator++ = new_x4; *writeIterator++ = new_y4; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u1; *writeIterator++ = v2; render_op.vertexData->vertexCount += TILE_VERTEX_COUNT; vertex_buffer->unlock(); }
JNIEXPORT void JNICALL Java_org_openscenegraph_osg_core_Geode_nativeGetTextureRectangle2( JNIEnv *env, jclass, jlong cptr, jlong imagecptr, jfloat width, jfloat height) { osg::Geode *geode = reinterpret_cast<osg::Geode *>(cptr); osg::Image *image = reinterpret_cast<osg::Image *>(imagecptr); osg::BoundingBox bb(0.0f,0.0f,0.0f,width,height,0.0f); osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMin(),bb.yMin(),bb.zMax()); osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMax()); osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax()); // create geometry osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(6); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = bottom_right; (*vertices)[4] = top_right; (*vertices)[5] = top_left; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(6); (*texcoords)[0].set(0.0f, 0.0f); (*texcoords)[1].set(0.0f, 1.0f); (*texcoords)[2].set(1.0f, 1.0f); (*texcoords)[3].set(1.0f, 1.0f); (*texcoords)[4].set(1.0f, 0.0f); (*texcoords)[5].set(0.0f, 0.0f); geom->setTexCoordArray(0,texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,-1.0f,0.0f); geom->setNormalArray(normals); geom->setNormalBinding(osg::Geometry::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); geom->setColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLES, 0, 6)); // disable display list so our modified tex coordinates show up geom->setUseDisplayList(false); // setup texture osg::Texture2D* texture = new osg::Texture2D(image); texture->setDataVariance(osg::Object::DYNAMIC); /*/////////////////////kookmin start/////////////////////*/ // setup state osg::StateSet* state = geom->getOrCreateStateSet(); state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); /*/////////////////////kookmin start/////////////////////*/ // turn off lighting state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); texture->ref(); //image->ref(); geom->ref(); geode->addDrawable(geom); }
int MRegion::right() const { return bottom_right().x; }
//! Creates a bounding box encompassing the vector from \a p1 to \a p2 bounding_box (const point< T >& p1, const point< T >& p2) { tl_ = top_left (p1, p2); br_ = bottom_right (p1, p2); }
int MRegion::bottom() const { return bottom_right().y; }
osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename) { osg::Group* group = new osg::Group; // left hand side of bounding box. osg::Vec3 top_left(bb.xMax(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMax(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMin(),bb.zMax()); osg::Vec3 center(bb.xMax(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f); float height = bb.zMax()-bb.zMin(); // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(-1.0f,2.0f); (*texcoords)[1].set(-1.0f,-1.0f); (*texcoords)[2].set(2.0f,-1.0f); (*texcoords)[3].set(2.0f,2.0f); geom->setTexCoordArray(0,texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(-1.0f,0.0f,0.0f); geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); // only used when wrap is set to CLAMP_TO_BORDER texture->setImage(osgDB::readRefImageFile(filename)); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); // create the text label. osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); text->setFont("fonts/arial.ttf"); text->setPosition(center); text->setCharacterSize(height*0.03f); text->setAlignment(osgText::Text::CENTER_CENTER); text->setAxisAlignment(osgText::Text::YZ_PLANE); osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON); group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. group->setUpdateCallback(new WrapCallback(texture,text)); return group; }
virtual ng::vertex_list3 map() const { auto r = bounding_box(); return ng::vertex_list3{ r.top_left().to_vector3(), r.top_right().to_vector3(), r.bottom_right().to_vector3(), r.bottom_left().to_vector3() }; }
// Generates the clipping region for an element. bool ElementUtilities::GetClippingRegion(Vector2i& clip_origin, Vector2i& clip_dimensions, Element* element) { clip_origin = Vector2i(-1, -1); clip_dimensions = Vector2i(-1, -1); int num_ignored_clips = element->GetClippingIgnoreDepth(); if (num_ignored_clips < 0) return false; // Search through the element's ancestors, finding all elements that clip their overflow and have overflow to clip. // For each that we find, we combine their clipping region with the existing clipping region, and so build up a // complete clipping region for the element. Element* clipping_element = element->GetParentNode(); while (clipping_element != NULL) { // Merge the existing clip region with the current clip region if we aren't ignoring clip regions. if (num_ignored_clips == 0 && clipping_element->IsClippingEnabled()) { // Ignore nodes that don't clip. if (clipping_element->GetClientWidth() < clipping_element->GetScrollWidth() || clipping_element->GetClientHeight() < clipping_element->GetScrollHeight()) { Vector2f element_origin_f = clipping_element->GetAbsoluteOffset(Box::CONTENT); Vector2f element_dimensions_f = clipping_element->GetBox().GetSize(Box::CONTENT); Vector2i element_origin(Math::RealToInteger(element_origin_f.x), Math::RealToInteger(element_origin_f.y)); Vector2i element_dimensions(Math::RealToInteger(element_dimensions_f.x), Math::RealToInteger(element_dimensions_f.y)); bool clip_x = element->GetProperty(OVERFLOW_X)->Get< int >() != OVERFLOW_VISIBLE; bool clip_y = element->GetProperty(OVERFLOW_Y)->Get< int >() != OVERFLOW_VISIBLE; ROCKET_ASSERT(!clip_x || !clip_y || (clip_x && clip_y)); //TODO: REPLACE FOLLOWING BUG FIX FOR OVERFLOW if( !( clip_x && clip_y ) ) { clip_x = true; clip_y = true; } //END TODO if (!clip_x) { element_origin.x = 0; element_dimensions.x = clip_dimensions.x < 0 ? element->GetContext()->GetDimensions().x : clip_dimensions.x; } else if (!clip_y) { element_origin.y = 0; element_dimensions.y = clip_dimensions.y < 0 ? element->GetContext()->GetDimensions().y : clip_dimensions.y; } if (clip_dimensions == Vector2i(-1, -1)) { clip_origin = element_origin; clip_dimensions = element_dimensions; } else { Vector2i top_left(Math::Max(clip_origin.x, element_origin.x), Math::Max(clip_origin.y, element_origin.y)); Vector2i bottom_right(Math::Min(clip_origin.x + clip_dimensions.x, element_origin.x + element_dimensions.x), Math::Min(clip_origin.y + clip_dimensions.y, element_origin.y + element_dimensions.y)); clip_origin = top_left; clip_dimensions.x = Math::Max(0, bottom_right.x - top_left.x); clip_dimensions.y = Math::Max(0, bottom_right.y - top_left.y); } } } // If this region is meant to clip and we're skipping regions, update the counter. if (num_ignored_clips > 0) { if (clipping_element->IsClippingEnabled()) num_ignored_clips--; } // Determine how many clip regions this ancestor ignores, and inherit the value. If this region ignores all // clipping regions, then we do too. int clipping_element_ignore_clips = clipping_element->GetClippingIgnoreDepth(); if (clipping_element_ignore_clips < 0) break; num_ignored_clips = Math::Max(num_ignored_clips, clipping_element_ignore_clips); // Climb the tree to this region's parent. clipping_element = clipping_element->GetParentNode(); } return clip_dimensions.x >= 0 && clip_dimensions.y >= 0; }
vertex_list3 sprite::map() const { auto r = bounding_box(); return vertex_list3{{ r.top_left().to_vector3(), r.top_right().to_vector3(), r.bottom_right().to_vector3(), r.bottom_left().to_vector3() }}; }
std::vector< std::vector<c_tikz_obj*> > c_polygon::split(const c_polygon& against) const { std::vector< std::vector<c_tikz_obj*> > ret(3); // Check each point individually char loc_a, loc_b, loc_c; loc_a = utils::is_located(a, against); loc_b = utils::is_located(b, against); loc_c = utils::is_located(c, against); // Check if we're above or below or inside if (loc_a == loc_b && loc_b == loc_c) { ret[loc_a].push_back(clone()); return ret; } // Check if point a is barely touching if (loc_a == 1 && loc_b == loc_c) { ret[loc_b].push_back(clone()); return ret; } // Check if point b is barely touching if (loc_b == 1 && loc_a == loc_c) { ret[loc_c].push_back(clone()); return ret; } // Check if point c is barely touching if (loc_c == 1 && loc_b == loc_a) { ret[loc_a].push_back(clone()); return ret; } // Check if a and b are barely touching if (loc_a == 1 && loc_b == 1) { ret[loc_c].push_back(clone()); return ret; } // Check if a and c are barely touching if (loc_a == 1 && loc_c == 1) { ret[loc_b].push_back(clone()); return ret; } // Check if b and c are barely touching if (loc_b == 1 && loc_c == 1) { ret[loc_a].push_back(clone()); return ret; } // Check if 1 point touching, one above, one below if (loc_a == 1 || loc_b == 1 || loc_c == 1) { c_line line; c_point split1, split2; if (loc_a == 1) { split1 = b; split2 = c; } if (loc_b == 1) { split1 = a; split2 = c; } if (loc_c == 1) { split1 = a; split2 = b; } line.set_points(split1, split2); // Split the line real split_pos = utils::get_split_point(line, against); c_point split_point = split1*split_pos + split2*(1-split_pos); c_polygon * polygon1 = (c_polygon*) this->clone(); c_polygon * polygon2 = (c_polygon*) this->clone(); if (loc_a == 1) { polygon1->a = a; polygon1->b = b; polygon1->c = split_point; polygon2->a = a; polygon2->b = c; polygon2->c = split_point; } if (loc_b == 1) { polygon1->a = b; polygon1->b = c; polygon1->c = split_point; polygon2->a = b; polygon2->b = a; polygon2->c = split_point; } if (loc_c == 1) { polygon1->a = c; polygon1->b = b; polygon1->c = split_point; polygon2->a = c; polygon2->b = a; polygon2->c = split_point; } ret[0].push_back(polygon1); ret[2].push_back(polygon2); return ret; } // Remaining cases: Two points above, one point below c_line line1, line2; bool two_above; if (loc_a == 0 && loc_b == 2 && loc_c == 2) { // Split ba and ca against the polygon line1.set_points(b, a); line2.set_points(c, a); two_above = true; } if (loc_a == 2 && loc_b == 0 && loc_c == 2) { // Split ab and cb against the polygon line1.set_points(a, b); line2.set_points(c, b); two_above = true; } if (loc_a == 2 && loc_b == 2 && loc_c == 0) { // Split ac and bc against the polygon line1.set_points(a, c); line2.set_points(b, c); two_above = true; } if (loc_a == 2 && loc_b == 0 && loc_c == 0) { // Split ba and ca against the polygon line1.set_points(b, a); line2.set_points(c, a); two_above = false; } if (loc_a == 0 && loc_b == 2 && loc_c == 0) { // Split ab and cb against the polygon line1.set_points(a, b); line2.set_points(c, b); two_above = false; } if (loc_a == 0 && loc_b == 0 && loc_c == 2) { // Split ac and bc against the polygon line1.set_points(a, c); line2.set_points(b, c); two_above = false; } std::vector< std::vector<c_tikz_obj*> > line1_split(3); std::vector< std::vector<c_tikz_obj*> > line2_split(3); line1_split = line1.split(against); line2_split = line2.split(against); int loc; if (two_above) { loc = 2; } else { loc = 0; } c_point point_top(((c_line*)line1_split[loc][0])->ex, ((c_line*)line1_split[loc][0])->ey, ((c_line*)line1_split[loc][0])->ez); c_point point_left(((c_line*)line1_split[loc][0])->sx, ((c_line*)line1_split[loc][0])->sy, ((c_line*)line1_split[loc][0])->sz); c_point point_right(((c_line*)line2_split[loc][0])->sx, ((c_line*)line2_split[loc][0])->sy, ((c_line*)line2_split[loc][0])->sz); c_point bottom_left(((c_line*)line1_split[2-loc][0])->sx, ((c_line*)line1_split[2-loc][0])->sy, ((c_line*)line1_split[2-loc][0])->sz); c_point bottom_right(((c_line*)line2_split[2-loc][0])->sx, ((c_line*)line2_split[2-loc][0])->sy, ((c_line*)line2_split[2-loc][0])->sz); c_polygon * polygon1 = (c_polygon*) this->clone(); c_polygon * polygon2 = (c_polygon*) this->clone(); c_polygon * polygon3 = (c_polygon*) this->clone(); polygon1->a = point_top; polygon1->b = point_left; polygon1->c = point_right; polygon2->a = bottom_left; polygon2->b = point_left; polygon2->c = point_right; polygon3->a = bottom_right; polygon3->b = bottom_left; polygon3->c = point_right; ret[2-loc].push_back(polygon1); ret[loc].push_back(polygon2); ret[loc].push_back(polygon3); return ret; }
void TrajectoryCosts::CalculateLateralAndLongitudinalCosts(vector<TrajectoryCost>& trajectoryCosts, const vector<vector<vector<WayPoint> > >& rollOuts, const vector<vector<WayPoint> >& totalPaths, const WayPoint& currState, const vector<WayPoint>& contourPoints, const PlanningParams& params, const CAR_BASIC_INFO& carInfo, const VehicleState& vehicleState) { double critical_lateral_distance = carInfo.width/2.0 + params.horizontalSafetyDistancel; double critical_long_front_distance = carInfo.wheel_base/2.0 + carInfo.length/2.0 + params.verticalSafetyDistance; double critical_long_back_distance = carInfo.length/2.0 + params.verticalSafetyDistance - carInfo.wheel_base/2.0; int iCostIndex = 0; PlannerHNS::Mat3 rotationMat(-currState.pos.a); PlannerHNS::Mat3 translationMat(-currState.pos.x, -currState.pos.y); PlannerHNS::Mat3 invRotationMat(currState.pos.a-M_PI_2); PlannerHNS::Mat3 invTranslationMat(currState.pos.x, currState.pos.y); double corner_slide_distance = critical_lateral_distance/2.0; double ratio_to_angle = corner_slide_distance/carInfo.max_steer_angle; double slide_distance = vehicleState.steer * ratio_to_angle; GPSPoint bottom_left(-critical_lateral_distance ,-critical_long_back_distance, currState.pos.z, 0); GPSPoint bottom_right(critical_lateral_distance, -critical_long_back_distance, currState.pos.z, 0); GPSPoint top_right_car(critical_lateral_distance, carInfo.wheel_base/3.0 + carInfo.length/3.0, currState.pos.z, 0); GPSPoint top_left_car(-critical_lateral_distance, carInfo.wheel_base/3.0 + carInfo.length/3.0, currState.pos.z, 0); GPSPoint top_right(critical_lateral_distance - slide_distance, critical_long_front_distance, currState.pos.z, 0); GPSPoint top_left(-critical_lateral_distance - slide_distance , critical_long_front_distance, currState.pos.z, 0); bottom_left = invRotationMat*bottom_left; bottom_left = invTranslationMat*bottom_left; top_right = invRotationMat*top_right; top_right = invTranslationMat*top_right; bottom_right = invRotationMat*bottom_right; bottom_right = invTranslationMat*bottom_right; top_left = invRotationMat*top_left; top_left = invTranslationMat*top_left; top_right_car = invRotationMat*top_right_car; top_right_car = invTranslationMat*top_right_car; top_left_car = invRotationMat*top_left_car; top_left_car = invTranslationMat*top_left_car; // m_SafetyBox.clear(); // m_SafetyBox.push_back(bottom_left); // m_SafetyBox.push_back(bottom_right); // m_SafetyBox.push_back(top_right); // m_SafetyBox.push_back(top_left); m_SafetyBorder.points.clear(); m_SafetyBorder.points.push_back(bottom_left) ; m_SafetyBorder.points.push_back(bottom_right) ; m_SafetyBorder.points.push_back(top_right_car) ; m_SafetyBorder.points.push_back(top_right) ; m_SafetyBorder.points.push_back(top_left) ; m_SafetyBorder.points.push_back(top_left_car) ; for(unsigned int il=0; il < rollOuts.size(); il++) { if(rollOuts.at(il).size() > 0 && rollOuts.at(il).at(0).size()>0) { RelativeInfo car_info; PlanningHelpers::GetRelativeInfo(totalPaths.at(il), currState, car_info); for(unsigned int it=0; it< rollOuts.at(il).size(); it++) { for(unsigned int icon = 0; icon < contourPoints.size(); icon++) { RelativeInfo obj_info; PlanningHelpers::GetRelativeInfo(totalPaths.at(il), contourPoints.at(icon), obj_info); double longitudinalDist = PlanningHelpers::GetExactDistanceOnTrajectory(totalPaths.at(il), car_info, obj_info); if(obj_info.iFront == 0 && longitudinalDist > 0) longitudinalDist = -longitudinalDist; double close_in_percentage = 1; // close_in_percentage = ((longitudinalDist- critical_long_front_distance)/params.rollInMargin)*4.0; // // if(close_in_percentage <= 0 || close_in_percentage > 1) close_in_percentage = 1; double distance_from_center = trajectoryCosts.at(iCostIndex).distance_from_center; if(close_in_percentage < 1) distance_from_center = distance_from_center - distance_from_center * (1.0-close_in_percentage); double lateralDist = fabs(obj_info.perp_distance - distance_from_center); if(longitudinalDist < -carInfo.length || lateralDist > 6) { continue; } longitudinalDist = longitudinalDist - critical_long_front_distance; if(m_SafetyBorder.PointInsidePolygon(m_SafetyBorder, contourPoints.at(icon).pos) == true) trajectoryCosts.at(iCostIndex).bBlocked = true; if(lateralDist <= critical_lateral_distance && longitudinalDist >= -carInfo.length/1.5 && longitudinalDist < params.minFollowingDistance) trajectoryCosts.at(iCostIndex).bBlocked = true; trajectoryCosts.at(iCostIndex).lateral_cost += 1.0/lateralDist; trajectoryCosts.at(iCostIndex).longitudinal_cost += 1.0/fabs(longitudinalDist); if(longitudinalDist >= -critical_long_front_distance && longitudinalDist < trajectoryCosts.at(iCostIndex).closest_obj_distance) { trajectoryCosts.at(iCostIndex).closest_obj_distance = longitudinalDist; trajectoryCosts.at(iCostIndex).closest_obj_velocity = contourPoints.at(icon).v; } } iCostIndex++; } } } }
// Generates the clipping region for an element. bool ElementUtilities::GetClippingRegion(Vector2i& clip_origin, Vector2i& clip_dimensions, Element* element) { clip_origin = Vector2i(-1, -1); clip_dimensions = Vector2i(-1, -1); int num_ignored_clips = element->GetClippingIgnoreDepth(); if (num_ignored_clips < 0) return false; // Search through the element's ancestors, finding all elements that clip their overflow and have overflow to clip. // For each that we find, we combine their clipping region with the existing clipping region, and so build up a // complete clipping region for the element. Element* clipping_element = element->GetParentNode(); while (clipping_element != NULL) { // Merge the existing clip region with the current clip region if we aren't ignoring clip regions. if (num_ignored_clips == 0 && clipping_element->IsClippingEnabled()) { Vector2f element_origin_f = clipping_element->GetAbsoluteOffset(Box::CONTENT); Vector2f element_dimensions_f = clipping_element->GetBox().GetSize(Box::CONTENT); Vector2i element_origin(Math::RealToInteger(element_origin_f.x), Math::RealToInteger(element_origin_f.y)); Vector2i element_dimensions(Math::RealToInteger(element_dimensions_f.x), Math::RealToInteger(element_dimensions_f.y)); if (clip_dimensions == Vector2i(-1, -1)) { clip_origin = element_origin; clip_dimensions = element_dimensions; } else { Vector2i top_left(Math::Max(clip_origin.x, element_origin.x), Math::Max(clip_origin.y, element_origin.y)); Vector2i bottom_right(Math::Min(clip_origin.x + clip_dimensions.x, element_origin.x + element_dimensions.x), Math::Min(clip_origin.y + clip_dimensions.y, element_origin.y + element_dimensions.y)); clip_origin = top_left; clip_dimensions.x = Math::Max(0, bottom_right.x - top_left.x); clip_dimensions.y = Math::Max(0, bottom_right.y - top_left.y); } } // If this region is meant to clip and we're skipping regions, update the counter. if (num_ignored_clips > 0) { if (clipping_element->IsClippingEnabled()) num_ignored_clips--; } // Determine how many clip regions this ancestor ignores, and inherit the value. If this region ignores all // clipping regions, then we do too. int clipping_element_ignore_clips = clipping_element->GetClippingIgnoreDepth(); if (clipping_element_ignore_clips < 0) break; num_ignored_clips = Math::Max(num_ignored_clips, clipping_element_ignore_clips); // Climb the tree to this region's parent. clipping_element = clipping_element->GetParentNode(); } return clip_dimensions.x >= 0 && clip_dimensions.y >= 0; }
osg::Node* createTestTexture2D(osg::Node* node, const std::string& filename) { osg::BoundingBox bb; osg::ref_ptr<osg::ComputeBoundsVisitor> boundsVistor = new osg::ComputeBoundsVisitor(); boundsVistor->reset(); node->accept(*boundsVistor.get()); bb = boundsVistor->getBoundingBox(); osg::Group* group = new osg::Group; // left hand side of bounding box. osg::Vec3 top_left(bb.xMin(), bb.yMin(), bb.zMax()); osg::Vec3 bottom_left(bb.xMin(), bb.yMin(), bb.zMin()); osg::Vec3 bottom_right(bb.xMin(), bb.yMax(), bb.zMin()); osg::Vec3 top_right(bb.xMin(), bb.yMax(), bb.zMax()); osg::Vec3 center(bb.xMin(), (bb.yMin() + bb.yMax())*0.5f, (bb.zMin() + bb.zMax())*0.5f); float height = bb.zMax() - bb.zMin(); // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f, 1.0f); (*texcoords)[1].set(0.0f, 0.0f); (*texcoords)[2].set(1.0f, 0.0f); (*texcoords)[3].set(1.0f, 1.0f); geom->setTexCoordArray(0, texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(1.0f, 0.0f, 0.0f); geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f, 1.0f, 1.0f, 1.0f); geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4)); osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. osg::notify(osg::FATAL) << filename << std::endl; osg::Image* image = g_SystemContext._resourceLoader->getImageByFileName(filename); if (image == NULL) { osg::notify(osg::FATAL) << filename << "--load faile!!!" << std::endl; } else texture->setImage(0, image); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); osg::notify(osg::FATAL) << "33333" << std::endl; // create the text label. osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); text->setFont("fonts/arial.ttf"); text->setPosition(center); text->setCharacterSize(height*0.03f); text->setAlignment(osgText::Text::CENTER_CENTER); text->setAxisAlignment(osgText::Text::YZ_PLANE); osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f, -1.0f), osg::StateAttribute::ON); group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. //group->setUpdateCallback(new FilterCallback(texture,text)); return group; }