+ add overloaded methods of save() and load() to write and read from streams
This commit is contained in:
parent
9c7bc073e4
commit
91ba585ee0
|
@ -164,6 +164,32 @@ bool MeshInput::LoadAny(const char* FileName)
|
|||
}
|
||||
}
|
||||
|
||||
bool MeshInput::LoadFormat(std::istream &str, MeshIO::Format fmt)
|
||||
{
|
||||
switch (fmt) {
|
||||
case MeshIO::BMS:
|
||||
_rclMesh.Read(str);
|
||||
return true;
|
||||
case MeshIO::APLY:
|
||||
case MeshIO::PLY:
|
||||
return LoadPLY(str);
|
||||
case MeshIO::ASTL:
|
||||
return LoadAsciiSTL(str);
|
||||
case MeshIO::BSTL:
|
||||
return LoadBinarySTL(str);
|
||||
case MeshIO::OBJ:
|
||||
return LoadOBJ(str);
|
||||
case MeshIO::OFF:
|
||||
return LoadOFF(str);
|
||||
case MeshIO::IV:
|
||||
return LoadInventor(str);
|
||||
case MeshIO::NAS:
|
||||
return LoadNastran(str);
|
||||
default:
|
||||
throw Base::FileException("Not supported file format");
|
||||
}
|
||||
}
|
||||
|
||||
/** Loads an STL file either in binary or ASCII format.
|
||||
* Therefore the file header gets checked to decide if the file is binary or not.
|
||||
*/
|
||||
|
@ -1662,6 +1688,42 @@ bool MeshOutput::SaveAny(const char* FileName, MeshIO::Format format) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MeshOutput::SaveFormat(std::ostream &str, MeshIO::Format fmt) const
|
||||
{
|
||||
switch (fmt) {
|
||||
case MeshIO::BMS:
|
||||
_rclMesh.Write(str);
|
||||
return true;
|
||||
case MeshIO::ASTL:
|
||||
return SaveAsciiSTL(str);
|
||||
case MeshIO::BSTL:
|
||||
return SaveBinarySTL(str);
|
||||
case MeshIO::OBJ:
|
||||
return SaveOBJ(str);
|
||||
case MeshIO::OFF:
|
||||
return SaveOFF(str);
|
||||
case MeshIO::IV:
|
||||
return SaveInventor(str);
|
||||
case MeshIO::X3D:
|
||||
return SaveX3D(str);
|
||||
case MeshIO::VRML:
|
||||
return SaveVRML(str);
|
||||
case MeshIO::WRZ:
|
||||
// it's up to the client to create the needed stream
|
||||
return SaveVRML(str);
|
||||
case MeshIO::NAS:
|
||||
return SaveNastran(str);
|
||||
case MeshIO::PLY:
|
||||
return SaveBinaryPLY(str);
|
||||
case MeshIO::APLY:
|
||||
return SaveAsciiPLY(str);
|
||||
case MeshIO::PY:
|
||||
return SavePython(str);
|
||||
default:
|
||||
throw Base::FileException("Not supported file format");
|
||||
}
|
||||
}
|
||||
|
||||
/** Saves the mesh object into an ASCII file. */
|
||||
bool MeshOutput::SaveAsciiSTL (std::ostream &rstrOut) const
|
||||
{
|
||||
|
|
|
@ -84,6 +84,8 @@ public:
|
|||
|
||||
/// Loads the file, decided by extension
|
||||
bool LoadAny(const char* FileName);
|
||||
/// Loads from a stream and the given format
|
||||
bool LoadFormat(std::istream &str, MeshIO::Format fmt);
|
||||
/** Loads an STL file either in binary or ASCII format.
|
||||
* Therefore the file header gets checked to decide if the file is binary or not.
|
||||
*/
|
||||
|
@ -137,6 +139,8 @@ public:
|
|||
static void SetSTLHeaderData(const std::string&);
|
||||
/// Saves the file, decided by extension if not explicitly given
|
||||
bool SaveAny(const char* FileName, MeshIO::Format f=MeshIO::Undefined) const;
|
||||
/// Saves to a stream and the given format
|
||||
bool SaveFormat(std::ostream &str, MeshIO::Format fmt) const;
|
||||
|
||||
/** Saves the mesh object into an ASCII STL file. */
|
||||
bool SaveAsciiSTL (std::ostream &rstrOut) const;
|
||||
|
|
|
@ -344,9 +344,15 @@ void MeshObject::save(const char* file, MeshCore::MeshIO::Format f,
|
|||
aWriter.SaveAny(file, f);
|
||||
}
|
||||
|
||||
void MeshObject::save(std::ostream& out) const
|
||||
void MeshObject::save(std::ostream& str, MeshCore::MeshIO::Format f,
|
||||
const MeshCore::Material* mat,
|
||||
const char* objectname) const
|
||||
{
|
||||
_kernel.Write(out);
|
||||
MeshCore::MeshOutput aWriter(this->_kernel, mat);
|
||||
if (objectname)
|
||||
aWriter.SetObjectName(objectname);
|
||||
aWriter.Transform(this->_Mtrx);
|
||||
aWriter.SaveFormat(str, f);
|
||||
}
|
||||
|
||||
bool MeshObject::load(const char* file, MeshCore::Material* mat)
|
||||
|
@ -356,6 +362,23 @@ bool MeshObject::load(const char* file, MeshCore::Material* mat)
|
|||
if (!aReader.LoadAny(file))
|
||||
return false;
|
||||
|
||||
swapKernel(kernel);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MeshObject::load(std::istream& str, MeshCore::MeshIO::Format f, MeshCore::Material* mat)
|
||||
{
|
||||
MeshCore::MeshKernel kernel;
|
||||
MeshCore::MeshInput aReader(kernel, mat);
|
||||
if (!aReader.LoadFormat(str, f))
|
||||
return false;
|
||||
|
||||
swapKernel(kernel);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MeshObject::swapKernel(MeshCore::MeshKernel& kernel)
|
||||
{
|
||||
_kernel.Swap(kernel);
|
||||
// Some file formats define several objects per file (e.g. OBJ).
|
||||
// Now we mark each object as an own segment so that we can break
|
||||
|
@ -403,8 +426,11 @@ bool MeshObject::load(const char* file, MeshCore::Material* mat)
|
|||
Base::Console().Log("Check for defects in mesh data structure failed\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
void MeshObject::save(std::ostream& out) const
|
||||
{
|
||||
_kernel.Write(out);
|
||||
}
|
||||
|
||||
void MeshObject::load(std::istream& in)
|
||||
|
|
|
@ -155,8 +155,13 @@ public:
|
|||
void save(const char* file,MeshCore::MeshIO::Format f=MeshCore::MeshIO::Undefined,
|
||||
const MeshCore::Material* mat = 0,
|
||||
const char* objectname = 0) const;
|
||||
void save(std::ostream&) const;
|
||||
void save(std::ostream&,MeshCore::MeshIO::Format f,
|
||||
const MeshCore::Material* mat = 0,
|
||||
const char* objectname = 0) const;
|
||||
bool load(const char* file, MeshCore::Material* mat = 0);
|
||||
bool load(std::istream&, MeshCore::MeshIO::Format f, MeshCore::Material* mat = 0);
|
||||
// Save and load in internal format
|
||||
void save(std::ostream&) const;
|
||||
void load(std::istream&);
|
||||
//@}
|
||||
|
||||
|
@ -371,6 +376,7 @@ private:
|
|||
void deletedFacets(const std::vector<unsigned long>& remFacets);
|
||||
void updateMesh(const std::vector<unsigned long>&);
|
||||
void updateMesh();
|
||||
void swapKernel(MeshCore::MeshKernel& m);
|
||||
|
||||
private:
|
||||
Base::Matrix4D _Mtrx;
|
||||
|
|
Loading…
Reference in New Issue
Block a user