MCPcopy Create free account
hub / github.com/ImageEngine/cortex / testVariableIndexedView

Function testVariableIndexedView

src/IECoreScene/bindings/PrimitiveBinding.cpp:68–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66 }
67
68void testVariableIndexedView()
69{
70 IECoreScene::PrimitivePtr primitive = new IECoreScene::MeshPrimitive();
71 primitive->variables["P"] = PrimitiveVariable(
72 IECoreScene::PrimitiveVariable::Interpolation::Vertex, new IECore::V3fVectorData( {Imath::V3f( 0, 0, 0 ), Imath::V3f( 1, 2, 3 )} )
73 );
74
75 // check we get an view if type & interpolation are compatible
76 {
77 std::optional<PrimitiveVariable::IndexedView<Imath::V3f>> optionalIndexedView = primitive->variableIndexedView<IECore::V3fVectorData>(
78 "P", IECoreScene::PrimitiveVariable::Interpolation::Vertex
79 );
80
81 if( optionalIndexedView )
82 {
83 PrimitiveVariable::IndexedView<Imath::V3f> indexedView = *optionalIndexedView;
84
85 IECORETEST_ASSERT( indexedView.size() == 2 );
86 IECORETEST_ASSERT( indexedView[0] == Imath::V3f( 0, 0, 0 ) );
87 IECORETEST_ASSERT( indexedView[1] == Imath::V3f( 1, 2, 3 ) );
88 }
89 else
90 {
91 IECORETEST_ASSERT( false );
92 }
93
94 // If requiredInterpolation = Invalid matches any interpolation
95 std::optional<PrimitiveVariable::IndexedView<Imath::V3f>> optionalIndexedView2 = primitive->variableIndexedView<IECore::V3fVectorData>(
96 "P", IECoreScene::PrimitiveVariable::Interpolation::Invalid
97 );
98
99 if( optionalIndexedView2 )
100 {
101 PrimitiveVariable::IndexedView<Imath::V3f> indexedView = *optionalIndexedView2;
102
103 IECORETEST_ASSERT( indexedView.size() == 2 );
104 IECORETEST_ASSERT( indexedView[0] == Imath::V3f( 0, 0, 0 ) );
105 IECORETEST_ASSERT( indexedView[1] == Imath::V3f( 1, 2, 3 ) );
106 }
107 else
108 {
109 IECORETEST_ASSERT( false );
110 }
111 }
112
113 // missing primvar
114 {
115 {
116 std::optional<PrimitiveVariable::IndexedView<Imath::V3f>> optionalIndexedView = primitive->variableIndexedView<IECore::V3fVectorData>(
117 "MISSING", IECoreScene::PrimitiveVariable::Interpolation::Vertex
118 );
119
120 IECORETEST_ASSERT( !optionalIndexedView );
121 }
122
123 bool exceptionRaised = false;
124 try
125 {

Callers

nothing calls this directly

Calls 3

PrimitiveVariableFunction · 0.85
whatMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected