10、基于osg引擎生成熱力圖高度圖實現3D熱力圖可視化、3D熱力圖實時更新(帶過渡效果)

1、結果
在這里插入圖片描述
在這里插入圖片描述
2、完整C++代碼

#include <sstream>
#include <iomanip>
#include <iostream>
#include <vector>
#include <random>
#include <cmath>
#include <functional>
#include <osgViewer/viewer>
#include <osgDB/ReadFile>
#include <osg/Texture3D>
#include <osg/Texture1D>
#include <osgDB/FileUtils>
#include <osg/Billboard>
#include <osg/TexGenNode>
#include <osg/ClipNode>
#include <osgDB/WriteFile>
#include <osg/Point>
#include <osg/ShapeDrawable>
#include <osg/PositionAttitudeTransform>
#include <osg/MatrixTransform>
#include <osgGA/TrackballManipulator>
#include <osg/ComputeBoundsVisitor>
#include <osg/TransferFunction>
#include <array>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator>
#include <osgUtil/SmoothingVisitor>
const std::string DATA_PATH = R"(..\data\)";
const std::string SHADER_PATH = R"(..\shaders\)";
const float RADIUS = 35;//設置熱力點的影響半徑
struct Point { int x, y; float value; };
// 生成隨機數
int getRandomInt(int min, int max) {return min + std::rand() % (max - min + 1);
}// 顏色插值(用于熱力圖漸變)
osg::Vec4 lerpColor(float value) {value = osg::clampBetween(value, 0.0f, 1.0f);  // 確保 value 在 [0, 1] 范圍內osg::Vec4 colors[] = {osg::Vec4(49/255.0, 54/255.0, 149/255.0, value),osg::Vec4(69/255.0, 117/255.0, 180/255.0, value),osg::Vec4(116/255.0, 173/255.0, 209/255.0, value),osg::Vec4(171/255.0, 217/255.0, 233/255.0, value),osg::Vec4(224/255.0, 243/255.0, 248/255.0, value),osg::Vec4(255/255.0, 255/255.0, 191/255.0, value),osg::Vec4(254/255.0, 224/255.0, 144/255.0, value),osg::Vec4(253/255.0, 174/255.0, 97/255.0, value),osg::Vec4(244/255.0, 109/255.0, 67/255.0, value),osg::Vec4(215/255.0, 48/255.0, 39/255.0, value),osg::Vec4(165/255.0, 0.0, 38/255.0, value)};//osg::Vec4 colors[] = {//    osg::Vec4(50 / 255.0, 136 / 255.0, 189 / 255.0, value),   //    osg::Vec4(102 / 255.0, 194 / 255.0, 165 / 255.0, value),//    osg::Vec4(171 / 255.0, 221 / 255.0, 164 / 255.0, value),//    osg::Vec4(230 / 255.0, 245 / 255.0, 152 / 255.0, value),//    osg::Vec4(254 / 255.0, 224 / 255.0, 139 / 255.0, value),//    osg::Vec4(253 / 255.0, 174 / 255.0, 97 / 255.0, value),//    osg::Vec4(244 / 255.0, 109 / 255.0, 67 / 255.0, value),//    osg::Vec4(213 / 255.0, 62 / 255.0, 79 / 255.0, value),//};int numColors = sizeof(colors) / sizeof(colors[0]);float t = value * (numColors - 1);      // 乘以 (數量-1)int index = static_cast<int>(t);// 處理邊界情況,避免越界if (index >= numColors - 1) {return colors[numColors - 1];       // 直接返回最后一個顏色}t -= index;// 提取 t 的小數部分,作為插值比例return colors[index] * (1 - t) + colors[index + 1] * t;
}std::vector<Point> generateData(int width, int height, int pointCount)
{std::vector<Point> points;for (int i = 0; i < pointCount; ++i) {points.push_back({ getRandomInt(10, width - 10), getRandomInt(10, height - 10), getRandomInt(0, 100) / 100.0f });}return points;
}// 生成熱力圖圖像
osg::ref_ptr<osg::Image> generateHeatmap(int width, int height, std::vector<Point> points) {osg::ref_ptr<osg::Image> image = new osg::Image();image->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE);std::vector<unsigned char> buffer(width * height * 4, 0); // 初始化RGBA緩沖區// 繪制點 (模擬圓形模糊)for (const auto& p : points) {for (int dx = -RADIUS; dx <= RADIUS; ++dx) {for (int dy = -RADIUS; dy <= RADIUS; ++dy) {int px = p.x + dx;//計算當前像素的x坐標int py = p.y + dy;//計算當前像素的y坐標//確保當前像素點在圖像范圍內if (px >= 0 && px < width && py >= 0 && py < height) {//計算該像素點與中心點的歸一化距離float dist = std::sqrt(dx * dx + dy * dy) / RADIUS;//如果距離在熱力點影響范圍內if (dist <= 1.0f) {//計算當前像素在緩沖區中的索引int index = (py * width + px) * 4;//計算當前像素的影響強度float intensity = (1.0f - dist) * p.value;//疊加透明度float oldAlpha = buffer[index + 3] / 255.0f; // 讀取背景透明度(歸一化到0~1)float newAlpha = intensity + oldAlpha * (1.0f - intensity); // 計算混合透明度buffer[index + 3] = static_cast<int>(std::min(255.0f, newAlpha * 255)); // 更新透明度}}}}}// 顏色映射for (int i = 0; i < width * height; ++i) {float alpha = buffer[i * 4 + 3] / 255.0f; // 歸一化透明度osg::Vec4 color = lerpColor(alpha);buffer[i * 4] = static_cast<unsigned char>(color.r() * 255);buffer[i * 4 + 1] = static_cast<unsigned char>(color.g() * 255);buffer[i * 4 + 2] = static_cast<unsigned char>(color.b() * 255);buffer[i * 4 + 3] = static_cast<unsigned char>(color.a() * 255);}// 復制數據到 osg::Imagememcpy(image->data(), buffer.data(), buffer.size());return image;
}// 生成高度圖
osg::ref_ptr<osg::Image> generateHeightmap(int width, int height, std::vector<Point> points)
{osg::ref_ptr<osg::Image> image = new osg::Image;image->allocateImage(width, height, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);std::vector<float> heightBuffer(width * height, 0.0);//浮點型高度緩存// 計算高度影響(使用高斯衰減)for (const auto& p : points){for (int dx = -RADIUS; dx <= RADIUS; ++dx) {for (int dy = -RADIUS; dy <= RADIUS; ++dy) {int px = p.x + dx;int py = p.y + dy;if (px >= 0 && px < width && py >= 0 && py < height){float distance = std::sqrt(dx * dx + dy * dy);if (distance <= RADIUS) {float normalizedDist = distance / RADIUS;//高斯衰減系數float falloff = std::exp(-normalizedDist * normalizedDist * 4.0f);int index = py * width + px;heightBuffer[index] += falloff * p.value;}}}}}// 歸一化處理float maxHeight = *std::max_element(heightBuffer.begin(), heightBuffer.end());std::vector<unsigned char> grayBuffer(width * height);for (int i = 0; i < width * height; ++i){float normalized = heightBuffer[i] / maxHeight;grayBuffer[i] = static_cast<unsigned char>(normalized * 255);}memcpy(image->data(), grayBuffer.data(), grayBuffer.size());return image;
}void generateHeatmapTexture()
{std::vector<Point> data = generateData(1024, 1024, 100);osg::ref_ptr<osg::Image> heatmap2dImage = generateHeatmap(1024, 1024, data);osg::ref_ptr<osg::Image> heightmapImage = generateHeightmap(1024, 1024, data);// 使用OSG保存圖像if (osgDB::writeImageFile(*heatmap2dImage, "heatmap2d.png")) {std::cout << "Image saved as " << "heatmap_osg.png" << std::endl;}else {std::cerr << "Error saving image." << std::endl;}if (osgDB::writeImageFile(*heightmapImage, "heightmap.png")) {std::cout << "Image saved as " << "heightmap.png" << std::endl;}else {std::cerr << "Error saving image." << std::endl;}
}// 創建地形節點
osg::ref_ptr<osg::Node> createTerrain(osg::Image* heightmap, osg::Image* heatmap) {// 創建幾何體osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();osg::ref_ptr<osg::Geode> geode = new osg::Geode();geode->addDrawable(geometry);// 創建頂點數組osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array();const int width = heightmap->s();const int height = heightmap->t();const float terrainSize = 200.0f; // 地形物理尺寸const float heightScale = 50.0f;  // 高度縮放系數// 生成頂點數據unsigned char* heightData = heightmap->data();for (int y = 0; y < height; ++y) {for (int x = 0; x < width; ++x) {// 計算頂點位置(居中)float xPos = (x - width / 2.0f) * (terrainSize / width);float yPos = (y - height / 2.0f) * (terrainSize / height);float zPos = heightData[y * width + x] / 255.0f * heightScale;vertices->push_back(osg::Vec3(xPos, yPos, zPos));}}// 創建索引數組(三角形帶)osg::ref_ptr<osg::DrawElementsUShort> indices =new osg::DrawElementsUShort(GL_TRIANGLES);for (int y = 0; y < height - 1; ++y) {for (int x = 0; x < width - 1; ++x) {// 創建兩個三角形組成四邊形int i0 = y * width + x;int i1 = i0 + 1;int i2 = i0 + width;int i3 = i2 + 1;indices->push_back(i1);indices->push_back(i2);indices->push_back(i0);indices->push_back(i3);indices->push_back(i2);indices->push_back(i1);}}// 設置幾何體數據geometry->setVertexArray(vertices);geometry->addPrimitiveSet(indices);// 自動生成法線osgUtil::SmoothingVisitor::smooth(*geometry);// 創建紋理坐標數組osg::ref_ptr<osg::Vec2Array> texCoords = new osg::Vec2Array();for (int y = 0; y < height; ++y) {for (int x = 0; x < width; ++x) {// 歸一化紋理坐標 [0,1]float u = static_cast<float>(x) / (width - 1);float v = static_cast<float>(y) / (height - 1);texCoords->push_back(osg::Vec2(u, v));}}geometry->setTexCoordArray(0, texCoords);// 應用紋理osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D();texture->setImage(heatmap);texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);osg::StateSet* stateset = geode->getOrCreateStateSet();stateset->setTextureAttributeAndModes(0, texture);stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);stateset->setMode(GL_BLEND, osg::StateAttribute::ON);return geode;
}osg::Geode* createHeatmap3D() {const int GRID_SIZE = 256;osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;osg::ref_ptr<osg::Vec2Array> texCoords = new osg::Vec2Array;for (int y = 0; y < GRID_SIZE; ++y) {for (int x = 0; x < GRID_SIZE; ++x) {float u = x / (GRID_SIZE - 1.0f);float v = y / (GRID_SIZE - 1.0f);vertices->push_back(osg::Vec3(u * 100 - 50, v * 100 - 50, 0)); // 居中顯示texCoords->push_back(osg::Vec2(u, v));}}// 創建索引osg::ref_ptr<osg::DrawElementsUInt> indices =new osg::DrawElementsUInt(GL_TRIANGLES);for (int y = 0; y < GRID_SIZE - 1; ++y) {for (int x = 0; x < GRID_SIZE - 1; ++x) {int i0 = y * GRID_SIZE + x;int i1 = i0 + 1;int i2 = i0 + GRID_SIZE;int i3 = i2 + 1;indices->push_back(i1);indices->push_back(i2);indices->push_back(i0);indices->push_back(i3);indices->push_back(i2);indices->push_back(i1);}}geom->setVertexArray(vertices);geom->setTexCoordArray(0, texCoords);geom->addPrimitiveSet(indices);osgUtil::SmoothingVisitor::smooth(*geom);osg::Geode* geode = new osg::Geode;geode->addDrawable(geom);return geode;
}osg::Texture2D* createTexture(osg::Image* image) {osg::Texture2D* tex = new osg::Texture2D;tex->setImage(image);tex->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);tex->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);tex->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);return tex;
}void setupStateSet(osg::Geode* geode) {osg::StateSet* ss = geode->getOrCreateStateSet();// 混合設置ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);ss->setMode(GL_BLEND, osg::StateAttribute::ON);std::vector<Point> data = generateData(256, 256, 100);osg::ref_ptr<osg::Image> heatmap2dImage1 = generateHeatmap(256, 256, data);osg::ref_ptr<osg::Image> heightmapImage1 = generateHeightmap(256, 256, data);struct Textures {osg::ref_ptr<osg::Texture2D> current;osg::ref_ptr<osg::Texture2D> next;float transition = 0.0f;bool updating = false;};Textures heightTex, heatmapTex;// 初始紋理heightTex.current = createTexture(heightmapImage1);heatmapTex.current = createTexture(heatmap2dImage1);data = generateData(256, 256, 200);osg::ref_ptr<osg::Image> heatmap2dImage2 = generateHeatmap(256, 256, data);osg::ref_ptr<osg::Image> heightmapImage2 = generateHeightmap(256, 256, data);heightTex.next = createTexture(heightmapImage2);heatmapTex.next = createTexture(heatmap2dImage2);osg::Program* program = new osg::Program;ss->setAttribute(program);program->addShader(osgDB::readRefShaderFile(osg::Shader::VERTEX, SHADER_PATH + R"(heatmap3d.vert)"));program->addShader(osgDB::readRefShaderFile(osg::Shader::FRAGMENT, SHADER_PATH + R"(heatmap3d.frag)"));ss->setAttributeAndModes(program);program->addBindAttribLocation("texCoord", osg::Drawable::TEXTURE_COORDS_0);// 綁定紋理單元ss->setTextureAttribute(0, heightTex.current);ss->setTextureAttribute(1, heightTex.next);ss->setTextureAttribute(2, heatmapTex.current);ss->setTextureAttribute(3, heatmapTex.next);// Uniform綁定ss->addUniform(new osg::Uniform("heightMap", 0));ss->addUniform(new osg::Uniform("nextHeightMap", 1));ss->addUniform(new osg::Uniform("heatmap", 2));ss->addUniform(new osg::Uniform("nextHeatmap", 3));ss->addUniform(new osg::Uniform("transitionProgress", 0.0f));
}osg::Timer_t startTime;
bool startSimulate = false;
class KeyboardEventHandler : public osgGA::GUIEventHandler {
public:KeyboardEventHandler(){}bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) override {if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN) {switch (ea.getKey()) {case 't':  if (!startSimulate){startTime = osg::Timer::instance()->tick();startSimulate = true;}return true;default:return false;}}return false;}private:
};class TimeUpdateCallback : public osg::NodeCallback
{
public:TimeUpdateCallback()  {}virtual void operator()(osg::Node* node, osg::NodeVisitor* nv){if (startSimulate){osg::StateSet* ss = node->getStateSet();if (ss){float time = osg::Timer::instance()->delta_s(startTime, osg::Timer::instance()->tick()) / 3.0f;time = osg::clampBetween(time, 0.0f, 1.0f);if (time == 1.0){std::random_device rd;  // 用于獲取隨機種子std::mt19937 gen(rd()); // 使用 Mersenne Twister 算法// 定義一個分布范圍 [100, 200]std::uniform_int_distribution<> dis(100, 200);std::vector<Point> data = generateData(256, 256, dis(gen));osg::ref_ptr<osg::Image> heatmap2dImage = generateHeatmap(256, 256, data);osg::ref_ptr<osg::Image> heightmapImage = generateHeightmap(256, 256, data);ss->setTextureAttribute(0, ss->getTextureAttribute(1, osg::StateAttribute::TEXTURE));ss->setTextureAttribute(1, createTexture(heightmapImage));ss->setTextureAttribute(2, ss->getTextureAttribute(3, osg::StateAttribute::TEXTURE));ss->setTextureAttribute(3, createTexture(heatmap2dImage));ss->getUniform("transitionProgress")->set(0.0f);startTime = osg::Timer::instance()->tick();}elsess->getUniform("transitionProgress")->set(time);}traverse(node, nv);}}};int preview3DHeatmapWithAnimate()
{osg::Geode* geode = createHeatmap3D();setupStateSet(geode);geode->setUpdateCallback(new TimeUpdateCallback());osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;osg::ref_ptr<osg::Group> group = new osg::Group;group->addChild(geode);viewer->setSceneData(group);viewer->addEventHandler(new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet()));viewer->addEventHandler(new osgViewer::StatsHandler());osg::ref_ptr<KeyboardEventHandler> keyboardHandler = new KeyboardEventHandler;viewer->addEventHandler(keyboardHandler);return viewer->run();
}int preview3DHeatmap()
{std::vector<Point> data = generateData(256, 256, 100);osg::ref_ptr<osg::Image> heatmap2dImage = generateHeatmap(256, 256, data);osg::ref_ptr<osg::Image> heightmapImage = generateHeightmap(256, 256, data);osg::ref_ptr<osg::Node> node = createTerrain(heightmapImage, heatmap2dImage);osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;osg::ref_ptr<osg::Group> group = new osg::Group;group->addChild(node);viewer->setSceneData(group);viewer->addEventHandler(new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet()));viewer->addEventHandler(new osgViewer::StatsHandler());return viewer->run();
}int preview2DHeatmap() {std::vector<Point> data = generateData(256, 256, 100);osg::ref_ptr<osg::Image> heatmap2dImage = generateHeatmap(256, 256, data);// 創建帶紋理的四邊形幾何體osg::ref_ptr<osg::Geometry> quad = osg::createTexturedQuadGeometry(osg::Vec3(-1.0f, -1.0f, 0.0f), // 左下角頂點osg::Vec3(2.0f, 0.0f, 0.0f),  // 寬度向量osg::Vec3(0.0f, 2.0f, 0.0f),  // 高度向量0.0f, 0.0f, 1.0f, 1.0f        // 紋理坐標 (左下角到右上角));osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;texture->setImage(heatmap2dImage);osg::ref_ptr<osg::StateSet> stateSet = quad->getOrCreateStateSet();stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);// 創建Geode并添加幾何體osg::ref_ptr<osg::Geode> geode = new osg::Geode;geode->addDrawable(quad);// 創建場景圖根節點osg::ref_ptr<osg::Group> root = new osg::Group;root->addChild(geode);// 創建并設置ViewerosgViewer::Viewer viewer;viewer.setSceneData(root);return viewer.run();
}int main()
{//return preview2DHeatmap();//return preview3DHeatmap();return preview3DHeatmapWithAnimate();
}

3、著色器代碼

//heatmap3d.vert
#version 110
/* GLSL 1.10需要顯式聲明精度 (OpenGL ES要求) */
#ifdef GL_ES
precision highp  float;
#endif
/* 自定義 uniforms */
uniform sampler2D heightMap;
uniform sampler2D nextHeightMap;
uniform float transitionProgress;
attribute vec2 texCoord;
// 輸入紋理坐標屬性(對應幾何體的第0層紋理)
varying vec2 vTexCoord;void main() {float x = gl_Vertex.x;float y = gl_Vertex.y;vTexCoord = texCoord;// 使用 texture2D 代替 texture 函數float currentHeight = texture2D(heightMap, texCoord.xy).r * 50.0;float nextHeight = texture2D(nextHeightMap, texCoord.xy).r * 50.0;// 高度插值計算float finalHeight = mix(currentHeight, nextHeight, transitionProgress);// 坐標變換vec4 pos = vec4(x, y, finalHeight, 1.0);gl_Position = gl_ModelViewProjectionMatrix * pos;
}
//heatmap3d.frag
#version 110
/* GLSL 1.10需要顯式聲明精度 (OpenGL ES要求) */
#ifdef GL_ES
precision mediump float;
#endifuniform sampler2D heatmap;
uniform sampler2D nextHeatmap;
uniform float transitionProgress;
varying vec2 vTexCoord;void main() {// 使用texture2D替代texture函數vec4 currentColor = texture2D(heatmap, vTexCoord);vec4 nextColor = texture2D(nextHeatmap, vTexCoord);// 使用gl_FragColor替代自定義輸出gl_FragColor = mix(currentColor, nextColor, transitionProgress);
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/73713.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/73713.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/73713.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

海量數據查詢加速:Presto、Trino、Apache Arrow

1. 引言 在大數據分析場景下,查詢速度往往是影響業務決策效率的關鍵因素。隨著數據量的增長,傳統的行存儲數據庫難以滿足低延遲的查詢需求,因此,基于列式存儲、向量化計算等技術的查詢引擎應運而生。本篇文章將深入探討 Presto、Trino、Apache Arrow 三種主流的查詢優化工…

Pycharm 社區版安裝教程

找到安裝包雙擊安裝文件---點擊下一步 一般路徑是&#xff1a;C:\Rambo\Software\Development 選擇完成后就是如下地址&#xff1a; C:\Rambo\Software\Development\PyCharm Community Edition 2024.3.3 點擊上述3個位置就可以了----下一步 等待安裝就可以了---完成后點擊完成…

vue3 elementUi table自由渲染組件

文章目錄 前言CustomTable如何使用tableColumn 屬性h函數創建原生元素創建組件動態生成 前言 elementui中的table組件&#xff0c;表格中想要自由地渲染內容&#xff0c;是一種比較麻煩的事情&#xff0c;比如你表格中想要某一列插入一個button按鈕&#xff0c;是不是要用插槽…

Mermaid 子圖 + 拖拽縮放:讓流程圖支持無限細節展示

在技術文檔、項目管理和可視化分析中&#xff0c;流程圖是傳遞復雜邏輯的核心工具。傳統流程圖往往靜態且難以適應細節展示&#xff0c;而 Mermaid 與 svg-pan-zoom 的結合&#xff0c;則為這一痛點提供了完美解決方案。本文將深入解析如何通過 Mermaid 的子圖&#xff08;subg…

前端權限系統

前端權限系統是為了確保用戶只能訪問他們有權限查看的資源而設計的。在現代前端開發中&#xff0c;權限控制不僅僅是簡單的顯示或隱藏元素&#xff0c;還涉及到對路由、組件、數據和操作權限的細致控制。下面是前端權限系統的常見設計方案和實現步驟。 前端權限系統的組成部分 …

Nature | TabPFN:表格基礎模型用于小規模數據分析

表格數據是按行和列組織的電子表格形式&#xff0c;在從生物醫學、粒子物理到經濟學和氣候科學等各個科學領域中無處不在 。基于表格其余列來填充標簽列缺失值的基本預測任務&#xff0c;對于生物醫學風險模型、藥物研發和材料科學等各種應用至關重要。盡管深度學習徹底改變了從…

c++學習系列----003.寫文件

c 寫文件 文章目錄 c 寫文件1?? 使用 ofstream 寫入文本文件2?? 追加模式寫入3?? 寫入二進制文件4?? 使用 fstream 進行讀寫5?? 使用 fprintf()&#xff08;C 方式&#xff09;6?? 使用 write() 低級 I/O 方式推薦方式 C 寫文件的幾種方式主要有以下幾種&#xff1…

C語言及內核開發中的回調機制與設計模式分析

在C語言以及操作系統內核開發中,回調機制是一種至關重要的編程模式。它通過注冊框架和定義回調函數,實現了模塊間的解耦和靈活交互,為系統的擴展性和可維護性提供了有力支持。本文將深入探討這種機制的工作原理、應用場景以及與設計模式的關聯。 一、回調機制的核心概念 (…

淺談StarRocks SQL性能檢查與調優

StarRocks性能受數據建模、查詢設計及資源配置核心影響。分桶鍵選擇直接決定數據分布與Shuffle效率&#xff0c;物化視圖可預計算復雜邏輯。執行計劃需關注分區裁剪、謂詞下推及Join策略&#xff0c;避免全表掃描或數據傾斜。資源層面&#xff0c;需平衡并行度、內存限制與網絡…

stable Diffusion 中的 VAE是什么

在Stable Diffusion中&#xff0c;VAE&#xff08;Variational Autoencoder&#xff0c;變分自編碼器&#xff09;是一個關鍵組件&#xff0c;用于生成高質量的圖像。它通過將輸入圖像編碼到潛在空間&#xff08;latent space&#xff09;&#xff0c;并在該空間中進行操作&…

從零開始 | C語言基礎刷題DAY3

?個人主頁&#xff1a;折枝寄北的博客 目錄 1.打印3的倍數的數2.從大到小輸出3. 打印素數4.打印閏年5.最大公約數 1.打印3的倍數的數 題目&#xff1a; 寫一個代碼打印1-100之間所有3的倍數的數字 代碼&#xff1a; int main(){int i 0;for (i 1; i < 100; i){if (i % …

告別死鎖!Hyperlane:Rust 異步 Web 框架的終極解決方案

告別死鎖&#xff01;Hyperlane&#xff1a;Rust異步Web框架的終極解決方案 &#x1f525; 為什么選擇Hyperlane&#xff1f; Hyperlane是專為Rust開發者打造的高性能異步Web框架&#xff0c;通過革命性的并發控制設計&#xff0c;讓您徹底擺脫多線程編程中的死鎖噩夢。框架內…

CLR中的類型轉換

CLR中的類型轉換 字符串類型轉換容器類型轉換自定義類型相互轉換項目設置CLR(Common Language Runtime,公共語言運行時)是微軟.NET框架的核心組件,是微軟對 CLI 標準的具體實現,負責管理和執行托管代碼,提供跨語言互操作性、內存管理、安全性等關鍵服務CLR的類型轉換機制…

QT5.15.2加載pdf為QGraphicsScene的背景

5.15.2使用pdf 必須要安裝QT源碼&#xff0c;可以看到編譯器lib目錄已經有pdf相關的lib文件&#xff0c;d是debug 1.找到源碼目錄&#xff1a;D:\soft\QT\5.15.2\Src\qtwebengine\include 復制這兩個文件夾到編譯器的包含目錄中:D:\soft\QT\5.15.2\msvc2019_64\include 2.找…

MCP 開放協議

本文翻譯整理自&#xff1a; https://modelcontextprotocol.io/introduction 文章目錄 簡介一、關于 MCP二、為什么選擇MCP&#xff1f;通用架構 三、開始使用1、快速入門2、示例 四、教程五、探索 MCP六、貢獻和支持反饋貢獻支持和反饋 服務器開發者一、構建服務器1、我們將要…

主流區塊鏈

文章目錄 主流鏈1. Solana特點&#xff1a;適用場景&#xff1a;工具鏈&#xff1a; 2. Binance Smart Chain (BSC)特點&#xff1a;適用場景&#xff1a;工具鏈&#xff1a; 3. Avalanche特點&#xff1a;適用場景&#xff1a;工具鏈&#xff1a; 4. Polkadot特點&#xff1a;…

GaussDB備份數據常用命令

1、常用備份命令gs_dump 說明&#xff1a;是一個服務器端工具&#xff0c;可以在線導出數據庫的數據&#xff0c;這些數據包含整個數據庫或數據庫中指定的對象&#xff08;如&#xff1a;模式&#xff0c;表&#xff0c;視圖等&#xff09;&#xff0c;并且支持導出完整一致的數…

ctfshow-萌新賽刷題筆記

1. 給她 啟動靶機&#xff0c;發現是sql注入&#xff0c;嘗試后發現被轉義\&#xff0c;思路到這里就斷了&#xff0c;再看題目給她&#xff0c;想到git.有可能是.git文件泄露&#xff0c;dirsearch掃描一下果然是&#xff0c;用GitHack看一下git備份文件&#xff0c;得到hint…

Transformer:GPT背后的造腦工程全解析(含手搓過程)

Transformer&#xff1a;GPT背后的"造腦工程"全解析&#xff08;含手搓過程&#xff09; Transformer 是人工智能領域的革命性架構&#xff0c;通過自注意力機制讓模型像人類一樣"全局理解"上下文關系。它摒棄傳統循環結構&#xff0c;采用并行計算實現高…

算法備案全景洞察趨勢解碼:技術迭代、行業裂變與生態重構

自 2023 年《互聯網信息服務深度合成管理規定》實施以來&#xff0c;算法備案已成為中國 AI 產業發展的晴雨表。截至 2025 年第十批備案公布&#xff0c;累計通過審核的深度合成算法已突破 5000 項&#xff0c;勾勒出一條 “技術攻堅 - 場景落地 - 生態構建” 的清晰軌跡。本文…