|
78 | 78 | (:projection :newprojection
|
79 | 79 | :view :viewpoint :view-direction :viewdistance
|
80 | 80 | :yon :hither))
|
81 |
| - pwidth pheight)) |
| 81 | + img-viewer pwidth pheight)) |
82 | 82 | (defmethod camera-model
|
83 | 83 | (:init
|
84 | 84 | (b &rest args
|
|
109 | 109 | (:width () "Returns width of the camera in pixel." pwidth)
|
110 | 110 | (:height () "Returns height of the camera in pixel." pheight)
|
111 | 111 | (:viewing (&rest args) (forward-message-to vwing args))
|
| 112 | + (:image-viewer (&rest args) (forward-message-to img-viewer args)) |
112 | 113 | (:fovy () "Returns field of view in degree"
|
113 | 114 | (let ((proj (send vwing :projection)))
|
114 | 115 | (* 2 (atan2 (/ pwidth 2.0) (aref proj 0 0)))))
|
|
190 | 191 | (send vwer :viewsurface :color pcolor)
|
191 | 192 | (gl::draw-glbody vwer self)
|
192 | 193 | (if flush (send vwer :viewsurface :flush))))
|
193 |
| - (:draw-objects |
| 194 | + (:draw-objects (objs) (send self :draw-objects-raw img-viewer objs)) |
| 195 | + (:draw-objects-raw |
194 | 196 | (vwr objs)
|
195 | 197 | (let* (pcurrent pcolor (draw-things (x::draw-things objs))
|
196 | 198 | viewpoint viewtarget
|
|
199 | 201 | (f (aref proj 0 0)))
|
200 | 202 | (send vwr :viewsurface :makecurrent)
|
201 | 203 | ;;(resetperspective (send vwr :viewing) (send vwr :viewsurface))
|
| 204 | + (if (> pwidth pheight) |
| 205 | + (gl::glviewport 0 (- (/ (- pwidth pheight) 2)) pwidth pwidth) |
| 206 | + (gl::glviewport (- (/ (- pheight pwidth) 2)) 0 pheight pheight)) |
202 | 207 | (gl::glMatrixMode gl::GL_PROJECTION)
|
203 | 208 | (gl::glLoadIdentity)
|
204 | 209 | ;; the following should get aspect ration from viewport
|
|
209 | 214 | (setq viewpoint
|
210 | 215 | (v+ (send self :worldpos) ;; for right camera
|
211 | 216 | (send self :viewing :rotate-vector
|
212 |
| - (scale 1000.0 (float-vector (/ (- (- (/ pwidth 2.0) 1) cx) f) |
213 |
| - (/ (- (- (/ pheight 2.0) 1) cy) f) |
| 217 | + (scale 1000.0 (float-vector (/ (- (/ (1- pwidth) 2.0) cx) f) |
| 218 | + (/ (- (/ (1- pheight) 2.0) cy) f) |
214 | 219 | 0)))))
|
215 | 220 | ;; glview define view-directoin to oppsite direction
|
216 | 221 | (setq viewtarget
|
217 | 222 | (v- viewpoint (send self :viewing :view-direction) ))
|
| 223 | + (pprint (list viewpoint viewtarget (v- (send self :viewing :view-up)))) |
218 | 224 | (gl::gluLookAtfv (concatenate vector viewpoint viewtarget
|
219 | 225 | (v- (send self :viewing :view-up))))
|
220 | 226 | (gl::glMatrixMode gl::GL_MODELVIEW)
|
|
236 | 242 | )
|
237 | 243 | (send vwr :viewsurface :flush)
|
238 | 244 | ))
|
239 |
| - (:get-image (vwr &key (points) (colors)) |
| 245 | + (:get-image |
| 246 | + (&key (with-points) (with-colors)) |
| 247 | + (let (points colors img pc) |
| 248 | + (if with-points |
| 249 | + (setq points (make-matrix (* pwidth pheight) 3))) |
| 250 | + (if with-colors |
| 251 | + (setq colors (make-matrix (* pwidth pheight) 3))) |
| 252 | + (setq img (send self :get-image-raw img-viewer :points points :colors colors)) |
| 253 | + (cond |
| 254 | + ((and with-points with-colors) |
| 255 | + (setq pc (instance pointcloud :init |
| 256 | + :height pheight :width pwidth |
| 257 | + :points points :colors colors))) |
| 258 | + (with-points |
| 259 | + (setq pc (instance pointcloud :init |
| 260 | + :height pheight :width pwidth |
| 261 | + :points points)))) |
| 262 | + (if with-points |
| 263 | + (cons img pc) |
| 264 | + img))) |
| 265 | + (:get-image-raw (vwr &key (points) (colors)) |
240 | 266 | (let* ((sf (send vwr :viewsurface))
|
241 | 267 | (width (send sf :width))
|
242 | 268 | (height (send sf :height))
|
|
256 | 282 | (when points
|
257 | 283 | (unless (and (= width pwidth) (= height pheight))
|
258 | 284 | (warn ";; width: %d /= %d or height: %d /= %d~%" width pwidth height pheight)
|
259 |
| - (return-from :get-image)) |
| 285 | + (return-from :get-image-raw)) |
260 | 286 | (setq fv (make-array num :element-type :float))
|
261 | 287 | (setq mat-ent (array-entity points))
|
262 | 288 | (fill mat-ent 0.0)
|
|
271 | 297 | (dotimes (x width)
|
272 | 298 | (if (< (elt fv vptr) 1.0)
|
273 | 299 | (let ((zpos (/ (* fp np) (- (* (elt fv vptr) (- fp np)) fp))))
|
| 300 | + (setq mptr (* 3 (+ (* (- height y 1) width) x))) |
274 | 301 | (setf (elt pos 0) (* (- cx x) (/ zpos focus)))
|
275 |
| - (setf (elt pos 1) (* (- y cy) (/ zpos focus))) |
276 |
| - (setf (elt pos 2) (- zpos)) |
| 302 | + (setf (elt pos 1) (* (- cy (- height y 1)) (/ zpos focus))) |
| 303 | + (setf (elt pos 2) (- zpos)) ;; ok |
277 | 304 | (sys::vector-replace mat-ent pos mptr)
|
278 | 305 | (when colors
|
279 | 306 | (setf (elt col 0)
|
|
283 | 310 | (setf (elt col 2)
|
284 | 311 | (/ (sys::peek img-ent (+ mptr 2) :byte) 255.0))
|
285 | 312 | (sys::vector-replace col-ent col mptr))))
|
286 |
| - (incf mptr 3) |
287 | 313 | (incf vptr 1)
|
288 | 314 | )))
|
289 | 315 | img
|
290 | 316 | ))
|
291 | 317 | )
|
292 | 318 |
|
293 | 319 | ;; utility functions
|
294 |
| -(defun make-camera-from-param (&key pwidth pheight fx fy cx cy (tx 0) (ty 0) parent-coords name) |
| 320 | +(defun make-camera-from-param (&key pwidth pheight fx fy cx cy (tx 0) (ty 0) parent-coords name |
| 321 | + create-viewer) |
295 | 322 | "Create camera object from given parameters."
|
296 | 323 | (let* ((b (body+ (make-cube 40 30 30)
|
297 | 324 | (send (make-cylinder 2 30) :rotate pi/2 :x)
|
|
310 | 337 | (send c :translate (float-vector (- tx) (- ty) 0))
|
311 | 338 | (send (c . vwing) :translate (float-vector tx ty 0))
|
312 | 339 | (if parent-coords (send parent-coords :assoc c))
|
| 340 | + (when create-viewer |
| 341 | + (unless (boundp '*irtviewer*) (make-irtviewer)) |
| 342 | + (let ((cv |
| 343 | + (view |
| 344 | + :x pwidth :y pheight |
| 345 | + :viewing (send c :viewing) |
| 346 | + :viewsurface |
| 347 | + (instance gl::glviewsurface :create |
| 348 | + :glcon ((send *irtviewer* :viewer :viewsurface) . gl::glcon) |
| 349 | + :title (format nil "~A_view" name) :width pwidth :height pheight) |
| 350 | + :title (format nil "~A_view" name)))) |
| 351 | + (setq (c . img-viewer) cv) |
| 352 | + )) |
313 | 353 | c))
|
314 | 354 |
|
315 |
| - |
316 | 355 | (in-package "GEOMETRY")
|
317 | 356 |
|
318 | 357 | (provide :irtsensor "$Id: $")
|
|
0 commit comments