使用Opencascade读取igs文件内模型,使用vtk进行显示。

本案例环境:Opencascade6.6.0 +  vtk-5.10 + VS2005(win32)

使用CMake管理工程。

CMakeLists.txt :

PROJECT (IgesReader)

#VTK Part:
FIND_PACKAGE(VTK)
IF (VTK_FOUND)
INCLUDE(${VTK_USE_FILE})
ELSE(VTK_FOUND)
MESSAGE(FATAL_ERROR
"Cannot build without VTK. Please set VTK_DIR.")
ENDIF (VTK_FOUND) #OpenCascade Part:
INCLUDE_DIRECTORIES(
C:\OpenCASCADE6.6.0\ros\inc
) LINK_LIBRARIES(
vtkCommon
vtkGraphics
vtkRendering
vtkIO
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKIGES.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKernel.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKBRep.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKMath.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKGeomBase.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKGeomAlgo.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKG3d.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKG2d.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKTopAlgo.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKXSBase.lib
C:\OpenCASCADE6.6.0\ros\win32\vc8\libd\TKMesh.lib
) ADD_EXECUTABLE(IgesReader Readiges.cpp)

main.cpp:

#define WNT
#include <gp_Circ.hxx>
#include <gp_Elips.hxx>
#include <gp_Sphere.hxx> #include <Poly_Polygon3D.hxx>
#include <Poly_Triangulation.hxx> #include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_HSequenceOfShape.hxx> #include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx> #include <IGESControl_Controller.hxx>
#include <IGESControl_Writer.hxx>
#include <IGESControl_Reader.hxx> #include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS.hxx> #include <BRep_Tool.hxx>
#include <BRepMesh.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx> #include <BRepAdaptor_Curve.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <TopExp_Explorer.hxx>
#include <Standard_TypeDef.hxx> #include <iostream> #include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h> //vtk lib
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
#include <vtkTriangle.h> Standard_Integer ReadIGES(const Standard_CString& aFileName,
Handle(TopTools_HSequenceOfShape)& aHSequenceOfShape)
{ IGESControl_Reader Reader; Standard_Integer status = Reader.ReadFile(aFileName); if (status != IFSelect_RetDone)
{
return status;
} Reader.TransferRoots(); TopoDS_Shape aShape = Reader.OneShape();
aHSequenceOfShape->Append(aShape); return status;
} void BuildMesh(vtkRenderer* render, const TopoDS_Face& face, double deflection = 0.1)
{
TopLoc_Location location;
BRepMesh::Mesh(face, deflection); Handle_Poly_Triangulation triFace = BRep_Tool::Triangulation(face, location); Standard_Integer nTriangles = triFace->NbTriangles(); gp_Pnt vertex1;
gp_Pnt vertex2;
gp_Pnt vertex3; Standard_Integer nVertexIndex1 = 0;
Standard_Integer nVertexIndex2 = 0;
Standard_Integer nVertexIndex3 = 0; TColgp_Array1OfPnt nodes(1, triFace->NbNodes());
Poly_Array1OfTriangle triangles(1, triFace->NbTriangles()); nodes = triFace->Nodes();
triangles = triFace->Triangles(); vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
points->Allocate(nTriangles * 3);
cells->Allocate(nTriangles); int id = 0; for (Standard_Integer i = 1; i <= nTriangles; i++)
{
Poly_Triangle aTriangle = triangles.Value(i); aTriangle.Get(nVertexIndex1, nVertexIndex2, nVertexIndex3); vertex1 = nodes.Value(nVertexIndex1).Transformed(location.Transformation());
vertex2 = nodes.Value(nVertexIndex2).Transformed(location.Transformation());
vertex3 = nodes.Value(nVertexIndex3).Transformed(location.Transformation()); points->InsertNextPoint(vertex1.X(), vertex1.Y(), vertex1.Z());
points->InsertNextPoint(vertex2.X(), vertex2.Y(), vertex2.Z());
points->InsertNextPoint(vertex3.X(), vertex3.Y(), vertex3.Z()); vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
triangle->GetPointIds()->SetId(0,id * 3);
triangle->GetPointIds()->SetId(1,id * 3 + 1);
triangle->GetPointIds()->SetId(2,id *3 + 2); // Add the triangle to a cell array
cells->InsertNextCell(triangle);
id++;
} polyData->SetPoints(points);
polyData->SetPolys(cells); vtkSmartPointer<vtkPolyDataMapper> sourceMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
sourceMapper->SetInput(polyData); vtkSmartPointer<vtkActor> sourceActor = vtkSmartPointer<vtkActor>::New();
sourceActor->SetMapper(sourceMapper);
sourceActor->GetProperty()->SetColor(1,0,0); render->AddActor(sourceActor); } void BuildScene( vtkRenderer *renderer, Handle(TopTools_HSequenceOfShape)& aHSequenceOfShape)
{
Standard_Integer index = aHSequenceOfShape->Length();
TopoDS_Shape theCompSolid = aHSequenceOfShape->ChangeValue(index); for (TopExp_Explorer faceExp(theCompSolid, TopAbs_FACE); faceExp.More(); faceExp.Next())
{
// The 3d-mesh of the FACE is assembled to form the
// boundary of the SOLID. const TopoDS_Face& theFace = TopoDS::Face(faceExp.Current());
BuildMesh(renderer, theFace ); } } int main(void)
{
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer); vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow); Handle(TopTools_HSequenceOfShape) aHSequenceOfShape = new TopTools_HSequenceOfShape();
Standard_Integer status = ReadIGES("e:\\p3.igs",aHSequenceOfShape);
cout<<"return status:"<<status<<endl; BuildScene(renderer, aHSequenceOfShape); renderer->SetBackground(1,1,1); // Render and interact
renderWindow->Render();
renderWindowInteractor->Start(); return 0; }

实例显示:

occ+vtk显示igs模型的更多相关文章

  1. 自制C#版3DS文件的解析器并用SharpGL显示3DS模型

    自制C#版3DS文件的解析器并用SharpGL显示3DS模型 我已经重写了3ds解析器,详情在此(http://www.cnblogs.com/bitzhuwei/p/CSharpGL-2-parse ...

  2. Unity在UI界面上显示3D模型/物体,控制模型旋转

    Unity3D物体在UI界面的显示 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...

  3. PHP--TP框架----把查询到的数据,显示在模型(模板)里面

    MainController.class.php <?php namespace Home\Controller; use Think\Controller; class MainControl ...

  4. Flash Stage3D 在2D UI 界面上显示3D模型问题完美解决

    一直以来很多Stage3D开发者都在为3D模型在2DUI上显示的问题头疼.Stage3D一直是在 Stage2D下面.为了做到3D模型在2DUI上显示通常大家有几种实现方式,下面来说说这几种实现方式吧 ...

  5. VTK拾取网格模型上的可见点

    消隐与Z-Buffer 使用缓冲器记录物体表面在屏幕上投影所覆盖范围内的全部像素的深度值,依次访问屏幕范围内物体表面所覆盖的每一像素,用深度小(深度用z值表示,z值小表示离视点近)的像素点颜色替代深度 ...

  6. 十ITK读取一张dcm图像然后通过vtk显示

    一.功能 通过ITK读取一张图片(dcm格式),然后通过vtk显示出来. 版本:VS2019 itk5.0.1 vtk 8.2.0 二.程序主要思路 1-读取dcm格式图片 2-转换为vtk可以读取的 ...

  7. VTK显示.vtk格式文件

    void ReadandShowVTKFile () { vtkSmartPointer<vtkRenderer > aRenderer = vtkSmartPointer<vtkR ...

  8. VTK计算网格模型上的最短路径

    Dijkstra algorithm to compute the graph geodesic.Takes as input a polygonal mesh and performs a sing ...

  9. 把pcl的VTK显示融合到MFC(代码找原作者)

    转自PCL中国,原文链接:http://www.pclcn.org/bbs/forum.php?mod=viewthread&tid=223&extra=page%3D1 本人做了少量 ...

随机推荐

  1. asprise-ocr-api-sample 高价收破解版64 32位

    asprise-ocr-api-sample验证码 高价收破解版64 32位 Reflector 8.5 打开自己的C#代码  完全100%的反编译了

  2. robotframework冷门关键字

    1.Reload Page 模拟页面重载 2.Register Keyword To Run On Failure 参数: Keyword 描述: 当Selenium2Library类库关键字执行失败 ...

  3. linux命令重定向>、>>、 1>、 2>、 1>>、 2>>、 <(转)

    原文章地址:https://www.cnblogs.com/piperck/p/6219330.html >和>>: 他们俩其实唯一的区别就是>是重定向到一个文件,>&g ...

  4. [JZOJ3362] 【NOI2013模拟】数数

    题目 题目大意 求区间\([A,B]\)有多少个数是"完美的". 一个数是"完美的",当且仅当这个数的各位能分成两个集合,使得两个集合中数字的和相等. \(B\ ...

  5. bootstrap1总结

    bootstrap中的排版----标题: 标题(h1~h6/.h1~.h6) 副标题(small) h1:36px h2:30px h3:24px h4:18px h5:14px h6:12px 排版 ...

  6. (转)ActiveMQ 使用场景

    转:http://306963591.iteye.com/blog/1044166 ActiveMQ 安装测试就不做介绍了,下面我说说ActiveMQ 使用场景. 1.非均匀应用集成 ActiveMQ ...

  7. (20)Oracle函数

    substr 截取字段 substr(字符串,截取开始位置,截取长度) substr(str,n,m) 第二,三参数可以省略, 第二个参数为负数时表示从倒数第n位开始向后截取m个 round(str, ...

  8. day19_生成器

    20180730 初次上传 20180731 更新,4.列表生成式,以及部分注释 #!/usr/bin/env python # -*- coding:utf-8 -*- # ************ ...

  9. service资源

    service的作用:帮助外界用户访问k8s内的服务,并且提供负载均衡 创建一个service vim k8s_svc.yml apiVersion: v1 kind: Service metadat ...

  10. datagrid 的标题的内容不对应整齐

    $(document).ready(function(){ var column = "[["+ "{'title':'工号','field':'grantorCode' ...