コード例 #1
0
ファイル: skeleton.cpp プロジェクト: gsi-upm/SmartSim
SmartBodyNewSkeleton::SmartBodyNewSkeleton()
{
	//order of makeJoint calls is very important
	makeJoint("shoulders",  Vector3(0., 0.6, 0.));                          //0
	//makeJoint("spine3",     Vector3(0., 0.25, 0.),      "shoulders");       //1
	makeJoint("spine2",     Vector3(0., 0.35, 0.),      "shoulders");       //1
	makeJoint("back",       Vector3(0., 0.2, 0.),      "spine2");       //2
	makeJoint("hips",       Vector3(0., 0., 0.),        "back");          //3
	makeJoint("spine4",     Vector3(0., 0.68, 0.),      "shoulders");       //4
	makeJoint("neck",       Vector3(0., 0.70, 0.),      "spine4");     //5
	makeJoint("skullbase",  Vector3(0., 0.75, 0.),       "neck");          //6
	makeJoint("head",       Vector3(0., 0.8, 0.),       "skullbase");     //7

	makeJoint("lthigh",     Vector3(-0.1, 0., 0.),      "hips");            //8
	makeJoint("lknee",      Vector3(-0.15, -0.35, 0.),  "lthigh");          //9
	makeJoint("lankle",     Vector3(-0.15, -0.8, 0.),  "lknee");           //10
	makeJoint("lfoot",      Vector3(-0.15, -0.85, 0.06),  "lankle");       //11
	makeJoint("ltoe",       Vector3(-0.15, -0.85, 0.1),   "lfoot");       //12

	makeJoint("rthigh",     Vector3(0.1, 0., 0.),       "hips");            //13
	makeJoint("rknee",      Vector3(0.15, -0.35, 0.),   "rthigh");          //14
	makeJoint("rankle",      Vector3(0.15, -0.8, 0.),   "rknee");           //15
	makeJoint("rfoot",      Vector3(0.15, -0.85, 0.06),   "rankle");        //16
	makeJoint("rtoe",      Vector3(0.15, -0.85, 0.1),   "rfoot");          //17

	makeJoint("lshoulder",  Vector3(-0.3, 0.55, 0.),     "shoulders");       //18
	makeJoint("lelbow",     Vector3(-0.45, 0.25, 0.075), "lshoulder");       //19
	makeJoint("lhand",      Vector3(-0.65, 0.0, 0.15),   "lelbow");          //20
	makeJoint("lthumb",      Vector3(-0.67, -0.03, 0.225),   "lhand");          //21


	makeJoint("rshoulder",  Vector3(0.3, 0.55, 0.),      "shoulders");       //22
	makeJoint("relbow",     Vector3(0.45, 0.25, 0.075),  "rshoulder");       //23
	makeJoint("rhand",      Vector3(0.65, 0.0, 0.15),    "relbow");          //24
	makeJoint("rthumb",      Vector3(0.67, -0.03, 0.225),   "rhand");          //25

	//symmetry
	makeSymmetric("lthigh", "rthigh");
	makeSymmetric("lknee", "rknee");
	makeSymmetric("lankle", "rankle");
	makeSymmetric("lfoot", "rfoot");
	makeSymmetric("ltoe", "rtoe");

	makeSymmetric("lshoulder", "rshoulder");
	makeSymmetric("lelbow", "relbow");
	makeSymmetric("lhand", "rhand");
	//makeSymmetric("lthumb", "rthumb");

	initCompressed();

	setFoot("ltoe");
	setFoot("rtoe");

	setFat("hips");
	setFat("shoulders");
	setFat("head");
	//setFat("rthumb");
	//setFat("lthumb");
	//setFat("skullbase");
}
コード例 #2
0
int main(int argc, char **argv) {
  int  i, j, k;
  FILE* fptr;
  fptr = fopen(argv[1], "r");
  fscanf(fptr,"%d",&n);
  
  Node = calloc(n, sizeof(node)); //declare node array
  decolour(); //set all colours to 2 (no colour)
  matrix = createMatrix(n);
  
  //scan file
  for(i = 0; i < n * n; i++) {
    fscanf(fptr, "%d", &matrix[i]);
  }
  fclose(fptr);
  
  makeSymmetric(matrix, n);
  
  //assign neighbours
  for(j = 0; j < n; j++) {
    Node[j].nbr = calloc(n, sizeof(int));
    for(k = 0; k < n; k++) {
      Node[j].nbr[k] = matrix[k + n*j];
    }
  }
  
  printMatrix(matrix, n);
  
  //running DFS now beginning from every vertex
  for(i=0; i<n; i++){
    counter = 1; //set visited counter to 1
    decolour(); //decolour all
    Node[i].colour = 0; 
    runDFS(i, -1);  
  }
  
  if(cyclic == 1) printf("Cyclic\n");
  else printf("Not Cyclic\n");
  
  if(counter != n){
    printf("Not Connected\n");
    printf("Not Tree\n");
  } 
  else{
    printf("Connected\n");
    if(cyclic == 0) printf("Tree\n");
    else printf("Not Tree\n");
  }
  
  if(bipartite == 1) printf("Bipartite\n");
  else printf("Not Bipartite\n");
    
  free(matrix);
  free(Node);
  
  return 0;
}
コード例 #3
0
ファイル: skeleton.cpp プロジェクト: gsi-upm/SmartSim
HorseSkeleton::HorseSkeleton()
{
    //order of makeJoint calls is very important
    makeJoint("shoulders",  Vector3(0., 0., 0.5));
    makeJoint("back",       Vector3(0., 0., 0.),         "shoulders");
    makeJoint("hips",       Vector3(0., 0., -0.5),       "back");
    makeJoint("neck",       Vector3(0., 0.2, 0.63),      "shoulders");
    makeJoint("head",       Vector3(0., 0.2, 0.9),       "neck");
    
    makeJoint("lthigh",     Vector3(-0.15, 0., -0.5),     "hips");
    makeJoint("lhknee",     Vector3(-0.2, -0.2, -0.45),  "lthigh");
    makeJoint("lhheel",     Vector3(-0.2, -0.4, -0.5),   "lhknee");
    makeJoint("lhfoot",     Vector3(-0.2, -0.8, -0.5),   "lhheel");
    
    makeJoint("rthigh",     Vector3(0.15, 0., -0.5),      "hips");
    makeJoint("rhknee",     Vector3(0.2, -0.2, -0.45),   "rthigh");
    makeJoint("rhheel",     Vector3(0.2, -0.4, -0.5),    "rhknee");
    makeJoint("rhfoot",     Vector3(0.2, -0.8, -0.5),    "rhheel");
    
    makeJoint("lshoulder",  Vector3(-0.2, 0., 0.5),      "shoulders");
    makeJoint("lfknee",     Vector3(-0.2, -0.4, 0.5),    "lshoulder");
    makeJoint("lffoot",      Vector3(-0.2, -0.8, 0.5),   "lfknee");
    
    makeJoint("rshoulder",  Vector3(0.2, 0.0, 0.5),      "shoulders");
    makeJoint("rfknee",     Vector3(0.2, -0.4, 0.5),     "rshoulder");
    makeJoint("rffoot",      Vector3(0.2, -0.8, 0.5),    "rfknee");
    
    makeJoint("tail",       Vector3(0., 0., -0.7),       "hips");
    
    //symmetry
    makeSymmetric("lthigh", "rthigh");
    makeSymmetric("lhknee", "rhknee");
    makeSymmetric("lhheel", "rhheel");
    makeSymmetric("lhfoot", "rhfoot");
    
    makeSymmetric("lshoulder", "rshoulder");
    makeSymmetric("lfknee", "rfknee");
    makeSymmetric("lffoot", "rffoot");
    
    initCompressed();

    setFoot("lhfoot");
    setFoot("rhfoot");
    setFoot("lffoot");
    setFoot("rffoot");

    setFat("hips");
    setFat("shoulders");
    setFat("head");
}
コード例 #4
0
ファイル: skeleton.cpp プロジェクト: gsi-upm/SmartSim
HumanSkeleton::HumanSkeleton()
{
    //order of makeJoint calls is very important
    makeJoint("shoulders",  Vector3(0., 0.5, 0.));                          //0
    makeJoint("back",       Vector3(0., 0.15, 0.),      "shoulders");       //1
    makeJoint("hips",       Vector3(0., 0., 0.),        "back");            //2
    makeJoint("head",       Vector3(0., 0.7, 0.),       "shoulders");       //3
    
    makeJoint("lthigh",     Vector3(-0.1, 0., 0.),      "hips");            //4
    makeJoint("lknee",      Vector3(-0.15, -0.35, 0.),  "lthigh");          //5
    makeJoint("lankle",      Vector3(-0.15, -0.8, 0.),  "lknee");           //6
    makeJoint("lfoot",      Vector3(-0.15, -0.8, 0.1),  "lankle");          //7
    
    makeJoint("rthigh",     Vector3(0.1, 0., 0.),       "hips");            //8
    makeJoint("rknee",      Vector3(0.15, -0.35, 0.),   "rthigh");          //9
    makeJoint("rankle",      Vector3(0.15, -0.8, 0.),   "rknee");           //10
    makeJoint("rfoot",      Vector3(0.15, -0.8, 0.1),   "rankle");          //11
    
    makeJoint("lshoulder",  Vector3(-0.2, 0.5, 0.),     "shoulders");       //12
    makeJoint("lelbow",     Vector3(-0.4, 0.25, 0.075), "lshoulder");       //13
    makeJoint("lhand",      Vector3(-0.6, 0.0, 0.15),   "lelbow");          //14
    
    makeJoint("rshoulder",  Vector3(0.2, 0.5, 0.),      "shoulders");       //15
    makeJoint("relbow",     Vector3(0.4, 0.25, 0.075),  "rshoulder");       //16
    makeJoint("rhand",      Vector3(0.6, 0.0, 0.15),    "relbow");          //17
    
    //symmetry
    makeSymmetric("lthigh", "rthigh");
    makeSymmetric("lknee", "rknee");
    makeSymmetric("lankle", "rankle");
    makeSymmetric("lfoot", "rfoot");
    
    makeSymmetric("lshoulder", "rshoulder");
    makeSymmetric("lelbow", "relbow");
    makeSymmetric("lhand", "rhand");

    initCompressed();

    setFoot("lfoot");
    setFoot("rfoot");

    setFat("hips");
    setFat("shoulders");
    setFat("head");
}
コード例 #5
0
ファイル: skeleton.cpp プロジェクト: gsi-upm/SmartSim
CentaurSkeleton::CentaurSkeleton()
{
    //order of makeJoint calls is very important
    makeJoint("shoulders",  Vector3(0., 0., 0.5));                      //0
    makeJoint("back",       Vector3(0., 0., 0.),         "shoulders");  //1
    makeJoint("hips",       Vector3(0., 0., -0.5),       "back");       //2

    makeJoint("hback",      Vector3(0., 0.25, 0.5),      "shoulders");  //3
    makeJoint("hshoulders", Vector3(0., 0.5, 0.5),       "hback");      //4
    makeJoint("head",       Vector3(0., 0.7, 0.5),       "hshoulders"); //5
    
    makeJoint("lthigh",     Vector3(-0.15, 0., -0.5),    "hips");       //6
    makeJoint("lhknee",     Vector3(-0.2, -0.4, -0.45),  "lthigh");     //7
    makeJoint("lhfoot",     Vector3(-0.2, -0.8, -0.5),   "lhknee");     //8
    
    makeJoint("rthigh",     Vector3(0.15, 0., -0.5),     "hips");       //9
    makeJoint("rhknee",     Vector3(0.2, -0.4, -0.45),   "rthigh");     //10
    makeJoint("rhfoot",     Vector3(0.2, -0.8, -0.5),    "rhknee");     //11
    
    makeJoint("lshoulder",  Vector3(-0.2, 0., 0.5),      "shoulders");  //12
    makeJoint("lfknee",     Vector3(-0.2, -0.4, 0.5),    "lshoulder");  //13
    makeJoint("lffoot",     Vector3(-0.2, -0.8, 0.5),    "lfknee");     //14
    
    makeJoint("rshoulder",  Vector3(0.2, 0.0, 0.5),      "shoulders");  //15
    makeJoint("rfknee",     Vector3(0.2, -0.4, 0.5),     "rshoulder");  //16
    makeJoint("rffoot",     Vector3(0.2, -0.8, 0.5),     "rfknee");     //17
    
    makeJoint("hlshoulder", Vector3(-0.2, 0.5, 0.5),     "hshoulders"); //18
    makeJoint("lelbow",     Vector3(-0.4, 0.25, 0.575),  "hlshoulder"); //19
    makeJoint("lhand",      Vector3(-0.6, 0.0, 0.65),    "lelbow");     //20
    
    makeJoint("hrshoulder", Vector3(0.2, 0.5, 0.5),      "hshoulders"); //21
    makeJoint("relbow",     Vector3(0.4, 0.25, 0.575),   "hrshoulder"); //22
    makeJoint("rhand",      Vector3(0.6, 0.0, 0.65),     "relbow");     //23

    makeJoint("tail",       Vector3(0., 0., -0.7),       "hips");       //24

    //symmetry
    makeSymmetric("lthigh", "rthigh");
    makeSymmetric("lhknee", "rhknee");
    makeSymmetric("lhheel", "rhheel");
    makeSymmetric("lhfoot", "rhfoot");
    
    makeSymmetric("lshoulder", "rshoulder");
    makeSymmetric("lfknee", "rfknee");
    makeSymmetric("lffoot", "rffoot");

    makeSymmetric("hlshoulder", "hrshoulder");
    makeSymmetric("lelbow", "relbow");
    makeSymmetric("lhand", "rhand");    
    
    initCompressed();

    setFoot("lhfoot");
    setFoot("rhfoot");
    setFoot("lffoot");
    setFoot("rffoot");

    setFat("hips");
    setFat("shoulders");
    setFat("hshoulders");
    setFat("head");
}
コード例 #6
0
ファイル: organized.hpp プロジェクト: nttputus/PCL
template<typename PointT> void
pcl::search::OrganizedNeighbor<PointT>::estimateProjectionMatrix ()
{
  // internally we calculate with double but store the result into float matrices.
  typedef double Scalar;
  projection_matrix_.setZero ();
  if (input_->height == 1 || input_->width == 1)
  {
    PCL_ERROR ("[pcl::%s::estimateProjectionMatrix] Input dataset is not organized!\n", getName ().c_str ());
    return;
  }

  // we just want to use every 16th column and row -> skip = 2^4
  const unsigned int skip = input_->width >> 4;
  Eigen::Matrix<Scalar, 4, 4> A = Eigen::Matrix<Scalar, 4, 4>::Zero ();
  Eigen::Matrix<Scalar, 4, 4> B = Eigen::Matrix<Scalar, 4, 4>::Zero ();
  Eigen::Matrix<Scalar, 4, 4> C = Eigen::Matrix<Scalar, 4, 4>::Zero ();
  Eigen::Matrix<Scalar, 4, 4> D = Eigen::Matrix<Scalar, 4, 4>::Zero ();

  for (unsigned yIdx = 0, idx = 0; yIdx < input_->height; yIdx += skip, idx += input_->width * (skip-1))
  {
    for (unsigned xIdx = 0; xIdx < input_->width; xIdx += skip, idx += skip)
    {
      const PointT& point = input_->points[idx];
      if (isFinite (point))
      {
        Scalar xx = point.x * point.x;
        Scalar xy = point.x * point.y;
        Scalar xz = point.x * point.z;
        Scalar yy = point.y * point.y;
        Scalar yz = point.y * point.z;
        Scalar zz = point.z * point.z;
        Scalar xx_yy = xIdx * xIdx + yIdx * yIdx;

        A.coeffRef (0) += xx;
        A.coeffRef (1) += xy;
        A.coeffRef (2) += xz;
        A.coeffRef (3) += point.x;

        A.coeffRef (5) += yy;
        A.coeffRef (6) += yz;
        A.coeffRef (7) += point.y;

        A.coeffRef (10) += zz;
        A.coeffRef (11) += point.z;
        A.coeffRef (15) += 1.0;

        B.coeffRef (0) -= xx * xIdx;
        B.coeffRef (1) -= xy * xIdx;
        B.coeffRef (2) -= xz * xIdx;
        B.coeffRef (3) -= point.x * xIdx;

        B.coeffRef (5) -= yy * xIdx;
        B.coeffRef (6) -= yz * xIdx;
        B.coeffRef (7) -= point.y * xIdx;

        B.coeffRef (10) -= zz * xIdx;
        B.coeffRef (11) -= point.z * xIdx;

        B.coeffRef (15) -= xIdx;

        C.coeffRef (0) -= xx * yIdx;
        C.coeffRef (1) -= xy * yIdx;
        C.coeffRef (2) -= xz * yIdx;
        C.coeffRef (3) -= point.x * yIdx;

        C.coeffRef (5) -= yy * yIdx;
        C.coeffRef (6) -= yz * yIdx;
        C.coeffRef (7) -= point.y * yIdx;

        C.coeffRef (10) -= zz * yIdx;
        C.coeffRef (11) -= point.z * yIdx;

        C.coeffRef (15) -= yIdx;

        D.coeffRef (0) += xx * xx_yy;
        D.coeffRef (1) += xy * xx_yy;
        D.coeffRef (2) += xz * xx_yy;
        D.coeffRef (3) += point.x * xx_yy;

        D.coeffRef (5) += yy * xx_yy;
        D.coeffRef (6) += yz * xx_yy;
        D.coeffRef (7) += point.y * xx_yy;

        D.coeffRef (10) += zz * xx_yy;
        D.coeffRef (11) += point.z * xx_yy;

        D.coeffRef (15) += xx_yy;
      }
    }
  }

  makeSymmetric(A);
  makeSymmetric(B);
  makeSymmetric(C);
  makeSymmetric(D);

  Eigen::Matrix<Scalar, 12, 12> X = Eigen::Matrix<Scalar, 12, 12>::Zero ();
  X.topLeftCorner<4,4> () = A;
  X.block<4,4> (0, 8) = B;
  X.block<4,4> (8, 0) = B;
  X.block<4,4> (4, 4) = A;
  X.block<4,4> (4, 8) = C;
  X.block<4,4> (8, 4) = C;
  X.block<4,4> (8, 8) = D;

  Eigen::SelfAdjointEigenSolver<Eigen::Matrix<Scalar, 12, 12> > ei_symm(X);
  Eigen::Matrix<Scalar, 12, 12> eigen_vectors = ei_symm.eigenvectors();

  // check whether the residual MSE is low. If its high, the cloud was not captured from a projective device.
  Eigen::Matrix<Scalar, 1, 1> residual_sqr = eigen_vectors.col (0).transpose () * X *  eigen_vectors.col (0);
  if ( residual_sqr.coeff (0) > eps_ * A.coeff (15))
  {
    PCL_ERROR ("[pcl::%s::radiusSearch] Input dataset is not from a projective device!\n", getName ().c_str ());
    return;
  }

  projection_matrix_.coeffRef (0) = eigen_vectors.coeff (0);
  projection_matrix_.coeffRef (1) = eigen_vectors.coeff (12);
  projection_matrix_.coeffRef (2) = eigen_vectors.coeff (24);
  projection_matrix_.coeffRef (3) = eigen_vectors.coeff (36);
  projection_matrix_.coeffRef (4) = eigen_vectors.coeff (48);
  projection_matrix_.coeffRef (5) = eigen_vectors.coeff (60);
  projection_matrix_.coeffRef (6) = eigen_vectors.coeff (72);
  projection_matrix_.coeffRef (7) = eigen_vectors.coeff (84);
  projection_matrix_.coeffRef (8) = eigen_vectors.coeff (96);
  projection_matrix_.coeffRef (9) = eigen_vectors.coeff (108);
  projection_matrix_.coeffRef (10) = eigen_vectors.coeff (120);
  projection_matrix_.coeffRef (11) = eigen_vectors.coeff (132);

  if (projection_matrix_.coeff (0) < 0)
    projection_matrix_ *= -1.0;

  // get left 3x3 sub matrix, which contains K * R, with K = camera matrix = [[fx s cx] [0 fy cy] [0 0 1]]
  // and R being the rotation matrix
  KR_ = projection_matrix_.topLeftCorner <3, 3> ();

  // precalculate KR * KR^T needed by calculations during nn-search
  KR_KRT_ = KR_ * KR_.transpose ();
}
コード例 #7
0
void testSymmetrize(Pooma::Tester &tester)
{

  tester.out() << std::endl << "========= " << D << "D =========" << std::endl;

  // Create Full, Antisymmetric, Symmetric, and Diagonal Tensors as inputs:
  Tensor<D,double,Full> tf;
  double value = 1.0;
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < D; j++) {
      tf(i,j) = value;
      value++;
    }
  }
  tester.out() << "tf: " << tf << std::endl;
  Tensor<D,double,Antisymmetric> ta;
  value = 1.0;
  for (int i = 0; i < TensorStorageSize<D,Antisymmetric>::Size; i++) {
    ta(i) = i + 1.0;
  }
  tester.out() << "ta: " << ta << std::endl;
  Tensor<D,double,Symmetric> ts;
  for (int i = 0; i < TensorStorageSize<D,Symmetric>::Size; i++) {
    ts(i) = i + 1.0;
  }
  tester.out() << "ts: " << ts << std::endl;
  Tensor<D,double,Diagonal> td;
  for (int i = 0; i < TensorStorageSize<D,Diagonal>::Size; i++) {
    td(i) = i + 1.0;
  }
  tester.out() << "td: " << td << std::endl;

  //---------------------------------------------------------------------------
  // Make Fields of these types, to test forwarding of symmetrize<>() function:
  // Create the physical Domains:
  const int nVerts = 6;
  const int nCells = nVerts - 1;
  int nCellsTot = 1;
  Interval<D> vertexDomain;
  for (int d = 0; d < D; d++) {
    vertexDomain[d] = Interval<1>(nVerts);
    nCellsTot *= nCells;
  }

  // Create the (uniform, logically rectilinear) mesh.
  Vector<D> origin(0.0), spacings(0.2);
  typedef UniformRectilinearMesh<D> Mesh_t;
  DomainLayout<D> layout(vertexDomain, GuardLayers<D>(0));

  // Create the Fields:
  Centering<D> cell = canonicalCentering<D>(CellType, Continuous);

  // Full, Antisymmetric, Symmetric, Diagonal Tensor Fields:
  Field<Mesh_t,Tensor<D,double,Full> > tff(cell, layout, origin, spacings);
  Field<Mesh_t,Tensor<D,double,Symmetric> >
    tfs(cell, layout, origin, spacings);
  Field<Mesh_t,Tensor<D,double,Antisymmetric> >
    tfa(cell, layout, origin, spacings);
  Field<Mesh_t,Tensor<D,double,Diagonal> > tfd(cell, layout, origin, spacings);

  // Assign to the single-Tensor values:
  tff = tf;
  tfs = ts;
  tfa = ta;
  tfd = td;

#ifndef __MWERKS__ // This whole module is too much for CW5 to compile
  // --------------------------------------------------------------------------
  // Symmetrize from Full tensor to {Antisymmetric, Symmetric, Diagonal}:

  // To Antisymmetric:
  if (!tester.check("symmetrize<Antisymmetric>(tf): ", 
                    (symmetrize<Antisymmetric>(tf) == 
                     makeAntisymmetric(tf)))) {
    tester.out() << "symmetrize<Antisymmetric>(tf) = " 
                 << symmetrize<Antisymmetric>(tf) 
                 << " != makeAntisymmetric(tf) = " 
                 << makeAntisymmetric(tf) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Antisymmetric>(tff)): ", 
                    (sum(symmetrize<Antisymmetric>(tff)) == 
                     nCellsTot*makeAntisymmetric(tf)))) {
    tester.out() << "sum(symmetrize<Antisymmetric>(tff)) = " 
                 << sum(symmetrize<Antisymmetric>(tff)) 
                 << " != nCellsTot*makeAntisymmetric(tf) = "
                 << nCellsTot*makeAntisymmetric(tf) << std::endl;
  }


  // To Symmetric:
  if (!tester.check("symmetrize<Symmetric>(tf): ", 
                    (symmetrize<Symmetric>(tf) == 
                     makeSymmetric(tf)))) {
    tester.out() << "symmetrize<Symmetric>(tf) = " 
                 << symmetrize<Symmetric>(tf) 
                 << " != makeSymmetric(tf) = " 
                 << makeSymmetric(tf) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Symmetric>(tff)): ", 
                    (sum(symmetrize<Symmetric>(tff)) == 
                     nCellsTot*makeSymmetric(tf)))) {
    tester.out() << "sum(symmetrize<Symmetric>(tff)) = " 
                 << sum(symmetrize<Symmetric>(tff)) 
                 << " != nCellsTot*makeSymmetric(tf) = "
                 << nCellsTot*makeSymmetric(tf) << std::endl;
  }

  // To Diagonal::
  if (!tester.check("symmetrize<Diagonal>(tf): ", 
                    (symmetrize<Diagonal>(tf) == 
                     makeDiagonal(tf)))) {
    tester.out() << "symmetrize<Diagonal>(tf) = " 
                 << symmetrize<Diagonal>(tf) 
                 << " != makeDiagonal(tf) = " 
                 << makeDiagonal(tf) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Diagonal>(tff)): ", 
                    (sum(symmetrize<Diagonal>(tff)) == 
                     nCellsTot*makeDiagonal(tf)))) {
    tester.out() << "sum(symmetrize<Diagonal>(tff)) = " 
                 << sum(symmetrize<Diagonal>(tff)) 
                 << " != nCellsTot*makeDiagonal(tf) = "
                 << nCellsTot*makeDiagonal(tf) << std::endl;
  }

  // --------------------------------------------------------------------------
  // Symmetrize from Antisymmetric tensor to {Full, Symmetric, Diagonal}:

  // To Full:
  if (!tester.check("symmetrize<Full>(ta): ", 
                    (symmetrize<Full>(ta) == 
                     makeFull(ta)))) {
    tester.out() << "symmetrize<Full>(ta) = " 
                 << symmetrize<Full>(ta) 
                 << " != makeFull(ta) = " 
                 << makeFull(ta) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Full>(tfa)): ", 
                    (sum(symmetrize<Full>(tfa)) == 
                     nCellsTot*makeFull(ta)))) {
    tester.out() << "sum(symmetrize<Full>(tfa)) = " 
                 << sum(symmetrize<Full>(tfa)) 
                 << " != nCellsTot*makeFull(ta) = "
                 << nCellsTot*makeFull(ta) << std::endl;
  }

  // To Symmetric:
  if (!tester.check("symmetrize<Symmetric>(ta): ", 
                    (symmetrize<Symmetric>(ta) == 
                     makeSymmetric(ta)))) {
    tester.out() << "symmetrize<Symmetric>(ta) = " 
                 << symmetrize<Symmetric>(ta) 
                 << " != makeSymmetric(ta) = " 
                 << makeSymmetric(ta) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Symmetric>(tfa)): ", 
                    (sum(symmetrize<Symmetric>(tfa)) == 
                     nCellsTot*makeSymmetric(ta)))) {
    tester.out() << "sum(symmetrize<Symmetric>(tfa)) = " 
                 << sum(symmetrize<Symmetric>(tfa)) 
                 << " != nCellsTot*makeSymmetric(ta) = "
                 << nCellsTot*makeSymmetric(ta) << std::endl;
  }

  // To Diagonal::
  if (!tester.check("symmetrize<Diagonal>(ta): ", 
                    (symmetrize<Diagonal>(ta) == 
                     makeDiagonal(ta)))) {
    tester.out() << "symmetrize<Diagonal>(ta) = " 
                 << symmetrize<Diagonal>(ta) 
                 << " != makeDiagonal(ta) = " 
                 << makeDiagonal(ta) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Diagonal>(tfa)): ", 
                    (sum(symmetrize<Diagonal>(tfa)) == 
                     nCellsTot*makeDiagonal(ta)))) {
    tester.out() << "sum(symmetrize<Diagonal>(tfa)) = " 
                 << sum(symmetrize<Diagonal>(tfa)) 
                 << " != nCellsTot*makeDiagonal(ta) = "
                 << nCellsTot*makeDiagonal(ta) << std::endl;
  }
#endif // __MWERKS__ 

  // --------------------------------------------------------------------------
  // Symmetrize from Symmetric tensor to {Full, Antisymmetric, Diagonal}:

  // To Full:
  if (!tester.check("symmetrize<Full>(ts): ", 
                    (symmetrize<Full>(ts) == 
                     makeFull(ts)))) {
    tester.out() << "symmetrize<Full>(ts) = " 
                 << symmetrize<Full>(ts) 
                 << " != makeFull(ts) = " 
                 << makeFull(ts) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Full>(tfs)): ", 
                    (sum(symmetrize<Full>(tfs)) == 
                     nCellsTot*makeFull(ts)))) {
    tester.out() << "sum(symmetrize<Full>(tfs)) = " 
                 << sum(symmetrize<Full>(tfs)) 
                 << " != nCellsTot*makeFull(ts) = "
                 << nCellsTot*makeFull(ts) << std::endl;
  }

  // To Antisymmetric:
  if (!tester.check("symmetrize<Antisymmetric>(ts): ", 
                    (symmetrize<Antisymmetric>(ts) == 
                     makeAntisymmetric(ts)))) {
    tester.out() << "symmetrize<Antisymmetric>(ts) = " 
                 << symmetrize<Antisymmetric>(ts) 
                 << " != makeAntisymmetric(ts) = " 
                 << makeAntisymmetric(ts) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Antisymmetric>(tfs)): ", 
                    (sum(symmetrize<Antisymmetric>(tfs)) == 
                     nCellsTot*makeAntisymmetric(ts)))) {
    tester.out() << "sum(symmetrize<Antisymmetric>(tfs)) = " 
                 << sum(symmetrize<Antisymmetric>(tfs)) 
                 << " != nCellsTot*makeAntisymmetric(ts) = "
                 << nCellsTot*makeAntisymmetric(ts) << std::endl;
  }

  // To Diagonal::
  if (!tester.check("symmetrize<Diagonal>(ts): ", 
                    (symmetrize<Diagonal>(ts) == 
                     makeDiagonal(ts)))) {
    tester.out() << "symmetrize<Diagonal>(ts) = " 
                 << symmetrize<Diagonal>(ts) 
                 << " != makeDiagonal(ts) = " 
                 << makeDiagonal(ts) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Diagonal>(tfs)): ", 
                    (sum(symmetrize<Diagonal>(tfs)) == 
                     nCellsTot*makeDiagonal(ts)))) {
    tester.out() << "sum(symmetrize<Diagonal>(tfs)) = " 
                 << sum(symmetrize<Diagonal>(tfs)) 
                 << " != nCellsTot*makeDiagonal(ts) = "
                 << nCellsTot*makeDiagonal(ts) << std::endl;
  }

  // --------------------------------------------------------------------------
  // Symmetrize from Diagonal tensor to {Full, Antisymmetric, Symmetric}:

  // To Full:
  if (!tester.check("symmetrize<Full>(td): ", 
                    (symmetrize<Full>(td) == 
                     makeFull(td)))) {
    tester.out() << "symmetrize<Full>(td) = " 
                 << symmetrize<Full>(td) 
                 << " != makeFull(td) = " 
                 << makeFull(td) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Full>(tfd)): ", 
                    (sum(symmetrize<Full>(tfd)) == 
                     nCellsTot*makeFull(td)))) {
    tester.out() << "sum(symmetrize<Full>(tfd)) = " 
                 << sum(symmetrize<Full>(tfd)) 
                 << " != nCellsTot*makeFull(td) = "
                 << nCellsTot*makeFull(td) << std::endl;
  }

  // To Antisymmetric:
  if (!tester.check("symmetrize<Antisymmetric>(td): ", 
                    (symmetrize<Antisymmetric>(td) == 
                     makeAntisymmetric(td)))) {
    tester.out() << "symmetrize<Antisymmetric>(td) = " 
                 << symmetrize<Antisymmetric>(td) 
                 << " != makeAntisymmetric(td) = " 
                 << makeAntisymmetric(td) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Antisymmetric>(tfd)): ", 
                    (sum(symmetrize<Antisymmetric>(tfd)) == 
                     nCellsTot*makeAntisymmetric(td)))) {
    tester.out() << "sum(symmetrize<Antisymmetric>(tfd)) = " 
                 << sum(symmetrize<Antisymmetric>(tfd)) 
                 << " != nCellsTot*makeAntisymmetric(td) = "
                 << nCellsTot*makeAntisymmetric(td) << std::endl;
  }

  // To Symmetric:
  if (!tester.check("symmetrize<Symmetric>(td): ", 
                    (symmetrize<Symmetric>(td) == 
                     makeSymmetric(td)))) {
    tester.out() << "symmetrize<Symmetric>(td) = " 
                 << symmetrize<Symmetric>(td) 
                 << " != makeSymmetric(td) = " 
                 << makeSymmetric(td) << std::endl;
  }
  if (!tester.check("sum(symmetrize<Symmetric>(tfd)): ", 
                    (sum(symmetrize<Symmetric>(tfd)) == 
                     nCellsTot*makeSymmetric(td)))) {
    tester.out() << "sum(symmetrize<Symmetric>(tfd)) = " 
                 << sum(symmetrize<Symmetric>(tfd)) 
                 << " != nCellsTot*makeSymmetric(td) = "
                 << nCellsTot*makeSymmetric(td) << std::endl;
  }

}
コード例 #8
0
static const size_t N = 11;

typedef cppmat::symmetric::matrix<double> sMat;

// =================================================================================================

TEST_CASE("cppmat::symmetric::matrix", "matrix.h")
{

// =================================================================================================
// arithmetic
// =================================================================================================

SECTION( "matrix += matrix" )
{
  MatD a = makeSymmetric(MatD::Random(M,N));
  MatD b = makeSymmetric(MatD::Random(M,N));

  sMat A = sMat::CopyDense(M, N, a.data(), a.data()+a.size());
  sMat B = sMat::CopyDense(M, N, b.data(), b.data()+b.size());

  for ( size_t i = 0 ; i < M ; ++i )
    for ( size_t j = 0 ; j < N ; ++j )
      a(i,j) += b(i,j);

  A += B;

  Equal(A, a);
}

// -------------------------------------------------------------------------------------------------