cgma
|
00001 #include "AppUtil.hpp" 00002 #include "CGMApp.hpp" 00003 #include "GeometryQueryTool.hpp" 00004 #include "FacetModifyEngine.hpp" 00005 #include "FacetQueryEngine.hpp" 00006 #include "CubitFacetData.hpp" 00007 #include "CubitPointData.hpp" 00008 #include "CubitQuadFacetData.hpp" 00009 #include "DLIList.hpp" 00010 #include "Surface.hpp" 00011 #include "ShellSM.hpp" 00012 #include "Lump.hpp" 00013 #include "Body.hpp" 00014 #include "BodySM.hpp" 00015 #include "RefFace.hpp" 00016 #include "RefVertex.hpp" 00017 00018 #include <iostream> 00019 00020 // forward declare some functions used and defined later 00021 bool generateFacetModel(DLIList<TopologyBridge*>& model); 00022 00023 int main(int argc, char* argv[]) 00024 { 00025 // Initialize CGM 00026 FacetQueryEngine* fqe = FacetQueryEngine::instance(); 00027 00028 DLIList<TopologyBridge*> model; 00029 const char *arg = "multifaceted.stl"; 00030 if (generateFacetModel(model)) 00031 { 00032 ModelExportOptions opts; 00033 fqe->export_solid_model( 00034 model, arg, FACET_TYPE, 00035 CubitString(), opts); 00036 std::cout << "Wrote \"" << arg << "\"\n"; 00037 } 00038 00039 return 0; 00040 } 00041 00042 bool generateFacetModel( 00043 DLIList<TopologyBridge*>& model) 00044 { 00045 FacetModifyEngine* fme = FacetModifyEngine::instance(); 00046 00047 CubitStatus stat; 00048 int i; 00049 00050 DLIList <CubitPoint*> plist; 00051 double pts[4][3] = { 00052 { 0., 0., 0. }, 00053 { 1., 0., 0. }, 00054 { 1., 1., 0. }, 00055 { 0., 1., 1. }, 00056 }; 00057 for (i = 0; i < (int)(sizeof(pts)/sizeof(pts[0])); ++i) 00058 { 00059 plist.append(new CubitPointData(pts[i][0], pts[i][1], pts[i][2])); 00060 } 00061 00062 // Build a tetrahedron, with 1 triangular facet per faceted-surface: 00063 int tconn[4][3] = { 00064 {0, 2, 1}, 00065 {0, 3, 2}, 00066 {0, 1, 3}, 00067 {1, 2, 3} 00068 }; 00069 DLIList<Surface*> all_surfs; 00070 DLIList<CubitFacet*> tflist; 00071 DLIList<CubitQuadFacet*> qflist; 00072 DLIList<CubitPoint*> facet_plist; 00073 for (i = 0; i < (int)(sizeof(tconn)/sizeof(tconn[0])); ++i) 00074 { 00075 std::cout << "Build faceted surface " << i << "\n"; 00076 //DLIList<CubitFacet*> tflist; 00077 //DLIList<CubitQuadFacet*> qflist; 00078 //DLIList<CubitPoint*> facet_plist; 00079 // Fails with or without the next 3 lines: 00080 //facet_plist.append(plist[tconn[i][0]]); 00081 //facet_plist.append(plist[tconn[i][1]]); 00082 //facet_plist.append(plist[tconn[i][2]]); 00083 // Create a single facet for our faceted surface: 00084 tflist.append( 00085 new CubitFacetData( 00086 plist[tconn[i][0]], plist[tconn[i][1]], plist[tconn[i][2]])); 00087 } 00088 DLIList<Surface*> slist; 00089 // Attempt to build a faceted surface: 00090 stat = fme->build_facet_surface( 00091 qflist, tflist, facet_plist, -1., 0, false, false, slist); 00092 if (slist.size() <= 0 || stat != CUBIT_SUCCESS) 00093 { 00094 PRINT_ERROR("Make surface failed. \n"); 00095 return false; 00096 } 00097 all_surfs += slist; 00098 00099 ShellSM* shell; 00100 stat = fme->make_facet_shell(all_surfs, shell); 00101 if (!shell || stat != CUBIT_SUCCESS) 00102 { 00103 PRINT_ERROR("Make shell failed. \n"); 00104 return false; 00105 } 00106 00107 DLIList<ShellSM*> shlist; 00108 shlist.append(shell); 00109 Lump* lump; 00110 stat = fme->make_facet_lump(shlist, lump); 00111 if (!lump || stat != CUBIT_SUCCESS) return false; 00112 00113 DLIList<Lump*> llist; 00114 BodySM* bodySM; 00115 Body* body; 00116 llist.append(lump); 00117 stat = fme->make_facet_body(llist, bodySM); 00118 body = GeometryQueryTool::instance()->make_Body(bodySM); 00119 if (!body || stat != CUBIT_SUCCESS) return false; 00120 00121 model.append(bodySM); 00122 return true; 00123 } 00124