当前位置: 首页 > wzjs >正文

如何通过网站做调查问卷饮食网站首页页面

如何通过网站做调查问卷,饮食网站首页页面,做投标的网站,受欢迎的邯郸网站建设文章目录 CloudCompare源码分析void ccGLWindowInterface::drawScale(const ccColor::Rgbub& color)🧩 总体功能🧠 函数逐步解析✅ 1. 断言只在正交模式下使用✅ 2. 计算显示的实际长度✅ 3. 字体和图形区域准备✅ 4. 计算比例尺图形的绘制位置✅ 5.…

文章目录

  • CloudCompare源码分析
    • void ccGLWindowInterface::drawScale(const ccColor::Rgbub& color)
      • 🧩 总体功能
      • 🧠 函数逐步解析
        • ✅ 1. 断言只在正交模式下使用
        • ✅ 2. 计算显示的实际长度
        • ✅ 3. 字体和图形区域准备
        • ✅ 4. 计算比例尺图形的绘制位置
        • ✅ 5. 绘制比例尺线段和端点刻度
        • ✅ 6. 绘制文字标签(比如 “10”)
      • 🧾 总结
      • ✅ 推荐你关注的点
    • double ccGLWindowInterface::computeActualPixelSize() const
      • ✅ 函数功能概述
      • 🧠 函数逐行解析
      • 🔁 举个例子说明
      • ✅ 总结
    • inline double RoundScale(double equivalentWidth)
    • ✅ 函数功能概述
      • 🧠 逐行详解
        • 1. 计算数量级 `k`
        • 2. 计算“粒度”或跳变步长
        • 3. 将输入值按 granularity 向下舍入
      • ✅ 举例
      • 🔧 总结

CloudCompare 的比例尺(Scale Bar)功能非常直观实用,它的实现具有以下几个关键点。下面将从 设计思想实现方式 两个方面详细说明,并与我们当前的实现思路进行对比,便于你优化自己的系统。


CloudCompare源码分析

源码链接:https://github.com/CloudCompare/CloudCompare
找到对应添加比例尺相关函数代码libs->qCC_glWindow->src->ccGLWindowInterface.cpp

void ccGLWindowInterface::drawScale(const ccColor::Rgbub& color)

在这里插入图片描述

void ccGLWindowInterface::drawScale(const ccColor::Rgbub& color)
{// 断言只在正交模式下使用assert(!m_viewportParams.perspectiveView); //a scale is only valid in ortho. mode!// 比例尺最大占屏幕宽度25%float scaleMaxW = glWidth() / 4.0f; //25% of screen width// 1像素对应的真实空间单位长度(如米)double pixelSize = computeActualPixelSize();// 将比例尺最大宽度(25% 屏幕)转换成实际长度(单位:米),并做了“美化舍入”,如 9.4 -> 10//we first compute the width equivalent to 25% of horizontal screen width//(this is why it's only valid in orthographic mode !)double equivalentWidth = RoundScale(scaleMaxW * pixelSize);// 字体和图形区域准备QFont font = getTextDisplayFont(); //we take rendering zoom into account!QFontMetrics fm(font); // 用于测量字体尺寸// 计算比例尺图形的绘制位置//we deduce the scale drawing widthfloat scaleW_pix = static_cast<float>(equivalentWidth / pixelSize);// 实际长度转换成像素长度float trihedronLength = computeTrihedronLength();// 屏幕上小坐标轴的长度float dW = 2.0f * trihedronLength + 20.0f * m_captureMode.zoomFactor;float dH = std::max(fm.height() * 1.25f, trihedronLength + 5.0f * m_captureMode.zoomFactor);float w = glWidth() / 2.0f - dW;float h = glHeight() / 2.0f - dH;float tick = 3.0f * m_captureMode.zoomFactor;ccQOpenGLFunctions* glFunc = functions();assert(glFunc);//force line widthglFunc->glPushAttrib(GL_LINE_BIT);glFunc->glLineWidth(1.0f);// 绘制比例尺线段和端点刻度//scale OpenGL drawingglColor3ubv_safe<ccQOpenGLFunctions>(glFunc, color);glFunc->glBegin(GL_LINES);// 主线段glFunc->glVertex3f(w - scaleW_pix, -h, 0.0f);glFunc->glVertex3f(w, -h, 0.0f);// 左刻度glFunc->glVertex3f(w - scaleW_pix, -h - tick, 0.0f);glFunc->glVertex3f(w - scaleW_pix, -h + tick, 0.0f);// 右刻度glFunc->glVertex3f(w, -h + tick, 0.0f);glFunc->glVertex3f(w, -h - tick, 0.0f);glFunc->glEnd();glFunc->glPopAttrib(); //GL_LINE_BIT// display label 绘制文字标签(比如 “10”)double textEquivalentWidth = RoundScale(scaleMaxW * pixelSize);QString text = QString::number(textEquivalentWidth);glColor3ubv_safe<ccQOpenGLFunctions>(glFunc, color);renderText(	glWidth() - static_cast<int>(scaleW_pix / 2 + dW) - fm.width(text) / 2,glHeight() - static_cast<int>(dH / 2) + fm.height() / 3,text,static_cast<uint16_t>(RenderTextReservedIDs::ScaleLabel),font);
}

这个函数 ccGLWindowInterface::drawScale() 是 CloudCompare 中 绘制比例尺(Scale Bar) 的主要函数。比例尺通常显示在右下角,仅在**正交视图(Orthographic View)**下启用,用于提示用户当前显示视图的空间尺度。


🧩 总体功能

绘制一个代表实际长度的线段比例尺(如 10m、100m 等),并在旁边绘制文字标签标注其长度。


🧠 函数逐步解析

✅ 1. 断言只在正交模式下使用
assert(!m_viewportParams.perspectiveView); // only valid in ortho. mode!

比例尺仅在正交投影下有效,透视模式下尺寸不再固定,比例尺无意义。


✅ 2. 计算显示的实际长度
float scaleMaxW = glWidth() / 4.0f; // 比例尺最大占屏幕宽度25%
double pixelSize = computeActualPixelSize(); // 1像素对应的真实空间单位长度(如米)
double equivalentWidth = RoundScale(scaleMaxW * pixelSize);
  • pixelSize: 当前视图下 1 像素等于多少“实际单位”(比如米)。
  • equivalentWidth: 将比例尺最大宽度(25% 屏幕)转换成实际长度(单位:米),并做了“美化舍入”,如 9.4 -> 10。

✅ 3. 字体和图形区域准备
QFont font = getTextDisplayFont();
QFontMetrics fm(font); // 用于测量字体尺寸

✅ 4. 计算比例尺图形的绘制位置
float scaleW_pix = equivalentWidth / pixelSize; // 实际长度转换成像素长度
float trihedronLength = computeTrihedronLength(); // 屏幕上小坐标轴的长度
float dW = 2.0f * trihedronLength + 20.0f * m_captureMode.zoomFactor;
float dH = max(fm.height() * 1.25f, trihedronLength + 5.0f * zoomFactor);
float w = glWidth() / 2.0f - dW;
float h = glHeight() / 2.0f - dH;
  • scaleW_pix: 比例尺显示为多长(像素数)。
  • w, h: 比例尺右端点坐标,一般在窗口右下角往左上偏移。
  • dW, dH: 距离边缘和文字的位置偏移量。

✅ 5. 绘制比例尺线段和端点刻度
glFunc->glBegin(GL_LINES);
// 主线段
glVertex3f(w - scaleW_pix, -h, 0.0f);
glVertex3f(w, -h, 0.0f);
// 左刻度
glVertex3f(w - scaleW_pix, -h - tick, 0.0f);
glVertex3f(w - scaleW_pix, -h + tick, 0.0f);
// 右刻度
glVertex3f(w, -h + tick, 0.0f);
glVertex3f(w, -h - tick, 0.0f);
glFunc->glEnd();

绘制了如下图形:

 |     ------------     |^ 左端点     ^ 右端点

✅ 6. 绘制文字标签(比如 “10”)
QString text = QString::number(textEquivalentWidth);
renderText(..., text, ..., font);

将比例尺的实际长度以文字形式显示在比例尺下方居中位置。


🧾 总结

功能实现
只在正交视图下启用assert(!m_viewportParams.perspectiveView)
以屏幕宽度 25% 为上限,计算比例尺真实长度scaleMaxW * pixelSize
比例尺线段与刻度绘制OpenGL glBegin(GL_LINES)...
长度文字标签绘制renderText(...)
缩放自适应pixelSizezoomFactor 控制

✅ 推荐你关注的点

  • RoundScale():控制比例尺长度的跳变规则(如 1/2/5/10/…)
  • computeActualPixelSize():控制比例尺单位与视图缩放的匹配方式
  • renderText():文字绘制细节,是否自动适配 DPI

double ccGLWindowInterface::computeActualPixelSize() const


double ccGLWindowInterface::computeActualPixelSize() const
{double pixelSize = m_viewportParams.computePixelSize(glWidth()); // we now use the width as the driving dimension for scaling// but we have to compensate for the aspect ratio is h > wdouble ar = static_cast<double>(glHeight()) / glWidth();if (ar > 1.0){pixelSize *= ar;}return pixelSize;}

你贴出的 ccGLWindowInterface::computeActualPixelSize() 是 CloudCompare 中**计算当前视图下每个像素所代表的真实空间长度(单位:米或其他单位)**的函数,是比例尺绘制逻辑的核心支撑之一。


✅ 函数功能概述

这个函数返回一个 pixelSize 值,即 “一个屏幕像素在当前视图中对应的实际长度(单位:米)”。这个值用于:

  • 比例尺长度的换算(实际长度 ↔ 屏幕像素长度)
  • label/文本等图元的缩放保持一致性

🧠 函数逐行解析

double pixelSize = m_viewportParams.computePixelSize(glWidth());
  • 使用 viewport 参数中的方法,传入当前窗口宽度(像素),计算当前视图下的单位像素长度
  • m_viewportParamsccViewportParameters 类型,表示当前视角的投影和缩放状态。
  • 默认使用 窗口宽度(X方向) 作为基础缩放维度。

double ar = static_cast<double>(glHeight()) / glWidth();
if (ar > 1.0)
{pixelSize *= ar;
}
  • 这一步是为了补偿高宽比不为1时的缩放失真

    • 当视图是竖屏(高度 > 宽度)时,Y方向单位会拉伸,比例尺就可能被拉短。
    • 通过乘上 aspectRatio = height / width,来补正这种拉伸,使得比例尺长度不变形。

🔁 举个例子说明

假设窗口是 800x600:

  • pixelSize = m_viewportParams.computePixelSize(800):表示800像素宽对应的实际场景宽度(如20米),那 1 像素就是 0.025米。
  • 如果是竖屏(高大于宽,比如 1200x800),Y方向会被压缩,因此乘以 1.5 来修正,让比例尺视觉效果正确。

✅ 总结

作用说明
控制比例尺精度决定 1 像素对应多少实际长度
正交视图缩放适配保证不同窗口尺寸、缩放下比例尺始终反映真实比例
支持非等比例窗口高宽比校正,避免变形显示

inline double RoundScale(double equivalentWidth)


inline double RoundScale(double equivalentWidth)
{//we compute the scale granularity (to avoid width values with a lot of decimals)int k = static_cast<int>(std::floor(std::log(equivalentWidth) / std::log(10.0f)));double granularity = std::pow(10.0, static_cast<double>(k)) / 2.0;//we choose the value closest to equivalentWidth with the right granularityreturn std::floor(std::max(equivalentWidth / granularity, 1.0))*granularity;
}

RoundScale() 是 CloudCompare 中用于**“美化”比例尺长度值**的函数,它会将任意的实际长度(如 92.342 米)舍入到一个“看起来舒服”的值(如 100 米)。


✅ 函数功能概述

inline double RoundScale(double equivalentWidth)

这个函数的目的:

  • equivalentWidth(比如 92.3 米)舍入为一个人类友好的、整洁的数值
  • 保证比例尺看起来是 10/20/50/100/500 这种“好看的刻度”

🧠 逐行详解

1. 计算数量级 k
int k = static_cast<int>(std::floor(std::log(equivalentWidth) / std::log(10.0f)));
  • 这是在算 equivalentWidth 的数量级(10 的几次方):

    • equivalentWidth = 92.3,则 log10(92.3) ≈ 1.965floor(...) = 1,说明是两位数 ≈ 10¹。
    • equivalentWidth = 734,则 k = 2(因为 10² = 100)。

2. 计算“粒度”或跳变步长
double granularity = std::pow(10.0, static_cast<double>(k)) / 2.0;
  • 使用 10 的 k 次方除以 2 得到跳变粒度:

    • 对于 92.3,k = 110¹ / 2 = 5.0
    • 对于 734,k = 2100 / 2 = 50.0
  • 这就让比例尺的跳变是:

    • 单位范围 10~100:每 5 增长(10, 15, 20…)
    • 单位范围 100~1000:每 50 增长(100, 150, 200…)

3. 将输入值按 granularity 向下舍入
return std::floor(std::max(equivalentWidth / granularity, 1.0)) * granularity;
  • equivalentWidth / granularity 得到倍数(如 92.3 / 5 = 18.46)

  • std::floor(...) * granularity → 向下舍入为最近的 granularity 倍数:

    • 92.3 → 18 * 5 = 90
    • 734 → 14 * 50 = 700
  • std::max(..., 1.0) 确保不会出现 0 值


✅ 举例

输入值 (equivalentWidth)粒度 (granularity)最终结果 (RoundScale)
92.3590
73450700
0.830.50.5
0.040.050.05

🔧 总结

目的实现
美化比例尺数字按数量级推导跳变步长
保证整齐可读避免像 92.387 这样的杂数
自适应范围自动在 0.05、0.5、5、50、500 之间切换


文章转载自:

http://tYILRqRP.pLqqn.cn
http://QjKrF0Yw.pLqqn.cn
http://VH8VEu1D.pLqqn.cn
http://IKGMOuX3.pLqqn.cn
http://QQgdxseg.pLqqn.cn
http://4QF1s8ml.pLqqn.cn
http://hb6YIbCZ.pLqqn.cn
http://PNjT8VuR.pLqqn.cn
http://nTyeQsgc.pLqqn.cn
http://HhdoyKrL.pLqqn.cn
http://6KddNdhh.pLqqn.cn
http://GBkzS9fd.pLqqn.cn
http://nQKTCVen.pLqqn.cn
http://1lGqtMm7.pLqqn.cn
http://VMo3beGv.pLqqn.cn
http://kuuWMEIb.pLqqn.cn
http://XiW1tIlW.pLqqn.cn
http://knA5LMLR.pLqqn.cn
http://8v8cbhdb.pLqqn.cn
http://Qwb03C2L.pLqqn.cn
http://EgykSdaD.pLqqn.cn
http://I37Dmau6.pLqqn.cn
http://1bwXheDx.pLqqn.cn
http://rFXAZcyo.pLqqn.cn
http://AC63i9Ko.pLqqn.cn
http://5DopkiWZ.pLqqn.cn
http://GeUMI8es.pLqqn.cn
http://J1kUanlb.pLqqn.cn
http://tZHPFfq7.pLqqn.cn
http://MPg57G1c.pLqqn.cn
http://www.dtcms.com/wzjs/760558.html

相关文章:

  • 做网站都有什么成本装饰工程施工
  • 农村电商网站建设方案各大网站黑白几天
  • 青海微信网站建设个性化WordPress网站
  • 网站建设的流程 步骤外链生成器
  • 教育网站制作方案给公司做网站要花多钱
  • 免费cad图纸下载网站学做网站 软件
  • 基于asp的网站设计与实现网站开发策划方案
  • 给别人做网站如何收费精准大数据营销公司
  • 学做古装网站快速做网站的技术
  • 网站改版设计流程江西城乡建设培训中心网站
  • 素材网站怎么推广医疗器械网上商城
  • 济南黄河路桥建设集团官方网站护肤品网站制作 网新科技
  • 在阿里云建设一个网站的全流程企业网站服务
  • 传奇网站发布网外贸网站seo优化方案
  • 某网站做参考文献的书写做网站的经历
  • 北京h5网站开发公司百度数据中心
  • 全景图制作平台网站建设.net网站空间
  • 网站建设关键要做好哪些工作wordpress文章页的宽度
  • 赤峰网站优化东莞企业黄页资料
  • 网站分站系统网站开发哪方面好做
  • 营销型网站标准网页源码哪家代理注册公司好
  • 用什么做淘宝客网站好手机网站怎么做淘宝客
  • html5做视频网站网页制作基础教程
  • 东莞高端品牌网站建设北京市住房与城乡建设厅网站
  • 松原网站建设公司天津建设项目招投标网站
  • 移动网站系统xuzhou网站制作
  • 深圳网站建设三把火科技wix wordpress
  • 网站开发搜索功能正规网站制作全包
  • vvic一起做网站2022年电商数据分析
  • 老牌网站建设建筑行业