Commit e71f48dd authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Initial OpenVDB export code.

parent 4808a327
......@@ -339,7 +339,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Export as a voxel volume in OpenVDB format.</property>
<property name="label" translatable="yes">OpenVDB (VDB)</property>
<property name="label" translatable="yes">OpenVDB (VDB)...</property>
<property name="use_underline">True</property>
</object>
</child>
......
......@@ -243,6 +243,7 @@ bool ExportStepSVX (LongPollPersist * psLongPollData, void * psData) {
// We're done with the PNG data, so we can close the stream
recclose (hFile);
//printf ("Output slice %d out of %d.\n", (psExportSVXData->nSlice + 1), psExportSVXData->nResolution);
free (pcData);
}
else {
printf ("Couldn't allocate memory for voxel slice.\n");
......
This diff is collapsed.
......@@ -37,8 +37,6 @@ typedef struct _ExportVDBPersist ExportVDBPersist;
ExportVDBPersist * NewExportVDBPersist (char const * szFilename, int nResolution, VisPersist * psVisData);
void DeleteExportVDBPersist (ExportVDBPersist * psExportVDBData);
void FilledCuboidSliceVDB (unsigned char * pcData, int nResolution, int nChannels, Vector3 * avCorners, float fZSlice);
bool ExportStartVDB (LongPollPersist * psLongPollData, void * psData);
bool ExportStepVDB (LongPollPersist * psLongPollData, void * psData);
bool ExportFinishVDB (LongPollPersist * psLongPollData, void * psData);
......
......@@ -34,6 +34,7 @@
#include "exportply.h"
#include "exportstl.h"
#include "exportsvx.h"
#include "exportvdb.h"
#include "exportbitmap.h"
#include "controlvar.h"
#include "longpoll.h"
......@@ -155,6 +156,7 @@ static gboolean SaveFilePress (GtkWidget * psWidget, gpointer psData);
static gboolean ExportFilePLYPress (GtkWidget * psWidget, gpointer psData);
static gboolean ExportFileSTLPress (GtkWidget * psWidget, gpointer psData);
static gboolean ExportFileSVXPress (GtkWidget * psWidget, gpointer psData);
static gboolean ExportFileVDBPress (GtkWidget * psWidget, gpointer psData);
static gboolean ExportAnimFilePLYPress (GtkWidget * psWidget, gpointer psData);
static gboolean ExportAnimFileSTLPress (GtkWidget * psWidget, gpointer psData);
static gboolean ExportAnimFilePNGPress (GtkWidget * psWidget, gpointer psData);
......@@ -226,10 +228,12 @@ FunctyPersist * NewFunctyPersist (void) {
psFunctyData->boExportedModelPLY = FALSE;
psFunctyData->boExportedModelSTL = FALSE;
psFunctyData->boExportedModelSVX = FALSE;
psFunctyData->boExportedModelVDB = FALSE;
psFunctyData->boExportedAnim = FALSE;
psFunctyData->szExportModelNamePLY = g_string_new (DEFAULT_EXPORTMODELNAME ".ply");
psFunctyData->szExportModelNameSTL = g_string_new (DEFAULT_EXPORTMODELNAME ".stl");
psFunctyData->szExportModelNameSVX = g_string_new (DEFAULT_EXPORTMODELNAME ".svx");
psFunctyData->szExportModelNameVDB = g_string_new (DEFAULT_EXPORTMODELNAME ".vdb");
psFunctyData->szExportAnimName = g_string_new (DEFAULT_EXPORTANIMNAME);
psFunctyData->boBinary = TRUE;
psFunctyData->fExportMultiplier = 1.0;
......@@ -279,6 +283,9 @@ void DeleteFunctyPersist (FunctyPersist * psFunctyData) {
if (psFunctyData->szExportModelNameSVX) {
g_string_free (psFunctyData->szExportModelNameSVX, TRUE);
}
if (psFunctyData->szExportModelNameVDB) {
g_string_free (psFunctyData->szExportModelNameVDB, TRUE);
}
if (psFunctyData->szExportAnimName) {
g_string_free (psFunctyData->szExportAnimName, TRUE);
}
......@@ -3281,6 +3288,104 @@ static gboolean ExportFileSVXPress (GtkWidget * psWidget, gpointer psData) {
return TRUE;
}
static gboolean ExportFileVDBPress (GtkWidget * psWidget, gpointer psData) {
FunctyPersist * psFunctyData = (FunctyPersist * )psData;
GtkWidget * psDialogue;
GtkWindow * psParent;
char * szFilename;
char * szFolder;
bool boExported;
GtkFileFilter * psFilterVDB;
GtkFileFilter * psFilterAll;
GtkWidget * psVoxelResolution;
GtkWidget * psOptionsFile;
GtkWidget * psWidgetAdd;
GtkAdjustment * psAdjustment;
ExportVDBPersist * psExportVDBData;
psFilterVDB = gtk_file_filter_new ();
gtk_file_filter_add_pattern (psFilterVDB, "*.vdb");
gtk_file_filter_add_mime_type (psFilterVDB, "text/vdb");
gtk_file_filter_add_mime_type (psFilterVDB, "application/vdb");
gtk_file_filter_set_name (psFilterVDB, "OpenVDB Format");
psFilterAll = gtk_file_filter_new ();
gtk_file_filter_add_pattern (psFilterAll, "*");
gtk_file_filter_set_name (psFilterAll, "All Files");
psParent = GTK_WINDOW (GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "MainWindow")));
psDialogue = gtk_file_chooser_dialog_new ("Export Model in OpenVDB", psParent, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (psDialogue), TRUE);
g_object_set (G_OBJECT (psDialogue), "local-only", FALSE, NULL);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (psDialogue), psFilterVDB);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (psDialogue), psFilterAll);
PauseAnimationModal (TRUE, psFunctyData);
if (psFunctyData->boFolderSet) {
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (psDialogue), psFunctyData->szFolder->str);
}
else {
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (psDialogue), g_get_home_dir ());
}
if (!psFunctyData->boExportedModelVDB) {
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (psDialogue), DEFAULT_EXPORTMODELNAME ".vdb");
}
else {
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (psDialogue), psFunctyData->szExportModelNameVDB->str);
}
psOptionsFile = gtk_hbox_new (FALSE, 8);
gtk_widget_show (psOptionsFile);
// Add file attribute widgets
psWidgetAdd = gtk_label_new ("Resolution");
gtk_label_set_justify (GTK_LABEL (psWidgetAdd), GTK_JUSTIFY_RIGHT);
gtk_widget_show (psWidgetAdd);
gtk_box_pack_start (GTK_BOX (psOptionsFile), psWidgetAdd, FALSE, TRUE, 0);
psAdjustment = GTK_ADJUSTMENT (gtk_adjustment_new (psFunctyData->nVoxelResolution, 1.0, 4096.0, 1.0, 10.0, 0.0));
psVoxelResolution = gtk_spin_button_new (psAdjustment, 1, 0);
gtk_widget_show (psVoxelResolution);
gtk_box_pack_start (GTK_BOX (psOptionsFile), psVoxelResolution, FALSE, TRUE, 0);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (psDialogue), psOptionsFile);
if (gtk_dialog_run (GTK_DIALOG (psDialogue)) == GTK_RESPONSE_ACCEPT) {
psFunctyData->nVoxelResolution = gtk_spin_button_get_value (GTK_SPIN_BUTTON (psVoxelResolution));
szFilename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (psDialogue));
// Actually perform the model export
gtk_widget_hide (psDialogue);
psExportVDBData = NewExportVDBPersist (szFilename, psFunctyData->nVoxelResolution, psFunctyData->psVisData);
boExported = LongPoll (psFunctyData->psXML, psExportVDBData, ExportStartVDB, ExportStepVDB, ExportFinishVDB, ExportCancelVDB);
if (boExported) {
g_string_assign (psFunctyData->szExportModelNameVDB, szFilename);
szFolder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (psDialogue));
psFunctyData->boFolderSet = (szFolder != NULL);
if (szFolder) {
g_string_assign (psFunctyData->szFolder, szFolder);
g_free (szFolder);
szFolder = NULL;
}
}
psFunctyData->boExportedModelVDB = boExported;
g_free (szFilename);
szFilename = NULL;
}
gtk_widget_destroy (psDialogue);
PauseAnimationModal (FALSE, psFunctyData);
return TRUE;
}
static gboolean ExportAnimFilePLYPress (GtkWidget * psWidget, gpointer psData) {
FunctyPersist * psFunctyData = (FunctyPersist * )psData;
......@@ -4198,6 +4303,8 @@ int main (int argc, char *argv[]) {
g_signal_connect (psWidget, "activate", G_CALLBACK (ExportFileSTLPress), (gpointer)psFunctyData);
psWidget = GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "MenuExportModelSVX"));
g_signal_connect (psWidget, "activate", G_CALLBACK (ExportFileSVXPress), (gpointer)psFunctyData);
psWidget = GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "MenuExportModelVDB"));
g_signal_connect (psWidget, "activate", G_CALLBACK (ExportFileVDBPress), (gpointer)psFunctyData);
psWidget = GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "MenuExportBitmapPNG"));
g_signal_connect (psWidget, "activate", G_CALLBACK (ExportBitmapPress), (gpointer)psFunctyData);
......
......@@ -55,10 +55,12 @@ struct _FunctyPersist {
bool boExportedModelPLY;
bool boExportedModelSTL;
bool boExportedModelSVX;
bool boExportedModelVDB;
bool boExportedAnim;
GString * szExportModelNamePLY;
GString * szExportModelNameSTL;
GString * szExportModelNameSVX;
GString * szExportModelNameVDB;
GString * szExportAnimName;
bool boBinary;
double fExportMultiplier;
......
///////////////////////////////////////////////////////////////////
// Enzyme
// 3D Functy/Dandelion/programming game
//
// Provides access to the LEAP API in C (via the C++ library)
// Functy
// 3D graph drawing utility
//
// David Llewellyn-Jones
// http://www.flypig.co.uk
//
// December 2013
// Summer 2015
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
......@@ -31,7 +30,7 @@ using namespace std;
struct _OVDBCPersist {
openvdb::FloatGrid::Ptr psGrid;
GString * szOutfile;
GString * szFilename;
openvdb::FloatGrid::Accessor sAccessor;
};
......@@ -46,15 +45,14 @@ struct _OVDBCPersist {
extern "C" {
OVDBCPersist * NewOVDBCPersist (char const * szOutfile) {
OVDBCPersist * NewOVDBCPersist (char const * szFilename) {
OVDBCPersist * psOVDBCData;
psOVDBCData = g_new0 (OVDBCPersist, 1);
openvdb::initialize ();
psOVDBCData->psGrid = openvdb::FloatGrid::create (2.0);
g_string_assign (psOVDBCData->szOutfile, szOutfile);
psOVDBCData->szFilename = g_string_new (szFilename);
psOVDBCData->sAccessor = psOVDBCData->psGrid->getAccessor();
......@@ -65,7 +63,7 @@ void DeleteOVDBCPersist (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->szOutfile->str);
openvdb::io::File file (psOVDBCData->szFilename->str);
openvdb::GridPtrVec psGrids;
psGrids.push_back (psOVDBCData->psGrid);
......@@ -74,14 +72,14 @@ void DeleteOVDBCPersist (OVDBCPersist * psOVDBCData) {
file.write (psGrids);
file.close ();
if (psOVDBCData->szOutfile) {
g_string_free (psOVDBCData->szOutfile, TRUE);
if (psOVDBCData->szFilename) {
g_string_free (psOVDBCData->szFilename, TRUE);
}
g_free (psOVDBCData);
}
void SetGridValue (Vector3 const * const pvPos, OVDBCPersist * psOVDBCData) {
void SetGridValueOVDBC (Vector3 const * const pvPos, OVDBCPersist * psOVDBCData) {
openvdb::Coord sCoord;
sCoord[0] = pvPos->fX;
sCoord[1] = pvPos->fY;
......@@ -90,12 +88,5 @@ void SetGridValue (Vector3 const * const pvPos, OVDBCPersist * psOVDBCData) {
psOVDBCData->sAccessor.setValue (sCoord, 1.0);
}
} /* extern "C" */
///////////////////////////////////////////////////////////////////
// Enzyme
// 3D Functy/Dandelion/programming game
//
// Provides access to the LEAP API in C (via the C++ library)
// Functy
// 3D graph drawing utility
//
// David Llewellyn-Jones
// http://www.flypig.co.uk
//
// December 2013
// Summer 2015
///////////////////////////////////////////////////////////////////
#ifndef OVDBC_H
......@@ -34,10 +33,10 @@ typedef struct _OVDBCPersist OVDBCPersist;
///////////////////////////////////////////////////////////////////
// Function definitions
OVDBCPersist * NewOVDBCPersist (char const * szOutfile);
OVDBCPersist * NewOVDBCPersist (char const * szFilename);
void DeleteOVDBCPersist (OVDBCPersist * psOVDBCData);
void SetGridValue (Vector3 const * const pvPos, 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