void MidpointDisplacement::generate( std::vector<Point> &points, int roughness, int npoints ) {
    if ( npoints < 0 )
        return;
    for ( unsigned int i = 1; i < points.size(); i += 2 ) {
        Point pMid = middle( points.at( i ), points.at( i - 1 ) );
        Point pDis = displace( pMid, roughness );
        points.insert( points.begin() + i, pDis );
        npoints--;
    }
    
    generate( points, roughness / 2, npoints );
}
UnicodeString &
FilteredNormalizer2::normalizeSecondAndAppend(UnicodeString &first,
                                              const UnicodeString &second,
                                              UBool doNormalize,
                                              UErrorCode &errorCode) const {
    uprv_checkCanGetBuffer(first, errorCode);
    uprv_checkCanGetBuffer(second, errorCode);
    if(U_FAILURE(errorCode)) {
        return first;
    }
    if(&first==&second) {
        errorCode=U_ILLEGAL_ARGUMENT_ERROR;
        return first;
    }
    if(first.isEmpty()) {
        if(doNormalize) {
            return normalize(second, first, errorCode);
        } else {
            return first=second;
        }
    }
    // merge the in-filter suffix of the first string with the in-filter prefix of the second
    int32_t prefixLimit=set.span(second, 0, USET_SPAN_SIMPLE);
    if(prefixLimit!=0) {
        UnicodeString prefix(second.tempSubString(0, prefixLimit));
        int32_t suffixStart=set.spanBack(first, INT32_MAX, USET_SPAN_SIMPLE);
        if(suffixStart==0) {
            if(doNormalize) {
                norm2.normalizeSecondAndAppend(first, prefix, errorCode);
            } else {
                norm2.append(first, prefix, errorCode);
            }
        } else {
            UnicodeString middle(first, suffixStart, INT32_MAX);
            if(doNormalize) {
                norm2.normalizeSecondAndAppend(middle, prefix, errorCode);
            } else {
                norm2.append(middle, prefix, errorCode);
            }
            first.replace(suffixStart, INT32_MAX, middle);
        }
    }
    if(prefixLimit<second.length()) {
        UnicodeString rest(second.tempSubString(prefixLimit, INT32_MAX));
        if(doNormalize) {
            normalize(rest, first, USET_SPAN_NOT_CONTAINED, errorCode);
        } else {
            first.append(rest);
        }
    }
    return first;
}
Example #3
0
bool isPalindrome(char word[], int length) {
  printWord(word, length);

  if (length == 0 || length == 1) {
    return true;
  } else {
    if (firstChar(word) != lastChar(word, length)) {
      return false;
    } else {
      return isPalindrome(middle(word), length - 2);
    }
  }
}
  void CHeightmap::test() {

    float maxDistance = sqrt(this->width * this->width + this->height * this->height) * 0.3f;

    vector2f middle (this->width * 0.5, this->height * 0.5);

    for (unsigned int x = 0 ; x < this->values.size() ; x++) {
      for (unsigned int y = 0 ; y < this->values[x].size() ; y++) {
        vector2f toMiddle (middle[0] - x, middle[1] - y);
        this->setValue(x, y, pow(1.0f - min(1.0f, toMiddle.length() / maxDistance), 4));
      }
    }

  }
void
QcMapGestureArea::start_two_touch_points()
{
  // qInfo();

  m_start_position1 = first_point().pos();
  m_start_position2 = second_point().pos();
  QcVectorDouble start_position = middle(m_start_position1, m_start_position2);
  // Fixme: duplicated code, excepted middle
  m_last_position_for_velocity = start_position;
  m_last_position_for_velocity_time.start();
  QcWgsCoordinate start_coordinate = m_map->to_coordinate(start_position, false);
  m_start_coordinate.set_longitude(start_coordinate.longitude() + m_start_coordinate.longitude() - m_touch_center_coordinate.longitude());
  m_start_coordinate.set_latitude(start_coordinate.latitude() + m_start_coordinate.latitude() - m_touch_center_coordinate.latitude());
}
Example #6
0
void Line::alignWithVec(Matrix<double> vec)
{
    Matrix<double> new_vec = vecNormalize(vec)*vecLength(p_position_b-p_position_a);

    Matrix<double> middle(3, 1);
    middle[0] = p_position_a[0] + 0.5 * (p_position_b[0] - p_position_a[0]);
    middle[1] = p_position_a[1] + 0.5 * (p_position_b[1] - p_position_a[1]);
    middle[2] = p_position_a[2] + 0.5 * (p_position_b[2] - p_position_a[2]);

    p_position_a = middle - 0.5*new_vec;
    p_position_b = middle + 0.5*new_vec;

    computePrism();
    computeVertices();
}
int palindrome(NODEPTR head) {
  if(head == NULL) {
    printf("List empty!\n");
    return 0;
  }
  NODEPTR mid = middle(head);
  mid = reverse(head);
  NODEPTR curr = head;
  while(mid != NULL && curr != NULL) {
    if(mid -> data != curr -> data)
      return 0;
    mid = mid -> next;
    curr = curr -> next;
  }
  return 1;
}
Example #8
0
void Auto_Score::trigger()
{
	if (Position == 1)
	{
		middle();
	}
	else if (Position == 2)
	{
		right();
	}
	else if (Position == 3)
	{
		left();
	}

}
void
QcMapGestureArea::update_two_touch_points()
{
  // qInfo();

  QcVectorDouble p1 = first_point().pos();
  QcVectorDouble p2 = second_point().pos();
  QcVectorDouble delta = p2 - p1;
  m_distance_between_touch_points = delta.magnitude();
  m_current_position = middle(p1, p2);
  update_velocity_list(m_current_position);

  m_two_touch_angle = delta.orientation();
  // Fixme: required ?
  if (m_two_touch_angle > 180)
    m_two_touch_angle -= 360;
}
void mergesort(struct node ** head)
{
	if( (*head) == NULL || (*head)->next == NULL )
		return ;
	else
	{
		struct node * temp;
		temp = middle(*head);
		struct node * mid = temp->next;
		temp->next = NULL;

		mergesort(head);
		mergesort(&mid);

		*head = merge(*head,mid);
	}
}
Example #11
0
int binsrc(std::vector<int> &vec, int key, int min, int max) {
	if(max < min) {
		// key not found
		return -1;
	} else {
		int mid = middle(min, max);

		if(vec[mid] > key) {
			return binsrc(vec, key, min, mid - 1);
		} else if(vec[mid] < key) {
			return binsrc(vec, key, mid + 1, max);
		} else {
			// key found, index will be returned
			return mid;
		}
	}
}
void Chapter2Test::Test2_3() {
  ofstream fout;
  OpenLogFile(fout,"test2_3.html","Problem 2.3: delete the node in the middle of the list, given only access to that node");

  ListNode *head(nullptr);
  ListNode *middle(nullptr);
  ListNode *expected(nullptr);
  stringstream ss;

  ListNode::GenerateListNode({}, 0, head);
  ListNode::GenerateListNode({}, 0, expected);
  ListNode::PrintListNode(head, ss);
  middle = nullptr;
  sol.prob2_3(middle);
  TestLinkedList(fout, ss.str(), head, expected);

  ss.str("");
  int A0[] = {1};
  ListNode::GenerateListNode(A0,1, head);
  ListNode::GenerateListNode({}, 0, expected);
  ListNode::PrintListNode(head, ss);
  middle = head;
  sol.prob2_3(middle);
  TestLinkedList(fout, ss.str(), head, expected);

  ss.str("");
  int A1[] = {1,2,3}, B1[] = {1,3};
  ListNode::GenerateListNode(A1, sizeof(A1)/sizeof(A1[0]), head);
  ListNode::GenerateListNode(B1, sizeof(B1)/sizeof(B1[0]), expected);
  ListNode::PrintListNode(head, ss);
  middle = head->next;
  sol.prob2_3(middle);
  TestLinkedList(fout, ss.str(), head, expected);

  ss.str("");
  int A2[] = {1,2,3,4,5}, B2[] = {1,2,4,5};
  ListNode::GenerateListNode(A2, sizeof(A2)/sizeof(A2[0]), head);
  ListNode::GenerateListNode(B2, sizeof(B2)/sizeof(B2[0]), expected);
  ListNode::PrintListNode(head, ss);
  middle = head->next->next;
  sol.prob2_3(middle);
  TestLinkedList(fout, ss.str(), head, expected);

  CloseLogFile(fout);
}
void
QcMapGestureArea::end_pinch()
{
  // qInfo();

  QcVectorDouble p1 = m_pinch.m_last_point1;
  QcVectorDouble p2 = m_pinch.m_last_point2;

  m_pinch.m_event.set_angle(m_pinch.m_last_angle);
  m_pinch.m_event.set_center(middle(p1, p2));
  m_pinch.m_event.set_number_of_points(0);
  m_pinch.m_event.set_point1(p1);
  m_pinch.m_event.set_point2(p2);
  m_pinch.m_event.set_accepted(true);
  emit pinch_finished(&m_pinch.m_event);

  m_pinch.m_start_distance = 0;
}
void WorldInHandNavigation::rotateBegin(const glm::ivec2 & mouse)
{
    if (NoInteraction != m_mode)
        return;

    m_mode = RotateInteraction;

    bool intersects = false;
    glm::ivec2 middle(m_viewportCapability.width()/2, m_viewportCapability.height()/2);
    m_referencePosition = mouseRayPlaneIntersection(intersects, middle);

    const float depth = m_coordProvider.depthAt(middle);
    m_refPositionValid = intersects && DepthExtractor::isValidDepth(depth);

    m_m0 = mouse;

    m_eye = m_cameraCapability.eye();
    m_center = m_cameraCapability.center();
}
Example #15
0
void Line::setCenter(Matrix<double> pos)
{
    Matrix<double> middle(3, 1);
    middle[0] = p_position_a[0] + 0.5 * (p_position_b[0] - p_position_a[0]);
    middle[1] = p_position_a[1] + 0.5 * (p_position_b[1] - p_position_a[1]);
    middle[2] = p_position_a[2] + 0.5 * (p_position_b[2] - p_position_a[2]);

    Matrix<double> translation(3, 1);
    translation[0] = - middle[0] + pos[0];
    translation[1] = - middle[1] + pos[1];
    translation[2] = - middle[2] + pos[2];

    translation.print(4);

    p_position_a += translation;
    p_position_b += translation;

    computePrism();
    computeVertices();
}
scalar stokesFifthProperties::waveNumber()
{
    scalar lower(1.0e-7);

    scalar upper = Foam::max
        (
            4.0*PI_/( period_*Foam::sqrt( Foam::mag(G_)*depth_)),
            2.0*PI_/( Foam::pow( period_, 2.0))
        );

    scalar middle(0.5*(lower + upper) );

    scalar valLower( eval( lower ) ),
           valUpper( eval( upper ) ),
           valMiddle( eval( middle ) );

    while (true)
    {
        if (Foam::sign( valLower ) == Foam::sign( valMiddle ))
        {
            lower    = middle;
            valLower = valMiddle;
        }
        else
        {
            upper    = middle;
            valUpper = valMiddle;
        }

        middle = 0.5*( lower + upper );

        valMiddle = eval(middle);

        if (Foam::mag(valMiddle) < 1.0e-13)
        {
            break;
        }
    }

    return middle;
}
Example #17
0
File: main.cpp Project: CCJY/coliru
point3d get_intersection(point3d topfrontleft, point3d backbottomright, point3d source)
{
    //find the middle
    point3d middle(topfrontleft.x/2+backbottomright.x/2,
                   topfrontleft.y/2+backbottomright.y/2,
                   topfrontleft.z/2+backbottomright.z/2);
    //slide box and source as if the "middle" was at the origin
    topfrontleft -= middle;
    backbottomright-= middle;
    source -= middle;
    //scale source as if the box is the unit square
    source /= topfrontleft;
    //find the smallest magnatude of the source offset
    point3d mag = abs(source);
    auto min = std::min(mag.x,std::min(mag.y,mag.z));
    //scale the source so that it touches the box
    source /= min;
    //then scale and slide that touching point back to original coordinates
    source = source * topfrontleft + middle;
    return source;
}
Example #18
0
int main() {
  Lattice lat(Cartesian(0,.5,.5), Cartesian(.5,0,.5), Cartesian(.5,.5,0));
  Cartesian middle(0.5,0.5,0.5);
  Relative middlerel = lat.toRelative(middle);
  Reciprocal recip(0.2,0,0);
  int resolution = 20;
  Grid foo(lat, resolution, resolution, resolution),
    bar(lat, resolution, resolution, resolution);
  foo.Set(gaussian);
  foo.epsSlice("demo.eps", Cartesian(1,0,0), Cartesian(0,1,0),
               Cartesian(-.5,-.5,.5), 150);
  foo.epsNativeSlice("native.eps", Cartesian(1,0,0), Cartesian(0,1,0),
                     Cartesian(-.5,-.5,.5));
  
  //std::cout << "and here is the foo" << (foo + 2*bar + foo.cwise()*bar);
  std::cout << "middle and middlerel are:\n"
            << middle << std::endl << middlerel << std::endl
            << lat.toCartesian(middlerel) << std::endl;
  std::cout << "middle dot recip: " << recip * middle << std::endl;
  return 0;
}
Example #19
0
	static Range<FreeAccessIteratorT__> find_bounds(
		FreeAccessIteratorT__ begin___,
		FreeAccessIteratorT__ end___,
		ValueT__ const& value___,
		BinaryPredicateT__ less___
	) {
		while (begin___ < end___) {
			FreeAccessIteratorT__ current___(middle(begin___, end___));
			if (less___(*current___, value___)) {
				begin___ = current___ + 1;
			} else if (less___(value___, *current___)) {
				end___ = current___;
			} else {
				return Range<FreeAccessIteratorT__>(
					::DD::find_lower_bound(begin___, current___, value___, less___),
					::DD::find_higher_bound(current___ + 1, end___, value___, less___)
				);
			}
		}
		return Range<FreeAccessIteratorT__>(begin___, end___);
	}
void makeMeshCircle(std::vector<Vector4f>& dst, float radius)
{
    const int resolution = 64;
    float interp = 1.0f / (float)resolution;
    Vector4f middle(0.0f, 0.0f, 0.0f, 1.0f);
    Vector4f v0(0.0f, 0.0f, 0.0f, 1.0f);
    Vector4f v1(0.0f, 0.0f, 0.0f, 1.0f);

    for(int i = 0; i<=resolution; ++i) {
        float alpha0 = (float)(i+0) * interp * PI * 2.0f;
        float alpha1 = (float)(i+1) * interp * PI * 2.0f;

        v0.x = sin(alpha0);
        v0.y = cos(alpha0);
        v1.x = sin(alpha1);
        v1.y = cos(alpha1);

        dst.push_back(v0);
        dst.push_back(middle);
        dst.push_back(v1);
    }
}
Example #21
0
void NaoHeadControl::RealSlowScan()
{
    float neckYaw, headPitch;
    Vector3f left(0.0,-0.0,120.0), middle(0.0,-35.0,0.0), right(0.0,-0.0,-120.0);

    if (headPathPlanner.getAngles(neckYaw, headPitch))
    {
        if (lastScanWasLeft)
        {
            Vector3f points[3]={left,middle, right};
            headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3f), 1200);
            lastScanWasLeft = !lastScanWasLeft;
        }
        else
        {
            Vector3f points[3]={right, middle, left};
            headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3f), 1200);
            lastScanWasLeft = !lastScanWasLeft;
        }
    }
    setJointsDirect(neckYaw, headPitch);
}
Example #22
0
    void TerrainWeightEditor::RecreateBrush()
    {
        QLabel *brush_canvas = editor_widget_->findChild<QLabel *>("brush_label");
        if(!brush_canvas)
            return;
        QPixmap map(brush_canvas->pixmap()->width(),brush_canvas->pixmap()->height()) ;
        map.fill(QColor(neutral_color_, neutral_color_, neutral_color_));
        QImage image = map.toImage();
        
        QPoint middle(image.width()*0.5f, image.height()*0.5f);
        f32 scale = static_cast<f32>(brush_size_max_)/image.width();
        for(int x=0; x<image.width();x++)
        {
            for(int y=0; y<image.height();y++)
            {
                int col;
                f32 dist = sqrt(pow(static_cast<f32>(x-middle.x()),2)+pow(static_cast<f32>(y-middle.y()),2));

                if((dist*scale)>(brush_size_*0.5f))
                {
                    col = neutral_color_;
                }
                else
                {
                    int mod = abs(brush_modifier_) - abs(dist*(brush_modifier_*falloff_percentage_));

                    if(mod<1)
                        mod = 0;

                    if(brush_modifier_<0)
                        mod = -mod;
                    int col = neutral_color_ + mod;
                    image.setPixel(x,y, QColor(col,col,col).rgb());
                }
            }
        }
        brush_canvas->setPixmap(QPixmap::fromImage(image));
    }
scalar stokesFirstProperties::linearWaveNumber() const
{
	scalar lower(0.0);

    scalar upper = Foam::max( 4.0 * PI_ / ( period_ * Foam::sqrt( Foam::mag(G_) * depth_)),
						      2.0 * PI_ / ( Foam::pow( period_, 2.0) ) );

    scalar middle(0.5 * (lower + upper) );

    scalar tanhMax(100);

    scalar valLower( Foam::pow(omega_, 2.0) - Foam::mag(G_) * lower * Foam::tanh( Foam::min(lower * depth_, tanhMax) ) ),
    	   valUpper( Foam::pow(omega_, 2.0) - Foam::mag(G_) * upper * Foam::tanh( Foam::min(upper * depth_, tanhMax) ) ),
    	   valMiddle( Foam::pow(omega_, 2.0) - Foam::mag(G_) * middle * Foam::tanh( Foam::min(middle * depth_, tanhMax) ) );

    while ( true )
    {
    	if ( Foam::sign( valLower ) == Foam::sign( valMiddle ) )
    	{
			lower    = middle;
			valLower = valMiddle;
    	}
    	else
    	{
    		upper    = middle;
    		valUpper = valMiddle;
    	}

    	middle = 0.5 * ( lower + upper );

    	valMiddle = Foam::pow(omega_, 2.0) - Foam::mag(G_) * middle * Foam::tanh( Foam::min(middle * depth_, tanhMax) );

    	if ( Foam::mag(valMiddle) < 1.0e-13 || Foam::mag(valLower - valUpper) / middle < 1.0e-13 )
    		break;
    }

	return middle;
}
Example #24
0
vector<Point2f> Train::rotateImage(Mat &image,
                        Mat &out,
                        float angle,
                        float scale)
{
    int borderSize = 40;
    int iRows = image.rows >> 1;
    int iCols = image.cols >> 1;
    int maxRC = max(iRows, iCols);
    int maxSize = (int)(sqrt(pow(maxRC, 2.0) * 2) + borderSize + 2) << 1;
    Mat tmp = Mat::zeros(maxSize, maxSize, image.type());
    int nRows = maxSize >> 1;
    int nCols = maxSize >> 1;
    Rect middle(Point( nCols - iCols,
                      nRows - iRows),
                Size(image.cols,
                     image.rows));
    
    vector<Point2f> corners;
    Point tl = middle.tl();
    Point br = middle.br();
    corners.push_back(Point2f(tl.x, tl.y));
    corners.push_back(Point2f(tl.x, tl.y) + Point2f(image.cols, 0));
    corners.push_back(Point2f(br.x, br.y));
    corners.push_back(Point2f(tl.x, tl.y) + Point2f(0, image.rows));
    vector<Point2f> outCorners(corners.size());
    
    image.copyTo(tmp(middle));
    
    Point2f center(nRows, nCols);
    Mat rot = getRotationMatrix2D(center, -angle, scale);
    warpAffine(tmp, out, rot,Size(maxSize, maxSize));
    rotateCorners(corners, outCorners, center, angle, scale     );
      
    return outCorners;
    
}
Example #25
0
BaseIF* makePlate(const Real& height,
                  const Real& thick,
                  const Real& radius,
                  const int&  doHoles,
                  const Real& holeRadius,
                  const Real& holeSpace)
{
  RealVect zero(D_DECL(0.0,0.0,0.0));
  RealVect xAxis(D_DECL(1.0,0.0,0.0));
  bool inside = true;

  // Create the plate without holes
  Vector<BaseIF*> pieces;

  RealVect normal1(D_DECL(1.0,0.0,0.0));
  RealVect point1(D_DECL(height,0.0,0.0));
  PlaneIF plane1(normal1,point1,inside);

  pieces.push_back(&plane1);

  RealVect normal2(D_DECL(-1.0,0.0,0.0));
  RealVect point2(D_DECL(height+thick,0.0,0.0));
  PlaneIF plane2(normal2,point2,inside);

  pieces.push_back(&plane2);

  TiltedCylinderIF middle(radius,xAxis,zero,inside);

  pieces.push_back(&middle);

  IntersectionIF plate(pieces);

  // Make the drills
  Vector<BaseIF*> drillBits;

  // Compute how many drills are needed in each direciton - 2*num+1 -
  // conservatively
  int num = (int)((radius - holeRadius) / holeSpace + 1.0);

  if (doHoles != 0)
  {
    for (int i = -num; i <= num; i++)
    {
      for (int j = -num; j <= num; j++)
      {
        RealVect center(D_DECL(0.0,i*holeSpace,j*holeSpace));
        TiltedCylinderIF* drill = new TiltedCylinderIF(holeRadius,xAxis,center,inside);

        drillBits.push_back(drill);
      }
    }
  }

  UnionIF drills(drillBits);
  ComplementIF notDrills(drills,true);

  // Drill the plate
  IntersectionIF* holyPlate = new IntersectionIF(plate,notDrills);

  return holyPlate;
}
Example #26
0
void MovieLooperUI::PositionIndicator::Draw(BRect update)
{
	BRect rect = Bounds();
	
	// draw the focus indicator
	if (IsFocus())
	{
		SetHighColor(navigationColor);
		StrokeRect(rect);
	}
	else // or not
	{
		// how bout a nice bevel?
		SetHighColor(255,255,255,255);
		StrokeLine(rect.RightTop(), rect.RightBottom());
		StrokeLine(rect.LeftBottom(), rect.RightBottom());
		SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
		StrokeLine(rect.LeftTop(), rect.RightTop());
		StrokeLine(rect.LeftTop(), rect.LeftBottom());
	}
	
	// the non-focus-indicating part of the view
	rect.InsetBy(1.0,1.0);
	
	// everything but the knobs
	if (startCoord == 3.0 && endCoord == rect.right-2.0)
	{
		// green
		SetHighColor(clipColor);
		// don't draw where the knobs draw
		rect.left += 5.0;
		rect.right -= 5.0;
		// draw
		FillRect(rect & update);
	}
	else
	{
		BRect left(rect.left, rect.top, startCoord-3.0, rect.bottom),
				right(endCoord+3.0, rect.top, rect.right, rect.bottom),
				middle(startCoord+3.0, rect.top, endCoord-3.0, rect.bottom);
		
		SetHighColor(clipColor);
		FillRect(middle & update);
		SetHighColor(unClipColor);
		FillRect(left & update);
		FillRect(right & update);
	}
	
	// the position indicator
	if (update.left < playCoord && update.right > playCoord)
	{
		if (playCoord >= (startCoord+3.0) && playCoord <= (endCoord-3.0))
		{
			SetHighColor(0,0,0,255);
			StrokeLine(BPoint(playCoord, 1.0), BPoint(playCoord, Bounds().bottom-1.0));
		}
	}
	// and the knobs
	rect.Set(startCoord-2.0, 1.0, startCoord+2.0, Bounds().bottom-1.0);
	if (update.Intersects(rect))
		DrawKnob(startCoord);
	
	rect.Set(endCoord-2.0, 1.0, endCoord+2.0, Bounds().bottom-1.0);
	if (update.Intersects(rect))
		DrawKnob(endCoord);
}
Example #27
0
void DeferredShading::draw_frustum(const Frustum &f)
{
	Vec3 far[4];
	copy(Slice<Vec3>(far), Slice<const Vec3>(f.far));
	Vec3 near[4];
	copy(Slice<Vec3>(near), Slice<const Vec3>(f.near));
	Vec3 middle(0);
	for (int i = 0; i < 4; i++) {
		middle += near[i];
		middle += far[i];
	}
	middle /= Vec3(8);

	for (int i = 0; i < 4; i++) {
		Vec3 tmp;

		tmp = near[i] - middle;
		tmp *= Vec3(0.9);
		near[i] = middle + tmp;

		tmp = far[i] - middle;
		tmp *= Vec3(0.9);
		far[i] = middle + tmp;
	}

	/*
	for (int i = 0; i < 4; i++) {
		const Vec3 dir = Normalize(near[i] - far[i]);
		near[i] = far[i] + dir * Vec3(1500.0);
	}
	*/
	vertex_buf.clear();
	// quad vertices
	// a b
	// c d
	// (when quad normal looks towards viewer)
	auto quad = [&](const Vec3 &a, const Vec3 &b, const Vec3 &c, const Vec3 &d) {
		vertex_buf.append({b, a, c});
		vertex_buf.append({d, b, c});
	};

	// far
	quad(far[FPC_TOP_LEFT], far[FPC_TOP_RIGHT],
		far[FPC_BOTTOM_LEFT], far[FPC_BOTTOM_RIGHT]);
	// near
	quad(near[FPC_TOP_RIGHT], near[FPC_TOP_LEFT],
		near[FPC_BOTTOM_RIGHT], far[FPC_BOTTOM_LEFT]);
	// left
	quad(near[FPC_TOP_LEFT], far[FPC_TOP_LEFT],
		near[FPC_BOTTOM_LEFT], far[FPC_BOTTOM_LEFT]);
	// right
	quad(far[FPC_TOP_RIGHT], near[FPC_TOP_RIGHT],
		far[FPC_BOTTOM_RIGHT], near[FPC_BOTTOM_RIGHT]);
	// bottom
	quad(far[FPC_BOTTOM_LEFT], far[FPC_BOTTOM_RIGHT],
		near[FPC_BOTTOM_LEFT], near[FPC_BOTTOM_RIGHT]);
	// top
	quad(near[FPC_TOP_LEFT], near[FPC_TOP_RIGHT],
		far[FPC_TOP_LEFT], far[FPC_TOP_RIGHT]);
	draw_vertices(vertex_stream, vertex_buf);
}
Example #28
0
//-----------------------------------------------------------------------------
// PROCESSING
//-----------------------------------------------------------------------------
void Mirror::add_perspective_to_mesh(ntk::Mesh *mesh, ntk::RGBDImage* image){
	if(!mesh || !image) return;

	if(!this->_flags[Mirror::PLANE]){
		return ;
	}

	cv::Mat1f aux_depth = image->depth();
	cv::Mat1b aux_depth_mask = image->depthMask();
	cv::Mat3b aux_color = image->rgb();
	ntk::Pose3D* aux_pose = image->calibration()->depth_pose;
	
	//Create a mask with all existing masks
	cv::Mat1b mega_mask;
	image->depthMask().copyTo(mega_mask);

	//image max and min to 
	int max_width;
	int max_height;
	int min_width;
	int min_height;

	if(this->_flags[Mirror::MASK]){
		max_width = this->_area_max_width;
		max_height = this->_area_max_height;
		min_width = this->_area_min_width;
		min_height = this->_area_min_height;

		cv::bitwise_and(mega_mask,this->_area_mask,mega_mask);
	}
	else{
		max_width = image->depth().cols;
		max_height = image->depth().rows;
		min_width = 0;
		min_height = 0;
	}

	cv::Vec3f normal = this->_plane.normal();
	normal*=-1;

	cv::Point3f middle(0.012746937,0.12180407,-0.75500000);

	for(int i = min_width ; i < max_width ; i++){
		for(int j = min_height ; j < max_height ; j++){
			cv::Point p(i,j);
			//If the point is part of the mask
			float coiso = aux_depth(p);

			if(mega_mask(p) && coiso < 1){
				//Unprojected point
				cv::Point3f pf = aux_pose->unprojectFromImage(p, aux_depth(p));
				
				//Project from Mirror
				double dp = this->_plane.distanceToPlane(pf);

				if(dp < 0.75){
					cv::Point3f pt2;
					pt2.x = pf.x + (dp * 2 * normal.val[0]);
					pt2.y = pf.y + (dp * 2 * normal.val[1]);
					pt2.z = pf.z + (dp * 2 * normal.val[2]);

					//Color vector to pass from RGB to BGR
					cv::Vec3b color = aux_color(p);

					//Create the Surfel, add porperties and add to mesh
					ntk::Surfel surf;
					surf.location = cv::Point3f(pt2);
					surf.color = cv::Vec3f(color.val[2],color.val[1],color.val[0]);
					mesh->addPointFromSurfel(surf);
				}
			}
		}
	}
}
Example #29
0
// This method checks if rects |a| and |b| are fully aligned either vertically or
// horizontally. In general, rects whose central point falls between the top or
// bottom of each other are considered fully aligned.
// Rects that match this criteria are preferable target nodes in move focus changing
// operations.
// * a = Current focused node's rect.
// * b = Focus candidate node's rect.
static bool areRectsFullyAligned(FocusDirection direction, const IntRect& a, const IntRect& b)
{
    int aStart, bStart, aEnd, bEnd;

    switch (direction) {
    case FocusDirectionLeft:
        aStart = a.x();
        bEnd = b.right();
        break;
    case FocusDirectionRight:
        aStart = b.x();
        bEnd = a.right();
        break;
    case FocusDirectionUp:
        aStart = a.y();
        bEnd = b.y();
        break;
    case FocusDirectionDown:
        aStart = b.y();
        bEnd = a.y();
        break;
    default:
        ASSERT_NOT_REACHED();
        return false;
    }

    if (aStart < bEnd)
        return false;

    aStart = start(direction, a);
    bStart = start(direction, b);

    int aMiddle = middle(direction, a);
    int bMiddle = middle(direction, b);

    aEnd = end(direction, a);
    bEnd = end(direction, b);

    // Picture of the totally aligned logic:
    //
    //     Horizontal    Vertical        Horizontal     Vertical
    //  ****************************  *****************************
    //  *  _          *   _ _ _ _  *  *         _   *      _ _    *
    //  * |_|     _   *  |_|_|_|_| *  *  _     |_|  *     |_|_|   *
    //  * |_|....|_|  *      .     *  * |_|....|_|  *       .     *
    //  * |_|    |_| (1)     .     *  * |_|    |_| (2)      .     *
    //  * |_|         *     _._    *  *        |_|  *    _ _._ _  *
    //  *             *    |_|_|   *  *             *   |_|_|_|_| *
    //  *             *            *  *             *             *
    //  ****************************  *****************************

    //     Horizontal    Vertical        Horizontal     Vertical
    //  ****************************  *****************************
    //  *  _......_   *   _ _ _ _  *  *  _          *    _ _ _ _  *
    //  * |_|    |_|  *  |_|_|_|_| *  * |_|     _   *   |_|_|_|_| *
    //  * |_|    |_|  *  .         *  * |_|    |_|  *           . *
    //  * |_|        (3) .         *  * |_|....|_| (4)          . *
    //  *             *  ._ _      *  *             *        _ _. *
    //  *             *  |_|_|     *  *             *       |_|_| *
    //  *             *            *  *             *             *
    //  ****************************  *****************************

    return ((bMiddle >= aStart && bMiddle <= aEnd) // (1)
            || (aMiddle >= bStart && aMiddle <= bEnd) // (2)
            || (bStart == aStart) // (3)
            || (bEnd == aEnd)); // (4)
}
Example #30
0
void KeyboardModel::createKeyboard()
{
    _scene = new osg::Group;
    
    osg::Vec3 origin(0.0f,0.0f,0.0f);
    osg::Vec3 pos=origin;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Control_L,"Ctrl",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Super_L,"Super",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Alt_L,"Alt",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Space,"Space",3.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Mode_switch,"Switch",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Super_R,"Super",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Menu,"Menu",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Control_R,"Ctrl",2.0f,0.5f);

    osg::Vec3 middle(pos.x()+1.0f,0.0f,0.0f);
    
    pos.x() = 0.0f;
    pos.z() += 1.0f;

    addKey(pos,osgGA::GUIEventAdapter::KEY_Shift_L,"Shift",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Backslash,"\\",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Z,"Z",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_X,"X",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_C,"C",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_V,"V",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_B,"B",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_N,"N",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_M,"M",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Comma,",",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Period,".",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Slash,"/",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Shift_R,"Shift",2.0f,0.5f);

    pos.x() = 0.0f;
    pos.z() += 1.0f;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Caps_Lock,"Caps",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_A,"A",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_S,"S",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_D,"D",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F,"F",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_G,"G",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_H,"H",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_J,"J",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_K,"K",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_L,"L",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Semicolon,";",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Quote,"'",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Hash,"#",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Return,"Return",4.0f,0.5f);

    pos.x() = 0.0f;
    pos.z() += 1.0f;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Tab,"Tab",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Q,"Q",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_W,"W",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_E,"E",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_R,"R",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_T,"T",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Y,"Y",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_U,"U",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_I,"I",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_O,"O",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_P,"P",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Leftbracket,"[",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Rightbracket,"]",1.0f,1.0f);

    pos.x() = 0.0f;
    pos.z() += 1.0f;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Backquote,"`",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_1,"1",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_2,"2",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_3,"3",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_4,"4",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_5,"5",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_6,"6",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_7,"7",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_8,"8",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_9,"9",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_0,"0",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Minus,"-",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Equals,"=",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_BackSpace,"Backspace",3.0f,0.5f);

    pos.x() = 0.0f;
    pos.z() += 1.5f;
    
    float F_height = 0.5f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_Escape,"Esc",2.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F1,"F1",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F2,"F2",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F3,"F3",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F4,"F4",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F5,"F5",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F6,"F6",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F7,"F7",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F8,"F8",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F9,"F9",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F10,"F10",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F11,"F11",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F12,"F12",1.0f,F_height);


    
    float cursorMoveHeight=0.35f;

    pos = middle;    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Left,"Left",1.0f,cursorMoveHeight);
    osg::Vec3 down = pos;
    addKey(pos,osgGA::GUIEventAdapter::KEY_Down,"Down",1.0f,cursorMoveHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Right,"Right",1.0f,cursorMoveHeight);
    
    osg::Vec3 keypad = pos;
    keypad.x()+=1.0f;

    pos = down;
    pos.z() += 1.0f;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Up,"Up",1.0f,cursorMoveHeight);
    

    float homeHeight = 0.35f;
    pos = middle;
    pos.z() += 3.0;    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Delete,"Delete",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_End,"End",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Page_Down,"Page\nDown",1.0f,homeHeight);
    
    pos = middle;
    pos.z() += 4.0;    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Insert,"Insert",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Home,"Home",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Page_Up,"Page\nUp",1.0f,homeHeight);

    pos = middle;
    pos.z() += 5.5;    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Print,"PrtScrn\nSysRq",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Scroll_Lock,"ScrLk",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Pause,"Pause\nBreak",1.0f,homeHeight);
    
    

    pos = keypad;
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Insert,"0",2.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Delete,".",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Enter,"Enter",1.0f,homeHeight);
    
    pos = keypad;
    pos.z() += 1.0f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_End,"1",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Down,"2",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Page_Down,"3",1.0f,1.0f);

    pos = keypad;
    pos.z() += 2.0f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Left,"4",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Begin,"5",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Right,"6",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Add,"+",1.0f,1.0f);

    pos = keypad;
    pos.z() += 3.0f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Home,"7",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Up,"8",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Page_Up,"9",1.0f,1.0f);

    pos = keypad;
    pos.z() += 4.0f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_Num_Lock,"Num\nLock",1.0f,0.3f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Divide,"/",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Multiply,"*",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Subtract,"-",1.0f,1.0f);
    
    float totalWidth = pos.x()-origin.x();
    pos = origin;
    pos.z() += -1.5f;

    osg::Geode* geodeInput = new osg::Geode;
    {
        _inputText = new osgText::Text;
        _inputText->setFont("fonts/arial.ttf");
        _inputText->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
        _inputText->setCharacterSize(1.0f);
        _inputText->setMaximumWidth(totalWidth);
        _inputText->setPosition(pos);
        _inputText->setDrawMode(osgText::Text::TEXT/*||osgText::Text::BOUNDINGBOX*/);
        _inputText->setAlignment(osgText::Text::BASE_LINE);
        _inputText->setAxisAlignment(osgText::Text::XZ_PLANE);
        _inputText->setDataVariance(osg::Object::DYNAMIC);
        _inputText->setText("Press some keys...");
        
        geodeInput->addDrawable(_inputText.get());
        
        _scene->addChild(geodeInput);
    }

}