Skip to content

Commit

Permalink
Added Compression control on binary stream writer
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderoster committed Feb 21, 2024
1 parent 9748f76 commit b817e32
Show file tree
Hide file tree
Showing 35 changed files with 1,368 additions and 53 deletions.
37 changes: 36 additions & 1 deletion Autogenerated/Bindings/C/lib3mf.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,41 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getpath(Lib3MF_BinaryStream pBi
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getuuid(Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nUUIDBufferSize, Lib3MF_uint32* pUUIDNeededChars, char * pUUIDBuffer);

/**
* Sets the float compression mode to raw. All subsequent writes will adhere to this mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_disablediscretizedarraycompression(Lib3MF_BinaryStream pBinaryStream);

/**
* Sets the compression mode to a quantized array. All subsequent writes will adhere to this mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] dUnits - Unit factor to use for quantization.
* @param[in] ePredictionType - Prediction type to use for arrays.
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_enablediscretizedarraycompression(Lib3MF_BinaryStream pBinaryStream, Lib3MF_double dUnits, eLib3MFBinaryStreamPredictionType ePredictionType);

/**
* Enables LZMA mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] nLZMALevel - LZMA Level (0-9)
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_enablelzma(Lib3MF_BinaryStream pBinaryStream, Lib3MF_uint32 nLZMALevel);

/**
* Disables LZMA mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_disablelzma(Lib3MF_BinaryStream pBinaryStream);

/*************************************************************************************************************************
Class definition for Writer
**************************************************************************************************************************/
Expand Down Expand Up @@ -236,7 +271,7 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_setcontentencryptioncallback(Lib3MF_W
LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_createbinarystream(Lib3MF_Writer pWriter, const char * pPath, Lib3MF_BinaryStream * pBinaryStream);

/**
* Sets a binary stream for a mesh object. Currently supported objects are Meshes and Toolpath layers.
* Sets a binary stream for an object. Currently supported objects are Meshes and Toolpath layers.
*
* @param[in] pWriter - Writer instance.
* @param[in] pInstance - Object instance to assign Binary stream to.
Expand Down
10 changes: 10 additions & 0 deletions Autogenerated/Bindings/C/lib3mf_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ typedef enum eLib3MFBeamLatticeBallMode {
eBeamLatticeBallModeAll = 2
} eLib3MFBeamLatticeBallMode;

typedef enum eLib3MFBinaryStreamPredictionType {
eBinaryStreamPredictionTypeNoPrediction = 0,
eBinaryStreamPredictionTypeDeltaPrediction = 1
} eLib3MFBinaryStreamPredictionType;

typedef enum eLib3MFProgressIdentifier {
eProgressIdentifierQUERYCANCELED = 0,
eProgressIdentifierDONE = 1,
Expand Down Expand Up @@ -487,6 +492,11 @@ typedef union {
int m_code;
} structEnumLib3MFBeamLatticeBallMode;

typedef union {
eLib3MFBinaryStreamPredictionType m_enum;
int m_code;
} structEnumLib3MFBinaryStreamPredictionType;

typedef union {
eLib3MFProgressIdentifier m_enum;
int m_code;
Expand Down
40 changes: 40 additions & 0 deletions Autogenerated/Bindings/CDynamic/lib3mf_dynamic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Lib3MFResult InitLib3MFWrapperTable(sLib3MFDynamicWrapperTable * pWrapperTable)
pWrapperTable->m_Base_ClassTypeId = NULL;
pWrapperTable->m_BinaryStream_GetPath = NULL;
pWrapperTable->m_BinaryStream_GetUUID = NULL;
pWrapperTable->m_BinaryStream_DisableDiscretizedArrayCompression = NULL;
pWrapperTable->m_BinaryStream_EnableDiscretizedArrayCompression = NULL;
pWrapperTable->m_BinaryStream_EnableLZMA = NULL;
pWrapperTable->m_BinaryStream_DisableLZMA = NULL;
pWrapperTable->m_Writer_WriteToFile = NULL;
pWrapperTable->m_Writer_GetStreamSize = NULL;
pWrapperTable->m_Writer_WriteToBuffer = NULL;
Expand Down Expand Up @@ -617,6 +621,42 @@ Lib3MFResult LoadLib3MFWrapperTable(sLib3MFDynamicWrapperTable * pWrapperTable,
if (pWrapperTable->m_BinaryStream_GetUUID == NULL)
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
pWrapperTable->m_BinaryStream_DisableDiscretizedArrayCompression = (PLib3MFBinaryStream_DisableDiscretizedArrayCompressionPtr) GetProcAddress(hLibrary, "lib3mf_binarystream_disablediscretizedarraycompression");
#else // _WIN32
pWrapperTable->m_BinaryStream_DisableDiscretizedArrayCompression = (PLib3MFBinaryStream_DisableDiscretizedArrayCompressionPtr) dlsym(hLibrary, "lib3mf_binarystream_disablediscretizedarraycompression");
dlerror();
#endif // _WIN32
if (pWrapperTable->m_BinaryStream_DisableDiscretizedArrayCompression == NULL)
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
pWrapperTable->m_BinaryStream_EnableDiscretizedArrayCompression = (PLib3MFBinaryStream_EnableDiscretizedArrayCompressionPtr) GetProcAddress(hLibrary, "lib3mf_binarystream_enablediscretizedarraycompression");
#else // _WIN32
pWrapperTable->m_BinaryStream_EnableDiscretizedArrayCompression = (PLib3MFBinaryStream_EnableDiscretizedArrayCompressionPtr) dlsym(hLibrary, "lib3mf_binarystream_enablediscretizedarraycompression");
dlerror();
#endif // _WIN32
if (pWrapperTable->m_BinaryStream_EnableDiscretizedArrayCompression == NULL)
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
pWrapperTable->m_BinaryStream_EnableLZMA = (PLib3MFBinaryStream_EnableLZMAPtr) GetProcAddress(hLibrary, "lib3mf_binarystream_enablelzma");
#else // _WIN32
pWrapperTable->m_BinaryStream_EnableLZMA = (PLib3MFBinaryStream_EnableLZMAPtr) dlsym(hLibrary, "lib3mf_binarystream_enablelzma");
dlerror();
#endif // _WIN32
if (pWrapperTable->m_BinaryStream_EnableLZMA == NULL)
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
pWrapperTable->m_BinaryStream_DisableLZMA = (PLib3MFBinaryStream_DisableLZMAPtr) GetProcAddress(hLibrary, "lib3mf_binarystream_disablelzma");
#else // _WIN32
pWrapperTable->m_BinaryStream_DisableLZMA = (PLib3MFBinaryStream_DisableLZMAPtr) dlsym(hLibrary, "lib3mf_binarystream_disablelzma");
dlerror();
#endif // _WIN32
if (pWrapperTable->m_BinaryStream_DisableLZMA == NULL)
return LIB3MF_ERROR_COULDNOTFINDLIBRARYEXPORT;

#ifdef _WIN32
pWrapperTable->m_Writer_WriteToFile = (PLib3MFWriter_WriteToFilePtr) GetProcAddress(hLibrary, "lib3mf_writer_writetofile");
#else // _WIN32
Expand Down
41 changes: 40 additions & 1 deletion Autogenerated/Bindings/CDynamic/lib3mf_dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,41 @@ typedef Lib3MFResult (*PLib3MFBinaryStream_GetPathPtr) (Lib3MF_BinaryStream pBin
*/
typedef Lib3MFResult (*PLib3MFBinaryStream_GetUUIDPtr) (Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nUUIDBufferSize, Lib3MF_uint32* pUUIDNeededChars, char * pUUIDBuffer);

/**
* Sets the float compression mode to raw. All subsequent writes will adhere to this mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @return error code or 0 (success)
*/
typedef Lib3MFResult (*PLib3MFBinaryStream_DisableDiscretizedArrayCompressionPtr) (Lib3MF_BinaryStream pBinaryStream);

/**
* Sets the compression mode to a quantized array. All subsequent writes will adhere to this mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] dUnits - Unit factor to use for quantization.
* @param[in] ePredictionType - Prediction type to use for arrays.
* @return error code or 0 (success)
*/
typedef Lib3MFResult (*PLib3MFBinaryStream_EnableDiscretizedArrayCompressionPtr) (Lib3MF_BinaryStream pBinaryStream, Lib3MF_double dUnits, eLib3MFBinaryStreamPredictionType ePredictionType);

/**
* Enables LZMA mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] nLZMALevel - LZMA Level (0-9)
* @return error code or 0 (success)
*/
typedef Lib3MFResult (*PLib3MFBinaryStream_EnableLZMAPtr) (Lib3MF_BinaryStream pBinaryStream, Lib3MF_uint32 nLZMALevel);

/**
* Disables LZMA mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @return error code or 0 (success)
*/
typedef Lib3MFResult (*PLib3MFBinaryStream_DisableLZMAPtr) (Lib3MF_BinaryStream pBinaryStream);

/*************************************************************************************************************************
Class definition for Writer
**************************************************************************************************************************/
Expand Down Expand Up @@ -223,7 +258,7 @@ typedef Lib3MFResult (*PLib3MFWriter_SetContentEncryptionCallbackPtr) (Lib3MF_Wr
typedef Lib3MFResult (*PLib3MFWriter_CreateBinaryStreamPtr) (Lib3MF_Writer pWriter, const char * pPath, Lib3MF_BinaryStream * pBinaryStream);

/**
* Sets a binary stream for a mesh object. Currently supported objects are Meshes and Toolpath layers.
* Sets a binary stream for an object. Currently supported objects are Meshes and Toolpath layers.
*
* @param[in] pWriter - Writer instance.
* @param[in] pInstance - Object instance to assign Binary stream to.
Expand Down Expand Up @@ -5113,6 +5148,10 @@ typedef struct {
PLib3MFBase_ClassTypeIdPtr m_Base_ClassTypeId;
PLib3MFBinaryStream_GetPathPtr m_BinaryStream_GetPath;
PLib3MFBinaryStream_GetUUIDPtr m_BinaryStream_GetUUID;
PLib3MFBinaryStream_DisableDiscretizedArrayCompressionPtr m_BinaryStream_DisableDiscretizedArrayCompression;
PLib3MFBinaryStream_EnableDiscretizedArrayCompressionPtr m_BinaryStream_EnableDiscretizedArrayCompression;
PLib3MFBinaryStream_EnableLZMAPtr m_BinaryStream_EnableLZMA;
PLib3MFBinaryStream_DisableLZMAPtr m_BinaryStream_DisableLZMA;
PLib3MFWriter_WriteToFilePtr m_Writer_WriteToFile;
PLib3MFWriter_GetStreamSizePtr m_Writer_GetStreamSize;
PLib3MFWriter_WriteToBufferPtr m_Writer_WriteToBuffer;
Expand Down
10 changes: 10 additions & 0 deletions Autogenerated/Bindings/CDynamic/lib3mf_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ typedef enum eLib3MFBeamLatticeBallMode {
eBeamLatticeBallModeAll = 2
} eLib3MFBeamLatticeBallMode;

typedef enum eLib3MFBinaryStreamPredictionType {
eBinaryStreamPredictionTypeNoPrediction = 0,
eBinaryStreamPredictionTypeDeltaPrediction = 1
} eLib3MFBinaryStreamPredictionType;

typedef enum eLib3MFProgressIdentifier {
eProgressIdentifierQUERYCANCELED = 0,
eProgressIdentifierDONE = 1,
Expand Down Expand Up @@ -487,6 +492,11 @@ typedef union {
int m_code;
} structEnumLib3MFBeamLatticeBallMode;

typedef union {
eLib3MFBinaryStreamPredictionType m_enum;
int m_code;
} structEnumLib3MFBinaryStreamPredictionType;

typedef union {
eLib3MFProgressIdentifier m_enum;
int m_code;
Expand Down
42 changes: 42 additions & 0 deletions Autogenerated/Bindings/CSharp/Lib3MF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public enum eBeamLatticeBallMode {
All = 2
};

public enum eBinaryStreamPredictionType {
NoPrediction = 0,
DeltaPrediction = 1
};

public enum eProgressIdentifier {
QUERYCANCELED = 0,
DONE = 1,
Expand Down Expand Up @@ -354,6 +359,18 @@ public class Lib3MFWrapper
[DllImport("lib3mf.dll", EntryPoint = "lib3mf_binarystream_getuuid", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 BinaryStream_GetUUID (IntPtr Handle, UInt32 sizeUUID, out UInt32 neededUUID, IntPtr dataUUID);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_binarystream_disablediscretizedarraycompression", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 BinaryStream_DisableDiscretizedArrayCompression (IntPtr Handle);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_binarystream_enablediscretizedarraycompression", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 BinaryStream_EnableDiscretizedArrayCompression (IntPtr Handle, Double AUnits, Int32 APredictionType);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_binarystream_enablelzma", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 BinaryStream_EnableLZMA (IntPtr Handle, UInt32 ALZMALevel);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_binarystream_disablelzma", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 BinaryStream_DisableLZMA (IntPtr Handle);

[DllImport("lib3mf.dll", EntryPoint = "lib3mf_writer_writetofile", CallingConvention=CallingConvention.Cdecl)]
public unsafe extern static Int32 Writer_WriteToFile (IntPtr Handle, byte[] AFilename);

Expand Down Expand Up @@ -2266,6 +2283,31 @@ public String GetUUID ()
return Encoding.UTF8.GetString(bytesUUID).TrimEnd(char.MinValue);
}

public void DisableDiscretizedArrayCompression ()
{

CheckError(Internal.Lib3MFWrapper.BinaryStream_DisableDiscretizedArrayCompression (Handle));
}

public void EnableDiscretizedArrayCompression (Double AUnits, eBinaryStreamPredictionType APredictionType)
{
Int32 enumPredictionType = (Int32) APredictionType;

CheckError(Internal.Lib3MFWrapper.BinaryStream_EnableDiscretizedArrayCompression (Handle, AUnits, enumPredictionType));
}

public void EnableLZMA (UInt32 ALZMALevel)
{

CheckError(Internal.Lib3MFWrapper.BinaryStream_EnableLZMA (Handle, ALZMALevel));
}

public void DisableLZMA ()
{

CheckError(Internal.Lib3MFWrapper.BinaryStream_DisableLZMA (Handle));
}

}

public class CWriter : CBase
Expand Down
37 changes: 36 additions & 1 deletion Autogenerated/Bindings/Cpp/lib3mf_abi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,41 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getpath(Lib3MF_BinaryStream pBi
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_getuuid(Lib3MF_BinaryStream pBinaryStream, const Lib3MF_uint32 nUUIDBufferSize, Lib3MF_uint32* pUUIDNeededChars, char * pUUIDBuffer);

/**
* Sets the float compression mode to raw. All subsequent writes will adhere to this mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_disablediscretizedarraycompression(Lib3MF_BinaryStream pBinaryStream);

/**
* Sets the compression mode to a quantized array. All subsequent writes will adhere to this mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] dUnits - Unit factor to use for quantization.
* @param[in] ePredictionType - Prediction type to use for arrays.
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_enablediscretizedarraycompression(Lib3MF_BinaryStream pBinaryStream, Lib3MF_double dUnits, Lib3MF::eBinaryStreamPredictionType ePredictionType);

/**
* Enables LZMA mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @param[in] nLZMALevel - LZMA Level (0-9)
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_enablelzma(Lib3MF_BinaryStream pBinaryStream, Lib3MF_uint32 nLZMALevel);

/**
* Disables LZMA mode.
*
* @param[in] pBinaryStream - BinaryStream instance.
* @return error code or 0 (success)
*/
LIB3MF_DECLSPEC Lib3MFResult lib3mf_binarystream_disablelzma(Lib3MF_BinaryStream pBinaryStream);

/*************************************************************************************************************************
Class definition for Writer
**************************************************************************************************************************/
Expand Down Expand Up @@ -236,7 +271,7 @@ LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_setcontentencryptioncallback(Lib3MF_W
LIB3MF_DECLSPEC Lib3MFResult lib3mf_writer_createbinarystream(Lib3MF_Writer pWriter, const char * pPath, Lib3MF_BinaryStream * pBinaryStream);

/**
* Sets a binary stream for a mesh object. Currently supported objects are Meshes and Toolpath layers.
* Sets a binary stream for an object. Currently supported objects are Meshes and Toolpath layers.
*
* @param[in] pWriter - Writer instance.
* @param[in] pInstance - Object instance to assign Binary stream to.
Expand Down
41 changes: 40 additions & 1 deletion Autogenerated/Bindings/Cpp/lib3mf_implicit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,10 @@ class CBinaryStream : public CBase {

inline std::string GetPath();
inline std::string GetUUID();
inline void DisableDiscretizedArrayCompression();
inline void EnableDiscretizedArrayCompression(const Lib3MF_double dUnits, const eBinaryStreamPredictionType ePredictionType);
inline void EnableLZMA(const Lib3MF_uint32 nLZMALevel);
inline void DisableLZMA();
};

/*************************************************************************************************************************
Expand Down Expand Up @@ -2407,6 +2411,41 @@ inline CBase* CWrapper::polymorphicFactory(Lib3MFHandle pHandle)
return std::string(&bufferUUID[0]);
}

/**
* CBinaryStream::DisableDiscretizedArrayCompression - Sets the float compression mode to raw. All subsequent writes will adhere to this mode.
*/
void CBinaryStream::DisableDiscretizedArrayCompression()
{
CheckError(lib3mf_binarystream_disablediscretizedarraycompression(m_pHandle));
}

/**
* CBinaryStream::EnableDiscretizedArrayCompression - Sets the compression mode to a quantized array. All subsequent writes will adhere to this mode.
* @param[in] dUnits - Unit factor to use for quantization.
* @param[in] ePredictionType - Prediction type to use for arrays.
*/
void CBinaryStream::EnableDiscretizedArrayCompression(const Lib3MF_double dUnits, const eBinaryStreamPredictionType ePredictionType)
{
CheckError(lib3mf_binarystream_enablediscretizedarraycompression(m_pHandle, dUnits, ePredictionType));
}

/**
* CBinaryStream::EnableLZMA - Enables LZMA mode.
* @param[in] nLZMALevel - LZMA Level (0-9)
*/
void CBinaryStream::EnableLZMA(const Lib3MF_uint32 nLZMALevel)
{
CheckError(lib3mf_binarystream_enablelzma(m_pHandle, nLZMALevel));
}

/**
* CBinaryStream::DisableLZMA - Disables LZMA mode.
*/
void CBinaryStream::DisableLZMA()
{
CheckError(lib3mf_binarystream_disablelzma(m_pHandle));
}

/**
* Method definitions for class CWriter
*/
Expand Down Expand Up @@ -2575,7 +2614,7 @@ inline CBase* CWrapper::polymorphicFactory(Lib3MFHandle pHandle)
}

/**
* CWriter::AssignBinaryStream - Sets a binary stream for a mesh object. Currently supported objects are Meshes and Toolpath layers.
* CWriter::AssignBinaryStream - Sets a binary stream for an object. Currently supported objects are Meshes and Toolpath layers.
* @param[in] pInstance - Object instance to assign Binary stream to.
* @param[in] pBinaryStream - Binary stream object to use for this layer.
*/
Expand Down
Loading

0 comments on commit b817e32

Please sign in to comment.