[仮想の庭・3次元表示 のための、断面画像を生成する], Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり

Python(パイソン) プログラム作ってみた インデックス へ

-----

2024.10.10 presented in [note] ( //note.com/runningWater/ )

----------
1 はじめに

これ以降に記述されている内容は、このようなコンピューター・プログラムを制作した、というような事を、ただ、述べているに過ぎない。

以下の記述を読んだ人が、それを単に参考にする、というのであれば、問題は無いと、思われる。

しかし、記述されている内容に沿って、その人が、そこに記されているのと同様の制作や作業を行った際に、その制作、作業、コンピューターの作動の結果、使用されたコンピューター等、様々な方面において、何らかの問題が発生しない、という保証は、全くない。

その制作、作業、コンピューターの作動の結果、その人や、その人が所属している組織、その人が使用した様々な機器、インフラストラクチャー等の、身の上にどのような事が起ころうとも、私は一切、責任を負わない。

このプログラムは、Python(パイソン) 言語を使って、記述されている。

----------
2 どのようなものを作ったのか

[断面画像を重ね合わせて、物体を3次元表示], Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり

のモジュール群に対して、与える、断面画像を生成する、というようなものを、作ってみた。

このモジュール群により、生成された断面画像のデータを、

[断面画像を重ね合わせて、物体を3次元表示], Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり] モジュール群

に対して、与え、そのモジュールを動かすと、下図のように、表示された。

----------
3 庭は、部分オブジェクトにより、構成

前記の図は、下記の、3個の[部分オブジェクト]によって、描画されている。

[部分オブジェクト]
 [地面]
 [山] (円錐形のように見える部分)
 [石] (褐色の塊のように見える部分)
 
[地面・部分オブジェクト] と [山・部分オブジェクト] は、それぞれ、下記3種類の画像から、構成されている。

(1)部分の断面の画像
(2)部分の径の推移(上下方向での)を示す曲線(を格納する画像)
(3)部分の表面の絵柄を表す画像

下記に、その画像を、記す。左から順に、上記(1)、(2)、(3)の順になっている。

[地面・部分オブジェクト]用

[山・部分オブジェクト]用

[石・部分オブジェクト]は、それぞれの高さでの断面画像の集合により、描画されるように、なっている。

高さ = 5
から
高さ = 24
まで
計、20個の断面画像により、描画される。

その一部を、下記に示す。ファイル名の中の2けたの数字が、その画像が対応する高さを、表している。

CrossSectionalView_05.png

CrossSectionalView_12.png

CrossSectionalView_18.png

この[部分オブジェクト]は、

 [ OneObjectTypeDrawingByCrossSectionalImages モジュール ] (詳細は、後述)により、描画される。
 
このような、
 [複数個の断面画像より、部分の画を描画する、という方式]
も可、と、することにより、
複雑な形状の部分でも、描画することができるだろう、と、思い、このような方式を導入した。

----------
3 このモジュール群の構成

[仮想の館・3次元表示 のための、断面画像を生成する], Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり

を構成しているモジュールの全てを、コピーして、このモジュール群に流用することにした。

それらのうち、下記に対しては、プログラム修正を加えた(詳細は、後述)

 [ MakeImageDatas ]
 [ Prepare ]
 
さらに、下記モジュールを、追加した(詳細は、後述)

 [ OneObjectTypeDrawingByCrossSectionalImages ]

======

以降に、上記各モジュールの内容を、記す。
----------
4 [ MakeImageDatas モジュール]

ファイル名 [ MakeImageDatas.py ]

----------


#import  sys
import  time

import  Prepare

import  OneObjectTypeDrawingByCrossSectionalImages
import  OneObjectTypeDrawingV
import  OneObjectTypeDrawingH

import  ImageDataTwoDimensionHandlingV3

MODULE_NAME = "MakeImageDatas"

global_number_of_Object = 0
global_list_Object_information = [ ]

global_from_Z = 1
global_to_Z     = 90

#=================================
def  make_list_Object_information (  ) :

    function_name = "make_list_Object_information"

    print ( "==================================" )
    print ( "Enter into , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "==================================" )

    global  global_number_of_Object
    global  global_list_Object_information

#******************************************
    global_list_Object_information = [ ]

    #******************************************
              # [ id , name , type , Center_of_Object_location_x , y , mode of radiation V ]
                  #======== Ground ========
    global_list_Object_information   \
        .append ( [ "1"  ,  "Ground" , "H" , 350 , 350 , "B" ] )
                  #======== Mount ========
    global_list_Object_information   \
        .append ( [ "2"  ,  "Mount"   , "V" , 150 , 350 , "B" ] )
                  #======== Stone ========
    global_list_Object_information   \
        .append ( [ "3"  ,  "Stone"    , "C" , 550 , 300 , " " ] )

#******************************************
    global_number_of_Object = len ( global_list_Object_information )
#******************************************

#=================================
def  make_ImageDatas (  ) :

    function_name = "make_ImageDatas"

    print ( "==================================" )
    print ( "Enter into , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "==================================" )
    
    global  global_list_Object_information
    global  global_number_of_Object
    global  global_from_Z
    global  global_to_Z
    
    
    list_Objects = make_all_Objects ( )

    name_of_Object  = global_list_Object_information [ 0 ] [ 1 ]
    list_of_path = Prepare   \
                            .make_path_list ( name_of_Object )

    print ( "==================================" )
    print ( "Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "passed : phase 1"  )
    print ( "list_of_path = "  )
    print ( list_of_path )
    print ( "==================================" )

    Prepare  \
            .make_SectionImageData_of_initial_status ( \
                        list_of_path [ 0 ]   # arg_abs_path_of_ImageData_Basic
                      , list_of_path [ 3 ]   # arg_Part_1_of_abs_path_of_ImageData_output
                      , list_of_path [ 4 ]   #arg_Part_2_of_abs_path_of_ImageData_outpu

                      , global_from_Z
                      , global_to_Z
                                                                          )

    print ( "==================================" )
    print ( "Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "passed : phase 2"  )
    print ( "==================================" )
             #------------------------------------------
    print ( "==================================" )
    print ( "Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "start : phase 3"  )
    print ( "==================================" )

    for  order_number_of_Object   \
                       in  range ( 1 , ( global_number_of_Object + 1 ) ) :

        print ( "**********************************************" )
        print ( "**********************************************" )
        print ( "**********************************************" )
        print ( "Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
        print ( "phase 3 ,order_number_of_Object = " ,  order_number_of_Object )
        print ( "**********************************************" )
        print ( "**********************************************" )
        print ( "**********************************************" )

        time.sleep ( 3 )

        ins_object = list_Objects [  order_number_of_Object - 1 ]
        ins_object  \
               .vary_ImageData_for_all_z (
                     MODULE_NAME    # arg_requester_module
                  ,  function_name    # arg_requester_function
                                                       )

    print ( "==================================" )
    print ( "Exit from , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "==================================" )

#=================================
def  make_all_Objects (  ) :

    function_name = "make_all_Object"

    print ( "==================================" )
    print ( "Enter into , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "==================================" )

    global  global_from_Z
    global  global_to_Z
    global  global_list_Object_information
    global  global_number_of_Object

#******************************************
    make_list_Object_information (  )
            #---------------------------------------

    list_of_Objects = [ ]

    for i in range ( 0 , global_number_of_Object ) :

        print ( "==================================" )
        print ( "Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
        print ( "i = " , i )
        print ( "global_number_of_Object = " ,global_number_of_Object )                            
        print ( "==================================" )

        information_list_of_Object = \
               global_list_Object_information [ i ]
        name_of_Object =  information_list_of_Object [ 1 ]      
        list_of_path = Prepare   \
                                  .make_path_list ( name_of_Object )
                  #----------------------------------------------
        if ( information_list_of_Object [ 2 ] == "C" ) :
                      # [ type of Object] is [drawing By CrossSectional Images ]
            ins_OneObject \
                  = OneObjectTypeDrawingByCrossSectionalImages   \
                        .OneObjectTypeDrawingByCrossSectionalImages (  \
                              MODULE_NAME   # arg_requester_module
                            , function_name     # arg_requester_function

                            , information_list_of_Object [ 0 ]
                            , information_list_of_Object [ 1 ]  #name of Object
                                                 # Center_of_Object_location_x , y
                            , information_list_of_Object [ 3 ]
                            , information_list_of_Object [ 4 ]

#                            , list_of_path [ 0 ]   # arg_abs_path_of_ImageData_Basic

                               #**************************************
                            , list_of_path [ 8 ]   # arg_abs_path_of_directory_for_CrossSectionalView
                               #**************************************

                            , list_of_path [ 3 ]   # arg_Part_1_of_abs_path_of_ImageData_output
                            , list_of_path [ 4 ]   #arg_Part_2_of_abs_path_of_ImageData_output
                                                                )
                   #--------------------------
            list_of_Objects  \
                    .append ( ins_OneObject )
             #----------------------------------------------
        if ( information_list_of_Object [ 2 ] == "H" ) :
                      # [ type of Object] is [drawing Horizantal direction]
            Prepare   \
                .make_TextData_contain_VariationOfRadius ( \
                                       # abs_path_of_VariationOfRadius
                                list_of_path [ 2 ]
                           ,           # abs_path_of_TextData_contain_VariationOfRadius
                                list_of_path [ 5 ]
                                                                            )
                    #---------------------------------------------
            ins_OneObject \
                  = OneObjectTypeDrawingH   \
                        .OneObjectTypeDrawingH (  \
                              MODULE_NAME   # arg_requester_module
                            , function_name     # arg_requester_function

                            , information_list_of_Object [ 0 ]
                            , information_list_of_Object [ 1 ]  #name of Object

                            , information_list_of_Object [ 3 ]
                            , information_list_of_Object [ 4 ]

                            ,  global_from_Z
                            ,  global_to_Z

                            , list_of_path [ 0 ]   # arg_abs_path_of_ImageData_Basic
                            , list_of_path [ 1 ]   # arg_abs_path_of_ImageData_for_drawing_CrossSectionalView
                            , list_of_path [ 6 ]   # arg_abs_path_ForDrawingSurfaceImage

                            , list_of_path [ 3 ]   # arg_Part_1_of_abs_path_of_ImageData_output
                            , list_of_path [ 4 ]   #arg_Part_2_of_abs_path_of_ImageData_output

                            , list_of_path [ 5 ]   # arg_abs_path_of_TextData_contain_VariationOfRadius

                            , information_list_of_Object [ 5 ]  # mode_of_VariationOfRadius
                                                                )
                   #--------------------------
            list_of_Objects  \
                    .append ( ins_OneObject )
             #----------------------------------------------
        if ( information_list_of_Object [ 2 ] == "V" ) :
                        # [ type of Object] is [drawing Vertical direction]
            Prepare   \
                .make_TextData_contain_VariationOfRadius ( \
                                       # abs_path_of_VariationOfRadius
                                list_of_path [ 2 ]
                           ,           # abs_path_of_TextData_contain_VariationOfRadius
                                list_of_path [ 5 ]
                                                                            )
                    #---------------------------------------------
            ins_OneObject \
                  = OneObjectTypeDrawingV   \
                         .OneObjectTypeDrawingV (  \
                                MODULE_NAME   # arg_requester_module
                              , function_name     # arg_requester_function

                              , information_list_of_Object [ 0 ]
                              , information_list_of_Object [ 1 ]  #name of Object

                              , information_list_of_Object [ 3 ]
                              , information_list_of_Object [ 4 ]

                              ,  global_from_Z
                              ,  global_to_Z

                              , list_of_path [ 0 ]   # arg_abs_path_of_ImageData_Basic
                              , list_of_path [ 1 ]   # arg_abs_path_of_ImageData_for_drawing_CrossSectionalView
                              , list_of_path [ 6 ]   # arg_abs_path_ForDrawingSurfaceImage

                              , list_of_path [ 3 ]   # arg_Part_1_of_abs_path_of_ImageData_output
                              , list_of_path [ 4 ]   #arg_Part_2_of_abs_path_of_ImageData_output

                              , list_of_path [ 7 ]   # arg_abs_path_of_TextData_contain_CrossSectionalView
                              , list_of_path [ 5 ]   # arg_abs_path_of_TextData_contain_VariationOfRadius

                              , information_list_of_Object [ 5 ]  # mode_of_VariationOfRadius
                                                                )
                     #-------------------------------------------
            list_of_Objects  \
                    .append ( ins_OneObject )

               #------------------------------------------------------------------------------
        print ( "==================================" )
        print ( "Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
        print ( "one Object has been constructed" )
        print (  "i = " , i )
        print ( "==================================" )

    #-------------------------------------------
    return   list_of_Objects


----------

----------
5 [ Prepare モジュール]

ファイル名 [ Prepare.py ]

----------


import  ImageDataTwoDimensionHandlingV3
import  OneObject
import  DetectCurveInImageData

MODULE_NAME = "Prepare"

#=================================
def  make_path_list ( arg_name_of_Object ) :

    function_name = "make_path_list"

    print ( "==================================" )
    print ( "Enter into , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "arg_name_of_Object = " , arg_name_of_Object )
    print ( "==================================" )

    return_list = [ " " , " " , " " , " " , " " , " "  , " " , " " , " " ]

    path_of_Top   \
                  =   "E:ForPython/ForTest/Test_9V3/"
    path_of_directory_InputImageData = "InputImageData/"

    path_of_directory_OutputImageData = "OutputImageData/"

    path_of_directory_ForEachObject = "ForEachObject/"

    path_of_directory_BasicImageData = "BasicImageData/"
    path_of_file_part_1_BasicImageData = "BasicImageData"

    path_of_directory_CrossSectionalView = "CrossSectionalView/"
    path_of_file_part_1_CrossSectionalView = "CrossSectionalView"

    path_of_directory_VariationOfRadius = "VariationOfRadius/"
    path_of_file_part_1_VariationOfRadius = "VariationOfRadius"

    path_of_directory_ForDrawingSurfaceImage = "ForDrawingSurfaceImage/"
    path_of_file_ForDrawingSurfaceImage = "ForDrawingSurfaceImage.png"

    path_of_directory_DrawingImageData = "DrawingImageData/"
    path_of_file_part_1_DrawingImageData = "DrawingImageData"

    path_of_directory_TextData = "TextData/"

    path_of_file_part_2_for_ImageData = ".png"
    path_of_file_part_2_for_TextData = ".txt"

        #------ abs_path_of_ImageData_Basic ----------------
    return_list [ 0 ] = \
               path_of_Top  \
            + path_of_directory_InputImageData \
            + path_of_directory_BasicImageData  \
            + path_of_file_part_1_BasicImageData  \
            + path_of_file_part_2_for_ImageData

    print ( "return_list [ 0 ] = " + return_list [ 0 ] )

        #------ abs_path_of_CrossSectionalView ----------------
    return_list [ 1 ] = \
               path_of_Top  \
            + path_of_directory_InputImageData \
                   + path_of_directory_ForEachObject  \
                   + arg_name_of_Object + "/"      \
            + path_of_directory_CrossSectionalView  \
            + path_of_file_part_1_CrossSectionalView  \
            + path_of_file_part_2_for_ImageData

    print ( "return_list [ 1 ] = " + return_list [ 1 ] )

        #------ abs_path_of_VariationOfRadius ----------------
    return_list [ 2 ] = \
                path_of_Top  \
             + path_of_directory_InputImageData \
                         + path_of_directory_ForEachObject   \
                         + arg_name_of_Object + "/"     \
             + path_of_directory_VariationOfRadius \
             + path_of_file_part_1_VariationOfRadius  \
             + path_of_file_part_2_for_ImageData

    print ( "return_list [ 2 ] = " + return_list [ 2 ] )

            #---- abs_path_of_ImageData_output_part_1 --------------
    return_list [ 3 ] =  \
                path_of_Top  \
             + path_of_directory_OutputImageData \
             + path_of_directory_DrawingImageData \
             + path_of_file_part_1_DrawingImageData  \
             + "_"

    print ( "return_list [ 3 ] = " + return_list [ 3 ] )

            #---- abs_path_of_ImageData_output_part_2 --------------
    return_list [ 4 ] =  \
                 path_of_file_part_2_for_ImageData

    print ( "return_list [ 4 ] = " + return_list [ 4 ] )

      # ----- abs_path_of_TextData_contain_VariationOfRadius ---------------
    return_list [ 5 ] =  \
             path_of_Top  \
          + path_of_directory_TextData \
                   + path_of_directory_ForEachObject    \
                   + arg_name_of_Object + "/"      \
          + path_of_directory_VariationOfRadius \
          + path_of_file_part_1_VariationOfRadius  \
          + path_of_file_part_2_for_TextData

    print ( "return_list [ 5 ] = " + return_list [ 5 ] )

       # ----- abs_path_of_ForDrawingSurfaceImage ---------------
    return_list [ 6 ] = \
               path_of_Top  \
            + path_of_directory_InputImageData \
                        + path_of_directory_ForEachObject   \
                        + arg_name_of_Object + "/"      \
            + path_of_directory_ForDrawingSurfaceImage  \
            + path_of_file_ForDrawingSurfaceImage

    print ( "return_list [ 6 ] = " + return_list [ 6 ] )
    
          # ----- abs_path_of_TextData_contain_CrossSectionalView ---------------
    return_list [ 7 ] =  \
              path_of_Top  \
           + path_of_directory_TextData \
                   + path_of_directory_ForEachObject    \
                   + arg_name_of_Object + "/"      \
           + path_of_directory_CrossSectionalView \
           + path_of_file_part_1_CrossSectionalView  \
           + path_of_file_part_2_for_TextData

    print ( "return_list [ 7 ] = " , return_list [ 7 ] )
    
            #------ abs_path_of_directory_CrossSectionalView ----------------
    return_list [ 8 ] = \
               path_of_Top  \
            + path_of_directory_InputImageData \
                   + path_of_directory_ForEachObject  \
                   + arg_name_of_Object + "/"      \
            + path_of_directory_CrossSectionalView

    print ( "return_list [ 8 ] = " + return_list [ 8 ] )

    print ( "==================================" )
    print ( "Exit from , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "==================================" )

    return return_list

#=================================
def  make_TextData_contain_VariationOfRadius ( \
                arg_abs_path_of_ImageData
              , arg_abs_path_of_TextData
                               ) :

    function_name = "make_TextData_contain_VariationOfRadius"

    print ( "==================================" )
    print ( "Enter into , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "arg_abs_path_of_ImageData = " , arg_abs_path_of_ImageData )
    print ( "arg_abs_path_of_TextData = " , arg_abs_path_of_TextData )
    print ( "==================================" )

    DetectCurveInImageData  \
        .detect_Curve_in_ImageData ( \
                arg_abs_path_of_ImageData
              , arg_abs_path_of_TextData
               )

    print ( "==================================" )
    print ( "Exit from , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "arg_abs_path_of_ImageData = " , arg_abs_path_of_ImageData )
    print ( "arg_abs_path_of_TextData = " , arg_abs_path_of_TextData )
    print ( "==================================" )

#=================================
def  make_SectionImageData_of_initial_status ( \
           arg_abs_path_of_ImageData_Basic
         , arg_abs_path_of_ImageData_output_part_1
         , arg_abs_path_of_ImageData_output_part_2

         ,  arg_from_Z
         ,  arg_to_Z
                                                            ) :

    function_name = "make_SectionImageData_of_initial_status"

    print ( "==================================" )
    print ( "Enter into , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "arg_abs_path_of_ImageData_Basic = " \
              + arg_abs_path_of_ImageData_Basic )
    print ( "arg_abs_path_of_ImageData_output_part_1 = " \
              + arg_abs_path_of_ImageData_output_part_1 )
    print ( "arg_abs_path_of_ImageData_output_part_2 = " \
              + arg_abs_path_of_ImageData_output_part_2 )
    print ( "==================================" )

    ins_ImageDataTwoDimensionHandling_BasicImage = \
        ImageDataTwoDimensionHandlingV3   \
          .ImageDataTwoDimensionHandlingV3 ( MODULE_NAME , function_name )
    ins_ImageDataTwoDimensionHandling_BasicImage  \
         .load_image_data ( \
                     MODULE_NAME \
                   , function_name
                   , arg_abs_path_of_ImageData_Basic
                     )

    from_Z = arg_from_Z
    to_Z = arg_to_Z

    current_Z = from_Z
    while ( current_Z <= to_Z ) :

        make_and_write_ImageData_for_directed_Z ( \
                current_Z
              , ins_ImageDataTwoDimensionHandling_BasicImage
              , arg_abs_path_of_ImageData_output_part_1
              , arg_abs_path_of_ImageData_output_part_2
                                     )
        print ( "==================================" )
        print ( "Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
        print ( "current_Z = " , current_Z )
        print ( "to_Z = " , to_Z )
        print ( "==================================" )

        current_Z += 1

      #---------------------------------------------------
def  make_and_write_ImageData_for_directed_Z ( \
                arg_z
              , arg_ins_ImageDataTwoDimensionHandling_BasicImage
              , arg_abs_path_of_ImageData_output_part_1
              , arg_abs_path_of_ImageData_output_part_2
                ) :

    function_name = "make_and_write_ImageData_for_directed_Z"

    print ( "==================================" )
    print ( "Enter into , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "arg_z = " , arg_z )
    print ( "==================================" )

    abs_path_of_write = \
            make_abs_path ( \
                arg_z
              , arg_abs_path_of_ImageData_output_part_1
              , arg_abs_path_of_ImageData_output_part_2
                           )
    arg_ins_ImageDataTwoDimensionHandling_BasicImage \
              .write_loaded_image_data_to_directed_path (
                          MODULE_NAME
                        , function_name
                        , abs_path_of_write )

    print ( "==================================" )
    print ( "Exit from , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "Has been written , " + abs_path_of_write )
    print ( "==================================" )

          #------------------------------------------------------------
def  make_abs_path (  \
                     arg_z
                   , arg_abs_path_of_ImageData_output_part_1
                   , arg_abs_path_of_ImageData_output_part_2
                    ) :

    function_name = "make_abs_path"

    print ( "==================================" )
    print ( "Enter into , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "arg_z = " , arg_z  )
    print ( "arg_abs_path_of_ImageData_output_part_1 = " \
              , arg_abs_path_of_ImageData_output_part_1  )
    print ( "arg_abs_path_of_ImageData_output_part_2 = " \
              , arg_abs_path_of_ImageData_output_part_2  )
    print ( "==================================" )

    if ( arg_z < 10 ) :
        string_of_file_order_number = "0" + str ( arg_z )
    else :
        string_of_file_order_number = str ( arg_z )

    return_abs_path_of_ImageDataFile =    \
             arg_abs_path_of_ImageData_output_part_1  \
           + string_of_file_order_number   \
           + arg_abs_path_of_ImageData_output_part_2

    print ( "==================================" )
    print ( "Exit from , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "return_abs_path_of_ImageDataFile = " \
              + return_abs_path_of_ImageDataFile )
    print ( "==================================" )

    return  return_abs_path_of_ImageDataFile

    #------------------------------------------------------------
def  prepare_ImageData_BasicImage ( \
                 arg_abs_path_of_ImageData_Basic ) :

    function_name = "prepare_ImageData_BasicImage"

    print ( "==================================" )
    print ( "Enter into , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "arg_abs_path_of_ImageData_Basic = " \
                + arg_abs_path_of_ImageData_Basic )
    print ( "==================================" )

    return_ins_ImageDataTwoDimensionHandling = \
             ImageDataTwoDimensionHandling  \
                 .ImageDataTwoDimensionHandling ( \
                          MODULE_NAME
                        , function_name
                                           )
    return_ins_ImageDataTwoDimensionHandling  \
           .load_image_data ( \
                          MODULE_NAME
                        , function_name
                        , arg_abs_path_of_ImageData_Basic
                         )

    width_of_BasicImage = \
            return_ins_ImageDataTwoDimensionHandling  \
                        .get_width_of_ImageData (  )
    height_of_BasicImage = \
            return_ins_ImageDataTwoDimensionHandling  \
                        .get_height_of_ImageData (  )

    print ( "==================================" )
    print ( "Exit from , Module = " + MODULE_NAME
                      + " ,  function = " + function_name )
    print ( "width_of_BasicImage = " , width_of_BasicImage )
    print ( "height_of_BasicImage = " , height_of_BasicImage )
    print ( "==================================" )

    return  return_ins_ImageDataTwoDimensionHandling


----------
6 [ OneObjectTypeDrawingByCrossSectionalImage モジュール ]

ファイル名 [ OneObjectTypeDrawingByCrossSectionalImage.py ]

----------


import  os

import  OneObject
import  ImageDataTwoDimensionHandlingV3

#===========================================
class  OneObjectTypeDrawingByCrossSectionalImages  ( OneObject.OneObject )  :

    CV_CLASS_NAME = "OneObjectTypeDrawingByCrossSectionalImages"

    #------------------------------------------------------------
            # definition of constructer

    def __init__( self
                      , arg_requester_module
                      , arg_requester_function

                      , arg_id_of_Object
                      , arg_name_of_Object

                      , arg_Center_of_Object_location_x
                      , arg_Center_of_Object_location_y

#                      , arg_abs_path_of_ImageData_Basic

                      , arg_abs_path_of_directory_ImageData_CrossSectionalImage

                      , arg_Part_1_of_abs_path_of_ImageData_output
                      , arg_Part_2_of_abs_path_of_ImageData_output
                       ):

        methode_name = "constructer"

        print ( "==================================" )
        print ( "Enter into , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "    arg_requester_module = " + arg_requester_module
                   + " , arg_requester_function = " + arg_requester_function )
        print ( "    arg_id_of_Object = " , arg_id_of_Object )
        print ( "    arg_name_of_Object = " , arg_name_of_Object )
        print ( "==================================" )

            #----------------------------------
        self.iv_id_of_Object = arg_id_of_Object
        self.iv_name_of_Object  = arg_name_of_Object

               #TypeDrawingBy [C] rossSectionalImages
        self.iv_type_of_Object = "C"
            #-----------------------------------
        self.iv_Center_of_Object_location_x = arg_Center_of_Object_location_x
        self.iv_Center_of_Object_location_y = arg_Center_of_Object_location_y
             #----------------------------------

#        self.iv_abs_path_of_ImageData_Basic = \
#              arg_abs_path_of_ImageData_Basic
#        print ( "self.iv_abs_path_of_ImageData_Basic = " \
#                      + self.iv_abs_path_of_ImageData_Basic )
#        self.iv_ins_ImageDataTwoDimensionHandling_BasicImage  \
#               = self.prepare_ImageData_BasicImage (  )
             # ----------------------------------
        self.iv_abs_path_of_directory_ImageData_CrossSectionalImage = \
              arg_abs_path_of_directory_ImageData_CrossSectionalImage
        print ( "self.iv_abs_path_of_directory_ImageData_CrossSectionalImage = " \
                      + self.iv_abs_path_of_directory_ImageData_CrossSectionalImage )
              #-----------------------------------------
        self.iv_abs_path_of_ImageData_output_part_1 = \
               arg_Part_1_of_abs_path_of_ImageData_output
        print ( "self.iv_abs_path_of_ImageData_output_part_1 = "
              , self.iv_abs_path_of_ImageData_output_part_1 )
        self.iv_Part_2_of_abs_path_of_ImageData_output = \
                 arg_Part_2_of_abs_path_of_ImageData_output
        print ( "self.iv_Part_2_of_abs_path_of_ImageData_output = "
              , self.iv_Part_2_of_abs_path_of_ImageData_output )

            #-----------------------------------
        self.iv_from_x = 0
        self.iv_to_x = 0
        self.iv_inliment_x = 1
        self.iv_median_x = 0

        self.iv_Center_of_Object_location_x = \
                  arg_Center_of_Object_location_x
             #----------------------------------
        self.iv_from_y  = 0
        self.iv_to_y = 0
        self.iv_inliment_y = 1
        self.iv_median_y = 0

        self.iv_Center_of_Object_location_y = \
                  arg_Center_of_Object_location_y
             #----------------------------------
        self.iv_list_z_value = [ ]
        self.iv_list_abs_path_of_CrossSectionalImage = [ ]
        self.iv_number_of_files_in_directory_CrossSectionalImage = 0

             #----------------------------------
        print ( "==================================" )
        print ( "Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )

        print ( "self.iv_Center_of_Object_location_x = "  \
                     , self.iv_Center_of_Object_location_x )
        print ( "self.iv_Center_of_Object_location_y = "  \
                     , self.iv_Center_of_Object_location_y )
        print ( "==================================" )

        print ( "==================================" )
        print ( "Exit from , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "==================================" )


   #---------------------------------------------------------------------------------
                #*********************************************
                # over written on the methode definion of [Class OneObject]
                #*********************************************
    def vary_ImageData_for_all_z ( self
                               ,  arg_requester_module
                               ,  arg_requester_function ) :

        methode_name = "vary_ImageData_for_all_z"

        print ( "==================================" )
        print ( "Enter into , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "    arg_requester_module = " + arg_requester_module
                   + " , arg_requester_function = " + arg_requester_function )
        print ( "==================================" )

        self.make_list_of_all_file_path_for_CrossSectionalImage ( )

        file_order_number = 1
        while ( file_order_number <= \
                    self.iv_number_of_files_in_directory_CrossSectionalImage ) :

                  #-----------------------------
            z_value = self.prepare_for_directed_file_order_number \
                                             ( file_order_number )
            self.over_draw_on_loaded_image_data ( \
                                       z_value
                                     , self.iv_ins_ImageDataTwoDimensionHandling_for_redrawing
                                     , self.iv_abs_path_of_ImageDataFile_for_redrawing
                                                                       )

            print ( "==================================" )
            print ( "Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
            print ( "file_order_number = " , file_order_number )
            print ( "==================================" )

            file_order_number += 1

#-------------------------------
    def  make_list_of_all_file_path_for_CrossSectionalImage ( self ) :

        methode_name = "make_list_of_all_file_name_for_CrossSectionalImage"

        print ( "==================================" )
        print ( "Enter into , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "==================================" )

        list_name_of_file_for_CrossSectionalImage = \
                 os.listdir ( self.iv_abs_path_of_directory_ImageData_CrossSectionalImage )
        self.iv_number_of_files_in_directory_CrossSectionalImage =   \
                 len ( list_name_of_file_for_CrossSectionalImage )
                   #------------------------------
        self.iv_list_z_value = \
                  [ 0 ] * self.iv_number_of_files_in_directory_CrossSectionalImage
        self.iv_list_abs_path_of_CrossSectionalImage =\
                  [ " " ] * self.iv_number_of_files_in_directory_CrossSectionalImage

        for  i  in range ( 0 , self.iv_number_of_files_in_directory_CrossSectionalImage ) :
            name_of_file = list_name_of_file_for_CrossSectionalImage [ i ]
            self.iv_list_abs_path_of_CrossSectionalImage [ i ] = \
                     self.iv_abs_path_of_directory_ImageData_CrossSectionalImage   \
                  + name_of_file
            self.iv_list_z_value [ i ] = \
                  self.decide_z_value_from_file_name ( name_of_file )

        print ( "==================================" )
        print ( "Exit from , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "self.iv_abs_path_of_directory_ImageData_CrossSectionalImage = "  \
                              ,  self.iv_abs_path_of_directory_ImageData_CrossSectionalImage )
        print ( "self.iv_number_of_files_in_directory_CrossSectionalImage = "  \
                          , self.iv_number_of_files_in_directory_CrossSectionalImage )
        print ( "self.iv_list_z_value = " )
        print ( self.iv_list_z_value )
        print ( "self.iv_list_abs_path_of_CrossSectionalImage = " )
        print ( self.iv_list_abs_path_of_CrossSectionalImage )                          
        print ( "==================================" )
        
        return  self.iv_number_of_files_in_directory_CrossSectionalImage

   #---------------------------------------------------------------------------------
    def  prepare_for_directed_file_order_number ( self , arg_file_order_number  ) :

        methode_name = "prepare_for_directed_file_order_number"

        print ( "==================================" )
        print ( "Enter into , Class = " + \
                 OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "arg_file_order_number = " ,  arg_file_order_number )
        print ( "==================================" )

        z_value =  self.iv_list_z_value  [  arg_file_order_number - 1  ]
                      #--------------------------------
        self.iv_ins_ImageDataTwoDimensionHandling_for_redrawing = \
                        self.get_Drawing_ImageData ( z_value )
              #-------------------------------------------------
        abs_path_of_ImageData_CrossSectionalImage = \
                self.iv_list_abs_path_of_CrossSectionalImage \
                                        [  arg_file_order_number - 1  ]  
        self.iv_ins_ImageDataTwoDimensionHandling_CrossSectionalImage = \
                 ImageDataTwoDimensionHandlingV3   \
                      .ImageDataTwoDimensionHandlingV3 ( \
                                   OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                                ,  methode_name )
        self.iv_ins_ImageDataTwoDimensionHandling_CrossSectionalImage  \
             .load_image_data ( \
                            OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                         ,  methode_name
                         ,  abs_path_of_ImageData_CrossSectionalImage
                                         )
                          #-----------------------------------
        self.iv_from_x = 0
        self.iv_to_x = ( self.iv_ins_ImageDataTwoDimensionHandling_CrossSectionalImage    \
                                     .get_width_of_ImageData (  )     \
                             ) - 1
        self.iv_inliment_x = 1
        self.iv_median_x = int ( ( self.iv_from_x + self.iv_to_x ) / 2.0 )
             #----------------------------------
        self.iv_from_y  = 0
        self.iv_to_y = ( self.iv_ins_ImageDataTwoDimensionHandling_CrossSectionalImage    \
                                 .get_height_of_ImageData (  )    \
                              ) - 1
        self.iv_inliment_y = 1
        self.iv_median_y = int ( ( self.iv_from_y + self.iv_to_y ) / 2.0 )

        print ( "==================================" )
        print ( "Exit from , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "==================================" )

   #---------------------------------------------------------------------------------
    def   over_draw_on_loaded_image_data ( self  \
                                     ,  arg_z
                                     ,  arg_ins_ImageDataTwoDimensionHandling_for_redrawing
                                     ,  arg_abs_path_of_ImageDataFile_for_redrawing
                                                                ) :

        methode_name = "over_draw_on_loaded_image_data"

        print ( "==================================" )
        print ( "Enter into , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "arg_z = " , arg_z )
        print ( "==================================" )

            # ------------ draw each locations ------------
        value_x = self.iv_from_x
        while ( value_x <= self.iv_to_x ) :
            value_y = self.iv_from_y
            while ( value_y <= self.iv_to_y ) :

                self.draw_one_point_on_ImageData ( \
                          value_x
                        , value_y
                        , arg_ins_ImageDataTwoDimensionHandling_for_redrawing
                                                 )

                value_y += self.iv_inliment_y

            value_x += self.iv_inliment_x

           #-------------------------------------
        arg_ins_ImageDataTwoDimensionHandling_for_redrawing   \
                .write_loaded_image_data_to_directed_path (    \
                          OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                        , methode_name
                        , arg_abs_path_of_ImageDataFile_for_redrawing )

        print ( "==================================" )
        print ( "Exit from , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "==================================" )

          #---------------------------------------------------
    def  draw_one_point_on_ImageData ( self \
                       , arg_value_x 
                       , arg_value_y
                       , arg_ins_ImageDataTwoDimensionHandling_Target
                                                            ) :

        methode_name = "draw_one_point_on_ImageData"

        #print ( "==================================" )
        #print ( "Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
        #              + " , methode = " + methode_name )
        #print ( "arg_value_x  = " , arg_value_x )
        #print ( "arg_value_y  = " , arg_value_y )
        #print ( "==================================" )

        list_drawing_location = \
              self.decide_location_of_drawing ( arg_value_x , arg_value_y   )
#        list_vector_from_Center_of_object_to_drawing_location =  [ \
#                             list_drawing_location [ 2 ]     \
#                          ,  list_drawing_location [ 3 ]     \
#                                                                                               ]
              #------------------------------------------------------------
        color_list = \
            self.decide_drawing_color (   \
                                                arg_value_x 
                                              , arg_value_y
                                                   )
            #------------------------------------------
        if ( ( color_list [ 0 ] == "O" )  #Over Area
              or
             ( color_list [ 0 ] == "W" )  #Color = White ( not draw )
          ) :
               # do not draw at this point
            return "N"
                #------------------------------------------
        if ( color_list [ 0 ] == "B" ) :
                               #draw Black
                self.draw_this_point ( \
                      list_drawing_location [ 0 ]
                    , list_drawing_location [ 1 ]
                    , 0 #Blue
                    , 0 #Green
                    , 0 #Red
                    , arg_ins_ImageDataTwoDimensionHandling_Target
                                 )
        else :
                                # draw at this point
              self.draw_this_point ( \
                    list_drawing_location [ 0 ]
                  , list_drawing_location [ 1 ]
                  , color_list [ 1 ] #Blue
                  , color_list [ 2 ] #Green
                  , color_list [ 3 ] #Red
                  , arg_ins_ImageDataTwoDimensionHandling_Target
                                 )

          #---------------------------------------------------
    def  decide_drawing_color ( self \
                                    , arg_value_x 
                                    , arg_value_y
                                              ) :

        methode_name = "decide_drawing_color"

        #print ( "==================================" )
        #print ( "Enter into , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
        #              + " , methode = " + methode_name )
        #print ( "arg_value_x = " , arg_value_x )
        #print ( "arg_value_y = " , arg_value_y )
        #print ( "==================================" )

        return_list  = [ "Y" , 0 , 0 , 0 ]
              # ------------------------------
        color_data = \
              self.iv_ins_ImageDataTwoDimensionHandling_CrossSectionalImage  \
                    .get_data_of_one_pixel ( \
                           OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                         , methode_name
                         , arg_value_x 
                         , arg_value_y 
                                                          )
        return_list [ 1 ] =  color_data [ 0 ]
        return_list [ 2 ] =  color_data [ 1 ]   
        return_list [ 3 ] =  color_data [ 2 ]                                                   
              #-----------------------------------
        if ( ( color_data [ 0 ] > 250 )  \
              and \
             ( color_data [ 1 ] > 250 )  \
              and \
             ( color_data [ 2 ] > 250 )  \
            ) :
                 # White color is set , at this location
                 #   not draw this location
            return_list [ 0 ] = "W"
            return return_list
              #-----------------------------------
        if ( ( color_data [ 0 ] <= 5 )  \
              and \
             ( color_data [ 1 ] <= 5  )  \
              and \
             ( color_data [ 2 ] <= 5  )  \
            ) :
                 # Black color is set , at this location
                 #   draw BlackColor this location
            return_list [ 0 ] = "B"
            return return_list
            #-----------------------------------
                 # normaly color was gotten
        return_list [ 0 ] = "Y"
        return return_list

           #---------------------------------------------------
    def  decide_location_of_drawing ( self \
                          ,  arg_value_x
                          ,  arg_value_y \
                                                    ) :

        methode_name = "decide_location_of_drawing"

        # print ( "==================================" )
        # print ( "Enter into , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
         #              + " , methode = " + methode_name )
        # print ( "arg_value_x = " , arg_value_x )
        # print ( "arg_value_y = " , arg_value_y )
        # print  ( "arg_rate_on_XYPlane = " , arg_rate_on_XYPlane )
        # print ( "==================================" )

        median_to_directed_x = arg_value_x - self.iv_median_x
        median_to_directed_y = arg_value_y - self.iv_median_y

        # print ( "==================================" )
        # print ( "Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
        #               + " , methode = " + methode_name )
        # print ( "self.iv_Center_of_Object_location_x = " , self.iv_Center_of_Object_location_x)
        # print ( "self.iv_Center_of_Object_location_y = " , self.iv_Center_of_Object_location_y )
        # print  ( "median_to_directed_x = " , median_to_directed_x )
        # print  ( "median_to_directed_y = " , median_to_directed_y )
        # print ( "==================================" )

            #--------------------------------
        vector_from_Center_of_object_to_drawing_location = [  \
               median_to_directed_x  \
             ,  \
               median_to_directed_y  \
                                                                                         ]
            #--------------------------------
        w_x =  self.iv_Center_of_Object_location_x   \
                        + vector_from_Center_of_object_to_drawing_location [ 0 ]
        w_y =  self.iv_Center_of_Object_location_y  \
                        + vector_from_Center_of_object_to_drawing_location [ 1 ]

        return_list = [ int ( w_x ) , int ( w_y )   \
                             , int ( vector_from_Center_of_object_to_drawing_location [ 0 ] ) \
                             , int ( vector_from_Center_of_object_to_drawing_location [ 1 ] ) \
                           ]

        #print ( "==================================" )
        #print ( "Exit from , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
        #              + " , methode = " + methode_name )
        #print ( "return_list = " , return_list )
        #print ( "==================================" )

        return return_list

    #------------------------------------------------------------
    def   draw_this_point ( self \
                   , arg_location_on_ImageData_x
                  , arg_location_on_ImageData_y
                  , arg_color_Blue
                  , arg_color_Green
                  , arg_color_Red
                  , arg_ins_ImageDataTwoDimensionHandling_Target
                                          )  :

        methode_name = "draw_this_point"

        # print ( "==================================" )
        # print ( "Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
        #               + " , methode = " + methode_name )
        # print ( "self.iv_Center_of_Object_location_x = " , self.iv_Center_of_Object_location_x)
        # print ( "self.iv_Center_of_Object_location_y = " , self.iv_Center_of_Object_location_y )
        # print  ( "median_to_directed_x = " , median_to_directed_x )
        # print  ( "median_to_directed_y = " , median_to_directed_y )
        # print ( "==================================" )

        arg_ins_ImageDataTwoDimensionHandling_Target  \
              .put_data_of_one_pixel ( \
                         OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                       , methode_name  # arg_requester_function
                              # in the commonly used mathematical XY cordinates
                       , arg_location_on_ImageData_x
                       , arg_location_on_ImageData_y
                       , arg_color_Blue
                       , arg_color_Green
                       , arg_color_Red
                               )

        #print ( "==================================" )
        #print ( "Exit from , Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
        #              + " , methode = " + methode_name )
        #print ( "arg_location_on_ImageData_x = " , arg_location_on_ImageData_x )
        # ( "arg_location_on_ImageData_y = " , arg_location_on_ImageData_y )
        #print ( "arg_color_Blue = " , arg_color_Blue )
        #print ( "arg_color_Green = " , arg_color_Green )
        #print ( "arg_color_Red = " , arg_color_Red )
        #print ( "==================================" )

    #------------------------------------------------------------
    def   decide_z_value_from_file_name ( self \
                   ,  arg_name_of_file
                                          )  :

        methode_name = "decide_z_value_from_file_name"

        location_of_period = arg_name_of_file   \
                                                .find ( "." )
        get_begin_location =  location_of_period - 2
        get_end_location =  get_begin_location + 2

        z_value_string = arg_name_of_file [ get_begin_location  : get_end_location ]



        print ( "==================================" )
        print ( "Class = " + OneObjectTypeDrawingByCrossSectionalImages.CV_CLASS_NAME
                       + " , methode = " + methode_name )
        print ( "arg_name_of_file = " , arg_name_of_file )
        print ( "location_of_period = " , location_of_period )
        print  ( "z_value_string = " , z_value_string )
        print ( "==================================" )

        return ( int (  z_value_string ) )

----------

----------

Python(パイソン) プログラム作ってみた インデックス へ

いいなと思ったら応援しよう!