set path [get3DEInstallPath] source $path/user_data/tcl_archive/veclib.tcl proc getBackProjectedPoint2D { pg point fobj frame }\ { set pg_type [getPGroupType $pg] set cam [getFobjCamera $fobj] # Geomery of the Camera set focal [getCameraFocalLength $cam] set width [getCameraFBackWidth $cam] set height [getCameraFBackHeight $cam] # Lens center offset set lcx [getCameraLensCenterX $cam] set lcy [getCameraLensCenterY $cam] # Field of View size in pixel set fov_width [getFobjImageWidthFOV $fobj] set fov_height [getFobjImageHeightFOV $fobj] set x [getPointCalcPosition3D $pg $point] set pos [getPGroupPosition3D $pg $fobj $frame] set rot [getPGroupRotation3D $pg $fobj $frame] if {$pg_type == "CAMERA"}\ { # Difference vector from the camera position to the point in 3d set d [vec3-vec3 $x $pos] # Calculate the inverse of the camera matrix set rotinv [mat3trans $rot] # Reformulate the Difference vector in the coordiante frame of the camera set dnew [mat3*vec3 $rotinv $d] # Project this into the z=-1-Plane, that is: x' = x / -z, y' = y' -z (remember: the camera looks into -z direction) set d2 [vec2/s [list [vget $dnew 0] [vget $dnew 1]] [expr -[vget $dnew 2]]] # Now we want to express this in pixel respective to the lower left corner of the field of view (dotted line) # We scale it to metric units, remove the lens center offset, scale it down to dimensionless coordinates, # so that (0,0) is the lower left corner of the field of view, and (1,1) is the lower upper corner. set dfovx [expr ([vget $d2 0] * $focal - $lcx) / ($width) + .5] set dfovy [expr ([vget $d2 1] * $focal - $lcy) / ($height) + .5] } # This doesn't work yet: if {$pg_type == "OBJECT"}\ { set rotinv [mat3invert $rot] set d [mat3*vec3 $rotinv $x] set dnew [vec3+vec3 $d $pos] set d2 [vec2/s [list [vget $dnew 0] [vget $dnew 1]] [expr -[vget $dnew 2]]] set dfovx [expr ([vget $d2 0] * $focal - $lcx) / ($width) + .5] set dfovy [expr ([vget $d2 1] * $focal - $lcy) / ($height) + .5] } set pos2d [list $dfovx $dfovy] return $pos2d } set fobj [getSelectedFobj] if {$fobj==0}\ { bell post3DEInfoRequester "Error, there is no sequence selected!" return } set pg [getSelectedPGroup] if {$pg==0}\ { bell post3DEInfoRequester "Error, there is no point group selected!" return } set width [getFobjImageWidth $fobj] set height [getFobjImageHeight $fobj] set no_frames [getFobjNoFrames $fobj] set string [post3DEPromptRequester "Enter Framerange ( ):"] set start [lindex $string 0] set end [lindex $string 1] for {set point [getFirstPoint $pg]} {$point!=0} {set point [getNextPoint $pg $point]}\ { set selected [getPointSelectionFlag $pg $point] if {$selected}\ { set curve [getPointPosition2DBlock $pg $point $fobj 1 $no_frames] for {set frame $start} {$frame<=$end} {set frame [expr $frame+1]}\ { set pos2d [getBackProjectedPoint2D $pg $point $fobj $frame] set curve [lreplace $curve [expr $frame-1] [expr $frame-1] $pos2d] } setPointPosition2DBlock $pg $point $fobj 1 $curve } }