QT - qwtplot3d-3D图标

QT - qwtplot3d-3D图标

  • 一、演示效果
  • 二、关键程序
  • 三、下载链接


一、演示效果

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

二、关键程序

#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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/324397.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

GAN在图像数据增强中的应用

在图像数据增强领域&#xff0c;生成对抗网络&#xff08;GAN&#xff09;的应用主要集中在通过生成新的图像数据来扩展现有数据集的规模和多样性。这种方法特别适用于训练数据有限的情况&#xff0c;可以通过增加数据的多样性来提高机器学习模型的性能和泛化能力。 以下是GAN在…

RabbitMQ交换机(2)-Direct

1.Direct 直连(路由)交换机,生产者将消息发送到交换机&#xff0c;并指定消息的Routing Key&#xff08;路由键&#xff09;。交换机会将Routing Key与队列绑定进行匹配&#xff0c;如果匹配成功&#xff0c;则将该消息路由到对应的队列中。如果没有匹配成功&#xff0c;该消息…

如何看待 Linux 内核邮件列表重启将内核中的 C 代码转换为 C++

如何看待 Linux 内核邮件列表重启将内核中的 C 代码转换为 C 的讨论&#xff1f; 在开始前我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「Linux的资料从专业入门到高级教程」&#xff0c; 点个关注在评论区回复“888”之后私信回复“888”&#xff0c;全部无偿…

2024年腾讯云服务器购买价格,真便宜

腾讯云服务器租用价格表&#xff1a;轻量应用服务器2核2G3M价格62元一年、2核2G4M价格118元一年&#xff0c;540元三年、2核4G5M带宽218元一年&#xff0c;2核4G5M带宽756元三年、轻量4核8G12M服务器446元一年、646元15个月&#xff0c;云服务器CVM S5实例2核2G配置280.8元一年…

数据库——DAY3(练习-在表中查找数据-单表查询)

一、实验要求&#xff08;单表查询&#xff09; 素材&#xff1a; 表名&#xff1a;worker-- 表中字段均为中文&#xff0c;比如 部门号 工资 职工号 参加工作 等 CREATE TABLE worker ( 部门号 int(11) NOT NULL, 职工号 int(11) NOT NULL, 工作时间 date NOT NULL, 工资 fl…

pod 控制器

pod 控制器&#xff1a; pv pvc 动态pv pod控制器&#xff1a;工作负载&#xff0c;workload&#xff0c;用于管理pod的中间层&#xff0c;确保pod资源符号预期的状态。 预期状态&#xff1a; 1&#xff0c;副本数 2&#xff0c;容器的重启策略 3&#xff0c;镜像拉取策略…

【WSL】Win10 使用 WSL2 进行 Linux GPU 开发

1. GPU 驱动 先安装 驱动 参考 https://docs.nvidia.com/cuda/wsl-user-guide/index.html 使用 https://www.nvidia.com/Download/index.aspx 提供的兼容 GeForce 或 NVIDIA RTX/Quadro 显卡在系统上安装 NVIDIA GeForce Game Ready 或 NVIDIA RTX Quadro Windows 11 显示驱动…

【征服redis2】redis的事务与lua

1.redis事务介绍 在前面我们介绍了redis的几种典型数据结构和应用&#xff0c;本文我们来看一下redis的事务问题。事务也是数据库的重要主题&#xff0c;熟悉关系型数据库的读者应该对事务比较了解&#xff0c;简单地说&#xff0c;事务表示一组动作&#xff0c;要么全部执行&…

Web接口自动化测试之Get与Post请求

关于HTTP协议&#xff0c;我考虑了一下觉得没必要再花一节内容来介绍&#xff0c;因为网上关于HTTP协议的介绍非常详细。本着以尽量避免介绍一空洞了概念与理论来介绍接口测试&#xff0c;我这里仍然会给出具体实例。 在此之前先简单的介绍一下基本概念&#xff1a;我们想要打开…

new mars3d.control.LocationBar({实时获取到地球渲染后的帧率fps等信息

问题&#xff1a;new mars3d.control.LocationBar({实时获取到地球渲染后的帧率fps等信息 实现代码参考&#xff1a;可以获取到之后展示在其他位置。 let _lastFpsSampleTime Cesium.getTimestamp()let _lastMsSampleTime Cesium.getTimestamp()let _fpsFrameCount 0let _ms…

课设:NFA确定化和最小化程序的设计与实现(html+css+js实现)

文章目录 问题描述待解决问题1、如何存储NFA或者是DFA2、NFA多初态问题3、子集化过程思路4、分割法过程思路 使用方法&#xff1a;下载链接 问题描述 NFA确定化和最小化程序的设计与实现&#xff08;参考教材3.4节&#xff09; 目的&#xff1a;设计一个应用程序&#xff0c;将…

Android 12+ MQTT适配

最终的解决方案是下载源码去改。我用的是已经修改好了的库&#xff0c;如果包名要自己的&#xff0c; 要注意&#xff1a; 1. compileSdk 34 和 targetSdk 34 改成33&#xff08;Android12&#xff09;或者34&#xff08;Android13&#xff09;。 2. 下载的 module 导入。 …

运筹说 第56期 | 整数规划的数学模型割平面法

前几章讨论过的线性规划问题的一个共同特点是&#xff1a;最优解的取值可以是分数或者小数。然而&#xff0c;在许多实际问题中&#xff0c;决策者要求最优解必须是整数&#xff0c;例如公交车的车辆数、员工的人数、机器的台数、产品的件数等。那么&#xff0c;我们能否将得到…

第06章_面向对象编程(基础)拓展练习(求三角形面积,猴子吃桃,圆类,学生类,矩形类)

文章目录 第06章_面向对象编程&#xff08;基础&#xff09;拓展练习1、圆类2、学生类3、MyInt类4、MyDate日期类-15、MyDate日期类-26、数学计算工具类7、常识工具类8、学生对象数组9、员工管理类-110、员工管理类-211、比较大小12、数组排序和遍历13、求三角形面积14、图形工…

【分布式微服务专题】SpringSecurity OAuth2快速入门

目录 前言阅读对象阅读导航前置知识笔记正文一、OAuth2 介绍1.1 使用场景*1.2 基本概念&#xff08;角色&#xff09;1.3 优缺点 二、OAuth2的设计思路2.1 客户端授权模式2.1.0 基本参数说明2.1.1 授权码模式2.1.2 简化&#xff08;隐式&#xff09;模式2.1.3 密码模式2.1.4 客…

Maven 基础安装配置及使用

大家好我是苏麟 , 今天聊聊Maven . Maven Maven , 是Apache公司下基于Java开发的开源项目 . 我们构建一个项目需要用到很多第三方的类库&#xff0c;需要引入大量的jar包。一个项目Jar包的数量之多往往让我们瞠目结舌&#xff0c;并且Jar包之间的关系错综复杂&#xff0c;一…

Openlayer【四】—— 控件

控件 控件是一个可见的小部件&#xff0c;其 DOM 元素位于 屏幕。它们可以涉及用户输入&#xff08;按钮&#xff09;&#xff0c;也可以仅供参考; 位置是使用 CSS 确定的。默认情况下&#xff0c;它们位于 容器&#xff0c;但可以使用 任何外部 DOM 元素。 其中ol/control是…

【LV12 DAY20 RTC实验】

编程实现通过LED状态显示当前电压范围&#xff0c;并打印产生低压警报时的时间 注&#xff1a; 电压在1501mv~1800mv时&#xff0c;LED2、LED3、LED4、LED5点亮 电压在1001mv~1500mv时&#xff0c;LED2、LED3、LED4点亮 电压在501mv~1000mv时&#xff0c;LED2、LED3点亮 电压在…

车厢重组#洛谷

题目描述 在一个旧式的火车站旁边有一座桥&#xff0c;其桥面可以绕河中心的桥墩水平旋转。一个车站的职工发现桥的长度最多能容纳两节车厢&#xff0c;如果将桥旋转 180 180 180 度&#xff0c;则可以把相邻两节车厢的位置交换&#xff0c;用这种方法可以重新排列车厢的顺序…

自定义vector的实现

实现前需要思考的一个问题 为什么需要将空间的申请与对象的构建分开 查看vector的模板参数时可以看到其有第三个参数是空间适配器allocator&#xff0c;查找其对外提供的成员函数不难发现它的实现逻辑是将空间的申请与对象的构建分开的&#xff0c;为什么呢&#xff1f;不弄清…