Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Commit 22c9729

Browse files
committed
Reading and writing of Mappings and DenseField works.
1 parent e19471d commit 22c9729

27 files changed

+1319
-828
lines changed

export/Exception.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,15 @@ DECLARE_FIELD3D_GENERIC_EXCEPTION(WriteMACFieldDataException, Exception)
145145
DECLARE_FIELD3D_GENERIC_EXCEPTION(WriteMappingException, Exception)
146146
DECLARE_FIELD3D_GENERIC_EXCEPTION(WriteSimpleDataException, Exception)
147147

148+
DECLARE_FIELD3D_GENERIC_EXCEPTION(OgIGroupException, Exception)
149+
DECLARE_FIELD3D_GENERIC_EXCEPTION(OgIDatasetException, Exception)
150+
DECLARE_FIELD3D_GENERIC_EXCEPTION(OgIAttributeException, Exception)
148151
DECLARE_FIELD3D_GENERIC_EXCEPTION(OgOGroupException, Exception)
149152
DECLARE_FIELD3D_GENERIC_EXCEPTION(OgODatasetException, Exception)
150153
DECLARE_FIELD3D_GENERIC_EXCEPTION(OgOAttributeException, Exception)
151154

155+
DECLARE_FIELD3D_GENERIC_EXCEPTION(ReadDataException, Exception)
156+
152157
//----------------------------------------------------------------------------//
153158

154159
} // namespace Exc

export/Field3DFile.h

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,19 @@ class FIELD3D_API Field3DInputFile : public Field3DFileBase
408408

409409
virtual void closeInternal()
410410
{
411+
cleanup();
412+
}
413+
414+
void cleanup()
415+
{
416+
// The destruction of the various Ogawa components must happen in the
417+
// right order
418+
419+
// First, the partition groups
420+
m_partitions.clear();
421+
// Then the root group
422+
m_root.reset();
423+
// Finally, the archive
411424
m_archive.reset();
412425
}
413426

@@ -513,12 +526,23 @@ class FIELD3D_API Field3DInputFile : public Field3DFileBase
513526
readLayer(const std::string &intPartitionName,
514527
const std::string &layerName) const;
515528

529+
//! Sets up all the partitions and layers, but does not load any data
530+
bool readPartitionAndLayerInfo();
531+
532+
//! Read metadata for this layer
533+
bool readMetadata(OgIGroup &metadataGroup, FieldBase::Ptr field) const;
534+
535+
//! Read global metadata for this file
536+
bool readMetadata(OgIGroup &metadataGroup);
537+
516538
// Data members --------------------------------------------------------------
517539

518540
//! Filename, only to be set by open().
519541
std::string m_filename;
520542
//! Pointer to the Ogawa archive
521543
boost::shared_ptr<Alembic::Ogawa::IArchive> m_archive;
544+
//! Pointer to root group
545+
boost::shared_ptr<OgIGroup> m_root;
522546

523547
};
524548

@@ -571,6 +595,11 @@ class FIELD3D_API Field3DOutputFile : public Field3DFileBase
571595
// From Field3DFileBase ------------------------------------------------------
572596

573597
virtual void closeInternal()
598+
{
599+
cleanup();
600+
}
601+
602+
void cleanup()
574603
{
575604
// The destruction of the various Ogawa components must happen in the
576605
// right order
@@ -678,7 +707,7 @@ class FIELD3D_API Field3DOutputFile : public Field3DFileBase
678707
//! Writes the mapping to the given Og node.
679708
//! Mappings are assumed to be light-weight enough to be stored as
680709
//! plain attributes under a group.
681-
bool writeMapping(OgOGroup &partitionLocation, FieldMapping::Ptr mapping);
710+
bool writeMapping(OgOGroup &partitionGroup, FieldMapping::Ptr mapping);
682711

683712
//! Writes metadata for this layer
684713
bool writeMetadata(OgOGroup &metadataGroup, FieldBase::Ptr layer);
@@ -771,16 +800,6 @@ Field3DInputFile::readLayers(const std::string &partitionName,
771800

772801
//----------------------------------------------------------------------------//
773802

774-
template <class Data_T>
775-
typename Field<Data_T>::Ptr
776-
Field3DInputFile::readLayer(const std::string &intPartitionName,
777-
const std::string &layerName) const
778-
{
779-
return typename Field<Data_T>::Ptr();
780-
}
781-
782-
//----------------------------------------------------------------------------//
783-
784803
FIELD3D_NAMESPACE_HEADER_CLOSE
785804

786805
//----------------------------------------------------------------------------//

export/Field3DFileHDF5.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,6 @@ readField(const std::string &className, hid_t layerGroup,
16061606
typedef typename Field<Data_T>::Ptr FieldPtr;
16071607

16081608
FieldIO::Ptr io = factory.createFieldIO(className);
1609-
assert(io != 0);
16101609
if (!io) {
16111610
Msg::print(Msg::SevWarning, "Unable to find class type: " +
16121611
className);

export/FieldIO.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <typeinfo>
5757

5858
#include "Field.h"
59+
#include "OgawaFwd.h"
5960
#include "Log.h"
6061

6162
//----------------------------------------------------------------------------//
@@ -118,11 +119,22 @@ class FieldIO : public RefBase
118119
const std::string &layerPath,
119120
DataTypeEnum typeEnum) = 0;
120121

122+
//! Read the field at the given Ogawa group
123+
//! \returns Pointer to the created field, or a null pointer if the field
124+
//! couldn't be read.
125+
virtual FieldBase::Ptr read(OgIGroup &layerGroup, const std::string &filename,
126+
const std::string &layerPath,
127+
OgDataType typeEnum) = 0;
128+
121129
//! Write the field to the given layer group
122130
//! \returns Whether the operation was successful
123131
virtual bool write(hid_t layerGroup, FieldBase::Ptr field) = 0;
124132

125-
//! Returns the class name. This is used when registering the class to the
133+
//! Write the field to the given layer group
134+
//! \returns Whether the operation was successful
135+
virtual bool write(OgOGroup &layerGroup, FieldBase::Ptr field) = 0;
136+
137+
//! Returns the class name. This is used when registering the class to the
126138
//! FieldIOFactory object.
127139
virtual std::string className() const = 0;
128140

export/FieldMappingIO.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <hdf5.h>
5252

5353
#include "FieldMapping.h"
54+
#include "OgawaFwd.h"
5455

5556
//----------------------------------------------------------------------------//
5657

@@ -98,10 +99,19 @@ class FieldMappingIO : public RefBase
9899
//! couldn't be read.
99100
virtual FieldMapping::Ptr read(hid_t mappingGroup) = 0;
100101

102+
//! Read the field at the given hdf5 group
103+
//! \returns Pointer to the created field, or a null pointer if the field
104+
//! couldn't be read.
105+
virtual FieldMapping::Ptr read(OgIGroup &mappingGroup) = 0;
106+
101107
//! Write the field to the given mapping group
102108
//! \returns Whether the operation was successful
103109
virtual bool write(hid_t mappingGroup, FieldMapping::Ptr mapping) = 0;
104110

111+
//! Write the field to the given mapping group
112+
//! \returns Whether the operation was successful
113+
virtual bool write(OgOGroup &mappingGroup, FieldMapping::Ptr mapping) = 0;
114+
105115
//! Returns the class name. This is used when registering the class in the
106116
//! ClassFactory.
107117
virtual std::string className() const = 0;
@@ -161,10 +171,19 @@ class NullFieldMappingIO : public FieldMappingIO
161171
//! \returns Null if no object was read
162172
virtual FieldMapping::Ptr read(hid_t mappingGroup);
163173

174+
//! Reads the field mapping and tries to create a NullFieldMapping
175+
//! object from it.
176+
//! \returns Null if no object was read
177+
virtual FieldMapping::Ptr read(OgIGroup &mappingGroup);
178+
164179
//! Writes the given field mapping to disk.
165180
//! \return true if successful, otherwise false
166181
virtual bool write(hid_t mappingGroup, FieldMapping::Ptr mapping);
167182

183+
//! Writes the given field mapping to disk.
184+
//! \return true if successful, otherwise false
185+
virtual bool write(OgOGroup &mappingGroup, FieldMapping::Ptr mapping);
186+
168187
//! Returns the class name
169188
virtual std::string className() const;
170189

@@ -224,10 +243,19 @@ class MatrixFieldMappingIO : public FieldMappingIO
224243
//! \returns Matrix if no object was read
225244
virtual FieldMapping::Ptr read(hid_t mappingGroup);
226245

246+
//! Reads the field mapping and tries to create a MatrixFieldMapping
247+
//! object from it.
248+
//! \returns Matrix if no object was read
249+
virtual FieldMapping::Ptr read(OgIGroup &mappingGroup);
250+
227251
//! Writes the given field mapping to disk.
228252
//! \return true if successful, otherwise false
229253
virtual bool write(hid_t mappingGroup, FieldMapping::Ptr mapping);
230254

255+
//! Writes the given field mapping to disk.
256+
//! \return true if successful, otherwise false
257+
virtual bool write(OgOGroup &mappingGroup, FieldMapping::Ptr mapping);
258+
231259
//! Returns the class name
232260
virtual std::string className() const;
233261

@@ -287,10 +315,19 @@ class FrustumFieldMappingIO : public FieldMappingIO
287315
//! \returns Null pointer if no object was read
288316
virtual FieldMapping::Ptr read(hid_t mappingGroup);
289317

318+
//! Reads the field mapping and tries to create a FrustumFieldMapping
319+
//! object from it.
320+
//! \returns Null pointer if no object was read
321+
virtual FieldMapping::Ptr read(OgIGroup &mappingGroup);
322+
290323
//! Writes the given field mapping to disk.
291324
//! \return true if successful, otherwise false
292325
virtual bool write(hid_t mappingGroup, FieldMapping::Ptr mapping);
293326

327+
//! Writes the given field mapping to disk.
328+
//! \return true if successful, otherwise false
329+
virtual bool write(OgOGroup &mappingGroup, FieldMapping::Ptr mapping);
330+
294331
//! Returns the class name
295332
virtual std::string className() const;
296333

export/OgawaFwd.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@
4545
#ifndef _INCLUDED_Field3D_OgawaFwd_H_
4646
#define _INCLUDED_Field3D_OgawaFwd_H_
4747

48+
#include "ns.h"
49+
4850
//----------------------------------------------------------------------------//
4951
// Forward declarations
5052
//----------------------------------------------------------------------------//
5153

54+
FIELD3D_NAMESPACE_OPEN
55+
5256
class OgIGroup;
5357
class OgOGroup;
5458

@@ -62,6 +66,10 @@ class OgIDataset;
6266
template <typename T>
6367
class OgODataset;
6468

69+
FIELD3D_NAMESPACE_HEADER_CLOSE
70+
71+
//----------------------------------------------------------------------------//
72+
6573
namespace Alembic {
6674
namespace Ogawa {
6775
namespace v7 {

export/Traits.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,48 @@ for converting templatization into strings and enums.
5959

6060
FIELD3D_NAMESPACE_OPEN
6161

62+
//----------------------------------------------------------------------------//
63+
// Types
64+
//----------------------------------------------------------------------------//
65+
66+
#if !defined(_MSC_VER)
67+
using ::uint8_t;
68+
using ::int8_t;
69+
using ::uint16_t;
70+
using ::int16_t;
71+
using ::uint32_t;
72+
using ::int32_t;
73+
using ::uint64_t;
74+
using ::int64_t;
75+
#else
76+
typedef unsigned char uint8_t;
77+
typedef signed char int8_t;
78+
typedef unsigned short uint16_t;
79+
typedef signed short int16_t;
80+
typedef unsigned int uint32_t;
81+
typedef int int32_t;
82+
typedef unsigned long long uint64_t;
83+
typedef long long int64_t;
84+
#endif
85+
86+
typedef half float16_t;
87+
typedef float float32_t;
88+
typedef double float64_t;
89+
90+
#ifdef FIELD3D_VERSION_NS
91+
typedef Field3D::V3h vec16_t;
92+
typedef Field3D::V3f vec32_t;
93+
typedef Field3D::V3d vec64_t;
94+
typedef Field3D::V3i veci32_t;
95+
typedef Field3D::M44d mtx64_t;
96+
#else
97+
typedef Imath::Vec3<float16_t> vec16_t;
98+
typedef Imath::Vec3<float32_t> vec32_t;
99+
typedef Imath::Vec3<float64_t> vec64_t;
100+
typedef Imath::Vec3<int32_t> veci32_t;
101+
typedef Imath::M44d mtx64_t;
102+
#endif
103+
62104
//----------------------------------------------------------------------------//
63105
// Enums
64106
//----------------------------------------------------------------------------//
@@ -75,6 +117,49 @@ enum DataTypeEnum {
75117
DataTypeUnknown
76118
};
77119

120+
//----------------------------------------------------------------------------//
121+
122+
//! Enumerates the various uses for Ogawa-level groups.
123+
//! \warning Do not under any circumstances alter the order of these! If you
124+
//! need to add more types, append them at the end, before F3DNumDataTypes.
125+
enum OgDataType {
126+
127+
// Signed and unsigned integers from char to long
128+
F3DInt8 = 0,
129+
F3DUint8,
130+
131+
F3DInt16,
132+
F3DUint16,
133+
134+
F3DInt32,
135+
F3DUint32,
136+
137+
F3DInt64,
138+
F3DUint64,
139+
140+
// Floats
141+
F3DFloat16,
142+
F3DFloat32,
143+
F3DFloat64,
144+
145+
// Vec3
146+
F3DVec16,
147+
F3DVec32,
148+
F3DVec64,
149+
F3DVecI32,
150+
151+
// Matrix
152+
F3DMtx64,
153+
154+
// String
155+
F3DString,
156+
157+
F3DNumDataTypes,
158+
159+
// Invalid type enum
160+
F3DInvalidDataType = 127
161+
};
162+
78163
//----------------------------------------------------------------------------//
79164
// FieldTraits
80165
//----------------------------------------------------------------------------//

0 commit comments

Comments
 (0)