Ejemplo n.º 1
0
static int EmptyPoly() {
  struct geod_geodesic g;
  struct geod_polygon p;
  double perim, area;
  int result = 0;
  geod_init(&g, wgs84_a, wgs84_f);
  geod_polygon_init(&p, 0);
  geod_polygon_testpoint(&g, &p, 1, 1, 0, 1, &area, &perim);
  result += area == 0 ? 0 : 1;
  result += perim == 0 ? 0 : 1;
  geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, &area, &perim);
  result += checkNaN(area);
  result += checkNaN(perim);
  geod_polygon_compute(&g, &p, 0, 1, &area, &perim);
  result += area == 0 ? 0 : 1;
  result += perim == 0 ? 0 : 1;
  geod_polygon_init(&p, 1);
  geod_polygon_testpoint(&g, &p, 1, 1, 0, 1, nullptr, &perim);
  result += perim == 0 ? 0 : 1;
  geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, nullptr, &perim);
  result += checkNaN(perim);
  geod_polygon_compute(&g, &p, 0, 1, nullptr, &perim);
  result += perim == 0 ? 0 : 1;
  geod_polygon_addpoint(&g, &p, 1, 1);
  geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, nullptr, &perim);
  result += checkEquals(perim, 1000, 1e-10);
  geod_polygon_testpoint(&g, &p, 2, 2, 0, 1, nullptr, &perim);
  result += checkEquals(perim, 156876.149, 0.5e-3);
  return result;
}
Ejemplo n.º 2
0
static int Planimeter19() {
  /* Coverage tests, includes Planimeter19 - Planimeter20 (degenerate
     polygons) + extra cases.  */
  struct geod_geodesic g;
  struct geod_polygon p;
  double area, perim;
  int result = 0;
  geod_init(&g, wgs84_a, wgs84_f);
  geod_polygon_init(&p, 0);
  geod_polygon_compute(&g, &p, 0, 1, &area, &perim);
  result += area == 0 ? 0 : 1;
  result += perim == 0 ? 0 : 1;
  geod_polygon_testpoint(&g, &p, 1, 1, 0, 1, &area, &perim);
  result += area == 0 ? 0 : 1;
  result += perim == 0 ? 0 : 1;
  geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, &area, &perim);
  result += checkNaN(area);
  result += checkNaN(perim);
  geod_polygon_addpoint(&g, &p, 1, 1);
  geod_polygon_compute(&g, &p, 0, 1, &area, &perim);
  result += area == 0 ? 0 : 1;
  result += perim == 0 ? 0 : 1;
  geod_polygon_init(&p, 1);
  geod_polygon_compute(&g, &p, 0, 1, nullptr, &perim);
  result += perim == 0 ? 0 : 1;
  geod_polygon_testpoint(&g, &p, 1, 1, 0, 1, nullptr, &perim);
  result += perim == 0 ? 0 : 1;
  geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, nullptr, &perim);
  result += checkNaN(perim);
  geod_polygon_addpoint(&g, &p, 1, 1);
  geod_polygon_compute(&g, &p, 0, 1, nullptr, &perim);
  result += perim == 0 ? 0 : 1;
  return result;
}
Ejemplo n.º 3
0
static int GeodSolve14() {
  /* Check fix for inverse ignoring lon12 = nan */
  double azi1, azi2, s12, nan;
  struct geod_geodesic g;
  int result = 0;
  {
    double minus1 = -1;
    /* cppcheck-suppress wrongmathcall */
    nan = sqrt(minus1);
  }
  geod_init(&g, wgs84_a, wgs84_f);
  geod_inverse(&g, 0, 0, 1, nan, &s12, &azi1, &azi2);
  result += checkNaN(azi1);
  result += checkNaN(azi2);
  result += checkNaN(s12);
  return result;
}
Ejemplo n.º 4
0
void writeResidual(solver *Solver, input *params)
{
  vector<double> res(params->nFields), resTmp(params->nFields);
  int iter = params->iter;

  for (auto& e:Solver->eles) {
    resTmp = e.getResidual(params->resType);
    if(checkNaN(resTmp)) FatalError("NaN Encountered in Solution Residual!");

    for (int i=0; i<params->nFields; i++) {
      if (params->resType == 3) {
        // Infinity norm [max residual over all spts]
        res[i] = max(res[i],resTmp[i]);
      }else{
        res[i] += resTmp[i];
      }
    }
  }

  // If taking 2-norm, res is sum squared; take sqrt to complete
  if (params->resType == 2) {
    for (auto& i:res) i = sqrt(i);
  }

  int colW = 16;
  cout.precision(8);
  cout.setf(ios::fixed, ios::floatfield);
  if (iter==1 || (iter/params->monitor_res_freq)%25==0) {
    cout << endl;
    cout << setw(8) << left << "Iter";
    if (params->equation == ADVECTION_DIFFUSION) {
      cout << " Residual " << endl;
    }else if (params->equation == NAVIER_STOKES) {
      cout << setw(colW) << left << "rho";
      cout << setw(colW) << left << "rhoU";
      cout << setw(colW) << left << "rhoV";
      cout << setw(colW) << left << "rhoE";
    }
    cout << endl;
  }

  cout << setw(8) << left << iter;
  for (int i=0; i<params->nFields; i++) {
    cout << setw(colW) << left << res[i];
  }
  cout << endl;
}
Ejemplo n.º 5
0
static int GeodSolve80() {
  /* Some tests to add code coverage: computing scale in special cases + zero
     length geodesic (includes GeodSolve80 - GeodSolve83) + using an incapable
     line. */
  double a12, s12, azi1, azi2, m12, M12, M21, S12;
  struct geod_geodesic g;
  struct geod_geodesicline l;
  int result = 0;
  geod_init(&g, wgs84_a, wgs84_f);
  geod_geninverse(&g, 0, 0, 0, 90, nullptr, nullptr, nullptr, nullptr, &M12, &M21, nullptr);
  result += checkEquals(M12, -0.00528427534, 0.5e-10);
  result += checkEquals(M21, -0.00528427534, 0.5e-10);
  geod_geninverse(&g, 0, 0, 1e-6, 1e-6, nullptr, nullptr, nullptr, nullptr, &M12, &M21, nullptr);
  result += checkEquals(M12, 1, 0.5e-10);
  result += checkEquals(M21, 1, 0.5e-10);
  a12 = geod_geninverse(&g, 20.001, 0, 20.001, 0,
                        &s12, &azi1, &azi2, &m12, &M12, &M21, &S12);
  result += checkEquals(a12, 0, 1e-13);
  result += checkEquals(s12, 0, 1e-8);
  result += checkEquals(azi1, 180, 1e-13);
  result += checkEquals(azi2, 180, 1e-13);
  result += checkEquals(m12, 0,  1e-8);
  result += checkEquals(M12, 1, 1e-15);
  result += checkEquals(M21, 1, 1e-15);
  result += checkEquals(S12, 0, 1e-10);
  a12 = geod_geninverse(&g, 90, 0, 90, 180,
                        &s12, &azi1, &azi2, &m12, &M12, &M21, &S12);
  result += checkEquals(a12, 0, 1e-13);
  result += checkEquals(s12, 0, 1e-8);
  result += checkEquals(azi1, 0, 1e-13);
  result += checkEquals(azi2, 180, 1e-13);
  result += checkEquals(m12, 0, 1e-8);
  result += checkEquals(M12, 1, 1e-15);
  result += checkEquals(M21, 1, 1e-15);
  result += checkEquals(S12, 127516405431022, 0.5);
  /* An incapable line which can't take distance as input */
  geod_lineinit(&l, &g, 1, 2, 90, GEOD_LATITUDE);
  a12 = geod_genposition(&l, 0, 1000, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
  result += checkNaN(a12);
  return result;
}
Ejemplo n.º 6
0
static int GeodSolve55() {
  /* Check fix for nan + point on equator or pole not returning all nans in
   * Geodesic::Inverse, found 2015-09-23. */
  double azi1, azi2, s12, nan;
  struct geod_geodesic g;
  int result = 0;
  {
    double minus1 = -1;
    /* cppcheck-suppress wrongmathcall */
    nan = sqrt(minus1);
  }
  geod_init(&g, wgs84_a, wgs84_f);
  geod_inverse(&g, nan, 0, 0, 90, &s12, &azi1, &azi2);
  result += checkNaN(azi1);
  result += checkNaN(azi2);
  result += checkNaN(s12);
  geod_inverse(&g, nan, 0, 90, 9, &s12, &azi1, &azi2);
  result += checkNaN(azi1);
  result += checkNaN(azi2);
  result += checkNaN(s12);
  return result;
}
Ejemplo n.º 7
0
v4r::meanVal BoundaryRelationsMeanDepth::compute()
{
  //@ep: TODO check reconditions
  if(!have_cloud)
  {
    printf("[BoundaryRelationsMeanDepth::compute] Error: No input cloud set.\n");
    exit(0);
  }

  if(!have_boundary)
  {
    printf("[BoundaryRelationsMeanDepth::compute] Error: No input border.\n");
    exit(0);
  }
  
  v4r::meanVal meanDepth;
  
  if(boundary.size() <= 0)
  {
    printf("[BoundaryRelationsMeanDepth::compute] Warning: Boundary size is 0. This means that constants are different everywhere!\n");
    meanDepth.mean = 0;
    meanDepth.stddev = 0;
    return meanDepth;
  }

  int boundaryLength = boundary.size();

  // calculate mean depth
  double totalDepth = 0.;
  double totalDepthStdDev = 0.;
  std::vector<double> valuesDepth;
  valuesDepth.reserve(boundaryLength);
  for(unsigned int i=0; i<boundary.size(); i++)
  {
    pcl::PointXYZRGB p1 = cloud->points.at(boundary.at(i).idx1);
    pcl::PointXYZRGB p2 = cloud->points.at(boundary.at(i).idx2);

    if(checkNaN(p1) || checkNaN(p2))
    {
      boundaryLength--;
      continue;
    }
 
    double depth = fabs(p1.z - p2.z);
    valuesDepth.push_back(depth);
    totalDepth += depth;
  }

  // normalize depth sum and calculate depth variance
  //@ep: this shoule be separate function in the utils
  if(boundaryLength > 0)
  {
    totalDepth /= boundaryLength;
    for(unsigned i=0; i<valuesDepth.size(); i++)
    {
      totalDepthStdDev += fabs(valuesDepth.at(i) - totalDepth);
    }
    totalDepthStdDev /= boundaryLength;
  }
  else
  {
    std::printf("[BoundaryRelationsMeanDepth::compute] Warning: Number of valid depth points is zero: totalDepth: %4.3f\n", totalDepth);
    totalDepth = 0.;
    totalDepthStdDev = 0.;
  }

  meanDepth.mean = totalDepth;
  meanDepth.stddev = totalDepthStdDev;

  return meanDepth;
}
Ejemplo n.º 8
0
int main(int argc, char *argv[]) {

	DIR *dir;
	ofstream fout;
	char slash = Unix ? '/' : '\\'; // It is '/' or '\' depending on OS
	char POS_PATH_BASE[MAX_PATH_LENGTH];
	char NEG_PATH_BASE[MAX_PATH_LENGTH];
	clock_t tic, toc;

	if (argc != 4) {
		error("Usage: train [POS_DIR] [NEG_DIR] [OUTPUT_FILE].");
	}

	if (!(dir = opendir(argv[1]))) {
		error("train: [POS_DIR] open failed.");
	}
	/* Set POS_PATH_BASE to [POS_DIR] and append '/' or '\' */
	strcpy(POS_PATH_BASE, argv[1]);
	sprintf(POS_PATH_BASE, "%s%c", POS_PATH_BASE, slash);
	closedir(dir);

	if (!(dir = opendir(argv[2]))) {
		error("train: [NEG_DIR] open failed.");
	}
	/* Set NEG_PATH_BASE to [NEG_DIR] and append '/' or '\' */
	strcpy(NEG_PATH_BASE, argv[2]);
	sprintf(NEG_PATH_BASE, "%s%c", NEG_PATH_BASE, slash);
	closedir(dir);

	fout.open(argv[3]);
	if (!(fout)) {
		error("train: [OUTPUT_FILE] open failed.");
	}

	/** Command is correct **/
	echoOS();
	cout << "This program provides cascaded-AdaBoost training.\n" <<
		"Please make sure that [POS_DIR] and [NEG_DIR] contain only training image data,\n" <<
		"  whose size is " << WINDOW_WIDTH << " x " << WINDOW_HEIGHT << ".\n" <<
		"Press [Enter] to continue, or ctrl+C/D/Z to exit ...";
	getchar();

	tic = clock();
	/* Use only one large matrix for storing all POS / NEG feature data */
	CvMat *POS = NULL, *NEG = NULL;
	int N1, N2; /* number of positive / negative images */
	int blockCount = 0; /* number of blocks in an image */

	/* [1] Feature extraction */
	/* First, check for validity of extraction parameters */
	assert(!(360 % (BIN_NUM * 2))); // (360 / BIN_NUM / 2) should be an integer */
	assert(360 / BIN_NUM == BIN_SIZE);
	assert(BIN_SIZE >> 1 == HALF_BIN_SIZE);

	cout << "\nStart of feature extraction ...\n";
	/* Should pass (CvMat *&) to really create the matrices */
	extractAll(POS_PATH_BASE, POS, N1, blockCount);
	cout << "Extraction of POS data completed.\n";

#if CHECKNaN
	cout << "Check POS matrix for NaN values:" << endl;
	if (checkNaN(POS, "POS")) {
	    error("POS matrix contains NaN values!");
    }
    else {
        cout << "OK!" << endl;
    }
#endif
	
	extractAll(NEG_PATH_BASE, NEG, N2, blockCount);
	cout << "Extraction of NEG data completed.\n";

#if CHECKNaN
	cout << "Check NEG matrix for NaN values:" << endl;
	if (checkNaN(NEG, "NEG")) {
	    error("NEG matrix contains NaN values!");
    }
    else {
        cout << "OK!" << endl;
    }
#endif
	assert(blockCount > 0);
	cout << endl << "# of blocks per image: " << blockCount << ".\n";
#if GETCHAR
	getchar();
#endif

	
	/* [2] Cascaded-AdaBoost training */
	cout << "Start of cascaded-AdaBoost training ...\n";
	srand(time(NULL));
	float F_current = 1.0;  // current overall false positive rate
	int i = 1;  // AdaBoost stage counter
	int rejectCount = 0;  // # of negative images rejected so far

	/* Allocate rejection table */
	/** Note: All the xxxTable[]'s are of boolean flags **/
	bool *rejectTable = new bool[ N2 ];
	memset(rejectTable, 0, N2);

	bool stop = false;  // Stopping flag
	vector<AdaStrong> H;  // A cascade of AdaBoost strong classifiers

	/*** The training algorithm ***/
	while (F_current > F_target && !stop) {
		/* upper bound for j */
		int jEnd = (i == 1) ? (ni + 1) : ni;

		for (int j = 1; j <= jEnd; j++) {
			/* Learn an A[i,j] stage */
			cout << "\nLearning stage A[" << i << "," << j << "]...\n";
			if ((stop = learnA(N1, N2, blockCount, rejectCount, rejectTable, POS, NEG, H, F_current))) {
				break;
			}
			cout << "Stage A[" << i << "," << j << "] completed.\n";
#if GETCHAR
			getchar();
#endif
		}
#if META
		if (stop) break;
		/* Learn a M[i] stage */
		cout << "\nLearning stage M[" << i << "]...\n";
		learnM();
		cout << "Stage M[" << i << "," << j << "] completed.\n";
  #if GETCHAR
		getchar();
  #endif
#endif
		i++;

	} // End of loop while (F_current > F_target && !stop)

	cout << "The entire training process completed.\nWriting model parameters to " << argv[3] << " ... ";
	/* Write model parameters to [OUTPUT_FILE]. See docs/train_format.txt for explanation. */
	writeModel(H, fout);
	cout << "done!\n";

	/* Show running time */
	toc = clock();
	runningTime(tic, toc);

	/* Don't forget to close the file stream */
	fout.close();
	return 0;
}