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

rendering paperspace viewports
rendering paperspace viewports
hi,
i need to render an autocad database.
we're using an opengl based rendering library, called openinventor.
it's an object-oriented c++ toolkit and encapsulates almost all the opengl lowlevel functions into classes.
i've inherited all the needed odgs and odgi classes and rendering is great (a great work from opendwg guys). the problem now is in viewport rendering.
may be it is someone from opendwg alliance who can help me a little:
1. i override pushclipboundary(), but it seems that it is not called at all.
it is placed in the odgsbaseview-inherited class. all other overriden methods like polyline() or pushmodeltransform() are called ok.
i saw that a new odgsbaseview is created for the paperspace viewport.
how can i retreive the model-paper matrix and clip geometry - shall i use oddbviewport directly?
2. if i succeed in getting the matrix and clip geometry, how should i perform the actual trim. i can found nowhere in openinventor how to create a clip boundary needed to render the paperspace viewport. in opengl there is a glscissor() function, but it can trim only rectangles.
in the gdi based rendering you use odgsbaseview::m_nrcpoints and the wingdi clipping regions. but i think it cannot be used in opengl rendering context (or it can?). can you please provide some direction of how you have implemented it in the opengl based device?
of course the evident way is to trim manually, which for polyline() overridable is easy, but for shell() and polygon() (filled) brings quite nasty calculations...
thank you very much in advance for any help.
regards
chudomir
hi chudomir,
1. pushclipboundary() is called by oddbblockreference::worlddraw() if block has a spatial filter (xclip).
2. our opengl device uses glviewport() to specify ps viewports. in addition it uses gl's stencil operations (glstencilxxx()) to specify viewport non-rect clipping boundary from odgsbaseview::m_nrcpoints (if the one exists).
dmitry.
thank you very much, dmitry!
i'll try the stencils.
regards
chudomir
hi,
can someone please help me with these:
1. i need to recieve the model to paper space transform to be applied to modelspace objects seen through a paperspace viewport. is there a suitable method or i should provide my own?
2. how to receive the actual clipping geometry (as a polyline) - odgsbaseview::m_nrcpoints() seems to be empty when i try to read it.
3. when the upper 2 items must be queried for? i suppose just before calling odgsbaseview::update(); - is there another point where they should return any suitable values?
thanks in advance for any help!
as to the transformation to and from model-paper, i have a source from one of the former autocad knowledge databases. anyway i would use the one provided by dwgdirect, if such exists.
regards
chudomir
hi,
1. it seems there is no way to receive the model to paper space transform from dd's (or acad's) gs interface, however you still can obtain it inside of yourgsview::update() in case it "knows" characteristics of gsview that represents overall viewport. gs views are not related to each other so to implement logical relation of model views to paper one dd framework recalculates viewport of each gsview ( odgsview::setviewport(const odgsdcrect& screen_rect) ) on every call to gsdevice::update(). so model to paper relation is stored in dd's framework and applied to gsviews representing ms in device coordinates. i just wondered if you really needed this transformation...
2. you should override odgsview::setviewportclipregion() to receive the actual clipping geometry (implementation of odgsbaseview::setviewportclipregion() just stores received data in m_nrcpoints).
dmitry.
thank you for your reply, dmitry.
here is what i have now. you can see on the attached jpg 3 items:
first 2 are the model and a paper space in autocad, and the 3rd one is my result. the model space contents is drawn in a separate view object - as if it was in the model space, but in paperspace coordinates. i thought i can just push the suitable model-paper matrix and the model entities to be "adjusted" as if seen through the viewport. then will come the clipping.
if i have more than one viewports then i have duplicated the drawables, so again pushing different matrices before them would produce the expected result.
regards
chudomir
attached images (23.4 kb, 53 views)

here is the transaltion between model and paper space - hope someone can find it useful:
code:
// this code is taken from the acad knowledge database
// the result matrix can be used to find a modelspace coordinate as looked in the paperspace
// is we transform a line from the model space with this matrix and
// adds a transformed line in the paper space then it should appear as looked from the viewport (hopefully!)
void ms2ps( oddbviewportptr pvp, odgematrix3d &resultmat) {
// first get all the data
odgevector3d viewdirection = pvp->viewdirection();
odgepoint2d centre2d = pvp->viewcenter();
odgepoint3d viewcenter = odgepoint3d( centre2d.x, centre2d.y, 0);
odgepoint3d viewtarget = pvp->viewtarget ();
double twistangle = -pvp->twistangle();
odgepoint3d centerpoint = pvp->centerpoint();
double viewheight = pvp->viewheight();
double height = pvp->height();
double width = pvp->width();
double scaling = viewheight / height;
double lenslength = pvp->lenslength();
// prepare the transformation
odgevector3d xaxis, yaxis, zaxis;
zaxis = viewdirection.normal();
xaxis = odgevector3d::kzaxis.crossproduct( viewdirection );
if( !xaxis.iszerolength() ) {
xaxis.normalize();
yaxis = zaxis.crossproduct( xaxis );
} else if( zaxis.z < 0 ) {
xaxis = -odgevector3d::kxaxis;
yaxis = odgevector3d::kyaxis;
zaxis = -odgevector3d::kzaxis;
} else {
xaxis = odgevector3d::kxaxis;
yaxis = odgevector3d::kyaxis;
zaxis = odgevector3d::kzaxis;
}
odgematrix3d dcs2wcs; // display coordinate system (dcs) to world coordinate system (wcs)
odgematrix3d ps2dcs; // paperspace to dcs
// first initialise with a transformation to centerpoint
ps2dcs = odgematrix3d::translation( odgepoint3d::korigin - centerpoint );
// then scale for the view
//ch_101102 viewcenter was placed by me; previous was centerpoint. and didn't work at all
ps2dcs = ps2dcs * odgematrix3d::scaling( scaling, centerpoint/*viewcenter*/ );
// then adjust to the viewcenter
dcs2wcs = odgematrix3d::translation( viewcenter - odgepoint3d::korigin );
// then transform for the view direction
odgematrix3d matcoords;
matcoords.setcoordsystem( odgepoint3d::korigin, xaxis, yaxis, zaxis);
dcs2wcs = matcoords * dcs2wcs;
// then adjust for the viewtarget
dcs2wcs = odgematrix3d::translation( viewtarget - odgepoint3d::korigin ) * dcs2wcs;
// then the twist angle
dcs2wcs = odgematrix3d::rotation(twistangle, zaxis, viewtarget ) * dcs2wcs;
odgematrix3d perspmat;
if( pvp->isperspectiveon()) {
// we do special perspective handling
double viewsize = viewheight;
double aspectratio = width / height;
double adjustfactor = 1.0 / 42.0;
double adjustedlenslength = viewsize * lenslength * sqrt ( 1.0 +
aspectratio * aspectratio ) * adjustfactor;
double eyedistance = viewdirection.length();
double lensdistance = eyedistance - adjustedlenslength;

double ed = eyedistance;
double ll = adjustedlenslength;
double l = lensdistance;
perspmat.entry[2][2] = (ll - l ) / ll;
perspmat.entry[2][3] = l * ( ed - ll ) / ll;
perspmat.entry[3][2] = -1.0 / ll;
perspmat.entry[3][3] = ed / ll;

}
resultmat = ps2dcs.inverse() * perspmat * dcs2wcs.inverse();
}
// it gets a viewport and returns a transformation matrix,
// with which we can move a paperspace coordinate to the model space
// as looked from the given viewport
void ps2ms ( oddbviewportptr pvp, odgematrix3d &resultmat ) {
// keep life simple, just invert the other way
odgematrix3d mat;
ms2ps( pvp, mat );
resultmat = mat.inverse();
}
actually this code is from an application, that still works with dwgdriect 1.05. i'm not sure whether the matrix class had some changes and now keeps the transaltion at the right instead of bottom, etc.
anyway i'll convert it to the new one in the very near future.
also the attached file contains some very useful topics from the former adesk knowledge database. it was off for free access for some time. i don't know whether it is accessible now.
regards
chudomir
attached files (255.8 kb, 54 views)

hi,
how can i understand whether i'm rendering a paperspace viewport while in the body of the inherited mehtod odgsbaseview::update()?
viewportid() or viewportobjectid() seems to return always zero.
thanks in advnace for any help.
regards
chudomir
is there a way to setviewportmatrix() ??
i'm looking for a way to scale a viewport differently on x- and y-axises
thanks for any help
i don't know whether it will work ok, but you can try with pushmodeltransform() and pass a non-uniformly scale matrix.
best regards
chudomir
indirectly i can manipulate the viewport transformation matrix using
for scale:
oddbviewport::setheight() //height on paper
oddbviewport::setviewheight() //logical height
for center (logical coordinate in the view center):
oddbviewport::setcenterpoint() //center on paper
oddbviewport::setviewcenter() //logical center of view
for rotation:
oddbviewport::settwistangle()
these function a very convinient. probably they manipulate a viewmatrix, and i wonder if this matrix is to be found somewhere. now i found your method to get this matrix - question is if there's a way to set it?
last edited by jesper; 11th january 2005 at 02:24 amfff">.

jesper, you can't set to oddbviewport parameters that corresponds to viewing matrix with non-uniform scale.
in dxf and dwg file for oddbviewport these parameters of viewing matrix are stored:
1) center, width and height in paperspace units.
2) height in modelspace units
3) view target, direction and twist angle.
there are no way to fit non-uniform transform here, since neither width in modelspace units, nor axes of viewing matrix are stored.
sincerely yours,
george udov
okay, thanks alot. i must find another way to draw my profile (xy-graph) then. i have a profile graph in modelspace spanning 15 km on x-axis but only a few hundred meters on y-axis. therefor i was planning on scaling x- and y- axises differently to be able to zoom all, in both x- and y-direction.
i must find another way to do this, but i guess this is not a dwgdirect issue, rather a acad issue on how to achieve this.

also please note that you still can use dwgdirect rendering to perform non-uniform scale. you can pushmodeltransform before vectorization of necessary view (e. g. in override of update() method), and popmodeltransform() after vectorization, as chudomir advised.
but you can't store such transform in dwg/dxf file (viewport entity) in way, compatible with autocad.
sincerely yours,
george udov
autocad compartible way to achieve it can be block refererence with non-iniform scale (and the geometry is inside block definition). this also can be xref block - reference to another drawing if you want to keep source data unchanged.
sergey slezkin
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】problem with erasing paperspace viewports yang686526 DirectDWG 0 2009-05-06 11:16 PM
【转帖】paperspace, viewport,layout or ... problem yang686526 DirectDWG 0 2009-05-06 09:40 PM
【转帖】paperspace with multiple viewports using odvectorizee yang686526 DirectDWG 0 2009-05-06 09:40 PM
【转帖】paperspace viewport custom scale yang686526 DirectDWG 0 2009-05-06 09:39 PM
【转帖】modelspace entities also drawn in paperspace yang686526 DirectDWG 0 2009-05-06 06:00 PM


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


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