Skip to content
Snippets Groups Projects
Commit 44aefc87 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

- don't use unset() (only available in cmake >= 2.6.4)

- make sure we don't package the binary dir in make package_source
- fix GMSH_VERSION in Info.plist
- move last few README to README.txt
- added all remaining un-committed converters from mailing list into utils/
parent 5e284d6d
No related branches found
No related tags found
No related merge requests found
Showing
with 3088 additions and 9 deletions
......@@ -445,12 +445,13 @@ if(ENABLE_OCC)
list(LENGTH OCC_LIBS_REQUIRED NUM_OCC_LIBS_REQUIRED)
set(OCC_LIBS)
foreach(OCC ${OCC_LIBS_REQUIRED})
set(OCC_LIB OCC_LIB-NOTFOUND CACHE INTERNAL "")
# unset(OCC_LIB CACHE) # cleaner, but only available in cmake >= 2.6.4
find_library(OCC_LIB ${OCC} PATHS ENV CASROOT PATH_SUFFIXES lib
${OCC_SYS_NAME}/lib)
if(OCC_LIB)
list(APPEND OCC_LIBS ${OCC_LIB})
endif(OCC_LIB)
unset(OCC_LIB CACHE)
endforeach(OCC)
list(LENGTH OCC_LIBS NUM_OCC_LIBS)
if(NUM_OCC_LIBS EQUAL NUM_OCC_LIBS_REQUIRED)
......@@ -576,6 +577,7 @@ include_directories(Common Fltk Geo Graphics Mesh Numeric Parser Plugin
# target)
add_library(lib STATIC EXCLUDE_FROM_ALL ${GMSH_SRC})
set_target_properties(lib PROPERTIES OUTPUT_NAME Gmsh)
if(HAVE_FLTK)
add_executable(gmsh WIN32 Fltk/Main.cpp ${GMSH_SRC})
target_link_libraries(gmsh ${FLTK_LIBRARIES} ${EXTERNAL_LIBRARIES}
......@@ -634,7 +636,7 @@ macro(unix2dos VARNAME)
if(CYGWIN)
string(REGEX REPLACE "\n" "\r\n" F1 "${F0}")
file(WRITE ${CMAKE_BINARY_DIR}/unix2dos/${N} "${F1}")
else(CYGWIN) # if not in cygwin, assume cmake does it for us
else(CYGWIN) # if not in cygwin, cmake adds '\r's automatically
file(WRITE ${CMAKE_BINARY_DIR}/unix2dos/${N} "${F0}")
endif(CYGWIN)
list(APPEND UNIX2DOS_FILES ${CMAKE_BINARY_DIR}/unix2dos/${N})
......@@ -727,12 +729,13 @@ set(CPACK_STRIP_FILES TRUE)
set(CPACK_SOURCE_PACKAGE_FILE_NAME gmsh-${GMSH_VERSION}-source)
set(CPACK_SOURCE_GENERATOR TGZ)
set(CPACK_SOURCE_IGNORE_FILES "/CVS/" "/.svn" "~$" "DS_Store$" "GmshConfig.h$"
"GmshVersion.h$" "/benchmarks/" "/tmp/" "/bin/" "/lib/" "/nightly/"
"GPATH" "GRTAGS" "GSYMS" "GTAGS" "/HTML/" "/TetgenNew/") #"/Tetgen.*/.*(cxx|h)")
set(CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}" "/CVS/" "/.svn" "~$"
"DS_Store$" "GmshConfig.h$" "GmshVersion.h$" "/benchmarks/" "/tmp/"
"/bin/" "/lib/" "/nightly/" "GPATH" "GRTAGS" "GSYMS" "GTAGS" "/HTML/"
"/TetgenNew/") #"/Tetgen.*/.*(cxx|h)")
# make sure we remove previous installs before doing the next one
# (make package; make package_source can lead to huge file lists
# ("make package; make package_source" would lead to huge file lists
# getting generated due to the Applications symlink in the bundle)
set(CPACK_INSTALL_COMMANDS
"${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/_CPack_Packages")
......@@ -740,9 +743,12 @@ set(CPACK_INSTALL_COMMANDS
if(APPLE)
set(CPACK_GENERATOR Bundle)
set(CPACK_BUNDLE_NAME Gmsh)
set(CPACK_BUNDLE_PLIST ${CMAKE_SOURCE_DIR}/utils/misc/Info.plist)
file(READ ${CMAKE_SOURCE_DIR}/utils/misc/gmsh_app.plist F0)
string(REPLACE GMSH_VERSION "${GMSH_VERSION}" F1 "${F0}")
file(WRITE ${CMAKE_BINARY_DIR}/Info.plist "${F1}")
set(CPACK_BUNDLE_PLIST ${CMAKE_BINARY_DIR}/Info.plist)
set(CPACK_BUNDLE_ICON ${CMAKE_SOURCE_DIR}/Fltk/MacIcons.icns)
set(CPACK_BUNDLE_STARTUP_COMMAND ${CMAKE_SOURCE_DIR}/utils/misc/gmsh_bundle.sh)
set(CPACK_BUNDLE_STARTUP_COMMAND ${CMAKE_SOURCE_DIR}/utils/misc/gmsh_app.sh)
install(FILES ${CMAKE_SOURCE_DIR}/Fltk/MacIconsGeo.icns DESTINATION .
RENAME GmshGeo.icns)
install(FILES ${CMAKE_SOURCE_DIR}/Fltk/MacIconsMsh.icns DESTINATION .
......
This diff is collapsed.
File moved
File moved
File moved
......@@ -14,7 +14,7 @@ library compile on all the architectures supported by Gmsh)
* Started 8/27/94
* George
*
* $Id: README,v 1.4 2006-02-24 22:07:08 geuzaine Exp $
* $Id: README.txt,v 1.1 2009-08-15 09:31:23 geuzaine Exp $
*/
......
File moved
File moved
File moved
File moved
/*
(C) 2009 Mark van Doesburg, Technolution B.V.
Distributed under GPL version 2
*/
#include <iterator>
/* OpenCASCADE ************************************************************/
#include <config.h>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Compound.hxx>
#include <BRepTools.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeSolid.hxx>
#include <BRepBuilderAPI_NurbsConvert.hxx>
#include <BRepOffsetAPI_ThruSections.hxx>
#include <BRep_Builder.hxx>
#include <GC_MakeEllipse.hxx>
#include <TopOpeBRep_DSFiller.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
/* Boolean operations */
#include <BRepAlgoAPI_Common.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Section.hxx>
// NEW
#include <BRepFill_Filling.hxx>
#include <GeomFill_BSplineCurves.hxx>
#include <TopTools.hxx>
#include <ShapeFix_Solid.hxx>
#include "BRLFile.h"
#include "printing.h"
#define scale 1
////////////////////////////////////////////////////////////////////////////////
// Construct TopoDS from BRL-CAD data
////////////////////////////////////////////////////////////////////////////////
BRLTopo::BRLTopo(struct rt_arb_internal *arb)
{
TopoDS_Vertex v[8];
for(int i=0;i<8;i++)
v[i]=BRepBuilderAPI_MakeVertex(
gp_Pnt(
scale*arb->pt[i][0],
scale*arb->pt[i][1],
scale*arb->pt[i][2]
)
);
int arbn;
if(!BRepTools::Compare(v[6],v[7]))
arbn=8;
else if(!BRepTools::Compare(v[4],v[5]))
arbn=7;
else if(!BRepTools::Compare(v[5],v[6]))
arbn=6;
else if(!BRepTools::Compare(v[0],v[3]))
arbn=5;
else
arbn=4;
switch(arbn) {
case 8: {
TopoDS_Edge e[12];
for(int i=0;i<4;i++) {
e[i]=BRepBuilderAPI_MakeEdge(v[i],v[(i+1)%4]);
e[i+4]=BRepBuilderAPI_MakeEdge(v[i+4],v[(i+1)%4+4]);
e[i+8]=BRepBuilderAPI_MakeEdge(v[i],v[(i+4)%8]);
}
TopoDS_Wire w[6];
w[0]=BRepBuilderAPI_MakeWire(e[0],e[1],e[2],e[3]);
w[1]=BRepBuilderAPI_MakeWire(e[4],e[5],e[6],e[7]);
w[2]=BRepBuilderAPI_MakeWire(e[0],e[9],e[4],e[8]);
w[3]=BRepBuilderAPI_MakeWire(e[1],e[10],e[5],e[9]);
w[4]=BRepBuilderAPI_MakeWire(e[2],e[11],e[6],e[10]);
w[5]=BRepBuilderAPI_MakeWire(e[3],e[8],e[7],e[11]);
BRep_Builder BB;
TopoDS_Shell shell;
BB.MakeShell(shell);
for(int i=0;i<6;i++) {
TopoDS_Face f=BRepBuilderAPI_MakeFace(w[i]);
BB.Add(shell,i? f.Reversed():f);
}
TopoDS_Solid solid;
BB.MakeSolid(solid);
BB.Add(solid,shell);
ShapeFix_Solid sf(solid);
sf.Perform();
shape=sf.Solid();
} break;
case 6: {
TopoDS_Edge e[9];
e[0]=BRepBuilderAPI_MakeEdge(v[0],v[1]);
e[1]=BRepBuilderAPI_MakeEdge(v[1],v[2]);
e[2]=BRepBuilderAPI_MakeEdge(v[2],v[3]);
e[3]=BRepBuilderAPI_MakeEdge(v[3],v[0]);
e[4]=BRepBuilderAPI_MakeEdge(v[0],v[4]);
e[5]=BRepBuilderAPI_MakeEdge(v[1],v[4]);
e[6]=BRepBuilderAPI_MakeEdge(v[2],v[6]);
e[7]=BRepBuilderAPI_MakeEdge(v[3],v[6]);
e[8]=BRepBuilderAPI_MakeEdge(v[4],v[6]);
TopoDS_Wire w[5];
w[0]=BRepBuilderAPI_MakeWire(e[0],e[1],e[2],e[3]);
w[1]=BRepBuilderAPI_MakeWire(e[0],e[4],e[5]);
w[2]=BRepBuilderAPI_MakeWire(e[2],e[6],e[7]);
w[3]=BRepBuilderAPI_MakeWire(e[3],e[4],e[8],e[7]);
w[4]=BRepBuilderAPI_MakeWire(e[1],e[5],e[8],e[6]);
BRep_Builder BB;
#if 0
TopoDS_Compound result;
BB.MakeCompound(result);
for(int i=0;i<5;i++) {
BB.Add(result,BRepBuilderAPI_MakeFace(w[i]));
}
shape=result;
#else
TopoDS_Shell shell;
BB.MakeShell(shell);
for(int i=0;i<5;i++) {
TopoDS_Face f=BRepBuilderAPI_MakeFace(w[i]);
BB.Add(shell,f); //i? f:f.Reversed());
}
TopoDS_Solid solid;
BB.MakeSolid(solid);
BB.Add(solid,shell);
ShapeFix_Solid sf(solid);
sf.Perform();
shape=sf.Solid();
#endif
} break;
default:
cerr << "Unhandled arb8 type n=" << arbn << '\n';
}
}
BRLTopo::BRLTopo(struct rt_tgc_internal *tgc)
{
/* We use the same names as BRL-CAD, but use 4 vertices on the edges.
These additional vertices have their letter repeated and the
direction vector inverted.
*/
gp_Pnt v(scale*tgc->v[0], scale*tgc->v[1], scale*tgc->v[2]);
gp_Pnt a(
scale*(v.Coord(1)+tgc->a[0]),
scale*(v.Coord(2)+tgc->a[1]),
scale*(v.Coord(3)+tgc->a[2]));
gp_Pnt b(
scale*(v.Coord(1)+tgc->b[0]),
scale*(v.Coord(2)+tgc->b[1]),
scale*(v.Coord(3)+tgc->b[2]));
gp_Pnt aa(
scale*(v.Coord(1)-tgc->a[0]),
scale*(v.Coord(2)-tgc->a[1]),
scale*(v.Coord(3)-tgc->a[2]));
gp_Pnt bb(
scale*(v.Coord(1)-tgc->b[0]),
scale*(v.Coord(2)-tgc->b[1]),
scale*(v.Coord(3)-tgc->b[2]));
Handle(Geom_Ellipse) top;
if(v.SquareDistance(a)<v.SquareDistance(b))
top=GC_MakeEllipse(b, aa, v);
else
top=GC_MakeEllipse(a, b, v);
TopoDS_Edge e_t[4];
e_t[0]=BRepBuilderAPI_MakeEdge(top,a,b);
e_t[1]=BRepBuilderAPI_MakeEdge(top,b,aa);
e_t[2]=BRepBuilderAPI_MakeEdge(top,aa,bb);
e_t[3]=BRepBuilderAPI_MakeEdge(top,bb,a);
gp_Pnt h(
scale*(v.Coord(1)+tgc->h[0]),
scale*(v.Coord(2)+tgc->h[1]),
scale*(v.Coord(3)+tgc->h[2]));
gp_Pnt c(
scale*(h.Coord(1)+tgc->c[0]),
scale*(h.Coord(2)+tgc->c[1]),
scale*(h.Coord(3)+tgc->c[2]));
gp_Pnt d(
scale*(h.Coord(1)+tgc->d[0]),
scale*(h.Coord(2)+tgc->d[1]),
scale*(h.Coord(3)+tgc->d[2]));
gp_Pnt cc(
scale*(h.Coord(1)-tgc->c[0]),
scale*(h.Coord(2)-tgc->c[1]),
scale*(h.Coord(3)-tgc->c[2]));
gp_Pnt dd(
scale*(h.Coord(1)-tgc->d[0]),
scale*(h.Coord(2)-tgc->d[1]),
scale*(h.Coord(3)-tgc->d[2]));
Handle(Geom_Ellipse) bottom;
if(h.SquareDistance(c)<h.SquareDistance(d))
bottom=GC_MakeEllipse(d, cc, h);
else
bottom=GC_MakeEllipse(c, d, h);
TopoDS_Edge e_b[4];
e_b[0]=BRepBuilderAPI_MakeEdge(bottom,c,d);
e_b[1]=BRepBuilderAPI_MakeEdge(bottom,d,cc);
e_b[2]=BRepBuilderAPI_MakeEdge(bottom,cc,dd);
e_b[3]=BRepBuilderAPI_MakeEdge(bottom,dd,c);
#if 1
BRepOffsetAPI_ThruSections BB(Standard_True);
BB.AddWire(BRepBuilderAPI_MakeWire(e_t[0],e_t[1],e_t[2],e_t[3]));
BB.AddWire(BRepBuilderAPI_MakeWire(e_b[0],e_b[1],e_b[2],e_b[3]));
BB.CheckCompatibility(Standard_False);
shape=BB.Shape();
#else
BRep_Builder BB;
TopoDS_Compound result;
BB.MakeCompound(result);
for(int i=0;i<4;i++) {
BB.Add(result,e_t[i]);
BB.Add(result,e_b[i]);
}
shape=result;
#endif
}
BRLTopo::BRLTopo(struct rt_ell_internal *ell)
{
#if 0
gp_Pnt v(ell->v[0], ell->v[1], ell->v[2]);
gp_Pnt a(v.Coord(1)+ell->a[0], v.Coord(2)+ell->a[1], v.Coord(3)+ell->a[2]);
gp_Pnt b(v.Coord(1)+ell->b[0], v.Coord(2)+ell->b[1], v.Coord(3)+ell->b[2]);
gp_Pnt c(v.Coord(1)+ell->c[0], v.Coord(2)+ell->c[1], v.Coord(3)+ell->c[2]);
gp_Pnt aa(v.Coord(1)-ell->a[0], v.Coord(2)-ell->a[1], v.Coord(3)-ell->a[2]);
gp_Pnt bb(v.Coord(1)-ell->b[0], v.Coord(2)-ell->b[1], v.Coord(3)-ell->b[2]);
gp_Pnt cc(v.Coord(1)-ell->c[0], v.Coord(2)-ell->c[1], v.Coord(3)-ell->c[2]);
Handle(Geom_Ellipse) sect1=GC_MakeEllipse(a, b, v);
Handle(Geom_Ellipse) sect2=GC_MakeEllipse(a, c, v);
Handle(Geom_Ellipse) sect3=GC_MakeEllipse(b, c, v);
TopoDS_Edge e_ab[4];
e_ab[0]=BRepBuilderAPI_MakeEdge(sect1,a,b);
e_ab[1]=BRepBuilderAPI_MakeEdge(sect1,b,aa);
e_ab[2]=BRepBuilderAPI_MakeEdge(sect1,aa,bb);
e_ab[3]=BRepBuilderAPI_MakeEdge(sect1,bb,a);
TopoDS_Edge e_ac[4];
e_ac[0]=BRepBuilderAPI_MakeEdge(sect2,c,aa);
e_ac[1]=BRepBuilderAPI_MakeEdge(sect2,a,c);
e_ac[2]=BRepBuilderAPI_MakeEdge(sect2,aa,cc);
e_ac[3]=BRepBuilderAPI_MakeEdge(sect2,cc,a);
TopoDS_Edge e_bc[4];
e_bc[0]=BRepBuilderAPI_MakeEdge(sect3,b,c);
e_bc[1]=BRepBuilderAPI_MakeEdge(sect3,c,bb);
e_bc[2]=BRepBuilderAPI_MakeEdge(sect3,bb,cc);
e_bc[3]=BRepBuilderAPI_MakeEdge(sect3,cc,b);
// FIXME, BRepFill_Filling?
TopoDS_Solid sph=BRepPrimAPI_MakeSphere(v,ell->a[0]);
TopoDS_Face init;
for(TopExp_Explorer p(sph,TopAbs_FACE); p.More(); p.Next())
init=TopoDS::Face(p.Current());
BRepFill_Filling face1;
//face1.LoadInitSurface(init);
face1.Add(e_ab[0],GeomAbs_C0);
face1.Add(e_ab[1],GeomAbs_C0);
face1.Add(e_ac[0],GeomAbs_C0);
face1.Add(e_ac[1],GeomAbs_C0);
face1.Add(e_bc[0],GeomAbs_C0,false);
face1.Build();
BRepFill_Filling face2;
//face2.LoadInitSurface(init);
face2.Add(e_ab[2],GeomAbs_C0);
face2.Add(e_ab[3],GeomAbs_C0);
face2.Add(e_ac[2],GeomAbs_C0);
face2.Add(e_ac[3],GeomAbs_C0);
face2.Add(e_bc[2],GeomAbs_C0,false);
face2.Build();
BRepFill_Filling face3;
//face3.LoadInitSurface(init);
face3.Add(e_ab[2],GeomAbs_C0);
face3.Add(e_ab[3],GeomAbs_C0);
face3.Add(e_ac[0],GeomAbs_C0);
face3.Add(e_ac[1],GeomAbs_C0);
face3.Add(e_bc[1],GeomAbs_C0,false);
face3.Build();
BRepFill_Filling face4;
//face4.LoadInitSurface(init);
face4.Add(e_ab[0],GeomAbs_C0);
face4.Add(e_ab[1],GeomAbs_C0);
face4.Add(e_ac[2],GeomAbs_C0);
face4.Add(e_ac[3],GeomAbs_C0);
face4.Add(e_bc[3],GeomAbs_C0,false);
face4.Build();
BRep_Builder BB;
TopoDS_Shell result;
BB.MakeShell(result);
BB.Add(result,face1.Face());
BB.Add(result,face2.Face().Reversed());
BB.Add(result,face3.Face());
BB.Add(result,face4.Face().Reversed());
shape=BRepBuilderAPI_MakeSolid(result);
#else
/* FIXME, we only support spheres at the moment. */
gp_Pnt v(scale*ell->v[0], scale*ell->v[1], scale*ell->v[2]);
TopoDS_Solid sph=BRepPrimAPI_MakeSphere(v,scale*ell->a[0]);
shape=sph;
#endif
}
////////////////////////////////////////////////////////////////////////////////
// Read the BRL-CAD file
////////////////////////////////////////////////////////////////////////////////
BRLFile::BRLFile(char *filename, int v)
{
verbose=v;
dbip = db_open(filename, "r");
if(dbip==DBI_NULL)
return;
/* build a wdbp structure for convenient read/write */
wdbp = wdb_dbopen(dbip, RT_WDB_TYPE_DB_DISK);
if (db_dirbuild(dbip) < 0) { /* create directory database contents */
bu_log("Error building directory for %s\n", filename);
exit(-1);
}
}
int BRLFile::AddModel(char const *name)
{
if(dbip==DBI_NULL)
return 1;
struct directory *dp=db_lookup(dbip, name, 1);
if(dp == NULL)
return 1;
rt_init_resource( &rt_uniresource, 0, NULL );
db_functree(dbip, dp, CsgCombine, CsgLeaf, &rt_uniresource, this);
while(construction.size()>0) {
Add(construction.front());
construction.pop_front();
}
return 0;
}
TopoDS_Shape BRLFile::PerformBoolean(union tree *tp)
{
TopoDS_Shape left, right, result;
if(tp->tr_op==OP_UNION || tp->tr_op==OP_INTERSECT || tp->tr_op==OP_SUBTRACT
) {
left=PerformBoolean(tp->tr_b.tb_left);
right=PerformBoolean(tp->tr_b.tb_right);
}
if(verbose&BRL) {
switch(tp->tr_op) {
case OP_UNION:
case OP_INTERSECT:
case OP_SUBTRACT:
cout<< " Bool " << *tp;
break;
case OP_DB_LEAF:
if(verbose&BRL)
cout << " Leaf " << tp->tr_l.tl_name;
break;
}
cout << " remaining " << construction.size() << '\n';
}
switch(tp->tr_op) {
case OP_UNION: return BRepAlgoAPI_Fuse(left,right);
case OP_INTERSECT:return BRepAlgoAPI_Common(left,right);
case OP_SUBTRACT: return BRepAlgoAPI_Cut(left,right);
case OP_DB_LEAF:
result=construction.back();
construction.pop_back();
return result;
default:
std::cerr << "Invalid boolean operation in " << __FUNCTION__ << '\n';
return result;
}
}
void BRLFile::CsgCombine(struct db_i *dbip, struct directory *dp, genptr_t ptr)
{
BRLFile *that=(BRLFile*)ptr;
struct rt_db_internal ip;
if(rt_db_get_internal(&ip, dp, dbip, NULL, &rt_uniresource)!=ID_COMBINATION
) {
std::cerr << "Combination is not a combination in "
<< __FUNCTION__ << '\n';
exit(1);
}
struct rt_comb_internal *comb = (struct rt_comb_internal *)ip.idb_ptr;
if(that->verbose&BRL) {
std::cout << "Combine " << dp->d_namep << '\n';
std::cout << *comb;
std::cout << " --------------------\n";
std::cout << " " << comb->tree << '\n';
}
that->construction.push_back(that->PerformBoolean(comb->tree));
}
void BRLFile::CsgLeaf(struct db_i *dbip, struct directory *dp, genptr_t ptr)
{
BRLFile *that=(BRLFile*)ptr;
if(that->verbose&BRL)
std::cout << "Leaf " << dp->d_namep << '\n';
struct rt_db_internal ip;
switch(rt_db_get_internal(&ip, dp, dbip, (fastf_t *)NULL, &rt_uniresource)){
case ID_ARB8: {
struct rt_arb_internal *arb=(struct rt_arb_internal *)ip.idb_ptr;
if(that->verbose&BRL) {
std::cout << " ARB8\n";
for(int i=0;i<8;i++) {
std::cout << " pt[" << i << "]=" << arb->pt[i] << '\n';
}
}
that->construction.push_front(BRLTopo(arb));
} break;
case ID_TGC: {
struct rt_tgc_internal *tgc=(struct rt_tgc_internal *)ip.idb_ptr;
if(that->verbose&BRL) {
std::cout
<< " TGC\n"
<< " v=" << tgc->v << '\n'
<< " h=" << tgc->h << '\n'
<< " a=" << tgc->a << '\n'
<< " b=" << tgc->b << '\n'
<< " c=" << tgc->c << '\n'
<< " d=" << tgc->d << '\n';
}
that->construction.push_front(BRLTopo(tgc));
} break;
case ID_ELL: {
struct rt_ell_internal *ell=(struct rt_ell_internal *)ip.idb_ptr;
if(that->verbose&BRL) {
std::cout << " v=" << ell->v << '\n';
std::cout << " a=" << ell->a << '\n';
std::cout << " b=" << ell->b << '\n';
std::cout << " c=" << ell->c << '\n';
}
that->construction.push_front(BRLTopo(ell));
} break;
default:
std::cout << " Unhandled type " <<
rt_db_get_internal(&ip, dp, dbip, (fastf_t *)NULL, &rt_uniresource)
<< '\n';
}
}
/*
(C) 2009 Mark van Doesburg, Technolution B.V.
Distributed under GPL version 2
*/
#include "OCC_Connect.h"
/* BRL-CAD ************************************************************/
#include "common.h"
#include "vmath.h" /* vector math macros */
#include "raytrace.h" /* librt interface definitions */
#include "rtgeom.h"
#include "wdb.h"
class BRLTopo {
TopoDS_Shape shape;
public:
BRLTopo(TopoDS_Shape const &s) { shape=s; }
BRLTopo(struct rt_arb_internal *arb);
BRLTopo(struct rt_tgc_internal *tgc);
BRLTopo(struct rt_ell_internal *ell);
operator TopoDS_Shape&() { return shape; }
};
class BRLFile:public OCC_Connect {
struct rt_wdb *wdbp;
struct db_i *dbip;
struct rt_db_internal ip;
std::deque<BRLTopo> construction;
public:
enum Verbose { Cutting=1, BRL=2 };
BRLFile(char *filename,int v=0);
int AddModel(char const *);
private:
static void CsgCombine(struct db_i *, struct directory *, genptr_t);
static void CsgLeaf(struct db_i *, struct directory *, genptr_t);
TopoDS_Shape PerformBoolean(union tree*);
};
This is a tool to convert a BRL CAD model to an OpenCASCADE brep
file. To compile this program you need BRL CAD and it's sources to be
installed. Set the paths BRL_SRC and BRL_LIB in the Makefile and type
make. On 32 bit systems the -D_OCC64 option must be removed.
To use the program type:
g-brep test.g complex.r tst_corner1.s tst_com.s tst_acom.s
The first parameter is the BRL database, the subsequent parameters are
the models to be included in the brep file. Note that these models will
become single solids. All these solids will be connected to each other.
It is possible to skip the connecting algorithm when the "-c" option
is used. This is used to test the connecting algorithm in gmsh.
The result of the g-brep program is test.brep which can be read by gmsh,
if gmsh is compiled with OCC support.
This program has been tested with brlcad-7.14.6 and OpenCASCADE-6.3.0.
Mark van Doesburg.
/*
(C) 2009 Mark van Doesburg, Technolution B.V.
Distributed under GPL version 2
Use this program to translate a BRL-CAD file to a brep file which
can be read using OpenCASCADE.
format: g-brep {filename} {model} [model] ...
*/
#include "BRLFile.h"
#include <string>
main(int argc, char **argv)
{
if(argc<3) {
cerr << "Filename and object name(s) required\n";
return 1;
}
BRLFile solid(argv[1],BRLFile::Cutting|BRLFile::BRL);
int connect=1;
for(int i=2; i<argc; i++) {
if(argv[i][0]=='-') {
switch(argv[i][1]) {
case 'c': connect=0; break;
default:
cerr << "Unknown option :" << argv[i] << "\n";
return 1;
}
} else if(solid.AddModel(argv[i])) {
cerr << "Cannot find model " << argv[i] << '\n';
return 1;
}
}
if(connect)
solid.Connect();
else
solid.Collect();
std::string newname=argv[1];
int start=newname.find(".g");
if(start==std::string::npos) {
newname+=".brep";
std::cerr << "Cannot find the .g extension, writing to: "
<< newname << std::endl;
} else
newname.replace(start,newname.length(),".brep");
solid.SaveBRep(newname.c_str());
//solid.Dump(cout);
}
/*
(C) 2009 Mark van Doesburg, Technolution B.V.
Distributed under GPL version 2
*/
#include "tprintf.h"
class Indent {
char *buffer;
public:
Indent(int i) { buffer=new char[i+1]; memset(buffer,' ',i); buffer[i]=0; }
~Indent() { delete buffer; }
operator const char*() { return buffer; }
};
std::ostream &operator <<(std::ostream &o,rt_comb_internal const &c)
{
o << " unsigned long magic " << c.magic << '\n';
o << " union tree * tree " << c.tree << '\n';
o << " char region_flag " << (int)c.region_flag << '\n';
o << " char is_fastgen " << (int)c.is_fastgen << '\n';
/* Begin GIFT compatability */
o << " long region_id " << c.region_id << '\n';
o << " long aircode " << c.aircode << '\n';
o << " long GIFTmater " << c.GIFTmater << '\n';
o << " long los " << c.los << '\n';
/* End GIFT compatability */
o << " char rgb_valid " << (int)c.rgb_valid << '\n';
o << " unsigned char rgb[3] " << (int)c.rgb[0] << ','
<< (int)c.rgb[1] << ',' << (int)c.rgb[2] << '\n';
o << " float temperature " << c.temperature << '\n';
//cout << " struct bu_vls shader " << c.shader << '\n';
//cout << " struct bu_vls material " << c.material << '\n';
o << " char inherit " << (int)c.inherit << '\n';
return o;
}
std::ostream &operator <<(std::ostream &o,point_t const &p)
{
for(int i=0;i<ELEMENTS_PER_POINT;i++) {
o<< (i? ',':'(') << p[i];
}
o<<')';
}
template <typename T>
std::ostream & operator<<(std::ostream &out, std::set<T> const &a)
{
std::copy(a.begin(),a.end(),std::ostream_iterator<T>(out," "));
return out;
}
std::ostream &operator <<(std::ostream &o,union tree &p)
{
if(p.tr_a.magic!=RT_TREE_MAGIC)
return o << "INVALID";
switch(p.tr_op) {
case OP_SOLID: return o << "OP_SOLID";
case OP_UNION: return o << "OP_UNION";
case OP_INTERSECT: return o << "OP_INTERSECT";
case OP_SUBTRACT: return o << "OP_SUBTRACT";
case OP_XOR: return o << "OP_XOR";
case OP_REGION: return o << "OP_REGION";
case OP_NOP: return o << "OP_NOP";
case OP_NOT: return o << "OP_NOT";
case OP_GUARD: return o << "OP_GUARD";
case OP_XNOP: return o << "OP_XNOP";
case OP_NMG_TESS: return o << "OP_NMG_TESS";
case OP_DB_LEAF: return o << "OP_DB_LEAF";
case OP_FREE: return o << "OP_FREE";
default: return o << "UNKNOWN";
}
}
std::ostream &operator <<(std::ostream &o,union tree *p)
{
switch(p->tr_op) {
case OP_DB_LEAF:
case OP_SOLID: return o << p->tr_l.tl_name;
case OP_UNION: return o << p->tr_b.tb_left << " u " << p->tr_b.tb_right;
case OP_INTERSECT:return o << p->tr_b.tb_left << " + " << p->tr_b.tb_right;
case OP_SUBTRACT: return o << p->tr_b.tb_left << " - " << p->tr_b.tb_right;
default: return o << *p;
}
}
This diff is collapsed.
#ifndef TPRINTF_H_INCLUDED
#define TPRINTF_H_INCLUDED
#include <stdarg.h>
#include <stdio.h>
class tprintf {
char *buffer;
public:
tprintf(const char *fmt, ...);
~tprintf() { delete buffer; }
operator const char* () const { return buffer; }
};
inline tprintf::tprintf(const char *fmt, ...)
{
va_list ap;
int size=100;
for(;;) {
buffer=new char[size];
va_start(ap,fmt);
int new_size=vsnprintf(buffer,size,fmt,ap);
va_end(ap);
if(new_size<size)
break;
size=new_size+1;
delete buffer;
}
}
#endif // TPRINTF_H_INCLUDED
////////////////////////////////////////////////////////////////////////////////////////////////////
// gmsh2_2gid.c routine to convert gmsh format 2 mesh files into gid mesh file for EBEM programme //
// writes out all the nodes but only writes out the triangular 3 node elements. //
// mark smith 2008 piedycat@tiscali.co.uk //
////////////////////////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINE 128
#define MaxNodes 32 // maximum number of nodes per element
#define version "gmsh2_2gid.exe ver 1.00 Oct 2008 Mark Smith\n"
#define debug 0
void jumpline (FILE *stream); //skip a line
FILE *fpGid,*fpGmsh;
int main(int argc, char *argv[])
{
char buffer[MAXLINE],temp[64];
long ELEMENTS,NODES,i,N,k=1; // number of elements and nodes etc
long n[MaxNodes];
int elem_type,n_tags,n_nodes=0,tag_1,tag_2,tag_3,j;
double x,y,z; //nodal coordinates
printf(version);
if(argc<2)
{
printf("Gmesh format 2 .msh file to Gid mesh .dat file conversion routine\n");
printf("writes out all the nodes but only writes out the triangular 3 node elements.\n");
printf("Usage: gmsh2_2gid.exe in_filename out_filename .\n");
exit(0);
}
if((fpGmsh=fopen(argv[1],"r"))==NULL)
{
printf("can't open input gmsh mesh .msh file\n");
exit(1);
}
if((fpGid=fopen(argv[2],"w"))==NULL)
{
printf("can't open output Gid mesh .dat file\n");
exit(1);
}
strcpy(temp,"$MeshFormat");
fgets(buffer, MAXLINE, fpGmsh);
if(!strstr(buffer,temp))
{
printf("input file not correct type!\n");
exit(0);
}
jumpline(fpGmsh); //jump over 2 0 8
jumpline(fpGmsh); //jump over $EndMeshFormat
jumpline(fpGmsh); //jump over $Nodes
fscanf(fpGmsh,"%ld ",&NODES); //read in the number of nodes
printf("number of NODES=%ld\n",NODES);
fprintf(fpGid,"MESH dimension 3 ElemType Triangle Nnode 3\nCoordinates\n"); // write out gid header
for(i=0;i<NODES;i++)
{
fscanf(fpGmsh,"%ld %lg %lg %lg ",&N,&x,&y,&z);
fprintf(fpGid,"%6ld %15.6e %15.6e %15.6e\n",N,x,y,z);
}
fprintf(fpGid,"end coordinates\n\nElements\n");
jumpline(fpGmsh); //jump over $EndNodes
jumpline(fpGmsh); //jump over $Elements
fscanf(fpGmsh,"%ld ",&ELEMENTS); //read in the number of elements
printf("number of ELEMENTS=%ld\n",ELEMENTS);
for(i=0;i<ELEMENTS;i++)
{
//elm-number elm-type number-of-tags < tag > ... node-number-list
fscanf(fpGmsh,"%ld %d %d ",&N,&elem_type,&n_tags);
switch(elem_type)
{
case 1:n_nodes=2;break; //2-node line.
case 2:n_nodes=3;break; //3-node triangle.
case 3:n_nodes=4;break; //4-node quadrangle.
case 4:n_nodes=4;break; //4-node tetrahedron.
case 5:n_nodes=8;break; //8-node hexahedron.
case 6:n_nodes=6;break; //6-node prism.
case 7:n_nodes=5;break; //5-node pyramid.
case 8:n_nodes=3;break; //3-node second order line (2 nodes associated with the vertices and 1 with the edge).
case 9:n_nodes=6;break; //6-node second order triangle (3 nodes associated with the vertices and 3 with the edges).
case 10:n_nodes=9;break; //9-node second order quadrangle (4 nodes associated with the vertices, 4 with the edges and 1 with the face).
case 11:n_nodes=10;break; //10-node second order tetrahedron (4 nodes associated with the vertices and 6 with the edges).
case 12:n_nodes=27;break; //27-node second order hexahedron (8 nodes associated with the vertices, 12 with the edges, 6 with the faces and 1 with the volume).
case 13:n_nodes=18;break; //18-node second order prism (6 nodes associated with the vertices, 9 with the edges and 3 with the quadrangular faces).
case 14:n_nodes=14;break; //14-node second order pyramid (5 nodes associated with the vertices, 8 with the edges and 1 with the quadrangular face).
case 15:n_nodes=1;break; //1-node point.
case 16:n_nodes=8;break; //8-node second order quadrangle (4 nodes associated with the vertices and 4 with the edges).
case 17:n_nodes=20;break; //20-node second order hexahedron (8 nodes associated with the vertices and 12 with the edges).
case 18:n_nodes=15;break; //15-node second order prism (6 nodes associated with the vertices and 9 with the edges).
}
fscanf(fpGmsh,"%d %d %d ",&tag_1,&tag_2,&tag_3);
// tag_1= the number of the physical entity to which the element belongs
// tag_2= the number of the elementary geometrical entity to which the element belongs
// tag_3= the number of a mesh partition to which the element belongs
for(j=0;j<n_nodes;j++)
{
fscanf(fpGmsh,"%ld ",&n[j]);
}
if(n_nodes==3) //only write out the 3 node triangular elements
{
fprintf(fpGid," %6ld %6ld %6ld %6ld %4d\n",k,n[0],n[1],n[2],tag_1);
k++; //keep a count of the elements written & renumber starting @ 1
}
if(debug)printf("%ld %d %d %d %d %d\n",N,elem_type,n_nodes,tag_1,tag_2,tag_3);
}
fprintf(fpGid,"end elements\n");
fclose(fpGmsh); // close all the files
fclose(fpGid);
printf("Finished!!");
return 0;
}
void jumpline (FILE *stream) //skip a line
{
char buffer[MAXLINE];
fgets(buffer, MAXLINE, stream);
if(debug)printf("buffer=%s\n",buffer);
}
Code posted by "Billy" on:
http://www.cfd-online.com/Forums/openfoam-meshing-opensource/61973-generating-unstructured-grids-stl-files.html
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment