Exemple #1
0
bool CuttingPlane::VertexIsOutsideOriginalPolygon( Vector2f point, float z)
{
	// Shoot a ray along +X and count the number of intersections.
	// If n_intersections is euqal, return true, else return false

	Vector2f EndP(point.x+10000, point.y);
	int intersectcount = 0;

	for(size_t p=0; p<polygons.size();p++)
	{
		size_t count = polygons[p].points.size();
		for(size_t i=0; i<count;i++)
		{
		Vector2f P1 = Vector2f( vertices[polygons[p].points[(i-1+count)%count]] );
		Vector2f P2 = Vector2f( vertices[polygons[p].points[i]]);

		if(P1.y == P2.y)	// Skip hortisontal lines, we can't intersect with them, because the test line in horitsontal
			continue;

		InFillHit hit;
		if(IntersectXY(point,EndP,P1,P2,hit))
			intersectcount++;
		}
	}
	return intersectcount%2;
}
Exemple #2
0
bool Poly::vertexInside2(const Vector2d &point, double maxoffset) const
{
  // Shoot a ray along +X and count the number of intersections.
  // If n_intersections is even, return false, else return true
  Vector2d EndP(point.x()+10000, point.y());
  int intersectcount = 1; // we want to test if uneven
  double maxoffsetSq = maxoffset*maxoffset;
  Vector2d dummy;
  for(size_t i=0; i<vertices.size();i++)
    {
      const Vector2d P1 = getVertexCircular(i-1);
      const Vector2d P2 = vertices[i];

      if (point_segment_distance_Sq(point, P1, P2, dummy) <= maxoffsetSq) return true;

      // Skip horizontal lines, we can't intersect with them,
      // because the test line is horizontal
      if(P1.y() == P2.y())
	continue;

      Intersection hit;
      if(IntersectXY(point,EndP,P1,P2,hit,maxoffset))
	intersectcount++;
    }
  return (intersectcount%2==0);
}
Exemple #3
0
Point<3> STLLine ::
GetPointInDist(const Array<Point<3> >& ap, double dist, int& index) const
{
    if (dist <= 0)
    {
        index = 1;
        return ap.Get(StartP());
    }

    double len = 0;
    int i;
    for (i = 1; i < pts.Size(); i++)
    {
        double seglen = Dist (ap.Get(pts.Get(i)),
                              ap.Get(pts.Get(i+1)));

        if (len + seglen > dist)
        {
            index = i;
            double relval = (dist - len) / (seglen + 1e-16);
            Vec3d v (ap.Get(pts.Get(i)), ap.Get(pts.Get(i+1)));
            return ap.Get(pts.Get(i)) + relval * v;
        }

        len += seglen;
    }

    index = pts.Size() - 1;
    return ap.Get(EndP());
}
Exemple #4
0
bool Poly::vertexInside(const Vector2d point, double maxoffset) const
{
  // Shoot a ray along +X and count the number of intersections.
  // If n_intersections is even, return false, else return true
  Vector2d EndP(point.x+10000, point.y);
  int intersectcount = 1; // we want to test if uneven

  for(size_t i=0; i<vertices.size();i++)
    {
      Vector2d P1 = getVertexCircular(i-1);
      Vector2d P2 = vertices[i];
                   
      // Skip horizontal lines, we can't intersect with them, 
      // because the test line is horizontal
      if(P1.y == P2.y)      
	continue;
      
      Intersection hit;
      if(IntersectXY(point,EndP,P1,P2,hit,maxoffset))
	intersectcount++;
    }
  return intersectcount%2;
}
Exemple #5
0
/*
double stlgh;
double GetH(const Point3d& p, double x)
{
  return stlgh;//+0.5)*(x+0.5);
}
*/
STLLine* STLLine :: Mesh(const Array<Point<3> >& ap,
                         Array<Point3d>& mp, double ghi,
                         class Mesh& mesh) const
{
    static int timer1a = NgProfiler::CreateTimer ("mesh stl-line 1a");
    static int timer1b = NgProfiler::CreateTimer ("mesh stl-line 1b");
    static int timer2 = NgProfiler::CreateTimer ("mesh stl-line 2");
    static int timer3 = NgProfiler::CreateTimer ("mesh stl-line 3");

    NgProfiler::StartTimer (timer1a);

    STLLine* line = new STLLine(geometry);

    //stlgh = ghi; //uebergangsloesung!!!!

    double len = GetLength(ap);
    double inthl = 0; //integral of 1/h
    double dist = 0;
    double h;
    int ind;
    Point3d p;

    Box<3> bbox;
    GetBoundingBox (ap, bbox);
    double diam = bbox.Diam();

    double minh = mesh.LocalHFunction().GetMinH (bbox.PMin(), bbox.PMax());

    double maxseglen = 0;
    for (int i = 1; i <= GetNS(); i++)
        maxseglen = max2 (maxseglen, GetSegLen (ap, i));

    int nph = 10+int(maxseglen / minh); //anzahl der integralauswertungen pro segment

    Array<double> inthi(GetNS()*nph);
    Array<double> curvelen(GetNS()*nph);

    NgProfiler::StopTimer (timer1a);
    NgProfiler::StartTimer (timer1b);


    for (int i = 1; i <= GetNS(); i++)
    {
        //double seglen = GetSegLen(ap,i);
        for (int j = 1; j <= nph; j++)
        {
            p = GetPointInDist(ap,dist,ind);
            //h = GetH(p,dist/len);
            h = mesh.GetH(p);


            dist += GetSegLen(ap,i)/(double)nph;

            inthl += GetSegLen(ap,i)/nph/(h);
            inthi.Elem((i-1)*nph+j) = GetSegLen(ap,i)/nph/h;
            curvelen.Elem((i-1)*nph+j) = GetSegLen(ap,i)/nph;
        }
    }


    int inthlint = int(inthl+1);

    if ( (inthlint < 3) && (StartP() == EndP()))
    {
        inthlint = 3;
    }
    if ( (inthlint == 1) && ShouldSplit())
    {
        inthlint = 2;
    }

    double fact = inthl/(double)inthlint;
    dist = 0;
    int j = 1;


    p = ap.Get(StartP());
    int pn = AddPointIfNotExists(mp, p, 1e-10*diam);

    int segn = 1;
    line->AddPoint(pn);
    line->AddLeftTrig(GetLeftTrig(segn));
    line->AddRightTrig(GetRightTrig(segn));
    line->AddDist(dist);

    NgProfiler::StopTimer (timer1b);
    NgProfiler::StartTimer (timer2);

    inthl = 0; //restart each meshseg
    for (int i = 1; i <= inthlint; i++)
    {
        while (inthl < 1.000000001 && j <= inthi.Size())
        {
            inthl += inthi.Get(j)/fact;
            dist += curvelen.Get(j);
            j++;
        }

        //went too far:
        j--;
        double tofar = (inthl - 1)/inthi.Get(j);
        inthl -= tofar*inthi.Get(j);
        dist -= tofar*curvelen.Get(j)*fact;

        if (i == inthlint && fabs(dist - len) >= 1E-8)
        {
            PrintSysError("meshline failed!!!");
        }

        if (i != inthlint)
        {
            p = GetPointInDist(ap,dist,ind);
            pn = AddPointIfNotExists(mp, p, 1e-10*diam);
            segn = ind;
            line->AddPoint(pn);
            line->AddLeftTrig(GetLeftTrig(segn));
            line->AddRightTrig(GetRightTrig(segn));
            line->AddDist(dist);
        }

        inthl = tofar*inthi.Get(j);
        dist += tofar*curvelen.Get(j)*fact;
        j++;
    }

    NgProfiler::StopTimer (timer2);
    NgProfiler::StartTimer (timer3);


    p = ap.Get(EndP());
    pn = AddPointIfNotExists(mp, p, 1e-10*diam);
    segn = GetNS();
    line->AddPoint(pn);
    line->AddLeftTrig(GetLeftTrig(segn));
    line->AddRightTrig(GetRightTrig(segn));
    line->AddDist(dist);

    for (int ii = 1; ii <= line->GetNS(); ii++)
    {
        int p1, p2;
        line->GetSeg(ii,p1,p2);
    }
    /*
    (*testout) << "line, " << ap.Get(StartP()) << "-" << ap.Get(EndP())
         << " len = " << Dist (ap.Get(StartP()), ap.Get(EndP())) << endl;
    */

    NgProfiler::StopTimer (timer3);

    return line;
}