Ejemplo n.º 1
0
void CMainDlg::OnBnClickedFlAutoprog()
{
	CBusy busy;
	
	if(!m_BootConnected)
		return;

	EnableControlBtn(false);
	
	// program it!
	if(prg_mem() < 0)
	{
		ProgressChanged(100);
		LogResetReplaceLine();
		fprintf(stderr, "Program memory failed.\n");
		LogResetReplaceLine();
		EnableControlBtn(true);
	}else
	{
		ProgressChanged(100);
		LogResetReplaceLine();
		EnableControlBtn(true);

		OnBnClickedConnect();
	}
}
Ejemplo n.º 2
0
/*
void CMainDlg::OnBnClickedFlRead()
{
	CBusy busy;
	BOARD_MEM imageOut;
	if(!m_BootConnected)
		return;

	EnableControlBtn(false);
	
	reset_S19image(&imageOut);



	if(read_mem(&imageOut) >= 0)
	{
		// save image!!
		CString fileName,pathName;

		CFileDialog dlg(TRUE,NULL,NULL,(OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT),_T("S19 files (*.s19;*.sx;*.srec)|*.s19; *.sx; *.srec|MOT files (*.mot)|*.mot|All files (*.*)|*.*||"));
		
		if(dlg.DoModal() == IDOK)
		{
			pathName = dlg.GetPathName();
			fileName=dlg.GetFileName();
			if(write_s19(pathName.GetBuffer(), &imageOut)<0)
			{
				MessageBox("Write output file operation failed.", "Read image Error",  MB_ICONERROR | MB_OK);
			}

			
		}else
			MessageBox("Open output file operation failed.", "Read image Error",  MB_ICONERROR | MB_OK);
		

	}else
	{
		MessageBox("Read image operation failed.", "Read image Error",  MB_ICONERROR | MB_OK);
	}
	
	LogResetReplaceLine();
	

	ProgressChanged(100);
	LogResetReplaceLine();
	EnableControlBtn(true);
}
*/
void CMainDlg::OnBnClickedFlRead()
{

	
	CBusy busy;
	BOARD_MEM* pImageOut;
	
	myprintf("/n Experimental feature!!!");

	if(!m_BootConnected)
		return;

	pImageOut = (BOARD_MEM*)malloc(sizeof(BOARD_MEM));

	EnableControlBtn(false);
	
	reset_S19image(pImageOut);



	if(read_mem(pImageOut, 1) >= 0)
	{
		// save image!!
		CString fileName,pathName;

		CFileDialog dlg(TRUE,NULL,NULL,(OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT),_T("S19 files (*.s19;*.sx;*.srec)|*.s19; *.sx; *.srec|MOT files (*.mot)|*.mot|All files (*.*)|*.*||"));
		
		if(dlg.DoModal() == IDOK)
		{
			pathName = dlg.GetPathName();
			fileName=dlg.GetFileName();
			if(write_s19(pathName.GetBuffer(), pImageOut)<0)
			{
				MessageBox("Write output file operation failed.", "Read image Error",  MB_ICONERROR | MB_OK);
			}

			
		}else
			MessageBox("Open output file operation failed.", "Read image Error",  MB_ICONERROR | MB_OK);
		

	}else
	{
		MessageBox("Read image operation failed.", "Read image Error",  MB_ICONERROR | MB_OK);
	}
	
	free(pImageOut);

	LogResetReplaceLine();
	

	ProgressChanged(100);
	LogResetReplaceLine();
	EnableControlBtn(true);
	
}
Ejemplo n.º 3
0
void DriveTransfer::TransferFile(QString sourcePath, QString relativeFilePath, QString targetPath, int64_t& checksum)
{
    QFile source(sourcePath + "/" + relativeFilePath);

    _subTaskDescription = "Copying " + relativeFilePath.toStdString();

    // TODO: Ensure trailing slash to remove need of appending it in multiple places
    if (QFile::exists(targetPath + relativeFilePath))
    {
        QFile::remove(targetPath + "/" + relativeFilePath);
    }

    QFile target(targetPath + "/" + relativeFilePath);

    OC_LOG_INFO("From: " + source.fileName().toStdString() + " To: " + target.fileName().toStdString());
    source.open(QIODevice::ReadOnly);
    target.open(QIODevice::WriteOnly);

    if (source.error() || target.error())
    {
        OC_LOG_ERROR("DriveTransfer failed.");
        return;
    }

    int TRANSFER_BLOCK_SIZE = 1024 * 1024; // 1MB

    float progressBlock = source.size() / 100.0f;
    int totalRead = 0;
    int progress = 0;

    const std::unique_ptr<IHashGenerator> hashGenerator(new xxHashAdapter());
    hashGenerator->Initialize();

    // TODO: Error handling
    char* buffer = new char[TRANSFER_BLOCK_SIZE];
    while (!source.atEnd())
    {
        qint64 readSize = source.read(buffer, TRANSFER_BLOCK_SIZE);
        target.write(buffer, readSize);

        hashGenerator->Update(buffer, readSize);

        totalRead += readSize;

         //progress = totalRead / progressBlock;

        if (totalRead > progressBlock * progress)
        {
            progress += totalRead / progressBlock;

            ProgressChanged(progress);
        }
    }

    checksum = hashGenerator->Retrieve();
}
Ejemplo n.º 4
0
void CMainDlg::OnBnClickedFlErase()
{
	CBusy busy;
	
	if(!m_BootConnected)
		return;

	EnableControlBtn(false);
	
	erase_mem(1); // to do - what to do when erase operation halted ?
	ProgressChanged(100);
	LogResetReplaceLine();
	EnableControlBtn(true);
}
Ejemplo n.º 5
0
void CMainDlg::OnBnClickedFlProgram()
{
	CBusy busy;

	if(!m_BootConnected)
		return;

	EnableControlBtn(false);
	
	prg_only_mem(); // to do what to do if error occured 	
	ProgressChanged(100);
	LogResetReplaceLine();
	EnableControlBtn(true);
}
Ejemplo n.º 6
0
void CMainDlg::OnBnClickedFlCompare()
{
	
	CBusy busy;
	
	if(!m_BootConnected)
		return;

	EnableControlBtn(false);
	
	// check if code goes to valid memory only - issue warning only, but continue! (r30323)
	check_image();
	LogResetReplaceLine();
	
	verify_mem(1);// to do - what to do when erase operation halted ?
	ProgressChanged(100);
	LogResetReplaceLine();
	EnableControlBtn(true);
}
Ejemplo n.º 7
0
void  Filter::guass3DFilterSipl(Raw* src, Raw *ret,int iter, int halfsize,void (*ProgressChanged)(int,int ,int,bool&))
{
	
	//globalProgressChanged = src->size();
	bool flag = false;
	int rs = 0 ;
	//if (  ProgressChanged != NULL )
	//{
	//	ProgressChanged (0, 100,0,flag);
	//}
	//progressStep =0;
	//ProgressChanged = ProgressChanged;

	int i=0,j=0,k=0,m=0,n=0,l=0,width=0,depth=0,length=0;
	float sum = 0;
	int delta=1;
	Raw *temp;
	bool MULTITHREADMIDLESILCES = iter !=0 && (iter+1)*ret->getZsize() < src->getZsize();
	bool MULTITHREADFIRST = (iter == 0 && (iter+1)*ret->getZsize() !=  src->getZsize());
	bool MULTITHREADLAST =   ((iter+1)*ret->getZsize() >=  src->getZsize()&& iter !=0 );
	bool SINGLETHREAD = true ;
	//int rs = 0;
	if (MULTITHREADMIDLESILCES)
	{
		//Raw *s = new Raw(ret->getXsize(), ret->getYsize(), ret->getZsize() + 2, src->getdata()+iter*ret->size()-ret->getXsize()*ret->getYsize());

		temp = new Raw(src->getXsize(),src->getYsize(),ret->getZsize() + 2*halfsize,src->getdata()+ 
			ret->size()*iter-halfsize*ret->getXsize()*ret->getYsize(),true);
		//puregauss(temp,rs,src,ret,halfsize,sum,globalProgressChanged,progressStep,ProgressChanged);

		//globalProgressChanged = src->size();
		size_t interval = globalProgressChanged/1000 == 0? 1:globalProgressChanged/1000;
		
		bool flag = false;
		//Raw * _ret =new Raw(*temp);
		width = temp->getXsize();
		length = temp->getYsize();
		depth = temp->getZsize();
		Raw *guass = new Raw(*temp);	///< The result of guass filter. 

		for (i = 0; i < depth; i++)
		{
			for (j = 0; j < length; j++)
			{
				for (k =0; k < width; k++)
				{
					//rs++;
					//if ( rs == interval && ProgressChanged != NULL )
					//{
					//	rs = 0;
					//	progressStep += interval;
					//	ProgressChanged (1, 100, (long long)( progressStep)*100/(globalProgressChanged + 
					//		(src->getZsize()/ret->getZsize()-1)*halfsize*2*ret->getXsize() * ret->getYsize()),flag);
					//}

					sum=0;
					float weight=0, total=0;
					for( l=i-halfsize; l<=i+halfsize; l++)
					{
						for(n=j-halfsize; n<=j+halfsize; n++)
						{
							for (int m = k - halfsize; m <= k + halfsize; m++ )
							{
								if(m >= 0 && m < width && n>=0 && n < length && l >= 0 && l < depth) 
								{
									//weight=1.0f/((m-i)*(m-i)+(n-i)*(n-i)+1);
									weight=1.0f/exp((float)((m-k)*(m-k)+(n-j)*(n-j) + (l-i)*(l-i) ));
									if (i == 250 && j == 407 && k == 0)
									{
										cout <<temp->get(i,j,k)<<endl;
									}
									sum += weight*(temp->get(m, n, l));
									total += weight;
								}
							}
						}
					}

					if(total!=0)
					{	
						sum /= total;//total is 1,regulation
						guass->put(k, j,i , (PIXTYPE)sum);


					}
					else  //should never come here
					{
						//cout << "total==0" << endl;
					}
				}//k...

			}//j...
		}//i...
		for (int i = 0; i < ret->size();i++ )
		{

			ret->putXYZ( i, guass->getXYZ(i + ret->getXsize()*ret->getYsize()) );
		}
		delete guass;
		delete temp;
	} 

	else if ( MULTITHREADFIRST|| MULTITHREADLAST )
	{
		if ( iter ==0 )
		{
			temp = new Raw(ret->getXsize(),ret->getYsize(),ret->getZsize()+ halfsize,src->getdata(),true);
			//puregauss(temp,rs,src,ret,halfsize,sum,globalProgressChanged,progressStep,ProgressChanged);
			globalProgressChanged = src->size();
			size_t interval = globalProgressChanged/1000 == 0? 1:globalProgressChanged/1000;
			//int rs = 0;
			bool flag = false;
			//Raw * _ret =new Raw(*temp);
			width = temp->getXsize();
			length = temp->getYsize();
			depth  = temp->getZsize();
			Raw *guass = new Raw(*temp);	///< The result of guass filter. 

			for (i = 0; i < depth; i++)
			{
				for (j = 0; j < length; j++)
				{
					for (k =0; k < width; k++)
					{
							//delete for qt gui 20140307
						//rs++;
						//if ( rs == interval && ProgressChanged != NULL )
						//{
						//	rs = 0;
						//	progressStep += interval;
						//	ProgressChanged (1, 100,(long long)( progressStep)*100/(globalProgressChanged + 
						//		(src->getZsize()/ret->getZsize()-1)*halfsize*2*ret->getXsize() * ret->getYsize()),flag);
						//}

						sum=0;
						float weight=0, total=0;
						for( l=i-halfsize; l<=i+halfsize; l++)
						{
							for(n=j-halfsize; n<=j+halfsize; n++)
							{
								for (int m = k - halfsize; m <= k + halfsize; m++ )
								{
									if(m >= 0 && m < width && n>=0 && n < length && l >= 0 && l < depth) 
									{
										//weight=1.0f/((m-i)*(m-i)+(n-i)*(n-i)+1);
										weight=1.0f/exp((float)((m-k)*(m-k)+(n-j)*(n-j) + (l-i)*(l-i) ));
										sum += weight*(temp->get(m, n, l));
										total += weight;
									}
								}
							}
						}

						if(total!=0)
						{	
							sum /= total;//total is 1,regulation
							guass->put(k, j,i , (PIXTYPE)sum);


						}
						else  //should never come here
						{
							//cout << "total==0" << endl;
						}
					}//k...

				}//j...
			}//i...
			for (int i =0; i < ret->size(); i++)
			{
				rs++;

				ret->putXYZ(i ,  guass->getXYZ(i));
			}


			delete guass;
			delete temp;
		} //...if first multi thread 
		else//last slice
		{
			temp = new Raw(ret->getXsize(),ret->getYsize(), ret->getZsize()+halfsize, 
				src->getdata() + iter*ret->getXsize()*ret->getYsize()*(src->getZsize()/(iter+1))-ret->getXsize()*ret->getYsize()*halfsize,true);
			//puregauss(temp,rs,src,ret,halfsize,sum,globalProgressChanged,progressStep,ProgressChanged);
			globalProgressChanged = src->size();
			size_t interval = globalProgressChanged/1000 == 0? 1:globalProgressChanged/1000;
			//int rs = 0;
			bool flag = false;
			//Raw * _ret =new Raw(*temp);
			width=temp->getXsize();
			length=temp->getYsize();
			depth = temp->getZsize();
			Raw *guass = new Raw(*temp);	///< The result of guass filter. 

			for (i = 0; i < depth; i++)
			{
				for (j = 0; j < length; j++)
				{
					for (k =0; k < width; k++)
					{
						//delete for qt gui
						//rs++;
						//if ( rs == interval && ProgressChanged != NULL )
						//{
						//	rs = 0;
						//	progressStep += interval;
						//	ProgressChanged (1, 100,(long long)( progressStep)*100/(globalProgressChanged + 
						//		(src->getZsize()/ret->getZsize()-1)*halfsize*2*ret->getXsize() * ret->getYsize()),flag);
						//}

						sum=0;
						float weight=0, total=0;
						for( l=i-halfsize; l<=i+halfsize; l++)
						{
							for(n=j-halfsize; n<=j+halfsize; n++)
							{
								for (int m = k - halfsize; m <= k + halfsize; m++ )
								{
									if(m >= 0 && m < width && n>=0 && n < length && l >= 0 && l < depth) 
									{
										//weight=1.0f/((m-i)*(m-i)+(n-i)*(n-i)+1);
										weight=1.0f/exp((float)((m-k)*(m-k)+(n-j)*(n-j) + (l-i)*(l-i) ));
										sum += weight*(temp->get(m, n, l));
										total += weight;
									}
								}
							}
						}

						if(total!=0)
						{	
							sum /= total;//total is 1,regulation
							guass->put(k, j,i , (PIXTYPE)sum);


						}
						else  //should never come here
						{
							//cout << "total==0" << endl;
						}
					}//k...

				}//j...
			}//i...
			for (int i =0; i < ret->size(); i++)
			{
				rs++;

				ret->putXYZ(i ,  guass->getXYZ(i + ret->getXsize()*ret->getYsize()*halfsize));//?????
			}
			delete guass;
			delete temp;
		}
		



	}
	else //single thread
	{
		temp = new Raw(ret->getXsize(),ret->getYsize(),ret->getZsize(),src->getdata(),true);
		//puregauss(temp,rs,src,ret,halfsize,sum,globalProgressChanged,progressStep,ProgressChanged);
		globalProgressChanged = src->size();
		size_t interval = globalProgressChanged/1000 == 0? 1:globalProgressChanged/1000;
		//int rs = 0;
		bool flag = false;
		//Raw * _ret =new Raw(*temp);
		width=temp->getXsize();
		length=temp->getYsize();
		depth = temp->getZsize();
		Raw *guass = new Raw(*temp);	///< The result of guass filter. 

		for (i = 0; i < depth; i++)
		{
			for (j = 0; j < length; j++)
			{
				for (k =0; k < width; k++)
				{
					rs++;
					if ( rs == interval && ProgressChanged != NULL )
					{
						rs = 0;
						progressStep += interval;
						ProgressChanged (1, 100,(long long)( progressStep)*100/(globalProgressChanged + 
							(src->getZsize()/ret->getZsize()-1)*halfsize*2*ret->getXsize() * ret->getYsize()),flag);
					}

					sum=0;
					float weight=0, total=0;
					for( l=i-halfsize; l<=i+halfsize; l++)
					{
						for(n=j-halfsize; n<=j+halfsize; n++)
						{
							for (int m = k - halfsize; m <= k + halfsize; m++ )
							{
								if(m >= 0 && m < width && n>=0 && n < length && l >= 0 && l < depth) 
								{
									//weight=1.0f/((m-i)*(m-i)+(n-i)*(n-i)+1);
									weight=1.0f/exp((float)((m-k)*(m-k)+(n-j)*(n-j) + (l-i)*(l-i) ));
									sum += weight*(temp->get(m, n, l));
									total += weight;
								}
							}
						}
					}

					if(total!=0)
					{	
						sum /= total;//total is 1,regulation
						guass->put(k, j,i , (PIXTYPE)sum);


					}
					else  //should never come here
					{
						//cout << "total==0" << endl;
					}
				}//k...

			}//j...
		}//i...
		for ( int i = 0; i < ret->size(); i ++)
		{

			ret->putXYZ(i , guass->getXYZ(i));
		}
		delete guass;
		delete temp;
	}
	

}
Ejemplo n.º 8
0
void puregauss(Raw *temp,int rs,Raw *src,Raw *ret,int halfsize,int sum,int globalProgressChanged,int progressStep,void (*ProgressChanged)(int,int ,int,bool&))
{
	size_t interval = globalProgressChanged/1000 == 0? 1:globalProgressChanged/1000;
	//int rs = 0;
	bool flag = false;
	//Raw * _ret =new Raw(*temp);
	int width = temp->getXsize();
	int length = temp->getYsize();
	int depth  = temp->getZsize();
	Raw *guass = new Raw(*temp);	///< The result of guass filter. 

	for (int i = 0; i < depth; i++)
	{
		for (int j = 0; j < length; j++)
		{
			for (int k =0; k < width; k++)
			{
				rs++;
				if ( rs == interval && ProgressChanged != NULL )
				{
					rs = 0;
					progressStep += interval;
					ProgressChanged (1, 100,(long long)( progressStep)*100/(globalProgressChanged + 
						(src->getZsize()/ret->getZsize()-1)*halfsize*2*ret->getXsize() * ret->getYsize()),flag);
				}

				sum=0;
				float weight=0, total=0;
				for( int l=i-halfsize; l<=i+halfsize; l++)
				{
					for(int n=j-halfsize; n<=j+halfsize; n++)
					{
						for (int m = k - halfsize; m <= k + halfsize; m++ )
						{
							if(m >= 0 && m < width && n>=0 && n < length && l >= 0 && l < depth) 
							{
								//weight=1.0f/((m-i)*(m-i)+(n-i)*(n-i)+1);
								weight=1.0f/exp((float)((m-k)*(m-k)+(n-j)*(n-j) + (l-i)*(l-i) ));
								sum += weight*(temp->get(m, n, l));
								total += weight;
							}
						}
					}
				}

				if(total!=0)
				{	
					sum /= total;//total is 1,regulation
					guass->put(k, j,i , (PIXTYPE)sum);


				}
				else  //should never come here
				{
					//cout << "total==0" << endl;
				}
			}//k...

		}//j...
	}//i...
	for (int i =0; i < ret->size(); i++)
	{
		rs++;

		ret->putXYZ(i ,  guass->getXYZ(i));
	}


	delete guass;
	delete temp;
}
Ejemplo n.º 9
0
void WipeNioisePde::Perona_MalikSipl(Raw *src,Raw *ret,int iter)
{
	//size_t progresstotal = src->size()*this->delt;
	//size_t progressstep = .size();
	globalProgressChanged = src->size();//*this->delt;
	float a=1,sum;
	int z,y,x,K,j,i;
	//Raw *d=new Raw(src->getXsize(),src->getYsize(),src->getZsize(),src->getdata());
	//Raw *d=new Raw(ret->getXsize(),ret->getYsize(),ret->getZsize(),ret->getdata());
	//Raw s=Raw(src);
	 Raw * temp;
	 float Maxvar;
	 if ( sizeof (PIXTYPE) == 1)
	 {
		 Maxvar = 255;
	 } 
	 else if ( sizeof (PIXTYPE) == 2)
	 {
		 //qym 2014-1-10
		 //Maxvar = 65536;
		 Maxvar = 65535;
	 } 
	 else 
	 {
		 //qym 2014-1-10
		 //Maxvar = 10000000;
		 Maxvar = std::numeric_limits<float>::max();
	 }
	if (iter > 0 && ( iter+1 )*ret->getZsize() < src->getZsize())
	{
		Raw *s = new Raw(ret->getXsize(), ret->getYsize(), ret->getZsize() + 2, src->getdata()+iter*ret->getXsize()*ret->getYsize()*(ret->getZsize())-ret->getXsize()*ret->getYsize());
		temp = new Raw(*s); 

		PIXTYPE *around =new PIXTYPE[6];
		//size_t threadtotal = s->size();
		size_t step = iter *ret->size();
		int call = 10000;
		bool flag = false;
	
		for (i = 0 ;i < delt; i++)
		{
			for (z = 1; z < s->getZsize()-1;z++)
			{
				for ( y = 1; y < s->getYsize()-1; y++)
				{
					for ( x = 1; x < s->getXsize()-1; x++)
					{

						around[0] = s->get(x-1,y,z)-s->get(x,y,z);
						around[1] = s->get(x,y-1,z)-s->get(x,y,z);
						around[2] = s->get(x,y,z-1)-s->get(x,y,z);
						around[3] = s->get(x+1,y,z-1)-s->get(x,y,z);
						around[4] = s->get(x,y+1,z)-s->get(x,y,z);
						around[5] = s->get(x,y,z+1)-s->get(x,y,z);
						sum=0;
						//swf 2014-1-9 for divide by zero
						if(val == 0)
							sum = 0;

						else 
						{
							for (int k=0; k < 6; k++)
							{
								//implementation sum(g(i)*f(i))
								sum += around[k]/(1 + around[k]*around[k]/(val*val));

							}
							float tempval = s->get(x,y,z) + a*sum/double(6);

							if (tempval <= Maxvar)
							{
								temp->put(x, y, z, tempval);
							} 
							else 
							{
								temp->put(x, y, z, s->get(x,y,z));
							}

						}//else val !=0...

					}//forx...
				}//fory...
				//cout << "times = :" << i << endl;
			}//for z...
			s = temp;
		}//for delta .....
		int interval = globalProgressChanged/1000 == 0 ? 1:globalProgressChanged /1000 ;//first call diygieshi0 houmianshi 1
		int rs = 0 ;
		//bool flag = false;
		for ( int i = 0; i < ret->size(); i ++)
		{

			rs ++;
			if ( rs == interval && ProgressChanged != NULL )
			{
				progressStep += interval;
				rs = 0;
				ProgressChanged (1, 100,(int) (long long)( progressStep)*100/(globalProgressChanged ),flag);
			}

			ret->putXYZ( i, temp->getXYZ(i + ret->getXsize() * ret->getYsize()) );
		}
		delete s;
	} 
	else
	{
		if ((iter == 0 && (iter+1)*ret->getZsize() !=  src->getZsize()) || ((iter+1)*ret->getZsize() >=  src->getZsize() && iter !=0 ))
		{
			/*
				two cases:
				one:number one time
				two:the last block of the multi thread 
			*/

			Raw *s;
			if (iter != 0)
			{
				 s= new Raw(ret->getXsize(),ret->getYsize(),ret->getZsize() + 1,
					src->getdata()+ iter*ret->getXsize()*ret->getYsize()*(src->getZsize()/(iter+1))-ret->getXsize()*ret->getYsize());
			} 
			else
			{
				s = new Raw(ret->getXsize(),ret->getYsize(),ret->getZsize() + 1,src->getdata());
			}
			
			temp = new Raw (*s);
			PIXTYPE *around=new PIXTYPE[6];
			for (i = 0 ;i < delt; i++)
			{
				for (z = 1; z < s->getZsize()-1;z++)
				{
					for ( y = 1; y < s->getYsize()-1; y++)
					{
						for ( x = 1; x < s->getXsize()-1; x++)
						{

							around[0]=s->get(x-1,y,z)-s->get(x,y,z);
							around[1]=s->get(x,y-1,z)-s->get(x,y,z);
							around[2]=s->get(x,y,z-1)-s->get(x,y,z);
							around[3]=s->get(x+1,y,z-1)-s->get(x,y,z);
							around[4]=s->get(x,y+1,z)-s->get(x,y,z);
							around[5]=s->get(x,y,z+1)-s->get(x,y,z);
							sum=0;

                            //qym 2014-1-8 for divide by zero
                            if(val == 0)
                                sum = 0;

							else
							{
								for (int k=0; k < 6; k++)
								{
									//implementation sum(g(i)*f(i))
									sum+=around[k]/(1+around[k]*around[k]/(val*val));

								}
								float tempval = s->get(x,y,z) + a*sum/double(6);
								if (tempval <= Maxvar)
								{
									temp->put(x, y, z, tempval);
								} 
								else 
								{
									temp->put(x, y, z, s->get(x,y,z));
								}
							}
						}//for x..

					}//for  y..

				}//forz..
				s = temp;
			}//for delta
			//size_t step = iter *ret->size();
			//int call = 10000;
			bool flag = false;
			int interval = globalProgressChanged/1000 == 0 ? 1:globalProgressChanged /1000 ;//first call diygieshi0 houmianshi 1
			int rs = 0 ;
			//bool flag = false;
			if (iter == 0)
			{
				int firstvar;
				if ( progressStep == 0 )
				{
					firstvar = 0;
				}
				else firstvar = 1;
				for ( int i = 0; i < ret->size(); i ++)
				{
					rs ++;
					
					if ( rs == interval && ProgressChanged != NULL )
					{

						progressStep += interval;
						rs = 0;
						ProgressChanged (firstvar, 100, (int) (long long)( progressStep)*100/(globalProgressChanged ), flag);
					}
					ret->putXYZ(i ,temp->getXYZ(i));
				}
			} 
			else//..iter!=0
			{
				int interval = globalProgressChanged/1000 == 0 ? 1:globalProgressChanged /1000 ;//first call diygieshi0 houmianshi 1
				int rs = 0 ;
				bool flag = false;

				for (int i = 0; i < ret->size(); i++)
				{
					rs++;
					if ( rs == interval && ProgressChanged != NULL )
					{
						progressStep += interval;
						rs = 0;
						ProgressChanged (1, 100,(int) (long long)( progressStep)*100/(globalProgressChanged ),flag);
					}
					ret->putXYZ(i ,temp->getXYZ(i + ret->getXsize()*ret->getYsize() ));
				}
			}//else ..._if iter =0

			delete s;
		}//if
		else
		{

			//P-M function  2nd-order PDE denoise
			PIXTYPE a=1,sum;
			int z,y,x,K,j,i;
			//Raw *d=new Raw(src->getXsize(),src->getYsize(),src->getZsize(),src->getdata());
			Raw *d=new Raw(src->getXsize(), src->getYsize(), src->getZsize(), src->getdata());
			temp = new Raw(*d);
			//Raw s=Raw(src);
			PIXTYPE *around=new PIXTYPE[6];

			for (i = 0 ;i < delt; i++)
			{
				for (z = 1; z < src->getZsize()-1;z++)
				{
					for ( y = 1; y < src->getYsize()-1; y++)
					{
						for ( x = 1; x < src->getXsize()-1; x++)
						{
							around[0]=d->get(x-1,y,z)-d->get(x,y,z);
							around[1]=d->get(x,y-1,z)-d->get(x,y,z);
							around[2]=d->get(x,y,z-1)-d->get(x,y,z);
							around[3]=d->get(x+1,y,z-1)-d->get(x,y,z);
							around[4]=d->get(x,y+1,z)-d->get(x,y,z);
							around[5]=d->get(x,y,z+1)-d->get(x,y,z);
							sum=0;
							//swf 2014-1-9 for divide by zero
							if(val == 0)
								sum = 0;
							else
							{
									for (int k=0; k < 6; k++)
									{
										//implementation sum(g(i)*f(i))
										sum += around[k]/(1 + around[k] * around[k]/(val * val));

									}
									float tempval = d->get(x,y,z) + a*sum/double(6);
									if ( tempval <= Maxvar )
									{
										temp->put(x, y, z, tempval);
									} 
									else 
									{
										temp->put(x, y, z, d->get(x,y,z));
									}
							}
						}//for
					}//for
					//cout << "times = :" << i << endl;
				}//for
				//d += s*(-1);
				d = temp;
			}//for delte
			//size_t step = iter *ret->size();
			int interval = globalProgressChanged/1000 == 0 ? 1:globalProgressChanged /1000 ;//first call diygieshi0 houmianshi 1
			int rs = 0 ;
			bool flag = false;
			//recover  data order from  x,z,y
			// 


			for ( int i = 0; i < ret->size(); i ++)
			{
				
				rs ++;
				if ( rs == interval && ProgressChanged != NULL )
				{
					progressStep += interval;
					rs = 0;
					ProgressChanged (1, 100,(int) (long long)( progressStep)*100/(globalProgressChanged ),flag);
				}
				ret->putXYZ(i , temp->getXYZ(i) );
			}
			delete d;
			//src = s;
			//return  d;
		}


	}
	//if (iter !=0 && (iter+1)*ret->getZsize() < src->getZsize())
	//{


	//} 
	//else if ((iter == 0 && (iter+1)*ret->getZsize() !=  src->getZsize())|| ((iter+1)*ret->getZsize() ==  src->getZsize()&& iter !=0 ))
	//{


	//} 
	//else
	//{


	//}


}