/src/alembic/lib/Alembic/AbcGeom/OFaceSet.h
Line | Count | Source (jump to first uncovered line) |
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_OFaceSet_h |
38 | | #define Alembic_AbcGeom_OFaceSet_h |
39 | | |
40 | | #include <Alembic/Util/Export.h> |
41 | | #include <Alembic/AbcGeom/Foundation.h> |
42 | | #include <Alembic/AbcGeom/SchemaInfoDeclarations.h> |
43 | | #include <Alembic/AbcGeom/OGeomParam.h> |
44 | | #include <Alembic/AbcGeom/FaceSetExclusivity.h> |
45 | | #include <Alembic/AbcGeom/OGeomBase.h> |
46 | | |
47 | | namespace Alembic { |
48 | | namespace AbcGeom { |
49 | | namespace ALEMBIC_VERSION_NS { |
50 | | |
51 | | //-***************************************************************************** |
52 | | class ALEMBIC_EXPORT OFaceSetSchema : public OGeomBaseSchema<FaceSetSchemaInfo> |
53 | | { |
54 | | public: |
55 | | //-************************************************************************* |
56 | | // Parition SAMPLE |
57 | | //-************************************************************************* |
58 | | class Sample |
59 | | { |
60 | | public: |
61 | | typedef Sample this_type; |
62 | | |
63 | | //! Creates a default sample with no data in it. |
64 | | //! ... |
65 | 0 | Sample() { reset(); } |
66 | | |
67 | | //! Creates a sample with the list of faces that are in this |
68 | | //! faceset. |
69 | | //! The array of face numbers MUST be ordered by face number. |
70 | | //! Code that reads and works with facesets depends on this for efficency. |
71 | | //! e.g. call std::sort (myVecOfFaces.begin (), myVecOfFaces.end ()); |
72 | | //! if you need to. |
73 | | //! The sample must be complete like this. Subsequent samples may also |
74 | | //! consist of faces which allows you to change of topology |
75 | | //! of the faceset. |
76 | | Sample( const Abc::Int32ArraySample &iFaceNums) |
77 | | : m_faces( iFaceNums ) |
78 | 0 | {} |
79 | | |
80 | | /* main accessors */ |
81 | | // Faces |
82 | 0 | const Abc::Int32ArraySample &getFaces() const { return m_faces; } |
83 | | void setFaces( const Abc::Int32ArraySample &iFaces) |
84 | 0 | { m_faces = iFaces; } |
85 | | |
86 | | // Bounding boxes |
87 | 0 | const Abc::Box3d &getSelfBounds() const { return m_selfBounds; } |
88 | | void setSelfBounds( const Abc::Box3d &iBnds ) |
89 | 0 | { m_selfBounds = iBnds; } |
90 | | |
91 | | void reset() |
92 | 0 | { |
93 | 0 | m_faces.reset(); |
94 | 0 |
|
95 | 0 | m_selfBounds.makeEmpty(); |
96 | 0 | } |
97 | | |
98 | | protected: |
99 | | Abc::Int32ArraySample m_faces; |
100 | | |
101 | | // bounds |
102 | | Abc::Box3d m_selfBounds; |
103 | | }; // end OFaceSetSchema::Sample |
104 | | |
105 | | |
106 | | //-************************************************************************* |
107 | | // FaceSet SCHEMA |
108 | | //-************************************************************************* |
109 | | public: |
110 | | //! By convention we always define this_type in AbcGeom classes. |
111 | | //! Used by unspecified-bool-type conversion below |
112 | | typedef OFaceSetSchema this_type; |
113 | | |
114 | | //-************************************************************************* |
115 | | // CONSTRUCTION, DESTRUCTION, ASSIGNMENT |
116 | | //-************************************************************************* |
117 | | //! The default constructor creates an empty OFaceSetSchema. |
118 | | //! OFaceSetSchema instances created this evaluate to a boolean value of false. |
119 | 0 | OFaceSetSchema() {} |
120 | | |
121 | | //! This constructor creates a new faceset writer. |
122 | | //! The first argument is an CompoundPropertyWriterPtr to use as a parent. |
123 | | //! The next is the name to give the schema which is usually the default |
124 | | //! name given by OFaceSet (.faceset) The remaining optional arguments |
125 | | //! can be used to override the ErrorHandlerPolicy, to specify |
126 | | //! MetaData, specify sparse sampling and to set TimeSampling. |
127 | | OFaceSetSchema( AbcA::CompoundPropertyWriterPtr iParent, |
128 | | const std::string &iName, |
129 | | const Abc::Argument &iArg0 = Abc::Argument(), |
130 | | const Abc::Argument &iArg1 = Abc::Argument(), |
131 | | const Abc::Argument &iArg2 = Abc::Argument(), |
132 | | const Abc::Argument &iArg3 = Abc::Argument() ); |
133 | | |
134 | | //! This constructor creates a new faceset writer. |
135 | | //! The first argument is an OCompundProperty to use as a parent, and from |
136 | | //! which the ErrorHandlerPolicy is derived. The next is the name to give |
137 | | //! the schema which is usually the default name given by OFaceSet |
138 | | //! (.faceset) The remaining optional arguments can be used to specify |
139 | | //! MetaData, specify sparse sampling and to set TimeSampling. |
140 | | OFaceSetSchema( Abc::OCompoundProperty iParent, |
141 | | const std::string &iName, |
142 | | const Abc::Argument &iArg0 = Abc::Argument(), |
143 | | const Abc::Argument &iArg1 = Abc::Argument(), |
144 | | const Abc::Argument &iArg2 = Abc::Argument() ); |
145 | | |
146 | | //! Default assignment and copy operator used. |
147 | | |
148 | | //-************************************************************************* |
149 | | // SCHEMA STUFF |
150 | | //-************************************************************************* |
151 | | |
152 | | //-************************************************************************* |
153 | | // SAMPLE STUFF |
154 | | //-************************************************************************* |
155 | | |
156 | | //! Get number of samples written so far. |
157 | | //! ... |
158 | | size_t getNumSamples() const |
159 | 0 | { return m_facesProperty.getNumSamples(); } |
160 | | |
161 | | //! Set a sample! First sample must have the list of faces in the faceset. |
162 | | void set( const Sample &iSamp ); |
163 | | |
164 | | void setTimeSampling( uint32_t iTimeSamplingID ); |
165 | | void setTimeSampling( AbcA::TimeSamplingPtr iTime ); |
166 | | |
167 | | void setFaceExclusivity( FaceSetExclusivity iFacesExclusive ); |
168 | 0 | FaceSetExclusivity getFaceExclusivity() { return m_facesExclusive; } |
169 | | //-************************************************************************* |
170 | | // ABC BASE MECHANISMS |
171 | | // These functions are used by Abc to deal with errors, validity, |
172 | | // and so on. |
173 | | //-************************************************************************* |
174 | | |
175 | | //! Reset returns this function set to an empty, default |
176 | | //! state. |
177 | | void reset() |
178 | 0 | { |
179 | 0 | m_facesProperty.reset(); |
180 | 0 |
|
181 | 0 | OGeomBaseSchema<FaceSetSchemaInfo>::reset(); |
182 | 0 | } |
183 | | |
184 | | //! Valid returns whether this instance holds real data. |
185 | | bool valid() const |
186 | 0 | { |
187 | 0 | return ( OGeomBaseSchema<FaceSetSchemaInfo>::valid() && |
188 | 0 | m_facesProperty.valid() |
189 | 0 | ); |
190 | 0 | } |
191 | | |
192 | | //! unspecified-bool-type operator overload. |
193 | | //! ... |
194 | | ALEMBIC_OVERRIDE_OPERATOR_BOOL( OFaceSetSchema::valid() ); |
195 | | |
196 | | protected: |
197 | | void _recordExclusivityHint(); |
198 | | |
199 | | void init( AbcA::CompoundPropertyWriterPtr iParent, |
200 | | const Abc::Argument &iArg0, const Abc::Argument &iArg1, |
201 | | const Abc::Argument &iArg2, const Abc::Argument &iArg3 ); |
202 | | |
203 | | Abc::OInt32ArrayProperty m_facesProperty; |
204 | | |
205 | | Abc::OUInt32Property m_facesExclusiveProperty; |
206 | | FaceSetExclusivity m_facesExclusive; |
207 | | }; |
208 | | |
209 | | |
210 | | //-***************************************************************************** |
211 | | // Nice to use typedef for users of this class. |
212 | | //-***************************************************************************** |
213 | | typedef Abc::OSchemaObject<OFaceSetSchema> OFaceSet; |
214 | | |
215 | | typedef Util::shared_ptr< OFaceSet > OFaceSetPtr; |
216 | | |
217 | | Abc::Box3d computeBoundsFromPositionsByFaces (const Int32ArraySample & faces, |
218 | | const Int32ArraySample & meshFaceCounts, |
219 | | const Int32ArraySample & vertexIndices, |
220 | | const P3fArraySample & meshP); |
221 | | |
222 | | } // End namespace ALEMBIC_VERSION_NS |
223 | | |
224 | | using namespace ALEMBIC_VERSION_NS; |
225 | | |
226 | | } // End namespace AbcGeom |
227 | | } // End namespace Alembic |
228 | | |
229 | | #endif |