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


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-05-06, 04:00 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】integrating dwg with open scene graph

integrating dwg with open scene graph
integrating dwg with open scene graph
hi there !
i'm completely new to dwg format, but i've been working a lot with the open scene graph library (basically a scene graph to display 3d worlds with opengl).
i'm trying to build a "dwg" plugin to access this kind of data directly in my software... (awfully intricate task for me :-( ).
i'm successfully "importing" some dwg files using a vectorization process... but as i have very little knowledge on the dwg database handling i'm facing strange behaviors :
in fact, i have multiple problems:
1) when i load a file and vectorize the entities, some of them appear correctly, but others are just missing : i have some "acdbblockreference", from which i retrieve a "acdbblocktablerecord" containing no entities at all... is this possible/normal ?
do i have to do something to access all the entities in the database (even if they are invisible/desactivated/hidden/ etc... (?)) ? could this be linked to the layer handling system in dwg files ? (i don't know anything about those layers lol).
2) for some entities (acdb3dsolid), i'm building a 3d objects using the results from a "entity->worlddraw(wd)" call (where "wd" is my "odgiworlddraw" derived class): i end in a call of the shell() function of my "odgiworldgeometry" derived class :
the code is :
void odgiworldgeometrydumper::shell(odint32 numvertices,
const odgepoint3d* vertexlist,
odint32 facelistsize,
const odint32* facelist,
const odgiedgedata* pedgedata,
const odgifacedata* pfacedata,
const odgivertexdata* pvertexdata)
{
osg::geode* geode = new osg::geode;
osg::geometry* geom = new osg::geometry;
osg::vec3array* vertices = new osg::vec3array();
osg::vec3array* normals = new osg::vec3array();
osg::vec4array* colors = new osg::vec4array();
geom->setvertexarray(vertices);
for(int f=0; f< facelistsize {
// pour chaque face on ajoute les vertices, et les normales:
int numverts = facelist[f++];
for(int v =0; v <abs(numverts); ++v) {
int id = facelist[f++];
vertices->push_back(converttovec3d(vertexlist[id]));
if(pfacedata && pfacedata->normals()) {
osg::vec3d n = converttovec3d(pfacedata->normals()[id]);
normals->push_back(forcevalidnormal(n));
}
if(pvertexdata && pvertexdata->normals()) {
osg::vec3d n = converttovec3d(pvertexdata->normals()[id]);
normals->push_back(forcevalidnormal(n));
}
if(pvertexdata && pvertexdata->truecolors()) {
colors->push_back(converttovec4d(pvertexdata->truecolors()[id]));
}
}
}
geom->setnormalarray(normals);
geom->setnormalbinding(osg::geometry::bind_per_vertex );
if(normals->empty()) {
normals->push_back(osg::vec3d(0,0,1));
geom->setnormalbinding(osg::geometry::bind_overall);
osg::notify(osg::notice) << "didn't find vertices normals in shell vectorization.\n";
}
if(!colors->empty()) {
geom->setcolorarray(colors);
geom->setcolorbinding(osg::geometry::bind_per_vertex) ;
osg::notify(osg::notice) << "adding vertices colors in shell vectorization.\n";
}
geom->addprimitiveset(new osg:rawarrays(osg:rimitiveset::triangles,0,ver tices->getnumelements()));
geode->adddrawable(geom);
dwgconverter::instance()->setcurrentnode(geode);
}
in this code i try to read the normals from the pvertexdata or pfacedata... : it seems to me that sometimes one is present when the other is not (how is this possible ?!)... and may i consider that when both are valid, the same normals values are obtained ?
any way, the major problem here is that i have some invalid normals for some calls to this function !!! for example i found things like:
found invalid normal: (6.2654e-294, -1.#qnan, 2.41908e-312)
found invalid normal: (-1.#qnan, -1.#qnan, 4.24399e-314)
found invalid normal: (6.2654e-294, -1.#qnan, 2.41908e-312)
found invalid normal: (-1.37524, 4.69823e-294, -1.#qnan)
found invalid normal: (-1.37524, 4.69823e-294, -1.#qnan)
found invalid normal: (0, 0, 0)
found invalid normal: (4.69856e-294, -1.#qnan, 1.6976e-312)
found invalid normal: (0, 0, 0)
found invalid normal: (6.06878e-294, -1.#qnan, 6.59516e-311)
how is this possible ?? apparently those normals are not initialized or even set to (0,0,0)... snif...
3) sometimes if i simply change a small output text, then i don't have the same import results ! am i facing a threding issue here ?
my conversion process is simple, but maybe i'm doing something wrong :
here is the whole code i use:
a- main entry :
oddbdatabaseptr pdb = svcs.readfile(file.c_str(), true, false, oda::ksharedenyno);
if (!pdb.isnull())
{
osg::notify(osg::info) << "database loaded.\n";
osg::notify(osg::info) << "\nfile version: " << pdb->originalfileversion() << "\n";
dwgconverter* dwg = dwgconverter::instance(pdb);
osg::ref_ptr<osg::group> root = dwg->getparent();
oddbblocktableptr ptable = pdb->getblocktableid().safeopenobject();
osg::notify(osg::info) << "blocktable description: " << ptable->desc()->name() << "\n";
oddbsymboltableiteratorptr pblkiter = ptable->newiterator();
for (pblkiter->start(); ! pblkiter->done(); pblkiter->step())
{
oddbblocktablerecordptr pblock = pblkiter->getrecordid().safeopenobject();
dwg->convert(pblock);
}
if(root->getnumchildren())
return root.release();
}
}
catch(oderror& e)
{
osg::notify(osg::fatal) << "\ndwgdirect error: " << svcs.geterrordescription(e.code()) << "\n";
}
catch (...)
{
osg::notify(osg::fatal) << "\nunknown error.\n";
}
b - the dwgconverter constructor:
dwgconverter:wgconverter(oddbdatabase* db)
: ctx(db) // ctx is a "odgicontextdumper" object (found in the odreadex sample)
, wd(0) // wd is a "odgiworlddrawdumper" object
{
wd.setcontext(&ctx);
parent = new osg::group;
}
c - the dwgconverter::convert(oddbblocktablerecordptr&) function:
void dwgconverter::convert(oddbblocktablerecordptr& pblock)
{
odprintconsolestring(dd_t("blockrecord description: %s\n"),pblock->desc()->name().c_str());
oddbobjectiteratorptr pentiter = pblock->newiterator();
int count = 0;
int good = 0;
osg::node* node;
for (; !pentiter->done(); pentiter->step())
{
oddbentityptr pent = pentiter->objectid().safeopenobject();
odprintconsolestring(dd_t("starting convertion of %s\n"),pent->isa()->name().c_str());
if((node = convert(pent)) || pent->isa()->name() == "acdbattributedefinition") {
if(node)
parent->addchild(node);
good++;
odprintconsolestring(dd_t("success for %s!\n"),pent->isa()->name().c_str());
}
else {
odprintconsolestring(dd_t("failure for %s!\n"),pent->isa()->name().c_str());
}
odprintconsolestring(dd_t("convertion of %s done.\n"),pent->isa()->name().c_str());
count++;
}
odprintconsolestring(dd_t("blocktablerecord done (%d on %d items done)\n"),good,count);
}
and finally:
d - the dwgconverter::convert(oddbentityptr&) function:
inline osg::node* convert(oddbentityptr& pent)
{
currentnode = null;
pent->worlddraw(&wd);
return currentnode.get();
}
... you see, its really not that complicated, and so i really don't see where those errors may come from... please someone help me !! :-(
regards,
emmanuel.
1. blocktablerecord can be empty but the reasons why entities are not vectorized may be different:
- odvectorizeex sample uses current view of active layout. other layouts are not vectorized. entities are clipped by view borders. entities outside of current view are not vectorized.
- blockreference can have spatial filter (clip applied to the block reference entity).
- enities on "off" layers are not vectorized.
- entities on layers "frozen" in current viewport are not vectorized.
2. normals can be specified per vertex (one normal per each vertex) or per face (one normal per each face). surely they are not the same and even their number is different (number of faces or number of normals).
face data contains number of elements equal to number of faces.
vertex data contains number of elements equal to number of vertices.
you simply access memory ouside of valid data using vertex index to access face data. (cube has 8 vertices and 6 faces).
btw, maybe looking into implementation of shell() primitive in our opengl or directx devices (availble with sources) would be helpful.
sergey slezkin
hi again !
thanks for this quite answer :-)
concerning the point 1)
- if a blocktablerecord has some "frozen" or "off" entities, will they still be found when i use an interator ? ("block->newiterator()")
- in fact i'm not using the vectorization framework as in the odvectorizeex sample : as i'm using the worlddraw() function directly, correct me if i'm wrong but i should have a viewport independant vectorization result, no ?
concerning the point 2): thanks !! it's probably an out of bound access indead :-).
i'm giving a look at the opengl device sample, thanks for the advise !
manu.
it's me again:
sorry but i can't find the definition i would need for the shell() function sample in opengl device :-( i have :
void odgsopenglvectorizeview::shell(odint32 nvertices,
const odgepoint3d* vertexlist,
odint32 facelistsize,
const odint32* facelist,
const odgiedgedata* edgedata,
const odgifacedata* facedata,
const odgivertexdata* vertexdata)
{
bool bbackfacesdiscarded = false;
if(device()->discardbackfaces() && mode() >= kflatshaded &&
((facedata && facedata->normals()) || (vertexdata && vertexdata->normals())) )
{
// ::gllightmodeli(gl_light_model_two_side, gl_false);
::glenable(gl_cull_face);
::glcullface(gl_back);
bbackfacesdiscarded = true;
}
odgsbasevectorizeview::shell(nvertices, vertexlist, facelistsize, facelist, edgedata, facedata, vertexdata);
if(bbackfacesdiscarded)
{
// ::gllightmodeli(gl_light_model_two_side, gl_true);
::gldisable(gl_cull_face);
}
}
but i don't have the source for :
odgsbasevectorizeview::shell(nvertices, vertexlist, facelistsize, facelist, edgedata, facedata, vertexdata);
i guess this means i don't access to the sources you're speaking about...
manu.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】error open dwg file yang686526 DirectDWG 0 2009-05-05 09:43 AM
【转帖】dwg extension in world coordinates yang686526 DirectDWG 0 2009-05-05 08:01 AM
【转帖】dwg doesnt open 9 use oddbmleader 0 yang686526 DirectDWG 0 2009-05-05 08:01 AM
【转帖】cannot open a dwg file in autocad - random problem yang686526 DirectDWG 0 2009-05-04 05:28 PM
【转帖】[求助]请求编程,查询符合要求条件的dwg文件 yang686526 数据库ObjectDBX 0 2009-04-19 05:36 PM


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


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