Exemple #1
0
int main() { 
	FLOAT a = computeT(10, f2F(-1.0), f2F(1.0), f);
	FLOAT ans = f2F(0.551222);
	nemu_assert(Fabs(a - ans) < f2F(1e-4));
	HIT_GOOD_TRAP;
	return 0;
}
// Implementation of virtual function that determines intersection
double Triangle::firstIntersectionBetween(Ray ray,
									   double &tMin,
									   double &tMax)
{
	// Setup
	computeDummyVariables(ray);
	double m = computeM(); 

	// Compute 't'	
	double t = computeT(m); 
	if (t < tMin || t > tMax)
		return -1;

	// Compute gamma
	double gamma = computeGamma(m);
	if (gamma < 0.0 || gamma > 1.0)
		return -1;

	// Compute betta
	double betta = computeBetta(m);
	if (betta < 0.0 || (betta > (1 - gamma)))
		return -1;

	// Intersected, fill in intersection
	tMax = t;

	return t;
}
Exemple #3
0
bool Math::isPointOnSegment(sf::Vector2f point, pair<sf::Vector2f, sf::Vector2f> segment)
{
	//the segment is 90°
	if(segment.first.x==segment.second.x || segment.first.y==segment.second.y)
	{
		if(point==segment.first)
		{
			return true;
		}
		
		sf::Vector2f vector=segment.second-segment.first;
		float length=Math::length(vector);
		vector=Math::normalize(vector);
		
		sf::Vector2f firstToPoint=point-segment.first;
		float pointLength=Math::length(firstToPoint);
		firstToPoint=Math::normalize(firstToPoint);
		cout << "Lengths: " << pointLength << "<=" << length << " " << (pointLength<=length) << " Angle: " << Math::angle(firstToPoint, vector) << endl; 
		cout << "vector: " << vector.x << " " << vector.y << " firstToPoint: " << firstToPoint.x << " " << firstToPoint.y << endl;
		
		return pointLength<=length && Math::angle(firstToPoint, vector)==0;
	}
	else
	{
		return newTCheck(pair<float, float>(computeT(segment.first.x, segment.second.x, point.x), computeT(segment.first.y, segment.second.y, point.y)));
	}
}
Exemple #4
0
int main() {
//	nemu_assert(int2F(1) + F_mul_int(F_mul_F(f2F(-0.8),f2F(-0.8)),25) > int2F(16.9));
//	nemu_assert(int2F(1) + F_mul_int(F_mul_F(f2F(-0.8),f2F(-0.8)),25) < int2F(17));
//	nemu_assert();
//	nemu_assert(F_div_F(int2F(1) , int2F(1) + F_mul_int(F_mul_F(f2F(-0.8),f2F(-0.8)),25)) > f2F(0));
//	nemu_assert(F_div_F(int2F(1) , f2F(17)) > f2F(0.05));
/*	nemu_assert(F_div_int(int2F(2),10) <= f2F(0.2));
	nemu_assert(F_div_int(int2F(2),10) > f2F(0.1999));
	nemu_assert(F_mul_F(f2F(1.0),int2F(25)) == f2F(25));
	nemu_assert(f(int2F(1)) < f2F(0.039));
	nemu_assert(F_mul_int(f2F(0.2),9 ) > f2F(1.7));*/
//	nemu_assert(F_mul_F(f2F(-0.8),f2F(-0.8)) == f2F(0.64));
 // nemu_assert(F_div_F(0x10000,0x10ffcd) == int2F(0));
//	nemu_assert(f(-0.8) > f2F(0.05));
//	nemu_assert(F_mul_F(f2F(0.8),f2F(0.8)) < f2F(0.64));
//	nemu_assert(f(f2F(0.8)) > f2F(0.05));
//	nemu_assert(f(f2F(0.8)) < f2F(0.06));
//	nemu_assert(F_mul_F(f2F(-0.2),f2F(-0.2)) == f2F(0.04));
//	nemu_assert(f(f2F(-0.2)) == int2F(0));
//	nemu_assert(f2F(-1.0) + F_mul_int(f2F(0.2),9) < f2F(0.9));
//	nemu_assert(f(f2F(-1.0) + F_mul_int(f2F(0.2), 9)) > f2F(0.03));
//	nemu_assert(f2F(0.2) == 0x3333);
//	nemu_assert(F_mul_F(f2F(2.756),f2F(0.2)) > f2F(0.55));
//	nemu_assert(F_mul_F(f2F(2.756),f2F(0.2)) < f2F(0.5515));
//	nemu_assert( < f2F(0.05));
//	nemu_assert(f(1.8)<f2F(0.040));
	FLOAT a = computeT(10, f2F(-1.0), f2F(1.0), f);
//	nemu_assert(a > int2F(1));
	FLOAT ans = f2F(0.551222);
	nemu_assert(Fabs(a - ans) < f2F(1e-4));
//	nemu_assert(a < f2F(0.019));
//	FLOAT ans = f2F(2.756);
	//nemu_assert(a <= ans);
//	nemu_assert(a > f2F(0.1));
//	nemu_assert(Fabs(a - ans) < f2F(1e-4));
	HIT_GOOD_TRAP;
	return 0;
}
int ccFastMarchingForNormsDirection::step()
{
	if (!m_initialized)
		return -1;

	//get 'earliest' cell
	unsigned minTCellIndex = getNearestTrialCell();
	if (minTCellIndex == 0)
		return 0;

	CCLib::FastMarching::Cell* minTCell = m_theGrid[minTCellIndex];
	assert(minTCell && minTCell->state != DirectionCell::ACTIVE_CELL);

	if (minTCell->T < Cell::T_INF())
	{
#ifdef QT_DEBUG
		if (s_cellIndex == 0)
		{
			//process seed cells first!
			for (size_t i=0; i<m_activeCells.size(); ++i)
				static_cast<DirectionCell*>(m_theGrid[m_activeCells[i]])->scalar = static_cast<float>(0);
			s_cellIndex++;
		}
		static_cast<DirectionCell*>(minTCell)->scalar = static_cast<float>(s_cellIndex++);
#endif

		//resolve the cell orientation
		resolveCellOrientation(minTCellIndex);
		//we add this cell to the "ACTIVE" set
		addActiveCell(minTCellIndex);

		//add its neighbors to the TRIAL set
		for (unsigned i=0;i<m_numberOfNeighbours;++i)
		{
			//get neighbor cell
			unsigned nIndex = minTCellIndex + m_neighboursIndexShift[i];
			CCLib::FastMarching::Cell* nCell = m_theGrid[nIndex];
			if (nCell)
			{
				//if it' not yet a TRIAL cell
				if (nCell->state == DirectionCell::FAR_CELL)
				{
					nCell->T = computeT(nIndex);
					addTrialCell(nIndex);
				}
				//otherwise we must update it's arrival time
				else if (nCell->state == DirectionCell::TRIAL_CELL)
				{
					const float& t_old = nCell->T;
					float t_new = computeT(nIndex);

					if (t_new < t_old)
						nCell->T = t_new;
				}
			}
		}
	}
	else
	{
		addIgnoredCell(minTCellIndex);
	}

	return 1;
}
int ccFastMarchingForNormsDirection::step()
{
	if (!initialized)
	{
		//printf("Not yet initialized !");
		return -1;
	}

	unsigned minTCellIndex = getNearestTrialCell();

	if (minTCellIndex==0)
	{
		//fl_alert("No more trial cells !");
		return 0;
	}

	//printf("minTCellIndex=%i\n",minTCellIndex);

	CCLib::FastMarching::Cell* minTCell =  theGrid[minTCellIndex];
	assert(minTCell != NULL);

	assert(minTCell->state != CCLib::FastMarching::Cell::ACTIVE_CELL);

	if (minTCell->T < FM_INF)
	{
		//on rajoute cette cellule au groupe des cellules "ACTIVE"
		minTCell->state = CCLib::FastMarching::Cell::ACTIVE_CELL;
		activeCells.push_back(minTCellIndex);

		//printf("Cell %i added to ACTIVE\n",minTCellIndex);
		//fprintf(fp,"%f %f %f\n",((DirectionCell*)minTCell)->f,minTCell->T,(minTCell->T-lastT)/cellSize);

		lastT = minTCell->T;

		//on doit rajouter ses voisines au groupe TRIAL
		unsigned nIndex;
		CCLib::FastMarching::Cell* nCell;
		for (int i=0;i<CC_FM_NUMBER_OF_NEIGHBOURS;++i)
		{
			nIndex = minTCellIndex + neighboursIndexShift[i];
			//pointeur vers la cellule voisine
			nCell = theGrid[nIndex];

			//si elle est définie
			if (nCell)
			{
				//et si elle n'est pas encore dans un groupe, on la rajoute
				if (nCell->state==CCLib::FastMarching::Cell::FAR_CELL)
				{
					nCell->state = CCLib::FastMarching::Cell::TRIAL_CELL;
					nCell->T = computeT(nIndex);

					addTrialCell(nIndex,nCell->T);
					//Console::print("Cell %i added to TRIAL\n",nIndex);
				}
				else if (nCell->state == CCLib::FastMarching::Cell::TRIAL_CELL)
				//sinon, il faut recaculer T
				{
					float t_old = nCell->T;
					float t_new = computeT(nIndex);

					if (t_new<t_old)
						nCell->T = t_new;
				}
			}
		}
	}

	return 1;
}
int FastMarchingForFacetExtraction::step()
{
	if (!m_initialized)
		return -1;

	//get 'earliest' cell
	unsigned minTCellIndex = getNearestTrialCell();
	if (minTCellIndex == 0)
		return 0;

	CCLib::FastMarching::Cell* minTCell =  m_theGrid[minTCellIndex];
	assert(minTCell && minTCell->state != PlanarCell::ACTIVE_CELL);

	if (minTCell->T < Cell::T_INF())
	{
		assert(m_currentFacetPoints);
		unsigned sizeBefore = m_currentFacetPoints->size();

		//check if we can add the cell to the current "ACTIVE" set
		ScalarType error = addCellToCurrentFacet(minTCellIndex);

		if (error >= 0)
		{
			if (error > m_maxError)
			{
				//resulting error would be too high
				m_currentFacetPoints->resize(sizeBefore);
				//we leave the cell as is (in the EMPTY state)
				//so that we won't look at it again!
				addIgnoredCell(minTCellIndex);
			}
			else
			{
				m_currentFacetError = error;

				//add the cell to the "ACTIVE" set
				addActiveCell(minTCellIndex);

				//add its neighbors to the TRIAL set
				for (unsigned i=0; i<m_numberOfNeighbours; ++i)
				{
					//get neighbor cell
					unsigned nIndex = minTCellIndex + m_neighboursIndexShift[i];
					CCLib::FastMarching::Cell* nCell = m_theGrid[nIndex];
					if (nCell)
					{
						//if it' not yet a TRIAL cell
						if (nCell->state == PlanarCell::FAR_CELL)
						{
							nCell->T = computeT(nIndex);
							addTrialCell(nIndex);
						}
						//otherwise we must update it's arrival time
						else if (nCell->state == PlanarCell::TRIAL_CELL)
						{
							const float& t_old = nCell->T;
							float t_new = computeT(nIndex);

							if (t_new < t_old)
								nCell->T = t_new;
						}
					}
				}
			}
		}
		else
		{
			//an error occurred
			return -1;
		}
	}
	else
	{
		addIgnoredCell(minTCellIndex);
	}

	return 1;
}