53#include <boost/tokenizer.hpp>
54#include <boost/utility.hpp>
61#include "OgIAttribute.h"
62#include "OgIDataset.h"
64#include "OgOAttribute.h"
65#include "OgODataset.h"
106 std::vector<std::string>
makeUnique(std::vector<std::string>
vec)
108 std::vector<string>
ret;
109 std::sort(
vec.begin(),
vec.end());
110 std::vector<std::string>::iterator
newEnd =
111 std::unique(
vec.begin(),
vec.end());
121 class print : std::unary_function<T, void>
127 void operator()(
const T& x)
const
129 for (
int i = 0;
i < indent;
i++)
131 std::cout << x << std::endl;
143 void checkFile(
const std::string &filename)
172 " is higher than the current version " +
181 " is lower than the minimum supported version " +
247 template <
class Data_T>
250 const std::string &filename,
const std::string &layerPath)
263 OgDataType typeEnum = OgawaTypeTraits<Data_T>::typeEnum();
286 std::vector<std::string>
attrs = group.attributeNames();
288 for (
size_t i = 0, end =
attrs.size();
i < end; ++
i) {
292 if (
attr.isValid()) {
299 if (
attr.isValid()) {
306 if (
attr.isValid()) {
313 if (
attr.isValid()) {
320 if (
attr.isValid()) {
361 for (LayerList::const_iterator
i =
m_layers.begin();
363 if (
i->name ==
name) {
377 for (LayerList::const_iterator
i =
m_layers.begin();
423 const std::string & ,
430 if ((**i).mapping->isIdentical(field->mapping())) {
455 if ((**i).name == partitionName)
469 if ((**i).name == partitionName)
481 size_t pos = partitionName.rfind(
".");
482 if (pos == partitionName.npos) {
483 return partitionName;
485 return partitionName.substr(0, pos);
515 const string &partitionName)
const
540 const string &partitionName)
const
570 names.push_back((**i).name);
578 const string &intPartitionName)
const
598 const string &intPartitionName)
const
650 string name = (**i).name;
651 size_t pos = name.rfind(
".");
652 if (pos != name.npos) {
653 if (name.substr(0, pos) == partitionName) {
668 return partitionName +
"." + boost::lexical_cast<std::string>(
i);
682 GroupMembershipMap::const_iterator end =
groupMembers.end();
684 for (;
i != end; ++
i) {
729 m_archive.reset(
new Alembic::Ogawa::IArchive(filename));
735 if (
m_hdf5->open(filename)) {
750 if (!version.isValid()) {
755 version.value()[2] };
778 "Unknown error when reading file metadata ");
803 "Unknown error when reading file hierarchy. ");
809 +
string(
e.what()) );
814 "In file: " + filename +
" - "
815 +
string(
e.what()) );
820 "In file: " + filename +
" - File version can not be read: "
826 "In file: " + filename +
" - Bad file hierarchy. ");
833 if (
m_hdf5->open(filename)) {
838 "In file: " + filename +
": " +
string(
e.what()));
844 "In file: " + filename +
" Unknown exception ");
864 for (std::vector<std::string>::const_iterator
i =
groups.begin(),
865 end =
groups.end();
i != end; ++
i) {
867 const std::string &name = *
i;
869 if (name ==
"field3d_global_metadata") {
883 const std::string &name = (**i).name;
903 (**i).mapping = mapping;
911 const std::string &partitionName = (**i).name;
920 for (std::vector<std::string>::const_iterator
l =
groups.begin(),
931 layer.
parent = partitionName;
933 partition(partitionName)->addLayer(layer);
993 m_archive.reset(
new Alembic::Ogawa::OArchive(filename));
1017 const std::string className = mapping->className();
1049 FieldMetadata::StrMetadata::const_iterator
i =
1050 field->metadata().strMetadata().begin();
1051 FieldMetadata::StrMetadata::const_iterator end =
1052 field->metadata().strMetadata().end();
1053 for (;
i != end; ++
i) {
1066 FieldMetadata::IntMetadata::const_iterator
i =
1067 field->metadata().intMetadata().begin();
1068 FieldMetadata::IntMetadata::const_iterator end =
1069 field->metadata().intMetadata().end();
1070 for (;
i != end; ++
i) {
1083 FieldMetadata::FloatMetadata::const_iterator
i =
1084 field->metadata().floatMetadata().begin();
1085 FieldMetadata::FloatMetadata::const_iterator end =
1086 field->metadata().floatMetadata().end();
1087 for (;
i != end; ++
i) {
1100 FieldMetadata::VecIntMetadata::const_iterator
i =
1101 field->metadata().vecIntMetadata().begin();
1102 FieldMetadata::VecIntMetadata::const_iterator end =
1103 field->metadata().vecIntMetadata().end();
1104 for (;
i != end; ++
i) {
1117 FieldMetadata::VecFloatMetadata::const_iterator
i =
1118 field->metadata().vecFloatMetadata().begin();
1119 FieldMetadata::VecFloatMetadata::const_iterator end =
1120 field->metadata().vecFloatMetadata().end();
1121 for (;
i != end; ++
i) {
1143 FieldMetadata::StrMetadata::const_iterator
i =
1145 FieldMetadata::StrMetadata::const_iterator end =
1147 for (;
i != end; ++
i) {
1160 FieldMetadata::IntMetadata::const_iterator
i =
1162 FieldMetadata::IntMetadata::const_iterator end =
1164 for (;
i != end; ++
i) {
1177 FieldMetadata::FloatMetadata::const_iterator
i =
1179 FieldMetadata::FloatMetadata::const_iterator end =
1181 for (;
i != end; ++
i) {
1194 FieldMetadata::VecIntMetadata::const_iterator
i =
1196 FieldMetadata::VecIntMetadata::const_iterator end =
1198 for (;
i != end; ++
i) {
1211 FieldMetadata::VecFloatMetadata::const_iterator
i =
1213 FieldMetadata::VecFloatMetadata::const_iterator end =
1215 for (;
i != end; ++
i) {
1237 return m_hdf5->writeGlobalMetadata();
1255 return m_hdf5->writeGroupMembership();
1262 using namespace std;
1271 "Error creating field3d_group_membership group.");
1275 if (!writeAttribute(group,
"is_field3d_group_membership",
"1")) {
1277 "Failed to write field3d_group_membership attribute.");
1281 std::map<std::string, std::string>::const_iterator
iter =
1283 std::map<std::string, std::string>::const_iterator
iEnd =
1287 if (!writeAttribute(group,
iter->first,
iter->second)) {
1289 "Failed to write groupMembership string: "+
iter->first);
1323 for (PartitionList::const_iterator
i =
m_partitions.begin();
1325 cout <<
"Name: " << (**i).name << endl;
1327 cout <<
" Mapping: " << (**i).mapping->className() << endl;
1329 cout <<
" Mapping: NULL" << endl;
1330 cout <<
" Layers: " << endl;
1332 (**i).getLayerNames(
names);
1356 const std::string & ,
1359 using namespace Exc;
1362 newPart->name = partitionName;
1376 "writeMapping returned false for an unknown reason ");
1387 "Unknown error when writing mapping for partition: "
1395 part->mapping = field->mapping();
1408template <
class Data_T>
1418 "Called writeLayer with null pointer. Ignoring...");
1425 "Attempting to write layer without opening file first.");
1446 "Couldn't add layer \"" +
layerName +
"\" to partition \""
1447 + partitionName +
"\" because the layer's mapping is null.");
1465 if (!
part->mapping) {
1472 if (!field->
mapping()->isIdentical(
part->mapping)) {
1474 +
"\" to partition \"" + partitionName
1475 +
"\" because mapping doesn't match");
1487 layer.
parent = partitionName;
1507 part->addLayer(layer);
1514template <
class Data_T>
1555 string layerPath = layer->
parent +
"/" + layer->
name;
1558 className =
layerGroup.findAttribute<
string>(
"class_name").value();
1606template <
class Data_T>
1617 std::vector<std::string>
parts;
1620 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
1623 for (vector<string>::iterator
l =
layers.begin();
l !=
layers.end(); ++
l) {
1625 if ((name.length() == 0) || (*
l == name)) {
1639template <
class Data_T>
1644 using namespace std;
1651 if ((
layerName.length() == 0) || (partitionName.length() == 0))
1654 std::vector<std::string>
parts;
1657 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
1658 std::vector<std::string>
layers;
1661 for (vector<string>::iterator
l =
layers.begin();
1678template <
class Data_T>
1681 const std::string &name,
1682 const std::string &attribute,
1685 using namespace boost;
1686 using namespace std;
1753template <
class Data_T>
1759 using namespace boost;
1760 using namespace std;
1771 if ((
layerName.length() == 0) || (partitionName.length() == 0))
1779 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
1787 for (vector<string>::iterator
l =
layers.begin();
1808 string layerPath = layer->
parent +
"/" + layer->
name;
1810 if (!parent.isValid()) {
1812 + layerPath +
" in .f3d file ");
1818 + layerPath +
" in .f3d file ");
1856template <
class Data_T>
1860 using namespace std;
1863 typedef std::vector<FieldPtr>
FieldList;
1867 std::vector<std::string>
parts;
1870 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
1871 std::vector<std::string>
layers;
1873 for (vector<string>::iterator
l =
layers.begin();
l !=
layers.end(); ++
l) {
1875 if ((name.length() == 0) || (*
l == name)) {
1877 for (
typename FieldList::iterator
i =
f.begin();
i !=
f.end(); ++
i) {
1891template <
class Data_T>
1895 using namespace std;
1898 typedef std::vector<FieldPtr>
FieldList;
1902 std::vector<std::string>
parts;
1905 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
1906 std::vector<std::string>
layers;
1908 for (vector<string>::iterator
l =
layers.begin();
l !=
layers.end(); ++
l) {
1910 if ((name.length() == 0) || (*
l == name)) {
1912 for (
typename FieldList::iterator
i =
f.begin();
i !=
f.end(); ++
i) {
1928#define FIELD3D_INSTANTIATION_WRITELAYER(type) \
1930 bool Field3DOutputFile::writeLayer<type> \
1931 (const std::string &, const std::string &, Field<type>::Ptr ); \
1944#define FIELD3D_INSTANTIATION_READLAYER(type) \
1947 Field3DInputFile::readLayer<type> \
1948 (const std::string &, const std::string &) const; \
1961#define FIELD3D_INSTANTIATION_READLAYERS1(type) \
1964 Field3DInputFile::readLayers<type>(const std::string &name) const; \
1975#define FIELD3D_INSTANTIATION_READLAYERS2(type) \
1978 Field3DInputFile::readLayers<type>(const std::string &partitionName, \
1979 const std::string &layerName) const; \
1990#define FIELD3D_INSTANTIATION_READPROXYLAYER(type) \
1992 EmptyField<type>::Vec \
1993 Field3DInputFile::readProxyLayer<type>(const std::string &partitionName, \
1994 const std::string &layerName, \
1995 bool isVectorLayer) const \
2006#define FIELD3D_INSTANTIATION_READPROXYSCALARLAYER(type) \
2008 EmptyField<type>::Vec \
2009 Field3DInputFile::readProxyScalarLayers<type> \
2010 (const std::string &name) const \
2021#define FIELD3D_INSTANTIATION_READPROXYVECTORLAYER(type) \
2023 EmptyField<type>::Vec \
2024 Field3DInputFile::readProxyVectorLayers<type> \
2025 (const std::string &name) const \
Contains the ClassFactory class for registering Field3D classes.
Contains the Field3DFileHDF5 classes.
Field< Data_T >::Ptr readField(const std::string &className, hid_t layerGroup, const std::string &filename, const std::string &layerPath)
This function creates a FieldIO instance based on className which then reads the field data from laye...
FIELD3D_API bool writeField(hid_t layerGroup, FieldBase::Ptr field)
This function creates a FieldIO instance based on field->className() which then writes the field data...
FIELD3D_API FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
This function creates a FieldMappingIO instance based on className read from mappingGroup location wh...
#define FIELD3D_INSTANTIATION_READPROXYLAYER(type)
#define FIELD3D_INSTANTIATION_WRITELAYER(type)
#define FIELD3D_INSTANTIATION_READPROXYVECTORLAYER(type)
#define FIELD3D_INSTANTIATION_READLAYERS1(type)
#define FIELD3D_INSTANTIATION_READLAYERS2(type)
#define FIELD3D_INSTANTIATION_READPROXYSCALARLAYER(type)
bool fileExists(const std::string &filename)
checks to see if a file/directory exists or not
Contains the Field3DFile classes.
bool fileExists(const std::string &filename)
checks to see if a file/directory exists or not
Contains the FieldCache class.
Contains Field, WritableField and ResizableField classes.
OgDataType
Enumerates the various uses for Ogawa-level groups.
static ClassFactory & singleton()
}
This subclass of Field does not store any data.
boost::intrusive_ptr< EmptyField > Ptr
boost::shared_ptr< Field3DFileHDF5Base > m_hdf5Base
HDF5 fallback.
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
void getScalarLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the scalar layers in a given partition.
virtual ~Field3DFileBase()=0
Pure virtual destructor to ensure we never instantiate this class.
std::string makeIntPartitionName(const std::string &partitionsName, int i) const
Makes an internal partition name given the external partition name. Effectively just tacks on ....
FieldMetadata & metadata()
accessor to the m_metadata class
virtual void closeInternal()=0
Closes the file if open.
void getIntScalarLayerNames(std::vector< std::string > &names, const std::string &intPartitionName) const
Gets the names of all the scalar layers in a given partition, but assumes that partition name is the ...
void clear()
Clear the data structures and close the file.
PartitionList m_partitions
Vector of partitions.
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
void getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.
void getVectorLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the vector layers in a given partition.
int numIntPartitions(const std::string &partitionName) const
Returns the number of internal partitions for a given partition name.
std::string intPartitionName(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Returns a unique partition name given the requested name. This ensures that partitions with matching ...
void printHierarchy() const
PartitionCountMap m_partitionCount
Contains a counter for each partition name. This is used to keep multiple fields with the same name u...
std::map< std::string, std::string > GroupMembershipMap
void addGroupMembership(const GroupMembershipMap &groupMembers)
Add to the group membership.
void getIntVectorLayerNames(std::vector< std::string > &names, const std::string &intPartitionName) const
Gets the names of all the vector layers in a given partition, but assumes that partition name is the ...
bool close()
Closes the file. No need to call this unless you specifically want to close the file early....
Provides writing of .f3d (internally, hdf5) files.
static bool ms_doOgawa
Whether to output ogawa files.
virtual void closeInternal()
Closes the file if open.
boost::shared_ptr< Field3DOutputFileHDF5 > m_hdf5
HDF5 fallback.
bool writeLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
File::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Create newPartition given the input config.
virtual ~Field3DOutputFile()
bool create(const std::string &filename, CreateMode cm=OverwriteMode)
Creates a .f3d file on disk.
bool writeGlobalMetadata()
This routine is call if you want to write out global metadata to disk.
boost::shared_ptr< OgOGroup > m_root
Pointer to root group.
boost::shared_ptr< Alembic::Ogawa::OArchive > m_archive
Pointer to the Ogawa archive.
bool writeMapping(OgOGroup &partitionGroup, FieldMapping::Ptr mapping)
Writes the mapping to the given Og node. Mappings are assumed to be light-weight enough to be stored ...
bool writeGroupMembership()
This routine is called just before closing to write out any group membership to disk.
bool writeMetadata(OgOGroup &metadataGroup, FieldBase::Ptr layer)
Writes metadata for this layer.
std::string incrementPartitionName(std::string &pname)
Increment the partition or make it zero if there's not an integer suffix.
boost::intrusive_ptr< FieldBase > Ptr
FieldMetadata & metadata()
accessor to the m_metadata class
std::string attribute
Optional name of the attribute the field represents.
std::string name
Optional name of the field.
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
boost::intrusive_ptr< FieldIO > Ptr
boost::intrusive_ptr< FieldMappingIO > Ptr
boost::intrusive_ptr< FieldMapping > Ptr
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
boost::intrusive_ptr< FieldRes > Ptr
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
boost::intrusive_ptr< Field > Ptr
std::string name
The name of the layer (always available)
std::string parent
The name of the parent partition. We need this in order to open its group.
boost::shared_ptr< OgOGroup > m_group
Group representing the partition.
LayerList m_layers
The layers belonging to this partition.
std::string name
Name of the partition.
void setGroup(boost::shared_ptr< OgOGroup > ptr)
Sets the group pointer.
virtual std::string className() const
void getLayerNames(std::vector< std::string > &names) const
Gets all the layer names.
OgOGroup & group() const
Returns a reference to the OgOGroup.
boost::intrusive_ptr< Partition > Ptr
const File::Layer * layer(const std::string &name) const
Finds a layer.
void addLayer(const File::Layer &layer)
Adds a layer.
Scoped object - creates a group on creation and closes it on destruction.
void setSize(const V3i &size)
Resizes the object.
Namespace for Exception objects.
Namespace for file I/O specifics.
Contains utility functions and classes for Hdf5 files.
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
#define FIELD3D_MAJOR_VER
#define FIELD3D_NAMESPACE_SOURCE_CLOSE
#define FIELD3D_MINOR_VER
#define FIELD3D_MICRO_VER