int AreaOfInterest::actionController(CvPoint mousePointer) { if (this->contains(mousePointer)) { double sqrtP = sqrt(cornerAreaPercentage_); CvPoint tl = cvPoint(rect_.x,rect_.y); CvPoint tr = cvPoint(rect_.x+rect_.width,rect_.y); CvPoint sizeVector = cvPoint(rect_.width, rect_.height); CvPoint sizeVectorInvert = cvPoint(-rect_.width, rect_.height); /*CvPoint center = divVector(addVectors(sizeVector,tl), 2);*/ CvPoint tl_inner = addVectors(tl, mulVector(sizeVector, sqrtP)); if ((mousePointer.x <= tl_inner.x) && (mousePointer.y <= tl_inner.y)) return RESIZE_TL; CvPoint tr_inner = addVectors(tr, mulVector(sizeVectorInvert, sqrtP)); if ((mousePointer.x >= tr_inner.x) && (mousePointer.y <= tr_inner.y)) return RESIZE_TR; CvPoint br_inner = addVectors(tl, mulVector(sizeVector, 1 - sqrtP)); if ((mousePointer.x >= br_inner.x) && (mousePointer.y >= br_inner.y)) return RESIZE_BR; CvPoint bl_inner = addVectors(tr, mulVector(sizeVectorInvert, 1 - sqrtP)); if ((mousePointer.x <= bl_inner.x) && (mousePointer.y >= bl_inner.y)) return RESIZE_BL; return MOVE_RECT; } else return -1; }
void AreaOfInterest::modify(int drawMethod, CvPoint vector) { CvPoint v_x, v_y; switch (drawMethod) { case MOVE_RECT: this->move(vector); break; case RESIZE_BR: this->resizeAddVector(vector); break; case RESIZE_TL: this->move(vector); vector = mulVector(vector, -1); this->resizeAddVector(vector); break; case RESIZE_TR: v_x = cvPoint(0, vector.y); v_y = cvPoint(vector.x, -vector.y); this->move(v_x); this->resizeAddVector(v_y); break; case RESIZE_BL: v_x = cvPoint(vector.x, 0); v_y = cvPoint(-vector.x, vector.y); this->move(v_x); this->resizeAddVector(v_y); break; default: throw "Exception here, modify to something meaningful please!"; } //void fixNegativeWH(); }
//1代表需要继续旋转 //0代表旋转完毕 int rotate(Rotation* r) { for (GLsizei i=0;i<r->len;++i) for (GLsizei j=0;j<8;++j) mulVertex(r->m,&r->cubeArray[i]->vertexArray[j]); for (GLsizei i=0;i<r->len;++i) for (GLsizei j=0;j<6;++j) mulVector(r->m,&(r->cubeArray[i]->faceArray[j].normalVector)); r->times--; if (r->times==0) { r->rotating=GL_FALSE; return 0; } else { return 1; } }
int main (int argc, char **argv) { /* Matrix data. */ CRS_MATRIX *M1, *M2; double *b1, *x1, *b2, *x2, *r; int n; int nvals; FILE *fp; if (argc == 1) { fp = stdin; } else if (argc == 2) { fp = fopen (*argv, "r"); } else { fprintf (stderr, "Usage: pardisoTestExample [<fileName>]\n"); exit (1); } M1 = readCRSMatrix (fp, /*symmetric=*/1); n = M1->nrows; b1 = readVector (fp, n); x1 = (double*)malloc(n*sizeof(double)); r = (double*)malloc(n*sizeof(double)); // ja -> M1->colIdxs; // a -> M1->vals; // ia -> M1->rowOffs int mtype = -2; /* Real symmetric matrix */ int nrhs = 1; /* Number of right hand sides. */ /* Internal solver memory pointer pt, */ /* 32-bit: int pt[64]; 64-bit: long int pt[64] */ /* or void *pt[64] should be OK on both architectures */ void *pt[64]; /* Pardiso control parameters. */ int iparm[64]; int maxfct, mnum, phase, error, msglvl; /* Number of processors. */ int num_procs; /* Auxiliary variables. */ char *var; int i; double ddum; /* Double dummy */ int idum; /* Integer dummy. */ double t0, t1; /* -------------------------------------------------------------------- */ /* .. Setup Pardiso control parameters. */ /* -------------------------------------------------------------------- */ error = 0; //solver = 0; /* use sparse direct solver */ // do we need this, or will init take care of it? for (i=0; i<64; i++) { pt[i] = (void*)0; } for (i=0; i<64; i++) { iparm[i] = 0; } iparm[0] = 1; /* Don't use solver default values */ iparm[1] = 3; /* Fill-in reordering from OpenMP METIS */ /* Numbers of processors; if 0, defaults to max number or MKL_NUM_THREADS */ iparm[2] = 0; iparm[3] = 0; /* No iterative-direct algorithm */ iparm[4] = 0; /* No user fill-in reducing permutation */ iparm[5] = 0; /* Write solution into x */ iparm[6] = 0; /* Not in use */ iparm[7] = 0; /* Max numbers of iterative refinement steps */ iparm[8] = 0; /* Not in use */ iparm[9] = 13; /* Perturb the pivot elements with 1E-13 */ iparm[10] = 1; /* Use nonsymmetric permutation and scaling MPS */ iparm[11] = 0; /* Not in use */ iparm[12] = 0; /* Maximum weighted matching algorithm is switched-off (default for symmetric). Try iparm[12] = 1 in case of inappropriate accuracy */ iparm[13] = 0; /* Output: Number of perturbed pivots */ iparm[14] = 0; /* Not in use */ iparm[15] = 0; /* Not in use */ iparm[16] = 0; /* Not in use */ iparm[17] = -1; /* Output: Number of nonzeros in the factor LU */ iparm[18] = -1; /* Output: Mflops for LU factorization */ iparm[19] = 0; /* Output: Numbers of CG Iterations */ iparm[20] = 1; /* use 1x1 and 2x2 pivoting //F77_FUNC(pardisoinit) (pt, &mtype, &solver, iparm, &error); if (error != 0) { if (error == -10 ) printf("No license file found \n"); if (error == -11 ) printf("License is expired \n"); if (error == -12 ) printf("Wrong username or hostname \n"); return 1; } else { printf("PARDISO license check was successful ... \n"); } /* Numbers of processors, value of OMP_NUM_THREADS */ var = getenv("OMP_NUM_THREADS"); if(var != NULL) sscanf( var, "%d", &num_procs ); else { printf("Set environment OMP_NUM_THREADS to 1"); exit(1); } iparm[2] = num_procs; // other special settings iparm[1] = 3; // 2 for metis, 0 for AMD iparm[9] = 12; iparm[10] = 1; iparm[12] = 1; // setting this to 2 can cause errors sometimes maxfct = 1; /* Maximum number of numerical factorizations. */ mnum = 1; /* Which factorization to use. */ msglvl = 0; /* Print statistical information */ error = 0; /* Initialize error flag */ /* -------------------------------------------------------------------- */ /* .. Reordering and Symbolic Factorization. This step also allocates */ /* all memory that is necessary for the factorization. */ /* -------------------------------------------------------------------- */ phase = 11; t0 = currentTimeUsec(); PARDISO (pt, &maxfct, &mnum, &mtype, &phase, &n, M1->vals, M1->rowOffs, M1->colIdxs, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error); t1 = currentTimeUsec(); if (error != 0) { printf("ERROR during symbolic factorization: %d\n", error); exit(1); } printf("Analyze: msec=%8.1f\n", (t1-t0)/1000.0); printf("Number of nonzeros in factors = %d\n", iparm[17]); printf("Number of factorization MFLOPS = %d\n", iparm[18]); /* -------------------------------------------------------------------- */ /* .. Numerical factorization. */ /* -------------------------------------------------------------------- */ phase = 22; t0 = currentTimeUsec(); PARDISO (pt, &maxfct, &mnum, &mtype, &phase, &n, M1->vals, M1->rowOffs, M1->colIdxs, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error); t1 = currentTimeUsec(); if (error != 0) { printf("ERROR during numerical factorization: %d\n", error); exit(2); } printf("Factor: msec=%8.1f\n", (t1-t0)/1000.0); /* -------------------------------------------------------------------- */ /* .. Back substitution and iterative refinement. */ /* -------------------------------------------------------------------- */ phase = 33; iparm[7] = 1; /* Max numbers of iterative refinement steps. */ t0 = currentTimeUsec(); PARDISO (pt, &maxfct, &mnum, &mtype, &phase, &n, M1->vals, M1->rowOffs, M1->colIdxs, &idum, &nrhs, iparm, &msglvl, b1, x1, &error); t1 = currentTimeUsec(); if (error != 0) { printf("ERROR during solution: %d\n", error); exit(3); } mulVector (r, M1, x1); subVector (r, r, b1, n); printf("Solve: msec=%8.1f\n\n", (t1-t0)/1000.0); /* for (i=0; i<n; i++) { */ /* printf ("%g ", x1[i]); */ /* } */ /* printf ("\n"); */ printf("residual=%g\n", normVector(r, n)); #if 0 M2 = readCRSMatrix (fp, /*symmetric=*/1); n = M2->nrows; b2 = readVector (fp, n); x2 = (double*)malloc(n*sizeof(double)); setVector (x2, x1, n); iparm[7] = 1; /* Max numbers of iterative refinement steps. */ iparm[3] = 102; printf ("maxfct=%d\n", maxfct); printf ("mnum=%d\n", mnum); printf ("mtype=%d\n", mtype); printf ("phase=%d\n", phase); printf ("idum=%d\n", idum); for (i=0; i<64; i++) { printf ("%d ", iparm[i]); } printf ("\n"); t0 = currentTimeUsec(); PARDISO (pt, &maxfct, &mnum, &mtype, &phase, &n, M2->vals, M2->rowOffs, M2->colIdxs, &idum, &nrhs, iparm, &msglvl, b2, x2, &error); t1 = currentTimeUsec(); if (error != 0) { printf("ERROR during solution: %d\n", error); exit(3); } printf ("num iterations=%d\n", iparm[19]); for (i=0; i<n; i++) { printf ("%g ", x2[i]); } printf ("\n"); printf("Solve: msec=%8.1f\n\n", (t1-t0)/1000.0); mulVector (r, M2, x2); subVector (r, r, b2, n); printf("residual=%g\n", normVector(r, n)); #endif /* -------------------------------------------------------------------- */ /* .. Termination and release of memory. */ /* -------------------------------------------------------------------- */ phase = -1; /* Release internal memory. */ PARDISO (pt, &maxfct, &mnum, &mtype, &phase, &n, &ddum, M1->rowOffs, M1->colIdxs, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error); return 0; }