QT - qwtplot3d-3D图标

本文详细介绍了使用QT库中的qwt3dplot3d模块创建3D坐标轴的步骤,包括关键程序片段如Axis类的构造函数和方法,以及如何设置坐标轴的属性和绘制。同时提供了示例代码和下载链接。
摘要由CSDN通过智能技术生成


一、演示效果

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

二、关键程序

#include "qwt3d_axis.h"

using namespace Qwt3D;

Axis::Axis()
{
  init();
};

Axis::~Axis()
{
}

Axis::Axis(Triple beg, Triple end)
{
 	init();
	setPosition(beg,end);
}

void Axis::init()
{
	detachAll();

  scale_ = qwt3d_ptr<Scale>(new LinearScale);

  beg_ = Triple(0.0, 0.0, 0.0);  
  end_ = beg_;
	
	majorintervals_ = 0;
	minorintervals_ = 0;
	setMajors(1);	
	setMinors(1);	
	setLimits(0,0);

	setTicOrientation(0.0, 0.0, 0.0);
	setTicLength(0.0, 0.0);
	setColor(0.0, 0.0, 0.0);
	setLineWidth(1.0);
	symtics_ = false;
	drawNumbers_ = false;
	drawLabel_ = false;

	drawTics_ = false;
	autoscale_ = true;
	markerLabel_.clear();
	numberfont_ = QFont("Courier",12);
	setLabelFont(QFont("Courier",14));

  numbercolor_ = RGBA(0,0,0,0);

	setNumberAnchor(Center);

	numbergap_ = 0;
	labelgap_ = 0;
}

void Axis::setPosition(const Triple& beg, const Triple& end)
{
	beg_ = beg;
	end_ = end;
}

void Axis::setMajors(int val)
{
	if (val == majorintervals_)
		return;
	
	majorintervals_ = (val<=0) ? 1 : val; // always >= 1
}

/*!
\see LogScale::setMinors().
*/
void Axis::setMinors(int val)
{
	if (val == minorintervals_)
		return;

	minorintervals_ = (val<=0) ? 1 : val; // always >= 1
}

void Axis::setTicLength(double majorl, double minorl)
{
	lmaj_ = majorl;
	lmin_ = minorl;
}

void Axis::setTicOrientation(double tx, double ty, double tz)
{
	setTicOrientation(Triple(tx,ty,tz));
}

void Axis::setTicOrientation(const Triple& val)
{
	orientation_ = val;
	orientation_.normalize();
}

/**
\param val thickness for axis base line
\param majfac relative thickness for axis major tics (majfac*val)
\param minfac relative thickness for axis minor tics (minfac*val)
*/
void Axis::setLineWidth(double val, double majfac, double minfac)
{
	lineWidth_ = val;
	majLineWidth_ = majfac * lineWidth_;
	minLineWidth_ = minfac * lineWidth_;
}

void Axis::draw()
{
	Drawable::draw();

	saveGLState();

//	GLStateBewarer sb(GL_LINE_SMOOTH, true);
//	glBlendFunc(GL_ONE, GL_ZERO);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glColor4d(color.r,color.g,color.b,color.a);		

	drawBase();
	drawTics();
	drawLabel();	

	restoreGLState();
}

/**
Always use AFTER drawNumbers() ! (Needs length of number string)
*/
void Axis::drawLabel()
{
	if (!drawLabel_)
		return;

  Triple diff = end() - begin();
	Triple center = begin() + diff/2;
	
	Triple bnumber = biggestNumberString(); 
//	double fac = 6*(second()-first()).length() / 100;
	
	switch (scaleNumberAnchor_) 
	{
		case BottomLeft:
		case TopLeft:
		case CenterLeft:
			bnumber.y = 0;
			break;
		case BottomRight:
		case TopRight:
		case CenterRight:
			bnumber.x = -bnumber.x;
			bnumber.y = 0;
			break;
		case TopCenter:
			bnumber.x = 0;
			bnumber.y = -bnumber.y;
			break;
		case BottomCenter:
			bnumber.x = 0;
			break;
		default:
			break;
	}
	
	Triple pos = ViewPort2World(World2ViewPort(center + ticOrientation() * lmaj_) + bnumber);
	setLabelPosition(pos, scaleNumberAnchor_);

	label_.adjust(labelgap_);
	label_.draw();
}

void Axis::drawBase()
{
	setDeviceLineWidth( lineWidth_ );
	glBegin( GL_LINES );
		glVertex3d( beg_.x, beg_.y, beg_.z); 
		glVertex3d( end_.x, end_.y, end_.z);
	glEnd();
}	

bool Axis::prepTicCalculation(Triple& startpoint)
{
  if (isPracticallyZero(start_, stop_))
		return false;

	autostart_ = start_;
	autostop_ = stop_;

 	if (autoScale()) 
  {  
    setMajors(scale_->autoscale(autostart_, autostop_, start_, stop_, majors()));
    if (isPracticallyZero(autostart_, autostop_))
		  return false;
  }
  
  scale_->setLimits(start_,stop_);
  scale_->setMajors(majors());
  scale_->setMinors(minors());
  scale_->setMajorLimits(autostart_,autostop_);
  scale_->calculate();

	Triple normal = (end_ - beg_);
	//normal.normalize();
	Triple beg = beg_ + ((autostart_ - start_) / (stop_ - start_)) * normal;
	Triple end = end_ - ((stop_ - autostop_) / (stop_ - start_))* normal;

	startpoint = end_ - beg_;

	majorpos_.clear();
	minorpos_.clear();

  return true;
}

void Axis::recalculateTics()
{
  Triple runningpoint;
  if (false==prepTicCalculation(runningpoint))
    return;

	unsigned int i;
	
	for (i = 0; i != scale_->majors_p.size(); ++i) 
	{
		double t = (scale_->majors_p[i] - start_) / (stop_-start_);
		majorpos_.push_back(beg_ + t * runningpoint);
	}
	for (i = 0; i != scale_->minors_p.size(); ++i) 
	{
		double t = (scale_->minors_p[i] - start_) / (stop_-start_);
		minorpos_.push_back(beg_ + t * runningpoint);
	}
}

void Axis::drawTics()
{
	Triple runningpoint;
  if (!drawTics_ || false==prepTicCalculation(runningpoint))
		return;
  
	unsigned int i;
  Triple nadir;
	
  markerLabel_.resize(scale_->majors_p.size());
	setDeviceLineWidth(majLineWidth_);
	for (i = 0; i != scale_->majors_p.size(); ++i) 
	{
		double t = (scale_->majors_p[i] - start_) / (stop_-start_);
    nadir = beg_ + t * runningpoint;
    majorpos_.push_back(drawTic(nadir, lmaj_));
		drawTicLabel(nadir + 1.2 * lmaj_ * orientation_, i);
  }
	setDeviceLineWidth(minLineWidth_);
	for (i = 0; i != scale_->minors_p.size(); ++i) 
	{
		double t = (scale_->minors_p[i] - start_) / (stop_-start_);
		nadir = beg_ + t * runningpoint;
    minorpos_.push_back(drawTic(nadir, lmin_));
  }
}

void Axis::drawTicLabel(Triple pos, int mtic)
{
	if (!drawNumbers_ || (mtic < 0))
		return;
	
	markerLabel_[mtic].setFont(numberfont_.family(), numberfont_.pointSize(), numberfont_.weight(), numberfont_.italic());
	markerLabel_[mtic].setColor(numbercolor_);
  markerLabel_[mtic].setString(scale_->ticLabel(mtic));	  
  markerLabel_[mtic].setPosition(pos, scaleNumberAnchor_);
	markerLabel_[mtic].adjust(numbergap_);
	markerLabel_[mtic].draw();
}

Triple Axis::drawTic(Triple nadir, double length)
{
	double ilength = (symtics_) ? -length : 0.0;

	glBegin( GL_LINES );
	glVertex3d( nadir.x  + ilength * orientation_.x,
				      nadir.y  + ilength * orientation_.y,
							nadir.z  + ilength * orientation_.z) ; 
	glVertex3d( nadir.x  + length * orientation_.x,
							nadir.y  + length * orientation_.y,
							nadir.z  + length * orientation_.z);
	glEnd();
	return nadir;
}

void Axis::setNumberFont(QString const& family, int pointSize, int weight, bool italic)
{
	numberfont_ = QFont(family, pointSize, weight, italic );
}

void Axis::setNumberFont(QFont const& font)
{
	numberfont_ = font;
}

void Axis::setNumberColor(RGBA col)
{
	numbercolor_ = col;
}

void Axis::setLabelFont(QString const& family, int pointSize, int weight, bool italic)
{
	labelfont_ = QFont(family, pointSize, weight, italic );
  label_.setFont(family, pointSize, weight, italic);
}

void Axis::setLabelFont(QFont const& font)
{
	setLabelFont(font.family(), font.pointSize(), font.weight(), font.italic());
}

void Axis::setLabelString(QString const& name)
{
	label_.setString(name);
}

/*!
  Sets label position in conjunction with an anchoring strategy
*/
void Axis::setLabelPosition(const Triple& pos,Qwt3D::ANCHOR an)
{
	label_.setPosition(pos, an);
}

//! Sets color for label
void Axis::setLabelColor(RGBA col)
{
	label_.setColor(col);
}

Triple Axis::biggestNumberString()
{
	Triple ret;
	unsigned size = markerLabel_.size();

	double width, height;

	for (unsigned i=0; i!=size; ++i)
	{
		width = fabs( (World2ViewPort(markerLabel_[i].second())-World2ViewPort(markerLabel_[i].first())).x );
		height = fabs( (World2ViewPort(markerLabel_[i].second())-World2ViewPort(markerLabel_[i].first())).y );

		if (width > ret.x)
			ret.x = width + markerLabel_[i].gap();
		if (height > ret.y)
			ret.y = height + markerLabel_[i].gap();;
	}
	return ret;
}

/*! 
  This variant sets a user-defined scale object.
  Use with a heap based initialized pointer only.
  The axis adopts ownership. 
*/
void Axis::setScale(Scale* val)
{
  scale_ = qwt3d_ptr<Scale>(val); 
}

/*!
  Sets one of the predefined scaling types.
  \warning Too small intervals in logarithmic scales lead to  
  empty scales (or perhaps a scale only containing an isolated 
  major tic). Better switch to linear scales in such cases.
*/
void Axis::setScale(Qwt3D::SCALETYPE val)
{
  switch(val) {
  case Qwt3D::LINEARSCALE:
    setScale(new LinearScale);
  	break;
  case Qwt3D::LOG10SCALE:
    setScale(new LogScale);
    setMinors(9);
  	break;
  default:
    break;
  }
}


三、下载链接

https://download.csdn.net/download/u013083044/88745622?spm=1001.2014.3001.5503

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: webrtc-qt-example是一个基于Qt框架开发的WebRTC示例项目。 WebRTC是一种开源的实时通信技术,能够支持音频、视频和数据的实时传输。它通过浏览器之间的端对端连接,实现了高质量的实时通信。 webrtc-qt-example的目的是展示如何使用Qt进行WebRTC开发。Qt是一套跨平台的C++应用程序开发框架,它提供了丰富的工具和库,使开发者能够快速构建可靠的应用程序。 这个示例项目提供了一些基本的功能和界面,使开发者能够了解和学习如何将WebRTC集成到Qt应用程序中。它包含了常见的WebRTC功能,如媒体流捕获、媒体流传输、信令交换等。 通过webrtc-qt-example,开发者可以学习到如何使用Qt的多媒体模块来捕获音频、视频和媒体设备。同时,也可以学习到如何使用Qt的网络模块来进行实时信令交换和流传输。 这个示例项目还提供了一些简单的界面,方便开发者进行测试和调试。开发者可以通过该界面实现与其他WebRTC应用的通信,例如建立视频通话、音频通话等。 总之,webrtc-qt-example是一个非常实用的示例项目,可以帮助开发者快速上手并掌握WebRTC在Qt中的开发。 ### 回答2: webrtc-qt-example是一个基于Qt框架的WebRTC示例应用程序。WebRTC是一种开源项目,它提供了在浏览器之间进行实时通信的能力,包括视频和音频的传输。而webrtc-qt-example则是将这种技术集成到Qt应用程序中的一个示例。 在webrtc-qt-example中,它使用了Qt的多媒体框架和WebRTC提供的API来实现音视频的传输和显示。通过使用WebRTC的API,webrtc-qt-example可以建立点对点的连接,进行音频和视频的实时传输。 webrtc-qt-example中的代码结构清晰,易于理解和扩展。它提供了一些基本的功能,如建立连接、发送和接收音视频流、呼叫取消等。开发者可以根据自己的需求来对这些功能进行定制和扩展。 此外,webrtc-qt-example还支持一些高级特性,如媒体设备的选择、音视频的编码和解码等。开发者可以通过修改代码来选择不同的媒体设备,并且可以使用不同的编码和解码算法来满足自己的需求。 总之,webrtc-qt-example是一个很棒的WebRTC示例应用程序,它可以帮助开发者快速了解和使用WebRTC技术。无论是为了实现实时视频通话、视频会议还是其他需要音视频传输的应用场景,webrtc-qt-example都提供了一个良好的起点,帮助开发者快速上手并实现自己的需求。 ### 回答3: webrtc-qt-example是一个基于Qt框架和WebRTC技术的示例应用。WebRTC是一种用于在Web浏览器上实现实时通信的开源项目,它提供了一套丰富的API和协议,可以实现音视频通话、数据传输以及屏幕共享等功能。 webrtc-qt-example利用Qt框架提供的跨平台能力,结合WebRTC技术,展示了在Qt应用中如何实现实时通信功能。这个示例应用具有以下特点和功能: 1. 界面友好:webrtc-qt-example使用Qt的GUI绘制工具,具有美观、直观的用户界面,便于用户操作和使用。 2. 实时通信:webrtc-qt-example内置了WebRTC的音视频通信功能,可以实现实时的语音和视频通话,支持两个或多个用户之间的通信。 3. 数据传输:除了音视频通话,webrtc-qt-example还支持在通话中传输数据。可以通过编写代码,实现实时文本传输或共享文件等功能。 4. 屏幕共享:webrtc-qt-example还支持屏幕共享功能,可以将自己的屏幕内容分享给其他用户,实现远程协助或在线教育等应用场景。 通过webrtc-qt-example的学习和实践,开发者可以了解并深入理解WebRTC技术的使用方法,以及在Qt框架中的应用。同时,借助webrtc-qt-example提供的示例代码和API文档,开发者可以进一步开发出更加复杂和功能丰富的实时通信应用,满足不同领域的需求。 总之,webrtc-qt-example是一个基于Qt框架和WebRTC技术的示例应用,具备实时音视频通话、数据传输和屏幕共享等功能,适用于开发者学习、实践和开发基于WebRTC的实时通信应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进击的大海贼

联系博主,为您提供有价值的资源

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值