-
-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Adding Test for Array PixelType in Mesh Wrapping
Added test in Python to demonstrate the usage of Array PixelType in Mesh. Usage of Array allows to change the size of pixeldata as per requirements later. Using Array, however breaks the API support for SetElement and SetPointData in PointSet. The only way to alter the data is through reference and for that CreateElementAt method is used in the VectorContainer.
- Loading branch information
1 parent
70351d1
commit d85bb67
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Modules/Core/Mesh/wrapping/test/itkMeshArrayPixelTypeTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# ========================================================================== | ||
# | ||
# Copyright NumFOCUS | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ==========================================================================*/ | ||
import itk | ||
import numpy as np | ||
|
||
Dimension = 3 | ||
PixelType = itk.Array.D | ||
NumberOfPoints = 10 | ||
PixelDataSize = 5 | ||
|
||
MeshType = itk.Mesh[PixelType, Dimension] | ||
mesh = MeshType.New() | ||
|
||
# Create Vector Container and Store values in it for each Point | ||
v = itk.VectorContainer[itk.UL, PixelType].New() | ||
v.Reserve(NumberOfPoints) | ||
|
||
for i in range(NumberOfPoints): | ||
pixel_data_reference = v.CreateElementAt(i) | ||
pixel_data_reference.SetSize(PixelDataSize) | ||
pixel_data_reference.Fill(0) | ||
pixel_data_reference[0] = i | ||
pixel_data_reference[4] = i+4 | ||
|
||
# Set the point data container | ||
mesh.SetPointData(v) | ||
|
||
assert mesh.GetPointData().Size() == NumberOfPoints | ||
assert mesh.GetPointData().ElementAt(0)[0] == 0 | ||
assert mesh.GetPointData().ElementAt(0)[4] == 4 | ||
assert mesh.GetPointData().ElementAt(2)[0] == 2+0 | ||
assert mesh.GetPointData().ElementAt(2)[4] == 2+4 | ||
|
||
# resize the PixelDataSize to see if it can be altered succesfully | ||
PixelDataSize = 10 | ||
for i in range(NumberOfPoints): | ||
pixel_data_reference = v.CreateElementAt(i) | ||
pixel_data_reference.SetSize(PixelDataSize) | ||
pixel_data_reference.Fill(0) | ||
pixel_data_reference[0] = i | ||
pixel_data_reference[9] = i+10 | ||
|
||
assert mesh.GetPointData().Size() == NumberOfPoints | ||
assert mesh.GetPointData().ElementAt(0)[0] == 0 | ||
assert mesh.GetPointData().ElementAt(0)[9] == 10 | ||
assert mesh.GetPointData().ElementAt(2)[0] == 2+0 | ||
assert mesh.GetPointData().ElementAt(2)[9] == 2+10 |