コンピューター・プログラム 制作 インデックス
[複数 の 断面図画像 を与えて 3次元 立体 表示] という制作テーマにより、コンピューター・プログラムを制作しました。
以下に、その様を記述しますが、その記述内容は、このようなコンピューター・プログラムを制作した、それを動かしたら、このような結果になった、というような事を、ただ、淡々と述べているに過ぎません。
下記の記述をお読みになった方が、それを単に参考にする、というのであれば、問題は無いと思われます。
しかし、記述されている内容に沿って、その方がそこに記されているのと同様の制作や作業を行われた際に、その制作や作業の結果、使用されたコンピューター等、様々な方面において、何らかの問題が発生しない、という保証は、全くありません。
その作業の結果、その方や、その方が使用された様々な器機、インフラ等の身の上にどのような事が起ころうとも、私は一切、責任を負いません。
------------
1 できたもの
制作作業の結果、できたのが、下記のようなコンピューター・プログラムです。
まず、10個の画像を制作し、所定のフォルダー中に格納しておきます。
画像には、L01.png , L02.png , L03.png ・・・ というように、連番でファイル名を与えておくようにします。
Fig1
これらの画像は、架空の山の各標高での断面図を示していると思ってください。
例えば、
L01.png は 標高0メートル での断面図
L02.png は 標高100メートル での断面図
L03.png は 標高200メートル での断面図
L04.png は 標高300メートル での断面図
・・・
というような、かんじです。
その後、このコンピューター・プログラムを起動すると、上記の断面図をもとにして、山のおおよその形状が、下記のように3次元表示されました。
Fig2
[For Data Input] 画面は、プログラムに対する操作の指示を行うためのものです。これを使って、
山を眺める角度を変えたら、示される形状が、下記のように変化しました。
Fig3
L01.png , L02.png 等の画像セットを、下記のように変えてみました、ピラミッドみたいな形を表示してくれるかな、と思い。。
Fig4
すると、下記のように表示されました。
Fig5
Fig6
------------
2 使用したコンピューターとソフトウェア
この、コンピューター・プログラムを制作・実行するために使用したものは、下記の通りです。
コンピューター
CPU : Core(TM) i7-7700HQ
メモリー : 16 GB
Operating System : Windows 10 Home, 64ビットオペレーティングシステム
OpenCV3
opencv-3.4.3-vc14_vc15.exe
Java
jdk-8u181-windows-x64.exe
[opencv3] と [Java] を組み合わせて使用する方法については、過去に発表ずみです。
その内容を読みたい方は、
[コンピューター・プログラム 制作 インデックス]にアクセスし(このページの先頭と末尾に、それへのリンクがあります)、
そこから、下記にアクセスしてください。
[開発費用ゼロ コンピューターグラフィックスによる動画制作 Java OpenCV3 Eclipse を使って]
------------
3 ソースリスト
このコンピューター・プログラムのソースリストを、以下に記します。
複数個のファイルに分割して記述しました。
==============================
Test3.java
--------------------------
//for using OpenCV3
import org.opencv.core.Core;
public class Test3 {
private static String mv_this_Class_name = "Test3" ;
public static void main ( String[] args ) {
String this_methode_name = "main" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
//prepare for using OpenCV3
prepare ( ) ;
//initialize value
Bridge.cv_Drawing_Scale_of_Showing_Image = 1.0 ;
Bridge.cv_angle_around_Z = 30.0 ;
Bridge.cv_angle_around_Y = -15.0 ;
//make instance of image data processing
Procc ins_Procc= new Procc ( ) ;
//set the instance into Mediater class
Mediater.set_Procc ( ins_Procc ) ;
//make instance for data input
JFrameDataInput ins_JFrameDataInput
= new JFrameDataInput (
//width of Frame
1000
//height of Frame
, 100
//topLeft Location x of Frame
, 1
//topLeft Location y of Frame
, 1
) ;
ins_JFrameDataInput.setVisible ( true ) ;
//set the instance into Mediater class
Mediater.set_JFrameDataInput ( ins_JFrameDataInput ) ;
//make instance for showing image data
JFrameShowImageData ins_JFrameShowImageData
= new JFrameShowImageData (
//title of frame
"For Show Image Data"
//width of Frame
, 1000
//height of Frame
, 1000
//topLeft Location x of Frame
, 1
//topLeft Location y of Frame
, 95
) ;
ins_JFrameShowImageData.setVisible ( true ) ;
//set the instance into Mediater class
Mediater.set_JFrameShowImageData ( ins_JFrameShowImageData ) ;
Mediater.do_repaint_process ( ) ;
System.out.println ( "Exit from Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( "----------------------------------" ) ;
}
//=====================
//prepare
//=====================
private static void prepare ( ) {
String this_methode_name = "prepare" ;
System.out.println ( " ----------------------------------" ) ;
System.out.println ( "Enter into Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.loadLibrary ( Core.NATIVE_LIBRARY_NAME ) ;
System.out.println ( "Done : System.loadLibrary" ) ;
System.out.println ( "Exit from Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( " ----------------------------------" ) ;
}
}
-------------------------
==============================
Bridge.java
--------------------------
public class Bridge {
public static double cv_Drawing_Scale_of_Showing_Image ;
public static double cv_angle_around_Z ;
public static double cv_angle_around_Y ;
}
-------------------------
==============================
ConstantValues.java
--------------------------
public class ConstantValues {
public static final String cv_path_of_dir_LayerImages
= "F:OpenCvTest\\FilesForThreeDUsingImageData\\Layerimages" ;
public static final String cv_path_of_dir_BaseImage
= "F:OpenCvTest\\FilesForThreeDUsingImageData\\Baseimage" ;
}
-------------------------
==============================
Mediater.java
--------------------------
//-------------------------------------------------
//Mediater
//-------------------------------------------------
class Mediater {
public static String cv_this_Class_name = "Mediater" ;
public static JFrameDataInput cv_ins_JFrameDataInput ;
public static JFrameShowImageData cv_ins_JFrameShowImageData ;
public static Procc cv_ins_Procc ;
//----------------------------------------
public static void set_JFrameDataInput (
JFrameDataInput para_ins_JFrameDataInput
) {
cv_ins_JFrameDataInput = para_ins_JFrameDataInput ;
}
//----------------------------------------
public static void set_JFrameShowImageData (
JFrameShowImageData para_ins_JFrameShowImageData
) {
cv_ins_JFrameShowImageData
= para_ins_JFrameShowImageData ;
}
//----------------------------------------
public static void set_Procc (
Procc para_ins_Procc
) {
cv_ins_Procc = para_ins_Procc ;
}
//----------------------------------------
public static void do_repaint_process ( ) {
cv_ins_Procc.edit_ImageData_for_display ( ) ;
cv_ins_JFrameShowImageData
.set_display_image_BufferedImage
( cv_ins_Procc.get_ins_BufferedImage_for_display () ) ;
cv_ins_JFrameShowImageData
.do_repaint ( ) ;
}
}
-------------------------
==============================
Procc.java
--------------------------
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc ;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.WritableRaster;
//==========================
// Procc
//==========================
public class Procc {
private String cv_this_Class_name = "Procc" ;
private Mat cv_ins_Mat_contain_BaseImageData ;
private int cv_width_of_BaseImageData ;
private int cv_height_of_BaseImageData ;
private BufferedImage cv_ins_BufferedImage_for_display ;
private ContainImageDatas cv_ins_ContainImageDatas_All_LayerS ;
private int cv_number_of_layers ;
private CreateImageForDisplay cv_ins_CreateImageForDisplay ;
//======================
//Constructer
//======================
Procc ( ) {
String this_methode_name = "constructer" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
cv_ins_Mat_contain_BaseImageData
= load_BaseImageData ( ) ;
cv_ins_BufferedImage_for_display
= construct_BufferedImage_instance (
cv_ins_Mat_contain_BaseImageData
) ;
cv_number_of_layers = 10 ;
cv_ins_ContainImageDatas_All_LayerS
= new ContainImageDatas ( cv_number_of_layers ) ;
cv_ins_CreateImageForDisplay
= new CreateImageForDisplay (
cv_ins_Mat_contain_BaseImageData
) ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Exit from Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
}
//=================================
//getter
//=================================
public BufferedImage get_ins_BufferedImage_for_display () {
return cv_ins_BufferedImage_for_display ;
}
//=================================
//edit_ImageData_for_display
//=================================
public void edit_ImageData_for_display ( ) {
String this_methode_name = "edit_ImageData_for_display " ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
cv_ins_Mat_contain_BaseImageData
= load_BaseImageData ( ) ;
Mat ins_Mat_for_display
= cv_ins_CreateImageForDisplay
.modify_BaseImageData_using_LayerImageDataS (
Bridge.cv_angle_around_Z
, Bridge.cv_angle_around_Y
, cv_ins_Mat_contain_BaseImageData
, cv_ins_ContainImageDatas_All_LayerS
) ;
cv_ins_BufferedImage_for_display
= convert_Mat_Image_to_BufferedImage (
ins_Mat_for_display
, cv_ins_BufferedImage_for_display
) ;
System.out.println ( "Exit from Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( "----------------------------------" ) ;
}
//=================================
// convert Mat format Image to BufferedImage
//=================================
private BufferedImage convert_Mat_Image_to_BufferedImage (
Mat para_ins_Mat
, BufferedImage para_ins_BufferedImage
) {
String this_methode_name = "convert_Mat_Image_to_BufferedImage" ;
System.out.println ( " ----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
//get the area of BufferedImage instance
// that contains image data values
WritableRaster ins_WritableRaster
= para_ins_BufferedImage.getRaster () ;
DataBufferByte ins_DataBufferByte
= ( DataBufferByte ) ( ins_WritableRaster.getDataBuffer () ) ;
byte[] array_byte = ins_DataBufferByte.getData ( ) ;
//set image data into array_byte
// ( into para_ins_BufferedImage )
para_ins_Mat.get ( 0 , 0 , array_byte ) ;
System.out.println ( "image data have converted to BufferedImage") ;
System.out.println ( "Exit from Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( " ----------------------------------" ) ;
return para_ins_BufferedImage ;
}
//=================================
//load BaseImageData
//=================================
public Mat load_BaseImageData ( ) {
String this_methode_name = "load_BaseImageData" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
//read the file directed by para_data_number
String w1 = ConstantValues.cv_path_of_dir_BaseImage
+ "\\BaseImage.png" ;
System.out.println ( "current : w1 = " + w1 ) ;
cv_ins_Mat_contain_BaseImageData = null ;
cv_ins_Mat_contain_BaseImageData
//Using OpenCV3
= Imgcodecs.imread ( w1 ) ;
cv_width_of_BaseImageData
= cv_ins_Mat_contain_BaseImageData
.width () ;
cv_height_of_BaseImageData
= cv_ins_Mat_contain_BaseImageData
.height () ;
System.out.println ( "cv_width_of_BaseImageData = "
+ cv_width_of_BaseImageData ) ;
System.out.println ( "cv_height_of_BaseImageData = "
+ cv_height_of_BaseImageData ) ;
System.out.println ( "Exit from Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( "----------------------------------" ) ;
return cv_ins_Mat_contain_BaseImageData ;
}
//==========================
//construct BufferedImage instance
// related to Mat instance
//==========================
private BufferedImage construct_BufferedImage_instance (
Mat arg_ins_Mat
) {
String this_methode_name = "construct_BufferedImage_instance" ;
System.out.println ( " ----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
//get size of image data
Size ins_Size = arg_ins_Mat.size () ;
//get type of Mat
int type_of_Mat = 0 ;
if ( ( arg_ins_Mat.channels () != 1 )
&&
( arg_ins_Mat.channels () != 3 )
) {
return null;
}
if ( arg_ins_Mat.channels () == 1) {
type_of_Mat = BufferedImage.TYPE_BYTE_GRAY ;
}
if ( arg_ins_Mat.channels () == 3 ) {
type_of_Mat = BufferedImage.TYPE_3BYTE_BGR;
}
//construct instance of BufferedImage
BufferedImage ins_BufferedImage
= new BufferedImage (
arg_ins_Mat.width () , arg_ins_Mat.height ()
, type_of_Mat ) ;
System.out.println ( "Exit from Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( " ----------------------------------" ) ;
return ins_BufferedImage ;
}
}
-------------------------
==============================
CreateImageForDisplay.java
下記中の、cv_array_value_Xdash_drawn は、陰線処理を行うためのものです。
--------------------------
import org.opencv.core.Mat;
public class CreateImageForDisplay {
String cv_this_Class_name = "CreateImageForDisplay" ;
Mat cv_ins_Mat_BaseImageData ;
int cv_width_of_Mat_BaseImageData ;
int cv_height_of_Mat_BaseImageData ;
int cv_origin_cordinate_X_of_drawing ;
int cv_origin_cordinate_Y_of_drawing ;
double cv_scale_of_drawing ;
int cv_thickness_of_layer ;
double [ ] [ ] cv_array_value_Xdash_drawn ;
//for calculating the cordinate value after 3Dspace rotation
Rotation3DZY cv_ins_Rotation3DZY ;
//======================
//Constructer
//======================
CreateImageForDisplay (
Mat para_ins_Mat_BaseImageData
) {
String this_methode_name = "constructer" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
cv_scale_of_drawing = 1.0 ;
cv_thickness_of_layer = 20 ;
cv_ins_Mat_BaseImageData = para_ins_Mat_BaseImageData ;
cv_width_of_Mat_BaseImageData
= cv_ins_Mat_BaseImageData.width ( ) ;
cv_height_of_Mat_BaseImageData
= cv_ins_Mat_BaseImageData.height ( ) ;
cv_origin_cordinate_X_of_drawing
= cv_width_of_Mat_BaseImageData / 2 ;
cv_origin_cordinate_Y_of_drawing
= cv_height_of_Mat_BaseImageData / 2 ;
make_Xdash_drawn_table (
cv_width_of_Mat_BaseImageData
, cv_height_of_Mat_BaseImageData
) ;
cv_ins_Rotation3DZY = new Rotation3DZY ( ) ;
System.out.println ( "Exit from Class : "
+ cv_this_Class_name
+ " , Methode : " + this_methode_name ) ;
System.out.println ( "----------------------------------" ) ;
}
//-------------------------------------
// make Xdash_drawn table
//-------------------------------------
public void make_Xdash_drawn_table (
int para_width_of_BaseImageData
, int para_height_of_BaseImageData
) {
cv_array_value_Xdash_drawn = new double
[ cv_width_of_Mat_BaseImageData ]
[ cv_height_of_Mat_BaseImageData ]
;
}
//-------------------------------------
// initialize Xdash_drawn table
//-------------------------------------
public void initialize_Xdash_drawn_table ( ) {
for ( int i = 0 ; i < cv_width_of_Mat_BaseImageData ; i ++ ) {
for ( int j = 0 ; j < cv_height_of_Mat_BaseImageData ; j ++ ) {
cv_array_value_Xdash_drawn
[ i ] [ j ] = -10000 ;
}
}
}
//-------------------------------------------------------------------
//modify BaseImageData using LayerImageDataS
//-------------------------------------------------------------------
public Mat modify_BaseImageData_using_LayerImageDataS (
double para_angle_around_Z
, double para_angle_around_Y
, Mat para_ins_Mat_contain_BaseImageData
, ContainImageDatas
para_ins_ContainImageDatas_All_LayerS
) {
String this_methode_name
= "modify_BaseImageData_using_LayerImageDataS" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
cv_ins_Mat_BaseImageData
= para_ins_Mat_contain_BaseImageData ;
initialize_Xdash_drawn_table ( ) ;
prepare_for_rotation (
para_angle_around_Z
, para_angle_around_Y
) ;
int number_of_layers
= para_ins_ContainImageDatas_All_LayerS
.get_number_of_Mat ( ) ;
for ( int number_of_Layer = 1
; number_of_Layer <= number_of_layers
; number_of_Layer ++ ) {
System.out.println ( "Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( "number_of_Layer = " + number_of_Layer ) ;
draw_one_Layer (
number_of_Layer
, ( para_ins_ContainImageDatas_All_LayerS
.get_Mat ( number_of_Layer ) )
) ;
}
System.out.println ( "Exit from Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( "----------------------------------" ) ;
return cv_ins_Mat_BaseImageData ;
}
//------------------------------------------
//draw_one_Layer
//------------------------------------------
private void draw_one_Layer (
int para_number_of_Layer
, Mat para_ins_Mat_for_draw_layer_image
) {
int width_of_Mat
= para_ins_Mat_for_draw_layer_image.width () ;
int height_of_Mat
= para_ins_Mat_for_draw_layer_image.height () ;
int half_width_of_Mat = width_of_Mat / 2 ;
int half_height_of_Mat = height_of_Mat / 2 ;
int from_x = 0 - half_height_of_Mat + 2 ;
int to_x = half_height_of_Mat - 2 ;
int from_y = 0 - half_width_of_Mat + 2 ;
int to_y = half_width_of_Mat - 2 ;
int from_z = para_number_of_Layer * cv_thickness_of_layer ;
int to_z = ( para_number_of_Layer + 1 ) * cv_thickness_of_layer - 1 ;
for ( int x = from_x ; x <= to_x ; x ++ ) {
for ( int y = from_y ; y <= to_y ; y ++ ) {
for ( int z = from_z ; z <= to_z ; z ++ ) {
draw_one_point (
x , y , z
, para_ins_Mat_for_draw_layer_image
, half_width_of_Mat
, half_height_of_Mat
) ;
}
}
}
}
//--------------------------------------------------
private char draw_one_point (
int para_x , int para_y , int para_z
, Mat para_ins_Mat_for_draw_layer_image
, int para_half_width_of_Mat
, int para_half_height_of_Mat
) {
String this_methode_name = "draw_one_point" ;
char return_value = 'E' ;
double [ ] drawing_color
= decide_drawing_color (
para_x , para_y
, para_ins_Mat_for_draw_layer_image
, para_half_width_of_Mat
, para_half_height_of_Mat
) ;
if ( ( drawing_color [ 0 ] > 250 )
&&
( drawing_color [ 1 ] > 250 )
&&
( drawing_color [ 2 ] > 250 )
) {
//if color is near to white, do not draw this point
return 'N' ;
}
double [ ] after_rotation_cordinate = new double [ 3 ] ;
double [ ] before_rotation_cordinate = new double [ 3 ] ;
before_rotation_cordinate [ 0 ] = para_x ;
before_rotation_cordinate [ 1 ] = para_y ;
before_rotation_cordinate [ 2 ] = para_z ;
//calculate the cordinate value after 3Dspace rotation
cv_ins_Rotation3DZY.calculate (
before_rotation_cordinate
, after_rotation_cordinate
) ;
int [ ] drawing_location_xy
= decide_drawing_location ( after_rotation_cordinate ) ;
if ( ( drawing_location_xy [ 0 ] < 0 )
||
( drawing_location_xy [ 0 ] >= cv_width_of_Mat_BaseImageData )
||
( drawing_location_xy [ 1 ] < 0 )
||
( drawing_location_xy [ 1 ] >= cv_height_of_Mat_BaseImageData )
) {
//can not draw this point
System.out.println ( "***********************************" ) ;
System.out.println ( "Class = "
+ cv_this_Class_name
+ " , Methode : " + this_methode_name ) ;
System.out.println ( "Error" ) ;
System.out.println ( "drawing_location_xy = "
+drawing_location_xy [ 0 ]
+ " , " + drawing_location_xy [ 1 ] ) ;
System.out.println ( "cv_width_of_Mat_BaseImageData = "
+ cv_width_of_Mat_BaseImageData ) ;
System.out.println ( "cv_height_of_Mat_BaseImageData = "
+ cv_height_of_Mat_BaseImageData ) ;
return return_value ;
}
double value_Xdash = after_rotation_cordinate [ 0 ] ;
double w_Xdash_drawn
= cv_array_value_Xdash_drawn
[ drawing_location_xy [ 0 ] ] [ drawing_location_xy [ 1 ] ] ;
if ( value_Xdash > w_Xdash_drawn ) {
//draw this location
cv_ins_Mat_BaseImageData
.put (
drawing_location_xy [ 1 ]
, drawing_location_xy [ 0 ]
, drawing_color
) ;
cv_array_value_Xdash_drawn
[ drawing_location_xy [ 0 ] ]
[ drawing_location_xy [ 1 ] ]
= value_Xdash ;
}
return_value = 'Y' ;
return return_value ;
}
//---------------------------------------
// decide_drawing_location
//---------------------------------------
private int [ ] decide_drawing_location ( double [ ] para_cordinate ) {
int [ ] return_value = new int [ 2 ] ;
return_value [ 0 ]
= ( int ) ( cv_origin_cordinate_X_of_drawing +
para_cordinate [ 1 ]
* cv_scale_of_drawing ) ;
return_value [ 1 ]
= (int) ( cv_origin_cordinate_Y_of_drawing -
para_cordinate [ 2]
* cv_scale_of_drawing ) ;
return return_value ;
}
//--------------------------------------------------
private double [ ] decide_drawing_color (
int para_x , int para_y
, Mat para_ins_Mat_for_draw_layer_image
, int para_half_width_of_Mat
, int para_half_height_of_Mat
) {
String this_methode_name = "decide_drawing_color" ;
int get_X_on_Mat = para_y + para_half_width_of_Mat ;
int get_Y_on_Mat = para_x + para_half_height_of_Mat ;
double [ ] get_color
= para_ins_Mat_for_draw_layer_image
.get (
get_Y_on_Mat, get_X_on_Mat
) ;
return get_color ;
}
//------------------------------------------------------------------
public void prepare_for_rotation (
double para_rotation_angle_around_Z_axis
, double para_rotation_angle_around_Y_axis
) {
cv_ins_Rotation3DZY
.prepare_RotationMatrix (
para_rotation_angle_around_Z_axis
, para_rotation_angle_around_Y_axis ) ;
}
}
-------------------------
==============================
ContainImageDatas.java
--------------------------
import org.opencv.core.Mat ;
import org.opencv.imgcodecs.Imgcodecs ;
public class ContainImageDatas {
private String cv_this_Class_name = "ContainImageDatas" ;
private Mat [ ] cv_array_Mat ;
private int cv_number_of_Mat ;
//======================
//Constructer
//======================
ContainImageDatas (
int para_number_of_Mat
) {
String this_methode_name = "constructer" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
cv_number_of_Mat = para_number_of_Mat ;
cv_array_Mat = new Mat [ cv_number_of_Mat ] ;
StringBuffer w1 = new StringBuffer () ;
int w2 , w3 ;
for ( int i = 1 ; i <= para_number_of_Mat ; i ++ ) {
//make file path
w1.setLength ( 0 ) ;
w1.append ( ConstantValues.cv_path_of_dir_LayerImages ) ;
w1.append ( "\\" ) ;
w2 = i / 10 ;
w3 = i % 10 ;
w1.append ( "L" + w2 + w3 + ".png" ) ;
//read the file directed by w1
cv_array_Mat [ i - 1 ]
//Using OpenCV3
= Imgcodecs.imread ( w1.toString () ) ;
System.out.println ( "i = " + i ) ;
System.out.println ( "w1 = " + w1 ) ;
System.out.println ( "Loaded" ) ;
System.out.println ( "width and height = "
+ cv_array_Mat [ i - 1 ].width () + " , " + cv_array_Mat [ i - 1 ].height () ) ;
}
System.out.println ( "Exit from Class : "
+ cv_this_Class_name
+ " , Methode : " + this_methode_name ) ;
}
//---------------------------------
public Mat get_Mat ( int para_index_of_Mat ) {
return cv_array_Mat [ para_index_of_Mat - 1 ] ;
}
//---------------------------------
public int get_number_of_Mat ( ) {
return cv_number_of_Mat ;
}
}
-------------------------
==============================
Rotation3DZY.java
--------------------------
public class Rotation3DZY {
private String cv_Class_name = "Rotation3DZY" ;
//Matrix for rotation ( 2 phase )
private double [ ] [ ] [ ] cv_Matrix_for_rotation ;
//======================
//Constructer
//======================
Rotation3DZY ( ) {
String this_methode_name = "Constructer" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class : "
+ cv_Class_name
+ " , Methode : " + this_methode_name ) ;
cv_Matrix_for_rotation
= new double
//ration phase
[ 2 ]
//row
[ 3 ]
//column
[ 3 ]
;
System.out.println ( "Exit from Class : "
+ cv_Class_name
+ " , Methode : " + this_methode_name ) ;
System.out.println ( "----------------------------------" ) ;
}
//-----------------------------------------------------------------------
public void prepare_RotationMatrix (
double arg_rotation_angle_around_Z_axis
, double arg_rotation_angle_around_Y_axis
) {
double cos_around_Z_axis
= Math.cos ( Math.PI * ( arg_rotation_angle_around_Z_axis / 180.0 ) ) ;
double sin_around_Z_axis
= Math.sin ( Math.PI * ( arg_rotation_angle_around_Z_axis / 180.0 ) ) ;
double cos_around_Y_axis
= Math.cos ( Math.PI * ( arg_rotation_angle_around_Y_axis / 180.0 ) ) ;
double sin_around_Y_axis
= Math.sin ( Math.PI * ( arg_rotation_angle_around_Y_axis / 180.0 ) ) ;
//---------------------------------------------
//phase 1 ( rotate around Z axis )
cv_Matrix_for_rotation [ 0 ] [ 0 ] [ 0 ] =
//cos ( rotation angle of phase 1 )
cos_around_Z_axis ;
cv_Matrix_for_rotation [ 0 ] [ 0 ] [ 1 ] =
//sin ( rotation angle of phase 1 )
sin_around_Z_axis ;
cv_Matrix_for_rotation [ 0 ] [ 0 ] [ 2 ] = 0.0 ;
cv_Matrix_for_rotation [ 0 ] [ 1 ] [ 0 ] =
//- sin ( rotation angle of phase 1 )
( 0.0 - sin_around_Z_axis ) ;
cv_Matrix_for_rotation [ 0 ] [ 1 ] [ 1 ] =
//cos ( rotation angle of phase 1 )
cos_around_Z_axis ;
cv_Matrix_for_rotation [ 0 ] [ 1 ] [ 2 ] = 0.0 ;
cv_Matrix_for_rotation [ 0 ] [ 2 ] [ 0 ] = 0.0 ;
cv_Matrix_for_rotation [ 0 ] [ 2 ] [ 1 ] = 0.0 ;
cv_Matrix_for_rotation [ 0 ] [ 2 ] [ 2 ] = 1.0 ;
//---------------------------------------------
//phase 2 ( rotate around Y axis )
cv_Matrix_for_rotation [ 1 ] [ 0 ] [ 0 ] =
//cos ( rotation angle of phase 2 )
cos_around_Y_axis ;
cv_Matrix_for_rotation [ 1 ] [ 0 ] [ 1 ] = 0.0 ;
cv_Matrix_for_rotation [ 1 ] [ 0 ] [ 2 ] =
//- sin ( rotation angle of phase 2 )
( 0.0 - sin_around_Y_axis ) ;
cv_Matrix_for_rotation [ 1 ] [ 1 ] [ 0 ] = 0.0 ;
cv_Matrix_for_rotation [ 1 ] [ 1 ] [ 1 ] = 1.0 ;
cv_Matrix_for_rotation [ 1 ] [ 1 ] [ 2 ] = 0.0 ;
cv_Matrix_for_rotation [ 1 ] [ 2 ] [ 0 ] =
// sin ( rotation angle of phase 2 )
sin_around_Y_axis ;
cv_Matrix_for_rotation [ 1 ] [ 2 ] [ 1 ] = 0.0 ;
cv_Matrix_for_rotation [ 1 ] [ 2 ] [ 2 ] =
//cos ( rotation angle of phase 2 )
cos_around_Y_axis ;
//---------------------------------------------
}
//--------------------------------------------------------------------------
public void calculate (
double [ ] arg_vector_before_rotation
, double [ ] arg_vector_after_rotation
) {
//apply phase 1 rotation
double [ ] ins_value_after_phase1 = new double [ 3 ] ;
Matrix33Calc.calculate (
cv_Matrix_for_rotation [ 0 ]
, arg_vector_before_rotation
, ins_value_after_phase1
) ;
//apply phase 2 rotation
Matrix33Calc.calculate (
cv_Matrix_for_rotation [ 1 ]
, ins_value_after_phase1
, arg_vector_after_rotation
) ;
}
}
-------------------------
==============================
Matrix33Calc.java
--------------------------
//----------------------------------------------
// calculate the values using 3 3 Matrix
//----------------------------------------------
public class Matrix33Calc {
public static void calculate (
double [ ] [ ] arg_Matrix
, double [ ] arg_vector_operation_applied
, double [ ] arg_vector_operation_result
) {
for ( int index_row = 0 ; index_row <= 2 ; index_row ++ ) {
arg_vector_operation_result [ index_row ] =
arg_Matrix [ index_row ] [ 0 ]
* arg_vector_operation_applied [ 0 ]
+ arg_Matrix [ index_row ] [ 1 ]
* arg_vector_operation_applied [ 1 ]
+ arg_Matrix [ index_row ] [ 2 ]
* arg_vector_operation_applied [ 2 ]
;
}
}
}
-------------------------
==============================
JFrameShowImageData.java
--------------------------
import java.awt.Graphics ;
import java.awt.image.BufferedImage ;
import java.awt.Color ;
import javax.swing.JFrame ;
import javax.swing.JPanel ;
//-------------------------------------------------
//JFrame for showing image data
//-------------------------------------------------
class JFrameShowImageData extends JFrame {
private String mv_this_Class_name = " JFrameShowImageData" ;
//for display image
private JPanelShowImageData cv_ins_JPanelShowImageData ;
private int cv_width_of_Frame ;
private int cv_height_of_Frame;
private int cv_topLeftLocation_x_of_Frame ;
private int cv_topLeftLocation_y_of_Frame ;
//======================
//Constructer
//======================
JFrameShowImageData (
String para_title
, int para_width_of_Frame
, int para_height_of_Frame
, int para_topLeftLocation_x_of_Frame
, int para_topLeftLocation_y_of_Frame
) {
String this_methode_name = "constructer" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
cv_width_of_Frame = para_width_of_Frame ;
cv_height_of_Frame = para_height_of_Frame ;
cv_topLeftLocation_x_of_Frame
= para_topLeftLocation_x_of_Frame ;
cv_topLeftLocation_y_of_Frame
= para_topLeftLocation_y_of_Frame ;
setTitle ( para_title ) ;
setBounds (
cv_topLeftLocation_x_of_Frame
, cv_topLeftLocation_y_of_Frame
, cv_width_of_Frame
, cv_height_of_Frame
) ;
setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ) ;
cv_ins_JPanelShowImageData
= new JPanelShowImageData ( ) ;
add ( cv_ins_JPanelShowImageData ) ;
}
//=================================
// set_display_image_BufferedImage
//=================================
public void set_display_image_BufferedImage (
BufferedImage para_ins_BufferedImage
) {
cv_ins_JPanelShowImageData
.set_BufferedImage ( para_ins_BufferedImage ) ;
}
//=================================
//do_repaint
//=================================
public void do_repaint ( ) {
cv_ins_JPanelShowImageData
.do_repaint ( ) ;
}
}
//-------------------------------------------------------------------------------------
class JPanelShowImageData extends JPanel {
private String cv_this_Class_name = "JPanelShowImageData" ;
private BufferedImage cv_ins_BufferedImage ;
private int cv_width_of_Drawing ;
private int cv_height_of_Drawing ;
private int cv_width_of_BufferedImage ;
private int cv_height_of_BufferedImage ;
//=================================
//set_BufferedImage
//=================================
public void set_BufferedImage (
BufferedImage para_BufferedImage
) {
String this_methode_name = "set_BufferedImage" ;
System.out.println ( " ----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
cv_ins_BufferedImage = para_BufferedImage ;
cv_width_of_BufferedImage
= cv_ins_BufferedImage.getWidth ( ) ;
cv_height_of_BufferedImage
= cv_ins_BufferedImage.getHeight ( ) ;
System.out.println ( "cv_width_of_BufferedImage = " +
cv_width_of_BufferedImage ) ;
System.out.println ( "cv_height_of_BufferedImage = " +
cv_height_of_BufferedImage ) ;
System.out.println ( " ----------------------------------" ) ;
System.out.println ( "Exit from Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
}
//=================================
//do_repaint
//=================================
public void do_repaint ( ) {
compute_Size_of_Drawing ( ) ;
repaint ( ) ;
}
//======================
//paint image
//======================
public void paint ( Graphics para_ins_Graphics ) {
//clear Panel
Color ins_Color_for_clear = new Color ( 0 , 0 , 100 ) ;
para_ins_Graphics
.setColor ( ins_Color_for_clear ) ;
para_ins_Graphics
.fillRect (
0, 0,
cv_width_of_BufferedImage
, cv_height_of_BufferedImage
) ;
//draw image
para_ins_Graphics.drawImage (
cv_ins_BufferedImage
, 0 , 0
, cv_width_of_Drawing
, cv_height_of_Drawing
, this
) ;
}
//=================================
//compute_Size_of_Drawing
//=================================
public void compute_Size_of_Drawing ( ) {
String this_methode_name = "compute_Size_of_Drawing" ;
System.out.println ( " ----------------------------------" ) ;
System.out.println ( "Enter into Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
cv_width_of_Drawing = ( int )
( cv_width_of_BufferedImage
* Bridge.cv_Drawing_Scale_of_Showing_Image ) ;
cv_height_of_Drawing = ( int )
( cv_height_of_BufferedImage
* Bridge.cv_Drawing_Scale_of_Showing_Image ) ;
System.out.println ( "cv_width_of_BufferedImage = "
+ cv_width_of_BufferedImage ) ;
System.out.println ( " cv_height_of_BufferedImage = "
+ cv_height_of_BufferedImage ) ;
System.out.println ( "Bridge.cv_Drawing_Scale_of_Showing_Image = "
+ Bridge.cv_Drawing_Scale_of_Showing_Image ) ;
System.out.println ( "cv_width_of_Drawing = " + cv_width_of_Drawing ) ;
System.out.println ( "cv_height_of_Drawing = " + cv_height_of_Drawing ) ;
System.out.println ( "Exit from Class = " + cv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( " ----------------------------------" ) ;
}
}
-------------------------
==============================
JFrameDataInput.java
--------------------------
import java.awt.BorderLayout ;
import java.awt.Dimension ;
import java.awt.Font ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import javax.swing.JFrame ;
import javax.swing.JPanel ;
import javax.swing.JLabel ;
import javax.swing.JTextField ;
//-------------------------------------------------
//JFrame for intput data
//-------------------------------------------------
class JFrameDataInput extends JFrame {
private String mv_this_Class_name = "JFrameDataInput" ;
private final String cv_title_of_JFrame = "For Data Input" ;
private int cv_width_of_Frame ;
private int cv_height_of_Frame;
private int cv_topLeftLocation_x_of_Frame ;
private int cv_topLeftLocation_y_of_Frame ;
//======================
//Constructer
//======================
JFrameDataInput (
int para_width_of_Frame
, int para_height_of_Frame
, int para_topLeftLocation_x_of_Frame
, int para_topLeftLocation_y_of_Frame
) {
String this_methode_name = "constructer" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
cv_width_of_Frame = para_width_of_Frame ;
cv_height_of_Frame = para_height_of_Frame ;
cv_topLeftLocation_x_of_Frame
= para_topLeftLocation_x_of_Frame ;
cv_topLeftLocation_y_of_Frame
= para_topLeftLocation_y_of_Frame ;
setTitle ( cv_title_of_JFrame ) ;
setBounds (
cv_topLeftLocation_x_of_Frame
, cv_topLeftLocation_y_of_Frame
, cv_width_of_Frame
, cv_height_of_Frame
) ;
setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ) ;
JPanel ins_JPanel = new JPanel () ;
//---------------------------
JLabel ins_1_JLabel = new JLabel ( "Angle around Z axis = " ) ;
ins_1_JLabel.setFont ( new Font ( "Serif", Font.PLAIN , 25 ) ) ;
JTextField ins_1_JTextField = new JTextField ( "30.0" ) ;
ins_1_JTextField.setPreferredSize ( new Dimension ( 80, 40 ) ) ;
ins_1_JTextField.setFont ( new Font ( "Serif", Font.PLAIN , 25 ) ) ;
ActionListenerText1 ins_ActionListenerText1
= new ActionListenerText1 ( ) ;
ins_1_JTextField.addActionListener ( ins_ActionListenerText1 ) ;
ins_JPanel.add ( ins_1_JLabel ) ;
ins_JPanel.add ( ins_1_JTextField ) ;
//---------------------------
JLabel ins_2_JLabel = new JLabel ( "Angle around Y axis = " ) ;
ins_2_JLabel.setFont ( new Font ( "Serif", Font.PLAIN , 25 ) ) ;
JTextField ins_2_JTextField = new JTextField ( "-15.0" ) ;
ins_2_JTextField.setPreferredSize ( new Dimension ( 80, 40 ) ) ;
ins_2_JTextField.setFont ( new Font ( "Serif", Font.PLAIN , 25 ) ) ;
ActionListenerText2 ins_ActionListenerText2
= new ActionListenerText2 ( ) ;
ins_2_JTextField.addActionListener ( ins_ActionListenerText2 ) ;
ins_JPanel.add ( ins_2_JLabel ) ;
ins_JPanel.add ( ins_2_JTextField ) ;
//---------------------------
JLabel ins_3_JLabel = new JLabel ( "Drawing Scale = " ) ;
ins_3_JLabel.setFont ( new Font ( "Serif", Font.PLAIN , 25 ) ) ;
JTextField ins_3_JTextField = new JTextField ( "1.0" ) ;
ins_3_JTextField.setPreferredSize ( new Dimension ( 80, 40 ) ) ;
ins_3_JTextField.setFont ( new Font ( "Serif", Font.PLAIN , 25 ) ) ;
ActionListenerText3 ins_ActionListenerText3
= new ActionListenerText3 ( ) ;
ins_3_JTextField.addActionListener ( ins_ActionListenerText3 ) ;
ins_JPanel.add ( ins_3_JLabel ) ;
ins_JPanel.add ( ins_3_JTextField ) ;
//---------------------------
add ( ins_JPanel , BorderLayout.CENTER ) ;
}
}
//-------------------------------------------------------
class ActionListenerText1 implements ActionListener {
private String mv_this_Class_name = "ActionListenerText1" ;
public void actionPerformed ( ActionEvent para_ins_ActionEvent ) {
String this_methode_name = "actionPerformed" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
//get JTextField instance related
JTextField ins_JTextField
= ( JTextField ) ( para_ins_ActionEvent.getSource () ) ;
//set value to related variety
Bridge.cv_angle_around_Z
= Double.parseDouble ( ins_JTextField.getText () ) ;
//request process to Mediater
Mediater.do_repaint_process ( ) ;
System.out.println ( "Exit from Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( "----------------------------------" ) ;
}
}
//-------------------------------------------------------
class ActionListenerText2 implements ActionListener {
private String mv_this_Class_name = "ActionListenerText2" ;
public void actionPerformed ( ActionEvent para_ins_ActionEvent ) {
String this_methode_name = "actionPerformed" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
//get JTextField instance related
JTextField ins_JTextField
= ( JTextField ) ( para_ins_ActionEvent.getSource () ) ;
//set value to related variety
Bridge.cv_angle_around_Y
= Double.parseDouble ( ins_JTextField.getText () ) ;
//request process to Mediater
Mediater.do_repaint_process ( ) ;
System.out.println ( "Exit from Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( "----------------------------------" ) ;
}
}
//-------------------------------------------------------
class ActionListenerText3 implements ActionListener {
private String mv_this_Class_name = "ActionListenerText3" ;
public void actionPerformed ( ActionEvent para_ins_ActionEvent ) {
String this_methode_name = "actionPerformed" ;
System.out.println ( "----------------------------------" ) ;
System.out.println ( "Enter into Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
//get JTextField instance related
JTextField ins_JTextField
= ( JTextField ) ( para_ins_ActionEvent.getSource () ) ;
//set value to related variety
Bridge.cv_Drawing_Scale_of_Showing_Image
= Double.parseDouble ( ins_JTextField.getText () ) ;
//request process to Mediater
Mediater.do_repaint_process ( ) ;
System.out.println ( "Exit from Class = " + mv_this_Class_name +
" : methode = " + this_methode_name ) ;
System.out.println ( "----------------------------------" ) ;
}
}
------------------------------------------------
コンピューター・プログラム 制作 インデックス