PLplot
5.10.0
|
00001 // 00002 // cdexpert highlights the expert functions in CD. You probably 00003 // don't want to use these unless you have to. 00004 // 00005 // 00006 // cdexpert.c: test program for the cgmdraw module. 00007 // 00008 // Written by G. Edward Johnson <mailto:lorax@nist.gov> 00009 // Date: January 1997 00010 // Copyright: cd software produced by NIST, an agency of the 00011 // U.S. government, is by statute not subject to copyright 00012 // in the United States. Recipients of this software assume all 00013 // responsibilities associated with its operation, modification 00014 // and maintenance. 00015 // 00016 // 00017 00018 00019 #include <stdio.h> 00020 #include <math.h> 00021 #include <string.h> 00022 #include <stdlib.h> 00023 #include "defines.h" 00024 #include "cd.h" 00025 00026 #define CD_CHECK_RETURN( x ) \ 00027 if ( !( x ) ) \ 00028 { \ 00029 cdImageDestroy( im ); \ 00030 fclose( outf ); \ 00031 return 1; \ 00032 } 00033 00034 00035 int main() 00036 { 00037 // you must create a pointer to the image(s) that you will be using 00038 // not suprisingly, it is of type cdImagePtr 00039 cdImagePtr im; 00040 cdPoint points[2]; 00041 00042 // this is a pointer to the output file you will be using 00043 FILE *outf; 00044 00045 // these will be index's into the color palette containing 00046 // the corresponding colors 00047 int black, white, blue; 00048 00049 // Create an image 00050 im = cdImageStartCgm(); 00051 // now open the file lets call it cdexpert1.cgm 00052 outf = fopen( "cdexp1.cgm", "wb" ); 00053 if ( !outf ) 00054 { 00055 cdImageDestroy( im ); 00056 return 1; 00057 } 00058 // set its size to 500x500 00059 CD_CHECK_RETURN( cdImageSetSize( im, 500, 500 ) ); 00060 // set Line, Marker, and Edge specification modes to absolute (0) 00061 // the default is scaled (1) 00062 CD_CHECK_RETURN( cdImageSetLineSpec( im, 0 ) ); 00063 CD_CHECK_RETURN( cdImageSetMarkerSpec( im, 0 ) ); 00064 CD_CHECK_RETURN( cdImageSetEdgeSpec( im, 0 ) ); 00065 // Clear the font list, then set it to just contain 1 font 00066 CD_CHECK_RETURN( cdImageClearFonts( im ) ); 00067 CD_CHECK_RETURN( cdImageAddFont( im, "TIMES_ROMAN" ) ); 00068 // start the picture 00069 CD_CHECK_RETURN( cdCgmHeader( im ) ); 00070 CD_CHECK_RETURN( cdCgmPic( im, 2 ) ); 00071 00072 00073 // allocate some colors (isn't this fun?) 00074 // the first color allocated is the background color 00075 white = cdImageColorAllocate( im, 255, 255, 255 ); 00076 black = cdImageColorAllocate( im, 0, 0, 0 ); 00077 blue = cdImageColorAllocate( im, 0, 0, 255 ); 00078 00079 // fill attributes: Empty 00080 CD_CHECK_RETURN( cdSetShapeFillAttrib( im, 4, -1, -1 ) ); 00081 00082 // Edge attributes: dots, width 3, blue, visible edges. 00083 CD_CHECK_RETURN( cdSetShapeEdgeAttrib( im, 2, 3, blue, 1 ) ); 00084 00085 // Text attributes: Times, black, size 25 00086 CD_CHECK_RETURN( cdSetTextAttrib( im, 1, black, 25 ) ); 00087 00088 // Line attributes: Solid Black Line of Width 5 00089 CD_CHECK_RETURN( cdSetLineAttrib( im, 1, 5, black ) ); 00090 00091 // Marker attributes: style pluses, size 3, black 00092 CD_CHECK_RETURN( cdSetMarkerAttrib( im, 2, 3, black ) ); 00093 00094 // Now that we have set some attributes, lets do some drawing 00095 00096 // Draw a rectangle (10,450) is upper left, (350,350) is lower right 00097 CD_CHECK_RETURN( cdRectangle( im, 10, 450, 350, 350 ) ); 00098 // Draw a line (300,100) to (400,100) 00099 CD_CHECK_RETURN( cdLine( im, 300, 100, 400, 100 ) ); 00100 00101 // Add Two markers 00102 CD_CHECK_RETURN( cdMarker( im, 325, 150 ) ); 00103 CD_CHECK_RETURN( cdMarker( im, 375, 150 ) ); 00104 00105 // lets put some text in the picture too. 00106 // (100,100) is the point at the lower left corner of the text 00107 CD_CHECK_RETURN( cdText( im, 100, 100, "Hello World" ) ); 00108 00109 // we could just finish off the CGM here with a 00110 // cdImageCgm(im, outf), but lets put another picture in. 00111 00112 // close the picture 00113 CD_CHECK_RETURN( cdImageEndPic( im ) ); 00114 // set the specifications modes back to the default 00115 CD_CHECK_RETURN( cdImageSetLineSpec( im, 1 ) ); 00116 CD_CHECK_RETURN( cdImageSetMarkerSpec( im, 1 ) ); 00117 CD_CHECK_RETURN( cdImageSetEdgeSpec( im, 1 ) ); 00118 // start a new picture, keeping all the changes we made, including 00119 // the color table 00120 CD_CHECK_RETURN( cdCgmPic( im, 1 ) ); 00121 00122 // draw the same image again, notice the Specification modes are 00123 // different 00124 // Draw a rectangle (10,450) is upper left, (350,350) is lower right 00125 CD_CHECK_RETURN( cdRectangle( im, 10, 450, 350, 350 ) ); 00126 00127 // Draw a line (300,100) to (400,100) 00128 CD_CHECK_RETURN( cdLine( im, 300, 100, 400, 100 ) ); 00129 00130 // Add Two markers 00131 // we are doing the markers a little bit differently this time 00132 points[0].x = 325; 00133 points[0].y = 150; 00134 points[1].x = 375; 00135 points[1].y = 150; 00136 CD_CHECK_RETURN( cdPolyMarker( im, points, 2 ) ); 00137 00138 // lets put some text in the picture too. 00139 // (100,100) is the point at the lower left corner of the text 00140 CD_CHECK_RETURN( cdText( im, 100, 100, "Hello World" ) ); 00141 00142 cdImageCgm( im, outf ); 00143 fclose( outf ); 00144 outf = 0; 00145 00146 // Remember to destroy the image when you are done 00147 cdImageDestroy( im ); 00148 im = 0; 00149 00150 printf( "I am a CGM expert!!!\n" ); 00151 00152 return 0; 00153 }