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; }
void Monster::createNeck(Game& game) { Window& w = game.getModule<Window>(); for (uint32_t i=0; i<neck_parts_count; ++i) { float dist = i*(float)neck_part_len; Vec2 rect_size((float)neck_part_len*1.4f, neck_bottom_thickness - i*neck_thickness_decrease); RectRenderable& neck_rect = renderables.add<RectRenderable>(game.getModule<Window>(), layerMonsterNeck, rect_size); neck_rect.setColor(0.223, 0.247, 0.01); neck_rect.getLocalTransform().setPosition({0, -dist}); neck_rect.getLocalTransform().setRotation(Angle::Pi/2); } }
void BezierCurveItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->setRenderHint(QPainter::Antialiasing, true); QPen pen; pen.setColor(Qt::red); pen.setWidth(2); pen.setStyle(Qt::DashDotLine); painter->setPen(pen); //drawPath; QPainterPath aPath(m_startPos); aPath.quadTo(m_midStartPos, m_midPos); painter->drawPath(aPath); QPainterPath bPath(m_midPos); bPath.quadTo(m_midEndPos, m_endPos); painter->drawPath(bPath); QPen penshaper; penshaper.setStyle(Qt::SolidLine); penshaper.setColor(Qt::darkRed); painter->setPen(penshaper); //#define the rect size; QSize rect_size(60, 60); QRect rect_shape1(m_startPos - QPoint(rect_size.height() / 2, rect_size.width() / 2), rect_size); QRect rect_shape2(m_endPos - QPoint(rect_size.height() / 2, rect_size.width() / 2), rect_size); QBrush brush(Qt::darkGray, Qt::CrossPattern); painter->fillRect(rect_shape1, brush); painter->fillRect(rect_shape2, brush); painter->drawRoundedRect(rect_shape1, 10, 10); painter->drawRoundedRect(rect_shape2, 10, 10); QPen dotpen; dotpen.setWidth(8); dotpen.setColor(Qt::red); brush.setStyle(Qt::SolidPattern); painter->setPen(dotpen); painter->drawPoint(m_startPos); painter->drawPoint(m_endPos); }
GLvoid DrawGLScene(GLvoid) { int i; double r,g,b,w,h,x,y,z; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); glTranslated(0.0,0.0,-6.0); // draw a pyramid (in smooth coloring mode) glBegin(GL_QUADS); // start drawing rectangles for (i=0; i<N; i++) { rect_color(mr[i].r, &r, &g, &b); rect_position(mr[i].r, &x, &y, &z); rect_size(mr[i].r, &w, &h); glColor3d(r,g,b); glVertex3d(x,y,z); glVertex3d(x, y+h, z); glVertex3d(x+w, y+h, z); glVertex3d(x+w, y, z); } glEnd(); glutSwapBuffers(); }
// Update the bed shape from the dialog fields. void BedShapePanel::update_shape() { auto page_idx = m_shape_options_book->GetSelection(); if (page_idx == SHAPE_RECTANGULAR) { Vec2d rect_size(Vec2d::Zero()); Vec2d rect_origin(Vec2d::Zero()); try{ rect_size = boost::any_cast<Vec2d>(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); } catch (const std::exception & /* e */) { return; } try { rect_origin = boost::any_cast<Vec2d>(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin")); } catch (const std::exception & /* e */) { return; } auto x = rect_size(0); auto y = rect_size(1); // empty strings or '-' or other things if (x == 0 || y == 0) return; double x0 = 0.0; double y0 = 0.0; double x1 = x; double y1 = y; auto dx = rect_origin(0); auto dy = rect_origin(1); x0 -= dx; x1 -= dx; y0 -= dy; y1 -= dy; m_canvas->m_bed_shape = { Vec2d(x0, y0), Vec2d(x1, y0), Vec2d(x1, y1), Vec2d(x0, y1)}; } else if(page_idx == SHAPE_CIRCULAR) { double diameter; try{ diameter = boost::any_cast<double>(m_optgroups[SHAPE_CIRCULAR]->get_value("diameter")); } catch (const std::exception & /* e */) { return; } if (diameter == 0.0) return ; auto r = diameter / 2; auto twopi = 2 * PI; auto edges = 60; std::vector<Vec2d> points; for (size_t i = 1; i <= 60; ++i) { auto angle = i * twopi / edges; points.push_back(Vec2d(r*cos(angle), r*sin(angle))); } m_canvas->m_bed_shape = points; } // $self->{on_change}->(); update_preview(); }