void ControlWindows::endStep()
{
 
 m_spiedino->stop();
  m_counterino->stop();
  disconnect( &m_clock, SIGNAL(timeout(QPrivateSignal)) , this, SLOT(update()));
  m_cache.append("#Duty: ").append( QString::number(m_duty ) ).append('\n');
  m_cache.append("#Conteggi: ").append( QString::number(m_counterino->getCount() ) ).append('\n');
  m_cache.append("#time[millis] rawMeasure\n");
 const Spiedino::AcquireData *bufferAcquireData=m_spiedino->getAcquireCache();
  
  for( unsigned int i=0; i < bufferAcquireData->time.size(); ++i){
    m_cache.append( QString::number(bufferAcquireData->time.at(i)       ) ).append(' ')
          .append( QString::number(bufferAcquireData->rawMeasure.at(i) ) ).append('\n') ;  
    
  }
  
  m_duty+=m_dutyStep;
  m_spiedino->clearAcquireCache();
  m_counterino->clear();
  
  
  
  if( m_duty >256 ){
    
    emit endOfSet();
    return;
    
  }
   
   startStep();
}
		void checkIn(int recdPoints)
		{
			totalParticles = totalParticles + recdPoints; 			
			chkinCounter++;
			if(chkinCounter == 64)
			{
				CkPrintf("Stage %d Total CheckIns : %d with %d particles. \n",stage,chkinCounter,totalParticles);
				startStep();
			}
		};
		main(CkArgMsg *m)
		{
			delete m;
			CkPrintf("%d Random points(x,y) between 0 and 1 being generated. On Total PEs: [%d] \n", TOTAL_PARTICLES, CkNumPes());
			mainProxy = thisProxy;
			pointsProxy = CProxy_points::ckNew(8,8);
			stage = 0;
			totalParticles = 0;
			startStep();			
	
		};
void ControlWindows::start()
{
   
  m_ui->horizontalLayout->setEnabled(false);  // FIXME fare una funzione più precisa
  m_DeltaT = m_ui->spinIntegrationTime->value();
  m_dutyStep=m_ui->spinDutyStep->value();
  m_pol=m_ui->doubleSpinOutPol->value();
  
  m_timer.setInterval(m_DeltaT*1000);
  m_duty=0;
  m_spiedino->setDuty(m_duty);
  m_counterino->clear();
  
  
  
  
  startStep();
  
}
		void shiftPoints()
		{
			int i;							//Generate random doubles between (-1/800 to 1/800)
			double shiftX = (((double)rand()/(double)RAND_MAX)/400 - (1.0/800.0));
			double shiftY = (((double)rand()/(double)RAND_MAX)/400 - (1.0/800.0));
			double tempX,tempY;
			for(i = 0;i<count;i++)
			{	
				tempX = valuesX[i];
				tempY = valuesY[i];
				valuesX[i] = valuesX[i]+shiftX;
				valuesY[i] = valuesY[i]+shiftY;
				if(valuesX[i] < 0.0)				//Adjustments done to ensure that the coordinates lie within [0,1].
					valuesX[i] = 0.0 - valuesX[i];
				else if(valuesX[i] > 1.0)
					valuesX[i] = tempX;
				if(valuesY[i] < 0.0)
					valuesY[i] = 0.0 - valuesY[i];
				else if(valuesY[i] > 1.0)
					valuesY[i] = tempY;
			}
			startStep();
		};
void pdp::ThickeningDetector::run()
{
    struct StepInfo {
        float realPercent;
        ThickeningDetectionStep* step;

        StepInfo(ThickeningDetectionStep* step) : step(step) {};
    };

    typedef std::list<StepInfo> StepList;
    StepList steps;

    // Add your steps here in a similar way.

	//using threshold to detect the lungs
	//the first and end slices containing a large enough amount of lungs are found
	LungsDetection* startEnd = new LungsDetection("detect start and end of the lungs");
	startEnd->setInputStepName("Original Lung CT");
	steps.push_back(startEnd);

	OtsuStep* otsu = new OtsuStep("detect start and end of the lungs");
	otsu->setInputStepName("Lungs");
	steps.push_back(otsu);

	//EMClassification* emClassifier = new EMClassification("detect start and end of the lungs");
	//emClassifier->setInputStepName("Otsu");
	//steps.push_back(emClassifier);
	
	//contourExtractor<double>* contour = new contourExtractor<double>("Extracting contours");
 //   contour->setInputStepName("Lungs");
 //   steps.push_back(contour);

 //   convexHull* convex = new convexHull("Computing the convex hull");
 //   steps.push_back(convex);
	//
	//thickeningsIdentification* thickIdent = new thickeningsIdentification("Identifying 3d thicks");
 //   steps.push_back(thickIdent);

	//visualizeData<double>* visualize = new visualizeData<double>("Visualizing data");
 //   steps.push_back(visualize);

    // Done adding steps, let's go!

    // Normalize the progress percents.
    float totalPercent = 0.0f;
    for(StepList::iterator iStep = steps.begin() ; iStep != steps.end() ; ++iStep) {
        totalPercent += iStep->step->relativePercent();
    }
    for(StepList::iterator iStep = steps.begin() ; iStep != steps.end() ; ++iStep) {
        iStep->realPercent = iStep->step->relativePercent() / totalPercent;
    }

    // Execute the steps.
    for(StepList::iterator iStep = steps.begin() ; iStep != steps.end() ; ++iStep) {
        QObject::connect(iStep->step, SIGNAL(stepProgress(float)),
                         this, SLOT(onStepProgress(float)));

        emit startStep(iStep->step->name(), iStep->realPercent);
		//! \todo exceptionhandling
		iStep->step->work(m_input, m_output);

        emit stepDone();

        // Cleanup
        QObject::disconnect(iStep->step, SIGNAL(stepProgress(float)),
                            this, SLOT(onStepProgress(float)));
        delete iStep->step;
    }

    this->exit();
}