⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bocostfunctionmex.cpp

📁 解决线性assignment的算法
💻 CPP
字号:
/***************************************************************************
 *   Copyright (C) 2008 by Boguslaw Obara                                  *
 *   http://boguslawobara.net                                              *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <vector>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "BOCostFunction.h"
#include "BOMatrix.h"

using namespace std;

extern "C" {
	#include "mex.h"
}
//------------------------------------------------------------------------------
// function: mex_bimread - entry point from Matlab via mexFucntion()
// INPUTS:
//   nlhs 		- number of left hand side arguments (outputs)
//   plhs[] 	- pointer to table where created matrix pointers are
//            		to be placed
//   nrhs 		- number of right hand side arguments (inputs)
//   prhs[] 	- pointer to table of input matrices
//------------------------------------------------------------------------------

//mex BOLogPolarHistMex.cpp BOLogPolarHist.cpp BOMatrix.cpp
//H = BOLogPolarHistMex( p_x, p_y, nr, nw);

void BOCostFunctionMex( int nlhs, mxArray *plhs[], int nrhs, const mxArray  *prhs[] )
{
	// Check for proper number of input and output arguments
	if (nrhs < 1) mexErrMsgTxt("Input arguments required. Usage: = BOCostFunctionMex(H1, H2).");
	if (nlhs < 1) mexErrMsgTxt("One output argument required. Usage: C = BOCostFunctionMex.");
	if (nrhs > 2) mexErrMsgTxt("Too many input arguments.");
	if (nlhs > 1) mexErrMsgTxt("Too many output arguments.");
	//-----------------------------------------------------------
	// get input
	//-----------------------------------------------------------
	

	if (nrhs > 0 && nlhs > 0) {
		printf("BOCostFunctionMex -> Start  :)\n");	

		// get inputs
		//-----------------------------------------------------------
		//Get matrix H1 and H2
		double* HValues1 = mxGetPr(prhs[0]);
		int r1 = mxGetN(prhs[0]);
		int c1 = mxGetM(prhs[0]);
		double* HValues2 = mxGetPr(prhs[1]);
		int r2 = mxGetN(prhs[1]);
		int c2 = mxGetM(prhs[1]);
		printf("r: c:  %d  %d\n", r1,c1);

		if ( r1==r2 && c1==c2) {
			BOMatrix<double> Hist1(c1,r1);
			BOMatrix<double> Hist2(c2,r2);
			//printf("Array: %d , %d ",assigncostrowLen, assigncostcolLen);
			for(int i=0;i<r1;i++)
				for(int j=0;j<c1;j++)
					Hist1[j][i] = (int)HValues1[(i*c1)+j];
	
			for(int i=0;i<r2;i++)
				for(int j=0;j<c2;j++)
					Hist2[j][i] = (int)HValues2[(i*c2)+j];
			// create output
			//-----------------------------------------------------------
			//double *HistD = new double [xcolLen*nr*nw];
			//plhs[0]    = mxCreateDoubleMatrix(xcolLen, nr*nw, mxREAL);
			//HistD = mxGetPr(plhs[0]);
			const int dims[] = { c1, c1};
			mxClassID t = mxDOUBLE_CLASS;
			plhs[0] = mxCreateNumericArray( 2, dims, t, mxREAL);
			double *Cost = (double *) mxGetData(plhs[0]);
			for(int j=0;j<r1;j++)
				for(int i=0;i<c1;i++){
					//*Cost = Hist1[i][j];
					//++Cost;
				}	


			// run
			//-----------------------------------------------------------
			BOCostFunction* costF = new BOCostFunction();
			BOMatrix<double> CostF = costF->Run(Hist1, Hist2);
			for(int j=0;j<c1;j++)
				for(int i=0;i<c2;i++){
					*Cost = CostF[i][j];
					++Cost;
				}
			//vector<double> xp = lph->ReadFromFile("files/x.txt");
			//vector<double> yp = lph->ReadFromFile("files/y.txt");
			//int nr =5, nw = 12;
			printf("BOCostFunctionMex -> Finished :)\n");
		}	
		else
 			mexErrMsgTxt("Usage: = BOCostFunctionMex(H1, H2), the size of H1 and H2 should be the same!");
	}
	//-----------------------------------------------------------
}


extern "C" {
  //--------------------------------------------------------------
  // mexFunction - Entry point from Matlab. From this C function,
  //   simply call the C++ application function, above.
  //--------------------------------------------------------------
  void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray  *prhs[] )
  {
    BOCostFunctionMex(nlhs, plhs, nrhs, prhs);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -