1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2012,
4 // Sony Pictures Imageworks, Inc. and
5 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 // * Neither the name of Sony Pictures Imageworks, nor
19 // Industrial Light & Magic nor the names of their contributors may be used
20 // to endorse or promote products derived from this software without specific
21 // prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //-*****************************************************************************
36
37 #include <Alembic/AbcCoreHDF5/ApwImpl.h>
38 #include <Alembic/AbcCoreHDF5/WriteUtil.h>
39 #include <Alembic/AbcCoreHDF5/StringWriteUtil.h>
40
41 namespace Alembic {
42 namespace AbcCoreHDF5 {
43 namespace ALEMBIC_VERSION_NS {
44
45 //-*****************************************************************************
ApwImpl(AbcA::CompoundPropertyWriterPtr iParent,hid_t iParentGroup,const std::string & iName,const AbcA::MetaData & iMetaData,const AbcA::DataType & iDataType,uint32_t iTimeSamplingIndex)46 ApwImpl::ApwImpl( AbcA::CompoundPropertyWriterPtr iParent,
47 hid_t iParentGroup,
48 const std::string & iName,
49 const AbcA::MetaData & iMetaData,
50 const AbcA::DataType & iDataType,
51 uint32_t iTimeSamplingIndex )
52 : SimplePwImpl<AbcA::ArrayPropertyWriter,
53 ApwImpl,
54 const AbcA::ArraySample &,
55 AbcA::ArraySample::Key>( iParent,
56 iParentGroup,
57 iName,
58 iMetaData,
59 iDataType,
60 iTimeSamplingIndex,
61 AbcA::kArrayProperty )
62 {
63 if ( m_header->getPropertyType() != AbcA::kArrayProperty )
64 {
65 ABCA_THROW( "Attempted to create a ArrayPropertyWriter from a "
66 "non-array property type" );
67 }
68
69 m_isScalarLike = true;
70
71 // The WrittenArraySampleID is invalid by default.
72 assert( !m_previousWrittenArraySampleID );
73 }
74
75
76 //-*****************************************************************************
~ApwImpl()77 ApwImpl::~ApwImpl()
78 {
79 WritePropertyInfo( m_parentGroup, *m_header, m_isScalarLike,
80 m_timeSamplingIndex, m_nextSampleIndex, m_firstChangedIndex,
81 m_lastChangedIndex );
82 }
83
84
85 //-*****************************************************************************
asArrayPtr()86 AbcA::ArrayPropertyWriterPtr ApwImpl::asArrayPtr()
87 {
88 return shared_from_this();
89 }
90
91 //-*****************************************************************************
copyPreviousSample(hid_t iGroup,const std::string & iSampleName,index_t iSampleIndex)92 void ApwImpl::copyPreviousSample( hid_t iGroup,
93 const std::string &iSampleName,
94 index_t iSampleIndex )
95 {
96 // Copy the sample.
97 CopyWrittenArray( iGroup, iSampleName,
98 m_previousWrittenArraySampleID );
99
100 PlainOldDataType pod = m_previousWrittenArraySampleID->getKey().origPOD;
101
102 if ( m_previousNumPoints > 1 && ( pod == kStringPOD || pod == kWstringPOD ))
103 {
104 std::string dimsName = iSampleName + ".dims";
105 Dimensions dims( m_previousNumPoints );
106 WriteDimensions( iGroup, dimsName, dims );
107 }
108 }
109
110 //-*****************************************************************************
writeSample(hid_t iGroup,const std::string & iSampleName,index_t iSampleIndex,const AbcA::ArraySample & iSamp,const AbcA::ArraySample::Key & iKey)111 void ApwImpl::writeSample( hid_t iGroup,
112 const std::string &iSampleName,
113 index_t iSampleIndex,
114 const AbcA::ArraySample & iSamp,
115 const AbcA::ArraySample::Key &iKey )
116 {
117 AbcA::ArchiveWriterPtr awp =
118 this->getObject()->getArchive();
119
120 ABCA_ASSERT(iSamp.getDataType() == m_header->getDataType(),
121 "DataType on ArraySample iSamp: " << iSamp.getDataType() <<
122 ", does not match the DataType of the Array property: " <<
123 m_header->getDataType());
124
125 // if we haven't written this already, m_isScalarLike will be true
126 if (m_isScalarLike && iSamp.getDimensions().numPoints() != 1)
127 {
128 m_isScalarLike = false;
129 }
130
131 // Write the sample.
132 // This distinguishes between string, wstring, and regular arrays.
133 m_previousWrittenArraySampleID =
134 WriteArray( GetWrittenArraySampleMap( awp ),
135 iGroup, iSampleName,
136 iSamp, iKey,
137 m_fileDataType,
138 m_nativeDataType,
139 awp->getCompressionHint() );
140
141 m_previousNumPoints = iSamp.getDimensions().numPoints();
142 }
143
144 } // End namespace ALEMBIC_VERSION_NS
145 } // End namespace AbcCoreHDF5
146 } // End namespace Alembic
147