Commit 5070256b authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

OpenVDB export enabled. Control variables correctly appled during voxel export.

parent e71f48dd
......@@ -1109,7 +1109,7 @@ void CartesianOutputVoxelSlice (unsigned char * pcData, int nResolution, int nCh
fZFunc = ApproximateOperation (psFuncData->psFunction);
if ((fZFunc < fZSlice) && ((psFuncData->boMaterialFill == TRUE) || (fZFunc > (fZSlice - psFuncData->fMaterialThickness)))) {
if ((fZSlice < fZFunc) && ((psFuncData->boMaterialFill == TRUE) || (fZSlice > (fZFunc - psFuncData->fMaterialThickness)))) {
ucFill = 255u;
}
else {
......
......@@ -104,6 +104,8 @@ bool ExportStartSVX (LongPollPersist * psLongPollData, void * psData) {
psExportSVXData->nSlice = 0;
AssignControlVarsToFunctionList (psExportSVXData->psVisData);
// Check whether the file exists and delete it if it does
nResult = access (psExportSVXData->szFilename->str, F_OK);
if (nResult == 0) {
......
......@@ -29,6 +29,7 @@
// Structures and enumerations
struct _ExportVDBPersist {
GString * szFilename;
OVDBCPersist * psOVDBCData;
int nResolution;
int nSlice;
......@@ -49,7 +50,8 @@ ExportVDBPersist * NewExportVDBPersist (char const * szFilename, int nResolution
psExportVDBData = g_new0 (ExportVDBPersist, 1);
psExportVDBData->psOVDBCData = NewOVDBCPersist (szFilename);
psExportVDBData->szFilename = g_string_new (szFilename);
psExportVDBData->psOVDBCData = NewOVDBCPersist ();
psExportVDBData->nResolution = nResolution;
psExportVDBData->nSlice = 0;
psExportVDBData->psVisData = psVisData;
......@@ -58,6 +60,8 @@ ExportVDBPersist * NewExportVDBPersist (char const * szFilename, int nResolution
}
void DeleteExportVDBPersist (ExportVDBPersist * psExportVDBData) {
g_string_free (psExportVDBData->szFilename, TRUE);
if (psExportVDBData->psOVDBCData) {
DeleteOVDBCPersist (psExportVDBData->psOVDBCData);
psExportVDBData->psOVDBCData = NULL;
......@@ -72,11 +76,13 @@ bool ExportStartVDB (LongPollPersist * psLongPollData, void * psData) {
boSuccess = TRUE;
LongPollSetProgress (0.0f, psLongPollData);
LongPollSetActivityMain ("Exporting VDB voxel model", psLongPollData);
LongPollSetActivityMain ("Exporting OpenVDB voxel model", psLongPollData);
LongPollSetActivitySub (psLongPollData, "Initialising");
psExportVDBData->nSlice = 0;
AssignControlVarsToFunctionList (psExportVDBData->psVisData);
return boSuccess;
}
......@@ -128,7 +134,7 @@ bool ExportStepVDB (LongPollPersist * psLongPollData, void * psData) {
for (nX = 0; nX < psExportVDBData->nResolution; nX++) {
for (nY = 0; nY < psExportVDBData->nResolution; nY++) {
if (pcData[(((nX + (nY * psExportVDBData->nResolution)) * nChannels) + nChannel)] != 0) {
SetVector3 (vPos, nX, psExportVDBData->nResolution - psExportVDBData->nSlice, nY)
SetVector3 (vPos, nX, psExportVDBData->nSlice, nY)
SetGridValueOVDBC (& vPos, psExportVDBData->psOVDBCData);
}
}
......@@ -157,6 +163,8 @@ bool ExportFinishVDB (LongPollPersist * psLongPollData, void * psData) {
boSuccess = TRUE;
LongPollSetProgress (1.0f, psLongPollData);
OutputGrid (psExportVDBData->szFilename->str, psExportVDBData->psOVDBCData);
DeleteExportVDBPersist (psExportVDBData);
return boSuccess;
......
......@@ -30,7 +30,6 @@ using namespace std;
struct _OVDBCPersist {
openvdb::FloatGrid::Ptr psGrid;
GString * szFilename;
openvdb::FloatGrid::Accessor sAccessor;
};
......@@ -45,14 +44,13 @@ struct _OVDBCPersist {
extern "C" {
OVDBCPersist * NewOVDBCPersist (char const * szFilename) {
OVDBCPersist * NewOVDBCPersist () {
OVDBCPersist * psOVDBCData;
psOVDBCData = g_new0 (OVDBCPersist, 1);
openvdb::initialize ();
psOVDBCData->psGrid = openvdb::FloatGrid::create (2.0);
psOVDBCData->szFilename = g_string_new (szFilename);
psOVDBCData->sAccessor = psOVDBCData->psGrid->getAccessor();
......@@ -60,23 +58,24 @@ OVDBCPersist * NewOVDBCPersist (char const * szFilename) {
}
void DeleteOVDBCPersist (OVDBCPersist * psOVDBCData) {
g_free (psOVDBCData);
}
void OutputGrid (char const * const szFilename, OVDBCPersist * psOVDBCData) {
psOVDBCData->psGrid->setTransform (openvdb::math::Transform::createLinearTransform (0.5));
psOVDBCData->psGrid->setGridClass (openvdb::GRID_FOG_VOLUME);
psOVDBCData->psGrid->setName ("LevelSetSVX");
openvdb::io::File file (psOVDBCData->szFilename->str);
openvdb::GridPtrVec psGrids;
psGrids.push_back (psOVDBCData->psGrid);
psOVDBCData->psGrid->setName ("LevelSetFuncty");
//psOVDBCData->psGrid->pruneGrid();
openvdb::io::File file (szFilename);
openvdb::GridPtrVec vGrids;
vGrids.push_back (psOVDBCData->psGrid);
//openvdb::tools::sdfToFogVolume<openvdb::FloatGrid>(grid.operator*());
file.write (psGrids);
file.write (vGrids);
file.close ();
if (psOVDBCData->szFilename) {
g_string_free (psOVDBCData->szFilename, TRUE);
}
g_free (psOVDBCData);
// Destroy the vector and its contents
vGrids.clear();
}
void SetGridValueOVDBC (Vector3 const * const pvPos, OVDBCPersist * psOVDBCData) {
......
......@@ -33,9 +33,10 @@ typedef struct _OVDBCPersist OVDBCPersist;
///////////////////////////////////////////////////////////////////
// Function definitions
OVDBCPersist * NewOVDBCPersist (char const * szFilename);
OVDBCPersist * NewOVDBCPersist ();
void DeleteOVDBCPersist (OVDBCPersist * psOVDBCData);
void OutputGrid (char const * const szFilename, OVDBCPersist * psOVDBCData);
void SetGridValueOVDBC (Vector3 const * const pvPos, OVDBCPersist * psOVDBCData);
#endif /* OVDBC_H */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment