Exemple #1
0
int processCommand(struct InputParserC * ipc , struct motionStats * st ,char * line , unsigned int words_count , unsigned int startAtFrame)
{

  if (InputParser_WordCompareAuto(ipc,0,"MOVE"))
   {
      int frameNum = InputParser_GetWordInt(ipc,2);
      if (frameNum<startAtFrame) { return 0; }

      float x = InputParser_GetWordFloat(ipc,3);
      float y = InputParser_GetWordFloat(ipc,4);
      float z = InputParser_GetWordFloat(ipc,5);

      float qW = InputParser_GetWordFloat(ipc,6);
      float qX = InputParser_GetWordFloat(ipc,7);
      float qY = InputParser_GetWordFloat(ipc,8);
      float qZ = InputParser_GetWordFloat(ipc,9);

      updatePosition(st,x,y,z,qW,qX,qY,qZ);
   }
    else
  if (InputParser_WordCompareAuto(ipc,0,"POSE"))
   {
    int frameNum = InputParser_GetWordInt(ipc,2);
    if (frameNum<startAtFrame) { return 0; }

    //fprintf(stdout,"Found Frame %u \n",InputParser_GetWordInt(ipc,1));
    char str[128];
    if (InputParser_GetWord(ipc,3,str,128)!=0)
    {//Flush next frame
      float x = InputParser_GetWordFloat(ipc,4);
      float y = InputParser_GetWordFloat(ipc,5);
      float z = InputParser_GetWordFloat(ipc,6);

      unsigned int where2work=0;
      if  ( getJointMemoryID(st,str,&where2work) )
      {
        updateJoint(st,where2work,x,y,z);
      }


      //fprintf(stdout," %0.2f %0.2f %0.2f \n",x,y,z);
      return 1;
    }
   }

  return 0;
}
int readVirtualStream(struct VirtualStream * newstream)
{
  #if USE_FILE_INPUT

  #if PRINT_DEBUGGING_INFO
  fprintf(stderr,"readVirtualStream(%s) called \n",newstream->filename);
  #endif

  //Our stack variables ..
  unsigned int readOpResult = 0;
  char line [LINE_MAX_LENGTH]={0};

  //Try and open filename
  FILE * fp = fopen(newstream->filename,"r");
  if (fp == 0 ) { fprintf(stderr,"Cannot open trajectory stream %s \n",newstream->filename); return 0; }

  //Find out the size of the file..!
  fseek (fp , 0 , SEEK_END);
  unsigned long lSize = ftell (fp);
  rewind (fp);
  fprintf(stderr,"Opening a %lu byte file %s \n",lSize,newstream->filename);

  //Allocate a token parser
  struct InputParserC * ipc=0;
  ipc = InputParser_Create(LINE_MAX_LENGTH,5);
  if (ipc==0)  { fprintf(stderr,"Cannot allocate memory for new stream\n"); return 0; }

  newstream->fileSize = lSize;

  //Add a dummy CAMERA Object here!
  growVirtualStreamObjectsTypes(newstream,OBJECT_TYPES_TO_ADD_STEP);
  strcpy( newstream->objectTypes[0].name , "camera" );
  strcpy( newstream->objectTypes[0].model , "camera" );
  ++newstream->numberOfObjectTypes;

  growVirtualStreamObjects(newstream,OBJECTS_TO_ADD_STEP);
  strcpy( newstream->object[0].name, "camera");
  strcpy( newstream->object[0].typeStr, "camera");
  strcpy( newstream->object[0].value, "camera");
  newstream->object[0].type = 0; //Camera
  newstream->object[0].R =0;
  newstream->object[0].G =0;
  newstream->object[0].B =0;
  newstream->object[0].Transparency=0;
  ++newstream->numberOfObjects;
  // CAMERA OBJECT ADDED

  newstream->debug=0;
 //Everything is set , Lets read the file!
  while (!feof(fp))
  {
   //We get a new line out of the file
   readOpResult = (fgets(line,LINE_MAX_LENGTH,fp)!=0);
   if ( readOpResult != 0 )
    {
      //We tokenize it
      unsigned int words_count = InputParser_SeperateWords(ipc,line,0);
      if ( words_count > 0 )
         {
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"DEBUG",5)==1)
            {
              fprintf(stderr,"DEBUG Mode on\n");
              newstream->debug=1;
            } else

            /*! REACHED AN AUTO REFRESH DECLERATION ( AUTOREFRESH(1500) )
              argument 0 = AUTOREFRESH , argument 1 = value in milliseconds (0 = off ) */
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"AUTOREFRESH",11)==1)
            {
                newstream->autoRefresh = InputParser_GetWordInt(ipc,1);
            } else
            /*! REACHED AN INTERPOLATE TIME SWITCH DECLERATION ( INTERPOLATE_TIME(1) )
              argument 0 = INTERPOLATE_TIME , argument 1 = (0 = off ) ( 1 = on )*/
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"INTERPOLATE_TIME",16)==1)
            {
                //The configuration INTERPOLATE_TIME is the "opposite" of this flag ignore time
                newstream->ignoreTime = InputParser_GetWordInt(ipc,1);
                // so we flip it here.. , the default is not ignoring time..
                if (newstream->ignoreTime == 0 ) { newstream->ignoreTime=1; } else
                                                 { newstream->ignoreTime=0; }
            } else
              /*! REACHED AN BACKGROUND DECLERATION ( BACKGROUND(0,0,0) )
              argument 0 = BACKGROUND , argument 1 = R , argument 2 = G , argument 3 = B , */
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"BACKGROUND",10)==1)
            {
                //The configuration INTERPOLATE_TIME is the "opposite" of this flag ignore time
                newstream->backgroundR = (float) InputParser_GetWordInt(ipc,1) / 255;
                newstream->backgroundG = (float) InputParser_GetWordInt(ipc,2) / 255;
                newstream->backgroundB = (float) InputParser_GetWordInt(ipc,3) / 255;
                // so we flip it here.. , the default is not ignoring time..
            } else
            /*! REACHED AN OBJECT TYPE DECLERATION ( OBJECTTYPE(spatoula_type,"spatoula.obj") )
              argument 0 = OBJECTTYPE , argument 1 = name ,  argument 2 = value */
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"OBJECTTYPE",10)==1)
            {
               char name[MAX_PATH]={0};
               char model[MAX_PATH]={0};
               InputParser_GetWord(ipc,1,name,MAX_PATH);
               InputParser_GetWord(ipc,2,model,MAX_PATH);

               addObjectTypeToVirtualStream( newstream , name, model );

            } else
            /*! REACHED AN OBJECT DECLERATION ( OBJECT(something,spatoula_type,0,255,0,0,0,1.0,spatoula_something) )
              argument 0 = OBJECT , argument 1 = name ,  argument 2 = type ,  argument 3-5 = RGB color  , argument 6 Transparency , argument 7 = No Color , argument 8 = Scale
              argument 9 = String Freely formed Data */
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"OBJECT",6)==1)
            {
               char name[MAX_PATH]={0} , typeStr[MAX_PATH]={0};
               InputParser_GetWord(ipc,1,name,MAX_PATH);
               InputParser_GetWord(ipc,2,typeStr,MAX_PATH);

               unsigned char R = (unsigned char) InputParser_GetWordInt(ipc,3);
               unsigned char G = (unsigned char)  InputParser_GetWordInt(ipc,4);
               unsigned char B = (unsigned char)  InputParser_GetWordInt(ipc,5);
               unsigned char Alpha = (unsigned char)  InputParser_GetWordInt(ipc,6) ;
               unsigned char nocolor = (unsigned char) InputParser_GetWordInt(ipc,7);
               float scale = (float) InputParser_GetWordFloat(ipc,8);

               //Value , not used : InputParser_GetWord(ipc,8,newstream->object[pos].value,15);
               addObjectToVirtualStream(newstream ,name,typeStr,R,G,B,Alpha,nocolor,0,0,scale);

            } else
            /*! REACHED A POSITION DECLERATION ( POS(hand,0,   0.0,0.0,0.0 , 0.0,0.0,0.0,0.0 ) )
              argument 0 = POS , argument 1 = name ,  argument 2 = time in MS , argument 3-5 = X,Y,Z , argument 6-9 = Rotations*/
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"POS",3)==1)
            {
               char name[MAX_PATH];
               InputParser_GetWord(ipc,1,name,MAX_PATH);
               unsigned int time = InputParser_GetWordInt(ipc,2);

               float pos[7]={0};
               pos[0] = InputParser_GetWordFloat(ipc,3);
               pos[1] = InputParser_GetWordFloat(ipc,4);
               pos[2] = InputParser_GetWordFloat(ipc,5);
               pos[3] = InputParser_GetWordFloat(ipc,6);
               pos[4] = InputParser_GetWordFloat(ipc,7);
               pos[5] = InputParser_GetWordFloat(ipc,8);
               pos[6] = InputParser_GetWordFloat(ipc,9);
               int coordLength=7;

              addPositionToObject( newstream , name  , time , (float*) pos , coordLength );
            }
             else
            /*! REACHED A PROJECTION MATRIX DECLERATION ( PROJECTION_MATRIX( ... 16 values ... ) )
              argument 0 = PROJECTION_MATRIX , argument 1-16 matrix values*/
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"PROJECTION_MATRIX",17)==1)
            {
               newstream->projectionMatrixDeclared=1;
               int i=1;
               for (i=1; i<=16; i++) { newstream->projectionMatrix[i-1] = (double)  InputParser_GetWordFloat(ipc,i); }
               fprintf(stderr,"Projection Matrix given to TrajectoryParser\n");
            }
             else
            /*! REACHED A MODELVIEW MATRIX DECLERATION ( MODELVIEW_MATRIX( ... 16 values ... ) )
              argument 0 = MODELVIEW_MATRIX , argument 1-16 matrix values*/
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"MODELVIEW_MATRIX",16)==1)
            {
               newstream->modelViewMatrixDeclared=1;
               int i=1;
               for (i=1; i<=16; i++) { newstream->modelViewMatrix[i-1] = (double) InputParser_GetWordFloat(ipc,i); }
               fprintf(stderr,"ModelView Matrix given to TrajectoryParser\n");
            }
         } // End of line containing tokens
    } //End of getting a line while reading the file
  }

  fclose(fp);
  InputParser_Destroy(ipc);

  return 1;
  #else
    fprintf(stderr,RED "This build of Trajectory parser does not have File Input compiled in!\n" NORMAL);
    fprintf(stderr,YELLOW "Please rebuild after setting USE_FILE_INPUT to 1 on file TrajectoryParser.cpp or .c\n" NORMAL);
    fprintf(stderr,YELLOW "also note that by enabling file input you will also need to link with InputParser_C.cpp or .c \n" NORMAL);
    fprintf(stderr,YELLOW "It can be found here https://github.com/AmmarkoV/InputParser/ \n" NORMAL);
  #endif

 return 0;
}