在编译occ通过过后,我需要验证occ是否能够正常结合vtk进行开发工作

使用CMake进行环境变量设置:

CMakeList.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.5.1\ros\inc
) LINK_LIBRARIES(
vtkCommon
vtkGraphics
vtkRendering
vtkIO
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKIGES.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKernel.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKBRep.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKMath.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKGeomBase.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKGeomAlgo.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKG3d.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKG2d.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKTopAlgo.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKXSBase.lib
C:\OpenCASCADE6.5.1\ros\win32\vc8\libd\TKMesh.lib
) ADD_EXECUTABLE(IGESReader example.cxx)

添加一个example.cxx

// sampleExample.cpp : Defines the entry point for the console application.
//
// OpenCascade library.
#include <gp_Circ.hxx>
#include <gp_Elips.hxx>
#include <gp_Sphere.hxx> #include <Poly_Polygon3D.hxx>
#include <Poly_Triangulation.hxx> #include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx> #include <BRep_Tool.hxx>
#include <BRepMesh.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx> //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> /*
* @breif Descret the shape: face.
* For Face will be discreted to triangles; (BRepMesh_FastDiscret)
* To get the triangles of the face, use BRep_Tool::Triangulation(Face, L);
*/
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* render)
{
gp_Ax2 axis; // 1. Test sphere face while deflection is default 0.1.
axis.SetLocation(gp_Pnt(26.0, 0.0, 0.0));
TopoDS_Face sphereFace1 = BRepBuilderAPI_MakeFace(gp_Sphere(axis, 8.0));
BuildMesh(render, sphereFace1); // 2. Test sphere face while deflection is 2.0.
axis.SetLocation(gp_Pnt(26.0, 18.0, 0.0));
TopoDS_Face sphereFace2 = BRepBuilderAPI_MakeFace(gp_Sphere(axis, 8.0));
BuildMesh(render,sphereFace2, 2.0); // 3. Test sphere face while deflection is 0.001.
axis.SetLocation(gp_Pnt(26.0, -18.0, 0.0));
TopoDS_Face sphereFace3 = BRepBuilderAPI_MakeFace(gp_Sphere(axis, 8.0));
BuildMesh(render, sphereFace3, 0.001);
} int main(int argc, char *argv[])
{
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow); //build mesh
BuildScene(renderer); renderer->SetBackground(1,1,1); // Render and interact
renderWindow->Render();
renderWindowInteractor->Start(); return 0;
}

你可能在编译的过程当中,遇到缺少dll文件,这个说明 你并没有把相应的dll文件放在环境变量当中去。

运行结果:

最新文章

  1. c/c++多线程模拟系统资源分配(并通过银行家算法避免死锁产生)
  2. C语言中指针的使用
  3. GridView--scroolview嵌套listview和gridview
  4. open和fopen的区别
  5. Common Linux log files name and usage--reference
  6. (原创)win7自带IIS7.5+php7.0.10安装教程(图)
  7. shell的string operator
  8. 初始go语言
  9. Markdown例子
  10. PAT1078 Hashing 坑爹
  11. 对JavaScript事件机制的一点理解
  12. 《深入浅出nodejs》读书笔记(1)
  13. sencha touch 选择器
  14. Jsp+Struts2+JavaBean+DAO开发模式(1)
  15. Maven项目打包成可执行Jar文件
  16. 去掉UITabBar和NavigationBar上的黑线
  17. [转][xml]SQL转义
  18. 解决IDEA 配置搞坏的问题
  19. winrar.exe 命令行参数
  20. QEMU,KVM及QEMU-KVM介绍

热门文章

  1. ubuntu卸载node和npm
  2. vue SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
  3. 在vue中使用高德地图vue-amap
  4. [JZOJ3690] 【CF418D】Big Problems for Organizers
  5. 【JZOJ4665】数列
  6. CSS——精灵技术
  7. hibernate_05_hibernateHQL查询QBC查询和SQL查询
  8. deployment资源
  9. dockerfile自动创建docker镜像
  10. MySQL 调优/优化的 101 个建议!