几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 合作项目区 » CAD自主知识产权开发 » Open CASCADE
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2007-06-06, 10:43 AM   #1
yogy
高级会员
 
注册日期: 06-11
帖子: 1527
精华: 15
现金: 6353 标准币
资产: 6353 标准币
yogy 向着好的方向发展
默认 【转帖】如何在导入文件时获得零件尺寸

如何在导入文件时获得零件尺寸

上次不知道,去OCC的论坛上发帖问了,有人给了比较详细的回答,现在整理出来,希望对大家有用
The codes in red is the implemented methods.


There are 3 ways to retrieve the dimensions of the imported part.

Method 1, Interate the shape with the TopExp_Explorer to get what your want, and then down cast to get the underlying curve (BRep_Tool::Curve). Then, based on the underlying geometry of the curve, you can get the appropriate dimensions.
For example: To retrieve the dimension of the shape constructed by myself to test the method, and refering to the imported shape, the step is the same.
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <Geom_Circle.hxx>
#include <gp_Circ.hxx>
void COCCVIewer3DDoc::OnCylinder()
{
// TODO: Add your command handler code here
myAISContext->CloseAllContexts();
BRepPrimAPI_MakeCylinder C(20.,20,1.5*PI);
Handle(AIS_Shape) aCylinder=new AIS_Shape(C.Shape());
myAISContext->Display(aCylinder);
FitAll(-1);
CString s;
TopExp_Explorer ex(C.Shape(),TopAbs_EDGE);
for(ex.Current();ex.More();ex.Next())
{
Standard_Real first,last;
Handle_Geom_Curve Cur=BRep_Tool::Curve(TopoDS::Edge(ex.Current()),first,last);
Handle(Standard_Type) curveType=Cur->DynamicType();
if(curveType==STANDARD_TYPE(Geom_Circle))
{
Handle(Geom_Circle) acircle=Handle(Geom_Circle)::DownCast(Cur);
gp_Circ circData=acircle->Circ();
Standard_Real radius=circData.Radius();
CString s1;
s1.Format("%f ",radius);
s+=s1;
}
CString s2f;
s2f.Format("%f,%f",first,last);s+=s2f;
s+="\n";
}
AfxMessageBox(s);
}
You would have to do similar things for the different types of curves you might encounter.

Method 2 , you can get the extents of an object in the global X,Y,and Z directions by using Bnd_Box and BRepBndLib, this method is only useful to retrieve the box's dimension.
eg:
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <TopExp_Explorer.hxx>
#include <ChFi3d_FilletShape.hxx>
#include <BRepBndLib.hxx>
void COCCVIewer3DDoc::OnBox()
{
// TODO: Add your command handler code here
myAISContext->CloseAllContexts();
TopoDS_Solid box=BRepPrimAPI_MakeBox (gp_Pnt(0.0,.0,.0),200.,150.,100.);
TopExp_Explorer ex(box,TopAbs_EDGE);
BRepFilletAPI_MakeFillet MF(box);
while (ex.More())
{
MF.Add(10,TopoDS::Edge(ex.Current()));
ex.Next();
}
Handle(AIS_Shape) aBox=new AIS_Shape(MF.Shape());
myAISContext->SetMaterial (aBox, Graphic3d_NOM_GOLD, Standard_False);
myAISContext->SetDisplayMode (aBox, 1, Standard_False);
myAISContext->Display(aBox);

TopoDS_Solid box2=BRepPrimAPI_MakeBox (gp_Pnt(200.0,200.0,100.0),200.,200.,200.);
BRepFilletAPI_MakeFillet Rake(box2);
ex.Init(box2,TopAbs_EDGE);
ChFi3d_FilletShape Fsh=ChFi3d_Rational;
Rake.SetFilletShape(Fsh);
Rake.Add(8,50,TopoDS::Edge(ex.Current()));
Handle(AIS_Shape) aBox2=new AIS_Shape(Rake.Shape());
myAISContext->SetMaterial (aBox2, Graphic3d_NOM_BRONZE, Standard_False);
myAISContext->SetDisplayMode (aBox2, 1, Standard_False);
myAISContext->Display(aBox2);
FitAll(-1);
Bnd_Box bounds;
BRepBndLib::Add(MF.Shape(),bounds);
bounds.SetGap(0.0);
Standard_Real xmin,ymin,zmin,xmax,ymax,zmax;
bounds.Get(xmin,ymin,zmin,xmax,ymax,zmax);
CString s;
s.Format("%f,%f,%f",xmax-xmin,ymax-ymin,zmax-zmin);
AfxMessageBox(s);
}

Method 3, you can always look at vertices and calculate distances from those.
NOTE: This method I am still trying to make it work. There are a lot of problems to solve. Hope someone can join me to let this happen.
yogy离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 05:37 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多