Skip to content

Instantly share code, notes, and snippets.

@jirihnidek
Created July 26, 2016 11:21
Show Gist options
  • Save jirihnidek/c3c868a6148018a8160b63e2aafe5f76 to your computer and use it in GitHub Desktop.
Save jirihnidek/c3c868a6148018a8160b63e2aafe5f76 to your computer and use it in GitHub Desktop.
OpenCascade Simple Face

OpenCascade Example of Face

Simple example of application using OpenCascade. It creates simple face and adds it to the sewing. You can build it at any platform using CMake and make:

mkdir build
cd build
cmake ../
make
# This example shows how to use find_package(OCE) by specifying
# a list of toolkits.
# If a toolkit is missing or if OCE is not found, a fatal error
# is thrown, we do not try to find an Opencascade installation.
cmake_minimum_required(VERSION 2.6)
find_package(OCE REQUIRED)
# Include files reside in ${OCE_INCLUDE_DIRS};
include_directories(${OCE_INCLUDE_DIRS})
# We do not need library path, they will be automatically imported.
add_executable(oce_face oce_face.cxx)
# Link binary with all OCE libraries (no documentation for this)
target_link_libraries(oce_face FWOSPlugin PTKernel TKAdvTools TKBinL TKBin TKBinTObj TKBinXCAF TKBool TKBO TKBRep TKCAF TKCDF TKernel TKFeat TKFillet TKGeomAlgo TKGeomBase TKG2d TKG3d TKHLR TKIGES TKLCAF TKMath TKMesh TKMeshVS TKNIS TKOffset TKOpenGl TKPCAF TKPLCAF TKPrim TKPShape TKService TKShapeSchema TKShHealing TKStdLSchema TKStdSchema TKSTEPAttr TKSTEPBase TKSTEP TKSTEP209 TKSTL TKTObj TKTopAlgo TKVoxel TKVRML TKV3d TKXCAFSchema TKXCAF TKXDEIGES TKXDESTEP TKXMesh TKXmlL TKXml TKXmlTObj TKXmlXCAF TKXSBase)
#include <stdlib.h>
#include <gp_Pnt.hxx>
#include <TopoDS_Edge.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <TopoDS_Face.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
int main(void)
{
// Create Sewing at the first time
BRepBuilderAPI_Sewing sewing;
// Create points
gp_Pnt point0 = gp_Pnt(0.25, 0.25, -1.0);
gp_Pnt point1 = gp_Pnt(0.75, 0.25, -1.0);
gp_Pnt point2 = gp_Pnt(0.75, 0.25, 1.0);
gp_Pnt point3 = gp_Pnt(0.25, 0.25, 1.0);
// Create edges
TopoDS_Edge edge0 = BRepBuilderAPI_MakeEdge(point0, point1);
TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(point1, point2);
TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge(point2, point3);
TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge(point3, point0);
// Create Wire
TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edge0, edge1, edge2, edge3);
// Create Face
TopoDS_Face face = BRepBuilderAPI_MakeFace(wire);
// Add face to sewing
sewing.Add(face);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment