/* 線の色は設定していない */ void myMarkSquare(int patt_id){ glPushMatrix(); myMatrix(object[patt_id].patt_trans); glLineWidth(3.0); // 線の太さを設定 glBegin( GL_LINE_LOOP ); glVertex3f( -object[patt_id].patt_width/2.0, -object[patt_id].patt_width/2.0, 0.0 ); glVertex3f( object[patt_id].patt_width/2.0, -object[patt_id].patt_width/2.0, 0.0 ); glVertex3f( object[patt_id].patt_width/2.0, object[patt_id].patt_width/2.0, 0.0 ); glVertex3f( -object[patt_id].patt_width/2.0, object[patt_id].patt_width/2.0, 0.0 ); glEnd(); glPopMatrix(); }
Vector<T> Matrix<T>::solve(Vector<T> b) { Matrix<T> myMatrix(MatrixBase<T>::size()); for(unsigned int i=0;i<myMatrix.size(); i++) for(unsigned int j=0;j<myMatrix.size(); j++) myMatrix[i][j] = operator()(i,j); //Forward elimination with partial pivoting for(unsigned int i=0;i<myMatrix.size()-1;i++) // need to eliminate things down to last column { //PIVOT int rowWithMax; rowWithMax = myMatrix.findMaxRow(i); //find row # with maximum element in col xzcV myMatrix.swapRow(i,rowWithMax); b.swapRow(i,rowWithMax); //Eliminate all the values below swapped row T mult; //used as the multiplier in the row operations for (unsigned int j=myMatrix.size()-1;j>i;j--) { if(myMatrix[j][i] != 0) { mult = -(myMatrix[j][i]/myMatrix[i][i]); myMatrix.rowOp(i,mult,j); b.rowOp(i,mult,j); myMatrix[j][i] = 0; } } } //now solve the matrix using back substitution Vector<T> solution(myMatrix.size()); //start at bottom row, work up. for(int i = myMatrix.size() - 1; i>=0; i--) { T subtractMe = 0; //gives 0 iterations at bottom row and one more for each row up after that for(int j = myMatrix.size() - 1 - i; j>0 ; j--) subtractMe = subtractMe + myMatrix[i][myMatrix.size()-j] * solution[solution.size()-j]; solution[i] = (b[i] - subtractMe)/myMatrix[i][i]; } return solution; }
void dgCollisionScene::CollideCompoundPair (dgCollidingPairCollector::dgPair* const pair, dgCollisionParamProxy& proxy) const { const dgNodeBase* stackPool[4 * DG_COMPOUND_STACK_DEPTH][2]; dgContact* const constraint = pair->m_contact; dgBody* const myBody = constraint->GetBody1(); dgBody* const otherBody = constraint->GetBody0(); dgAssert (myBody == proxy.m_floatingBody); dgAssert (otherBody == proxy.m_referenceBody); dgCollisionInstance* const myCompoundInstance = myBody->m_collision; dgCollisionInstance* const otherCompoundInstance = otherBody->m_collision; dgAssert (myCompoundInstance->GetChildShape() == this); dgAssert (otherCompoundInstance->IsType (dgCollision::dgCollisionCompound_RTTI)); dgCollisionCompound* const otherCompound = (dgCollisionCompound*)otherCompoundInstance->GetChildShape(); const dgContactMaterial* const material = constraint->GetMaterial(); dgMatrix myMatrix (myCompoundInstance->GetLocalMatrix() * myBody->m_matrix); dgMatrix otherMatrix (otherCompoundInstance->GetLocalMatrix() * otherBody->m_matrix); dgOOBBTestData data (otherMatrix * myMatrix.Inverse()); dgInt32 stack = 1; stackPool[0][0] = m_root; stackPool[0][1] = otherCompound->m_root; const dgVector& hullVeloc = otherBody->m_veloc; dgFloat32 baseLinearSpeed = dgSqrt (hullVeloc % hullVeloc); dgFloat32 closestDist = dgFloat32 (1.0e10f); if (proxy.m_continueCollision && (baseLinearSpeed > dgFloat32 (1.0e-6f))) { dgAssert (0); } else { while (stack) { stack --; const dgNodeBase* const me = stackPool[stack][0]; const dgNodeBase* const other = stackPool[stack][1]; dgAssert (me && other); if (me->BoxTest (data, other)) { if ((me->m_type == m_leaf) && (other->m_type == m_leaf)) { dgAssert (!me->m_right); bool processContacts = true; if (material->m_compoundAABBOverlap) { processContacts = material->m_compoundAABBOverlap (*material, myBody, me->m_myNode, otherBody, other->m_myNode, proxy.m_threadIndex); } if (processContacts) { const dgCollisionInstance* const mySrcInstance = me->GetShape(); const dgCollisionInstance* const otherSrcInstance = other->GetShape(); //dgCollisionInstance childInstance (*mySrcInstance, mySrcInstance->GetChildShape()); //dgCollisionInstance otherInstance (*otherSrcInstance, otherSrcInstance->GetChildShape()); dgCollisionInstance childInstance (*me->GetShape(), me->GetShape()->GetChildShape()); dgCollisionInstance otherInstance (*other->GetShape(), other->GetShape()->GetChildShape()); childInstance.SetGlobalMatrix(childInstance.GetLocalMatrix() * myMatrix); otherInstance.SetGlobalMatrix(otherInstance.GetLocalMatrix() * otherMatrix); proxy.m_floatingCollision = &childInstance; proxy.m_referenceCollision = &otherInstance; dgInt32 count = pair->m_contactCount; m_world->SceneChildContacts (pair, proxy); if (pair->m_contactCount > count) { dgContactPoint* const buffer = proxy.m_contacts; for (dgInt32 i = count; i < pair->m_contactCount; i ++) { //if (buffer[i].m_collision0 == proxy.m_floatingCollision) { // buffer[i].m_collision0 = mySrcInstance; //} //if (buffer[i].m_collision1 == proxy.m_referenceCollision) { // buffer[i].m_collision1 = otherSrcInstance; //} if (buffer[i].m_collision1->GetChildShape() == otherSrcInstance->GetChildShape()) { dgAssert(buffer[i].m_collision0->GetChildShape() == mySrcInstance->GetChildShape()); buffer[i].m_collision0 = mySrcInstance; buffer[i].m_collision1 = otherSrcInstance; } else { dgAssert(buffer[i].m_collision1->GetChildShape() == mySrcInstance->GetChildShape()); buffer[i].m_collision1 = mySrcInstance; buffer[i].m_collision0 = otherSrcInstance; } } } closestDist = dgMin(closestDist, constraint->m_closestDistance); } } else if (me->m_type == m_leaf) { dgAssert (other->m_type == m_node); stackPool[stack][0] = me; stackPool[stack][1] = other->m_left; stack++; dgAssert (stack < dgInt32 (sizeof (stackPool) / sizeof (dgNodeBase*))); stackPool[stack][0] = me; stackPool[stack][1] = other->m_right; stack++; dgAssert (stack < dgInt32 (sizeof (stackPool) / sizeof (dgNodeBase*))); } else if (other->m_type == m_leaf) { dgAssert (me->m_type == m_node); stackPool[stack][0] = me->m_left; stackPool[stack][1] = other; stack++; dgAssert (stack < dgInt32 (sizeof (stackPool) / sizeof (dgNodeBase*))); stackPool[stack][0] = me->m_right; stackPool[stack][1] = other; stack++; dgAssert (stack < dgInt32 (sizeof (stackPool) / sizeof (dgNodeBase*))); } else { dgAssert (me->m_type == m_node); dgAssert (other->m_type == m_node); stackPool[stack][0] = me->m_left; stackPool[stack][1] = other->m_left; stack++; dgAssert (stack < dgInt32 (sizeof (stackPool) / sizeof (dgNodeBase*))); stackPool[stack][0] = me->m_left; stackPool[stack][1] = other->m_right; stack++; dgAssert (stack < dgInt32 (sizeof (stackPool) / sizeof (dgNodeBase*))); stackPool[stack][0] = me->m_right; stackPool[stack][1] = other->m_left; stack++; dgAssert (stack < dgInt32 (sizeof (stackPool) / sizeof (dgNodeBase*))); stackPool[stack][0] = me->m_right; stackPool[stack][1] = other->m_right; stack++; dgAssert (stack < dgInt32 (sizeof (stackPool) / sizeof (dgNodeBase*))); } } } } constraint->m_closestDistance = closestDist; }
static void draw(void) { int i,j,k; float size = CUBE_SIZE; float normals[6][3] = { { 0.0, 0.0, -1.0}, { 1.0, 0.0, 0.0}, { 0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, { 0.0, -1.0, 0.0} }; float cube_points[8][3] ={ { -size, -size, -size }, { size, -size, -size }, { size, -size, size }, { -size, -size, size }, { -size, size, -size }, { size, size, -size }, { size, size, size }, { -size, size, size } }; /* 3Dオブジェクトを描画するための準備 */ argDrawMode3D(); argDraw3dCamera(0, 0); glClear(GL_DEPTH_BUFFER_BIT); //バッファの消去 glEnable( GL_DEPTH_TEST ); // 陰面処理の適用 mySetLight(); glEnable( GL_LIGHTING ); myMatrix(object[PTT1_MARK_ID].patt_trans); renew(); // フレーム毎の更新内容 // 立方体 glPushMatrix(); glTranslated( c_trans[0], c_trans[1], c_trans[2]);//平行移動値の設定 glRotatef(c_angle[0], 1.0, 0.0, 0.0 ); glRotatef(c_angle[1], 0.0, 1.0, 0.0 ); glRotatef(c_angle[2], 0.0, 0.0, 1.0 ); /* 前 */ glEnable( GL_TEXTURE_2D ); glBegin( GL_QUADS ); mySetMaterial( 1.0, 1.0, 1.0 ); glBindTexture(GL_TEXTURE_2D, texture); glNormal3fv(normals[0]); glTexCoord2f(0.0, 1.0); glVertex3fv(cube_points[0]); glTexCoord2f(1.0, 1.0); glVertex3fv(cube_points[1]); glTexCoord2f(1.0, 0.0); glVertex3fv(cube_points[5]); glTexCoord2f(0.0, 0.0); glVertex3fv(cube_points[4]); glEnd(); glDisable( GL_TEXTURE_2D ); /* 右 */ glBegin( GL_QUADS ); mySetMaterial( 0.0, 1.0, 0.0); glNormal3fv(normals[1]); glVertex3fv(cube_points[1]); glVertex3fv(cube_points[2]); glVertex3fv(cube_points[6]); glVertex3fv(cube_points[5]); glEnd(); /* 後ろ */ glBegin( GL_QUADS ); mySetMaterial( 0.0, 1.0, 1.0); glNormal3fv(normals[2]); glVertex3fv(cube_points[2]); glVertex3fv(cube_points[3]); glVertex3fv(cube_points[7]); glVertex3fv(cube_points[6]); glEnd(); /* 左 */ glBegin( GL_QUADS ); mySetMaterial( 1.0, 0.0, 1.0); glNormal3fv(normals[3]); glVertex3fv(cube_points[3]); glVertex3fv(cube_points[0]); glVertex3fv(cube_points[4]); glVertex3fv(cube_points[7]); glEnd(); /* 上 */ glBegin( GL_QUADS ); mySetMaterial( 0.0, 0.0, 1.0); glNormal3fv(normals[4]); glVertex3fv(cube_points[4]); glVertex3fv(cube_points[5]); glVertex3fv(cube_points[6]); glVertex3fv(cube_points[7]); glEnd(); /* 下 */ glBegin( GL_QUADS ); mySetMaterial( 1.0, 1.0, 0.0); glNormal3fv(normals[5]); glVertex3fv(cube_points[0]); glVertex3fv(cube_points[1]); glVertex3fv(cube_points[2]); glVertex3fv(cube_points[3]); glEnd(); glPopMatrix(); glDisable( GL_LIGHTING ); glDisable( GL_DEPTH_TEST ); // 陰面処理の適用 }
Rcpp::StringMatrix proc_feature( Rcpp::StringVector myBed, // std::vector< int > POS, Rcpp::StringMatrix myData, int fill_missing ){ // myBed is a StringVector: // myBed(0) = chrom // myBed(1) = chromStart // myBed(2) = chromEnd // myBed(3) = name // myData is a StringMatrix // column 0 = CHROM // column 1 = POS // Convert POS to ints std::vector< int > POS = get_pos(myData); // Create an empty matrix to return in exceptions. Rcpp::StringMatrix MT_matrix(0, myData.ncol()); // Rcpp::StringVector myBed includes start and stop integer coordinates. // Convert Rcpp::StringVector elements to int std::string temp = Rcpp::as< std::string >( myBed(1) ); int start = atoi(temp.c_str()); temp = Rcpp::as< std::string >( myBed(2) ); int end = atoi(temp.c_str()); // Manage if feature is on reverse strand if(end < start){ int tmp = start; start = end; end = tmp; } // Increment i so that chromosome in myData // matches the chromosome in the single BED record. int i = 0; // Data row counter while ( myData(i,0) != myBed(0) && i < myData.nrow() ){ i++; } // If we didn't find the chromosome return an empty matrix. if( i == myData.nrow() & fill_missing != 1 ){ return MT_matrix; } // Rcpp::Rcout << " Found CHROM " << myBed(0) << " in myData CHROM:" << myData(i,0) << " POS:" << myData(i,1) << "\n"; // We should now have i at the correct chromosome in myData. // POS is the integer recast of POS in myData. // We can now increment to the correct position in the chromosome // by incrementing to the start of teh annotation. // // Increment to POS. while( myData(i,0) == myBed(0) && POS[i] < start && i < myData.nrow() ){ i++; } // If we didn't find the POS return an empty matrix. if( i == myData.nrow() & fill_missing != 1 ){ return MT_matrix; } // Rcpp::Rcout << " Found CHROM " << myBed(0) << " in myData POS:" << POS[i] << "\n"; // Increment to the end of the feature int j=i; while( myData(j,0) == myBed(0) && POS[j] <= end && j < myData.nrow() ){ j++; } // Rcpp::Rcout << " Found end of feature at: " << POS[j-1] << "\n"; // We now have the information to declare a return matrix // and populate it. if( fill_missing != 1 ){ // Do not fill missubg data. Rcpp::StringMatrix myMatrix( j-i , myData.ncol()); Rcpp::colnames(myMatrix) = Rcpp::colnames(myData); // Populate the return matrix for(int k = 0; k < myMatrix.nrow(); k++){ Rcpp::checkUserInterrupt(); myMatrix(k, Rcpp::_) = myData(k+i, Rcpp::_); } return myMatrix; } else { // Fill missing data. Rcpp::StringMatrix myMatrix( end - start + 1 , myData.ncol()); Rcpp::colnames(myMatrix) = Rcpp::colnames(myData); // Populate the return matrix if( i >= myData.nrow()){ // No data for(int k = 0; k < myMatrix.nrow(); k++){ Rcpp::checkUserInterrupt(); myMatrix(k,0) = myBed(0); // myMatrix(k,1) = std::to_string(start + k); std::ostringstream stm; stm << start + k; myMatrix(k,1) = stm.str(); myMatrix(k,2) = NA_STRING; // for(int m=2; m<myMatrix.ncol(); m++){ // myMatrix(k,m) = NA_STRING; // } } } else { // Data and possibly missing data int l = 0; for(int k = 0; k < myMatrix.nrow(); k++){ Rcpp::checkUserInterrupt(); if( i + l < myData.nrow() ){ // We have not overrun the file yet temp = Rcpp::as< std::string >( myData( i+l , 1 ) ); int myPOS = atoi(temp.c_str()); // int myPOS = stoi(temp); if( myPOS == start + k ){ // myMatrix(k, Rcpp::_) = myData(k+i, Rcpp::_); myMatrix(k, Rcpp::_) = myData( i + l, Rcpp::_); l++; } else { myMatrix(k,0) = myBed(0); // myMatrix(k,1) = std::to_string(myPOS); std::ostringstream stm; stm << myPOS; myMatrix(k,1) = stm.str(); myMatrix(k,2) = NA_STRING; //myMatrix(k,1) = myBed(1) + k; //for(int m=2; m<myMatrix.ncol(); m++){ // myMatrix(k,m) = NA_STRING; //} } } else { // We've overrun the rows in the file. myMatrix(k,0) = myBed(0); // myMatrix(k,1) = std::to_string( start + k ); std::ostringstream stm; stm << start + k; myMatrix(k,1) = stm.str(); myMatrix(k,2) = NA_STRING; //myMatrix(k,1) = myBed(1) + k; //for(int m=2; m<myMatrix.ncol(); m++){ // myMatrix(k,m) = NA_STRING; //} } } } return myMatrix; } Rcpp::Rcerr << "You should never get here, something bad has happened!\n"; }
static void draw( void ) { static int before_visible[2] = {0, 0}; static int Wire_count = -1; // 出力する Wire の選択(0〜4) static int flag_first1 = 0; // 一度でも hiro が見つかったら立つ int i; static double begin[3]; double wtrans[3][4]; double gl_para[16]; /* 3Dオブジェクトを描画するための準備 */ argDrawMode3D(); argDraw3dCamera(0, 0); /* Zバッファなどの設定 */ glClear( GL_DEPTH_BUFFER_BIT ); // 陰面処理の設定 glEnable( GL_DEPTH_TEST ); // 陰面処理の適用 mySetLight(); // 光源の設定 glEnable( GL_LIGHTING ); // 光源の適用 /* マーカの出現と消失の処理 */ /* マーカ1の処理 */ if( myCheck_appear(before_visible[PTT1_MARK_ID], object[PTT1_MARK_ID].visible) ){ begin[0] = object[PTT1_MARK_ID].patt_trans[0][3]; begin[1] = object[PTT1_MARK_ID].patt_trans[1][3]; begin[2] = object[PTT1_MARK_ID].patt_trans[2][3]; points[L_P_count].flag_after_change = 0; } if( myCheck_disappear(before_visible[PTT1_MARK_ID], object[PTT1_MARK_ID].visible) ){ myCopyTrans( object[PTT1_MARK_ID].patt_trans, points[L_P_count].trans); points[L_P_count].start_point[0] = begin[0] - object[PTT1_MARK_ID].patt_trans[0][3]; points[L_P_count].start_point[1] = -( begin[1] - object[PTT1_MARK_ID].patt_trans[1][3] ); // Y軸はカメラに対して反転しているので points[L_P_count].start_point[2] = -( begin[2] - object[PTT1_MARK_ID].patt_trans[2][3] ); // Z軸はカメラに対して反転しているので for(i=0; i<3; i++){ points[L_P_count].end_point[i] = 0.0; } myMoveBallInit( &points[L_P_count] ); L_P_count++; if(MAX_LINES <= L_P_count){ L_P_count = 0; } } /* マーカ2の出現と消失 */ if( myCheck_appear(before_visible[PTT2_MARK_ID], object[PTT2_MARK_ID].visible) ){ for(i=0; i < L_P_count; i++){ arUtilMatMul( itrans2, points[i].trans, wtrans); myCopyTrans( wtrans, points[i].trans); points[i].flag_after_change = 1; } } if( myCheck_disappear(before_visible[PTT2_MARK_ID], object[PTT2_MARK_ID].visible) ){ for(i=0; i < L_P_count; i++){ arUtilMatMul( object[PTT2_MARK_ID].patt_trans, points[i].trans, wtrans); myCopyTrans( wtrans, points[i].trans ); } } /* 3Dオブジェクトの描画 */ /* 過去に描いた線分の描画 */ if(flag_first1 && L_P_count >= 1 && !(object[PTT2_MARK_ID].visible) ){ mySelectColor( 1.0, 0.0, 0.0); // 材質特性の設定 glLineWidth( 5.0); for(i=0; i < L_P_count; i++){ glPushMatrix(); // 念のため myMatrix( points[i].trans); myLineLoop(i, i+1); glPopMatrix(); // 念のため } } /* マーカ1(Hiro) が映ったときの処理 */ if(object[PTT1_MARK_ID].visible){ flag_first1 = 1; /* 現在書いている線分の描画 */ myMatrix(object[PTT1_MARK_ID].patt_trans); mySelectColor( 1.0, 0.8, 0.0); // 材質特性の設定 glLineWidth( 5.0); glBegin( GL_LINES ); glVertex3f( begin[0] - object[PTT1_MARK_ID].patt_trans[0][3], -( begin[1] - object[PTT1_MARK_ID].patt_trans[1][3] ), -( begin[2] - object[PTT1_MARK_ID].patt_trans[2][3] ) ); glVertex3f( 0.0, 0.0, 0.0 ); glEnd(); /* hiro のマーカを縁取り */ myMatrix(object[PTT1_MARK_ID].patt_trans); mySelectColor( 0.0, 0.0, 1.0); // 材質特性の設定 glLineWidth( 3.0); myMarkSquare (PTT1_MARK_ID); } /* マーカ2(kanji) が表示されているとき */ if(object[PTT2_MARK_ID].visible){ /* マーカ2の縁取り */ myMatrix(object[PTT2_MARK_ID].patt_trans); mySelectColor( 0.0, 1.0, 0.0); // 材質特性の設定 glLineWidth( 3.0); myMarkSquare (PTT2_MARK_ID); /* 座標変換 */ glLineWidth( 5.0); for(i=0; i < L_P_count; i++){ glPushMatrix(); mySelectColor( 0.0, 0.0, 1.0); // 材質特性の設定 argConvGlpara( points[i].trans, gl_para ); glMultMatrixd( gl_para ); myLineLoop(i, i+1); if( flag_animation){ myMoveBall( &points[i] ); } else{ myMoveBall2( &points[i], i ); } glPopMatrix(); } } visible_log(PTT_NUM, before_visible); // 各マーカの visible 状態の記録 glDisable( GL_LIGHTING ); // 光源の無効化 glDisable( GL_DEPTH_TEST ); // 陰面処理の無効化 }
//-------------------------------------------------------------- void ofxGLWarper::processMatrices(){ //we set it to the default - 0 translation //and 1.0 scale for x y z and w myMatrix = ofMatrix4x4(); // default constructor generates identity //we need our points as opencv points //be nice to do this without opencv? CvPoint2D32f cvsrc[4]; CvPoint2D32f cvdst[4]; //we set the warp coordinates //source coordinates as the dimensions of our window cvsrc[0].x = x; cvsrc[0].y = y; cvsrc[1].x = x+width; cvsrc[1].y = y; cvsrc[2].x = x+width; cvsrc[2].y = y+height; cvsrc[3].x = x; cvsrc[3].y = y+height; //corners are in 0.0 - 1.0 range //so we scale up so that they are at the window's scale for(int i = 0; i < 4; i++){ //cvdst[i].x = corners[i].x * (float)width; //cvdst[i].y = corners[i].y * (float)height; cvdst[i].x = corners[i].x; cvdst[i].y = corners[i].y; } //we create a matrix that will store the results //from openCV - this is a 3x3 2D matrix that is //row ordered CvMat * translate = cvCreateMat(3,3,CV_32FC1); //this is the slightly easier - but supposidly less //accurate warping method //cvWarpPerspectiveQMatrix(cvsrc, cvdst, translate); //for the more accurate method we need to create //a couple of matrixes that just act as containers //to store our points - the nice thing with this //method is you can give it more than four points! CvMat* src_mat = cvCreateMat( 4, 2, CV_32FC1 ); CvMat* dst_mat = cvCreateMat( 4, 2, CV_32FC1 ); //copy our points into the matrixes cvSetData( src_mat, cvsrc, sizeof(CvPoint2D32f)); cvSetData( dst_mat, cvdst, sizeof(CvPoint2D32f)); //figure out the warping! //warning - older versions of openCV had a bug //in this function. cvFindHomography(src_mat, dst_mat, translate); //get the matrix as a list of floats float *matrix = translate->data.fl; //we need to copy these values //from the 3x3 2D openCV matrix which is row ordered // // ie: [0][1][2] x // [3][4][5] y // [6][7][8] w //to openGL's 4x4 3D column ordered matrix // x y z w // ie: [0][3][ ][6] // [1][4][ ][7] // [ ][ ][ ][ ] // [2][5][ ][8] // myMatrix(0,0) = matrix[0]; myMatrix(1,0) = matrix[1]; myMatrix(3,0) = matrix[2]; myMatrix(0,1) = matrix[3]; myMatrix(1,1) = matrix[4]; myMatrix(3,1) = matrix[5]; myMatrix(0,3) = matrix[6]; myMatrix(1,3) = matrix[7]; myMatrix(3,3) = matrix[8]; }