Example #1
0
bool Mda::write64(const char* path) const
{
    if (QString(path).endsWith(".txt")) {
        return d->write_to_text_file(path, ' ');
    }
    if (QString(path).endsWith(".csv")) {
        return d->write_to_text_file(path, ',');
    }
    FILE* output_file = fopen(path, "wb");
    if (!output_file) {
        printf("Warning: Unable to open mda file for writing: %s\n", path);
        return false;
    }
    MDAIO_HEADER H;
    H.data_type = MDAIO_TYPE_FLOAT64;
    H.num_bytes_per_entry = 4;
    for (int i = 0; i < MDAIO_MAX_DIMS; i++)
        H.dims[i] = 1;
    for (int i = 0; i < MDA_MAX_DIMS; i++)
        H.dims[i] = d->dims(i);
    H.num_dims = d->determine_num_dims(N1(), N2(), N3(), N4(), N5(), N6());
    mda_write_header(&H, output_file);
    mda_write_float64((double*)d->constData(), &H, d->totalSize(), output_file);
    d->incrementBytesWrittenCounter(d->totalSize() * H.num_bytes_per_entry);
    fclose(output_file);
    return true;
}
Example #2
0
int main(){
  TTableContext Context;
  // create scheme
  Schema AnimalS;
  AnimalS.Add(TPair<TStr,TAttrType>("Animal", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Size", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Location", atStr));
  AnimalS.Add(TPair<TStr,TAttrType>("Number", atInt));
  TIntV RelevantCols;
  RelevantCols.Add(0);
  RelevantCols.Add(1);
  RelevantCols.Add(2);
  // create table
  PTable T = TTable::LoadSS("Animals", AnimalS, "tests/animals.txt", Context, RelevantCols);
  //PTable T = TTable::LoadSS("Animals", AnimalS, "animals.txt");
  T->Unique("Animal");
  TTable Ts = *T;  // did we fix problem with copy-c'tor ?
  //PTable Ts = TTable::LoadSS("Animals_s", AnimalS, "../../testfiles/animals.txt", RelevantCols);
  //Ts->Unique(AnimalUnique);

  // test Select
  // create predicate tree: find all animals that are big and african or medium and Australian
  TPredicate::TAtomicPredicate A1(atStr, true, EQ, "Location", "", 0, 0, "Africa");  
  TPredicate::TPredicateNode N1(A1);  // Location == "Africa"
  TPredicate::TAtomicPredicate A2(atStr, true, EQ, "Size", "", 0, 0, "big");  
  TPredicate::TPredicateNode N2(A2);  // Size == "big"
  TPredicate::TPredicateNode N3(AND);
  N3.AddLeftChild(&N1);
  N3.AddRightChild(&N2);
  TPredicate::TAtomicPredicate A4(atStr, true, EQ, "Location", "", 0, 0, "Australia");  
  TPredicate::TPredicateNode N4(A4);  
  TPredicate::TAtomicPredicate A5(atStr, true, EQ, "Size", "", 0, 0, "medium");  
  TPredicate::TPredicateNode N5(A5); 
  TPredicate::TPredicateNode N6(AND);
  N6.AddLeftChild(&N4);
  N6.AddRightChild(&N5);
  TPredicate::TPredicateNode N7(OR);
  N7.AddLeftChild(&N3);
  N7.AddRightChild(&N6);
  TPredicate Pred(&N7);
  TIntV SelectedRows;
  Ts.Select(Pred, SelectedRows);

  TStrV GroupBy;
  GroupBy.Add("Location");
  T->Group(GroupBy, "LocationGroup");
  GroupBy.Add("Size");
  T->Group(GroupBy, "LocationSizeGroup");
  T->Count("LocationCount", "Location");
  PTable Tj = T->Join("Location", Ts, "Location");
  TStrV UniqueAnimals;
  UniqueAnimals.Add("Animals_1.Animal");
  UniqueAnimals.Add("Animals_2.Animal");
  Tj->Unique(UniqueAnimals, false);
  //print table
   T->SaveSS("tests/animals_out_T.txt");
   Ts.SaveSS("tests/animals_out_Ts.txt");
   Tj->SaveSS("tests/animals_out_Tj.txt");
  return 0;
}
Example #3
0
double* Mda::dataPtr(bigint i1, bigint i2, bigint i3, bigint i4, bigint i5, bigint i6)
{
    const bigint N12 = N1() * N2();
    const bigint N13 = N12 * N3();
    const bigint N14 = N13 * N4();
    const bigint N15 = N14 * N5();

    return d->data() + (i1 + N1() * i2 + N12 * i3 + N13 * i4 + N14 * i5 + N15 * i6);
}
Example #4
0
bool Mda::reshape(bigint N1b, bigint N2b, bigint N3b, bigint N4b, bigint N5b, bigint N6b)
{
    if (N1b * N2b * N3b * N4b * N5b * N6b != this->totalSize()) {
        qWarning() << "Unable to reshape Mda, wrong total size";
        qWarning() << N1b << N2b << N3b << N4b << N5b << N6b;
        qWarning() << N1() << N2() << N3() << N4() << N5() << N6();
        return false;
    }
    d->setDims(N1b, N2b, N3b, N4b, N5b, N6b);
    return true;
}
Example #5
0
void N3()
{
	unsigned long dwReturnAddress;
	printf("In N3()\n");
	
	P_CODE_START
		for(int i = 0; i < 5; i++)
			printf("%d ", i);
	printf("\nCalling N4()\n");
	N4();
	P_CODE_END
	return;
}
Example #6
0
int main() {

  Nef_polyhedron N1(Nef_polyhedron::COMPLETE);

  Line l(2,4,2); // l : 2x + 4y + 2 = 0
  Nef_polyhedron N2(l,Nef_polyhedron::INCLUDED);
  Nef_polyhedron N3 = N2.complement();
  CGAL_assertion(N1 == N2.join(N3));

  Point p1(0,0), p2(10,10), p3(-20,15);
  Point triangle[3] = { p1, p2, p3 };
  Nef_polyhedron N4(triangle, triangle+3);
  Nef_polyhedron N5 = N2.intersection(N4);
  CGAL_assertion(N5 <= N2 && N5 <= N4);

  return 0;
}
Example #7
0
int main() {

  Nef_polyhedron N1(Plane_3( 1, 0, 0,-1),Nef_polyhedron::INCLUDED);
  Nef_polyhedron N2(Plane_3(-1, 0, 0,-1),Nef_polyhedron::INCLUDED);
  Nef_polyhedron N3(Plane_3( 0, 1, 0,-1),Nef_polyhedron::INCLUDED);
  Nef_polyhedron N4(Plane_3( 0,-1, 0,-1),Nef_polyhedron::INCLUDED);
  Nef_polyhedron N5(Plane_3( 0, 0, 1,-1),Nef_polyhedron::INCLUDED);
  Nef_polyhedron N6(Plane_3( 0, 0,-1,-1),Nef_polyhedron::INCLUDED);

  Nef_polyhedron I1(!N1+!N2);
  Nef_polyhedron I2(N3-!N4);
  Nef_polyhedron I3(N5^N6);
  Nef_polyhedron Cube1(I2 *!I1);
  Cube1 *= !I3;
  Nef_polyhedron Cube2 = N1 * N2 * N3 * N4 * N5 * N6;
  CGAL_assertion (Cube1 == Cube2);
  return 0;
}
Example #8
0
int main() {

  Nef_polyhedron N1(Nef_polyhedron::COMPLETE);

  Sphere_circle c(1,1,1); // c : x + y + z = 0
  Nef_polyhedron N2(c, Nef_polyhedron::INCLUDED);
  Nef_polyhedron N3(N2.complement());
  CGAL_assertion(N1 == N2.join(N3));

  Sphere_point   p1(1,0,0), p2(0,1,0), p3(0,0,1);
  Sphere_segment s1(p1,p2), s2(p2,p3), s3(p3,p1);
  Sphere_segment triangle[3] = { s1, s2, s3 };
  Nef_polyhedron N4(triangle, triangle+3);
  Nef_polyhedron N5;
  N5 += N2;
  N5 = N5.intersection(N4);
  CGAL_assertion(N5 <= N2 && N5 != N4);

  return 0;
}
Example #9
0
bool Mda::write16ui(const QString& path) const
{
    FILE* output_file = fopen(path.toLatin1().data(), "wb");
    if (!output_file) {
        printf("Warning: Unable to open mda file for writing: %s\n", path.toLatin1().data());
        return false;
    }
    MDAIO_HEADER H;
    H.data_type = MDAIO_TYPE_UINT16;
    H.num_bytes_per_entry = 2;
    for (int i = 0; i < MDAIO_MAX_DIMS; i++)
        H.dims[i] = 1;
    for (int i = 0; i < MDA_MAX_DIMS; i++)
        H.dims[i] = d->dims(i);
    H.num_dims = d->determine_num_dims(N1(), N2(), N3(), N4(), N5(), N6());
    mda_write_header(&H, output_file);
    mda_write_float64((double*)d->constData(), &H, d->totalSize(), output_file);
    d->incrementBytesWrittenCounter(d->totalSize() * H.num_bytes_per_entry);
    fclose(output_file);
    return true;
}
Example #10
0
int main() {
  Nef_polyhedron N0;
  Nef_polyhedron N1(Nef_polyhedron::EMPTY);
  Nef_polyhedron N2(Nef_polyhedron::COMPLETE);
  Nef_polyhedron N3(Plane_3( 1, 2, 5,-1));
  Nef_polyhedron N4(Plane_3( 1, 2, 5,-1), Nef_polyhedron::INCLUDED);
  Nef_polyhedron N5(Plane_3( 1, 2, 5,-1), Nef_polyhedron::EXCLUDED);

  CGAL_assertion(N0 == N1);
  CGAL_assertion(N3 == N4);
  CGAL_assertion(N0 != N2);
  CGAL_assertion(N3 != N5);

  CGAL_assertion(N4 >= N5);
  CGAL_assertion(N5 <= N4);
  CGAL_assertion(N4 > N5);
  CGAL_assertion(N5 < N4);

  N5 = N5.closure();
  CGAL_assertion(N4 >= N5);
  CGAL_assertion(N4 <= N5);

  return 0;
}
Example #11
0
int Mda::ndims() const
{
    return d->determine_num_dims(N1(), N2(), N3(), N4(), N5(), N6());
}
Example #12
0
void table(){
  static GLboolean first = GL_TRUE;
  static GLuint buffer, normalsBuffer, stripsBuffer, coordsBuffer;
  static Image images[3];
  static char *ppmNames[3] = {"glass.ppm", "table.ppm", "donut.ppm"};
  if (first) {
    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glGenTextures(3, texNames);
 
    getppm(ppmNames[1], &images[1]);
    
    GLfloat verts[4][3] = {
      {3.0, 3.0, 0.0}, {-3.0, 3.0, 0.0}, {-3.0, -3.0, 0.0}, {3.0, -3.0, 0.0}
    };
    
    plane(verts[1], verts[2], verts[3]);
    
    GLfloat normals[1][3];
    
    normals[0][0] = N4(verts[0][0], verts[1][0], verts[2][0], verts[3][0]);
    normals[0][1] = N4(verts[0][1], verts[1][1], verts[2][1], verts[3][1]);
    normals[0][2] = N4(verts[0][2], verts[1][2], verts[2][2], verts[3][2]);
    
    GLushort indices[4] = {0,1,2,3};
    
    GLfloat texCoords[4][2] = {
      {1,1},
      {0,1},
      {0,0},
      {1,0}
    };
    
    glGenBuffers(1, &buffer);
    glBindBuffer(GL_ARRAY_BUFFER, buffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(verts),
                 verts, GL_STATIC_DRAW);
    
    glGenBuffers(1, &normalsBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, normalsBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(normals),
                 normals, GL_STATIC_DRAW);
    
    glGenBuffers(1, &stripsBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, stripsBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices),
                 indices, GL_STATIC_DRAW);
    
    glGenBuffers(1, &coordsBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, coordsBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(texCoords),
                  texCoords, GL_STATIC_DRAW);    
    
    first = GL_FALSE;
  }
  
  glBindTexture(GL_TEXTURE_2D, texNames[1]);
  glTexParameteri(GL_TEXTURE_2D,
      GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri(GL_TEXTURE_2D,
      GL_TEXTURE_WRAP_T, GL_CLAMP);
  glTexParameteri(GL_TEXTURE_2D,
      GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,
      GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
    images[1].lW, images[1].lH, 0,
    GL_RGBA, GL_UNSIGNED_BYTE, images[1].rgba);

  
  glEnable(GL_TEXTURE_2D);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);
  
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glBindBuffer(GL_ARRAY_BUFFER, buffer); 
  glVertexPointer(3, GL_FLOAT, 0, (GLvoid*) 0);
  glBindBuffer(GL_ARRAY_BUFFER, normalsBuffer);
  glNormalPointer(GL_FLOAT, 0, (GLvoid*) 0);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, stripsBuffer);
  glBindBuffer(GL_ARRAY_BUFFER, coordsBuffer);
  glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*) 0);
  
  for (int i = 0, offset = 0; i < 1;
        i++, offset += 4*sizeof(GLushort))
    glDrawElements(GL_QUADS, 4,
                    GL_UNSIGNED_SHORT, (GLvoid*) offset);
  glDisable(GL_TEXTURE_2D);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
   Matrix3x3d
   computeIntersectionCovariance(vector<Matrix3x4d> const& projections,
                                 vector<PointMeasurement> const& measurements,
                                 double sigma)
   {
      Matrix<double> Cp(3, 3, 0.0);
      Cp[0][0] = Cp[1][1] = sigma;
      Cp[2][2] = 0.0;

      int const N = measurements.size();

      Matrix<double> A(2*N, 4, 0.0);
      InlineMatrix<double, 2, 3> Sp;
      makeZeroMatrix(Sp);
      InlineMatrix<double, 2, 4> Sp_P;
      for (int i = 0; i < N; ++i)
      {
         Sp[0][1] = -1; Sp[0][2] = measurements[i].pos[1];
         Sp[1][0] =  1; Sp[1][2] = -measurements[i].pos[0];

         int const view = measurements[i].view;
         multiply_A_B(Sp, projections[view], Sp_P);

         A[2*i+0][0] = Sp_P[0][0]; A[2*i+0][1] = Sp_P[0][1]; A[2*i+0][2] = Sp_P[0][2]; A[2*i+0][3] = Sp_P[0][3];
         A[2*i+1][0] = Sp_P[1][0]; A[2*i+1][1] = Sp_P[1][1]; A[2*i+1][2] = Sp_P[1][2]; A[2*i+1][3] = Sp_P[1][3];
      } // end for (i)

      SVD<double> svd(A);

      Matrix<double> V;
      svd.getV(V);

      Vector4d X;
      X[0] = V[0][3]; X[1] = V[1][3]; X[2] = V[2][3]; X[3] = V[3][3];

      Vector3d P;
      Matrix<double> S(2, 3, 0.0);
      Matrix<double> B(2*N, 3*N, 0.0);

      for (int i = 0; i < N; ++i)
      {
         int const view = measurements[i].view;
         multiply_A_v(projections[view], X, P);
         P[0] /= P[2]; P[1] /= P[2]; P[2] = 1.0;

         S[0][1] = -P[2]; S[0][2] =  P[1];
         S[1][0] =  P[2]; S[1][2] = -P[0];

         B[2*i+0][3*i+0] = -S[0][0]; B[2*i+0][3*i+1] = -S[0][1]; B[2*i+0][3*i+2] = S[0][2];
         B[2*i+1][3*i+0] = -S[1][0]; B[2*i+1][3*i+1] = -S[1][1]; B[2*i+1][3*i+2] = S[1][2];
      } // end for (i)

      Matrix<double> C(3*N, 3*N, 0.0);
      for (int i = 0; i < N; ++i)
      {
         C[3*i+0][3*i+0] = Cp[0][0]; C[3*i+0][3*i+1] = Cp[0][1]; C[3*i+0][3*i+2] = Cp[0][2];
         C[3*i+1][3*i+0] = Cp[1][0]; C[3*i+1][3*i+1] = Cp[1][1]; C[3*i+1][3*i+2] = Cp[1][2];
         C[3*i+2][3*i+0] = Cp[2][0]; C[3*i+2][3*i+1] = Cp[2][1]; C[3*i+2][3*i+2] = Cp[2][2];
      } // end for (i)

      Matrix<double> B_C(2*N, 3*N);
      multiply_A_B(B, C, B_C);
      Matrix<double> T(2*N, 2*N);
      multiply_A_Bt(B_C, B, T);

      Matrix<double> Tinv;
      invertMatrix(T, Tinv);

      Matrix<double> NN(5, 5), N4(4, 4);
      Matrix<double> At_Tinv(4, 2*N);
      multiply_At_B(A, Tinv, At_Tinv);
      multiply_A_B(At_Tinv, A, N4);

      for (int r = 0; r < 4; ++r)
         for (int c = 0; c < 4; ++c)
            NN[r][c] = N4[r][c];

      NN[0][4] = NN[4][0] = X[0];
      NN[1][4] = NN[4][1] = X[1];
      NN[2][4] = NN[4][2] = X[2];
      NN[3][4] = NN[4][3] = X[3];
      NN[4][4] = 0.0;

      Matrix<double> Ninv(5, 5);
      invertMatrix(NN, Ninv);

      Matrix4x4d sigma_XX;
      for (int r = 0; r < 4; ++r)
         for (int c = 0; c < 4; ++c)
            sigma_XX[r][c] = Ninv[r][c];

      Matrix3x4d Je;
      makeZeroMatrix(Je);
      Je[0][0] = Je[1][1] = Je[2][2] = 1.0 / X[3];
      Je[0][3] = -X[0] / (X[3]*X[3]);
      Je[1][3] = -X[1] / (X[3]*X[3]);
      Je[2][3] = -X[2] / (X[3]*X[3]);

      Matrix3x3d sigma_X = Je * sigma_XX * Je.transposed();
      return sigma_X;
   }