コード例 #1
0
ファイル: mda.cpp プロジェクト: magland/mountainlab
void Mda::setChunk(Mda& X, bigint i1, bigint i2, bigint i3)
{
    bigint size1 = X.N1();
    bigint size2 = X.N2();
    bigint size3 = X.N3();

    bigint a1_begin = i1;
    bigint x1_begin = 0;
    bigint a1_end = i1 + size1 - 1;
    bigint x1_end = size1 - 1;
    if (a1_begin < 0) {
        a1_begin += 0 - a1_begin;
        x1_begin += 0 - a1_begin;
    }
    if (a1_end >= N1()) {
        a1_end += N1() - 1 - a1_end;
        x1_end += N1() - 1 - a1_end;
    }

    bigint a2_begin = i2;
    bigint x2_begin = 0;
    bigint a2_end = i2 + size2 - 1;
    bigint x2_end = size2 - 1;
    if (a2_begin < 0) {
        a2_begin += 0 - a2_begin;
        x2_begin += 0 - a2_begin;
    }
    if (a2_end >= N2()) {
        a2_end += N2() - 1 - a2_end;
        x2_end += N2() - 1 - a2_end;
    }

    bigint a3_begin = i3;
    bigint x3_begin = 0;
    bigint a3_end = i3 + size3 - 1;
    bigint x3_end = size3 - 1;
    if (a3_begin < 0) {
        a2_begin += 0 - a3_begin;
        x3_begin += 0 - a3_begin;
    }
    if (a3_end >= N3()) {
        a3_end += N3() - 1 - a3_end;
        x3_end += N3() - 1 - a3_end;
    }

    double* ptr1 = this->dataPtr();
    double* ptr2 = X.dataPtr();

    for (bigint ind3 = 0; ind3 <= a3_end - a3_begin; ind3++) {
        for (bigint ind2 = 0; ind2 <= a2_end - a2_begin; ind2++) {
            bigint ii_out = (ind2 + x2_begin) * size1 + (ind3 + x3_begin) * size1 * size2;
            bigint ii_in = (ind2 + a2_begin) * N1() + (ind3 + a3_begin) * N1() * N2();
            for (bigint ind1 = 0; ind1 <= a1_end - a1_begin; ind1++) {
                ptr1[ii_in] = ptr2[ii_out];
                ii_in++;
                ii_out++;
            }
        }
    }
}
コード例 #2
0
ファイル: mda.cpp プロジェクト: magland/mountainlab
void Mda::getChunk(Mda& ret, bigint i1, bigint i2, bigint i3, bigint size1, bigint size2, bigint size3) const
{
    // A lot of bugs fixed on 5/31/16
    bigint a1_begin = i1;
    bigint x1_begin = 0;
    bigint a1_end = i1 + size1 - 1;
    bigint x1_end = size1 - 1;
    if (a1_begin < 0) {
        x1_begin += 0 - a1_begin;
        a1_begin += 0 - a1_begin;
    }
    if (a1_end >= N1()) {
        x1_end += N1() - 1 - a1_end;
        a1_end += N1() - 1 - a1_end;
    }

    bigint a2_begin = i2;
    bigint x2_begin = 0;
    bigint a2_end = i2 + size2 - 1;
    bigint x2_end = size2 - 1;
    if (a2_begin < 0) {
        x2_begin += 0 - a2_begin;
        a2_begin += 0 - a2_begin;
    }
    if (a2_end >= N2()) {
        x2_end += N2() - 1 - a2_end;
        a2_end += N2() - 1 - a2_end;
    }

    bigint a3_begin = i3;
    bigint x3_begin = 0;
    bigint a3_end = i3 + size3 - 1;
    bigint x3_end = size3 - 1;
    if (a3_begin < 0) {
        x3_begin += 0 - a3_begin;
        a3_begin += 0 - a3_begin;
    }
    if (a3_end >= N3()) {
        x3_end += N3() - 1 - a3_end;
        a3_end += N3() - 1 - a3_end;
    }

    ret.allocate(size1, size2, size3);

    const double* ptr1 = this->constDataPtr();
    double* ptr2 = ret.dataPtr();

    for (bigint ind3 = 0; ind3 <= a3_end - a3_begin; ind3++) {
        for (bigint ind2 = 0; ind2 <= a2_end - a2_begin; ind2++) {
            bigint ii_out = x1_begin + (ind2 + x2_begin) * size1 + (ind3 + x3_begin) * size1 * size2; //bug fixed on 5/31/16 by jfm
            bigint ii_in = a1_begin + (ind2 + a2_begin) * N1() + (ind3 + a3_begin) * N1() * N2(); //bug fixed on 5/31/16 by jfm
            for (bigint ind1 = 0; ind1 <= a1_end - a1_begin; ind1++) {
                ptr2[ii_out] = ptr1[ii_in];
                ii_in++;
                ii_out++;
            }
        }
    }
}
コード例 #3
0
ファイル: mda.cpp プロジェクト: magland/mountainlab
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;
}
コード例 #4
0
void ViewmdaModel::setC3(int i) {
	if (m_d3<0) return;
	if (C3()==i) return;
	if ((i<0)||(i>=N3())) return;
	m_current_index[m_d3]=i;
	emit currentSliceChanged();	
} 
コード例 #5
0
ファイル: TableTest.cpp プロジェクト: mayankgupta/snapr
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;
}
コード例 #6
0
ファイル: mda.cpp プロジェクト: magland/mountainlab
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);
}
コード例 #7
0
ファイル: mda.cpp プロジェクト: magland/mountainlab
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;
}
コード例 #8
0
ファイル: test_file.cpp プロジェクト: m0n0ph1/Kryptonite
void N2()
{
	unsigned long dwReturnAddress;
	printf("In N2()\n");
	
	P_CODE_START
		for(int i = 0; i < 5; i++)
			printf("%d ", i);
	printf("\nCalling N3()\n");
	N3();
	P_CODE_END
	return;
}
コード例 #9
0
ファイル: Element.C プロジェクト: Jieun2/moose
void
Element::polarDecompositionEigen( const ColumnMajorMatrix & Fhat, ColumnMajorMatrix & Rhat, SymmTensor & strain_increment )
{
  const int ND = 3;

  ColumnMajorMatrix eigen_value(ND,1), eigen_vector(ND,ND);
  ColumnMajorMatrix invUhat(ND,ND), logVhat(ND,ND);
  ColumnMajorMatrix n1(ND,1), n2(ND,1), n3(ND,1), N1(ND,1), N2(ND,1), N3(ND,1);

  ColumnMajorMatrix Chat = Fhat.transpose() * Fhat;

  Chat.eigen(eigen_value,eigen_vector);

  for(int i = 0; i < ND; i++)
  {
    N1(i) = eigen_vector(i,0);
    N2(i) = eigen_vector(i,1);
    N3(i) = eigen_vector(i,2);
  }

  const Real lamda1 = std::sqrt(eigen_value(0));
  const Real lamda2 = std::sqrt(eigen_value(1));
  const Real lamda3 = std::sqrt(eigen_value(2));


  const Real log1 = std::log(lamda1);
  const Real log2 = std::log(lamda2);
  const Real log3 = std::log(lamda3);

  ColumnMajorMatrix Uhat = N1 * N1.transpose() * lamda1 +  N2 * N2.transpose() * lamda2 +  N3 * N3.transpose() * lamda3;

  invertMatrix(Uhat,invUhat);

  Rhat = Fhat * invUhat;

  strain_increment = N1 * N1.transpose() * log1 +  N2 * N2.transpose() * log2 +  N3 * N3.transpose() * log3;
}
コード例 #10
0
ファイル: set_operations.cpp プロジェクト: FMX/CGAL
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;
}
コード例 #11
0
ファイル: nef_s2_construction.cpp プロジェクト: ArcEarth/cgal
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;
}
コード例 #12
0
ファイル: mda.cpp プロジェクト: magland/mountainlab
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;
}
コード例 #13
0
ファイル: nef_3_construction.cpp プロジェクト: ArcEarth/cgal
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;
}
コード例 #14
0
ファイル: mda.cpp プロジェクト: magland/mountainlab
int Mda::ndims() const
{
    return d->determine_num_dims(N1(), N2(), N3(), N4(), N5(), N6());
}