unibas-gravis / scalismo-faces

Scalable Image Analysis and Shape Modelling: Module to work with 2d images, with a focus on face images
Apache License 2.0
118 stars 27 forks source link

MoMoRenderer: Speed up the cached MoMoRenderer for the same instance. #91

Closed andreas-schneider closed 6 years ago

andreas-schneider commented 6 years ago

Problem

Currently when using the cached version of the MoMoRenderer a mesh is generated from the model every time something in the RenderParameter changes. Including illumination and pose, which do not affect mesh generation.

Affected Usecase

This results in unnecessary computation when rendering the same MoMoInstance under different illuminations or poses.

Solution

Do not cache accoding to the RenderParameter but only according to the MoMoInstance part of the RenderParameter.

Result

Speed up of 4 for rendering the same mesh with different poses and illuminations (512x512) when the proposed changes are applied.

def test() = {
  val model = ???
  val renderer = MoMoRenderer(model).cached(5)
  val res: immutable.Seq[(PixelImage[RGBA], Double)] = for(i<- 0.0 until 50.0 by 1.0) yield {
    val p = RenderParameter.defaultSquare.withMoMo(MoMoInstance.zero(100, 100, 0, new URI(""))).withPose(Pose(1.0, Vector(0,0,1000), 0, i*0.01, 0)).withEnvironmentMap(SphericalHarmonicsLight.fromAmbientDiffuse(RGB(0.5), RGB(0.5), Vector(0,0,i)))
    LanguageUtilities.timed{
      renderer.renderImage(p)
    }
  }

  val times = res.slice(10,40).map(_._2)
  println(times.sum / times.length)
}
Andreas-Forster commented 6 years ago

Thx. This makes absolute sense and is definitively a better solution.