void ThreeDPlane::ChangePlane(Vector3& _normal, Vector3& _pos)
{
	normal = _normal.normalize();
	pos = _pos;

	CalculateD();
}
Example #2
0
	inline void Initialize( float FrequencyHz, float BandwidthHz, float SampleRate )
	{
		const float C = CalculateC( BandwidthHz, SampleRate );
		const float D = CalculateD( FrequencyHz, SampleRate );

		const float A0 = 1.0f;
		const float A1 = D * ( 1.0f - C );
		const float A2 = -C;
		const float B0 = 1.0f + C;
		const float B1 = 0.0f;
		const float B2 = -B0;

		Coefficient0 = B0 / A0;

		Coefficient1 = +B1 / A0;
		Coefficient2 = +B2 / A0;
		Coefficient3 = -A1 / A0;
		Coefficient4 = -A2 / A0;

		Z0 = Z1 = Y0 = Y1 = 0.0f;
	}
	inline void Initialize( FLOAT FrequencyHz, FLOAT BandwidthHz, FLOAT SampleRate )
	{
		const FLOAT C = CalculateC( BandwidthHz, SampleRate );
		const FLOAT D = CalculateD( FrequencyHz, SampleRate );
		
		const FLOAT A0 = 1.0f;
		const FLOAT A1 = D * ( 1.0f - C );
		const FLOAT A2 = -C;
		const FLOAT B0 = 1.0f + C;
		const FLOAT B1 = 0.0f;
		const FLOAT B2 = -B0;
		
		Coefficient0 = B0 / A0;
		
		Coefficient1 = +B1 / A0;
		Coefficient2 = +B2 / A0;
		Coefficient3 = -A1 / A0;
		Coefficient4 = -A2 / A0;
		
		Z0 = Z1 = Y0 = Y1 = 0.0f;
	}
Example #4
0
void ADMMCut::MakeLayers()
{
	// Initial Cutting Edge Setting
	InitState();

	debug_ = false;
	int cut_count = 0;
	vector<double> cut_energy;
	vector<double> res_energy;
	do
	{
		/* Recreate dual graph at the beginning of each cut */
		SetStartingPoints(cut_count);
		CreateA();

		ptr_stiff_->CalculateD(D_, x_, 0, 0, cut_count);

		///* for rendering */
		//if (cut_count == 0)
		//{
		//	WriteWeight();
		//	WriteStiffness("offset1.txt", "rotation1.txt");
		//	getchar();
		//}
		//if (cut_count == 4)
		//{
		//	WriteStiffness("offset2.txt", "rotation2.txt");
		//	getchar();
		//}
		//if (cut_count == 6)
		//{
		//	WriteStiffness("offset3.txt", "rotation3.txt");
		//	getchar();
		//}

		/* set x for intial cut setting */
		SetBoundary();

		/*
		* energy specify:
		* cut		 energy : | A * x |
		* defomation energy : norm(K D - F)
		*/
		ptr_stiff_->CreateGlobalK(x_);
		ptr_stiff_->CreateF(x_);
		SpMat K_init = *(ptr_stiff_->WeightedK());
		VX	  F_init = *(ptr_stiff_->WeightedF());


		double icut_energy = 0;
		VX V_Cut = A_ * x_;
		for (int i = 0; i < Md_; i++)
		{
			icut_energy += abs(V_Cut[i]);
		}
		double ideform_energy = (K_init * D_ - F_init).norm();

		cout << "****************************************" << endl;
		cout << "ADMMCut Round : " << cut_count << endl;
		cout << "Initial cut energy before entering ADMM: " << icut_energy << endl;
		cout << "Initial Lagrangian energy before entering ADMM: " << ideform_energy << endl;
		cout << "---------------------------------" << endl;

		int rew_count = 0;
		VX x_prev;
		VX D_prev;

		/* Output energy list for reweighting process in a single
		graph cut problem, energy.size() = number of reweighting
		process performed.
		cut energy = |A_ * x_| = sum_{e_ij} w_ij * |x_i - x_j|
		res energy = (K(x)D - F(x)).norm()
		*/

		cut_energy.clear();
		res_energy.clear();

		cut_energy.push_back(icut_energy);
		res_energy.push_back(ideform_energy);

		do
		{
			/* Reweighting loop for cut */

			int ADMM_count = 0;
			x_prev = x_;
			CreateC(cut_count, rew_count);

			do
			{
				cout << "ADMMCut Round: " << cut_count << ", reweight iteration:" << rew_count
					<< ", ADMM " << ADMM_count << " iteration." << endl;

				/*-------------------ADMM loop-------------------*/
				CalculateX();

				D_prev = D_;
				CalculateD();

				UpdateLambda();

				/*-------------------Residual Calculation-------------------*/
				SpMat Q_prev;
				SpMat Q_new;
				CalculateQ(D_prev, Q_prev);
				CalculateQ(D_, Q_new);

				/* Update K reweighted by new x */
				ptr_stiff_->CreateGlobalK(x_);
				ptr_stiff_->CreateF(x_);
				SpMat K_new = *(ptr_stiff_->WeightedK());
				VX    F_new = *(ptr_stiff_->WeightedF());

				dual_res_ = penalty_ * (D_prev - D_).transpose() * K_new.transpose() * Q_prev
					+ lambda_.transpose() * (Q_prev - Q_new);
				primal_res_ = K_new * D_ - F_new;

				/*-------------------Screenplay-------------------*/
				double new_cut_energy = x_.dot(H1_ * x_);

				cout << "new quadratic func value record: " << new_cut_energy << endl;
				cout << "dual_residual : " << dual_res_.norm() << endl;
				cout << "primal_residual(KD-F) : " << primal_res_.norm() << endl;

				cout << "---------------------" << endl;
				ADMM_count++;
			} while (!TerminationCriteria(ADMM_count));

			/* One reweighting process ended! */
			/* Output energy and residual */

			double energy = 0;
			VX V_Cut = A_ * x_;
			for (int i = 0; i < Md_; i++)
			{
				energy += ptr_dualgraph_->Weight(i) * abs(V_Cut[i]);
			}

			/*-------------------Screenplay-------------------*/
			double res_tmp = primal_res_.norm();
			cout << "Cut " << cut_count << " Reweight " << rew_count << " completed." << endl;
			cout << "Cut Energy :" << energy << endl;
			cout << "Res Energy :" << res_tmp << endl;
			cout << "<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-" << endl;

			cut_energy.push_back(energy);
			res_energy.push_back(res_tmp);

			/* write x distribution to a file */
			string str_x = "Cut_" + to_string(cut_count) + "_Rew_" + to_string(rew_count) + "_x";
			Statistics tmp_x(str_x, x_);
			tmp_x.GenerateVectorFile();

			rew_count++;
		} while (!UpdateR(x_prev, rew_count));

		/* Output reweighting energy history for last cut process */
		string str_eC = "Cut_" + to_string(cut_count) + "_Cut_Energy";
		Statistics s_eC(str_eC, cut_energy);
		s_eC.GenerateStdVecFile();

		string str_eR = "Cut_" + to_string(cut_count) + "_Res_Energy";
		Statistics s_eR(str_eR, res_energy);
		s_eR.GenerateStdVecFile();

		/* Update New Cut information to Rendering (layer_label_) */

		UpdateCut();

		fprintf(stdout, "ADMMCut No.%d process is Finished!\n", cut_count);
		cut_count++;

	} while (!CheckLabel(cut_count));

	fprintf(stdout, "All done!\n");
}