SoCallbackAction

/*----------------------------------------------------------- * Using a callback for generated primitives. * A simple scene with a sphere is created. * A callback is used to write out the triangles that * form the sphere in the scene. *----------------------------------------------------------*/ #include <Inventor/SoDB.h> #include <Inventor/SoPrimitiveVertex.h> #include <Inventor/actions/SoCallbackAction.h> #include <Inventor/actions/SoWriteAction.h> #include <Inventor/nodes/SoDirectionalLight.h> #include <Inventor/nodes/SoMaterial.h> #include <Inventor/nodes/SoPerspectiveCamera.h> #include <Inventor/nodes/SoSeparator.h> #include <Inventor/nodes/SoSphere.h> #ifdef WIN32 # include "print.h" #endif // Function prototypes void printSpheres(SoNode *); int printHeaderCallback(void *, SoCallbackAction *, const SoNode *); void printTriangleCallback(void *, SoCallbackAction *, const SoPrimitiveVertex *, const SoPrimitiveVertex *, const SoPrimitiveVertex *); void printVertex(const SoPrimitiveVertex *); // // CODE FOR The Inventor Mentor STARTS HERE void printSpheres(SoNode *root) { SoCallbackAction myAction; //#ifdef WIN32 // myAction.addPreCallback(SoSphere::getClassTypeId(), // printHeaderCallback, NULL); //#else myAction.addPreCallback(SoSphere::getClassTypeId(), (SoCallbackAction::SoCallbackActionCB *)printHeaderCallback, NULL); //#endif myAction.addTriangleCallback(SoSphere::getClassTypeId(), printTriangleCallback, NULL); myAction.apply(root); } int printHeaderCallback(void *, SoCallbackAction *, const SoNode *node) { printf("/n Sphere "); // Print the node name (if it exists) and address if (! !node->getName()) printf("named /"%s/" ", node->getName().getString()); printf("at address %#x/n", node); return SoCallbackAction::CONTINUE; } void printTriangleCallback(void *, SoCallbackAction *, const SoPrimitiveVertex *vertex1, const SoPrimitiveVertex *vertex2, const SoPrimitiveVertex *vertex3) { printf("Triangle:/n"); printVertex(vertex1); printVertex(vertex2); printVertex(vertex3); } void printVertex(const SoPrimitiveVertex *vertex) { const SbVec3f &point = vertex->getPoint(); printf("/tCoords = (%g, %g, %g)/n", point[0], point[1], point[2]); const SbVec3f &normal = vertex->getNormal(); printf("/tNormal = (%g, %g, %g)/n", normal[0], normal[1], normal[2]); } // CODE FOR The Inventor Mentor ENDS HERE /// int main(int, char **) { // Initialize Inventor SoDB::init(); // Make a scene containing a red sphere SoSeparator *root = new SoSeparator; SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoMaterial *myMaterial = new SoMaterial; root->ref(); root->addChild(myCamera); root->addChild(new SoDirectionalLight); myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); // Red root->addChild(myMaterial); root->addChild(new SoSphere); root->ref(); // Write out the triangles that form the sphere in the scene printSpheres(root); root->unref(); exit(1); // The usual exit(0) has been replaced with exit(1) to enable the console // window showing the output to stay on the screen until the user deletes it return 1; }

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在 IT 领域,数据库存储是处理多媒体数据(如图片)时不可或缺的环节。本示例主要探讨如何将图片通过 BASE64 编码后存入数据库的 Blob 类型字段,并能够从数据库中取出这些数据还原为原始图片。以下是相关知识点的说明: BASE64 编码:BASE64 是一种将二进制数据转换为 ASCII 字符串的编码方式。它通过将每 3 个字节的数据转换为 4 个字符,确保所有标准 ASCII 字符都能表示。在图片处理中,BASE64 编码常用于将图片数据转换为文本格式,便于在网络传输或存储时使用。 Blob 类型:Blob 是 Binary Large Object 的缩写,是数据库中用于存储大量二进制数据的字段类型,例如图片、音频、视频等。Blob 字段可存储非结构化数据,与普通数值或字符串字段不同。 图片加密:此处提到的“加密”可能是指 BASE64 编码过程,但这并非传统意义上的加密。BASE64 是一种编码方式,而非加密算法,因此不具备安全性。若需对图片进行安全保护,通常会使用 AES、RSA 等加密算法,而 BASE64 编码仅作为传输辅助手段。 图片解密:这里的“解密”可能是指将 BASE64 字符串恢复为原始图片数据的过程,即解码。解码是将 BASE64 编码的字符串转换回原始二进制形式。 数据库操作:插入和检索 Blob 类型字段通常需要使用 SQL 语句或 ORM 框架。例如,使用 Java 的 JDBC API,可通过 PreparedStatement 执行 INSERT 语句,再使用 OutputStream 将 BASE64 解码后的字节数组写入 Blob 对象。检索时,通过 ResultSet 获取 Blob 对象,读取其 InputStream,最终转换回图片。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值