void DualPolyhedron_3::partiallyMove(const Vector_3 &xOld,
		const Vector_3 &xNew,
		const std::vector<Vertex_handle> &vertices,
		const Vertex_handle &dominator, double alpha, double alpha2)
{
	DEBUG_START;
	unsigned numDeletable = 0;
	unsigned iDeleted = vertices.size();
	unsigned numSpecial = 0;
	unsigned iSpecial = vertices.size();
	for (unsigned i = 0; i < vertices.size(); ++i)
	{
		unsigned iPrev = indexModulo(i - 1, vertices.size());
		unsigned iNext = indexModulo(i + 1, vertices.size());
		Point_3 prev = vertices[iPrev]->point();
		Point_3 next = vertices[iNext]->point();
		Point_3 curr = vertices[i]->point();
		Point_3 dom = dominator->point();

		if (isPositivelyDecomposable(prev, next, dom, curr))
		{
			iDeleted = i;
			++numDeletable;
		}

		Vector_3 product = CGAL::cross_product(prev - CGAL::Origin(),
				next - CGAL::Origin());
		if ((product * curr) * (product * dom) < 0.)
		{
			iSpecial = i;
			++numSpecial;
		}

	}
	std::cout << "Number of positively decomposable vectors: "
		<< numDeletable << std::endl;
	ASSERT(numDeletable <= 1 && "Wrong topological configuration");
	if (numDeletable == 0)
		ASSERT(numSpecial == 1 && "This case not handled yet");

	Vertex_handle vertexDeleted = vertices[iDeleted];
	if (numDeletable == 0)
	{
		std::cout << "  " << iSpecial << "-th vertex is special"
			<< std::endl;
		std::cout << "  Changing alpha: " << alpha << " -> ";
		alpha = 0.7 * alpha + 0.3 * alpha2;
		std::cout << alpha << std::endl;
	}
	Vector_3 tangient = alpha * xOld + (1. - alpha) * xNew;
	for (unsigned i = 0; i < vertices.size(); ++i)
	{
		Vertex_handle vertex = vertices[i];
		Point_3 point;
		if (numDeletable > 0 && i == iDeleted)
		{
			point = INNER_RESOLVED_POINT_FACTOR * vertex->point();
			std::cout << "  " << i << "-th vertex is deletable"
				<< std::endl;
		}
		else
		{
			point = calculateMove(vertex, tangient);
		}
		std::cout << "  Moving " << i << "-th vertex:"
			<< std::endl;
		std::cout << "    " << vertex->point() << std::endl;
		std::cout << "    " << point << std::endl;
		Vertex_handle vertexNew = move(vertex, point);
		ASSERT(vertex == vertexNew && "Conflict happened");
	}
	DEBUG_END;
}
bool DualPolyhedron_3::fullyMove(const std::vector<Vertex_handle> &vertices,
		const Vector_3 &xNew, const std::vector<unsigned> &activeGroup)
{
	DEBUG_START;
	std::vector<Point_3> initialPoints;
	bool succeeded = true;

	for (const Vertex_handle vertex : vertices)
	{
		ASSERT(isOuterVertex(vertex));
		initialPoints.push_back(vertex->point());
	}
	for (unsigned i = 0; i < NUM_FACET_VERTICES; ++i)
	{
		Vertex_handle vertex = vertices[i];
		Point_3 point = calculateMove(vertex, xNew);
		std::cout << "Moving dual point #" << vertex->info()
			<< ": " << std::endl
			<< std::setprecision(16)
			<< vertex->point() << " -> " << std::endl
			<< point << std::endl;
		unsigned numOld = number_of_vertices();
		Vertex_handle vertexNew = move(vertex, point);
		ASSERT(vertexNew == vertex);
		std::cout << vertex->point() << std::endl;
		ASSERT(number_of_vertices() == numOld);
	}
	for (const Vertex_handle vertex : vertices)
	{
		if (!isOuterVertex(vertex))
		{
			std::cout << "Vertex #" << vertex->info()
				<< ", i.e. " << vertex->point()
				<< " became non-outer" << std::endl;
			succeeded = false;
		}
	}

	if (!succeeded)
	{
		std::cout << "Rolling back to non-moved positions."
			<< std::endl;
		for (unsigned i = 0; i < NUM_FACET_VERTICES; ++i)
		{
			Vertex_handle vertex = vertices[i];
			move(vertex, initialPoints[i]);
		}
		DEBUG_END;
		return false;
	}

	unsigned numNewlyResolved = 0;
	for (unsigned iPlane : activeGroup)
	{
		if (!items[iPlane].resolved)
		{
			std::cout << "  Marking item #" << iPlane
				<< " as resolved" << std::endl;
			items[iPlane].resolved = true;
			++numNewlyResolved;
		}
		else
			std::cout << "  Item #" << iPlane
				<< " is already resolved" << std::endl;
	}
	ASSERT(numNewlyResolved > 0 && "Nothing has been resolved");
	DEBUG_END;
	return true;
}
Exemplo n.º 3
0
float AltAzTest::test_move (double JD, struct ln_equ_posn *pos, int32_t &azc, int32_t &altc, float speed, float max_time)
{
	int32_t t_azc = azc;
	int32_t t_altc = altc;

	// calculates elapsed time
	float elapsed = 0;

	int ret = test_sky2counts (JD, pos, t_azc, t_altc);
	if (ret)
		return NAN;

	const int32_t tt_azc = t_azc;
	const int32_t tt_altc = t_altc;

	int pm = 0;

	struct ln_hrz_posn hrz;

	double un_az, un_alt;

	counts2hrz (azc, altc, hrz.az, hrz.alt, un_az, un_alt);

	std::cout << "moving from alt az " << hrz.alt << " " << hrz.az << std::endl;

	while (elapsed < max_time)
	{
		pm = calculateMove (JD, azc, altc, t_azc, t_altc);
		if (pm == -1)
			return NAN;

		int32_t d_ac = labs (azc - t_azc);
		int32_t d_dc = labs (altc - t_altc);

		float e = 1;

		if (d_ac > d_dc)
			e = d_ac / azCpd->getValueDouble () / speed;
		else
			e = d_dc / altCpd->getValueDouble () / speed;
		elapsed += (e > 1) ? e : 1;

		counts2hrz (t_azc, t_altc, hrz.az, hrz.alt, un_az, un_alt);

		std::cout << "move to alt az " << hrz.alt << " " << hrz.az << " pm " << pm << std::endl;

		if (pm == 0)
		{
			azc = t_azc;
			altc = t_altc;
			break;
		}

		// 1 deg margin for check..
		if (azc < t_azc)
			azc = t_azc - azCpd->getValueDouble ();
		else if (azc > t_azc)
			azc = t_azc + azCpd->getValueDouble ();

		if (altc < t_altc)
			altc = t_altc - altCpd->getValueDouble ();
		else if (azc > t_azc)
			altc = t_altc + altCpd->getValueDouble ();

		t_azc = tt_azc;
		t_altc = tt_altc;

		JD += elapsed / 86400.0;
	}
	
	return elapsed;
}