/src/alembic/lib/Alembic/AbcGeom/OGeomBase.h
Line | Count | Source |
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 | | #ifndef Alembic_AbcGeom_OGeometrySchema_h |
38 | | #define Alembic_AbcGeom_OGeometrySchema_h |
39 | | |
40 | | #include <Alembic/Abc/OSchema.h> |
41 | | #include <Alembic/AbcGeom/Foundation.h> |
42 | | #include <Alembic/AbcGeom/OGeomParam.h> |
43 | | |
44 | | namespace Alembic { |
45 | | namespace AbcGeom { |
46 | | namespace ALEMBIC_VERSION_NS { |
47 | | |
48 | | |
49 | | //! This class holds properties common to all classes with a physical volume. |
50 | | //! - selfBounds |
51 | | //! - childBounds (optional) |
52 | | //! - GeomParams (optional) |
53 | | //! - UserProperties (optional) |
54 | | //! |
55 | | //! This class is used to encapsulate common functionality of the |
56 | | //! real Geometry schema classes, like OPoints and OPolyMesh and so on |
57 | | template <class INFO> |
58 | | class OGeomBaseSchema : public Abc::OSchema<INFO> |
59 | | { |
60 | | public: |
61 | | //-************************************************************************* |
62 | | // TYPEDEFS AND IDENTIFIERS |
63 | | //-************************************************************************* |
64 | | |
65 | | typedef INFO info_type; |
66 | | |
67 | | |
68 | | //-************************************************************************* |
69 | | // Constructors that pass through to OSchema |
70 | | //-************************************************************************* |
71 | | // |
72 | | //! The default constructor creates an empty OSchema. |
73 | | //! Used to create "NULL/invalid" instances. |
74 | | OGeomBaseSchema() {} |
75 | | |
76 | | //! Delegates to Abc/OSchema, and then creates always-present |
77 | | //! properties |
78 | | OGeomBaseSchema( AbcA::CompoundPropertyWriterPtr iParent, |
79 | | const std::string &iName, |
80 | | const Argument &iArg0 = Argument(), |
81 | | const Argument &iArg1 = Argument(), |
82 | | const Argument &iArg2 = Argument(), |
83 | | const Argument &iArg3 = Argument() ) |
84 | | : Abc::OSchema<info_type>( iParent, iName, iArg0, iArg1, iArg2, iArg3 ) |
85 | | { |
86 | | AbcA::TimeSamplingPtr tsPtr = |
87 | | Abc::GetTimeSampling( iArg0, iArg1, iArg2, iArg3 ); |
88 | | uint32_t tsIndex = |
89 | | Abc::GetTimeSamplingIndex( iArg0, iArg1, iArg2, iArg3 ); |
90 | | |
91 | | // if we specified a valid TimeSamplingPtr, use it to determine the |
92 | | // index otherwise use the default index of 0 - uniform. |
93 | | if ( tsPtr ) |
94 | | { |
95 | | tsIndex = iParent->getObject()->getArchive()->addTimeSampling( |
96 | | *tsPtr ); |
97 | | } |
98 | | |
99 | | // Create our always present property |
100 | | init( tsIndex, Abc::IsSparse( iArg0, iArg1, iArg2, iArg3 ) ); |
101 | | } |
102 | | |
103 | | virtual void reset () |
104 | 0 | { |
105 | 0 | m_selfBoundsProperty.reset(); |
106 | 0 | m_childBoundsProperty.reset(); |
107 | 0 | m_arbGeomParams.reset(); |
108 | 0 | m_userProperties.reset(); |
109 | 0 | Abc::OSchema<info_type>::reset(); |
110 | 0 | } Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::CurvesSchemaInfo>::reset() Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::FaceSetSchemaInfo>::reset() Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::NuPatchSchemaInfo>::reset() Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::PointsSchemaInfo>::reset() Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::PolyMeshSchemaInfo>::reset() Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::SubDSchemaInfo>::reset() |
111 | | |
112 | | virtual bool valid() const |
113 | 0 | { |
114 | 0 | return ( Abc::OSchema<info_type>::valid() ); |
115 | 0 | } Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::CurvesSchemaInfo>::valid() const Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::FaceSetSchemaInfo>::valid() const Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::NuPatchSchemaInfo>::valid() const Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::PointsSchemaInfo>::valid() const Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::PolyMeshSchemaInfo>::valid() const Unexecuted instantiation: Alembic::AbcGeom::v12::OGeomBaseSchema<Alembic::AbcGeom::v12::SubDSchemaInfo>::valid() const |
116 | | |
117 | | Abc::OCompoundProperty getArbGeomParams() |
118 | | { |
119 | | // Accessing the ArbGeomParams will create its compound |
120 | | // property if needed. |
121 | | ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::getArbGeomParams()" ); |
122 | | |
123 | | if ( ! m_arbGeomParams ) |
124 | | { |
125 | | m_arbGeomParams = Abc::OCompoundProperty( this->getPtr(), |
126 | | ".arbGeomParams" ); |
127 | | } |
128 | | |
129 | | return m_arbGeomParams; |
130 | | |
131 | | ALEMBIC_ABC_SAFE_CALL_END(); |
132 | | |
133 | | Abc::OCompoundProperty ret; |
134 | | return ret; |
135 | | } |
136 | | |
137 | | Abc::OCompoundProperty getUserProperties() |
138 | | { |
139 | | // Accessing UserProperties will create its compound |
140 | | // property if needed. |
141 | | ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::getUserProperties()" ); |
142 | | |
143 | | if ( ! m_userProperties ) |
144 | | { |
145 | | m_userProperties = Abc::OCompoundProperty( this->getPtr(), |
146 | | ".userProperties" ); |
147 | | } |
148 | | |
149 | | return m_userProperties; |
150 | | |
151 | | ALEMBIC_ABC_SAFE_CALL_END(); |
152 | | |
153 | | Abc::OCompoundProperty ret; |
154 | | return ret; |
155 | | } |
156 | | |
157 | | Abc::OBox3dProperty getChildBoundsProperty() |
158 | | { |
159 | | // Accessing Child Bounds Property will create it if needed |
160 | | ALEMBIC_ABC_SAFE_CALL_BEGIN( |
161 | | "OGeomBaseSchema::getChildBoundsProperty()" ); |
162 | | |
163 | | if ( ! m_childBoundsProperty ) |
164 | | { |
165 | | AbcA::CompoundPropertyWriterPtr _this = this->getPtr(); |
166 | | |
167 | | // for now, use the self bounds time sampling, this |
168 | | // can and should be changed depending on how the children |
169 | | // are sampled |
170 | | m_childBoundsProperty = Abc::OBox3dProperty( _this, |
171 | | ".childBnds", m_selfBoundsProperty.getTimeSampling() ); |
172 | | |
173 | | } |
174 | | |
175 | | ALEMBIC_ABC_SAFE_CALL_END(); |
176 | | return m_childBoundsProperty; |
177 | | } |
178 | | |
179 | | protected: |
180 | | |
181 | | void init( uint32_t iTsIndex, bool isSparse) |
182 | 0 | { |
183 | 0 | ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::init()" ); |
184 | 0 |
|
185 | 0 | if( !isSparse ) |
186 | 0 | { |
187 | 0 | createSelfBoundsProperty(iTsIndex, 0); |
188 | 0 | } |
189 | 0 |
|
190 | 0 | ALEMBIC_ABC_SAFE_CALL_END_RESET(); |
191 | 0 | } |
192 | | |
193 | | //! Creates the self bounds |
194 | | void createSelfBoundsProperty(uint32_t iTsIndex, size_t iNumSamples) |
195 | 0 | { |
196 | 0 | ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::createSelfBoundsProperty()" ); |
197 | 0 |
|
198 | 0 | if ( m_selfBoundsProperty.valid() ) |
199 | 0 | { |
200 | 0 | return; |
201 | 0 | } |
202 | 0 |
|
203 | 0 | m_selfBoundsProperty = Abc::OBox3dProperty( this->getPtr(), ".selfBnds", |
204 | 0 | iTsIndex ); |
205 | 0 |
|
206 | 0 | Abc::Box3d bnds; |
207 | 0 | for ( size_t i = 0; i < iNumSamples; ++i ) |
208 | 0 | { |
209 | 0 | m_selfBoundsProperty.set( bnds ); |
210 | 0 | } |
211 | 0 | ALEMBIC_ABC_SAFE_CALL_END(); |
212 | 0 | } |
213 | | |
214 | | // Only selfBounds is required, all others are optional |
215 | | Abc::OBox3dProperty m_selfBoundsProperty; |
216 | | Abc::OBox3dProperty m_childBoundsProperty; |
217 | | |
218 | | Abc::OCompoundProperty m_arbGeomParams; |
219 | | Abc::OCompoundProperty m_userProperties; |
220 | | |
221 | | }; |
222 | | |
223 | | |
224 | | } // End namespace ALEMBIC_VERSION_NS |
225 | | |
226 | | using namespace ALEMBIC_VERSION_NS; |
227 | | |
228 | | } // End namespace AbcGeom |
229 | | } // End namespace Alembic |
230 | | |
231 | | #endif |