Skip to content

Commit

Permalink
ENH: Add IsPixelInsideRegion Python example
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Mar 17, 2021
1 parent 34633b2 commit b9b630b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/Core/Common/CreateASize/Documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ Create a Size
Synopsis
--------


Create a itk::Size, which represents the size of a region in an itk::Image.


Results
-------

Output::

[0, 0]
[1, 2]

Expand Down
8 changes: 7 additions & 1 deletion src/Core/Common/IsPixelInsideRegion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ install( TARGETS IsPixelInsideRegion
COMPONENT Runtime
)

install( FILES Code.cxx CMakeLists.txt
install( FILES Code.cxx Code.py CMakeLists.txt
DESTINATION share/ITKExamples/Code/Core/Common/IsPixelInsideRegion
COMPONENT Code
)

enable_testing()
add_test( NAME IsPixelInsideRegionTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/IsPixelInsideRegion )

if(ITK_WRAP_PYTHON)
add_test(NAME IsPixelInsideRegionPython
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
)
endif()
50 changes: 50 additions & 0 deletions src/Core/Common/IsPixelInsideRegion/Code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python

# 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

Dimension = 2

SizeType = itk.Size[Dimension]
size = SizeType()
size.Fill(3)

IndexType = itk.Index[Dimension]
start = IndexType()
start.Fill(0)

RegionType = itk.ImageRegion[Dimension]
region = RegionType(start, size)

testPixel1 = IndexType()
testPixel1[0] = 1
testPixel1[1] = 1

testPixel2 = IndexType()
testPixel2[0] = 6
testPixel2[1] = 6

print(testPixel1, end=" ")
if region.IsInside(testPixel1):
print("Inside")
else:
print("Outside")

print(testPixel2, end=" ")
if region.IsInside(testPixel2):
print("Inside")
else:
print("Outside")
7 changes: 7 additions & 0 deletions src/Core/Common/IsPixelInsideRegion/Documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ Output::
Code
----

Python
......

.. literalinclude:: Code.py
:language: python
:lines: 1, 16-

C++
...

Expand Down

0 comments on commit b9b630b

Please sign in to comment.