Beispiel #1
0
void PlotGl::updateViewMatrix()
{
	tl::t_mat4 matScale = tl::make_mat<tl::t_mat4>(
		{{m_dMouseScale,              0,             0, 0},
		{            0,   m_dMouseScale,             0, 0},
		{            0,               0, m_dMouseScale, 0},
		{            0,               0,             0, 1}});

	tl::t_mat4 matR0 = tl::rotation_matrix_3d_z(tl::d2r<t_real>(m_dMouseRot[0]));
	tl::t_mat4 matR1 = tl::rotation_matrix_3d_x(tl::d2r<t_real>(-90. + m_dMouseRot[1]));
	matR0.resize(4,4,1); matR1.resize(4,4,1);
	matR0(3,3) = matR1(3,3) = 1.;
	for(short i=0; i<3; ++i) matR0(i,3)=matR0(3,i)=matR1(i,3)=matR1(3,i)=0.;
	tl::t_mat4 matRot0 = matR0, matRot1 = matR1;

	tl::t_mat4 matTrans = tl::make_mat<tl::t_mat4>(
		{{ 1, 0, 0,  0},
		{  0, 1, 0,  0},
		{  0, 0, 1, -2},
		{  0, 0, 0,  1}});

	{
		std::lock_guard<QMutex> _lck(m_mutex);
		m_matView = ublas::prod(matTrans, matRot1);
		m_matView = ublas::prod(m_matView, matRot0);
		m_matView = ublas::prod(m_matView, matScale);
	}
}
Beispiel #2
0
void PlotGl::PlotSphere(const ublas::vector<t_real_gl>& vecPos,
	t_real_gl dRadius, int iObjIdx)
{
	if(iObjIdx < 0)
	{
		clear();
		iObjIdx = 0;
	}

	{
		std::lock_guard<QMutex> _lck(m_mutex);

		if(iObjIdx >= int(m_vecObjs.size()))
			m_vecObjs.resize(iObjIdx+1);
		PlotObjGl& obj = m_vecObjs[iObjIdx];

		obj.plttype = PLOT_SPHERE;
		if(obj.vecParams.size() != 4)
			obj.vecParams.resize(4);

		obj.vecParams[0] = vecPos[0];
		obj.vecParams[1] = vecPos[1];
		obj.vecParams[2] = vecPos[2];
		obj.vecParams[3] = dRadius;
	}
}
Beispiel #3
0
void PlotGl::run()
{
	static std::atomic<std::size_t> iThread(0);
	std::size_t iThisThread = ++iThread;
	tl::log_debug("GL thread ", iThisThread, " started.");

	makeCurrent();
	initializeGLThread();

	t_real_gl dTime = 0.;
	while(m_bRenderThreadActive)
	{
		if(m_bDoResize)
		{
			std::lock_guard<QMutex> _lck(m_mutex);
			resizeGLThread(m_iW, m_iH);
			m_bDoResize = 0;
		}

		if(isVisible())
		{
			tickThread(dTime);
			paintGLThread();
		}

		long fps = isVisible() ? RENDER_FPS : (RENDER_FPS/10);
		long lns = long(1e9) / fps;
		sleep_nano(lns);
		dTime += t_real_gl(lns) * 1e-9;
	}

	doneCurrent();
	freeGLThread();
	tl::log_debug("GL thread ", iThisThread, " ended.");
}
Beispiel #4
0
void PlotGl::PlotEllipsoid(const ublas::vector<t_real_gl>& widths,
	const ublas::vector<t_real_gl>& offsets,
	const ublas::matrix<t_real_gl>& rot,
	int iObjIdx)
{
	if(iObjIdx < 0)
	{
		clear();
		iObjIdx = 0;
	}

	{
		std::lock_guard<QMutex> _lck(m_mutex);

		if(iObjIdx >= int(m_vecObjs.size()))
			m_vecObjs.resize(iObjIdx+1);
		PlotObjGl& obj = m_vecObjs[iObjIdx];

		obj.plttype = PLOT_ELLIPSOID;
		if(obj.vecParams.size() != 15)
			obj.vecParams.resize(15);

		obj.vecParams[0] = widths[0];
		obj.vecParams[1] = widths[1];
		obj.vecParams[2] = widths[2];
		obj.vecParams[3] = offsets[0];
		obj.vecParams[4] = offsets[1];
		obj.vecParams[5] = offsets[2];

		std::size_t iNum = 6;
		for(std::size_t i=0; i<3; ++i)
			for(std::size_t j=0; j<3; ++j)
				obj.vecParams[iNum++] = rot(j,i);
	}
}
Beispiel #5
0
void PlotGl::SetObjectUseLOD(std::size_t iObjIdx, bool bLOD)
{
	std::lock_guard<QMutex> _lck(m_mutex);

	if(m_vecObjs.size() <= iObjIdx)
		return;
	m_vecObjs[iObjIdx].bUseLOD = bLOD;
}
Beispiel #6
0
void PlotGl::SetObjectLabel(std::size_t iObjIdx, const std::string& strLab)
{
	std::lock_guard<QMutex> _lck(m_mutex);

	if(m_vecObjs.size() <= iObjIdx)
		return;
	m_vecObjs[iObjIdx].strLabel = strLab;
}
Beispiel #7
0
void PlotGl::SetObjectColor(std::size_t iObjIdx, const std::vector<t_real>& vecCol)
{
	std::lock_guard<QMutex> _lck(m_mutex);

	if(m_vecObjs.size() <= iObjIdx)
		return;
	m_vecObjs[iObjIdx].vecColor = vecCol;
}
Beispiel #8
0
void PlotGl::SetLabels(const char* pcLabX, const char* pcLabY, const char* pcLabZ)
{
	std::lock_guard<QMutex> _lck(m_mutex);

	m_strLabels[0] = pcLabX;
	m_strLabels[1] = pcLabY;
	m_strLabels[2] = pcLabZ;
}
Beispiel #9
0
			phand_for_gosrc::machine_ptr
				phand_for_gosrc::
					rebind_cureent_machine(const machine_ptr& m)
			{
				scoped_lock _lck(obj()->_mlock);
				auto ret = m;
				obj()->_mcurm = m;
				return ret;
			}
Beispiel #10
0
void PlotGl::resizeEvent(QResizeEvent *evt)
{
	std::lock_guard<QMutex> _lck(m_mutex);

	m_iW = size().width();
	m_iH = size().height();

	m_bDoResize = 1;
}
Beispiel #11
0
			processor::~processor()
			{
				scoped_lock _lck(_mlock);
				_mstate.store(pdead);
				if (!_mrunable.empty())
				{
					gosrc_mhand_for_p(global_goroutine_manager()).
						reciperare(_mrunable);
				}
			}
Beispiel #12
0
			const bool phand_for_gosrc::alloc_freeg(goroutine_list& list)
			{
				scoped_lock _lck(obj()->_mlock);
				if (obj()->_mfreed.empty())
				{
					return false;
				}
				spliceback(list, obj()->_mfreed, 1);
				return true;
			}
Beispiel #13
0
void PlotGl::mouseSelectObj(t_real_gl dX, t_real_gl dY)
{
	std::lock_guard<QMutex> _lck(m_mutex);
	tl::Line<t_real_gl> ray = tl::screen_ray(dX, dY, m_matProj, m_matView);

	for(PlotObjGl& obj : m_vecObjs)
	{
		obj.bSelected = 0;

		tl::Quadric<t_real_gl> *pQuad = nullptr;
		tl::t_vec3 vecOffs = ublas::zero_vector<t_real_gl>(3);

		if(obj.plttype == PLOT_SPHERE)
		{
			pQuad = new tl::QuadSphere<t_real_gl>(obj.vecParams[3]);
			vecOffs = tl::make_vec<tl::t_vec3>({obj.vecParams[0], obj.vecParams[1], obj.vecParams[2]});
		}
		else if(obj.plttype == PLOT_ELLIPSOID)
		{
			pQuad = new tl::QuadEllipsoid<t_real_gl>(obj.vecParams[0], obj.vecParams[1], obj.vecParams[2]);

			vecOffs = tl::make_vec<tl::t_vec3>({obj.vecParams[3], obj.vecParams[4], obj.vecParams[5]});
			tl::t_mat3 matRot = tl::make_mat<tl::t_mat3>(
				{{obj.vecParams[6],  obj.vecParams[7],  obj.vecParams[8]},
				 {obj.vecParams[9],  obj.vecParams[10], obj.vecParams[11]},
				 {obj.vecParams[12], obj.vecParams[13], obj.vecParams[14]}});
			pQuad->transform(matRot);
		}

		pQuad->SetOffset(vecOffs);

		std::vector<t_real_gl> vecT = pQuad->intersect(ray);
		if(vecT.size() > 0)
		{
			for(t_real_gl t : vecT)
			{
				if(t < 0.) continue; // beyond "near" plane
				if(t > 1.) continue; // beyond "far" plane
				obj.bSelected = 1;
			}
		}

		delete pQuad;
	}
}
Beispiel #14
0
				m_mgrhand_for_sched::machine_ptr
				m_mgrhand_for_sched::allocm(const goroutine_ptr& g,
				const processor_ptr& proc_iter)
			{
				scoped_lock _lck(obj()->_mlock);
				if (!obj()->_midle.empty())
				{
					auto m_iter = obj()->_midle.begin();
					shared_ptr<machine>& m = m_iter->second;
					mhand_for_sched handle(m);
					handle.rebind(proc_iter);
					handle.switchg(g);
					auto ret=obj()->_mrunning.insert(*m_iter);
					obj()->_midle.erase(m_iter);
					return m;
				}
				id_type id = _alloc_m_id();
				auto ret=
					obj()->_mrunning.insert(
					std::make_pair(id, 
						machine_ptr(new machine(id,g, proc_iter ) ) ) );
				assert(ret.second);
				return ret.first->second;
			}
Beispiel #15
0
void PlotGl::paintGLThread()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	bool bEnabled = m_bEnabled.load();
	if(!bEnabled) return;

	glMatrixMode(GL_MODELVIEW);
	t_real_gl glmat[16];
	{
		std::lock_guard<QMutex> _lck(m_mutex);
		tl::to_gl_array(m_matView, glmat);
	}
	glLoadMatrixd(glmat);


	glPushMatrix();
		glDisable(GL_LIGHTING);
		glDisable(GL_BLEND);
		glDisable(GL_TEXTURE_2D);
		glLineWidth(2.);
		glColor3d(0., 0., 0.);

		const t_real_gl dAxisScale = 1.8;
		glBegin(GL_LINES);
			glVertex3d(m_dXMin*dAxisScale, 0., 0.);
			glVertex3d(m_dXMax*dAxisScale, 0., 0.);
			glVertex3d(0., m_dYMin*dAxisScale, 0.);
			glVertex3d(0., m_dYMax*dAxisScale, 0.);
			glVertex3d(0., 0., m_dZMin*dAxisScale);
			glVertex3d(0., 0., m_dZMax*dAxisScale);
		glEnd();
	glPopMatrix();

	glEnable(GL_BLEND);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glDisable(GL_TEXTURE_2D);

	std::unique_lock<QMutex> _lck(m_mutex);
	std::size_t iPltIdx = 0;
	for(const PlotObjGl& obj : m_vecObjs)
	{
		int iLOD = 0;

		bool bColorSet = 0;
		if(obj.bSelected)
		{
			SetColor(0.25, 0.25, 0.25, 0.9);
			bColorSet = 1;
		}

		glPushMatrix();
		if(obj.plttype == PLOT_SPHERE)
		{
			glTranslated(obj.vecParams[0], obj.vecParams[1], obj.vecParams[2]);
			glScaled(obj.vecParams[3], obj.vecParams[3], obj.vecParams[3]);
		}
		else if(obj.plttype == PLOT_ELLIPSOID)
		{
			glTranslated(obj.vecParams[3], obj.vecParams[4], obj.vecParams[5]);

			t_real_gl dMatRot[] = {obj.vecParams[6], obj.vecParams[7], obj.vecParams[8], 0.,
				obj.vecParams[9], obj.vecParams[10], obj.vecParams[11], 0.,
				obj.vecParams[12], obj.vecParams[13], obj.vecParams[14], 0.,
				0., 0., 0., 1. };
			glMultMatrixd(dMatRot);
			glScaled(obj.vecParams[0], obj.vecParams[1], obj.vecParams[2]);
		}
		else
			tl::log_warn("Unknown plot object.");

		if(obj.bUseLOD)
		{
			t_real_gl dLenDist = tl::gl_proj_sphere_size(/*dRadius*/1.);
			//std::cout << "proj sphere size: " << dLenDist << std::endl;
			iLOD = dLenDist * 50.;
			if(iLOD >= int(sizeof(m_iLstSphere)/sizeof(*m_iLstSphere)))
				iLOD = sizeof(m_iLstSphere)/sizeof(*m_iLstSphere)-1;
			if(iLOD < 0) iLOD = 0;
			iLOD = sizeof(m_iLstSphere)/sizeof(*m_iLstSphere) - iLOD - 1;
			//std::cout << "dist: " << dLenDist << ", lod: " << iLOD << std::endl;
		}

		if(!bColorSet)
		{
			if(obj.vecColor.size())
				SetColor(obj.vecColor[0], obj.vecColor[1], obj.vecColor[2], obj.vecColor[3]);
			else
				SetColor(iPltIdx);
		}
		glCallList(m_iLstSphere[iLOD]);

		if(obj.bSelected && obj.strLabel.length() && m_pFont && m_pFont->IsOk())
		{
			glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_LIGHTING_BIT);
			m_pFont->BindTexture();
			glColor4d(0., 0., 0., 1.);
			m_pFont->DrawText(0., 0., 0., obj.strLabel);
			glPopAttrib();
		}

		glPopMatrix();

		++iPltIdx;
	}
	_lck.unlock();

	glPushMatrix();
		if(m_pFont && m_pFont->IsOk())
		{
			m_pFont->BindTexture();

			glColor4d(0., 0., 1., 1.);
			m_pFont->DrawText(m_dXMax*dAxisScale, 0., 0., m_strLabels[0].toStdString());
			m_pFont->DrawText(0., m_dYMax*dAxisScale , 0., m_strLabels[1].toStdString());
			m_pFont->DrawText(0., 0., m_dZMax*dAxisScale , m_strLabels[2].toStdString());

			glColor4d(0., 0., 0., 1.);
			m_pFont->DrawText(m_dXMin, 0., 0., tl::var_to_str(m_dXMin+m_dXMinMaxOffs, m_iPrec));
			m_pFont->DrawText(m_dXMax, 0., 0., tl::var_to_str(m_dXMax+m_dXMinMaxOffs, m_iPrec));
			m_pFont->DrawText(0., m_dYMin, 0., tl::var_to_str(m_dYMin+m_dYMinMaxOffs, m_iPrec));
			m_pFont->DrawText(0., m_dYMax, 0., tl::var_to_str(m_dYMax+m_dYMinMaxOffs, m_iPrec));
			m_pFont->DrawText(0., 0., m_dZMin, tl::var_to_str(m_dZMin+m_dZMinMaxOffs, m_iPrec));
			m_pFont->DrawText(0., 0., m_dZMax, tl::var_to_str(m_dZMax+m_dZMinMaxOffs, m_iPrec));
		}
	glPopMatrix();

	swapBuffers();
}
Beispiel #16
0
			void m_mgrhand_for_sched::_mov(map_type& lhs, map_type& rhs, const id_type id)
			{
				scoped_lock _lck(obj()->_mlock);
				mov(lhs, rhs, id);
			}
Beispiel #17
0
void PlotGl::clear()
{
	std::lock_guard<QMutex> _lck(m_mutex);
	m_vecObjs.clear();
}