Canvas3DI.java
Go to the documentation of this file.
1 // -*- indent-tabs-mode: nil; tab-width: 4; -*-
2 /*
3  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
4  * All rights reserved. This program is made available under the terms of the
5  * Eclipse Public License v1.0 which accompanies this distribution, and is
6  * available at http://www.eclipse.org/legal/epl-v10.html
7  * Contributors:
8  * General Robotix Inc.
9  * National Institute of Advanced Industrial Science and Technology (AIST)
10  */
11 package com.generalrobotix.ui.view.vsensor;
12 
13 import java.awt.GraphicsConfiguration;
14 import java.awt.image.BufferedImage;
15 
16 import javax.media.j3d.DepthComponentFloat;
17 import javax.media.j3d.GraphicsContext3D;
18 import javax.media.j3d.Raster;
19 
25 @SuppressWarnings("serial")
26 public class Canvas3DI extends javax.media.j3d.Canvas3D {
27  // raster object
28  protected Raster raster_;
29  protected int width_;
30  protected int height_;
31  protected int rasterType_;
32  protected GraphicsContext3D gc_;
33 
34  // color buffer, depth buffer
35  int[] colorBuffer_;
36  float[] depthBuffer_;
37  boolean finished_ = false;
38 
39  // working space
40  protected BufferedImage color_;
41  protected DepthComponentFloat depth_;
42 
47  public Canvas3DI(GraphicsConfiguration gc) {
48  super(gc);
49  }
50 
56  public Canvas3DI(GraphicsConfiguration gc, boolean offscr,
57  Raster raster, int width, int height, int rasterType) {
58  super(gc, offscr);
59  gc_ = getGraphicsContext3D();
60  raster_ = raster;
61  width_ = width;
62  height_ = height;
63  rasterType_ = rasterType;
64 
65  if (rasterType_ == Raster.RASTER_DEPTH
66  || rasterType_ == Raster.RASTER_COLOR_DEPTH) {
67  depthBuffer_ = new float[width_ * height_];
68  }
69  if (rasterType_ == Raster.RASTER_COLOR
70  || rasterType_ == Raster.RASTER_COLOR_DEPTH) {
71  colorBuffer_ = new int[width_ * height_];
72  }
73  setSize(width, height);
74  }
75 
80  public int[] getColorBuffer() {
81  return colorBuffer_;
82  }
83 
84  public byte[] getMonoBuffer() {
85  byte[] monoBuffer = new byte[width_*height_];
86  for (int i=0; i<width_; i++) {
87  for (int j=0; j<height_; j++) {
88  monoBuffer[i+j*width_] =
89  (byte)(0.587*(0xff&(colorBuffer_[i+j*width_]>>8))
90  +0.114*(0xff&(colorBuffer_[i+j*width_]))
91  +0.299*(0xff&(colorBuffer_[i+j*width_]>>16)));
92  }
93  }
94  return monoBuffer;
95  }
96 
101  public float[] getDepthBuffer() {
102  return depthBuffer_;
103  }
107  public void postSwap() {
108  super.postSwap();
109  _readRaster();
110  }
111 
115  private void _readRaster() {
116  if (finished_)
117  return;
118 
119  gc_.readRaster(raster_);
120 
121  // read color buffer
122  if (rasterType_ == Raster.RASTER_COLOR ||
123  rasterType_ == Raster.RASTER_COLOR_DEPTH){
124  color_ = raster_.getImage().getImage();
125  color_.getRGB(0, 0, width_, height_, colorBuffer_, 0, width_);
126  if (colorBuffer_.length != width_*height_){
127  System.out.println("invalid length of color buffer = "+colorBuffer_.length);
128  }
129  }
130 
131  // read depth buffer
132  if (rasterType_ == Raster.RASTER_DEPTH ||
133  rasterType_ == Raster.RASTER_COLOR_DEPTH){
134  depth_ = (DepthComponentFloat)raster_.getDepthComponent();
135  depth_.getDepthData(depthBuffer_);
136  if (depthBuffer_.length != width_*height_){
137  System.out.println("invalid length of depth buffer = "+depthBuffer_.length);
138  }
139  }
140  finished_ = true;
141  }
142 
143  public void renderOnce(){
144  finished_ = false;
145  }
146 }
png_uint_32 i
Definition: png.h:2735
png_infop png_uint_32 * width
Definition: png.h:2309
png_infop png_uint_32 png_uint_32 * height
Definition: png.h:2309
Canvas3DI(GraphicsConfiguration gc, boolean offscr, Raster raster, int width, int height, int rasterType)
Definition: Canvas3DI.java:56


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:02