|
| 1 | +# ========================================================================== |
| 2 | +# |
| 3 | +# Copyright NumFOCUS |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +# ==========================================================================*/ |
| 18 | +import itk |
| 19 | +import numpy as np |
| 20 | + |
| 21 | +Dimension = 3 |
| 22 | +PixelType = itk.Array.D |
| 23 | +NumberOfPoints = 10 |
| 24 | +PixelDataSize = 5 |
| 25 | + |
| 26 | +MeshType = itk.Mesh[PixelType, Dimension] |
| 27 | +mesh = MeshType.New() |
| 28 | + |
| 29 | +# Create Vector Container and Store values in it for each Point |
| 30 | +v = itk.VectorContainer[itk.UL, PixelType].New() |
| 31 | +v.Reserve(NumberOfPoints) |
| 32 | + |
| 33 | +for i in range(NumberOfPoints): |
| 34 | + pixel_data_reference = v.CreateElementAt(i) |
| 35 | + pixel_data_reference.SetSize(PixelDataSize) |
| 36 | + pixel_data_reference.Fill(0) |
| 37 | + pixel_data_reference[0] = i |
| 38 | + pixel_data_reference[4] = i+4 |
| 39 | + |
| 40 | +# Set the point data container |
| 41 | +mesh.SetPointData(v) |
| 42 | + |
| 43 | +assert mesh.GetPointData().Size() == NumberOfPoints |
| 44 | +assert mesh.GetPointData().ElementAt(0)[0] == 0 |
| 45 | +assert mesh.GetPointData().ElementAt(0)[4] == 4 |
| 46 | +assert mesh.GetPointData().ElementAt(2)[0] == 2+0 |
| 47 | +assert mesh.GetPointData().ElementAt(2)[4] == 2+4 |
| 48 | + |
| 49 | +# resize the PixelDataSize to see if it can be altered succesfully |
| 50 | +PixelDataSize = 10 |
| 51 | +for i in range(NumberOfPoints): |
| 52 | + pixel_data_reference = v.CreateElementAt(i) |
| 53 | + pixel_data_reference.SetSize(PixelDataSize) |
| 54 | + pixel_data_reference.Fill(0) |
| 55 | + pixel_data_reference[0] = i |
| 56 | + pixel_data_reference[9] = i+10 |
| 57 | + |
| 58 | +assert mesh.GetPointData().Size() == NumberOfPoints |
| 59 | +assert mesh.GetPointData().ElementAt(0)[0] == 0 |
| 60 | +assert mesh.GetPointData().ElementAt(0)[9] == 10 |
| 61 | +assert mesh.GetPointData().ElementAt(2)[0] == 2+0 |
| 62 | +assert mesh.GetPointData().ElementAt(2)[9] == 2+10 |
0 commit comments