void CEdge::Blend(double radius, bool chamfer_not_fillet){ try{ CShape* body = GetParentBody(); if(body){ if(chamfer_not_fillet) { BRepFilletAPI_MakeChamfer chamfer(body->Shape()); for(std::list<CFace*>::iterator It = m_faces.begin(); It != m_faces.end(); It++) { CFace* face = *It; chamfer.Add(radius, m_topods_edge, TopoDS::Face(face->Face())); } TopoDS_Shape new_shape = chamfer.Shape(); wxGetApp().AddUndoably(new CSolid(*((TopoDS_Solid*)(&new_shape)), _("Solid with edge chamfer"), *(body->GetColor()), body->GetOpacity()), NULL, NULL); } else { BRepFilletAPI_MakeFillet fillet(body->Shape()); fillet.Add(radius, m_topods_edge); TopoDS_Shape new_shape = fillet.Shape(); wxGetApp().AddUndoably(new CSolid(*((TopoDS_Solid*)(&new_shape)), _("Solid with edge blend"), *(body->GetColor()), body->GetOpacity()), NULL, NULL); } wxGetApp().DeleteUndoably(body); } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); wxMessageBox(wxString(chamfer_not_fillet ?_("Error making fillet"):_("Error making fillet")) + _T(": ") + Ctt(e->GetMessageString())); } catch(...) { wxMessageBox(chamfer_not_fillet ? _("A fatal error happened during Chamfer"):_("A fatal error happened during Blend")); } }// end Blend function
void CBaiDlg::OnBtOpen() { CFileDialog filedlg(TRUE,"ccr","",NULL,"ÆåÆ×|*.ccr||",this); int respond=filedlg.DoModal(); if(respond==IDOK) { CFace face; if(face.Open(filedlg.GetFileName())) { if(face.IsNormal())New(face); else { CString str; str.Format("\"%s\"\n²»ÊÇÕýÈ·µÄÆåÆ×",filedlg.GetFileName()); MessageBox(str,"´íÎó",MB_OK|MB_ICONERROR); } } else { CString str; str.Format("²»ÄÜ´ò¿ª\"%s\"",filedlg.GetFileName()); MessageBox(str,"´íÎó",MB_OK|MB_ICONERROR); } } }
void CShape::KillGLLists() { if (m_face_gl_list) { glDeleteLists(m_face_gl_list, 1); m_face_gl_list = 0; } if (m_edge_gl_list) { glDeleteLists(m_edge_gl_list, 1); m_edge_gl_list = 0; } m_box = CBox(); if(m_faces) { for(HeeksObj* object = m_faces->GetFirstChild(); object; object = m_faces->GetNextChild()) { CFace* f = (CFace*)object; f->KillMarkingGLList(); } } }
CFace* CShape::find(const TopoDS_Face &face) { for(HeeksObj* object = m_faces->GetFirstChild(); object; object = m_faces->GetNextChild()) { CFace* f = (CFace*)object; if(f->Face() == face)return f; } return NULL; }
double CShape::Area()const{ double area = 0.0; for(HeeksObj* object = m_faces->GetFirstChild(); object; object = m_faces->GetNextChild()) { CFace* f = (CFace*)object; area += f->Area(); } return area; }
void CBaiDlg::OnBtSave() { UpdateData(TRUE); CFace face; if(GetFace(face)) { face.side=m_nGoSide; CFileDialog filedlg(FALSE,"ccr","δÃüÃû",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"ÆåÆ×|*.ccr||",this); int respond=filedlg.DoModal(); if(respond==IDOK)face.Save(filedlg.GetFileName()); } }
void ConvexHull::CConvexHull::_remove_upper_tets() { ConvexHull::CVertex v(-1); v.point() = ConvexHull::CPoint4(0,0,0, 1e+20); _visibility( &v ); //remove visible tets std::vector<ConvexHull::CTet*> visible_tets; for( std::set<ConvexHull::CTet*>::iterator iter = m_tets.begin(); iter != m_tets.end(); iter ++ ) { ConvexHull::CTet * pT = *iter; if( pT->visible() ) visible_tets.push_back( pT ); } std::vector<ConvexHull::CFace*> visible_faces; for( std::set<ConvexHull::CFace*>::iterator iter = m_faces.begin(); iter != m_faces.end(); iter ++ ) { CFace * pF = *iter; CTet * pT = pF->tets(0); CTet * pW = pF->tets(1); if( pT->visible() && pW->visible() ) visible_faces.push_back( pF ); } for( size_t i = 0; i < visible_tets.size(); i ++ ) { ConvexHull::CTet * pT = visible_tets[i]; std::set<ConvexHull::CTet*>::iterator iter = std::find( m_tets.begin(), m_tets.end(), pT ); assert( iter != m_tets.end() ); m_tets.erase( iter ); m_tet_pool.delocate( pT ); } //remove visible faces for( size_t i = 0; i < visible_faces.size(); i ++ ) { ConvexHull::CFace * pF = visible_faces[i]; std::set<ConvexHull::CFace*>::iterator iter = std::find( m_faces.begin(), m_faces.end(), pF ); m_faces.erase( iter ); ConvexHull::CVertex * pV = pF->min_vert(); pV->remove( pF ); m_face_pool.delocate( pF ); } }
void CGLRenderer::hide(const CFace &f) { const TemplPrimVar<RtFloat> *pptr = f.floats(RI_P); if ( !pptr ) return; #if defined _OPENGL_TRANSFORM const TemplPrimVar<RtFloat> *nptr = f.floats(RI_N); const std::vector<RtFloat> *pp = &(pptr->values()); const std::vector<RtFloat> *np = nptr ? &(nptr->values()) : 0; #else std::vector<RtFloat> p; std::vector<RtFloat> n; const std::vector<RtFloat> *pp = &p; const std::vector<RtFloat> *np = &n; getPosAndNormals(f, toCamera(), p, n); if ( p.empty() ) return; #endif // Draw normals? if ( m_drawNormals && np ) { drawNormals(*pp, *np); } // State variables setCullFace(); setColor(); // vertexArray glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, &(*pp)[0]); // normalArray if ( np ) { if ( np->size() == np->size() ) { glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, &(*np)[0]); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } else if ( np->size() == 3 ) { glNormal3f((*np)[0], (*np)[1], (*np)[2]); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } } // surface opacity const TemplPrimVar<RtFloat> *pcSurfOpacity = f.floats(RI_OS); std::vector<RtFloat> os; if ( pcSurfOpacity ) { getAlpha(pcSurfOpacity->declaration().colorDescr(), pcSurfOpacity->values(), os); } // surface color, todo constant & mix alpha const TemplPrimVar<RtFloat> *pcSurf = f.floats(RI_CS); std::vector<RtFloat> cs; if ( pcSurf ) { getCs(pcSurf->declaration().colorDescr(), renderState()->options().gain(), renderState()->options().gamma(), pcSurf->values(), cs); } if ( cs.size() == 3 ) { RtFloat alpha = opacityToAlpha(attributes().opacity()); glColor4f(cs[0], cs[1], cs[2], alpha); } else if ( cs.size() == pp->size() ) { glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3, GL_FLOAT, 0, &cs[0]); if ( replayMode() ) glDepthMask(GL_TRUE); } // Draw vertices // std::cout << "# *** Size of indices: " << f.indices().size() << std::endl; IndexType sizeCnt = 0; switch ( f.faceType() ) { case FACETYPE_TRIANGLES: { for ( std::vector<IndexType>::const_iterator siter = f.sizes().begin(); siter != f.sizes().end(); siter++ ) { glDrawElements(GL_TRIANGLES, (*siter), GL_UNSIGNED_INT, &f.indices()[sizeCnt]); sizeCnt += (*siter); } } break; case FACETYPE_TRIANGLESTRIPS: { for ( std::vector<IndexType>::const_iterator siter = f.sizes().begin(); siter != f.sizes().end(); siter++ ) { glDrawElements(GL_TRIANGLE_STRIP, (*siter), GL_UNSIGNED_INT, &f.indices()[sizeCnt]); sizeCnt += (*siter); } } break; default: // std::cout << "# *** Unhandled face type" << std::endl; break; } // reset state /* if ( replayMode() ) glDepthMask(GL_FALSE); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); if ( np && (np->size() == pp->size()) ) { glDisableClientState(GL_NORMAL_ARRAY); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); } */ }
void CShape::FilletOrChamferEdges(std::list<HeeksObj*> &list, double radius, bool chamfer_not_fillet) { // make a map with a list of edges for each solid std::map< HeeksObj*, std::list< HeeksObj* > > solid_edge_map; for(std::list<HeeksObj*>::const_iterator It = list.begin(); It != list.end(); It++){ HeeksObj* edge = *It; if(edge->GetType() == EdgeType) { HeeksObj* solid = edge->HEEKSOBJ_OWNER->HEEKSOBJ_OWNER; if(solid && solid->GetType() == SolidType) { std::map< HeeksObj*, std::list< HeeksObj* > >::iterator FindIt = solid_edge_map.find(solid); if(FindIt == solid_edge_map.end()) { std::list< HeeksObj* > empty_list; solid_edge_map.insert( make_pair(solid, empty_list) ); FindIt = solid_edge_map.find(solid); } std::list< HeeksObj* > &list = FindIt->second; list.push_back(edge); } } } // do each solid for(std::map< HeeksObj*, std::list< HeeksObj* > >::iterator It = solid_edge_map.begin(); It != solid_edge_map.end(); It++) { HeeksObj* solid = It->first; std::list< HeeksObj* > &list = It->second; try{ if(chamfer_not_fillet) { BRepFilletAPI_MakeChamfer chamfer(((CShape*)solid)->Shape()); for(std::list< HeeksObj* >::iterator It2 = list.begin(); It2 != list.end(); It2++) { CEdge* edge = (CEdge*)(*It2); for(CFace* face = (CFace*)(edge->GetFirstFace()); face; face = (CFace*)(edge->GetNextFace())) { chamfer.Add(radius, TopoDS::Edge(edge->Edge()), TopoDS::Face(face->Face())); } } TopoDS_Shape new_shape = chamfer.Shape(); wxGetApp().Add(new CSolid(*((TopoDS_Solid*)(&new_shape)), _("Solid with edge blend"), *(solid->GetColor()), ((CShape*)solid)->m_opacity), NULL); wxGetApp().Remove(solid); } else { BRepFilletAPI_MakeFillet fillet(((CShape*)solid)->Shape()); for(std::list< HeeksObj* >::iterator It2 = list.begin(); It2 != list.end(); It2++) { fillet.Add(radius, TopoDS::Edge(((CEdge*)(*It2))->Edge())); } TopoDS_Shape new_shape = fillet.Shape(); wxGetApp().Add(new CSolid(*((TopoDS_Solid*)(&new_shape)), _("Solid with edge blend"), *(solid->GetColor()), ((CShape*)solid)->m_opacity), NULL); wxGetApp().Remove(solid); } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); wxMessageBox(wxString(_("Error making fillet")) + _T(": ") + Ctt(e->GetMessageString())); } catch(...) { wxMessageBox(_("A fatal error happened during Blend")); } } wxGetApp().Repaint(); }
void CShape::glCommands(bool select, bool marked, bool no_color) { bool mesh_called = false; bool draw_faces = (wxGetApp().m_solid_view_mode == SolidViewFacesAndEdges || wxGetApp().m_solid_view_mode == SolidViewFacesOnly); bool draw_edges = (wxGetApp().m_solid_view_mode == SolidViewFacesAndEdges || wxGetApp().m_solid_view_mode == SolidViewEdgesOnly); if(draw_faces) { for(HeeksObj* object = m_faces->GetFirstChild(); object; object = m_faces->GetNextChild()) { CFace* f = (CFace*)object; f->MakeSureMarkingGLListExists(); } if(!m_face_gl_list) { if(!mesh_called) { CallMesh(); mesh_called = true; } // make the display list m_face_gl_list = glGenLists(1); glNewList(m_face_gl_list, GL_COMPILE); // render all the faces m_faces->glCommands(true, marked, no_color); glEndList(); } // update faces marking display list GLint currentListIndex; glGetIntegerv(GL_LIST_INDEX, ¤tListIndex); if(currentListIndex == 0){ for(HeeksObj* object = m_faces->GetFirstChild(); object; object = m_faces->GetNextChild()) { CFace* f = (CFace*)object; f->UpdateMarkingGLList(wxGetApp().m_marked_list->ObjectMarked(f)); } } } if(draw_edges && !m_edge_gl_list) { if(!mesh_called) { CallMesh(); mesh_called = true; } // make the display list m_edge_gl_list = glGenLists(1); glNewList(m_edge_gl_list, GL_COMPILE); // render all the edges m_edges->glCommands(true, marked, no_color); // render all the vertices m_vertices->glCommands(true, false, false); glEndList(); } if(draw_faces && m_face_gl_list) { // draw the face display list glEnable(GL_LIGHTING); glShadeModel(GL_SMOOTH); glCallList(m_face_gl_list); glDisable(GL_LIGHTING); glShadeModel(GL_FLAT); } { // turn off transparency glDisable(GL_BLEND); glDepthMask(1); } if(draw_edges && m_edge_gl_list) { // draw the edge display list glCallList(m_edge_gl_list); } }
void CreateFacesAndEdges(TopoDS_Shape shape, CFaceList* faces, CEdgeList* edges, CVertexList* vertices) { // create index maps TopTools_IndexedMapOfShape faceMap; TopTools_IndexedMapOfShape edgeMap; TopTools_IndexedMapOfShape vertexMap; for (TopExp_Explorer explorer(shape, TopAbs_FACE); explorer.More(); explorer.Next()) { faceMap.Add(explorer.Current()); } for (TopExp_Explorer explorer(shape, TopAbs_EDGE); explorer.More(); explorer.Next()) { edgeMap.Add(explorer.Current()); } for (TopExp_Explorer explorer(shape, TopAbs_VERTEX); explorer.More(); explorer.Next()) { vertexMap.Add(explorer.Current()); } std::vector<CFace*> face_array; face_array.resize(faceMap.Extent() + 1); std::vector<CEdge*> edge_array; edge_array.resize(edgeMap.Extent() + 1); std::vector<CVertex*> vertex_array; vertex_array.resize(vertexMap.Extent() + 1); // create the edge objects for(int i = 1;i<=edgeMap.Extent();i++) { const TopoDS_Shape &s = edgeMap(i); CEdge* new_object = new CEdge(TopoDS::Edge(s)); edge_array[i] = new_object; } // create the vertex objects for(int i = 1;i<=vertexMap.Extent();i++) { const TopoDS_Shape &s = vertexMap(i); CVertex* new_object = new CVertex(TopoDS::Vertex(s)); vertex_array[i] = new_object; } // add the edges in their face loop order std::set<CEdge*> edges_added; std::set<CVertex*> vertices_added; // create the face objects for(int i = 1;i<=faceMap.Extent();i++) { const TopoDS_Shape &s = faceMap(i); CFace* new_face_object = new CFace(TopoDS::Face(s)); faces->Add(new_face_object, NULL); face_array[i] = new_face_object; // create the loop objects TopTools_IndexedMapOfShape loopMap; for (TopExp_Explorer explorer(s, TopAbs_WIRE); explorer.More(); explorer.Next()) { loopMap.Add(explorer.Current()); } TopoDS_Wire outerWire=BRepTools::OuterWire(new_face_object->Face()); int outer_index = loopMap.FindIndex(outerWire); for(int i = 1;i<=loopMap.Extent();i++) { const TopoDS_Shape &s = loopMap(i); CLoop* new_loop_object = new CLoop(TopoDS::Wire(s)); new_face_object->m_loops.push_back(new_loop_object); if(outer_index == i)new_loop_object->m_is_outer = true; new_loop_object->m_pface = new_face_object; // find the loop's edges for(BRepTools_WireExplorer explorer(TopoDS::Wire(s)); explorer.More(); explorer.Next()) { CEdge* e = edge_array[edgeMap.FindIndex(explorer.Current())]; new_loop_object->m_edges.push_back(e); // add the edge if(edges_added.find(e) == edges_added.end()) { edges->Add(e, NULL); edges_added.insert(e); } // add the vertex CVertex* v = vertex_array[vertexMap.FindIndex(explorer.CurrentVertex())]; if(vertices_added.find(v) == vertices_added.end()) { vertices->Add(v, NULL); vertices_added.insert(v); } } } } // find the vertices' edges for(unsigned int i = 1; i<vertex_array.size(); i++) { CVertex* v = vertex_array[i]; TopTools_IndexedMapOfShape vertexEdgeMap; for (TopExp_Explorer expEdge(v->Vertex(), TopAbs_EDGE); expEdge.More(); expEdge.Next()) { vertexEdgeMap.Add(expEdge.Current()); } for(int i = 1; i<=vertexEdgeMap.Extent(); i++) { const TopoDS_Shape &s = vertexEdgeMap(i); CEdge* e = edge_array[edgeMap.FindIndex(s)]; v->m_edges.push_back(e); } } // find the faces' edges for(unsigned int i = 1; i<face_array.size(); i++) { CFace* face = face_array[i]; TopTools_IndexedMapOfShape faceEdgeMap; for (TopExp_Explorer expEdge(face->Face(), TopAbs_EDGE); expEdge.More(); expEdge.Next()) { faceEdgeMap.Add(expEdge.Current()); } for(int i = 1; i<=faceEdgeMap.Extent(); i++) { const TopoDS_Shape &s = faceEdgeMap(i); CEdge* e = edge_array[edgeMap.FindIndex(s)]; face->m_edges.push_back(e); e->m_faces.push_back(face); bool sense = (s.IsEqual(e->Edge()) == Standard_True); e->m_face_senses.push_back(sense); } } }
void ConvexHull::CConvexHull::_insert_one_vertex( CVertex * pV ) { //test the visibility of each tetrahedron _visibility( pV ); std::vector<ConvexHull::CFace*> visible_faces; std::vector<ConvexHull::CFace*> silhoutte_faces; std::set<ConvexHull::CFace*> invisible_faces; for( std::set<CFace*>::iterator iter = m_faces.begin(); iter != m_faces.end(); iter ++ ) { CFace * pF = *iter; CTet * pT = pF->tets(0); CTet * pW = pF->tets(1); if( pT->visible() && pW->visible() ) visible_faces.push_back( pF ); else { invisible_faces.insert( pF ); } if( ( pT->visible() && !pW->visible() ) || (!pT->visible() && pW->visible()) ) silhoutte_faces.push_back( pF ); } m_faces.clear(); m_faces = invisible_faces; //generate new tets std::vector<ConvexHull::CTet*> new_tets; //Silhoutte face for( size_t i = 0; i < silhoutte_faces.size(); i ++ ) { CFace * pF = silhoutte_faces[i]; if( pF->tets(0)->visible() ) { CTet * pTet = m_tet_pool.allocate(); (*pTet)[0] = pV; (*pTet)[1] = (*pF)[0]; (*pTet)[2] = (*pF)[1]; (*pTet)[3] = (*pF)[2]; pF->tets(0) = pTet; m_tets.insert( pTet ); new_tets.push_back( pTet ); } else //pF->tets()[1]->visible() { CTet * pTet = m_tet_pool.allocate(); (*pTet)[0] = pV; (*pTet)[1] = (*pF)[1]; (*pTet)[2] = (*pF)[0]; (*pTet)[3] = (*pF)[2]; pF->tets(1) = pTet; m_tets.insert( pTet ); new_tets.push_back( pTet ); } } //generate new faces for( size_t i = 0; i < new_tets.size(); i ++ ) { ConvexHull::CTet * pT = new_tets[i]; std::set<ConvexHull::CFace*> fs; boundary( *pT, fs ); for( std::set<ConvexHull::CFace*>::iterator iter=fs.begin(); iter != fs.end(); iter ++ ) { ConvexHull::CFace * pF = *iter; ConvexHull::CVertex * pV = pF->min_vert(); ConvexHull::CFace * pD = pV->find( pF ); if( pD != NULL ) { int id = consistent( pD,pF ); switch( id ) { case +1: pD->tets(0) = pT; break; case -1: pD->tets(1) = pT; break; } m_face_pool.delocate( pF ); } else { pF->tets(0) = pT; pV->faces().push_back( pF ); m_faces.insert( pF ); } } } //remove visible faces for( size_t i = 0; i < visible_faces.size(); i ++ ) { ConvexHull::CFace * pF = visible_faces[i]; ConvexHull::CVertex * pV = pF->min_vert(); pV->remove( pF ); m_face_pool.delocate( pF ); } };