Open CASCADE Technology: Modeling Data
Introduction Modeling Data supplies data structures to represent 2D and 3D geometric models. This manual explains how to use Modeling Data. Geometry Utilities Geometry Utilities provide the following services: Creation of shapes by interpolation and approx
dev.opencascade.org
Topology
Pure topological data structures.
Defines relationships between simple geometric entities.
Assemblies of simpler entities.
mixed-dimensional;
- 0D entities such as points;
- 1D entities such as curves;
- 2D entities such as surfaces;
- 3D entities such as volumes.
basic entity in abstract topological data structure;
- Vertex – a zero-dimensional shape corresponding to a point in geometry;
- Edge – a shape corresponding to a curve, and bound by a vertex at each extremity;
- Wire – a sequence of edges connected by their vertices;
- Face – part of a plane (in 2D geometry) or a surface (in 3D geometry) bounded by a closed wire;
- Shell – a collection of faces connected by some edges of their wire boundaries;
- Solid – a part of 3D space bound by a shell;
- Compound solid – a collection of solids.
wire, solid는 무한이거나 closed일 수 있다.
총 6개의 package 제공.
첫 3개는 topological data structure 제공;
- TopAbs package : general resources for topology-driven applications.
- enumerations that are used to describe basic topological notions:
topological shape, orientation and state. - methods to manage these enumerations.
- enumerations that are used to describe basic topological notions:
- TopLoc package : resources to handle 3D local coordinate systems:
- Datum3D : elementary coordinate system
- Location : comprises a series of elementary coordinate systems
- TopoDS package : classes to model and build data structures that are purely topological.
나머지 3개는 이 추상 topology를 접근하고 다루는 도구들
;
- TopTools package : basic tools to use on topological data structures.
- TopExp package : classes to explore and manipulate the topological data structures described in the TopoDS package.
- BRepTools package : classes to explore, manipulate, read and write BRep data structures.
These more complex data structures combine topological descriptions with additional geometric information, and include rules for evaluating equivalence of different possible representations of the same object, for example, a point.
Shape content
TopAbs package
3 notions;
- Type - TopAbs_ShapeEnum;
- Orientation - TopAbs_Orientation;
- State - StateTopAbs_State.
Topological types
TopAbs_ShapeEnum; 복잡한 것에서 단순한 것 순서로.
- COMPOUND – a group of any type of topological objects.
- COMPSOLID – composite solid : face들에 의해 연결된 solid 들의 집합.
WIRE and SHELL의 개념을 solid로 확장. - SOLID – shell에 의해 제한된 공간의 일부. 3D.
- SHELL – edge에 의해 연결된 face들의 집합. can be open or closed.
- FACE – 2D에서 plane의 일부; 3D에서 surface의 일부. Its geometry is constrained (trimmed) by contours. 2D.
- WIRE – vertex들에 의해 연결된 edge들의 집합. It can be an open or closed contour depending on whether the edges are linked or not.
- EDGE – 제한된 curve에 해당하는 topology 요소. 일반적으로 vertex들에 의해 제한됨. 1D.
- VERTEX – 점에 해당하는 topology 요소. 0D.
- SHAPE – 위의 모두를 포함하는 일반 용어.
graph of objects with adjacency relationships.
Orientation
TopAbs_Orientation enumeration.
interior or material.
Orientation | Description |
FORWARD | The interior is the default region. |
REVERSED | The interior is the region complementary to the default. |
INTERNAL | The interior includes both regions. The boundary lies inside the material. For example a surface inside a solid. |
EXTERNAL | The interior includes neither region. The boundary lies outside the material. For example an edge in a wire-frame model. |
Orientation | Association |
FORWARD | Entering |
REVERSED | Exiting |
INTERNAL | Touching from inside |
EXTERNAL | Touching from outside |
State
TopAbs_State enumeration.
position of a vertex or a set of vertices.
Position | Description |
IN | The point is interior. |
OUT | The point is exterior. |
ON | The point is on the boundary(within tolerance). |
UNKNOWN | The state of the point is indeterminate. |
Shape Location
local coordinate system
- A right-handed trihedron with an origin and three orthonormal vectors. The gp_Ax2 package corresponds to this definition.
- A transformation of a +1 determinant, allowing the transformation of coordinates between local and global references frames. This corresponds to the gp_Trsf.
TopLoc package
- TopLoc_Datum3D class provides the elementary reference coordinate, represented by a right-handed orthonormal system of axes or by a right-handed unitary transformation.
- TopLoc_Location class provides the composite reference coordinate made from elementary ones. It is a marker composed of a chain of references to elementary markers. The resulting cumulative transformation is stored in order to avoid recalculating the sum of the transformations for the whole list.
three elementary coordinates:
R1, R2, R3;
composite coordinates are:
C1 = R1 * R2;
C2 = R2 * R3;
C3 = C1 * R3;
C4 = R1 * C2;
C3 and C4 are equal because they are both R1 * R2 * R3
Change of coordinates
TopLoc_Datum3D class
gp_Trsf package. (transformation)
Manipulating shapes and sub-shapes
TopoDS package : topological data structure;
- orientation, location 없이 추상 shape에 대한 참조.
- tool class들을 통해 데이터 구조에 접근.
vertex : parametric space에서 정의.
face, shape : 공간의 제약으로 정의.
집합으로 결합; edge 집합이 wire를 구성, face 집합이 shell을 구성, solid 집합이 composite solid를 구성.
shape 모델은 shareable data structure이고, 참조에 의해 다뤄진다.
참조 외에 orientation과 local coordinate reference가 추가될 수 있다.
- An orientation tells how the referenced shape is used in a boundary (Orientation from TopAbs).
- A local reference coordinate (Location from TopLoc) allows referencing a shape at a position different from that of its definition.
TopoDS_TShape class : shape description의 root. (참조로 다뤄짐.)
TopoDS_Shape class : shape에 대한 참조, orientation, local reference coordinate. (값으로 다뤄짐.)
이 데이터 구조는 back references를 포함하지 않는다.
참조의 방향 : more complex underlying shapes -> less complex ones
같은 sub-object를 공유:
local coordinates 를 사용해 반복적인 sub-structure를 공유할 수 있다.
아래 그림에서는 Tsh2 -> TFcyl 의 3개의 참조는 local coordinate system들을 갖는다. (구멍의 위치)
Classes inheriting TopoDS_Shape
TopoDS package가 2가지 class 집합 제공.
1) underlying shape를 상속하며, orientation과 location 없음.
2) TopoDS_Shape를 상속, TopAbs package에서 enumerate된 표준 topological shape를 표현.
1) TopoDS_Vertex, TopoDS_Edge, TopoDS_Wire, TopoDS_Face, TopoDS_Shell, TopoDS_Solid, TopoDS_CompSolid, and TopoDS_Compound
2) TopoDS_Shape는 TopoDS_TShape에 대한 참조이며 orientation과 local reference를 가짐.
TopoDS_Shape는 값으로 다뤄지고 sharing이 의미없음.
TopoDS_TShape는 참조로 다뤄짐.
TopoDS_Shape class에서 상속받는 class들은 생성자가 없다 (암시적 casting 금지.)
TopoDS package는 type 검증을 포함한 casting을 위한 package method 제공함.
예제 : TopoDS_Shape 타입을 argument로 받아, 그것이 vertex면 V에 넣고, edge이면 ProcessEdge method를 호출한다.
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Edge.hxx>
void ProcessEdge (const TopoDS_Edge& theEdge);
void Process (const TopoDS_Shape& theShape)
{
if (theShape.Shapetype() == TopAbs_VERTEX)
{
TopoDS_Vertex V;
V = TopoDS::Vertex (theShape); // Also correct
TopoDS_Vertex V2 = theShape; // Rejected by the compiler
TopoDS_Vertex V3 = TopoDS::Vertex (theShape); // Correct
}
else if (theShape.ShapeType() == TopAbs_EDGE)
{
ProcessEdge (theShape); // This is rejected
ProcessEdge (TopoDS::Edge (theShape)); // Correct
}
else
{
std::cout << "Neither a vertex nor an edge?\n";
ProcessEdge (TopoDS::Edge (theShape));
// OK for compiler but an exception will be raised at run-time
}
}
Exploration of Topological Data Structures
TopExp package : TopoDS package 로 정의된 데이터 구조를 탐색하는 도구들을 제공.
; 주어진 type의 모든 sub-object들 (가령 solid의 모든 face) 찾기.
TopExp_Explorer class ;
- The shape to be explored.
- 찾을 shape type ; 가령, VERTEX, EDGE with the exception of SHAPE, which is not allowed.
- 피할 shape type ; 가령, SHELL, EDGE.
default type은 SHAPE, 즉 제약없는 탐색.
예제: S shape의 모든 face 찾기;
void test()
{
TopoDS_Shape S;
for (TopExp_Explorer Ex (S, TopAbs_FACE); Ex.More(); Ex.Next())
{
ProcessFace (Ex.Current());
}
}
edge 내에 있지 않은 모든 vertex 찾기:
for (TopExp_Explorer Ex (S, TopAbs_VERTEX, TopAbs_EDGE); Ex.More(); Ex.Next()) {}
SHELL 내의 모든 face 찾기, SHELL 안에 있지 않은 모든 face 찾기.
void test()
{
TopExp_Explorer Ex1, Ex2;
TopoDS_Shape S;
for (Ex1.Init (S, TopAbs_SHELL); Ex1.More(); Ex1.Next())
{
// visit all shells
for (Ex2.Init (Ex1.Current(), TopAbs_FACE); Ex2.More(); Ex2.Next())
{
// visit all the faces of the current shell
ProcessFaceinAshell(Ex2.Current());
...
}
}
for (Ex1.Init (S, TopAbs_FACE, TopAbs_SHELL); Ex1.More(); Ex1.Next())
{
// visit all faces not in a shell
ProcessFace (Ex1.Current());
}
}
TopExp package의 MapShapes method 는 Map을 채운다.
Explorer class를 사용하는 탐색의 경우, 여러 번 참조되는 object는 여러 번 탐색된다.
1번만 처리하려면, Map에 배치해야 한다.
예제:
void TopExp::MapShapes (const TopoDS_Shape& S,
const TopAbs_ShapeEnum T,
TopTools_IndexedMapOfShape& M)
{
TopExp_Explorer Ex (S, T);
while (Ex.More())
{
M.Add (Ex.Current());
Ex.Next();
}
}
다음 예제의 drawing 규칙;
- The faces are represented by a network of NbIso iso-parametric lines with FaceIsoColor color.
- The edges are drawn in a color, which indicates the number of faces sharing the edge:
- FreeEdgeColor for edges, which do not belong to a face (i.e. wireframe element).
- BorderEdgeColor for an edge belonging to a single face.
- SharedEdgeColor for an edge belonging to more than one face.
- The methods DrawEdge and DrawFaceIso are also available to display individual edges and faces.
다음 step 수행됨;
- edge를 map에 저장하고, edge를 공유하는 face 개수를 셀 정수의 배열을 병행해 만든다. 배열은 0으로 초기화.
- face들 탐색. 각 face 그리기.
- edge들 탐색. 각 edge는 배열의 face 개수를 증가시킴.
- edge의 Map으로 부터, face 개수에 해당하는 색상으로 각 edge 그리기.
void DrawShape (const TopoDS_Shape& aShape,
const Standard_Integer nbIsos,
const Quantity_Color FaceIsocolor,
const Quantity_Color FreeEdgeColor,
const Quantity_Color BorderEdgeColor,
const Quantity_Color SharedEdgeColor)
{
// Store the edges in a Map
TopTools_IndexedMapOfShape edgemap;
TopExp::MapShapes (aShape, TopAbs_EDGE, edgeMap);
// Create an array set to zero
TColStd_Array1OfInteger faceCount (1, edgeMap.Extent());
faceCount.Init (0);
// Explore the faces.
TopExp_Explorer expFace(aShape,TopAbs_FACE);
while (expFace.More())
{
// Draw the current face.
DrawFaceIsos (TopoDS::Face (expFace.Current()), nbIsos, FaceIsoColor);
// Explore the edges of the face
TopExp_Explorer expEdge (expFace.Current(), TopAbs_EDGE);
while (expEdge.More())
{
// Increment the face count for this edge
++faceCount[edgemap.FindIndex (expEdge.Current())];
expEdge.Next();
}
expFace.Next();
}
// Draw the edges of theMap
for (Standard_Integer i = 1; i <= edgemap.Extent(); i++)
{
switch (faceCount[i])
{
case 0:
DrawEdge (TopoDS::Edge (edgemap (i)), FreeEdgeColor);
break;
case 1:
DrawEdge (TopoDS::Edge (edgemap (i)), BorderEdgeColor);
break;
default:
DrawEdge (TopoDS::Edge (edgemap (i)), SharedEdgeColor);
break;
}
}
}
Lists and Maps of Shapes
TopTools package : TopoDS 데이터 구조를 이용하는 툴을 담고 있다. TopoDS의 shape의 TCollection package 도구의 instance 화.
- TopTools_Array1OfShape, HArray1OfShape – instantiation of the NCollection_Array1 with TopoDS_Shape.
- TopTools_SequenceOfShape – instantiation of the NCollection_Sequence with TopoDS_Shape.
- TopTools_MapOfShape - instantiation of the NCollection_Map. Allows the construction of sets of shapes.
- TopTools_IndexedMapOfShape - instantiation of the NCollection_IndexedMap. Allows the construction of tables of shapes and other data structures
TopTools_Map 으로 Shape의 참조 집합이 중복없이 보관될 수 있다.
예제 : TShape의 개수로 데이터 구조의 크기 카운트.
#include <TopoDS_Iterator.hxx>
Standard_Integer Size (const TopoDS_Shape& aShape)
{
// This is a recursive method.
// The size of a shape is1 + the sizes of the subshapes.
Standard_Integer size = 1;
for (TopoDS_Iterator It (aShape); It.More(); It.Next())
{
size += Size (It.Value());
}
return size;
}
공유가 존재한다면 결과가 잘못 나온다.
contour of four edges는 1 wire + 4 edges +4 vertices이므로 결과는 9이지만, vertex들이 두 edge에 공유되므로 13을 리턴한다.
2번 카운팅을 방지하는 한 가지 방법은 다음 예제와 같다.
#include <TopoDS_Iterator.hxx>
#include <TopTools_MapOfShape.hxx>
void MapShapes (const TopoDS_Shape& aShape,
TopTools_MapOfShape& aMap)
{
// This is a recursive auxiliary method. It stores all subShapes of aShape in a Map.
if (aMap.Add (aShape))
{
// Add returns True if aShape was not already in the Map.
for (TopoDS_Iterator It (aShape); It.More(); It.Next())
{
MapShapes (It.Value(), aMap);
}
}
}
Standard_Integer Size (const TopoDS_Shape& aShape)
{
// Store Shapes in a Mapand return the size.
TopTools_MapOfShape M;
MapShapes (aShape, M);
return M.Extent();
}
예제 : IndexedMap을 사용해 data 구조를 복사. 사본은 동일 구조이지만 원본과는 공유가 없어야 함.
알고리즘:
- 구조의 모든 shape가 IndexedMap에 배치됨.
- 사본을 받을 map과 병행하여 table of shape가 생성됨.
- 보조 재귀 함수를 사용해 구조가 복사된다. (map에서 배열로 복사).
#include <TopoDS_Shape.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_Array1OfShape.hxx>
#include <TopoDS_Location.hxx>
TopoDS_Shape Copy (const TopoDS_Shape& aShape,
const TopoDS_Builder& aBuilder)
{
// Copies the wholestructure of aShape using aBuilder.
// Stores all thesub-Shapes in an IndexedMap.
TopTools_IndexedMapOfShape theMap;
TopoDS_Iterator It;
TopLoc_Location Identity;
TopoDS_Shape S = aShape;
S.Location (Identity);
S.Orientation(TopAbs_FORWARD);
theMap.Add(S);
for (Standard_Integer i = 1; i <= theMap.Extent(); i++)
{
for (It.Initialize(theMap(i)); It.More(); It.Next())
{
S = It.Value();
S.Location(Identity);
S.Orientation (TopAbs_FORWARD);
theMap.Add (S);
}
}
}
// Create an array to store the copies.
TopTools_Array1OfShapetheCopies (1, theMap.Extent());
// Use a recursivefunction to copy the first element.
void AuxiliaryCopy (Standard_Integer ,
const TopTools_IndexedMapOfShape& ,
TopTools_Array1OfShape& ,
const TopoDS_Builder& );
AuxiliaryCopy (1, theMap, theCopies, aBuilder);
// Get the result with the correct local reference and orientation.
S = theCopies (1);
S.Location (aShape.Location());
S.Orientation (aShape.Orientation());
return S;
void AuxiliaryCopy (Standard_Integer index,
const TopTools_IndexedMapOfShapes& sources,
TopTools_Array1OfShape& copies,
const TopoDS_Builder& aBuilder)
{
// If the copy is a null Shape the copy is not done.
if (copies[index].IsNull())
{
copies[index] = sources(index).EmptyCopied();
// Insert copies of the sub-shapes.
TopoDS_Shape S;
TopLoc_Location Identity;
for (TopoDS_Iterator It (sources (index)), It.More(), It.Next())
{
S = It.Value();
S.Location (Identity);
S.Orientation (TopAbs_FORWARD);
AuxiliaryCopy (sources.FindIndex (S), sources, copies, aBuilder);
S.Location (It.Value().Location());
S.Orientation (It.Value().Orientation());
aBuilder.Add (copies[index], S);
}
}
}
Wire Explorer
BRepTools_WireExplorer class는 wire의 edge들에 연결 순서로 접근.
예제 : recuperate the edges in the order {e1, e2, e3,e4, e5}:
TopoDS_Wire W = ...;
BRepTools_WireExplorer Ex;
for (Ex.Init (W); Ex.More(); Ex.Next())
{
ProcessTheCurrentEdge (Ex.Current());
ProcessTheVertexConnectingTheCurrentEdgeToThePreviousOne (Ex.CurrentVertex());
}