使用 NZR 可视化点






3.33/5 (3投票s)
2007年8月14日
3分钟阅读

30234

1963
一篇关于 3D 点可视化的文章
引言
如果你住在波士顿,那么去 Fire & Ice 餐厅是一种享受。 你可以从各种各样的食材和酱料中创造你自己的特殊菜肴,而不必经历准备食材的麻烦。 NZR 可视化框架借鉴了 Fire & Ice 的一个页面,它为开发人员提供了一种在 3D 窗口中定制各种数据类型的可视化效果的能力,而无需学习 OpenGL 或其他复杂的可视化库。 本教程重点介绍使用 NZR 可视化点数据,并突出显示了这样做的简单性。
像点这样无害的东西,在 3D 空间中渲染它们时,可能具有相当大的复杂性。 在开发算法、科学数据收集、金融建模等时,通常需要可视化点数据。 开发人员通常必须学习复杂的图形包或依赖于罐头应用程序。 NZR 是 SoftServ Int'l. Corp. 宣布的一个新的可视化框架,它解耦了开发人员的所有数据渲染复杂性,并提供了一个非常简单的 API 来渲染各种类型的数据。 在这里,我将展示使用 NZR Lite 进行点数据的可视化,它实现了 NZR 功能的一个子集。 鼓励您尝试不同的属性设置,以探索其对您需求的适用性。
Using the Code
点可视化包括以下步骤
- 实例化点数据结构。
- 调用
newObject()
以在本地设置默认值,即在您的程序中。 - 在本地修改属性。
- 调用
createObject()
以在 NZR 内存中实例化对象。 - 填充点数据数组。
- 调用
writeObject()
将点数据传输到 NZR。 - 将相机设置在正确的 3D 位置。
- 调用
render()
来渲染数据。
NZR 有不同类型的光标来方便查看数据。 主 NZR 窗口有一个面板,可以随时显示相机设置。 这些设置可用于建立用于以编程方式设置相机的正确参数。
第一个示例使用 CONE
字形显示点数据,这些字形已根据与每个点关联的强度进行缩放。
#include "nzrLiteClient.h"
pPointLocations = new nzr_points;
// Set the default values locally
myNZRClient->newObject(pPointLocations); // set default values
// The default values are the Reference Position of
// the points in 3D window space
// , the scale of Points, the color of Points, the opacity of the Points
// , Light Model Parameters and the orientation of Points in the 3D window.
// Any of the above default display attributes can be changed
pPointLocations->cmnd.display.colorR = 10;
pPointLocations->cmnd.display.colorG = 10;
pPointLocations->cmnd.display.colorB = 10;
// The points can be visualized using glyphs, which are
// geometrical shapes representing a point
pPointLocations->glyphType = CONE;
// valid values are NONE, CONE, SPHERE, CUBE, ARROW, LINE, CYLINDER
pPointLocations->glyphScale = (float) 0.05; // Sets the scale of glyphs
// A glyph can be further scaled using either
// intensity or vector value associated with each point
pPointLocations->glyphScaleMode = INTENSITY; // could also be set to VECTOR
myNZRClient->createObject(pPointLocations); // creates the new object
// Initialize an array of points
float alpha = 20.0;
float beta = (float) 0.02;
pPointLocations->sizeOfData=0;
for( int t = 0; t < NUMBER_OF_POINTS; t++)
{
inputArray[t].x = (float) alpha*sin(t/(float) 10.0);
inputArray[t].y = (float) alpha*cos(t/(float) 10.0);
inputArray[t].z = (float) beta*t; // z value
inputArray[t].intensity = (float) (t%10); // change the intensity value
inputArray[t].vx = 0;
inputArray[t].vy = 0;
inputArray[t].vz = 1.0; // point the glyph in + z direction
pPointLocations->sizeOfData++;
}
// Now write the point values to NZR
myNZRClient->writeObject(pPointLocations, (void *) &inputArray[0]);
// Camera is used to set the viewpoint.
pMyCamera = new nzr_camera;
myNZRClient->newObject(pMyCamera); // set default values
// Over ride the camera settings
pMyCamera->FocalPointX = 0;
pMyCamera->FocalPointY = 0;
pMyCamera->FocalPointZ = 0;
pMyCamera->posX = 0;
pMyCamera->posY = 0;
pMyCamera->posZ = 100;
pMyCamera->ClippingNear = 97;
pMyCamera->ClippingFar = 103;
myNZRClient->setCamera(pMyCamera); // set camera parameter
// Now render the point data on NZR display which will make it visible
myNZRClient->render();
将程序与 *nzrLiteClientLibR.lib* 链接。 就这样。 在运行示例之前,NZR Lite 应该正在运行并打开 sc doc。 有几个辅助函数可用于删除场景中的单个对象或所有对象。 也可以以编程方式设置背景颜色。
有时,需要表示与点关联的矢量数据,例如,可视化高尔夫挥杆的动力学。 第二个示例展示了如何完成此操作,并使用第二组点呈现额外的点数据,但使用不同的字形类型进行可视化。 在这里,通过启用 glyphScaleMode
为 VECTOR
并填充矢量数据(如下所示)来可视化矢量数据。
pPointVectors->glyphScaleMode = VECTOR;
pPointVectors->glyphType = ARROW;
...
for( int t = 0; t < NUMBER_OF_POINTS; t++)
{
...
inputArray[t].vx = (float) 12*sin((float)t/20.0); // x value
inputArray[t].vy = (float) 12*cos((float)t/20.0); // y value
inputArray[t].vz = (float) 0; // z value
}
复杂的点数据可以采用类似的策略,即使用颜色、字形类型、缩放模式和不透明度的组合来直观地传达复杂的数据值。
关注点
我还包括了库中的 渲染折线,您可以尝试使用它。 我将在稍后的时间介绍使用 NZR 可视化线条。
历史
- 2007 年 8 月:首次发布