closes https://github.com/assimp/assimp/issues/842: experimental suppor for ascii stl pointcloud export.

pull/1935/head
Kim Kulling 2018-05-01 09:06:22 +02:00
parent 410e9d4b3f
commit 9f835ea843
6 changed files with 52 additions and 18 deletions

View File

@ -54,14 +54,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/ByteSwapper.h> #include <assimp/ByteSwapper.h>
using namespace Assimp; using namespace Assimp;
namespace Assimp { namespace Assimp {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to Stereolithograpy. Prototyped and registered in Exporter.cpp // Worker function for exporting a scene to Stereolithograpy. Prototyped and registered in Exporter.cpp
void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/) void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties )
{ {
bool exportPointClouds = pProperties->GetPropertyBool(AI_CONFIG_EXPORT_POINT_CLOUDS);
// invoke the exporter // invoke the exporter
STLExporter exporter(pFile, pScene); STLExporter exporter(pFile, pScene, exportPointClouds );
if (exporter.mOutput.fail()) { if (exporter.mOutput.fail()) {
throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile)); throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile));
@ -75,10 +78,12 @@ void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1); outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
} }
void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/) void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties )
{ {
bool exportPointClouds = pProperties->GetPropertyBool(AI_CONFIG_EXPORT_POINT_CLOUDS);
// invoke the exporter // invoke the exporter
STLExporter exporter(pFile, pScene, true); STLExporter exporter(pFile, pScene, exportPointClouds, true);
if (exporter.mOutput.fail()) { if (exporter.mOutput.fail()) {
throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile)); throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile));
@ -97,7 +102,7 @@ void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, const aiScene*
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
STLExporter :: STLExporter(const char* _filename, const aiScene* pScene, bool binary) STLExporter::STLExporter(const char* _filename, const aiScene* pScene, bool exportPointClouds, bool binary)
: filename(_filename) : filename(_filename)
, endl("\n") , endl("\n")
{ {
@ -118,12 +123,37 @@ STLExporter :: STLExporter(const char* _filename, const aiScene* pScene, bool bi
} }
AI_SWAP4(meshnum); AI_SWAP4(meshnum);
mOutput.write((char *)&meshnum, 4); mOutput.write((char *)&meshnum, 4);
if (exportPointClouds) {
}
for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) { for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
WriteMeshBinary(pScene->mMeshes[i]); WriteMeshBinary(pScene->mMeshes[i]);
} }
} else { } else {
const std::string& name = "AssimpScene"; const std::string& name = "AssimpScene";
// Exporting only point clouds
if (exportPointClouds) {
mOutput << "solid " << name << endl;
aiVector3D nor;
mOutput << " facet normal " << nor.x << " " << nor.y << " " << nor.z << endl;
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
aiMesh *mesh = pScene->mMeshes[i];
if (mesh->mNormals) {
for (unsigned int a = 0; a < mesh->mNumVertices; ++a) {
const aiVector3D& v = mesh->mVertices[a];
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
}
}
}
mOutput << "endsolid " << name << endl;
return;
}
mOutput << "solid " << name << endl; mOutput << "solid " << name << endl;
for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) { for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
WriteMesh(pScene->mMeshes[i]); WriteMesh(pScene->mMeshes[i]);

View File

@ -62,9 +62,7 @@ class STLExporter
{ {
public: public:
/// Constructor for a specific scene to export /// Constructor for a specific scene to export
STLExporter(const char* filename, const aiScene* pScene, bool binary = false); STLExporter(const char* filename, const aiScene* pScene, bool exportPOintClouds, bool binary = false);
public:
/// public stringstreams to write all output into /// public stringstreams to write all output into
std::ostringstream mOutput; std::ostringstream mOutput;

View File

@ -75,4 +75,5 @@ bool CPUSupportsSSE2() {
#endif #endif
} }
} // Namespace Assimp } // Namespace Assimp

View File

@ -115,12 +115,10 @@ public:
} }
}; };
public: public:
Exporter(); Exporter();
~Exporter(); ~Exporter();
public:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Supplies a custom IO handler to the exporter to use to open and /** Supplies a custom IO handler to the exporter to use to open and
* access files. * access files.
@ -172,8 +170,10 @@ public:
* Any IO handlers set via #SetIOHandler are ignored here. * Any IO handlers set via #SetIOHandler are ignored here.
* @note Use aiCopyScene() to get a modifiable copy of a previously * @note Use aiCopyScene() to get a modifiable copy of a previously
* imported scene. */ * imported scene. */
const aiExportDataBlob* ExportToBlob(const aiScene* pScene, const char* pFormatId, unsigned int pPreprocessing = 0u, const ExportProperties* = NULL); const aiExportDataBlob* ExportToBlob(const aiScene* pScene, const char* pFormatId,
const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const std::string& pFormatId, unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = NULL); unsigned int pPreprocessing = 0u, const ExportProperties* = nullptr);
const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const std::string& pFormatId,
unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Convenience function to export directly to a file. Use /** Convenience function to export directly to a file. Use
@ -208,8 +208,10 @@ public:
* @return AI_SUCCESS if everything was fine. * @return AI_SUCCESS if everything was fine.
* @note Use aiCopyScene() to get a modifiable copy of a previously * @note Use aiCopyScene() to get a modifiable copy of a previously
* imported scene.*/ * imported scene.*/
aiReturn Export( const aiScene* pScene, const char* pFormatId, const char* pPath, unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = NULL); aiReturn Export( const aiScene* pScene, const char* pFormatId, const char* pPath,
aiReturn Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath, unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = NULL); unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr);
aiReturn Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath,
unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Returns an error description of an error that occurred in #Export /** Returns an error description of an error that occurred in #Export

View File

@ -85,7 +85,6 @@ struct aiExportFormatDesc
*/ */
ASSIMP_API size_t aiGetExportFormatCount(void); ASSIMP_API size_t aiGetExportFormatCount(void);
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Returns a description of the nth export file format. Use #aiGetExportFormatCount() /** Returns a description of the nth export file format. Use #aiGetExportFormatCount()
* to learn how many export formats are supported. The description must be released by * to learn how many export formats are supported. The description must be released by
@ -186,7 +185,6 @@ ASSIMP_API aiReturn aiExportSceneEx( const C_STRUCT aiScene* pScene,
C_STRUCT aiFileIO* pIO, C_STRUCT aiFileIO* pIO,
unsigned int pPreprocessing ); unsigned int pPreprocessing );
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Describes a blob of exported scene data. Use #aiExportSceneToBlob() to create a blob containing an /** Describes a blob of exported scene data. Use #aiExportSceneToBlob() to create a blob containing an
* exported scene. The memory referred by this structure is owned by Assimp. * exported scene. The memory referred by this structure is owned by Assimp.
@ -245,8 +243,8 @@ private:
* @param pPreprocessing Please see the documentation for #aiExportScene * @param pPreprocessing Please see the documentation for #aiExportScene
* @return the exported data or NULL in case of error * @return the exported data or NULL in case of error
*/ */
ASSIMP_API const C_STRUCT aiExportDataBlob* aiExportSceneToBlob( const C_STRUCT aiScene* pScene, const char* pFormatId, unsigned int pPreprocessing ); ASSIMP_API const C_STRUCT aiExportDataBlob* aiExportSceneToBlob( const C_STRUCT aiScene* pScene, const char* pFormatId,
unsigned int pPreprocessing );
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Releases the memory associated with the given exported data. Use this function to free a data blob /** Releases the memory associated with the given exported data. Use this function to free a data blob

View File

@ -953,6 +953,11 @@ enum aiComponent
#define AI_CONFIG_EXPORT_XFILE_64BIT "EXPORT_XFILE_64BIT" #define AI_CONFIG_EXPORT_XFILE_64BIT "EXPORT_XFILE_64BIT"
/**
*
*/
#define AI_CONFIG_EXPORT_POINT_CLOUDS "EXPORT_POINT_CLOUDS"
/** /**
* @brief Specifies a gobal key factor for scale, float value * @brief Specifies a gobal key factor for scale, float value
*/ */