|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Tue Dec 29, 2009 12:30 pm Post subject: Using DRAW_FILLED_POLYGON@ to plot a mesh |
|
|
Background: I work on a finite element program for rotating electrical machines. All the code is in Fotran. In the past I used Matlab for the graphics. At present I started with Clearwin (all new to me). The first thing to plot is the polygons used by the mesher and then later the mesh itself.
In the help I found an example (with some modification) to plot the mesh. For plotting the polygons/mesh it is necessary
(a) to do some axis transformation since (1,1) is top left in the window
(b) define som factor to get the axis ratio correct.
Question: If anyone has an working example of using DRAW_FILLED_POLYGON@ and some automatic axis tranformation this would be very helpful. SIMDEM will defininately work. However, I am still playing around with it (unfortunately the learning curve is not so easy as advertised). I would appreciate some tipps
Code: | WINAPP
INTEGER i,winio@
EXTERNAL fill_cb,start_cb
i=winio@('%ww[no_border,no_maxminbox]&')
i=winio@('%sy[3d_depressed]&')
i=winio@('%^gr[black,rgb_colours]&',600,600,start_cb)
i=winio@('%sc',start_cb)
END
c------------------------------------------------------------
INTEGER FUNCTION start_cb()
INCLUDE <clearwin.ins>
INTEGER x,y,d,f,red,green,black,amber,white,colour,a
integer nseg_pol,i,nspnts_pol,nstype_pol,j
INTEGER i,white,ix(50),iy(50),n,icol
double precision x_ply(50),y_ply(50),xmax,ymin
integer iu
CALL get_mouse_info@(x,y,d)
CALL get_rgb_value@(x,y,colour)
red= get_matched_colour@(RGB@(255,0,0))
green=get_matched_colour@(RGB@(0,255,0))
amber=get_matched_colour@(RGB@(255,168,0))
white=get_matched_colour@(RGB@(200,200,200))
black=0
C READ THE FILE CONTAINING THE POLYGON INFORMATION
C Determine the min/max values for x and y
iu = 99
open(unit=iu,FILE='aa.pol')
rewind iu
read (iu,*) nseg_pol
xmin = 0.0
ymax = 0.0
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
read (iu,*) x_ply(j),y_ply(j)
if (x_ply(j)<xmin) then
xmin = x_ply(j)
endif
if (y_ply(j)>ymax) then
ymax = y_ply(j)
endif
end do
end do
C Now plot the data
rewind iu
read (iu,*) nseg_pol
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
read (iu,*) x_ply(j),y_ply(j)
ix(j) = abs(x_ply(j)/xmin)*600
iy(j) = abs(y_ply(j)/xmin)*600
end do
IF(nstype_pol.EQ.250)THEN
f=red
ELSEIF(nstype_pol.EQ.201)THEN
f=amber
ELSEIF(nstype_pol.eq.0)THEN
f=green
ELSE
f=black
ENDIF
call DRAW_FILLED_POLYGON@(ix,iy,nspnts_pol,f)
end do
close(unit=iu)
start_cb=1
END | An example of a polygon file is as follows:
Code: | 2
3 250 2
-0.129912310687 7.500490754584E-02
-0.132363215957 7.641993836383E-02
-0.135452629966 7.098673400850E-02
3 250 3
-0.132363215957 7.641993836383E-02
-0.134814121228 7.783496918180E-02
-0.137867949246 7.238121924504E-02 |
|
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Tue Dec 29, 2009 9:42 pm Post subject: |
|
|
Lots of people have been here before you. Problem 1 is that the screen coordinates are in pixels, and your nodes have coordinates in real units. Problem 2 is that the screen pixels are numbered down from the top. Problem 3 is the scaling to see what you want on the screen.
My take on this is to evaluate the scale I want. I then do the scaling, conversion to integer and reversal of y coordinate direction using 2 statement functions:
Code: | C STATEMENT FUNCTIONS
C -------------------
C
C ... The next two lines are "statement functions" - these are
C internal to this subroutine, and are put inline when
C required.
C
IPOSX(XX) = (XX-P2X)/SCRN_SCALE+IXRES/2
IPOSY(YY) = IYRES/2-(YY-P2Y)/SCRN_SCALE |
IXRES and IYRES are the size of screen obtained from calls to (say CLEARWIN_INFO) with 'graphics_width' and 'graphics_depth' specified. Remember to adjust IXRES and IYRES to never be smaller than 1, to cope with an attempt by a user to resize the graphics area out of existence and force resizing. (A screen dimension of 0 will cause a scaling error!)
SCRN_SCALE is my scaling function to adjust the maximum real-world x and y to fit on the screen, P2X and P2Y are the real world coords of the centre of the object with the current view port on to it.
If your objects are 3D, then the triangles you want to plot will also need to be mapped into the 2D frame normal to the line of sight you want. That is a matter of building a transformation matrix to rotate and shift everything. However, your file looks more like a planar problem to me.
Centering the plot makes it behave more naturally if the user resizes the window.
Regards
Eddie |
|
Back to top |
|
|
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Wed Dec 30, 2009 12:24 pm Post subject: |
|
|
Eddie, thanks for your approach to this. We use 2D FEA and therefore this should be very easy. My JAVA colleague recently wanted to plot the mesh (I only provide the number chrunching part of the software) and got stuck with the same issue. I wanted show of with Fortran but without examples it is not that easy to get the graphics done.
It seems like using Clearwin is one solution to solve this. From another thread I read about the simpleplot manuals (and downloaded it). It seems to be much easier to use the simpleplot functions than writing everthing using only Clearwin (is this correct?).
Below is my new attempt to plot the polygons. Seems to work fine. I still have to figure out the axes settings!
Code: | winapp
PROGRAM VIS01
REAL Z(50,50) ! 2-d user matrix
real x_ply(50),y_ply(50),xarr(50),yarr(50)
INTEGER I,J,IU
C
CALL VSVRTP(0.0,0.0,90.0)
CALL VSNEW ! ViSualization NEW picture
Z = 0.0
C
iu = 99
open(unit=iu,FILE='aa.pol')
rewind iu
read (iu,*) nseg_pol
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
read (iu,*) x_ply(j),y_ply(j)
xarr(j)=x_ply(j)*4.0
yarr(j)=y_ply(j)*4.0
end do
CALL VSPGFL(xarr, yarr, Z, nspnts_pol)
end do
CALL VSOUT ! ViSualization OUTput
close(unit=iu)
CALL ENDPLT ! Close SIMPLEPLOT
END |
|
|
Back to top |
|
|
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Thu Dec 31, 2009 10:18 am Post subject: |
|
|
I finally got some (quick and dirty) solution to plot the polygons using simpleplot. With this I can check the FEA model. Each material type has its own colour. This means one can also check to see if the material data are correct.
For this solution I used simpleplot. However, on the long term I would like to use Clearwin/OpenGL. Unfortunately I have to start from scratch. I would be pleased to have an example in Clearwin which produce the same result as the simpleplot solution.
If I have something I can change/improve it. With nothing in the hand I can do nothing. I have worked through a few examples in the documentation but could not find anything that work (without using unsatisfactory methods).
Code: | winapp
PROGRAM VIS01
REAL Z(50,50) ! 2-d user matrix
real x_ply(50),y_ply(50),xarr(50),yarr(50)
INTEGER I,J,IU,IBLUE
C
CALL VS3DLM(-0.215, 0.115, 0.0, 0.215, -1.0, 1.0)
CALL VSVRTP(0.0,0.0,90.0)
CALL VSFULL(0)
CALL VSLBOX(1)
CALL VSNEW ! ViSualization NEW picture
CALL VSCRGB(IBLUE, 1.0, 1.0, 0.0)
CALL VSFILC(14)
Z = 0.0
C
iu = 99
open(unit=iu,FILE='ad.pol')
rewind iu
read (iu,*) nseg_pol
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
read (iu,*) x_ply(j),y_ply(j)
xarr(j)=x_ply(j)
yarr(j)=y_ply(j)
end do
if (nstype_pol == 0) CALL VSFILC(13)
if (nstype_pol == 1) CALL VSFILC(1)
if (nstype_pol == 2) CALL VSFILC(2)
if (nstype_pol == 3) CALL VSFILC(3)
if (nstype_pol == 8) CALL VSFILC(4)
if (nstype_pol == 5) CALL VSFILC(5)
if (nstype_pol == -1) CALL VSFILC(6)
if (nstype_pol == -2) CALL VSFILC(7)
if (nstype_pol == -3) CALL VSFILC(8)
if (nstype_pol == -8) CALL VSFILC(9)
if (nstype_pol == -5) CALL VSFILC(10)
if (nstype_pol == 10) CALL VSFILC(9)
if (nstype_pol == -10) CALL VSFILC(10)
if (nstype_pol == 201) CALL VSFILC(11)
if (nstype_pol == 250) CALL VSFILC(12)
CALL VSPGFL(xarr, yarr, Z, nspnts_pol)
end do
CALL VSOUT ! ViSualization OUTput
close(unit=iu)
CALL ENDPLT ! Close SIMPLEPLOT
END |
|
|
Back to top |
|
|
Smib
Joined: 26 Apr 2009 Posts: 22 Location: Melbourne
|
Posted: Sat Jan 02, 2010 7:58 am Post subject: Using DRAW_FILLED_POLYGON@ to plot a mesh |
|
|
Attached are extracts of code I have used for thsi problem
Code: | isdepth=clearwin_info@('screen_depth')
iswidth=clearwin_info@('screen_width')
.
.
.
.
xsize=(297.)*2.1*float(iswidth)/800.
ysize=(211.)*2.1*float(isdepth)/600.
ixcentre=int(xsize/2)
iycentre=int(ysize/2)
.
.
.
.
c get element node coordinates
do ii=1,ne
do ij=1,icoord
coord(ij,1)=acoord(elnode(ii,ij),1)
coord(ij,2)=acoord(elnode(ii,ij),2)
end do
end do
c set up polygon definition for element (xpmax,xpmin - range x coord in mesh ditto for yp values)
do ii=1,ne
do ij=1,icoord
coord(ij,1)=acoord(elnode(ii,ij),1)
coord(ij,2)=acoord(elnode(ii,ij),2)
ix(ij)=ixcentre-((xpmax+xpmin)/2-coord(ij,1))*scale
iy(ij)=iycentre+((ypmax+ypmin)/2-coord(ij,2))*scale
end do
ix(9)=ixcentre-((xpmax+xpmin)/2-coord(1,1))*scale
iy(9)=iycentre+((ypmax+ypmin)/2-coord(1,2))*scale
c set up colours for material properties type
icol1=255
icol2=0
icol3=0
if(mat_type(ii).eq.2) then
icol1=00
icol2=255
icol3=0
end if
if(mat_type(ii).eq.3) then
icol1=0
icol2=0
icol3=255
end if
if(mat_type(ii).eq.4) then
icol1=255
icol2=255
icol3=0
end if
if(mat_type(ii).eq.5) then
icol1=0
icol2=255
icol3=255
end if
call create_polygon@(ix,iy,9,hpol1,err)
call fill_polygon@(hpol1,rgb@(icol1,icol2,icol3),err)
call delete_polygon_definition@(hpol1,err)
end do
Alternative form is:
if(mat_type.eq.1) then
call draw_filled_polygon@(ix,iy,9,rgb@(255,0,0))
call draw_polyline@(ix,iy,9,rgb@(0,0,0))
end if
if(mat_type.eq.2) then
call draw_filled_polygon@(ix,iy,9,rgb@(0,255,0))
call draw_polyline@(ix,iy,9,rgb@(0,0,0))
end if
etc |
Cheers |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Sat Jan 02, 2010 1:07 pm Post subject: |
|
|
There are many of us in this forum that have spent many years developing software for FE applications and graphics.
There are 2 main approaches:
1) use opengl or
2) use the clearwin routines in a %gr window.
I have used the latter and use routines such as draw_filled_polygon@ and draw_line_between@
Before you get to the screen window and coordinates, you need to define a virtual coordinate system (real*8 ) which transforms the 3d coordinate system of your model to an orientation for viewing on the screen.
You can then transform (scale) this coordinate system to the upside down screen coordinate system (integer*4 ) of the clearwin+ routines.
It is best to keep these units as general as possible as there are many different screen sizes ( pixels ) which the clearwin+ routines respond to.
A refresher course in vector transformations is very useful, such as the cross product of 2 vectors. The 3D transformation can be easily understood as the product of 2 rotations about principal axes, using a 3x3 transformation matrix.
None of it is very complex, but is can take a lot of time to get to where you want.
Start with your simple 2d screen plot and then try to layer the axis systems and transformations, such as
1) 3D axis system of FE model (XYZ as real*8 )
2) transformed 3D axis system with u,v in orientation of screen (uvw as real*8 )
3) scaled axis system of screen in horizontal and vertical pixels (ih,iv as integer*4 )
In 3D, you will find that the depth dimension "w" is very important so that you draw the front last.
When going to the screen axis system, when zooming in, you will also need to clip your lines and polygons to the visable screen. This clipping can best be done when going to the uvw system, using real*8.
In the end there are few routines that are required to draw, being the polygon, line and point, of a certain colour.
All this is handled in opengl, although my software development and approach pre-dates opengl and is based on tektronix plot-10.
Again, get the simple 2d picture drawn then expand from there.
Good luck
John |
|
Back to top |
|
|
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Mon Jan 04, 2010 4:28 pm Post subject: |
|
|
John and smib, thanks for your comments and ideas. The clearwin subroutines sounds like a good option. I played a bit with the conversion that smib provided. Works fine and: I now have something on which I can improve However, the resolution seems to be quite low. Is this typical? Especially the polylines look rather like dashed lines. Below is my test code.
Code: | winapp
INTEGER i,winio@
EXTERNAL cb_polygon
i=winio@('%ww[no_border,no_maxminbox]&')
i=winio@('%sy[3d_depressed]&')
i=winio@('%gr[white,rgb_colours]&',800,600)
i=winio@('%sc',cb_polygon)
end
INTEGER FUNCTION cb_polygon()
implicit none
INCLUDE 'clearwin.ins'
real x_ply(50),y_ply(50)
INTEGER I,J,IU
integer isdepth,iswidth,ixcentre,iycentre,fac
integer ix(50),iy(50),ic1,ic2,ic3
integer nstype_pol,nspnts_pol,nseg_pol
real xsize,ysize,xpmax,xpmin,ypmax,ypmin
isdepth=clearwin_info@('screen_depth')
iswidth=clearwin_info@('screen_width')
xsize=(297.)*2.1*float(iswidth)/800.
ysize=(211.)*2.1*float(isdepth)/600.
ixcentre=int(xsize/2)
iycentre=int(ysize/2)
iu = 99
xpmax=-100000000;
xpmin= 100000000;
ypmin=xpmin;
ypmax=xpmax;
open(unit=iu,FILE='ad.pol')
rewind iu
read (iu,*) nseg_pol
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
! get polygon node coordinates
read (iu,*) x_ply(j),y_ply(j)
C min/maxs
xpmax=max(xpmax,x_ply(j))
xpmin=min(xpmin,x_ply(j))
ypmax=max(ypmax,y_ply(j))
ypmin=min(ypmin,y_ply(j))
end do
end do
fac = 2200
rewind iu
read (iu,*) nseg_pol
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
! get polygon node coordinates
read (iu,*) x_ply(j),y_ply(j)
ix(j) = ixcentre-((xpmax+xpmin)/2-x_ply(j))*fac
iy(j) = iycentre+((ypmax+ypmin)/2-y_ply(j))*fac
end do
if(abs(nstype_pol).eq.0) then
ic1=0
ic2=0
ic3=0
elseif(abs(nstype_pol).eq.1) then
ic1=255
ic2=0
ic3=0
elseif(abs(nstype_pol).eq.2) then
ic1=0
ic2=0
ic3=255
elseif(abs(nstype_pol).eq.3) then
ic1=255
ic2=255
ic3=0
elseif(abs(nstype_pol).eq.201) then
ic1=0
ic2=255
ic3=0
elseif(abs(nstype_pol).eq.250) then
ic1=0
ic2=255
ic3=0
endif
call draw_filled_polygon@(ix,iy,nspnts_pol,rgb@(ic1,ic2,ic3))
call draw_polyline@(ix,iy,nspnts_pol,rgb@(0,0,0))
end do
cb_polygon = 1
close(iu)
end |
|
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Tue Jan 05, 2010 1:39 am Post subject: |
|
|
I was not able to run your program, but if the display is too course, the problem may be with your integer arithmetic. You could try changing
ix(j) = ixcentre-((xpmax+xpmin)/2-x_ply(j))*fac
to
ix(j) = ixcentre - nint ( ((xpmax+xpmin)/2.0-x_ply(j))*real(fac)) )
or use the following in the appropriate places
real*8 xc, yc, fac
xc = (xpmax+xpmin)/2.0
ix(j) = ixcentre - nint ( (xc - x_ply(j)) * fac )
You may also want to change the value of FAC based on the values of :
(xpmax-xpmin) / real (iswidth) and
(ypmax-ypmin) / real (isdepth)
xc, yc and fac are key parameters for your screen display, which can be modified to change the view.
ix and iy need to be tested to see if they are on the visable screen, otherwise the polygon needs to be clipped. You could introduce a subroutine Clip_Polygon ( ix, iy, nspnts_pol, isdepth, iswidth)
this could modify the values of ix, iy and nspnts_pol. eg
call Clip_Polygon ( ix, iy, nspnts_pol, iswidth, isdepth)
if (nspnts_pol < 3) cycle
Clearwin+ tends to use integer*4 and real*8 variable types, so it may be useful to standardise on those, although there are a few uses of integer*2 to trick you up. |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Tue Jan 05, 2010 3:34 am Post subject: |
|
|
I found your points data and changed your program. It's been a while since I used some of these routines for setting up the screen and I had trouble getting the screen handle and dimensions. clearwin_info@ ('GRAPHICS_WIDTH') did not return what I wanted ?
Anyway, I've listed teh program, asd I have changed it. I did not include the clip_polygon routine. That takes a little time to write.
Code: | winapp
common /zz/ handle
INTEGER i,winio@, handle
EXTERNAL cb_polygon
!
handle = 1
!
i = winio@ ('%sy[3d_depressed]&')
i = winio@ ('%ca@&', 'Test graphics')
i = winio@ ('%gr[white,rgb_colours]&',800,600)
i = winio@ ('%ww[no_border,no_maxminbox]&')
i = winio@ ('%hw&', handle)
i = winio@ ('%sc',cb_polygon)
end
INTEGER FUNCTION cb_polygon()
implicit none
INCLUDE 'clearwin.ins'
!
common /zz/ handle
integer*4 HANDLE, X, Y, WIDTH, HEIGHT
real*8 x_ply(50),y_ply(50)
INTEGER*4 I,J,IU
integer*4 isdepth,iswidth,ixcentre,iycentre, s_width, s_depth
integer*4 ix(50),iy(50),ic1,ic2,ic3, icol, black
integer*4 nstype_pol, nspnts_pol, nseg_pol
real*8 xsize,ysize,xpmax,xpmin,ypmax,ypmin, fac,xc,yc, xr, yr
!
! get screen dimensions
s_width = clearwin_info@ ('SCREEN_WIDTH') ! full screen width
s_depth = clearwin_info@ ('SCREEN_DEPTH') ! full screen depth
write (*,*) 'SCREEN_WIDTH', s_width, s_depth
!
! get graphics window dimensions
! handle = clearwin_info@ ('GRAPHICS_HDC')
write (*,*) 'handle=', handle
call GET_WINDOW_LOCATION@ ( HANDLE, X, Y, WIDTH, HEIGHT)
write (*,*) 'GRAPHICS_HDC', HANDLE, X, Y, WIDTH, HEIGHT
!
iswidth = clearwin_info@ ('GRAPHICS_WIDTH')
isdepth = clearwin_info@ ('GRAPHICS_DEPTH')
write (*,*) 'GRAPHICS_WIDTH', iswidth, isdepth, 'Note: this does not work ???'
!
iswidth = width - 20 ! allow for border
isdepth = height - 45 ! allow for caption
!
! xsize=(297.)*2.1*float(iswidth)/800.
! ysize=(211.)*2.1*float(isdepth)/600.
! ixcentre=int(xsize/2)
! iycentre=int(ysize/2)
!
ixcentre = iswidth/2
iycentre = isdepth/2
write (*,*) 'x', iswidth, ixcentre
write (*,*) 'y', isdepth, iycentre
!
iu = 99
xpmin = 1.e8
xpmax = -xpmin
ypmin = xpmin
ypmax = xpmax
open(unit=iu,FILE='ad.pol')
! rewind iu
read (iu,*) nseg_pol
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
! get polygon node coordinates
read (iu,*) x_ply(j),y_ply(j)
! min/maxs
xpmax = max (xpmax,x_ply(j))
xpmin = min (xpmin,x_ply(j))
ypmax = max (ypmax,y_ply(j))
ypmin = min (ypmin,y_ply(j))
end do
end do
!
xc = (xpmin+xpmax)/2.0
yc = (ypmin+ypmax)/2.0
xr = xpmax-xpmin
yr = ypmax-ypmin
!z fac = 3200.
fac = 0.85 * min ( real(iswidth)/xr, real(isdepth)/yr)
write (*,*) 'x', xpmin, xpmax, xc, xr
write (*,*) 'y', ypmin, ypmax, yc, yr
write (*,*) 'fac', fac
!
|
|
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Tue Jan 05, 2010 3:36 am Post subject: |
|
|
rest of program
Code: | !
black = rgb@ (0,0,0)
rewind iu
read (iu,*) nseg_pol
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
! get polygon node coordinates
read (iu,*) x_ply(j),y_ply(j)
ix(j) = ixcentre - (xc-x_ply(j))*fac
iy(j) = iycentre + (yc-y_ply(j))*fac
write (*,*) j, x_ply(j), y_ply(j), ix(j), iy(j)
! ?? check orientation of X,Y
end do
! close polygon for draw_polyline@
ix(j) = ix(1)
iy(j) = iy(1)
!
! select colour
if(abs(nstype_pol).eq.0) then ! black
ic1=0
ic2=0
ic3=0
elseif(abs(nstype_pol).eq.1) then ! red
ic1=255
ic2=0
ic3=0
elseif(abs(nstype_pol).eq.2) then ! blue
ic1=0
ic2=0
ic3=255
elseif(abs(nstype_pol).eq.3) then ! yellow
ic1=255
ic2=255
ic3=0
elseif(abs(nstype_pol).eq.201) then ! green
ic1=0
ic2=255
ic3=0
elseif(abs(nstype_pol).eq.250) then ! green
ic1=0
ic2=255
ic3=0
end if
icol = rgb@(ic1,ic2,ic3)
!
call draw_filled_polygon@ (ix,iy,nspnts_pol,icol)
call draw_polyline@ (ix,iy, nspnts_pol+1, black)
end do
close(iu)
!
cb_polygon = 1
!
end |
|
|
Back to top |
|
|
Smib
Joined: 26 Apr 2009 Posts: 22 Location: Melbourne
|
Posted: Tue Jan 05, 2010 6:38 am Post subject: |
|
|
John,
you can use this to clip
Code: |
integer*4 ixtop,ixbot,iytop,iybot
ijhndl=clearwin_info@('GRAPHICS_HDC')
ihdr=CreateRectRgn(ixtop,iytop,ixbot,iybot)
call SelectClipRgn(ijhndl,ihdr)
***** plot here*****
call SelectClipRgn(ijhndl,0)[quote]
|
Cheers |
|
Back to top |
|
|
Smib
Joined: 26 Apr 2009 Posts: 22 Location: Melbourne
|
Posted: Tue Jan 05, 2010 6:39 am Post subject: |
|
|
oops
ignore '[quote]' |
|
Back to top |
|
|
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Tue Jan 05, 2010 2:51 pm Post subject: |
|
|
John, I worked through your code suggestions. The resolution is now as one would expect it. Thanks! It would have taken me quite a while to figure this out all by myself.
I used some code example provided in the Clearwin documentation to find the rgb-values for the colours I need and then made a colour function. The code then are as follows:
Code: | ! Code from Clearwin documentation to determine colour rgb-values.
WINAPP
INCLUDE <windows.ins>
INTEGER i,v(3)
i=winio@('%ca[colour palette] %cl',v)
i=winio@('%ca[colour mix result] The colour was %wd.',v(1))
END |
Code: | integer*4 function f_colour(nstype_pol)
implicit none
INCLUDE 'clearwin.ins'
integer*4,intent(in) :: nstype_pol
select case(nstype_pol)
case(0)
f_colour = rgb@ (0,0,0) ! black
case(1)
f_colour = rgb@ (128,0,0) ! dark red
case(-1)
f_colour = rgb@ (255,0,0) ! red
case(2)
f_colour = rgb@ (0,0,128) ! dark blue
case(-2)
f_colour = rgb@ (0,0,255) ! blue
case(3)
f_colour = rgb@ (128,128,128) ! dark grey
case(-3)
f_colour = rgb@ (192,192,192) ! grey
case(4)
f_colour = rgb@ (255,0,0) ! dark red
case(-4)
f_colour = rgb@ (128,0,0) ! red
case(8)
f_colour = rgb@ (255,0,0) ! red
case(5)
f_colour = rgb@ (0,0,255) ! blue
case(-5)
f_colour = rgb@ (0,0,128) ! dark blue
case(10)
f_colour = rgb@ (0,0,255) ! blue
case(201)
f_colour = rgb@ (0,201,0) ! green
case(250)
f_colour = rgb@ (0,250,0) ! green
case default
f_colour = rgb@ (0,0,0)
end select
return
end function |
|
|
Back to top |
|
|
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Tue Jan 05, 2010 2:59 pm Post subject: |
|
|
To conclude this topic I would like to thank John and Smib for their input! The final code does excactly what I would like it to do: Simply plot the polygons with a high resolution
For the moment I can see what the model looks like before starting with the FEA solution - using only FTN95. In the near future I will add some other functionality based on this axample (and report it here).
Code: | winapp
common /zz/ handle
INTEGER i,winio@, handle
EXTERNAL cb_polygon
!
handle = 1
!
i = winio@ ('%sy[3d_depressed]&')
i = winio@ ('%ca@&', 'Polygons')
i = winio@ ('%gr[white,rgb_colours]&',800,600)
i = winio@ ('%ww[no_border,no_maxminbox]&')
i = winio@ ('%hw&', handle)
i = winio@ ('%sc',cb_polygon)
end
!----------------------------------------------------------
INTEGER FUNCTION cb_polygon()
implicit none
INCLUDE 'clearwin.ins'
!
common /zz/ handle
integer*4 HANDLE, X, Y, WIDTH, HEIGHT
real*8 x_ply(50),y_ply(50)
INTEGER*4 I,J,IU
integer*4 isdepth,iswidth,ixcentre,iycentre
integer*4 ix(50),iy(50),f_colour,colour
integer*4 nstype_pol, nspnts_pol, nseg_pol
real*8 xpmax,xpmin,ypmax,ypmin, fac,xc,yc, xr, yr
!
! get graphics window dimensions
call GET_WINDOW_LOCATION@ ( HANDLE, X, Y, WIDTH, HEIGHT)
iswidth = width - 20 ! allow for border
isdepth = height - 45 ! allow for caption
ixcentre = iswidth/2
iycentre = isdepth/2
!
iu = 99
xpmin = 1.e8
xpmax = -xpmin
ypmin = xpmin
ypmax = xpmax
open(unit=iu,FILE='aa.pol')
read (iu,*) nseg_pol
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
! get polygon node coordinates
read (iu,*) x_ply(j),y_ply(j)
! min/maxs
xpmax = max (xpmax,x_ply(j))
xpmin = min (xpmin,x_ply(j))
ypmax = max (ypmax,y_ply(j))
ypmin = min (ypmin,y_ply(j))
end do
end do
!
xc = (xpmin+xpmax)/2.0
yc = (ypmin+ypmax)/2.0
xr = xpmax-xpmin
yr = ypmax-ypmin
fac = 0.9 * min ( real(iswidth)/xr, real(isdepth)/yr)
!
rewind iu
read (iu,*) nseg_pol
do i=1,nseg_pol
read (iu,*) nspnts_pol,nstype_pol
do j=1,nspnts_pol
! get polygon node coordinates
read (iu,*) x_ply(j),y_ply(j)
ix(j) = ixcentre - (xc-x_ply(j))*fac
iy(j) = iycentre + (yc-y_ply(j))*fac
end do
! close polygon for draw_polyline@
ix(j) = ix(1)
iy(j) = iy(1)
!
! select colour
colour = f_colour(nstype_pol)
!
call draw_filled_polygon@ (ix,iy,nspnts_pol,colour)
call draw_polyline@ (ix,iy, nspnts_pol+1, rgb@ (0,0,0))
end do
close(iu)
!
cb_polygon = 1
!
end |
|
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Wed Jan 06, 2010 12:56 pm Post subject: |
|
|
1. You are looking at the window size with GET_WINDOW_LOCATION@, but you could look at the graphics size, then you would not need to allow for the borders or menu bar, and your code would still work properly if you go on to add toolbars, status line etc - or even change the style of the window. This is the code I use:
Code: | IXRES0 = CLEARWIN_INFO@ ('GRAPHICS_WIDTH')
IYRES0 = CLEARWIN_INFO@ ('GRAPHICS_DEPTH')
IXRES = MAX (1, IXRES0)
IYRES = MAX (1, IYRES0) |
This code is in the callback for my %gr region, and allows me to have a %pv on the %gr, so the window behaves properly, and is resizable. if the window is resized, you have to program the redrawing. Not a problem if you are programming for yourself - leave it as it is. But if programming an application for others to use, you need to not just have the graphics drawing in the callback to the startup of your window, you need to have it in the callback for the %gr, and to react to a resize message.
2. If you do things with reference to the window, then I recommend on on-screen ruler program for measuring pixels. I use "ruler by george", which you can search for on the web.
3. I've never found the need (in Clearwin+ and on the screen) to clip anything. All you do is just go ahead and draw it all, if the coordinates lie outside the plottable area, Clearwin plots up to the edge.
4. When getting a hard copy, you do sometimes need to clip things. Clipping algorithms are awful, although some good ideas were posted here in this thread (thanks, I learnt something - actually, a lot). However, I find it preferable and simpler to go ahead and draw everything, then draw over what I don't want with (up to) 4 white rectangles. If you do his last, then they cover up the bits you don't want.
5. Your %gr region is set to 800x600, which I would think is only a fraction of your screen . These statements:
Code: | IX=GetSystemMetrics(SM_CXSCREEN)
IY=GetSystemMetrics(SM_CYSCREEN) |
let you find out how big the screen is, and size your window and graphics area accordingly. The allowances for borders etc change if you use a computer with large fonts enabled. The reasons for this are complicated. Again, not a problem if you are running on one computer, a bigger problem in a general purpose application.
Eddie |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|