Esempio n. 1
0
int runVegas(void)
{
    int i;
    double sd;
    double avgi;
    char mess[25];
    FILE * iprt = NULL;
    int mode=1;
    void * pscr=NULL;
    static int n_Line=7;

    i=imkmom(inP1,inP2);
    if(veg_Ptr&&veg_Ptr->ndim!=i)clearGrid();
    if(!veg_Ptr) veg_Ptr=vegas_init(i,50);     

    if(nin_int == 2) strcpy(mess, "Cross section[pb]");
      else           strcpy(mess, "   Width[Gev]    ");
    
/* ** save current session parameters */
     w_sess__(NULL);
/* ** open protocol and resulting files */
       
    {  char fname[50];
       sprintf(fname,"%sprt_%d",outputDir,nSess);
       iprt=fopen(fname,"a");
       if(ftell(iprt)==0) 
       { fprintf(iprt,"    CalcHEP kinematics module \n The session parameters:\n");
         w_sess__(iprt);
         fprintf(iprt,"===================================\n");   
       }
    }

/* **  initkinematics */

    while(correctHistList()) editHist();
    
/* *** Main cycle */
    if(!integral.old || n_Line==7)
    { n_Line=7;
      scrcolor(Blue, BGmain);
//    printLn(iprt,&n_Line," #IT  %20s Error %%    nCall   chi**2",mess); 
      printLn(iprt,&n_Line," #IT %s Error[%%]  nCalls   Eff.  chi^2",mess);
    }

    for(;;)
    {
        static int worn=1;
        char strmen[]="\030"
         " nSess  = N2_1          "
         " nCalls = N1_1          "
         " Set  Distributions     "
         "*Start integration      "
         " Display Distributions  "
         " Clear statistic        "
         " Freeze grid        OFF " 
	 " Clear  grid            "
	 " Event Cubes NCUBE      "
	 " Generate Events        ";

        improveStr(strmen,"N1_1","%d",integral.ncall[0]);
        improveStr(strmen,"N2_1","%d",integral.itmx[0]);
        improveStr(strmen,"NCUBE","%d",EventGrid);

        if(integral.freeze) improveStr(strmen,"OFF","ON");

        menu1(54,7,"",strmen,"n_veg_*",&pscr,&mode);
        switch(mode)
        {     
        case 0:
          if(iprt) fclose(iprt);
          return 0;           
        case 1:  
          correctInt(50,12,"Enter new value ",&integral.itmx[0],1); break;
        case 2: 
          correctLong(50,12,"Enter new value ",&integral.ncall[0],1); break;
        case 3:  editHist(); break;
        case 4:
          if(veg_Ptr->fMax && !integral.freeze)
          {  if(!mess_y_n(15,15,"You have event generator prepared.\n"
             " The  answer 'Y'  will start Vegas session \nwhich destroys it."
             " To save the event generator answer 'N' \nand set "
             " ' Freeze grid' ON")) break;
             else { free(veg_Ptr->fMax); veg_Ptr->fMax=NULL; veg_Ptr->nCubes=0;}  
          }
          for (i = 1; i <= integral.itmx[0]; ++i)                                       
          { double sum;
            char  errtxt[100]="";
            int k;

            if(integral.ncall[0]==0) break;
            nCall=0;                                                                  
            negPoints=0;                                                              
            badPoints=0; 
            hFill=1;  
            if(vegas_int(veg_Ptr, integral.ncall[0],1.5*(!integral.freeze), 
                 func_, &avgi, &sd)        
              ) break;
            integral.old=1;                                              
            negPoints/=nCall;                                                         
            badPoints/=nCall;                                                         
            integral.nCallTot+=nCall;                                                          
            scrcolor(FGmain,BGmain);                                                 
            printLn(iprt,&n_Line,"%4d   %12.4E %10.2E %8d %s",                     
                 ++integral.n_it, avgi,avgi? 100*sd/(double)fabs(avgi):0.,nCall,effInfo());
                                                                   
            if(negPoints<0) sprintf(errtxt+strlen(errtxt)," Negative points %.1G%%;",                
                                      -100*negPoints/(avgi-2*negPoints));             
            if(badPoints)  sprintf(errtxt+strlen(errtxt),                             
                 "Bad Precision %.1G%%;",100*badPoints/(avgi-2*negPoints));           
                                                                                      
            if(errtxt[0])                                                             
            {                                                                         
               scrcolor(Red,BGmain);                                                  
               printLn(iprt,&n_Line,"%s",errtxt);                                     
            }
                                                                                                                                                
            integral.s0+=sd*sd;                                                                  
            integral.s1+=avgi;                                                             
            integral.s2+=avgi*avgi;                                    
          } 
          
          
          integral.In=integral.s1/integral.n_it; 
          integral.dI=sqrt(integral.s0)/integral.n_it;
          if(integral.n_it<=1 || integral.s0==0 ) integral.khi2=0; else 
          integral.khi2=(integral.s2-integral.s1*integral.s1/integral.n_it)*integral.n_it/(integral.n_it-1)/fabs(integral.s0);  
          
          scrcolor(FGmain,BGmain);

          printLn(iprt,&n_Line," < >   %12.4E %10.2E %8d %7.7s %-7.1G" ,
                      integral.In, fabs(integral.In)? 100*integral.dI/(double)fabs(integral.In):0., integral.nCallTot, 
                                                              effInfo(),  integral.khi2);
          if(histTab.strings)
          { char  fname[20];
            FILE * d;
            sprintf(fname,"distr_%d",nSess);
            d=fopen(fname,"w");  
            wrt_hist2(d,Process);
            fclose(d);
          }
                    messanykey(54,11,"Integration is over");
/*          integral.freeze=0; */
          break;

        case 5: showHist(54,10,Process); break;
        case 6: clearStatistics(-1);
                messanykey(54,13,"Old results for integral\n"
                "and distributions\nare deleted.");
                break;
        case 7: integral.freeze=!integral.freeze; break; 
        case 8: if(!integral.freeze || mess_y_n(15,15,"The information for Event Generator will be lost\n OK?"))  
                { int ndim=veg_Ptr->ndim;
                  vegas_finish(veg_Ptr);
                  veg_Ptr=vegas_init(ndim,50);
                  messanykey(57,11,"OK");
                }   
                break;
        case 9: 
           if(correctLong(50,12,"Enter new value ",&EventGrid,1))
           { if(veg_Ptr->fMax) {free(veg_Ptr->fMax); veg_Ptr->fMax=NULL;veg_Ptr->nCubes=0;}} break;
        case 10: 
           if( !veg_Ptr || !veg_Ptr->fMax)
           { char * mess="Before event generation one has to launch  Vegas session with freezed grid\n"
                                           "to prepare generator";
                if(blind) { printf("%s\n",mess); sortie(200);}  else messanykey(4,13,mess);
           }    else    runEvents(); 
       }
    }    
}
void BlobDetection::detectWalls(cv::Mat& image, const ros::Time& timestamp) const {
    cv::Mat wall;
    cv::cvtColor(image, wall, CV_BGR2HSV);

    std::vector<cv::Mat> spl;
    cv::split(wall, spl);

    int element_size = 3;
    // cv::Mat element = getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(2 * element_size + 1, 2 * element_size + 1), cv::Point(element_size, element_size) );
    // cv::morphologyEx(spl[1], spl[1], cv::MORPH_OPEN, element);
    cv::medianBlur(spl[1], spl[1], 13); // removes salt and pepper noise from saturation
    cv::GaussianBlur(spl[1], spl[1],cv::Size(7, 7), 7); // removes gaussian noise (well, weakens it) from saturation
    showImage(spl[1], "saturation");

    double satWeight = .25;
    n.getParam("satWeight", satWeight);

    wall = spl[1] * satWeight; // this can work against reflections
    wall += spl[2] * (1.0 - satWeight);

    cv::Mat element = getStructuringElement(cv::MORPH_CROSS, cv::Size(2 * element_size + 1, 2 * element_size + 1), cv::Point(element_size, element_size) );
    cv::morphologyEx(wall, wall, cv::MORPH_OPEN, element);
    cv::GaussianBlur(wall, wall, cv::Size(7, 7), 7);
    /*
       double minVal = 0.0, maxVal = 0.0; // maybe they come in handy some time ...
       minMaxLoc(wall, &minVal, &maxVal);
    */

    bool useNormalization = false;
    n.getParam("useNormalization", useNormalization);
    if(useNormalization)
        cv::normalize(wall, wall, 0, 255, NORM_MINMAX, CV_8UC1);

    showImage(wall, "wall");
    showHist(wall, "wall_hist");

    int upperBound = 50;
    n.getParam("upperBound", upperBound);

    Mat mask, maskValue, maskWall;

    cv::morphologyEx(spl[2], spl[2], cv::MORPH_OPEN, element);
    cv::GaussianBlur(spl[2], spl[2], cv::Size(7, 7), 7);
    showImage(spl[2], "value");
    showHist(spl[2], "value_hist");

    cv::inRange(spl[2], 0, upperBound, maskValue);
    //cv::morphologyEx(maskValue, maskValue, cv::MORPH_OPEN, element);
    showImage(maskValue, "value_mask");

    cv::inRange(wall, 0, upperBound, maskWall);
    //cv::morphologyEx(maskWall, maskWall, cv::MORPH_OPEN, element);
    showImage(maskWall, "wall_mask");

    cv::bitwise_or(maskValue, maskWall, mask);
    cv::morphologyEx(mask, mask, cv::MORPH_OPEN, element);

    double maxBlacknessScore = 0.0;
    int bestContourIndex = -1, secondBestContourIndex = -1;
    std::vector<std::vector<cv::Point> > contours; // Vector for storing contour

    cv::findContours(mask, contours, cv::noArray(), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image
    std::vector<std::vector<cv::Point> > poligons(contours.size()); // Vector for storing the 2 best simplified contour


    double blacknessWeight = 1.0;
    n.getParam("blacknessWeight", blacknessWeight);

    double maxSlope = 0.3;
    n.getParam("maxSlope", maxSlope);

    double minLength = 0.7;
    n.getParam("minLength", minLength);
    cv::Mat tmp;

    for(size_t i = 0; i < contours.size(); i++) {// iterate through each contour.
        tmp = cv::Mat::zeros(image.size(), CV_8UC1);
        cv::drawContours(tmp, contours, i, Scalar(255), CV_FILLED, 8); // draw the area in the contour completely white
        cv::subtract(tmp, spl[2] * blacknessWeight, tmp, tmp); // subtract the value channel from the white contour (the lighter the pixel the lower the score for it)
        double blacknessScore = cv::sum(tmp)[0]; // now sum over the score (the higher the black quality and the larger the area the "better" is the black surface.
        if(blacknessScore > maxBlacknessScore){
            cv::RotatedRect boundingBox = cv::minAreaRect(contours[i]);
            cv::approxPolyDP(contours[i], poligons[i], 20, true);
            bool wallCandidate = false;
            for(size_t j = 0; j < poligons[i].size() - 1; j++) {
            	float len = cv::norm(poligons[i][j] - poligons[i][j + 1]);
            	if(len > minLength * std::max(boundingBox.size.width, boundingBox.size.height)){
                	float m = fabs(static_cast<float>(poligons[i][j].y) - poligons[i][j + 1].y) / fabs(static_cast<float>(poligons[i][j].x) - poligons[i][j + 1].x);
            		if(maxSlope >= 0.0 && m > maxSlope)
            			continue;
#ifdef DEBUG
            		cv::Point2f rect_points[4];
            		boundingBox.points( rect_points );
            		//for( size_t k = 0; k < 4; k++ )
            			//line(tmp, rect_points[k], rect_points[(k + 1) % 4], Scalar(64), 2, 8, 0 );
            		cv::line(tmp, poligons[i][j], poligons[i][j + 1] , cv::Scalar(127), 7, 8, 0 );
#endif
            		wallCandidate = true;
            		break;
            	}
            }
            if(wallCandidate){
				// secondBestContourIndex = bestContourIndex;
				maxBlacknessScore = blacknessScore;
				bestContourIndex = static_cast<int>(i);
#ifdef DEBUG
		        cv::drawContours(tmp, poligons, i, Scalar(64), 2, 8 );
#endif
            }
#ifdef DEBUG
            // drawContours(tmp, outline, 0, Scalar(127), 2, 8 );
            // showImage(tmp, "tmp");
#endif
        }
    }
	showImage(tmp, "tmp");
    cv::Mat img = image.clone();
    if(bestContourIndex >= 0){
        object_detection_blob::BlobWall wallMessage;
        wallMessage.header.seq++;
        wallMessage.header.stamp = timestamp;
        wallMessage.header.frame_id = "image";
        auto contourMoments = cv::moments(poligons[bestContourIndex]);
        wallMessage.center.x = contourMoments.m10 / contourMoments.m00;
        wallMessage.center.y = contourMoments.m01 / contourMoments.m00;
        wallMessage.imgSize.x = img.cols;
        wallMessage.imgSize.y = img.rows;
        wallMessage.bottomCenter.x = wallMessage.center.x;
        wallMessage.bottomCenter.y = 0;
        cv::Point& lastPoint = poligons[bestContourIndex][0];
        for(auto& point : poligons[bestContourIndex]){
        	object_detection_blob::Vector2 element;
        	element.x = point.x;
        	element.y = point.y;
        	wallMessage.contour.push_back(element);
        	if(point.x <= wallMessage.center.x && wallMessage.center.x <= lastPoint.x){ // contour goes right to left and intersects with vertical line through center point
        		int distX = point.x - lastPoint.x;
        		int distY = lastPoint.y - point.y;
        		int bottomY = lastPoint.y + distY * static_cast<float>(point.x - wallMessage.center.x) / distX;
        		if(bottomY > wallMessage.bottomCenter.y)
        			wallMessage.bottomCenter.y = bottomY;
        	}
        	if(lastPoint.x <= wallMessage.center.x && wallMessage.center.x <= point.x){ // contour goes left to right and intersects with vertical line through center point
        		int distX = lastPoint.x - point.x;
        		int distY = point.y - lastPoint.y;
        		int bottomY = point.y + distY * static_cast<float>(point.x - wallMessage.center.x) / distX;
        		if(bottomY > wallMessage.bottomCenter.y)
        			wallMessage.bottomCenter.y = bottomY;
        	}
        	lastPoint = point;
        }
        wallMessage.relativeArea = cv::contourArea(contours[bestContourIndex]) / (img.cols * img.rows);
        if(wallMessage.center.x >= 0 && wallMessage.center.y >= 0) // the center is computed from the simplified polygon. if it is too simple (a line) there is no center of gravity for some reason and the shape is not worth publishing
        	wallPublisher.publish(wallMessage);
#ifdef DEBUG
        cv::drawContours(img, contours, bestContourIndex, Scalar(255, 0, 0), 2, 8 ); // Draw the best contour using previously stored index.
        cv::circle(img, cv::Point(contourMoments.m10 / contourMoments.m00, contourMoments.m01 / contourMoments.m00), 3,  Scalar(0, 255, 0), 2);
        cv::circle(img, cv::Point(wallMessage.bottomCenter.x, wallMessage.bottomCenter.y), 3,  Scalar(0, 0, 255), 2);
#endif
    }
    /*
    if(secondBestContourIndex >= 0){
        object_detection_blob::BlobWall wallMessage;
        wallMessage.header.seq++;
        wallMessage.header.stamp = timestamp;
        wallMessage.header.frame_id = "image";
        auto contourMoments = cv::moments(poligons[secondBestContourIndex]);
        wallMessage.center.x = contourMoments.m10 / contourMoments.m00;
        wallMessage.center.y = contourMoments.m01 / contourMoments.m00;
        wallMessage.imgSize.x = img.cols;
        wallMessage.imgSize.y = img.rows;
        wallMessage.bottomCenter.x = wallMessage.center.x;
        wallMessage.bottomCenter.y = 0;
        cv::Point& lastPoint = poligons[secondBestContourIndex][0];
        for(auto& point : poligons[secondBestContourIndex]){
            object_detection_blob::Vector2 element;
            element.x = point.x;
            element.y = point.y;
            wallMessage.contour.push_back(element);
            if(point.x <= wallMessage.center.x && wallMessage.center.x <= lastPoint.x){ // contour goes right to left and intersects with vertical line through center point
            	int distX = point.x - lastPoint.x;
            	int distY = lastPoint.y - point.y;
            	int bottomY = lastPoint.y + distY * static_cast<float>(point.x - wallMessage.center.x) / distX;
            	if(bottomY > wallMessage.bottomCenter.y)
            		wallMessage.bottomCenter.y = bottomY;
            }
            if(lastPoint.x <= wallMessage.center.x && wallMessage.center.x <= point.x){ // contour goes left to right and intersects with vertical line through center point
            	int distX = lastPoint.x - point.x;
            	int distY = point.y - lastPoint.y;
            	int bottomY = point.y + distY * static_cast<float>(point.x - wallMessage.center.x) / distX;
            	if(bottomY > wallMessage.bottomCenter.y)
            		wallMessage.bottomCenter.y = bottomY;
            }
        	lastPoint = point;
        }
        wallMessage.relativeArea = cv::contourArea(contours[secondBestContourIndex]) / (img.cols * img.rows);
        if(wallMessage.center.x >= 0 && wallMessage.center.y >= 0) // the center is computed from the simplified polygon. if it is too simple (a line) there is no center of gravity for some reason and the shape is not worth publishing
        	wallPublisher.publish(wallMessage);
#ifdef DEBUG
        cv::drawContours(img, contours, secondBestContourIndex, Scalar(255, 0, 0), 2, 8 ); // Draw the second best contour using previously stored index.
        cv::circle(img, cv::Point(contourMoments.m10 / contourMoments.m00, contourMoments.m01 / contourMoments.m00), 3,  Scalar(0, 255, 0), 2);
        cv::circle(img, cv::Point(wallMessage.bottomCenter.x, wallMessage.bottomCenter.y), 3,  Scalar(0, 0, 255), 2);
#endif
    }
    */
    showImage(img, "black");
}
Esempio n. 3
0
int runVegas(void)
{
    int i;
    double sd;
    double avgi;
    char mess[25];
    FILE * iprt = NULL;
    int mode=1;
    void * pscr=NULL;
    static int n_Line=0;
    
    if(blind) vegas_control=NULL; else  vegas_control=infoLine;
    i=imkmom(inP1,inP2);
    if(veg_Ptr&&veg_Ptr->dim!=i)clearGrid();
    if(!veg_Ptr) veg_Ptr=vegas_init(i,func_,50);     

    if(nin_int == 2) strcpy(mess, "Cross section[pb]");
      else           strcpy(mess, "   Width[Gev]    ");
    
/* ** save current session parameters */
     w_sess__(NULL);
/* ** open protocol and resulting files */
       
    {  char fname[50];
       sprintf(fname,"%sprt_%d",outputDir,nSess);
       iprt=fopen(fname,"a");
    }

/* **  initkinematics */

    while(correctHistList()) editHist();

    if(integral.old) { if(!n_Line)  n_Line=9;} else
    {
       w_sess__(iprt);
       n_Line=8;
    }
                           
/* *** Main cycle */

    for(;;)
    {
        int fz;
        char strmen[]="\030"
         " nSess  = N2_1          "
         " nCalls = N1_1          "
         " Set  Distributions     "
         "*Start integration      "
         " Display Distributions  "
         " Clear statistic        "
         " Freeze grid        OFF " 
	 " Clear  grid            "
	 " Event Cubes NCUBE      "
	 " Num. of events=NE      "
	 " Generate Events        ";
	 
        if(integral.freeze)
        {  fz=1;
           improveStr(strmen,"OFF","ON");
           improveStr(strmen,"NCUBE","%d",EventGrid);
        }  
        else
        {  fz=0;
           strmen[ 030*8+2]=0;
        }

        improveStr(strmen,"N1_1","%d",integral.ncall[fz]);
        improveStr(strmen,"N2_1","%d",integral.itmx[fz]);
        improveStr(strmen,"NE","%d",nEvents);
        menu1(54,7,"",strmen,"n_veg_*",&pscr,&mode);
        switch(mode)
        {     
        case 0:
           w_sess__(NULL);
          if(iprt) fclose(iprt);
          return 0;           
        case 1: correctInt(50,12,"Enter new value ", integral.itmx+fz,1);  break;
        case 2: correctLong(50,12,"Enter new value ",integral.ncall+fz,1);break;
        case 3:  editHist(); break;
        case 4:
          if(veg_Ptr->fMax && !integral.freeze) 
          {  free(veg_Ptr->fMax); veg_Ptr->fMax=NULL; veg_Ptr->evnCubes=0; }
          if(!veg_Ptr->fMax && integral.freeze)
          {  setEventCubes(veg_Ptr, EventGrid);
             EventGrid=veg_Ptr->evnCubes;
          }

          for (i = 1; i <= integral.itmx[fz]; ++i)                                       
          { char  errtxt[100]="";
            long nCall;
            if(integral.ncall[0]==0) break;                                                                  
            negPoints=0;                                                              
            badPoints=0; 
            hFill=1;   
            nCall=vegas_int(veg_Ptr, integral.ncall[fz],1.5*(!fz),nPROCSS,&avgi, &sd);
            if(nCall<0) { messanykey(10,10,"NaN in integrand"); break;}
            if(nCall==0) break;
            
            integral.old=1;                                              
            negPoints/=nCall;                                                         
            badPoints/=nCall;                                                         
            integral.nCallTot+=nCall;                                                          
            scrcolor(FGmain,BGmain);                                                 
            printLn(iprt,&n_Line,"%4d   %12.4E %10.2E %8d %s",                     
                 ++integral.n_it, avgi,avgi? 100*sd/(double)fabs(avgi):0.,nCall,effInfo());
                                                                   
            if(negPoints<0) sprintf(errtxt+strlen(errtxt)," Negative points %.1G%%;",                
                                      -100*negPoints/(avgi-2*negPoints));             
            if(badPoints)  sprintf(errtxt+strlen(errtxt),                             
                 "Bad Precision %.1G%%;",100*badPoints/(avgi-2*negPoints));           
                                                                                      
            if(errtxt[0])                                                             
            {                                                                         
               scrcolor(Red,BGmain);                                                  
               printLn(iprt,&n_Line,"%s",errtxt);                                     
            }
                                                                                                                                                
            integral.s0+=sd*sd;                                                                  
            integral.s1+=avgi;                                                             
            integral.s2+=avgi*avgi;                                    
          } 
          
          
          integral.In=integral.s1/integral.n_it; 
          integral.dI=sqrt(integral.s0)/integral.n_it;
          if(integral.n_it<=1 || integral.s0==0 ) integral.khi2=0; else 
          integral.khi2=(integral.s2-integral.s1*integral.s1/integral.n_it)*integral.n_it/(integral.n_it-1)/fabs(integral.s0);  
          
          scrcolor(FGmain,BGmain);

          printLn(iprt,&n_Line," < >   %12.4E %10.2E %8d %7.7s %-7.1G" ,
                      integral.In, fabs(integral.In)? 100*integral.dI/(double)fabs(integral.In):0., integral.nCallTot, 
                                                              effInfo(),  integral.khi2);
          if(histTab.strings)
          { char  fname[20];
            FILE * d;
            sprintf(fname,"distr_%d",nSess);
            d=fopen(fname,"w");  
            wrt_hist2(d,Process);
            fclose(d);
          }
                    messanykey(54,11,"Integration is over");
/*          integral.freeze=0; */
          break;

        case 5: showHist(54,10,Process); break;
        case 6: clearStatistics(-1);
                messanykey(54,13,"Old results for integral\n"
                "and distributions\nare deleted.");
                break;
        case 7: 
             if(veg_Ptr->fMax && integral.freeze) 
             {  if(mess_y_n(15,15,"You have event generator prepared.\n"
                " Setting the flag \"OFF\"  will destroy it."
                " Press 'Y' to confirm.")) integral.freeze=0; 
             } else  integral.freeze=!integral.freeze; 
             break; 
        case 8: if(!integral.freeze || mess_y_n(15,15,"The information for Event Generator will be lost\n OK?"))  
                { int ndim=veg_Ptr->dim;
                  vegas_finish(veg_Ptr);
                  veg_Ptr=vegas_init(ndim,func_,50);
                  messanykey(57,11,"OK");
                }   
                break;
        case 9: 
           if(correctLong(50,12,"Enter new value ",&EventGrid,1))
           { if(veg_Ptr->fMax) {free(veg_Ptr->fMax); veg_Ptr->fMax=NULL;}
             printf("EventGrid=%d\n",EventGrid);
             setEventCubes(veg_Ptr, EventGrid);
             EventGrid=veg_Ptr->evnCubes;  
           } break;
        case 10:  correctInt(50,15,"",&nEvents,1); break;
        case 11: 
           if( !veg_Ptr || !veg_Ptr->fMax)
           { char * mess="Before event generation one has to launch  Vegas session with freezed grid\n"
                                           "to prepare generator";
                if(blind) { printf("%s\n",mess); sortie(200);}  else messanykey(4,13,mess);
           } else  runEvents();
       }
    }    
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // canvas
    imageLabel = new QLabel("Загрузите изображение");
    imageLabel->setBackgroundRole(QPalette::Dark);

    ui->scrollArea->setWidget(imageLabel);

    imageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    imageLabel->setBackgroundRole(QPalette::Base);

    // layouts
    ui->centralWidget->setLayout(ui->mainLayout);
    ui->scrollArea->setBackgroundRole(QPalette::Dark);

    ui->toolsDock->setWidget(ui->toolsScrollArea);
    ui->toolsLayout->setMargin(10);
    ui->toolsScrollAreaContent->setLayout(ui->toolsLayout);

    ui->brightnessDock->setWidget(ui->brightnessScrollArea);
    ui->brightnessLayout->setMargin(10);
    ui->brightnessScrollAreaContents->setLayout(ui->brightnessLayout);

    ui->filtersDock->setWidget(ui->filtersScrollArea);
    ui->filtersLayout->setMargin(5);
    ui->filtersScrollArea->setLayout(ui->filtersLayout);

    ui->multiTab->setLayout(ui->multiLayout);
    ui->multiLayout->setMargin(10);

    ui->additTab->setLayout(ui->additLayout);
    ui->additLayout->setMargin(10);

    ui->impulseTab->setLayout(ui->impulseLayout);
    ui->impulseLayout->setMargin(10);

    ui->analysisTab->setLayout(ui->analysisLayout);
    ui->analysisLayout->setMargin(10);

    ui->autolevelsGroupBox->setLayout(ui->autolevelsLayout);
    ui->linContrastGroupBox->setLayout(ui->linContrastLayout);
    //ui->autolevelsLayout->setMargin(5);

    ui->brightnessDock->hide();
    // signals & slots
    connect(ui->loadButton, SIGNAL(clicked()), this, SLOT(loadImage()));

    connect(ui->showToolsAction,      SIGNAL(toggled(bool)),     ui->toolsDock,      SLOT(setShown(bool)));
    connect(ui->showBrightnessAction, SIGNAL(toggled(bool)),     ui->brightnessDock, SLOT(setShown(bool)));

    connect(ui->showProcessedButton,  SIGNAL(clicked()),         this, SIGNAL(restoreImage()));
    connect(ui->noiseDial,            SIGNAL(valueChanged(int)), this, SIGNAL(rateChanged(int)));
    connect(ui->filterOffsetBox,      SIGNAL(valueChanged(int)), this, SIGNAL(offsetChanged(int)));
    connect(ui->actionGrayscale,      SIGNAL(triggered()),       this, SIGNAL(grayscale()));
    connect(ui->histAction,           SIGNAL(triggered()),       this, SIGNAL(showHist()));
    connect(ui->invertseAction,       SIGNAL(triggered()),       this, SIGNAL(inverse()));
    connect(ui->equalizeAction,       SIGNAL(triggered()),       this, SIGNAL(equalize()));

    // test
    connect(ui->showConvolutionAction, SIGNAL(toggled(bool)), ui->filtersDock, SLOT(setShown(bool)));

    ui->collectionsTab->setLayout(ui->collectionsLayout);
    ui->collectionsLayout->setMargin(5);

    this->resize(1000, 600);
    this->move(50, 50);
    this->raise();
}