Open CASCADE Technology: Foundation Classes
Introduction This manual explains how to use Open CASCADE Technology (OCCT) Foundation Classes. It provides basic documentation on foundation classes. Foundation Classes provide a variety of general-purpose services such as automated dynamic memory managem
dev.opencascade.org
Collections, Strings, Quantities and Unit Conversion
Collections
Overview
STL collection보다 약간 더 넓은 기능을 제공.
TColStd package (Collections of Standard Objects component)
- Arrays : 고정크기. random access.
- Sequences : 변동크기. 순차 접근.
- Maps : 동적 구조, 빠른 접근.
- Lists : Sequences와 비슷하나 접근 알고리즘 다름.
- Acceleration structures : (3D에서의 ray picking 등) 빠른 traverse에 최적화된 tree 혹은 다른 구조.
NCollection_Define*.hxx 에 매크로 정의 있음. (obsolete)
#include <NCollection_Sequence.hxx>
#include <gp_Pnt.hxx>
typedef NCollection_Sequence<gp_Pnt> MyPackage_SequenceOfPnt;
handle로 다뤄야 하면, DEFINE_HSEQUENCE 매크로 사용;
#include <NCollection_Sequence.hxx>
#include <NCollection_DefineHSequence.hxx>
#include <gp_Pnt.hxx>
typedef NCollection_Sequence<gp_Pnt> MyPackage_SequenceOfPnt;
DEFINE_HSEQUENCE(MyPackage_HSequenceOfPnt, MyPackage_SequenceOfPnt)
...
Handle(MyPackage_HSequenceOfPnt) aSeq = new MyPackage_HSequenceOfPnt();
Arrays and sequences
- NCollection_Array1 - 1차원; index는 임의 수로 시작, 보통 1.
- NCollection_Array2 - 2차원; index는 임의 수로 시작, 보통 1.
- NCollection_List - list. NCollection_List::Iterator로 순차 접근. 삽입 빠름. 검색 느림.
- NCollection_Sequence – index로 접근하는 양방향 리스트; index는 1로 시작; 변동 크기,
- NCollection_Vector – 2 step indexed 배열, 확장 가능, 축소 불가;
- SetValue(ind, theValue) - 삽입. ind는 삽입되는 item의 index. ind >= Length() 이면 확장됨.
- Append(theValue) - 맨 뒤 추가, 확장됨.
- Clear(), Value, ChangeValue()
- 첫 요소는 index 0.
- NCollection_SparseArray. - NCollection_DataMap<int,TheItemType>와 동등. 메모리 적게 차지.
- NCollection_DataMap와 NCollection_Vector와 동일한 item 접근 인터페이스.
Maps
hash로 빠른 검색.
hash set은 key만 존재, hash map은 key와 item이 존재.
- Collection_Map – hash set;
- NCollection_IndexedMap – set with a prefixed order of elements, allowing fast access by index or by value (hash-based); index=(1...Upper), 마지막 key만 제거 가능.
- NCollection_DataMap – hash map;
- NCollection_IndexedDataMap – map with a prefixed order of elements, allowing fast access by index or by value (hash-based); index=(1...Upper), 마지막 key만 제거 가능.
- NCollection_DoubleMap – two-side hash map (with two keys).
key, items, hasher는 OCCT map template의 파라미터들.
NCollection_DefaultHasher
NCollection_DataMap::Iterator 제공.
NCollection_DefaultHasher
- HashCode() : key -> bucket index.
- IsEqual : equality test between two keys.
Iterator
특정 collection type의 subtype으로 정의됨. (e.g. MyPackage_StackOfPnt::Iterator)
The common methods of Iterator are:
Name | Method | Description |
Init() | void Init (MyCollection& ) | Initializes the iterator on the collection object |
More() | bool More() | Makes a query if there is another non-iterated member |
Next() | void Next() | Increments the iterator |
Value() | const ItemType& Value() | Returns the current member |
ChangeValue() | ItemType& ChangeValue() | Returns the mutable current member |
typedef Ncollection_Sequence<gp_Pnt> MyPackage_SequenceOfPnt;
void Perform (const MyPackage_SequenceOfPnt& theSequence)
{
for (MyPackage_SequenceOfPnt::Iterator anIter (theSequence); anIter.More(); anIter.Next())
{
const gp_Pnt aPnt& = anIter.Value();
...
}
}
Allocators
생성자 마지막 파라미터 Allocator 객체
default : NCollection_BaseAllocator
virtual void* Allocate (const size_t theSize) override;
virtual void Free (void* theAddress) override;
NCollection_IncAllocator : 메모리 증가만 하는 방식으로 성능 개선.
Acceleration structures
3D space의 traverse에 최적화된 데이터 구조체들.
- NCollection_UBTree – Unbalanced Binary Tree;
- NCollection_CellFilter – array of 2D/3D cells;
- BVH_Tree – boundary volume hierarchy.
NCollection_UBTree
binary tree of overlapped bounding objects.
fast geometric selection of objects.
NCollection_UBTree::Selector
TheBndType
class MyBndType
{
public:
//! Updates me with other bounding type instance
void Add (const MyBndType& theOther);
//! Classifies other bounding type instance relatively me
Standard_Boolean IsOut (const MyBndType& theOther) const;
//! Computes the squared maximal linear extent of me (for a box it is the squared diagonal of the box).
Standard_Real SquareExtent() const;
};
Bnd package: Bnd_Box, Bnd_Box2d, Bnd_B2x, Bnd_B3x.
typedef NCollection_UBTree<MyData, Bnd_B2f> UBTree;
typedef NCollection_List<MyData> ListOfSelected;
//! Tree Selector type
class MyTreeSelector : public UBTree::Selector
{
public:
//! This constructor initializes the selection criterion (e.g., a point)
MyTreeSelector (const gp_XY& thePnt) : myPnt(thePnt) {}
//! Get the list of selected objects
const ListOfSelected& ListAccepted() const { return myList; }
//! Bounding box rejection - definition of virtual method.
//! @return True if theBox is outside the selection criterion.
virtual Standard_Boolean Reject (const Bnd_B2f& theBox) const override { return theBox.IsOut (myPnt); }
//! Redefined from the base class.
//! Called when the bounding of theData conforms to the selection criterion.
//! This method updates myList.
virtual Standard_Boolean Accept (const MyData& theData) override { myList.Append (theData); }
private:
gp_XY myPnt;
ListOfSelected myList;
};
. . .
// Create a UBTree instance and fill it with data, each data item having the corresponding 2D box.
UBTree aTree;
NCollection_UBTreeFiller <MyData, Bnd_B2f> aTreeFiller (aTree);
for(;;)
{
const MyData& aData = ...;
const Bnd_B2d& aBox = aData.GetBox();
aTreeFiller.Add (aData, aBox);
}
aTreeFiller.Fill();
. . .
// Perform selection based on "aPoint2d"
MyTreeSelector aSel (aPoint2d);
aTree.Select (aSel);
const ListOfSelected& aSelected = aSel.ListAccepted();
NCollection_CellFilter
data structure for sorting geometric objects in n-dimensional space into cells.
Collections of Standard Objects
TShort, TColGeom, TColGeom2d, TColStd, TColgp
package TopTools
TopTools_ShapeMapHasher, TopTools_MapOfShape.
TColStd_PackedMapOfInteger.
Strings
TCollection_AsciiString : variable-length sequence of UTF-8
TCollection_ExtendedString : UTF-16/UCS-2 code points (16-bit character type)
UTF-8 <-> UTF-16 conversion
Resource_Unicode : ANSI, EUC, GB or SJIS <-> unicode.
NCollection_UtfIterator
Quantities
date and time information and color.
- Unit conversion tools (see package UnitsAPI)
- dates and time periods
- color definition
name, the value (real) and the unit.
Unit Conversion
UnitsAPI global functions.
3 unit system.
- the SI System,
- the user's Local System, ; SetLocalSystem( ) 로 정의.
- the user's Current System. ; SetCurrentUnit ( ) 함수로 단위를 수정해 정의.
OCCT는 SI 국제 표준을 준수하지만, 길이는 m 대신 mm를 사용.