Skip to content

Commit 5bb9eb6

Browse files
authored
Merge pull request #1465 from murraystevenson/objectMatrix
IECore : Add ObjectMatrix
2 parents 0add1b5 + b7fc185 commit 5bb9eb6

File tree

10 files changed

+704
-0
lines changed

10 files changed

+704
-0
lines changed

Changes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
10.5.x.x (relative to 10.5.13.1)
22
========
33

4+
Features
5+
--------
6+
7+
- ObjectMatrix : Added new class providing an object that holds a matrix of child objects.
8+
49
Fixes
510
-----
611

include/IECore/ObjectMatrix.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2025, Cinesite VFX Ltd. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECORE_OBJECTMATRIX_H
36+
#define IECORE_OBJECTMATRIX_H
37+
38+
#include "IECore/Export.h"
39+
#include "IECore/Object.h"
40+
41+
namespace IECore
42+
{
43+
44+
/// An Object which holds a matrix of child Objects.
45+
class IECORE_API ObjectMatrix : public Object
46+
{
47+
48+
public :
49+
50+
ObjectMatrix( size_t rows = 0, size_t columns = 0 );
51+
~ObjectMatrix() override;
52+
53+
IE_CORE_DECLAREOBJECT( ObjectMatrix, Object );
54+
55+
size_t numRows() const;
56+
size_t numColumns() const;
57+
58+
/// Resizes the matrix, preserving the original positions of its values.
59+
void resize( size_t rows, size_t columns );
60+
61+
ObjectPtr *operator[]( size_t row )
62+
{
63+
return &m_members[ row * m_columns ];
64+
}
65+
66+
const ObjectPtr *operator[]( size_t row ) const
67+
{
68+
return &m_members[ row * m_columns ];
69+
}
70+
71+
private :
72+
73+
using MemberContainer = std::vector<ObjectPtr>;
74+
75+
MemberContainer m_members;
76+
size_t m_rows;
77+
size_t m_columns;
78+
79+
};
80+
81+
IE_CORE_DECLAREPTR( ObjectMatrix );
82+
83+
} // namespace IECore
84+
85+
#endif // IECORE_OBJECTMATRIX_H

include/IECore/TypeIds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ enum TypeId
254254
V3iVectorDataBaseTypeId = 386,
255255
LensModelTypeId = 387,
256256
StandardRadialLensModelTypeId = 388,
257+
ObjectMatrixTypeId = 389,
257258

258259
// Remember to update TypeIdBinding.cpp !!!
259260

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2025, Cinesite VFX Ltd. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECOREPYTHON_OBJECTMATRIXBINDING_H
36+
#define IECOREPYTHON_OBJECTMATRIXBINDING_H
37+
38+
#include "IECorePython/Export.h"
39+
40+
namespace IECorePython
41+
{
42+
IECOREPYTHON_API void bindObjectMatrix();
43+
}
44+
45+
#endif // IECOREPYTHON_OBJECTMATRIXBINDING_H

src/IECore/ObjectMatrix.cpp

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2025, Cinesite VFX Ltd. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#include "IECore/ObjectMatrix.h"
36+
37+
#include "IECore/MurmurHash.h"
38+
39+
using namespace IECore;
40+
41+
IE_CORE_DEFINEOBJECTTYPEDESCRIPTION( ObjectMatrix );
42+
43+
ObjectMatrix::ObjectMatrix( size_t rows, size_t columns )
44+
: m_rows( rows ), m_columns( columns )
45+
{
46+
m_members.resize( rows * columns, nullptr );
47+
}
48+
49+
ObjectMatrix::~ObjectMatrix()
50+
{
51+
}
52+
53+
size_t ObjectMatrix::numRows() const
54+
{
55+
return m_rows;
56+
}
57+
58+
size_t ObjectMatrix::numColumns() const
59+
{
60+
return m_columns;
61+
}
62+
63+
void ObjectMatrix::resize( size_t rows, size_t columns )
64+
{
65+
MemberContainer originalMembers( m_members );
66+
m_members.clear();
67+
m_members.resize( rows * columns, nullptr );
68+
for( size_t i = 0; i < rows && i < m_rows; ++i )
69+
{
70+
for( size_t j = 0; j < columns && j < m_columns; ++j )
71+
{
72+
m_members[ i * columns + j ] = originalMembers[ i * m_columns + j ];
73+
}
74+
}
75+
m_rows = rows;
76+
m_columns = columns;
77+
}
78+
79+
void ObjectMatrix::copyFrom( const Object *other, CopyContext *context )
80+
{
81+
Object::copyFrom( other, context );
82+
const ObjectMatrix *tOther = static_cast<const ObjectMatrix *>( other );
83+
m_members.resize( tOther->m_members.size() );
84+
for( MemberContainer::size_type i = 0; i < m_members.size(); ++i )
85+
{
86+
if( !tOther->m_members[i] )
87+
{
88+
m_members[i] = nullptr;
89+
}
90+
else
91+
{
92+
m_members[i] = context->copy<Object>( tOther->m_members[i].get() );
93+
}
94+
}
95+
m_rows = tOther->m_rows;
96+
m_columns = tOther->m_columns;
97+
}
98+
99+
void ObjectMatrix::save( Object::SaveContext *context ) const
100+
{
101+
Object::save( context );
102+
throw IECore::NotImplementedException( "ObjectMatrix::save" );
103+
}
104+
105+
void ObjectMatrix::load( Object::LoadContextPtr context )
106+
{
107+
Object::load( context );
108+
throw IECore::NotImplementedException( "ObjectMatrix::load" );
109+
}
110+
111+
bool ObjectMatrix::isEqualTo( const Object *other ) const
112+
{
113+
if( !Object::isEqualTo( other ) )
114+
{
115+
return false;
116+
}
117+
const ObjectMatrix *tOther = static_cast<const ObjectMatrix *>( other );
118+
if( m_rows != tOther->m_rows || m_columns != tOther->m_columns )
119+
{
120+
return false;
121+
}
122+
for( MemberContainer::size_type i = 0; i < m_members.size(); ++i )
123+
{
124+
if( m_members[i] )
125+
{
126+
if( !tOther->m_members[i] || !m_members[i]->isEqualTo( tOther->m_members[i].get() ) )
127+
{
128+
return false;
129+
}
130+
}
131+
else
132+
{
133+
if( tOther->m_members[i] )
134+
{
135+
return false;
136+
}
137+
}
138+
}
139+
140+
return true;
141+
}
142+
143+
void ObjectMatrix::memoryUsage( Object::MemoryAccumulator &a ) const
144+
{
145+
Object::memoryUsage( a );
146+
for( const auto &m : m_members )
147+
{
148+
if( m )
149+
{
150+
a.accumulate( m.get() );
151+
}
152+
}
153+
a.accumulate( sizeof( m_rows ) );
154+
a.accumulate( sizeof( m_columns ) );
155+
}
156+
157+
void ObjectMatrix::hash( MurmurHash &h ) const
158+
{
159+
Object::hash( h );
160+
for( const auto &m : m_members )
161+
{
162+
if( m )
163+
{
164+
m->hash( h );
165+
}
166+
else
167+
{
168+
h.append( 0 );
169+
}
170+
}
171+
h.append( m_rows );
172+
h.append( m_columns );
173+
}

0 commit comments

Comments
 (0)