示例#1
0
void AspMainTest::FillPartWithPoints(MainFrame * mainWindow, AspMainTool *tool){
	auto iter = tool->product->UnitMap.begin();
	auto end = tool->product->UnitMap.end();


	Timer timer;
	timer.Start();
	_int fullAmount = 0;
	_int inPointsAMount = 0;
	for (_int i = 0; iter != end; ++iter, ++i){
		//Status updating
		QString status = "Pnt gen ";
		status += std::to_string(i).c_str();
		status += " / ";
		status += std::to_string( tool->product->UnitMap.size()).c_str();
		mainWindow->SetStatus(status);

		static BRepClass3d_SolidClassifier solidClsf;

		TopoDS_Shape pShape = iter->second->getShape();
		gp_Pnt center = iter->second->GetCenter();
		Bnd_Box * pBox = iter->second->BndBox();
		gp_Pnt pBoxInf = pBox->CornerMin();
		gp_Pnt pBoxSup = pBox->CornerMax();

		//Points every 3 mm
		_real step = 2;
		_real XRange = pBoxSup.X() - pBoxInf.X();
		_real YRange = pBoxSup.Y() - pBoxInf.Y();
		_real ZRange = pBoxSup.Z() - pBoxInf.Z();

		_int nbX = std::ceil(XRange / step);
		_int nbY = std::ceil(YRange / step);
		_int nbZ = std::ceil(ZRange / step);
		_int amount = nbX*nbY*nbZ;
		fullAmount += amount;
		nbX = nbX ? nbX : 1;
		nbY = nbY ? nbY : 1;
		nbZ = nbZ ? nbZ : 1;

		_real stpX = XRange / nbX;
		_real stpY = YRange / nbY;
		_real stpZ = ZRange / nbZ;

		std::vector<gp_Pnt> pointsInsidePart;


		solidClsf.Load(pShape);

		for (_int i = 1; i <= nbX; ++i){
			static gp_XYZ tstPnt;
			static _real x = pBoxInf.X();
			x += stpX;
			tstPnt.SetX(x);
			_real y = pBoxInf.Y();
			for (_int j = 1; j <= nbY; ++j){
				y += stpY;
				tstPnt.SetY(y);
				_real z = pBoxInf.Z();
				for (_int k = 1; k <= nbZ; ++k){
					z += stpZ;
					tstPnt.SetZ(z);

					solidClsf.Perform(tstPnt, Precision::Confusion());

					if (solidClsf.State() == TopAbs_IN)
						pointsInsidePart.push_back(tstPnt);
				}
			}
			status.clear();
			status += std::to_string(i*nbY*nbZ).c_str();
			status += " / ";
			status += std::to_string(amount).c_str();
			status += "T: ";
			status += timer.WhatTime().c_str();
			mainWindow->SetStatus(status);
		}
		inPointsAMount += (_int) pointsInsidePart.size();
	}
	timer.Stop();

	_real speed = fullAmount / timer.Seconds();

	QString status = std::to_string(inPointsAMount).c_str();
	status += " / ";
	status += std::to_string(fullAmount).c_str();
	status += " on speed = ";
	status += std::to_string(speed).c_str();

	mainWindow->SetStatus(status);
}