1 Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorListener.java
\r
2 ===================================================================
\r
3 --- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorListener.java (revision 0)
\r
4 +++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorListener.java (revision 178)
\r
7 + * NyARToolkit
\82ÌBehavior
\82Ì
\83\8a\83X
\83i
\r
8 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
9 + * airmail@ebony.plala.or.jp
\r
10 + * http://nyatla.jp/
\r
12 +package jp.nyatla.nyartoolkit.java3d.utils;
\r
14 +import javax.media.j3d.*;
\r
16 +public interface NyARSingleMarkerBehaviorListener
\r
19 + *
\82±
\82Ì
\83\8a\83X
\83i
\82Í
\81A
\83\8a\83X
\83i
\82É
\83}
\81[
\83J
\81[
\82É
\98A
\93®
\82µ
\82Ä
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\91\80\8dì
\82·
\82é
\83`
\83\83\83\93\83X
\82ð
\97^
\82¦
\82Ü
\82·
\81B
\r
20 + *
\83\8a\83X
\83i
\82ÍNyARSingleMarkerBehavior
\8aÖ
\90\94\93à
\82ÌprocessStimulus
\8aÖ
\90\94\82©
\82ç
\8cÄ
\82Ñ
\8fo
\82³
\82ê
\82Ü
\82·
\81B
\r
22 + * @param i_is_marker_exist
\r
23 + *
\83}
\81[
\83J
\81[
\82ª
\91¶
\8dÝ
\82·
\82é
\8fê
\8d\87true
\81A
\91¶
\8dÝ
\82µ
\82È
\82¢
\8fê
\8d\87\81Afalse
\82Å
\82·
\81B
\r
24 + * @param i_transform3d
\r
25 + *
\83}
\81[
\83J
\81[
\82ª
\91¶
\8dÝ
\82·
\82é
\8fê
\8d\87\81A
\82»
\82Ì
\95Ï
\8a·
\8ds
\97ñ
\82ª
\8ew
\92è
\82³
\82ê
\82Ü
\82·
\81B
\r
26 + * i_is_marker_exist
\82ªtrue
\82Ì
\8e\9e\82¾
\82¯
\97L
\8cø
\82Å
\82·
\81B
\r
28 + public void onUpdate(boolean i_is_marker_exist,Transform3D i_transform3d);
\r
30 Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java
\r
31 ===================================================================
\r
32 --- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java (revision 0)
\r
33 +++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java (revision 178)
\r
36 + * NyARRaster_RGB
\82ÉOpenGL
\8cü
\82¯
\8aÖ
\90\94\82ð
\92Ç
\89Á
\82µ
\82½
\82à
\82Ì
\r
37 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
38 + * airmail(at)ebony.plala.or.jp
\r
39 + * http://nyatla.jp/
\r
41 +package jp.nyatla.nyartoolkit.java3d.utils;
\r
43 +import java.awt.image.*;
\r
44 +import java.awt.color.*;
\r
46 +import javax.media.j3d.ImageComponent;
\r
47 +import javax.media.j3d.ImageComponent2D;
\r
51 +import jp.nyatla.nyartoolkit.NyARException;
\r
52 +import jp.nyatla.nyartoolkit.core.NyARParam;
\r
53 +import jp.nyatla.nyartoolkit.jmf.utils.*;
\r
56 +public class J3dNyARRaster_RGB extends JmfNyARRaster_RGB
\r
58 +// public ImageUpdater updater;
\r
59 + private ImageComponent2D imc2d;
\r
60 + private byte[] i2d_buf;
\r
62 + public void setBuffer(javax.media.Buffer i_buffer) throws NyARException
\r
64 + super.setBuffer(i_buffer);
\r
65 + //
\83\81\83\82\81F
\82±
\82Ì
\8e\9e\93_
\82Å
\82Í
\81Aref_data
\82É
\82Íi_buffer
\82Ì
\8eQ
\8fÆ
\92l
\82ª
\93ü
\82Á
\82Ä
\82é
\81B
\r
66 + synchronized(imc2d){
\r
67 + //
\83L
\83\83\83v
\83`
\83\83\83f
\81[
\83^
\82ði2d
\82Ì
\83o
\83b
\83t
\83@
\82É
\83R
\83s
\81[
\82·
\82é
\81B
\81i
\82±
\82ê
\8fÈ
\97ª
\82µ
\82½
\82¢
\82È
\82 \81c
\81B
\81j
\r
68 + System.arraycopy(ref_buf,0,i2d_buf,0,this.i2d_buf.length);
\r
70 + //
\82±
\82±
\82Åref_buf
\82Ì
\8eQ
\8fÆ
\92l
\82ðref_buf
\82Ö
\88Ú
\93®
\r
73 + public J3dNyARRaster_RGB(NyARParam i_cparam)
\r
75 + super(i_cparam.getX(),i_cparam.getY());
\r
77 + //RGB
\82Ì
\83\89\83X
\83^
\82ð
\8dì
\82é
\81B
\r
78 +// ColorSpace cs=ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
\r
79 +// ComponentColorModel cm;
\r
80 +// cm=new ComponentColorModel(cs,new int[]{8,8,8},false,false,ComponentColorModel.OPAQUE,DataBuffer.TYPE_BYTE);
\r
81 +// java.awt.image.WritableRaster raster=cm.createCompatibleWritableRaster(width,height);
\r
82 +// i2d_buf=((DataBufferByte)raster.getDataBuffer()).getData();
\r
83 +// BufferedImage background_image = new BufferedImage(cm,raster, false, null);
\r
84 + BufferedImage background_image = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
\r
85 + i2d_buf=((DataBufferByte)background_image.getRaster().getDataBuffer()).getData();
\r
87 + imc2d= new ImageComponent2D(ImageComponent2D.FORMAT_RGB, background_image, true, true);
\r
88 + imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);
\r
91 + *
\82±
\82Ì
\83I
\83u
\83W
\83F
\83N
\83g
\82Æ
\98A
\93®
\82·
\82éImageComponent2D
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\8eQ
\8fÆ
\92l
\82ð
\93¾
\82é
\81B
\r
94 + public ImageComponent2D getImageComponent2D()
\r
99 Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java
\r
100 ===================================================================
\r
101 --- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java (revision 0)
\r
102 +++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java (revision 178)
\r
105 + * NyARParam
\82ÉOpenGL
\8cü
\82¯
\8aÖ
\90\94\82ð
\92Ç
\89Á
\82µ
\82½
\82à
\82Ì
\r
106 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
107 + * airmail(at)ebony.plala.or.jp
\r
108 + * http://nyatla.jp/
\r
110 +package jp.nyatla.nyartoolkit.java3d.utils;
\r
112 +import jp.nyatla.nyartoolkit.core.*;
\r
113 +import javax.media.j3d.Transform3D;
\r
115 +public class J3dNyARParam extends NyARParam
\r
117 + private double view_distance_min=0.01;//1cm
\81`10.0m
\r
118 + private double view_distance_max=10.0;
\r
119 + private Transform3D m_projection=null;
\r
121 + *
\8e\8b\91Ì
\90Ï
\82Ì
\8bß
\82¢
\95û
\82ð
\83\81\81[
\83g
\83\8b\82Å
\8ew
\92è
\r
122 + * @param i_new_value
\r
124 + public void setViewDistanceMin(double i_new_value)
\r
126 + m_projection=null;//
\83L
\83\83\83b
\83V
\83\85\8dÏ
\95Ï
\90\94\8f\89\8aú
\89»
\r
127 + view_distance_min=i_new_value;
\r
130 + *
\8e\8b\91Ì
\90Ï
\82Ì
\89\93\82¢
\95û
\82ð
\83\81\81[
\83g
\83\8b\82Å
\8ew
\92è
\r
131 + * @param i_new_value
\r
133 + public void setViewDistanceMax(double i_new_value)
\r
135 + m_projection=null;//
\83L
\83\83\83b
\83V
\83\85\8dÏ
\95Ï
\90\94\8f\89\8aú
\89»
\r
136 + view_distance_max=i_new_value;
\r
139 + * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])
\r
140 + *
\8aÖ
\90\94\82Ì
\92u
\82«
\8a·
\82¦
\r
141 + * @param focalmin
\r
142 + * @param focalmax
\r
145 + public Transform3D getCameraTransform()
\r
147 + //
\8aù
\82É
\92l
\82ª
\83L
\83\83\83b
\83V
\83\85\82³
\82ê
\82Ä
\82¢
\82½
\82ç
\82»
\82ê
\82ð
\8eg
\82¤
\r
148 + if(m_projection!=null){
\r
149 + return m_projection;
\r
151 + //
\96³
\82¯
\82ê
\82Î
\8cv
\8eZ
\r
153 + NyARMat trans_mat=new NyARMat(3,4);
\r
154 + NyARMat icpara_mat=new NyARMat(3,4);
\r
155 + double[][] p=new double[3][3], q=new double[4][4];
\r
156 + double width, height;
\r
162 + decompMat(icpara_mat,trans_mat);
\r
164 + double[][] icpara=icpara_mat.getArray();
\r
165 + double[][] trans=trans_mat.getArray();
\r
166 + for (i = 0; i < 4; i++) {
\r
167 + icpara[1][i] = (height - 1)*(icpara[2][i]) - icpara[1][i];
\r
170 + for(i = 0; i < 3; i++) {
\r
171 + for(j = 0; j < 3; j++) {
\r
172 + p[i][j] = icpara[i][j] / icpara[2][2];
\r
175 + //p[0][0],p[1][1]=n
\r
176 + //p[0][2],p[1][2]=t+b
\r
178 + //Projection
\82Ì
\8cv
\8eZ
\r
179 + q[0][0] = (2.0 * p[0][0] / (width - 1));
\r
180 + q[0][1] = (2.0 * p[0][1] / (width - 1));
\r
181 + q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);
\r
185 + q[1][1] = -(2.0 * p[1][1] / (height - 1));
\r
186 + q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);
\r
191 + q[2][2] = (view_distance_max + view_distance_min)/(view_distance_min - view_distance_max);
\r
192 + q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);
\r
199 + q[2][2]=q[2][2]*-1;
\r
200 + q[2][3]=q[2][3]*-1;
\r
202 + double[] tmp_projection=new double[16];
\r
203 + for (i = 0; i < 4; i++) { // Row.
\r
204 + // First 3 columns of the current row.
\r
205 + for (j = 0; j < 3; j++) { // Column.
\r
206 + tmp_projection[i + j*4] =(
\r
207 + q[i][0] * trans[0][j] +
\r
208 + q[i][1] * trans[1][j] +
\r
209 + q[i][2] * trans[2][j]);
\r
211 + // Fourth column of the current row.
\r
212 + tmp_projection[i + 3*4]=
\r
213 + q[i][0] * trans[0][3] +
\r
214 + q[i][1] * trans[1][3] +
\r
215 + q[i][2] * trans[2][3] +
\r
218 + m_projection=new Transform3D(tmp_projection);
\r
219 + m_projection.transpose();
\r
220 + return m_projection;
\r
223 Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java
\r
224 ===================================================================
\r
225 --- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java (revision 0)
\r
226 +++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java (revision 178)
\r
229 + * NyARToolkit
\82ÌBehavior
\83z
\83\8b\83_
\81[
\r
230 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
231 + * airmail@ebony.plala.or.jp
\r
232 + * http://nyatla.jp/
\r
234 +package jp.nyatla.nyartoolkit.java3d.utils;
\r
236 +import java.util.Enumeration;
\r
238 +import javax.media.Buffer;
\r
239 +import javax.media.j3d.*;
\r
240 +import javax.vecmath.*;
\r
242 +import jp.nyatla.nyartoolkit.core.NyARParam;
\r
243 +import jp.nyatla.nyartoolkit.detector.NyARSingleDetectMarker;
\r
244 +import jp.nyatla.nyartoolkit.jmf.*;
\r
245 +import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;
\r
246 +import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;
\r
247 +import jp.nyatla.nyartoolkit.*;
\r
248 +import jp.nyatla.nyartoolkit.core.*;
\r
251 + * NyARToolkit
\82Æ
\98A
\93®
\82µ
\82½Behavior
\82ð
\95Ô
\8bp
\82·
\82é
\83N
\83\89\83X
\82Å
\82·
\81B
\r
252 + *
\92ñ
\8b\9f\82Å
\82«
\82éBehavior
\82Í
\81ABackground
\82ÆTransformgroup
\82Å
\82·
\81B
\r
255 +public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener
\r
257 + private NyARParam cparam;
\r
258 + private JmfCameraCapture capture;
\r
259 + private J3dNyARRaster_RGB nya_raster;//
\8dÅ
\91å3
\83X
\83\8c\83b
\83h
\82Å
\8b¤
\97L
\82³
\82ê
\82é
\82Ì
\82Å
\81A
\94r
\91¼
\90§
\8cä
\82©
\82¯
\82é
\82±
\82Æ
\81B
\r
260 + private NyARSingleDetectMarker nya;
\r
261 + //Behavior
\83z
\83\8b\83_
\r
262 + private NyARBehavior nya_behavior;
\r
263 + public NyARSingleMarkerBehaviorHolder(NyARParam i_cparam,float i_rate,NyARCode i_ar_code,double i_marker_width) throws NyARException
\r
265 + nya_behavior=null;
\r
267 + capture=new JmfCameraCapture(cparam.getX(),cparam.getY(),i_rate,JmfCameraCapture.PIXEL_FORMAT_RGB);
\r
268 + capture.setCaptureListener(this);
\r
269 + nya_raster=new J3dNyARRaster_RGB(cparam);
\r
270 + nya=new NyARSingleDetectMarker(cparam,i_ar_code,i_marker_width);
\r
271 + nya_behavior=new NyARBehavior(nya,nya_raster,i_rate);
\r
273 + public Behavior getBehavior()
\r
275 + return nya_behavior;
\r
278 + * i_back_ground
\82É
\83L
\83\83\83v
\83`
\83\83\89æ
\91\9c\82ð
\93]
\91\97\82·
\82é
\82æ
\82¤
\82ÉBehavior
\82ð
\90Ý
\92è
\82µ
\82Ü
\82·
\81B
\r
279 + * i_back_groung
\82ÍALLOW_IMAGE_WRITE
\91®
\90«
\82ð
\8e\9d\82Â
\82à
\82Ì
\82Å
\82 \82é
\95K
\97v
\82ª
\82 \82è
\82Ü
\82·
\81B
\r
280 + * @param i_back_groung
\r
283 + public void setBackGround(Background i_back_ground)
\r
285 + //
\83R
\81[
\83\8b\90æ
\82Å
\94r
\91¼
\90§
\8cä
\r
286 + nya_behavior.setRelatedBackGround(i_back_ground);
\r
289 + * i_trgroup
\82Ì
\8dÀ
\95W
\8cn
\82ð
\83}
\81[
\83J
\81[
\82É
\82 \82í
\82¹
\82é
\82æ
\82¤
\82ÉBehavior
\82ð
\90Ý
\92è
\82µ
\82Ü
\82·
\81B
\r
292 + public void setTransformGroup(TransformGroup i_trgroup)
\r
294 + //
\83R
\81[
\83\8b\90æ
\82Å
\94r
\91¼
\90§
\8cä
\r
295 + nya_behavior.setRelatedTransformGroup(i_trgroup);
\r
298 + *
\8dÀ
\95W
\8cn
\8dÄ
\8cv
\8eZ
\8cã
\82É
\8cÄ
\82Ñ
\8fo
\82³
\82ê
\82é
\83\8a\83X
\83i
\82Å
\82·
\81B
\r
299 + * @param i_listener
\r
301 + public void setUpdateListener(NyARSingleMarkerBehaviorListener i_listener)
\r
303 + //
\83R
\81[
\83\8b\90æ
\82Å
\94r
\91¼
\90§
\8cä
\r
304 + nya_behavior.setUpdateListener(i_listener);
\r
307 + *
\83\89\83X
\83^
\82ð
\8dX
\90V
\83R
\81[
\83\8b\83o
\83b
\83N
\8aÖ
\90\94\82¾
\82©
\82ç
\8cÄ
\82ñ
\82¶
\82á
\82ç
\82ß
\82¦
\r
309 + public void onUpdateBuffer(Buffer i_buffer)
\r
312 + synchronized(nya_raster){
\r
313 + nya_raster.setBuffer(i_buffer);
\r
315 + }catch(Exception e){
\r
316 + e.printStackTrace();
\r
319 + public void start() throws NyARException
\r
324 + public void stop()
\r
331 +class NyARBehavior extends Behavior
\r
333 + private NyARSingleDetectMarker related_nya;
\r
334 + private TransformGroup trgroup;
\r
335 + private Background back_ground;
\r
336 + private J3dNyARRaster_RGB raster;
\r
337 + private WakeupCondition wakeup;
\r
338 + private NyARSingleMarkerBehaviorListener listener;
\r
339 + public void initialize()
\r
341 + wakeupOn(wakeup);
\r
344 + * i_related_ic2d
\82Ì
\93à
\97e
\82Å
\92è
\8aú
\93I
\82Éi_back_ground
\82ð
\8dX
\90V
\82·
\82éBehavior
\r
345 + * @param i_back_ground
\r
346 + * @param i_related_ic2d
\r
348 + public NyARBehavior(NyARSingleDetectMarker i_related_nya,J3dNyARRaster_RGB i_related_raster,float i_rate)
\r
351 + wakeup=new WakeupOnElapsedTime((int)(1000/i_rate));
\r
352 + related_nya=i_related_nya;
\r
354 + raster =i_related_raster;
\r
355 + back_ground=null;
\r
357 + this.setSchedulingBounds(new BoundingSphere(new Point3d(), 100.0));
\r
359 + public void setRelatedBackGround(Background i_back_ground)
\r
361 + synchronized(raster){
\r
362 + back_ground=i_back_ground;
\r
365 + public void setRelatedTransformGroup(TransformGroup i_trgroup)
\r
367 + synchronized(raster){
\r
368 + trgroup=i_trgroup;
\r
371 + public void setUpdateListener(NyARSingleMarkerBehaviorListener i_listener)
\r
373 + synchronized(raster){
\r
374 + listener=i_listener;
\r
379 + *
\82¢
\82í
\82ä
\82é
\83C
\83x
\83\93\83g
\83n
\83\93\83h
\83\89\r
381 + public void processStimulus(Enumeration criteria)
\r
384 + synchronized(raster){
\r
385 + Transform3D t3d=null;
\r
386 + boolean is_marker_exist=false;
\r
387 + if(back_ground!=null){
\r
388 + back_ground.setImage(raster.getImageComponent2D());
\r
390 + if(raster.hasData()){
\r
391 + is_marker_exist=related_nya.detectMarkerLite(raster, 100);
\r
392 + if(is_marker_exist){
\r
393 + NyARMat nymat=related_nya.getTransmationMatrix();
\r
394 + double[][] src=nymat.getArray();
\r
395 + Matrix4d matrix=new Matrix4d(
\r
396 + src[0][0],-src[1][0],-src[2][0],0,
\r
397 + -src[0][1], src[1][1], src[2][1],0,
\r
398 + -src[0][2], src[1][2], src[2][2],0,
\r
399 + -src[0][3], src[1][3], src[2][3],1);
\r
400 + matrix.transpose();
\r
401 + t3d=new Transform3D(matrix);
\r
402 + if(trgroup!=null){
\r
403 + trgroup.setTransform(t3d);
\r
407 + if(listener!=null)
\r
409 + listener.onUpdate(is_marker_exist, t3d);
\r
412 + wakeupOn(wakeup);
\r
413 + }catch(Exception e){
\r
414 + e.printStackTrace();
\r
419 Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java
\r
420 ===================================================================
\r
421 --- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java (revision 0)
\r
422 +++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java (revision 178)
\r
425 + * Java3D
\83T
\83\93\83v
\83\8b\83v
\83\8d\83O
\83\89\83\80\r
426 + *
\83V
\83\93\83O
\83\8b\83}
\81[
\83J
\81[
\92Ç
\90Õ
\97p
\82ÌBehavior
\82ð
\8eg
\82Á
\82Ä
\81A
\94w
\8ci
\82Æ
\82P
\8cÂ
\82Ì
\83}
\81[
\83J
\81[
\82É
\98A
\93®
\82µ
\82½TransformGroup
\r
427 + *
\82ð
\93®
\82©
\82µ
\82Ü
\82·
\81B
\r
428 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
429 + * airmail@ebony.plala.or.jp
\r
430 + * http://nyatla.jp/
\r
432 +package jp.nyatla.nyartoolkit.java3d.sample;
\r
434 +import java.awt.BorderLayout;
\r
435 +import javax.media.j3d.*;
\r
437 +import com.sun.j3d.utils.universe.*;
\r
438 +import java.awt.*;
\r
439 +import javax.swing.JFrame;
\r
440 +import javax.vecmath.*;
\r
442 +import jp.nyatla.nyartoolkit.core.*;
\r
443 +import jp.nyatla.nyartoolkit.java3d.utils.*;
\r
445 +import com.sun.j3d.utils.geometry.ColorCube;
\r
447 +public class NyARJava3D extends JFrame implements NyARSingleMarkerBehaviorListener
\r
449 + private final String CARCODE_FILE ="../../Data/patt.hiro";
\r
450 + private final String PARAM_FILE ="../../Data/camera_para.dat";
\r
451 + //NyARToolkit
\8aÖ
\8cW
\r
452 + private NyARSingleMarkerBehaviorHolder nya_behavior;
\r
453 + private J3dNyARParam ar_param;
\r
454 + //universe
\8aÖ
\8cW
\r
455 + private Canvas3D canvas;
\r
456 + private Locale locale;
\r
457 + private VirtualUniverse universe;
\r
458 + public static void main(String[] args)
\r
461 + NyARJava3D frame = new NyARJava3D();
\r
463 + frame.setVisible(true);
\r
464 + Insets ins=frame.getInsets();
\r
465 + frame.setSize(320+ins.left+ins.right,240+ins.top+ins.bottom);
\r
466 + frame.startCapture();
\r
467 + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
\r
468 + }catch(Exception e){
\r
469 + e.printStackTrace();
\r
472 + public void onUpdate(boolean i_is_marker_exist,Transform3D i_transform3d)
\r
475 + * TODO:Please write your behavior operation code here.
\r
476 + *
\83}
\81[
\83J
\81[
\82Ì
\8ep
\90¨
\82ð
\8c³
\82É
\91¼
\82Ì
\82RD
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\91\80\8dì
\82·
\82é
\82Æ
\82«
\82Í
\81A
\82±
\82±
\82É
\8f\88\97\9d\82ð
\8f\91\82«
\82Ü
\82·
\81B*/
\r
479 + public void startCapture() throws Exception
\r
481 + nya_behavior.start();
\r
483 + public NyARJava3D() throws Exception
\r
485 + super("Java3D Example NyARToolkit");
\r
487 + //NyARToolkit
\82Ì
\8f\80\94õ
\r
488 + NyARCode ar_code =new NyARCode(16,16);
\r
489 + ar_code.loadFromARFile(CARCODE_FILE);
\r
490 + ar_param=new J3dNyARParam();
\r
491 + ar_param.loadFromARFile(PARAM_FILE);
\r
492 + ar_param.changeSize(320,240);
\r
494 + //locale
\82Ì
\8dì
\90¬
\82Ælocate
\82Æview
\82Ì
\90Ý
\92è
\r
495 + universe = new VirtualUniverse();
\r
496 + locale = new Locale( universe );
\r
497 + canvas=new Canvas3D( SimpleUniverse.getPreferredConfiguration());
\r
498 + View view = new View();
\r
499 + ViewPlatform viewPlatform = new ViewPlatform();
\r
500 + view.attachViewPlatform( viewPlatform );
\r
501 + view.addCanvas3D(canvas);
\r
502 + view.setPhysicalBody( new PhysicalBody() );
\r
503 + view.setPhysicalEnvironment( new PhysicalEnvironment());
\r
505 + //
\8e\8b\8aE
\82Ì
\90Ý
\92è(
\83J
\83\81\83\89\90Ý
\92è
\82©
\82ç
\8eæ
\93¾)
\r
506 + Transform3D camera_3d=ar_param.getCameraTransform();
\r
507 + view.setCompatibilityModeEnable(true);
\r
508 + view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
\r
509 + view.setLeftProjection(camera_3d);
\r
511 + //
\8e\8b\93_
\90Ý
\92è(0,0,0
\82©
\82ç
\81AY
\8e²
\82ð180
\93x
\89ñ
\93]
\82µ
\82ÄZ+
\95û
\8cü
\82ð
\8cü
\82
\82æ
\82¤
\82É
\82·
\82é
\81B)
\r
512 + TransformGroup viewGroup = new TransformGroup();
\r
513 + Transform3D viewTransform = new Transform3D();
\r
514 + viewTransform.rotY(Math.PI);
\r
515 + viewTransform.setTranslation(new Vector3d(0.0,0.0,0.0));
\r
516 + viewGroup.setTransform( viewTransform );
\r
517 + viewGroup.addChild( viewPlatform );
\r
518 + BranchGroup viewRoot = new BranchGroup();
\r
519 + viewRoot.addChild( viewGroup );
\r
520 + locale.addBranchGraph( viewRoot );
\r
523 + //
\83o
\83b
\83N
\83O
\83\89\83E
\83\93\83h
\82Ì
\8dì
\90¬
\r
524 + Background background =new Background();
\r
525 + BoundingSphere bounds = new BoundingSphere();
\r
526 + bounds.setRadius( 10.0 );
\r
527 + background.setApplicationBounds(bounds);
\r
528 + background.setImageScaleMode(Background.SCALE_FIT_ALL);
\r
529 + background.setCapability(Background.ALLOW_IMAGE_WRITE);
\r
530 + BranchGroup root = new BranchGroup();
\r
531 + root.addChild(background);
\r
533 + //TransformGroup
\82Å
\88Í
\82Á
\82½
\83V
\81[
\83\93\83O
\83\89\83t
\82Ì
\8dì
\90¬
\r
534 + TransformGroup transform=new TransformGroup();
\r
535 + transform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
\r
536 + transform.addChild(createSceneGraph());
\r
537 + root.addChild(transform);
\r
539 + //NyARToolkit
\82ÌBehavior
\82ð
\8dì
\82é
\81B(
\83}
\81[
\83J
\81[
\83T
\83C
\83Y
\82Í
\83\81\81[
\83g
\83\8b\82Å
\8ew
\92è
\82·
\82é
\82±
\82Æ)
\r
540 + nya_behavior=new NyARSingleMarkerBehaviorHolder(ar_param,30f,ar_code,0.08);
\r
541 + //Behavior
\82É
\98A
\93®
\82·
\82é
\83O
\83\8b\81[
\83v
\82ð
\83Z
\83b
\83g
\r
542 + nya_behavior.setTransformGroup(transform);
\r
543 + nya_behavior.setBackGround(background);
\r
545 + //
\8fo
\97\88\82½behavior
\82ð
\83Z
\83b
\83g
\r
546 + root.addChild(nya_behavior.getBehavior());
\r
547 + nya_behavior.setUpdateListener(this);
\r
549 + //
\95\
\8e¦
\83u
\83\89\83\93\83`
\82ðLocate
\82É
\83Z
\83b
\83g
\r
550 + locale.addBranchGraph(root);
\r
552 + //
\83E
\83C
\83\93\83h
\83E
\82Ì
\90Ý
\92è
\r
553 + setLayout(new BorderLayout());
\r
554 + add(canvas,BorderLayout.CENTER);
\r
557 + *
\83V
\81[
\83\93\83O
\83\89\83t
\82ð
\8dì
\82Á
\82Ä
\81A
\82»
\82Ì
\83m
\81[
\83h
\82ð
\95Ô
\82·
\81B
\r
558 + *
\82±
\82Ì
\83m
\81[
\83h
\82Í40mm
\82Ì
\90F
\82Â
\82«
\83i
\83^
\83f
\83R
\83R
\82ð
\95\
\8e¦
\82·
\82é
\83V
\81[
\83\93\81B
\82\9a\8e²
\82ð
\8aî
\8f\80\82É20mm
\8fã
\82É
\95\82\82©
\82¹
\82Ä
\82é
\81B
\r
561 + private Node createSceneGraph()
\r
563 + TransformGroup tg=new TransformGroup();
\r
564 + Transform3D mt=new Transform3D();
\r
565 + mt.setTranslation(new Vector3d(0.00,0.0,20*0.001));
\r
566 + //
\91å
\82«
\82³ 40mm
\82Ì
\90F
\95t
\82«
\97§
\95û
\91Ì
\82ð
\81AZ
\8e²
\8fã
\82Å20mm
\93®
\82©
\82µ
\82Ä
\94z
\92u
\81j
\r
567 + tg.setTransform(mt);
\r
568 + tg.addChild(new ColorCube(20*0.001));
\r
572 Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java
\r
573 ===================================================================
\r
574 --- D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java (revision 174)
\r
575 +++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java (revision 178)
\r
578 - * simpleLite
\82Æ
\93¯
\82¶
\82æ
\82¤
\82È
\83e
\83X
\83g
\83v
\83\8d\83O
\83\89\83\80\r
579 - *
\83}
\81[
\83J
\81[
\82Ì
\88ê
\92v
\93x
\82Ì
\8dÅ
\92á
\92l
\82ð
\83`
\83F
\83b
\83N
\82·
\82é
\82Æ
\82±
\82ë
\82ð
\94²
\82¢
\82½
\82Ì
\82Å
\81A
\93¯
\82¶
\83}
\81[
\83J
\81[
\82ð
\91å
\97Ê
\82É
\r
580 - *
\8c\9f\8fo
\82·
\82é
\82Æ
\96Ê
\94\92\82¢
\82±
\82Æ
\82É
\82È
\82è
\82Ü
\82·
\81B
\r
581 - * (c)2008 R.iizuka
\r
582 - * airmail(at)ebony.plala.or.jp
\r
583 - * http://nyatla.jp/
\r
585 -import java.awt.event.WindowAdapter;
\r
586 -import java.awt.event.WindowEvent;
\r
587 -import java.awt.*;
\r
589 -import javax.media.Buffer;
\r
591 -import javax.media.opengl.GL;
\r
592 -import javax.media.opengl.GLAutoDrawable;
\r
593 -import javax.media.opengl.GLEventListener;
\r
594 -import javax.media.opengl.GLCanvas;
\r
596 -import com.sun.opengl.util.Animator;
\r
598 -import jp.nyatla.nyartoolkit.core.NyARCode;
\r
600 -import jp.nyatla.nyartoolkit.jmf.JmfCameraCapture;
\r
601 -import jp.nyatla.nyartoolkit.jmf.JmfCaptureListener;
\r
602 -import jp.nyatla.nyartoolkit.gutil.*;
\r
605 -public class JavaSimpleLite implements GLEventListener,JmfCaptureListener
\r
607 - private final String CARCODE_FILE ="../../Data/patt.hiro";
\r
608 - private final String PARAM_FILE ="../../Data/camera_para.dat";
\r
611 - private Animator animator;
\r
612 - private GLNyARRaster_RGB cap_image;
\r
614 - private JmfCameraCapture capture;
\r
616 - //NyARToolkit
\8aÖ
\8cW
\r
617 - private GLNyARSingleDetectMarker nya;
\r
618 - private GLNyARParam ar_param;
\r
620 - *
\97§
\95û
\91Ì
\82ð
\8f\91\82
\r
625 - // Colour cube data.
\r
626 - int polyList = 0;
\r
627 - float fSize = 0.5f;
\r
629 - float[][] cube_vertices=new float[][]{
\r
630 - {1.0f, 1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f},
\r
631 - {1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}
\r
633 - float[][] cube_vertex_colors=new float[][]{
\r
634 - {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 1.0f},
\r
635 - {1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}
\r
637 - int cube_num_faces = 6;
\r
638 - short[][] cube_faces =new short[][]{
\r
639 - {3, 2, 1, 0}, {2, 3, 7, 6}, {0, 1, 5, 4}, {3, 0, 4, 7}, {1, 2, 6, 5}, {4, 5, 6, 7}
\r
642 - if (polyList==0) {
\r
643 - polyList = gl.glGenLists (1);
\r
644 - gl.glNewList(polyList, GL.GL_COMPILE);
\r
645 - gl.glBegin(GL.GL_QUADS);
\r
646 - for (f = 0; f < cube_num_faces; f++)
\r
647 - for (i = 0; i < 4; i++) {
\r
648 - gl.glColor3f (cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]);
\r
649 - gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);
\r
652 - gl.glColor3f(0.0f, 0.0f, 0.0f);
\r
653 - for (f = 0; f < cube_num_faces; f++) {
\r
654 - gl.glBegin (GL.GL_LINE_LOOP);
\r
655 - for (i = 0; i < 4; i++)
\r
656 - gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);
\r
662 - gl.glPushMatrix(); // Save world coordinate system.
\r
663 - gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.
\r
664 - gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.
\r
665 - gl.glDisable(GL.GL_LIGHTING); // Just use colours.
\r
666 - gl.glCallList(polyList); // Draw the cube.
\r
667 - gl.glPopMatrix(); // Restore world coordinate system.
\r
673 - public JavaSimpleLite()
\r
675 - Frame frame = new Frame("Java simpleLite with NyARToolkit");
\r
678 - // 3D
\82ð
\95`
\89æ
\82·
\82é
\83R
\83\93\83|
\81[
\83l
\83\93\83g
\r
679 - GLCanvas canvas = new GLCanvas();
\r
680 - frame.add(canvas);
\r
681 - canvas.addGLEventListener(this);
\r
682 - frame.addWindowListener(new WindowAdapter() {
\r
683 - public void windowClosing(WindowEvent e) {
\r
688 - frame.setVisible(true);
\r
689 - Insets ins=frame.getInsets();
\r
690 - frame.setSize(320+ins.left+ins.right,240+ins.top+ins.bottom);
\r
691 - canvas.setBounds(ins.left,ins.top,320,240);
\r
694 - public void init(GLAutoDrawable drawable) {
\r
695 - gl = drawable.getGL();
\r
696 - gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
\r
697 - //NyARToolkit
\82Ì
\8f\80\94õ
\r
699 - //
\83L
\83\83\83v
\83`
\83\83\82Ì
\8f\80\94õ
\r
700 - capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXEL_FORMAT_RGB);
\r
701 - capture.setCaptureListener(this);
\r
702 - //NyARToolkit
\82Ì
\8f\80\94õ
\r
703 - ar_param=new GLNyARParam();
\r
704 - NyARCode ar_code =new NyARCode(16,16);
\r
705 - ar_param.loadFromARFile(PARAM_FILE);
\r
706 - ar_param.changeSize(320,240);
\r
707 - nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0);
\r
708 - ar_code.loadFromARFile(CARCODE_FILE);
\r
709 - //GL
\91Î
\89\9e\82ÌRGB
\83\89\83X
\83^
\83I
\83u
\83W
\83F
\83N
\83g
\r
710 - cap_image=new GLNyARRaster_RGB(gl,ar_param);
\r
711 - //
\83L
\83\83\83v
\83`
\83\83\8aJ
\8en
\r
713 - }catch(Exception e){
\r
714 - e.printStackTrace();
\r
716 - animator = new Animator(drawable);
\r
718 - animator.start();
\r
722 - public void reshape(GLAutoDrawable drawable,
\r
724 - int width, int height)
\r
726 - float ratio = (float)height / (float)width;
\r
727 - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
\r
728 - gl.glViewport(0, 0, width, height);
\r
730 - //
\8e\8b\91Ì
\90Ï
\82Ì
\90Ý
\92è
\r
731 - gl.glMatrixMode(GL.GL_PROJECTION);
\r
732 - gl.glLoadIdentity();
\r
733 - gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
\r
735 - //
\8c©
\82é
\88Ê
\92u
\r
736 - gl.glMatrixMode(GL.GL_MODELVIEW);
\r
737 - gl.glLoadIdentity();
\r
738 - gl.glTranslatef(0.0f, 0.0f, -10.0f);
\r
741 - public void display(GLAutoDrawable drawable)
\r
745 - if(!cap_image.hasData()){
\r
748 - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
\r
749 - //
\89æ
\91\9c\83`
\83F
\83b
\83N
\82µ
\82Ä
\83}
\81[
\83J
\81[
\92T
\82µ
\82Ä
\81A
\94w
\8ci
\82ð
\8f\91\82
\r
750 - boolean is_marker_exist;
\r
751 - synchronized(cap_image){
\r
752 - is_marker_exist=nya.detectMarkerLite(cap_image,100);
\r
753 - //
\94w
\8ci
\82ð
\8f\91\82
\r
754 - cap_image.glDispImage(1.0);
\r
756 - //
\82 \82Á
\82½
\82ç
\97§
\95û
\91Ì
\82ð
\8f\91\82
\r
757 - if(is_marker_exist){
\r
758 - // Projection transformation.
\r
759 - gl.glMatrixMode(GL.GL_PROJECTION);
\r
760 - gl.glLoadMatrixd(ar_param.getCameraFrustumRH(),0);
\r
761 - gl.glMatrixMode(GL.GL_MODELVIEW);
\r
762 - // Viewing transformation.
\r
763 - gl.glLoadIdentity();
\r
764 - gl.glLoadMatrixd(nya.getCameraViewRH(),0);
\r
767 - // All other lighting and geometry goes here.
\r
770 - }catch(Exception e){
\r
771 - e.printStackTrace();
\r
774 - public void onUpdateBuffer(Buffer i_buffer)
\r
777 - synchronized(cap_image){
\r
778 - cap_image.setBuffer(i_buffer, true);
\r
780 - }catch(Exception e){
\r
781 - e.printStackTrace();
\r
785 - public void displayChanged(GLAutoDrawable drawable,
\r
786 - boolean modeChanged,
\r
787 - boolean deviceChanged) {}
\r
789 - public static void main(String[] args) {
\r
790 - new JavaSimpleLite();
\r
794 Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java
\r
795 ===================================================================
\r
796 --- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java (revision 0)
\r
797 +++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java (revision 178)
\r
800 + * NyARRaster_RGB
\82ÉOpenGL
\97p
\82Ì
\83f
\81[
\83^
\95Ï
\8a·
\8b@
\94\
\82ð
\92Ç
\89Á
\82µ
\82½
\82à
\82Ì
\82Å
\82·
\81B
\r
802 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
803 + * airmail(at)ebony.plala.or.jp
\r
804 + * http://nyatla.jp/
\r
806 +package jp.nyatla.nyartoolkit.jogl.utils;
\r
808 +import javax.media.format.RGBFormat;
\r
809 +import javax.media.opengl.GL;
\r
810 +import jp.nyatla.nyartoolkit.NyARException;
\r
811 +import jp.nyatla.nyartoolkit.jmf.utils.*;
\r
812 +import jp.nyatla.nyartoolkit.core.*;
\r
814 +public class GLNyARRaster_RGB extends JmfNyARRaster_RGB
\r
816 + private byte[] gl_buf;
\r
817 + private int gl_flag;
\r
819 + public GLNyARRaster_RGB(GL i_ref_gl,NyARParam i_param)
\r
821 + super(i_param.getX(),i_param.getY());
\r
822 + this.gl_flag=GL.GL_RGB;
\r
823 + this.gl_buf=new byte[this.width*this.height*3];
\r
825 + public void setBuffer(javax.media.Buffer i_buffer,boolean i_is_reverse) throws NyARException
\r
827 + //JMF
\83f
\81[
\83^
\82Å
\83t
\83H
\81[
\83}
\83b
\83g
\83v
\83\8d\83p
\83e
\83B
\82ð
\8f\89\8aú
\89»
\r
828 + initFormatProperty((RGBFormat)i_buffer.getFormat());
\r
830 + byte[] src_buf=(byte[])i_buffer.getData();
\r
831 + //GL
\97p
\82Ì
\83f
\81[
\83^
\82ð
\8f\80\94õ
\r
832 + if(i_is_reverse){
\r
833 + int length=this.width*3;
\r
835 + int dest_idx=(this.height-1)*length;
\r
836 + for(int i=0;i<this.height;i++){
\r
837 + System.arraycopy(src_buf,src_idx,this.gl_buf,dest_idx,length);
\r
839 + dest_idx-=length;
\r
842 + System.arraycopy(src_buf,0,gl_buf,0,src_buf.length);
\r
844 + //GL
\82Ì
\83t
\83\89\83O
\90Ý
\92è
\r
845 + switch(this.pix_type){
\r
846 + case GLNyARRaster_RGB.PIXEL_ORDER_BGR:
\r
847 + this.gl_flag=GL.GL_BGR;
\r
849 + case GLNyARRaster_RGB.PIXEL_ORDER_RGB:
\r
850 + this.gl_flag=GL.GL_RGB;
\r
853 + throw new NyARException();
\r
855 + //ref_buf
\82ðgl_buf
\82É
\8d·
\82µ
\91Ö
\82¦
\82é
\r
859 + * GL
\82Å
\82»
\82Ì
\82Ü
\82Ü
\95`
\89æ
\82Å
\82«
\82éRGB
\83o
\83b
\83t
\83@
\82ð
\95Ô
\82·
\81B
\r
862 + public byte[] getGLRgbArray()
\r
864 + return this.ref_buf;
\r
867 + * GL
\97p
\82ÌRGB
\83o
\83b
\83t
\83@
\82Ì
\83o
\83C
\83g
\95À
\82Ñ
\83^
\83C
\83v
\82ð
\95Ô
\82·
\81B
\r
870 + public int getGLPixelFlag()
\r
872 + return this.gl_flag;
\r
875 Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java
\r
876 ===================================================================
\r
877 --- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java (revision 0)
\r
878 +++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java (revision 178)
\r
881 + * NyARSingleDetectMarker
\82ÉOpenGL
\8cü
\82¯
\8aÖ
\90\94\82ð
\92Ç
\89Á
\82µ
\82½
\82à
\82Ì
\r
882 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
883 + * airmail(at)ebony.plala.or.jp
\r
884 + * http://nyatla.jp/
\r
886 +package jp.nyatla.nyartoolkit.jogl.utils;
\r
888 +import jp.nyatla.nyartoolkit.NyARException;
\r
889 +import jp.nyatla.nyartoolkit.core.NyARCode;
\r
890 +import jp.nyatla.nyartoolkit.core.NyARMat;
\r
891 +import jp.nyatla.nyartoolkit.core.NyARParam;
\r
892 +import jp.nyatla.nyartoolkit.detector.*;
\r
894 +public class GLNyARSingleDetectMarker extends NyARSingleDetectMarker
\r
896 + private double view_scale_factor=0.025;//#define VIEW_SCALEFACTOR 0.025 // 1.0 ARToolKit unit becomes 0.025 of my OpenGL units.
\r
897 + public GLNyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width)
\r
899 + super(i_param,i_code,i_marker_width);
\r
901 + public void setScaleFactor(double i_new_value)
\r
903 + view_scale_factor=i_new_value;
\r
905 + // public static void arglCameraViewRH(const double para[3][4], GLdouble m_modelview[16], const double scale)
\r
906 + public double[] getCameraViewRH() throws NyARException
\r
908 + //
\8dÀ
\95W
\82ð
\8cv
\8eZ
\r
909 + NyARMat mat=getTransmationMatrix();
\r
910 + //
\8ds
\97ñ
\95Ï
\8a·
\r
911 + double[][] para=mat.getArray();
\r
912 + double[] result=new double[16];
\r
913 + result[0 + 0*4] = para[0][0]; // R1C1
\r
914 + result[0 + 1*4] = para[0][1]; // R1C2
\r
915 + result[0 + 2*4] = para[0][2];
\r
916 + result[0 + 3*4] = para[0][3];
\r
917 + result[1 + 0*4] = -para[1][0]; // R2
\r
918 + result[1 + 1*4] = -para[1][1];
\r
919 + result[1 + 2*4] = -para[1][2];
\r
920 + result[1 + 3*4] = -para[1][3];
\r
921 + result[2 + 0*4] = -para[2][0]; // R3
\r
922 + result[2 + 1*4] = -para[2][1];
\r
923 + result[2 + 2*4] = -para[2][2];
\r
924 + result[2 + 3*4] = -para[2][3];
\r
925 + result[3 + 0*4] = 0.0;
\r
926 + result[3 + 1*4] = 0.0;
\r
927 + result[3 + 2*4] = 0.0;
\r
928 + result[3 + 3*4] = 1.0;
\r
929 + if (view_scale_factor != 0.0) {
\r
930 + result[12] *= view_scale_factor;
\r
931 + result[13] *= view_scale_factor;
\r
932 + result[14] *= view_scale_factor;
\r
937 Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java
\r
938 ===================================================================
\r
939 --- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (revision 0)
\r
940 +++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (revision 178)
\r
943 + * NyARToolkit
\97p
\82ÌJOGL
\8ex
\89\87\8aÖ
\90\94\8cQ
\r
944 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
945 + * airmail(at)ebony.plala.or.jp
\r
946 + * http://nyatla.jp/
\r
948 +package jp.nyatla.nyartoolkit.jogl.utils;
\r
949 +import java.nio.ByteBuffer;
\r
950 +import java.nio.IntBuffer;
\r
952 +import javax.media.opengl.GL;
\r
953 +import javax.media.opengl.glu.GLU;
\r
955 +import jp.nyatla.nyartoolkit.core.*;
\r
957 +public class NyARGLUtil
\r
959 + private NyARParam ar_param;
\r
960 + private javax.media.opengl.GL gl;
\r
961 + private javax.media.opengl.glu.GLU glu;
\r
962 + public NyARGLUtil(javax.media.opengl.GL i_gl,NyARParam i_camera_param)
\r
964 + this.ar_param=i_camera_param;
\r
966 + this.glu=new GLU();
\r
969 + * GLNyARRaster_RGB
\82ð
\83o
\83b
\83N
\83O
\83\89\83E
\83\93\83h
\82É
\8f\91\82«
\8fo
\82·
\81B
\r
973 + public void drawBackGround(GLNyARRaster_RGB i_raster,double i_zoom)
\r
975 + IntBuffer texEnvModeSave=IntBuffer.allocate(1);
\r
976 + boolean lightingSave;
\r
977 + boolean depthTestSave;
\r
978 + javax.media.opengl.GL gl_=this.gl;
\r
980 + // Prepare an orthographic projection, set camera position for 2D drawing, and save GL state.
\r
981 + gl_.glGetTexEnviv(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave); // Save GL texture environment mode.
\r
982 + if (texEnvModeSave.array()[0] != GL.GL_REPLACE){
\r
983 + gl_.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
\r
985 + lightingSave = gl_.glIsEnabled(GL.GL_LIGHTING); // Save enabled state of lighting.
\r
986 + if (lightingSave == true){
\r
987 + gl_.glDisable(GL.GL_LIGHTING);
\r
989 + depthTestSave = gl_.glIsEnabled(GL.GL_DEPTH_TEST); // Save enabled state of depth test.
\r
990 + if (depthTestSave == true){
\r
991 + gl_.glDisable(GL.GL_DEPTH_TEST);
\r
993 + gl_.glMatrixMode(GL.GL_PROJECTION);
\r
994 + gl_.glPushMatrix();
\r
995 + gl_.glLoadIdentity();
\r
996 + glu.gluOrtho2D(0.0,ar_param.getX(),0.0,ar_param.getY());
\r
997 + gl_.glMatrixMode(GL.GL_MODELVIEW);
\r
998 + gl_.glPushMatrix();
\r
999 + gl_.glLoadIdentity();
\r
1000 + arglDispImageStateful(i_raster,i_zoom);
\r
1003 + // Restore previous projection, camera position, and GL state.
\r
1004 + gl_.glMatrixMode(GL.GL_PROJECTION);
\r
1005 + gl_.glPopMatrix();
\r
1006 + gl_.glMatrixMode(GL.GL_MODELVIEW);
\r
1007 + gl_.glPopMatrix();
\r
1008 + if (depthTestSave){
\r
1009 + gl_.glEnable(GL.GL_DEPTH_TEST); // Restore enabled state of depth test.
\r
1011 + if (lightingSave){
\r
1012 + gl_.glEnable(GL.GL_LIGHTING); // Restore enabled state of lighting.
\r
1014 + if (texEnvModeSave.get(0) != GL.GL_REPLACE){
\r
1015 + gl_.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave.get(0)); // Restore GL texture environment mode.
\r
1020 + * arglDispImageStateful
\8aÖ
\90\94\83\82\83h
\83L
\r
1024 + private void arglDispImageStateful(GLNyARRaster_RGB i_raster,double zoom)
\r
1026 + javax.media.opengl.GL gl_=this.gl;
\r
1027 + int width =i_raster.getWidth();
\r
1028 + int height=i_raster.getHeight();
\r
1030 + IntBuffer params=IntBuffer.allocate(4);
\r
1031 + zoomf = (float)zoom;
\r
1032 + gl_.glDisable(GL.GL_TEXTURE_2D);
\r
1033 + gl_.glGetIntegerv(GL.GL_VIEWPORT,params);
\r
1034 + gl_.glPixelZoom(zoomf * ((float)(params.get(2)) / (float)width),-zoomf * ((float)(params.get(3)) / (float)height));
\r
1035 + gl_.glRasterPos2f(0.0f,(float)height);
\r
1036 + gl_.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
\r
1037 + ByteBuffer buf=ByteBuffer.wrap(i_raster.getGLRgbArray());
\r
1038 + gl_.glDrawPixels(width,height,i_raster.getGLPixelFlag(),GL.GL_UNSIGNED_BYTE,buf);
\r
1041 Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java
\r
1042 ===================================================================
\r
1043 --- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java (revision 0)
\r
1044 +++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java (revision 178)
\r
1047 + * NyARParam
\82ÉOpenGL
\8cü
\82¯
\8aÖ
\90\94\82ð
\92Ç
\89Á
\82µ
\82½
\82à
\82Ì
\r
1048 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
1049 + * airmail(at)ebony.plala.or.jp
\r
1050 + * http://nyatla.jp/
\r
1052 +package jp.nyatla.nyartoolkit.jogl.utils;
\r
1054 +import jp.nyatla.nyartoolkit.core.*;
\r
1055 +public class GLNyARParam extends NyARParam
\r
1057 + private double view_distance_min=0.1;//#define VIEW_DISTANCE_MIN 0.1 // Objects closer to the camera than this will not be displayed.
\r
1058 + private double view_distance_max=100.0;//#define VIEW_DISTANCE_MAX 100.0 // Objects further away from the camera than this will not be displayed.
\r
1059 + private double[] m_projection=null;
\r
1060 + public void setViewDistanceMin(double i_new_value)
\r
1062 + m_projection=null;//
\83L
\83\83\83b
\83V
\83\85\8dÏ
\95Ï
\90\94\8f\89\8aú
\89»
\r
1063 + view_distance_min=i_new_value;
\r
1065 + public void setViewDistanceMax(double i_new_value)
\r
1067 + m_projection=null;//
\83L
\83\83\83b
\83V
\83\85\8dÏ
\95Ï
\90\94\8f\89\8aú
\89»
\r
1068 + view_distance_max=i_new_value;
\r
1071 + * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])
\r
1072 + *
\8aÖ
\90\94\82Ì
\92u
\82«
\8a·
\82¦
\r
1073 + * @param focalmin
\r
1074 + * @param focalmax
\r
1077 + public double[] getCameraFrustumRH()
\r
1079 + //
\8aù
\82É
\92l
\82ª
\83L
\83\83\83b
\83V
\83\85\82³
\82ê
\82Ä
\82¢
\82½
\82ç
\82»
\82ê
\82ð
\8eg
\82¤
\r
1080 + if(m_projection!=null){
\r
1081 + return m_projection;
\r
1083 + //
\96³
\82¯
\82ê
\82Î
\8cv
\8eZ
\r
1084 + m_projection=new double[16];
\r
1085 + NyARMat trans_mat=new NyARMat(3,4);
\r
1086 + NyARMat icpara_mat=new NyARMat(3,4);
\r
1087 + double[][] p=new double[3][3], q=new double[4][4];
\r
1088 + int width, height;
\r
1094 + decompMat(icpara_mat,trans_mat);
\r
1096 + double[][] icpara=icpara_mat.getArray();
\r
1097 + double[][] trans=trans_mat.getArray();
\r
1098 + for (i = 0; i < 4; i++) {
\r
1099 + icpara[1][i] = (height - 1)*(icpara[2][i]) - icpara[1][i];
\r
1102 + for(i = 0; i < 3; i++) {
\r
1103 + for(j = 0; j < 3; j++) {
\r
1104 + p[i][j] = icpara[i][j] / icpara[2][2];
\r
1107 + q[0][0] = (2.0 * p[0][0] / (width - 1));
\r
1108 + q[0][1] = (2.0 * p[0][1] / (width - 1));
\r
1109 + q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);
\r
1113 + q[1][1] = -(2.0 * p[1][1] / (height - 1));
\r
1114 + q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);
\r
1119 + q[2][2] = (view_distance_max + view_distance_min)/(view_distance_min - view_distance_max);
\r
1120 + q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);
\r
1127 + for (i = 0; i < 4; i++) { // Row.
\r
1128 + // First 3 columns of the current row.
\r
1129 + for (j = 0; j < 3; j++) { // Column.
\r
1130 + m_projection[i + j*4] =
\r
1131 + q[i][0] * trans[0][j] +
\r
1132 + q[i][1] * trans[1][j] +
\r
1133 + q[i][2] * trans[2][j];
\r
1135 + // Fourth column of the current row.
\r
1136 + m_projection[i + 3*4]=
\r
1137 + q[i][0] * trans[0][3] +
\r
1138 + q[i][1] * trans[1][3] +
\r
1139 + q[i][2] * trans[2][3] +
\r
1142 + return m_projection;
\r
1145 Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java
\r
1146 ===================================================================
\r
1147 --- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java (revision 0)
\r
1148 +++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java (revision 178)
\r
1151 + * simpleLite
\82Æ
\93¯
\82¶
\82æ
\82¤
\82È
\83e
\83X
\83g
\83v
\83\8d\83O
\83\89\83\80\r
1152 + *
\83}
\81[
\83J
\81[
\82Ì
\88ê
\92v
\93x
\82Ì
\8dÅ
\92á
\92l
\82ð
\83`
\83F
\83b
\83N
\82·
\82é
\82Æ
\82±
\82ë
\82ð
\94²
\82¢
\82½
\82Ì
\82Å
\81A
\93¯
\82¶
\83}
\81[
\83J
\81[
\82ð
\91å
\97Ê
\82É
\r
1153 + *
\8c\9f\8fo
\82·
\82é
\82Æ
\96Ê
\94\92\82¢
\82±
\82Æ
\82É
\82È
\82è
\82Ü
\82·
\81B
\r
1154 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
1155 + * airmail(at)ebony.plala.or.jp
\r
1156 + * http://nyatla.jp/
\r
1158 +package jp.nyatla.nyartoolkit.jogl.sample;
\r
1160 +import java.awt.event.WindowAdapter;
\r
1161 +import java.awt.event.WindowEvent;
\r
1162 +import java.awt.*;
\r
1164 +import javax.media.Buffer;
\r
1166 +import javax.media.opengl.GL;
\r
1167 +import javax.media.opengl.GLAutoDrawable;
\r
1168 +import javax.media.opengl.GLEventListener;
\r
1169 +import javax.media.opengl.GLCanvas;
\r
1171 +import com.sun.opengl.util.Animator;
\r
1173 +import jp.nyatla.nyartoolkit.core.NyARCode;
\r
1175 +import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;
\r
1176 +import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;
\r
1177 +import jp.nyatla.nyartoolkit.jogl.utils.*;
\r
1180 +public class JavaSimpleLite implements GLEventListener,JmfCaptureListener
\r
1182 + private final String CARCODE_FILE ="../../Data/patt.hiro";
\r
1183 + private final String PARAM_FILE ="../../Data/camera_para.dat";
\r
1185 + private final static int SCREEN_X=320;
\r
1186 + private final static int SCREEN_Y=240;
\r
1187 + private Animator animator;
\r
1188 + private GLNyARRaster_RGB cap_image;
\r
1190 + private JmfCameraCapture capture;
\r
1192 + private NyARGLUtil glnya;
\r
1195 + //NyARToolkit
\8aÖ
\8cW
\r
1196 + private GLNyARSingleDetectMarker nya;
\r
1197 + private GLNyARParam ar_param;
\r
1199 + *
\97§
\95û
\91Ì
\82ð
\8f\91\82
\r
1204 + // Colour cube data.
\r
1205 + int polyList = 0;
\r
1206 + float fSize = 0.5f;//
\83}
\81[
\83J
\81[
\83T
\83C
\83Y
\82É
\91Î
\82µ
\82Ä0.5
\94{
\82È
\82Ì
\82Å
\81A4cm
\82Ì
\83i
\83^
\83f
\83R
\83R
\r
1208 + float[][] cube_vertices=new float[][]{
\r
1209 + {1.0f, 1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f},
\r
1210 + {1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}
\r
1212 + float[][] cube_vertex_colors=new float[][]{
\r
1213 + {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 1.0f},
\r
1214 + {1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}
\r
1216 + int cube_num_faces = 6;
\r
1217 + short[][] cube_faces =new short[][]{
\r
1218 + {3, 2, 1, 0}, {2, 3, 7, 6}, {0, 1, 5, 4}, {3, 0, 4, 7}, {1, 2, 6, 5}, {4, 5, 6, 7}
\r
1221 + if (polyList==0) {
\r
1222 + polyList = gl.glGenLists (1);
\r
1223 + gl.glNewList(polyList, GL.GL_COMPILE);
\r
1224 + gl.glBegin(GL.GL_QUADS);
\r
1225 + for (f = 0; f < cube_num_faces; f++)
\r
1226 + for (i = 0; i < 4; i++) {
\r
1227 + gl.glColor3f (cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]);
\r
1228 + gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);
\r
1231 + gl.glColor3f(0.0f, 0.0f, 0.0f);
\r
1232 + for (f = 0; f < cube_num_faces; f++) {
\r
1233 + gl.glBegin (GL.GL_LINE_LOOP);
\r
1234 + for (i = 0; i < 4; i++)
\r
1235 + gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);
\r
1238 + gl.glEndList ();
\r
1241 + gl.glPushMatrix(); // Save world coordinate system.
\r
1242 + gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.
\r
1243 + gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.
\r
1244 + gl.glDisable(GL.GL_LIGHTING); // Just use colours.
\r
1245 + gl.glCallList(polyList); // Draw the cube.
\r
1246 + gl.glPopMatrix(); // Restore world coordinate system.
\r
1252 + public JavaSimpleLite()
\r
1254 + Frame frame = new Frame("Java simpleLite with NyARToolkit");
\r
1257 + // 3D
\82ð
\95`
\89æ
\82·
\82é
\83R
\83\93\83|
\81[
\83l
\83\93\83g
\r
1258 + GLCanvas canvas = new GLCanvas();
\r
1259 + frame.add(canvas);
\r
1260 + canvas.addGLEventListener(this);
\r
1261 + frame.addWindowListener(new WindowAdapter() {
\r
1262 + public void windowClosing(WindowEvent e) {
\r
1267 + frame.setVisible(true);
\r
1268 + Insets ins=frame.getInsets();
\r
1269 + frame.setSize(SCREEN_X+ins.left+ins.right,SCREEN_Y+ins.top+ins.bottom);
\r
1270 + canvas.setBounds(ins.left,ins.top,SCREEN_X,SCREEN_Y);
\r
1273 + public void init(GLAutoDrawable drawable) {
\r
1274 + gl = drawable.getGL();
\r
1275 + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
\r
1276 + //NyARToolkit
\82Ì
\8f\80\94õ
\r
1278 + //
\83L
\83\83\83v
\83`
\83\83\82Ì
\8f\80\94õ
\r
1279 + capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXEL_FORMAT_RGB);
\r
1280 + capture.setCaptureListener(this);
\r
1281 + //NyARToolkit
\82Ì
\8f\80\94õ
\r
1282 + ar_param=new GLNyARParam();
\r
1283 + NyARCode ar_code =new NyARCode(16,16);
\r
1284 + ar_param.loadFromARFile(PARAM_FILE);
\r
1285 + ar_param.changeSize(SCREEN_X,SCREEN_Y);
\r
1286 + nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0);
\r
1287 + ar_code.loadFromARFile(CARCODE_FILE);
\r
1288 + //NyARToolkit
\97p
\82Ì
\8ex
\89\87\83N
\83\89\83X
\r
1289 + glnya=new NyARGLUtil(gl,ar_param);
\r
1290 + //GL
\91Î
\89\9e\82ÌRGB
\83\89\83X
\83^
\83I
\83u
\83W
\83F
\83N
\83g
\r
1291 + cap_image=new GLNyARRaster_RGB(gl,ar_param);
\r
1292 + //
\83L
\83\83\83v
\83`
\83\83\8aJ
\8en
\r
1293 + capture.start();
\r
1294 + }catch(Exception e){
\r
1295 + e.printStackTrace();
\r
1297 + animator = new Animator(drawable);
\r
1299 + animator.start();
\r
1303 + public void reshape(GLAutoDrawable drawable,
\r
1305 + int width, int height)
\r
1307 + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
\r
1308 + gl.glViewport(0, 0, width, height);
\r
1310 + //
\8e\8b\91Ì
\90Ï
\82Ì
\90Ý
\92è
\r
1311 + gl.glMatrixMode(GL.GL_PROJECTION);
\r
1312 + gl.glLoadIdentity();
\r
1313 + //
\8c©
\82é
\88Ê
\92u
\r
1314 + gl.glMatrixMode(GL.GL_MODELVIEW);
\r
1315 + gl.glLoadIdentity();
\r
1318 + public void display(GLAutoDrawable drawable)
\r
1322 + if(!cap_image.hasData()){
\r
1325 + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
\r
1326 + //
\89æ
\91\9c\83`
\83F
\83b
\83N
\82µ
\82Ä
\83}
\81[
\83J
\81[
\92T
\82µ
\82Ä
\81A
\94w
\8ci
\82ð
\8f\91\82
\r
1327 + boolean is_marker_exist;
\r
1328 + synchronized(cap_image){
\r
1329 + is_marker_exist=nya.detectMarkerLite(cap_image,100);
\r
1330 + //
\94w
\8ci
\82ð
\8f\91\82
\r
1331 + glnya.drawBackGround(cap_image, 1.0);
\r
1333 + //
\82 \82Á
\82½
\82ç
\97§
\95û
\91Ì
\82ð
\8f\91\82
\r
1334 + if(is_marker_exist){
\r
1335 + //
\83}
\81[
\83J
\81[
\82Ì
\88ê
\92v
\93x
\82ð
\92²
\8d¸
\82·
\82é
\82È
\82ç
\82Î
\81A
\82±
\82±
\82Ånya.getConfidence()
\82Å
\88ê
\92v
\93x
\82ð
\92²
\82×
\82Ä
\89º
\82³
\82¢
\81B
\r
1336 + // Projection transformation.
\r
1337 + gl.glMatrixMode(GL.GL_PROJECTION);
\r
1338 + gl.glLoadMatrixd(ar_param.getCameraFrustumRH(),0);
\r
1339 + gl.glMatrixMode(GL.GL_MODELVIEW);
\r
1340 + // Viewing transformation.
\r
1341 + gl.glLoadIdentity();
\r
1342 + gl.glLoadMatrixd(nya.getCameraViewRH(),0);
\r
1345 + // All other lighting and geometry goes here.
\r
1348 + }catch(Exception e){
\r
1349 + e.printStackTrace();
\r
1352 + public void onUpdateBuffer(Buffer i_buffer)
\r
1355 + synchronized(cap_image){
\r
1356 + cap_image.setBuffer(i_buffer, true);
\r
1358 + }catch(Exception e){
\r
1359 + e.printStackTrace();
\r
1363 + public void displayChanged(GLAutoDrawable drawable,
\r
1364 + boolean modeChanged,
\r
1365 + boolean deviceChanged) {}
\r
1367 + public static void main(String[] args) {
\r
1368 + new JavaSimpleLite();
\r
1372 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java
\r
1373 ===================================================================
\r
1374 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java (revision 174)
\r
1375 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java (revision 178)
\r
1378 - * VFM
\83L
\83\83\83v
\83`
\83\83\83e
\83X
\83g
\83v
\83\8d\83O
\83\89\83\80\r
1379 - * (c)2008 R.iizuka
\r
1380 - * airmail@ebony.plala.or.jp
\r
1381 - * http://nyatla.jp/
\r
1383 -import javax.media.*;
\r
1385 -import javax.media.util.BufferToImage;
\r
1386 -import javax.media.format.*;
\r
1388 -import jp.nyatla.nyartoolkit.NyARException;
\r
1389 -import jp.nyatla.nyartoolkit.jmf.*;
\r
1390 -import java.awt.*;
\r
1394 -public class JmfCaptureTest extends Frame implements JmfCaptureListener{
\r
1395 - public JmfCaptureTest() throws NyARException
\r
1397 - setTitle("JmfCaptureTest");
\r
1398 - setBounds(0,0,320+64,240+64);
\r
1399 - capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
\r
1400 - capture.setCaptureListener(this);
\r
1405 - private JmfCameraCapture capture;
\r
1406 - public void onUpdateBuffer(Buffer i_buffer)
\r
1408 - BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
\r
1409 - Image img=b2i.createImage(i_buffer);
\r
1410 - Graphics g = getGraphics();
\r
1411 - g.drawImage(img, 32, 32,this);
\r
1413 - private void startCapture()
\r
1416 - capture.start();
\r
1417 - }catch(Exception e){
\r
1418 - e.printStackTrace();
\r
1421 - public static void main(String[] args) {
\r
1423 - JmfCaptureTest mainwin = new JmfCaptureTest();
\r
1424 - mainwin.setVisible(true);
\r
1425 - mainwin.startCapture();
\r
1426 - }catch(Exception e){
\r
1427 - e.printStackTrace();
\r
1433 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java
\r
1434 ===================================================================
\r
1435 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java (revision 174)
\r
1436 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java (revision 178)
\r
1439 - * VFM+ARToolkit
\83e
\83X
\83g
\83v
\83\8d\83O
\83\89\83\80\r
1440 - *
\83J
\83\81\83\89\82©
\82ç
\8eæ
\82è
\8d\9e\82ñ
\82¾
\83f
\81[
\83^
\82©
\82ç
\83}
\81[
\83J
\81[
\82ð
\8c\9f\8fo
\82µ
\82Ä
\81A
\88ê
\92v
\93x
\82Æ
\95Ï
\8a·
\8ds
\97ñ
\82ð
\95\
\8e¦
\82µ
\82Ü
\82·
\81B
\r
1441 - * (c)2008 R.iizuka
\r
1442 - * airmail(at)ebony.plala.or.jp
\r
1443 - * http://nyatla.jp/
\r
1445 -import javax.media.*;
\r
1447 -import javax.media.util.BufferToImage;
\r
1448 -import javax.media.format.*;
\r
1450 -import jp.nyatla.nyartoolkit.NyARException;
\r
1451 -import jp.nyatla.nyartoolkit.jmf.*;
\r
1452 -import jp.nyatla.nyartoolkit.jmfutil.*;
\r
1453 -import java.awt.*;
\r
1455 -import jp.nyatla.nyartoolkit.core.*;
\r
1456 -import jp.nyatla.nyartoolkit.detector.*;
\r
1457 -import jp.nyatla.nyartoolkit.core.raster.*;
\r
1463 -public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
\r
1465 - private final String CARCODE_FILE ="../../Data/patt.hiro";
\r
1466 - private final String PARAM_FILE ="../../Data/camera_para.dat";
\r
1467 - private JmfCameraCapture capture;
\r
1468 - NyARSingleDetectMarker nya;
\r
1469 - JmfNyARRaster_RGB raster;
\r
1471 - public NyarToolkitLinkTest() throws NyARException,NyARException
\r
1473 - setTitle("JmfCaptureTest");
\r
1474 - setBounds(0,0,320+64,240+64);
\r
1475 - //
\83L
\83\83\83v
\83`
\83\83\82Ì
\8f\80\94õ
\r
1476 - capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
\r
1477 - capture.setCaptureListener(this);
\r
1479 - //NyARToolkit
\82Ì
\8f\80\94õ
\r
1480 - NyARParam ar_param=new NyARParam();
\r
1481 - NyARCode ar_code =new NyARCode(16,16);
\r
1482 - ar_param.loadFromARFile(PARAM_FILE);
\r
1483 - ar_param.changeSize(320,240);
\r
1484 - nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);
\r
1485 - ar_code.loadFromARFile(CARCODE_FILE);
\r
1486 - //
\83L
\83\83\83v
\83`
\83\83\83C
\83\81\81[
\83W
\97p
\82Ì
\83\89\83X
\83^
\82ð
\8f\80\94õ
\r
1487 - raster=new JmfNyARRaster_RGB(320,240);
\r
1492 - public void onUpdateBuffer(Buffer i_buffer)
\r
1495 - //
\83L
\83\83\83v
\83`
\83\83\82µ
\82½
\83o
\83b
\83t
\83@
\82ð
\83\89\83X
\83^
\82É
\83Z
\83b
\83g
\r
1496 - raster.setBuffer(i_buffer);
\r
1498 - //
\83L
\83\83\83v
\83`
\83\83\82µ
\82½
\83C
\83\81\81[
\83W
\82ð
\95\
\8e¦
\97p
\82É
\89Á
\8dH
\r
1499 - BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
\r
1500 - Image img=b2i.createImage(i_buffer);
\r
1502 - Graphics g = getGraphics();
\r
1503 - double[][] atm=null;
\r
1505 - //
\83}
\81[
\83J
\81[
\8c\9f\8fo
\r
1506 - boolean is_marker_exist=nya.detectMarkerLite(raster,100);
\r
1507 - if(is_marker_exist){
\r
1508 - //
\95Ï
\8a·
\8ds
\97ñ
\82ð
\8eæ
\93¾
\r
1509 - atm=nya.getTransmationMatrix().getArray();
\r
1511 - //
\8fî
\95ñ
\82ð
\89æ
\96Ê
\82É
\8f\91\82
\r
1512 - g.drawImage(img, 32, 32,this);
\r
1513 - if(is_marker_exist){
\r
1514 - g.drawString("
\83}
\81[
\83J
\81[
\8c\9f\8fo:"+nya.getConfidence(),32,50);
\r
1515 - for(int i=0;i<3;i++){
\r
1516 - for(int i2=0;i2<4;i2++){
\r
1517 - g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);
\r
1522 - g.drawString("
\83}
\81[
\83J
\81[
\96¢
\8c\9f\8fo:",32,100);
\r
1524 - }catch(Exception e){
\r
1525 - e.printStackTrace();
\r
1532 - private void startCapture()
\r
1535 - capture.start();
\r
1536 - }catch(Exception e){
\r
1537 - e.printStackTrace();
\r
1540 - public static void main(String[] args) {
\r
1542 - NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();
\r
1543 - mainwin.setVisible(true);
\r
1544 - mainwin.startCapture();
\r
1545 - }catch(Exception e){
\r
1546 - e.printStackTrace();
\r
1552 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorCDS.java
\r
1553 ===================================================================
\r
1554 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorCDS.java (revision 174)
\r
1555 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorCDS.java (revision 178)
\r
1558 - * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
\r
1560 - * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
\r
1561 - * modify and redistribute this software in source and binary code form,
\r
1562 - * provided that i) this copyright notice and license appear on all copies of
\r
1563 - * the software; and ii) Licensee does not utilize the software in a manner
\r
1564 - * which is disparaging to Sun.
\r
1566 - * This software is provided "AS IS," without a warranty of any kind. ALL
\r
1567 - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
\r
1568 - * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
\r
1569 - * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
\r
1570 - * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
\r
1571 - * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
\r
1572 - * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
\r
1573 - * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
\r
1574 - * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
\r
1575 - * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
\r
1576 - * POSSIBILITY OF SUCH DAMAGES.
\r
1578 - * This software is not designed or intended for use in on-line control of
\r
1579 - * aircraft, air traffic, aircraft navigation or aircraft communications; or in
\r
1580 - * the design, construction, operation or maintenance of any nuclear
\r
1581 - * facility. Licensee represents and warrants that it will not use or
\r
1582 - * redistribute the Software for such purposes.
\r
1584 -package jp.nyatla.nyartoolkit.jmf;
\r
1587 -import javax.media.*;
\r
1588 -import javax.media.protocol.*;
\r
1589 -import javax.media.control.*;
\r
1591 -import java.io.IOException;
\r
1595 -public class MonitorCDS extends PushBufferDataSource{
\r
1597 - private PushBufferDataSource delegate = null;
\r
1598 - private PushBufferStream [] delStreams = null;
\r
1599 - private MonitorStream monitorStream = null;
\r
1600 - private PushBufferStream [] monitorStreams = null;
\r
1601 - boolean delStarted = false; // variable used by MonitorStream also
\r
1602 - private Control [] controls;
\r
1604 - public MonitorCDS(DataSource ds)
\r
1606 - // Get the stream from the actual datasource
\r
1607 - // and create a MonitorStream from it
\r
1608 - // Export the MonitorControl interface of the MonitorStream
\r
1609 - if (ds instanceof PushBufferDataSource)
\r
1611 - delegate = (PushBufferDataSource) ds;
\r
1612 - delStreams = delegate.getStreams();
\r
1613 - monitorStream = new MonitorStream(delStreams[0], this);
\r
1614 - monitorStreams = new PushBufferStream[] {monitorStream};
\r
1618 - public Object [] getControls()
\r
1620 - return controls;
\r
1623 - public Object getControl(String value) {
\r
1624 - if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl"))
\r
1625 - return monitorStream;
\r
1630 - public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
\r
1632 - return ((CaptureDevice)delegate).getCaptureDeviceInfo();
\r
1635 - public FormatControl[] getFormatControls()
\r
1637 - return ((CaptureDevice)delegate).getFormatControls();
\r
1640 - public String getContentType()
\r
1642 - return delegate.getContentType();
\r
1645 - public void connect() throws IOException
\r
1647 - if (delegate == null)
\r
1648 - throw new IOException("Incompatible DataSource");
\r
1649 - // Delegate is already connected
\r
1652 - public void disconnect()
\r
1654 - monitorStream.setEnabled(false);
\r
1655 - delegate.disconnect();
\r
1658 - public synchronized void start() throws IOException
\r
1660 - startDelegate();
\r
1661 - delStarted = true;
\r
1664 - public synchronized void stop() throws IOException
\r
1666 - if (!monitorStream.isEnabled()) {
\r
1669 - delStarted = false;
\r
1672 - public Time getDuration()
\r
1674 - return delegate.getDuration();
\r
1677 - public PushBufferStream [] getStreams()
\r
1679 - return monitorStreams;
\r
1682 - void startDelegate() throws IOException
\r
1684 - delegate.start();
\r
1687 - void stopDelegate() throws IOException
\r
1689 - delegate.stop();
\r
1693 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorStream.java
\r
1694 ===================================================================
\r
1695 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorStream.java (revision 174)
\r
1696 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorStream.java (revision 178)
\r
1699 - * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
\r
1701 - * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
\r
1702 - * modify and redistribute this software in source and binary code form,
\r
1703 - * provided that i) this copyright notice and license appear on all copies of
\r
1704 - * the software; and ii) Licensee does not utilize the software in a manner
\r
1705 - * which is disparaging to Sun.
\r
1707 - * This software is provided "AS IS," without a warranty of any kind. ALL
\r
1708 - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
\r
1709 - * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
\r
1710 - * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
\r
1711 - * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
\r
1712 - * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
\r
1713 - * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
\r
1714 - * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
\r
1715 - * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
\r
1716 - * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
\r
1717 - * POSSIBILITY OF SUCH DAMAGES.
\r
1719 - * This software is not designed or intended for use in on-line control of
\r
1720 - * aircraft, air traffic, aircraft navigation or aircraft communications; or in
\r
1721 - * the design, construction, operation or maintenance of any nuclear
\r
1722 - * facility. Licensee represents and warrants that it will not use or
\r
1723 - * redistribute the Software for such purposes.
\r
1725 -package jp.nyatla.nyartoolkit.jmf;
\r
1729 -import javax.media.*;
\r
1730 -import javax.media.protocol.*;
\r
1732 -import javax.media.util.BufferToImage;
\r
1733 -import java.io.IOException;
\r
1734 -import java.awt.*;
\r
1736 -public class MonitorStream implements PushBufferStream, BufferTransferHandler {
\r
1738 - JmfCaptureListener img_listener;
\r
1739 - PushBufferStream actual = null;
\r
1740 - boolean dataAvailable = false;
\r
1741 - boolean terminate = false;
\r
1742 - boolean enabled = false;
\r
1743 - Object bufferLock = new Object();
\r
1744 - Buffer cbuffer = new Buffer();
\r
1745 - BufferTransferHandler transferHandler = null;
\r
1746 - Component component = null;
\r
1748 - BufferToImage bti = null;
\r
1750 - MonitorStream(PushBufferStream actual, MonitorCDS cds) {
\r
1751 - this.actual = actual;
\r
1752 - actual.setTransferHandler(this);
\r
1756 - public javax.media.Format getFormat()
\r
1758 - return actual.getFormat();
\r
1761 - *
\94ñ
\93¯
\8aúREAD
\r
1763 - public void read(Buffer buffer) throws IOException
\r
1765 - // Wait for data to be available
\r
1766 - // Doesn't get used much because the transferData
\r
1767 - // call is made when data IS available. And most
\r
1768 - // Processors/Players read the data in the same
\r
1769 - // thread that called transferData, although that's
\r
1770 - // not a safe assumption to make
\r
1771 - if (!dataAvailable) {
\r
1772 - synchronized (bufferLock) {
\r
1773 - while (!dataAvailable && !terminate) {
\r
1775 - bufferLock.wait(100);
\r
1776 - } catch (InterruptedException ie) {
\r
1782 - if (dataAvailable) {
\r
1783 - synchronized (bufferLock) {
\r
1784 - // Copy the buffer attributes, but swap the data
\r
1785 - // attributes so that no extra copy is made.
\r
1786 - buffer.copy(cbuffer, true);
\r
1787 - //dataAvailable = false;
\r
1792 - public void setCaptureListener(JmfCaptureListener i_listener)
\r
1794 - img_listener=i_listener;
\r
1797 - public void transferData(PushBufferStream pbs)
\r
1799 - // Get the data from the original source stream
\r
1800 - synchronized (bufferLock) {
\r
1802 - pbs.read(cbuffer);
\r
1803 - } catch (IOException ioe) {
\r
1806 - dataAvailable = true;
\r
1807 - bufferLock.notifyAll();
\r
1809 - if(img_listener!=null){
\r
1810 - img_listener.onUpdateBuffer(cbuffer);
\r
1814 - // Display data if monitor is active
\r
1815 - if (isEnabled()) {
\r
1816 - if (bti == null) {
\r
1817 - VideoFormat vf = (VideoFormat) cbuffer.getFormat();
\r
1818 - bti = new BufferToImage(vf);
\r
1820 - if (bti != null && component != null) {
\r
1821 - Image im = bti.createImage(cbuffer);
\r
1822 - Graphics g = component.getGraphics();
\r
1823 - Dimension size = component.getSize();
\r
1825 - g.drawImage(im, 0, 0, component);
\r
1829 - // Maybe synchronize this with setTransferHandler() ?
\r
1830 - if (transferHandler != null && cds.delStarted)
\r
1831 - transferHandler.transferData(this);
\r
1834 - public void setTransferHandler(BufferTransferHandler transferHandler) {
\r
1835 - this.transferHandler = transferHandler;
\r
1838 - public boolean setEnabled(boolean value) {
\r
1839 - enabled = value;
\r
1840 - if (value == false) {
\r
1841 - if (!cds.delStarted) {
\r
1843 - cds.stopDelegate();
\r
1844 - } catch (IOException ioe) {
\r
1848 - // Start the capture datasource if the monitor is enabled
\r
1850 - cds.startDelegate();
\r
1851 - }catch (IOException ioe) {
\r
1857 - public boolean isEnabled()
\r
1864 - public float setPreviewFrameRate(float rate)
\r
1866 - System.err.println("TODO");
\r
1870 - public ContentDescriptor getContentDescriptor()
\r
1872 - return actual.getContentDescriptor();
\r
1875 - public long getContentLength()
\r
1877 - return actual.getContentLength();
\r
1880 - public boolean endOfStream() {
\r
1881 - return actual.endOfStream();
\r
1884 - public Object [] getControls() {
\r
1885 - return new Object[0];
\r
1888 - public Object getControl(String str) {
\r
1894 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCaptureListener.java
\r
1895 ===================================================================
\r
1896 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCaptureListener.java (revision 174)
\r
1897 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCaptureListener.java (revision 178)
\r
1900 - * JMF
\82¨
\8eè
\8cy
\83L
\83\83\83v
\83`
\83\83\97p
\83\8a\83X
\83i
\r
1901 - * (c)2008 R.Iizuka
\r
1902 - * airmail@ebony.plala.or.jp
\r
1903 - * http://nyatla.jp/
\r
1905 -package jp.nyatla.nyartoolkit.jmf;
\r
1907 -import javax.media.Buffer;
\r
1909 -public interface JmfCaptureListener{
\r
1910 - public void onUpdateBuffer(Buffer i_buffer);
\r
1913 \ No newline at end of file
\r
1914 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java
\r
1915 ===================================================================
\r
1916 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java (revision 174)
\r
1917 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java (revision 178)
\r
1920 - * JMF
\82¨
\8eè
\8cy
\83L
\83\83\83v
\83`
\83\83\83N
\83\89\83X
\r
1921 - * (c)2008 R.Iizuka
\r
1922 - * airmail@ebony.plala.or.jp
\r
1923 - * http://nyatla.jp/
\r
1925 -package jp.nyatla.nyartoolkit.jmf;
\r
1929 -import javax.media.*;
\r
1930 -import javax.media.protocol.*;
\r
1931 -import javax.media.control.*;
\r
1932 -import javax.media.format.*;
\r
1933 -import java.awt.*;
\r
1934 -import java.util.*;
\r
1935 -import javax.media.protocol.DataSource;
\r
1937 -import jp.nyatla.nyartoolkit.NyARException;
\r
1943 -public class JmfCameraCapture
\r
1945 - private Dimension image_size;
\r
1946 - private JmfCaptureListener capture_listener;
\r
1947 - private DataSource jmf_data_source;
\r
1948 - private MonitorStream jmf_monitor_stream;
\r
1949 - private Processor jmf_processor;
\r
1950 - private VideoFormat jmf_video_format;
\r
1952 - private Buffer read_buf=new Buffer();
\r
1953 - public static final String PIXEL_FORMAT_RGB="RGB";
\r
1954 - public JmfCameraCapture(int i_width,int i_height,float i_rate,String i_pixcel_format)
\r
1956 - String encoding = i_pixcel_format;//comboEncoding.getSelectedItem();
\r
1957 - image_size = new Dimension(i_width,i_height);
\r
1958 - jmf_video_format = new VideoFormat(encoding, image_size, Format.NOT_SPECIFIED,null,i_rate);
\r
1960 - public Dimension getSize()
\r
1962 - return image_size;
\r
1964 - public javax.media.Buffer readBuffer() throws NyARException
\r
1966 - if(jmf_monitor_stream==null){
\r
1967 - throw new NyARException();
\r
1970 - jmf_monitor_stream.read(read_buf);
\r
1971 - }catch(Exception e){
\r
1972 - throw new NyARException(e);
\r
1974 - return read_buf;
\r
1976 - public void setCaptureListener(JmfCaptureListener i_listener) throws NyARException
\r
1978 - if(jmf_processor!=null){
\r
1979 - throw new NyARException();
\r
1981 - capture_listener=i_listener;
\r
1984 - public void start() throws NyARException
\r
1987 - DataSource ds=getCaptureDS(jmf_video_format);
\r
1988 - VideoFormat[] formats=new VideoFormat[]{new VideoFormat(null)};
\r
1989 - ProcessorModel pm = new ProcessorModel(ds,formats,null);//, formats, ftd);
\r
1990 - Processor processor;
\r
1992 - processor = Manager.createRealizedProcessor(pm);
\r
1993 - } catch (Exception e){
\r
1994 - // Make sure the capture devices are released
\r
1995 - ds.disconnect();
\r
1996 - throw new NyARException(e);
\r
1998 - // Get the monitor control:
\r
1999 - // Since there are more than one MonitorControl objects
\r
2000 - // exported by the DataSource, we get the specific one
\r
2001 - // that is also the MonitorStream object.
\r
2002 - jmf_monitor_stream=(MonitorStream)ds.getControl("jmfsample.MonitorStream");
\r
2003 - jmf_monitor_stream.setCaptureListener(capture_listener);
\r
2004 - jmf_data_source=ds;
\r
2005 - jmf_processor=processor;
\r
2006 - jmf_processor.start();
\r
2008 - public void stop()
\r
2010 - jmf_processor.stop();
\r
2011 - jmf_processor.close();
\r
2012 - jmf_processor = null;
\r
2015 - protected void finalize()
\r
2017 - if(jmf_processor!=null){
\r
2018 - jmf_processor.stop();
\r
2019 - jmf_processor.close();
\r
2020 - jmf_processor = null;
\r
2023 - private static DataSource getCaptureDS(VideoFormat vf) {
\r
2024 - DataSource dsVideo = null;
\r
2025 - DataSource ds = null;
\r
2027 - // Create a capture DataSource for the video
\r
2028 - // If there is no video capture device, then exit with null
\r
2029 - if (vf != null) {
\r
2030 - dsVideo = createDataSource(vf);
\r
2031 - if (dsVideo == null)
\r
2036 - // Create the monitoring datasource wrapper
\r
2037 - if (dsVideo != null) {
\r
2038 - dsVideo = new MonitorCDS(dsVideo);
\r
2042 - // Merge the data sources, if both audio and video are available
\r
2044 - ds = Manager.createMergingDataSource(new DataSource[]{dsVideo});
\r
2045 - } catch (IncompatibleSourceException ise){
\r
2052 - private static DataSource createDataSource(Format format) {
\r
2055 - CaptureDeviceInfo cdi;
\r
2056 - MediaLocator ml;
\r
2058 - // Find devices for format
\r
2059 - devices = CaptureDeviceManager.getDeviceList(format);
\r
2060 - if (devices.size() < 1) {
\r
2061 - System.err.println("! No Devices for " + format);
\r
2064 - // Pick the first device
\r
2065 - cdi = (CaptureDeviceInfo) devices.elementAt(0);
\r
2067 - ml = cdi.getLocator();
\r
2070 - ds = Manager.createDataSource(ml);
\r
2072 - if (ds instanceof CaptureDevice)
\r
2074 - setCaptureFormat((CaptureDevice) ds, format);
\r
2076 - } catch (Exception e) {
\r
2077 - System.err.println(e);
\r
2083 - private static void setCaptureFormat(CaptureDevice cdev, Format format) {
\r
2084 - FormatControl [] fcs = cdev.getFormatControls();
\r
2085 - if (fcs.length < 1){
\r
2088 - FormatControl fc = fcs[0];
\r
2089 - Format [] formats = fc.getSupportedFormats();
\r
2090 - for (int i = 0; i < formats.length; i++) {
\r
2091 - if (formats[i].matches(format)){
\r
2092 - format = formats[i].intersects(format);
\r
2093 - fc.setFormat(format);
\r
2099 \ No newline at end of file
\r
2100 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java
\r
2101 ===================================================================
\r
2102 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java (revision 0)
\r
2103 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java (revision 178)
\r
2106 + * RGB
\8c`
\8e®
\82ÌJMF
\83o
\83b
\83t
\83@
\82ð
\83\89\83b
\83v
\82·
\82éNyARRaster
\82Å
\82·
\81B
\r
2107 + * JMF
\82©
\82ç
\93¾
\82½
\83\89\83X
\83^
\83f
\81[
\83^
\82Ì
\83s
\83N
\83Z
\83\8b\95À
\82Ñ
\8f\87\82ð
\8dl
\97¶
\82µ
\82Ü
\82·
\81B
\r
2108 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
2109 + * airmail(at)ebony.plala.or.jp
\r
2110 + * http://nyatla.jp/
\r
2112 +package jp.nyatla.nyartoolkit.jmf.utils;
\r
2115 +import javax.media.format.RGBFormat;
\r
2116 +import java.awt.Dimension;
\r
2117 +import jp.nyatla.nyartoolkit.NyARException;
\r
2118 +import jp.nyatla.nyartoolkit.core.raster.NyARRaster;
\r
2121 +public class JmfNyARRaster_RGB implements NyARRaster
\r
2123 + public final static int PIXEL_ORDER_RGB=1;
\r
2124 + public final static int PIXEL_ORDER_BGR=2;
\r
2125 + protected int pix_type;
\r
2126 + private int red_idx;
\r
2127 + private int green_idx;
\r
2128 + private int blue_idx;
\r
2129 + protected byte[] ref_buf;
\r
2130 + protected int width=0;
\r
2131 + protected int height=0;
\r
2134 + * RGB
\8c`
\8e®
\82ÌJMF
\83o
\83b
\83t
\83@
\82ð
\83\89\83b
\83v
\82·
\82é
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\82Â
\82
\82è
\82Ü
\82·
\81B
\r
2135 + *
\90¶
\90¬
\92¼
\8cã
\82Ì
\83I
\83u
\83W
\83F
\83N
\83g
\82Í
\83f
\81[
\83^
\82ð
\8e\9d\82¿
\82Ü
\82¹
\82ñ
\81B
\r
2136 + *
\83\81\83\93\83o
\8aÖ
\90\94\82ÍsetBuffer
\82ð
\8eÀ
\8ds
\8cã
\82É
\8eg
\97p
\89Â
\94\
\82É
\82È
\82è
\82Ü
\82·
\81B
\r
2138 + public JmfNyARRaster_RGB(int i_width,int i_height)
\r
2142 + height=i_height;
\r
2145 + *
\83t
\83H
\81[
\83}
\83b
\83g
\82ð
\89ð
\90Í
\82µ
\82Ä
\81A
\83C
\83\93\83X
\83^
\83\93\83X
\82Ì
\83t
\83H
\81[
\83}
\83b
\83g
\83v
\83\8d\83p
\83e
\83B
\82ð
\8f\89\8aú
\89»
\82µ
\82Ü
\82·
\81B
\r
2147 + * @param i_buffer
\r
2148 + * @throws NyARException
\r
2150 + protected void initFormatProperty(RGBFormat i_fmt) throws NyARException
\r
2152 + //
\83f
\81[
\83^
\83T
\83C
\83Y
\82Ì
\8am
\94F
\r
2153 + Dimension s=i_fmt.getSize();
\r
2154 + if(width!=s.width || height !=s.height){
\r
2155 + throw new NyARException();
\r
2157 + //
\83f
\81[
\83^
\94z
\97ñ
\82Ì
\8am
\94F
\r
2158 + red_idx =i_fmt.getRedMask()-1;
\r
2159 + green_idx=i_fmt.getGreenMask()-1;
\r
2160 + blue_idx =i_fmt.getBlueMask()-1;
\r
2162 + //
\90F
\94z
\97ñ
\82Ì
\93Á
\92è
\r
2163 + if(red_idx==0 && blue_idx==2){
\r
2164 + pix_type=PIXEL_ORDER_RGB;
\r
2165 + }else if(red_idx==2 && blue_idx==0){
\r
2166 + pix_type=PIXEL_ORDER_BGR;
\r
2168 + throw new NyARException("Unknown pixel order.");
\r
2172 + * javax.media.Buffer
\82ð
\95ª
\90Í
\82µ
\82Ä
\81A
\82»
\82Ì
\95ª
\90Í
\8c\8b\89Ê
\82ðNyARRaster
\82É
\93K
\8d\87\82·
\82é
\8c`
\82Å
\95Û
\8e\9d\82µ
\82Ü
\82·
\81B
\r
2173 + *
\8aÖ
\90\94\8eÀ
\8ds
\8cã
\82É
\8aO
\95\94\82Åi_buffer
\82Ì
\93à
\97e
\95Ï
\8dX
\82µ
\82½
\8fê
\8d\87\82É
\82Í
\81A
\8dÄ
\93xsetBuffer
\8aÖ
\90\94\82ð
\8cÄ
\82Ñ
\8fo
\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B
\r
2174 + * @param i_buffer
\r
2175 + * RGB
\8c`
\8e®
\82Ì
\83f
\81[
\83^
\82ð
\8ai
\94[
\82µ
\82½javax.media.Buffer
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\8ew
\92è
\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B
\r
2177 + * i_buffer
\82ð
\83\89\83b
\83v
\82µ
\82½
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\95Ô
\82µ
\82Ü
\82·
\81B
\r
2178 + * @throws NyARException
\r
2180 + public void setBuffer(javax.media.Buffer i_buffer) throws NyARException
\r
2182 + initFormatProperty((RGBFormat)i_buffer.getFormat());
\r
2183 + ref_buf=(byte[])i_buffer.getData();
\r
2185 + public int getPixelTotal(int i_x,int i_y)
\r
2187 + int bp=(i_x+i_y*width)*3;
\r
2188 + return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);
\r
2190 + public int getWidth()
\r
2194 + public int getHeight()
\r
2198 + public void pickRgbArray(int i_x,int i_y,int[] i_rgb)
\r
2200 + int bp=(i_x+i_y*width)*3;
\r
2201 + i_rgb[0]=(ref_buf[bp+red_idx] & 0xff);//R
\r
2202 + i_rgb[1]=(ref_buf[bp+green_idx] & 0xff);//G
\r
2203 + i_rgb[2]=(ref_buf[bp+blue_idx] & 0xff);//B
\r
2206 + *
\83s
\83N
\83Z
\83\8b\82Ì
\8f\87\8f\98\83^
\83C
\83v
\82ð
\95Ô
\82µ
\82Ü
\82·
\81B
\r
2210 + public int getPixelOrder()
\r
2212 + return pix_type;
\r
2215 + *
\83f
\81[
\83^
\82ð
\8e\9d\82Á
\82Ä
\82¢
\82é
\82©
\82ð
\95Ô
\82µ
\82Ü
\82·
\81B
\r
2218 + public boolean hasData()
\r
2220 + return ref_buf!=null;
\r
2224 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java
\r
2225 ===================================================================
\r
2226 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java (revision 0)
\r
2227 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java (revision 178)
\r
2230 + * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
\r
2232 + * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
\r
2233 + * modify and redistribute this software in source and binary code form,
\r
2234 + * provided that i) this copyright notice and license appear on all copies of
\r
2235 + * the software; and ii) Licensee does not utilize the software in a manner
\r
2236 + * which is disparaging to Sun.
\r
2238 + * This software is provided "AS IS," without a warranty of any kind. ALL
\r
2239 + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
\r
2240 + * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
\r
2241 + * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
\r
2242 + * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
\r
2243 + * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
\r
2244 + * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
\r
2245 + * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
\r
2246 + * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
\r
2247 + * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
\r
2248 + * POSSIBILITY OF SUCH DAMAGES.
\r
2250 + * This software is not designed or intended for use in on-line control of
\r
2251 + * aircraft, air traffic, aircraft navigation or aircraft communications; or in
\r
2252 + * the design, construction, operation or maintenance of any nuclear
\r
2253 + * facility. Licensee represents and warrants that it will not use or
\r
2254 + * redistribute the Software for such purposes.
\r
2256 +package jp.nyatla.nyartoolkit.jmf.utils;
\r
2259 +import javax.media.*;
\r
2260 +import javax.media.protocol.*;
\r
2261 +import javax.media.control.*;
\r
2263 +import java.io.IOException;
\r
2267 +public class MonitorCDS extends PushBufferDataSource{
\r
2269 + private PushBufferDataSource delegate = null;
\r
2270 + private PushBufferStream [] delStreams = null;
\r
2271 + private MonitorStream monitorStream = null;
\r
2272 + private PushBufferStream [] monitorStreams = null;
\r
2273 + boolean delStarted = false; // variable used by MonitorStream also
\r
2274 + private Control [] controls;
\r
2276 + public MonitorCDS(DataSource ds)
\r
2278 + // Get the stream from the actual datasource
\r
2279 + // and create a MonitorStream from it
\r
2280 + // Export the MonitorControl interface of the MonitorStream
\r
2281 + if (ds instanceof PushBufferDataSource)
\r
2283 + delegate = (PushBufferDataSource) ds;
\r
2284 + delStreams = delegate.getStreams();
\r
2285 + monitorStream = new MonitorStream(delStreams[0], this);
\r
2286 + monitorStreams = new PushBufferStream[] {monitorStream};
\r
2290 + public Object [] getControls()
\r
2292 + return controls;
\r
2295 + public Object getControl(String value) {
\r
2296 + if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl"))
\r
2297 + return monitorStream;
\r
2302 + public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
\r
2304 + return ((CaptureDevice)delegate).getCaptureDeviceInfo();
\r
2307 + public FormatControl[] getFormatControls()
\r
2309 + return ((CaptureDevice)delegate).getFormatControls();
\r
2312 + public String getContentType()
\r
2314 + return delegate.getContentType();
\r
2317 + public void connect() throws IOException
\r
2319 + if (delegate == null)
\r
2320 + throw new IOException("Incompatible DataSource");
\r
2321 + // Delegate is already connected
\r
2324 + public void disconnect()
\r
2326 + monitorStream.setEnabled(false);
\r
2327 + delegate.disconnect();
\r
2330 + public synchronized void start() throws IOException
\r
2332 + startDelegate();
\r
2333 + delStarted = true;
\r
2336 + public synchronized void stop() throws IOException
\r
2338 + if (!monitorStream.isEnabled()) {
\r
2341 + delStarted = false;
\r
2344 + public Time getDuration()
\r
2346 + return delegate.getDuration();
\r
2349 + public PushBufferStream [] getStreams()
\r
2351 + return monitorStreams;
\r
2354 + void startDelegate() throws IOException
\r
2356 + delegate.start();
\r
2359 + void stopDelegate() throws IOException
\r
2361 + delegate.stop();
\r
2365 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java
\r
2366 ===================================================================
\r
2367 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java (revision 0)
\r
2368 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java (revision 178)
\r
2371 + * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
\r
2373 + * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
\r
2374 + * modify and redistribute this software in source and binary code form,
\r
2375 + * provided that i) this copyright notice and license appear on all copies of
\r
2376 + * the software; and ii) Licensee does not utilize the software in a manner
\r
2377 + * which is disparaging to Sun.
\r
2379 + * This software is provided "AS IS," without a warranty of any kind. ALL
\r
2380 + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
\r
2381 + * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
\r
2382 + * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
\r
2383 + * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
\r
2384 + * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
\r
2385 + * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
\r
2386 + * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
\r
2387 + * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
\r
2388 + * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
\r
2389 + * POSSIBILITY OF SUCH DAMAGES.
\r
2391 + * This software is not designed or intended for use in on-line control of
\r
2392 + * aircraft, air traffic, aircraft navigation or aircraft communications; or in
\r
2393 + * the design, construction, operation or maintenance of any nuclear
\r
2394 + * facility. Licensee represents and warrants that it will not use or
\r
2395 + * redistribute the Software for such purposes.
\r
2397 +package jp.nyatla.nyartoolkit.jmf.utils;
\r
2401 +import javax.media.*;
\r
2402 +import javax.media.protocol.*;
\r
2404 +import javax.media.util.BufferToImage;
\r
2405 +import java.io.IOException;
\r
2406 +import java.awt.*;
\r
2408 +public class MonitorStream implements PushBufferStream, BufferTransferHandler {
\r
2410 + JmfCaptureListener img_listener;
\r
2411 + PushBufferStream actual = null;
\r
2412 + boolean dataAvailable = false;
\r
2413 + boolean terminate = false;
\r
2414 + boolean enabled = false;
\r
2415 + Object bufferLock = new Object();
\r
2416 + Buffer cbuffer = new Buffer();
\r
2417 + BufferTransferHandler transferHandler = null;
\r
2418 + Component component = null;
\r
2420 + BufferToImage bti = null;
\r
2422 + MonitorStream(PushBufferStream actual, MonitorCDS cds) {
\r
2423 + this.actual = actual;
\r
2424 + actual.setTransferHandler(this);
\r
2428 + public javax.media.Format getFormat()
\r
2430 + return actual.getFormat();
\r
2433 + *
\94ñ
\93¯
\8aúREAD
\r
2435 + public void read(Buffer buffer) throws IOException
\r
2437 + // Wait for data to be available
\r
2438 + // Doesn't get used much because the transferData
\r
2439 + // call is made when data IS available. And most
\r
2440 + // Processors/Players read the data in the same
\r
2441 + // thread that called transferData, although that's
\r
2442 + // not a safe assumption to make
\r
2443 + if (!dataAvailable) {
\r
2444 + synchronized (bufferLock) {
\r
2445 + while (!dataAvailable && !terminate) {
\r
2447 + bufferLock.wait(100);
\r
2448 + } catch (InterruptedException ie) {
\r
2454 + if (dataAvailable) {
\r
2455 + synchronized (bufferLock) {
\r
2456 + // Copy the buffer attributes, but swap the data
\r
2457 + // attributes so that no extra copy is made.
\r
2458 + buffer.copy(cbuffer, true);
\r
2459 + //dataAvailable = false;
\r
2464 + public void setCaptureListener(JmfCaptureListener i_listener)
\r
2466 + img_listener=i_listener;
\r
2469 + public void transferData(PushBufferStream pbs)
\r
2471 + // Get the data from the original source stream
\r
2472 + synchronized (bufferLock) {
\r
2474 + pbs.read(cbuffer);
\r
2475 + } catch (IOException ioe) {
\r
2478 + dataAvailable = true;
\r
2479 + bufferLock.notifyAll();
\r
2481 + if(img_listener!=null){
\r
2482 + img_listener.onUpdateBuffer(cbuffer);
\r
2486 + // Display data if monitor is active
\r
2487 + if (isEnabled()) {
\r
2488 + if (bti == null) {
\r
2489 + VideoFormat vf = (VideoFormat) cbuffer.getFormat();
\r
2490 + bti = new BufferToImage(vf);
\r
2492 + if (bti != null && component != null) {
\r
2493 + Image im = bti.createImage(cbuffer);
\r
2494 + Graphics g = component.getGraphics();
\r
2495 + Dimension size = component.getSize();
\r
2497 + g.drawImage(im, 0, 0, component);
\r
2501 + // Maybe synchronize this with setTransferHandler() ?
\r
2502 + if (transferHandler != null && cds.delStarted)
\r
2503 + transferHandler.transferData(this);
\r
2506 + public void setTransferHandler(BufferTransferHandler transferHandler) {
\r
2507 + this.transferHandler = transferHandler;
\r
2510 + public boolean setEnabled(boolean value) {
\r
2511 + enabled = value;
\r
2512 + if (value == false) {
\r
2513 + if (!cds.delStarted) {
\r
2515 + cds.stopDelegate();
\r
2516 + } catch (IOException ioe) {
\r
2520 + // Start the capture datasource if the monitor is enabled
\r
2522 + cds.startDelegate();
\r
2523 + }catch (IOException ioe) {
\r
2529 + public boolean isEnabled()
\r
2536 + public float setPreviewFrameRate(float rate)
\r
2538 + System.err.println("TODO");
\r
2542 + public ContentDescriptor getContentDescriptor()
\r
2544 + return actual.getContentDescriptor();
\r
2547 + public long getContentLength()
\r
2549 + return actual.getContentLength();
\r
2552 + public boolean endOfStream() {
\r
2553 + return actual.endOfStream();
\r
2556 + public Object [] getControls() {
\r
2557 + return new Object[0];
\r
2560 + public Object getControl(String str) {
\r
2566 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java
\r
2567 ===================================================================
\r
2568 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java (revision 0)
\r
2569 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java (revision 178)
\r
2572 + * JMF
\82¨
\8eè
\8cy
\83L
\83\83\83v
\83`
\83\83\97p
\83\8a\83X
\83i
\r
2573 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
2574 + * airmail@ebony.plala.or.jp
\r
2575 + * http://nyatla.jp/
\r
2577 +package jp.nyatla.nyartoolkit.jmf.utils;
\r
2579 +import javax.media.Buffer;
\r
2581 +public interface JmfCaptureListener{
\r
2582 + public void onUpdateBuffer(Buffer i_buffer);
\r
2585 \ No newline at end of file
\r
2586 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java
\r
2587 ===================================================================
\r
2588 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java (revision 0)
\r
2589 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java (revision 178)
\r
2592 + * JMF
\82¨
\8eè
\8cy
\83L
\83\83\83v
\83`
\83\83\83N
\83\89\83X
\r
2593 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
2594 + * airmail@ebony.plala.or.jp
\r
2595 + * http://nyatla.jp/
\r
2597 +package jp.nyatla.nyartoolkit.jmf.utils;
\r
2601 +import javax.media.*;
\r
2602 +import javax.media.protocol.*;
\r
2603 +import javax.media.control.*;
\r
2604 +import javax.media.format.*;
\r
2605 +import java.awt.*;
\r
2606 +import java.util.*;
\r
2607 +import javax.media.protocol.DataSource;
\r
2609 +import jp.nyatla.nyartoolkit.NyARException;
\r
2615 +public class JmfCameraCapture
\r
2617 + private Dimension image_size;
\r
2618 + private JmfCaptureListener capture_listener;
\r
2619 + private DataSource jmf_data_source;
\r
2620 + private MonitorStream jmf_monitor_stream;
\r
2621 + private Processor jmf_processor;
\r
2622 + private VideoFormat jmf_video_format;
\r
2624 + private Buffer read_buf=new Buffer();
\r
2625 + public static final String PIXEL_FORMAT_RGB="RGB";
\r
2626 + public JmfCameraCapture(int i_width,int i_height,float i_rate,String i_pixcel_format)
\r
2628 + String encoding = i_pixcel_format;//comboEncoding.getSelectedItem();
\r
2629 + image_size = new Dimension(i_width,i_height);
\r
2630 + jmf_video_format = new VideoFormat(encoding, image_size, Format.NOT_SPECIFIED,null,i_rate);
\r
2632 + public Dimension getSize()
\r
2634 + return image_size;
\r
2636 + public javax.media.Buffer readBuffer() throws NyARException
\r
2638 + if(jmf_monitor_stream==null){
\r
2639 + throw new NyARException();
\r
2642 + jmf_monitor_stream.read(read_buf);
\r
2643 + }catch(Exception e){
\r
2644 + throw new NyARException(e);
\r
2646 + return read_buf;
\r
2648 + public void setCaptureListener(JmfCaptureListener i_listener) throws NyARException
\r
2650 + if(jmf_processor!=null){
\r
2651 + throw new NyARException();
\r
2653 + capture_listener=i_listener;
\r
2656 + public void start() throws NyARException
\r
2659 + DataSource ds=getCaptureDS(jmf_video_format);
\r
2660 + VideoFormat[] formats=new VideoFormat[]{new VideoFormat(null)};
\r
2661 + ProcessorModel pm = new ProcessorModel(ds,formats,null);//, formats, ftd);
\r
2662 + Processor processor;
\r
2664 + processor = Manager.createRealizedProcessor(pm);
\r
2665 + } catch (Exception e){
\r
2666 + // Make sure the capture devices are released
\r
2667 + ds.disconnect();
\r
2668 + throw new NyARException(e);
\r
2670 + // Get the monitor control:
\r
2671 + // Since there are more than one MonitorControl objects
\r
2672 + // exported by the DataSource, we get the specific one
\r
2673 + // that is also the MonitorStream object.
\r
2674 + jmf_monitor_stream=(MonitorStream)ds.getControl("jmfsample.MonitorStream");
\r
2675 + jmf_monitor_stream.setCaptureListener(capture_listener);
\r
2676 + jmf_data_source=ds;
\r
2677 + jmf_processor=processor;
\r
2678 + jmf_processor.start();
\r
2680 + public void stop()
\r
2682 + jmf_processor.stop();
\r
2683 + jmf_processor.close();
\r
2684 + jmf_processor = null;
\r
2687 + protected void finalize()
\r
2689 + if(jmf_processor!=null){
\r
2690 + jmf_processor.stop();
\r
2691 + jmf_processor.close();
\r
2692 + jmf_processor = null;
\r
2695 + private static DataSource getCaptureDS(VideoFormat vf) {
\r
2696 + DataSource dsVideo = null;
\r
2697 + DataSource ds = null;
\r
2699 + // Create a capture DataSource for the video
\r
2700 + // If there is no video capture device, then exit with null
\r
2701 + if (vf != null) {
\r
2702 + dsVideo = createDataSource(vf);
\r
2703 + if (dsVideo == null)
\r
2708 + // Create the monitoring datasource wrapper
\r
2709 + if (dsVideo != null) {
\r
2710 + dsVideo = new MonitorCDS(dsVideo);
\r
2714 + // Merge the data sources, if both audio and video are available
\r
2716 + ds = Manager.createMergingDataSource(new DataSource[]{dsVideo});
\r
2717 + } catch (IncompatibleSourceException ise){
\r
2724 + private static DataSource createDataSource(Format format) {
\r
2727 + CaptureDeviceInfo cdi;
\r
2728 + MediaLocator ml;
\r
2730 + // Find devices for format
\r
2731 + devices = CaptureDeviceManager.getDeviceList(format);
\r
2732 + if (devices.size() < 1) {
\r
2733 + System.err.println("! No Devices for " + format);
\r
2736 + // Pick the first device
\r
2737 + cdi = (CaptureDeviceInfo) devices.elementAt(0);
\r
2739 + ml = cdi.getLocator();
\r
2742 + ds = Manager.createDataSource(ml);
\r
2744 + if (ds instanceof CaptureDevice)
\r
2746 + setCaptureFormat((CaptureDevice) ds, format);
\r
2748 + } catch (Exception e) {
\r
2749 + System.err.println(e);
\r
2755 + private static void setCaptureFormat(CaptureDevice cdev, Format format) {
\r
2756 + FormatControl [] fcs = cdev.getFormatControls();
\r
2757 + if (fcs.length < 1){
\r
2760 + FormatControl fc = fcs[0];
\r
2761 + Format [] formats = fc.getSupportedFormats();
\r
2762 + for (int i = 0; i < formats.length; i++) {
\r
2763 + if (formats[i].matches(format)){
\r
2764 + format = formats[i].intersects(format);
\r
2765 + fc.setFormat(format);
\r
2771 \ No newline at end of file
\r
2772 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/JmfCaptureTest.java
\r
2773 ===================================================================
\r
2774 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/JmfCaptureTest.java (revision 0)
\r
2775 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/JmfCaptureTest.java (revision 178)
\r
2778 + * VFM
\83L
\83\83\83v
\83`
\83\83\83e
\83X
\83g
\83v
\83\8d\83O
\83\89\83\80\r
2779 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
2780 + * airmail@ebony.plala.or.jp
\r
2781 + * http://nyatla.jp/
\r
2783 +package jp.nyatla.nyartoolkit.jmf.sample;
\r
2785 +import javax.media.*;
\r
2787 +import javax.media.util.BufferToImage;
\r
2788 +import javax.media.format.*;
\r
2789 +import jp.nyatla.nyartoolkit.NyARException;
\r
2790 +import jp.nyatla.nyartoolkit.jmf.utils.*;
\r
2792 +import java.awt.*;
\r
2796 +public class JmfCaptureTest extends Frame implements JmfCaptureListener{
\r
2797 + public JmfCaptureTest() throws NyARException
\r
2799 + setTitle("JmfCaptureTest");
\r
2800 + setBounds(0,0,320+64,240+64);
\r
2801 + capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
\r
2802 + capture.setCaptureListener(this);
\r
2807 + private JmfCameraCapture capture;
\r
2808 + public void onUpdateBuffer(Buffer i_buffer)
\r
2810 + BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
\r
2811 + Image img=b2i.createImage(i_buffer);
\r
2812 + Graphics g = getGraphics();
\r
2813 + g.drawImage(img, 32, 32,this);
\r
2815 + private void startCapture()
\r
2818 + capture.start();
\r
2819 + }catch(Exception e){
\r
2820 + e.printStackTrace();
\r
2823 + public static void main(String[] args) {
\r
2825 + JmfCaptureTest mainwin = new JmfCaptureTest();
\r
2826 + mainwin.setVisible(true);
\r
2827 + mainwin.startCapture();
\r
2828 + }catch(Exception e){
\r
2829 + e.printStackTrace();
\r
2835 Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java
\r
2836 ===================================================================
\r
2837 --- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (revision 0)
\r
2838 +++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (revision 178)
\r
2841 + * VFM+ARToolkit
\83e
\83X
\83g
\83v
\83\8d\83O
\83\89\83\80\r
2842 + *
\83J
\83\81\83\89\82©
\82ç
\8eæ
\82è
\8d\9e\82ñ
\82¾
\83f
\81[
\83^
\82©
\82ç
\83}
\81[
\83J
\81[
\82ð
\8c\9f\8fo
\82µ
\82Ä
\81A
\88ê
\92v
\93x
\82Æ
\95Ï
\8a·
\8ds
\97ñ
\82ð
\95\
\8e¦
\82µ
\82Ü
\82·
\81B
\r
2843 + * (c)2008 A
\8cÕ
\81\97nyatla.jp
\r
2844 + * airmail(at)ebony.plala.or.jp
\r
2845 + * http://nyatla.jp/
\r
2847 +package jp.nyatla.nyartoolkit.jmf.sample;
\r
2849 +import javax.media.*;
\r
2851 +import javax.media.util.BufferToImage;
\r
2852 +import javax.media.format.*;
\r
2854 +import jp.nyatla.nyartoolkit.NyARException;
\r
2855 +import jp.nyatla.nyartoolkit.jmf.utils.*;
\r
2857 +import java.awt.*;
\r
2859 +import jp.nyatla.nyartoolkit.core.*;
\r
2860 +import jp.nyatla.nyartoolkit.detector.*;
\r
2867 +public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
\r
2869 + private final String CARCODE_FILE ="../../Data/patt.hiro";
\r
2870 + private final String PARAM_FILE ="../../Data/camera_para.dat";
\r
2871 + private JmfCameraCapture capture;
\r
2872 + NyARSingleDetectMarker nya;
\r
2873 + JmfNyARRaster_RGB raster;
\r
2875 + public NyarToolkitLinkTest() throws NyARException,NyARException
\r
2877 + setTitle("JmfCaptureTest");
\r
2878 + setBounds(0,0,320+64,240+64);
\r
2879 + //
\83L
\83\83\83v
\83`
\83\83\82Ì
\8f\80\94õ
\r
2880 + capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
\r
2881 + capture.setCaptureListener(this);
\r
2883 + //NyARToolkit
\82Ì
\8f\80\94õ
\r
2884 + NyARParam ar_param=new NyARParam();
\r
2885 + NyARCode ar_code =new NyARCode(16,16);
\r
2886 + ar_param.loadFromARFile(PARAM_FILE);
\r
2887 + ar_param.changeSize(320,240);
\r
2888 + nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);
\r
2889 + ar_code.loadFromARFile(CARCODE_FILE);
\r
2890 + //
\83L
\83\83\83v
\83`
\83\83\83C
\83\81\81[
\83W
\97p
\82Ì
\83\89\83X
\83^
\82ð
\8f\80\94õ
\r
2891 + raster=new JmfNyARRaster_RGB(320,240);
\r
2896 + public void onUpdateBuffer(Buffer i_buffer)
\r
2899 + //
\83L
\83\83\83v
\83`
\83\83\82µ
\82½
\83o
\83b
\83t
\83@
\82ð
\83\89\83X
\83^
\82É
\83Z
\83b
\83g
\r
2900 + raster.setBuffer(i_buffer);
\r
2902 + //
\83L
\83\83\83v
\83`
\83\83\82µ
\82½
\83C
\83\81\81[
\83W
\82ð
\95\
\8e¦
\97p
\82É
\89Á
\8dH
\r
2903 + BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
\r
2904 + Image img=b2i.createImage(i_buffer);
\r
2906 + Graphics g = getGraphics();
\r
2907 + double[][] atm=null;
\r
2909 + //
\83}
\81[
\83J
\81[
\8c\9f\8fo
\r
2910 + boolean is_marker_exist=nya.detectMarkerLite(raster,100);
\r
2911 + if(is_marker_exist){
\r
2912 + //
\95Ï
\8a·
\8ds
\97ñ
\82ð
\8eæ
\93¾
\r
2913 + atm=nya.getTransmationMatrix().getArray();
\r
2915 + //
\8fî
\95ñ
\82ð
\89æ
\96Ê
\82É
\8f\91\82
\r
2916 + g.drawImage(img, 32, 32,this);
\r
2917 + if(is_marker_exist){
\r
2918 + g.drawString("
\83}
\81[
\83J
\81[
\8c\9f\8fo:"+nya.getConfidence(),32,50);
\r
2919 + for(int i=0;i<3;i++){
\r
2920 + for(int i2=0;i2<4;i2++){
\r
2921 + g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);
\r
2926 + g.drawString("
\83}
\81[
\83J
\81[
\96¢
\8c\9f\8fo:",32,100);
\r
2928 + }catch(Exception e){
\r
2929 + e.printStackTrace();
\r
2936 + private void startCapture()
\r
2939 + capture.start();
\r
2940 + }catch(Exception e){
\r
2941 + e.printStackTrace();
\r
2944 + public static void main(String[] args) {
\r
2946 + NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();
\r
2947 + mainwin.setVisible(true);
\r
2948 + mainwin.startCapture();
\r
2949 + }catch(Exception e){
\r
2950 + e.printStackTrace();
\r
2956 -2008.03.29 R.Iizuka nyatla.jp
\r
2957 +2008.03.29 R.Iizuka A
\8cÕ
\81\97nyatla.jp
\r
2958 Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARCode.java
\r
2959 ===================================================================
\r
2960 --- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARCode.java (revision 174)
\r
2961 +++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARCode.java (revision 178)
\r
2963 package jp.nyatla.nyartoolkit.core;
\r
2965 import java.io.FileInputStream;
\r
2966 +import java.io.InputStream;
\r
2967 import java.io.InputStreamReader;
\r
2968 import java.io.StreamTokenizer;
\r
2970 @@ -84,19 +85,32 @@
\r
2971 pat=new int[4][height][width][3];//static int pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
2972 patBW=new short[4][height][width];//static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
2977 * int arLoadPatt( const char *filename );
\r
2978 * ARToolKit
\82Ì
\83p
\83^
\81[
\83\93\83t
\83@
\83C
\83\8b\82ð
\83\8d\81[
\83h
\82·
\82é
\81B
\r
2979 + *
\83t
\83@
\83C
\83\8b\8c`
\8e®
\82ÍBGR
\8c`
\8e®
\82Å
\8bL
\98^
\82³
\82ê
\82½
\83p
\83^
\81[
\83\93\83t
\83@
\83C
\83\8b\82Å
\82 \82é
\82±
\82Æ
\81B
\r
2982 * @throws Exception
\r
2984 public void loadFromARFile(String filename) throws NyARException
\r
2987 + loadFromARFile(new FileInputStream(filename));
\r
2989 + } catch (Exception e) {
\r
2990 + throw new NyARException(e);
\r
2995 + * @param i_stream
\r
2996 + * @throws NyARException
\r
2998 + public void loadFromARFile(InputStream i_stream) throws NyARException
\r
3001 - StreamTokenizer st=new StreamTokenizer(new InputStreamReader(new FileInputStream(filename)));
\r
3002 + StreamTokenizer st=new StreamTokenizer(new InputStreamReader(i_stream));
\r
3003 //
\83p
\83^
\81[
\83\93\83f
\81[
\83^
\82ÍGBRA
\82Å
\95À
\82ñ
\82Å
\82é
\81B
\r
3004 for(int h=0; h<4; h++ ) {
\r
3006 Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARParam.java
\r
3007 ===================================================================
\r
3008 --- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARParam.java (revision 174)
\r
3009 +++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARParam.java (revision 178)
\r
3010 @@ -72,18 +72,25 @@
\r
3012 public void loadFromARFile(String i_filename) throws NyARException
\r
3015 - FileInputStream fs=new FileInputStream(i_filename);
\r
3016 - NyARParam new_inst[]=arParamLoad(fs,1);
\r
3018 - xsize =new_inst[0].xsize;
\r
3019 - ysize =new_inst[0].ysize;
\r
3020 - mat =new_inst[0].mat;
\r
3021 - dist_factor=new_inst[0].dist_factor;
\r
3022 - }catch(Exception e){
\r
3023 - throw new NyARException(e);
\r
3026 + loadFromARFile(new FileInputStream(i_filename));
\r
3027 + } catch (Exception e) {
\r
3028 + throw new NyARException(e);
\r
3031 + public void loadFromARFile(InputStream i_stream) throws NyARException
\r
3034 + NyARParam new_inst[] = arParamLoad(i_stream, 1);
\r
3035 + i_stream.close();
\r
3036 + xsize = new_inst[0].xsize;
\r
3037 + ysize = new_inst[0].ysize;
\r
3038 + mat = new_inst[0].mat;
\r
3039 + dist_factor = new_inst[0].dist_factor;
\r
3040 + } catch (Exception e) {
\r
3041 + throw new NyARException(e);
\r
3044 /*static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )*/
\r
3045 private static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )
\r
3047 Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt.java
\r
3048 ===================================================================
\r
3049 --- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt.java (revision 174)
\r
3050 +++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt.java (revision 178)
\r
3052 public double getConfidence();
\r
3053 public int getDirection();
\r
3054 public void evaluate(NyARCode i_code);
\r
3055 - public void setPatt(NyARColorPatt i_target_patt) throws NyARException;
\r
3056 + public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException;
\r
3060 Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java
\r
3061 ===================================================================
\r
3062 --- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java (revision 174)
\r
3063 +++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java (revision 178)
\r
3065 public int getDirection(){
\r
3068 - public void setPatt(NyARColorPatt i_target_patt) throws NyARException
\r
3069 + public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException
\r
3071 width=i_target_patt.getWidth();
\r
3072 height=i_target_patt.getHeight();
\r
3073 @@ -81,11 +81,12 @@
\r
3075 datapow = Math.sqrt( (double)sum );
\r
3076 if(datapow == 0.0){
\r
3077 - throw new NyARException();
\r
3078 + return false;// throw new NyARException();
\r
3079 // dir.set(0);//*dir = 0;
\r
3080 // cf.set(-1.0);//*cf = -1.0;
\r
3087 * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer cf)
\r
3088 Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java
\r
3089 ===================================================================
\r
3090 --- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java (revision 174)
\r
3091 +++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java (revision 178)
\r
3093 public int getDirection(){
\r
3096 - public void setPatt(NyARColorPatt i_target_patt) throws NyARException
\r
3097 + public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException
\r
3099 width=i_target_patt.getWidth();
\r
3100 height=i_target_patt.getHeight();
\r
3101 @@ -87,11 +87,12 @@
\r
3103 datapow = Math.sqrt( (double)sum );
\r
3104 if(datapow == 0.0){
\r
3105 - throw new NyARException();
\r
3106 + return false;//throw new NyARException();
\r
3107 // dir.set(0);//*dir = 0;
\r
3108 // cf.set(-1.0);//*cf = -1.0;
\r
3115 * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer cf)
\r
3116 Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java
\r
3117 ===================================================================
\r
3118 --- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java (revision 174)
\r
3119 +++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java (revision 178)
\r
3121 private int dir=0;
\r
3123 private int[][][] input=new int[height][width][3];
\r
3124 - public void setPatt(NyARColorPatt i_target_patt) throws NyARException
\r
3125 + public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException
\r
3127 width=i_target_patt.getWidth();
\r
3128 height=i_target_patt.getHeight();
\r
3129 @@ -71,11 +71,12 @@
\r
3131 datapow = Math.sqrt( (double)sum );
\r
3132 if( datapow == 0.0 ){
\r
3133 - throw new NyARException();
\r
3134 + return false;// throw new NyARException();
\r
3135 // dir.set(0);//*dir = 0;
\r
3136 // cf.set(-1.0);//*cf = -1.0;
\r
3141 public double getConfidence()
\r
3143 Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java
\r
3144 ===================================================================
\r
3145 --- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (revision 174)
\r
3146 +++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (revision 178)
\r
3147 @@ -91,7 +91,10 @@
\r
3148 //
\83p
\83^
\81[
\83\93\82Ì
\95]
\89¿
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\8dì
\82é
\81B
\r
3149 NyARMatchPatt_Color_WITHOUT_PCA eva=new NyARMatchPatt_Color_WITHOUT_PCA();
\r
3150 //
\83p
\83^
\81[
\83\93\82ð
\95]
\89¿
\8aí
\82É
\83Z
\83b
\83g
\r
3151 - eva.setPatt(patt);
\r
3152 + if(!eva.setPatt(patt)){
\r
3153 + //
\8cv
\8eZ
\82É
\8e¸
\94s
\82µ
\82½
\81B
\r
3156 //
\83R
\81[
\83h
\82Æ
\94ä
\8ar
\82·
\82é
\r
3157 eva.evaluate(code);
\r
3158 int square_index=0;
\r