diff --git a/libsrc/meshing/bcfunctions.cpp b/libsrc/meshing/bcfunctions.cpp index 04c8f7f6..1bab1b75 100644 --- a/libsrc/meshing/bcfunctions.cpp +++ b/libsrc/meshing/bcfunctions.cpp @@ -115,6 +115,7 @@ namespace netgen if(!header_found) { + ocf.close(); throw NgException("AutoColourAlg_UserProfile: Invalid or empty Boundary Colour Profile file\n"); return; } @@ -125,6 +126,7 @@ namespace netgen { if(!ocf.good()) { + ocf.close(); throw NgException("AutoColourAlg_UserProfile: Invalid or empty Boundary Colour Profile file\n"); return; } @@ -133,8 +135,8 @@ namespace netgen } else { - PrintMessage(3, "AutoColourAlg_UserProfile: No Boundary Colour entries found.... no changes made!"); ocf.close(); + PrintMessage(3, "AutoColourAlg_UserProfile: No Boundary Colour entries found.... no changes made!"); return; } @@ -164,7 +166,11 @@ namespace netgen >> bc_colours.Elem(i).Z(); if(!ocf.good()) + { + ocf.close(); throw NgException("Boundary Colour file error: Number of entries do not match specified list size!!\n"); + return; + } // Bound checking of the values // The RGB values should be between 0.0 and 1.0 @@ -450,6 +456,12 @@ namespace netgen PrintMessage(1, "AutoColourBcProps: Using Boundary Colour Profile file: "); PrintMessage(1, " ", bccolourfile); AutoColourAlg_UserProfile(mesh, ocf); + + // Make sure the file is closed before exiting the function + if(ocf.is_open()) + { + ocf.close(); + } } } } diff --git a/libsrc/meshing/bcfunctions.hpp b/libsrc/meshing/bcfunctions.hpp index ddfaeecf..593838af 100644 --- a/libsrc/meshing/bcfunctions.hpp +++ b/libsrc/meshing/bcfunctions.hpp @@ -44,6 +44,10 @@ namespace netgen */ //extern void OCCAutoColourBcProps(Mesh & mesh, OCCGeometry & occgeometry, const char *occcolourfile); extern void AutoColourBcProps(Mesh & mesh, const char *bccolourfile); + + extern void GetFaceColours(Mesh & mesh, Array & face_colours); + + extern bool ColourMatch(Vec3d col1, Vec3d col2, double eps = 2.5e-05); } #endif diff --git a/ng/dialog.tcl b/ng/dialog.tcl index e934cb19..0f6aff94 100644 --- a/ng/dialog.tcl +++ b/ng/dialog.tcl @@ -1530,6 +1530,99 @@ proc bcpropdialog { } { +# +# Philippose - 25/07/2010 +# Display the face colours currently +# available in the mesh +# +proc currmeshcoloursdialog { } { + + set w .currmeshcolours_dlg + + if {[winfo exists .currmeshcolours_dlg] == 1} { + wm withdraw $w + wm deiconify $w + focus $w + } { + toplevel $w + + global facecolslist + + frame $w.facecols -borderwidth 3 + pack $w.facecols -side top -expand yes -fill x -fill y + + listbox $w.facecols.list -yscroll "$w.facecols.scroll set" -selectmode single -setgrid 1 -width 32 -height 12 + scrollbar $w.facecols.scroll -command "$w.facecols.list yview" + pack $w.facecols.scroll -side right -fill y + pack $w.facecols.list -side left -expand 1 -fill both + + Ng_CurrentFaceColours getcolours facecolslist + set i 1 + foreach el $facecolslist { + set hel [format "%d: (%.4f %.4f %.4f)" $i [ lindex $el 0 ] [ lindex $el 1 ] [ lindex $el 2 ]] + incr i + $w.facecols.list insert end $hel } + + frame $w.bu1 + pack $w.bu1 + + button $w.bu1.showonly -text "show only" -command { + Ng_CurrentFaceColours showonly [.currmeshcolours_dlg.facecols.list curselection] + redraw + } + button $w.bu1.hideonly -text "hide only" -command { + Ng_CurrentFaceColours hideonly [.currmeshcolours_dlg.facecols.list curselection] + redraw + } + pack $w.bu1.showonly $w.bu1.hideonly -fill x -padx 3 -pady 3 -side left + + frame $w.bu2 + pack $w.bu2 + + button $w.bu2.showalso -text "show" -command { + Ng_CurrentFaceColours showalso [.currmeshcolours_dlg.facecols.list curselection] + redraw + } + button $w.bu2.hidealso -text "hide" -command { + Ng_CurrentFaceColours hidealso [.currmeshcolours_dlg.facecols.list curselection] + redraw + } + pack $w.bu2.showalso $w.bu2.hidealso -fill x -padx 3 -pady 3 -side left + + frame $w.bu3 + pack $w.bu3 + + button $w.bu3.showall -text "show all" -command { + Ng_CurrentFaceColours showall + redraw + } + button $w.bu3.hideall -text "hide all" -command { + Ng_CurrentFaceColours hideall + redraw + } + pack $w.bu3.showall $w.bu3.hideall -fill x -padx 3 -pady 3 -side left + + frame $w.bu4 + pack $w.bu4 + + button $w.bu4.close -text "close" -command { + destroy .currmeshcolours_dlg + } + pack $w.bu4.close -pady 3 -side right + + pack $w.bu4 -side bottom + + wm withdraw $w + wm geom $w +100+100 + wm deiconify $w + wm title $w "Inspect Mesh Colours" + focus $w + } +} + + + + # # Philippose - 30/01/2009 # Local Surface Mesh Size Selection diff --git a/ng/menustat.tcl b/ng/menustat.tcl index a852d45e..d6650a0d 100644 --- a/ng/menustat.tcl +++ b/ng/menustat.tcl @@ -788,6 +788,11 @@ menu .ngmenu.special .ngmenu.special add cascade -label "Colour-based boundary conditions" -menu .ngmenu.special.colbndcond menu .ngmenu.special.colbndcond + .ngmenu.special.colbndcond add command -label "Inspect Colours in mesh" \ + -command { currmeshcoloursdialog } + + .ngmenu.special.colbndcond add separator + .ngmenu.special.colbndcond add command -label "Automatic Assignment" \ -command { Ng_AutoColourBcProps auto; redraw } diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index 8e539c7f..be4f5c45 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -1555,6 +1555,178 @@ namespace netgen + // Philippose - 25/07/2010 + // TCL interface function for extracting and eventually + // setting or editing the current colours present in the mesh + int Ng_CurrentFaceColours (ClientData clientData, + Tcl_Interp * interp, + int argc, tcl_const char *argv[]) + { + if(argc < 1) + { + Tcl_SetResult (interp, (char *)"Ng_GetCurrentFaceColours needs arguments", TCL_STATIC); + return TCL_ERROR; + } + + if(!mesh.Ptr()) + { + Tcl_SetResult (interp, (char *)"Ng_GetCurrentFaceColours: Valid netgen mesh required...please mesh the Geometry first", TCL_STATIC); + return TCL_ERROR; + } + + if(strcmp(argv[1], "getcolours") == 0) + { + stringstream outVar; + Array face_colours; + GetFaceColours(*mesh, face_colours); + + for(int i = 0; i < face_colours.Size();i++) + { + outVar << "{ " << face_colours[i].X(1) + << " " << face_colours[i].X(2) + << " " << face_colours[i].X(3) + << " } "; + } + + tcl_const char * valuevar = argv[2]; + Tcl_SetVar (interp, valuevar, (char*)outVar.str().c_str(), 0); + } + + if(strcmp(argv[1], "showalso") == 0) + { + Array face_colours; + GetFaceColours(*mesh,face_colours); + + int colourind = atoi (argv[2]); + + for(int i = 1; i <= mesh->GetNFD(); i++) + { + Array surfElems; + mesh->GetSurfaceElementsOfFace(i,surfElems); + + if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour())) + { + for(int j = 0; j < surfElems.Size(); j++) + { + mesh->SurfaceElement(surfElems[j]).Visible(1); + } + } + } + + mesh->SetNextTimeStamp(); + } + + if(strcmp(argv[1], "hidealso") == 0) + { + Array face_colours; + GetFaceColours(*mesh,face_colours); + + int colourind = atoi (argv[2]); + + for(int i = 1; i <= mesh->GetNFD(); i++) + { + Array surfElems; + mesh->GetSurfaceElementsOfFace(i,surfElems); + + if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour())) + { + for(int j = 0; j < surfElems.Size(); j++) + { + mesh->SurfaceElement(surfElems[j]).Visible(0); + } + } + } + + mesh->SetNextTimeStamp(); + } + + if(strcmp(argv[1], "showonly") == 0) + { + Array face_colours; + GetFaceColours(*mesh,face_colours); + + int colourind = atoi (argv[2]); + + for(int i = 1; i <= mesh->GetNFD(); i++) + { + Array surfElems; + mesh->GetSurfaceElementsOfFace(i,surfElems); + + if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour())) + { + for(int j = 0; j < surfElems.Size(); j++) + { + mesh->SurfaceElement(surfElems[j]).Visible(1); + } + } + else + { + for(int j = 0; j < surfElems.Size(); j++) + { + mesh->SurfaceElement(surfElems[j]).Visible(0); + } + } + } + + mesh->SetNextTimeStamp(); + } + + if(strcmp(argv[1], "hideonly") == 0) + { + Array face_colours; + GetFaceColours(*mesh,face_colours); + + int colourind = atoi (argv[2]); + + for(int i = 1; i <= mesh->GetNFD(); i++) + { + Array surfElems; + mesh->GetSurfaceElementsOfFace(i,surfElems); + + if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour())) + { + for(int j = 0; j < surfElems.Size(); j++) + { + mesh->SurfaceElement(surfElems[j]).Visible(0); + } + } + else + { + for(int j = 0; j < surfElems.Size(); j++) + { + mesh->SurfaceElement(surfElems[j]).Visible(1); + } + } + } + + mesh->SetNextTimeStamp(); + } + + if(strcmp(argv[1], "showall") == 0) + { + for(int i = 1; i <= mesh->GetNSE(); i++) + { + mesh->SurfaceElement(i).Visible(1); + } + + mesh->SetNextTimeStamp(); + } + + if(strcmp(argv[1], "hideall") == 0) + { + for(int i = 1; i <= mesh->GetNSE(); i++) + { + mesh->SurfaceElement(i).Visible(0); + } + + mesh->SetNextTimeStamp(); + } + + return TCL_OK; + } + + + // Philippose - 10/03/2009 // TCL interface function for the Automatic Colour-based @@ -4940,6 +5112,13 @@ namespace netgen Tcl_CreateCommand (interp, "Ng_AutoColourBcProps", Ng_AutoColourBcProps, (ClientData)NULL, (Tcl_CmdDeleteProc*) NULL); + + // Philippose - 25/07/2010 + // Register the TCL Interface Command for handling the face colours + // present in the mesh + Tcl_CreateCommand(interp, "Ng_CurrentFaceColours", Ng_CurrentFaceColours, + (ClientData)NULL, + (Tcl_CmdDeleteProc*) NULL); // meshing