PLplot
5.10.0
|
00001 00002 #include <stdio.h> 00003 #include <math.h> 00004 #include <string.h> 00005 #include <stdlib.h> 00006 #include "defines.h" 00007 #include "cd.h" 00008 00009 // cdtest.c: test program for the cgmdraw module. 00010 // 00011 // Written by G. Edward Johnson <mailto:lorax@nist.gov> 00012 // Date: April 1996 00013 // Copyright: cd software produced by NIST, an agency of the 00014 // U.S. government, is by statute not subject to copyright 00015 // in the United States. Recipients of this software assume all 00016 // responsibilities associated with its operation, modification 00017 // and maintenance. 00018 // 00019 // 00020 00021 00022 int main() 00023 { 00024 cdImagePtr myimage; 00025 00026 // Color indexes 00027 int white; 00028 int blue; 00029 int red; 00030 int green; 00031 int black; 00032 int lavender; 00033 // points for polygons and polylines 00034 cdPoint points[15]; 00035 // output file 00036 FILE *outf; 00037 00038 00039 // create an image, 1000 by 1000 pixels 00040 myimage = cdImageCreate( 1000, 1000 ); 00041 00042 // Allocate the background color 00043 white = cdImageColorAllocate( myimage, 255, 255, 255 ); 00044 red = cdImageColorAllocate( myimage, 255, 0, 0 ); 00045 green = cdImageColorAllocate( myimage, 0, 255, 0 ); 00046 blue = cdImageColorAllocate( myimage, 0, 0, 255 ); 00047 black = cdImageColorAllocate( myimage, 0, 0, 0 ); 00048 00049 if ( cdSetLineColor( myimage, blue ) ) 00050 { 00051 fprintf( stderr, "cdSetLineColor Successful\n" ); 00052 } 00053 else 00054 { 00055 fprintf( stderr, "cdSetLineColor Unsuccessful\n" ); 00056 } 00057 00058 if ( cdSetLineColor( myimage, blue ) ) 00059 { 00060 fprintf( stderr, "cdSetLineColor Successful\n" ); 00061 } 00062 else 00063 { 00064 fprintf( stderr, "cdSetLineColor Unsuccessful\n" ); 00065 } 00066 00067 00068 if ( cdImageLine( myimage, 400, 8, 520, 8, green ) ) 00069 { 00070 fprintf( stderr, "cdImageLine Successful\n" ); 00071 } 00072 else 00073 { 00074 fprintf( stderr, "cdImageLine Unsuccessful\n" ); 00075 } 00076 00077 if ( cdImageLine( myimage, 50, 50, 500, 500, red ) ) 00078 { 00079 fprintf( stderr, "cdImageLine Successful\n" ); 00080 } 00081 else 00082 { 00083 fprintf( stderr, "cdImageLine Unsuccessful\n" ); 00084 } 00085 00086 if ( cdSetLineAttrib( myimage, 2, 3, red ) ) 00087 { 00088 fprintf( stderr, "cdSetLineAttrib Successful\n" ); 00089 } 00090 else 00091 { 00092 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" ); 00093 } 00094 00095 if ( cdLine( myimage, 500, 50, 50, 500 ) ) 00096 { 00097 fprintf( stderr, "cdLine Successful\n" ); 00098 } 00099 else 00100 { 00101 fprintf( stderr, "cdLine Unsuccessful\n" ); 00102 } 00103 00104 // Now, build a rectangle 00105 if ( cdSetShapeFillAttrib( myimage, 3, blue, 6 ) ) 00106 { 00107 fprintf( stderr, "cdSetShapeFillAttrib Successful\n" ); 00108 } 00109 else 00110 { 00111 fprintf( stderr, "cdSetShapeFillAttrib Unsuccessful\n" ); 00112 } 00113 00114 if ( cdSetShapeEdgeAttrib( myimage, 1, 2, green, 1 ) ) 00115 { 00116 fprintf( stderr, "cdSetShapeEdgeAttrib Successful\n" ); 00117 } 00118 else 00119 { 00120 fprintf( stderr, "cdSetShapeEdgeAttrib Unsuccessful\n" ); 00121 } 00122 00123 if ( cdRectangle( myimage, 100, 100, 250, 250 ) ) 00124 { 00125 fprintf( stderr, "cdRectangle Successful\n" ); 00126 } 00127 else 00128 { 00129 fprintf( stderr, "cdRectangle Unsuccessful\n" ); 00130 } 00131 00132 00133 00134 // now check out each of the line styles in order 00135 00136 if ( cdSetLineAttrib( myimage, 5, 4, green ) ) 00137 { 00138 fprintf( stderr, "cdSetLineAttrib Successful\n" ); 00139 } 00140 else 00141 { 00142 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" ); 00143 } 00144 00145 if ( cdLine( myimage, 100, 600, 500, 600 ) ) 00146 { 00147 fprintf( stderr, "cdLine Successful\n" ); 00148 } 00149 else 00150 { 00151 fprintf( stderr, "cdLine Unsuccessful\n" ); 00152 } 00153 00154 if ( cdSetLineAttrib( myimage, 4, -1, -1 ) ) 00155 { 00156 fprintf( stderr, "cdSetLineAttrib Successful\n" ); 00157 } 00158 else 00159 { 00160 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" ); 00161 } 00162 if ( cdLine( myimage, 100, 625, 500, 625 ) ) 00163 { 00164 fprintf( stderr, "cdLine Successful\n" ); 00165 } 00166 else 00167 { 00168 fprintf( stderr, "cdLine Unsuccessful\n" ); 00169 } 00170 00171 if ( cdSetLineAttrib( myimage, 3, -1, -1 ) ) 00172 { 00173 fprintf( stderr, "cdSetLineAttrib Successful\n" ); 00174 } 00175 else 00176 { 00177 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" ); 00178 } 00179 if ( cdLine( myimage, 100, 650, 500, 650 ) ) 00180 { 00181 fprintf( stderr, "cdLine Successful\n" ); 00182 } 00183 else 00184 { 00185 fprintf( stderr, "cdLine Unsuccessful\n" ); 00186 } 00187 00188 00189 if ( cdSetLineAttrib( myimage, 2, -1, -1 ) ) 00190 { 00191 fprintf( stderr, "cdSetLineAttrib Successful\n" ); 00192 } 00193 else 00194 { 00195 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" ); 00196 } 00197 if ( cdLine( myimage, 100, 675, 500, 675 ) ) 00198 { 00199 fprintf( stderr, "cdLine Successful\n" ); 00200 } 00201 else 00202 { 00203 fprintf( stderr, "cdLine Unsuccessful\n" ); 00204 } 00205 00206 if ( cdSetLineAttrib( myimage, 1, -1, -1 ) ) 00207 { 00208 fprintf( stderr, "cdSetLineAttrib Successful\n" ); 00209 } 00210 else 00211 { 00212 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" ); 00213 } 00214 if ( cdLine( myimage, 100, 700, 500, 700 ) ) 00215 { 00216 fprintf( stderr, "cdLine Successful\n" ); 00217 } 00218 else 00219 { 00220 fprintf( stderr, "cdLine Unsuccessful\n" ); 00221 } 00222 00223 // now make a circle 00224 if ( cdSetShapeFillAttrib( myimage, 1, -1, 6 ) ) 00225 { 00226 fprintf( stderr, "cdSetShapeFillAttrib Successful\n" ); 00227 } 00228 else 00229 { 00230 fprintf( stderr, "cdSetShapeFillAttrib Unsuccessful\n" ); 00231 } 00232 00233 if ( cdSetShapeEdgeAttrib( myimage, 1, 2, green, 0 ) ) 00234 { 00235 fprintf( stderr, "cdSetShapeEdgeAttrib Successful\n" ); 00236 } 00237 else 00238 { 00239 fprintf( stderr, "cdSetShapeEdgeAttrib Unsuccessful\n" ); 00240 } 00241 00242 if ( cdCircle( myimage, 500, 500, 25 ) ) 00243 { 00244 fprintf( stderr, "cdCircle Successful\n" ); 00245 } 00246 else 00247 { 00248 fprintf( stderr, "cdCircle Unsuccessful\n" ); 00249 } 00250 00251 // how about a Circular Arc now 00252 if ( cdArc3Pt( myimage, 550, 500, 600, 600, 650, 550 ) ) 00253 { 00254 fprintf( stderr, "cdArc3Pt Successful\n" ); 00255 } 00256 else 00257 { 00258 fprintf( stderr, "cdArc3Pt Unsuccessful\n" ); 00259 } 00260 00261 // now draw a closed Circular Arc 00262 if ( cdArc3PtClose( myimage, 550, 200, 600, 300, 650, 250, 0 ) ) 00263 { 00264 fprintf( stderr, "cdArc3PtClose Successful\n" ); 00265 } 00266 else 00267 { 00268 fprintf( stderr, "cdArc3PtClose Unsuccessful\n" ); 00269 } 00270 00271 // and now for an ellipse 00272 if ( cdSetShapeEdgeAttrib( myimage, 1, 2, green, 1 ) ) 00273 { 00274 fprintf( stderr, "cdSetShapeEdgeAttrib Successful\n" ); 00275 } 00276 else 00277 { 00278 fprintf( stderr, "cdSetShapeEdgeAttrib Unsuccessful\n" ); 00279 } 00280 00281 if ( cdEllipse( myimage, 750, 200, 800, 250, 750, 300 ) ) 00282 { 00283 fprintf( stderr, "cdEllipse Successful\n" ); 00284 } 00285 else 00286 { 00287 fprintf( stderr, "cdEllipse Unsuccessful\n" ); 00288 } 00289 00290 00291 // Now, the harder ones. First lets try the polygon stuff 00292 // a polygon with 7 or less points 00293 00294 points[0].x = 700; 00295 points[0].y = 700; 00296 points[1].x = 725; 00297 points[1].y = 750; 00298 points[2].x = 775; 00299 points[2].y = 650; 00300 00301 if ( cdPolygon( myimage, points, 3 ) ) 00302 { 00303 fprintf( stderr, "cdPolygon Successful\n" ); 00304 } 00305 else 00306 { 00307 fprintf( stderr, "cdPolygon Unsuccessful\n" ); 00308 } 00309 00310 // Here's a tough one, a polygon with more than seven points 00311 00312 points[0].x = 800; 00313 points[0].y = 700; 00314 points[1].x = 825; 00315 points[1].y = 725; 00316 points[2].x = 850; 00317 points[2].y = 700; 00318 points[3].x = 875; 00319 points[3].y = 750; 00320 points[4].x = 900; 00321 points[4].y = 775; 00322 points[5].x = 925; 00323 points[5].y = 750; 00324 points[6].x = 950; 00325 points[6].y = 850; 00326 points[7].x = 925; 00327 points[7].y = 850; 00328 points[8].x = 875; 00329 points[8].y = 800; 00330 points[9].x = 850; 00331 points[9].y = 825; 00332 points[10].x = 825; 00333 points[10].y = 900; 00334 00335 if ( cdPolygon( myimage, points, 11 ) ) 00336 { 00337 fprintf( stderr, "cdPolygon Successful\n" ); 00338 } 00339 else 00340 { 00341 fprintf( stderr, "cdPolygon Unsuccessful\n" ); 00342 } 00343 00344 // Now for a polygon set, two polygons (both triangles) the first one 00345 // with an invisible edge closing it. 00346 00347 points[0].x = 500; // start of first polygon 00348 points[0].y = 350; 00349 points[0].e = 1; // edge out is visible 00350 points[1].x = 575; 00351 points[1].y = 350; 00352 points[1].e = 1; 00353 points[2].x = 575; 00354 points[2].y = 430; 00355 points[2].e = 3; // close polygon with visible edge 00356 points[3].x = 600; // start of second polygon 00357 points[3].y = 350; 00358 points[3].e = 0; // edge out is invisible 00359 points[4].x = 700; 00360 points[4].y = 350; 00361 points[4].e = 1; 00362 points[5].x = 650; 00363 points[5].y = 475; 00364 points[5].e = 2; // close polygone with an invisible edge 00365 00366 // make the edges wider so it is easier to see if they are there 00367 if ( cdSetEdgeWidth( myimage, 3 ) ) 00368 { 00369 fprintf( stderr, "cdSetEdgeWidth Successful\n" ); 00370 } 00371 else 00372 { 00373 fprintf( stderr, "cdSetEdgeWidth Unsuccessful\n" ); 00374 } 00375 if ( cdPolygonSet( myimage, points, 6 ) ) // draw the polygonset 00376 { 00377 fprintf( stderr, "cdPolygonSet Successful\n" ); 00378 } 00379 else 00380 { 00381 fprintf( stderr, "cdPolygonSet Unsuccessful\n" ); 00382 } 00383 00384 // now for poly lines, just like polygons (except they're lines) 00385 00386 if ( cdSetLineAttrib( myimage, 1, 1, red ) ) 00387 { 00388 fprintf( stderr, "cdSetLineAttrib Successful\n" ); 00389 } 00390 else 00391 { 00392 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" ); 00393 } 00394 00395 00396 points[0].x = 400; 00397 points[0].y = 16; 00398 points[1].x = 520; 00399 points[1].y = 16; 00400 if ( cdPolyLine( myimage, points, 2 ) ) 00401 { 00402 fprintf( stderr, "cdPolyLine Successful\n" ); 00403 } 00404 else 00405 { 00406 fprintf( stderr, "cdPolyLine Unsuccessful\n" ); 00407 } 00408 00409 points[0].x = 800; 00410 points[0].y = 650; 00411 points[1].x = 825; 00412 points[1].y = 675; 00413 points[2].x = 850; 00414 points[2].y = 650; 00415 points[3].x = 875; 00416 points[3].y = 700; 00417 if ( cdPolyLine( myimage, points, 4 ) ) 00418 { 00419 fprintf( stderr, "cdPolyLine Successful\n" ); 00420 } 00421 else 00422 { 00423 fprintf( stderr, "cdPolyLine Unsuccessful\n" ); 00424 } 00425 00426 00427 // Markers 00428 // set the attributes 00429 if ( cdSetMarkerAttrib( myimage, 1, 1, green ) ) 00430 { 00431 fprintf( stderr, "cdSetMarkerAttrib Successful\n" ); 00432 } 00433 else 00434 { 00435 fprintf( stderr, "cdSetMarkerAttrib Unsuccessful\n" ); 00436 } 00437 00438 // now plot the marker 00439 00440 if ( cdMarker( myimage, 900, 500 ) ) 00441 { 00442 fprintf( stderr, "cdMarker Successful\n" ); 00443 } 00444 else 00445 { 00446 fprintf( stderr, "cdMarker Unsuccessful\n" ); 00447 } 00448 00449 00450 if ( cdSetMarkerAttrib( myimage, 5, 3, black ) ) 00451 { 00452 // set the marker type to cross 00453 fprintf( stderr, "cdSetMarkerAttrib Successful\n" ); 00454 } 00455 else 00456 { 00457 fprintf( stderr, "cdSetMarkerAttrib Unsuccessful\n" ); 00458 } 00459 00460 // a Poly Marker, two markers in different places 00461 points[0].x = 715; 00462 points[0].y = 785; 00463 points[1].x = 735; 00464 points[1].y = 815; 00465 00466 if ( cdPolyMarker( myimage, points, 2 ) ) 00467 { 00468 fprintf( stderr, "cdPolyMarker Successful\n" ); 00469 } 00470 else 00471 { 00472 fprintf( stderr, "cdMarker Unsuccessful\n" ); 00473 } 00474 00475 00476 // Hey, things are going so well, lets do some text 00477 lavender = cdImageColorAllocate( myimage, 204, 102, 255 ); 00478 00479 if ( cdSetTextAttrib( myimage, 1, lavender, 50 ) ) 00480 { 00481 fprintf( stderr, "cdSetTextAttrib Successful\n" ); 00482 } 00483 else 00484 { 00485 fprintf( stderr, "cdSetTextAttrib Unsuccessful\n" ); 00486 } 00487 00488 if ( cdText( myimage, 50, 800, "CGM Draw Version 1.3" ) ) 00489 { 00490 fprintf( stderr, "cdText Successful\n" ); 00491 } 00492 else 00493 { 00494 fprintf( stderr, "cdText Unsuccessful\n" ); 00495 } 00496 00497 // More text. This time test TextPath and TextOrient 00498 if ( cdSetTextPath( myimage, 3 ) ) 00499 { 00500 fprintf( stderr, "cdSetTextPath Successful\n" ); 00501 } 00502 else 00503 { 00504 fprintf( stderr, "cdSetTextPath Unsuccessful\n" ); 00505 } 00506 00507 if ( cdText( myimage, 50, 800, "CGM Draw" ) ) 00508 { 00509 fprintf( stderr, "cdText Successful\n" ); 00510 } 00511 else 00512 { 00513 fprintf( stderr, "cdText Unsuccessful\n" ); 00514 } 00515 00516 if ( cdSetTextOrient( myimage, 1, 0, 0, -1 ) ) 00517 { 00518 fprintf( stderr, "cdSetTextOrient Successful\n" ); 00519 } 00520 else 00521 { 00522 fprintf( stderr, "cdSetTextOrient Unsuccessful\n" ); 00523 } 00524 00525 if ( cdSetTextPath( myimage, 0 ) ) 00526 { 00527 fprintf( stderr, "cdSetTextPath Successful\n" ); 00528 } 00529 else 00530 { 00531 fprintf( stderr, "cdSetTextPath Unsuccessful\n" ); 00532 } 00533 00534 if ( cdText( myimage, 950, 400, "CGM Draw" ) ) 00535 { 00536 fprintf( stderr, "cdText Successful\n" ); 00537 } 00538 else 00539 { 00540 fprintf( stderr, "cdText Unsuccessful\n" ); 00541 } 00542 00543 00544 if ( cdSetTextOrient( myimage, 0, 1, 1, 0 ) ) 00545 { 00546 fprintf( stderr, "cdSetTextOrient Successful\n" ); 00547 } 00548 else 00549 { 00550 fprintf( stderr, "cdSetTextOrient Unsuccessful\n" ); 00551 } 00552 00553 00554 if ( cdSetTextAttrib( myimage, 5, -1, 25 ) ) 00555 { 00556 fprintf( stderr, "cdSetTextAttrib Successful\n" ); 00557 } 00558 else 00559 { 00560 fprintf( stderr, "cdSetTextAttrib Unsuccessful\n" ); 00561 } 00562 00563 if ( cdText( myimage, 5, 5, "G. Edward Johnson" ) ) 00564 { 00565 fprintf( stderr, "cdText Successful\n" ); 00566 } 00567 else 00568 { 00569 fprintf( stderr, "cdText Unsuccessful\n" ); 00570 } 00571 00572 00573 00574 00575 outf = fopen( "cdout.cgm", "wb" ); 00576 if ( !outf ) 00577 return 1; 00578 cdImageCgm( myimage, outf ); 00579 fclose( outf ); 00580 outf = 0; 00581 00582 cdImageDestroy( myimage ); 00583 00584 00585 return 0; 00586 }