1 //-*****************************************************************************
2 //
3 // Copyright (c) 2013,
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/AbcCoreOgawa/SprImpl.h>
38 #include <Alembic/AbcCoreOgawa/ReadUtil.h>
39 #include <Alembic/AbcCoreOgawa/StreamManager.h>
40 #include <Alembic/AbcCoreOgawa/OrImpl.h>
41
42 namespace Alembic {
43 namespace AbcCoreOgawa {
44 namespace ALEMBIC_VERSION_NS {
45
46 //-*****************************************************************************
SprImpl(AbcA::CompoundPropertyReaderPtr iParent,Ogawa::IGroupPtr iGroup,PropertyHeaderPtr iHeader)47 SprImpl::SprImpl( AbcA::CompoundPropertyReaderPtr iParent,
48 Ogawa::IGroupPtr iGroup,
49 PropertyHeaderPtr iHeader )
50 : m_parent( iParent )
51 , m_group( iGroup )
52 , m_header( iHeader )
53 {
54 // Validate all inputs.
55 ABCA_ASSERT( m_parent, "Invalid parent" );
56 ABCA_ASSERT( m_group, "Invalid scalar property group" );
57 ABCA_ASSERT( m_header, "Invalid header" );
58
59 if ( m_header->header.getPropertyType() != AbcA::kScalarProperty )
60 {
61 ABCA_THROW( "Attempted to create a ScalarPropertyReader from a "
62 "non-array property type" );
63 }
64 }
65
66 //-*****************************************************************************
getHeader() const67 const AbcA::PropertyHeader & SprImpl::getHeader() const
68 {
69 return m_header->header;
70 }
71
72 //-*****************************************************************************
getObject()73 AbcA::ObjectReaderPtr SprImpl::getObject()
74 {
75 return m_parent->getObject();
76 }
77
78 //-*****************************************************************************
getParent()79 AbcA::CompoundPropertyReaderPtr SprImpl::getParent()
80 {
81 return m_parent;
82 }
83
84 //-*****************************************************************************
asScalarPtr()85 AbcA::ScalarPropertyReaderPtr SprImpl::asScalarPtr()
86 {
87 return shared_from_this();
88 }
89
90 //-*****************************************************************************
getNumSamples()91 size_t SprImpl::getNumSamples()
92 {
93 return m_header->nextSampleIndex;
94 }
95
96 //-*****************************************************************************
isConstant()97 bool SprImpl::isConstant()
98 {
99 return ( m_header->firstChangedIndex == 0 );
100 }
101
102 //-*****************************************************************************
getSample(index_t iSampleIndex,void * iIntoLocation)103 void SprImpl::getSample( index_t iSampleIndex, void * iIntoLocation )
104 {
105 size_t index = m_header->verifyIndex( iSampleIndex );
106
107 StreamIDPtr streamId = Alembic::Util::dynamic_pointer_cast< ArImpl,
108 AbcA::ArchiveReader > ( getObject()->getArchive() )->getStreamID();
109
110 std::size_t id = streamId->getID();
111 Ogawa::IDataPtr data = m_group->getData( index, id );
112 AbcA::DataType dt = m_header->header.getDataType();
113
114 // Check to make sure the Ogawa data size matches our expected scalar
115 // property size, the + 16 is to account for the data key.
116 if ( dt.getPod() < Util::kStringPOD && data &&
117 data->getSize() != dt.getNumBytes() + 16 )
118 {
119 ABCA_THROW( "ScalarPropertyReader::getSample size is not correct "
120 "expected: " << dt.getNumBytes() << " got: " <<
121 data->getSize() - 16 );
122 }
123
124 ReadData( iIntoLocation, data, id, dt, dt.getPod() );
125 }
126
127 //-*****************************************************************************
getFloorIndex(chrono_t iTime)128 std::pair<index_t, chrono_t> SprImpl::getFloorIndex( chrono_t iTime )
129 {
130 return m_header->header.getTimeSampling()->getFloorIndex( iTime,
131 m_header->nextSampleIndex );
132 }
133
134 //-*****************************************************************************
getCeilIndex(chrono_t iTime)135 std::pair<index_t, chrono_t> SprImpl::getCeilIndex( chrono_t iTime )
136 {
137 return m_header->header.getTimeSampling()->getCeilIndex( iTime,
138 m_header->nextSampleIndex );
139 }
140
141 //-*****************************************************************************
getNearIndex(chrono_t iTime)142 std::pair<index_t, chrono_t> SprImpl::getNearIndex( chrono_t iTime )
143 {
144 return m_header->header.getTimeSampling()->getNearIndex( iTime,
145 m_header->nextSampleIndex );
146 }
147
148 } // End namespace ALEMBIC_VERSION_NS
149 } // End namespace AbcCoreOgawa
150 } // End namespace Alembic
151