Beispiel #1
0
bool MyPolygon::intersects(float x, float y) {

  float x0 = this->_points[0]->get(0);
  float y0 = this->_points[0]->get(1);
  float x1 = this->_points[1]->get(0);
  float y1 = this->_points[1]->get(1);
  float x2 = this->_points[2]->get(0);
  float y2 = this->_points[2]->get(1);
  float x3 = this->_points[3]->get(0);
  float y3 = this->_points[3]->get(1);

  bool in0 = isInTriangle(x2,y2, x1,y1, x3,y3, x, y);
  bool in1 = isInTriangle(x1,y1, x0,y0, x2,y2, x, y);

  return in0 || in1;
}
Beispiel #2
0
bool getPointedFace(int x, int y, EdgeInfo& info, point** cords, int rows, int cols){
	const int MAX = 30;
	int pointedX[MAX], pointedY[MAX], cordZ[MAX];
	bool pointedOrientation[MAX];
	int count=0;
	for(int i=0; i<rows-1; ++i){
		for(int j=0; j<cols-1; ++j){
			if(count<MAX-4){
				bool isIn = isInTriangle(cords[i][j].x, cords[i][j].y, cords[i+1][j].x, cords[i+1][j].y,
							cords[i][j+1].x, cords[i][j+1].y, x, y);
				if(isIn==true){
					pointedX[count] = i;
					pointedY[count] = j;
					cordZ[count] = cords[i][j].z; 
					pointedOrientation[count] = true;
					count++;
					info.pArray = cords;
					info.height = rows;
					info.width = cols;
				}

				isIn = isInTriangle(cords[i+1][j+1].x, cords[i+1][j+1].y, cords[i+1][j].x, cords[i+1][j].y,
							cords[i][j+1].x, cords[i][j+1].y, x, y);
				if(isIn==true){
					pointedX[count] = i;
					pointedY[count] = j;
					cordZ[count] = cords[i][j].z; 
					pointedOrientation[count] = false;
					count++;
					info.pArray = cords;
					info.height = rows;
					info.width = cols;
				}
			}
		}
	}
	if (count==0) return false;

	assert(count<MAX);
	int tempX, tempY, tempZ, tempOri;
	for(int i=0; i<count; ++i){
		for(int j=0; j<count-1; ++j){
			if(cordZ[j]>cordZ[j+1]){
				tempOri = pointedOrientation[j];
				tempX = pointedX[j];
				tempY = pointedY[j];
				tempZ = cordZ[j];
				
				pointedOrientation[j] = pointedOrientation[j+1];
				pointedX[j] = pointedX[j+1];
				pointedY[j] = pointedY[j+1];
				cordZ[j] = cordZ[j+1];
				
				pointedOrientation[j+1] = tempOri;
				pointedX[j+1] = tempX;
				pointedY[j+1] = tempY;
				cordZ[j+1] = tempZ;
			}
		}
	}
	info.orientation = pointedOrientation[0];
	info.x = pointedX[0];
	info.y = pointedY[0];
	info.pArray = cords;
	info.height = rows;
	info.width = cols;

	return true;
}
void Delaunay::rebucket(VHandle vh, VHandleVec& vhvec)
{
    // get all outgoing half_edge around the vertex
    HHandleVec hhvec;
    //   for (auto vhit = mesh.voh_begin(vh); vhit != mesh.voh_end(vh); vhit++ )
    //{
    //	hhvec.push_back(*vhit);
    //}

    for(auto& hh : mesh.voh_range(vh))
    {
        hhvec.push_back(hh);
    }

    //for(auto& hh : mesh)

    // get all face handles around the vertex
    FHandleVec fhvec;
    //for(auto &hh : hhvec)
    //{
    //    fhvec.push_back(mesh.face_handle(hh));
    //}

    //for(auto& fh : mesh.vf_range(vh))
    //{
    //    fhvec.push_back(fh);
    //}
    
    for(auto fit = mesh.vf_begin(vh); fit != mesh.vf_end(vh); fit++)
    {
        fhvec.push_back(*fit);
    }


    // following code lead to compiler crash:
    //for(auto& fhi : mesh.vf_range(vh))
    //    fhvec.push_back(fhi);

    // clear the incident faces' property
    for(auto& fh : fhvec)
    {
        mesh.property(FaceToVertices, fh).clear();
    }

    // what's the diff up and down

    // reset vertex's property
    for (auto& vh : vhvec)
    {
        mesh.property(VertexToFace, vh).invalidate();
        mesh.property(VertexToHEdge, vh).invalidate();
    }

    // for every vertex influenced, find new Face/Edge it belongs to
    for(auto& vhi : vhvec)
    {
        // ENSURE(vh != vhi) and deal with points OVERLAP
        if (isOverlap(vhi, vh))
        {
            continue;
        }

        // find new face it belongs to
        for(auto& fh : fhvec)
        {
            if (isInTriangle(mesh.point(vhi), fh))
            {
                mesh.property(FaceToVertices, fh).push_back(vhi);
                mesh.property(VertexToFace, vhi) = fh;
                break;
            }

            // if (isOnTriangleEdges)

        }

        // the vertex is not IN any triangle
        // check whether lies ON an edge of the triangles
        if (!mesh.property(VertexToFace, vhi).is_valid())
        {
            for (auto &hhi : hhvec)
            {
                // find new edge it belongs to
                HHandle hh_on;
                HHandle hh_next =  mesh.next_halfedge_handle(hhi);
                if (isOnEdge(mesh.point(vhi), hhi))
                {
                    hh_on = hhi;
                }
                else if (isOnEdge(mesh.point(vhi),hh_next))
                {
                    hh_on = hh_next;
                }

                if (hh_on.is_valid())
                {
                    mesh.property(VertexToHEdge, vhi) = hh_on;
                    FHandle fh = mesh.face_handle(hh_on);
                    mesh.property(FaceToVertices, fh).push_back(vhi);
                    mesh.property(VertexToFace, vhi) = fh;
                    break;
                }
            }
        }
    }
}