Alembic: AbcGeom/OGeomBase.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
OGeomBase.h
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
44namespace Alembic {
45namespace AbcGeom {
46namespace ALEMBIC_VERSION_NS {
47
48
57template <class INFO>
58 class OGeomBaseSchema : public Abc::OSchema<INFO>
59{
60public:
61 //-*************************************************************************
62 // TYPEDEFS AND IDENTIFIERS
63 //-*************************************************************************
64
65 typedef INFO info_type;
66
67
68 //-*************************************************************************
69 // Constructors that pass through to OSchema
70 //-*************************************************************************
71 //
74 OGeomBaseSchema() {}
75
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 {
105 m_selfBoundsProperty.reset();
106 m_childBoundsProperty.reset();
107 m_arbGeomParams.reset();
108 m_userProperties.reset();
109 Abc::OSchema<info_type>::reset();
110 }
111
112 virtual bool valid() const
113 {
114 return ( Abc::OSchema<info_type>::valid() );
115 }
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
179protected:
180
181 void init( uint32_t iTsIndex, bool isSparse)
182 {
183 ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::init()" );
184
185 if( !isSparse )
186 {
187 createSelfBoundsProperty(iTsIndex, 0);
188 }
189
190 ALEMBIC_ABC_SAFE_CALL_END_RESET();
191 }
192
194 void createSelfBoundsProperty(uint32_t iTsIndex, size_t iNumSamples)
195 {
196 ALEMBIC_ABC_SAFE_CALL_BEGIN( "OGeomBaseSchema::createSelfBoundsProperty()" );
197
198 if ( m_selfBoundsProperty.valid() )
199 {
200 return;
201 }
202
203 m_selfBoundsProperty = Abc::OBox3dProperty( this->getPtr(), ".selfBnds",
204 iTsIndex );
205
206 Abc::Box3d bnds;
207 for ( size_t i = 0; i < iNumSamples; ++i )
208 {
209 m_selfBoundsProperty.set( bnds );
210 }
211 ALEMBIC_ABC_SAFE_CALL_END();
212 }
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
226using namespace ALEMBIC_VERSION_NS;
227
228} // End namespace AbcGeom
229} // End namespace Alembic
230
231#endif
Alembic::Abc::ALEMBIC_VERSION_NS::Argument
Definition Argument.h:120
Alembic::Abc::ALEMBIC_VERSION_NS::OBasePropertyT< AbcA::CompoundPropertyWriterPtr >::getPtr
AbcA::CompoundPropertyWriterPtr getPtr() const
Definition OBaseProperty.h:162
Alembic::Abc::ALEMBIC_VERSION_NS::OBasePropertyT< AbcA::CompoundPropertyWriterPtr >::reset
void reset()
Definition OBaseProperty.h:166
Alembic::Abc::ALEMBIC_VERSION_NS::OBasePropertyT< AbcA::CompoundPropertyWriterPtr >::valid
bool valid() const
Definition OBaseProperty.h:170
Alembic::Abc::ALEMBIC_VERSION_NS::OCompoundProperty
Definition OCompoundProperty.h:53
Alembic::Abc::ALEMBIC_VERSION_NS::OSchema
Definition OSchema.h:119
Alembic::Abc::ALEMBIC_VERSION_NS::OSchema::OSchema
OSchema()
Definition OSchema.h:191
Alembic::AbcGeom::ALEMBIC_VERSION_NS::OGeomBaseSchema::OGeomBaseSchema
OGeomBaseSchema()
Definition OGeomBase.h:74
Alembic::AbcGeom::ALEMBIC_VERSION_NS::OGeomBaseSchema::OGeomBaseSchema
OGeomBaseSchema(AbcA::CompoundPropertyWriterPtr iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition OGeomBase.h:78
Alembic::AbcGeom::ALEMBIC_VERSION_NS::OGeomBaseSchema::createSelfBoundsProperty
void createSelfBoundsProperty(uint32_t iTsIndex, size_t iNumSamples)
Creates the self bounds.
Definition OGeomBase.h:194
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39