Esempio n. 1
0
static void locate_point( Mat& img, Subdiv2D& subdiv, Point2f fp, Scalar active_color )
{
	int e0=0, vertex=0;


	subdiv.locate(fp, e0, vertex);


	if( e0 > 0 )
	{
		int e = e0;
		do
		{
			Point2f org, dst;
			if( subdiv.edgeOrg(e, &org) > 0 && subdiv.edgeDst(e, &dst) > 0 )
				line( img, org, dst, active_color, 3);


			e = subdiv.getEdge(e, Subdiv2D::NEXT_AROUND_LEFT);
		}
		while( e != e0 );
	}

	draw_subdiv_point( img, fp, active_color );
}
Esempio n. 2
0
static void draw_subdiv( Mat& img, Subdiv2D& subdiv, Scalar delaunay_color )
{
#if 1
    vector<Vec6f> triangleList;
    subdiv.getTriangleList(triangleList);
    vector<Point> pt(3);
    
    for( size_t i = 0; i < triangleList.size(); i++ )
    {
        Vec6f t = triangleList[i];
        pt[0] = Point(cvRound(t[0]), cvRound(t[1]));
        pt[1] = Point(cvRound(t[2]), cvRound(t[3]));
        pt[2] = Point(cvRound(t[4]), cvRound(t[5]));
        line(img, pt[0], pt[1], delaunay_color, 1, CV_AA, 0);
        line(img, pt[1], pt[2], delaunay_color, 1, CV_AA, 0);
        line(img, pt[2], pt[0], delaunay_color, 1, CV_AA, 0);
    }
#else
    vector<Vec4f> edgeList;
    subdiv.getEdgeList(edgeList);
    for( size_t i = 0; i < edgeList.size(); i++ )
    {
        Vec4f e = edgeList[i];
        Point pt0 = Point(cvRound(e[0]), cvRound(e[1]));
        Point pt1 = Point(cvRound(e[2]), cvRound(e[3]));
        line(img, pt0, pt1, delaunay_color, 1, CV_AA, 0);
    }
#endif
}
Esempio n. 3
0
static void locate_point( Mat& img, Subdiv2D& subdiv, Point2f fp, Scalar active_color )
{
    int e0=0, vertex=0;

//    cout << "locate: " << fp << "\n";
    subdiv.locate(fp, e0, vertex);

    if( e0 > 0 )
    {
        int e = e0;
        do
        {
            Point2f org, dst;
            if( subdiv.edgeOrg(e, &org) > 0 && subdiv.edgeDst(e, &dst) > 0 )

                // line( img, org, dst, active_color, 3, LINE_AA, 0 );

            e = subdiv.getEdge(e, Subdiv2D::NEXT_AROUND_LEFT);
        }
        while( e != e0 );
    }

    // interactive drawing
//    draw_subdiv_point( img, fp, active_color );
}
Esempio n. 4
0
void paint_voronoi( Mat& img, Subdiv2D& subdiv )
{
    vector<vector<Point2f> > facets;
    vector<Point2f> centers;
    subdiv.getVoronoiFacetList(vector<int>(), facets, centers);
    
    vector<Point> ifacet;
    vector<vector<Point> > ifacets(1);
    
    for( size_t i = 0; i < facets.size(); i++ )
    {
        ifacet.resize(facets[i].size());
        for( size_t j = 0; j < facets[i].size(); j++ )
            ifacet[j] = facets[i][j];
    
        Scalar color;
        color[0] = rand() & 255;
        color[1] = rand() & 255;
        color[2] = rand() & 255;
        fillConvexPoly(img, ifacet, color, 8, 0);
        
        ifacets[0] = ifacet;
        polylines(img, ifacets, true, Scalar(), 1, CV_AA, 0);
        circle(img, centers[i], 3, Scalar(), -1, CV_AA, 0);
    }
}
Esempio n. 5
0
void AAM::displayTriangulation(Subdiv2D subdiv)
{
    Mat img=Mat::zeros(ImageWidth, ImageHeight, CV_8UC1);
    Scalar delaunay_color=Scalar(255, 0, 0);
    bool draw;
    vector<Vec6f> triangleList;
    subdiv.getTriangleList(triangleList);
    vector<Point> pt(3);

    for(int i = 0; i < triangleList.size(); i++)
    {
      Vec6f t = triangleList[i];

      pt[0] = Point(cvRound(t[0]), cvRound(t[1]));
      pt[1] = Point(cvRound(t[2]), cvRound(t[3]));
      pt[2] = Point(cvRound(t[4]), cvRound(t[5]));

      draw=true;

      for(int i=0;i<3;i++)
      {
         if(pt[i].x>img.rows||pt[i].y>img.cols||pt[i].x<0||pt[i].y<0)
            draw=false;
      }
      if (draw)
      {
         line(img, pt[0], pt[1], delaunay_color, 1);
         line(img, pt[1], pt[2], delaunay_color, 1);
         line(img, pt[2], pt[0], delaunay_color, 1);
      }
    }
    imshow("triangulacja", img);
}
Esempio n. 6
0
// Draw delaunay triangles
static void draw_delaunay( Mat& img, Subdiv2D& subdiv, Scalar delaunay_color )
{

    vector<Vec6f> triangleList;
    subdiv.getTriangleList(triangleList);
    vector<Point> pt(3);
    Size size = img.size();
    Rect rect(0,0, size.width, size.height);

    for( size_t i = 0; i < triangleList.size(); i++ )
    {
        Vec6f t = triangleList[i];
        pt[0] = Point(cvRound(t[0]), cvRound(t[1]));
        pt[1] = Point(cvRound(t[2]), cvRound(t[3]));
        pt[2] = Point(cvRound(t[4]), cvRound(t[5]));
        
        // Draw rectangles completely inside the image.
        if ( rect.contains(pt[0]) && rect.contains(pt[1]) && rect.contains(pt[2]))
        {
            line(img, pt[0], pt[1], delaunay_color, 1, CV_AA, 0);
            line(img, pt[1], pt[2], delaunay_color, 1, CV_AA, 0);
            line(img, pt[2], pt[0], delaunay_color, 1, CV_AA, 0);
        }
    }
}
Esempio n. 7
0
static void draw_subdiv( Mat& img, Subdiv2D& subdiv, Scalar delaunay_color )
{
    vector<Vec6f> triangleList;
    subdiv.getTriangleList(triangleList);
    vector<Point> pt(3);

    for( size_t i = 0; i < triangleList.size(); i++ )
    {
        Vec6f t = triangleList[i];
        pt[0] = Point(cvRound(t[0]), cvRound(t[1]));
        pt[1] = Point(cvRound(t[2]), cvRound(t[3]));
        pt[2] = Point(cvRound(t[4]), cvRound(t[5]));
		bool draw=true;
		for(int i=0;i<3;i++){
		 if(pt[i].x>img.cols||pt[i].y>img.rows||pt[i].x<0||pt[i].y<0)
			draw=false;
		}
		if (draw){
			line(img, pt[0], pt[1], delaunay_color, 1);
			line(img, pt[1], pt[2], delaunay_color, 1);
			line(img, pt[2], pt[0], delaunay_color, 1);
		}
    }
}
Esempio n. 8
0
/* ----------------------------------------------------------------
 *                   CALCULATE FINAL INTENSITIES
 *-----------------------------------------------------------------*/
void MainWindow::calculateFinalIntensities(Subdiv2D& subdiv){
    int nearestCell;

    for(int i=0; i<NUMBEROFLIGHTSOURCES; i++){
         voronoiIntensities[i][0] = 0;
         voronoiIntensities[i][1] = 0;
         voronoiIntensities[i][2] = 0;
         voronoiIntensities[i][3] = 0;
         finalVoronoiIntensities[i][0] = 0;
         finalVoronoiIntensities[i][1] = 0;
         finalVoronoiIntensities[i][2] = 0;
         finalVoronoiColors[i][0] = 0;
         finalVoronoiColors[i][1] = 0;
         finalVoronoiColors[i][2] = 0;
         averageTheta[i] = 0;
    }
    //red-green-blue.pfm  grace_lat_long.pfm
    const char* imageName = lightMapPathname.toStdString().c_str();
    unsigned int mapLatitude = 1024;
    unsigned int mapLongtitude = 512;
    unsigned int mapComponenets = 3;
    lightProbePFM = loadPFM(imageName, mapLatitude, mapLongtitude, mapComponenets);

    int i=0;

      for(int theta=0; theta<LONGTITUDE; theta++){
          for(int phi=0; phi<LATITUDE; phi++){
            for(int color=0; color<COLORCOMPONENTS; color++){

                Point2f fp(phi,theta);
                Point2f nearestCentroid;
                subdiv.findNearest(fp, &nearestCentroid);
                nearestCell = findNearestCell(nearestCentroid);

                //summing all theta of points from the same cell for the SOLID ANGLE
                float scaledTheta;
                float scalar = LONGTITUDE/PI;
                scaledTheta = theta/scalar;

                // change R
                if(color==0){
                    voronoiIntensities[nearestCell][0] += 1.0;
                    voronoiIntensities[nearestCell][1] += (lightProbePFM[i]*qSin(scaledTheta));
                }

                // change G
                else if(color==1){
                    voronoiIntensities[nearestCell][2] += (lightProbePFM[i]*qSin(scaledTheta));
                }

                // change B
                else if(color==2){
                    voronoiIntensities[nearestCell][3] += (lightProbePFM[i]*qSin(scaledTheta));
                }

                // next index
                i++;
            }
        }
    }

    float scalar;

    for(int i=0; i<NUMBEROFLIGHTSOURCES; i++){

        if(voronoiIntensities[i][0]!=0)
        {
            finalVoronoiIntensities[i][0] = voronoiIntensities[i][1]/voronoiIntensities[i][0];
            finalVoronoiIntensities[i][1] = voronoiIntensities[i][2]/voronoiIntensities[i][0];
            finalVoronoiIntensities[i][2] = voronoiIntensities[i][3]/voronoiIntensities[i][0];
        }

          // final cell intensity is the contrast added to the RF images
         finalCellIntensity[i] = (finalVoronoiIntensities[i][0]+finalVoronoiIntensities[i][1]+finalVoronoiIntensities[i][2])/3;

           //normalise values to get colour between 0-1
         scalar = (finalVoronoiIntensities[i][0] + finalVoronoiIntensities[i][1] + finalVoronoiIntensities[i][2])/15;

         finalVoronoiColors[i][0] = finalVoronoiIntensities[i][0]/scalar;
         finalVoronoiColors[i][1] = finalVoronoiIntensities[i][1]/scalar;
         finalVoronoiColors[i][2] = finalVoronoiIntensities[i][2]/scalar;

     }
}