1 // 2 // Copyright 2016 Pixar 3 // 4 // Licensed under the Apache License, Version 2.0 (the "Apache License") 5 // with the following modification; you may not use this file except in 6 // compliance with the Apache License and the following modification to it: 7 // Section 6. Trademarks. is deleted and replaced with: 8 // 9 // 6. Trademarks. This License does not grant permission to use the trade 10 // names, trademarks, service marks, or product names of the Licensor 11 // and its affiliates, except as required to comply with Section 4(c) of 12 // the License and to reproduce the content of the NOTICE file. 13 // 14 // You may obtain a copy of the Apache License at 15 // 16 // http://www.apache.org/licenses/LICENSE-2.0 17 // 18 // Unless required by applicable law or agreed to in writing, software 19 // distributed under the Apache License with the above modification is 20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21 // KIND, either express or implied. See the Apache License for the specific 22 // language governing permissions and limitations under the Apache License. 23 // 24 #ifndef PXR_USD_PLUGIN_USD_ABC_ALEMBIC_READER_H 25 #define PXR_USD_PLUGIN_USD_ABC_ALEMBIC_READER_H 26 27 /// \file usdAbc/alembicReader.h 28 29 #include "pxr/pxr.h" 30 #include "pxr/usd/sdf/abstractData.h" 31 #include "pxr/usd/sdf/fileFormat.h" 32 #include "pxr/base/tf/token.h" 33 #include <boost/noncopyable.hpp> 34 #include <boost/scoped_ptr.hpp> 35 #include <stdint.h> 36 #include <string> 37 #include <vector> 38 39 PXR_NAMESPACE_OPEN_SCOPE 40 41 42 // Note -- Even though this header is private we try to keep Alembic headers 43 // out of it anyway for simplicity's sake. 44 45 /// \class UsdAbc_AlembicDataReader 46 /// 47 /// An alembic reader suitable for an SdfAbstractData. 48 /// 49 class UsdAbc_AlembicDataReader : boost::noncopyable { 50 public: 51 typedef int64_t Index; 52 53 UsdAbc_AlembicDataReader(); 54 ~UsdAbc_AlembicDataReader(); 55 56 /// Open a file. Returns \c true on success; errors are reported by 57 /// \c GetErrors(). 58 bool Open(const std::string& filePath, 59 const SdfFileFormat::FileFormatArguments&); 60 61 /// Close the file. 62 void Close(); 63 64 /// Return any errors. 65 std::string GetErrors() const; 66 67 /// Set a reader flag. 68 void SetFlag(const TfToken&, bool set = true); 69 70 /// Test for the existence of a spec at \p path. 71 bool HasSpec(const SdfPath& path) const; 72 73 /// Returns the spec type for the spec at \p path. 74 SdfSpecType GetSpecType(const SdfPath& path) const; 75 76 /// Test for the existence of and optionally return the value at 77 /// (\p path,\p fieldName). 78 bool HasField(const SdfPath& path, 79 const TfToken& fieldName, 80 SdfAbstractDataValue* value) const; 81 82 /// Test for the existence of and optionally return the value at 83 /// (\p path,\p fieldName). 84 bool HasField(const SdfPath& path, 85 const TfToken& fieldName, 86 VtValue* value) const; 87 88 /// Test for the existence of and optionally return the value of the 89 /// property at \p path at index \p index. 90 bool HasValue(const SdfPath& path, Index index, 91 SdfAbstractDataValue* value) const; 92 93 /// Test for the existence of and optionally return the value of the 94 /// property at \p path at index \p index. 95 bool HasValue(const SdfPath& path, Index index, 96 VtValue* value) const; 97 98 /// Visit the specs. 99 void VisitSpecs(const SdfAbstractData& owner, 100 SdfAbstractDataSpecVisitor* visitor) const; 101 102 /// List the fields. 103 TfTokenVector List(const SdfPath& path) const; 104 105 /// The type holds a set of Usd times and can return an Alembic index 106 /// for each time. 107 class TimeSamples { 108 typedef std::vector<double> _UsdTimeCodes; 109 public: 110 typedef _UsdTimeCodes::const_iterator const_iterator; 111 112 /// Construct an empty set of samples. 113 TimeSamples(); 114 115 /// Construct from the time samples which must be monotonically 116 /// increasing. 117 TimeSamples(const std::vector<double>& times); 118 119 /// Swaps the contents of this with \p other. 120 void Swap(TimeSamples& other); 121 122 /// Returns \c true iff there are no samples. 123 bool IsEmpty() const; 124 125 /// Returns the number of samples. 126 size_t GetSize() const; 127 128 /// Returns the Usd times. 129 std::set<double> GetTimes() const; 130 131 /// Returns the time sample at index \p index. 132 double operator[](size_t index) const; 133 134 /// Add these Usd times to the given set. 135 void AddTo(std::set<double>*) const; 136 137 /// Returns the index for Usd time \p usdTime and returns \c true 138 /// or returns \c false if \p usdTime is not in the set of samples. 139 bool FindIndex(double usdTime, Index* index) const; 140 141 /// Returns the times bracketing \p time. 142 bool Bracket(double usdTime, double* tLower, double* tUpper) const; 143 144 /// Returns the times bracketing \p time. 145 template <class T> 146 static bool Bracket(const T&, double usdTime, 147 double* tLower, double* tUpper); 148 149 private: 150 // The monotonically increasing Usd times. 151 _UsdTimeCodes _times; 152 }; 153 154 /// Returns the sampled times over all properties. 155 const std::set<double>& ListAllTimeSamples() const; 156 157 /// Returns the sampled times for the property at \p path. 158 const TimeSamples& 159 ListTimeSamplesForPath(const SdfPath& path) const; 160 161 private: 162 boost::scoped_ptr<class UsdAbc_AlembicDataReaderImpl> _impl; 163 std::string _errorLog; 164 }; 165 166 167 PXR_NAMESPACE_CLOSE_SCOPE 168 169 #endif 170