void Mult (const FlatVector<TVX> & x, FlatVector<TVY> & y) const { // const TVX * hx = x.Addr(0); // TVY * hy = y.Addr(0); FlatVector<TVX> hx = x; FlatVector<TVY> hy = y; const T * hm = &mem[0]; for (int i = 0; i < n; i++) hy[i] = hx[i]; int i, jj = n; for (i = 0; i < bw-1; i++) { typedef typename mat_traits<TVY>::TSCAL TTSCAL; TVY sum = TTSCAL(0.0); for (int j = 0; j < i; j++, jj++) sum += hm[jj] * hy[j]; hy[i] -= sum; } for ( ; i < n; i++) { typedef typename mat_traits<TVY>::TSCAL TTSCAL; TVY sum = TTSCAL(0.0); for (int j = i-bw+1; j < i; j++, jj++) sum += hm[jj] * hy[j]; hy[i] -= sum; } for (int i = 0; i < n; i++) { TVY sum = mem[i] * hy[i]; hy[i] = sum; } // jj = n + (n-1) * (bw-1) - bw*(bw-1)/2; for (i = n-1; i >= bw-1; i--) { jj -= bw-1; TVY val = hy[i]; int firstj = i-bw+1; for (int j = 0; j < bw-1; j++) hy[firstj+j] -= Trans (mem[jj+j]) * val; } for ( ; i >= 0; i--) { jj -= i; TVY val = hy[i]; for (int j = 0; j < i; j++) hy[j] -= Trans (mem[jj+j]) * val; } }
inline void CalcInverse (const Mat<3,2> & m, Mat<2,3> & inv) { Mat<2,2> a = Trans (m) * m; Mat<2,2> ainv; CalcInverse (a, ainv); inv = ainv * Trans (m); }
vnl_matrix<double> MakeTranslationMatrix(const vgl_vector_3d<double> &T) { vnl_matrix<double> Trans(4,4); Trans.set_identity(); Trans(0,3) = T.x(); Trans(1,3) = T.y(); Trans(2,3) = T.z(); return Trans; }
void Input(void) { int c, seg[MAXN] = {0}; while (c = getchar(), isdigit(c)) seg[++seg[0]] = c - '0'; Trans(x, seg); while (c = getchar(), !isdigit(c)) {} seg[0] = 0; seg[ ++seg[0] ] = c - '0'; while (c = getchar(), isdigit(c)) seg[++seg[0]] = c - '0'; Trans(y, seg); }
void GradGrad<D>::T_CalcElementMatrix (const FiniteElement & base_fel, const ElementTransformation & eltrans, FlatMatrix<SCAL> elmat, LocalHeap & lh) const { const CompoundFiniteElement & cfel // product space = dynamic_cast<const CompoundFiniteElement&> (base_fel); const ScalarFiniteElement<D> & fel_u = // u space dynamic_cast<const ScalarFiniteElement<D>&> (cfel[GetInd1()]); const ScalarFiniteElement<D> & fel_e = // e space dynamic_cast<const ScalarFiniteElement<D>&> (cfel[GetInd2()]); elmat = SCAL(0.0); // u dofs [ru.First() : ru.Next()-1], e dofs [re.First() : re.Next()-1] IntRange ru = cfel.GetRange(GetInd1()); IntRange re = cfel.GetRange(GetInd2()); int ndofe = re.Size(); int ndofu = ru.Size(); FlatMatrixFixWidth<D> dum(ndofu,lh); // to store grad(u-basis) FlatMatrixFixWidth<D> dem(ndofe,lh); // to store grad(e-basis) ELEMENT_TYPE eltype // get the type of element: = fel_u.ElementType(); // ET_TRIG in 2d, ET_TET in 3d. const IntegrationRule & // Note: p = fel_u.Order()-1 ir = SelectIntegrationRule(eltype, fel_u.Order()+fel_e.Order()-2); FlatMatrix<SCAL> submat(ndofe,ndofu,lh); submat = 0.0; for(int k=0; k<ir.GetNIP(); k++) { MappedIntegrationPoint<D,D> mip (ir[k],eltrans); // set grad(u-basis) and grad(e-basis) at mapped pts in dum and dem. fel_u.CalcMappedDShape( mip, dum ); fel_e.CalcMappedDShape( mip, dem ); // evaluate coefficient SCAL fac = coeff_a -> T_Evaluate<SCAL>(mip); fac *= mip.GetWeight() ; // [ndofe x D] * [D x ndofu] submat += fac * dem * Trans(dum) ; } elmat.Rows(re).Cols(ru) += submat; if (GetInd1() != GetInd2()) elmat.Rows(ru).Cols(re) += Conj(Trans(submat)); }
void FluxFluxBoundary<D> :: T_CalcElementMatrix (const FiniteElement & base_fel, const ElementTransformation & eltrans, FlatMatrix<SCAL> elmat, LocalHeap & lh) const { const CompoundFiniteElement & cfel // product space = dynamic_cast<const CompoundFiniteElement&> (base_fel); // This FE is already multiplied by normal: const HDivNormalFiniteElement<D-1> & fel_q = // q.n space dynamic_cast<const HDivNormalFiniteElement<D-1>&> (cfel[GetInd1()]); const HDivNormalFiniteElement<D-1> & fel_r = // r.n space dynamic_cast<const HDivNormalFiniteElement<D-1>&> (cfel[GetInd2()]); elmat = SCAL(0.0); IntRange rq = cfel.GetRange(GetInd1()); IntRange rr = cfel.GetRange(GetInd2()); int ndofq = rq.Size(); int ndofr = rr.Size(); FlatMatrix<SCAL> submat(ndofr, ndofq, lh); submat = SCAL(0.0); FlatVector<> qshape(fel_q.GetNDof(), lh); FlatVector<> rshape(fel_r.GetNDof(), lh); const IntegrationRule ir(fel_q.ElementType(), fel_q.Order() + fel_r.Order()); for (int i = 0 ; i < ir.GetNIP(); i++) { MappedIntegrationPoint<D-1,D> mip(ir[i], eltrans); SCAL cc = coeff_c -> T_Evaluate<SCAL>(mip); fel_r.CalcShape (ir[i], rshape); fel_q.CalcShape (ir[i], qshape); // mapped q.n-shape is simply reference q.n-shape / measure qshape *= 1.0/mip.GetMeasure(); rshape *= 1.0/mip.GetMeasure(); // [ndofr x 1] [1 x ndofq] submat += (cc*mip.GetWeight()) * rshape * Trans(qshape); } elmat.Rows(rr).Cols(rq) += submat; if (GetInd1() != GetInd2()) elmat.Rows(rq).Cols(rr) += Conj(Trans(submat)); }
vnl_matrix<double> CameraTransform(const Ray &View1, const Ray &View2) { //This function takes two rays (ie 2 sets of view points and view directions), and finds the matrix M between them (from V1 to V2) vgl_point_3d<double> A1 = View1.getOrigin(); vgl_point_3d<double> A2 = View1.PointAlong(1.0); vgl_point_3d<double> B1 = View2.getOrigin(); vgl_point_3d<double> B2 = View2.PointAlong(1.0); vtkSmartPointer<vtkLandmarkTransform> LandmarkTransform = vtkSmartPointer<vtkLandmarkTransform>::New(); vtkSmartPointer<vtkPoints> SourcePoints = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkPoints> TargetPoints = vtkSmartPointer<vtkPoints>::New(); double A1array[3] = {A1.x(), A1.y(), A1.z()}; SourcePoints->InsertNextPoint(A1array); double A2array[3] = {A2.x(), A2.y(), A2.z()}; SourcePoints->InsertNextPoint(A2array); double B1array[3] = {B1.x(), B1.y(), B1.z()}; TargetPoints->InsertNextPoint(B1array); double B2array[3] = {B2.x(), B2.y(), B2.z()}; TargetPoints->InsertNextPoint(B2array); LandmarkTransform->SetSourceLandmarks(SourcePoints); LandmarkTransform->SetTargetLandmarks(TargetPoints); LandmarkTransform->SetModeToRigidBody(); LandmarkTransform->Update(); vnl_matrix<double> Trans(4,4); vtkMatrix4x4* M = LandmarkTransform->GetMatrix(); //cout << M << endl; for(unsigned int r = 0; r < 4; r++) { for(unsigned int c = 0; c < 4; c++) { Trans(r,c) = M->GetElement(r,c); } } //cout << Trans << endl; return Trans; }
virtual Vec<DIM_CURL_(D)> EvaluateCurlShape (const IntegrationPoint & ip, FlatVector<double> x, LocalHeap & lh) const { HeapReset hr(lh); return Trans (GetCurlShape(ip, lh)) * x; }
void PyramidObject::transform( void ) { // update the angles this->angles += this->rotSpeeds; // create temp matrices Matrix Scale(SCALE, 0.5f, 0.5f, 0.5f); Matrix RotX( ROT_X, this->angles[x] ); Matrix RotY( ROT_Y, this->angles[y] ); Matrix RotZ( ROT_Z, this->angles[z] ); ///////////////////////DEMO CODE, UNECESSARY REMOVE /////////////////////////// if (this->currPos[x] <= -7.0f) this->dir[x] *= -1; if (this->currPos[x] >= -3.0f) this->dir[x] *= -1; ///////////////////////////////////////////////////////////////////////////// this->currPos[x] += this->dir[x]; this->currPos[y] += this->dir[y]; this->currPos[z] += this->dir[z]; Matrix Trans( TRANS, this->currPos[x], this->currPos[y], this->currPos[z]); // Create the local to world matrix (ie Model) this->LocalToWorld = Scale * RotY * RotX * RotZ * Trans; // Create the ModelView ( LocalToWorld * View) // Some pipelines have the project concatenated, others don't // Best to keep the separated, you can always join them with a quick multiply this->ModelView = this->LocalToWorld * pCamera->getViewMatrix(); };
Vec<DIM_CURL_(D), typename TVX::TSCAL> EvaluateCurlShape (const IntegrationPoint & ip, const TVX & x, LocalHeap & lh) const { HeapReset hr(lh); return Trans (GetCurlShape(ip, lh)) * x; }
void CShapeEffectCreator::CreateShapeRegion (int iAngle, int iLength, int iWidth, CG16bitRegion *pRegion) // CreateShapeRegion // // Creates a transformed polygon from m_Points and the given parameters { // Define a transformation for this shape CXForm Trans(xformScale, ((Metric)iLength)/100.0, ((Metric)iWidth)/100.0); Trans = Trans * CXForm(xformRotate, iAngle); // Transform the points for (int i = 0; i < m_iPointCount; i++) { Metric x, y; Trans.Transform(m_Points[i].x, m_Points[i].y, &x, &y); m_TransBuffer[i].x = (int)(x + 0.5); m_TransBuffer[i].y = -(int)(y + 0.5); } // Create the region if (m_bConvexPolygon) pRegion->CreateFromConvexPolygon(m_iPointCount, m_TransBuffer); else pRegion->CreateFromPolygon(m_iPointCount, m_TransBuffer); }
A_solve(double *c_mat,int c_rows,int c_cols,double *b_mat,int b_rows,int b_cols, double *a_mat) { /******************************************************************\ * This function performs a least squares solution to the equation * C = A * B, where the matrix A is the one that needs to be solved. * The numerics are all double precision. The routine assumes that the * user has ordered the matrices properly * \*******************************************************************/ double *bt, *bbt, *cbt; bt = (double *)malloc(b_cols * b_rows * sizeof(double)); bbt = (double *)malloc(b_rows * b_rows * sizeof(double)); cbt =(double *)malloc(c_rows * b_rows * sizeof(double)); if(cbt == NULL)return(-1); Trans(b_mat,b_rows,b_cols,bt); /* compute transpose of B */ MatMult(c_mat,c_rows,c_cols,bt,b_cols,b_rows,cbt); /* post multiply B * C */ MatMult(b_mat,b_rows,b_cols,bt,b_cols,b_rows,bbt); /* calculate bb transpose */ Invert(bbt,b_rows);/* invert this result */ MatMult(cbt,c_rows,b_rows,bbt,b_rows,b_rows,a_mat); free(bt); free(bbt); free(cbt); return(0); }
void SmokeParticle::WorldUpdate(float currentTime) { currentTime; //AZUL_UNUSED_FLOAT(currentTime); // Goal: update the world matrix Matrix Scale(MatrixScaleType::SCALE, this->scaleX, this->scaleY, 1.0f); Matrix Rot(RotType::ROT_Z, this->angle); Matrix Trans(MatrixTransType::TRANS, this->posX, this->posY, 0.0f); *this->pWorld = Scale * Rot * Trans; float timeInSec = Simulation::Instance()->getTimeStep(); this->lifeTime += timeInSec; // add schrink if (timeInSec > 0.0f) { this->scaleX *= 0.99f; this->scaleY *= 0.99f; } // this->pendingDamage = this->damage; // test with a small delta if (this->lifeTime >= maxLifeTime) { this->deleteMe = true; // Add to death list GameObjectMan::AddToDeleteList(this); } }
void DGFiniteElement<D>:: GetTraceTrans (int facet, FlatVector<> fcoefs, FlatVector<> coefs) const { Matrix<> trace(fcoefs.Size(), coefs.Size()); CalcTraceMatrix(facet, trace); coefs = Trans (trace) * fcoefs; }
/************************************************* Function: TransToIP Description: 将2进制字符串转换为10进制IP形式 Calls: Trans IntToStr Called By: TransToIP Input: 无 Output: 无 Return: iRes *************************************************/ char * TransToIP(char * f_pString) { scanf("%s", f_pString); // printf("%s\n", f_pString); char *pIPString = (char *)malloc(20);//为IP对应的字符给出16个字节空间 IntToStr(Trans(f_pString, f_pString + 7), pIPString); pIPString[3] = '.'; IntToStr(Trans(f_pString + 8, f_pString + 15), pIPString + 4); pIPString[7] = '.'; IntToStr(Trans(f_pString + 16, f_pString + 23), pIPString + 8); pIPString[11] = '.'; IntToStr(Trans(f_pString + 24, f_pString + 31), pIPString + 12); pIPString[15] = '\0'; return pIPString; }
void TFtrGenNumeric::Add( const TStr& Val, TIntFltKdV& SpV, int& Offset) const { double Flt = GetFlt(Val); SpV.Add(TIntFltKd(Offset, Trans(Flt))); Offset++; }
void TraceTraceBoundary<D> :: T_CalcElementMatrix (const FiniteElement & base_fel, const ElementTransformation & eltrans, FlatMatrix<SCAL> elmat, LocalHeap & lh) const { const CompoundFiniteElement & cfel // product space = dynamic_cast<const CompoundFiniteElement&> (base_fel); // get surface elements const ScalarFiniteElement<D-1> & fel_u = // u space dynamic_cast<const ScalarFiniteElement<D-1>&> (cfel[GetInd1()]); const ScalarFiniteElement<D-1> & fel_e = // u space dynamic_cast<const ScalarFiniteElement<D-1>&> (cfel[GetInd2()]); elmat = SCAL(0.0); IntRange ru = cfel.GetRange(GetInd1()); IntRange re = cfel.GetRange(GetInd2()); int ndofu = ru.Size(); int ndofe = re.Size(); FlatMatrix<SCAL> submat(ndofe, ndofu, lh); submat = SCAL(0.0); FlatVector<> ushape(fel_u.GetNDof(), lh); FlatVector<> eshape(fel_e.GetNDof(), lh); const IntegrationRule ir(fel_u.ElementType(), fel_u.Order() + fel_e.Order()); for (int i = 0 ; i < ir.GetNIP(); i++) { MappedIntegrationPoint<D-1,D> mip(ir[i], eltrans); SCAL cc = coeff_c -> T_Evaluate<SCAL>(mip); fel_u.CalcShape (ir[i], ushape); fel_e.CalcShape (ir[i], eshape); // [ndofe x 1] [1 x ndofu] submat += (cc*mip.GetWeight()) * eshape * Trans(ushape); } elmat.Rows(re).Cols(ru) += submat; if (GetInd1() != GetInd2()) elmat.Rows(ru).Cols(re) += Conj(Trans(submat)); }
void VR_Canvas::privTransform() { Matrix Scale(SCALE, 1.3f, 1.6f, 1.0f); Matrix Trans( TRANS, 0.0f, 0.0f, -5.0f); this->LocalToWorld = Scale * Trans; }
Vec<D> ScalarFiniteElement<D> :: EvaluateGrad (const IntegrationPoint & ip, FlatVector<double> x) const { MatrixFixWidth<D> dshape(ndof); CalcDShape (ip, dshape); Vec<D> grad = Trans (dshape) * x; return grad; }
void DGFiniteElement<D>:: GetGradientTrans (FlatMatrixFixWidth<D> grad, FlatVector<> coefs) const { Matrix<> gmat(D*grad.Height(), coefs.Size()); CalcGradientMatrix (gmat); FlatVector<> vgrad(gmat.Height(), &grad(0,0)); coefs = Trans (gmat) * vgrad; }
void EyeEye<D>::T_CalcElementMatrix (const FiniteElement & base_fel, const ElementTransformation & eltrans, FlatMatrix<SCAL> elmat, LocalHeap & lh) const { const CompoundFiniteElement & cfel // product space = dynamic_cast<const CompoundFiniteElement&> (base_fel); const ScalarFiniteElement<D> & fel_u = // u space dynamic_cast<const ScalarFiniteElement<D>&> (cfel[GetInd1()]); const ScalarFiniteElement<D> & fel_e = // e space dynamic_cast<const ScalarFiniteElement<D>&> (cfel[GetInd2()]); elmat = SCAL(0.0); IntRange ru = cfel.GetRange(GetInd1()); IntRange re = cfel.GetRange(GetInd2()); int ndofe = re.Size(); int ndofu = ru.Size(); Vector<> ushape(ndofu); Vector<> eshape(ndofe); ELEMENT_TYPE eltype = fel_u.ElementType(); const IntegrationRule & ir = SelectIntegrationRule(eltype, fel_u.Order()+fel_e.Order()); FlatMatrix<SCAL> submat(ndofe,ndofu,lh); submat = SCAL(0.0); for(int k=0; k<ir.GetNIP(); k++) { MappedIntegrationPoint<D,D> mip (ir[k],eltrans); fel_u.CalcShape( ir[k], ushape ); fel_e.CalcShape( ir[k], eshape ); SCAL fac = (coeff_a -> T_Evaluate<SCAL>(mip))* mip.GetWeight() ; // [ndofe x D] * [D x ndofu] submat += fac * eshape * Trans(ushape) ; } elmat.Rows(re).Cols(ru) += submat; if (GetInd1() != GetInd2()) elmat.Rows(ru).Cols(re) += Conj(Trans(submat)); }
BOOL CDRFilter::TransformArrowhead(NodeRenderableBounded *N, DocCoord *Point, DocCoord *Other, BOOL Start, INT32 LineWidth, INT32 Distance) { // first of all, work out how much we need to scale this thingy by double Scale = (double)LineWidth / (double)cdrfARROWHEAD_LINEWIDTH; // work out the adj and opp side of the triangle we're going to rotate around double Adj = (double)Point->x - (double)Other->x; double Opp = (double)Point->y - (double)Other->y; // work out the hyp of the triangle double Hyp = sqrt((Adj * Adj) + (Opp * Opp)); // how far we need to move the arrowhead by double Move = Scale * (double)Distance; // calculate a matrix double a, b, c, d, e, f; if(Hyp == 0) { // default thing which shouldn't do too much hard - avoid div by zero a = Scale; b = 0; c = 0; d = Scale; e = Point->x + Move; f = Point->y; } else { double cosTheta = (Adj / Hyp); double sinTheta = (Opp / Hyp); a = Scale * cosTheta; b = Scale * sinTheta; c = 0 - (Scale * sinTheta); d = Scale * cosTheta; e = Point->x + (Move * cosTheta); f = Point->y + (Move * sinTheta); } // knock up a matrix Matrix M = Matrix(a, b, c, d, (INT32)e, (INT32)f); // need to flip it over? if(Start) { Matrix F = Matrix(1, 0, 0, -1, 0, 0); M = F * M; } // transform the node Trans2DMatrix Trans(M); N->Transform(Trans); return TRUE; }
CTV CTM::Degen(CBV &bvX, CBV &bvY) { int a,b,c,i,k=0,w,u,d,e=0,g=1,q,m=GetCountR(),n=GetCountC(); CTV tv(n,'-'); if(!m || bvY.IsZero()) return(tv); if(bvX.IsZero()) return(0); CBM BmY(n,m), BmX(n,n); CTM TmV(n,n); CTM mtt = Trans(); //CTM mtt(mt, 0); CBV bvy; while (g) { switch (d=UnAltRow (mtt, bvX, bvY, tv)) { case -3: return (tv); case -2: { if(!k--) return(0); // Решения нет bvX=BmX[k]; tv=TmV.GetRowTv(k); bvY=BmY[k]; continue; } default: { switch (mtt.UnAltCol(bvX, bvY, tv)) { case -3: return (tv); case -2: { if(!k--) return(0); // Решения нет bvX=BmX[k]; tv=TmV.GetRowTv(k); bvY=BmY[k]; continue; } case -1: continue; default: { if(d<0) d=bvY.LeftOne(-1); w=0; i=-1; // Максимальный столбец, пересекающий d-ю строку while((i=LeftDef(d, i, bvX))!=-1) if((a=mtt.CountDefs(bvY, i))>=w) { b=mtt.CountOnes(bvY, i); c=a-b; if ((a>w)||(b>u)||(c>u)) { e=i; w=a; u=(b<c)? c:b; q=(b<c)? 0 : 1;} } tv.SetBitAt(e, q+'0'); TmV.SetRowTv(k,tv); bvX.SetBitAt(e, 0); BmX.SetRow(k,bvX); bvy=bvY; bvY-=((q) ? mtt.GetRowZero(e) : mtt.GetRowOne(e)); BmY.SetRow(k++, bvY); tv.SetBitAt(e,q^'1'); bvY=bvy -((q) ? mtt.GetRowOne(e) : mtt.GetRowZero(e)); } } } } } return (tv); }
void ScalarFiniteElement<D> :: CalcMappedDShape (const MappedIntegrationPoint<D,D> & mip, SliceMatrix<> dshape) const { CalcDShape (mip.IP(), dshape); for (int i = 0; i < dshape.Height(); i++) { Vec<D> hv = dshape.Row(i); FlatVec<D> (&dshape(i,0)) = Trans (mip.GetJacobianInverse ()) * hv; } }
hMatrix Transpose(hMatrix Mat){ int row = Mat.GetRow(), col = Mat.GetCol(); hMatrix Trans(col,row); for(int i =0; i<row; i++){ for(int j=0; j<col; j++){ Trans.SetElement(j,i,Mat.element(i,j)); } } return Trans; }
/// Matrix vector multiplication void Mult (const FlatVector<TV> & x, FlatVector<TV> & y) const { for (int i = 0; i < n; i++) y(i) = (*this)(i,i) * x(i); for (int i = 0; i < n; i++) for (int j = max2(i-bw+1, 0); j < i; j++) { y(i) += (*this)(i,j) * x(j); y(j) += Trans((*this)(i,j)) * x(i); } }
int main() { Matrix a, b; printf("=====矩阵转置 By:落絮飞雁=====\n"); while (1) { Inst(a); Trans(a, b); Out(b); } return 0; }
BOOL ArrowRec::GetArrowMatrix(const DocCoord& ArrowCentre, const DocCoord& Direction, INT32 ParentLineWidth, Trans2DMatrix* pMatrix) { if (IsNullArrow()) return FALSE; TRACEUSER( "DavidM", wxT("ArrowRec::GetArrowMatrix %d\n"), m_bExtendPath ); ANGLE RotateAngle = CalcAngle(ArrowCentre, Direction); // Now we work how much we need to scale the path DocRect ArrowBounds = ArrowShape->GetBoundingRect(); double TempLineWidth = ParentLineWidth; if (TempLineWidth == 0) TempLineWidth = ZEROWIDTH_ARROW_LINEWIDTH; BOOL DoScale = ScaleWithLineWidth; FIXED16 xscale = DoScale ? ((ArrowWidth.MakeDouble() * TempLineWidth) / LineWidth) : (ArrowWidth); FIXED16 yscale = DoScale ? ((ArrowHeight.MakeDouble() * TempLineWidth) / LineWidth) : (ArrowWidth); // move the centre of the arrow DocRect ArrowRect = ArrowShape->GetBoundingRect(); DocCoord centre; if (!m_bExtendPath) { centre.x = ArrowRect.hi.x; centre.y = (ArrowRect.lo.y + ArrowRect.hi.y) / 2; } else { centre = Centre; } Matrix Mat = Matrix(-centre.x, -centre.y); // Move shape to origin Mat *= Matrix(xscale, yscale); // Scale it Mat *= Matrix(RotateAngle); // Rotate it Mat *= Matrix(ArrowCentre); // Move it to the line point Trans2DMatrix Trans(Mat); *pMatrix = Trans; return TRUE; }
/* Calculates the element matrix. Input is: the finite element: fel the geometry of the element: eltrans Output is: the element matrix: elmat Efficient memorymanagement is provided my locheap */ void MyLaplaceIntegrator :: CalcElementMatrix (const FiniteElement & base_fel, const ElementTransformation & eltrans, FlatMatrix<double> elmat, LocalHeap & lh) const { /* tell the compiler that we are expecting to get an scalar fe in 2D. if not, an exception will be raised */ const ScalarFiniteElement<2> & fel = dynamic_cast<const ScalarFiniteElement<2> &> (base_fel); // number of element basis functions: int ndof = fel.GetNDof(); elmat = 0; Matrix<> dshape_ref(ndof, 2); // gradient on reference element Matrix<> dshape(ndof, 2); // gradient on mapped element /* get integration rule for element geometry, integration order is 2 times element order */ IntegrationRule ir(fel.ElementType(), 2*fel.Order()); // loop over integration points for (int i = 0 ; i < ir.GetNIP(); i++) { // calculate Jacobi matrix in the integration point MappedIntegrationPoint<2,2> mip(ir[i], eltrans); // lambda(x) double lam = coef_lambda -> Evaluate (mip); /* gradient on reference element the i-th row of the matrix is the grad of the i-th shape function */ fel.CalcDShape (ir[i], dshape_ref); // transform it for the mapped element dshape = dshape_ref * mip.GetJacobianInverse(); // integration weight and Jacobi determinant double fac = mip.IP().Weight() * mip.GetMeasure(); // elmat_{i,j} += (fac*lam) * InnerProduct (grad shape_i, grad shape_j) elmat += (fac*lam) * dshape * Trans(dshape); } }
NodeRegularShape * OpBackground::DoCreateRectangle(Spread * pSpread) { ERROR2IF(pSpread == NULL,FALSE,"OpBackground::DoCreateRectangle Bad params error!"); if (pSpread == NULL) return NULL; // This assumes that we have already checked to see if there is a page covering rectangle // already present on this layer. // Create a new rectangle node on the layer NodeRegularShape *pShape = new NodeRegularShape; if (pShape != NULL) { BOOL ok = pShape->SetUpShape(); if (!ok) { // Do something sensible in here delete pShape; return NULL; } // We want to make the rectangle the same size as the current union of // all the pages on the current spread DocRect Rect; pSpread->GetPagesRect(&Rect); /* // We must expand the rectangle by a single pixel as the page redraw // draws a single pixel line around the outside. const MILLIPOINT pixel = (MILLIPOINT)(72000.0/96.0); Rect.Inflate(pixel); */ const INT32 CornerRadius = 0; // No curvature if (pShape->MakeRectangle(Rect.Width(), Rect.Height(), CornerRadius)) { // Translate centre from 0,0 to required position relative to page INT32 XTrans = Rect.lo.x + (Rect.Width()/2); INT32 YTrans = Rect.lo.y + (Rect.Height()/2); Trans2DMatrix Trans(XTrans, YTrans); pShape->Transform(Trans); // finish off the shape pShape->InvalidateBoundingRect(); } } return pShape; }