//=============================================================================
Epetra_IntSerialDenseMatrix::Epetra_IntSerialDenseMatrix(Epetra_DataAccess CV, int* A, int LDA, 
																												 int NumRows, int NumCols)
  : Epetra_Object("Epetra::IntSerialDenseMatrix"),
		CV_(CV),
		A_Copied_(false),
		M_(NumRows),
		N_(NumCols),
		LDA_(LDA),
		A_(A)
{
	if(A == 0)
		throw ReportError("Null pointer passed as A parameter.", -3);
	if(NumRows < 0)
		throw ReportError("NumRows = " + toString(NumRows) + ". Should be >= 0", -1);
	if(NumCols < 0)
		throw ReportError("NumCols = " + toString(NumCols) + ". Should be >= 0", -1);
	if(LDA < 0)
		throw ReportError("LDA = " + toString(LDA) + ". Should be >= 0", -1);

  if(CV == Copy) {
    LDA_ = M_;
		const int newsize = LDA_ * N_;
		if(newsize > 0) {
			A_ = new int[newsize];
			CopyMat(A, LDA, M_, N_, A_, LDA_);
			A_Copied_ = true;
		}
		else {
			A_ = 0;
		}
  }
}
//=============================================================================
int Epetra_IntSerialDenseMatrix::Reshape(int NumRows, int NumCols) {
	if(NumRows < 0 || NumCols < 0)
		return(-1);

	int* A_tmp = 0;
	const int newsize = NumRows * NumCols;

	if(newsize > 0) {
		// Allocate space for new matrix
		A_tmp = new int[newsize];
		for(int k = 0; k < newsize; k++) 
			A_tmp[k] = 0; // Zero out values
		int M_tmp = EPETRA_MIN(M_, NumRows);
		int N_tmp = EPETRA_MIN(N_, NumCols);
		if(A_ != 0) 
			CopyMat(A_, LDA_, M_tmp, N_tmp, A_tmp, NumRows); // Copy principal submatrix of A to new A
	}
  
  CleanupData(); // Get rid of anything that might be already allocated  
  M_ = NumRows;
  N_ = NumCols;
  LDA_ = M_;
  A_ = A_tmp; // Set pointer to new A
  A_Copied_ = (newsize>0);
  return(0);
}
//=============================================================================
Epetra_LongLongSerialDenseMatrix::Epetra_LongLongSerialDenseMatrix(Epetra_DataAccess CV_in, long long* A_in, int lda, 
                                                         int NumRows, int NumCols)
  : Epetra_Object("Epetra::LongLongSerialDenseMatrix"),
    CV_(CV_in),
    A_Copied_(false),
    M_(NumRows),
    N_(NumCols),
    LDA_(lda),
    A_(A_in)
{
  if(A_in == 0)
    throw ReportError("Null pointer passed as A_in parameter.", -3);
  if(NumRows < 0)
    throw ReportError("NumRows = " + toString(NumRows) + ". Should be >= 0", -1);
  if(NumCols < 0)
    throw ReportError("NumCols = " + toString(NumCols) + ". Should be >= 0", -1);
  if(lda < 0)
    throw ReportError("LDA = " + toString(lda) + ". Should be >= 0", -1);

  if(CV_in == Copy) {
    LDA_ = M_;
    const int newsize = LDA_ * N_;
    if(newsize > 0) {
      A_ = new long long[newsize];
      CopyMat(A_in, lda, M_, N_, A_, LDA_);
      A_Copied_ = true;
    }
    else {
      A_ = 0;
    }
  }
}
Example #4
0
std::vector<glm::mat4> Mesh::
GetOffsetFromMesh(const aiMesh* pMesh, 
		  std::map<std::string, uint> Bone2TfIdx)
{
  std::vector<glm::mat4> BoneOffset(Bone2TfIdx.size());
  // Fill OffsetMatrix
  for(uint i=0; i< pMesh->mNumBones; i++)
    {
      uint boneIdx =0;
      std::string BoneNm(pMesh->mBones[i]->mName.data);
      
      if(Bone2TfIdx.find(BoneNm) != Bone2TfIdx.end())
	{
	  boneIdx = Bone2TfIdx[BoneNm];
	  CopyMat(pMesh->mBones[i]->mOffsetMatrix, BoneOffset[boneIdx]);
	  
	  //printf("Idx: %2u, Name: %s\n", boneIdx, BoneNm.c_str());
	  //pprintMat16(mBoneOffset[boneIdx]);
	  }
      else
	{
	  //printf("Not needed: %s\n", BoneNm.c_str());
	}
    }
  return BoneOffset;
}
Example #5
0
bool Mesh::InitBonesFromMesh(const aiMesh* pMesh, 
			     std::vector<VtxBoneInfo>& bones)
{
  // Fill OffsetMatrix
  for(uint i=0; i< pMesh->mNumBones; i++)
    {
      uint boneIdx =0;
      std::string BoneNm(pMesh->mBones[i]->mName.data);
      
      if(mBone2TfIdx.find(BoneNm) != mBone2TfIdx.end())
	{
	  boneIdx = mBone2TfIdx[BoneNm];
	  CopyMat(pMesh->mBones[i]->mOffsetMatrix, mBoneOffset[boneIdx]);
	  
	  //printf("Idx: %2u, Name: %s\n", boneIdx, BoneNm.c_str());
	  //pprintMat16(mBoneOffset[boneIdx]);
	  }
      else
	{
	  //printf("Not needed: %s\n", BoneNm.c_str());
	}

      // Fill weights:
      for (unsigned int j=0; j< pMesh->mBones[i]->mNumWeights; j++)
	{
	  unsigned int Vid = pMesh->mBones[i]->mWeights[j].mVertexId;
	  float weight = pMesh->mBones[i]->mWeights[j].mWeight;
	  //  printf("vid = %u, weight = %f\n", Vid, weight);
	  bones[Vid].AddBoneData(boneIdx, weight);
	}
    }
  return true;
}
//=============================================================================
Epetra_IntSerialDenseMatrix& Epetra_IntSerialDenseMatrix::operator = (const Epetra_IntSerialDenseMatrix& Source) {
  if(this == &Source)
		return(*this); // Special case of source same as target
	if((CV_ == View) && (Source.CV_ == View) && (A_ == Source.A_))
		return(*this); // Special case of both are views to same data.

	if(std::strcmp(Label(), Source.Label()) != 0)
		throw ReportError("operator= type mismatch (lhs = " + string(Label()) + 
											", rhs = " + string(Source.Label()) + ").", -5);
	
	if(Source.CV_ == View) {
		if(CV_ == Copy) { // C->V only
			CleanupData();
			CV_ = View;
		}
		M_ = Source.M_; // C->V and V->V
		N_ = Source.N_;
		LDA_ = Source.LDA_;
		A_ = Source.A_;
	}
	else {
		if(CV_ == View) { // V->C
			CV_ = Copy;
			M_ = Source.M_;
			N_ = Source.N_;
			LDA_ = Source.M_;
			const int newsize = LDA_ * N_;
			if(newsize > 0) {
				A_ = new int[newsize];
				A_Copied_ = true;
			}
			else {
				A_ = 0;
				A_Copied_ = false;
			}
		}
		else { // C->C
			if((Source.M_ <= LDA_) && (Source.N_ == N_)) { // we don't need to reallocate
				M_ = Source.M_;
				N_ = Source.N_;
			}
			else { // we need to allocate more space (or less space)
				CleanupData();
				M_ = Source.M_;
				N_ = Source.N_;
				LDA_ = Source.M_;
				const int newsize = LDA_ * N_;
				if(newsize > 0) {
					A_ = new int[newsize];
					A_Copied_ = true;
				}
			}
		}
		CopyMat(Source.A_, Source.LDA_, M_, N_, A_, LDA_); // V->C and C->C
	}
	
  return(*this);
}
Example #7
0
void Animation::
ReadNodeHeirarchy(int frameIdx, 
		  const aiNode* pNode, 
		  const glm::mat4& parTf)
{
  std::string nodeName(pNode->mName.data);
  if (mBoneIdx.find(nodeName) == mBoneIdx.end())
    return;
  
  uint32 boneIdx = mBoneIdx[nodeName];
  
  const aiNodeAnim* pAnim = mBoneAnim[boneIdx];
  aiVectorKey& sc= pAnim->mScalingKeys[frameIdx % pAnim->mNumScalingKeys];
  aiMatrix4x4 matScale;
  aiMatrix4x4::Scaling(sc.mValue, matScale);
  
  aiQuatKey& qt = pAnim->mRotationKeys[frameIdx % pAnim->mNumRotationKeys];
  aiMatrix4x4 matRotat(qt.mValue.GetMatrix());
  
  aiVectorKey& tr = pAnim->mPositionKeys[frameIdx % pAnim->mNumPositionKeys];
  aiMatrix4x4 matTrans;
  aiMatrix4x4::Translation(tr.mValue, matTrans);

  // Convert from aiMatrix4x4 to glm::mat4
  glm::mat4 nodeTf;
  CopyMat(matTrans * matRotat * matScale, nodeTf);

  glm::mat4 globalTf= parTf * nodeTf;
  
  glm::mat4 finalTf = globalTf * mBoneOffsets[boneIdx];
  mBoneFinalTf[boneIdx] = finalTf;
  
  // Print out info
  //    cout << nodeName << endl;
  //    pprintMat4x4(finalTf);
  // pprintScQtTr(sc.mValue, qt.mValue, tr.mValue);
  //    pprintMat16(nodeTf);
  
  for(uint i=0; i< pNode->mNumChildren; ++i)
    ReadNodeHeirarchy(frameIdx, pNode->mChildren[i], globalTf);
}
//=============================================================================
Epetra_IntSerialDenseMatrix::Epetra_IntSerialDenseMatrix(const Epetra_IntSerialDenseMatrix& Source)
  : Epetra_Object(Source),
		CV_(Source.CV_),
    A_Copied_(false),
    M_(Source.M_),
    N_(Source.N_),
    LDA_(Source.LDA_),
    A_(Source.A_)
{
	if(CV_ == Copy) {
		LDA_ = M_;
		const int newsize = LDA_ * N_;
		if(newsize > 0) {
			A_ = new int[newsize];
			CopyMat(Source.A_, Source.LDA_, M_, N_, A_, LDA_);
			A_Copied_ = true;
		}
		else {
			A_ = 0;
			A_Copied_ = false;
		}
	}
}