Take screenshot programmatically in scalismo UI

20 views
Skip to first unread message

Elon

unread,
Jul 25, 2022, 10:54:12 PM7/25/22
to scalismo
Hi does anyone know if it is possible to save an image of the scalismo UI viewport programmatically in the IDE? Much thanks!

Elon

Marcel Luethi

unread,
Jul 26, 2022, 11:52:34 AM7/26/22
to Elon, scalismo
Hi Elon

It is possible, but not yet nicely exposed in the api. The reason is, that it is still a bit flaky. A known limitation is, for example, that dpi scaling needs to be 100% on Windows, as otherwise the scene appears shifted.
If you would like to give it a try, you can create a custom version of Scalismo-UI with the necessary functionality, as shown below.

Best regards,

Marcel

package local

import scalismo.ui.model.Scene
import scalismo.ui.view.{ScalismoFrame, ScalismoLookAndFeel}
import scalismo.ui.api.Viewport
import scalismo.ui.api.ObjectView
import scalismo.ui.api.ScalismoUI
import scalismo.io.MeshIO

class MyScalismoUI(title: String) extends ScalismoUI(title) {

  def setBackgroundColor(color : java.awt.Color) : Unit = {
      frame.sceneControl.backgroundColor.value = color
  }

  def screenshot(viewport : Viewport, file : java.io.File) : Unit = {
    frame.perspective.viewports.find(_.name == viewport.name)
    .foreach(v => v.rendererPanel.screenshot(file))
  }
}

object MyScalismoUI {

  def apply(title: String = ""): MyScalismoUI = {
    scalismo.initialize()
    ScalismoLookAndFeel.initializeWith(ScalismoLookAndFeel.DefaultLookAndFeelClassName)
    new MyScalismoUI(title)
  }
}


object Test {

  def main(args : Array[String]) : Unit = {
 
    val ui = MyScalismoUI()
    ui.setBackgroundColor(java.awt.Color.WHITE)
    val mesh = MeshIO.readMesh(new java.io.File("test.ply")).get
    ui.show(mesh, "mesh")
    Thread.sleep(3000) // make sure  the mesh is rendered before the screenshot is taken
    ui.screenshot(_3DMain, new java.io.File("x.png"))
  }
}





On Tue, Jul 26, 2022 at 4:54 AM Elon <kevin...@gmail.com> wrote:
Hi does anyone know if it is possible to save an image of the scalismo UI viewport programmatically in the IDE? Much thanks!

Elon

--
You received this message because you are subscribed to the Google Groups "scalismo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalismo+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalismo/0e2dd494-40d7-40a6-9200-382b69aade1fn%40googlegroups.com.

Elon

unread,
Jul 26, 2022, 3:33:41 PM7/26/22
to scalismo
Thanks Marcel, this works great!

Elon

Reply all
Reply to author
Forward
0 new messages