mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-24 13:50:49 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
59
samples/mfc/standard/07_Triangulation/src/ISession_Curve.cpp
Executable file
59
samples/mfc/standard/07_Triangulation/src/ISession_Curve.cpp
Executable file
@@ -0,0 +1,59 @@
|
||||
// ISession_Curve.cpp: implementation of the ISession_Curve class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ISession_Curve.h"
|
||||
#include <Prs3d_LineAspect.hxx>
|
||||
#include <StdPrs_Curve.hxx>
|
||||
#include <GeomAdaptor_Curve.hxx>
|
||||
#include <AIS_Drawer.hxx>
|
||||
#include <Prs3d_ArrowAspect.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(ISession_Curve,AIS_InteractiveObject)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(ISession_Curve,AIS_InteractiveObject)
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
ISession_Curve::ISession_Curve(const Handle(Geom_Curve)& aCurve)
|
||||
:AIS_InteractiveObject(),myCurve(aCurve)
|
||||
{
|
||||
}
|
||||
|
||||
ISession_Curve::~ISession_Curve()
|
||||
{
|
||||
|
||||
}
|
||||
void ISession_Curve::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
|
||||
const Handle(Prs3d_Presentation)& aPresentation,
|
||||
const Standard_Integer /*aMode*/)
|
||||
{
|
||||
GeomAdaptor_Curve anAdaptorCurve(myCurve);
|
||||
if (hasOwnColor)
|
||||
myDrawer->LineAspect()->SetColor(myOwnColor);
|
||||
myDrawer->Link()->SetDiscretisation(100);
|
||||
myDrawer->Link()->SetMaximalParameterValue(500);
|
||||
|
||||
StdPrs_Curve::Add (aPresentation, anAdaptorCurve, myDrawer);
|
||||
}
|
||||
|
||||
void ISession_Curve::Compute(const Handle(Prs3d_Projector)& aProjector,
|
||||
const Handle(Prs3d_Presentation)& aPresentation)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ISession_Curve::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
|
||||
const Standard_Integer aMode)
|
||||
{
|
||||
}
|
||||
|
||||
|
33
samples/mfc/standard/07_Triangulation/src/ISession_Curve.h
Executable file
33
samples/mfc/standard/07_Triangulation/src/ISession_Curve.h
Executable file
@@ -0,0 +1,33 @@
|
||||
// ISession_Curve.h: interface for the ISession_Curve class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_ISESSION_CURVE_H__F981CB93_A3CC_11D1_8DA3_0800369C8A03__INCLUDED_)
|
||||
#define AFX_ISESSION_CURVE_H__F981CB93_A3CC_11D1_8DA3_0800369C8A03__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
#include <Standard_Macro.hxx>
|
||||
#include <Standard_DefineHandle.hxx>
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
#include <Geom_Curve.hxx>
|
||||
|
||||
DEFINE_STANDARD_HANDLE(ISession_Curve,AIS_InteractiveObject)
|
||||
|
||||
class ISession_Curve : public AIS_InteractiveObject
|
||||
{
|
||||
public:
|
||||
ISession_Curve(const Handle(Geom_Curve)& aCurve);
|
||||
virtual ~ISession_Curve();
|
||||
DEFINE_STANDARD_RTTI(ISession_Curve)
|
||||
private:
|
||||
|
||||
Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,const Handle(Prs3d_Presentation)& aPresentation,const Standard_Integer aMode = 0) ;
|
||||
Standard_EXPORT virtual void Compute(const Handle(Prs3d_Projector)& aProjector,const Handle(Prs3d_Presentation)& aPresentation) ;
|
||||
void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,const Standard_Integer aMode) ;
|
||||
|
||||
Handle(Geom_Curve) myCurve;
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_ISESSION_CURVE_H__F981CB93_A3CC_11D1_8DA3_0800369C8A03__INCLUDED_)
|
331
samples/mfc/standard/07_Triangulation/src/OCCDemo_Presentation.cpp
Executable file
331
samples/mfc/standard/07_Triangulation/src/OCCDemo_Presentation.cpp
Executable file
@@ -0,0 +1,331 @@
|
||||
// OCCDemo_Presentation.cpp: implementation of the OCCDemo_Presentation class.
|
||||
// This is a base class for all presentations
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "OCCDemo_Presentation.h"
|
||||
#include <OCC_3dView.h>
|
||||
#include "TriangulationDoc.h"
|
||||
#include "ISession_Curve.h"
|
||||
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
#include <Geom_Surface.hxx>
|
||||
#include <Geom_Curve.hxx>
|
||||
#include <Geom2d_Curve.hxx>
|
||||
#include <Quantity_Color.hxx>
|
||||
#include <AIS_Shape.hxx>
|
||||
#include <BRepBuilderAPI_MakeFace.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <Geom_Line.hxx>
|
||||
#include <Geom_TrimmedCurve.hxx>
|
||||
#include <AIS_Drawer.hxx>
|
||||
#include <Prs3d_ArrowAspect.hxx>
|
||||
#include <AIS_Point.hxx>
|
||||
#include <Geom_CartesianPoint.hxx>
|
||||
#include <Geom2d_OffsetCurve.hxx>
|
||||
#include <GeomAPI.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <Geom_OffsetCurve.hxx>
|
||||
|
||||
#define MAX_PARAM 1000 // if a surface parameter is infinite, it is assingned
|
||||
// this value in order to display the "infinit" object in the viewer.
|
||||
|
||||
|
||||
Standard_Boolean OCCDemo_Presentation::WaitForInput (unsigned long aMilliSeconds)
|
||||
{
|
||||
//::WaitForSingleObject(::CreateEvent (NULL, FALSE, FALSE, NULL), aMilliSeconds);
|
||||
if (::MsgWaitForMultipleObjects(0, NULL, FALSE, aMilliSeconds,
|
||||
QS_KEY | QS_MOUSEBUTTON) != WAIT_TIMEOUT)
|
||||
{
|
||||
MSG msg;
|
||||
if (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
|
||||
{
|
||||
if (msg.message == WM_KEYUP)
|
||||
{
|
||||
::PeekMessage (&msg, NULL, 0, 0, PM_REMOVE);
|
||||
return WaitForInput (aMilliSeconds);
|
||||
}
|
||||
else
|
||||
return Standard_True;
|
||||
}
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//================================================================
|
||||
// Function : fixParam
|
||||
// Purpose : assings a finite value to theParam if it intinite
|
||||
// (equal to +- Precision::Infinite())
|
||||
//================================================================
|
||||
static Standard_Boolean fixParam(Standard_Real& theParam)
|
||||
{
|
||||
Standard_Boolean aResult = Standard_False;
|
||||
if (Precision::IsNegativeInfinite(theParam))
|
||||
{
|
||||
theParam = -MAX_PARAM;
|
||||
aResult = Standard_True;
|
||||
}
|
||||
if (Precision::IsPositiveInfinite(theParam))
|
||||
{
|
||||
theParam = MAX_PARAM;
|
||||
aResult = Standard_True;
|
||||
}
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//================================================================
|
||||
// Function : DrawSurface
|
||||
// Purpose : displays a given geometric surface in 3d viewer
|
||||
// (creates a finite face and displays it)
|
||||
//================================================================
|
||||
Handle_AIS_InteractiveObject OCCDemo_Presentation::drawSurface
|
||||
(const Handle_Geom_Surface& theSurface,
|
||||
const Quantity_Color& theColor,
|
||||
const Standard_Boolean toDisplay)
|
||||
{
|
||||
Standard_Real u1, u2, v1, v2;
|
||||
theSurface->Bounds(u1,u2,v1,v2);
|
||||
fixParam(u1);
|
||||
fixParam(u2);
|
||||
fixParam(v1);
|
||||
fixParam(v2);
|
||||
|
||||
Handle_AIS_Shape aGraphicSurface =
|
||||
new AIS_Shape(BRepBuilderAPI_MakeFace (theSurface, u1, u2, v1, v2));
|
||||
|
||||
getAISContext()->SetMaterial(aGraphicSurface, Graphic3d_NOM_PLASTIC, toDisplay);
|
||||
getAISContext()->SetColor(aGraphicSurface, theColor, toDisplay);
|
||||
if (toDisplay) {
|
||||
if (FitMode){
|
||||
getAISContext()->Display (aGraphicSurface, Standard_False);
|
||||
CTriangulationDoc::Fit();
|
||||
}
|
||||
else
|
||||
getAISContext()->Display (aGraphicSurface);
|
||||
}
|
||||
|
||||
return aGraphicSurface;
|
||||
}
|
||||
|
||||
//================================================================
|
||||
// Function : DrawCurve
|
||||
// Purpose : displays a given curve 3d
|
||||
//================================================================
|
||||
Handle_AIS_InteractiveObject OCCDemo_Presentation::drawCurve
|
||||
(const Handle_Geom_Curve& theCurve,
|
||||
const Quantity_Color& theColor,
|
||||
const Standard_Boolean toDisplay)
|
||||
{
|
||||
Handle(ISession_Curve) aGraphicCurve = new ISession_Curve (theCurve);
|
||||
|
||||
getAISContext()->SetColor (aGraphicCurve, theColor, toDisplay);
|
||||
aGraphicCurve->Attributes()->Link()->SetLineArrowDraw(Standard_False);
|
||||
if (toDisplay){
|
||||
if (FitMode){
|
||||
getAISContext()->Display (aGraphicCurve, Standard_False);
|
||||
CTriangulationDoc::Fit();
|
||||
}
|
||||
else
|
||||
getAISContext()->Display (aGraphicCurve);
|
||||
}
|
||||
|
||||
return aGraphicCurve;
|
||||
}
|
||||
|
||||
//================================================================
|
||||
// Function : DrawCurve
|
||||
// Purpose : displays a given curve 2d
|
||||
//================================================================
|
||||
Handle_AIS_InteractiveObject OCCDemo_Presentation::drawCurve
|
||||
(const Handle_Geom2d_Curve& theCurve,
|
||||
const Quantity_Color& theColor,
|
||||
const Standard_Boolean toDisplay,
|
||||
const gp_Ax2& aPosition)
|
||||
{
|
||||
// create 3D curve in plane
|
||||
Handle(Geom_Curve) aCurve3d;
|
||||
if (theCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve)))
|
||||
{
|
||||
Handle(Geom2d_OffsetCurve) aOffCurve =
|
||||
Handle(Geom2d_OffsetCurve)::DownCast(theCurve);
|
||||
Handle(Geom_Curve) aBasCurve3d =
|
||||
GeomAPI::To3d (aOffCurve->BasisCurve(), gp_Pln(aPosition));
|
||||
Standard_Real aDist = aOffCurve->Offset();
|
||||
aCurve3d = new Geom_OffsetCurve (aBasCurve3d, aDist, aPosition.Direction());
|
||||
}
|
||||
else
|
||||
{
|
||||
aCurve3d = GeomAPI::To3d (theCurve, gp_Pln(aPosition));
|
||||
}
|
||||
return drawCurve (aCurve3d, theColor, toDisplay);
|
||||
}
|
||||
|
||||
//================================================================
|
||||
// Function : drawPoint
|
||||
// Purpose : displays a given point
|
||||
//================================================================
|
||||
Handle_AIS_Point OCCDemo_Presentation::drawPoint
|
||||
(const gp_Pnt& aPnt,
|
||||
const Quantity_Color& theColor,
|
||||
const Standard_Boolean toDisplay)
|
||||
{
|
||||
Handle(AIS_Point) aGraphicPoint = new AIS_Point (new Geom_CartesianPoint(aPnt));
|
||||
|
||||
getAISContext()->SetColor (aGraphicPoint, theColor, toDisplay);
|
||||
if (toDisplay) {
|
||||
getAISContext()->Display (aGraphicPoint);
|
||||
//COCCDemoDoc::Fit();
|
||||
}
|
||||
|
||||
return aGraphicPoint;
|
||||
}
|
||||
|
||||
//================================================================
|
||||
// Function : drawVector
|
||||
// Purpose : displays a given vector in 3d viewer
|
||||
// (segment of line starting at thePnt with the arrow at the end,
|
||||
// the length of segment is the length of the vector)
|
||||
//================================================================
|
||||
Handle_AIS_InteractiveObject OCCDemo_Presentation::drawVector
|
||||
(const gp_Pnt& thePnt,
|
||||
const gp_Vec& theVec,
|
||||
const Quantity_Color& theColor,
|
||||
const Standard_Boolean toDisplay)
|
||||
{
|
||||
Standard_Real aLength = theVec.Magnitude();
|
||||
if (aLength < Precision::Confusion())
|
||||
return Handle(AIS_InteractiveObject)();
|
||||
|
||||
Handle(Geom_Curve) aCurve = new Geom_Line (thePnt, theVec);
|
||||
aCurve = new Geom_TrimmedCurve (aCurve, 0, aLength);
|
||||
|
||||
Handle(ISession_Curve) aGraphicCurve = new ISession_Curve (aCurve);
|
||||
|
||||
getAISContext()->SetColor (aGraphicCurve, theColor, toDisplay);
|
||||
Handle(Prs3d_Drawer) aDrawer = aGraphicCurve->Attributes()->Link();
|
||||
aDrawer->SetLineArrowDraw(Standard_True);
|
||||
aDrawer->ArrowAspect()->SetLength(aLength/10);
|
||||
if (toDisplay) {
|
||||
if (FitMode){
|
||||
getAISContext()->Display (aGraphicCurve, Standard_False);
|
||||
CTriangulationDoc::Fit();
|
||||
}
|
||||
else
|
||||
getAISContext()->Display (aGraphicCurve);
|
||||
}
|
||||
|
||||
return aGraphicCurve;
|
||||
}
|
||||
|
||||
|
||||
Handle_AIS_Shape OCCDemo_Presentation::drawShape
|
||||
(const TopoDS_Shape& theShape,const Quantity_Color& theColor,
|
||||
const Standard_Boolean toDisplay)
|
||||
{
|
||||
Handle_AIS_Shape aGraphicShape = new AIS_Shape(theShape);
|
||||
|
||||
getAISContext()->SetMaterial(aGraphicShape, Graphic3d_NOM_PLASTIC, toDisplay);
|
||||
getAISContext()->SetColor (aGraphicShape, theColor, toDisplay);
|
||||
if (toDisplay){
|
||||
if (FitMode){
|
||||
getAISContext()->Display (aGraphicShape, Standard_False);
|
||||
CTriangulationDoc::Fit();
|
||||
}
|
||||
else
|
||||
getAISContext()->Display (aGraphicShape);
|
||||
}
|
||||
|
||||
return aGraphicShape;
|
||||
}
|
||||
|
||||
Handle_AIS_Shape OCCDemo_Presentation::drawShape
|
||||
(const TopoDS_Shape& theShape,
|
||||
const Graphic3d_NameOfMaterial theMaterial,
|
||||
const Standard_Boolean toDisplay)
|
||||
{
|
||||
Handle_AIS_Shape aGraphicShape = new AIS_Shape(theShape);
|
||||
|
||||
getAISContext()->SetMaterial(aGraphicShape, theMaterial, toDisplay);
|
||||
if (toDisplay) {
|
||||
if (FitMode){
|
||||
getAISContext()->Display (aGraphicShape, Standard_False);
|
||||
CTriangulationDoc::Fit();
|
||||
}
|
||||
else
|
||||
getAISContext()->Display (aGraphicShape);
|
||||
}
|
||||
|
||||
return aGraphicShape;
|
||||
}
|
||||
/*
|
||||
void OCCDemo_Presentation::GetViewCenter(V3d_Coordinate& Xc, V3d_Coordinate& Yc)
|
||||
{
|
||||
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
||||
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
|
||||
OCC_3dView *pView = (OCC_3dView*)pChild->GetActiveView();
|
||||
pView->GetViewCenter(Xc,Yc);
|
||||
}
|
||||
|
||||
void OCCDemo_Presentation::SetViewCenter(V3d_Coordinate Xc, V3d_Coordinate Yc)
|
||||
{
|
||||
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
||||
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
|
||||
COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView();
|
||||
pView->SetViewCenter(Xc,Yc);
|
||||
}
|
||||
|
||||
void OCCDemo_Presentation::GetViewEye(V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z)
|
||||
{
|
||||
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
||||
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
|
||||
COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView();
|
||||
pView->GetViewEye(X,Y,Z);
|
||||
}
|
||||
|
||||
void OCCDemo_Presentation::SetViewEye(V3d_Coordinate X, V3d_Coordinate Y, V3d_Coordinate Z)
|
||||
{
|
||||
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
||||
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
|
||||
COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView();
|
||||
pView->SetViewEye(X,Y,Z);
|
||||
}
|
||||
|
||||
Quantity_Factor OCCDemo_Presentation::GetViewScale()
|
||||
{
|
||||
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
||||
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
|
||||
COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView();
|
||||
return pView->GetViewScale();
|
||||
}
|
||||
|
||||
void OCCDemo_Presentation::SetViewScale(Quantity_Factor Coef)
|
||||
{
|
||||
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
||||
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
|
||||
COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView();
|
||||
pView->SetViewScale(Coef);
|
||||
}
|
||||
|
||||
void OCCDemo_Presentation::ResetView()
|
||||
{
|
||||
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
||||
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
|
||||
COCCDemoView *pView = (COCCDemoView *) pChild->GetActiveView();
|
||||
pView->Reset();
|
||||
}
|
||||
*/
|
||||
Handle_AIS_InteractiveContext OCCDemo_Presentation::getAISContext() const
|
||||
{
|
||||
return myDoc->GetAISContext();
|
||||
}
|
||||
|
||||
Handle_V3d_Viewer OCCDemo_Presentation::getViewer() const
|
||||
{
|
||||
return myDoc->GetViewer();
|
||||
}
|
||||
|
||||
|
||||
Standard_CString OCCDemo_Presentation::GetDataDir()
|
||||
{
|
||||
return myDoc->GetDataDir();
|
||||
}
|
135
samples/mfc/standard/07_Triangulation/src/OCCDemo_Presentation.h
Executable file
135
samples/mfc/standard/07_Triangulation/src/OCCDemo_Presentation.h
Executable file
@@ -0,0 +1,135 @@
|
||||
// OCCDemo_Presentation.h: interface for the OCCDemo_Presentation class.
|
||||
// This is a base class for all presentations
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_OCCDEMO_PRESENTATION_H__790EED7F_7BA2_11D5_BA4A_0060B0EE18EA__INCLUDED_)
|
||||
#define AFX_OCCDEMO_PRESENTATION_H__790EED7F_7BA2_11D5_BA4A_0060B0EE18EA__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
#define WAIT_A_LITTLE WaitForInput(500)
|
||||
#define WAIT_A_SECOND WaitForInput(1000)
|
||||
|
||||
//#include "TriangulationDoc.h"
|
||||
//#include <OCCDemo.h>
|
||||
class CTriangulationDoc;
|
||||
class Handle_AIS_InteractiveObject;
|
||||
class Handle_AIS_Point;
|
||||
class Handle_Geom_Surface;
|
||||
class Handle_Geom_Curve;
|
||||
class Handle_Geom2d_Curve;
|
||||
class Quantity_Color;
|
||||
|
||||
class OCCDemo_Presentation
|
||||
{
|
||||
public:
|
||||
// Construction
|
||||
OCCDemo_Presentation() : myIndex(0), myNbSamples(0), FitMode(false){}
|
||||
virtual ~OCCDemo_Presentation() {}
|
||||
|
||||
public:
|
||||
static OCCDemo_Presentation* Current;
|
||||
// this pointer must be initialized when realize a derivable class;
|
||||
// it is used by application to access to a presentation class instance
|
||||
|
||||
void SetDocument (CTriangulationDoc* theDoc) {myDoc = theDoc;}
|
||||
// document must be set by the user of this class before first use of iterations
|
||||
CTriangulationDoc* GetDocument () {return myDoc;}
|
||||
|
||||
public:
|
||||
// Titling
|
||||
const CString& GetName() const {return myName;}
|
||||
|
||||
public:
|
||||
// Iteration on samples
|
||||
void FirstSample() {myIndex=0;}
|
||||
void LastSample() {myIndex=myNbSamples-1;}
|
||||
Standard_Boolean AtFirstSample() const {return myIndex <= 0;}
|
||||
Standard_Boolean AtLastSample() const {return myIndex >= myNbSamples-1;}
|
||||
void NextSample() {myIndex++;}
|
||||
void PrevSample() {myIndex--;}
|
||||
virtual void DoSample() = 0;
|
||||
/*
|
||||
static void GetViewCenter(V3d_Coordinate& Xc, V3d_Coordinate& Yc);
|
||||
static void SetViewCenter(const V3d_Coordinate Xc, const V3d_Coordinate Yc);
|
||||
static void GetViewEye(V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z);
|
||||
static void SetViewEye(V3d_Coordinate X, V3d_Coordinate Y, V3d_Coordinate Z);
|
||||
static Quantity_Factor GetViewScale();
|
||||
static void SetViewScale(Quantity_Factor Coef);
|
||||
static void ResetView();
|
||||
*/
|
||||
|
||||
// place one-time initialization code in this function
|
||||
virtual void Init() {}
|
||||
|
||||
protected:
|
||||
// Methods to call from a derivable class
|
||||
void setName (const char* theName) {myName = CString(theName);}
|
||||
Handle_AIS_InteractiveContext getAISContext() const;
|
||||
Handle_V3d_Viewer getViewer() const;
|
||||
Standard_CString GetDataDir();
|
||||
|
||||
Standard_Boolean WaitForInput (unsigned long aMilliSeconds);
|
||||
// Waits for a user input or a period of time has been elapsed
|
||||
|
||||
Handle_AIS_InteractiveObject drawSurface (const Handle_Geom_Surface& theSurface,
|
||||
const Quantity_Color& theColor = Quantity_Color(Quantity_NOC_LEMONCHIFFON3),
|
||||
const Standard_Boolean toDisplay = Standard_True);
|
||||
// creates a finite face based on the given geometric surface
|
||||
// and displays it in the viewer if toDisplay = Standard_True
|
||||
|
||||
Handle_AIS_InteractiveObject drawCurve (const Handle_Geom_Curve& theCurve,
|
||||
const Quantity_Color& theColor = Quantity_Color(Quantity_NOC_RED),
|
||||
const Standard_Boolean toDisplay = Standard_True);
|
||||
// creates an ISession_Curve based on the given geometric curve
|
||||
// and displays it in the viewer if toDisplay = Standard_True
|
||||
|
||||
Handle_AIS_InteractiveObject drawCurve (const Handle_Geom2d_Curve& theCurve,
|
||||
const Quantity_Color& theColor = Quantity_Color(Quantity_NOC_RED),
|
||||
const Standard_Boolean toDisplay = Standard_True,
|
||||
const gp_Ax2& aPosition = gp::XOY());
|
||||
// converts a given curve to 3d using aPosition and calls the previous method
|
||||
|
||||
Handle_AIS_Point drawPoint (const gp_Pnt& thePnt,
|
||||
const Quantity_Color& theColor = Quantity_Color(Quantity_NOC_GREEN),
|
||||
const Standard_Boolean toDisplay = Standard_True);
|
||||
// creates a presentation of the given point
|
||||
// and displays it in the viewer if toDisplay = Standard_True
|
||||
|
||||
Handle_AIS_InteractiveObject drawVector (const gp_Pnt& thePnt,
|
||||
const gp_Vec& theVec,
|
||||
const Quantity_Color& theColor = Quantity_Color(Quantity_NOC_YELLOW),
|
||||
const Standard_Boolean toDisplay = Standard_True);
|
||||
// creates a presentation of the given vector
|
||||
// and displays it in the viewer if toDisplay = Standard_True
|
||||
|
||||
Handle_AIS_Shape drawShape (const TopoDS_Shape& theShape,
|
||||
const Quantity_Color& theColor,
|
||||
const Standard_Boolean toDisplay = Standard_True);
|
||||
// creates a presentation of the given shape
|
||||
// with material PLASTIC and a given color
|
||||
// and displays it in the viewer if toDisplay = Standard_True
|
||||
|
||||
Handle_AIS_Shape drawShape (const TopoDS_Shape& theShape,
|
||||
const Graphic3d_NameOfMaterial theMaterial = Graphic3d_NOM_BRASS,
|
||||
const Standard_Boolean toDisplay = Standard_True);
|
||||
// creates a presentation of the given shape with the given material
|
||||
// (color is default for a given material)
|
||||
// and displays it in the viewer if toDisplay = Standard_True
|
||||
|
||||
protected:
|
||||
// Fields to use in a derivable class
|
||||
BOOL FitMode;
|
||||
int myIndex;
|
||||
int myNbSamples;
|
||||
|
||||
private:
|
||||
CTriangulationDoc* myDoc;
|
||||
CString myName;
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_OCCDEMO_PRESENTATION_H__790EED7F_7BA2_11D5_BA4A_0060B0EE18EA__INCLUDED_)
|
6
samples/mfc/standard/07_Triangulation/src/StdAfx.cpp
Executable file
6
samples/mfc/standard/07_Triangulation/src/StdAfx.cpp
Executable file
@@ -0,0 +1,6 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// SampleTriangulation.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
118
samples/mfc/standard/07_Triangulation/src/StdAfx.h
Executable file
118
samples/mfc/standard/07_Triangulation/src/StdAfx.h
Executable file
@@ -0,0 +1,118 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
|
||||
|
||||
#include <afxwin.h> // MFC core and standard components
|
||||
#include <afxext.h> // MFC extensions
|
||||
#include <afxdisp.h> // MFC OLE automation classes
|
||||
#ifndef _AFX_NO_AFXCMN_SUPPORT
|
||||
#include <afxcmn.h> // MFC support for Windows Common Controls
|
||||
#endif // _AFX_NO_AFXCMN_SUPPORT
|
||||
|
||||
#if !defined(WNT)
|
||||
#error WNT precompiler directive is mandatory for CasCade
|
||||
#endif
|
||||
|
||||
#pragma warning( disable : 4244 ) // Issue warning 4244
|
||||
#include "Standard_ShortReal.hxx"
|
||||
#pragma warning( default : 4244 ) // Issue warning 4244
|
||||
|
||||
#include <Standard.hxx>
|
||||
/*
|
||||
#ifndef Version15B
|
||||
# ifndef Version15D
|
||||
# ifndef Version20
|
||||
# define Version15B
|
||||
# endif // Version20
|
||||
# endif // Version15D
|
||||
#endif // Version15B
|
||||
|
||||
#pragma message ("=============================")
|
||||
#ifdef Version15B
|
||||
# pragma message ("Set the libs for version 1.5B")
|
||||
#endif // Version15B
|
||||
|
||||
#ifdef Version15D
|
||||
# pragma message ("Set the libs for version 1.5D")
|
||||
#endif // Version15D
|
||||
|
||||
#ifdef Version20
|
||||
# pragma message ("Set the libs for version 2.0 ")
|
||||
#endif // Version20
|
||||
#pragma message ("=============================")
|
||||
|
||||
#ifdef Version15B
|
||||
# pragma comment (lib,"TKTop.lib")
|
||||
# pragma comment (lib,"TShort.lib")
|
||||
# pragma comment (lib,"TColQuantity.lib")
|
||||
#endif
|
||||
|
||||
#ifdef Version15D
|
||||
# pragma comment (lib,"TKTop.lib")
|
||||
#endif
|
||||
|
||||
#ifdef Version20
|
||||
# pragma comment (lib,"TKTop1.lib")
|
||||
# pragma comment (lib,"TKTop2.lib")
|
||||
#endif
|
||||
|
||||
#pragma message ("Set the specific libs for the application")
|
||||
# pragma comment (lib,"TKPrs.lib")
|
||||
# pragma comment (lib,"TKGeom.lib")
|
||||
# pragma comment (lib,"TKGlt.lib")
|
||||
# pragma comment (lib,"TKGraphic.lib")
|
||||
# pragma comment (lib,"TKPrsMgr.lib")
|
||||
# pragma comment (lib,"TKViewers.lib")
|
||||
# pragma comment (lib,"TKSession.lib")
|
||||
# pragma comment (lib,"TColgp.lib")
|
||||
# pragma comment (lib,"TKernel.lib")
|
||||
*/
|
||||
|
||||
|
||||
#include <AIS_InteractiveContext.hxx>
|
||||
#include <AIS_Shape.hxx>
|
||||
#include <Graphic3d_WNTGraphicDevice.hxx>
|
||||
#include <V3d_Viewer.hxx>
|
||||
#include <V3d_View.hxx>
|
||||
#include <WNT_Window.hxx>
|
||||
#include <Standard_ErrorHandler.hxx>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <BRepPrimAPI_MakeCylinder.hxx>
|
||||
|
||||
#include "TopoDS_Shape.hxx"
|
||||
#include "BRepPrimAPI_MakeBox.hxx"
|
||||
#include "BRepPrimAPI_MakeSphere.hxx"
|
||||
#include "gp_Pnt.hxx"
|
||||
#include "BRepAlgoAPI_Cut.hxx"
|
||||
#include "BRepMesh.hxx"
|
||||
#include "TopExp_Explorer.hxx"
|
||||
#include "TopoDS_Face.hxx"
|
||||
#include "TopLoc_Location.hxx"
|
||||
#include "Poly_Triangulation.hxx"
|
||||
#include "BRep_Tool.hxx"
|
||||
#include "TopoDS.hxx"
|
||||
#include "TColgp_Array1OfPnt.hxx"
|
||||
#include "Poly_Array1OfTriangle.hxx"
|
||||
#include "Poly_Triangle.hxx"
|
||||
#include "gp_Pnt.hxx"
|
||||
#include "BRepBuilderAPI_MakeEdge.hxx"
|
||||
#include "BRep_Builder.hxx"
|
||||
#include "TopoDS_Compound.hxx"
|
||||
#include "BRepAlgoAPI_Fuse.hxx"
|
||||
#include "BRepBuilderAPI_MakeVertex.hxx"
|
||||
#include "TopoDS.hxx"
|
||||
#include "BRepTools.hxx"
|
||||
|
||||
#include <UnitsAPI.hxx>
|
||||
|
||||
#include <res\resource.h>
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
450
samples/mfc/standard/07_Triangulation/src/Tesselate_Presentation.cpp
Executable file
450
samples/mfc/standard/07_Triangulation/src/Tesselate_Presentation.cpp
Executable file
@@ -0,0 +1,450 @@
|
||||
// Tesselate_Presentation.cpp: implementation of the Tesselate_Presentation class.
|
||||
// Tesselate shapes.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Tesselate_Presentation.h"
|
||||
#include "TriangulationApp.h"
|
||||
#include "TriangulationDoc.h"
|
||||
|
||||
#include <Precision.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRepTools.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <BRepMesh.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopLoc_Location.hxx>
|
||||
#include <TopTools_DataMapOfIntegerShape.hxx>
|
||||
#include <TopTools_SequenceOfShape.hxx>
|
||||
|
||||
#include <Poly_Triangulation.hxx>
|
||||
#include <Poly_PolygonOnTriangulation.hxx>
|
||||
#include <Poly_Array1OfTriangle.hxx>
|
||||
#include <TColgp_Array1OfPnt.hxx>
|
||||
#include <TColStd_Array1OfInteger.hxx>
|
||||
|
||||
#include <gp_Pnt.hxx>
|
||||
|
||||
|
||||
#ifdef WNT
|
||||
#define EOL "\r\n"
|
||||
#else
|
||||
#define EOL "\n"
|
||||
#endif
|
||||
|
||||
// Initialization of global variable with an instance of this class
|
||||
OCCDemo_Presentation* OCCDemo_Presentation::Current = new Tesselate_Presentation;
|
||||
|
||||
// Initialization of array of samples
|
||||
Standard_CString Tesselate_Presentation::myFileNames[] =
|
||||
{
|
||||
"wedge_ok.brep",
|
||||
"shell1.brep",
|
||||
"Pump_Nut.brep",
|
||||
"Pump_TopCover.brep",
|
||||
0
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
Tesselate_Presentation::Tesselate_Presentation()
|
||||
{
|
||||
for (myNbSamples = 0; myFileNames[myNbSamples]; myNbSamples++);
|
||||
setName ("Tesselate shapes");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Sample execution
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Tesselate_Presentation::DoSample()
|
||||
{
|
||||
((CTriangulationApp*) AfxGetApp())->SetSampleName("Tesselate");
|
||||
((CTriangulationApp*) AfxGetApp())->SetSamplePath("");
|
||||
getAISContext()->EraseAll();
|
||||
if (myIndex >=0 && myIndex < myNbSamples)
|
||||
sample (myFileNames[myIndex]);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Sample functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//================================================================
|
||||
|
||||
inline Standard_Integer _key(Standard_Integer n1,Standard_Integer n2)
|
||||
{
|
||||
|
||||
Standard_Integer key =
|
||||
(n2>n1)?(n1<<16)+n2:(n2<<16)+n1;
|
||||
return key;
|
||||
}
|
||||
|
||||
//DATA : [myIndex][{Deflection,NumberOfFace,NumberOfEdge}]
|
||||
static const Standard_Real DATA [][3] =
|
||||
{
|
||||
{0.2,1,2},{0.5,6,2},{0.7,16,2},{1,1,2}
|
||||
};
|
||||
|
||||
|
||||
void Tesselate_Presentation::tesselateShape(const TopoDS_Shape& aShape)
|
||||
{
|
||||
// setResultTitle("Tesselate shape");
|
||||
TCollection_AsciiString aText = (
|
||||
"/////////////////////////////////////////////////////////////////" EOL
|
||||
"// Tesselate shape." EOL
|
||||
"/////////////////////////////////////////////////////////////////" EOL EOL
|
||||
) ;
|
||||
|
||||
Standard_Real aDeflection = DATA[myIndex][0];
|
||||
Standard_Integer aNumOfFace = (Standard_Integer)DATA[myIndex][1];
|
||||
Standard_Integer aNumOfEdge = (Standard_Integer)DATA[myIndex][2];
|
||||
|
||||
aText +=
|
||||
"Standard_Real aDeflection;" EOL
|
||||
"// aDeflection = ... ;" EOL EOL
|
||||
|
||||
"// removes all the triangulations of the faces ," EOL
|
||||
"//and all the polygons on the triangulations of the edges:" EOL
|
||||
"BRepTools::Clean(aShape);" EOL EOL
|
||||
|
||||
"// adds a triangulation of the shape aShape with the deflection aDeflection:" EOL
|
||||
"BRepMesh::Mesh(aShape,aDeflection);" EOL EOL
|
||||
|
||||
"TopExp_Explorer aExpFace,aExpEdge;" EOL
|
||||
"for(aExpFace.Init(aShape,TopAbs_FACE);aExpFace.More();aExpFace.Next())" EOL
|
||||
"{ " EOL
|
||||
" TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());" EOL
|
||||
" TopLoc_Location aLocation;" EOL EOL
|
||||
|
||||
" // takes the triangulation of the face aFace:" EOL
|
||||
" Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);" EOL EOL
|
||||
|
||||
" if(!aTr.IsNull()) // if this triangulation is not NULL" EOL
|
||||
" { " EOL
|
||||
" // takes the array of nodes for this triangulation:" EOL
|
||||
" const TColgp_Array1OfPnt& aNodes = aTr->Nodes();" EOL
|
||||
" // takes the array of triangles for this triangulation:" EOL
|
||||
" const Poly_Array1OfTriangle& triangles = aTr->Triangles();" EOL EOL
|
||||
|
||||
" // create array of node points in absolute coordinate system" EOL
|
||||
" TColgp_Array1OfPnt aPoints(1, aNodes.Length());" EOL
|
||||
" for( Standard_Integer i = 1; i < aNodes.Length()+1; i++)" EOL
|
||||
" aPoints(i) = aNodes(i).Transformed(aLocation);" EOL EOL
|
||||
|
||||
" // Takes the node points of each triangle of this triangulation." EOL
|
||||
" // takes a number of triangles:" EOL
|
||||
" Standard_Integer nnn = aTr->NbTriangles();" EOL
|
||||
" Standard_Integer nt,n1,n2,n3;" EOL
|
||||
" for( nt = 1 ; nt < nnn+1 ; nt++)" EOL
|
||||
" {" EOL
|
||||
" // takes the node indices of each triangle in n1,n2,n3:" EOL
|
||||
" triangles(nt).Get(n1,n2,n3);" EOL
|
||||
" // takes the node points:" EOL
|
||||
" gp_Pnt aPnt1 = aPoints(n1);" EOL
|
||||
" gp_Pnt aPnt2 = aPoints(n2);" EOL
|
||||
" gp_Pnt aPnt3 = aPoints(n3);" EOL
|
||||
" } " EOL EOL
|
||||
|
||||
" // Takes the polygon associated to an edge." EOL
|
||||
" aExpEdge.Init(aFace,TopAbs_EDGE);" EOL
|
||||
" TopoDS_Edge aEdge;" EOL
|
||||
" // for example,working with the first edge:" EOL
|
||||
" if(aExpEdge.More())" EOL
|
||||
" aEdge = TopoDS::Edge(aExpEdge.Current());" EOL EOL
|
||||
|
||||
" if(!aEdge.IsNull()) // if this edge is not NULL" EOL
|
||||
" {" EOL
|
||||
" // takes the polygon associated to the edge aEdge:" EOL
|
||||
" Handle_Poly_PolygonOnTriangulation aPol = " EOL
|
||||
" BRep_Tool::PolygonOnTriangulation(aEdge,aTr,aEdge.Location());" EOL EOL
|
||||
|
||||
" if(!aPol.IsNull()) // if this polygon is not NULL" EOL
|
||||
" // takes the array of nodes for this polygon" EOL
|
||||
" // (indexes in the array of nodes for triangulation of theFace):" EOL
|
||||
" const TColStd_Array1OfInteger& aNodesOfPol = aPol->Nodes();" EOL
|
||||
" }" EOL
|
||||
" }" EOL
|
||||
"}" EOL EOL
|
||||
|
||||
"//==================================================" EOL EOL
|
||||
|
||||
;
|
||||
aText += " Result with deflection = ";
|
||||
aText += TCollection_AsciiString(aDeflection);
|
||||
aText += " :" EOL;
|
||||
|
||||
GetDocument()->PocessTextInDialog("Compute the triangulation on a shape", aText);
|
||||
// setResultText(aText.ToCString());
|
||||
|
||||
//==========================================================================
|
||||
|
||||
BRepTools::Clean(aShape);
|
||||
BRepMesh::Mesh(aShape,aDeflection);
|
||||
|
||||
BRep_Builder aBuilder,aBuild1,aBuild2;
|
||||
TopoDS_Compound aCompound,aComp1,aComp2;
|
||||
aBuilder.MakeCompound(aCompound);
|
||||
aBuild1.MakeCompound(aComp1);
|
||||
aBuild2.MakeCompound(aComp2);
|
||||
|
||||
TopTools_SequenceOfShape aVertices;
|
||||
Standard_Integer aCount = 0;
|
||||
Standard_Integer aNumOfNodes = 0;
|
||||
Standard_Integer aNumOfTriangles = 0;
|
||||
|
||||
Handle_AIS_InteractiveObject aShowEdge,aShowFace,aShowShape;
|
||||
|
||||
TopExp_Explorer aExpFace,aExpEdge;
|
||||
|
||||
for(aExpFace.Init(aShape,TopAbs_FACE);aExpFace.More();aExpFace.Next())
|
||||
{
|
||||
aCount++;
|
||||
|
||||
TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());
|
||||
TopLoc_Location aLocation;
|
||||
|
||||
Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);
|
||||
|
||||
if(!aTr.IsNull())
|
||||
{
|
||||
const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
|
||||
aNumOfNodes += aTr->NbNodes();
|
||||
Standard_Integer aLower = aNodes.Lower();
|
||||
Standard_Integer anUpper = aNodes.Upper();
|
||||
const Poly_Array1OfTriangle& triangles = aTr->Triangles();
|
||||
aNumOfTriangles += aTr->NbTriangles();
|
||||
|
||||
if(aCount == aNumOfFace)
|
||||
{
|
||||
Standard_Integer aNbOfNodesOfFace = aTr->NbNodes();
|
||||
Standard_Integer aNbOfTrianglesOfFace = aTr->NbTriangles();
|
||||
aExpEdge.Init(aFace,TopAbs_EDGE);
|
||||
|
||||
TopoDS_Edge aEdge;
|
||||
|
||||
for( Standard_Integer i = 0; aExpEdge.More() && i < aNumOfEdge ; aExpEdge.Next(), i++)
|
||||
aEdge = TopoDS::Edge(aExpEdge.Current());
|
||||
|
||||
if(!aEdge.IsNull())
|
||||
{
|
||||
Handle_Poly_PolygonOnTriangulation aPol =
|
||||
BRep_Tool::PolygonOnTriangulation(aEdge,aTr,aEdge.Location());
|
||||
|
||||
if(!aPol.IsNull())
|
||||
{
|
||||
const TColStd_Array1OfInteger& aNodesOfPol = aPol->Nodes();
|
||||
Standard_Integer aNbOfNodesOfEdge = aPol->NbNodes();
|
||||
|
||||
aText += "Number of nodes of the edge = ";
|
||||
aText += TCollection_AsciiString(aNbOfNodesOfEdge) + EOL;
|
||||
aText += "Number of nodes of the face = ";
|
||||
aText += TCollection_AsciiString(aNbOfNodesOfFace) + EOL;
|
||||
aText += "Number of triangles of the face = ";
|
||||
aText += TCollection_AsciiString(aNbOfTrianglesOfFace) + EOL;
|
||||
GetDocument()->PocessTextInDialog("Compute the triangulation on a shape", aText);
|
||||
// setResultText(aText.ToCString());
|
||||
|
||||
Standard_Integer aLower = aNodesOfPol.Lower(), anUpper = aNodesOfPol.Upper();
|
||||
for( int i = aLower; i < anUpper ; i++)
|
||||
{
|
||||
gp_Pnt aPnt1 = aNodes(aNodesOfPol(i)).Transformed(aLocation);
|
||||
gp_Pnt aPnt2 = aNodes(aNodesOfPol(i+1)).Transformed(aLocation);
|
||||
TopoDS_Vertex aVertex1 = BRepBuilderAPI_MakeVertex (aPnt1);
|
||||
TopoDS_Vertex aVertex2 = BRepBuilderAPI_MakeVertex (aPnt2);
|
||||
|
||||
if(!aVertex1.IsNull() && !aVertex2.IsNull() && // if vertices are "alive"
|
||||
!BRep_Tool::Pnt(aVertex1).IsEqual(
|
||||
BRep_Tool::Pnt(aVertex2),Precision::Confusion())) // if they are different
|
||||
{
|
||||
aEdge = BRepBuilderAPI_MakeEdge (aVertex1,aVertex2);
|
||||
aBuild2.Add(aComp2,aVertex1);
|
||||
if(!aEdge.IsNull())
|
||||
aBuild2.Add(aComp2,aEdge);
|
||||
if(i == anUpper-1)
|
||||
aBuild2.Add(aComp2,aVertex2);
|
||||
}
|
||||
}
|
||||
|
||||
getAISContext()->EraseAll();
|
||||
aShowShape = drawShape(aShape);
|
||||
if(WAIT_A_SECOND) return;
|
||||
aShowEdge = drawShape(aComp2,Quantity_NOC_GREEN);
|
||||
getAISContext()->Erase(aShowShape);
|
||||
if(WAIT_A_SECOND) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TopTools_DataMapOfIntegerShape aEdges;
|
||||
TopTools_SequenceOfShape aVertices;
|
||||
|
||||
for( Standard_Integer i = 1; i < aNodes.Length()+1; i++)
|
||||
{
|
||||
gp_Pnt aPnt = aNodes(i).Transformed(aLocation);
|
||||
TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(aPnt);
|
||||
|
||||
if(!aVertex.IsNull())
|
||||
{
|
||||
aBuilder.Add(aCompound,aVertex);
|
||||
if(aCount == aNumOfFace )
|
||||
aBuild1.Add(aComp1,aVertex);
|
||||
aVertices.Append(aVertex);
|
||||
}
|
||||
}
|
||||
|
||||
Standard_Integer nnn = aTr->NbTriangles();
|
||||
Standard_Integer nt,n1,n2,n3;
|
||||
|
||||
for( nt = 1 ; nt < nnn+1 ; nt++)
|
||||
{
|
||||
triangles(nt).Get(n1,n2,n3);
|
||||
|
||||
Standard_Integer key[3];
|
||||
|
||||
TopoDS_Vertex aV1,aV2;
|
||||
key[0] = _key(n1, n2);
|
||||
if(!aEdges.IsBound(key[0]))
|
||||
{
|
||||
aV1 = TopoDS::Vertex(aVertices(n1));
|
||||
aV2 = TopoDS::Vertex(aVertices(n2));
|
||||
if(!aV1.IsNull() && !aV2.IsNull() &&
|
||||
!BRep_Tool::Pnt(aV1).IsEqual(BRep_Tool::Pnt(aV2),Precision::Confusion()))
|
||||
{
|
||||
TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge (aV1,aV2);
|
||||
if(!aEdge.IsNull())
|
||||
{
|
||||
aEdges.Bind(key[0], aEdge);
|
||||
aBuilder.Add(aCompound,aEdges(key[0]));
|
||||
if(aCount == aNumOfFace)
|
||||
aBuild1.Add(aComp1,aEdges(key[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
key[1] = _key(n2,n3);
|
||||
if(!aEdges.IsBound(key[1]))
|
||||
{
|
||||
aV1 = TopoDS::Vertex(aVertices(n2));
|
||||
aV2 = TopoDS::Vertex(aVertices(n3));
|
||||
if(!aV1.IsNull() && !aV2.IsNull() &&
|
||||
!BRep_Tool::Pnt(aV1).IsEqual(BRep_Tool::Pnt(aV2),Precision::Confusion()))
|
||||
{
|
||||
TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge (aV1,aV2);
|
||||
if(!aEdge.IsNull())
|
||||
{
|
||||
aEdges.Bind(key[1],aEdge);
|
||||
aBuilder.Add(aCompound,aEdges(key[1]));
|
||||
if(aCount == aNumOfFace)
|
||||
aBuild1.Add(aComp1,aEdges(key[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
key[2] = _key(n3,n1);
|
||||
if(!aEdges.IsBound(key[2]))
|
||||
{
|
||||
aV1 = TopoDS::Vertex(aVertices(n3));
|
||||
aV2 = TopoDS::Vertex(aVertices(n1));
|
||||
if(!aV1.IsNull() && !aV2.IsNull() &&
|
||||
!BRep_Tool::Pnt(aV1).IsEqual(BRep_Tool::Pnt(aV2),Precision::Confusion()))
|
||||
{
|
||||
TopoDS_Edge aEdge = BRepBuilderAPI_MakeEdge (aV1,aV2);
|
||||
if(!aEdge.IsNull())
|
||||
{
|
||||
aEdges.Bind(key[2],aEdge);
|
||||
aBuilder.Add(aCompound,aEdges(key[2]));
|
||||
if(aCount == aNumOfFace)
|
||||
aBuild1.Add(aComp1,aEdges(key[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(aCount == aNumOfFace)
|
||||
{
|
||||
aShowFace = drawShape(aComp1,Quantity_NOC_GREEN);
|
||||
getAISContext()->Erase(aShowEdge);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aText += "Can't compute a triangulation on face ";
|
||||
aText += TCollection_AsciiString(aCount) + EOL;
|
||||
GetDocument()->PocessTextInDialog("Compute the triangulation on a shape", aText);
|
||||
// setResultText(aText.ToCString());
|
||||
}
|
||||
}
|
||||
|
||||
aText += "Number of nodes of the shape = ";
|
||||
aText += TCollection_AsciiString(aNumOfNodes) + EOL;
|
||||
aText += "Number of triangles of the shape = ";
|
||||
aText += TCollection_AsciiString(aNumOfTriangles) + EOL EOL;
|
||||
GetDocument()->PocessTextInDialog("Compute the triangulation on a shape", aText);
|
||||
// setResultText(aText.ToCString());
|
||||
|
||||
if(WAIT_A_SECOND) return;
|
||||
drawShape(aCompound,Quantity_NOC_GREEN);
|
||||
getAISContext()->Erase(aShowFace);
|
||||
|
||||
}
|
||||
|
||||
void Tesselate_Presentation::sample(const Standard_CString aFileName)
|
||||
{
|
||||
CString initfile(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir());
|
||||
initfile += "\\..\\..\\Data\\";
|
||||
initfile += aFileName;
|
||||
|
||||
|
||||
TCollection_AsciiString Path((Standard_CString)(LPCTSTR)initfile);
|
||||
/*
|
||||
ResetView();
|
||||
|
||||
if (aFileName == "wedge_ok.brep"){
|
||||
SetViewCenter(6.3639597574916, 4.4907309380832);
|
||||
SetViewScale(52.722555157077);
|
||||
}
|
||||
|
||||
if (aFileName == "shell1.brep"){
|
||||
SetViewCenter(60.457553053711, -20.351208944076);
|
||||
SetViewScale(26.857478563027);
|
||||
}
|
||||
|
||||
if (aFileName == "Pump_Nut.brep"){
|
||||
SetViewCenter(248.77723166710, 77.249633819945);
|
||||
SetViewScale(12.371719671833);
|
||||
}
|
||||
|
||||
if (aFileName == "Pump_TopCover.brep"){
|
||||
SetViewCenter(408.72474423160, 169.38361094986);
|
||||
SetViewScale(2.1932732873087);
|
||||
}
|
||||
*/
|
||||
|
||||
TopoDS_Shape aShape;
|
||||
BRep_Builder aBld;
|
||||
//Standard_Boolean isRead = BRepTools::Read (aShape, aPath.ToCString(), aBld);
|
||||
//if (!isRead)
|
||||
// isRead = BRepTools::Read (aShape, bPath.ToCString(), aBld);
|
||||
Standard_Boolean isRead = BRepTools::Read (aShape, Path.ToCString(), aBld);
|
||||
if (!isRead)
|
||||
{
|
||||
Path += " was not found. The sample can not be shown.";
|
||||
GetDocument()->PocessTextInDialog("Compute the triangulation on a shape", Path);
|
||||
// setResultText(Path.ToCString());
|
||||
return;
|
||||
}
|
||||
|
||||
tesselateShape (aShape);
|
||||
|
||||
}
|
34
samples/mfc/standard/07_Triangulation/src/Tesselate_Presentation.h
Executable file
34
samples/mfc/standard/07_Triangulation/src/Tesselate_Presentation.h
Executable file
@@ -0,0 +1,34 @@
|
||||
// Tesselate_Presentation.h: interface for the Tesselate_Presentation class.
|
||||
// Presentation class: Tesselate shapes.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_Tesselate_PRESENTATION_H__790EED7F_7BA2_11D5_BA4A_0060B0EE18EA__INCLUDED_)
|
||||
#define AFX_Tesselate_PRESENTATION_H__790EED7F_7BA2_11D5_BA4A_0060B0EE18EA__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include <OCCDemo_Presentation.h>
|
||||
|
||||
class Tesselate_Presentation : public OCCDemo_Presentation
|
||||
{
|
||||
public:
|
||||
// Construction
|
||||
Tesselate_Presentation();
|
||||
|
||||
public:
|
||||
// Iteration on samples
|
||||
virtual void DoSample();
|
||||
// one phase of iterations
|
||||
|
||||
private:
|
||||
// Sample functions
|
||||
void sample(const Standard_CString aFileName);
|
||||
void tesselateShape(const TopoDS_Shape& aShape);
|
||||
|
||||
static Standard_CString myFileNames[];
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_Tesselate_PRESENTATION_H__790EED7F_7BA2_11D5_BA4A_0060B0EE18EA__INCLUDED_)
|
76
samples/mfc/standard/07_Triangulation/src/TriangulationApp.cpp
Executable file
76
samples/mfc/standard/07_Triangulation/src/TriangulationApp.cpp
Executable file
@@ -0,0 +1,76 @@
|
||||
// TriangulationApp.cpp : Defines the class behaviors for the application.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "TriangulationApp.h"
|
||||
|
||||
#include "OCC_MainFrame.h"
|
||||
#include "OCC_3dChildFrame.h"
|
||||
#include "TriangulationDoc.h"
|
||||
#include "OCC_3dView.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTriangulationApp construction
|
||||
|
||||
CTriangulationApp::CTriangulationApp()
|
||||
{
|
||||
SampleName = "TopologyTriangulation"; //for about dialog
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// The one and only CTriangulationApp object
|
||||
|
||||
CTriangulationApp theApp;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTriangulationApp initialization
|
||||
|
||||
BOOL CTriangulationApp::InitInstance()
|
||||
{
|
||||
AfxEnableControlContainer();
|
||||
|
||||
// Standard initialization
|
||||
// If you are not using these features and wish to reduce the size
|
||||
// of your final executable, you should remove from the following
|
||||
// the specific initialization routines you do not need.
|
||||
|
||||
// Change the registry key under which our settings are stored.
|
||||
// You should modify this string to be something appropriate
|
||||
// such as the name of your company or organization.
|
||||
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
|
||||
|
||||
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
|
||||
|
||||
// Register the application's document templates. Document templates
|
||||
// serve as the connection between documents, frame windows and views.
|
||||
|
||||
CMultiDocTemplate* pDocTemplate;
|
||||
pDocTemplate = new CMultiDocTemplate(
|
||||
IDR_3DTYPE,
|
||||
RUNTIME_CLASS(CTriangulationDoc),
|
||||
RUNTIME_CLASS(OCC_3dChildFrame), // custom MDI child frame
|
||||
RUNTIME_CLASS(OCC_3dView));
|
||||
AddDocTemplate(pDocTemplate);
|
||||
|
||||
// create main MDI Frame window
|
||||
OCC_MainFrame* pMainFrame = new OCC_MainFrame(with_AIS_TB);
|
||||
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
|
||||
return FALSE;
|
||||
m_pMainWnd = pMainFrame;
|
||||
|
||||
// Parse command line for standard shell commands, DDE, file open
|
||||
CCommandLineInfo cmdInfo;
|
||||
ParseCommandLine(cmdInfo);
|
||||
|
||||
// Dispatch commands specified on the command line
|
||||
if (!ProcessShellCommand(cmdInfo))
|
||||
return FALSE;
|
||||
|
||||
// The main window has been initialized, so show and update it.
|
||||
pMainFrame->ShowWindow(m_nCmdShow);
|
||||
pMainFrame->UpdateWindow();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
30
samples/mfc/standard/07_Triangulation/src/TriangulationApp.h
Executable file
30
samples/mfc/standard/07_Triangulation/src/TriangulationApp.h
Executable file
@@ -0,0 +1,30 @@
|
||||
// TriangulationApp.h : main header file for the TRIANGULATION application
|
||||
//
|
||||
|
||||
#if !defined(AFX_TRIANGULATIONAPP_H__3045338A_3E75_11D7_8611_0060B0EE281E__INCLUDED_)
|
||||
#define AFX_TRIANGULATIONAPP_H__3045338A_3E75_11D7_8611_0060B0EE281E__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
#include <OCC_3dApp.h>
|
||||
|
||||
class CTriangulationApp : public OCC_3dApp
|
||||
{
|
||||
public:
|
||||
CTriangulationApp();
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CTriangulationApp)
|
||||
public:
|
||||
virtual BOOL InitInstance();
|
||||
//}}AFX_VIRTUAL
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_TRIANGULATIONAPP_H__3045338A_3E75_11D7_8611_0060B0EE281E__INCLUDED_)
|
451
samples/mfc/standard/07_Triangulation/src/TriangulationDoc.cpp
Executable file
451
samples/mfc/standard/07_Triangulation/src/TriangulationDoc.cpp
Executable file
@@ -0,0 +1,451 @@
|
||||
// TriangulationDoc.cpp : implementation of the CTriangulationDoc class
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "TriangulationDoc.h"
|
||||
|
||||
#include "TriangulationApp.h"
|
||||
|
||||
#include "OCCDemo_Presentation.h"
|
||||
|
||||
#include <OCC_3dView.h>
|
||||
|
||||
#include "..\res\resource.h"
|
||||
|
||||
#include <AIS_ListOfInteractive.hxx>
|
||||
#include <AIS_ListIteratorOfListOfInteractive.hxx>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTriangulationDoc
|
||||
|
||||
IMPLEMENT_DYNCREATE(CTriangulationDoc, CDocument)
|
||||
|
||||
BEGIN_MESSAGE_MAP(CTriangulationDoc, OCC_3dBaseDoc)
|
||||
//{{AFX_MSG_MAP(CTriangulationDoc)
|
||||
ON_COMMAND(ID_TRIANGU, OnTriangu)
|
||||
ON_COMMAND(ID_Clear, OnClear)
|
||||
ON_COMMAND(ID_Visu, OnVisu)
|
||||
ON_COMMAND(ID_BUTTONNext, OnBUTTONNext)
|
||||
ON_COMMAND(ID_BUTTONStart, OnBUTTONStart)
|
||||
ON_COMMAND(ID_BUTTONRepeat, OnBUTTONRepeat)
|
||||
ON_COMMAND(ID_BUTTONPrev, OnBUTTONPrev)
|
||||
ON_COMMAND(ID_BUTTONEnd, OnBUTTONEnd)
|
||||
ON_UPDATE_COMMAND_UI(ID_BUTTONNext, OnUpdateBUTTONNext)
|
||||
ON_UPDATE_COMMAND_UI(ID_BUTTONPrev, OnUpdateBUTTONPrev)
|
||||
ON_COMMAND(ID_FILE_NEW, OnFileNew)
|
||||
ON_COMMAND(ID_DUMP_VIEW, OnDumpView)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTriangulationDoc construction/destruction
|
||||
|
||||
CTriangulationDoc::CTriangulationDoc()
|
||||
{
|
||||
myPresentation = OCCDemo_Presentation::Current;
|
||||
myPresentation->SetDocument(this);
|
||||
|
||||
strcpy_s(myDataDir, "Data");
|
||||
strcpy_s(myLastPath, ".");
|
||||
}
|
||||
|
||||
CTriangulationDoc::~CTriangulationDoc()
|
||||
{
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTriangulationDoc diagnostics
|
||||
|
||||
#ifdef _DEBUG
|
||||
void CTriangulationDoc::AssertValid() const
|
||||
{
|
||||
CDocument::AssertValid();
|
||||
}
|
||||
|
||||
void CTriangulationDoc::Dump(CDumpContext& dc) const
|
||||
{
|
||||
CDocument::Dump(dc);
|
||||
}
|
||||
#endif //_DEBUG
|
||||
|
||||
void CTriangulationDoc::OnTriangu()
|
||||
{
|
||||
AIS_ListOfInteractive aList;
|
||||
myAISContext->DisplayedObjects(aList);
|
||||
AIS_ListIteratorOfListOfInteractive aListIterator;
|
||||
for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
|
||||
myAISContext->Remove(aListIterator.Value());
|
||||
}
|
||||
|
||||
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,60,60);
|
||||
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80);
|
||||
TopoDS_Shape ShapeFused = BRepAlgoAPI_Fuse(theSphere,theBox);
|
||||
BRepMesh::Mesh(ShapeFused,1);
|
||||
|
||||
Handle (AIS_Shape) aSection = new AIS_Shape(ShapeFused);
|
||||
myAISContext->SetDisplayMode(aSection,1);
|
||||
myAISContext->SetColor(aSection,Quantity_NOC_RED);
|
||||
myAISContext->SetMaterial(aSection,Graphic3d_NOM_GOLD);
|
||||
myAISContext->Display(aSection);
|
||||
|
||||
Standard_Integer result(0);
|
||||
|
||||
for (TopExp_Explorer ex(ShapeFused,TopAbs_FACE) ; ex.More(); ex.Next()) {
|
||||
TopoDS_Face F =TopoDS::Face(ex.Current());
|
||||
TopLoc_Location L;
|
||||
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
|
||||
result = result + facing->NbTriangles();
|
||||
}
|
||||
Fit();
|
||||
|
||||
TCollection_AsciiString Message ("\
|
||||
\n\
|
||||
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,60,60); \n\
|
||||
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80); \n\
|
||||
\n\
|
||||
TopoDS_Shape ShapeFused = BRepBuilderAPI_Fuse(theSphere,theBox); \n\
|
||||
\n\
|
||||
BRepMesh::Mesh(ShapeFused,1); \n\
|
||||
\n\
|
||||
Standard_Integer result(0); \n\
|
||||
\n\
|
||||
for (TopExp_Explorer ex(ShapeFused,TopAbs_FACE) ; ex.More(); ex.Next()) { \n\
|
||||
TopoDS_Face F =TopoDS::Face(ex.Current()); \n\
|
||||
TopLoc_Location L; \n\
|
||||
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L); \n\
|
||||
result = result + facing->NbTriangles(); \n\
|
||||
} \n\
|
||||
\n\
|
||||
--- Number of created triangles ---\n");
|
||||
TCollection_AsciiString nombre(result);
|
||||
Message += nombre;
|
||||
Message +=("\
|
||||
\n\
|
||||
\n");
|
||||
PocessTextInDialog("Compute the triangulation on a shape", Message);
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnVisu()
|
||||
{
|
||||
|
||||
AIS_ListOfInteractive aList;
|
||||
myAISContext->DisplayedObjects(aList);
|
||||
AIS_ListIteratorOfListOfInteractive aListIterator;
|
||||
for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
|
||||
myAISContext->Remove(aListIterator.Value());
|
||||
}
|
||||
|
||||
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,60,60);
|
||||
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80);
|
||||
TopoDS_Shape ShapeFused = BRepAlgoAPI_Fuse(theSphere,theBox);
|
||||
BRepMesh::Mesh(ShapeFused,1);
|
||||
|
||||
Handle (AIS_Shape) aSection = new AIS_Shape(ShapeFused);
|
||||
myAISContext->SetDisplayMode(aSection,1);
|
||||
myAISContext->SetColor(aSection,Quantity_NOC_RED);
|
||||
myAISContext->SetMaterial(aSection,Graphic3d_NOM_GOLD);
|
||||
myAISContext->SetTransparency(aSection,0.1);
|
||||
myAISContext->Display(aSection);
|
||||
|
||||
BRep_Builder builder;
|
||||
TopoDS_Compound Comp;
|
||||
builder.MakeCompound(Comp);
|
||||
|
||||
for (TopExp_Explorer ex(ShapeFused,TopAbs_FACE) ; ex.More(); ex.Next()) {
|
||||
|
||||
TopoDS_Face F =TopoDS::Face(ex.Current());
|
||||
TopLoc_Location L;
|
||||
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
|
||||
TColgp_Array1OfPnt tab(1,(facing->NbNodes()));
|
||||
tab = facing->Nodes();
|
||||
Poly_Array1OfTriangle tri(1,facing->NbTriangles());
|
||||
tri = facing->Triangles();
|
||||
|
||||
for (Standard_Integer i=1;i<=(facing->NbTriangles());i++) {
|
||||
Poly_Triangle trian = tri.Value(i);
|
||||
Standard_Integer index1,index2,index3,M,N;
|
||||
trian.Get(index1,index2,index3);
|
||||
|
||||
for (Standard_Integer j=1;j<=3;j++) {
|
||||
switch (j) {
|
||||
case 1 :
|
||||
M = index1;
|
||||
N = index2;
|
||||
break;
|
||||
case 2 :
|
||||
N = index3;
|
||||
break;
|
||||
case 3 :
|
||||
M = index2;
|
||||
}
|
||||
|
||||
BRepBuilderAPI_MakeEdge ME(tab.Value(M),tab.Value(N));
|
||||
if (ME.IsDone()) {
|
||||
builder.Add(Comp,ME.Edge());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Handle (AIS_Shape) atriangulation = new AIS_Shape(Comp);
|
||||
myAISContext->SetDisplayMode(atriangulation,0);
|
||||
myAISContext->SetColor(atriangulation,Quantity_NOC_WHITE);
|
||||
myAISContext->Display(atriangulation);
|
||||
|
||||
Fit();
|
||||
|
||||
TCollection_AsciiString Message ("\
|
||||
\n\
|
||||
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,60,60); \n\
|
||||
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80); \n\
|
||||
TopoDS_Shape ShapeFused = BRepAlgoAPI_Fuse(theSphere,theBox); \n\
|
||||
BRepMesh::Mesh(ShapeFused,1); \n\
|
||||
\n\
|
||||
BRep_Builder builder; \n\
|
||||
TopoDS_Compound Comp; \n\
|
||||
builder.MakeCompound(Comp); \n\
|
||||
\n\
|
||||
for (TopExp_Explorer ex(ShapeFused,TopAbs_FACE) ; ex.More(); ex.Next()) { \n\
|
||||
\n\
|
||||
TopoDS_Face F =TopoDS::Face(ex.Current()); \n\
|
||||
TopLoc_Location L; \n\
|
||||
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L); \n\
|
||||
TColgp_Array1OfPnt tab(1,(facing->NbNodes())); \n\
|
||||
tab = facing->Nodes(); \n\
|
||||
Poly_Array1OfTriangle tri(1,facing->NbTriangles()); \n\
|
||||
tri = facing->Triangles(); \n\
|
||||
\n\
|
||||
for (Standard_Integer i=1;i<=(facing->NbTriangles());i++) { \n\
|
||||
Poly_Triangle trian = tri.Value(i); \n\
|
||||
Standard_Integer index1,index2,index3,M,N; \n\
|
||||
trian.Get(index1,index2,index3); \n\
|
||||
\n\
|
||||
for (Standard_Integer j=1;j<=3;j++) { \n\
|
||||
switch (j) { \n\
|
||||
case 1 : \n\
|
||||
M = index1; \n\
|
||||
N = index2; \n\
|
||||
break; \n\
|
||||
case 2 : \n\
|
||||
N = index3; \n\
|
||||
break; \n\
|
||||
case 3 : \n\
|
||||
M = index2; \n\
|
||||
} \n\
|
||||
\n\
|
||||
BRepBuilderAPI_MakeEdge ME(tab.Value(M),tab.Value(N)); \n\
|
||||
if (ME.IsDone()) { \n\
|
||||
builder.Add(Comp,ME.Edge()); \n\
|
||||
} \n\
|
||||
} \n\
|
||||
} \n\
|
||||
} \n\
|
||||
\n\
|
||||
Warning : The visualisation of the mesh is not optimised.\n\
|
||||
The shared edges between triangles are dispayed twice.\n\
|
||||
The purpose here is only to show how to decode the data structure of triangulation.\n\
|
||||
\n");
|
||||
PocessTextInDialog("Visualize the triangulation on a shape", Message);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void CTriangulationDoc::OnClear()
|
||||
{
|
||||
AIS_ListOfInteractive aList;
|
||||
myAISContext->DisplayedObjects(aList);
|
||||
AIS_ListIteratorOfListOfInteractive aListIterator;
|
||||
for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
|
||||
myAISContext->Remove(aListIterator.Value());
|
||||
}
|
||||
|
||||
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,60,60);
|
||||
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80);
|
||||
TopoDS_Shape ShapeFused = BRepAlgoAPI_Fuse(theSphere,theBox);
|
||||
BRepMesh::Mesh(ShapeFused,1);
|
||||
|
||||
|
||||
Handle (AIS_Shape) aSection = new AIS_Shape(ShapeFused);
|
||||
myAISContext->SetDisplayMode(aSection,1);
|
||||
myAISContext->SetColor(aSection,Quantity_NOC_RED);
|
||||
myAISContext->SetMaterial(aSection,Graphic3d_NOM_GOLD);
|
||||
myAISContext->Display(aSection);
|
||||
|
||||
BRepTools::Clean(ShapeFused);
|
||||
|
||||
TCollection_AsciiString test;
|
||||
if (!BRepTools::Triangulation(ShapeFused,1)) {
|
||||
test = ("In fact the triangulation has been removed\n");
|
||||
}
|
||||
|
||||
Fit();
|
||||
TCollection_AsciiString Message ("\
|
||||
\n\
|
||||
TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,60,60); \n\
|
||||
TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80); \n\
|
||||
TopoDS_Shape ShapeFused = BRepAlgoAPI_Fuse(theSphere,theBox); \n\
|
||||
BRepMesh::Mesh(ShapeFused,1); \n\
|
||||
\n\
|
||||
BRepTools::Clean(ShapeFused); \n\
|
||||
\n\
|
||||
if (!BRepTools::Triangulation(ShapeFused,1)) { \n\
|
||||
TCollection_AsciiString test(<In fact the triangulation has been removed>); \n\
|
||||
} \n\
|
||||
\n\
|
||||
--- Result ---\n");
|
||||
|
||||
Message += test;
|
||||
Message +=("\
|
||||
\n\
|
||||
\n");
|
||||
|
||||
PocessTextInDialog("Remove the triangulation", Message);
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
********************* T E S S E L A T E **************************************
|
||||
*******************************************************************************/
|
||||
|
||||
void CTriangulationDoc::Start()
|
||||
{
|
||||
myPresentation->Init();
|
||||
OnBUTTONStart();
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnFileNew()
|
||||
{
|
||||
OnNewDocument();
|
||||
Start();
|
||||
}
|
||||
|
||||
void CTriangulationDoc::InitViewButtons()
|
||||
{
|
||||
POSITION pos = GetFirstViewPosition();
|
||||
/* LLS
|
||||
while (pos != NULL)
|
||||
{
|
||||
COCCDemoView* pView = (COCCDemoView*) GetNextView(pos);
|
||||
pView->InitButtons();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void CTriangulationDoc::DoSample()
|
||||
{
|
||||
InitViewButtons();
|
||||
|
||||
HCURSOR hOldCursor = ::GetCursor();
|
||||
HCURSOR hNewCursor = AfxGetApp()->LoadStandardCursor(IDC_APPSTARTING);
|
||||
|
||||
SetCursor(hNewCursor);
|
||||
{
|
||||
try
|
||||
{
|
||||
myPresentation->DoSample();
|
||||
}
|
||||
catch (Standard_Failure)
|
||||
{
|
||||
Standard_SStream aSStream;
|
||||
aSStream << "An exception was caught: " << Standard_Failure::Caught() << ends;
|
||||
Standard_CString aMsg = aSStream.str().c_str();
|
||||
// aSStream.rdbuf()->freeze(0); // allow deletion of dynamic array
|
||||
AfxMessageBox (aMsg);
|
||||
}
|
||||
}
|
||||
SetCursor(hOldCursor);
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnBUTTONStart()
|
||||
{
|
||||
myAISContext->EraseAll(Standard_False);
|
||||
myPresentation->FirstSample();
|
||||
DoSample();
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnBUTTONEnd()
|
||||
{
|
||||
myAISContext->EraseAll(Standard_False);
|
||||
myPresentation->LastSample();
|
||||
DoSample();
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnBUTTONRepeat()
|
||||
{
|
||||
DoSample();
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnBUTTONNext()
|
||||
{
|
||||
if (!myPresentation->AtLastSample())
|
||||
{
|
||||
myPresentation->NextSample();
|
||||
DoSample();
|
||||
}
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnBUTTONPrev()
|
||||
{
|
||||
if (!myPresentation->AtFirstSample())
|
||||
{
|
||||
myPresentation->PrevSample();
|
||||
DoSample();
|
||||
}
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnUpdateBUTTONNext(CCmdUI* pCmdUI)
|
||||
{
|
||||
pCmdUI->Enable (!myPresentation->AtLastSample());
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnUpdateBUTTONPrev(CCmdUI* pCmdUI)
|
||||
{
|
||||
pCmdUI->Enable (!myPresentation->AtFirstSample());
|
||||
}
|
||||
|
||||
void CTriangulationDoc::OnDumpView()
|
||||
{
|
||||
// save current directory and restore it on exit
|
||||
char aCurPath[MAX_PATH];
|
||||
::GetCurrentDirectory(MAX_PATH, aCurPath);
|
||||
|
||||
::SetCurrentDirectory(myLastPath);
|
||||
|
||||
CFileDialog *aDlg = new CFileDialog(false, "gif", "OCCView.gif",
|
||||
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "GIF Files (*.gif)|*.gif||", NULL);
|
||||
|
||||
int result = aDlg->DoModal();
|
||||
if ( result == IDOK)
|
||||
{
|
||||
CString aFileName = aDlg->GetFileName();
|
||||
delete aDlg;
|
||||
|
||||
POSITION pos = GetFirstViewPosition();
|
||||
while (pos != NULL)
|
||||
{
|
||||
OCC_3dView* pView = (OCC_3dView*) GetNextView(pos);
|
||||
pView->UpdateWindow();
|
||||
}
|
||||
|
||||
myViewer->InitActiveViews();
|
||||
Handle(V3d_View) aView = myViewer->ActiveView();
|
||||
char aStrFileName[MAX_PATH];
|
||||
strcpy_s(aStrFileName, aFileName);
|
||||
aView->Dump(aStrFileName);
|
||||
}
|
||||
else
|
||||
delete aDlg;
|
||||
|
||||
::GetCurrentDirectory(MAX_PATH, myLastPath);
|
||||
::SetCurrentDirectory(aCurPath);
|
||||
}
|
||||
|
||||
void CTriangulationDoc::Fit()
|
||||
{
|
||||
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
||||
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
|
||||
OCC_3dView *pView = (OCC_3dView*)pChild->GetActiveView();
|
||||
pView->FitAll();
|
||||
}
|
63
samples/mfc/standard/07_Triangulation/src/TriangulationDoc.h
Executable file
63
samples/mfc/standard/07_Triangulation/src/TriangulationDoc.h
Executable file
@@ -0,0 +1,63 @@
|
||||
// TriangulationDoc.h : interface of the CTopologyTriangulationDoc class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_TRIANGULATIONDOC_H__3045338B_3E75_11D7_8611_0060B0EE281E__INCLUDED_)
|
||||
#define AFX_TRIANGULATIONDOC_H__3045338B_3E75_11D7_8611_0060B0EE281E__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
#include <OCC_3dDoc.h>
|
||||
//#include "OCCDemo_Presentation.h"
|
||||
class OCCDemo_Presentation;
|
||||
|
||||
class CTriangulationDoc : public OCC_3dDoc
|
||||
{
|
||||
|
||||
protected: // create from serialization only
|
||||
CTriangulationDoc();
|
||||
DECLARE_DYNCREATE(CTriangulationDoc)
|
||||
void InitViewButtons();
|
||||
void DoSample();
|
||||
public:
|
||||
virtual ~CTriangulationDoc();
|
||||
void Start();
|
||||
static void Fit();
|
||||
Standard_CString GetDataDir() {return myDataDir;}
|
||||
#ifdef _DEBUG
|
||||
virtual void AssertValid() const;
|
||||
virtual void Dump(CDumpContext& dc) const;
|
||||
#endif
|
||||
|
||||
// Generated message map functions
|
||||
protected:
|
||||
//{{AFX_MSG(CTriangulationDoc)
|
||||
afx_msg void OnTriangu();
|
||||
afx_msg void OnClear();
|
||||
afx_msg void OnVisu();
|
||||
afx_msg void OnBUTTONNext();
|
||||
afx_msg void OnBUTTONStart();
|
||||
afx_msg void OnBUTTONRepeat();
|
||||
afx_msg void OnBUTTONPrev();
|
||||
afx_msg void OnBUTTONEnd();
|
||||
afx_msg void OnUpdateBUTTONNext(CCmdUI* pCmdUI);
|
||||
afx_msg void OnUpdateBUTTONPrev(CCmdUI* pCmdUI);
|
||||
afx_msg void OnFileNew();
|
||||
afx_msg void OnDumpView();
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
private:
|
||||
OCCDemo_Presentation *myPresentation;
|
||||
char myDataDir[5]; // for "Data\0"
|
||||
char myLastPath[MAX_PATH]; // directory of lastly saved file in DumpView()
|
||||
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_TRIANGULATIONDOC_H__3045338B_3E75_11D7_8611_0060B0EE281E__INCLUDED_)
|
Reference in New Issue
Block a user