Yuto Horikawa
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- robots: noindex, nofollow lang: ja dir: ltr breaks: true slideOptions: theme: white transition: slide --- <style> .reveal, .reveal h1, .reveal h2, .reveal h3, .reveal h4, .reveal h5, .reveal h6 { font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, "Microsoft JhengHei", Meiryo, sans-serif; } h1, h2, h3, h4, h5, h6 { text-transform: none !important; } .color-yellow{ color: yellow; } .alert { padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; text-align: left; padding: 10px 0; } .alert-info { color: #31708f; background-color: #d9edf7; border-color: #bce8f1; } .alert-success { color: #3c763d; background-color: #dff0d8; border-color: #d6e9c6; } .alert-danger { color: #a94442; background-color: #f2dede; border-color: #ebccd1; } .reveal .slides span { text-align: left; display: inline-block; } p, li { font-size: 0.88em !important; } li>p { font-size: 1em !important; } </style> # Julia Tokai #3 (2019/08/24) ###### tags: `juliatokai` --- ## JuliaでPOV-Rayのラッパーを ## 実装してみた   ![](https://i.imgur.com/w6PWVYp.jpg =200x) [ほりたみゅ (@Hyrodium)](https://twitter.com/hyrodium ) --- ### おしながき * 自己紹介 * POV-Rayとは * 実装したもの ---- ### 自己紹介 * 趣味 * 数学 (幾何学など) * Julia歴 * 最初に使ったのはv0.6.2 * 大学院(修士)での数値計算 * 曲面模型を弾性論に基づいて作る研究 * 非線形偏微分方程式をGalerkin法で離散化する * 非線形連立方程式をNewton法で数値解を求める ![](https://pbs.twimg.com/media/DtF88E9VsAE3OAH.jpg:orig =x200) ![](https://pbs.twimg.com/media/DtF82dAVAAAyc05.jpg:orig =x200) ![](https://pbs.twimg.com/media/DtJ1A0SUwAAOX4Y.jpg:orig =x200) ![](https://pbs.twimg.com/media/DtKG2a0U8AAKGLY.jpg:orig =x200) --- ### POV-Rayとは (1) 以下のような画像が出力できるソフトウェア ![](https://media.giphy.com/media/BWClhsM6ACc7QaPNDc/giphy.gif =200x200) ![](https://media.giphy.com/media/iOyEw7f0TradhMIMZe/giphy.gif =200x200) ![](https://media.giphy.com/media/3o6gb8Ny1TLXfhhawM/giphy.gif =200x200) ![](https://media.giphy.com/media/8L1am0zM2TkbzsssgI/giphy.gif =200x200) * Scene Description Language (シーン記述言語) * 円柱 / 直方体 / 球 / 三角形 などの基本的な図形の組み合わせで物体を表現 * 制御構文やマクロを使った記述が可能 (`#declare`, `#if`, `#while`, `#marcro`) ---- ### POV-Rayとは (2) ``` camera{ perspective location <2,1,2> look_at <0,0,0> } light_source{ <2,3,4> color rgb<1,1,1> } background{rgb<1,1,1>} sphere{<0,0,0>,0.2} cylinder{<0,0,0>,<1,0,0>,0.1 pigment{rgb<1,0,0>}} cylinder{<0,0,0>,<0,1,0>,0.1 pigment{rgb<0,1,0>}} cylinder{<0,0,0>,<0,0,1>,0.1 pigment{rgb<0,0,1>}} ``` ![](https://camo.qiitausercontent.com/52f29581f7e517732207ea1a2bd9774e5712e03c/68747470733a2f2f692e696d6775722e636f6d2f68794a766453462e706e67 =300x) ---- ### POV-Rayとは (3) * 色々なツールからPOV-Rayのコードが出力可能 * Mathematica * Blender * ParaView * POV-Ray言語の使いにくいところ * ベクトル`<...>`は2,3,4次元のみ * 変数の型を明示的に意識しにくい * 空集合が無い * 行列演算などが無い **→ JuliaからもPOV-Rayのコードを出力したい!** --- ### つくったもの : JuliRay * JuliaによるPOV-Rayのラッパー * https://github.com/hyrodium/JuliRay (ここでデモ) ![](https://i.imgur.com/VRAZFJQ.png =900x)![](https://i.imgur.com/T8c9FB1.png =200x) ---- ### なにを処理しているか 1. オブジェクトの定義 - `Sphere`, `Box`, `Torus`, `Polygon`, `csgUnion`など 2. POV-Ray言語への変換 - `.pov`ファイルの生成 (物体やカメラ) - `.ini`ファイルの生成 (レンダリングの設定) 3. レンダリング - `run(povray filename.pov)` を実行 --- ### JuliRayで定義してる型 ``` JuliRay Camera ParallelCamera PerspectiveCamera Light PointLight Object ColoredObject rgbColor rgbftColor PrimitiveObject Box Cone Cylinder Disc Empty Polygon Sphere Torus TransformedObject AffineTransform ParallelTranslation Scaling csgObject csgClip csgDifference csgIntersection csgMerge csgUnion Pigment FT ``` 木構造で管理できるので便利! ![](https://i.imgur.com/DeEqYMz.png =800x) ---- ### 多重ディスパッチ (トーラスの例) 2半径のみ指定するトーラス ``` struct Torus <: PrimitiveObject R :: Float64 r :: Float64 Torus(R,r) = ?(r == 0) Empty() : new(abs(R),abs(r)) end ``` 中心と法ベクトルと2半径を指定するトーラス ``` Torus(center::RealVector, normal::RealVector, R::Float64, r::Float64) ``` 3点と半径を指定するトーラス ``` Torus(p₁::RealVector, p₂::RealVector, p₃::RealVector, r::Float64) ``` ---- ### 透過処理 * 色の指定にはColors.jlの`RGB(r,g,b)`を使用 * 透過も指定する`RGBA(r,g,b,a)`は使っていない * POV-Rayでは2種類の透過があるため * 透過色指定用の型`FT(f,t)`を別に用意して実装 ![](https://camo.qiitausercontent.com/d4ebac7df2e4bbbcd336fc089d752efcfabb9645/68747470733a2f2f692e696d6775722e636f6d2f41514d374377342e676966 =300x300) ![](https://camo.qiitausercontent.com/b07d05b65a5e56473889433bc0488d2c0146242a/68747470733a2f2f692e696d6775722e636f6d2f424a56727833722e676966 =300x300) filter         transmit ---- ### 困っていたところ 自分で定義した型の等号判定が上手くできない ![](https://i.imgur.com/cwtSQPJ.png) (これと同じ理由?) ![](https://i.imgur.com/SEkY1mk.png) ---- ### 今後の予定 * POV-Rayの他の機能の追加 * svg画像の読み込み * モジュール化・パッケージ化 * JuliRayを使ったアニメーション制作 ![](https://i.giphy.com/media/H1wXzPqnl59qY5U9Mc/giphy.webp)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully