void FlowBox::applyTransform(const cv::Point3f t) { x += t.x; y += t.y; rotate(t.z); }
void Calculate_HF_deriv(int *tlist,double *vlist,int nfac,int nvert,double *angles,double *Eo,double *E0o,double *up,double TIME,double dist,double Gamma,double A,double Hdist,int N,double WL,double *freqx,double *freqy,int nfreq,double *offset,double *Fr,double *Fi,double *dFdxr,double *dFdxi,double *dFdyr,double *dFdyi,double *dFdzr,double *dFdzi,double *dFdAr,double *dFdAi,double *dFdoffr,double *dFdoffi) { double complex *F=calloc(nfreq,sizeof(double complex)); double complex *F0,*FTda,*FTdb,*FTdc,*FTdd,*FTdh,*FTdg,*FTdx,*FTdy,*FTdz,*FTdA; FTdx=calloc(nfreq*nvert,sizeof(double complex)); FTdy=calloc(nfreq*nvert,sizeof(double complex)); FTdz=calloc(nfreq*nvert,sizeof(double complex)); FTdA=calloc(nfreq*3,sizeof(double complex)); F0=calloc(nfreq,sizeof(double complex)); FTda=malloc(nfreq*sizeof(double complex)); FTdb=malloc(nfreq*sizeof(double complex)); FTdc=malloc(nfreq*sizeof(double complex)); FTdd=malloc(nfreq*sizeof(double complex)); FTdh=malloc(nfreq*sizeof(double complex)); FTdg=malloc(nfreq*sizeof(double complex)); double M[3][3],dMb[3][3],dMo[3][3],dMl[3][3],Mt[3][3],dMbT[3][3],dMoT[3][3],dMlT[3][3]; //Rotation matrices and their derivatives and transposes double R[3][3],Rdb[3][3],Rdl[3][3],Rdo[3][3],RT[3][3]; //Projection matrix, and derivatives of combined projection+rotation matrix double dEdb[3],dEdl[3],dEdo[3],dE0db[3],dE0dl[3],dE0do[3]; double dndx1[3],dndx2[3],dndx3[3],dndy1[3],dndy2[3],dndy3[3],dndz1[3],dndz2[3],dndz3[3]; //Derivatives of the facet normal vector double dBdx1,dBdy1,dBdz1,dBdx2,dBdy2,dBdz2,dBdx3,dBdy3,dBdz3,dBdb,dBdl,dBdo; //Derivatives of facet brightness double *dTBdx,*dTBdy,*dTBdz; //Derivatives of total brightness, allocating memory double *Flux,*Fldx,*Fldy,*Fldz,*FldA; Flux=calloc(nfac,sizeof(double)); Fldx=calloc(nfac*nvert,sizeof(double)); Fldy=calloc(nfac*nvert,sizeof(double)); Fldz=calloc(nfac*nvert,sizeof(double)); FldA=calloc(nfac*3,sizeof(double)); double dTBdA[3]={0}; dTBdx=calloc(nvert,sizeof(double)); dTBdy=calloc(nvert,sizeof(double)); dTBdz=calloc(nvert,sizeof(double)); double dmudx1,dmudy1,dmudz1,dmudx2,dmudy2,dmudz2,dmudx3,dmudy3,dmudz3; double dmu0dx1,dmu0dy1,dmu0dz1,dmu0dx2,dmu0dy2,dmu0dz2,dmu0dx3,dmu0dy3,dmu0dz3; double dmudl,dmudb,dmudo,dmu0dl,dmu0db,dmu0do; //Derivatives of mu and mu0 double dAdx[3],dAdy[3],dAdz[3]; //Facet area derivatives double dadx,dady,dadz,dbdx,dbdy,dbdz; //Derivatives of projected vertices double E[3],E0[3]; //Earth and Sun direction, rotated double side1[3],side2[3]; double n[3]; double v1db[3],v2db[3],v3db[3],v1dl[3],v2dl[3],v3dl[3],v1do[3],v2do[3],v3do[3]; //Derivatives of 2d vertices wrt angles double vr1[3],vr2[3],vr3[3]; double v1[3],v2[3],v3[3]; double complex scale; double dp; double B,TB=0.0; double norm; double mut,mu0t; int t1,t2,t3; int j1,j2,j3; double mu,mu0,area; double *normal; int *visible; int tb1,tb2,tb3; //Indices to the vertices of possible blocker facet int blocked=0; //Distance km->arcsec dp=1/(dist*149597871.0)*180.0/PI*3600.0; visible=calloc(nfac,sizeof(int)); //Calculate_Frame_Matrix_Derivatives(Eo,angles,TIME,rfreq,R,Rdb,Rdl,Rdo); Calculate_Frame_Matrix(Eo,up,R); //Calculate frame change matrix //FacetsOverHorizon(tlist,vlist,nfac,nvert,normal,centroid,NumofBlocks,IndexofBlocks); rotate(angles[0],angles[1],angles[2],0.0,TIME,M,dMb,dMl,dMo); //Construct asteroid->Camera frame matrix, which is //asteroid->world frame->camera frame transpose(M,Mt); //Transpose, since we rotate the model, not view directions transpose(dMb,dMbT); transpose(dMl,dMlT); transpose(dMo,dMoT); mult_mat(R,Mt,RT); mult_vector(M,Eo,E); mult_vector(M,E0o,E0); mult_mat(R,dMbT,Rdb); mult_mat(R,dMlT,Rdl); mult_mat(R,dMoT,Rdo); //Derivatives of E,E0 wrt beta,lambda,omega mult_vector(dMb,Eo,dEdb); mult_vector(dMl,Eo,dEdl); mult_vector(dMo,Eo,dEdo); mult_vector(dMb,E0o,dE0db); mult_vector(dMl,E0o,dE0dl); mult_vector(dMo,E0o,dE0do); dadx=RT[0][0]; dady=RT[0][1]; dadz=RT[0][2]; dbdx=RT[1][0]; dbdy=RT[1][1]; dbdz=RT[1][2]; /*For each facet, * 1)Check if facet is visible * 2) Calculate echo * 3) Convert triangle to range-Doppler frame * 4) Calculate FT */ //Find actual blockers FindActualBlockers(tlist,vlist,nfac,nvert,E,E,1,visible); //visible is nfac vector, visible[j]=1 if facet (j+1)th facet is visible //NOTE INDEXING Calculate_Radiance(tlist,vlist,nfac,nvert,angles,Eo,E0o,TIME,Gamma, A,Hdist,WL,N,Flux,Fldx,Fldy,Fldz,FldA,1); //for(int j=0;j<nfac;j++) for(int j=0;j<nfac;j++) { if(visible[j]==0) continue; //Calculate normal from facet vertices //Vertex indices of the current facet //Note that C indices from 0, matlab from 1 j1=tlist[j*3]-1; j2=tlist[j*3+1]-1; j3=tlist[j*3+2]-1; //Current vertices for(int i=0;i<3;i++) { v1[i]=*(vlist+j1*3+i)*dp; //convert km->arcsec v2[i]=*(vlist+j2*3+i)*dp; v3[i]=*(vlist+j3*3+i)*dp; } //Calculate Normal derivatives (in the original frame) Calculate_Area_and_Normal_Derivative(v1,v2,v3,n,dndx1,dndx2,dndx3,dndy1,dndy2,dndy3,dndz1,dndz2,dndz3,&area,dAdx,dAdy,dAdz); //Calculate normals and centroids mu=DOT(E,n); //Convert to camera frame mult_vector(RT,v1,vr1); mult_vector(RT,v2,vr2); mult_vector(RT,v3,vr3); //Now we should convert to frequency domain, ie calculate the contribution of each facet // Calc_FTC(freqx,freqy,nfreq,vr1[0],vr1[1],vr2[0],vr2[1],vr3[0],vr3[1],F0); Calc_FTC_deriv(freqx,freqy,nfreq,vr1[0],vr1[1],vr2[0],vr2[1],vr3[0],vr3[1],F0,FTda,FTdb,FTdc,FTdd,FTdg,FTdh); //Derivatives wrt angles mult_vector(Rdb,v1,v1db); mult_vector(Rdb,v2,v2db); mult_vector(Rdb,v3,v3db); mult_vector(Rdl,v1,v1dl); mult_vector(Rdl,v2,v2dl); mult_vector(Rdl,v3,v3dl); mult_vector(Rdo,v1,v1do); mult_vector(Rdo,v2,v2do); mult_vector(Rdo,v3,v3do); //Derivatives of mu,mu0 dmudx1=DOT(E,dndx1); dmudx2=DOT(E,dndx2); dmudx3=DOT(E,dndx3); dmudy1=DOT(E,dndy1); dmudy2=DOT(E,dndy2); dmudy3=DOT(E,dndy3); dmudz1=DOT(E,dndz1); dmudz2=DOT(E,dndz2); dmudz3=DOT(E,dndz3); dmudb=DOT(dEdb,n); dmudl=DOT(dEdl,n); dmudo=DOT(dEdo,n); B=Flux[j]; //Derivatives of B dBdx1=Fldx[j*nvert+j1]/dp; dBdx2=Fldx[j*nvert+j2]/dp; dBdx3=Fldx[j*nvert+j3]/dp; dBdy1=Fldy[j*nvert+j1]/dp; dBdy2=Fldy[j*nvert+j2]/dp; dBdy3=Fldy[j*nvert+j3]/dp; dBdz1=Fldz[j*nvert+j1]/dp; dBdz2=Fldz[j*nvert+j2]/dp; dBdz3=Fldz[j*nvert+j3]/dp; dBdb=FldA[3*j]; dBdl=FldA[3*j+1]; dBdo=FldA[3*j+2]; //Derivative of total brightness dTBdx[j1]+=dBdx1*area*mu+B*dAdx[0]*mu+B*area*dmudx1; dTBdx[j2]+=dBdx2*area*mu+B*dAdx[1]*mu+B*area*dmudx2; dTBdx[j3]+=dBdx3*area*mu+B*dAdx[2]*mu+B*area*dmudx3; dTBdy[j1]+=dBdy1*area*mu+B*dAdy[0]*mu+B*area*dmudy1; dTBdy[j2]+=dBdy2*area*mu+B*dAdy[1]*mu+B*area*dmudy2; dTBdy[j3]+=dBdy3*area*mu+B*dAdy[2]*mu+B*area*dmudy3; dTBdz[j1]+=dBdz1*area*mu+B*dAdz[0]*mu+B*area*dmudz1; dTBdz[j2]+=dBdz2*area*mu+B*dAdz[1]*mu+B*area*dmudz2; dTBdz[j3]+=dBdz3*area*mu+B*dAdz[2]*mu+B*area*dmudz3; dTBdA[0]+=dBdb*area*mu+B*area*dmudb; dTBdA[1]+=dBdl*area*mu+B*area*dmudl; dTBdA[2]+=dBdo*area*mu+B*area*dmudo; for(int jf=0;jf<nfreq;jf++) { F[jf]+=B*F0[jf]; FTdx[jf*nvert+j1]+=dBdx1*F0[jf]+B*(FTda[jf]*dadx+FTdb[jf]*dbdx); FTdx[jf*nvert+j2]+=dBdx2*F0[jf]+B*(FTdc[jf]*dadx+FTdd[jf]*dbdx); FTdx[jf*nvert+j3]+=dBdx3*F0[jf]+B*(FTdg[jf]*dadx+FTdh[jf]*dbdx); FTdy[jf*nvert+j1]+=dBdy1*F0[jf]+B*(FTda[jf]*dady+FTdb[jf]*dbdy); FTdy[jf*nvert+j2]+=dBdy2*F0[jf]+B*(FTdc[jf]*dady+FTdd[jf]*dbdy); FTdy[jf*nvert+j3]+=dBdy3*F0[jf]+B*(FTdg[jf]*dady+FTdh[jf]*dbdy); FTdz[jf*nvert+j1]+=dBdz1*F0[jf]+B*(FTda[jf]*dadz+FTdb[jf]*dbdz); FTdz[jf*nvert+j2]+=dBdz2*F0[jf]+B*(FTdc[jf]*dadz+FTdd[jf]*dbdz); FTdz[jf*nvert+j3]+=dBdz3*F0[jf]+B*(FTdg[jf]*dadz+FTdh[jf]*dbdz); //angle derivatives FTdA[jf*3+0]+=dBdb*F0[jf]+B*(FTda[jf]*v1db[0]+FTdb[jf]*v1db[1]+FTdc[jf]*v2db[0]+FTdd[jf]*v2db[1]+FTdg[jf]*v3db[0]+FTdh[jf]*v3db[1]); FTdA[jf*3+1]+=dBdl*F0[jf]+B*(FTda[jf]*v1dl[0]+FTdb[jf]*v1dl[1]+FTdc[jf]*v2dl[0]+FTdd[jf]*v2dl[1]+FTdg[jf]*v3dl[0]+FTdh[jf]*v3dl[1]); FTdA[jf*3+2]+=dBdo*F0[jf]+B*(FTda[jf]*v1do[0]+FTdb[jf]*v1do[1]+FTdc[jf]*v2do[0]+FTdd[jf]*v2do[1]+FTdg[jf]*v3do[0]+FTdh[jf]*v3do[1]); } TB=TB+B*area*mu; } //Normalize with total brightness double complex temp; for(int j=0;j<nfreq;j++) { scale=cexp(2.0*PI*I*(offset[0]*freqx[j]+offset[1]*freqy[j])); for(int k=0;k<nvert;k++) { temp=dp*scale*(FTdx[j*nvert+k]*TB-F[j]*dTBdx[k])/pow(TB,2); dFdxr[j*nvert+k]=creal(temp); dFdxi[j*nvert+k]=cimag(temp); temp=dp*scale*(FTdy[j*nvert+k]*TB-F[j]*dTBdy[k])/pow(TB,2); dFdyr[j*nvert+k]=creal(temp); dFdyi[j*nvert+k]=cimag(temp); temp=dp*scale*(FTdz[j*nvert+k]*TB-F[j]*dTBdz[k])/pow(TB,2); dFdzr[j*nvert+k]=creal(temp); dFdzi[j*nvert+k]=cimag(temp); } temp=scale*(FTdA[j*3+0]*TB-F[j]*dTBdA[0])/pow(TB,2); dFdAr[j*3+0]=creal(temp); dFdAi[j*3+0]=cimag(temp); temp=scale*(FTdA[j*3+1]*TB-F[j]*dTBdA[1])/pow(TB,2); dFdAr[j*3+1]=creal(temp); dFdAi[j*3+1]=cimag(temp); temp=scale*(FTdA[j*3+2]*TB-F[j]*dTBdA[2])/pow(TB,2); dFdAr[j*3+2]=creal(temp); dFdAi[j*3+2]=cimag(temp); temp=cexp(2.0*PI*I*(offset[0]*freqx[j]+offset[1]*freqy[j]))*F[j]/TB; Fr[j]=creal(temp); Fi[j]=cimag(temp); temp=2.0*PI*I*freqx[j]*F[j]; dFdoffr[j*2+0]=creal(temp); dFdoffi[j*2+0]=cimag(temp); temp=2.0*PI*I*freqy[j]*F[j]; dFdoffr[j*2+1]=creal(temp); dFdoffi[j*2+1]=cimag(temp); } free(FTdx); free(FTdy); free(FTdz); free(FTdA); free(dTBdx); free(dTBdy); free(dTBdz); free(FTda); free(FTdb); free(FTdc); free(FTdd); free(FTdg); free(FTdh); free(F0); free(visible); free(Flux); free(Fldx); free(Fldy); free(Fldz); free(FldA); free(F); }
//--------------------------------------------------------------------------- void LogFile::threadExecute() { #ifndef __FreeBSD__ priority(THREAD_PRIORITY_LOWEST); #endif threadFile_.fileName(file_).createIfNotExist(true); AsyncFile lck; lck.fileName(threadFile_.fileName() + ".lck").createIfNotExist(true).removeAfterClose(true); bool exception = false; for(;;){ exception = false; AutoPtr<char,AutoPtrMemoryDestructor> buffer; uintptr_t bufferPos = 0; int64_t ft; try { { AutoLock<LiteWriteLock> lock(threadReadWriteLock_); bufferPos = bufferPos_; ft = bufferDataTTA_ - (gettimeofday() - lastFlushTime_); } if( bufferPos == 0 && !terminated_ ){ bufferSemaphore_.wait(); continue; } if( bufferPos > 0 && !terminated_ && ft >= 0 ){ bufferSemaphore_.timedWait(ft); } { AutoLock<LiteWriteLock> lock(threadReadWriteLock_); buffer.xchg(buffer_); bufferPos = bufferPos_; bufferPos_ = 0; bufferSize_ = 0; } } catch( ExceptionSP & e ){ exceptionStdErrorToSyslog(e); } if( terminated_ && (bufferPos == 0 || exception) ) break; if( bufferPos > 0 ){ exception = false; AutoFileWRLock<AsyncFile> lock; try { lck.open(); lck.wrLock(0,0); lock.setLocked(lck); threadFile_.exclusive(false).open(); threadFile_.seek(threadFile_.size()).writeBuffer(buffer,bufferPos); { AutoLock<LiteWriteLock> lock(threadReadWriteLock_); lastFlushTime_ = gettimeofday(); } rotate(threadFile_); } catch( ExceptionSP & e ){ exception = true; exceptionStdErrorToSyslog(e); } } if( exception ){ threadFile_.close(); lck.close(); } } // fprintf(stderr,"%s %d\n",__FILE__,__LINE__); }
TBool CHuiFxVg10TransformFilter::Draw(CHuiFxEngine& /*aEngine*/, CHuiGc& /*aGc*/, CHuiFxRenderbuffer& aTarget, CHuiFxRenderbuffer& aSource, const TRect& /*aTargetRect*/, const TRect& aSourceRect, TBool /*aHasSurface*/) { aSource.BindAsTexture(ERenderbufferUsageReadOnly); aTarget.BindAsRenderTarget(); VGImage srcImage = (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(&aSource))->AcquireSubImage(aSourceRect); vgLoadIdentity(); vgScale(iScaleX, iScaleY); vgSeti(VG_BLEND_MODE, VG_BLEND_SRC); vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL); identity(); // Matrix multiplication is generally not commutative. // Therefore the order of the transformations matters. // In order to prevent the scaling ang skewing from affecting the translation, // if seems wiser to do the translation first, otherwise the results seem to be unpredictable. // Translation if (iTranslationX != 0.0f || iTranslationY != 0.0f || iTranslationZ != 0.0f) { translate(iTranslationX, iTranslationY, iTranslationZ); } // Scaling if (iScaleX != 1.0f || iScaleY != 1.0f || iScaleZ != 1.0f) { translate(iScaleOriginX, iScaleOriginY, iScaleOriginZ); scale(iScaleX, iScaleY, iScaleZ); translate(-iScaleOriginX, -iScaleOriginY, -iScaleOriginZ); } // Skewing if (iSkewAngleX != 0.0f || iSkewAngleY != 0.0f || iSkewAngleZ != 0.0f) { const TReal32 radsPerDeg = 2.0f * (float)M_PI / 360.0f; TReal32 skewX = tan(iSkewAngleX * radsPerDeg); TReal32 skewY = tan(iSkewAngleY * radsPerDeg); TReal32 skewZ = tan(iSkewAngleZ * radsPerDeg); translate(iSkewOriginX, iSkewOriginY, iSkewOriginZ); shear(skewX, skewY, skewZ); translate(-iSkewOriginX, -iSkewOriginY, -iSkewOriginZ); } // Rotation if (iRotationAngle != 0.0f) { translate(iRotationOriginX, iRotationOriginY, iRotationOriginZ); rotate(iRotationAngle, iRotationAxisX, iRotationAxisY, iRotationAxisZ); translate(-iRotationOriginX, -iRotationOriginY, -iRotationOriginZ); } /* // Translation if (iTranslationX != 0.0f || iTranslationY != 0.0f || iTranslationZ != 0.0f) { translate(iTranslationX, iTranslationY, iTranslationZ); } */ ASSERT(!"TODO: implement the following:"); // TODO: project vertices // TODO: create warp quad matrix from projected vertices, // see http://torus.untergrund.net/misc/projective_image_warping.pdf // TODO load matrix vgDrawImage(srcImage); // TODO: pixel relative parameters HUIFX_VG_INVARIANT(); (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(&aSource))->ReleaseSubImage(srcImage); aTarget.UnbindAsRenderTarget(); aSource.UnbindAsTexture(); return ETrue; }
inline Matrix4 rotateZ(float ang) { return rotate(ang, 0.f,0.f,1.f); }
// rotation local x void Camera::pitch(const screen::math::Degree& iAngle){ SCREEN_DECL_METHOD(pitch); rotate(getRight(), iAngle); }
int Marker::getMarkerId(cv::Mat &markerImage,int &nRotations) { assert(markerImage.rows == markerImage.cols); assert(markerImage.type() == CV_8UC1); cv::Mat grey = markerImage; //threshold image cv::threshold(grey, grey, 125, 255, cv::THRESH_BINARY | cv::THRESH_OTSU); //Markers are divided in 7x7 regions, of which the inner 5x5 belongs to marker info //the external border should be entirely black int cellSize = markerImage.rows / 7; for (int y=0;y<7;y++) { int inc=6; if (y==0 || y==6) inc=1; //for first and last row, check the whole border for (int x=0;x<7;x+=inc) { int cellX = x * cellSize; int cellY = y * cellSize; cv::Mat cell = grey(cv::Rect(cellX,cellY,cellSize,cellSize)); int nZ = cv::countNonZero(cell); if (nZ > (cellSize*cellSize) / 2) { return -1;//can not be a marker because the border element is not black! } } } cv::Mat bitMatrix = cv::Mat::zeros(5,5,CV_8UC1); //get information(for each inner square, determine if it is black or white) for (int y=0;y<5;y++) { for (int x=0;x<5;x++) { int cellX = (x+1)*cellSize; int cellY = (y+1)*cellSize; cv::Mat cell = grey(cv::Rect(cellX,cellY,cellSize,cellSize)); int nZ = cv::countNonZero(cell); if (nZ> (cellSize*cellSize) /2) bitMatrix.at<uchar>(y,x) = 1; } } //check all possible rotations cv::Mat rotations[4]; int distances[4]; rotations[0] = bitMatrix; distances[0] = hammDistMarker(rotations[0]); std::pair<int,int> minDist(distances[0],0); for (int i=1; i<4; i++) { //get the hamming distance to the nearest possible word rotations[i] = rotate(rotations[i-1]); distances[i] = hammDistMarker(rotations[i]); if (distances[i] < minDist.first) { minDist.first = distances[i]; minDist.second = i; } } nRotations = minDist.second; if (minDist.first == 0) { return mat2id(rotations[minDist.second]); } return -1; }
/* ************************************************************************* */ Unit3 Rot3::operator*(const Unit3& p) const { return rotate(p); }
void RotatedHartenLaxLeerSolver::solve(FluidArray& F, const FluidArray& Q_l, const FluidArray& Q_r, double a_l2, double a_r2, double gamma, int dim) const { bool pureHLLC = false, pureHLL = false; Eigen::Matrix<double, 3, 1> d(dim==0 ? 1 : 0, dim==1 ? 1 : 0, dim==2 ? 1 : 0); Eigen::Matrix<double, 3, 1> n1(Q_r[UID::VEL+0]-Q_l[UID::VEL+0], Q_r[UID::VEL+1]-Q_l[UID::VEL+1], Q_r[UID::VEL+2]-Q_l[UID::VEL+2]); Eigen::Matrix<double, 3, 1> n2; if (n1(dim) < 0) n1 = -1*n1; if (n1.norm() < 1.0e-6) pureHLLC = true; else { n1.normalize(); if (n1.cross(d).norm() == 0) pureHLL = true; else { n2 = (n1.cross(d)).cross(n1); if (n2.norm() == 0) pureHLL = true; else { if (n2(dim) < 0) n2 = -1*n2; n2.normalize(); if (n2.cross(d).norm() == 0) pureHLLC = true; } } } if (!pureHLLC && !pureHLL) { FluidArray F1, F2; FluidArray Q_l_R = Q_l; FluidArray Q_r_R = Q_r; //Eigen::Matrix<double, 3, 3> R1 = getRotationMatrix(axis1, alpha1, beta1); Eigen::Matrix<double, 3, 3> R1 = getRotationFromA2B(n1, d); rotate(R1, Q_l_R); rotate(R1, Q_r_R); m_hll.solve(F1, Q_l_R, Q_r_R, a_l2, a_r2, gamma, dim); //Eigen::Matrix<double, 3, 3> R1_inv = getInverseRotationMatrix(axis1, alpha1, beta1); Eigen::Matrix<double, 3, 3> R1_inv = getRotationFromA2B(d, n1); rotate(R1_inv, Q_l_R); rotate(R1_inv, Q_r_R); rotate(R1_inv, F1); //Eigen::Matrix<double, 3, 3> R2 = getRotationMatrix(axis2, alpha2, beta2); Eigen::Matrix<double, 3, 3> R2 = getRotationFromA2B(n2, d); rotate(R2, Q_l_R); rotate(R2, Q_r_R); m_hllc.solve(F2, Q_l_R, Q_r_R, a_l2, a_r2, gamma, dim); //Eigen::Matrix<double, 3, 3> R2_inv = getInverseRotationMatrix(axis2, alpha2, beta2); Eigen::Matrix<double, 3, 3> R2_inv = getRotationFromA2B(d, n2); rotate(R2_inv, Q_l_R); rotate(R2_inv, Q_r_R); rotate(R2_inv, F2); for (int iu = 0; iu < UID::N; ++iu) F[iu] = std::abs(d.dot(n1))*F1[iu] + std::abs(d.dot(n2))*F2[iu]; } else if (pureHLL) m_hll.solve(F, Q_l, Q_r, a_l2, a_r2, gamma, dim); else if (pureHLLC) m_hllc.solve(F, Q_l, Q_r, a_l2, a_r2, gamma, dim); }
bool TimePermRingBuffer::insert(DataSample &data, long current_time) { long last_time, delta, steps; m_lastTimeStamp.readData((void*)&last_time); delta = current_time - last_time; #ifdef SERIAL_DEBUG Serial.print("==== TimePermRingBuffer["); Serial.print(m_bufferStart, DEC); Serial.print("]::insert -> current="); Serial.print(current_time, DEC); Serial.print(" - last_time="); Serial.print(last_time, DEC); Serial.print(" : delta="); Serial.println(delta, DEC); #endif if ( delta < 0 ) { // something happened: we are going back in the past // just let clear everything and start orer #ifdef SERIAL_DEBUG Serial.println("------ back to the past -> clear"); #endif clear(); m_lastTimeStamp.writeData((void*)¤t_time); push(data.data()); return true; } if ( delta > timeSpan() ) { // elapsed time greater than buffer time span #ifdef SERIAL_DEBUG Serial.println("------ elapsed time greater than buffer time span -> clear"); #endif clear(); m_lastTimeStamp.writeData((void*)¤t_time); push(data.data()); } else { if ( 0 == delta % m_period ) { steps = delta / m_period; if ( steps > 0 ) { // this is time to insert the new sample if ( steps > 1 ) { // elapsed time more than one single period #ifdef SERIAL_DEBUG Serial.print("------ elapsed time more than a single period -> rotate steps = "); Serial.println(steps-1, DEC); #endif rotate(steps-1); } m_lastTimeStamp.writeData((void*)¤t_time); push(data.data()); } } else { #ifdef SERIAL_DEBUG Serial.println("------ period not elapsed -> no insertion"); #endif return false; } } return true; }
void pulsesequence() { /* Internal variable declarations *************************/ double freqEx[MAXNSLICE]; double pespoil_amp,maxgradtime,spoilMoment,perTime,pe2_offsetamp,tau1,te_delay,tr_delay; double te2=0.0,te3=0.0,te2min,te3min,tau2,tau3,te2_delay,te3_delay=0; char minte2[MAXSTR],minte3[MAXSTR],spoilflag[MAXSTR],perName[MAXSTR]; int sepSliceRephase,sepReadRephase=0,readrev,table,shapeEx; int i; /* Real-time variables used in this sequence **************/ int vpe_steps = v1; // Number of PE steps int vpe_ctr = v2; // PE loop counter int vms_slices = v3; // Number of slices int vms_ctr = v4; // Slice loop counter int vpe_offset = v5; // PE/2 for non-table offset int vpe_mult = v6; // PE multiplier, ranges from -PE/2 to PE/2 int vper_mult = v7; // PE rewinder multiplier; turn off rewinder when 0 int vpe2_steps = v8; // Number of PE2 steps int vpe2_ctr = v9; // PE2 loop counter int vpe2_mult = v10; // PE2 multiplier int vpe2_offset = v11; // PE2/2 for non-table offset int vpe2r_mult = v12; // PE2 rewinder multiplier int vssc = v13; // Compressed steady-states int vacquire = v14; // Argument for setacqvar, to skip steady state acquires int vrfspoil_ctr = v15; // RF spoil counter int vrfspoil = v16; // RF spoil multiplier int vtrimage = v17; // Counts down from nt, trimage delay when 0 int vne = v18; // Number of echoes int vne_ctr = v19; // Echo loop counter int vneindex = v20; // Echo index, odd or even int vnelast = v21; // Check for last echo int vtrigblock = v22; // Number of slices per trigger block /* Initialize paramaters **********************************/ init_mri(); getstr("spoilflag",spoilflag); te2=getval("te2"); te3=getval("te3"); getstr("minte2",minte2); getstr("minte3",minte3); readrev=(int)getval("readrev"); /* Check for external PE table ***************************/ table = 0; if (strcmp(petable,"n") && strcmp(petable,"N") && strcmp(petable,"")) { loadtable(petable); table = 1; } /* Set Rcvr/Xmtr phase increments for RF Spoiling ********/ /* Ref: Zur, Y., Magn. Res. Med., 21, 251, (1991) *******/ if (rfspoil[0] == 'y') { rcvrstepsize(rfphase); obsstepsize(rfphase); } /* Initialize gradient structures *************************/ shape_rf(&p1_rf,"p1",p1pat,p1,flip1,rof1,rof2 ); // excitation pulse init_slice(&ss_grad,"ss",thk); // slice select gradient init_slice_refocus(&ssr_grad,"ssr"); // slice refocus gradient init_readout(&ro_grad,"ro",lro,np,sw); // readout gradient init_readout_refocus(&ror_grad,"ror"); // dephase gradient init_phase(&pe_grad,"pe",lpe,nv); // phase encode gradient init_phase(&pe2_grad,"pe2",lpe2,nv2); // 2nd phase encode gradient init_dephase(&spoil_grad,"spoil"); // optimized spoiler init_dephase(&ref_grad,"ref"); // readout rephase /* RF Calculations ****************************************/ calc_rf(&p1_rf,"tpwr1","tpwr1f"); /* Gradient calculations **********************************/ calc_slice(&ss_grad,&p1_rf,WRITE,"gss"); calc_slice_refocus(&ssr_grad, &ss_grad, WRITE,"gssr"); calc_readout(&ro_grad, WRITE,"gro","sw","at"); calc_readout_refocus(&ror_grad,&ro_grad,NOWRITE,"gror"); calc_phase(&pe_grad, NOWRITE,"gpe","tpe"); calc_phase(&pe2_grad,NOWRITE,"gpe2",""); calc_dephase(&ref_grad,WRITE,ro_grad.m0,"",""); if (spoilflag[0] == 'y') { spoilMoment = ro_grad.acqTime*ro_grad.roamp; // Optimal spoiling is at*gro for 2pi per pixel spoilMoment -= ro_grad.m0def; // Subtract partial spoiling from back half of readout if (perewind[0] == 'y') calc_dephase(&spoil_grad,NOWRITE,spoilMoment,"gspoil","tspoil"); else calc_dephase(&spoil_grad,WRITE,spoilMoment,"gspoil","tspoil"); } /* Is TE long enough for separate slab refocus? *******/ maxgradtime = MAX(ror_grad.duration,pe_grad.duration); if (spoilflag[0] == 'y') maxgradtime = MAX(maxgradtime,spoil_grad.duration); tau1 = ss_grad.rfCenterBack + ssr_grad.duration + maxgradtime + alfa + ro_grad.timeToEcho + 4e-6; if ((te >= tau1) && (minte[0] != 'y')) sepSliceRephase = 1; // Set flag for separate slice rephase else { sepSliceRephase = 0; pe2_grad.areaOffset = ss_grad.m0ref; // Add slab refocus on pe2 axis calc_phase(&pe2_grad,NOWRITE,"gpe2",""); // Recalculate pe2 to include slab refocus } /* Equalize refocus and PE gradient durations *************/ pespoil_amp = 0.0; perTime = 0.0; if ((perewind[0] == 'y') && (spoilflag[0] == 'y')) { // All four must be single shape if (ror_grad.duration > spoil_grad.duration) { // calc_sim first with ror calc_sim_gradient(&pe_grad,&pe2_grad,&ror_grad,tpemin,WRITE); calc_sim_gradient(&ror_grad,&spoil_grad,&null_grad,tpemin,NOWRITE); } else { // calc_sim first with spoil calc_sim_gradient(&pe_grad,&pe2_grad,&spoil_grad,tpemin,WRITE); calc_sim_gradient(&ror_grad,&spoil_grad,&null_grad,tpemin,WRITE); } strcpy(perName,pe_grad.name); perTime = pe_grad.duration; } else { // post-acquire shape will be either pe or spoil, but not both calc_sim_gradient(&ror_grad,&pe_grad,&pe2_grad,tpemin,WRITE); if ((perewind[0] == 'y') && (spoilflag[0] == 'n')) { // Rewinder, no spoiler strcpy(perName,pe_grad.name); perTime = pe_grad.duration; spoil_grad.amp = 0.0; } else if ((perewind[0] == 'n') && (spoilflag[0] == 'y')) { // Spoiler, no rewinder strcpy(perName,spoil_grad.name); perTime = spoil_grad.duration; pespoil_amp = spoil_grad.amp; // Apply spoiler on PE & PE2 axis if no rewinder } } pe2_offsetamp = sepSliceRephase ? 0.0 : pe2_grad.offsetamp; // pe2 slab refocus /* Create optional prepulse events ************************/ if (sat[0] == 'y') create_satbands(); if (fsat[0] == 'y') create_fatsat(); if (mt[0] == 'y') create_mtc(); if (ir[0] == 'y') create_inversion_recovery(); /* Set up frequency offset pulse shape list ********/ offsetlist(pss,ss_grad.ssamp,0,freqEx,ns,seqcon[1]); shapeEx = shapelist(p1_rf.pulseName,ss_grad.rfDuration,freqEx,ns,ss_grad.rfFraction,seqcon[1]); /* Check that all Gradient calculations are ok ************/ sgl_error_check(sglerror); /* Min TE ******************************************/ tau1 = ss_grad.rfCenterBack + pe_grad.duration + alfa + ro_grad.timeToEcho; tau1 += (sepSliceRephase) ? ssr_grad.duration : 0.0; // Add slice refocusing if separate event temin = tau1 + 4e-6; /* ensure that te_delay is at least 4us */ if (minte[0] == 'y') { te = temin; putvalue("te",te); } if (te < temin) { abort_message("TE too short. Minimum TE= %.2fms\n",temin*1000+0.005); } te_delay = te - tau1; /* Min TE2 *****************************************/ tau2 = (readrev) ? 2*ro_grad.timeFromEcho+alfa : ro_grad.duration+ref_grad.duration; te2min = tau2 + 4e-6; if (minte2[0] == 'y') { te2 = te2min; putvalue("te2",te2); } if (te2 < te2min) { abort_message("TE2 too short. Minimum TE2= %.2fms\n",te2min*1000+0.005); } if (readrev) te2_delay = te2 - tau2; else { tau2 = ro_grad.duration + 2*ror_grad.duration; if (te2 >= tau2) { sepReadRephase = 1; // Set flag for separate read rephase te2_delay = te2 - ro_grad.duration - 2*ror_grad.duration; } else { sepReadRephase = 0; if (te2 > te2min+4e-6) { ref_grad.duration = granularity(te2-ro_grad.duration-8e-6,GRADIENT_RES); ref_grad.calcFlag = AMPLITUDE_FROM_MOMENT_DURATION; calc_dephase(&ref_grad,WRITE,ro_grad.m0,"",""); } te2_delay = te2 - ro_grad.duration - ref_grad.duration; } } /* Min TE3 *****************************************/ if (readrev) { tau3 = 2*ro_grad.timeToEcho + alfa; te3min = tau3 + 4e-6; if (minte3[0] == 'y') { te3 = te3min; putvalue("te3",te3); } if (te3 < te3min) { abort_message("TE3 too short. Minimum TE3= %.2fms\n",te3min*1000+0.005); } te3_delay = te3 - tau3; } /* Now set the TE array accordingly */ putCmd("TE = 0"); /* Re-initialize TE */ putCmd("TE[1] = %f",te*1000); if (readrev) { for (i=1;i<ne;i++) { if (i%2 == 0) putCmd("TE[%d] = TE[%d]+%f",i+1,i,te3*1000); else putCmd("TE[%d] = TE[%d]+%f",i+1,i,te2*1000); } } else { for (i=1;i<ne;i++) putCmd("TE[%d] = TE[%d]+%f",i+1,i,te2*1000); } /* Check nsblock, the number of slices blocked together (used for triggering and/or inversion recovery) */ check_nsblock(); /* Min TR ******************************************/ trmin = ss_grad.duration + te_delay + pe_grad.duration + ne*ro_grad.duration + perTime + 8e-6; trmin += (sepSliceRephase) ? ssr_grad.duration : 0.0; // Add slice refocusing if separate event if (readrev) trmin += (ne/2)*te2_delay + ((ne-1)/2)*te3_delay; else trmin += (sepReadRephase) ? (ne-1)*(te2_delay+2*ror_grad.duration) : (ne-1)*(te2_delay+ref_grad.duration); /* Increase TR if any options are selected *********/ if (sat[0] == 'y') trmin += satTime; if (fsat[0] == 'y') trmin += fsatTime; if (mt[0] == 'y') trmin += mtTime; if (ticks > 0) trmin += 4e-6; /* Adjust for all slices ***************************/ trmin *= ns; /* Inversion recovery *********************************/ if (ir[0] == 'y') { /* tiaddTime is the additional time beyond IR component to be included in ti */ /* satTime, fsatTime and mtTime all included as those modules will be after IR */ tiaddTime = satTime + fsatTime + mtTime + 4e-6 + ss_grad.rfCenterFront; /* calc_irTime checks ti and returns the time of all IR components */ trmin += calc_irTime(tiaddTime,trmin,mintr[0],tr,&trtype); } if (mintr[0] == 'y') { tr = trmin; putvalue("tr",tr); } if (FP_LT(tr,trmin)) { abort_message("TR too short. Minimum TR = %.2fms\n",trmin*1000+0.005); } /* Calculate tr delay */ tr_delay = granularity((tr-trmin)/ns,GRADIENT_RES); /* Set pe_steps for profile or full image **********/ pe_steps = prep_profile(profile[0],nv,&pe_grad,&per_grad); F_initval(pe_steps/2.0,vpe_offset); pe2_steps = prep_profile(profile[1],nv2,&pe2_grad,&null_grad); F_initval(pe2_steps/2.0,vpe2_offset); /* Shift DDR for pro *******************************/ roff = -poffset(pro,ro_grad.roamp); /* Adjust experiment time for VnmrJ *******************/ if (ssc<0) { if (seqcon[2]=='s') g_setExpTime(trmean*ntmean*pe_steps*pe2_steps*arraydim); else if (seqcon[3]=='s') g_setExpTime(trmean*pe2_steps*(ntmean*pe_steps*arraydim - ssc*arraydim)); else g_setExpTime(trmean*(ntmean*pe_steps*pe2_steps*arraydim - ssc*arraydim)); } else { if (seqcon[2]=='s') g_setExpTime(trmean*ntmean*pe_steps*pe2_steps*arraydim); else g_setExpTime(trmean*ntmean*pe_steps*pe2_steps*arraydim + tr*ssc); } /* Return parameters to VnmrJ */ putvalue("tror",ror_grad.duration); // ROR duration putvalue("gpe",pe_grad.peamp); // PE max grad amp putvalue("gss",ss_grad.ssamp); // Excitation slice grad putvalue("gro",ro_grad.roamp); // RO grad /* PULSE SEQUENCE ***************************************/ status(A); rotate(); triggerSelect(trigger); // Select trigger input 1/2/3 obsoffset(resto); delay(4e-6); initval(fabs(ssc),vssc); // Compressed steady-state counter if (seqcon[2]=='s') assign(zero,vssc); // Zero for standard peloop assign(zero,vrfspoil_ctr); // RF spoil phase counter assign(zero,vrfspoil); // RF spoil multiplier assign(one,vacquire); // real-time acquire flag setacqvar(vacquire); // Turn on acquire when vacquire is zero /* trigger */ if (ticks > 0) F_initval((double)nsblock,vtrigblock); /* Begin phase-encode loop ****************************/ peloop2(seqcon[3],pe2_steps,vpe2_steps,vpe2_ctr); /* Begin phase-encode loop ****************************/ peloop(seqcon[2],pe_steps,vpe_steps,vpe_ctr); if (trtype) delay(ns*tr_delay); // relaxation delay /* Compressed steady-states: 1st array & transient, all arrays if ssc is negative */ if ((ix > 1) && (ssc > 0)) assign(zero,vssc); sub(vpe_ctr,vssc,vpe_ctr); // vpe_ctr counts up from -ssc assign(zero,vssc); if (seqcon[2] == 's') assign(zero,vacquire); // Always acquire for non-compressed loop else { ifzero(vpe_ctr); assign(zero,vacquire); // Start acquiring when vpe_ctr reaches zero endif(vpe_ctr); } /* Use standard encoding order for 2nd PE dimension */ ifzero(vacquire); sub(vpe2_ctr,vpe2_offset,vpe2_mult); elsenz(vacquire); sub(zero,vpe2_offset,vpe2_mult); endif(vacquire); /* Set rcvr/xmtr phase for RF spoiling *******************/ if (rfspoil[0] == 'y') { incr(vrfspoil_ctr); // vrfspoil_ctr = 1 2 3 4 5 6 add(vrfspoil,vrfspoil_ctr,vrfspoil); // vrfspoil = 1 3 6 10 15 21 xmtrphase(vrfspoil); rcvrphase(vrfspoil); } /* Read external kspace table if set ******************/ if (table) getelem(t1,vpe_ctr,vpe_mult); else { ifzero(vacquire); sub(vpe_ctr,vpe_offset,vpe_mult); elsenz(vacquire); sub(zero,vpe_offset,vpe_mult); // Hold PE mult at initial value for steady states endif(vacquire); } /* PE rewinder follows PE table; zero if turned off ***/ if (perewind[0] == 'y') { assign(vpe_mult,vper_mult); assign(vpe2_mult,vpe2r_mult); } else { assign(zero,vper_mult); assign(zero,vpe2r_mult); } /* Begin multislice loop ******************************/ msloop(seqcon[1],ns,vms_slices,vms_ctr); if (!trtype) delay(tr_delay); // Relaxation delay if (ticks > 0) { modn(vms_ctr,vtrigblock,vtest); ifzero(vtest); // if the beginning of an trigger block xgate(ticks); grad_advance(gpropdelay); delay(4e-6); elsenz(vtest); delay(4e-6); endif(vtest); } /* TTL scope trigger **********************************/ sp1on(); delay(4e-6); sp1off(); /* Prepulse options ***********************************/ if (ir[0] == 'y') inversion_recovery(); if (sat[0] == 'y') satbands(); if (fsat[0] == 'y') fatsat(); if (mt[0] == 'y') mtc(); /* Slice select RF pulse ******************************/ obspower(p1_rf.powerCoarse); obspwrf(p1_rf.powerFine); delay(4e-6); obl_shapedgradient(ss_grad.name,ss_grad.duration,0,0,ss_grad.amp,NOWAIT); delay(ss_grad.rfDelayFront); shapedpulselist(shapeEx,ss_grad.rfDuration,oph,rof1,rof2,seqcon[1],vms_ctr); delay(ss_grad.rfDelayBack); /* Phase encode, refocus, and dephase gradient ********/ if (sepSliceRephase) { // separate slice refocus gradient obl_shapedgradient(ssr_grad.name,ssr_grad.duration,0,0,-ssr_grad.amp,WAIT); delay(te_delay); // delay between slab refocus and pe pe2_shapedgradient(pe_grad.name,pe_grad.duration,-ror_grad.amp,0,-pe2_offsetamp, -pe_grad.increment,-pe2_grad.increment,vpe_mult,vpe2_mult,WAIT); } else { pe2_shapedgradient(pe_grad.name,pe_grad.duration,-ror_grad.amp,0,-pe2_offsetamp, -pe_grad.increment,-pe2_grad.increment,vpe_mult,vpe2_mult,WAIT); delay(te_delay); // delay after refocus/pe } F_initval(ne,vne); loop(vne,vne_ctr); if (readrev) { mod2(vne_ctr,vneindex); ifzero(vneindex); /* Shift DDR for pro *******************************/ roff = -poffset(pro,ro_grad.roamp); /* Readout gradient ********************************/ obl_shapedgradient(ro_grad.name,ro_grad.duration,ro_grad.amp,0,0,NOWAIT); delay(ro_grad.atDelayFront); /* Acquisition ***************************************/ startacq(alfa); acquire(np,1.0/sw); delay(ro_grad.atDelayBack); endacq(); sub(vne,vne_ctr,vnelast); sub(vnelast,one,vnelast); ifzero(vnelast); elsenz(vnelast); delay(te2_delay); endif(vnelast); elsenz(vneindex); /* Shift DDR for pro *******************************/ roff = -poffset(pro,-ro_grad.roamp); /* Readout gradient ********************************/ obl_shapedgradient(ro_grad.name,ro_grad.duration,-ro_grad.amp,0,0,NOWAIT); delay(ro_grad.atDelayFront); /* Acquisition ***************************************/ startacq(alfa); acquire(np,1.0/sw); delay(ro_grad.atDelayBack); endacq(); sub(vne,vne_ctr,vnelast); sub(vnelast,one,vnelast); ifzero(vnelast); elsenz(vnelast); delay(te3_delay); endif(vnelast); endif(vneindex); } else { /* Shift DDR for pro *******************************/ roff = -poffset(pro,ro_grad.roamp); /* Readout gradient ********************************/ obl_shapedgradient(ro_grad.name,ro_grad.duration,ro_grad.amp,0,0,NOWAIT); delay(ro_grad.atDelayFront); /* Acquisition ***************************************/ startacq(alfa); acquire(np,1.0/sw); delay(ro_grad.atDelayBack); endacq(); sub(vne,vne_ctr,vnelast); sub(vnelast,one,vnelast); ifzero(vnelast); elsenz(vnelast); if (sepReadRephase) { obl_shapedgradient(ror_grad.name,ror_grad.duration,-ror_grad.amp,0,0,WAIT); delay(te2_delay); obl_shapedgradient(ror_grad.name,ror_grad.duration,-ror_grad.amp,0,0,WAIT); } else { obl_shapedgradient(ref_grad.name,ref_grad.duration,-ref_grad.amp,0,0,WAIT); delay(te2_delay); } endif(vnelast); } endloop(vne_ctr); /* Rewind / spoiler gradient **************************/ if ((perewind[0] == 'y') || (spoilflag[0] == 'y')) { pe2_shapedgradient(perName,perTime,spoil_grad.amp,pespoil_amp,pespoil_amp, pe_grad.increment,pe2_grad.increment,vper_mult,vpe2r_mult,WAIT); } endmsloop(seqcon[1],vms_ctr); endpeloop(seqcon[2],vpe_ctr); endpeloop(seqcon[3],vpe2_ctr); /* Inter-image delay **********************************/ sub(ntrt,ct,vtrimage); decr(vtrimage); ifzero(vtrimage); delay(trimage); endif(vtrimage); }
/// process 64 bytes void MD5::processBlock(const void* data) { // get last hash uint32_t a = m_hash[0]; uint32_t b = m_hash[1]; uint32_t c = m_hash[2]; uint32_t d = m_hash[3]; // data represented as 16x 32-bit words const uint32_t* words = (uint32_t*) data; // computations are little endian, swap data if necessary #if defined(__BYTE_ORDER) && (__BYTE_ORDER != 0) && (__BYTE_ORDER == __BIG_ENDIAN) #define LITTLEENDIAN(x) swap(x) #else #define LITTLEENDIAN(x) (x) #endif // first round uint32_t word0 = LITTLEENDIAN(words[ 0]); a = rotate(a + f1(b,c,d) + word0 + 0xd76aa478, 7) + b; uint32_t word1 = LITTLEENDIAN(words[ 1]); d = rotate(d + f1(a,b,c) + word1 + 0xe8c7b756, 12) + a; uint32_t word2 = LITTLEENDIAN(words[ 2]); c = rotate(c + f1(d,a,b) + word2 + 0x242070db, 17) + d; uint32_t word3 = LITTLEENDIAN(words[ 3]); b = rotate(b + f1(c,d,a) + word3 + 0xc1bdceee, 22) + c; uint32_t word4 = LITTLEENDIAN(words[ 4]); a = rotate(a + f1(b,c,d) + word4 + 0xf57c0faf, 7) + b; uint32_t word5 = LITTLEENDIAN(words[ 5]); d = rotate(d + f1(a,b,c) + word5 + 0x4787c62a, 12) + a; uint32_t word6 = LITTLEENDIAN(words[ 6]); c = rotate(c + f1(d,a,b) + word6 + 0xa8304613, 17) + d; uint32_t word7 = LITTLEENDIAN(words[ 7]); b = rotate(b + f1(c,d,a) + word7 + 0xfd469501, 22) + c; uint32_t word8 = LITTLEENDIAN(words[ 8]); a = rotate(a + f1(b,c,d) + word8 + 0x698098d8, 7) + b; uint32_t word9 = LITTLEENDIAN(words[ 9]); d = rotate(d + f1(a,b,c) + word9 + 0x8b44f7af, 12) + a; uint32_t word10 = LITTLEENDIAN(words[10]); c = rotate(c + f1(d,a,b) + word10 + 0xffff5bb1, 17) + d; uint32_t word11 = LITTLEENDIAN(words[11]); b = rotate(b + f1(c,d,a) + word11 + 0x895cd7be, 22) + c; uint32_t word12 = LITTLEENDIAN(words[12]); a = rotate(a + f1(b,c,d) + word12 + 0x6b901122, 7) + b; uint32_t word13 = LITTLEENDIAN(words[13]); d = rotate(d + f1(a,b,c) + word13 + 0xfd987193, 12) + a; uint32_t word14 = LITTLEENDIAN(words[14]); c = rotate(c + f1(d,a,b) + word14 + 0xa679438e, 17) + d; uint32_t word15 = LITTLEENDIAN(words[15]); b = rotate(b + f1(c,d,a) + word15 + 0x49b40821, 22) + c; // second round a = rotate(a + f2(b,c,d) + word1 + 0xf61e2562, 5) + b; d = rotate(d + f2(a,b,c) + word6 + 0xc040b340, 9) + a; c = rotate(c + f2(d,a,b) + word11 + 0x265e5a51, 14) + d; b = rotate(b + f2(c,d,a) + word0 + 0xe9b6c7aa, 20) + c; a = rotate(a + f2(b,c,d) + word5 + 0xd62f105d, 5) + b; d = rotate(d + f2(a,b,c) + word10 + 0x02441453, 9) + a; c = rotate(c + f2(d,a,b) + word15 + 0xd8a1e681, 14) + d; b = rotate(b + f2(c,d,a) + word4 + 0xe7d3fbc8, 20) + c; a = rotate(a + f2(b,c,d) + word9 + 0x21e1cde6, 5) + b; d = rotate(d + f2(a,b,c) + word14 + 0xc33707d6, 9) + a; c = rotate(c + f2(d,a,b) + word3 + 0xf4d50d87, 14) + d; b = rotate(b + f2(c,d,a) + word8 + 0x455a14ed, 20) + c; a = rotate(a + f2(b,c,d) + word13 + 0xa9e3e905, 5) + b; d = rotate(d + f2(a,b,c) + word2 + 0xfcefa3f8, 9) + a; c = rotate(c + f2(d,a,b) + word7 + 0x676f02d9, 14) + d; b = rotate(b + f2(c,d,a) + word12 + 0x8d2a4c8a, 20) + c; // third round a = rotate(a + f3(b,c,d) + word5 + 0xfffa3942, 4) + b; d = rotate(d + f3(a,b,c) + word8 + 0x8771f681, 11) + a; c = rotate(c + f3(d,a,b) + word11 + 0x6d9d6122, 16) + d; b = rotate(b + f3(c,d,a) + word14 + 0xfde5380c, 23) + c; a = rotate(a + f3(b,c,d) + word1 + 0xa4beea44, 4) + b; d = rotate(d + f3(a,b,c) + word4 + 0x4bdecfa9, 11) + a; c = rotate(c + f3(d,a,b) + word7 + 0xf6bb4b60, 16) + d; b = rotate(b + f3(c,d,a) + word10 + 0xbebfbc70, 23) + c; a = rotate(a + f3(b,c,d) + word13 + 0x289b7ec6, 4) + b; d = rotate(d + f3(a,b,c) + word0 + 0xeaa127fa, 11) + a; c = rotate(c + f3(d,a,b) + word3 + 0xd4ef3085, 16) + d; b = rotate(b + f3(c,d,a) + word6 + 0x04881d05, 23) + c; a = rotate(a + f3(b,c,d) + word9 + 0xd9d4d039, 4) + b; d = rotate(d + f3(a,b,c) + word12 + 0xe6db99e5, 11) + a; c = rotate(c + f3(d,a,b) + word15 + 0x1fa27cf8, 16) + d; b = rotate(b + f3(c,d,a) + word2 + 0xc4ac5665, 23) + c; // fourth round a = rotate(a + f4(b,c,d) + word0 + 0xf4292244, 6) + b; d = rotate(d + f4(a,b,c) + word7 + 0x432aff97, 10) + a; c = rotate(c + f4(d,a,b) + word14 + 0xab9423a7, 15) + d; b = rotate(b + f4(c,d,a) + word5 + 0xfc93a039, 21) + c; a = rotate(a + f4(b,c,d) + word12 + 0x655b59c3, 6) + b; d = rotate(d + f4(a,b,c) + word3 + 0x8f0ccc92, 10) + a; c = rotate(c + f4(d,a,b) + word10 + 0xffeff47d, 15) + d; b = rotate(b + f4(c,d,a) + word1 + 0x85845dd1, 21) + c; a = rotate(a + f4(b,c,d) + word8 + 0x6fa87e4f, 6) + b; d = rotate(d + f4(a,b,c) + word15 + 0xfe2ce6e0, 10) + a; c = rotate(c + f4(d,a,b) + word6 + 0xa3014314, 15) + d; b = rotate(b + f4(c,d,a) + word13 + 0x4e0811a1, 21) + c; a = rotate(a + f4(b,c,d) + word4 + 0xf7537e82, 6) + b; d = rotate(d + f4(a,b,c) + word11 + 0xbd3af235, 10) + a; c = rotate(c + f4(d,a,b) + word2 + 0x2ad7d2bb, 15) + d; b = rotate(b + f4(c,d,a) + word9 + 0xeb86d391, 21) + c; // update hash m_hash[0] += a; m_hash[1] += b; m_hash[2] += c; m_hash[3] += d; }
void graphDistortion(int size, float G1[size][2], float G2[size][2], float centerX, float centerY){ rotate(size, G1, G2, centerX, centerY); translate(size, G2, G2, centerX, centerY); } //end of function
int main() { FILE *fin, *fout; int i, j, change; Board in, out; fin = fopen("transform.in", "r"); fout = fopen("transform.out", "w"); assert(fin != NULL && fout != NULL); fscanf(fin, "%d", &num); //printf("num = %d\n", num); in.n = num; out.n = num; //fscanf(fin, "%d", &i); getc(fin); for (i = 0; i < num; ++i) { for (j = 0; j < num; ++j) { in.b[i][j] = getc(fin); //fscanf(fin, "%c", &(Matrix_in[i][j])); } getc(fin); } for (i = 0; i < num; ++i) { for (j = 0; j < num; ++j) { out.b[i][j] = getc(fin); //fscanf(fin, "%c", &(Matrix_in[i][j])); } getc(fin); } //print_matrix(in); //printf("\n"); //print_matrix(rotate(in)); //printf("\n"); //print_matrix(rotate(rotate(in))); //printf("\n"); //print_matrix(rotate(rotate(rotate(in)))); //printf("\n"); //print_matrix(reflect(in)); //printf("\n"); //print_matrix(combin(in)); if (is_equal(out, rotate(in))) change = 1; else if(is_equal(out, rotate(rotate(in)))) change = 2; else if(is_equal(out, rotate(rotate(rotate(in))))) change = 3; else if(is_equal(out, reflect(in))) change = 4; else if(is_equal(out, rotate(reflect(in))) || is_equal(out, rotate(rotate(reflect(in)))) || is_equal(out, rotate(rotate(rotate(reflect(in)))))) change = 5; else if(is_equal(out, in)) change = 6; else change = 7; //printf("change = %d\n", change); fprintf(fout, "%d\n", change); return 0; }
// rotation local z void Camera::roll(const screen::math::Degree& iAngle){ SCREEN_DECL_METHOD(roll); rotate(getDirection(), iAngle); }
// [7/30/2008 zhangxiang] void sgNode::rotationY(const Radian &aAngle, int aRelativeTo /* = TS_LOCAL */){ rotate(Vector3::UNIT_Y, aAngle, aRelativeTo); }
// rotation local y void Camera::yaw(const screen::math::Degree& iAngle){ SCREEN_DECL_METHOD(yaw); rotate(getUp(), iAngle); }
// [7/30/2008 zhangxiang] void sgNode::rotate(const Vector3 &aAxis, const Radian& aAngle, int aRelativeTo /* = TS_LOCAL */){ Quaternion q; q.fromAngleAxis(aAngle, aAxis); rotate(q, aRelativeTo); }
Node* splay(Node* root) { return rotate(NULL, root, root->right); }
void motion(int x, int y) { if (mot == PAN) pan(x, y); else if (mot == ROT) rotate(x,y); }
void SystemActions::generateActions(const std::vector<int> & actions) { category()->setText(QCoreApplication::tr("System")); actions_.clear(); std::vector<int> all = actions; if (all.size() <= 0) { all.push_back(ROTATE_SCREEN); all.push_back(SCREEN_UPDATE_TYPE); all.push_back(MUSIC); #ifdef BUILD_WITH_TFT all.push_back(BACKLIGHT_BRIGHTNESS); #endif if (sys::isIRTouch()) { all.push_back(SYSTEM_VOLUME); } all.push_back(RETURN_TO_LIBRARY); } for(int i = 0; i < static_cast<int>(all.size()); ++i) { switch (all[i]) { case ROTATE_SCREEN: { shared_ptr<QAction> rotate(new QAction(exclusiveGroup())); rotate->setCheckable(true); rotate->setText(QCoreApplication::tr("Rotate Screen")); rotate->setIcon(QIcon(QPixmap(":/images/screen_rotation.png"))); rotate->setData(ROTATE_SCREEN); actions_.push_back(rotate); break; } case SCREEN_UPDATE_TYPE: { // Screen update type. shared_ptr<QAction> screen(new QAction(exclusiveGroup())); screen->setCheckable(true); if (onyx::screen::instance().defaultWaveform() == onyx::screen::ScreenProxy::GC) { screen->setText(QCoreApplication::tr("Full Refresh Off")); screen->setIcon(QIcon(QPixmap(":/images/fast_update.png"))); } else { screen->setText(QCoreApplication::tr("Full Refresh On")); screen->setIcon(QIcon(QPixmap(":/images/full_update.png"))); } screen->setData(SCREEN_UPDATE_TYPE); actions_.push_back(screen); break; } case FULL_SCREEN: { shared_ptr<QAction> fullScreen(new QAction(exclusiveGroup())); fullScreen->setCheckable(true); fullScreen->setText(QCoreApplication::tr("Full Screen")); fullScreen->setIcon(QIcon(QPixmap(":/images/full_screen.png"))); fullScreen->setData(FULL_SCREEN); actions_.push_back(fullScreen); break; } case EXIT_FULL_SCREEN: { shared_ptr<QAction> exitFullScreen(new QAction(exclusiveGroup())); exitFullScreen->setCheckable(true); exitFullScreen->setText(QCoreApplication::tr("Exit Full Screen")); exitFullScreen->setIcon(QIcon(QPixmap( ":/images/exit_full_screen.png"))); exitFullScreen->setData(EXIT_FULL_SCREEN); actions_.push_back(exitFullScreen); break; } case MUSIC: { if (sys::SystemConfig::isMusicPlayerAvailable()) { // Music. shared_ptr<QAction> music(new QAction(exclusiveGroup())); music->setCheckable(true); music->setText(QCoreApplication::tr("Music")); music->setIcon(QIcon(QPixmap(":/images/music.png"))); music->setData(MUSIC); actions_.push_back(music); } break; } case SYSTEM_VOLUME: { // when music and tts both are disabled, do not show volume configure bool music_available = sys::SystemConfig::isMusicPlayerAvailable(); bool disable_tts = qgetenv("DISABLE_TTS").toInt(); if (!music_available && disable_tts) { continue; } // system volume. shared_ptr<QAction> volume(new QAction(exclusiveGroup())); volume->setCheckable(true); volume->setText(QCoreApplication::tr("Volume")); volume->setIcon(QIcon(QPixmap(":/images/system_volume.png"))); volume->setData(SYSTEM_VOLUME); actions_.push_back(volume); break; } case RETURN_TO_LIBRARY: { // Close document. shared_ptr<QAction> close(new QAction(exclusiveGroup())); close->setCheckable(true); close->setText(QCoreApplication::tr("Close")); close->setIcon(QIcon(QPixmap(":/images/return_to_library.png"))); close->setData(RETURN_TO_LIBRARY); actions_.push_back(close); break; } case BACKLIGHT_BRIGHTNESS: { shared_ptr<QAction> br(new QAction(exclusiveGroup())); br->setCheckable(true); br->setText(QCoreApplication::tr("Brightness")); br->setIcon(QIcon(QPixmap(":/images/return_to_library.png"))); br->setData(BACKLIGHT_BRIGHTNESS); actions_.push_back(br); break; } } } }
void RS_DimRadial::rotate(const RS_Vector& center, const double& angle) { rotate(center,RS_Vector(angle)); }
//------------------------------ bool MolState::Read() { int i,j,k,l; char tmpCh; std::string tmp_str, tmp_atomName; std::istringstream tmp_iStr; Atom tmp_atom; //------------ Read IP (if provided) ---------------------------------- if ( xmlF.CheckSubNode("ip") ) { xmlF.node("ip"); energy = xmlF.getDoubleValue(); xmlF.stepBack(); } //------------ Read the Geometry -------------------------------------- xmlF.node("geometry"); int tmp_nAtoms, tmp_nNormMds; tmp_nAtoms=xmlF.getIntValue("number_of_atoms"); std::string units; units=xmlF.value("units"); ifLinear= xmlF.getBoolValue("linear"); if (ifLinear) tmp_nNormMds = (3*tmp_nAtoms - 5); else tmp_nNormMds = (3*tmp_nAtoms - 6); tmp_iStr.str(xmlF.value("text")); tmp_iStr.clear(); atoms.clear(); for (i=0; i<tmp_nAtoms; i++) { tmp_atomName=""; tmpCh=' '; while ( !ifLetterOrNumber(tmpCh) and !(tmp_iStr.fail()) ) tmp_iStr.get(tmpCh); if (tmp_iStr.fail()) { std::cout << "\nError: less then "<< tmp_nAtoms <<" atoms found or the format error, \"text\"-s line nuumber "<<i+1<<"\n"; xmlF.exitOnFormatError(true); } do { tmp_atomName+=tmpCh; tmp_iStr.get( tmpCh ); } while( ifLetterOrNumber(tmpCh) ); tmp_atom.Name() = tmp_atomName; for (k=0; k<CARTDIM; k++) { tmp_iStr >> tmp_atom.Coord(k); if (units=="au") tmp_atom.Coord(k)*=AU2ANGSTROM; } if (tmp_iStr.fail()) { std::cout << "\nError: less then "<< tmp_nAtoms <<" atoms found or the format error in the atomic coordinates,\n" << " \"text\"-s line number "<<i+1<<"\n"; xmlF.exitOnFormatError(true); } atoms.push_back(tmp_atom); } //------------ Convert atomic names to masses -------------------------- for (i=0; i<NAtoms(); i++) { tmp_iStr.str( amuF.reset().node("masses").node( getAtom(i).Name().c_str() ).value() ); tmp_iStr.clear(); tmp_iStr >> getAtom(i).Mass(); amuF.exitOnFormatError(tmp_iStr.fail()); } //------------ Read Normal Modes --------------------------------------- NormalMode tmp_normMode(NAtoms(),0); // one temp. norm mode normModes.clear(); xmlF.stepBack(); xmlF.node("normal_modes"); tmp_iStr.str(xmlF.value("text")); tmp_iStr.clear(); for (i=0; i < tmp_nNormMds; i++) normModes.push_back( tmp_normMode ); int nModesPerLine=3; // three number of vib. modes per Line int nLines; nLines = tmp_nNormMds / nModesPerLine; if ( tmp_nNormMds % nModesPerLine != 0) nLines++; for (k = 0; k < nLines; k++) // number of blocks with 3 norm.modes. ("lines") { int current_nModesPerLine = nModesPerLine; // for the last entree, nModesPerString may differ from 3 if (nLines - 1 == k) if ( tmp_nNormMds % nModesPerLine != 0 ) current_nModesPerLine = tmp_nNormMds % nModesPerLine; for (i=0; i < NAtoms(); i++) for (j=0; j < current_nModesPerLine; j++) for (l=0; l < CARTDIM; l++) { tmp_iStr >> normModes[k*nModesPerLine+j].getDisplacement()[i*CARTDIM+l]; if (tmp_iStr.fail()) { std::cout << "\nError: less normal modes found than expected or the format error\n"; xmlF.exitOnFormatError(true); } } } //------------ Read Frequencies ---------------------------------------- xmlF.stepBack(); xmlF.node("frequencies"); tmp_iStr.str(xmlF.value("text")); tmp_iStr.clear(); for (i=0; i < tmp_nNormMds; i++) { tmp_iStr >> getNormMode(i).getFreq(); if (tmp_iStr.fail()) { std::cout << "\nError: format error at frequency #"<<i<< " or less than " << tmp_nNormMds <<" frequencies found\n"; xmlF.exitOnFormatError(true); } if (getNormMode(i).getFreq()<=0) { std::cout <<"\nError. The frequency ["<<getNormMode(i).getFreq() <<"] is negative\n"; xmlF.exitOnFormatError(true); } } // Now MolState is in a good shape, and some transformations can be performed //------------ 1. Un-mass-weight normal modes---------------------------- xmlF.stepBack(); xmlF.node("normal_modes"); bool if_massweighted; if_massweighted=xmlF.getBoolValue("if_mass_weighted"); //------------ 1. mass un-weight normal modes, if needed (QChem-->ACES format; )---------------- // qchem if_massweighted="true"; aces if_massweighted="false"; reduced_masses.Adjust(NNormModes(),1); reduced_masses.Set(1); if (if_massweighted) { // Read atomic names from "...->normal_modes->atoms" std::vector<Atom> normalModeAtoms; tmp_iStr.str(xmlF.value("atoms")); tmp_iStr.clear(); normalModeAtoms.clear(); for (i=0; i<NAtoms(); i++) { tmp_atomName=""; tmpCh=' '; while ( !ifLetterOrNumber(tmpCh) and !(tmp_iStr.fail()) ) tmp_iStr.get(tmpCh); xmlF.exitOnFormatError(tmp_iStr.fail()); do { tmp_atomName+=tmpCh; tmp_iStr.get( tmpCh ); } while( ifLetterOrNumber(tmpCh) ); tmp_atom.Name() = tmp_atomName; normalModeAtoms.push_back(tmp_atom); } // Get masses for each atomic name: for (i=0; i<NAtoms(); i++) { tmp_iStr.str( amuF.reset().node("masses").node( normalModeAtoms[i].Name().c_str() ).value() ); tmp_iStr.clear(); tmp_iStr >> normalModeAtoms[i].Mass(); amuF.exitOnFormatError(tmp_iStr.fail()); } // Mass-un-weight normal modes: for (int nm=0; nm<NNormModes(); nm++) for (int a=0; a<NAtoms(); a++) for (int i=0; i<CARTDIM; i++ ) getNormMode(nm).getDisplacement().Elem1(a*CARTDIM+i) *= sqrt(normalModeAtoms[a].Mass()); // normolize each normal mode (/sqrt(norm) which is also /sqrt(reduced mass)): // KMatrix reduced_masses(NNormModes(),1); for (int nm=0; nm<NNormModes(); nm++) { reduced_masses[nm] = 0; for (int a=0; a<NAtoms(); a++) for (int i=0; i<CARTDIM; i++ ) reduced_masses[nm]+= getNormMode(nm).getDisplacement().Elem1(a*CARTDIM+i) * getNormMode(nm).getDisplacement().Elem1(a*CARTDIM+i); } // reduced_masses.Print("Reduced masses:"); // Normalize: for (int nm=0; nm<NNormModes(); nm++) for (int a=0; a<NAtoms(); a++) for (int i=0; i<CARTDIM; i++ ) getNormMode(nm).getDisplacement().Elem1(a*CARTDIM+i)/=sqrt(reduced_masses[nm]); } xmlF.stepBack(); //------------ 2. Align geometry if requested ---------------------------- if_aligned_manually=false; double man_rot_x, man_rot_y, man_rot_z; Vector3D man_shift; if ( xmlF.CheckSubNode("manual_coordinates_transformation") ) { xmlF.node("manual_coordinates_transformation"); man_rot_x=xmlF.getDoubleValue("rotate_around_x"); man_rot_y=xmlF.getDoubleValue("rotate_around_y"); man_rot_z=xmlF.getDoubleValue("rotate_around_z"); man_shift.getCoord(0)=-xmlF.getDoubleValue("shift_along_x"); man_shift.getCoord(1)=-xmlF.getDoubleValue("shift_along_y"); man_shift.getCoord(2)=-xmlF.getDoubleValue("shift_along_z"); std::cout << "Molecular structure and normal modes of this electronic state\nwill be transformed as requested in the input.\n"; shiftCoordinates(man_shift); rotate(man_rot_x*PI,man_rot_y*PI,man_rot_z*PI); applyCoordinateThreshold(COORDINATE_THRESHOLD); if_aligned_manually=true; xmlF.stepBack(); } //------------ 3. Reorder normal modes if requested -------------------- if ( xmlF.CheckSubNode("manual_normal_modes_reordering") ) { xmlF.node("manual_normal_modes_reordering"); if_nm_reordered_manually=false; normModesOrder.clear(); std::cout << "New normal modes order was requested:\n" << xmlF.value("new_order") <<"\n"; tmp_iStr.str(xmlF.value("new_order")); int tmpInt; for (int nm=0; nm < NNormModes(); nm++) { tmp_iStr >> tmpInt; //input error check: if (tmp_iStr.fail()) { std::cout << "\nFormat error: non numeric symbol or less entries then the number of normal modes\n\n"; xmlF.exitOnFormatError(true); } if ( (tmpInt<0) or (tmpInt>=NNormModes()) ) { std::cout << "\nError: normal mode number ["<< tmpInt<<"] is out of range [0.."<<NNormModes()-1<<"].\n\n"; xmlF.exitOnFormatError(true); } normModesOrder.push_back(tmpInt); } // check if there are duplicates in the list: std::vector<int> tmpIntVector, tmpIntVector2; tmpIntVector = normModesOrder; std::sort( tmpIntVector.begin(), tmpIntVector.end() ); tmpIntVector2 = tmpIntVector; std::vector<int>::const_iterator intVec_iter; intVec_iter= unique( tmpIntVector.begin(), tmpIntVector.end() ); if (intVec_iter != tmpIntVector.end()) { std::cout << "\nFormat error: there are non unique entries. Check the sorted list:\n"; for (std::vector<int>::const_iterator tmp_iter=tmpIntVector2.begin(); tmp_iter!=tmpIntVector2.end(); tmp_iter++) std::cout << ' ' << *tmp_iter; std::cout<<'\n'; xmlF.exitOnFormatError(true); } // backup normal modes std::vector<NormalMode> oldNormModes; oldNormModes.clear(); for (int nm=0; nm < NNormModes(); nm++) { tmp_normMode = getNormMode(nm); oldNormModes.push_back( tmp_normMode ); } // copy normal modes using new order for (int nm=0; nm < NNormModes(); nm++) getNormMode(nm) = oldNormModes[ normModesOrder[nm] ]; std::cout << "Normal modes were reordered accordingly.\n"; if_nm_reordered_manually=true; xmlF.stepBack(); }
/* simulates the flying.. */ bool Player::tick(){ /* if we need to orient the camera.. control the orientation */ if(current_control_state & YAW_LEFT) { controlStick(vec4(0,-ROTATE_FACTOR,0,0)); } if(current_control_state & YAW_RIGHT) { controlStick(vec4(0,ROTATE_FACTOR,0,0)); } if(current_control_state & ROLL_LEFT) { controlStick(vec4(0,0,-ROTATE_FACTOR, 0)); } if(current_control_state & ROLL_RIGHT) { controlStick(vec4(0,0,ROTATE_FACTOR, 0)); } if(current_control_state & PITCH_DOWN) { controlStick(vec4(-ROTATE_FACTOR,0,0, 0)); } if(current_control_state & PITCH_UP) { controlStick(vec4(ROTATE_FACTOR,0,0, 0)); } /* if we need to move the camera.. control the direction */ if(current_control_state & STRAFE_LEFT) { controlDirection(vec4(-STRAFE_LEFT_SPEED * sprint_multiplier,0,0, 0)); } if(current_control_state & STRAFE_RIGHT) { controlDirection(vec4(STRAFE_RIGHT_SPEED * sprint_multiplier,0,0, 0)); } if(current_control_state & STRAFE_UP) { controlDirection(vec4(0,0,STRAFE_UP_SPEED, 0)); } if(current_control_state & STRAFE_DOWN) { controlDirection(vec4(0,0,-STRAFE_DOWN_SPEED, 0)); } if(current_control_state & MOVE_FORWARD) { controlDirection(vec4(0,0,-MOVE_FORWARD_SPEED * sprint_multiplier, 0)); } if(current_control_state & MOVE_BACKWARD) { controlDirection(vec4(0,0,MOVE_BACKWARD_SPEED * sprint_multiplier, 0)); } // non each frame this function is called: // the direction and thetas are being collected.. // now we need to take action and update the properties // of this geometry's orientation and position so // the camera can update it's position based on this // player's attributes if (player_frozen == false) { //cam->walk(vec4(0,0,-((float)cur_throttle/max_throttle) * MAX_SPEED, 0) + this->direction ); //cam->adjust(thetas); translate(vec4(0,0,0, 0) + this->direction ); rotate(thetas); update_view(); this->thetas -= this->thetas * drag_factor; // drag the change in angle.. this->direction -= this->direction * drag_factor; return true; } return false; }
void Calculate_HF(int *tlist,double *vlist,int nfac,int nvert,double *angles,double *Eo,double *E0o,double *up,double TIME,double dist,double Gamma,double A,double Hdist,int N,double WL,double *freqx,double *freqy,int nfreq,double *offset,double *Fr,double *Fi) { double complex *F=calloc(nfreq,sizeof(double complex)); double complex *F0; F0=(double complex*)calloc(nfreq,sizeof(double complex)); double *Flux,*Fldx,*Fldy,*Fldz,*FldA; Flux=(double*)calloc(nfac,sizeof(double)); double M[3][3],dMb[3][3],dMo[3][3],dMl[3][3],Mt[3][3]; double R[3][3],Rdb[3][3],Rdl[3][3],Rdo[3][3],RT[3][3]; double E[3],E0[3]; double normalr[3],side1[3],side2[3]; double dechdx[3],dechdy[3],dechdz[3],dechdA[3]; double n[3],*nb,*cent; double *vb1,*vb2,*vb3; double vr1[3],vr2[3],vr3[3]; double *v1,*v2,*v3; double scale; double complex tscale,FTC; double dp; double B,TB=0; double norm; int t1,t2,t3,blocker,sign; int j1,j2,j3; double mu,mu0,area,mub,ech,rexp; double *normal,*centroid; int *visible; int tb1,tb2,tb3; //Indices to the vertices of possible blocker facet int blocked=0; //Distance km->arcsec dp=1/(dist*149597871.0)*180.0/PI*3600.0; visible=calloc(nfac,sizeof(int)); //Allocate for memory // normal=(double*)malloc(3*nfac*sizeof(double)); // centroid=(double*)mxCalloc(3*nfac,sizeof(double)); // IndexofBlocks=(int*)mxCalloc(nfac,sizeof(int)); // NumofBlocks=(int*)mxCalloc(nfac,sizeof(int)); //Calculate frame change matrix Calculate_Frame_Matrix(Eo,up,R); //FacetsOverHorizon(tlist,vlist,nfac,nvert,normal,centroid,NumofBlocks,IndexofBlocks); rotate(angles[0],angles[1],angles[2],0.0,TIME,M,dMb,dMl,dMo); //Construct asteroid->Camera frame matrix, which is //asteroid->world frame->camera frame transpose(M,Mt); //Transpose, since we rotate the model, not view directions mult_mat(R,Mt,RT); mult_vector(M,Eo,E); mult_vector(M,E0o,E0); /*For each facet, * 1)Check if facet is visible * 2) Calculate echo * 3) Convert triangle to range-Doppler frame * 4) Calculate FT */ //Find actual blockers FindActualBlockers(tlist,vlist,nfac,nvert,E,E,1,visible); Calculate_Radiance(tlist,vlist,nfac,nvert,angles,Eo,E0o,TIME,Gamma, A,Hdist,WL,N,Flux,Fldx,Fldy,Fldz,FldA,0); //for(int i=27;i<nfac;i++) // mexPrintf("fl%d: %.10e\n",i+1, Flux[i]); //visible is nfac vector, visible[j]=1 if facet (j+1)th facet is visible //NOTE INDEXING //mexPrintf("%f %f %f\n",vlist[0],vlist[1],vlist[2]); for(int j=0;j<nfac;j++) { if(visible[j]==0) continue; //Calculate normal from facet vertices //Vertex indices of the current facet //Note that C indices from 0, matlab from 1 j1=tlist[j*3]-1; j2=tlist[j*3+1]-1; j3=tlist[j*3+2]-1; //Current vertices v1=vlist+j1*3; v2=vlist+j2*3; v3=vlist+j3*3; //Calculate normals and centroids for(int i=0;i<3;i++) { side1[i]=dp*(v2[i]-v1[i]); //Convert km->arcsec side2[i]=dp*(v3[i]-v1[i]); } cross(side1,side2,n); norm=NORM(n); n[0]=n[0]/norm; n[1]=n[1]/norm; n[2]=n[2]/norm; mu=DOT(E,n); mu0=DOT(E0,n); //Convert to camera frame mult_vector(RT,v1,vr1); mult_vector(RT,v2,vr2); mult_vector(RT,v3,vr3); for(int i=0;i<3;i++) { vr1[i]=dp*vr1[i]; vr2[i]=dp*vr2[i]; vr3[i]=dp*vr3[i]; } //Now we should convert to frequency domain, ie calculate the contribution of each facet Calc_FTC(freqx,freqy,nfreq,vr1[0],vr1[1],vr2[0],vr2[1],vr3[0],vr3[1],F0); // printf("Fdd: %f %f\n",creal(FTdd[0]),cimag(FTdd[0])); //Note that we sum to F at each round, does not work, we need to multiply with the echo //Derivatives wrt angles area=0.5*norm; //if(j==0) //{ // mexPrintf("area: %f mu: %f F0: %f\n",area,mu,F0[0]); //} //mexPrintf("area: %f normal: %f %f %f mu: %f mu0: %f\n",area,n[0],n[1],n[2],mu,mu0); B=Flux[j]; for(int jf=0;jf<nfreq;jf++) { //This should be taken outside of the loop // mexPrintf("scale:%f offset: %f %f\n",scale,creal(cexp(2*PI*I*(offset[0]*freqx[jf]+offset[1]*freqy[jf]))),cimag(cexp(2*PI*I*(offset[0]*freqx[jf]+offset[1]*freqy[jf])))); //FTC=tscale*F0[jf]; F[jf]+=B*F0[jf]; } TB=TB+B*area*mu; // printf("Flux: %f area: %f mu: %f\n",B,area,mu); } //printf("Total brightness: %f\n",TB); //Normalize with total brightness double complex temp; for(int j=0;j<nfreq;j++) { temp=cexp(2.0*PI*I*(offset[0]*freqx[j]+offset[1]*freqy[j]))*F[j]/TB; Fr[j]=creal(temp); Fi[j]=cimag(temp); } free(visible); free(Flux); free(F0); free(F); }
//FIXME: Do we really need two versions of all of this code? (int/float) void SkyQPainter::drawDeepSkySymbol(const QPointF &pos, int type, float size, float e, float positionAngle) { float x = pos.x(); float y = pos.y(); float zoom = Options::zoomFactor(); int isize = int(size); float dx1 = -0.5*size; float dx2 = 0.5*size; float dy1 = -1.0*e*size/2.; float dy2 = e*size/2.; float x1 = x + dx1; float x2 = x + dx2; float y1 = y + dy1; float y2 = y + dy2; float dxa = -size/4.; float dxb = size/4.; float dya = -1.0*e*size/4.; float dyb = e*size/4.; float xa = x + dxa; float xb = x + dxb; float ya = y + dya; float yb = y + dyb; float psize; QBrush tempBrush; switch ( type ) { case 0: case 1: //catalog star //Some NGC/IC objects are stars...changed their type to 1 (was double star) if (size<2.) size = 2.; if ( Options::useAntialias() ) drawEllipse( QRectF(x1, y1, size/2., size/2.) ); else drawEllipse( QRect(int(x1), int(y1), int(size/2), int(size/2)) ); break; case 2: //Planet break; case 3: //Open cluster; draw circle of points case 13: // Asterism tempBrush = brush(); setBrush( pen().color() ); psize = 2.; if ( size > 50. ) psize *= 2.; if ( size > 100. ) psize *= 2.; if ( Options::useAntialias() ) { drawEllipse( QRectF(xa, y1, psize, psize) ); drawEllipse( QRectF(xb, y1, psize, psize) ); drawEllipse( QRectF(xa, y2, psize, psize) ); drawEllipse( QRectF(xb, y2, psize, psize) ); drawEllipse( QRectF(x1, ya, psize, psize) ); drawEllipse( QRectF(x1, yb, psize, psize) ); drawEllipse( QRectF(x2, ya, psize, psize) ); drawEllipse( QRectF(x2, yb, psize, psize) ); } else { int ix1 = int(x1); int iy1 = int(y1); int ix2 = int(x2); int iy2 = int(y2); int ixa = int(xa); int iya = int(ya); int ixb = int(xb); int iyb = int(yb); drawEllipse( QRect(ixa, iy1, int(psize), int(psize)) ); drawEllipse( QRect(ixb, iy1, int(psize), int(psize)) ); drawEllipse( QRect(ixa, iy2, int(psize), int(psize)) ); drawEllipse( QRect(ixb, iy2, int(psize), int(psize)) ); drawEllipse( QRect(ix1, iya, int(psize), int(psize)) ); drawEllipse( QRect(ix1, iyb, int(psize), int(psize)) ); drawEllipse( QRect(ix2, iya, int(psize), int(psize)) ); drawEllipse( QRect(ix2, iyb, int(psize), int(psize)) ); } setBrush( tempBrush ); break; case 4: //Globular Cluster if (size<2.) size = 2.; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawEllipse( QRectF(dx1, dy1, size, e*size) ); drawLine( QPointF(0., dy1), QPointF(0., dy2) ); drawLine( QPointF(dx1, 0.), QPointF(dx2, 0.) ); restore(); //reset coordinate system } else { int idx1 = int(dx1); int idy1 = int(dy1); int idx2 = int(dx2); int idy2 = int(dy2); drawEllipse( QRect(idx1, idy1, isize, int(e*size)) ); drawLine( QPoint(0, idy1), QPoint(0, idy2) ); drawLine( QPoint(idx1, 0), QPoint(idx2, 0) ); restore(); //reset coordinate system } break; case 5: //Gaseous Nebula case 15: // Dark Nebula if (size <2.) size = 2.; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawLine( QPointF(dx1, dy1), QPointF(dx2, dy1) ); drawLine( QPointF(dx2, dy1), QPointF(dx2, dy2) ); drawLine( QPointF(dx2, dy2), QPointF(dx1, dy2) ); drawLine( QPointF(dx1, dy2), QPointF(dx1, dy1) ); } else { int idx1 = int(dx1); int idy1 = int(dy1); int idx2 = int(dx2); int idy2 = int(dy2); drawLine( QPoint(idx1, idy1), QPoint(idx2, idy1) ); drawLine( QPoint(idx2, idy1), QPoint(idx2, idy2) ); drawLine( QPoint(idx2, idy2), QPoint(idx1, idy2) ); drawLine( QPoint(idx1, idy2), QPoint(idx1, idy1) ); } restore(); //reset coordinate system break; case 6: //Planetary Nebula if (size<2.) size = 2.; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawEllipse( QRectF(dx1, dy1, size, e*size) ); drawLine( QPointF(0., dy1), QPointF(0., dy1 - e*size/2. ) ); drawLine( QPointF(0., dy2), QPointF(0., dy2 + e*size/2. ) ); drawLine( QPointF(dx1, 0.), QPointF(dx1 - size/2., 0.) ); drawLine( QPointF(dx2, 0.), QPointF(dx2 + size/2., 0.) ); } else { int idx1 = int(dx1); int idy1 = int(dy1); int idx2 = int(dx2); int idy2 = int(dy2); drawEllipse( QRect( idx1, idy1, isize, int(e*size) ) ); drawLine( QPoint(0, idy1), QPoint(0, idy1 - int(e*size/2) ) ); drawLine( QPoint(0, idy2), QPoint(0, idy2 + int(e*size/2) ) ); drawLine( QPoint(idx1, 0), QPoint(idx1 - int(size/2), 0) ); drawLine( QPoint(idx2, 0), QPoint(idx2 + int(size/2), 0) ); } restore(); //reset coordinate system break; case 7: //Supernova remnant if (size<2) size = 2; save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawLine( QPointF(0., dy1), QPointF(dx2, 0.) ); drawLine( QPointF(dx2, 0.), QPointF(0., dy2) ); drawLine( QPointF(0., dy2), QPointF(dx1, 0.) ); drawLine( QPointF(dx1, 0.), QPointF(0., dy1) ); } else { int idx1 = int(dx1); int idy1 = int(dy1); int idx2 = int(dx2); int idy2 = int(dy2); drawLine( QPoint(0, idy1), QPoint(idx2, 0) ); drawLine( QPoint(idx2, 0), QPoint(0, idy2) ); drawLine( QPoint(0, idy2), QPoint(idx1, 0) ); drawLine( QPoint(idx1, 0), QPoint(0, idy1) ); } restore(); //reset coordinate system break; case 8: //Galaxy case 16: // Quasar if ( size <1. && zoom > 20*MINZOOM ) size = 3.; //force ellipse above zoomFactor 20 if ( size <1. && zoom > 5*MINZOOM ) size = 1.; //force points above zoomFactor 5 if ( size>2. ) { save(); translate( x, y ); rotate( positionAngle ); //rotate the coordinate system if ( Options::useAntialias() ) { drawEllipse( QRectF(dx1, dy1, size, e*size) ); } else { int idx1 = int(dx1); int idy1 = int(dy1); drawEllipse( QRect(idx1, idy1, isize, int(e*size)) ); } restore(); //reset coordinate system } else if ( size>0. ) { drawPoint( QPointF(x, y) ); } break; case 14: // Galaxy cluster - draw a circle of + marks tempBrush = brush(); setBrush( pen().color() ); psize = 1.; if ( size > 50. ) psize *= 2.; if ( Options::useAntialias() ) { drawLine( QLineF( xa - psize, y1, xa + psize, y1 ) ); drawLine( QLineF( xa, y1 - psize, xa, y1 + psize ) ); drawLine( QLineF( xb - psize, y1, xb + psize, y1 ) ); drawLine( QLineF( xb, y1 - psize, xb, y1 + psize ) ); drawLine( QLineF( xa - psize, y2, xa + psize, y2 ) ); drawLine( QLineF( xa, y2 - psize, xa, y2 + psize ) ); drawLine( QLineF( xb - psize, y2, xb + psize, y2 ) ); drawLine( QLineF( xb, y2 - psize, xb, y2 + psize ) ); drawLine( QLineF( x1 - psize, ya, x1 + psize, ya ) ); drawLine( QLineF( x1, ya - psize, x1, ya + psize ) ); drawLine( QLineF( x1 - psize, yb, x1 + psize, yb ) ); drawLine( QLineF( x1, yb - psize, x1, yb + psize ) ); drawLine( QLineF( x2 - psize, ya, x2 + psize, ya ) ); drawLine( QLineF( x2, ya - psize, x2, ya + psize ) ); drawLine( QLineF( x2 - psize, yb, x2 + psize, yb ) ); drawLine( QLineF( x2, yb - psize, x2, yb + psize ) ); } else { int ix1 = int(x1); int iy1 = int(y1); int ix2 = int(x2); int iy2 = int(y2); int ixa = int(xa); int iya = int(ya); int ixb = int(xb); int iyb = int(yb); drawLine( QLineF( ixa - int(psize), iy1, ixa + int(psize), iy1 ) ); drawLine( QLineF( ixa, iy1 - int(psize), ixa, iy1 + int(psize) ) ); drawLine( QLineF( ixb - int(psize), iy1, ixb + int(psize), iy1 ) ); drawLine( QLineF( ixb, iy1 - int(psize), ixb, iy1 + int(psize) ) ); drawLine( QLineF( ixa - int(psize), iy2, ixa + int(psize), iy2 ) ); drawLine( QLineF( ixa, iy2 - int(psize), ixa, iy2 + int(psize) ) ); drawLine( QLineF( ixb - int(psize), iy2, ixb + int(psize), iy2 ) ); drawLine( QLineF( ixb, iy2 - int(psize), ixb, iy2 + int(psize) ) ); drawLine( QLineF( ix1 - int(psize), iya, ix1 + int(psize), iya ) ); drawLine( QLineF( ix1, iya - int(psize), ix1, iya + int(psize) ) ); drawLine( QLineF( ix1 - int(psize), iyb, ix1 + int(psize), iyb ) ); drawLine( QLineF( ix1, iyb - int(psize), ix1, iyb + int(psize) ) ); drawLine( QLineF( ix2 - int(psize), iya, ix2 + int(psize), iya ) ); drawLine( QLineF( ix2, iya - int(psize), ix2, iya + int(psize) ) ); drawLine( QLineF( ix2 - int(psize), iyb, ix2 + int(psize), iyb ) ); drawLine( QLineF( ix2, iyb - int(psize), ix2, iyb + int(psize) ) ); } setBrush( tempBrush ); break; } }
bool ClipObject::processCommand(QString cmd) { bool ok; cmd = cmd.toLower(); QStringList list = cmd.split(" ", QString::SkipEmptyParts); if (list[0] == "mop") { if (list.size() == 2 && list[1] == "clip") { m_mopClip = true; return true; } else return false; } else if (list[0] == "tfset") { int tf = 1000; if (list.size() == 2) tf = qMax(0, list[1].toInt()); m_tfset = tf; return true; } else if (list[0] == "reorientcamera") { m_reorientCamera = true; return true; } else if (list[0] == "color") { QColor dcolor = QColor::fromRgbF(m_color.x, m_color.y, m_color.z); QColor color = DColorDialog::getColor(dcolor); if (color.isValid()) { float r = color.redF(); float g = color.greenF(); float b = color.blueF(); m_color = Vec(r,g,b); } } else if (list[0] == "solidcolor") { if (list.size() == 2 && list[1] == "no") m_solidColor = false; else m_solidColor = true; return true; } else if (list[0] == "savesliceimage") { m_resliceSubsample = 1; m_saveSliceImage = true; if (list.size() == 2) m_resliceSubsample = qMax(1, list[1].toInt(&ok)); return true; } else if (list[0] == "reslice") { m_resliceSubsample = 1; m_resliceTag = -1; m_resliceVolume = true; if (list.size() > 1) m_resliceSubsample = qMax(1, list[1].toInt(&ok)); if (list.size() > 2) m_resliceTag = list[2].toInt(&ok); return true; } else if (list[0] == "grid") { if (list.size() == 1) { m_gridX = m_gridY = 10; } else if (list.size() == 2 && list[1] == "no") { m_gridX = m_gridY = 0; } else if (list.size() == 3) { m_gridX = list[1].toInt(); m_gridY = list[2].toInt(); } return true; } else if (list[0] == "image") { if (list.size() == 2 && list[1] == "no") clearImage(); else loadImage(); return true; } else if (list[0] == "imageframe") { if (list.size() == 2) { int frm = list[1].toInt(&ok); if (frm >= 0) { loadImage(m_imageName, frm); } else QMessageBox::information(0, "Error", "ImageFrame not changed. Positive values required"); } else QMessageBox::information(0, "Error", "Please specify ImageFrame number for the clipplane"); return true; } else if (list[0] == "caption") { if (list.count() == 2 && list[1] == "no") clearCaption(); else loadCaption(); return true; } else if (list[0] == "vscale" || list[0] == "scale") { if (list.size() > 1) { float scl1, scl2; if (list.size() == 2) { scl1 = list[1].toFloat(&ok); scl2 = scl1; } else { scl1 = list[1].toFloat(&ok); scl2 = list[2].toFloat(&ok); } if (list[0] == "scale") { m_scale1 = -qAbs(scl1); m_scale2 = -qAbs(scl2); } else { m_scale1 = scl1; m_scale2 = scl2; } } else QMessageBox::information(0, "Error", "Please specify both scalings for the clipplane"); return true; } else if (list[0] == "opacity") { if (list.size() == 2) { float scl = list[1].toFloat(&ok); if (scl >= 0 && scl <= 1) { m_opacity = scl; m_opacity = qMax(0.02f, qMin(1.0f, m_opacity)); } else QMessageBox::information(0, "Error", "Opacity not changed. Value between 0 and 1 required"); } else QMessageBox::information(0, "Error", "Please specify opacity for the clipplane"); return true; } else if (list[0] == "translate" || list[0] == "translatex" || list[0] == "translatey" || list[0] == "translatez" || list[0] == "move" || list[0] == "movex" || list[0] == "movey" || list[0] == "movez") { Vec pos; float x=0,y=0,z=0; if (list[0] == "translate" || list[0] == "move") { if (list.size() > 1) x = list[1].toFloat(&ok); if (list.size() > 2) y = list[2].toFloat(&ok); if (list.size() > 3) z = list[3].toFloat(&ok); pos = Vec(x,y,z); } else { float v=0; if (list.size() > 1) v = list[1].toFloat(&ok); if (list[0] == "translatex" || list[0] == "movex") pos = Vec(v,0,0); else if (list[0] == "translatey" || list[0] == "movey") pos = Vec(0,v,0); else if (list[0] == "translatez" || list[0] == "movez") pos = Vec(0,0,v); } if (list[0].contains("move")) { Vec cpos = position(); pos = pos + cpos; } setPosition(pos); return true; } else if (list[0] == "rotatea" || list[0] == "rotateb" || list[0] == "rotatec") { float angle = 0; if (list.size() > 1) { angle = list[1].toFloat(&ok); if (list[0] == "rotatea") rotate(m_xaxis, angle); if (list[0] == "rotateb") rotate(m_yaxis, angle); if (list[0] == "rotatec") rotate(m_tang, angle); } else { QMessageBox::information(0, "", "No angle specified"); } return true; } else if (list[0] == "movea" || list[0] == "moveb" || list[0] == "movec") { float shift = 0; if (list.size() > 1) { shift = list[1].toFloat(&ok); if (list[0] == "movea") translate(shift*m_xaxis); if (list[0] == "moveb") translate(shift*m_yaxis); if (list[0] == "movec") translate(shift*m_tang); } else { QMessageBox::information(0, "", "No distance specified"); } return true; } else if (list[0] == "rotate" || list[0] == "rotatex" || list[0] == "rotatey" || list[0] == "rotatez" || list[0] == "addrotation" || list[0] == "addrotationx" || list[0] == "addrotationy" || list[0] == "addrotationz") { Quaternion rot; float x=0,y=0,z=0,a=0; if (list[0] == "rotate" || list[0] == "addrotation") { if (list.size() > 1) x = list[1].toFloat(&ok); if (list.size() > 2) y = list[2].toFloat(&ok); if (list.size() > 3) z = list[3].toFloat(&ok); if (list.size() > 4) a = list[4].toFloat(&ok); rot = Quaternion(Vec(x,y,z), DEG2RAD(a)); } else { float a=0; if (list.size() > 1) a = list[1].toFloat(&ok); if (list[0] == "rotatex" || list[0] == "addrotationx") rot = Quaternion(Vec(1,0,0), DEG2RAD(a)); else if (list[0] == "rotatey" || list[0] == "addrotationy") rot = Quaternion(Vec(0,1,0), DEG2RAD(a)); else if (list[0] == "rotatez" || list[0] == "addrotationz") rot = Quaternion(Vec(0,0,1), DEG2RAD(a)); } if (list[0].contains("addrotation")) { Quaternion orot = orientation(); rot = rot*orot; } setOrientation(rot); return true; } else QMessageBox::information(0, "Error", QString("Cannot understand the command : ") + cmd); return false; }
void My_TestGLDrawing::InitTest() { _renderIndex = HdRenderIndex::New(&_renderDelegate); TF_VERIFY(_renderIndex != nullptr); _delegate = new Hdx_UnitTestDelegate(_renderIndex); _delegate->SetRefineLevel(_refineLevel); // prepare render task SdfPath renderSetupTask("/renderSetupTask"); SdfPath renderTask("/renderTask"); _delegate->AddRenderSetupTask(renderSetupTask); _delegate->AddRenderTask(renderTask); // render task parameters. HdxRenderTaskParams param = _delegate->GetTaskParam( renderSetupTask, HdTokens->params).Get<HdxRenderTaskParams>(); param.enableLighting = true; // use default lighting _delegate->SetTaskParam(renderSetupTask, HdTokens->params, VtValue(param)); _delegate->SetTaskParam(renderTask, HdTokens->collection, VtValue(HdRprimCollection(HdTokens->geometry, HdReprSelector(_reprName)))); // prepare scene // To ensure that the non-aggregated element index returned via picking, // we need to have at least two cubes with uniform colors. GfVec4f red(1,0,0,1), green(0,1,0,1), blue(0,0,1,1), yellow(1,1,0,1), magenta(1,0,1,1), cyan(0,1,1,1), white(1,1,1,1), black(0,0,0,1); GfVec4f faceColors[] = { red, green, blue, yellow, magenta, cyan}; VtValue faceColor = VtValue(_BuildArray(&faceColors[0], sizeof(faceColors)/sizeof(faceColors[0]))); GfVec4f vertColors[] = { white, blue, green, yellow, black, blue, magenta, red}; VtValue vertColor = VtValue(_BuildArray(&vertColors[0], sizeof(vertColors)/sizeof(vertColors[0]))); _delegate->AddCube(SdfPath("/cube0"), _GetTranslate( 5, 0, 5), /*guide=*/false, /*instancerId=*/SdfPath(), /*scheme=*/PxOsdOpenSubdivTokens->catmark, /*color=*/faceColor, /*colorInterpolation=*/HdInterpolationUniform); _delegate->AddCube(SdfPath("/cube1"), _GetTranslate(-5, 0, 5), /*guide=*/false, /*instancerId=*/SdfPath(), /*scheme=*/PxOsdOpenSubdivTokens->catmark, /*color=*/faceColor, /*colorInterpolation=*/HdInterpolationUniform); _delegate->AddCube(SdfPath("/cube2"), _GetTranslate(-5, 0,-5)); _delegate->AddCube(SdfPath("/cube3"), _GetTranslate( 5, 0,-5), /*guide=*/false, /*instancerId=*/SdfPath(), /*scheme=*/PxOsdOpenSubdivTokens->catmark, /*color=*/vertColor, /*colorInterpolation=*/HdInterpolationVertex); { _delegate->AddInstancer(SdfPath("/instancerTop")); _delegate->AddCube(SdfPath("/protoTop"), GfMatrix4d(1), false, SdfPath("/instancerTop")); std::vector<SdfPath> prototypes; prototypes.push_back(SdfPath("/protoTop")); VtVec3fArray scale(3); VtVec4fArray rotate(3); VtVec3fArray translate(3); VtIntArray prototypeIndex(3); scale[0] = GfVec3f(1); rotate[0] = GfVec4f(0); translate[0] = GfVec3f(3, 0, 2); prototypeIndex[0] = 0; scale[1] = GfVec3f(1); rotate[1] = GfVec4f(0); translate[1] = GfVec3f(0, 0, 2); prototypeIndex[1] = 0; scale[2] = GfVec3f(1); rotate[2] = GfVec4f(0); translate[2] = GfVec3f(-3, 0, 2); prototypeIndex[2] = 0; _delegate->SetInstancerProperties(SdfPath("/instancerTop"), prototypeIndex, scale, rotate, translate); } { _delegate->AddInstancer(SdfPath("/instancerBottom")); _delegate->AddCube(SdfPath("/protoBottom"), GfMatrix4d(1), false, SdfPath("/instancerBottom")); std::vector<SdfPath> prototypes; prototypes.push_back(SdfPath("/protoBottom")); VtVec3fArray scale(3); VtVec4fArray rotate(3); VtVec3fArray translate(3); VtIntArray prototypeIndex(3); scale[0] = GfVec3f(1); rotate[0] = GfVec4f(0); translate[0] = GfVec3f(3, 0, -2); prototypeIndex[0] = 0; scale[1] = GfVec3f(1); rotate[1] = GfVec4f(0); translate[1] = GfVec3f(0, 0, -2); prototypeIndex[1] = 0; scale[2] = GfVec3f(1); rotate[2] = GfVec4f(0); translate[2] = GfVec3f(-3, 0, -2); prototypeIndex[2] = 0; _delegate->SetInstancerProperties(SdfPath("/instancerBottom"), prototypeIndex, scale, rotate, translate); } SetCameraTranslate(GfVec3f(0, 0, -20)); // XXX: Setup a VAO, the current drawing engine will not yet do this. glGenVertexArrays(1, &vao); glBindVertexArray(vao); glBindVertexArray(0); }
void Vector::rotate(const Vector & rot){ rotate(rot.x(), rot.y(), rot.z()); }
void LLCoordFrame::rotate(const LLQuaternion &q) { LLMatrix3 rotation_matrix(q); rotate(rotation_matrix); }