Simplify printing procedures

Use opencv's print() procedure in place of my own procedures to output
matrices and std::vectors.

Interestingly enough, operator<< does not work for matrices, when called
from my .cpp files in src/ subfolder of the optim module, although it
works when called from tests and stand-alone programs, compiled with
opencv. I think, this requires investigation and, maybe, bug report.
pull/1192/head
Alex Leontiev 12 years ago
parent 459c16ca99
commit 33e7640fb0
  1. 1
      modules/optim/include/opencv2/optim.hpp
  2. 54
      modules/optim/src/lpsolver.cpp

@ -44,7 +44,6 @@
#define __OPENCV_OPTIM_HPP__ #define __OPENCV_OPTIM_HPP__
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include <iostream>
namespace cv{namespace optim namespace cv{namespace optim
{ {

@ -12,20 +12,8 @@ using namespace std;
#ifdef ALEX_DEBUG #ifdef ALEX_DEBUG
#define dprintf(x) printf x #define dprintf(x) printf x
static void print_matrix(const Mat& x){ static void print_matrix(const Mat& x){
printf("\ttype:%d vs %d,\tsize: %d-on-%d\n",x.type(),CV_64FC1,x.rows,x.cols); print(x);
if(!true){ printf("\n");
//cout<<x;
}
else{
for(int i=0;i<x.rows;i++){
printf("\t[");
for(int j=0;j<x.cols;j++){
printf("%g, ",x.at<double>(i,j));
}
printf("]\n");
}
}
} }
static void print_simplex_state(const Mat& c,const Mat& b,double v,const std::vector<int> N,const std::vector<int> B){ static void print_simplex_state(const Mat& c,const Mat& b,double v,const std::vector<int> N,const std::vector<int> B){
printf("\tprint simplex state\n"); printf("\tprint simplex state\n");
@ -36,18 +24,14 @@ static void print_simplex_state(const Mat& c,const Mat& b,double v,const std::ve
print_matrix(c); print_matrix(c);
printf("non-basic: "); printf("non-basic: ");
for (std::vector<int>::const_iterator it = N.begin() ; it != N.end(); ++it){ print(Mat(N));
printf("%d, ",*it);
}
printf("\n"); printf("\n");
printf("here b goes\n"); printf("here b goes\n");
print_matrix(b); print_matrix(b);
printf("basic: "); printf("basic: ");
for (std::vector<int>::const_iterator it = B.begin() ; it != B.end(); ++it){ print(Mat(B));
printf("%d, ",*it);
}
printf("\n"); printf("\n");
} }
#else #else
@ -85,23 +69,8 @@ int solveLP(const Mat& Func, const Mat& Constr, Mat& z){
if(Func.rows==1){ if(Func.rows==1){
Func.convertTo(bigC.colRange(1,bigC.cols),CV_64FC1); Func.convertTo(bigC.colRange(1,bigC.cols),CV_64FC1);
}else{ }else{
dprintf(("hi from other branch\n")); Mat FuncT=Func.t();
Mat_<double> slice=bigC.colRange(1,bigC.cols); FuncT.convertTo(bigC.colRange(1,bigC.cols),CV_64FC1);
MatIterator_<double> slice_iterator=slice.begin();
switch(Func.type()){
case CV_64FC1:
for(MatConstIterator_<double> it=Func.begin<double>();it!=Func.end<double>();it++,slice_iterator++){
* slice_iterator= *it;
}
break;
case CV_32FC1:
for(MatConstIterator_<float> it=Func.begin<float>();it!=Func.end<double>();it++,slice_iterator++){
* slice_iterator= *it;
}
break;
}
print_matrix(Func);
print_matrix(bigC);
} }
Constr.convertTo(bigB.colRange(1,bigB.cols),CV_64FC1); Constr.convertTo(bigB.colRange(1,bigB.cols),CV_64FC1);
double v=0; double v=0;
@ -286,14 +255,9 @@ static int inner_simplex(Mat_<double>& c, Mat_<double>& b,double& v,vector<int>&
dprintf(("constraints\n")); dprintf(("constraints\n"));
print_matrix(b); print_matrix(b);
dprintf(("non-basic: ")); dprintf(("non-basic: "));
for (std::vector<int>::iterator it = N.begin() ; it != N.end(); ++it){ print_matrix(Mat(N));
dprintf(("%d, ",*it)); dprintf(("basic: "));
} print_matrix(Mat(B));
dprintf(("\nbasic: "));
for (std::vector<int>::iterator it = B.begin() ; it != B.end(); ++it){
dprintf(("%d, ",*it));
}
dprintf(("\n"));
} }
} }

Loading…
Cancel
Save