Esempio n. 1
0
int Meshing::findBiggestPoly()
{
    if(mesh_.size()==1) return 0;
    double area = computeArea(mesh_.at(0));
    int id = 0;
    for(int i=1;i<mesh_.size();i++){
        double a = computeArea(mesh_.at(i));
        if(a>area){
            id = i;
            area = a;
        }
    }
    return id;
}
Esempio n. 2
0
ResultStatus CubeWorker::readAreaLines(const vector<string> &result, vector<string> &areaIds, vector<PArea> &areas)
{
	for (vector<string>::const_iterator i = result.begin(); i != result.end(); ++i) {
		vector<string> values;
		StringUtils::splitString(*i, &values, ';');

		// check for AREA string
		if (values[0] == "AREA" || values.size() < 6) {
			string areaId;
			PArea area;

			try {
				bool ok = computeArea(values, areaId, area);

				if (ok) {
					if (area->dimCount() > 0) {
						areaIds.push_back(areaId);
						areas.push_back(area);
					}
				} else {
					Logger::error << "error in worker response AREA: '" << *i << "'" << endl;
					return RESULT_FAILED;
				}
			} catch (...) {
				Logger::error << "error in worker response AREA: '" << *i << "'" << endl;
				return RESULT_FAILED;
			}
		} else {
			Logger::error << "error in worker response: '" << *i << "'" << endl;
			return RESULT_FAILED;
		}
	}

	return RESULT_OK;
}
Esempio n. 3
0
// Detailed constructor
CylinderPeteW::CylinderPeteW(const CirclePeteW &base, 
								const FractionPeteW &height) : 
								CirclePeteW(base), h(height) {
	computeArea();
	computeVolume();
	cout << "\nCalling CylinderPeteW() on " << *this;
}
Esempio n. 4
0
    RealType getArea() { 
      if(HaveArea_){
	return area_;
      }else{
	return computeArea();
      }
    }
Esempio n. 5
0
Mat computeWhiteMaskShadow(Mat& img)
 {
    // I = rgbFrame(:,:,1)>80 & rgbFrame(:,:,3)>80 | rgbFrame(:,:,3)>80 & abs(double(rgbFrame(:,:,1))-double(rgbFrame(:,:,3)))<20;
    // I = medfilt2(I,[20,20]);
	Mat BGRbands[3];  
	split(img,BGRbands);
	Mat maskB, maskG, maskR, maskD, maskT, mask;
	vector< vector<Point> > contours;
	threshold(BGRbands[0],maskB,90,255,THRESH_BINARY);
	threshold(BGRbands[1],maskG,90,255,THRESH_BINARY);
	threshold(BGRbands[2],maskR,90,255,THRESH_BINARY);
	absdiff(BGRbands[2],BGRbands[0],maskD);
	threshold(maskD,maskD,25,255,THRESH_BINARY);
	bitwise_not(maskD,maskD);
	bitwise_and(maskR,maskD,maskD);
	bitwise_and(maskB,maskR,maskT);
	bitwise_or(maskD,maskT,maskT);

	findContours(maskT, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
	vector<double> areas = computeArea(contours);
	for(int j = areas.size()-1; j>=0; j--){
		if(areas.at(j)>MAX_AREA || areas.at(j)<MIN_AREA )
			contours.erase(contours.begin()+j);
	}
	Mat out = Mat::zeros(Size(img.cols,img.rows), CV_8U);
	for (int idx = 0; idx < contours.size(); idx++)
		drawContours(out, contours, idx, Scalar(255,255,255), CV_FILLED, 8);
	return out;
 }
Esempio n. 6
0
int main(){
	int area = computeArea(-1500000001, 0, -1500000000, 1, 1500000000, 0, 1500000001, 1);
	printf("area:%d\n",area);

	int r=11/4;
	printf("r:%d\n",r);
	puts("end of app");
}
Esempio n. 7
0
File: main.c Progetto: f2008700/BITS
int main()
{
	Rect Re1, Re2, Re3;
	Rect RA[100];
	int i,N;
	/* Create Re1 and Re2 */
	Re1=createRect();
	Re2=createRect();
	printf("\nRe1 after creation\n");
	printRect(Re1);
	printf("\nRe2 after creation\n");
	printRect(Re2);

	/* get data from user */
	Re1=getData(Re1);
	Re2=getData(Re2);
	printf("\nRe1 after getData\n");
	printRect(Re1);
	printf("\nRe2 after getData\n");
	printRect(Re2);

	/* isSquare */
	if(isSquare(Re1))
		printf("\nThe Rectangle R1 is SQUARE\n");
	else
		printf("\nThe Rectangle R1 is NOT SQUARE\n");

	/* isEqual */
	if(isEqual(Re1,Re2))
		printf("\nThe Rectangle R1 is EQUAL to R2\n");
	else
		printf("\nThe Rectangle R1 is NOT EQUAL to R2\n");

	/* compute Area */
	printf("\nThe Area of Rectangle R1 is %d\n",computeArea(Re1));

	/* Copy Re1 to Re3 */
	Re3=Re1;
	printf("\nRe1 details\n");
	printRect(Re1);
	printf("\nRe3 details after copying Re1\n");
	printRect(Re3);

/* Create RA */
	printf("Enter the Number of Elements in Rect Array\n");
	scanf("%d",&N);
	for(i=0;i<N;i++)
		RA[i]=createRect();
	
/* get data */
	for(i=0;i<N;i++)
		RA[i]=getData(RA[i]);
/* Find the Rectangle with Max Area */
	i=findMaxArea(RA,N);
	printf("\nMax Area Rect is in %d position, its length is %d and its width is %d\n",i,RA[i].length,RA[i].width);
	return 0;
}
Esempio n. 8
0
void
MatlabExportModule :: doOutput(TimeStep *tStep)
{
    FILE *FID;
    FID = giveOutputStream(tStep);

    fprintf( FID, "function [mesh area data specials]=%s\n\n", functionname.c_str() );

    if ( exportMesh ) {
        doOutputMesh(tStep, FID);
    } else {
        fprintf(FID, "\tmesh=[];\n");
    }

    if ( exportData ) {
        doOutputData(tStep, FID);
    } else {
        fprintf(FID, "\tdata=[];\n");
    }

    if ( exportArea ) {
        computeArea();
        fprintf(FID, "\tarea.xmax=%f;\n", xmax);
        fprintf(FID, "\tarea.xmin=%f;\n", xmin);
        fprintf(FID, "\tarea.ymax=%f;\n", ymax);
        fprintf(FID, "\tarea.ymin=%f;\n", ymin);
        fprintf(FID, "\tarea.area=%f;\n", Area);
    } else {
        fprintf(FID, "\tarea=[];\n");
    }

    if ( exportSpecials ) {
        if ( !exportArea ) {
            computeArea();
        }

        doOutputSpecials(tStep, FID);
    } else {
        fprintf(FID, "\tspecials=[];\n");
    }

    fprintf(FID, "\nend\n");
    fclose(FID);
}
Esempio n. 9
0
int main(void)
{
    struct circle instance;
    printf ("Enter the diameter: ");
    scanf ("%f", &instance.diameter);

    instance = computeArea(instance);

    printf ("The area of the circle is: %f", instance.area);
}
Esempio n. 10
0
int main(int argc, char **argv) 
{
	int area = 0;

	area = computeArea(-2,-2,2,2,-2,-2,2,2);
	//area = computeArea(-3,0,3,4,0,-1,9,2);
	//area = computeArea(0,0,0,0, -1,-1,1,1);
	printf("area = %d\n", area);

	return 0;
}
Esempio n. 11
0
int ComputeNormalFlow(const xs::Reach& reach, double depth, double g, double kn, double& Q)
{
    auto x = reach.getXs();

    double n = reach.getRoughness();
    double A = x->computeArea(depth);
    double P = x->computeWettedPerimiter(depth);

    Q = kn / n * std::pow(A / P, TWOTHIRDS) * std::sqrt(reach.getSlope()) * A;

    return 0;
}
Esempio n. 12
0
/*
Mat bwareaopen(Mat& img, int size)
 {
     CBlobResult blobs;
     blobs = CBlobResult( img ,Mat(),4);
     blobs.Filter( blobs, B_INCLUDE, CBlobGetLength(), B_GREATER, size );

     Mat newimg(img.size(),img.type());
     newimg.setTo(0);
     for(int i=0;i<blobs.GetNumBlobs();i++)
     {
         blobs.GetBlob(i)->FillBlob(newimg,CV_RGB(255,255,255),0,0,true);
     }
     return newimg;
 }

Mat removeUseless(Mat& img, int low, int hight)
 {
     CBlobResult blobs;
     blobs = CBlobResult( img ,Mat(),4);
	 blobs.Filter( blobs, B_OUTSIDE, CBlobGetLength(), low, hight );

     Mat newimg(img.size(),img.type());
     newimg.setTo(0);
     for(int i=0;i<blobs.GetNumBlobs();i++)
     {
         blobs.GetBlob(i)->FillBlob(newimg,CV_RGB(255,255,255),0,0,true);
     }
     return newimg;
 }
 */
Mat computeWhiteMaskLight(Mat& input){
	Mat img, gray;
	input.clone().convertTo(img,CV_64F);
	Mat BGRbands[3] = {Mat::zeros(img.size(), CV_64F), Mat::zeros(img.size(), CV_64F),Mat::zeros(img.size(), CV_64F)};  
	Mat I1 = Mat::zeros(img.size(), CV_64F);
	Mat I2 = Mat::zeros(img.size(), CV_64F);
	Mat I3 = Mat::zeros(img.size(), CV_64F);
	Mat Id1 = Mat::zeros(img.size(), CV_64F);
	Mat Id2 = Mat::zeros(img.size(), CV_64F);
	Mat Id3 = Mat::zeros(img.size(), CV_64F);
	Mat I = Mat::zeros(img.size(), CV_64F);
	Mat mask = Mat::zeros(img.size(), CV_8U);
	vector< vector<Point> > contours;
	Mat mask2 = Mat::zeros(img.size(), CV_8U);
	split(img,BGRbands);
	I1 = BGRbands[0]-BGRbands[1];
	I1 = I1.mul(I1);
	I2 = BGRbands[0]-BGRbands[2];
	I2 = I2.mul(I2);
	I3 = BGRbands[1]-BGRbands[2];
	I3 = I3.mul(I3);
	Id1 = I1-I2;
	Id2 = I1-I3;
	Id3 = I3-I2;
	Id1 = Id1.mul(Id1);
	Id2 = Id2.mul(Id2);
	Id3 = Id3.mul(Id3);
	I = Id1+Id2+Id3;
	sqrt(I,I);
	sqrt(I,I);
	I.convertTo(mask,CV_8U);
	threshold(mask,mask,50,255,THRESH_BINARY_INV);
	Mat d = detectShadows(input);
	bitwise_and(mask,d,mask);
	cvtColor(input,gray,CV_BGR2GRAY);
	threshold(gray,mask2,160,255,THRESH_BINARY);
	mask = mask+mask2;
	medianBlur(mask,mask,9);
	findContours(mask, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
	vector<double> areas = computeArea(contours);
	for(int j = areas.size()-1; j>=0; j--){
		if(areas.at(j)>MAX_AREA || areas.at(j)<MIN_AREA ) // 10000 400
			contours.erase(contours.begin()+j);
	}
	Mat out = Mat::zeros(Size(img.cols,img.rows), CV_8U);
	for (int idx = 0; idx < contours.size(); idx++)
		drawContours(out, contours, idx, Scalar(255,255,255), CV_FILLED, 8);
	return out;
}
void main(){

int i,n;
scanf("%d",&n);
Rect r[n];
for (i=0; i<n; i++){

r[i]=createRect();
r[i]=getData(r[i]);
printRect(r[i]);
printf("\n");
printf("Is this rectange a Square?\n(1 for YES, 0 for NO): %d",isSquare(r[i]));
printf("\narea is %d",computeArea(r[i]));
}

int maxarea;
maxarea=findMaxArea(r,n);
printf("\n the max area is %d\n",maxarea);

}
Esempio n. 14
0
void main(int argc, char * argv[]) {

  if (argc != 9) {
    printf("Please specify the correct arguments.\n");
    return;
  }

  int area = computeArea(
                  atoi(argv[1]),
                  atoi(argv[2]),
                  atoi(argv[3]),
                  atoi(argv[4]),
                  atoi(argv[5]),
                  atoi(argv[6]),
                  atoi(argv[7]),
                  atoi(argv[8])
                  );
  printf ("Area covered by these two rectangles is %d.\n", area);

}
Esempio n. 15
0
/*
 * compute the area of the polygon poly.
 * the vertices must be "sorted" clockwise.
 * if poly is not covex, then it's triangles must be set.
 * return the area of the poly (in addition of setting the area field in poly)
 */
float computeArea(Poly *poly) {
    float area=0;
    Vertex *v1, *v2;
    int i;
    if(poly == NULL) {
        return -1;
    }
    // check if triangulation set, in which case set the area of each triangle and get the sum.
    if(poly->num_triangles>0) {
        for(area=0, i=0; i<poly->num_triangles; i++) {
            area+=computeArea(poly->triangles+i);
        }
        poly->area=area;
        return area;
    }
    for(area=0, i=0; i<poly->num_verts; i++) {
        v1=poly->verts+i;
        v2=poly->verts+((i+1)%poly->num_verts);
        area+=v2->x*v1->y-v1->x*v2->y;
    }
    area/=2;
    poly->area=area;
    return area;
}
Esempio n. 16
0
int main(){
    int result = computeArea(-3,0,3,4,0,-1,9,2);
    printf("%d\n",result);
    return 0;
}
Esempio n. 17
0
void detect2(Mat img, vector<Mat>& regionsOfInterest,vector<Blob>& blobs){
/*	Mat blurred; 
	GaussianBlur(img, blurred, Size(), _SharpSigma, _SharpSigma);
	Mat lowContrastMask = abs(img - blurred) < _SharpThreshold;
	Mat sharpened = img*(1+_SharpAmount) + blurred*(-_SharpAmount);
	img.copyTo(sharpened, lowContrastMask);
	sharpened.copyTo(img);*/
	/*************INIZIALIZZAZIONI**********/
	Mat gray; 
	Mat out = Mat::zeros(Size(WIDTH,HEIGH), CV_8U);
	Mat masked = Mat::zeros(Size(WIDTH,HEIGH), CV_8U);
	Mat morph = Mat::zeros(Size(WIDTH,HEIGH), CV_8U);
	Mat bwmorph = Mat::zeros(Size(WIDTH,HEIGH), CV_8U);
	Mat cont = Mat::zeros(Size(WIDTH,HEIGH), CV_8U);
	Mat maskHSV = Mat::zeros(Size(WIDTH,HEIGH), CV_8U);
	Mat whiteMaskMasked = Mat::zeros(Size(WIDTH,HEIGH), CV_8U);
	Mat whiteMaskOrig = Mat::zeros(Size(WIDTH,HEIGH), CV_8U);
	Mat Bands[3];
	Mat noBackMask = Mat::zeros(Size(WIDTH,HEIGH), CV_8U);
	Mat kernelEr = getStructuringElement(MORPH_ELLIPSE,Size(5,5));
	Mat thMasked; Mat thOrig; Mat bwOrig; Mat bwNoBackMask;
	Mat kernelOp = getStructuringElement(MORPH_ELLIPSE,Size(13,13));
	vector<Mat> BGRbands;  split(img,BGRbands);
	vector< vector<Point> > contours;
	/***************************************/
	/*cvtColor(img,gray,CV_BGR2GRAY);
	gray = (gray!=0);
	imshow("gray",gray);*/
	/*Rimozione Ombre e Background*/
//	masked = applyMaskBandByBand(maskHSV,BGRbands); split(masked,BGRbands);
	
	/*Rimozione sfondo e sogliatura per videnziare esclusivamente ciò che è bianco*/
	noBackMask = backgroundRemoval(img);
	masked = applyMaskBandByBand(noBackMask,BGRbands);
/*
	whiteMaskOrig = computeWhiteMaskLight(img);
	whiteMaskOrig = whiteMaskOrig + computeWhiteMaskShadow(img);

	whiteMaskMasked = computeWhiteMaskLight(masked);
	whiteMaskMasked = whiteMaskMasked + computeWhiteMaskShadow(masked);
*/
	CBlobResult blobsRs;
	blobsRs = computeWhiteMaskOtsu(img, img, blobsRs, img.rows*img.cols, img.rows*img.cols, 0.8, 0.8, 30, 200, 0);
	
	//Mat newimg(img.size(),img.type());
    whiteMaskOrig.setTo(0);
    for(int i=0;i<blobsRs.GetNumBlobs();i++){
			 blobsRs.GetBlob(i)->FillBlob(whiteMaskOrig,CV_RGB(255,255,255),0,0,true);
    }

	threshold(masked,whiteMaskMasked,0,255,THRESH_BINARY);
	cvtColor(whiteMaskMasked,whiteMaskMasked,CV_BGR2GRAY);
		cout << whiteMaskMasked.type() << " " << whiteMaskOrig.type() << endl;
	bitwise_or(whiteMaskMasked,whiteMaskOrig,thOrig);
	masked = applyMaskBandByBand(thOrig,BGRbands);
#if DO_MORPH
	/*Operazioni morfologiche per poter riempire i buchi e rimuovere i bordi frastagliati*/
	dilate(masked,morph,kernelEr);
	erode(morph,morph,kernelEr);
	
	erode(morph,morph,kernelOp);
	dilate(morph,morph,kernelOp);
#else
	morph = masked;
#endif
	/*Ricerca componenti connesse e rimozione in base all'area*/
	cvtColor(morph,bwmorph,CV_BGR2GRAY);
	findContours(bwmorph, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
	vector<double> areas = computeArea(contours);
	for(int j = areas.size()-1; j>=0; j--){
		if(areas.at(j)>MAX_AREA || areas.at(j)<MIN_AREA )
			contours.erase(contours.begin()+j);
	}

	/*Calcolo Bounding Rectangle a partire dall'immagine con componenti connesse di interesse*/
	 vector<Rect> boundRect( contours.size() );
	 vector<vector<Point> > contours_poly( contours.size() );
	 vector<Point2f>center( contours.size() ); 
	 vector<float>radius( contours.size() );
	 /*Costruzione immagine finale ed estrazione regioni di interesse*/
	for (int idx = 0; idx < contours.size(); idx++){
		Blob b; b.originalImage = &img;
		Scalar color(255);
		approxPolyDP( Mat(contours[idx]), contours_poly[idx], 3, true );
		boundRect[idx] = boundingRect( Mat(contours_poly[idx]) );
		
		minEnclosingCircle( (Mat)contours_poly[idx], center[idx], radius[idx] );
	//	Rect tmpRect(center[idx].x-boundRect[idx].width/2,center[idx].y-boundRect[idx].height/2,boundRect[idx].width,boundRect[idx].height);
		Rect tmpRect(center[idx].x-radius[idx],center[idx].y-radius[idx],radius[idx]*2,radius[idx]*2);
		//Rect tmpRect = boundRect[idx];
		Rect toPrint; 
		tmpRect += Size(tmpRect.width*RECT_AUGMENT ,tmpRect.height*RECT_AUGMENT);			  // Aumenta area di RECT_ARGUMENT
		tmpRect -= Point((tmpRect.width*RECT_AUGMENT)/2 , (tmpRect.height*RECT_AUGMENT)/2 ); // Ricentra il rettangolo
		
		drawContours(cont, contours, idx, color, CV_FILLED, 8);
		if(tmpRect.x>0 && tmpRect.y>0 && tmpRect.x+tmpRect.width < morph.cols && tmpRect.y+tmpRect.height < morph.rows){ //Se il nuovo rettangolo allargato
																														// NON esce fuori dall'immagine, accettalo
			regionsOfInterest.push_back(masked(tmpRect));
			b.cuttedWithBack = img(tmpRect);
			b.cuttedImages = masked(tmpRect);
			b.blobsImage = cont(tmpRect);
			b.rectangles = tmpRect;
			toPrint = tmpRect;
		}
		else{
			toPrint = boundRect[idx];
			regionsOfInterest.push_back(masked(boundRect[idx]));
			b.cuttedImages = masked(boundRect[idx]);
			b.cuttedWithBack = img(boundRect[idx]);
			b.rectangles = boundRect[idx];
			b.blobsImage = cont(boundRect[idx]);
		}
		Point centroid = computeCentroid(contours[idx]);
		b.centroid = centroid;
		b.area = contourArea(contours[idx]);
		b.distance = HEIGH - centroid.y;
		
		/*rectangle( cont, toPrint.tl(), toPrint.br(), color, 2, 8, 0 );
		circle( cont, center[idx], (int)radius[idx], color, 2, 8, 0 );*/
		blobs.push_back(b);
	}
	
	//out = out+cont;
	bitwise_xor(out,cont,out);
	
	/*imshow("img",img);
	imshow("out",out);
	waitKey(0);*/
}
Esempio n. 18
0
File: text.cpp Progetto: DCayee/iDSL
int main(int argc, char **argv){

  if(argc != 9){
    printf("wrong # args\n");
    printf("inputfile outDir(./lol/) invert (0 or 1) k*1000 windowRadius gaussPyramidThresh(>= survive) finalMixThresh(>= survive) writeDebugImages(0 or 1)\n");
  }

  int width, height, channels;
  unsigned char *data;
  char *dir = argv[2];
  int inv = atoi(argv[3]);
  float k = float(atoi(argv[4]))/1000.f;
  int window = atoi(argv[5]);
  int gaussPyramidThresh = atoi(argv[6]);
  int finalMixThresh = atoi(argv[7]);
  bool debugImages = atoi(argv[8]);

  bool res = loadImage(argv[1], &width, &height, &channels, &data);

  if(!res){
    printf("error reading image\n");
    return 1;
  }

  printf("start\n");

  // to grayscale
  unsigned char *dataGray = new unsigned char[width*height];
  toGrayscale(width,height,data,dataGray);

  // build SAT
  unsigned int *sat = new unsigned int[width*height];
  float * satSquared = new float[width*height];
  SAT(dataGray,sat,width,height);
  SATSquared(dataGray,satSquared,width,height);

  // do thresh
  thresh(dataGray, sat, satSquared, width, height, k, window);
  if(inv){invert(dataGray,width,height);}

  char filename[200];
  sprintf(filename,"%sresRaw.bmp",dir);
  if(debugImages){saveImage(filename, width, height, 1, dataGray);}

  unsigned char ** pyramid=NULL;
  makePyramid(dataGray, &pyramid, pyramidLevels, gaussPyramidThresh, width,height);

  for(int L=0; L<pyramidLevels; L++){
    char filename[200];
    sprintf(filename,"%sres_raw_%d.bmp",dir,L);
    if(debugImages){saveImage(filename,width/pow(2,L),height/pow(2,L),1,pyramid[L]);}
  }


  // label
  int vecSizeY=32;
  int vecSizeX=128;

  unsigned char *dist=new unsigned char[width*height];
  unsigned short *labels = new unsigned short[width*height];
  unsigned short area[maxLabels];
  unsigned char *reason = new unsigned char[width*height];
  unsigned char *tile = new unsigned char[width*height];
  
  for(int l = pyramidLevels-1; l>=0; l--){
    int lw = width/pow(2,l);
    int lh = height/pow(2,l);
    
    // write out debug data
    char filename[200];
    sprintf(filename,"%sres_%dp2.bmp",dir,l);
    if(debugImages){saveImage(filename, lw,lh, 1, pyramid[l]);}
  }

  for(int L = pyramidLevels-1; L>=0; L--){
    int lw = width/pow(2,L);
    int lh = height/pow(2,L);

    // clear out labels so that we can do progressive cleanup passes
    for(int i=0; i<lw*lh; i++){reason[i]=0;labels[i]=0;}

    unsigned short firstId = 1;

    int tileId = 0;

    int minArea = 6;
    if(L<2){minArea = 30;}

    int nTilesX = ceil((float)lw/(float)vecSizeX);
    int nTilesY = ceil((float)lh/(float)vecSizeY);

    int lastFixup = 0;

    for(int by=0; by<nTilesY; by++){
      int endY = (by+1)*vecSizeY;
      if(endY>lh){endY=lh;}
      
      bool fixupRanThisRow = false;

      for(int bx=0; bx<nTilesX; bx++){

	int endX = (bx+1)*vecSizeX;
	if(endX>lw){endX=lw;}

	label(pyramid[L],labels,reason,area,lw,lh,minArea,vecSizeX*bx,endX,vecSizeY*by,endY,maxLabels);
	unsigned short lastId=0;
	if(!condenseLabels(labels,area,firstId,&lastId,lw,lh,vecSizeX*bx,endX,vecSizeY*by,endY,maxLabels)){
	  printf("Error: ran out of labels!\n");
	  goto writeout;  // an exception occured
	}
	firstId=lastId+1;
	//printf("ML %d\n",(int)firstId);
	
	// for debugging
	for(int x=vecSizeX*bx; x<endX; x++){
	  for(int y=vecSizeY*by; y<endY; y++){
	    tile[x+y*lw]=tileId;
	  }
	}

	tileId++;

	if(firstId > (maxLabels*4)/5 && !fixupRanThisRow){
	  labelProp(labels,area,lw,lh,0,lw,0,endY,maxLabels);
	  filter(pyramid,L,reason,labels,minArea,lw,lh,width,0,lw,lastFixup,endY,maxLabels);
	  computeArea(labels,area,lw,lh,0,lw,0,endY,maxLabels);
	  condenseLabels(labels,area,1,&firstId,lw,lh,0,lw,0,endY,maxLabels);
	  firstId++;
	  printf("fixup TL %d\n",firstId);
	  
	  lastFixup = (by+1)*vecSizeY;
	  fixupRanThisRow=true;
	}
	
      }

    }
    
    // fix labels across region boundries
    labelProp(labels,area,lw,lh,0,lw,0,lh,maxLabels);
    computeArea(labels,area,lw,lh,0,lw,0,lh,maxLabels);
    condenseLabels(labels,area,1,&firstId,lw,lh,0,lw,0,lh,maxLabels);
    //printf("TL %d\n",firstId);
    
    distanceTransform(pyramid[L],dist,0,lw,lh);
    
    filter(pyramid,L,reason,labels,minArea,lw,lh,width,0,lw,0,lh,maxLabels);

    // now what's left "must" be text, so delete it from other pyrmid levels and save it
    
    writeout:
    // write out debug data
    char filename[200];
    if(debugImages){
      sprintf(filename,"%sL_%d.bmp",dir,L);
      saveImage(filename, lw,lh, labels);
      sprintf(filename,"%sD_%d.bmp",dir,L);
      saveImage(filename, lw,lh, 1, dist);
      sprintf(filename,"%sres_%d.bmp",dir,L);
      saveImage(filename, lw,lh, 1, pyramid[L]);
      sprintf(filename,"%sR_%d.bmp",dir,L);
      saveImage(filename, lw,lh, 1, reason);
      sprintf(filename,"%sT_%d.bmp",dir,L);
      saveImage(filename, lw,lh, 1, tile);
    }

    if(L==pyramidLevels-1){
      for(int l = 2; l>=0; l--){
	int lw = width/pow(2,l);
	int lh = height/pow(2,l);
	
	// write out debug data
	char filename[200];
	sprintf(filename,"%sres_%dp.bmp",dir,l);
	if(debugImages){saveImage(filename, lw,lh, 1, pyramid[l]);}
      }
    }
    
  }
  
  for(int y=0; y<height; y++){
    for(int x=0; x<width; x++){
      int count=0;
      for(int l=0; l<pyramidLevels; l++){
	int lx = x/pow(2,l);
	int ly = y/pow(2,l);

	int lw = width/pow(2,l);

	if(pyramid[l][lx+ly*lw]){count++;}
      }
      if(count<finalMixThresh){
	dataGray[x+y*width]=0;
      }
    }
  }

  sprintf(filename,"%sres.bmp",dir);
  saveImage(filename, width, height, 1, dataGray);

  return 0;
}
Esempio n. 19
0
File: text.cpp Progetto: DCayee/iDSL
void filter(
  unsigned char **pyramid, 
  int L, // pyramid level
  unsigned char *reason,
  unsigned short *labels, 
  int minArea,
  int width, int height,
  int owidth,
  int startX, int endX,
  int startY, int endY,
  int maxLabels){

  unsigned char *in = pyramid[L];

  unsigned short area[maxLabels];
  computeArea(labels,area,width,height,startX,endX,startY,endY,maxLabels);

  unsigned short l[maxLabels];
  unsigned short r[maxLabels];
  unsigned short t[maxLabels];
  unsigned short b[maxLabels];
  computeBB(labels,l,r,t,b,width,height,startX,endX,startY,endY,maxLabels);

  bool kill[maxLabels];
  unsigned char kreason[maxLabels];

  for(int i=0; i<maxLabels; i++){
    if(area[i]>0 && i>0){ // is this region still there?

      // ratio
      int w = (r[i]-l[i])+1;
      int h = (t[i]-b[i])+1;
      float ratio = float(w)/float(h);
      
      //solidity
      float solidity = float(area[i])/float(w*h);
      
      //printf("%d %f %d %f\n",i,ratio,area[i],solidity);
      
      float areaPercent = float(area[i])/float(width*height);
      
      if(ratio < 0.1f || ratio > 2.f){
	kill[i] = true;
	kreason[i]=50;
      }else if(area[i]<minArea){
	kill[i] = true;
	kreason[i]=100;
      }else if(areaPercent>0.2f){
	kill[i] = true;
	kreason[i]=150;
      }else if(solidity < 0.20f){
	kill[i] = true;
	kreason[i]=200;
      }else{
	kill[i]=false;
	kreason[i]=0;
      }
      
    }else{
      kill[i] = false;
      kreason[i]=0;
    }
  }


  for(int x=startX; x<endX; x++){
    for(int y=startY; y<endY; y++){
      if(kill[labels[x+y*width]]){
	in[x+y*width] = 0;
	unsigned char r = kreason[labels[x+y*width]];
	reason[x+y*width]=r;
	labels[x+y*width]=0;

	if(r==150){
	  int sX = x*2;
	  int eX = x*2+2;
	  int sY = y*2;
	  int eY = y*2+2;

	  for(int l=L-1; l>=0; l--){
	    int lw=owidth/pow(2,l);

	    for(int i=sX; i<eX; i++){
	      for(int j=sY; j<eY; j++){
		pyramid[l][i+j*lw]=0;
	      }
	    }
	    sX*=2;
	    sY*=2;
	    eX*=2;
	    eY*=2;
	  }
	}

      }
    }
  }

  // keep area accurate
  for(int i=0; i<maxLabels;i++){
    if(kill[i]){area[i]=0;}
  }
}
Esempio n. 20
0
int main()
{
	int A = -2,B = -2,C = 2,D = 2,E = -2,F = -2,G = 2,H = 2;
	int area = computeArea( A, B, C, D, E, F, G, H);
	printf("area is :%d\n",area);
}
Esempio n. 21
0
int Mymain()
{
    cout << computeArea(-3, 0, 3, 4, 0, -1, 9, 2) << endl;
    return 0;
}
Esempio n. 22
0
void
MatlabExportModule :: doOutput(TimeStep *tStep, bool forcedOutput)
{
    if ( !( testTimeStepOutput(tStep) || forcedOutput ) ) {
        return;
    }


    int nelem = this->elList.giveSize();
    if ( nelem == 0 ) { // no list given, export all elements
        this->elList.enumerate(this->emodel->giveDomain(1)->giveNumberOfElements());
    }

    FILE *FID;
    FID = giveOutputStream(tStep);
    Domain *domain  = emodel->giveDomain(1);
    ndim=domain->giveNumberOfSpatialDimensions();

    // Output header
    fprintf( FID, "%%%% OOFEM generated export file \n");
    fprintf( FID, "%% Output for time %f\n", tStep->giveTargetTime() );


    fprintf( FID, "function [mesh area data specials ReactionForces IntegrationPointFields]=%s\n\n", functionname.c_str() );

    if ( exportMesh ) {
        doOutputMesh(tStep, FID);
    } else {
        fprintf(FID, "\tmesh=[];\n");
    }

    if ( exportData ) {
        doOutputData(tStep, FID);
    } else {
        fprintf(FID, "\tdata=[];\n");
    }

    if ( exportArea ) {
        computeArea(tStep);
        fprintf(FID, "\tarea.xmax=%f;\n", smax.at(0));
        fprintf(FID, "\tarea.xmin=%f;\n", smin.at(0));
        fprintf(FID, "\tarea.ymax=%f;\n", smax.at(1));
        fprintf(FID, "\tarea.ymin=%f;\n", smin.at(1));
        if ( ndim == 2 ) {
            fprintf(FID, "\tarea.area=%f;\n", Area);
            fprintf(FID, "\tvolume=[];\n");
        } else {
            fprintf(FID, "\tarea.zmax=%f;\n", smax.at(2));
            fprintf(FID, "\tarea.zmin=%f;\n", smin.at(2));
            fprintf(FID, "\tarea.area=[];\n");
            fprintf(FID, "\tarea.volume=%f;\n", Volume);
            for (size_t i=0; i<this->partName.size(); i++) {
                fprintf(FID, "\tarea.volume_%s=%f;\n", partName.at(i).c_str(), partVolume.at(i));
            }
        }
    } else {
        fprintf(FID, "\tarea.area=[];\n");
        fprintf(FID, "\tarea.volume=[];\n");
    }

    if ( exportSpecials ) {
        if ( !exportArea ) {
            computeArea(tStep);
        }

        doOutputSpecials(tStep, FID);
    } else {
        fprintf(FID, "\tspecials=[];\n");
    }

    // Reaction forces
    if ( exportReactionForces ) {
        doOutputReactionForces(tStep, FID);
    } else {
        fprintf(FID, "\tReactionForces=[];\n");
    }

    // Internal variables in integration points
    if ( exportIntegrationPointFields ) {
        doOutputIntegrationPointFields(tStep, FID);
    } else {
        fprintf(FID, "\tIntegrationPointFields=[];\n");
    }

    // Homogenized quantities
    if ( exportHomogenizeIST ) {
        doOutputHomogenizeDofIDs(tStep, FID);
    }

    fprintf(FID, "\nend\n");
    fclose(FID);
}
Esempio n. 23
0
void main(void)
{
    int i = computeArea(-2, -2, 2, 2, -2, -2, 2, 2);
}
Esempio n. 24
0
int main() {
	printf("%d\n", computeArea(-2, -2, 2, 2, 3, 3, 4, 4));
}
Esempio n. 25
0
// Setter
void CylinderPeteW::setHeight(const FractionPeteW &height) {
	h = (height > 0) ? height : -height;
	computeArea();
	computeVolume();
}
Esempio n. 26
0
/*
 * returns the area of the polygons poly1 and poly2.
 * the normals and dists fields of poly1 and poly2 must be set beforehand.
 */
float intersectionArea(Poly *poly1, Poly *poly2) {
    Poly poly;
    Poly *p1, *p2;
    Poly *pp1, *pp2;
    Vector *normals, *n1, *n2, *n_end;
    Vertex *v;
    Point pt;
    float *dists, *angles;
    int num_p1, num_p2, num_dists, verts_allocated;
    float area, det, tmp;
    int i, j, k;
    if(poly1==NULL || poly2==NULL) {
        return -1;
    }
    // set array of polynoms representing poly1
    if(poly1->num_triangles==0) {
        p1=poly1;
        num_p1=1;
    }
    else {
        p1=poly1->triangles;
        num_p1=poly1->num_triangles;
    }
    // set array of polynoms representing poly2
    if(poly2->num_triangles==0) {
        p2=poly2;
        num_p2=1;
    }
    else {
        p2=poly2->triangles;
        num_p2=poly2->num_triangles;
    }
    verts_allocated=4;
    poly.num_verts=0;
    poly.verts=(Vertex*)calloc(verts_allocated, sizeof(Vertex));
    poly.area=0;
    poly.num_triangles=0;
    poly.triangles=NULL;
    poly.dists=NULL;
    poly.normals=NULL;
    num_dists=0;
    normals=NULL;
    dists=NULL;
    angles=(float*)calloc(verts_allocated, sizeof(float));
    area=0;
    // check intersection of each pair of polygons
    for(pp1=p1; pp1<p1+num_p1; pp1++) {
        for(pp2=p2; pp2<p2+num_p2; pp2++) {
            // make set of normals and distances.
            if(pp1->num_verts+pp2->num_verts>num_dists) {
                num_dists=pp1->num_verts+pp2->num_verts;
                normals=(Vector*)realloc(normals, num_dists*sizeof(Vector));
                dists=(float*)realloc(dists, num_dists*sizeof(float));
            }
            for(i=0; i<pp1->num_verts; i++) {
                normals[i].x=pp1->normals[i].x;
                normals[i].y=pp1->normals[i].y;
                dists[i]=pp1->dists[i];
            }
            for(i=0, j=pp1->num_verts; i<pp2->num_verts; i++, j++) {
                normals[j].x=pp2->normals[i].x;
                normals[j].y=pp2->normals[i].y;
                dists[j]=pp2->dists[i];
            }
            // for each pair of lines, compute intersection
            n_end=normals+pp1->num_verts+pp2->num_verts;
            poly.num_verts=0;
            for(n1=normals, i=0; n1<n_end-1; n1++, i++) {
                for(n2=n1+1, j=i+1; n2<n_end; n2++, j++) {
                    det=n1->x*n2->y-n2->x*n1->y;
                    if(fabs(det)<SMALL)
                        continue;
                    pt.x=(n2->y*dists[i]-n1->y*dists[j])/det;
                    pt.y=(n1->x*dists[j]-n2->x*dists[i])/det;
                    // check if intersection is inside pp1 and pp2
                    for(k=0; k<pp1->num_verts; k++) {
                        if((pt.x*pp1->normals[k].x+pt.y*pp1->normals[k].y)>(pp1->dists[k]+10*SMALL))
                            break;
                    }
                    if(k<pp1->num_verts)
                        continue;
                    for(k=0; k<pp2->num_verts; k++) {
                        if((pt.x*pp2->normals[k].x+pt.y*pp2->normals[k].y)>(pp2->dists[k]+10*SMALL))
                            break;
                    }
                    if(k<pp2->num_verts)
                        continue;
                    // point pt is inside both pp1 and pp2: this point is a vertex.
                    if(poly.num_verts>=verts_allocated) {
                        verts_allocated*=2;
                        poly.verts=(Vertex*)realloc(poly.verts, verts_allocated*sizeof(Vertex));
                        angles=(float*)realloc(angles, verts_allocated*sizeof(float));
                    }
                    poly.verts[poly.num_verts].x=pt.x;
                    poly.verts[poly.num_verts].y=pt.y;
                    poly.num_verts++;
                }
            }
            // order vertices clockwise (get point inside poly, compute bunch of angles and sort them)
            pt.x=pt.y=0;
            for(v=poly.verts; v<poly.verts+poly.num_verts; v++) {
                pt.x+=v->x;
                pt.y+=v->y;
            }
            pt.x/=poly.num_verts;
            pt.y/=poly.num_verts;
            for(i=0, v=poly.verts; i<poly.num_verts; i++, v++) {
                angles[i]=(float)acos((v->x-pt.x)/sqrt((v->x-pt.x)*(v->x-pt.x)+(v->y-pt.y)*(v->y-pt.y)));
                if((v->y-pt.y)<0)
                    angles[i]=-angles[i];
            }
            for(i=0; i<poly.num_verts-1; i++) {
                for(j=i+1; j<poly.num_verts; j++) {
                    if(angles[i]<angles[j]) {
                        tmp=angles[i];
                        angles[i]=angles[j];
                        angles[j]=tmp;
                        tmp=poly.verts[i].x;
                        poly.verts[i].x=poly.verts[j].x;
                        poly.verts[j].x=tmp;
                        tmp=poly.verts[i].y;
                        poly.verts[i].y=poly.verts[j].y;
                        poly.verts[j].y=tmp;
                    }
                }
            }
            area+=computeArea(&poly);
        }
    }
    free(poly.verts);
    free(angles);
    free(normals);
    free(dists);
    return area;
}
Esempio n. 27
0
Filter* getFilter(int (*transform)(void*, Point*, Point*), void *params, int dim_x, int dim_y,
                  Point pt0) {
    Filter *tg;
    Point *t_grid; //transformed grid
    Poly *cell_poly, *poly;
    Vertex *v;
    char *is_transformed;
    int dim;
    float min_x, max_x, min_y, max_y;
    float area;
    int i, j, k;
    int ii, jj;
    int index;
    int last, allocated;

    if(params==NULL)
        return NULL;
    tg=(Filter*)calloc(1, sizeof(Filter));
    tg->dim_x=dim_x;
    tg->dim_y=dim_y;
    tg->x0=pt0.x;
    tg->y0=pt0.y;
    tg->dx=tg->dy=1;
    dim=tg->dim_x*tg->dim_y;
    tg->num_pts=(int*)calloc(dim, sizeof(int));
    tg->pts=(Point**)calloc(dim, sizeof(Point*));
    tg->coefs=(float**)calloc(dim, sizeof(float*));

    // compute the transformed grid (used to get the polygons corresponding to the cells.
    t_grid=(Point*)calloc((tg->dim_x+1)*(tg->dim_y+1), sizeof(Point));
    is_transformed=(char*)calloc((tg->dim_x+1)*(tg->dim_y+1), sizeof(char));
    for(k=0, j=0; j<=tg->dim_y; j++) {
        for(i=0; i<=tg->dim_x; i++, k++) {
            t_grid[k].x=tg->x0+i*tg->dx-tg->dx/2;
            t_grid[k].y=tg->y0+j*tg->dy-tg->dy/2;
            is_transformed[k]=(char)transform(params, t_grid+k, t_grid+k);
            if(is_transformed[k]==-1)
                return NULL; //should never happen!
        }
    }

    //for each cell, get the corresponding polygon, transform it, get all the overlapping cells,
    //(number of overlaping cells=numPoints[k]) and compute percentage of area inside each of these
    // cells
    cell_poly=generatePoly(4);
    cell_poly->verts[0].x=0;
    cell_poly->verts[0].y=1;
    cell_poly->verts[1].x=1;
    cell_poly->verts[1].y=1;
    cell_poly->verts[2].x=1;
    cell_poly->verts[2].y=0;
    cell_poly->verts[3].x=0;
    cell_poly->verts[3].y=0;
    setSides(cell_poly); // verts won't be used from now on, just normals and dists. only update dists
    for(index=0, k=0, j=0; j<tg->dim_y; j++, index++) {
        for(i=0; i<tg->dim_x; i++, k++, index++) {
            if(!(is_transformed[index] &&
                    is_transformed[index+1] &&
                    is_transformed[index+tg->dim_x+1] &&
                    is_transformed[index+tg->dim_x+2]))
                continue;
            if(!is_transformed[index] ||
                    !is_transformed[index+1] ||
                    !is_transformed[index+tg->dim_x+1] ||
                    !is_transformed[index+tg->dim_x+2]) {
                // cell contains border of transformation area.
                // TODO: handle this case
                continue;
            }
            poly=generatePoly(4);
            v=poly->verts;
            v[0].x=t_grid[index+tg->dim_x+1].x;
            v[0].y=t_grid[index+tg->dim_x+1].y;
            v[1].x=t_grid[index+tg->dim_x+2].x;
            v[1].y=t_grid[index+tg->dim_x+2].y;
            v[2].x=t_grid[index+1].x;
            v[2].y=t_grid[index+1].y;
            v[3].x=t_grid[index].x;
            v[3].y=t_grid[index].y;
            if(convexify4(poly)==-1) {
                deletePoly(poly, 1);
                continue;
            }
            setSides(poly);
            computeArea(poly);
            min_x=max_x=v[0].x;
            min_y=max_y=v[0].y;
            for(ii=1; ii<4; ii++) {
                if(v[ii].x<min_x)
                    min_x=v[ii].x;
                else if(v[ii].x>max_x)
                    max_x=v[ii].x;
                if(v[ii].y<min_y)
                    min_y=v[ii].y;
                else if(v[ii].y>max_y)
                    max_y=v[ii].y;
            }
            min_x=floorf(min_x);
            max_x=ceilf(max_x);
            min_y=floorf(min_y);
            max_y=ceilf(max_y);
            allocated=0;
            if((max_x-min_x) > 100 ||(max_y-min_y) > 100) {
                tg->num_pts[k]=1;
                tg->coefs[k]=(float*)calloc(1, sizeof(float));
                tg->pts[k]=(Point*)calloc(1, sizeof(Point));
                tg->coefs[k][0]=1;
                tg->pts[k][0].x=floor((max_x-min_x)/2); //TODO: fix that!
                tg->pts[k][0].y=floor((max_y-min_y)/2);
                deletePoly(poly, 1);
                continue;
            }
            for(jj=(int)min_y; jj<(int)max_y; jj++) {
                for(ii=(int)min_x; ii<(int)max_x; ii++) {
                    cell_poly->dists[0]=jj+1;
                    cell_poly->dists[1]=ii+1;
                    cell_poly->dists[2]=-jj;
                    cell_poly->dists[3]=-ii;
                    area=intersectionArea(poly, cell_poly);
                    if(area<SMALL)
                        continue;
                    last=tg->num_pts[k]++;
                    if(tg->num_pts[k]>allocated) {
                        allocated+=32;
                        tg->coefs[k]=(float*)realloc(tg->coefs[k], allocated*sizeof(float));
                        tg->pts[k]=(Point*)realloc(tg->pts[k], allocated*sizeof(Point));
                    }
                    tg->coefs[k][last]=area/poly->area;
                    tg->pts[k][last].x=ii;
                    tg->pts[k][last].y=jj;
                }
            }
            tg->coefs[k]=(float*)realloc(tg->coefs[k], tg->num_pts[k]*sizeof(float));
            tg->pts[k]=(Point*)realloc(tg->pts[k], tg->num_pts[k]*sizeof(Point));
            deletePoly(poly, 1);
        } //for(i)
    } //for(j)
    free(t_grid);
    free(is_transformed);
    return tg;
}