void compute_M_row_column_down(int position_c, int position_a, MAT & M) { MAT M_new(M.size1()-1,M.size2()-1); int k_old; int l_old; for (int k=0; k<M_new.size1(); k++) { k_old = (k<position_c ? k : k+1); for (int l=0; l<M_new.size2(); l++) { l_old = (l<position_a ? l : l+1); M_new(k,l) = M(k_old, l_old)-M(k_old,position_a)*M(position_c,l_old)/M(position_c,position_a); } } M_new.swap(M); }
int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(width, height); glutInitWindowPosition(50, 50); glutCreateWindow("Transformations matricielles"); glViewport(0, 0, width, height); glClearColor(0,0,0,0); glutDisplayFunc(display); // glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutSpecialFunc(special); glutMouseFunc(mouse); glutIdleFunc(idle); p_light[0]=-10.0; p_light[1]=20.0; p_light[2]=0.0; p_light[3]=1.0; p_aim = V_new(0,0,-2.75); P = P_new(); M = M_new(); glutMainLoop(); return 0; }
void keyboard(unsigned char keycode, int x, int y) { // printf("Touche frapee : %c (code ascii %d)\n",keycode, keycode); if (keycode==27) // ECHAP exit(0); if (keycode=='e') { dim = DIM3; M_perlinExtrude(M, P, 64); stop = 1; } if (keycode=='r') { dim = DIM3; M_revolution(M, P, 128); stop = 1; } //initialisation if (keycode=='i') { //reset things P = P_new(); M = M_new(); p_aim = V_new(0,0,-2.75); theta = 0; phi = 0; stop = 0; dim = DIM2; } if(keycode=='a'){ if(affichage == 0){ M->_is_filled = 1; affichage++; } else if(affichage == 1){ affichage++; } else{ M->_is_filled = 0; affichage = 0; } } //rotations switch(keycode){ case 'z': theta +=10; break; case 's': theta -=10; break; case 'q': phi += 1; break; case 'd': phi -=1; break; } glutPostRedisplay(); }
void compute_M_row_column_up(int row, int column, MAT & M, MAT2& sign_Fs, MAT2& Fe_M, typename MAT::type det_rat) { typedef typename MAT::type SCALAR; SCALAR det_rat_inv=1./det_rat; double sign=((row+column)%2==0 ? 1 : -1); Eigen::Matrix<SCALAR,Eigen::Dynamic,Eigen::Dynamic> M_sign_Fs(sign_Fs.size(),1); M_sign_Fs = M.block()*sign_Fs; assert(M.size1()==M.size2()); MAT M_new(M.size1()+1,M.size2()+1); int i_new; int j_new; // element (j,i) M_new(column,row) = sign*det_rat_inv; // row j and column i for (int k=0; k<M.size1(); k++) { i_new = (k<column ? k : k+1); j_new = (k<row ? k : k+1); M_new(i_new,row) = -M_sign_Fs(k)*det_rat_inv; M_new(column,j_new) = -sign*Fe_M(k)*det_rat_inv; } // remaining elements for (int k=0; k<M.size1(); k++) { i_new = (k<column ? k : k+1); for (int l=0; l<M.size1(); l++) { j_new = (l<row ? l : l+1); M_new(i_new, j_new) = M(k,l) + M_sign_Fs(k)*Fe_M(l)*det_rat_inv; } } M_new.swap(M); return; }
//---------------------------------------------------------------- // Function: TopoDS_Shape level function to update the core Surface // for any movement or Boolean operation of the body. // Author: Jane Hu //---------------------------------------------------------------- CubitStatus OCCSurface::update_OCC_entity(TopoDS_Face& old_surface, TopoDS_Shape& new_surface, BRepBuilderAPI_MakeShape *op, TopoDS_Vertex* removed_vertex, LocOpe_SplitShape* sp) { //set the Wires TopTools_IndexedMapOfShape M, M2; TopoDS_Shape shape, shape2, shape_edge, shape_vertex; TopExp::MapShapes(old_surface, TopAbs_WIRE, M); TopTools_ListOfShape shapes; BRepFilletAPI_MakeFillet2d* test_op = NULL; for (int ii=1; ii<=M.Extent(); ii++) { TopoDS_Wire wire = TopoDS::Wire(M(ii)); TopTools_ListOfShape shapes; if(op) { test_op = dynamic_cast<BRepFilletAPI_MakeFillet2d*>(op); if(!test_op) shapes.Assign(op->Modified(wire)); if(shapes.Extent() == 0) shapes.Assign(op->Generated(wire)); if(!new_surface.IsNull()) TopExp::MapShapes(new_surface,TopAbs_WIRE, M2); } else if(sp) shapes.Assign(sp->DescendantShapes(wire)); if (shapes.Extent() == 1) { shape = shapes.First(); if(M2.Extent() == 1) { shape2 = TopoDS::Wire(M2(1)); if(!shape.IsSame(shape2)) shape = shape2; } else if(M2.Extent() > 1) shape.Nullify(); } else if(shapes.Extent() > 1) shape.Nullify(); else if(op->IsDeleted(wire) || shapes.Extent() == 0) { TopTools_IndexedMapOfShape M_new; TopExp::MapShapes(new_surface, TopAbs_WIRE, M_new); if (M_new.Extent()== 1) shape = M_new(1); else shape.Nullify(); } else { shape = wire; continue; } //set curves BRepTools_WireExplorer Ex; for(Ex.Init(wire); Ex.More();Ex.Next()) { TopoDS_Edge edge = Ex.Current(); if(op && !test_op) { shapes.Assign(op->Modified(edge)); if(shapes.Extent() == 0) shapes.Assign(op->Generated(edge)); } else if(sp) shapes.Assign(sp->DescendantShapes(edge)); if (shapes.Extent() == 1) { //in fillet creating mothod, one edge could generated a face, so check //it here. TopAbs_ShapeEnum type = shapes.First().TShape()->ShapeType(); if(type != TopAbs_EDGE) shape_edge.Nullify(); else shape_edge = shapes.First(); } else if (shapes.Extent() > 1) { //update all attributes first. TopTools_ListIteratorOfListOfShape it; it.Initialize(shapes); for(; it.More(); it.Next()) { shape_edge = it.Value(); OCCQueryEngine::instance()->copy_attributes(edge, shape_edge); } shape_edge.Nullify(); } else if (op->IsDeleted(edge)) shape_edge.Nullify(); else if (test_op) { if(!test_op->IsModified(edge)) shape_edge = edge; else shape_edge = (test_op->Modified(edge)).First(); } else shape_edge = edge; //update vertex TopoDS_Vertex vertex = Ex.CurrentVertex(); shapes.Clear(); if(test_op) assert(removed_vertex != NULL); if(op && ! test_op ) shapes.Assign(op->Modified(vertex)); else if(sp) shapes.Assign(sp->DescendantShapes(vertex)); if (shapes.Extent() == 1) shape_vertex = shapes.First(); else if(shapes.Extent() > 1) { //update all attributes first. TopTools_ListIteratorOfListOfShape it; it.Initialize(shapes); for(; it.More(); it.Next()) { shape_vertex = it.Value(); OCCQueryEngine::instance()->copy_attributes(vertex, shape_vertex); } shape_vertex.Nullify() ; } else if(op->IsDeleted(vertex) || (test_op && vertex.IsSame( *removed_vertex))) shape_vertex.Nullify() ; else shape_vertex = vertex; if(!vertex.IsSame(shape_vertex) ) OCCQueryEngine::instance()->update_OCC_map(vertex, shape_vertex); if (!edge.IsSame(shape_edge)) OCCQueryEngine::instance()->update_OCC_map(edge, shape_edge); } if (!wire.IsSame(shape)) OCCQueryEngine::instance()->update_OCC_map(wire, shape); } double dTOL = OCCQueryEngine::instance()->get_sme_resabs_tolerance(); if (!old_surface.IsSame(new_surface)) { TopAbs_ShapeEnum shapetype = TopAbs_SHAPE; if(!new_surface.IsNull()) shapetype = new_surface.TShape()->ShapeType(); if(shapetype == TopAbs_FACE || new_surface.IsNull()) OCCQueryEngine::instance()->update_OCC_map(old_surface, new_surface); else { TopTools_IndexedMapOfShape M; TopExp::MapShapes(new_surface, TopAbs_FACE, M); TopoDS_Shape new_shape; if(M.Extent() == 1) new_shape = M(1); else if(M.Extent() > 1) { for(int i = 1; i <= M.Extent(); i++) { GProp_GProps myProps; BRepGProp::SurfaceProperties(old_surface, myProps); double orig_mass = myProps.Mass(); gp_Pnt orig_pnt = myProps.CentreOfMass(); BRepGProp::SurfaceProperties(M(i), myProps); double after_mass = myProps.Mass(); gp_Pnt after_pnt = myProps.CentreOfMass(); if(fabs(-after_mass + orig_mass) <= dTOL && orig_pnt.IsEqual(after_pnt, dTOL)) { new_shape = M(i); break; } } } OCCQueryEngine::instance()->update_OCC_map(old_surface, new_shape); } } return CUBIT_SUCCESS; }
void* operator new(size_t size,const char* pszFilename,int iLine) { return M_new(size,pszFilename,iLine); }
//---------------------------------------------------------------- // Function: TopoDS_Shape level function to update the core Body // for any Boolean operation of the body. // Author: Jane Hu //---------------------------------------------------------------- CubitStatus OCCBody::update_OCC_entity(TopoDS_Shape& old_shape, TopoDS_Shape& new_shape, BRepBuilderAPI_MakeShape *op, LocOpe_SplitShape* sp) { //set the Shells TopTools_IndexedMapOfShape M; TopExp::MapShapes(old_shape, TopAbs_SOLID, M); TopTools_IndexedMapOfShape M_new; TopExp::MapShapes(new_shape, TopAbs_SOLID, M_new); TopTools_ListOfShape shapes; TopoDS_Shape shape; CubitBoolean updated = CUBIT_FALSE; if(!old_shape.IsNull() && old_shape.ShapeType() == TopAbs_COMPOUND && !new_shape.IsNull() && new_shape.ShapeType() == TopAbs_COMPOUND && !old_shape.IsSame(new_shape)) { //By updating underling solids, shells etc., the old_shape will get changed. //trying to make sure the the number of each entity in the old and new //shapes are the same, which means that nothing is delete, that we can //update the map here. Otherwise, when deleting solids, it'll delete the //the old body and create new body. This is Ok for general boolean operation //except imprint when booleans are called, usually the original body are // supposed to be kept. updated = CUBIT_TRUE; OCCQueryEngine::instance()->update_OCC_map(old_shape, new_shape); } DLIList<int> new_solid_nums; DLIList<int> unfound_nums; for(int ii=1; ii<=M.Extent(); ii++) { TopoDS_Solid solid = TopoDS::Solid(M(ii)); TopTools_ListOfShape shapes; if(op) { shapes.Assign(op->Modified(solid)); if(shapes.Extent() == 0) shapes.Assign(op->Generated(solid)); } else if(sp) shapes.Assign(sp->DescendantShapes(solid)); if (shapes.Extent() == 1) shape = shapes.First(); else if(shapes.Extent() > 1) { //update all attributes first. TopTools_ListIteratorOfListOfShape it; it.Initialize(shapes); for(; it.More(); it.Next()) { shape = it.Value(); OCCQueryEngine::instance()->copy_attributes(solid, shape); } shape = shapes.First(); } else if(op->IsDeleted(solid)) { if (M_new.Extent()== 1 && ii == 1) shape = M_new(1); else if(M_new.Extent()== 1 && ii > 1) shape.Nullify(); else if(M_new.Extent() > 1) { GProp_GProps myProps; BRepGProp::VolumeProperties(solid, myProps); double bf_mass = myProps.Mass(); gp_Pnt old_center = myProps.CentreOfMass(); CubitBoolean found = CUBIT_FALSE; for(int l = 1; l <= M_new.Extent(); l++) { BRepGProp::VolumeProperties(M_new(l), myProps); double af_mass = myProps.Mass(); double dTol = OCCQueryEngine::instance()->get_sme_resabs_tolerance(); if(fabs(bf_mass-af_mass) < dTol) //unchanged { gp_Pnt new_center = myProps.CentreOfMass(); if(new_center.IsEqual(old_center, dTol)) { found = CUBIT_TRUE; shape = M_new(l); new_solid_nums.append(l); break; } } } if(!found) { unfound_nums.append(ii); continue; } } else shape.Nullify(); } else { shape = solid; continue; } if(shapes.Extent() > 0 || (op && op->IsDeleted(solid))) OCCLump::update_OCC_entity(solid, shape, op, sp); } if( unfound_nums.size() == 1 ) { TopoDS_Solid solid = TopoDS::Solid(M(unfound_nums.get())); for(int kk = 1; kk <= M_new.Extent(); kk++) { if(!new_solid_nums.move_to(kk)) { shape = M_new(kk); break; } } OCCLump::update_OCC_entity(solid, shape, op, sp); } else if(unfound_nums.size() > 1) { shape.Nullify(); for(int kk = 1; kk <=unfound_nums.size(); kk++) { TopoDS_Solid solid = TopoDS::Solid(M(unfound_nums.get_and_step())); OCCLump::update_OCC_entity(solid, shape, op, sp); } } if(!old_shape.IsSame(new_shape) && !updated) OCCQueryEngine::instance()->update_OCC_map(old_shape, new_shape); return CUBIT_SUCCESS; }