[回転するメタン分子 化学構造 の 動画を作る] , Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり

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

-----

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

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

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

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

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

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

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

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

これまでに、下記の2個のモジュール群を作成した。

モジュール群(1)

[メタン の化学構造を、3次元表示する], Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり

モジュール群(2)

[動画を作る , 動画を読み込む] , Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり

上記で作成されたモジュールを流用して、

 [メタン の化学構造が、回転していく様を、描く、動画] を 作製するモジュール群
 
を、作ることができるのではないかと、考え、そのようなものを、作ってみた。

このモジュール群中の、[ TestVideoHandling ] を起動すると、以下のように、動いていく。

(1) 動画データを作成

下記のような処理を、90回、繰り返す。

 下記(Fig 1) のイメージデータを読み込み、
 そのイメージデータ上に、メタン分子の構造を表す画像を、書き込み、
 それを、1個の動画フレームデータとして、書き出す
 メタン分子の角度を、少し、変える
 
このようにして、90個のフレームから成る、動画データが、作成される。

(2) 動画データを読み込み、特定のフレームの内容を、画像データとして、書き出す

 (1) で作成された動画データを、最初のフレームから順に、読み込み、特定のフレームにさしかかったら、そのフレームの内容を、画像データとして、出力する。(下記 Fig 2 , Fig 3 , Fig 4, Fig 5, Fig 6 ) 

Fig 1


Fig 2


Fig 3


Fig 4


Fig 5


Fig 6


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

このモジュール群は、以下のモジュールより、構成されている。

 (1) DrawingOneSphere
 (2) ErrorProcess
 (3) HiddenLineRemoval
 (4) ImageDataTwoDimensionHandlingV2
 (5) MakeImageData
 (6) MatrixFor3DRotaion
 (7) TestVideoHandling
 (8) VideoHandling
 (9) ViewSpace
 (10) WorldSpace

上記のうち、下記モジュール

 (1) , (3) , (6) , (10)

は、 

 [メタン の化学構造を、3次元表示する], Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり

より流用した(コピーして作った)。

上記のうち、下記モジュール

 (4) , (8)
 
は、 

 [動画を作る , 動画を読み込む] , Python(パイソン) 使って作ってみた ,ソースプログラムリスト あり
 
より流用した(コピーして作った)。

上記のうち、下記モジュール

 (2)
 
は、 

Python(パイソン) ,ソースプログラムリスト あり ,プログラム作ってみた ,[エラー処理] を 行う

で説明したものを、用いた。

上記以外のモジュールの内容について、以降に記す。

----------
4 [ MakeImageData ] , ファイル名 [ MakeImageData.py ]

----------


#********************************************
import ImageDataTwoDimensionHandlingV2
    #  import ImageDataTwoDimensionHandling
#********************************************

import  WorldSpace
import  ViewSpace

MODULE_NAME = "MakeImageData"

global_ins_WorldSpace = " "
global_ins_ViewSpace = " "

     # -----------------------------------------
def   initializing_process (  ) :

    function_name = "initializing_process"

    global  global_ins_WorldSpace
    global_ins_WorldSpace = \
          WorldSpace.WorldSpace ( MODULE_NAME ,  function_name )

    global  global_ins_ViewSpace
    global_ins_ViewSpace = \
          ViewSpace.ViewSpace ( MODULE_NAME ,  function_name )

      #------------------------------------------------------------
def  get_size_of_ViewSpace ( ) :

    function_name = "get_size_of_ViewSpace"

    global  global_ins_ViewSpace
    global_ins_ViewSpace = \
          ViewSpace.ViewSpace ( MODULE_NAME ,  function_name )

    return_list = global_ins_ViewSpace  \
                         .get_size_of_ViewSpace ( )
    return  return_list

     # -----------------------------------------
def  set_rotation_angle_degree ( \
                   arg_rotation_angle_degree_XAxis_to_YAxis
                 , arg_rotation_angle_degree_XAxis_to_ZAxis
                                ) :

    function_name = "set_rotation_angle_degree"

    # print ( "==================================" )
    # print ( "Enter into , Module = " + MODULE_NAME
    #                   + " , function = " + function_name )
    # print (  "arg_rotation_angle_degree_XAxis_to_YAxis = " \
    #               , arg_rotation_angle_degree_XAxis_to_YAxis )
    # print (  "arg_rotation_angle_degree_XAxis_to_ZAxis = " \
    #               ,  arg_rotation_angle_degree_XAxis_to_ZAxis )
    # print ( "==================================" )

    global  global_ins_ViewSpace
    global_ins_ViewSpace    \
            .set_rotation_angle_degree ( \
                       arg_rotation_angle_degree_XAxis_to_YAxis
                     , arg_rotation_angle_degree_XAxis_to_ZAxis )

    # print ( "==================================" )
    # print ( "Exit from , Module = " + MODULE_NAME
    #                   + " , function = " + function_name )
    # print (  "arg_rotation_angle_degree_XAxis_to_YAxis = " \
    #               , arg_rotation_angle_degree_XAxis_to_YAxis )
    # print (  "arg_rotation_angle_degree_XAxis_to_ZAxis = " \
    #               ,  arg_rotation_angle_degree_XAxis_to_ZAxis )
    # print ( "==================================" )

    return_instance = \
        global_ins_ViewSpace  \
            .get_ImageDataTwoDimensionHandling_for_presnting_View_Space ( )

    return return_instance

        # -------------------------------------
        #***********************************************
def make_image_data (  ) :
  #  def make_image_data ( arg_ins_DataToBeHandedOver ) :
        #***********************************************

    function_name = "make_image_data"

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

    global_ins_WorldSpace   \
            .initializing_process ( )
    global_ins_ViewSpace    \
            .initializing_process ( )

    response_list_from_WorldSpace = " "

    process_continue = "Y"
    while ( process_continue == "Y" ) :
              # --------------------------------------
        response_list_from_WorldSpace = \
              global_ins_WorldSpace  \
                     .make_one_point_on_WorldSpace ( )
              # --------------------------------------
        if (  response_list_from_WorldSpace [ 1 - 1 ] == "N" ) :
                   # process reached to end,
                   #    so there is no need to continue process
                process_continue = "N"
                break
               # ----------------------------------------------

        list_x_y_z_in_WorldSpace = [  \
                 response_list_from_WorldSpace [ 2 - 1 ]   # x in WoldSpace  \
              ,  response_list_from_WorldSpace [ 3 - 1 ]   # y in WoldSpace  \
              ,  response_list_from_WorldSpace [ 4 - 1 ]   # z in WoldSpace  \
                                    ]
        list_color_value_for_drawing = [  \
                  response_list_from_WorldSpace [ 5 - 1 ]   # Blue
               ,  response_list_from_WorldSpace [ 6 - 1 ]   # Green
               ,  response_list_from_WorldSpace [ 7 - 1 ]   # Red
                                       ]
        global_ins_ViewSpace  \
             .draw_one_point_in_ViewSpace ( \
                       list_x_y_z_in_WorldSpace
                    ,  list_color_value_for_drawing
                                         )

#***********************************
                 # draw axis line
    global_ins_ViewSpace  \
             .draw_axis_line ( \
                    "X"    # arg_axis_x_y_z
                                )
    global_ins_ViewSpace  \
             .draw_axis_line ( \
                    "Y"    # arg_axis_x_y_z
                                )
    global_ins_ViewSpace  \
             .draw_axis_line ( \
                    "Z"    # arg_axis_x_y_z
                                )
#***********************************

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

    return_instance = \
        global_ins_ViewSpace  \
            .get_ImageDataTwoDimensionHandling_for_presnting_View_Space ( )

    return return_instance

----------

----------
5 [ TestVideoHandling ] , ファイル名 [ TestVideoHandling.py ]

----------


import  ImageDataTwoDimensionHandlingV2
import  VideoHandling

import  MakeImageData

#-----------------------------------

def insert_text_into_image_data ( \
                       arg_ins_ImageDataTwoDimensionHandlingV2
                     , arg_frame_counter ) :

    module_name = "_____"
    function_name = "insert_text_into_image_data"

    arg_ins_ImageDataTwoDimensionHandlingV2   \
           .insert_text_into_ImageData ( \
                          module_name
                        , function_name
                             # in the commonly used mathematical XY cordinates
                        , 200   # arg_x_on_ImageData_space
                        , 300    #arg_y_on_ImageData_space

                        , ( "frame number = " + str ( arg_frame_counter ) )

                        , 10     # arg_font_color_Blue
                        , 60     # arg_font_color_Green
                        , 220   #arg_font_color_Red
                                   )

#======================================

# Test for VideoHandling Class

module_name = "___"
function_name = "Test"

MakeImageData   \
        .initializing_process (  )


size_of_ViewSpace = MakeImageData  \
                        .get_size_of_ViewSpace ( )

    # --------------------------------------------------
      # construct a instance of VideoHandling Class
ins_VideoHandling = VideoHandling  \
                         .VideoHandling (  module_name
                                   , function_name )

ins_VideoHandling  \
        .prepare_for_output_VideoData ( \
                  module_name
                , function_name
                , "E:/ForPython/ForTest/Test_7/Test.mp4"
                , size_of_ViewSpace [ 0 ] # width_of_ViewSpace
                , size_of_ViewSpace [ 1 ] # height_of_ViewSpace
                                   )
      # ======================

           # ----------- output VideoData -------------
rotation_angle_degree_XAxis_to_YAxis = 0.0
rotation_angle_degree_XAxis_to_ZAxis = 0.0
rotation_angle_degree_incliment = 5.0

frame_counter = 1
while ( frame_counter <= 90 ) :

    print ( "***********************************************************" )
    print ( "***********************************************************" )
    print ( "Module = " + module_name        \
                + " , funtion = " + function_name )
    print ( "frame_counter = " , frame_counter )
    print ( "rotation_angle_degree_XAxis_to_YAxis = "  \
               , rotation_angle_degree_XAxis_to_YAxis )
    print ( "rotation_angle_degree_XAxis_to_ZAxis = "  \
               , rotation_angle_degree_XAxis_to_ZAxis )
    print ( "***********************************************************" )

    MakeImageData   \
        .set_rotation_angle_degree ( \
                   rotation_angle_degree_XAxis_to_YAxis
                 , rotation_angle_degree_XAxis_to_ZAxis
                                )
    ins_ImageDataTwoDimensionHandlingV2  \
       = MakeImageData   \
                .make_image_data (  )
    insert_text_into_image_data ( \
                       ins_ImageDataTwoDimensionHandlingV2
                     , frame_counter )
    ins_VideoHandling  \
          .write_one_frame_data_for_output_VideoData ( \
                   module_name
                 , function_name
                 , ins_ImageDataTwoDimensionHandlingV2
                                            )

    frame_counter += 1

    w_angle_degree = rotation_angle_degree_XAxis_to_YAxis \
                                           + rotation_angle_degree_incliment
    if ( w_angle_degree >= 360 ) :
        rotation_angle_degree_XAxis_to_YAxis = 0.0
    else :
        rotation_angle_degree_XAxis_to_YAxis = w_angle_degree

    w_angle_degree = rotation_angle_degree_XAxis_to_ZAxis \
                                           + rotation_angle_degree_incliment
    if ( w_angle_degree >= 360 ) :
        rotation_angle_degree_XAxis_to_ZAxis = 0.0
    else :
        rotation_angle_degree_XAxis_to_ZAxis = w_angle_degree


ins_VideoHandling  \
        .terminate_writing_for_output_VideoData ( module_name
                                                      , function_name )

#================================
           # ----------- input VideoData -------------

ins_VideoHandling  \
        .prepare_for_input_VideoData ( \
                  module_name
                , function_name
                , "E:/ForPython/ForTest/Test_7/Test.mp4"
                                   )

process_continue = "Y"

frame_counter = 1
while ( process_continue == "Y" ) :

    result_value , ins_ImageDataTwoDimensionHandlingV2 \
         =  ins_VideoHandling  \
              .read_one_frame_data_of_VideoData ( \
                      module_name
                    , function_name
                                               )

    print (  "result_value = " , result_value )

    if ( result_value == "E" ) :
             # reached to data end
        process_continue = "N"
        break

    width_of_loaded_image_data \
       = ins_ImageDataTwoDimensionHandlingV2 \
            .get_width_of_ImageData ( )
    height_of_loaded_image_data \
       = ins_ImageDataTwoDimensionHandlingV2 \
            .get_height_of_ImageData ( )

    print (  "width_of_loaded_image_data = " , width_of_loaded_image_data )
    print (  "height_of_loaded_image_data = " , height_of_loaded_image_data )
    print ( "frame_counter = " , frame_counter )

        # write image of frame
    if ( ( frame_counter == 1 )       \
         or                            \
         ( frame_counter == 2 )       \
         or                            \
         ( frame_counter == 3 )      \
                  or                            \
         ( frame_counter == 4 )      \
                  or                            \
         ( frame_counter == 5 )      \
       ) :
        ins_ImageDataTwoDimensionHandlingV2 \
               .write_loaded_image_data_to_directed_path ( \
                      module_name
                    , function_name
                    , "E:/ForPython/ForTest/Test_7/output"  \
                         + "_" + str ( frame_counter ) + ".png" )

    frame_counter += 1

    #------------------------

ins_VideoHandling  \
        .terminate_reading_for_input_VideoData ( module_name
                                                      , function_name )

    #==================================================



----------

----------
6 [ ViewSpace ] , ファイル名 [ ViewSpace.py ]

----------


import ImageDataTwoDimensionHandlingV2
import MatrixFor3DRotaion
import HiddenLineRemoval

#========================================
class ViewSpace :

    CV_CLASS_NAME = "ViewSpace"

    #------------------------------------------------------------
    # cordinate system in World Space
    #   x + ---> to forward side
    #   y + ---> to right side
    #   Z + ---> to upper side

    #--View ----------------------------------------------------------
    # dordinate system in View Space
    #   X + ---> to right side
    #   Y + ---> to upper side
    # origin located at left under corner of window

    #--------------------------------
        # definition of constructer
    def __init__( self
                , arg_requester_module
                , arg_requester_function
                                ) :

        methode_name = "constructer"

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

        self.iv_ins_MatrixFor3DRotaion = " "
        self.iv_rotation_angle_degree_XAxis_to_YAxis = 0
        self.iv_rotation_angle_degree_XAxis_to_ZAxis = 0

        self.iv_ins_HiddenLineRemoval = " "
                 #----------------------------------

        self.iv_ins_ImageDataTwoDimensionHandling_for_presnting_View_Space = \
               ImageDataTwoDimensionHandlingV2  \
                     .ImageDataTwoDimensionHandlingV2 ( \
                               ViewSpace.CV_CLASS_NAME
                             , methode_name )
                    #---------------------
        self.iv_abs_path_of_ImageDataFile     \
            = "E:ForPython/ForTest/Test_7/BaseImage.png"
        self.iv_ins_ImageDataTwoDimensionHandling_for_presnting_View_Space \
               .load_image_data (
                         ViewSpace.CV_CLASS_NAME
                       , methode_name
                       , self.iv_abs_path_of_ImageDataFile
                            )
               #---------------------
        self.iv_width_of_ViewSpace = \
             self.iv_ins_ImageDataTwoDimensionHandling_for_presnting_View_Space \
                .get_width_of_ImageData ( )
        self.iv_height_of_ViewSpace = \
             self.iv_ins_ImageDataTwoDimensionHandling_for_presnting_View_Space \
                .get_height_of_ImageData ( )
               #---------------------
        self.iv_half_width_of_ViewSpace = ( int ) ( self.iv_width_of_ViewSpace / 2.0 )
        self.iv_half_height_of_ViewSpace = ( int ) ( self.iv_height_of_ViewSpace / 2.0 )

        self.iv_x_value_of_perspective_drawing_vanishing_point  = float ( -1000 )
        self.iv_drawing_color_sleshold = 5

        #------------------------------------------------

        print ( "==================================" )
        print ( "Exit from , Class = " + ViewSpace.CV_CLASS_NAME
                      + " , methode = " + methode_name )
        print ( "    arg_requester_module = " + arg_requester_module
                   + " , arg_requester_function = " + arg_requester_function )
        print ( "==================================" )

        return

        #------------------------------------------------------------
    def  get_size_of_ViewSpace ( self ) :

        return_list = [ \
                         self.iv_width_of_ViewSpace  \
                       , self.iv_height_of_ViewSpace
                        ]

        return  return_list

        #------------------------------------------------------------
    def  get_ImageDataTwoDimensionHandling_for_presnting_View_Space ( \
                      self ) :

        return self.iv_ins_ImageDataTwoDimensionHandling_for_presnting_View_Space

        #------------------------------------------------------------
    def  set_rotation_angle_degree ( \
                       self
                     , arg_rotation_angle_degree_XAxis_to_YAxis
                     , arg_rotation_angle_degree_XAxis_to_ZAxis
                                ) :

        methode_name = "set_rotation_angle_degree_XAxis_to_YAxis"

        self.iv_rotation_angle_degree_XAxis_to_YAxis = \
                float ( arg_rotation_angle_degree_XAxis_to_YAxis )
        self.iv_rotation_angle_degree_XAxis_to_ZAxis = \
                float ( arg_rotation_angle_degree_XAxis_to_ZAxis )

                # ------ make rotation instance ---------------
        self.iv_ins_MatrixFor3DRotaion = \
            MatrixFor3DRotaion          \
               .MatrixFor3DRotaion (
                   ViewSpace.CV_CLASS_NAME  # arg_requester_module
                 , methode_name     # arg_requester_function
                          # first rotation
                 , "Z"       # arg_first_rotation_around_axis
                 , self.iv_rotation_angle_degree_XAxis_to_YAxis

                          # second rotation
                 , "Y"       # arg_need_Y_N_second_rotation

                 , "Y"        # arg_second_rotation_around_axis
                 , self.iv_rotation_angle_degree_XAxis_to_ZAxis
                               )

    #------------------------------------------------------------
    def  initializing_process ( \
                       self
                                ) :

        methode_name = "initializing_process"

            # reload image_data
        self.iv_ins_ImageDataTwoDimensionHandling_for_presnting_View_Space \
               .load_image_data (
                         ViewSpace.CV_CLASS_NAME
                       , methode_name
                       , self.iv_abs_path_of_ImageDataFile
                            )

            #--- prepare area for HiddenLineRemoval ---

        # print ( "==================================" )
        # print ( "Class = " + ViewSpace.CV_CLASS_NAME
        #               + " , methode = " + methode_name )
        # print ( "self.iv_x_value_of_perspective_drawing_vanishing_point = "  \
        #         , self.iv_x_value_of_perspective_drawing_vanishing_point )
        # print ( "==================================" )

        self.iv_ins_HiddenLineRemoval = \
              HiddenLineRemoval  \
                .HiddenLineRemoval ( \
                    ViewSpace.CV_CLASS_NAME
                  , methode_name

                  , self.iv_x_value_of_perspective_drawing_vanishing_point
                  , self.iv_width_of_ViewSpace
                  , self.iv_height_of_ViewSpace
                                 )
        return

    #------------------------------------------------------------
    def  draw_one_point_in_ViewSpace ( \
                       self
                    ,  arg_list_x_y_z_in_WorldSpace
                    ,  arg_list_color_value_for_drawing
                                ) :

        methode_name = "draw_one_point_in_ViewSpace"

        # print ( "==================================" )
        # print ( "Enter into , Class = " + ViewSpace.CV_CLASS_NAME
        #               + " , methode = " + methode_name )
        # print ( "arg_list_x_y_z_in_WorldSpace = " )
        # print ( arg_list_x_y_z_in_WorldSpace  )
        # print ( "arg_list_color_value_for_drawing = " )
        # print ( arg_list_color_value_for_drawing )
        # print ( "==================================" )

        #-------------- not draw color? -------------------------
        if ( ( arg_list_color_value_for_drawing [ 0 ] \
                  < int ( self.iv_drawing_color_sleshold ) )\
                 and                                                                                      \
              ( arg_list_color_value_for_drawing [ 1 ] \
                  < int ( self.iv_drawing_color_sleshold ) )\
                 and                                                                                      \
              ( arg_list_color_value_for_drawing [ 2 ] \
                  < int ( self.iv_drawing_color_sleshold ) )\
            ) :
                #not draw this point
            return "N"

         #------------------------------------
        drawing_location_in_ViewSpace = \
            self.calculate_drawing_location_in_ViewSpace (  \
                    arg_list_x_y_z_in_WorldSpace
                                               )

        # print ( "==================================" )
        # print ( "Class = " + ViewSpace.CV_CLASS_NAME
        #               + " , methode = " + methode_name )
        # print ( "arg_list_x_y_z_in_WorldSpace = " )
        # print ( arg_list_x_y_z_in_WorldSpace  )
        # print ( "drawing_location_in_ViewSpace = " )
        # print ( drawing_location_in_ViewSpace )
        # print ( "==================================" )

        it_must_be_drawed_Y_N_about_hidden_line = \
            self.iv_ins_HiddenLineRemoval    \
                .detect_and_set_x_value_of_directed_location ( \
                       ViewSpace.CV_CLASS_NAME
                    ,  methode_name
                    ,  drawing_location_in_ViewSpace [ 0 ]   # arg_X_in ViewSpace
                    ,  drawing_location_in_ViewSpace [ 1 ]   # arg_Y_in ViewSpace
                    ,  arg_list_x_y_z_in_WorldSpace [ 0 ]   #arg_x_in_WorldSpace
                                   )

        # print ( "==================================" )
        # print ( "Class = " + ViewSpace.CV_CLASS_NAME
        #               + " , methode = " + methode_name )
        # print ( "it_must_be_drawed_Y_N_about_hidden_line = "  \
        #          , it_must_be_drawed_Y_N_about_hidden_line )
        # print ( "==================================" )

        if ( it_must_be_drawed_Y_N_about_hidden_line == "Y" ) :
               # ------ draw one point --------------
            self.draw_one_point_at_directed_location_in_ViewSpace (  \
                    [ drawing_location_in_ViewSpace [ 0 ]   \
                    , drawing_location_in_ViewSpace [ 1 ]   \
                    ]
                 ,  arg_list_color_value_for_drawing
                                )
            return "Y"

        return "N"

    #------------------------------------------------------------
    def  draw_axis_line ( \
                       self
                    ,  arg_axis_x_y_z
                                ) :

        methode_name = "draw_axis_line"

        # print ( "==================================" )
        # print ( "Enter into , Class = " + HiddenLineRemoval.CV_CLASS_NAME
        #               + " , methode = " + methode_name )
        # print ( "    arg_requester_module = " + arg_requester_module
         #           + " , arg_requester_function = " + arg_requester_function )
        # print ( "    arg_X_in ViewSpace = "  \
        #          + str ( arg_X_in ViewSpace )
        # print ( "    arg_Y_in ViewSpace = " +  str ( arg_Y_in ViewSpace ) )
        # print ( "    arg_x_in_WorldSpace = " +  str ( arg_x_in_WorldSpace ) )
        # print ( "==================================" )

        list_start_point_x_y_z = [ 0  ,  0  , 0 ]
        list_end_point_x_y_z = [ 0  ,  0  , 0 ]
        if ( arg_axis_x_y_z == "X" ) :
           list_end_point_x_y_z [ 0 ] = 120
        if ( arg_axis_x_y_z == "Y" ) :
           list_end_point_x_y_z [ 1 ] = 120
        if ( arg_axis_x_y_z == "Z" ) :
           list_end_point_x_y_z [ 2 ] = 120

                    #------------------------------------
        drawing_location_start_point_in_ViewSpace = \
            self.calculate_drawing_location_in_ViewSpace (  \
                    list_start_point_x_y_z
                                               )
        drawing_location_end_point_in_ViewSpace = \
            self.calculate_drawing_location_in_ViewSpace (  \
                    list_end_point_x_y_z
                                               )

        self.iv_ins_ImageDataTwoDimensionHandling_for_presnting_View_Space \
             .insert_line_figure_into_ImageData (
                     ViewSpace.CV_CLASS_NAME  # arg_requester_module
                   , methode_name  # arg_requester_function
                              # in the commonly used mathematical XY cordinates
                   , drawing_location_start_point_in_ViewSpace [ 0 ] \
                          # arg_From_x_on_ImageData_space
                   , drawing_location_start_point_in_ViewSpace [ 1 ]  \
                          # arg_From_y_on_ImageData_space
                   , drawing_location_end_point_in_ViewSpace [ 0 ]  \
                                 # arg_To_x_on_ImageData_space
                   , drawing_location_end_point_in_ViewSpace [ 1 ]  \
                                 # arg_To_y_on_ImageData_space

                   , 3    # arg_thickness_of_line_figure

                   , 20  # arg_color_Blue
                   , 10  # arg_color_Green
                   , 220 # arg_color_Red
                                   )

        self.iv_ins_ImageDataTwoDimensionHandling_for_presnting_View_Space \
               .insert_text_into_ImageData (
                     ViewSpace.CV_CLASS_NAME  # arg_requester_module
                   , methode_name  # arg_requester_function
                              # in the commonly used mathematical XY cordinates
                   , drawing_location_end_point_in_ViewSpace [ 0 ]  \
                                 # arg_To_x_on_ImageData_space
                   , drawing_location_end_point_in_ViewSpace [ 1 ]  \

                   , arg_axis_x_y_z

                   , 20  # arg_color_Blue
                   , 10  # arg_color_Green
                   , 220 # arg_color_Red
                                   )

        return

    #------------------------------------------------------------
    def  calculate_drawing_location_in_ViewSpace (  \
                         self
                      ,  arg_list_x_y_z_in_WorldSpace
                                               ) :

                 # do rotation
        list__x_y_z_after_rotation = \
            self.iv_ins_MatrixFor3DRotaion    \
               .calculate_cordinate_after_rotation (    \
                     arg_list_x_y_z_in_WorldSpace
                                            )
               # x in WorldSpace
        w1 = list__x_y_z_after_rotation [ 0 ] \
                -  self.iv_x_value_of_perspective_drawing_vanishing_point
        w2 = 0 - self.iv_x_value_of_perspective_drawing_vanishing_point

        rate_of_magnification = w1 / w2

        w1_X = list__x_y_z_after_rotation [ 1 ]    # y cordinate value
        w1_Y = list__x_y_z_after_rotation [ 2 ]    # z cordinate value

        w2_X = w1_X * rate_of_magnification
        w2_Y = w1_Y * rate_of_magnification

        drawing_location_X_in_ViewSpace = \
             int ( self.iv_half_width_of_ViewSpace + w2_X )
        drawing_location_Y_in_ViewSpace = \
             int ( self.iv_half_height_of_ViewSpace + w2_Y )

        return_list = [ drawing_location_X_in_ViewSpace   \
                     ,  drawing_location_Y_in_ViewSpace ]

        return return_list

    #------------------------------------------------------------
    def  draw_one_point_at_directed_location_in_ViewSpace (  \
                               self
                            ,  arg_list_X_Y_in_ViewSpace
                            ,  arg_list_color_value_for_drawing
                                ) :

        methode_name = "draw_one_point_at_directed_location_in_ViewSpace"

        # print ( "==================================" )
        # print ( "Class = " + ViewSpace.CV_CLASS_NAME
        #               + " , methode = " + methode_name )
        # print ( "arg_list_X_Y_in_ViewSpace = " )
        # print ( arg_list_X_Y_in_ViewSpace )
        # print ( "arg_list_color_value_for_drawing = " )
        # print ( arg_list_color_value_for_drawing )
        # print ( "==================================" )

        self.iv_ins_ImageDataTwoDimensionHandling_for_presnting_View_Space \
             .put_data_of_one_pixel ( \
                      ViewSpace.CV_CLASS_NAME  # arg_requester_module
                    , methode_name     # arg_requester_function

                           # in the commonly used mathematical XY cordinates
                    , arg_list_X_Y_in_ViewSpace [ 0 ] # arg_x_on_ImageData_space
                    , arg_list_X_Y_in_ViewSpace [ 1 ] # arg_Y_on_ImageData_space

                    , arg_list_color_value_for_drawing [ 0 ]  # arg_color_data_Blue
                    , arg_list_color_value_for_drawing [ 1 ]  # arg_color_data_Green
                    , arg_list_color_value_for_drawing [ 2 ]  # arg_color_data_Red
                         )

----------

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


この記事が気に入ったらサポートをしてみませんか?