fix LoadGeometry in nglib (geom2d, stl)

This commit is contained in:
Joachim Schoeberl 2013-01-17 12:41:57 +00:00
parent 7f4d9f485b
commit 3d7092e8b3
4 changed files with 113 additions and 75 deletions

View File

@ -10,42 +10,24 @@ namespace netgen
{
extern DLL_HEADER NetgenGeometry * ng_geometry;
// extern DLL_HEADER NetgenGeometry * ng_geometry;
static VisualSceneGeometry2d vsgeom2d;
class SplineGeometryRegister : public GeometryRegister
class SplineGeometryVisRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const;
virtual NetgenGeometry * Load (string filename) const { return NULL; }
virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
};
NetgenGeometry * SplineGeometryRegister :: Load (string filename) const
VisualScene * SplineGeometryVisRegister :: GetVisualScene (const NetgenGeometry * geom) const
{
const char * cfilename = filename.c_str();
if (strcmp (&cfilename[strlen(cfilename)-4], "in2d") == 0)
{
PrintMessage (1, "Load 2D-Spline geometry file ", cfilename);
ifstream infile(cfilename);
SplineGeometry2d * hgeom = new SplineGeometry2d();
hgeom -> Load (cfilename);
return hgeom;
}
return NULL;
}
VisualScene * SplineGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const
{
SplineGeometry2d * geometry = dynamic_cast<SplineGeometry2d*> (ng_geometry);
const SplineGeometry2d * geometry = dynamic_cast<const SplineGeometry2d*> (geom);
if (geometry)
{
vsgeom2d.SetGeometry (geometry);
@ -67,6 +49,6 @@ extern "C" int Ng_geom2d_Init (Tcl_Interp * interp);
int Ng_geom2d_Init (Tcl_Interp * interp)
{
geometryregister.Append (new SplineGeometryRegister);
geometryregister.Append (new SplineGeometryVisRegister);
return TCL_OK;
}

View File

@ -945,4 +945,41 @@ namespace netgen
return * new Refinement2d (*this);
}
class SplineGeometryRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const;
};
NetgenGeometry * SplineGeometryRegister :: Load (string filename) const
{
const char * cfilename = filename.c_str();
if (strcmp (&cfilename[strlen(cfilename)-4], "in2d") == 0)
{
PrintMessage (1, "Load 2D-Spline geometry file ", cfilename);
ifstream infile(cfilename);
SplineGeometry2d * hgeom = new SplineGeometry2d();
hgeom -> Load (cfilename);
return hgeom;
}
return NULL;
}
class SplineGeoInit
{
public:
SplineGeoInit()
{
geometryregister.Append (new SplineGeometryRegister);
}
};
SplineGeoInit sginit;
}

View File

@ -3506,4 +3506,65 @@ void STLGeometry :: SmoothGeometry ()
SetPoint (i, pi);
}
}
class STLGeometryRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const;
};
NetgenGeometry * STLGeometryRegister :: Load (string filename) const
{
const char * cfilename = filename.c_str();
if (strcmp (&cfilename[strlen(cfilename)-3], "stl") == 0)
{
PrintMessage (1, "Load STL geometry file ", cfilename);
ifstream infile(cfilename);
STLGeometry * hgeom = STLGeometry :: Load (infile);
hgeom -> edgesfound = 0;
return hgeom;
}
else if (strcmp (&cfilename[strlen(cfilename)-4], "stlb") == 0)
{
PrintMessage (1, "Load STL binary geometry file ", cfilename);
ifstream infile(cfilename);
STLGeometry * hgeom = STLGeometry :: LoadBinary (infile);
hgeom -> edgesfound = 0;
return hgeom;
}
else if (strcmp (&cfilename[strlen(cfilename)-3], "nao") == 0)
{
PrintMessage (1, "Load naomi (F. Kickinger) geometry file ", cfilename);
ifstream infile(cfilename);
STLGeometry * hgeom = STLGeometry :: LoadNaomi (infile);
hgeom -> edgesfound = 0;
return hgeom;
}
return NULL;
}
class STLInit
{
public:
STLInit()
{
geometryregister.Append (new STLGeometryRegister);
}
};
STLInit stlinit;
}

View File

@ -31,10 +31,10 @@ namespace netgen
class STLGeometryRegister : public GeometryRegister
class STLGeometryVisRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const;
virtual NetgenGeometry * Load (string filename) const { return NULL; }
virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
virtual void SetParameters (Tcl_Interp * interp)
{
@ -103,7 +103,7 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
STLGeometryRegister reg;
STLGeometryVisRegister reg;
reg.SetParameters (interp);
return TCL_OK;
@ -406,48 +406,6 @@ namespace netgen
NetgenGeometry * STLGeometryRegister :: Load (string filename) const
{
const char * cfilename = filename.c_str();
if (strcmp (&cfilename[strlen(cfilename)-3], "stl") == 0)
{
PrintMessage (1, "Load STL geometry file ", cfilename);
ifstream infile(cfilename);
STLGeometry * hgeom = STLGeometry :: Load (infile);
hgeom -> edgesfound = 0;
return hgeom;
}
else if (strcmp (&cfilename[strlen(cfilename)-4], "stlb") == 0)
{
PrintMessage (1, "Load STL binary geometry file ", cfilename);
ifstream infile(cfilename);
STLGeometry * hgeom = STLGeometry :: LoadBinary (infile);
hgeom -> edgesfound = 0;
return hgeom;
}
else if (strcmp (&cfilename[strlen(cfilename)-3], "nao") == 0)
{
PrintMessage (1, "Load naomi (F. Kickinger) geometry file ", cfilename);
ifstream infile(cfilename);
STLGeometry * hgeom = STLGeometry :: LoadNaomi (infile);
hgeom -> edgesfound = 0;
return hgeom;
}
return NULL;
}
@ -581,12 +539,12 @@ namespace netgen
VisualScene * STLGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const
VisualScene * STLGeometryVisRegister :: GetVisualScene (const NetgenGeometry * geom) const
{
STLGeometry * geometry = dynamic_cast<STLGeometry*> (ng_geometry);
const STLGeometry * geometry = dynamic_cast<const STLGeometry*> (geom);
if (geometry)
{
vsstlmeshing.SetGeometry (geometry);
vsstlmeshing.SetGeometry (const_cast<STLGeometry*> (geometry));
return &vsstlmeshing;
}
return NULL;
@ -599,7 +557,7 @@ using namespace netgen;
extern "C" int Ng_stl_Init (Tcl_Interp * interp);
int Ng_stl_Init (Tcl_Interp * interp)
{
geometryregister.Append (new STLGeometryRegister);
geometryregister.Append (new STLGeometryVisRegister);
Tcl_CreateCommand (interp, "Ng_SetSTLParameters", Ng_SetSTLParameters,
(ClientData)NULL,