几何尺寸与公差论坛------致力于产品几何量公差标准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-07, 12:36 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】reading oddb3dsolid, oddbbody decomposeforsave

reading oddb3dsolid, oddbbody decomposeforsave
reading oddb3dsolid, oddbbody decomposeforsave
dear oda users,
i have this problem for a long long time without any solution yet ....
i can't display dwg files with complex objects.
i would like to explode 3dsolid or body into someything i can display like a face array (mesh) for ex..
this would be nice.
/////////////////////////////////////////////////////
every thread about this discussion are using decomposeforsave
oddbobjectptr pnewobj = psolid->decomposeforsave(oddb::vac12, replaceid, exchangexdata);
// and next
((oddbentityptr )pnewobj)->explode(entityset);
// so you get oddbpolyfacemesh. if you use explode again you obtain oddbface . this is what i want indeed at the end > n faces
i also know the code in odamfcapp\dwgview.cpp
cdwgview:neditacisconversion()
/////////////////////////////////////////////////////
but my database is in read mode since i'm traversing it to read the file.
how can i use decomposeforsave since i don't really want to save something.
decomposeforsave returns an error since my database is not in write mode.
can i save while reading ?
must i create a copy of initial file tempory file and write inside it ?
any idea or even better code will be greatly appreciated
philippe
philippe,
i dont know if this helps, but i have created two different vectorizers, one is my outline vectorizer, the other is my shaded vectorizer.
the i store the details in a "3d object" container and use this to draw, save, intersect test, etc with.
the main reason i did it this way was for performance, i have many drawings where using the decompose for save took a very long to load the data, this version below is much faster (i suppose it is because the decompose for save is creating brand new objects etc.. but i am only guessing)
example code as belows :
note: i have copied and pasted direct out of my engine, and some items are specific to my very own objects, you will simply need to use common sense to replace these with appropriate items, or do it in a totally different way then myself. also note that since you are parsing the file yourself (which is how i have done it), that the vertices below are in there base form, ie if the 3dsolid is inside of a block, you will need to ensure the matrix manipulations are done as well, this is the reason for addpnt2ent functions, as they have the current matrix stack and will adjust the vertex to the correct location.
class vectorizer : public odgigeometrysimplifier, public odgsbasevectorizeview {
public:
vectorizer() {
};
virtual void polylineout(odint32 n, const odgepoint3d* pts);
virtual void polygonout(odint32 nbpoints, const odgepoint3d *pvertexlist, const odgevector3d *pnormal = 0);
void setgmtryent(csmplptr apgmtry) { m_apgmtry = apgmtry;};
void setldr(copendwgptr apldr) { m_apldr = apldr;};
private:
csmplptr m_apgmtry;
copendwgptr m_apldr;
};
void vectorizerlylineout(odint32 n, const odgepoint3d* pts) {
if( m_apldr.valid() && m_apgmtry.valid() ) {
m_apldr->bgnaddpnts(m_apgmtry);
const odgepoint3d *curpnt = pts;
for( int i = 0; i < n; i++ ) {
m_apldr->addpnt2ent(m_apgmtry, odgepoint3d(curpnt->x, curpnt->y, curpnt->z));
curpnt++;
}
m_apldr->endaddpnts(m_apgmtry);
}
}
void vectorizerlygonout(odint32 nbpoints, const odgepoint3d *pvertexlist, const odgevector3d *pnormal) {
if( m_apldr.valid() && m_apgmtry.valid() ) {
m_apldr->bgnaddpnts(m_apgmtry);
const odgepoint3d *curpnt = pvertexlist;
for( int i = 0; i < nbpoints; i++ ) {
m_apldr->addpnt2ent(m_apgmtry, odgepoint3d(curpnt->x, curpnt->y, curpnt->z));
curpnt++;
}
m_apldr->endaddpnts(m_apgmtry);
}
}
and i call the above with code like :
/////////////////////////////////////////////////////////////////////////////////////////
// first get the polyline representation
/////////////////////////////////////////////////////////////////////////////////////////
{
odstaticrxobject<vectorizer> dv;
dv.setgmtryent(ap3dsolid);
dv.setldr(this);
odstaticrxobject<odgicontextfordbdatabase> gicontext;
gicontext.setdatabase(od3dsolidptr->database());
dv.setdrawcontext(&dv);
dv.setcontext(&gicontext);
dv.output().setdestgeometry(dv);
dv.beginviewvectorization();
dv.draw(od3dsolidptr);
dv.endviewvectorization();
}
next i do the shaded view with :
//---------------------------------------------------------------------------------
class shadedvectorizer : public odgigeometrysimplifier, public odgsbasevectorizeview {
public:
shadedvectorizer() {
odgsbasevectorizeview::setmode(kgouraudshaded);
};
virtual void triangleout(const odint32* vertices, const odgevector3d* pnormal);
void settrisets(ctrisets *ptrisets) {m_ptrisets = ptrisets;};
void setldr(copendwgptr apldr) { m_apldr = apldr;};
private:
ctrisets *m_ptrisets;
copendwgptr m_apldr;
};
void shadedvectorizer::triangleout(const odint32* vertices, const odgevector3d* pnormal) {
const odgepoint3d *pvtces = vertexdatalist();
const odgepoint3d pv1 = pvtces[vertices[0]];
const odgepoint3d pv2 = pvtces[vertices[1]];
const odgepoint3d pv3 = pvtces[vertices[2]];
cvctr nrmls[3];
if( vertexdata() ) { // m_bisvertsnormals ) {
odgiorientationtype ornt = vertexdata()->orientationflag();
for( int i = 0; i < 3; i++ ) {
const odgevector3d *podnrml = vertexdata()->normals() + vertices[i];
switch( ornt ) {
case kodgicounterclockwise:
{
nrmls[i] = cvctr(podnrml->x, podnrml->y, podnrml->z);
}
break;
case kodgiclockwise:
{
nrmls[i] = cvctr(-podnrml->x, -podnrml->y, -podnrml->z);
}
break;
default:
{
if( vertexdata()->normals() ) {
odgevector3d normal = vertexdata()->normals()[ vertices[i] ];
if( pnormal ) {
if( normal.dotproduct(*pnormal) < 0.0) {
normal *= -1.0;
}
nrmls[i] = cvctr(normal.x, normal.y, normal.z);
}
}
}
}
}
} else if( pnormal ){
//nrmls[0] = cvctr(pnormal->x, pnormal->y, pnormal->z);
nrmls[0] = get3dnorm(cpnt(pv1.x, pv1.y, pv1.z), cpnt(pv2.x, pv2.y, pv2.z), cpnt(pv3.x, pv3.y, pv3.z));
nrmls[1] = nrmls[0];
nrmls[2] = nrmls[0];
} else {
// should do our own calc here
nrmls[0] = get3dnorm(cpnt(pv1.x, pv1.y, pv1.z), cpnt(pv2.x, pv2.y, pv2.z), cpnt(pv3.x, pv3.y, pv3.z));
nrmls[1] = nrmls[0];
nrmls[2] = nrmls[0];
}
m_apldr->addtriset(m_ptrisets, pv1, pv2, pv3, nrmls[0], nrmls[1], nrmls[2]);
}
/////////////////////////////////////////////////////////////////////////////////////////
// no get the gourade shading of the solid
/////////////////////////////////////////////////////////////////////////////////////////
{
odstaticrxobject<shadedvectorizer> dvs;
dvs.settrisets(dynamic_cast<ctrisets*>( ap3dsolid.get()) );
dvs.setldr(this);
odstaticrxobject<odgicontextfordbdatabase> gicontext;
gicontext.setdatabase(od3dsolidptr->database());
dvs.setdrawcontext(&dvs);
dvs.setcontext(&gicontext);
dvs.output().setdestgeometry(dvs);
dvs.beginviewvectorization();
dvs.draw(od3dsolidptr);
dvs.endviewvectorization();
}
hope this helps
cheers
jason
last edited by janderssen; 29th march 2007 at 06:50 pmfff">.

very nice! i've been looking for a small piece of code like this.
but one problem remains for me:
i only get polyline representations out of my database. if i use the shadedvectorizer simply nothing is returned.
i really need those vertices in modelspace coordinates as i have to import the geometry to my own mesh format.
1) did you setup some view options except the gouraudshading?
2) did you supply specific transformation matrices for world2eye etc?
any hints are appreciated.
p.s. i've played around with the exvectorizer ... same problem here. i guess it's related to the layout chosen.
where do we set mode (odgsview::kgouraudshaded) ???
janderssen,
thanks for your help. with your help and \msvc6\examples\odvectorizeex\odvectorizeex.dsp
i finally find a solution to get faces but i don't know why one code fails and one succeed :
this code wil output polyline
odgsviewptr exgssimpledevice::createview(const odgsclientviewinfo* pinfo, bool benablelayervisibilityperview)
{
odgsviewptr pview = exsimpleview::createobject();
exsimpleview* pmyview = static_cast<exsimpleview*>(pview.get());
pmyview->setmode(odgsview::kgouraudshaded);
...
}
this code works will output faces :
void exsimpleview::draw(const odgidrawable* pdrawable)
{
...
odgsbasevectorizeview::setmode(kgouraudshaded);
odgsbasevectorizeview::draw(pdrawable);
..
}
phillipe,
sorry for the delay, i have just returned from holidays.
my shaded vectorizer is as follows :
//---------------------------------------------------------------------------------
class shadedvectorizer : public odgigeometrysimplifier, public odgsbasevectorizeview {
public:
shadedvectorizer() {
odgsbasevectorizeview::setmode(kgouraudshaded);
};
virtual void triangleout(const odint32* vertices, const odgevector3d* pnormal);
void settrisets(ctrisets *ptrisets) {m_ptrisets = ptrisets;};
void setldr(copendwgptr apldr) { m_apldr = apldr;};
private:
ctrisets *m_ptrisets;
copendwgptr m_apldr;
};
take note of the setmode call in the constructor.
hope this helps
cheers
jason
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】problem with decomposeforsave for an oddbbody entity yang686526 DirectDWG 0 2009-05-06 11:11 PM
【转帖】oddbregion and oddb3dsolid yang686526 DirectDWG 0 2009-05-06 08:09 PM
【转帖】oddb3dsolid-rotate-move yang686526 DirectDWG 0 2009-05-06 07:20 PM
【转帖】getgeomextents of oddbbody yang686526 DirectDWG 0 2009-05-05 11:22 AM
【转帖】get extents for oddb3dsolid yang686526 DirectDWG 0 2009-05-05 11:15 AM


所有的时间均为北京时间。 现在的时间是 11:16 PM.


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