Пример #1
0
int main()
{
    typedef bg::model::point<double, 2, bg::cs::cartesian> point_t;
    typedef bg::model::segment<point_t> segment_t;

    segment_t seg1; /*< Default-construct a segment. >*/
    segment_t seg2(point_t(0.0, 0.0), point_t(5.0, 5.0)); /*< Construct, assigning the first and the second point. >*/

#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX

    segment_t seg3{{0.0, 0.0}, {5.0, 5.0}}; /*< Construct, using C++11 unified initialization syntax. >*/

#endif

    bg::set<0, 0>(seg1, 1.0); /*< Set a coordinate. >*/
    bg::set<0, 1>(seg1, 2.0);
    bg::set<1, 0>(seg1, 3.0);
    bg::set<1, 1>(seg1, 4.0);

    double x0 = bg::get<0, 0>(seg1); /*< Get a coordinate. >*/
    double y0 = bg::get<0, 1>(seg1);
    double x1 = bg::get<1, 0>(seg1);
    double y1 = bg::get<1, 1>(seg1);

    std::cout << x0 << ", " << y0 << ", " << x1 << ", " << y1 << std::endl;

    return 0;
}
void SegmentsTests<dimension>::run()
{
  VecD origin1 = random_vec<VecD>();
  VecD direction1 = random_vec<VecD>();
  geom::Point<dimension> point1( new typename geom::Point<dimension>::EuclideanDriver( random_vec<HomogenousVecD>() ) );
  geom::Point<dimension> point2( new typename geom::Point<dimension>::EuclideanDriver( random_vec<HomogenousVecD>() ) );
  
  // Test based on line
  geom::Line<dimension> line1( new typename geom::Line<dimension>::EuclideanDriver( origin1, direction1));
  
  double firstIndex = random_float();
  double lastIndex = random_float();
  SegmentD seg1( new typename SegmentD::LineDriver( &line1, firstIndex, lastIndex ) );
  test_segment_validity( seg1 );
  GEOM_CHECK_VEC_EQUAL( seg1.firstPoint(), line1.pointAt(firstIndex) );
  GEOM_CHECK_VEC_EQUAL( seg1.lastPoint(), line1.pointAt(lastIndex) );
  GEOM_CHECK_NULL( geom::angle(seg1, line1 ) );
  test_segment( seg1 );
  JFR_CHECK( !seg1.isTransformable() );
  // Test constructor based on two points
  SegmentD seg2( new typename SegmentD::TwoPointsPointerDriver( &point1, &point2 ) );
  test_segment_validity( seg2 );
  GEOM_CHECK_VEC_EQUAL( seg2.firstPoint(), point1.homogenousCoordinates() );
  GEOM_CHECK_VEC_EQUAL( seg2.lastPoint(), point2.homogenousCoordinates() );
  test_segment( seg2 );
  JFR_CHECK( !seg2.isTransformable() );
  // Test constructor based on two points
  SegmentD seg3( new typename SegmentD::TwoPointsDriver( point1.homogenousCoordinates(), point2.homogenousCoordinates() ) );
  test_segment_validity( seg3 );
  GEOM_CHECK_VEC_EQUAL( seg3.firstPoint(), point1.homogenousCoordinates() );
  GEOM_CHECK_VEC_EQUAL( seg3.lastPoint(), point2.homogenousCoordinates() );
  test_segment( seg3 );
  JFR_CHECK( seg3.isTransformable() );
  // Test transformability
  HomogenousMatrixD m = random_inversible_mat<dimension>();
  HomogenousMatrixD mInv;
  jmath::ublasExtra::inv( m, mInv );
  SegmentD seg3bis = seg3;
  seg3bis.applyTransformation( m );
  GEOM_CHECK_VEC_EQUAL( seg3bis.firstPoint(), ublas::prod(m, seg3.firstPoint() ) );
  GEOM_CHECK_VEC_EQUAL( seg3bis.lastPoint(), ublas::prod(m, seg3.lastPoint() ) );
  seg3bis.applyTransformation( mInv );
  GEOM_CHECK_VEC_EQUAL( seg3bis.firstPoint(), seg3.firstPoint() );
  GEOM_CHECK_VEC_EQUAL( seg3bis.lastPoint(), seg3.lastPoint() );
  
  // Test distance
  test_distance(seg1, seg2);
  test_distance(seg2, seg3);
  test_distance(seg1, seg3);
  test_distance(seg1, seg2.support());
  test_distance(seg1, seg3.support());
  test_distance(seg2, seg1.support());
  test_distance(seg2, seg3.support());
  test_distance(seg3, seg2.support());
  test_distance(seg3, seg1.support());
}
Пример #3
0
void drawPoint(
    const Vec3& pos,
    const Color& color
) {
    Segment seg1(pos - Vec3(1,0,0), pos + Vec3(1,0,0));
    Segment seg2(pos - Vec3(0,0,1), pos + Vec3(0,0,1));
    
    drawSegment(seg1, color, 0.1f);
    drawSegment(seg2, color, 0.1f);
}
Пример #4
0
const bool Collision::isRectInCircle(const MyRectangle* rect, const Circle* circle)const
{

	Segment seg1(rect->getPosition(), rect->getPosition() + GSvector2(rect->getWidth(), 0));//0,1
	Segment seg2(rect->getPosition() + rect->getSize(),rect->getPosition() + GSvector2(0, rect->getHeight()));//3,2
	float res1 = segment_Point_atan(&seg1,&circle->center);
	float res2 = segment_Point_atan(&seg2,&circle->center);
	if (0 <= res1 && res1 <= 90 &&
		0 <= res2&& res2 <= 90)
	{
		return true;
	}
	return false;
}
Пример #5
0
void Draw2D::drawCube(SDL_Surface *screen,Point3D _pt1, Point3D _pt2, Point3D _pt3, Point3D _pt4)
{
    //   4----6
    //  /|   /|
    //  7----8|
    //  |1---|2
    //  |/   |/
    //  3----5

    // with the 4 points we can find the 4 others
    Point3D pt5 = _pt2+_pt3-_pt1;
    Point3D pt6 = _pt2+_pt4-_pt1;
    Point3D pt7 = _pt3+_pt4-_pt1;
    Point3D pt8 = pt5+_pt4-_pt1;

    // construct all segments
    Segment3D seg1(_pt1,_pt2);
    Segment3D seg2(_pt1,_pt3);
    Segment3D seg3(_pt1,_pt4);
    Segment3D seg4(_pt3,pt5);
    Segment3D seg5(pt5,pt8);
    Segment3D seg6(pt5,_pt2);
    Segment3D seg7(_pt3,pt7);
    Segment3D seg8(_pt2,pt6);
    Segment3D seg9(pt7,_pt4);
    Segment3D seg10(_pt4,pt6);
    Segment3D seg11(pt6,pt8);
    Segment3D seg12(pt7,pt8);

    // draw all segments
    drawSegment(screen,seg1);
    drawSegment(screen,seg2);
    drawSegment(screen,seg3);
    drawSegment(screen,seg4);
    drawSegment(screen,seg5);
    drawSegment(screen,seg6);
    drawSegment(screen,seg7);
    drawSegment(screen,seg8);
    drawSegment(screen,seg9);
    drawSegment(screen,seg10);
    drawSegment(screen,seg11);
    drawSegment(screen,seg12);
}
Пример #6
0
void drawAxis(
    const Vec3& pos
) {
        t3::Segment seg1(
        t3::Vec3(0, 3, 0),
        t3::Vec3(0, 0, 0)
    );

    t3::Segment seg2(
        t3::Vec3(0, 0, 3),
        t3::Vec3(0, 0, 0)
    );

    t3::Segment seg3(
        t3::Vec3(3, 0, 0),
        t3::Vec3(0, 0, 0)
    );
    
    t3::drawSegment(seg1, t3::color_sample::red(), 3.1f);
    t3::drawSegment(seg2, t3::color_sample::blue(), 3.1f);
    t3::drawSegment(seg3, t3::color_sample::green(), 3.1f);
}
bool frgExtractTopologicalEntsFromLinesAlgm::_is_parallel_between(const rlEdge2d *e1, const rlEdge2d *e2) const
{
	// - 构造第一个线段
	rlId vId1 = e1->v1();
	rlId vId2 = e1->v2();

	rlVertex2d *v1 = _topologies->get<rlVertex2d *>(vId1);
	rlVertex2d *v2 = _topologies->get<rlVertex2d *>(vId2);
	if (v1 == NULL || v2 == NULL)
	{
		assert(false);
		return false;
	}

	AcGeLineSeg2d seg1(AcGePoint2d(v1->x(), v1->y()), AcGePoint2d(v2->x(), v2->y()));

	// - 构造第二个线段
	vId1 = e2->v1();
	vId2 = e2->v2();

	v1 = _topologies->get<rlVertex2d *>(vId1);
	v2 = _topologies->get<rlVertex2d *>(vId2);
	if (v1 == NULL || v2 == NULL)
	{
		assert(false);
		return false;
	}

	AcGeLineSeg2d seg2(AcGePoint2d(v1->x(), v1->y()), AcGePoint2d(v2->x(), v2->y()));

	// - 判断二者是否平行
	if (seg1.isParallelTo(seg2, frgGlobals::Gtol) == Adesk::kTrue)
		return true;

	return false;
}
Пример #8
0
void DIGIT::displayMonth(int month)
{
     bool display[8]; 
     switch (month)
     {
            case 1:      seg0(true); 
                         seg1(true);
                         seg2(true);
                         seg3(true);
                         x += 9;
                         seg0(true);
                         seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         seg7(true); 
                         x += 9;
                         seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg8(true);
                         seg13(true);
                         break; 
                 
            case 2:      seg0(true);
                         seg4(true);
                         seg5(true);
                         seg6(true); 
                         x += 9;
                         seg0(true);
                         seg3(true); 
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         x += 9; 
                         for(int i=0; i<8; i++)
                             (this->*ptr[i])(true);
                         break; 
                             
            case 3:      seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg8(true);
                         seg9(true);
                         x += 9;
                         seg0(true);
                         seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         seg7(true); 
                         x += 9;
                         seg0(true);
                         seg1(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         seg7(true);
                         seg13(true);
                         break;   
                          
            case 4:      seg0(true);
                         seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         seg7(true); 
                         x += 9;
                         seg0(true);
                         seg1(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         seg7(true);
                         seg13(true);
                         x += 9;
                         seg0(true);
                         seg1(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         seg7(true);
                         seg13(true);
                         break; 
                         
            case 5:      seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg8(true);
                         seg9(true);
                         x += 9;
                         seg0(true);
                         seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         seg7(true); 
                         x += 9;
                         seg8(true);
                         seg10(true);
                         seg12(true);
                         break; 
                          
            case 6:      seg0(true); 
                         seg1(true);
                         seg2(true);
                         seg3(true);
                         x += 9;
                         seg1(true);
                         seg2(true);
                         seg3(true);
                         seg4(true);
                         seg5(true);
                         x += 9;
                         seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg8(true);
                         seg13(true);
                         break;
                         
            case 7:      seg0(true); 
                         seg1(true);
                         seg2(true);
                         seg3(true);
                         x += 9;
                         seg1(true);
                         seg2(true);
                         seg3(true);
                         seg4(true);
                         seg5(true);
                         x += 9;
                         seg1(true);
                         seg2(true);
                         break;
                          
            case 8:      seg0(true);
                         seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         seg7(true);
                         x += 9;
                         seg1(true);
                         seg2(true);
                         seg3(true);
                         seg4(true);
                         seg5(true);
                         x += 9;
                         seg0(true); 
                         seg3(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         break;
                          
            case 9:      lookup(5, display);
                         for(int i=0; i<8; i++)
                             (this->*ptr[i])(display[i]);
                         x += 9;
                         seg0(true);
                         seg3(true); 
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         x += 9;
                         seg0(true);
                         seg1(true);
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         seg7(true);
                         seg13(true);
                         break;
                          
            case 10:     lookup(0, display);
                         for(int i=0; i<8; i++)
                             (this->*ptr[i])(display[i]);
                         x += 9;
                         seg0(true);
                         seg3(true);
                         seg4(true);
                         seg5(true);
                         x += 9;
                         seg0(true);
                         seg9(true);
                         seg12(true);
                         break; 
                          
            case 11:     seg1(true);
                         seg2(true);
                         seg4(true);
                         seg5(true);
                         seg8(true);
                         seg13(true);
                         x += 9;
                         lookup(0, display);
                         for(int i=0; i<8; i++)
                             (this->*ptr[i])(display[i]);
                         x += 9;
                         seg1(true);
                         seg2(true);
                         seg8(true);
                         seg13(true);
                         break; 
                         
            case 12:     lookup(0, display);
                         for(int i=0; i<8; i++)
                             (this->*ptr[i])(display[i]);
                         x += 9;
                         seg0(true);
                         seg3(true); 
                         seg4(true);
                         seg5(true);
                         seg6(true);
                         x += 9; 
                         seg0(true);
                         seg3(true);
                         seg4(true);
                         seg5(true);
                         break; 
                       
            }                     

}
void LaneDetection::AlgoFilterLanes(ntuple_list line_out)
{
	//fout_2.open("pairs.txt");
	unsigned int dim = line_out->dim;
	int n_size = line_out->size;
	
	Mat lines_candidats = Mat::zeros(processGrayImage.size(), CV_32SC1);

	for (int i = 0; i < n_size; i++)
	{
		const Point2d p1(line_out->values[i * dim + 0], line_out->values[i * dim + 1]);
		const Point2d p2(line_out->values[i * dim + 2], line_out->values[i * dim + 3]);
		Segment2d p12 = Segment2d(p1, p2);//p1.y < p2.y

		for (int j = 0; j < n_size; j++)
		{
			if (j == i) continue;
			Point2d seg1(line_out->values[j * dim + 0], line_out->values[j * dim + 1]);
			Point2d seg2(line_out->values[j * dim + 2], line_out->values[j * dim + 3]);
			Segment2d seg(seg1, seg2);
			
			if (seg.getLength() > p12.getLength())
			{
				continue;
			}

			//simple check
			if (!p12.isNeighbor(seg))
			{
				continue;
			}

			//slope difference?
			if (abs(atan(p12.getSlope()) - atan(seg.getSlope())) > 15 * CV_PI / 180)
			{
				//fout_2 << p1 << p2 << seg1 << seg2 << p12.getSlope() << "," << seg.getSlope() << endl;
				//fout_2 << "continue in abs(atan(p12.getSlope()) - atan(seg.getSlope())) > 10 * CV_PI / 180" << endl;
				continue;
			}

			vector<Segment2d> v = p12.getValidPoly(seg, processGrayImage.rows);
			//valid?
			if (v.empty())
			{
				//fout_2 << p1 << p2 << seg1 << seg2 << endl;
				//fout_2 << "continue in v.empty()" << endl;
				continue;
			}

			//color compare
			Point2d translation[3];
			translation[0] = Point2d(0, 0);
			translation[1] = v[0].p1 - v[1].p1;
			translation[2] = -translation[1];

			vector<uchar> vec_color[3];
			double mean_color[3];
			double stdDev_color[3];
			

			for (int _trans = 0; _trans < 3; _trans++)
			{
				Rect box = getBoundingBox(v[0].p1 + translation[_trans], v[0].p2 + translation[_trans],
					v[1].p1 + translation[_trans], v[1].p2 + translation[_trans]);
				for (int _y = box.y; _y < box.y + box.height; _y++)
				{
					if (_y >= processImage.rows || _y < 0) continue;
					uchar* ptr_row_processImage = processGrayImage.ptr<uchar>(_y);
					for (int _x = box.x; _x < box.x + box.width; _x++)
					{
						if (_x >= processImage.cols || _x < 0) continue;
						Point2d p(_x, _y);
						int direc = cross(p, v[0].p1 + translation[_trans], v[0].p2 + translation[_trans]) > -0.0 ? 1 : -1;

						if (direc != (cross(p, v[0].p2 + translation[_trans], v[1].p2 + translation[_trans]) > -0.0 ? 1 : -1))
							continue;
						if (direc != (cross(p, v[1].p2 + translation[_trans], v[1].p1 + translation[_trans]) > -0.0 ? 1 : -1))
							continue;
						if (direc != (cross(p, v[1].p1 + translation[_trans], v[0].p1 + translation[_trans]) > -0.0 ? 1 : -1))
							continue;

						vec_color[_trans].push_back(ptr_row_processImage[_x]);
					}
				}
				if (vec_color[_trans].empty())
					;
				else
				{
					Mat mean, stdDev;
					meanStdDev(vec_color[_trans], mean, stdDev);
					mean_color[_trans] = mean.at<double>(0);
					stdDev_color[_trans] = stdDev.at<double>(0);
				}
			}

			bool color_matched = (mean_color[0] > mean_color[1] + 10) && (mean_color[0] > mean_color[2] + 10)
				&& stdDev_color[0] < 50;

			if (!color_matched)
			{
				//fout_2 << p1 << p2 << seg1 << seg2 << mean_color[0] << "," << mean_color[1] << "," << mean_color[2];
				//fout_2 << "," << stdDev_color[0] << endl;
				//fout_2 << "continue in color_matched" << endl;

				continue;
			}

			//fout_2 << p1 << p2 << seg1 << seg2 << endl;
			//fout_2 << "Paired!!!!!!" << endl;

			line(processImage, p1, p2, Scalar(0, 0, 255));
			line(processImage, seg1, seg2, Scalar(0, 255, 0));
			//imshow("step1", processImage);
			//waitKey();
			//break;
		}//end for j

	}


	//fout_2 << "-------------------" << endl;
	//fout_2.close();
}
void LaneDetection::AlgoFilterLanes_back(ntuple_list line_out){
	unsigned int dim = line_out->dim;
	int n_size = line_out->size;
	vector< vector<int> > pairs;//each element is a vector of index of segment(s)
	pairs.resize(n_size);

	for (int i = 0; i < n_size; i++)
	{
		const Point2d p1(line_out->values[i * dim + 0], line_out->values[i * dim + 1]);
		const Point2d p2(line_out->values[i * dim + 2], line_out->values[i * dim + 3]);
		double longeur_p12 = dist_p2p(p1, p2);
		Segment2d s(p1, p2);

		//if (line_out->values[i * dim + 0] > 662 && line_out->values[i * dim + 0] < 664)
		//{
		//	int c = 0;
		//}
		//else
		//	continue;

		Point2d milieu_p12 = (p1 + p2) / 2;
		for (int j = 0; j < n_size; j++)
		{
			if (j == i) continue;
			Point2d seg1(line_out->values[j * dim + 0], line_out->values[j * dim + 1]);
			Point2d seg2(line_out->values[j * dim + 2], line_out->values[j * dim + 3]);
			Segment2d seg(seg1, seg2);


			//simple check
			if (!s.isNeighbor(seg))
				continue;

			//not same side
			//if ((cross(p1, seg1, seg2) > -0.0 ? 1 : -1) * (cross(p2, seg1, seg2) > -0.0 ? 1 : -1) < 0)
			//{
			//	continue;
			//}
			
			//slope difference
			double slope_dif = abs(atan(slope_seg(p1, p2)) - atan(slope_seg(seg1, seg2)));
			if (slope_dif > 10 * CV_PI / 180)
			{
				continue;
			}

			double longeur_seg = dist_p2p(seg1, seg2);
			Point2d t_p1, t_p2, t_seg1, t_seg2;
			if (longeur_p12 > longeur_seg * 3)
			{
				if (foot_p2segment(seg1, p1, p2, t_p1) && foot_p2segment(seg2, p1, p2, t_p2))
				{
					t_seg1 = seg1;
					t_seg2 = seg2;
				}
				else
				{
					t_p1 = p1;
					t_p2 = p2;
					t_seg1 = seg1;
					t_seg2 = seg2;
				}
			}
			else if (longeur_seg > longeur_p12 * 3)
			{
				if (foot_p2segment(p1, seg1, seg2, t_seg1) && foot_p2segment(p2, seg1, seg2, t_seg2))
				{
					t_p1 = p1;
					t_p2 = p2;
				}
				else
				{
					t_p1 = p1;
					t_p2 = p2;
					t_seg1 = seg1;
					t_seg2 = seg2;
				}
			}
			else
			{
				t_p1 = p1;
				t_p2 = p2;
				t_seg1 = seg1;
				t_seg2 = seg2;
			}

			Point2d p_start = (t_p1 + t_p2) / 2;
			Point2d p_end = (t_seg1 + t_seg2) / 2;

			//distance
			double thresh = 20;
			if (p_start.y < 2 * processImage.rows / 3 && p_end.y < 2 * processImage.rows / 3)
				thresh = 10;
			if (dist_p2segment(t_p1, t_seg1, t_seg2) > thresh && dist_p2segment(t_p2, t_seg1, t_seg2) > thresh)
			{
				continue;
			}

			//color condition
			int mean_color[3] = { 0, 0, 0 };
			int num[3] = { 0, 0, 0 };
			
			Point2d translation[3];
			translation[0] = Point2d(0, 0);
			translation[1] = p_start - p_end;
			translation[2] = -translation[1];

			for (int _trans = 0; _trans < 3; _trans++)
			{
				Rect box = getBoundingBox(t_p1 + translation[_trans], t_p2 + translation[_trans],
					t_seg1 + translation[_trans], t_seg2 + translation[_trans]);

				Point2d milieu = (p_start + p_end) / 2 + translation[_trans];

				//check direction of cross.
				int direc = (cross(milieu, t_seg1 + translation[_trans], t_seg2 + translation[_trans]) > -EPS_HERE ? 1 : -1) *
					(cross(milieu, t_p1 + translation[_trans], t_p2 + translation[_trans]) > -EPS_HERE ? 1 : -1);
					

				for (int _y = box.y; _y < box.y + box.height; _y++)
				{
					if (_y >= processImage.rows || _y < 0) continue;
					uchar* ptr_row_processImage = ipmImage.ptr<uchar>(_y);
					for (int _x = box.x; _x < box.x + box.width; _x++)
					{
						if (_x >= processImage.cols || _x < 0) continue;
						Point2d p(_x, _y);
						if (direc != (cross(p, t_seg1 + translation[_trans], t_seg2 + translation[_trans]) > -EPS_HERE ? 1 : -1) *
							(cross(p, t_p1 + translation[_trans], t_p2 + translation[_trans]) > -EPS_HERE ? 1 : -1))
						{
							continue;
						}
						mean_color[_trans] += ptr_row_processImage[_x];
						num[_trans]++;
					}
				}
				mean_color[_trans] = (double)mean_color[_trans] / num[_trans];
			}

			bool color_matched = (mean_color[0] > mean_color[1] + 30) && (mean_color[0] > mean_color[2] + 30);

			if (!color_matched)
			{
				//line(processImage, p1, p2, Scalar(255, 0, 0));
				continue;
			}


			Rect box = getBoundingBox(t_p1, t_p2,
				t_seg1, t_seg2);

			Point2d milieu = (p_start + p_end) / 2;
			
			int _trans = 0;
			//check direction of cross.
			int direc = (cross(milieu, t_seg1 + translation[_trans], t_seg2 + translation[_trans]) > -EPS_HERE ? 1 : -1) *
				(cross(milieu, t_p1 + translation[_trans], t_p2 + translation[_trans]) > -EPS_HERE ? 1 : -1);


			for (int _y = box.y; _y < box.y + box.height; _y++)
			{
				if (_y >= processImage.rows || _y < 0) continue;
				Vec3b* ptr_row_processImage = processImage.ptr<Vec3b>(_y);
				for (int _x = box.x; _x < box.x + box.width; _x++)
				{
					if (_x >= processImage.cols || _x < 0) continue;
					Point2d p(_x, _y);
					if (direc != (cross(p, t_seg1 + translation[_trans], t_seg2 + translation[_trans]) > -EPS_HERE ? 1 : -1) *
						(cross(p, t_p1 + translation[_trans], t_p2 + translation[_trans]) > -EPS_HERE ? 1 : -1))
					{
						continue;
					}
					ptr_row_processImage[_x] = Vec3b(255, 0, 255);
				}
			}
			
			//TODO: ADD MORE CONDITIONS to check if they are a pair.
			//line(processImage, p1, p2, Scalar(0, 255, 0));
			//break;
			//add candidate pair to vector.
		}
	}

	ofstream fout("pairs.txt");
	for (int i = 0; i < n_size; i++)
	{
		const Point2d p1(line_out->values[i * dim + 0], line_out->values[i * dim + 1]);
		const Point2d p2(line_out->values[i * dim + 2], line_out->values[i * dim + 3]);

		fout << i << "{" << p1 << "; " << p2 << "}" << " pairs: ";
		int b = (unsigned)theRNG() & 255;
		int g = (unsigned)theRNG() & 255;
		int r = (unsigned)theRNG() & 255;

		if (pairs[i].size() <= 1)
			continue;

		for (int j = 0; j < pairs[i].size(); j++)
		{
			Point2d seg1(line_out->values[pairs[i][j] * dim + 0], line_out->values[pairs[i][j] * dim + 1]);
			Point2d seg2(line_out->values[pairs[i][j] * dim + 2], line_out->values[pairs[i][j] * dim + 3]);



			fout << "[" << seg1 << "; " << seg2 << " ],";
		}




		//line(processImage, p1, p2, Scalar(b, g, r));
		//line(processImage, seg1, seg2, Scalar(b, g, r));

		fout << "--------" << endl;
	}

}
Пример #11
0
TrackGenerator::TrackGenerator() {
  /*
  * Phase 1 -
  * Generate the track tree and place control points that wrap
  * closely around the tree segments.
  */

  // Start by generating the tree
  TrackTreeNode* rootTrackTreeNode = new TrackTreeNode(0.0, 0.0, NULL, 0);

  // Place the control points
  TrackTreeNode* current_start = rootTrackTreeNode;
  TrackTreeNode* previous_start = rootTrackTreeNode->neighbors[0];

  TrackTreeNode* current = current_start;
  TrackTreeNode* previous = previous_start;
  
  vector<vec3> controlPts;

  do {
    TrackTreeNode* next = current->getNextNode(previous);

    if (previous == next) { // happens if current node only has one segment
      vec2 direction = current->xz - previous->xz;
      direction.normalize();
      direction *= current->radius;
      vec2 offset(-direction[1], direction[0]);

      vec2 temp = current->xz + direction + offset;
      vec3 v(temp[0], RAND * 20 + 10, temp[1]);
      controlPts.push_back(v);
      temp = current->xz + direction - offset;
      v = vec3(temp[0], RAND * 20 + 10, temp[1]);
      controlPts.push_back(v);
    }
    else { // Otherwise, do the bisector thing
      vec2 direction1 = current->xz - previous->xz;
      direction1.normalize();
      direction1 = vec2(-direction1[1], direction1[0]);
      vec2 direction2 = next->xz - current->xz;
      direction2.normalize();
      direction2 = vec2(-direction2[1], direction2[0]);

      vec2 newDir = direction1 + direction2;

      double angle = acos(direction1 * direction2);

      newDir.normalize();
      newDir *= current->radius / cos(angle / 2);
      newDir += current->xz;

      // First, randomly assign heights
      vec3 v(newDir[0], RAND * 20 + 10, newDir[1]);
      controlPts.push_back(v);
    }

    // Advance
    previous = current;
    current = next;
  } while (current != current_start || previous != previous_start);
  
  bool majorChange = true;

  while (majorChange) {
    majorChange = false;

    /*
    * Phase 2 -
    * Merge nearby control points and prune control points with angles
    * that are too acute. Repeat until the track stops changing.
    */

    bool changed = true;
    while (changed) {
      changed = false;
      vector<vec3> tempControlPts;

      // Merge close control points first
      double threshold = 20.0;
      int size = controlPts.size();
      for (int i = 0; i < size; i++) {
        vec3 current = controlPts[i];
        vec3 previous = controlPts[(i + size - 1) % size];
        vec3 next = controlPts[(i + 1) % size];

        vec3 distvec1 = current - previous;
        vec3 distvec2 = next - current;
        distvec1[1] = 0.0;
        distvec2[1] = 0.0;
        double dist1 = distvec1.length();
        double dist2 = distvec2.length();
        if (dist1 > threshold && dist2 > threshold) {
          tempControlPts.push_back(current);
        }
        else if (dist2 <= threshold) {
          changed = true;
          vec3 newPoint = (current + next) / 2;
          tempControlPts.push_back(newPoint);
        }
        majorChange |= changed;
      }
      controlPts = tempControlPts;

      // Next, prune sharply angled control points
      tempControlPts.clear();
      size = controlPts.size();
      for (int i = 0; i < size; i++) {
        vec3 current = controlPts[i];
        vec3 previous = controlPts[(i + size - 1) % size];
        vec3 next = controlPts[(i + 1) % size];

        vec3 dir1 = current - previous;
        vec3 dir2 = current - next;
        dir1.normalize();
        dir2.normalize();
        if (acos(dir1 * dir2) < M_PI / 4) {
          changed = true;
        }
        else {
          tempControlPts.push_back(current);
        }
        majorChange |= changed;
      }
      controlPts = tempControlPts;
    }

    /*
    * Phase 3 -
    * Add height information and then adjust to make sure that
    * the track will not overlap too closely.
    */

    // TODO - compare segment distances to make sure that they aren't overalapping too closely
    changed = true;
    while (changed) {
      changed = false;

      for (unsigned int i = 0; i < controlPts.size() - 1; i++) {
        for (unsigned int j = i + 1; j < controlPts.size(); j++) {
          unsigned int jn = (j+1)%controlPts.size();
          pair<vec3, vec3> seg1(controlPts[i], controlPts[i+1]);
          pair<vec3, vec3> seg2(controlPts[j], controlPts[jn]);
          vec3 check = checkSegments(seg1, seg2);
          if (check.length() > 0.01) {
            changed = true;
            controlPts[i] += check / 2;
            controlPts[i+1] += check / 2;
            controlPts[j] -= check / 2;
            controlPts[jn] -= check / 2;
            controlPts[i][1] = max(controlPts[i][1], 4.0);
            controlPts[i+1][1] = max(controlPts[i+1][1], 4.0);
            controlPts[j][1] = max(controlPts[j][1], 4.0);
            controlPts[jn][1] = max(controlPts[jn][1], 4.0);
          }
        }
      }
      
      majorChange |= changed;
    }
  }

  /*
  * Recenter the track
  */
  vector<vec3>::iterator it = controlPts.begin();
  double xMin = (*it)[0];
  double xMax = (*it)[0];
  double zMin = (*it)[2];
  double zMax = (*it)[2];
  it++;
  while (it != controlPts.end()) {
    xMin = min(xMin, (*it)[0]);
    xMax = max(xMax, (*it)[0]);
    zMin = min(zMin, (*it)[2]);
    zMax = max(zMax, (*it)[2]);
    it++;
  }
  double xMid = (xMax + xMin) / 2;
  double zMid = (zMax + zMin) / 2;
  for (unsigned int i = 0; i < controlPts.size(); i++) {
    controlPts[i][0] -= xMid;
    controlPts[i][2] -= zMid;
  }

  xWidth = xMax - xMin;
  zWidth = zMax - zMin;

  /*
  * Add banking to make better turns, and add to pathPts
  */
  for (unsigned int i = 0; i < controlPts.size(); i++) {
    vec2 current = vec2(controlPts[i], VY);
    vec2 prev = vec2(controlPts[(i - 1 + controlPts.size()) % controlPts.size()], VY);
    vec2 next = vec2(controlPts[(i + 1) % controlPts.size()], VY);

    double angle = angleBetween(current, prev, next);
    vec2 dir = current - prev;
    vec2 turn = next - current;
    
    vec3 dir2(dir[0], 0, dir[1]);
    vec3 turn2(turn[0], 0, turn[1]);

    double bankAmount = 45 * pow(0.999, angle * dir.length() * turn.length() / 100);

    if ((dir2 ^ turn2)[1] > 0) {
      bankAmount *= -1;
    }

    pathPts.push_back(PathPoint(controlPts[i], bankAmount));
  }
}
Пример #12
0
std::vector<std::string> StrainMeasures::getSixteenSegmentTorsions(double wall_xi) {

	//The measure of change due to helix rotation between the walls
	//Setup segments
	const double base_start = 1.0;
	const double mid_start = 0.7;
	const double apex_start = 0.5;
	const double apex_end = 0.001;
	const double wall_epi = 1.0;
	if (wall_xi == 1.0)
		wall_xi = 0.99;
	std::vector<WallSegment> segments;
	//APLAX
	const double apexAngle = 0.0;
	//Base
	WallSegment seg1(3, 7); //Segment 2
	seg1.setXIA(apexAngle, 0.5 * (base_start + mid_start), wall_xi);
	seg1.setXIB(apexAngle, 0.5 * (base_start + mid_start), wall_epi);

	WallSegment seg2(5, 1); //Segment 5
	seg2.setXIA(apexAngle, 0.5 * (base_start + mid_start), wall_xi);
	seg2.setXIB(apexAngle, 0.5 * (base_start + mid_start), wall_epi);

	//Mid
	WallSegment seg3(7, 11); //Segment 8
	seg3.setXIA(apexAngle, 0.5 * (mid_start + apex_start), wall_xi);
	seg3.setXIB(apexAngle, 0.5 * (mid_start + apex_start), wall_epi);

	WallSegment seg4(5, 9); //Segment 11
	seg4.setXIA(apexAngle, 0.5 * (mid_start + apex_start), wall_xi);
	seg4.setXIB(apexAngle, 0.5 * (mid_start + apex_start), wall_epi);

	//Apex

	WallSegment seg5(12, 16); //Segment 13
	seg5.setXIA(0.8, 0.5 * (apex_start + apex_end), wall_xi);
	seg5.setXIB(0.8, 0.5 * (apex_start + apex_end), wall_epi);

	WallSegment seg6(9, 13); //Segment 15
	seg6.setXIA(0.1, 0.5 * (apex_start + apex_end), wall_xi);
	seg6.setXIB(0.1, 0.5 * (apex_start + apex_end), wall_epi);

	//TCH
	const double tchAngle = 2.5 / 3.0;
	//Base
	WallSegment tseg1(4, 8); //Segment 3
	tseg1.setXIA(tchAngle, 0.5 * (base_start + mid_start), wall_xi);
	tseg1.setXIB(tchAngle, 0.5 * (base_start + mid_start), wall_epi);

	WallSegment tseg2(6, 2); //Segment 6
	tseg2.setXIA(tchAngle, 0.5 * (base_start + mid_start), wall_xi);
	tseg2.setXIB(tchAngle, 0.5 * (base_start + mid_start), wall_epi);

	//Mid
	WallSegment tseg3(8, 12); //Segment 9
	tseg3.setXIA(tchAngle, 0.5 * (mid_start + apex_start), wall_xi);
	tseg3.setXIB(tchAngle, 0.5 * (mid_start + apex_start), wall_epi);

	WallSegment tseg4(6, 10); //Segment 12
	tseg4.setXIA(tchAngle, 0.5 * (mid_start + apex_start), wall_xi);
	tseg4.setXIB(tchAngle, 0.5 * (mid_start + apex_start), wall_epi);

	//Apex
	WallSegment tseg5(12, 16); //Segment 14
	tseg5.setXIA(tchAngle, 0.5 * (apex_start + apex_end), wall_xi);
	tseg5.setXIB(tchAngle, 0.5 * (apex_start + apex_end), wall_epi);

	WallSegment tseg6(10, 14); //Segment 16
	tseg6.setXIA(tchAngle, 0.5 * (apex_start + apex_end), wall_xi);
	tseg6.setXIB(tchAngle, 0.5 * (apex_start + apex_end), wall_epi);

	//FCH
	const double fchAngle = 1.0 / 3.0;
	//Base
	WallSegment fseg1(1, 5); //Segment 4
	fseg1.setXIA(fchAngle, 0.5 * (base_start + mid_start), wall_xi);
	fseg1.setXIB(fchAngle, 0.5 * (base_start + mid_start), wall_epi);

	WallSegment fseg2(7, 3); //Segment 1
	fseg2.setXIA(fchAngle, 0.5 * (base_start + mid_start), wall_xi);
	fseg2.setXIB(fchAngle, 0.5 * (base_start + mid_start), wall_epi);

	//Mid
	WallSegment fseg3(5, 9); //Segment 10
	fseg3.setXIA(fchAngle, 0.5 * (mid_start + apex_start), wall_xi);
	fseg3.setXIB(fchAngle, 0.5 * (mid_start + apex_start), wall_epi);

	WallSegment fseg4(7, 11); //Segment 7
	fseg4.setXIA(fchAngle, 0.5 * (mid_start + apex_start), wall_xi);
	fseg4.setXIB(fchAngle, 0.5 * (mid_start + apex_start), wall_epi);

	//Apex
	WallSegment fseg5(9, 13); //Segment 14+15
	fseg5.setXIA(fchAngle, apex_start, wall_xi);
	fseg5.setXIB(fchAngle, apex_end, wall_epi);

	WallSegment fseg6(11, 15); //Segment 13+16
	fseg6.setXIA(fchAngle, apex_start, wall_xi);
	fseg6.setXIB(fchAngle, apex_end, wall_epi);

	segments.clear();

	segments.push_back(fseg2); //1
	segments.push_back(seg1); //2
	segments.push_back(tseg1); //3
	segments.push_back(fseg1); //4
	segments.push_back(seg2); //5
	segments.push_back(tseg2); //6
	segments.push_back(fseg4); //7
	segments.push_back(seg3); //8
	segments.push_back(tseg3); //9
	segments.push_back(fseg3); //10
	segments.push_back(seg4); //11
	segments.push_back(tseg4); //12
	segments.push_back(seg5); //13
	segments.push_back(tseg5); //14
	segments.push_back(seg6); //15
	segments.push_back(tseg6); //16

	//Setup the active strain segments
	int aplaxStrainIds[] = { 1, 7, 12, 14, 10, 4 };
	int tchStrainIds[] = { 2, 8, 13, 15, 11, 5 };
	int fchStrainIds[] = { 0, 6, 9, 3 };
	int activeStrainSegments[16];
	unsigned int totalActiveSegments = 0;
	memset(activeStrainSegments, 0, sizeof(int) * 16);
	for (int i = 0; i < 6; i++)
		activeStrainSegments[aplaxStrainIds[i]] = 1;
	totalActiveSegments += 6;
	for (int i = 0; i < 6; i++)
		activeStrainSegments[tchStrainIds[i]] = 1;
	totalActiveSegments += 6;
	for (int i = 0; i < 4; i++)
		activeStrainSegments[fchStrainIds[i]] = 1;
	totalActiveSegments += 4;

	//Compute the strain for each segment over time
	unsigned int samples = numberOfModelFrames_;
	double* length = new double[samples];
	double* nstrain = new double[numberOfModelFrames_];
	double* avgstrain = new double[numberOfModelFrames_];
	double temp_array[3], temp_array1[3];
	unsigned int numSegments = segments.size();

	memset(avgstrain, 0, numberOfModelFrames_ * sizeof(double));
	std::vector<std::string> strains;
	std::stringstream ss;
	//Setup the header
	for (unsigned int i = 0; i < numSegments; i++) {
		WallSegment& seg = segments[i];
		for (unsigned int dt = 0; dt < samples; dt++) {
			double time = ((double) dt) / (samples - 1.0);

			Cmiss_field_cache_set_time(fieldCache, time);
			temp_array1[0] = temp_array1[1] = temp_array1[2] = 0.0;
			//Since cmiss id starts at 1 subtract 1 from seg.elementid?
			Cmiss_field_cache_set_mesh_location(fieldCache, elements[seg.elementida - 1], 3, seg.xia);
			Cmiss_field_evaluate_real(coordianteField, fieldCache, 3, temp_array);
			Cmiss_field_cache_set_mesh_location(fieldCache, elements[seg.elementida - 1], 3, seg.xib);
			Cmiss_field_evaluate_real(coordianteField, fieldCache, 3, temp_array1);

			length[dt] = fabs(temp_array1[2]);
		}

		ss << " 0.0";
		avgstrain[0] = 0.0;
		for (unsigned int dt = 1; dt < samples - 1; dt++) {
			nstrain[dt] = length[dt] - length[0];

			ss << "," << nstrain[dt];
			avgstrain[dt] += nstrain[dt] * activeStrainSegments[i];
		}
		ss << "," << nstrain[0];
		avgstrain[numberOfModelFrames_ - 1] += nstrain[0] * activeStrainSegments[i];
		strains.push_back(ss.str());
		//Clear the buffer
		ss.str("");
	}

	ss << avgstrain[0];
	for (unsigned int dt = 1; dt < numberOfModelFrames_; dt++) {
		ss << "," << avgstrain[dt] / totalActiveSegments;
	}
	strains.push_back(ss.str());

	delete[] length;
	delete[] nstrain;
	delete[] avgstrain;
	return strains;
}
Пример #13
0
std::vector<std::string> StrainMeasures::getSixteenSegmentStrains(std::string fieldName, double wall_xi) {

#ifdef printcoord
	std::cout << "Linear 3D " << fieldName << "\t" << wall_xi << std::endl;
#endif
	std::vector<WallSegment> segments;

	//APLAX 10 22 34 46 46 40 28 16 4
	//      13  9  5  1  1  3  7 11 15
	//Base
	WallSegment seg1(13, 9);
	seg1.setXIA(0, 1, wall_xi);
	seg1.setXIB(0, 1, wall_xi);

	WallSegment seg2(9, 5);
	seg2.setXIA(0, 1, wall_xi);
	seg2.setXIB(0, 1, wall_xi);

	//Mid
	WallSegment seg3(5, 1);
	seg3.setXIA(0, 1, wall_xi);
	seg3.setXIB(0, 1, wall_xi);

	WallSegment seg4(1, 1);
	seg4.setXIA(0, 1, wall_xi);
	seg4.setXIB(0, 0, wall_xi);

	//Apex

	WallSegment seg5(1, 3);
	seg5.setXIA(0, 0, wall_xi);
	seg5.setXIB(0, 1, wall_xi);

	WallSegment seg6(3, 7);
	seg6.setXIA(0, 1, wall_xi);
	seg6.setXIB(0, 1, wall_xi);

	WallSegment seg7(7, 11);
	seg7.setXIA(0, 1, wall_xi);
	seg7.setXIB(0, 1, wall_xi);

	WallSegment seg8(11, 15);
	seg8.setXIA(0, 1, wall_xi);
	seg8.setXIB(0, 1, wall_xi);

	//TCH 12 24 36 48 48 42 30 18 6
	//    45 41 37 33 33 35 39 43 47
	//Base
	WallSegment tseg1(45, 41);
	tseg1.setXIA(0, 1, wall_xi);
	tseg1.setXIB(0, 1, wall_xi);

	WallSegment tseg2(41, 37);
	tseg2.setXIA(0, 1, wall_xi);
	tseg2.setXIB(0, 1, wall_xi);

	//Mid
	WallSegment tseg3(37, 33);
	tseg3.setXIA(0, 1, wall_xi);
	tseg3.setXIB(0, 1, wall_xi);

	WallSegment tseg4(33, 33);
	tseg4.setXIA(0, 1, wall_xi);
	tseg4.setXIB(0, 0, wall_xi);

	//Apex

	WallSegment tseg5(33, 35);
	tseg5.setXIA(0, 0, wall_xi);
	tseg5.setXIB(0, 1, wall_xi);

	WallSegment tseg6(35, 39);
	tseg6.setXIA(0, 1, wall_xi);
	tseg6.setXIB(0, 1, wall_xi);

	WallSegment tseg7(39, 43);
	tseg7.setXIA(0, 1, wall_xi);
	tseg7.setXIB(0, 1, wall_xi);

	WallSegment tseg8(43, 47);
	tseg8.setXIA(0, 1, wall_xi);
	tseg8.setXIB(0, 1, wall_xi);

	//FCH 2 14 26 38 38 44 32 20 8
	//   32 28 24 20 20 18 22 26 30
	//Base
	WallSegment fseg1(32, 28);
	fseg1.setXIA(0, 1, wall_xi);
	fseg1.setXIB(0, 1, wall_xi);

	WallSegment fseg2(28, 24);
	fseg2.setXIA(0, 1, wall_xi);
	fseg2.setXIB(0, 1, wall_xi);

	//Mid
	WallSegment fseg3(24, 20);
	fseg3.setXIA(0, 1, wall_xi);
	fseg3.setXIB(0, 1, wall_xi);

	WallSegment fseg4(20, 20);
	fseg4.setXIA(0, 1, wall_xi);
	fseg4.setXIB(0, 0, wall_xi);

	//Apex

	WallSegment fseg5(20, 18);
	fseg5.setXIA(0, 0, wall_xi);
	fseg5.setXIB(0, 1, wall_xi);

	WallSegment fseg6(18, 22);
	fseg6.setXIA(0, 1, wall_xi);
	fseg6.setXIB(0, 1, wall_xi);

	WallSegment fseg7(22, 26);
	fseg7.setXIA(0, 1, wall_xi);
	fseg7.setXIB(0, 1, wall_xi);

	WallSegment fseg8(26, 30);
	fseg8.setXIA(0, 1, wall_xi);
	fseg8.setXIB(0, 1, wall_xi);

	segments.clear();

	segments.push_back(seg1);
	segments.push_back(seg2);
	segments.push_back(seg3);
	segments.push_back(seg4);
	segments.push_back(seg5);
	segments.push_back(seg6);
	segments.push_back(seg7);
	segments.push_back(seg8);

	segments.push_back(tseg1);
	segments.push_back(tseg2);
	segments.push_back(tseg3);
	segments.push_back(tseg4);
	segments.push_back(tseg5);
	segments.push_back(tseg6);
	segments.push_back(tseg7);
	segments.push_back(tseg8);
	segments.push_back(fseg1);
	segments.push_back(fseg2);
	segments.push_back(fseg3);
	segments.push_back(fseg4);
	segments.push_back(fseg5);
	segments.push_back(fseg6);
	segments.push_back(fseg7);
	segments.push_back(fseg8);

	mySegments = &segments;
	return getSegmentStrains(fieldName);
}