OpenCASCADE Data Exchange - 3D PDF

OpenCASCADE Data Exchange - 3D PDF

eryar@163.com

Abstract. Today most 3D engineering model data are save to 3D PDF files. Universal 3D(U3D) along side Product Representation Compact(PRC), U3D is the historical foundation used to embed 3D interactive data and models into a PDF file. But PRC is now the preferred and most feature-rich method to embed 3D data into a PDF file. So the paper is focus on to translate OpenCASCADE geometry data to 3D PDF by embedding PRC file.

Key Words. PDF 3D, OpenCASCADE, U3D, PRC, libharu


1.Introduction

如今很多工程模型会转换成3D PDF格式,这样用户可以使用免费的Adobe Reader去查看模型,减轻用户软件授权费用。3D PDF可用于工程设计、制造、数值造型、医学、空间、地理及石油气的探索,建筑工程和环境调查,也可作为CAM、CAE、PLM的数据交换文件。还可用于培训、市场、存档及工程汇报等。

那么问题来了,如何将三维模型导入PDF文件呢?Adobe提供了嵌入两种文件格式U3D(Universal 3D)和PRC(Product Representation Compact)的方式来将三维模型导入PDF中。

U3D出现的时间较早,在sourceforge上有个u3d的库:

https://sourceforge.net/projects/u3d/

可用于将三维模型转换成U3D格式。其中MeshLab就是使用了这个工具,先将三维网格模型转换成IDTF格式,再调用IDTFConverter程序将其转换成U3D格式。下载了u3d的源码看了下,使用还比较复杂,而且软件授权方式是GPL的。

PRC是出现的比U3D要晚,所以PRC支持的几何形状比U3D要多,包括支持NURBS曲线曲面,还支持复杂的组合体。在网上找了下实现PRC文件读写的源码存在于一款数学软件Asymptote中,https://sourceforge.net/projects/asymptote

发现这个库使用起来相对U3D的要简单,且支持NURBS曲线曲面。

三维模型准备好了,需要将这些模型文件嵌入到PDF中。在网上找了下有个开源库libharu还是很不错的。

综上所述,准备考虑使用PRC->3D PDF的套路来实现将OpenCASCADE中的几何模型转换成3D PDF文件。

2.Code Example

结合上述思路,下载相应的库并编译通过,只需要如下简单的代码就可以将模型嵌入PDF中了,代码如下:

 

/*
*    Copyright (c) 2016 Shing Liu All Rights Reserved.
*
*           File : main.cpp
*         Author : Shing Liu(eryar@163.com)
*           Date : 2016-03-24 21:00
*        Version : OpenCASCADE6.9.0
*
*    Description : test embed 3d model into 3d pdf.
*/

#include "oPrcFile.h"

#include "hpdf.h"

#pragma comment(lib, "libprc.lib")
#pragma comment(lib, "libhpdfd.lib")

void testPrc(void)
{
    prc::oPRCFile aPrcFile("test.prc");

    prc::PRCmaterial materialGreen(
        prc::RGBAColour(0.0,0.18,0.0),
        prc::RGBAColour(0.0,0.878431,0.0),
        prc::RGBAColour(0.0,0.32,0.0),
        prc::RGBAColour(0.0,0.072,0.0),
        1.0,0.1);

    // Sphere
    aPrcFile.begingroup("Sphere");
    aPrcFile.addSphere(1.0, materialGreen);
    aPrcFile.endgroup();

    aPrcFile.addCylinder(0.8, 6.0, materialGreen);

    aPrcFile.finish();

    // embed prc file to pdf.
    HPDF_Doc aPdfDoc = HPDF_New (NULL, NULL);
    if (!aPdfDoc)
    {
        printf("error: cannot create PdfDoc object");
        return;
    }

    HPDF_Rect aRect = {0, 0, 800, 800};
    HPDF_Page aPage = HPDF_AddPage(aPdfDoc);
    HPDF_Page_SetWidth(aPage, aRect.right);
    HPDF_Page_SetHeight(aPage,aRect.top);

    HPDF_U3D aU3D = HPDF_LoadU3DFromFile(aPdfDoc, "test.prc");
    HPDF_Annotation aAnnot = HPDF_Page_Create3DAnnot(aPage, aRect, HPDF_TRUE, HPDF_FALSE, aU3D, NULL);

    HPDF_SaveToFile(aPdfDoc, "test.pdf");

    HPDF_Free(aPdfDoc);
}

int main(int argc, char* argv[])
{
    testPrc();

    return 0;
}

生成的test.pdf如下图所示:

 

Download 3D PDF test.pdf


3.Conclusion

通过将三维模型转换成U3D或PRC格式,就可以嵌入PDF中生成3D PDF。因为Adobe Reader的免费使用,所以可以减轻用户软件授权费用。若三维软件系统可以生成3D PDF也是一个功能亮点。

本文详细说明了如何将几何模型嵌入3D PDF中,并给出了代码示例。OpenCASCADE中的NURBS曲线曲面也可以直接转换成PRC格式。虽然PRC中也有BREP体,但是正确转换的前提是需要开发人员对两者的BREP有清晰的认识,难度较大。一种简单的处理方法是将模型全部转换成网格数据,再转换成PRC。

4.References

1. http://www.pdf3d.com/understanding-how-pdfe-u3d-and-prc-are-related-to-3d-pdf/

2. http://www.pdf3d.com/about-prc/

3. http://www.pdf3d.com/u3d/

时间: 2024-10-26 20:05:37

OpenCASCADE Data Exchange - 3D PDF的相关文章

Open Cascade Data Exchange --- STL

Open Cascade Data Exchange --- STL eryar@163.com 摘要Abstract:介绍了三维数据交换格式STL的组成,以及Open Cascade中对STL的读写.并将Open Cascade读进来的STL的三角面片在OpenSceneGraph中显示. 关键字Key Words:STL, Open Cascade, OpenSceneGraph, Data Exchange STL(the Stereo Lithograpy)是快速原型系统所应用的标准文件

Model Data Exchange Change Log

Model Data Exchange Change Log eryar@163.com 关键字:AVEVA Plant.PDMS.ModelDataExchange.IGES.STEP.STL.OpenCascade 1. 导出元素不限制为设备(Equipment),可以是任意选中的元素,如SITE.ZONE等等. 2. 可以导出除了管嘴外所有设备模型,包括负实体(Negative Primitives): 3. 可以导出的三维数据文件格式有:IGES.STEP.STL.3DS: 效果图如下所

AVEVA Model Data Exchange

 AVEVA Model Data Exchange Download ModelDataExchange V0.1: the ModelDataExchange Addin 1. Introduction The Model Data Exchange Addin allows the user to extract 3D geometric models from the DESIGN databases and output them in STEP, IGES, STL format.

AVEVA Model Data Exchange Exports Structure Models

AVEVA Model Data Exchange Exports Structure Modelseryar@163.com   Use Model Data Exchange Addin to export structure models for PDMS: Figure 1.1 Structure models in AVEVA PDMS Figure 1.2 Structure models exported by Model Data Exchange Figure 1.3 Put

RvmTranslator Translate RVM to 3D PDF

RvmTranslator Translate RVM to 3D PDF eryar@163.com The Portable Document Format(PDF) is a file format used to present documents in a manner independent of application software, hardware, and operating system. RVM file is used in AVEVA Review to visu

AVEVA Model Data Exchange V0.2

Download: AVEVA Model Data Exchange V0.2 AVEVA Model Data Exchange V0.2 增加导出3ds格式功能:

Open CASCADE Modeling Data – 3D Geometry

Open CASCADE Modeling Data – 3D Geometry eryar@163.com 一.概述 Overview 在创建几何对象之前,必须要考虑是用于三维还是用于二维,及怎样来处理之.OpenCASCADE提供了所有三维对象及其属性的数据结构. 二.包Geom 包Geom2d位于工具箱TKG3d中,定义了三维空间中的几何对象.所有的几何实体也是STEP可处理的.对象是非持久性的且由引用来控制.可用的对象如下: u 点: u 笛卡尔点: u 向量: u 方向: u 带幅值的

AVEVA Model Data Exchange ChangeLog

配置方法见程序文档说明或:http://www.cppblog.com/eryar/archive/2013/05/01/199875.html   RvmTranslator2.1  [20150818]----------------1. Improve performance for STEP translation;2. Finish parse all the primitive shapes in RVM file; RvmTranslator2.0  [20150504]-----

Model Data Exchange Change Log 2

eryar@163.com 可以导出管嘴模型: 可以导出设备所有模型. Figure 1.1 Equipment models in PDMS Figure 1.2 Exported equipment models include nozzles Figure 2. 1 Pumps and tanks equipments in PDMS Figure 2.2 Pumps and tanks exported by ModelDataExchange