// Converts the Boxa array to a list of C_BLOB, getting rid of severely // overlapping outlines and those that are children of a bigger one. // The output is a list of C_BLOBs that are owned by the list. // The C_OUTLINEs in the C_BLOBs contain no outline data - just empty // bounding boxes. The Boxa is consumed and destroyed. void LineFinder::ConvertBoxaToBlobs(int image_width, int image_height, Boxa** boxes, C_BLOB_LIST* blobs) { #ifdef HAVE_LIBLEPT C_OUTLINE_LIST outlines; C_OUTLINE_IT ol_it = &outlines; // Iterate the boxes to convert to outlines. int nboxes = boxaGetCount(*boxes); for (int i = 0; i < nboxes; ++i) { l_int32 x, y, width, height; boxaGetBoxGeometry(*boxes, i, &x, &y, &width, &height); // Make a C_OUTLINE from the leptonica box. This is a bit of a hack, // as there is no outline, just a bounding box, but with some very // small changes to coutln.cpp, it works nicely. ICOORD top_left(x, image_height - y); ICOORD bot_right(x + width, image_height - (y + height)); CRACKEDGE startpt; startpt.pos = top_left; C_OUTLINE* outline = new C_OUTLINE(&startpt, top_left, bot_right, 0); ol_it.add_after_then_move(outline); } // Use outlines_to_blobs to convert the outlines to blobs and find // overlapping and contained objects. The output list of blobs in the block // has all the bad ones filtered out and deleted. BLOCK block; ICOORD page_tl(0, 0); ICOORD page_br(image_width, image_height); outlines_to_blobs(&block, page_tl, page_br, &outlines); // Transfer the created blobs to the output list. C_BLOB_IT blob_it(blobs); blob_it.add_list_after(block.blob_list()); // The boxes aren't needed any more. boxaDestroy(boxes); #endif }
cv::Mat ImageOps::rectlinearProject(cv::Mat ImgToCalibrate, bool INV_FLAG, float F) { cv::Mat Img = ImgToCalibrate; int height = Img.rows; int width = Img.cols; cv::Mat destPic = cv::Mat(cv::Size(width, height), ImgToCalibrate.type()); //std::cout << "rect linear " << ImgToCalibrate.type() << " " << CV_8UC3 << " " << CV_8UC1 << " " << CV_8UC4 << std::endl; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { cv::Point2f current_pos(x, y); current_pos = convert_pt(current_pos, width, height, INV_FLAG, F); cv::Point2i top_left((int)current_pos.x, (int)current_pos.y); //top left because of integer rounding //make sure the point is actually inside the original image if (top_left.x < 0 || top_left.x > width - 2 || top_left.y < 0 || top_left.y > height - 2) { continue; } if (destPic.type() == CV_8UC1) { interpolateBilinear(Img, current_pos, top_left, destPic.at<uchar>(y, x)); } else {//JH: added color pixels interpolateBilinear(Img, current_pos, top_left, destPic.at<cv::Vec3b>(y, x)); } } } return destPic; }
void top_left(node * root) { if (root->left != NULL) { top_left(root->left); } cout << root->data << " "; }
VCrop::VCrop(cv::VideoCapture &capture, const float &x, const float &y, const float &size) : capture(&capture) { if (!capture.isOpened()) { std::string error_message = "Error when reading input stream"; LOG(ERROR) << error_message; throw error_message; } int frame_width = capture.get(CV_CAP_PROP_FRAME_WIDTH); int frame_height = capture.get(CV_CAP_PROP_FRAME_HEIGHT); VLOG(2) << "Frame Width: " << frame_width; VLOG(2) << "Frame Height: " << frame_height; LOG_IF(FATAL, frame_width <= 0) << "Frame width is less than zero."; LOG_IF(FATAL, frame_height <= 0) << "Frame height is less than zero."; float diameter = sqrt(frame_width * frame_width + frame_height * frame_height); cv::Point2i top_left(frame_width * x, frame_height * y); cv::Size2i rect_size(diameter * size, diameter * size); if (top_left.x + rect_size.width > frame_width || top_left.y + rect_size.height > frame_height) { LOG(ERROR) << "Size(" << rect_size << ") to too large for given x(" << top_left.x << ") and y(" << top_left.y << ") coordinate."; } roi = new cv::Rect(top_left, rect_size); VLOG(1) << "RoI: \t" << *roi; frame_rate = capture.get(CV_CAP_PROP_FPS); if (isnan(frame_rate) || frame_rate <= 0) { LOG(WARNING) << "Failed to get frame rate, setting rate to 10fps."; frame_rate = 10; } VLOG(1) << "Frame Rate: \t" << frame_rate; }
bool ConsoleOverlayWindow::ResizeConsole(rectangle const& requestedSizePos) { if (!_consoleHelper.RefreshInfo()) return false; auto currentPixelSize = GetWindowRect(_hWndConsole).size(); auto addedCells = (requestedSizePos.size() - currentPixelSize) / _consoleHelper.CellSize(); if (!addedCells) return false; auto newBufferView = _consoleHelper.BufferView() + addedCells; auto rc = _consoleHelper.Resize(newBufferView); if (rc) { auto newPixelSize = GetWindowRect(_hWndConsole); if (newPixelSize.top_left() != requestedSizePos.top_left()) { ::SetWindowPos(_hWndConsole, NULL, requestedSizePos.left(), requestedSizePos.top(), 0, 0, SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOSIZE | SWP_NOZORDER); } } return rc; }
/////////////////////////////////////////////////////////////////////////////// /// \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(); } }
// 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; }
void top_view(node * root) { if (root->left != NULL) { top_left(root->left); } cout << root->data << " "; if (root->right != NULL) { top_right(root->right); } }
void Font::render(){ glPushMatrix(); //get texture GLuint texture_ID = Texture::Instance().get_texture(Texture::FONT); glBindTexture(GL_TEXTURE_2D, texture_ID); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //start drawing glLoadIdentity(); for (int i = 0; i < texts.size(); i++) { Rect rec = texts[i].box; T_Rect text_clip = clips[texts[i].frame]; std::vector<Point> clip_point = Scene::Instance().get_clip_point(rec); std::vector<Point> texture_clip; if (!clip_point.empty()) { Point top_left(texts[i].box.x, texts[i].box.y); float ratio_w = rec.w / text_clip.w; float ratio_h = rec.h / text_clip.h; //map the clip_point to texture point for (Point & p : clip_point) { Point cp(p); cp.x = (p.x - top_left.x)/ratio_w + text_clip.x; cp.y = (p.y - top_left.y)/ratio_h + text_clip.y; texture_clip.push_back(cp); } glBegin(GL_TRIANGLE_FAN); glColor3f(1, 1, 0); for (int j = 0; j < clip_point.size();j++) { glTexCoord2f(texture_clip[j].x, texture_clip[j].y); glVertex2f(clip_point[j].x, clip_point[j].y); } glEnd(); } } //unbind texture glBindTexture(GL_TEXTURE_2D, 0); glPopMatrix(); }
void test_diamond(int i, float f, double d, char c) { top(&i); left(&f); right(&d); bottom(&c); bottom(&d); // expected-warning{{incompatible pointer types passing 'double *' to parameter of type 'char *'}} // Names in multiple places in the diamond. top_left(&c); left_and_right(&i); struct left_and_right lr; lr.left = 17; }
/** Exporte l'ellipse en XML @param xml_document Document XML a utiliser pour creer l'element XML @return un element XML decrivant l'ellipse */ const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const { QDomElement xml_element; if (qFuzzyCompare(rect().width(), rect().height())) { xml_element = xml_document.createElement("circle"); xml_element.setAttribute("diameter", QString("%1").arg(rect().width())); } else { xml_element = xml_document.createElement("ellipse"); xml_element.setAttribute("width", QString("%1").arg(rect().width())); xml_element.setAttribute("height", QString("%1").arg(rect().height())); } QPointF top_left(sceneTopLeft()); xml_element.setAttribute("x", QString("%1").arg(top_left.x())); xml_element.setAttribute("y", QString("%1").arg(top_left.y())); stylesToXml(xml_element); return(xml_element); }
/** * \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; }); }
int ccc_win_main() { Point top_left(1, 3); Point top_right(1, 4); Point bottom_left(2, 3); Line horizontal(top_left, top_right); Line vertical(top_left, bottom_left); cwin << horizontal << vertical; horizontal.move(1, 0); vertical.move(0, 1); cwin << horizontal << vertical; return 0; }
QStyleOptionViewItemV4 PlaylistDelegateBase::Adjusted(const QStyleOptionViewItem& option, const QModelIndex& index) const { if (!view_) return option; QPoint top_left(-view_->horizontalScrollBar()->value(), -view_->verticalScrollBar()->value()); if (view_->header()->logicalIndexAt(top_left) != index.column()) return option; QStyleOptionViewItemV4 ret(option); if (index.data(Playlist::Role_IsCurrent).toBool()) { // Move the text in a bit on the first column for the song that's currently // playing ret.rect.setLeft(ret.rect.left() + 20); } return ret; }
void GLOffscreenTarget::updateImageTile(Size x_lower, Size y_lower, Size x_upper, Size y_upper) { QImage current_screen; if (use_pixel_buffer_ && pixel_buffer_) current_screen = pixel_buffer_->toImage(); else if (share_from_) current_screen = share_from_->grabFrameBuffer(); if (!current_screen.isNull()) { // compute the coordinates of the rectangle in the final image (remembering // that Qt sets y to 0 on the *upper* boundary of the image!) QPoint top_left(x_lower, current_image_.height() - (y_upper+1)); QPoint bot_right(x_upper, current_image_.height() - (y_lower+1)); QPainter p(¤t_image_); p.drawImage(QRect(top_left, bot_right), current_screen, current_screen.rect()); p.end(); } }
void LuaSrcView::OnContextMenu(CWnd* wnd, CPoint point) { CMenu menu; if (!menu.LoadMenu(IDR_POPUP_EDIT)) return; CMenu *popup = menu.GetSubMenu(0); ASSERT(popup != NULL); if (point.x == -1 && point.y == -1) { CRect rect; GetClientRect(rect); point = rect.TopLeft(); CPoint top_left(0, 0); ClientToScreen(&top_left); point.x = top_left.x + rect.Width() / 2; point.y = top_left.y + rect.Height() / 2; } popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd()); }
// 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; }
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++; } } } }
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() }}; }
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); }
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; }
bool me::WindowManager::handle_touch_event(MirTouchEvent const* tev) { bool handled = false; geometry::Point cursor = average_pointer(tev); auto const& modifiers = mir_touch_event_modifiers(tev); int fingers = mir_touch_event_point_count(tev); if (fingers > max_fingers) max_fingers = fingers; auto const surf = focus_controller->focused_surface(); if (surf && (modifiers & mir_input_event_modifier_alt || fingers >= 3)) { geometry::Displacement pinch_dir; auto pinch_diam = measure_pinch(tev, pinch_dir); // Start of a gesture: When the latest finger/button goes down if (any_touches_went_down(tev)) { click = cursor; save_edges(*surf, click); handled = true; } else if(max_fingers <= 3) // Avoid accidental movement { geometry::Displacement drag = cursor - old_cursor; surf->move_to(old_pos + drag); if (fingers == 3) { // Resize by pinch/zoom float diam_delta = pinch_diam - old_pinch_diam; /* * Resize vector (dx,dy) has length=diam_delta and * direction=pinch_dir, so solve for (dx,dy)... */ float lenlen = diam_delta * diam_delta; int x = pinch_dir.dx.as_int(); int y = pinch_dir.dy.as_int(); int xx = x * x; int yy = y * y; int xxyy = xx + yy; int dx = sqrtf(lenlen * xx / xxyy); int dy = sqrtf(lenlen * yy / xxyy); if (diam_delta < 0.0f) { dx = -dx; dy = -dy; } int width = old_size.width.as_int() + dx; int height = old_size.height.as_int() + dy; surf->resize({width, height}); } handled = true; } old_pos = surf->top_left(); old_size = surf->size(); old_pinch_diam = pinch_diam; } auto gesture_ended = last_touch_released(tev); if (max_fingers == 4 && gesture_ended) { // Four fingers released geometry::Displacement dir = cursor - click; if (abs(dir.dx.as_int()) >= min_swipe_distance) { focus_controller->focus_next_session(); if (auto const surface = focus_controller->focused_surface()) focus_controller->raise({surface}); handled = true; } } if (fingers == 1 && gesture_ended) max_fingers = 0; old_cursor = cursor; return handled; }
//! 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); }
bool me::WindowManager::handle_pointer_event(MirPointerEvent const* pev) { bool handled = false; geometry::Point cursor{mir_pointer_event_axis_value(pev, mir_pointer_axis_x), mir_pointer_event_axis_value(pev, mir_pointer_axis_y)}; auto action = mir_pointer_event_action(pev); auto modifiers = mir_pointer_event_modifiers(pev); auto vscroll = mir_pointer_event_axis_value(pev, mir_pointer_axis_vscroll); auto primary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_primary); auto tertiary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_tertiary); float new_zoom_mag = 0.0f; // zero means unchanged if (modifiers & mir_input_event_modifier_meta && action == mir_pointer_action_motion) { zoom_exponent += vscroll; // Negative exponents do work too, but disable them until // there's a clear edge to the desktop. if (zoom_exponent < 0) zoom_exponent = 0; new_zoom_mag = powf(1.2f, zoom_exponent); handled = true; } me::DemoCompositor::for_each( [new_zoom_mag,&cursor](me::DemoCompositor& c) { if (new_zoom_mag > 0.0f) c.zoom(new_zoom_mag); c.on_cursor_movement(cursor); }); if (zoom_exponent || new_zoom_mag) force_redraw(); auto const surf = focus_controller->focused_surface(); if (surf && (modifiers & mir_input_event_modifier_alt) && (primary_button_pressed || tertiary_button_pressed)) { // Start of a gesture: When the latest finger/button goes down if (action == mir_pointer_action_button_down) { click = cursor; save_edges(*surf, click); handled = true; } else if (action == mir_pointer_action_motion) { geometry::Displacement drag = cursor - old_cursor; if (tertiary_button_pressed) { // Resize by mouse middle button resize(*surf, cursor); } else { surf->move_to(old_pos + drag); } handled = true; } old_pos = surf->top_left(); old_size = surf->size(); } if (surf && (modifiers & mir_input_event_modifier_alt) && action == mir_pointer_action_motion && vscroll) { float alpha = surf->alpha(); alpha += 0.1f * vscroll; if (alpha < 0.0f) alpha = 0.0f; else if (alpha > 1.0f) alpha = 1.0f; surf->set_alpha(alpha); handled = true; } old_cursor = cursor; return handled; }
//! 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); }
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; }
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; }