新建工程

  1. 工程设置
    • 右键或者在Project中点击Settings,打开设置界面
      • General中,设置:Not Using MFC(无界面的dll)
    • C/C++中
      • Catagory选择Code Generation,设置Use run-time library为Debug Multithreaded DLL
      • PreProcessor中,设置 Additional include directories为\openrs\desktop\include
    • Link中
      • General中是设置OutPutFIle Name 路径修改为\openRS\desktop\debug\vc60\Plugins\
      • 需要gdal等时,在input中,设置Addtional library path为\openRS\desktop\lib\vc60,\OpenRS\external\lib

添加文件orsXPlugin.cpp

orsXPlugin.cpp
#ifdef WIN32
#pragma warning(disable:4786)
#include <windows.h>
#endif
 
#include "orsBase/orsAlgInterface.h"
#include "orsBase/orsIExe.h"
#include <string>
 
//对象工厂声明,实现在orsXTest最后
orsIObject* createExeExampleObject(bool bForRegister);
 
#ifdef _WIN32
BOOL  APIENTRY DllMain( HANDLE hModule,
					  DWORD  ul_reason_for_call,
					  LPVOID lpReserved
					  )
{
    return TRUE;
}
#endif
//orsPluginInitializer类只要是继承orsIPlugin即可,需要调用ORS_REGISTER_PLUGIN宏来注册
class orsPluginInitializer: public orsIPlugin
{
public:
	//ID
	virtual const orsChar *getID()
	{
		return "org.openRS.pluginTest";
	};
	//插件名称
	virtual	const orsChar *getName()
	{
		return "pluginTest";
	};
	//作者
	virtual const orsChar *getProvider()
	{
		return "edu.whu.liesmars.guowei";
	};
	//版本
	virtual const orsChar *getVersion()
	{
		return "0.1";
	}
	//实现initialize函数
	virtual  bool initialize(orsIPlatform*  platform)
	{
		//注册服务
		//调用用createExeExampleObject函数
		//createExeExampleObject函数中创建一个实例,实例继承自orsIExeHelper,orsObjectBase
		platform->getRegisterService()->registerObject(createExeExampleObject);
		return true;
	}
 
	virtual void finalize()
	{
 
	}
};
//调用宏注册插件
ORS_REGISTER_PLUGIN(orsPluginInitializer)

添加orsXTest.cpp文件

orsXTest.cpp
#ifdef WIN32
#pragma warning(disable:4786)
#include <windows.h>
#endif
 
#include "Fill.h"
#include "orsBase/orsIExe.h"
#include "orsBase/orsIPlatform.h"
#include "orsImage/orsIImageData.h"
#include "orsImage/orsIImageChain.h"
#include "orsImage/orsIImageWriter.h"
#include "orsBase/orsIUtilityService.h"
ORS_GET_UTILITY_SERVICE_IMPL();  //getUtilityService() 声明
ORS_GET_IMAGE_SERVICE_IMPL();    //getImageService()
#include <string>
//如果需要在菜单中显示,需要多级继承
class orsISE_ExeExample: public orsISimpleExe
{
public:
	ORS_INTERFACE_DEF(orsISimpleExe, "Fusion");
};
//主要函数,继承实现
class orsExeExample : public orsIExeHelper<orsISE_ExeExample>, public orsObjectBase
{
private:
	orsString		m_outFileName; //输出文件默认名称
 
	orsString m_file1,m_file2; //输入影像名称
 
	ors_int32	m_fromRow;  //从xx行
	ors_int32	m_toRow;   //至xx行
 
	ors_int32	m_fromCol; //从xx列
	ors_int32	m_toCol;   //至xx列
 
	ref_ptr<orsIImageSource> m_FileOne;  //输入影像1
	ref_ptr<orsIImageSource> m_FileTwo;  //输入影像2
 
	ors_float64 m_tnum;     /////进行多波段修复′
	ors_int32  m_minnum;
 
	//需要多少影像就添加多少
 
	//orsString m_para1; //输入参数1,都为string类型,需要的话可以开放
	//orsString m_para2; //输入参数2
	//////////////////////////////////////////////////////////////////////////
	/*
 
	*/
	void ExecuteALR(int HeightAll,int WidthAll,int BandNum,bool m_check,byte **OutputImg)
	{
		int OverlapAll = 100; 
		int SizeAllH = 800;
		int SizeAllV = 800;
		int i,j,k;
		int Height = SizeAllH + 2*OverlapAll;  //真实计算的分块大小
		int Width = SizeAllV + 2*OverlapAll;  
		if(Height>HeightAll)
		{
			Height=HeightAll;	
			SizeAllH=HeightAll;
		}
		if(Width>WidthAll)
		{
			Width=WidthAll;	
			SizeAllV=WidthAll;
		}
		int SizeNumH, SizeNH, SizeNumW, SizeNW;
 
 
		SizeNumH = ceil(HeightAll/float(SizeAllH));  //分块的个数
		SizeNumW = ceil(WidthAll/float(SizeAllV));
 
		orsBandSet bandSet;//波段数组 相当于[0,1,2...]
		int iBand;
		for( iBand=0; iBand<BandNum; iBand++ )
			bandSet.push_back( iBand );
 
		for(SizeNH=0;SizeNH<SizeNumH;SizeNH++)
		{
			if (SizeNumH>1)
			{
				if (SizeNH==0)
				{
					Height = SizeAllH + OverlapAll;
				}
				else
				{
					Height = SizeAllH + 2*OverlapAll;
				}		
 
			}
 
 
			for(SizeNW=0;SizeNW<SizeNumW;SizeNW++)
			{
 
				if (SizeNumW>1)
				{
					if (SizeNW==0)
					{
						Width = SizeAllV + OverlapAll;
					}
					else
					{
						Width = SizeAllV + 2*OverlapAll;
					}
				}
 
				float **Inputimg1f = new float*[BandNum];
				double **Inputimg1 = new double*[BandNum];
 
				if (SizeNW==SizeNumW-1 && SizeNumW>1)
				{
					Width=WidthAll-SizeNW*SizeAllV+OverlapAll;
				}
				else if (Width>WidthAll-SizeNW*SizeAllV)
				{
					Width=WidthAll-SizeNW*SizeAllV+OverlapAll;
				}
				else if(Width>WidthAll)
				{
					Width=WidthAll;	
					SizeAllV=WidthAll;
				}
 
 
				if (SizeNH==SizeNumH-1 && SizeNumH>1)
				{
					Height=HeightAll-SizeNH*SizeAllH+OverlapAll;
				}
				else if (Height>HeightAll-SizeNH*SizeAllH)
				{
					Height=HeightAll-SizeNH*SizeAllH+OverlapAll;
				}
				else if(Height>HeightAll)
				{
					Height=HeightAll;	
					SizeAllH=HeightAll;
				}
 
 
				int PosW, PosH;
 
				PosW=SizeNW*SizeAllV-OverlapAll;
				PosH=SizeNH*SizeAllH-OverlapAll;
 
				if (PosW<0)
				{
					PosW=0;
				}
 
				if (PosH<0)
				{
					PosH=0;
				}
 
				int ImgSize = Height*Width;
				orsRect_i roi( PosW, PosH,Width,Height);
 
				orsIImageData *inData = m_FileOne->getImageData(roi,1,bandSet);
 
				for(j=0;j<BandNum;j++)
				{
					Inputimg1f[j] = new float[ImgSize];
					Inputimg1[j] = new double[ImgSize];
					//	HRSBAND hInBand1 = InImg1.GetBand(j);
					//	if(!InImg1.ReadBlock(hInBand1,PosW, PosH, Width, Height, 1,Inputimg1f[j],(*fnProgress)))
					//	{
					//		SetLastErrorInfo(RS_Failure,"影像读取失败!");
					//	}
					inData->buf2Float(j,Inputimg1f[j]);
					for (i=0; i<Width*Height; i++)
					{
						Inputimg1[j][i]=double(Inputimg1f[j][i]);
					}
				}
				for(j=0;j<BandNum;j++)
				{
					delete []Inputimg1f[j];
				}
				delete []Inputimg1f;
 
 
				float **Inputimg2f = new float*[BandNum];
				double **Inputimg2 = new double*[BandNum];
				orsIImageData *inData2 = m_FileTwo->getImageData(roi,1,bandSet);
 
				for(j=0;j<BandNum;j++)
				{
					Inputimg2f[j] = new float[ImgSize];
					Inputimg2[j] = new double[ImgSize];
			//		HRSBAND hInBand2 = InImg2.GetBand(j);
			//		if(!InImg2.ReadBlock(hInBand2,PosW, PosH, Width, Height, 1,Inputimg2f[j],(*fnProgress)))
			//		{
			//			SetLastErrorInfo(RS_Failure,"影像读取失败!");
			//		}
					inData2->buf2Float(j,Inputimg2f[j]);
					for (int i=0; i<Width*Height; i++)
					{
						Inputimg2[j][i]=double(Inputimg2f[j][i]);
					}
				}
				for(j=0;j<BandNum;j++)
				{
					delete []Inputimg2f[j];
				}
				delete []Inputimg2f;
 
			//////////////////////////////////////////////////////////////////////////
 
 				////处理处理处理处理处理处理处理处理处理处理处理处理处理处理处理
.............
............
...........
..........
 
 				////处理处理处理处理处理处理处理处理处理处理处理处理处理处理处理
 
 
				//释放内存
 
				for( j=0;j<BandNum;j++)
				{
					delete []Inputimg1[j];
					delete []Inputimg2[j];
					delete []OutputImg1[j];
					delete []OutputImgf[j];
					delete []OutputImg2[j];
					delete []Weight[j];
					delete []Bias[j];
					delete []Gain[j];
 
			//		delete []refer[j];
				}
				delete []Inputimg1;
				delete []Inputimg2;
				delete []OutputImg1;
				delete []OutputImgf;
				delete []OutputImg2;
				delete []Weight;
				delete []Bias;
				delete []Gain;
 				delete []GapMask1;
 				delete []GapMask2;
				delete []mark;
			//	delete []refer;
			}
		}
	}
public:
	//初始化设置默认参数,即界面启动后,显示在界面上参数
	orsExeExample( bool bForRegister ) : orsIExeHelper<orsISE_ExeExample>(bForRegister)
	{
		if( !bForRegister )
		{
			m_tnum = 0.5;
			m_minnum = 30;
			orsString m_inFileName,m_inFileName2; //默认输入文件名,为空,可以设置,为直接路径
 
			m_outFileName = _T("test:filenameOut" );//默认输出文件名
 
			m_inputFileNames->addAttr( "inputFileName", m_inFileName );//添加输入文件1,参数为"inputFileName",下面获取输入文件名参数时,即用此字符串获取输入文件名,下同
			m_inputFileNames->addAttr( "inputFileName2", m_inFileName2);
 
			m_parameterArgs->addAttr( "tnum", m_tnum ); //添加默认参数
			m_parameterArgs->addAttr( "minnum", m_minnum ); //添加默认参数2
 
			m_outputFileNames->addAttr( "outputFileName", m_outFileName ); //添加输出文件参数
 
			// 都为零,代表整个影像
			m_fromRow = m_toRow = 0;
			m_fromCol = m_toCol = 0;
		}
	}
 
 
	virtual ~orsExeExample()
	{
	}
 
 
	//获取参数,在点击运行的时候获取
	virtual bool setArguments( orsIProperty *inputFileNames, orsIProperty *parameters, orsIProperty *outputFileNames )
	{
		//获取第一个影像,将字符串放入m_file1中,下同
		//getAttr(orsString "paraName",out orsString para)
		inputFileNames->getAttr( "inputFileName", m_file1 );
		inputFileNames->getAttr("inputFileName2", m_file2);//获取第二个影像
 
		outputFileNames->getAttr( "outputFileName", m_outFileName );//获取输出路径
 
		m_parameterArgs->getAttr( "tnum", m_tnum );
		m_parameterArgs->getAttr( "minnum", m_minnum );
 
		return true;
	}
 
 
	//执行,即原来框架中读入影像,处理,然后输出影像过程
	virtual ref_ptr<orsIProperty> execute(orsIProcessMsg *process)
	{
		//返回值
		ref_ptr<orsIProperty> jobOutput = getPlatform()->createProperty();		
		jobOutput->addAttr("out:fileName", m_outFileName );
 
		////原来框架中获取输入影像部分:
		//1.获取输入影像
		m_FileOne = getImageService()->openImageFile( m_file1 );
		m_FileTwo = getImageService()->openImageFile( m_file2 );
		//2.获得影像波段
		int BandNum = m_FileOne->getNumberOfOutputBands(); //
 
		int WidthAll, HeightAll;
		//3.获得影像宽度、高度
		WidthAll = m_FileOne->getWidth();
		HeightAll = m_FileOne->getHeight();
		//4.获取影像大小
		int ImgSize = HeightAll*WidthAll;
 
		if( m_toRow <= m_fromRow )
			m_toRow = HeightAll;
 
		if( m_toCol <= m_fromCol )
			m_toCol = WidthAll;
		//5.创建一个影像一样大的矩形
		orsRect_i roi( m_fromCol, m_fromRow, m_toCol, m_toRow );
		//6.数据读取到数组中,准备处理
		byte **OutputImg = new byte*[BandNum];
		for(int j=0;j<BandNum;j++)
		{
			OutputImg[j] = new byte[ImgSize];
		}
 
		/*
		//第一个影像 读取
		float **Inputimg1 = new float*[BandNum];
		//获取所有波段的数据
		orsIImageData *inData1 = m_FileOne->getImageData( roi, 1, bandSet );
		for(int j=0;j<BandNum;j++)
		{
			Inputimg1[j] = new float[ImgSize];
			//将波段数据写入Inputimg1中,默认全是float类型,读取时需要注意
                        //如果需要其他的类型,请将float数组手动转换
			inData1->buf2Float(j,Inputimg1[j] );
		}
		//第二个影像
		float **Inputimg2 = new float*[BandNum];
		orsIImageData *inData2 = m_FileTwo->getImageData( roi, 1, bandSet );
		for(j=0;j<BandNum;j++)
		{
			Inputimg2[j] = new float[ImgSize];
			inData2->buf2Float(j,Inputimg2[j]);
		}
		*/
//该部分即原框架中的处理部分
///处理处理处理处理处理处理处理处理处理处理处理处理处理处理处理处理
		ExecuteALR(HeightAll,WidthAll,BandNum,false,OutputImg);
///处理处理处理处理处理处理处理处理处理处理处理处理处理处理处理处理
 
		//7.创建输出文件
		ref_ptr<orsIImageWriter> outImg = ORS_CREATE_OBJECT(orsIImageWriter, ORS_IMAGE_WRITER_DEFAULT );
		if( !outImg->Create( m_outFileName, m_FileOne.get(), roi,  BandNum ) )	{
			getPlatform()->logPrint(ORS_LOG_ERROR, "Can not create image %s", m_outFileName.c_str() );
			return jobOutput;
		}
		//8.写入输出
		for(int iBand =0; iBand<BandNum; iBand++ )
		{
			outImg->WriteBandRect( iBand,0, 0, roi.width(), roi.height(), OutputImg[iBand]);					
		}		
		//9.delete
		for(int j=0;j<BandNum;j++)
		{
			delete []OutputImg[j];
		}
 
		delete []OutputImg;
 
		//进度条显示,0-1表示,可以在处理过程中添加
		process->process( 1 );	
		return jobOutput;
	}
 
 
	virtual orsArray<ref_ptr<orsIProperty> > getTasks()
	{
		orsArray<ref_ptr<orsIProperty> > tasks;
		return tasks;
	};
 
 
	//通过Job信息和Task信息进行计算得到输出信息,taskOutput在外部分配内存<map>
	virtual ref_ptr<orsIProperty> taskExecute(ref_ptr<orsIProperty> taskInput,orsIProcessMsg *process)
	{
		return NULL;
	};
 
	//进行子任务合并<reduce>
	virtual ref_ptr<orsIProperty> taskCombine(orsArray<ref_ptr<orsIProperty> > taskInputs,orsIProcessMsg *process)
	{
		return NULL;
	};
 
	//注册对象,在菜单下将显示为pluginTest的子菜单:“fill”
	ORS_OBJECT_IMP3(orsExeExample,orsISE_ExeExample, orsISimpleExe, orsIExecute, "ALR", "Simple fill Exe");
};
//createExeExampleObject实现
orsIObject* createExeExampleObject(bool bForRegister)
{
	return new orsExeExample( bForRegister );
}

添加原来的处理数据的类:fill.h和fill.cpp

该部分可以直接移植文件过来,只要在上面的实现中添加include即可

fill.h
// Fill.h: interface for the CFill class.
//
//////////////////////////////////////////////////////////////////////
 
#if !defined(AFX_FILL_H__FDDC0F42_9F87_4F79_9687_36FFD2D267E8__INCLUDED_)
#define AFX_FILL_H__FDDC0F42_9F87_4F79_9687_36FFD2D267E8__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
 
class CFill  
{
public:
	CFill();
	virtual ~CFill();
//	void ALR(double *input1, double *input2, int hi, int wj, int Height, int Width, byte &output, double &bias, double &gain, double &weight);
 
	void NSWR(double **input1, double **input2, bool *mask1, bool *mask2,int bandnum, int Height, int Width, byte **output, 
		byte **output2, double **bias, double **gain, double **weight, byte *mark, double tnum, int minnum);
 
	void Wallis(double *input1, double *input2, int hi, int wj, int Height, int Width, byte &output, double &bias, double &gain, double &weight);
	void GetBiasandGain(double *input1, double *input2, double *weight, int Height, int Width, double *A, double *B);
	void CalBG(double *input1, double *input2, double &diff, int Height, int Width, int hi, int wj, double &A, double &B);
	void GetWeight(byte *input1, double *input2, double *Weight, int Height, int Width);
	void MatrixTransposemByn(double *input ,int m, int n, double *output);
	bool MatrixInversenByn(double *input, int n);
	void Retrieving(double *input, double *output, int num, double *Relationship);
	void MultiplymBynandnByp(double *Mult1, double *Mult2, double *output, int m, int n, int p);
	void CalcuRela(double *input1, double *input2, int num, double *Relationship);
	bool DestripModelGainBias2(double *X,double *Y,double *Weight,double *A,double *B,int Height,int Width,char *RegType,double MostWeight);
	bool DestripModelGainBiasCG(double *X,double *Y,double *Weight,double *A,double *B,int Height,int Width,char *RegType,double MostWeight);
 
	bool DestripModelGainBias3(double **X,double **Y,double ** Relation, double ** RCoe, double **Weight,double **A,double **B,
		int BandNum,int Height,int Width,char *RegType,double SpatialWeight, double SpectWeight);
 
	bool Constrain_Amp22(double *X, int n, double Max, double Min);
	void RegularFuc(double *X,double *ReguX,long Height, long Width);
	bool GetHMRFDiff(int Height,int Width,double * X,double *Result,double *Y,double a,int DiffNum,double scale);
	double HuberFucValue(double *X,int Height,int Width,double a, double scale);
	void HMRFDiffFuc22(double * X,double *Result,double *Y,int ImageSize,double a,int Index,int Index1,int Index2,
				  double scale,int DiffNum);
	double HMRFEdgeFuc22(double x,double a);
 
	double CoeofDet(double *X, double *Y, double *Weight, double a, double b, double mY, int n);
//	double ReleCoefficient(double *X,double *Y, double *Weight,double mx, double my,int N);
 
	void GapMasking(double **input, bool *output, int ImgSize, int BandNum);
 
	void BandRela(double **input, double **Relation, double ** RCoe, int BandNum, int thisband, int Height, int Width);
 
 
 
};
 
#endif // !defined(AFX_FILL_H__FDDC0F42_9F87_4F79_9687_36FFD2D267E8__INCLUDED_)