Problem about using TopExp_Explorer

I can get all faces of a TopoDS_Shape by using TopExp_Explorer.but how could I distinguish them.For example, I explorer a box to get all faces,which one is the front face, which one is the bottom face?
tks!

Rob Bachrach's picture

You would have to look at some geometric attribute of the face, like the outward pointing normal or the locations of the vertices. You can not find this from a pure topological perspective.

Rob

helloha's picture

Rob Help me out..

Rob Bachrach's picture

One method is to find the normal of your face. Here is an example:

Standard_Real fUMin, fUMax, fVMin, fVMax;
BRepTools::UVBounds(face, fUMin, fUMax, fVMin, fVMax);

Standard_Real fU = (fUMax-fUMin)/2.0;
Standard_Real fV = (fVMax-fVMin)/2.0;

gp_Dir gNormal;
GeomLProp_SLProps props(BRep_Tool::Surface(face), fU, fV, 1, Precision::Confusion());
if (props.IsNormalDefined()) {
gNormal = props.Normal();
if (face.Orientation() == TopAbs_REVERSED) normal = normal * -1.0;
}

Then, take the dot product of the normal with your basic axes. A value near 1 (within some tolerance) indicates the normal mostly aligns with the axis in question, indicating the side of the box.

soaroc's picture

tks! Is there existing any sequence to construct a face byo vertexes? When I explorerde a TopoDS_Box, I got 48 vertexes!!, most of which are the same.

Rob Bachrach's picture

You get 48 vertices because the explorer visits them through the topological tree. The box has 6 faces, each with a wire. Each wire has 4 edges. Edge edge has 2 vertices. 6*4*2=48 (some of which are shared). You should actually see that there are only 8 unique vertices, each found 6 times.

Are you looking to actually construct a new face or to discover which existing vertices are part of an existing face. If the latter, you can explore the vertices for a given face and ignore duplicates or explore the face to get its wire and use a BRepTools_WireExplorer and the CurrentVertex function to get the vertices.

helloha's picture

PS:Handle(Graphic3d_WNTGraphicDevice) TheGraphicDevice = new Graphic3d_WNTGraphicDevice();
TCollection_ExtendedString aName("OCC Viewer");
Handle(V3d_Viewer) myViewer = new V3d_Viewer(TheGraphicDevice,aName.ToExtString(),"");
myViewer->Init();
myViewer->SetDefaultLights();
myViewer->SetLightOn();
//
Handle(WNT_Window) AWNTWindow;
AWNTWindow = new WNT_Window(TheGraphicDevice,theApp.m_pMainWnd->GetSafeHwnd());
Handle(V3d_View) myView = myViewer->CreateView();
myView->SetWindow(AWNTWindow);

Cwnd->GetSafeHwnd() << I don't know how to get Cwnd->GetSafeHwnd()

Help. why no one answer my questions?

helloha's picture

help.. i don't know how to create Cwnd->GetSafeHwnd()
it said GetSafeHwnd() unidentified so i create the following code to make Cwnd-> GetSafeHwnd():
class MFC_Tutorial_Window :public CFrameWnd
{
public:
MFC_Tutorial_Window()
{
Create(NULL,L"MFC Tutorial Part 1 CoderSource Window");
}
};

class MyApp :public CWinApp
{
MFC_Tutorial_Window *wnd;
public:
BOOL InitInstance()
{
wnd = new MFC_Tutorial_Window();
m_pMainWnd = wnd;
m_pMainWnd->ShowWindow(1);
return 1;
}
};
MyApp theApp;

----------------
instead of Cwnd->getSafehwnd(),

i wrote theApp.m_pMainwnd->getsafeHwnd()..
is it right?
do you have the sample code on displaying shape on V3d_viewer?(not the demo ones cuz it doesn't work, library files are missing. thanks
thanks