home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / 3d / irit / docs / cexample / lst_sqrs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-12  |  2.5 KB  |  109 lines

  1. #include "irit_sm.h"
  2. #include "iritprsr.h"
  3. #include "allocate.h"
  4. #include "attribut.h"
  5. #include "cagd_lib.h"
  6. #include "irit_soc.h"
  7. #include "iritgrap.h"
  8. #include "getarg.h"
  9.  
  10. static char *CtrlStr =
  11.     "Lst_Sqrs n%-#Pts!d d%-Degree!d f%-DOF!d p%-PrgmName!s h%-";
  12.  
  13. void main(int argc, char **argv)
  14. {
  15.     int i, Error, PrgmInput, PrgmOutput,
  16.     NumOfPoints = 100,
  17.     NumOfPtsFlag = FALSE,
  18.     Degree = 3,
  19.     DegreeFlag = FALSE,
  20.     NumOfDOF = 10,
  21.     NumOfDOFFlag = FALSE,
  22.     PrgmFlag = FALSE,
  23.     HelpFlag = FALSE;
  24.     char *Err,
  25.     *Program = "x11drvs -s-";
  26.  
  27.     if ((Error = GAGetArgs(argc, argv, CtrlStr,
  28.                &NumOfPtsFlag, &NumOfPoints,
  29.                &DegreeFlag, &Degree,
  30.                &NumOfDOFFlag, &NumOfDOF,
  31.                &PrgmFlag, &Program,
  32.                &HelpFlag)) != 0) {
  33.     GAPrintErrMsg(Error);
  34.     GAPrintHowTo(CtrlStr);
  35.     exit(1);
  36.     }
  37.  
  38.     if (HelpFlag) {
  39.     GAPrintHowTo(CtrlStr);
  40.     exit(0);
  41.     }
  42.     if (IritPrsrSrvrExecAndConnect(Program, &PrgmInput, &PrgmOutput, TRUE)) {
  43.     char Line[LINE_LEN];
  44.     IPObjectStruct
  45.         *PClrObj = GenStrObject("command_", "clear", NULL);
  46.  
  47.     do {
  48.         CagdPtStruct
  49.         *PtList = NULL;
  50.         IPPolygonStruct
  51.         *PPoly = IPAllocPolygon(0, 0, NULL, NULL);
  52.         CagdCrvStruct *Crv;
  53.         IPObjectStruct *PCrvObj, *PPolyObj;
  54.  
  55.         for (i = 0; i < NumOfPoints; i++) {
  56.         int j;
  57.         IPVertexStruct *V;
  58.         CagdPtStruct
  59.             *Pt = CagdPtNew();
  60.  
  61.         if (i == 0) {
  62.             for (j = 0; j < 3; j++)
  63.             Pt -> Pt[j] = IritRandom(-1.0, 1.0);
  64.         }
  65.         else {
  66.             for (j = 0; j < 3; j++)
  67.             Pt -> Pt[j] = PtList -> Pt[j] + IritRandom(-0.1, 0.1);
  68.         }
  69.  
  70.         V = IPAllocVertex(0, 0, NULL, PPoly -> PVertex);
  71.         for (j = 0; j < 3; j++)
  72.             V -> Coord[j] = Pt -> Pt[j];
  73.         PPoly -> PVertex = V;
  74.  
  75.         LIST_PUSH(Pt, PtList);
  76.         }
  77.  
  78.         Crv = BspCrvInterpPts(PtList, Degree + 1,
  79.                   NumOfDOF, CAGD_UNIFORM_PARAM);
  80.         CagdPtFreeList(PtList);
  81.  
  82.         CagdCrvWriteToFile3(Crv, stdout, 0, "This is from LstSqrs", &Err);
  83.  
  84.         /* Generate objects out of the geometry and set proper attrs. */
  85.         PCrvObj = GenCRVObject(Crv);
  86.         AttrSetObjectColor(PCrvObj, IG_IRIT_GREEN);
  87.  
  88.         PPolyObj = GenPOLYObject(PPoly);
  89.         IP_SET_POLYLINE_OBJ(PPolyObj);
  90.         AttrSetObjectColor(PPolyObj, IG_IRIT_YELLOW);
  91.  
  92.         /* Clear old data and display our curve and data. */
  93.         SocWriteOneObject(PrgmInput, PClrObj);
  94.         SocWriteOneObject(PrgmInput, PCrvObj);
  95.         SocWriteOneObject(PrgmInput, PPolyObj);
  96.  
  97.         IPFreeObject(PCrvObj);
  98.         IPFreeObject(PPolyObj);
  99.  
  100.         gets(Line);
  101.     }
  102.     while (Line[0] != 'q' && Line[0] != 'Q');
  103.  
  104.     IritPrsrSrvrKillAndDisConnect(TRUE, PrgmInput, PrgmOutput);
  105.     }
  106.  
  107.     exit(0);
  108. }
  109.