-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
albedo, illumination and normal renderer added #98
Merged
Merged
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8f68528
albedo, illumination and normal renderer added
3819a32
corrected normals
799330f
normals corrected
23a3900
change such that the values go in the same direction in color space (…
2d168b5
that was a stupid moment :)
f7cbf01
travis run again please and added comments
6a88dc4
corrected colortransform
8a39b6e
updated normalMapRenderer
5783e06
alternative proposal for the implementation of ModalityRenderers
Andreas-Forster 7652678
fixed import
Andreas-Forster 28bb708
fixed typo and added comments for new parameters
Andreas-Forster b4f2558
separated modality renderers to make the accidental use of the wrong …
Andreas-Forster d9c43aa
choosen better naming
Andreas-Forster a9371d1
change method names
eca3c3b
renamed function
a99d593
changed objects to classes, reducing a parameter in function calls
Andreas-Forster 39ce8f4
made the modalities ParametricImageRenderers
Andreas-Forster cef7515
renamed renderer to avoid misunderstandings
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/main/scala/scalismo/faces/sampling/face/ModalityRenderers.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright University of Basel, Graphics and Vision Research Group | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package scalismo.faces.sampling.face | ||
|
||
import scalismo.faces.color.RGBA | ||
import scalismo.faces.image.PixelImage | ||
import scalismo.faces.momo.MoMo | ||
import scalismo.faces.parameters.{ParametricRenderer, RenderParameter, SphericalHarmonicsLight} | ||
import scalismo.mesh.SurfacePointProperty | ||
|
||
|
||
case class DepthMapRenderer(correspondenceMoMoRenderer: CorrespondenceMoMoRenderer, clearColor: RGBA = RGBA.Black) extends RenderFromCorrespondenceImage[RGBA](correspondenceMoMoRenderer: CorrespondenceMoMoRenderer) { | ||
/** render the depthimage described by the parameters */ | ||
override def renderImage(parameters: RenderParameter): PixelImage[RGBA] = { | ||
val correspondenceImage = correspondenceMoMoRenderer.renderCorrespondenceImage(parameters) | ||
val depthMap = correspondenceImage.map{ px=> | ||
if(px.isDefined){ | ||
val frag = px.get | ||
val tId = frag.triangleId | ||
val bcc = frag.worldBCC | ||
val mesh = frag.mesh | ||
|
||
val posModel = mesh.position(tId, bcc) | ||
val posEyeCoordinates = parameters.modelViewTransform(posModel) | ||
|
||
Some((parameters.view.eyePosition-posEyeCoordinates).norm) | ||
}else{ | ||
None | ||
} | ||
} | ||
val values = depthMap.values.toIndexedSeq.flatten | ||
val ma = values.max | ||
val mi = values.min | ||
val mami = ma-mi | ||
depthMap.map{d=> | ||
if(d.isEmpty) | ||
clearColor | ||
else { | ||
RGBA(1.0 - (d.get - mi)/mami) | ||
} | ||
} | ||
} | ||
} | ||
|
||
case class NormalMapRenderer(correspondenceMoMoRenderer: CorrespondenceMoMoRenderer, clearColor: RGBA = RGBA.Black) extends RenderFromCorrespondenceImage[RGBA](correspondenceMoMoRenderer: CorrespondenceMoMoRenderer) { | ||
/** render the normals described by the parameters */ | ||
override def renderImage(parameters: RenderParameter): PixelImage[RGBA] = { | ||
val correspondenceImage = correspondenceMoMoRenderer.renderCorrespondenceImage(parameters) | ||
val normalMap = correspondenceImage.map { px => | ||
if (px.isDefined) { | ||
val frag = px.get | ||
val tId = frag.triangleId | ||
val bcc = frag.worldBCC | ||
val mesh = frag.mesh | ||
val normal = parameters.modelViewTransform(mesh.vertexNormals(tId, bcc)) | ||
|
||
Some(normal) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
normalMap.map(n => | ||
if (n.isEmpty) | ||
clearColor | ||
else { | ||
val v = n.get * 0.5 | ||
RGBA(0.5 - v.x, 0.5 - v.y, 0.5 - v.z) | ||
}) | ||
} | ||
} | ||
|
||
case class AlbedoRenderer(override val model: MoMo, override val clearColor: RGBA = RGBA.Black) extends MoMoRenderer(model: MoMo, clearColor: RGBA){ | ||
|
||
/** render the albedo described by the parameters */ | ||
override def renderImage(parameters: RenderParameter): PixelImage[RGBA] = { | ||
val inst = instance(parameters) | ||
val ambientParameters = parameters.noLightAndColor | ||
ParametricRenderer.renderParameterVertexColorMesh( | ||
ambientParameters, | ||
inst, | ||
clearColor) | ||
} | ||
|
||
} | ||
|
||
case class IlluminationRenderer(override val model: MoMo, override val clearColor: RGBA = RGBA.Black) extends MoMoRenderer(model: MoMo, clearColor: RGBA){ | ||
|
||
/** render the illumination component described by the parameters */ | ||
override def renderImage(parameters: RenderParameter): PixelImage[RGBA] = { | ||
val inst = instance(parameters) | ||
val noColorInst = inst.copy(color = SurfacePointProperty(inst.shape.triangulation, inst.color.pointData.map(_ => RGBA(0.5, 0.5, 0.5)))) | ||
ParametricRenderer.renderParameterVertexColorMesh( | ||
parameters.noColorTransform, | ||
noColorInst, | ||
clearColor) | ||
} | ||
|
||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, what is done in this map can be done in the map above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maps merged