示例#1
0
double arlCore::Mesh::getRMSDistance( void ) const
{
    double distance = 0.0;
    unsigned int i, j;
    const unsigned int Size = (unsigned int)m_triangles.size();
    for( i=0 ; i<Size ; ++i )
    {
        vnl_vector_fixed<double,3> lengths = getLengths(i);
        for( j=0 ; j<3 ; ++j )
            distance += lengths[j]*lengths[j];
    }
    return sqrt(distance/(double)(Size*3));
}
示例#2
0
bool arlCore::Mesh::resampling( double step )
{
    if(step<=0) return false;
    unsigned int i, j;
    const double Tol = 2.0*step;
    std::vector<arlCore::Point::sptr > points(3);
    for( i=0 ; i<(unsigned int)m_triangles.size() ; )
    {
        vnl_vector_fixed<double,3> lengths = getLengths(i);
        if((lengths[0]+lengths[1])>=Tol)
        {
            std::vector<unsigned int> index(6);
            for( j=0 ; j<3 ; ++j )
                index[j] = m_triangles[i][j];
            const arlCore::Point::sptr A = (*m_pointList)[index[0]];
            const arlCore::Point::sptr B = (*m_pointList)[index[1]];
            const arlCore::Point::sptr C = (*m_pointList)[index[2]];
            m_freeTriangles.push_back(i);
            --m_nbReferences[m_triangles[i][0]];
            --m_nbReferences[m_triangles[i][1]];
            --m_nbReferences[m_triangles[i][2]];
            for( j=0 ; j<3 ; ++j )
            {
                points[0]->set(j, ( (*A)[j]+(*B)[j])/2.0);
                points[1]->set(j, ( (*B)[j]+(*C)[j])/2.0);
                points[2]->set(j, ( (*C)[j]+(*A)[j])/2.0);
            }
            for( j=0 ; j<3 ; ++j )
                index[3+j] = addPoint(points[j]);
            addTriangle( index[0], index[3], index[5] );
            addTriangle( index[3], index[1], index[4] );
            addTriangle( index[4], index[2], index[5] );
            addTriangle( index[5], index[3], index[4] );
        }else ++i;
    }
    assert(m_freePoints.size()==0);
    assert(m_freeTriangles.size()==0);
    return true;
}
示例#3
0
/* void getParams()
 * Parses the command line.
 */
void getParams(int argc, char** argv) {

  char* outFile = NULL, *inFile = NULL, *primFile = NULL,
    *bedFile = NULL, *fwdPos = NULL, *revPos = NULL,
    *bedPos = NULL, *logFile = NULL, *wasteFile = NULL,
    *corrFile = NULL;
  int misAllow = 0, revLen = 0, revMis = 0, revLMis = 0,
    revOpt = 0;

  // parse argv
  for (int i = 1; i < argc; i++) {
    if (!strcmp(argv[i], HELP))
      usage();
    else if (!strcmp(argv[i], REVOPT))
      revOpt = 1;
    else if (i < argc - 1) {
      if (!strcmp(argv[i], OUTFILE))
        outFile = argv[++i];
      else if (!strcmp(argv[i], INFILE))
        inFile = argv[++i];
      else if (!strcmp(argv[i], PRIMFILE))
        primFile = argv[++i];
      else if (!strcmp(argv[i], BEDFILE))
        bedFile = argv[++i];
      else if (!strcmp(argv[i], FWDPOS))
        fwdPos = argv[++i];
      else if (!strcmp(argv[i], REVPOS))
        revPos = argv[++i];
      else if (!strcmp(argv[i], BEDPOS))
        bedPos = argv[++i];
      else if (!strcmp(argv[i], LOGFILE))
        logFile = argv[++i];
      else if (!strcmp(argv[i], WASTEFILE))
        wasteFile = argv[++i];
      else if (!strcmp(argv[i], MISALLOW))
        misAllow = getInt(argv[++i]);
      else if (!strcmp(argv[i], REVMIS))
        revMis = getInt(argv[++i]);
      else if (!strcmp(argv[i], REVLENGTH))
        revLen = getInt(argv[++i]);
      else if (!strcmp(argv[i], REVLMIS))
        revLMis = getInt(argv[++i]);
      else if (!strcmp(argv[i], CORRFILE))
        corrFile = argv[++i];
      else
        exit(error(argv[i], ERRINVAL));
    } else
      exit(error(argv[i], ERRINVAL));
  }

  if (outFile == NULL || inFile == NULL || primFile == NULL)
    usage();
  int gz = 0;
  if (!strcmp(inFile + strlen(inFile) - strlen(GZEXT), GZEXT))
    gz = 1;

  // open files, load primer sequences
  File out, in, waste, corr;
  FILE* prim = NULL, *log = NULL, *bed = NULL;
  openFiles(outFile, &out, primFile, &prim, inFile, &in,
    logFile, &log, bedFile, &bed, wasteFile, &waste,
    corrFile, &corr, gz);
  int pr = loadSeqs(prim);

  // get start and end locations
  int fwdSt = 0, fwdEnd = 1, revSt = 0, revEnd = 1,
    bedSt = 0, bedEnd = 1;
  getPos(fwdPos, &fwdSt, &fwdEnd);
  getPos(revPos, &revSt, &revEnd);
  if (bed != NULL) {
    getLengths(bed);
    getPos(bedPos, &bedSt, &bedEnd);
  }

  // read file
  int match = 0, rcmatch = 0;  // counting variables
  int count = readFile(in, out, misAllow, &match, &rcmatch,
    fwdSt, fwdEnd, revSt, revEnd, bedSt, bedEnd,
    waste, wasteFile != NULL, revMis, revLen, revLMis,
    revOpt, corr, corrFile != NULL, gz);

  // print log output
  if (log != NULL) {
    fprintf(log, "Primer pairs: %d\nRead count: %d\n", pr, count);
    fprintf(log, "Primer matches: %d\nBoth primer matches: %d\n\n", match, rcmatch);
    fprintf(log, "Matches:\nPrimer\tFwd\tFwd-Both\tRev\tRev-Both\n");
    for (Primer* p = primo; p != NULL; p = p->next)
      fprintf(log, "%s\t%d\t%d\t%d\t%d\n", p->name, p->fcount, p->fcountr,
        p->rcount, p->rcountr);
  }

  // close files
  if ( (gz && (gzclose(in.gzf) != Z_OK || gzclose(out.gzf) != Z_OK ||
      (wasteFile != NULL && gzclose(waste.gzf) != Z_OK) ||
      (corrFile != NULL && gzclose(corr.gzf) != Z_OK) ) ) ||
      ( ! gz && (fclose(in.f) || fclose(out.f) ||
      (wasteFile != NULL && fclose(waste.f)) ||
      (corrFile != NULL && fclose(corr.f)) ) ) ||
      fclose(prim) || (log != NULL && fclose(log)) ||
      (bed != NULL && fclose(bed)) )
    exit(error("", ERRCLOSE));
}