コード例 #1
0
ファイル: InitFilesIO.cpp プロジェクト: FrankieLi/IceNine
  //------------------------------
  //
  //  ReadFundamentalZoneFile
  //
  //------------------------------
  bool ReadFundamentalZoneFile( vector<SVector3> & vFZEulerAngleList,
                                const string & sFilename )
  {
    char *pBuffer = NULL;
    Size_Type nBufSize = 0;
    vector< vector<string> > vsTokens;
	
    pBuffer = ReadFileToBuf(nBufSize, sFilename);
    if(pBuffer == NULL){
      return false;
    }

    string sBuffStr( pBuffer, nBufSize );
    
    GeneralLib::Tokenize( vsTokens, sBuffStr, ",# \t\n");
    
    for(Size_Type i = 0; i < vsTokens.size(); i ++){
      
      RUNTIME_ASSERT( (vsTokens[i].size() >= 3), 
                      "[ReadFundamentalZoneFile] ERROR: Invalid Euler Angles\n");
      
      
      Float fPhi   = DEGREE_TO_RADIAN( atof( vsTokens[i][0].c_str() ) );
      Float fTheta = DEGREE_TO_RADIAN( atof( vsTokens[i][1].c_str() ) );
      Float fPsi   = DEGREE_TO_RADIAN( atof( vsTokens[i][2].c_str() ) );

      SVector3 newAngles;

      newAngles.Set( fPhi, fTheta, fPsi );

      vFZEulerAngleList.push_back( newAngles );
    }


    delete [] pBuffer;
    return true;
  }
コード例 #2
0
ファイル: MicIO.cpp プロジェクト: CMU-Suter-Group/XDMXX
//---------------------------------------------------------
//
//  Public:
//  Read
//
//
//---------------------------------------------------------
//      MIC file format
//
// line 1: a0, the fundamental lattice constant for the triangular mesh
//
// others:
//
// columns 1 -3: xyz location of left vertex of a triangle
// column 4: 1/2 for triangle type -- 1 for upward pointing or 2 for downward
// pointing
// column 5: generation number -- triangle side length = a0/(2^generation),
// generation = 0,1,2,...
// column 6: 0/1 for phase -- 0 mean it wasn't (or hasn't yet) fitted to an
// orientation, 1 means it was
// columns 7 -9: Eulers in degrees
// column 10: confidence parameter: fraction of simulated Bragg peaks that hit
// experimental peaks
//---------------------------------------------------------
bool CMic::ReadEffient( const string &filename )
{
 
  vector< vector<string> > vsTokens;

  if( !ReadFileToBuf(filename))
  {
    return false;
  }

  std::ifstream InputStream;
  if( !InputStream.open( filename ) )
    return false;


  std::string Tokens = " \t\n";
  //  GeneralLib::Tokenize( vsTokens, string( pBuffer, nBufferSize ), " \t\n");
  // we expect side length for the first line
	
  if(vsTokens[0].size() > 1){
    cerr << "[CMic::ReadMicFile] Incorrect Mic File Format " << filename << endl;
    exit(0);
  }
	
  //  fInitialSideLength = atof(vsTokens[0][0].c_str());
  //  for( Size_Type i = 1; i < vsTokens.size(); i ++){

  while()
  {
    if(vsTokens[i].size() < 9 )
    {
      cerr << "[CMic::ReadMicFile] Error: Incorrect number of columns, line: "
           << i  << filename << endl;
    }
    else
    {
      DEBUG_ALERT( vsTokens[i].size() >= 10, "CMic::Read:  Warning!  Old format MIC file with only 9 columns\n" );
      SVoxel v;

      v.nGeneration = atoi( vsTokens[i][4].c_str() );
      v.fSideLength = fInitialSideLength / pow( 2,  v.nGeneration ) ;
      v.nPhase = atoi( vsTokens[i][5].c_str() );

      Float fX, fY, fZ;

      fX = atof( vsTokens[i][0].c_str() );
      fY = atof( vsTokens[i][1].c_str() );
      fZ = atof( vsTokens[i][2].c_str() );

      if ( atoi( vsTokens[i][3].c_str() ) == UP  ) 
      {
        // Winding order, counter clockwise
        v.pVertex[0].Set( fX,                 fY, fZ );
        v.pVertex[1].Set( fX + v.fSideLength, fY, fZ );
        v.pVertex[2].Set( fX + v.fSideLength / (Float) 2.0 , fY + v.fSideLength / (Float) 2.0 * sqrt( (Float) 3.0 ) , fZ);
        v.bVoxelPointsUp = true;
      }
      else
      {
        // Winding order, counter clockwise
        v.pVertex[0].Set( fX,                 fY, fZ );
        v.pVertex[1].Set( fX + v.fSideLength / (Float) 2.0 , fY - v.fSideLength / (Float) 2.0 * sqrt( (Float) 3.0 ) , fZ);
        v.pVertex[2].Set( fX + v.fSideLength, fY, fZ );
        v.bVoxelPointsUp = false;
      }

      SVector3 oOrientation;
      oOrientation.Set(  DEGREE_TO_RADIAN( atof(vsTokens[i][6].c_str()) ),
                         DEGREE_TO_RADIAN( atof(vsTokens[i][7].c_str()) ),
                         DEGREE_TO_RADIAN( atof(vsTokens[i][8].c_str()) ) );
      
      // note that orientation matrix assigned here - the choice of active vs. passive
      // transform is made by the file format

      v.oOrientMatrix.BuildActiveEulerMatrix( oOrientation.m_fX,
                                              oOrientation.m_fY,
                                              oOrientation.m_fZ );
      
      if( vsTokens[i].size() > 9 )
        v.fConfidence = atof( vsTokens[i][9].c_str() );
      else
        v.fConfidence = 0;
      
      if( vsTokens[i].size() == 19 )   //  Defining our strain tensor to be ( I)
      {
        v.fCost                = atof( vsTokens[i][10].c_str() );
        v.fPixelOverlapRatio   = atof( vsTokens[i][11].c_str() );
        v.oDeformation.m[0][0] = atof( vsTokens[i][13].c_str() );
        v.oDeformation.m[1][1] = atof( vsTokens[i][14].c_str() );
        v.oDeformation.m[2][2] = atof( vsTokens[i][15].c_str() );
        
        v.oDeformation.m[0][1] = v.oDeformation.m[1][0] = atof( vsTokens[i][16].c_str() );
        v.oDeformation.m[1][2] = v.oDeformation.m[2][1] = atof( vsTokens[i][17].c_str() );
        v.oDeformation.m[0][2] = v.oDeformation.m[2][0] = atof( vsTokens[i][18].c_str() );
      }
      else
      {
        v.oDeformation.SetIdentity();
      }
      
      oVoxelList.push_back(v);
    }	

  }

  ClearBuffer();  // clear buffer after use
  return true;
}