• R/O
  • HTTP
  • SSH
  • HTTPS

nyartoolkit-and: Commit

NyARToolkit for Android v2.x, 3.x mainline.

master: NyARToolkit core.
android-1.6: for Android 1.6. obsolete version.
android-2.2: for Android 2.2. current version.


Commit MetaInfo

Revisionbc64cbadcf99b914e5f24ee3df9d3fb77ad90da8 (tree)
Time2008-06-07 11:37:50
Authornyatla <nyatla@7cac...>
Commiternyatla

Log Message

[リリース]NyARToolkit 1.0.0

git-svn-id: http://svn.sourceforge.jp/svnroot/nyartoolkit/NyARToolkit@80 7cac0a50-4618-4814-88d0-24b83990f816

Change Summary

Incremental Difference

--- a/trunk/changelog/0.6.20080330.0.txt
+++ /dev/null
@@ -1,30 +0,0 @@
1-2008.03.30 version 0.6.20080330.0
2-
3-*Title
4--メモリ管理の見直し
5--速度向上(84%up)
6--サンプルの15fps化
7-
8-*PublicAPI
9-
10--NyARCode.java
11-[改名--rename]
12- NyARCode::LoadFromARFileをNyARCode::loadFromARFile
13-
14--NyARDetectMarker.java
15-[廃止--delete]
16-NyARDetectMarker::getMarkerArray
17-[追加--add]
18-NyARDetectMarker::getMarker
19-
20-
21--NyARMat.java
22-[更新--update]
23-NyARMat::matrixSelfInv
24-NyARMat::matrixDup
25-
26--DoubleValue.java
27-[廃止--delete]
28-DoubleValue::set
29-DoubleValue::get
30-DoubleValue::add
--- a/trunk/changelog/0.7.20080406.0.txt
+++ /dev/null
@@ -1,595 +0,0 @@
1-2008.04.06 version 0.7.20080406.0
2-
3-*Title
4--バグフィクス
5---キャプチャ画像のBGRをRGBとして評価していたのを修正
6---JMFキャプチャ画像ピクセルフォーマット認識の自動化
7---サンプルバグ修正
8---スペルミス修正
9-
10-
11-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java
12-===================================================================
13---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java (revision 172)
14-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java (revision 173)
15-@@ -121,9 +121,8 @@
16- //NyARToolkitの準備
17- try{
18- //キャプチャの準備
19-- capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXCEL_FORMAT_RGB);
20-+ capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXEL_FORMAT_RGB);
21- capture.setCaptureListener(this);
22-- capture.start();
23- //NyARToolkitの準備
24- ar_param=new GLNyARParam();
25- NyARCode ar_code =new NyARCode(16,16);
26-@@ -132,8 +131,9 @@
27- nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0);
28- ar_code.loadFromARFile(CARCODE_FILE);
29- //GL対応のRGBラスタオブジェクト
30-- cap_image=new GLNyARRaster_RGB(gl,ar_param,320,240);
31--
32-+ cap_image=new GLNyARRaster_RGB(gl,ar_param);
33-+ //キャプチャ開始
34-+ capture.start();
35- }catch(Exception e){
36- e.printStackTrace();
37- }
38-@@ -166,17 +166,10 @@
39- {
40-
41- try{
42-- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
43--
44--
45-- //キャプチャしたイメージを加工
46-- Buffer b=capture.readBuffer();
47-- //BufferToImage b2i=new BufferToImage((VideoFormat)b.getFormat());
48-- if(b.getData()==null){
49-+ if(!cap_image.hasData()){
50- return;
51-- }else{
52-- //画像準備OK
53-- }
54-+ }
55-+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
56- //画像チェックしてマーカー探して、背景を書く
57- boolean is_marker_exist;
58- synchronized(cap_image){
59-@@ -206,7 +199,7 @@
60- {
61- try{
62- synchronized(cap_image){
63-- cap_image.setRawData((byte[])i_buffer.getData(), true);
64-+ cap_image.setBuffer(i_buffer, true);
65- }
66- }catch(Exception e){
67- e.printStackTrace();
68-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/gutil/GLNyARRaster_RGB.java
69-===================================================================
70---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/gutil/GLNyARRaster_RGB.java (revision 172)
71-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/gutil/GLNyARRaster_RGB.java (revision 173)
72-@@ -1,5 +1,6 @@
73- /**
74-- * NyARRaster_RGBにOpenGL向け関数を追加したもの
75-+ * NyARRaster_RGBにOpenGL向け関数を追加したものです。
76-+ *
77- * (c)2008 R.iizuka
78- * airmail(at)ebony.plala.or.jp
79- * http://nyatla.jp/
80-@@ -12,37 +13,58 @@
81- import javax.media.opengl.GL;
82- import javax.media.opengl.glu.GLU;
83-
84-+import jp.nyatla.nyartoolkit.NyARException;
85- import jp.nyatla.nyartoolkit.core.NyARParam;
86--import jp.nyatla.nyartoolkit.core.raster.NyARRaster_RGB;
87-+import jp.nyatla.nyartoolkit.jmfutil.*;
88-
89--public class GLNyARRaster_RGB extends NyARRaster_RGB
90-+public class GLNyARRaster_RGB extends JmfNyARRaster_RGB
91- {
92- private NyARParam cparam;
93- private GL ref_gl;
94- private GLU glu;
95-- public GLNyARRaster_RGB(GL i_ref_gl,NyARParam i_cparam,int i_width,int i_height)
96-+ private byte[] gl_buf;
97-+ private int gl_flag;
98-+
99-+ public GLNyARRaster_RGB(GL i_ref_gl,NyARParam i_cparam)
100- {
101-- width=i_width;
102-- height=i_height;
103-+ super(i_cparam.getX(),i_cparam.getY());
104-+ gl_flag=GL.GL_RGB;
105- cparam=i_cparam;
106- ref_gl=i_ref_gl;
107- glu=new GLU();
108-- this.ref_buf=new byte[i_width*i_height*3];
109-+ this.gl_buf=new byte[width*height*3];
110- }
111-- public void setRawData(byte[] i_buf,boolean i_is_reverse)
112-+ public void setBuffer(javax.media.Buffer i_buffer,boolean i_is_reverse) throws NyARException
113- {
114-+ super.setBuffer(i_buffer);
115-+ //メモ:この時点では、ref_dataにはi_bufferの参照値が入ってる。
116-+
117-+ //GL用のデータを準備
118- if(i_is_reverse){
119- int length=width*3;
120- int src_idx=0;
121- int dest_idx=(height-1)*length;
122- for(int i=0;i<height;i++){
123-- System.arraycopy(i_buf,src_idx,ref_buf,dest_idx,length);
124-+ System.arraycopy(ref_buf,src_idx,gl_buf,dest_idx,length);
125- src_idx+=length;
126- dest_idx-=length;
127- }
128- }else{
129-- System.arraycopy(i_buf,0,ref_buf,0,this.ref_buf.length);
130-+ System.arraycopy(ref_buf,0,gl_buf,0,this.ref_buf.length);
131- }
132-+ //GLのフラグ設定
133-+ switch(this.pix_type){
134-+ case GLNyARRaster_RGB.PIXEL_ORDER_BGR:
135-+ gl_flag=GL.GL_BGR;
136-+ break;
137-+ case GLNyARRaster_RGB.PIXEL_ORDER_RGB:
138-+ gl_flag=GL.GL_RGB;
139-+ break;
140-+ default:
141-+ throw new NyARException();
142-+ }
143-+ //ref_bufをgl_bufに差し替える
144-+ ref_buf=gl_buf;
145- }
146- /**
147- * 保持してるイメージをGLに出力する。
148-@@ -104,15 +126,13 @@
149- {
150- float zoomf;
151- IntBuffer params=IntBuffer.allocate(4);
152-- int xsize=cparam.getX();
153-- int ysize=cparam.getY();
154- zoomf = (float)zoom;
155- ref_gl.glDisable(GL.GL_TEXTURE_2D);
156- ref_gl.glGetIntegerv(GL.GL_VIEWPORT,params);
157-- ref_gl.glPixelZoom(zoomf * ((float)(params.get(2)) / (float)xsize),-zoomf * ((float)(params.get(3)) / (float)ysize));
158-+ ref_gl.glPixelZoom(zoomf * ((float)(params.get(2)) / (float)width),-zoomf * ((float)(params.get(3)) / (float)height));
159- ref_gl.glRasterPos2i(-1,1);
160- ref_gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
161- ByteBuffer buf=ByteBuffer.wrap(ref_buf);
162-- ref_gl.glDrawPixels(xsize,ysize,GL.GL_BGR,GL.GL_UNSIGNED_BYTE,buf);
163-+ ref_gl.glDrawPixels(width,height,gl_flag,GL.GL_UNSIGNED_BYTE,buf);
164- }
165- }
166-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java
167-===================================================================
168---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java (revision 172)
169-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java (revision 173)
170-@@ -20,7 +20,7 @@
171- {
172- setTitle("JmfCaptureTest");
173- setBounds(0,0,320+64,240+64);
174-- capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXCEL_FORMAT_RGB);
175-+ capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
176- capture.setCaptureListener(this);
177- }
178-
179-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmfutil/JmfNyARRaster_RGB.java
180-===================================================================
181---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmfutil/JmfNyARRaster_RGB.java (revision 0)
182-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmfutil/JmfNyARRaster_RGB.java (revision 173)
183-@@ -0,0 +1,110 @@
184-+/**
185-+ * RGB形式のJMFバッファをラップするNyARRasterです。
186-+ * 複数のピクセルの並び順に対応してます。
187-+ * (c)2008 R.iizuka
188-+ * airmail(at)ebony.plala.or.jp
189-+ * http://nyatla.jp/
190-+ */
191-+package jp.nyatla.nyartoolkit.jmfutil;
192-+
193-+
194-+import javax.media.format.RGBFormat;
195-+import java.awt.Dimension;
196-+import jp.nyatla.nyartoolkit.NyARException;
197-+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;
198-+
199-+
200-+public class JmfNyARRaster_RGB implements NyARRaster
201-+{
202-+ public final static int PIXEL_ORDER_RGB=1;
203-+ public final static int PIXEL_ORDER_BGR=2;
204-+ protected int pix_type;
205-+ private int red_idx;
206-+ private int green_idx;
207-+ private int blue_idx;
208-+ protected byte[] ref_buf;
209-+ protected int width=0;
210-+ protected int height=0;
211-+
212-+ /**
213-+ * RGB形式のJMFバッファをラップするオブジェクトをつくります。
214-+ * 生成直後のオブジェクトはデータを持ちません。
215-+ * メンバ関数はsetBufferを実行後に使用可能になります。
216-+ */
217-+ public JmfNyARRaster_RGB(int i_width,int i_height)
218-+ {
219-+ ref_buf=null;
220-+ width=i_width;
221-+ height=i_height;
222-+ }
223-+ /**
224-+ * javax.media.Bufferを分析して、その分析結果をNyARRasterに適合する形で保持します。
225-+ * 関数実行後に外部でi_bufferの内容変更した場合には、再度setBuffer関数を呼び出してください。
226-+ * @param i_buffer
227-+ * RGB形式のデータを格納したjavax.media.Bufferオブジェクトを指定してください。
228-+ * @return
229-+ * i_bufferをラップしたオブジェクトを返します。
230-+ * @throws NyARException
231-+ */
232-+ public void setBuffer(javax.media.Buffer i_buffer) throws NyARException
233-+ {
234-+ RGBFormat fmt=(RGBFormat)i_buffer.getFormat();
235-+ //データサイズの確認
236-+ Dimension s=fmt.getSize();
237-+ if(width!=s.width || height !=s.height){
238-+ throw new NyARException();
239-+ }
240-+ //データ配列の確認
241-+ red_idx =fmt.getRedMask()-1;
242-+ green_idx=fmt.getGreenMask()-1;
243-+ blue_idx =fmt.getBlueMask()-1;
244-+
245-+ //色配列の特定
246-+ if(red_idx==0 && blue_idx==2){
247-+ pix_type=PIXEL_ORDER_RGB;
248-+ }else if(red_idx==2 && blue_idx==0){
249-+ pix_type=PIXEL_ORDER_BGR;
250-+ }else{
251-+ throw new NyARException("Unknown pixel order.");
252-+ }
253-+ ref_buf=(byte[])i_buffer.getData();
254-+ }
255-+ public int getPixelTotal(int i_x,int i_y)
256-+ {
257-+ int bp=(i_x+i_y*width)*3;
258-+ return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);
259-+ }
260-+ public int getWidth()
261-+ {
262-+ return width;
263-+ }
264-+ public int getHeight()
265-+ {
266-+ return height;
267-+ }
268-+ public void pickRgbArray(int i_x,int i_y,int[] i_rgb)
269-+ {
270-+ int bp=(i_x+i_y*width)*3;
271-+ i_rgb[0]=(ref_buf[bp+red_idx] & 0xff);//R
272-+ i_rgb[1]=(ref_buf[bp+green_idx] & 0xff);//G
273-+ i_rgb[2]=(ref_buf[bp+blue_idx] & 0xff);//B
274-+ }
275-+ /**
276-+ * ピクセルの順序タイプを返します。
277-+ * @return
278-+ * その値
279-+ */
280-+ public int getPixelOrder()
281-+ {
282-+ return pix_type;
283-+ }
284-+ /**
285-+ * データを持っているかを返します。
286-+ * @return
287-+ */
288-+ public boolean hasData()
289-+ {
290-+ return ref_buf!=null;
291-+ }
292-+
293-+}
294-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java
295-===================================================================
296---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java (revision 172)
297-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java (revision 173)
298-@@ -24,6 +24,7 @@
299-
300- public class JmfCameraCapture
301- {
302-+ private Dimension image_size;
303- private JmfCaptureListener capture_listener;
304- private DataSource jmf_data_source;
305- private MonitorStream jmf_monitor_stream;
306-@@ -31,13 +32,17 @@
307- private VideoFormat jmf_video_format;
308-
309- private Buffer read_buf=new Buffer();
310-- public static final String PIXCEL_FORMAT_RGB="RGB";
311-+ public static final String PIXEL_FORMAT_RGB="RGB";
312- public JmfCameraCapture(int i_width,int i_height,float i_rate,String i_pixcel_format)
313- {
314- String encoding = i_pixcel_format;//comboEncoding.getSelectedItem();
315-- Dimension size = new Dimension(i_width,i_height);
316-- jmf_video_format = new VideoFormat(encoding, size, Format.NOT_SPECIFIED,null,i_rate);
317-+ image_size = new Dimension(i_width,i_height);
318-+ jmf_video_format = new VideoFormat(encoding, image_size, Format.NOT_SPECIFIED,null,i_rate);
319- }
320-+ public Dimension getSize()
321-+ {
322-+ return image_size;
323-+ }
324- public javax.media.Buffer readBuffer() throws NyARException
325- {
326- if(jmf_monitor_stream==null){
327-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java
328-===================================================================
329---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java (revision 172)
330-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java (revision 173)
331-@@ -12,7 +12,7 @@
332-
333- import jp.nyatla.nyartoolkit.NyARException;
334- import jp.nyatla.nyartoolkit.jmf.*;
335--
336-+import jp.nyatla.nyartoolkit.jmfutil.*;
337- import java.awt.*;
338-
339- import jp.nyatla.nyartoolkit.core.*;
340-@@ -29,13 +29,14 @@
341- private final String PARAM_FILE ="../../Data/camera_para.dat";
342- private JmfCameraCapture capture;
343- NyARSingleDetectMarker nya;
344-+ JmfNyARRaster_RGB raster;
345-
346- public NyarToolkitLinkTest() throws NyARException,NyARException
347- {
348- setTitle("JmfCaptureTest");
349- setBounds(0,0,320+64,240+64);
350- //キャプチャの準備
351-- capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXCEL_FORMAT_RGB);
352-+ capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
353- capture.setCaptureListener(this);
354-
355- //NyARToolkitの準備
356-@@ -45,6 +46,8 @@
357- ar_param.changeSize(320,240);
358- nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);
359- ar_code.loadFromARFile(CARCODE_FILE);
360-+ //キャプチャイメージ用のラスタを準備
361-+ raster=new JmfNyARRaster_RGB(320,240);
362- }
363-
364-
365-@@ -52,15 +55,18 @@
366- public void onUpdateBuffer(Buffer i_buffer)
367- {
368- try{
369-- //キャプチャしたイメージを加工
370-+ //キャプチャしたバッファをラスタにセット
371-+ raster.setBuffer(i_buffer);
372-+
373-+ //キャプチャしたイメージを表示用に加工
374- BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
375- Image img=b2i.createImage(i_buffer);
376-- Graphics g = getGraphics();
377-- NyARRaster_RGB ra=NyARRaster_RGB.wrap((byte[])i_buffer.getData(), 320, 240);
378-- //i_buffer.
379-- boolean is_marker_exist=nya.detectMarkerLite(ra,100);
380--
381-+
382-+ Graphics g = getGraphics();
383- double[][] atm=null;
384-+
385-+ //マーカー検出
386-+ boolean is_marker_exist=nya.detectMarkerLite(raster,100);
387- if(is_marker_exist){
388- //変換行列を取得
389- atm=nya.getTransmationMatrix().getArray();
390-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_Blank.java
391-===================================================================
392---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_Blank.java (revision 172)
393-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_Blank.java (revision 173)
394-@@ -38,16 +38,15 @@
395- */
396- public class NyARRaster_Blank implements NyARRaster
397- {
398-- int width;
399-- int height;
400-+ private int width;
401-+ private int height;
402- public NyARRaster_Blank(int i_width,int i_height)
403- {
404-- NyARRaster_BGRA new_inst=new NyARRaster_BGRA();
405-- new_inst.width =i_width;
406-- new_inst.height =i_height;
407-+ width =i_width;
408-+ height =i_height;
409- }
410- //RGBの合計値を返す
411-- public int getPixcelTotal(int i_x,int i_y)
412-+ public int getPixelTotal(int i_x,int i_y)
413- {
414- return 0;
415- }
416-@@ -61,8 +60,8 @@
417- }
418- public void pickRgbArray(int i_x,int i_y,int[] i_rgb)
419- {
420-- i_rgb[0]=0;
421-- i_rgb[1]=0;
422-- i_rgb[2]=0;
423-+ i_rgb[0]=0;
424-+ i_rgb[1]=0;
425-+ i_rgb[2]=0;
426- }
427- }
428-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_RGB.java
429-===================================================================
430---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_RGB.java (revision 172)
431-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_RGB.java (revision 173)
432-@@ -39,32 +39,32 @@
433- protected int height;
434- public static NyARRaster_RGB wrap(byte[] i_buffer,int i_width,int i_height)
435- {
436-- NyARRaster_RGB new_inst=new NyARRaster_RGB();
437-- new_inst.ref_buf=i_buffer;
438-- new_inst.width =i_width;
439-- new_inst.height =i_height;
440-- return new_inst;
441-+ NyARRaster_RGB new_inst=new NyARRaster_RGB();
442-+ new_inst.ref_buf=i_buffer;
443-+ new_inst.width =i_width;
444-+ new_inst.height =i_height;
445-+ return new_inst;
446- }
447- //RGBの合計値を返す
448-- public int getPixcelTotal(int i_x,int i_y)
449-+ public int getPixelTotal(int i_x,int i_y)
450- {
451-- int bp=(i_x+i_y*width)*3;
452-- return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);
453-+ int bp=(i_x+i_y*width)*3;
454-+ return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);
455- }
456- public int getWidth()
457- {
458-- return width;
459-+ return width;
460- }
461- public int getHeight()
462- {
463-- return height;
464-+ return height;
465- }
466- public void pickRgbArray(int i_x,int i_y,int[] i_rgb)
467- {
468-- int bp=(i_x+i_y*width)*3;
469-- i_rgb[0]=(ref_buf[bp+0] & 0xff);//R
470-- i_rgb[1]=(ref_buf[bp+1] & 0xff);//G
471-- i_rgb[2]=(ref_buf[bp+2] & 0xff);//B
472-+ int bp=(i_x+i_y*width)*3;
473-+ i_rgb[0]=(ref_buf[bp+0] & 0xff);//R
474-+ i_rgb[1]=(ref_buf[bp+1] & 0xff);//G
475-+ i_rgb[2]=(ref_buf[bp+2] & 0xff);//B
476- }
477- }
478-
479-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BGRA.java
480-===================================================================
481---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BGRA.java (revision 172)
482-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster_BGRA.java (revision 173)
483-@@ -35,25 +35,25 @@
484- public class NyARRaster_BGRA implements NyARRaster
485- {
486- private byte[] ref_buf;
487-- int width;
488-- int height;
489-+ private int width;
490-+ private int height;
491- public static NyARRaster_BGRA wrap(byte[] i_buffer,int i_width,int i_height)
492- {
493-- NyARRaster_BGRA new_inst=new NyARRaster_BGRA();
494-- new_inst.ref_buf=i_buffer;
495-- new_inst.width =i_width;
496-- new_inst.height =i_height;
497-- return new_inst;
498-+ NyARRaster_BGRA new_inst=new NyARRaster_BGRA();
499-+ new_inst.ref_buf=i_buffer;
500-+ new_inst.width =i_width;
501-+ new_inst.height =i_height;
502-+ return new_inst;
503- }
504- //RGBの合計値を返す
505-- public int getPixcelTotal(int i_x,int i_y)
506-+ public int getPixelTotal(int i_x,int i_y)
507- {
508-- int bp=(i_x+i_y*width)*4;
509-- return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);
510-+ int bp=(i_x+i_y*width)*4;
511-+ return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);
512- }
513- public int getWidth()
514- {
515-- return width;
516-+ return width;
517- }
518- public int getHeight()
519- {
520-@@ -61,10 +61,10 @@
521- }
522- public void pickRgbArray(int i_x,int i_y,int[] i_rgb)
523- {
524-- int bp=(i_x+i_y*width)*4;
525-- i_rgb[0]=(ref_buf[bp+2] & 0xff);//R
526-- i_rgb[1]=(ref_buf[bp+1] & 0xff);//G
527-- i_rgb[2]=(ref_buf[bp+0] & 0xff);//B
528-+ int bp=(i_x+i_y*width)*4;
529-+ i_rgb[0]=(ref_buf[bp+2] & 0xff);//R
530-+ i_rgb[1]=(ref_buf[bp+1] & 0xff);//G
531-+ i_rgb[2]=(ref_buf[bp+0] & 0xff);//B
532- }
533- }
534-
535-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java
536-===================================================================
537---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java (revision 172)
538-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java (revision 173)
539-@@ -33,7 +33,7 @@
540-
541- public interface NyARRaster{
542- //RGBの合計値を返す
543-- public int getPixcelTotal(int i_x,int i_y);
544-+ public int getPixelTotal(int i_x,int i_y);
545- public int getWidth();
546- public int getHeight();
547- public void pickRgbArray(int i_x,int i_y,int[] i_rgb);
548-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java
549-===================================================================
550---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java (revision 172)
551-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java (revision 173)
552-@@ -206,7 +206,7 @@
553- int p2=j;
554- for(int i = 1; i < lxsize-1; i++, nya_pnt_start_x+=nya_poff_step) {//for(int i = 1; i < lxsize-1; i++, pnt+=poff, pnt2++) {
555- //RGBの合計値が閾値より大きいかな?
556-- if(image.getPixcelTotal(nya_pnt_start_x,nya_pnt_start_y)<=thresht3){
557-+ if(image.getPixelTotal(nya_pnt_start_x,nya_pnt_start_y)<=thresht3){
558- //pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 = &(pnt2[-lxsize]);
559- if(label_img[p1][i]>0){//if( *pnt1 > 0 ) {
560- label_img[p2][i]=label_img[p1][i];//*pnt2 = *pnt1;
561-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARSquare.java
562-===================================================================
563---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARSquare.java (revision 172)
564-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARSquare.java (revision 173)
565-@@ -36,19 +36,19 @@
566- *
567- */
568- public class NyARSquare{
569-- private NyARMarker marker;
570-- public int area;
571-- public double[] pos;
572-- public double[][] line; //double[4][3]
573-- public double[][] vertex;//double[4][2];
574-+ private NyARMarker marker;
575-+ public int area;
576-+ public double[] pos;
577-+ public double[][] line; //double[4][3]
578-+ public double[][] vertex;//double[4][2];
579- public NyARSquare(NyARMarker i_marker,double[][] i_attached_line,double[][] i_attached_vertex)
580- {
581-- //ARSquareは、ARMarkerを完全にラップするようにした。
582-- marker=i_marker;
583-- area=i_marker.area;
584-- pos =i_marker.pos;
585-- line =i_attached_line;
586-- vertex=i_attached_vertex;
587-+ //ARSquareは、ARMarkerを完全にラップするようにした。
588-+ marker=i_marker;
589-+ area=i_marker.area;
590-+ pos =i_marker.pos;
591-+ line =i_attached_line;
592-+ vertex=i_attached_vertex;
593- }
594- public NyARMarker getMarker()
595- {
--- a/trunk/changelog/0.8.20080412.0.txt
+++ /dev/null
@@ -1,3158 +0,0 @@
1-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorListener.java
2-===================================================================
3---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorListener.java (revision 0)
4-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorListener.java (revision 178)
5-@@ -0,0 +1,24 @@
6-+/**
7-+ * NyARToolkitのBehaviorのリスナ
8-+ * (c)2008 A虎@nyatla.jp
9-+ * airmail@ebony.plala.or.jp
10-+ * http://nyatla.jp/
11-+ */
12-+package jp.nyatla.nyartoolkit.java3d.utils;
13-+
14-+import javax.media.j3d.*;
15-+
16-+public interface NyARSingleMarkerBehaviorListener
17-+{
18-+ /**
19-+ * このリスナは、リスナにマーカーに連動してオブジェクトを操作するチャンスを与えます。
20-+ * リスナはNyARSingleMarkerBehavior関数内のprocessStimulus関数から呼び出されます。
21-+ *
22-+ * @param i_is_marker_exist
23-+ * マーカーが存在する場合true、存在しない場合、falseです。
24-+ * @param i_transform3d
25-+ * マーカーが存在する場合、その変換行列が指定されます。
26-+ * i_is_marker_existがtrueの時だけ有効です。
27-+ */
28-+ public void onUpdate(boolean i_is_marker_exist,Transform3D i_transform3d);
29-+}
30-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java
31-===================================================================
32---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java (revision 0)
33-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java (revision 178)
34-@@ -0,0 +1,64 @@
35-+/**
36-+ * NyARRaster_RGBにOpenGL向け関数を追加したもの
37-+ * (c)2008 A虎@nyatla.jp
38-+ * airmail(at)ebony.plala.or.jp
39-+ * http://nyatla.jp/
40-+ */
41-+package jp.nyatla.nyartoolkit.java3d.utils;
42-+
43-+import java.awt.image.*;
44-+import java.awt.color.*;
45-+
46-+import javax.media.j3d.ImageComponent;
47-+import javax.media.j3d.ImageComponent2D;
48-+
49-+
50-+
51-+import jp.nyatla.nyartoolkit.NyARException;
52-+import jp.nyatla.nyartoolkit.core.NyARParam;
53-+import jp.nyatla.nyartoolkit.jmf.utils.*;
54-+
55-+
56-+public class J3dNyARRaster_RGB extends JmfNyARRaster_RGB
57-+{
58-+// public ImageUpdater updater;
59-+ private ImageComponent2D imc2d;
60-+ private byte[] i2d_buf;
61-+
62-+ public void setBuffer(javax.media.Buffer i_buffer) throws NyARException
63-+ {
64-+ super.setBuffer(i_buffer);
65-+ //メモ:この時点では、ref_dataにはi_bufferの参照値が入ってる。
66-+ synchronized(imc2d){
67-+ //キャプチャデータをi2dのバッファにコピーする。(これ省略したいなあ…。)
68-+ System.arraycopy(ref_buf,0,i2d_buf,0,this.i2d_buf.length);
69-+ }
70-+ //ここでref_bufの参照値をref_bufへ移動
71-+ ref_buf=i2d_buf;
72-+ }
73-+ public J3dNyARRaster_RGB(NyARParam i_cparam)
74-+ {
75-+ super(i_cparam.getX(),i_cparam.getY());
76-+
77-+ //RGBのラスタを作る。
78-+// ColorSpace cs=ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
79-+// ComponentColorModel cm;
80-+// cm=new ComponentColorModel(cs,new int[]{8,8,8},false,false,ComponentColorModel.OPAQUE,DataBuffer.TYPE_BYTE);
81-+// java.awt.image.WritableRaster raster=cm.createCompatibleWritableRaster(width,height);
82-+// i2d_buf=((DataBufferByte)raster.getDataBuffer()).getData();
83-+// BufferedImage background_image = new BufferedImage(cm,raster, false, null);
84-+ BufferedImage background_image = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
85-+ i2d_buf=((DataBufferByte)background_image.getRaster().getDataBuffer()).getData();
86-+ //
87-+ imc2d= new ImageComponent2D(ImageComponent2D.FORMAT_RGB, background_image, true, true);
88-+ imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);
89-+ }
90-+ /**
91-+ * このオブジェクトと連動するImageComponent2Dオブジェクトの参照値を得る。
92-+ * @return
93-+ */
94-+ public ImageComponent2D getImageComponent2D()
95-+ {
96-+ return imc2d;
97-+ }
98-+}
99-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java
100-===================================================================
101---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java (revision 0)
102-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARParam.java (revision 178)
103-@@ -0,0 +1,119 @@
104-+/**
105-+ * NyARParamにOpenGL向け関数を追加したもの
106-+ * (c)2008 A虎@nyatla.jp
107-+ * airmail(at)ebony.plala.or.jp
108-+ * http://nyatla.jp/
109-+ */
110-+package jp.nyatla.nyartoolkit.java3d.utils;
111-+
112-+import jp.nyatla.nyartoolkit.core.*;
113-+import javax.media.j3d.Transform3D;
114-+
115-+public class J3dNyARParam extends NyARParam
116-+{
117-+ private double view_distance_min=0.01;//1cm〜10.0m
118-+ private double view_distance_max=10.0;
119-+ private Transform3D m_projection=null;
120-+ /**
121-+ * 視体積の近い方をメートルで指定
122-+ * @param i_new_value
123-+ */
124-+ public void setViewDistanceMin(double i_new_value)
125-+ {
126-+ m_projection=null;//キャッシュ済変数初期化
127-+ view_distance_min=i_new_value;
128-+ }
129-+ /**
130-+ * 視体積の遠い方をメートルで指定
131-+ * @param i_new_value
132-+ */
133-+ public void setViewDistanceMax(double i_new_value)
134-+ {
135-+ m_projection=null;//キャッシュ済変数初期化
136-+ view_distance_max=i_new_value;
137-+ }
138-+ /**
139-+ * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])
140-+ * 関数の置き換え
141-+ * @param focalmin
142-+ * @param focalmax
143-+ * @return
144-+ */
145-+ public Transform3D getCameraTransform()
146-+ {
147-+ //既に値がキャッシュされていたらそれを使う
148-+ if(m_projection!=null){
149-+ return m_projection;
150-+ }
151-+ //無ければ計算
152-+
153-+ NyARMat trans_mat=new NyARMat(3,4);
154-+ NyARMat icpara_mat=new NyARMat(3,4);
155-+ double[][] p=new double[3][3], q=new double[4][4];
156-+ double width, height;
157-+ int i, j;
158-+
159-+ width = xsize;
160-+ height = ysize;
161-+
162-+ decompMat(icpara_mat,trans_mat);
163-+
164-+ double[][] icpara=icpara_mat.getArray();
165-+ double[][] trans=trans_mat.getArray();
166-+ for (i = 0; i < 4; i++) {
167-+ icpara[1][i] = (height - 1)*(icpara[2][i]) - icpara[1][i];
168-+ }
169-+
170-+ for(i = 0; i < 3; i++) {
171-+ for(j = 0; j < 3; j++) {
172-+ p[i][j] = icpara[i][j] / icpara[2][2];
173-+ }
174-+ }
175-+ //p[0][0],p[1][1]=n
176-+ //p[0][2],p[1][2]=t+b
177-+
178-+ //Projectionの計算
179-+ q[0][0] = (2.0 * p[0][0] / (width - 1));
180-+ q[0][1] = (2.0 * p[0][1] / (width - 1));
181-+ q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);
182-+ q[0][3] = 0.0;
183-+
184-+ q[1][0] = 0.0;
185-+ q[1][1] = -(2.0 * p[1][1] / (height - 1));
186-+ q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);
187-+ q[1][3] = 0.0;
188-+
189-+ q[2][0] = 0.0;
190-+ q[2][1] = 0.0;
191-+ q[2][2] = (view_distance_max + view_distance_min)/(view_distance_min - view_distance_max);
192-+ q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);
193-+
194-+ q[3][0] = 0.0;
195-+ q[3][1] = 0.0;
196-+ q[3][2] = -1.0;
197-+ q[3][3] = 0.0;
198-+
199-+ q[2][2]=q[2][2]*-1;
200-+ q[2][3]=q[2][3]*-1;
201-+
202-+ double[] tmp_projection=new double[16];
203-+ for (i = 0; i < 4; i++) { // Row.
204-+ // First 3 columns of the current row.
205-+ for (j = 0; j < 3; j++) { // Column.
206-+ tmp_projection[i + j*4] =(
207-+ q[i][0] * trans[0][j] +
208-+ q[i][1] * trans[1][j] +
209-+ q[i][2] * trans[2][j]);
210-+ }
211-+ // Fourth column of the current row.
212-+ tmp_projection[i + 3*4]=
213-+ q[i][0] * trans[0][3] +
214-+ q[i][1] * trans[1][3] +
215-+ q[i][2] * trans[2][3] +
216-+ q[i][3];
217-+ }
218-+ m_projection=new Transform3D(tmp_projection);
219-+ m_projection.transpose();
220-+ return m_projection;
221-+ }
222-+}
223-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java
224-===================================================================
225---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java (revision 0)
226-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java (revision 178)
227-@@ -0,0 +1,191 @@
228-+/**
229-+ * NyARToolkitのBehaviorホルダー
230-+ * (c)2008 A虎@nyatla.jp
231-+ * airmail@ebony.plala.or.jp
232-+ * http://nyatla.jp/
233-+ */
234-+package jp.nyatla.nyartoolkit.java3d.utils;
235-+
236-+import java.util.Enumeration;
237-+
238-+import javax.media.Buffer;
239-+import javax.media.j3d.*;
240-+import javax.vecmath.*;
241-+
242-+import jp.nyatla.nyartoolkit.core.NyARParam;
243-+import jp.nyatla.nyartoolkit.detector.NyARSingleDetectMarker;
244-+import jp.nyatla.nyartoolkit.jmf.*;
245-+import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;
246-+import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;
247-+import jp.nyatla.nyartoolkit.*;
248-+import jp.nyatla.nyartoolkit.core.*;
249-+
250-+/**
251-+ * NyARToolkitと連動したBehaviorを返却するクラスです。
252-+ * 提供できるBehaviorは、BackgroundとTransformgroupです。
253-+ *
254-+ */
255-+public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener
256-+{
257-+ private NyARParam cparam;
258-+ private JmfCameraCapture capture;
259-+ private J3dNyARRaster_RGB nya_raster;//最大3スレッドで共有されるので、排他制御かけること。
260-+ private NyARSingleDetectMarker nya;
261-+ //Behaviorホルダ
262-+ private NyARBehavior nya_behavior;
263-+ public NyARSingleMarkerBehaviorHolder(NyARParam i_cparam,float i_rate,NyARCode i_ar_code,double i_marker_width) throws NyARException
264-+ {
265-+ nya_behavior=null;
266-+ cparam=i_cparam;
267-+ capture=new JmfCameraCapture(cparam.getX(),cparam.getY(),i_rate,JmfCameraCapture.PIXEL_FORMAT_RGB);
268-+ capture.setCaptureListener(this);
269-+ nya_raster=new J3dNyARRaster_RGB(cparam);
270-+ nya=new NyARSingleDetectMarker(cparam,i_ar_code,i_marker_width);
271-+ nya_behavior=new NyARBehavior(nya,nya_raster,i_rate);
272-+ }
273-+ public Behavior getBehavior()
274-+ {
275-+ return nya_behavior;
276-+ }
277-+ /**
278-+ * i_back_groundにキャプチャ画像を転送するようにBehaviorを設定します。
279-+ * i_back_groungはALLOW_IMAGE_WRITE属性を持つものである必要があります。
280-+ * @param i_back_groung
281-+ * @return
282-+ */
283-+ public void setBackGround(Background i_back_ground)
284-+ {
285-+ //コール先で排他制御
286-+ nya_behavior.setRelatedBackGround(i_back_ground);
287-+ }
288-+ /**
289-+ * i_trgroupの座標系をマーカーにあわせるようにBehaviorを設定します。
290-+ *
291-+ */
292-+ public void setTransformGroup(TransformGroup i_trgroup)
293-+ {
294-+ //コール先で排他制御
295-+ nya_behavior.setRelatedTransformGroup(i_trgroup);
296-+ }
297-+ /**
298-+ * 座標系再計算後に呼び出されるリスナです。
299-+ * @param i_listener
300-+ */
301-+ public void setUpdateListener(NyARSingleMarkerBehaviorListener i_listener)
302-+ {
303-+ //コール先で排他制御
304-+ nya_behavior.setUpdateListener(i_listener);
305-+ }
306-+ /**
307-+ * ラスタを更新 コールバック関数だから呼んじゃらめえ
308-+ */
309-+ public void onUpdateBuffer(Buffer i_buffer)
310-+ {
311-+ try{
312-+ synchronized(nya_raster){
313-+ nya_raster.setBuffer(i_buffer);
314-+ }
315-+ }catch(Exception e){
316-+ e.printStackTrace();
317-+ }
318-+ }
319-+ public void start() throws NyARException
320-+ {
321-+ //開始
322-+ capture.start();
323-+ }
324-+ public void stop()
325-+ {
326-+ capture.stop();
327-+ }
328-+}
329-+
330-+
331-+class NyARBehavior extends Behavior
332-+{
333-+ private NyARSingleDetectMarker related_nya;
334-+ private TransformGroup trgroup;
335-+ private Background back_ground;
336-+ private J3dNyARRaster_RGB raster;
337-+ private WakeupCondition wakeup;
338-+ private NyARSingleMarkerBehaviorListener listener;
339-+ public void initialize()
340-+ {
341-+ wakeupOn(wakeup);
342-+ }
343-+ /**
344-+ * i_related_ic2dの内容で定期的にi_back_groundを更新するBehavior
345-+ * @param i_back_ground
346-+ * @param i_related_ic2d
347-+ */
348-+ public NyARBehavior(NyARSingleDetectMarker i_related_nya,J3dNyARRaster_RGB i_related_raster,float i_rate)
349-+ {
350-+ super();
351-+ wakeup=new WakeupOnElapsedTime((int)(1000/i_rate));
352-+ related_nya=i_related_nya;
353-+ trgroup =null;
354-+ raster =i_related_raster;
355-+ back_ground=null;
356-+ listener=null;
357-+ this.setSchedulingBounds(new BoundingSphere(new Point3d(), 100.0));
358-+ }
359-+ public void setRelatedBackGround(Background i_back_ground)
360-+ {
361-+ synchronized(raster){
362-+ back_ground=i_back_ground;
363-+ }
364-+ }
365-+ public void setRelatedTransformGroup(TransformGroup i_trgroup)
366-+ {
367-+ synchronized(raster){
368-+ trgroup=i_trgroup;
369-+ }
370-+ }
371-+ public void setUpdateListener(NyARSingleMarkerBehaviorListener i_listener)
372-+ {
373-+ synchronized(raster){
374-+ listener=i_listener;
375-+ }
376-+ }
377-+
378-+ /**
379-+ * いわゆるイベントハンドラ
380-+ */
381-+ public void processStimulus(Enumeration criteria)
382-+ {
383-+ try{
384-+ synchronized(raster){
385-+ Transform3D t3d=null;
386-+ boolean is_marker_exist=false;
387-+ if(back_ground!=null){
388-+ back_ground.setImage(raster.getImageComponent2D());
389-+ }
390-+ if(raster.hasData()){
391-+ is_marker_exist=related_nya.detectMarkerLite(raster, 100);
392-+ if(is_marker_exist){
393-+ NyARMat nymat=related_nya.getTransmationMatrix();
394-+ double[][] src=nymat.getArray();
395-+ Matrix4d matrix=new Matrix4d(
396-+ src[0][0],-src[1][0],-src[2][0],0,
397-+ -src[0][1], src[1][1], src[2][1],0,
398-+ -src[0][2], src[1][2], src[2][2],0,
399-+ -src[0][3], src[1][3], src[2][3],1);
400-+ matrix.transpose();
401-+ t3d=new Transform3D(matrix);
402-+ if(trgroup!=null){
403-+ trgroup.setTransform(t3d);
404-+ }
405-+ }
406-+ }
407-+ if(listener!=null)
408-+ {
409-+ listener.onUpdate(is_marker_exist, t3d);
410-+ }
411-+ }
412-+ wakeupOn(wakeup);
413-+ }catch(Exception e){
414-+ e.printStackTrace();
415-+ }
416-+ }
417-+}
418-+
419-Index: D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java
420-===================================================================
421---- D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java (revision 0)
422-+++ D:/project.files/java.Lab/NyARToolKit/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java (revision 178)
423-@@ -0,0 +1,148 @@
424-+/**
425-+ * Java3Dサンプルプログラム
426-+ * シングルマーカー追跡用のBehaviorを使って、背景と1個のマーカーに連動したTransformGroup
427-+ * を動かします。
428-+ * (c)2008 A虎@nyatla.jp
429-+ * airmail@ebony.plala.or.jp
430-+ * http://nyatla.jp/
431-+ */
432-+package jp.nyatla.nyartoolkit.java3d.sample;
433-+
434-+import java.awt.BorderLayout;
435-+import javax.media.j3d.*;
436-+
437-+import com.sun.j3d.utils.universe.*;
438-+import java.awt.*;
439-+import javax.swing.JFrame;
440-+import javax.vecmath.*;
441-+
442-+import jp.nyatla.nyartoolkit.core.*;
443-+import jp.nyatla.nyartoolkit.java3d.utils.*;
444-+
445-+import com.sun.j3d.utils.geometry.ColorCube;
446-+
447-+public class NyARJava3D extends JFrame implements NyARSingleMarkerBehaviorListener
448-+{
449-+ private final String CARCODE_FILE ="../../Data/patt.hiro";
450-+ private final String PARAM_FILE ="../../Data/camera_para.dat";
451-+ //NyARToolkit関係
452-+ private NyARSingleMarkerBehaviorHolder nya_behavior;
453-+ private J3dNyARParam ar_param;
454-+ //universe関係
455-+ private Canvas3D canvas;
456-+ private Locale locale;
457-+ private VirtualUniverse universe;
458-+ public static void main(String[] args)
459-+ {
460-+ try{
461-+ NyARJava3D frame = new NyARJava3D();
462-+
463-+ frame.setVisible(true);
464-+ Insets ins=frame.getInsets();
465-+ frame.setSize(320+ins.left+ins.right,240+ins.top+ins.bottom);
466-+ frame.startCapture();
467-+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
468-+ }catch(Exception e){
469-+ e.printStackTrace();
470-+ }
471-+ }
472-+ public void onUpdate(boolean i_is_marker_exist,Transform3D i_transform3d)
473-+ {
474-+ /*
475-+ * TODO:Please write your behavior operation code here.
476-+ * マーカーの姿勢を元に他の3Dオブジェクトを操作するときは、ここに処理を書きます。*/
477-+
478-+ }
479-+ public void startCapture() throws Exception
480-+ {
481-+ nya_behavior.start();
482-+ }
483-+ public NyARJava3D() throws Exception
484-+ {
485-+ super("Java3D Example NyARToolkit");
486-+
487-+ //NyARToolkitの準備
488-+ NyARCode ar_code =new NyARCode(16,16);
489-+ ar_code.loadFromARFile(CARCODE_FILE);
490-+ ar_param=new J3dNyARParam();
491-+ ar_param.loadFromARFile(PARAM_FILE);
492-+ ar_param.changeSize(320,240);
493-+
494-+ //localeの作成とlocateとviewの設定
495-+ universe = new VirtualUniverse();
496-+ locale = new Locale( universe );
497-+ canvas=new Canvas3D( SimpleUniverse.getPreferredConfiguration());
498-+ View view = new View();
499-+ ViewPlatform viewPlatform = new ViewPlatform();
500-+ view.attachViewPlatform( viewPlatform );
501-+ view.addCanvas3D(canvas);
502-+ view.setPhysicalBody( new PhysicalBody() );
503-+ view.setPhysicalEnvironment( new PhysicalEnvironment());
504-+
505-+ //視界の設定(カメラ設定から取得)
506-+ Transform3D camera_3d=ar_param.getCameraTransform();
507-+ view.setCompatibilityModeEnable(true);
508-+ view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
509-+ view.setLeftProjection(camera_3d);
510-+
511-+ //視点設定(0,0,0から、Y軸を180度回転してZ+方向を向くようにする。)
512-+ TransformGroup viewGroup = new TransformGroup();
513-+ Transform3D viewTransform = new Transform3D();
514-+ viewTransform.rotY(Math.PI);
515-+ viewTransform.setTranslation(new Vector3d(0.0,0.0,0.0));
516-+ viewGroup.setTransform( viewTransform );
517-+ viewGroup.addChild( viewPlatform );
518-+ BranchGroup viewRoot = new BranchGroup();
519-+ viewRoot.addChild( viewGroup );
520-+ locale.addBranchGraph( viewRoot );
521-+
522-+
523-+ //バックグラウンドの作成
524-+ Background background =new Background();
525-+ BoundingSphere bounds = new BoundingSphere();
526-+ bounds.setRadius( 10.0 );
527-+ background.setApplicationBounds(bounds);
528-+ background.setImageScaleMode(Background.SCALE_FIT_ALL);
529-+ background.setCapability(Background.ALLOW_IMAGE_WRITE);
530-+ BranchGroup root = new BranchGroup();
531-+ root.addChild(background);
532-+
533-+ //TransformGroupで囲ったシーングラフの作成
534-+ TransformGroup transform=new TransformGroup();
535-+ transform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
536-+ transform.addChild(createSceneGraph());
537-+ root.addChild(transform);
538-+
539-+ //NyARToolkitのBehaviorを作る。(マーカーサイズはメートルで指定すること)
540-+ nya_behavior=new NyARSingleMarkerBehaviorHolder(ar_param,30f,ar_code,0.08);
541-+ //Behaviorに連動するグループをセット
542-+ nya_behavior.setTransformGroup(transform);
543-+ nya_behavior.setBackGround(background);
544-+
545-+ //出来たbehaviorをセット
546-+ root.addChild(nya_behavior.getBehavior());
547-+ nya_behavior.setUpdateListener(this);
548-+
549-+ //表示ブランチをLocateにセット
550-+ locale.addBranchGraph(root);
551-+
552-+ //ウインドウの設定
553-+ setLayout(new BorderLayout());
554-+ add(canvas,BorderLayout.CENTER);
555-+ }
556-+ /**
557-+ * シーングラフを作って、そのノードを返す。
558-+ * このノードは40mmの色つきナタデココを表示するシーン。z軸を基準に20mm上に浮かせてる。
559-+ * @return
560-+ */
561-+ private Node createSceneGraph()
562-+ {
563-+ TransformGroup tg=new TransformGroup();
564-+ Transform3D mt=new Transform3D();
565-+ mt.setTranslation(new Vector3d(0.00,0.0,20*0.001));
566-+ // 大きさ 40mmの色付き立方体を、Z軸上で20mm動かして配置)
567-+ tg.setTransform(mt);
568-+ tg.addChild(new ColorCube(20*0.001));
569-+ return tg;
570-+ }
571-+}
572-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java
573-===================================================================
574---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java (revision 174)
575-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/JavaSimpleLite.java (revision 178)
576-@@ -1,217 +0,0 @@
577--/**
578-- * simpleLiteと同じようなテストプログラム
579-- * マーカーの一致度の最低値をチェックするところを抜いたので、同じマーカーを大量に
580-- * 検出すると面白いことになります。
581-- * (c)2008 R.iizuka
582-- * airmail(at)ebony.plala.or.jp
583-- * http://nyatla.jp/
584-- */
585--import java.awt.event.WindowAdapter;
586--import java.awt.event.WindowEvent;
587--import java.awt.*;
588--
589--import javax.media.Buffer;
590--
591--import javax.media.opengl.GL;
592--import javax.media.opengl.GLAutoDrawable;
593--import javax.media.opengl.GLEventListener;
594--import javax.media.opengl.GLCanvas;
595--
596--import com.sun.opengl.util.Animator;
597--
598--import jp.nyatla.nyartoolkit.core.NyARCode;
599--
600--import jp.nyatla.nyartoolkit.jmf.JmfCameraCapture;
601--import jp.nyatla.nyartoolkit.jmf.JmfCaptureListener;
602--import jp.nyatla.nyartoolkit.gutil.*;
603--
604--
605--public class JavaSimpleLite implements GLEventListener,JmfCaptureListener
606--{
607-- private final String CARCODE_FILE ="../../Data/patt.hiro";
608-- private final String PARAM_FILE ="../../Data/camera_para.dat";
609--
610--
611-- private Animator animator;
612-- private GLNyARRaster_RGB cap_image;
613--
614-- private JmfCameraCapture capture;
615-- private GL gl;
616-- //NyARToolkit関係
617-- private GLNyARSingleDetectMarker nya;
618-- private GLNyARParam ar_param;
619-- /**
620-- * 立方体を書く
621-- *
622-- */
623-- void drawCube()
624-- {
625-- // Colour cube data.
626-- int polyList = 0;
627-- float fSize = 0.5f;
628-- int f, i;
629-- float[][] cube_vertices=new float[][]{
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},
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}
632-- };
633-- float[][] cube_vertex_colors=new float[][]{
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},
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}
636-- };
637-- int cube_num_faces = 6;
638-- short[][] cube_faces =new short[][]{
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}
640-- };
641--
642-- if (polyList==0) {
643-- polyList = gl.glGenLists (1);
644-- gl.glNewList(polyList, GL.GL_COMPILE);
645-- gl.glBegin(GL.GL_QUADS);
646-- for (f = 0; f < cube_num_faces; f++)
647-- for (i = 0; i < 4; i++) {
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]);
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);
650-- }
651-- gl.glEnd();
652-- gl.glColor3f(0.0f, 0.0f, 0.0f);
653-- for (f = 0; f < cube_num_faces; f++) {
654-- gl.glBegin (GL.GL_LINE_LOOP);
655-- for (i = 0; i < 4; i++)
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);
657-- gl.glEnd ();
658-- }
659-- gl.glEndList ();
660-- }
661--
662-- gl.glPushMatrix(); // Save world coordinate system.
663-- gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.
664-- gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.
665-- gl.glDisable(GL.GL_LIGHTING); // Just use colours.
666-- gl.glCallList(polyList); // Draw the cube.
667-- gl.glPopMatrix(); // Restore world coordinate system.
668--
669-- }
670--
671--
672--
673-- public JavaSimpleLite()
674-- {
675-- Frame frame = new Frame("Java simpleLite with NyARToolkit");
676--
677--
678-- // 3Dを描画するコンポーネント
679-- GLCanvas canvas = new GLCanvas();
680-- frame.add(canvas);
681-- canvas.addGLEventListener(this);
682-- frame.addWindowListener(new WindowAdapter() {
683-- public void windowClosing(WindowEvent e) {
684-- System.exit(0);
685-- }
686-- });
687--
688-- frame.setVisible(true);
689-- Insets ins=frame.getInsets();
690-- frame.setSize(320+ins.left+ins.right,240+ins.top+ins.bottom);
691-- canvas.setBounds(ins.left,ins.top,320,240);
692-- }
693--
694-- public void init(GLAutoDrawable drawable) {
695-- gl = drawable.getGL();
696-- gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
697-- //NyARToolkitの準備
698-- try{
699-- //キャプチャの準備
700-- capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXEL_FORMAT_RGB);
701-- capture.setCaptureListener(this);
702-- //NyARToolkitの準備
703-- ar_param=new GLNyARParam();
704-- NyARCode ar_code =new NyARCode(16,16);
705-- ar_param.loadFromARFile(PARAM_FILE);
706-- ar_param.changeSize(320,240);
707-- nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0);
708-- ar_code.loadFromARFile(CARCODE_FILE);
709-- //GL対応のRGBラスタオブジェクト
710-- cap_image=new GLNyARRaster_RGB(gl,ar_param);
711-- //キャプチャ開始
712-- capture.start();
713-- }catch(Exception e){
714-- e.printStackTrace();
715-- }
716-- animator = new Animator(drawable);
717--
718-- animator.start();
719--
720-- }
721--
722-- public void reshape(GLAutoDrawable drawable,
723-- int x, int y,
724-- int width, int height)
725-- {
726-- float ratio = (float)height / (float)width;
727-- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
728-- gl.glViewport(0, 0, width, height);
729--
730-- //視体積の設定
731-- gl.glMatrixMode(GL.GL_PROJECTION);
732-- gl.glLoadIdentity();
733-- gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
734-- 5.0f, 40.0f);
735-- //見る位置
736-- gl.glMatrixMode(GL.GL_MODELVIEW);
737-- gl.glLoadIdentity();
738-- gl.glTranslatef(0.0f, 0.0f, -10.0f);
739-- }
740--
741-- public void display(GLAutoDrawable drawable)
742-- {
743--
744-- try{
745-- if(!cap_image.hasData()){
746-- return;
747-- }
748-- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
749-- //画像チェックしてマーカー探して、背景を書く
750-- boolean is_marker_exist;
751-- synchronized(cap_image){
752-- is_marker_exist=nya.detectMarkerLite(cap_image,100);
753-- //背景を書く
754-- cap_image.glDispImage(1.0);
755-- }
756-- //あったら立方体を書く
757-- if(is_marker_exist){
758-- // Projection transformation.
759-- gl.glMatrixMode(GL.GL_PROJECTION);
760-- gl.glLoadMatrixd(ar_param.getCameraFrustumRH(),0);
761-- gl.glMatrixMode(GL.GL_MODELVIEW);
762-- // Viewing transformation.
763-- gl.glLoadIdentity();
764-- gl.glLoadMatrixd(nya.getCameraViewRH(),0);
765--
766--
767-- // All other lighting and geometry goes here.
768-- drawCube();
769-- }
770-- }catch(Exception e){
771-- e.printStackTrace();
772-- }
773-- }
774-- public void onUpdateBuffer(Buffer i_buffer)
775-- {
776-- try{
777-- synchronized(cap_image){
778-- cap_image.setBuffer(i_buffer, true);
779-- }
780-- }catch(Exception e){
781-- e.printStackTrace();
782-- }
783-- }
784--
785-- public void displayChanged(GLAutoDrawable drawable,
786-- boolean modeChanged,
787-- boolean deviceChanged) {}
788--
789-- public static void main(String[] args) {
790-- new JavaSimpleLite();
791-- }
792--}
793--
794-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java
795-===================================================================
796---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java (revision 0)
797-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java (revision 178)
798-@@ -0,0 +1,76 @@
799-+/**
800-+ * NyARRaster_RGBにOpenGL用のデータ変換機能を追加したものです。
801-+ *
802-+ * (c)2008 A虎@nyatla.jp
803-+ * airmail(at)ebony.plala.or.jp
804-+ * http://nyatla.jp/
805-+ */
806-+package jp.nyatla.nyartoolkit.jogl.utils;
807-+
808-+import javax.media.format.RGBFormat;
809-+import javax.media.opengl.GL;
810-+import jp.nyatla.nyartoolkit.NyARException;
811-+import jp.nyatla.nyartoolkit.jmf.utils.*;
812-+import jp.nyatla.nyartoolkit.core.*;
813-+
814-+public class GLNyARRaster_RGB extends JmfNyARRaster_RGB
815-+{
816-+ private byte[] gl_buf;
817-+ private int gl_flag;
818-+
819-+ public GLNyARRaster_RGB(GL i_ref_gl,NyARParam i_param)
820-+ {
821-+ super(i_param.getX(),i_param.getY());
822-+ this.gl_flag=GL.GL_RGB;
823-+ this.gl_buf=new byte[this.width*this.height*3];
824-+ }
825-+ public void setBuffer(javax.media.Buffer i_buffer,boolean i_is_reverse) throws NyARException
826-+ {
827-+ //JMFデータでフォーマットプロパティを初期化
828-+ initFormatProperty((RGBFormat)i_buffer.getFormat());
829-+
830-+ byte[] src_buf=(byte[])i_buffer.getData();
831-+ //GL用のデータを準備
832-+ if(i_is_reverse){
833-+ int length=this.width*3;
834-+ int src_idx=0;
835-+ int dest_idx=(this.height-1)*length;
836-+ for(int i=0;i<this.height;i++){
837-+ System.arraycopy(src_buf,src_idx,this.gl_buf,dest_idx,length);
838-+ src_idx+=length;
839-+ dest_idx-=length;
840-+ }
841-+ }else{
842-+ System.arraycopy(src_buf,0,gl_buf,0,src_buf.length);
843-+ }
844-+ //GLのフラグ設定
845-+ switch(this.pix_type){
846-+ case GLNyARRaster_RGB.PIXEL_ORDER_BGR:
847-+ this.gl_flag=GL.GL_BGR;
848-+ break;
849-+ case GLNyARRaster_RGB.PIXEL_ORDER_RGB:
850-+ this.gl_flag=GL.GL_RGB;
851-+ break;
852-+ default:
853-+ throw new NyARException();
854-+ }
855-+ //ref_bufをgl_bufに差し替える
856-+ ref_buf=gl_buf;
857-+ }
858-+ /**
859-+ * GLでそのまま描画できるRGBバッファを返す。
860-+ * @return
861-+ */
862-+ public byte[] getGLRgbArray()
863-+ {
864-+ return this.ref_buf;
865-+ }
866-+ /**
867-+ * GL用のRGBバッファのバイト並びタイプを返す。
868-+ * @return
869-+ */
870-+ public int getGLPixelFlag()
871-+ {
872-+ return this.gl_flag;
873-+ }
874-+}
875-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java
876-===================================================================
877---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java (revision 0)
878-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java (revision 178)
879-@@ -0,0 +1,57 @@
880-+/**
881-+ * NyARSingleDetectMarkerにOpenGL向け関数を追加したもの
882-+ * (c)2008 A虎@nyatla.jp
883-+ * airmail(at)ebony.plala.or.jp
884-+ * http://nyatla.jp/
885-+ */
886-+package jp.nyatla.nyartoolkit.jogl.utils;
887-+
888-+import jp.nyatla.nyartoolkit.NyARException;
889-+import jp.nyatla.nyartoolkit.core.NyARCode;
890-+import jp.nyatla.nyartoolkit.core.NyARMat;
891-+import jp.nyatla.nyartoolkit.core.NyARParam;
892-+import jp.nyatla.nyartoolkit.detector.*;
893-+
894-+public class GLNyARSingleDetectMarker extends NyARSingleDetectMarker
895-+{
896-+ private double view_scale_factor=0.025;//#define VIEW_SCALEFACTOR 0.025 // 1.0 ARToolKit unit becomes 0.025 of my OpenGL units.
897-+ public GLNyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width)
898-+ {
899-+ super(i_param,i_code,i_marker_width);
900-+ }
901-+ public void setScaleFactor(double i_new_value)
902-+ {
903-+ view_scale_factor=i_new_value;
904-+ }
905-+ // public static void arglCameraViewRH(const double para[3][4], GLdouble m_modelview[16], const double scale)
906-+ public double[] getCameraViewRH() throws NyARException
907-+ {
908-+ //座標を計算
909-+ NyARMat mat=getTransmationMatrix();
910-+ //行列変換
911-+ double[][] para=mat.getArray();
912-+ double[] result=new double[16];
913-+ result[0 + 0*4] = para[0][0]; // R1C1
914-+ result[0 + 1*4] = para[0][1]; // R1C2
915-+ result[0 + 2*4] = para[0][2];
916-+ result[0 + 3*4] = para[0][3];
917-+ result[1 + 0*4] = -para[1][0]; // R2
918-+ result[1 + 1*4] = -para[1][1];
919-+ result[1 + 2*4] = -para[1][2];
920-+ result[1 + 3*4] = -para[1][3];
921-+ result[2 + 0*4] = -para[2][0]; // R3
922-+ result[2 + 1*4] = -para[2][1];
923-+ result[2 + 2*4] = -para[2][2];
924-+ result[2 + 3*4] = -para[2][3];
925-+ result[3 + 0*4] = 0.0;
926-+ result[3 + 1*4] = 0.0;
927-+ result[3 + 2*4] = 0.0;
928-+ result[3 + 3*4] = 1.0;
929-+ if (view_scale_factor != 0.0) {
930-+ result[12] *= view_scale_factor;
931-+ result[13] *= view_scale_factor;
932-+ result[14] *= view_scale_factor;
933-+ }
934-+ return result;
935-+ }
936-+}
937-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java
938-===================================================================
939---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (revision 0)
940-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java (revision 178)
941-@@ -0,0 +1,99 @@
942-+/**
943-+ * NyARToolkit用のJOGL支援関数群
944-+ * (c)2008 A虎@nyatla.jp
945-+ * airmail(at)ebony.plala.or.jp
946-+ * http://nyatla.jp/
947-+ */
948-+package jp.nyatla.nyartoolkit.jogl.utils;
949-+import java.nio.ByteBuffer;
950-+import java.nio.IntBuffer;
951-+
952-+import javax.media.opengl.GL;
953-+import javax.media.opengl.glu.GLU;
954-+
955-+import jp.nyatla.nyartoolkit.core.*;
956-+
957-+public class NyARGLUtil
958-+{
959-+ private NyARParam ar_param;
960-+ private javax.media.opengl.GL gl;
961-+ private javax.media.opengl.glu.GLU glu;
962-+ public NyARGLUtil(javax.media.opengl.GL i_gl,NyARParam i_camera_param)
963-+ {
964-+ this.ar_param=i_camera_param;
965-+ this.gl=i_gl;
966-+ this.glu=new GLU();
967-+ }
968-+ /**
969-+ * GLNyARRaster_RGBをバックグラウンドに書き出す。
970-+ * @param image
971-+ * @param zoom
972-+ */
973-+ public void drawBackGround(GLNyARRaster_RGB i_raster,double i_zoom)
974-+ {
975-+ IntBuffer texEnvModeSave=IntBuffer.allocate(1);
976-+ boolean lightingSave;
977-+ boolean depthTestSave;
978-+ javax.media.opengl.GL gl_=this.gl;
979-+
980-+ // Prepare an orthographic projection, set camera position for 2D drawing, and save GL state.
981-+ gl_.glGetTexEnviv(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave); // Save GL texture environment mode.
982-+ if (texEnvModeSave.array()[0] != GL.GL_REPLACE){
983-+ gl_.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
984-+ }
985-+ lightingSave = gl_.glIsEnabled(GL.GL_LIGHTING); // Save enabled state of lighting.
986-+ if (lightingSave == true){
987-+ gl_.glDisable(GL.GL_LIGHTING);
988-+ }
989-+ depthTestSave = gl_.glIsEnabled(GL.GL_DEPTH_TEST); // Save enabled state of depth test.
990-+ if (depthTestSave == true){
991-+ gl_.glDisable(GL.GL_DEPTH_TEST);
992-+ }
993-+ gl_.glMatrixMode(GL.GL_PROJECTION);
994-+ gl_.glPushMatrix();
995-+ gl_.glLoadIdentity();
996-+ glu.gluOrtho2D(0.0,ar_param.getX(),0.0,ar_param.getY());
997-+ gl_.glMatrixMode(GL.GL_MODELVIEW);
998-+ gl_.glPushMatrix();
999-+ gl_.glLoadIdentity();
1000-+ arglDispImageStateful(i_raster,i_zoom);
1001-+
1002-+
1003-+ // Restore previous projection, camera position, and GL state.
1004-+ gl_.glMatrixMode(GL.GL_PROJECTION);
1005-+ gl_.glPopMatrix();
1006-+ gl_.glMatrixMode(GL.GL_MODELVIEW);
1007-+ gl_.glPopMatrix();
1008-+ if (depthTestSave){
1009-+ gl_.glEnable(GL.GL_DEPTH_TEST); // Restore enabled state of depth test.
1010-+ }
1011-+ if (lightingSave){
1012-+ gl_.glEnable(GL.GL_LIGHTING); // Restore enabled state of lighting.
1013-+ }
1014-+ if (texEnvModeSave.get(0) != GL.GL_REPLACE){
1015-+ gl_.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave.get(0)); // Restore GL texture environment mode.
1016-+ }
1017-+ gl_.glEnd();
1018-+ }
1019-+ /**
1020-+ * arglDispImageStateful関数モドキ
1021-+ * @param image
1022-+ * @param zoom
1023-+ */
1024-+ private void arglDispImageStateful(GLNyARRaster_RGB i_raster,double zoom)
1025-+ {
1026-+ javax.media.opengl.GL gl_=this.gl;
1027-+ int width =i_raster.getWidth();
1028-+ int height=i_raster.getHeight();
1029-+ float zoomf;
1030-+ IntBuffer params=IntBuffer.allocate(4);
1031-+ zoomf = (float)zoom;
1032-+ gl_.glDisable(GL.GL_TEXTURE_2D);
1033-+ gl_.glGetIntegerv(GL.GL_VIEWPORT,params);
1034-+ gl_.glPixelZoom(zoomf * ((float)(params.get(2)) / (float)width),-zoomf * ((float)(params.get(3)) / (float)height));
1035-+ gl_.glRasterPos2f(0.0f,(float)height);
1036-+ gl_.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
1037-+ ByteBuffer buf=ByteBuffer.wrap(i_raster.getGLRgbArray());
1038-+ gl_.glDrawPixels(width,height,i_raster.getGLPixelFlag(),GL.GL_UNSIGNED_BYTE,buf);
1039-+ }
1040-+}
1041-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java
1042-===================================================================
1043---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java (revision 0)
1044-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java (revision 178)
1045-@@ -0,0 +1,99 @@
1046-+/**
1047-+ * NyARParamにOpenGL向け関数を追加したもの
1048-+ * (c)2008 A虎@nyatla.jp
1049-+ * airmail(at)ebony.plala.or.jp
1050-+ * http://nyatla.jp/
1051-+ */
1052-+package jp.nyatla.nyartoolkit.jogl.utils;
1053-+
1054-+import jp.nyatla.nyartoolkit.core.*;
1055-+public class GLNyARParam extends NyARParam
1056-+{
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.
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.
1059-+ private double[] m_projection=null;
1060-+ public void setViewDistanceMin(double i_new_value)
1061-+ {
1062-+ m_projection=null;//キャッシュ済変数初期化
1063-+ view_distance_min=i_new_value;
1064-+ }
1065-+ public void setViewDistanceMax(double i_new_value)
1066-+ {
1067-+ m_projection=null;//キャッシュ済変数初期化
1068-+ view_distance_max=i_new_value;
1069-+ }
1070-+ /**
1071-+ * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])
1072-+ * 関数の置き換え
1073-+ * @param focalmin
1074-+ * @param focalmax
1075-+ * @return
1076-+ */
1077-+ public double[] getCameraFrustumRH()
1078-+ {
1079-+ //既に値がキャッシュされていたらそれを使う
1080-+ if(m_projection!=null){
1081-+ return m_projection;
1082-+ }
1083-+ //無ければ計算
1084-+ m_projection=new double[16];
1085-+ NyARMat trans_mat=new NyARMat(3,4);
1086-+ NyARMat icpara_mat=new NyARMat(3,4);
1087-+ double[][] p=new double[3][3], q=new double[4][4];
1088-+ int width, height;
1089-+ int i, j;
1090-+
1091-+ width = xsize;
1092-+ height = ysize;
1093-+
1094-+ decompMat(icpara_mat,trans_mat);
1095-+
1096-+ double[][] icpara=icpara_mat.getArray();
1097-+ double[][] trans=trans_mat.getArray();
1098-+ for (i = 0; i < 4; i++) {
1099-+ icpara[1][i] = (height - 1)*(icpara[2][i]) - icpara[1][i];
1100-+ }
1101-+
1102-+ for(i = 0; i < 3; i++) {
1103-+ for(j = 0; j < 3; j++) {
1104-+ p[i][j] = icpara[i][j] / icpara[2][2];
1105-+ }
1106-+ }
1107-+ q[0][0] = (2.0 * p[0][0] / (width - 1));
1108-+ q[0][1] = (2.0 * p[0][1] / (width - 1));
1109-+ q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);
1110-+ q[0][3] = 0.0;
1111-+
1112-+ q[1][0] = 0.0;
1113-+ q[1][1] = -(2.0 * p[1][1] / (height - 1));
1114-+ q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);
1115-+ q[1][3] = 0.0;
1116-+
1117-+ q[2][0] = 0.0;
1118-+ q[2][1] = 0.0;
1119-+ q[2][2] = (view_distance_max + view_distance_min)/(view_distance_min - view_distance_max);
1120-+ q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);
1121-+
1122-+ q[3][0] = 0.0;
1123-+ q[3][1] = 0.0;
1124-+ q[3][2] = -1.0;
1125-+ q[3][3] = 0.0;
1126-+
1127-+ for (i = 0; i < 4; i++) { // Row.
1128-+ // First 3 columns of the current row.
1129-+ for (j = 0; j < 3; j++) { // Column.
1130-+ m_projection[i + j*4] =
1131-+ q[i][0] * trans[0][j] +
1132-+ q[i][1] * trans[1][j] +
1133-+ q[i][2] * trans[2][j];
1134-+ }
1135-+ // Fourth column of the current row.
1136-+ m_projection[i + 3*4]=
1137-+ q[i][0] * trans[0][3] +
1138-+ q[i][1] * trans[1][3] +
1139-+ q[i][2] * trans[2][3] +
1140-+ q[i][3];
1141-+ }
1142-+ return m_projection;
1143-+ }
1144-+}
1145-Index: D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java
1146-===================================================================
1147---- D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java (revision 0)
1148-+++ D:/project.files/java.Lab/NyARToolKit/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java (revision 178)
1149-@@ -0,0 +1,222 @@
1150-+/**
1151-+ * simpleLiteと同じようなテストプログラム
1152-+ * マーカーの一致度の最低値をチェックするところを抜いたので、同じマーカーを大量に
1153-+ * 検出すると面白いことになります。
1154-+ * (c)2008 A虎@nyatla.jp
1155-+ * airmail(at)ebony.plala.or.jp
1156-+ * http://nyatla.jp/
1157-+ */
1158-+package jp.nyatla.nyartoolkit.jogl.sample;
1159-+
1160-+import java.awt.event.WindowAdapter;
1161-+import java.awt.event.WindowEvent;
1162-+import java.awt.*;
1163-+
1164-+import javax.media.Buffer;
1165-+
1166-+import javax.media.opengl.GL;
1167-+import javax.media.opengl.GLAutoDrawable;
1168-+import javax.media.opengl.GLEventListener;
1169-+import javax.media.opengl.GLCanvas;
1170-+
1171-+import com.sun.opengl.util.Animator;
1172-+
1173-+import jp.nyatla.nyartoolkit.core.NyARCode;
1174-+
1175-+import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;
1176-+import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;
1177-+import jp.nyatla.nyartoolkit.jogl.utils.*;
1178-+
1179-+
1180-+public class JavaSimpleLite implements GLEventListener,JmfCaptureListener
1181-+{
1182-+ private final String CARCODE_FILE ="../../Data/patt.hiro";
1183-+ private final String PARAM_FILE ="../../Data/camera_para.dat";
1184-+
1185-+ private final static int SCREEN_X=320;
1186-+ private final static int SCREEN_Y=240;
1187-+ private Animator animator;
1188-+ private GLNyARRaster_RGB cap_image;
1189-+
1190-+ private JmfCameraCapture capture;
1191-+ private GL gl;
1192-+ private NyARGLUtil glnya;
1193-+
1194-+
1195-+ //NyARToolkit関係
1196-+ private GLNyARSingleDetectMarker nya;
1197-+ private GLNyARParam ar_param;
1198-+ /**
1199-+ * 立方体を書く
1200-+ *
1201-+ */
1202-+ void drawCube()
1203-+ {
1204-+ // Colour cube data.
1205-+ int polyList = 0;
1206-+ float fSize = 0.5f;//マーカーサイズに対して0.5倍なので、4cmのナタデココ
1207-+ int f, i;
1208-+ float[][] cube_vertices=new float[][]{
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},
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}
1211-+ };
1212-+ float[][] cube_vertex_colors=new float[][]{
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},
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}
1215-+ };
1216-+ int cube_num_faces = 6;
1217-+ short[][] cube_faces =new short[][]{
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}
1219-+ };
1220-+
1221-+ if (polyList==0) {
1222-+ polyList = gl.glGenLists (1);
1223-+ gl.glNewList(polyList, GL.GL_COMPILE);
1224-+ gl.glBegin(GL.GL_QUADS);
1225-+ for (f = 0; f < cube_num_faces; f++)
1226-+ for (i = 0; i < 4; i++) {
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]);
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);
1229-+ }
1230-+ gl.glEnd();
1231-+ gl.glColor3f(0.0f, 0.0f, 0.0f);
1232-+ for (f = 0; f < cube_num_faces; f++) {
1233-+ gl.glBegin (GL.GL_LINE_LOOP);
1234-+ for (i = 0; i < 4; i++)
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);
1236-+ gl.glEnd ();
1237-+ }
1238-+ gl.glEndList ();
1239-+ }
1240-+
1241-+ gl.glPushMatrix(); // Save world coordinate system.
1242-+ gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.
1243-+ gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.
1244-+ gl.glDisable(GL.GL_LIGHTING); // Just use colours.
1245-+ gl.glCallList(polyList); // Draw the cube.
1246-+ gl.glPopMatrix(); // Restore world coordinate system.
1247-+
1248-+ }
1249-+
1250-+
1251-+
1252-+ public JavaSimpleLite()
1253-+ {
1254-+ Frame frame = new Frame("Java simpleLite with NyARToolkit");
1255-+
1256-+
1257-+ // 3Dを描画するコンポーネント
1258-+ GLCanvas canvas = new GLCanvas();
1259-+ frame.add(canvas);
1260-+ canvas.addGLEventListener(this);
1261-+ frame.addWindowListener(new WindowAdapter() {
1262-+ public void windowClosing(WindowEvent e) {
1263-+ System.exit(0);
1264-+ }
1265-+ });
1266-+
1267-+ frame.setVisible(true);
1268-+ Insets ins=frame.getInsets();
1269-+ frame.setSize(SCREEN_X+ins.left+ins.right,SCREEN_Y+ins.top+ins.bottom);
1270-+ canvas.setBounds(ins.left,ins.top,SCREEN_X,SCREEN_Y);
1271-+ }
1272-+
1273-+ public void init(GLAutoDrawable drawable) {
1274-+ gl = drawable.getGL();
1275-+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1276-+ //NyARToolkitの準備
1277-+ try{
1278-+ //キャプチャの準備
1279-+ capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXEL_FORMAT_RGB);
1280-+ capture.setCaptureListener(this);
1281-+ //NyARToolkitの準備
1282-+ ar_param=new GLNyARParam();
1283-+ NyARCode ar_code =new NyARCode(16,16);
1284-+ ar_param.loadFromARFile(PARAM_FILE);
1285-+ ar_param.changeSize(SCREEN_X,SCREEN_Y);
1286-+ nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0);
1287-+ ar_code.loadFromARFile(CARCODE_FILE);
1288-+ //NyARToolkit用の支援クラス
1289-+ glnya=new NyARGLUtil(gl,ar_param);
1290-+ //GL対応のRGBラスタオブジェクト
1291-+ cap_image=new GLNyARRaster_RGB(gl,ar_param);
1292-+ //キャプチャ開始
1293-+ capture.start();
1294-+ }catch(Exception e){
1295-+ e.printStackTrace();
1296-+ }
1297-+ animator = new Animator(drawable);
1298-+
1299-+ animator.start();
1300-+
1301-+ }
1302-+
1303-+ public void reshape(GLAutoDrawable drawable,
1304-+ int x, int y,
1305-+ int width, int height)
1306-+ {
1307-+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1308-+ gl.glViewport(0, 0, width, height);
1309-+
1310-+ //視体積の設定
1311-+ gl.glMatrixMode(GL.GL_PROJECTION);
1312-+ gl.glLoadIdentity();
1313-+ //見る位置
1314-+ gl.glMatrixMode(GL.GL_MODELVIEW);
1315-+ gl.glLoadIdentity();
1316-+ }
1317-+
1318-+ public void display(GLAutoDrawable drawable)
1319-+ {
1320-+
1321-+ try{
1322-+ if(!cap_image.hasData()){
1323-+ return;
1324-+ }
1325-+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.
1326-+ //画像チェックしてマーカー探して、背景を書く
1327-+ boolean is_marker_exist;
1328-+ synchronized(cap_image){
1329-+ is_marker_exist=nya.detectMarkerLite(cap_image,100);
1330-+ //背景を書く
1331-+ glnya.drawBackGround(cap_image, 1.0);
1332-+ }
1333-+ //あったら立方体を書く
1334-+ if(is_marker_exist){
1335-+ //マーカーの一致度を調査するならば、ここでnya.getConfidence()で一致度を調べて下さい。
1336-+ // Projection transformation.
1337-+ gl.glMatrixMode(GL.GL_PROJECTION);
1338-+ gl.glLoadMatrixd(ar_param.getCameraFrustumRH(),0);
1339-+ gl.glMatrixMode(GL.GL_MODELVIEW);
1340-+ // Viewing transformation.
1341-+ gl.glLoadIdentity();
1342-+ gl.glLoadMatrixd(nya.getCameraViewRH(),0);
1343-+
1344-+
1345-+ // All other lighting and geometry goes here.
1346-+ drawCube();
1347-+ }
1348-+ }catch(Exception e){
1349-+ e.printStackTrace();
1350-+ }
1351-+ }
1352-+ public void onUpdateBuffer(Buffer i_buffer)
1353-+ {
1354-+ try{
1355-+ synchronized(cap_image){
1356-+ cap_image.setBuffer(i_buffer, true);
1357-+ }
1358-+ }catch(Exception e){
1359-+ e.printStackTrace();
1360-+ }
1361-+ }
1362-+
1363-+ public void displayChanged(GLAutoDrawable drawable,
1364-+ boolean modeChanged,
1365-+ boolean deviceChanged) {}
1366-+
1367-+ public static void main(String[] args) {
1368-+ new JavaSimpleLite();
1369-+ }
1370-+}
1371-+
1372-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java
1373-===================================================================
1374---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java (revision 174)
1375-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/JmfCaptureTest.java (revision 178)
1376-@@ -1,56 +0,0 @@
1377--/**
1378-- * VFMキャプチャテストプログラム
1379-- * (c)2008 R.iizuka
1380-- * airmail@ebony.plala.or.jp
1381-- * http://nyatla.jp/
1382-- */
1383--import javax.media.*;
1384--
1385--import javax.media.util.BufferToImage;
1386--import javax.media.format.*;
1387--
1388--import jp.nyatla.nyartoolkit.NyARException;
1389--import jp.nyatla.nyartoolkit.jmf.*;
1390--import java.awt.*;
1391--
1392--
1393--
1394--public class JmfCaptureTest extends Frame implements JmfCaptureListener{
1395-- public JmfCaptureTest() throws NyARException
1396-- {
1397-- setTitle("JmfCaptureTest");
1398-- setBounds(0,0,320+64,240+64);
1399-- capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
1400-- capture.setCaptureListener(this);
1401-- }
1402--
1403--
1404--
1405-- private JmfCameraCapture capture;
1406-- public void onUpdateBuffer(Buffer i_buffer)
1407-- {
1408-- BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
1409-- Image img=b2i.createImage(i_buffer);
1410-- Graphics g = getGraphics();
1411-- g.drawImage(img, 32, 32,this);
1412-- }
1413-- private void startCapture()
1414-- {
1415-- try{
1416-- capture.start();
1417-- }catch(Exception e){
1418-- e.printStackTrace();
1419-- }
1420-- }
1421-- public static void main(String[] args) {
1422-- try{
1423-- JmfCaptureTest mainwin = new JmfCaptureTest();
1424-- mainwin.setVisible(true);
1425-- mainwin.startCapture();
1426-- }catch(Exception e){
1427-- e.printStackTrace();
1428-- }
1429--
1430-- }
1431--
1432--}
1433-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java
1434-===================================================================
1435---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java (revision 174)
1436-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/NyarToolkitLinkTest.java (revision 178)
1437-@@ -1,114 +0,0 @@
1438--/**
1439-- * VFM+ARToolkitテストプログラム
1440-- * カメラから取り込んだデータからマーカーを検出して、一致度と変換行列を表示します。
1441-- * (c)2008 R.iizuka
1442-- * airmail(at)ebony.plala.or.jp
1443-- * http://nyatla.jp/
1444-- */
1445--import javax.media.*;
1446--
1447--import javax.media.util.BufferToImage;
1448--import javax.media.format.*;
1449--
1450--import jp.nyatla.nyartoolkit.NyARException;
1451--import jp.nyatla.nyartoolkit.jmf.*;
1452--import jp.nyatla.nyartoolkit.jmfutil.*;
1453--import java.awt.*;
1454--
1455--import jp.nyatla.nyartoolkit.core.*;
1456--import jp.nyatla.nyartoolkit.detector.*;
1457--import jp.nyatla.nyartoolkit.core.raster.*;
1458--
1459--
1460--
1461--
1462--
1463--public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
1464--{
1465-- private final String CARCODE_FILE ="../../Data/patt.hiro";
1466-- private final String PARAM_FILE ="../../Data/camera_para.dat";
1467-- private JmfCameraCapture capture;
1468-- NyARSingleDetectMarker nya;
1469-- JmfNyARRaster_RGB raster;
1470--
1471-- public NyarToolkitLinkTest() throws NyARException,NyARException
1472-- {
1473-- setTitle("JmfCaptureTest");
1474-- setBounds(0,0,320+64,240+64);
1475-- //キャプチャの準備
1476-- capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
1477-- capture.setCaptureListener(this);
1478--
1479-- //NyARToolkitの準備
1480-- NyARParam ar_param=new NyARParam();
1481-- NyARCode ar_code =new NyARCode(16,16);
1482-- ar_param.loadFromARFile(PARAM_FILE);
1483-- ar_param.changeSize(320,240);
1484-- nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);
1485-- ar_code.loadFromARFile(CARCODE_FILE);
1486-- //キャプチャイメージ用のラスタを準備
1487-- raster=new JmfNyARRaster_RGB(320,240);
1488-- }
1489--
1490--
1491--
1492-- public void onUpdateBuffer(Buffer i_buffer)
1493-- {
1494-- try{
1495-- //キャプチャしたバッファをラスタにセット
1496-- raster.setBuffer(i_buffer);
1497--
1498-- //キャプチャしたイメージを表示用に加工
1499-- BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
1500-- Image img=b2i.createImage(i_buffer);
1501--
1502-- Graphics g = getGraphics();
1503-- double[][] atm=null;
1504--
1505-- //マーカー検出
1506-- boolean is_marker_exist=nya.detectMarkerLite(raster,100);
1507-- if(is_marker_exist){
1508-- //変換行列を取得
1509-- atm=nya.getTransmationMatrix().getArray();
1510-- }
1511-- //情報を画面に書く
1512-- g.drawImage(img, 32, 32,this);
1513-- if(is_marker_exist){
1514-- g.drawString("マーカー検出:"+nya.getConfidence(),32,50);
1515-- for(int i=0;i<3;i++){
1516-- for(int i2=0;i2<4;i2++){
1517-- g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);
1518-- }
1519--
1520-- }
1521-- }else{
1522-- g.drawString("マーカー未検出:",32,100);
1523-- }
1524-- }catch(Exception e){
1525-- e.printStackTrace();
1526-- }
1527--
1528--
1529--
1530--
1531-- }
1532-- private void startCapture()
1533-- {
1534-- try{
1535-- capture.start();
1536-- }catch(Exception e){
1537-- e.printStackTrace();
1538-- }
1539-- }
1540-- public static void main(String[] args) {
1541-- try{
1542-- NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();
1543-- mainwin.setVisible(true);
1544-- mainwin.startCapture();
1545-- }catch(Exception e){
1546-- e.printStackTrace();
1547-- }
1548--
1549-- }
1550--
1551--}
1552-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorCDS.java
1553-===================================================================
1554---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorCDS.java (revision 174)
1555-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorCDS.java (revision 178)
1556-@@ -1,136 +0,0 @@
1557--/*
1558-- * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
1559-- *
1560-- * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
1561-- * modify and redistribute this software in source and binary code form,
1562-- * provided that i) this copyright notice and license appear on all copies of
1563-- * the software; and ii) Licensee does not utilize the software in a manner
1564-- * which is disparaging to Sun.
1565-- *
1566-- * This software is provided "AS IS," without a warranty of any kind. ALL
1567-- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
1568-- * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
1569-- * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
1570-- * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
1571-- * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
1572-- * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
1573-- * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
1574-- * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
1575-- * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
1576-- * POSSIBILITY OF SUCH DAMAGES.
1577-- *
1578-- * This software is not designed or intended for use in on-line control of
1579-- * aircraft, air traffic, aircraft navigation or aircraft communications; or in
1580-- * the design, construction, operation or maintenance of any nuclear
1581-- * facility. Licensee represents and warrants that it will not use or
1582-- * redistribute the Software for such purposes.
1583-- */
1584--package jp.nyatla.nyartoolkit.jmf;
1585--
1586--
1587--import javax.media.*;
1588--import javax.media.protocol.*;
1589--import javax.media.control.*;
1590--
1591--import java.io.IOException;
1592--
1593--
1594--
1595--public class MonitorCDS extends PushBufferDataSource{
1596--
1597-- private PushBufferDataSource delegate = null;
1598-- private PushBufferStream [] delStreams = null;
1599-- private MonitorStream monitorStream = null;
1600-- private PushBufferStream [] monitorStreams = null;
1601-- boolean delStarted = false; // variable used by MonitorStream also
1602-- private Control [] controls;
1603--
1604-- public MonitorCDS(DataSource ds)
1605-- {
1606-- // Get the stream from the actual datasource
1607-- // and create a MonitorStream from it
1608-- // Export the MonitorControl interface of the MonitorStream
1609-- if (ds instanceof PushBufferDataSource)
1610-- {
1611-- delegate = (PushBufferDataSource) ds;
1612-- delStreams = delegate.getStreams();
1613-- monitorStream = new MonitorStream(delStreams[0], this);
1614-- monitorStreams = new PushBufferStream[] {monitorStream};
1615-- }
1616-- }
1617--
1618-- public Object [] getControls()
1619-- {
1620-- return controls;
1621-- }
1622--
1623-- public Object getControl(String value) {
1624-- if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl"))
1625-- return monitorStream;
1626-- else
1627-- return null;
1628-- }
1629--
1630-- public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
1631-- {
1632-- return ((CaptureDevice)delegate).getCaptureDeviceInfo();
1633-- }
1634--
1635-- public FormatControl[] getFormatControls()
1636-- {
1637-- return ((CaptureDevice)delegate).getFormatControls();
1638-- }
1639--
1640-- public String getContentType()
1641-- {
1642-- return delegate.getContentType();
1643-- }
1644--
1645-- public void connect() throws IOException
1646-- {
1647-- if (delegate == null)
1648-- throw new IOException("Incompatible DataSource");
1649-- // Delegate is already connected
1650-- }
1651--
1652-- public void disconnect()
1653-- {
1654-- monitorStream.setEnabled(false);
1655-- delegate.disconnect();
1656-- }
1657--
1658-- public synchronized void start() throws IOException
1659-- {
1660-- startDelegate();
1661-- delStarted = true;
1662-- }
1663--
1664-- public synchronized void stop() throws IOException
1665-- {
1666-- if (!monitorStream.isEnabled()) {
1667-- stopDelegate();
1668-- }
1669-- delStarted = false;
1670-- }
1671--
1672-- public Time getDuration()
1673-- {
1674-- return delegate.getDuration();
1675-- }
1676--
1677-- public PushBufferStream [] getStreams()
1678-- {
1679-- return monitorStreams;
1680-- }
1681--
1682-- void startDelegate() throws IOException
1683-- {
1684-- delegate.start();
1685-- }
1686--
1687-- void stopDelegate() throws IOException
1688-- {
1689-- delegate.stop();
1690-- }
1691--
1692--}
1693-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorStream.java
1694-===================================================================
1695---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorStream.java (revision 174)
1696-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/MonitorStream.java (revision 178)
1697-@@ -1,196 +0,0 @@
1698--/*
1699-- * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
1700-- *
1701-- * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
1702-- * modify and redistribute this software in source and binary code form,
1703-- * provided that i) this copyright notice and license appear on all copies of
1704-- * the software; and ii) Licensee does not utilize the software in a manner
1705-- * which is disparaging to Sun.
1706-- *
1707-- * This software is provided "AS IS," without a warranty of any kind. ALL
1708-- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
1709-- * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
1710-- * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
1711-- * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
1712-- * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
1713-- * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
1714-- * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
1715-- * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
1716-- * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
1717-- * POSSIBILITY OF SUCH DAMAGES.
1718-- *
1719-- * This software is not designed or intended for use in on-line control of
1720-- * aircraft, air traffic, aircraft navigation or aircraft communications; or in
1721-- * the design, construction, operation or maintenance of any nuclear
1722-- * facility. Licensee represents and warrants that it will not use or
1723-- * redistribute the Software for such purposes.
1724-- */
1725--package jp.nyatla.nyartoolkit.jmf;
1726--
1727--
1728--
1729--import javax.media.*;
1730--import javax.media.protocol.*;
1731--
1732--import javax.media.util.BufferToImage;
1733--import java.io.IOException;
1734--import java.awt.*;
1735--
1736--public class MonitorStream implements PushBufferStream, BufferTransferHandler {
1737--
1738-- JmfCaptureListener img_listener;
1739-- PushBufferStream actual = null;
1740-- boolean dataAvailable = false;
1741-- boolean terminate = false;
1742-- boolean enabled = false;
1743-- Object bufferLock = new Object();
1744-- Buffer cbuffer = new Buffer();
1745-- BufferTransferHandler transferHandler = null;
1746-- Component component = null;
1747-- MonitorCDS cds;
1748-- BufferToImage bti = null;
1749--
1750-- MonitorStream(PushBufferStream actual, MonitorCDS cds) {
1751-- this.actual = actual;
1752-- actual.setTransferHandler(this);
1753-- this.cds = cds;
1754-- }
1755--
1756-- public javax.media.Format getFormat()
1757-- {
1758-- return actual.getFormat();
1759-- }
1760-- /**
1761-- * 非同期READ
1762-- */
1763-- public void read(Buffer buffer) throws IOException
1764-- {
1765-- // Wait for data to be available
1766-- // Doesn't get used much because the transferData
1767-- // call is made when data IS available. And most
1768-- // Processors/Players read the data in the same
1769-- // thread that called transferData, although that's
1770-- // not a safe assumption to make
1771-- if (!dataAvailable) {
1772-- synchronized (bufferLock) {
1773-- while (!dataAvailable && !terminate) {
1774-- try {
1775-- bufferLock.wait(100);
1776-- } catch (InterruptedException ie) {
1777-- }
1778-- }
1779-- }
1780-- }
1781--
1782-- if (dataAvailable) {
1783-- synchronized (bufferLock) {
1784-- // Copy the buffer attributes, but swap the data
1785-- // attributes so that no extra copy is made.
1786-- buffer.copy(cbuffer, true);
1787-- //dataAvailable = false;
1788-- }
1789-- }
1790--// return;
1791-- }
1792-- public void setCaptureListener(JmfCaptureListener i_listener)
1793-- {
1794-- img_listener=i_listener;
1795-- }
1796--
1797-- public void transferData(PushBufferStream pbs)
1798-- {
1799-- // Get the data from the original source stream
1800-- synchronized (bufferLock) {
1801-- try {
1802-- pbs.read(cbuffer);
1803-- } catch (IOException ioe) {
1804-- return;
1805-- }
1806-- dataAvailable = true;
1807-- bufferLock.notifyAll();
1808-- }
1809-- if(img_listener!=null){
1810-- img_listener.onUpdateBuffer(cbuffer);
1811-- }
1812--
1813--/*
1814-- // Display data if monitor is active
1815-- if (isEnabled()) {
1816-- if (bti == null) {
1817-- VideoFormat vf = (VideoFormat) cbuffer.getFormat();
1818-- bti = new BufferToImage(vf);
1819-- }
1820-- if (bti != null && component != null) {
1821-- Image im = bti.createImage(cbuffer);
1822-- Graphics g = component.getGraphics();
1823-- Dimension size = component.getSize();
1824-- if (g != null)
1825-- g.drawImage(im, 0, 0, component);
1826-- }
1827-- }
1828--*/
1829-- // Maybe synchronize this with setTransferHandler() ?
1830-- if (transferHandler != null && cds.delStarted)
1831-- transferHandler.transferData(this);
1832-- }
1833--
1834-- public void setTransferHandler(BufferTransferHandler transferHandler) {
1835-- this.transferHandler = transferHandler;
1836-- }
1837--
1838-- public boolean setEnabled(boolean value) {
1839-- enabled = value;
1840-- if (value == false) {
1841-- if (!cds.delStarted) {
1842-- try {
1843-- cds.stopDelegate();
1844-- } catch (IOException ioe) {
1845-- }
1846-- }
1847-- } else {
1848-- // Start the capture datasource if the monitor is enabled
1849-- try {
1850-- cds.startDelegate();
1851-- }catch (IOException ioe) {
1852-- }
1853-- }
1854-- return enabled;
1855-- }
1856--
1857-- public boolean isEnabled()
1858-- {
1859-- return enabled;
1860-- }
1861--
1862--
1863--
1864-- public float setPreviewFrameRate(float rate)
1865-- {
1866-- System.err.println("TODO");
1867-- return rate;
1868-- }
1869--
1870-- public ContentDescriptor getContentDescriptor()
1871-- {
1872-- return actual.getContentDescriptor();
1873-- }
1874--
1875-- public long getContentLength()
1876-- {
1877-- return actual.getContentLength();
1878-- }
1879--
1880-- public boolean endOfStream() {
1881-- return actual.endOfStream();
1882-- }
1883--
1884-- public Object [] getControls() {
1885-- return new Object[0];
1886-- }
1887--
1888-- public Object getControl(String str) {
1889-- return null;
1890-- }
1891--
1892--
1893--}
1894-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCaptureListener.java
1895-===================================================================
1896---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCaptureListener.java (revision 174)
1897-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCaptureListener.java (revision 178)
1898-@@ -1,14 +0,0 @@
1899--/**
1900-- * JMFお手軽キャプチャ用リスナ
1901-- * (c)2008 R.Iizuka
1902-- * airmail@ebony.plala.or.jp
1903-- * http://nyatla.jp/
1904-- */
1905--package jp.nyatla.nyartoolkit.jmf;
1906--
1907--import javax.media.Buffer;
1908--
1909--public interface JmfCaptureListener{
1910-- public void onUpdateBuffer(Buffer i_buffer);
1911--
1912--}
1913-\ No newline at end of file
1914-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java
1915-===================================================================
1916---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java (revision 174)
1917-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/JmfCameraCapture.java (revision 178)
1918-@@ -1,180 +0,0 @@
1919--/**
1920-- * JMFお手軽キャプチャクラス
1921-- * (c)2008 R.Iizuka
1922-- * airmail@ebony.plala.or.jp
1923-- * http://nyatla.jp/
1924-- */
1925--package jp.nyatla.nyartoolkit.jmf;
1926--
1927--
1928--
1929--import javax.media.*;
1930--import javax.media.protocol.*;
1931--import javax.media.control.*;
1932--import javax.media.format.*;
1933--import java.awt.*;
1934--import java.util.*;
1935--import javax.media.protocol.DataSource;
1936--
1937--import jp.nyatla.nyartoolkit.NyARException;
1938--
1939--
1940--
1941--
1942--
1943--public class JmfCameraCapture
1944--{
1945-- private Dimension image_size;
1946-- private JmfCaptureListener capture_listener;
1947-- private DataSource jmf_data_source;
1948-- private MonitorStream jmf_monitor_stream;
1949-- private Processor jmf_processor;
1950-- private VideoFormat jmf_video_format;
1951--
1952-- private Buffer read_buf=new Buffer();
1953-- public static final String PIXEL_FORMAT_RGB="RGB";
1954-- public JmfCameraCapture(int i_width,int i_height,float i_rate,String i_pixcel_format)
1955-- {
1956-- String encoding = i_pixcel_format;//comboEncoding.getSelectedItem();
1957-- image_size = new Dimension(i_width,i_height);
1958-- jmf_video_format = new VideoFormat(encoding, image_size, Format.NOT_SPECIFIED,null,i_rate);
1959-- }
1960-- public Dimension getSize()
1961-- {
1962-- return image_size;
1963-- }
1964-- public javax.media.Buffer readBuffer() throws NyARException
1965-- {
1966-- if(jmf_monitor_stream==null){
1967-- throw new NyARException();
1968-- }
1969-- try{
1970-- jmf_monitor_stream.read(read_buf);
1971-- }catch(Exception e){
1972-- throw new NyARException(e);
1973-- }
1974-- return read_buf;
1975-- }
1976-- public void setCaptureListener(JmfCaptureListener i_listener) throws NyARException
1977-- {
1978-- if(jmf_processor!=null){
1979-- throw new NyARException();
1980-- }
1981-- capture_listener=i_listener;
1982--
1983-- }
1984-- public void start() throws NyARException
1985-- {
1986--
1987-- DataSource ds=getCaptureDS(jmf_video_format);
1988-- VideoFormat[] formats=new VideoFormat[]{new VideoFormat(null)};
1989-- ProcessorModel pm = new ProcessorModel(ds,formats,null);//, formats, ftd);
1990-- Processor processor;
1991-- try {
1992-- processor = Manager.createRealizedProcessor(pm);
1993-- } catch (Exception e){
1994-- // Make sure the capture devices are released
1995-- ds.disconnect();
1996-- throw new NyARException(e);
1997-- }
1998-- // Get the monitor control:
1999-- // Since there are more than one MonitorControl objects
2000-- // exported by the DataSource, we get the specific one
2001-- // that is also the MonitorStream object.
2002-- jmf_monitor_stream=(MonitorStream)ds.getControl("jmfsample.MonitorStream");
2003-- jmf_monitor_stream.setCaptureListener(capture_listener);
2004-- jmf_data_source=ds;
2005-- jmf_processor=processor;
2006-- jmf_processor.start();
2007-- }
2008-- public void stop()
2009-- {
2010-- jmf_processor.stop();
2011-- jmf_processor.close();
2012-- jmf_processor = null;
2013--
2014-- }
2015-- protected void finalize()
2016-- {
2017-- if(jmf_processor!=null){
2018-- jmf_processor.stop();
2019-- jmf_processor.close();
2020-- jmf_processor = null;
2021-- }
2022-- }
2023-- private static DataSource getCaptureDS(VideoFormat vf) {
2024-- DataSource dsVideo = null;
2025-- DataSource ds = null;
2026--
2027-- // Create a capture DataSource for the video
2028-- // If there is no video capture device, then exit with null
2029-- if (vf != null) {
2030-- dsVideo = createDataSource(vf);
2031-- if (dsVideo == null)
2032-- return null;
2033-- }
2034--
2035--
2036-- // Create the monitoring datasource wrapper
2037-- if (dsVideo != null) {
2038-- dsVideo = new MonitorCDS(dsVideo);
2039-- return dsVideo;
2040-- }
2041--
2042-- // Merge the data sources, if both audio and video are available
2043-- try {
2044-- ds = Manager.createMergingDataSource(new DataSource[]{dsVideo});
2045-- } catch (IncompatibleSourceException ise){
2046-- return null;
2047-- }
2048--
2049-- return ds;
2050-- }
2051--
2052-- private static DataSource createDataSource(Format format) {
2053-- DataSource ds;
2054-- Vector devices;
2055-- CaptureDeviceInfo cdi;
2056-- MediaLocator ml;
2057--
2058-- // Find devices for format
2059-- devices = CaptureDeviceManager.getDeviceList(format);
2060-- if (devices.size() < 1) {
2061-- System.err.println("! No Devices for " + format);
2062-- return null;
2063-- }
2064-- // Pick the first device
2065-- cdi = (CaptureDeviceInfo) devices.elementAt(0);
2066--
2067-- ml = cdi.getLocator();
2068--
2069-- try {
2070-- ds = Manager.createDataSource(ml);
2071-- ds.connect();
2072-- if (ds instanceof CaptureDevice)
2073-- {
2074-- setCaptureFormat((CaptureDevice) ds, format);
2075-- }
2076-- } catch (Exception e) {
2077-- System.err.println(e);
2078-- return null;
2079-- }
2080-- return ds;
2081-- }
2082--
2083-- private static void setCaptureFormat(CaptureDevice cdev, Format format) {
2084-- FormatControl [] fcs = cdev.getFormatControls();
2085-- if (fcs.length < 1){
2086-- return;
2087-- }
2088-- FormatControl fc = fcs[0];
2089-- Format [] formats = fc.getSupportedFormats();
2090-- for (int i = 0; i < formats.length; i++) {
2091-- if (formats[i].matches(format)){
2092-- format = formats[i].intersects(format);
2093-- fc.setFormat(format);
2094-- break;
2095-- }
2096-- }
2097-- }
2098--}
2099-\ No newline at end of file
2100-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java
2101-===================================================================
2102---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java (revision 0)
2103-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java (revision 178)
2104-@@ -0,0 +1,119 @@
2105-+/**
2106-+ * RGB形式のJMFバッファをラップするNyARRasterです。
2107-+ * JMFから得たラスタデータのピクセル並び順を考慮します。
2108-+ * (c)2008 A虎@nyatla.jp
2109-+ * airmail(at)ebony.plala.or.jp
2110-+ * http://nyatla.jp/
2111-+ */
2112-+package jp.nyatla.nyartoolkit.jmf.utils;
2113-+
2114-+
2115-+import javax.media.format.RGBFormat;
2116-+import java.awt.Dimension;
2117-+import jp.nyatla.nyartoolkit.NyARException;
2118-+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;
2119-+
2120-+
2121-+public class JmfNyARRaster_RGB implements NyARRaster
2122-+{
2123-+ public final static int PIXEL_ORDER_RGB=1;
2124-+ public final static int PIXEL_ORDER_BGR=2;
2125-+ protected int pix_type;
2126-+ private int red_idx;
2127-+ private int green_idx;
2128-+ private int blue_idx;
2129-+ protected byte[] ref_buf;
2130-+ protected int width=0;
2131-+ protected int height=0;
2132-+
2133-+ /**
2134-+ * RGB形式のJMFバッファをラップするオブジェクトをつくります。
2135-+ * 生成直後のオブジェクトはデータを持ちません。
2136-+ * メンバ関数はsetBufferを実行後に使用可能になります。
2137-+ */
2138-+ public JmfNyARRaster_RGB(int i_width,int i_height)
2139-+ {
2140-+ ref_buf=null;
2141-+ width=i_width;
2142-+ height=i_height;
2143-+ }
2144-+ /**
2145-+ * フォーマットを解析して、インスタンスのフォーマットプロパティを初期化します。
2146-+ *
2147-+ * @param i_buffer
2148-+ * @throws NyARException
2149-+ */
2150-+ protected void initFormatProperty(RGBFormat i_fmt) throws NyARException
2151-+ {
2152-+ //データサイズの確認
2153-+ Dimension s=i_fmt.getSize();
2154-+ if(width!=s.width || height !=s.height){
2155-+ throw new NyARException();
2156-+ }
2157-+ //データ配列の確認
2158-+ red_idx =i_fmt.getRedMask()-1;
2159-+ green_idx=i_fmt.getGreenMask()-1;
2160-+ blue_idx =i_fmt.getBlueMask()-1;
2161-+
2162-+ //色配列の特定
2163-+ if(red_idx==0 && blue_idx==2){
2164-+ pix_type=PIXEL_ORDER_RGB;
2165-+ }else if(red_idx==2 && blue_idx==0){
2166-+ pix_type=PIXEL_ORDER_BGR;
2167-+ }else{
2168-+ throw new NyARException("Unknown pixel order.");
2169-+ }
2170-+ }
2171-+ /**
2172-+ * javax.media.Bufferを分析して、その分析結果をNyARRasterに適合する形で保持します。
2173-+ * 関数実行後に外部でi_bufferの内容変更した場合には、再度setBuffer関数を呼び出してください。
2174-+ * @param i_buffer
2175-+ * RGB形式のデータを格納したjavax.media.Bufferオブジェクトを指定してください。
2176-+ * @return
2177-+ * i_bufferをラップしたオブジェクトを返します。
2178-+ * @throws NyARException
2179-+ */
2180-+ public void setBuffer(javax.media.Buffer i_buffer) throws NyARException
2181-+ {
2182-+ initFormatProperty((RGBFormat)i_buffer.getFormat());
2183-+ ref_buf=(byte[])i_buffer.getData();
2184-+ }
2185-+ public int getPixelTotal(int i_x,int i_y)
2186-+ {
2187-+ int bp=(i_x+i_y*width)*3;
2188-+ return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);
2189-+ }
2190-+ public int getWidth()
2191-+ {
2192-+ return width;
2193-+ }
2194-+ public int getHeight()
2195-+ {
2196-+ return height;
2197-+ }
2198-+ public void pickRgbArray(int i_x,int i_y,int[] i_rgb)
2199-+ {
2200-+ int bp=(i_x+i_y*width)*3;
2201-+ i_rgb[0]=(ref_buf[bp+red_idx] & 0xff);//R
2202-+ i_rgb[1]=(ref_buf[bp+green_idx] & 0xff);//G
2203-+ i_rgb[2]=(ref_buf[bp+blue_idx] & 0xff);//B
2204-+ }
2205-+ /**
2206-+ * ピクセルの順序タイプを返します。
2207-+ * @return
2208-+ * その値
2209-+ */
2210-+ public int getPixelOrder()
2211-+ {
2212-+ return pix_type;
2213-+ }
2214-+ /**
2215-+ * データを持っているかを返します。
2216-+ * @return
2217-+ */
2218-+ public boolean hasData()
2219-+ {
2220-+ return ref_buf!=null;
2221-+ }
2222-+
2223-+}
2224-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java
2225-===================================================================
2226---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java (revision 0)
2227-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java (revision 178)
2228-@@ -0,0 +1,136 @@
2229-+/*
2230-+ * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
2231-+ *
2232-+ * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
2233-+ * modify and redistribute this software in source and binary code form,
2234-+ * provided that i) this copyright notice and license appear on all copies of
2235-+ * the software; and ii) Licensee does not utilize the software in a manner
2236-+ * which is disparaging to Sun.
2237-+ *
2238-+ * This software is provided "AS IS," without a warranty of any kind. ALL
2239-+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
2240-+ * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
2241-+ * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
2242-+ * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
2243-+ * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
2244-+ * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
2245-+ * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
2246-+ * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
2247-+ * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
2248-+ * POSSIBILITY OF SUCH DAMAGES.
2249-+ *
2250-+ * This software is not designed or intended for use in on-line control of
2251-+ * aircraft, air traffic, aircraft navigation or aircraft communications; or in
2252-+ * the design, construction, operation or maintenance of any nuclear
2253-+ * facility. Licensee represents and warrants that it will not use or
2254-+ * redistribute the Software for such purposes.
2255-+ */
2256-+package jp.nyatla.nyartoolkit.jmf.utils;
2257-+
2258-+
2259-+import javax.media.*;
2260-+import javax.media.protocol.*;
2261-+import javax.media.control.*;
2262-+
2263-+import java.io.IOException;
2264-+
2265-+
2266-+
2267-+public class MonitorCDS extends PushBufferDataSource{
2268-+
2269-+ private PushBufferDataSource delegate = null;
2270-+ private PushBufferStream [] delStreams = null;
2271-+ private MonitorStream monitorStream = null;
2272-+ private PushBufferStream [] monitorStreams = null;
2273-+ boolean delStarted = false; // variable used by MonitorStream also
2274-+ private Control [] controls;
2275-+
2276-+ public MonitorCDS(DataSource ds)
2277-+ {
2278-+ // Get the stream from the actual datasource
2279-+ // and create a MonitorStream from it
2280-+ // Export the MonitorControl interface of the MonitorStream
2281-+ if (ds instanceof PushBufferDataSource)
2282-+ {
2283-+ delegate = (PushBufferDataSource) ds;
2284-+ delStreams = delegate.getStreams();
2285-+ monitorStream = new MonitorStream(delStreams[0], this);
2286-+ monitorStreams = new PushBufferStream[] {monitorStream};
2287-+ }
2288-+ }
2289-+
2290-+ public Object [] getControls()
2291-+ {
2292-+ return controls;
2293-+ }
2294-+
2295-+ public Object getControl(String value) {
2296-+ if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl"))
2297-+ return monitorStream;
2298-+ else
2299-+ return null;
2300-+ }
2301-+
2302-+ public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
2303-+ {
2304-+ return ((CaptureDevice)delegate).getCaptureDeviceInfo();
2305-+ }
2306-+
2307-+ public FormatControl[] getFormatControls()
2308-+ {
2309-+ return ((CaptureDevice)delegate).getFormatControls();
2310-+ }
2311-+
2312-+ public String getContentType()
2313-+ {
2314-+ return delegate.getContentType();
2315-+ }
2316-+
2317-+ public void connect() throws IOException
2318-+ {
2319-+ if (delegate == null)
2320-+ throw new IOException("Incompatible DataSource");
2321-+ // Delegate is already connected
2322-+ }
2323-+
2324-+ public void disconnect()
2325-+ {
2326-+ monitorStream.setEnabled(false);
2327-+ delegate.disconnect();
2328-+ }
2329-+
2330-+ public synchronized void start() throws IOException
2331-+ {
2332-+ startDelegate();
2333-+ delStarted = true;
2334-+ }
2335-+
2336-+ public synchronized void stop() throws IOException
2337-+ {
2338-+ if (!monitorStream.isEnabled()) {
2339-+ stopDelegate();
2340-+ }
2341-+ delStarted = false;
2342-+ }
2343-+
2344-+ public Time getDuration()
2345-+ {
2346-+ return delegate.getDuration();
2347-+ }
2348-+
2349-+ public PushBufferStream [] getStreams()
2350-+ {
2351-+ return monitorStreams;
2352-+ }
2353-+
2354-+ void startDelegate() throws IOException
2355-+ {
2356-+ delegate.start();
2357-+ }
2358-+
2359-+ void stopDelegate() throws IOException
2360-+ {
2361-+ delegate.stop();
2362-+ }
2363-+
2364-+}
2365-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java
2366-===================================================================
2367---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java (revision 0)
2368-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java (revision 178)
2369-@@ -0,0 +1,196 @@
2370-+/*
2371-+ * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
2372-+ *
2373-+ * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
2374-+ * modify and redistribute this software in source and binary code form,
2375-+ * provided that i) this copyright notice and license appear on all copies of
2376-+ * the software; and ii) Licensee does not utilize the software in a manner
2377-+ * which is disparaging to Sun.
2378-+ *
2379-+ * This software is provided "AS IS," without a warranty of any kind. ALL
2380-+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
2381-+ * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
2382-+ * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
2383-+ * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
2384-+ * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
2385-+ * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
2386-+ * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
2387-+ * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
2388-+ * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
2389-+ * POSSIBILITY OF SUCH DAMAGES.
2390-+ *
2391-+ * This software is not designed or intended for use in on-line control of
2392-+ * aircraft, air traffic, aircraft navigation or aircraft communications; or in
2393-+ * the design, construction, operation or maintenance of any nuclear
2394-+ * facility. Licensee represents and warrants that it will not use or
2395-+ * redistribute the Software for such purposes.
2396-+ */
2397-+package jp.nyatla.nyartoolkit.jmf.utils;
2398-+
2399-+
2400-+
2401-+import javax.media.*;
2402-+import javax.media.protocol.*;
2403-+
2404-+import javax.media.util.BufferToImage;
2405-+import java.io.IOException;
2406-+import java.awt.*;
2407-+
2408-+public class MonitorStream implements PushBufferStream, BufferTransferHandler {
2409-+
2410-+ JmfCaptureListener img_listener;
2411-+ PushBufferStream actual = null;
2412-+ boolean dataAvailable = false;
2413-+ boolean terminate = false;
2414-+ boolean enabled = false;
2415-+ Object bufferLock = new Object();
2416-+ Buffer cbuffer = new Buffer();
2417-+ BufferTransferHandler transferHandler = null;
2418-+ Component component = null;
2419-+ MonitorCDS cds;
2420-+ BufferToImage bti = null;
2421-+
2422-+ MonitorStream(PushBufferStream actual, MonitorCDS cds) {
2423-+ this.actual = actual;
2424-+ actual.setTransferHandler(this);
2425-+ this.cds = cds;
2426-+ }
2427-+
2428-+ public javax.media.Format getFormat()
2429-+ {
2430-+ return actual.getFormat();
2431-+ }
2432-+ /**
2433-+ * 非同期READ
2434-+ */
2435-+ public void read(Buffer buffer) throws IOException
2436-+ {
2437-+ // Wait for data to be available
2438-+ // Doesn't get used much because the transferData
2439-+ // call is made when data IS available. And most
2440-+ // Processors/Players read the data in the same
2441-+ // thread that called transferData, although that's
2442-+ // not a safe assumption to make
2443-+ if (!dataAvailable) {
2444-+ synchronized (bufferLock) {
2445-+ while (!dataAvailable && !terminate) {
2446-+ try {
2447-+ bufferLock.wait(100);
2448-+ } catch (InterruptedException ie) {
2449-+ }
2450-+ }
2451-+ }
2452-+ }
2453-+
2454-+ if (dataAvailable) {
2455-+ synchronized (bufferLock) {
2456-+ // Copy the buffer attributes, but swap the data
2457-+ // attributes so that no extra copy is made.
2458-+ buffer.copy(cbuffer, true);
2459-+ //dataAvailable = false;
2460-+ }
2461-+ }
2462-+// return;
2463-+ }
2464-+ public void setCaptureListener(JmfCaptureListener i_listener)
2465-+ {
2466-+ img_listener=i_listener;
2467-+ }
2468-+
2469-+ public void transferData(PushBufferStream pbs)
2470-+ {
2471-+ // Get the data from the original source stream
2472-+ synchronized (bufferLock) {
2473-+ try {
2474-+ pbs.read(cbuffer);
2475-+ } catch (IOException ioe) {
2476-+ return;
2477-+ }
2478-+ dataAvailable = true;
2479-+ bufferLock.notifyAll();
2480-+ }
2481-+ if(img_listener!=null){
2482-+ img_listener.onUpdateBuffer(cbuffer);
2483-+ }
2484-+
2485-+/*
2486-+ // Display data if monitor is active
2487-+ if (isEnabled()) {
2488-+ if (bti == null) {
2489-+ VideoFormat vf = (VideoFormat) cbuffer.getFormat();
2490-+ bti = new BufferToImage(vf);
2491-+ }
2492-+ if (bti != null && component != null) {
2493-+ Image im = bti.createImage(cbuffer);
2494-+ Graphics g = component.getGraphics();
2495-+ Dimension size = component.getSize();
2496-+ if (g != null)
2497-+ g.drawImage(im, 0, 0, component);
2498-+ }
2499-+ }
2500-+*/
2501-+ // Maybe synchronize this with setTransferHandler() ?
2502-+ if (transferHandler != null && cds.delStarted)
2503-+ transferHandler.transferData(this);
2504-+ }
2505-+
2506-+ public void setTransferHandler(BufferTransferHandler transferHandler) {
2507-+ this.transferHandler = transferHandler;
2508-+ }
2509-+
2510-+ public boolean setEnabled(boolean value) {
2511-+ enabled = value;
2512-+ if (value == false) {
2513-+ if (!cds.delStarted) {
2514-+ try {
2515-+ cds.stopDelegate();
2516-+ } catch (IOException ioe) {
2517-+ }
2518-+ }
2519-+ } else {
2520-+ // Start the capture datasource if the monitor is enabled
2521-+ try {
2522-+ cds.startDelegate();
2523-+ }catch (IOException ioe) {
2524-+ }
2525-+ }
2526-+ return enabled;
2527-+ }
2528-+
2529-+ public boolean isEnabled()
2530-+ {
2531-+ return enabled;
2532-+ }
2533-+
2534-+
2535-+
2536-+ public float setPreviewFrameRate(float rate)
2537-+ {
2538-+ System.err.println("TODO");
2539-+ return rate;
2540-+ }
2541-+
2542-+ public ContentDescriptor getContentDescriptor()
2543-+ {
2544-+ return actual.getContentDescriptor();
2545-+ }
2546-+
2547-+ public long getContentLength()
2548-+ {
2549-+ return actual.getContentLength();
2550-+ }
2551-+
2552-+ public boolean endOfStream() {
2553-+ return actual.endOfStream();
2554-+ }
2555-+
2556-+ public Object [] getControls() {
2557-+ return new Object[0];
2558-+ }
2559-+
2560-+ public Object getControl(String str) {
2561-+ return null;
2562-+ }
2563-+
2564-+
2565-+}
2566-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java
2567-===================================================================
2568---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java (revision 0)
2569-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java (revision 178)
2570-@@ -0,0 +1,14 @@
2571-+/**
2572-+ * JMFお手軽キャプチャ用リスナ
2573-+ * (c)2008 A虎@nyatla.jp
2574-+ * airmail@ebony.plala.or.jp
2575-+ * http://nyatla.jp/
2576-+ */
2577-+package jp.nyatla.nyartoolkit.jmf.utils;
2578-+
2579-+import javax.media.Buffer;
2580-+
2581-+public interface JmfCaptureListener{
2582-+ public void onUpdateBuffer(Buffer i_buffer);
2583-+
2584-+}
2585-\ No newline at end of file
2586-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java
2587-===================================================================
2588---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java (revision 0)
2589-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java (revision 178)
2590-@@ -0,0 +1,180 @@
2591-+/**
2592-+ * JMFお手軽キャプチャクラス
2593-+ * (c)2008 A虎@nyatla.jp
2594-+ * airmail@ebony.plala.or.jp
2595-+ * http://nyatla.jp/
2596-+ */
2597-+package jp.nyatla.nyartoolkit.jmf.utils;
2598-+
2599-+
2600-+
2601-+import javax.media.*;
2602-+import javax.media.protocol.*;
2603-+import javax.media.control.*;
2604-+import javax.media.format.*;
2605-+import java.awt.*;
2606-+import java.util.*;
2607-+import javax.media.protocol.DataSource;
2608-+
2609-+import jp.nyatla.nyartoolkit.NyARException;
2610-+
2611-+
2612-+
2613-+
2614-+
2615-+public class JmfCameraCapture
2616-+{
2617-+ private Dimension image_size;
2618-+ private JmfCaptureListener capture_listener;
2619-+ private DataSource jmf_data_source;
2620-+ private MonitorStream jmf_monitor_stream;
2621-+ private Processor jmf_processor;
2622-+ private VideoFormat jmf_video_format;
2623-+
2624-+ private Buffer read_buf=new Buffer();
2625-+ public static final String PIXEL_FORMAT_RGB="RGB";
2626-+ public JmfCameraCapture(int i_width,int i_height,float i_rate,String i_pixcel_format)
2627-+ {
2628-+ String encoding = i_pixcel_format;//comboEncoding.getSelectedItem();
2629-+ image_size = new Dimension(i_width,i_height);
2630-+ jmf_video_format = new VideoFormat(encoding, image_size, Format.NOT_SPECIFIED,null,i_rate);
2631-+ }
2632-+ public Dimension getSize()
2633-+ {
2634-+ return image_size;
2635-+ }
2636-+ public javax.media.Buffer readBuffer() throws NyARException
2637-+ {
2638-+ if(jmf_monitor_stream==null){
2639-+ throw new NyARException();
2640-+ }
2641-+ try{
2642-+ jmf_monitor_stream.read(read_buf);
2643-+ }catch(Exception e){
2644-+ throw new NyARException(e);
2645-+ }
2646-+ return read_buf;
2647-+ }
2648-+ public void setCaptureListener(JmfCaptureListener i_listener) throws NyARException
2649-+ {
2650-+ if(jmf_processor!=null){
2651-+ throw new NyARException();
2652-+ }
2653-+ capture_listener=i_listener;
2654-+
2655-+ }
2656-+ public void start() throws NyARException
2657-+ {
2658-+
2659-+ DataSource ds=getCaptureDS(jmf_video_format);
2660-+ VideoFormat[] formats=new VideoFormat[]{new VideoFormat(null)};
2661-+ ProcessorModel pm = new ProcessorModel(ds,formats,null);//, formats, ftd);
2662-+ Processor processor;
2663-+ try {
2664-+ processor = Manager.createRealizedProcessor(pm);
2665-+ } catch (Exception e){
2666-+ // Make sure the capture devices are released
2667-+ ds.disconnect();
2668-+ throw new NyARException(e);
2669-+ }
2670-+ // Get the monitor control:
2671-+ // Since there are more than one MonitorControl objects
2672-+ // exported by the DataSource, we get the specific one
2673-+ // that is also the MonitorStream object.
2674-+ jmf_monitor_stream=(MonitorStream)ds.getControl("jmfsample.MonitorStream");
2675-+ jmf_monitor_stream.setCaptureListener(capture_listener);
2676-+ jmf_data_source=ds;
2677-+ jmf_processor=processor;
2678-+ jmf_processor.start();
2679-+ }
2680-+ public void stop()
2681-+ {
2682-+ jmf_processor.stop();
2683-+ jmf_processor.close();
2684-+ jmf_processor = null;
2685-+
2686-+ }
2687-+ protected void finalize()
2688-+ {
2689-+ if(jmf_processor!=null){
2690-+ jmf_processor.stop();
2691-+ jmf_processor.close();
2692-+ jmf_processor = null;
2693-+ }
2694-+ }
2695-+ private static DataSource getCaptureDS(VideoFormat vf) {
2696-+ DataSource dsVideo = null;
2697-+ DataSource ds = null;
2698-+
2699-+ // Create a capture DataSource for the video
2700-+ // If there is no video capture device, then exit with null
2701-+ if (vf != null) {
2702-+ dsVideo = createDataSource(vf);
2703-+ if (dsVideo == null)
2704-+ return null;
2705-+ }
2706-+
2707-+
2708-+ // Create the monitoring datasource wrapper
2709-+ if (dsVideo != null) {
2710-+ dsVideo = new MonitorCDS(dsVideo);
2711-+ return dsVideo;
2712-+ }
2713-+
2714-+ // Merge the data sources, if both audio and video are available
2715-+ try {
2716-+ ds = Manager.createMergingDataSource(new DataSource[]{dsVideo});
2717-+ } catch (IncompatibleSourceException ise){
2718-+ return null;
2719-+ }
2720-+
2721-+ return ds;
2722-+ }
2723-+
2724-+ private static DataSource createDataSource(Format format) {
2725-+ DataSource ds;
2726-+ Vector devices;
2727-+ CaptureDeviceInfo cdi;
2728-+ MediaLocator ml;
2729-+
2730-+ // Find devices for format
2731-+ devices = CaptureDeviceManager.getDeviceList(format);
2732-+ if (devices.size() < 1) {
2733-+ System.err.println("! No Devices for " + format);
2734-+ return null;
2735-+ }
2736-+ // Pick the first device
2737-+ cdi = (CaptureDeviceInfo) devices.elementAt(0);
2738-+
2739-+ ml = cdi.getLocator();
2740-+
2741-+ try {
2742-+ ds = Manager.createDataSource(ml);
2743-+ ds.connect();
2744-+ if (ds instanceof CaptureDevice)
2745-+ {
2746-+ setCaptureFormat((CaptureDevice) ds, format);
2747-+ }
2748-+ } catch (Exception e) {
2749-+ System.err.println(e);
2750-+ return null;
2751-+ }
2752-+ return ds;
2753-+ }
2754-+
2755-+ private static void setCaptureFormat(CaptureDevice cdev, Format format) {
2756-+ FormatControl [] fcs = cdev.getFormatControls();
2757-+ if (fcs.length < 1){
2758-+ return;
2759-+ }
2760-+ FormatControl fc = fcs[0];
2761-+ Format [] formats = fc.getSupportedFormats();
2762-+ for (int i = 0; i < formats.length; i++) {
2763-+ if (formats[i].matches(format)){
2764-+ format = formats[i].intersects(format);
2765-+ fc.setFormat(format);
2766-+ break;
2767-+ }
2768-+ }
2769-+ }
2770-+}
2771-\ No newline at end of file
2772-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/JmfCaptureTest.java
2773-===================================================================
2774---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/JmfCaptureTest.java (revision 0)
2775-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/JmfCaptureTest.java (revision 178)
2776-@@ -0,0 +1,58 @@
2777-+/**
2778-+ * VFMキャプチャテストプログラム
2779-+ * (c)2008 A虎@nyatla.jp
2780-+ * airmail@ebony.plala.or.jp
2781-+ * http://nyatla.jp/
2782-+ */
2783-+package jp.nyatla.nyartoolkit.jmf.sample;
2784-+
2785-+import javax.media.*;
2786-+
2787-+import javax.media.util.BufferToImage;
2788-+import javax.media.format.*;
2789-+import jp.nyatla.nyartoolkit.NyARException;
2790-+import jp.nyatla.nyartoolkit.jmf.utils.*;
2791-+
2792-+import java.awt.*;
2793-+
2794-+
2795-+
2796-+public class JmfCaptureTest extends Frame implements JmfCaptureListener{
2797-+ public JmfCaptureTest() throws NyARException
2798-+ {
2799-+ setTitle("JmfCaptureTest");
2800-+ setBounds(0,0,320+64,240+64);
2801-+ capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
2802-+ capture.setCaptureListener(this);
2803-+ }
2804-+
2805-+
2806-+
2807-+ private JmfCameraCapture capture;
2808-+ public void onUpdateBuffer(Buffer i_buffer)
2809-+ {
2810-+ BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
2811-+ Image img=b2i.createImage(i_buffer);
2812-+ Graphics g = getGraphics();
2813-+ g.drawImage(img, 32, 32,this);
2814-+ }
2815-+ private void startCapture()
2816-+ {
2817-+ try{
2818-+ capture.start();
2819-+ }catch(Exception e){
2820-+ e.printStackTrace();
2821-+ }
2822-+ }
2823-+ public static void main(String[] args) {
2824-+ try{
2825-+ JmfCaptureTest mainwin = new JmfCaptureTest();
2826-+ mainwin.setVisible(true);
2827-+ mainwin.startCapture();
2828-+ }catch(Exception e){
2829-+ e.printStackTrace();
2830-+ }
2831-+
2832-+ }
2833-+
2834-+}
2835-Index: D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java
2836-===================================================================
2837---- D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (revision 0)
2838-+++ D:/project.files/java.Lab/NyARToolKit/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java (revision 178)
2839-@@ -0,0 +1,116 @@
2840-+/**
2841-+ * VFM+ARToolkitテストプログラム
2842-+ * カメラから取り込んだデータからマーカーを検出して、一致度と変換行列を表示します。
2843-+ * (c)2008 A虎@nyatla.jp
2844-+ * airmail(at)ebony.plala.or.jp
2845-+ * http://nyatla.jp/
2846-+ */
2847-+package jp.nyatla.nyartoolkit.jmf.sample;
2848-+
2849-+import javax.media.*;
2850-+
2851-+import javax.media.util.BufferToImage;
2852-+import javax.media.format.*;
2853-+
2854-+import jp.nyatla.nyartoolkit.NyARException;
2855-+import jp.nyatla.nyartoolkit.jmf.utils.*;
2856-+
2857-+import java.awt.*;
2858-+
2859-+import jp.nyatla.nyartoolkit.core.*;
2860-+import jp.nyatla.nyartoolkit.detector.*;
2861-+
2862-+
2863-+
2864-+
2865-+
2866-+
2867-+public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
2868-+{
2869-+ private final String CARCODE_FILE ="../../Data/patt.hiro";
2870-+ private final String PARAM_FILE ="../../Data/camera_para.dat";
2871-+ private JmfCameraCapture capture;
2872-+ NyARSingleDetectMarker nya;
2873-+ JmfNyARRaster_RGB raster;
2874-+
2875-+ public NyarToolkitLinkTest() throws NyARException,NyARException
2876-+ {
2877-+ setTitle("JmfCaptureTest");
2878-+ setBounds(0,0,320+64,240+64);
2879-+ //キャプチャの準備
2880-+ capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
2881-+ capture.setCaptureListener(this);
2882-+
2883-+ //NyARToolkitの準備
2884-+ NyARParam ar_param=new NyARParam();
2885-+ NyARCode ar_code =new NyARCode(16,16);
2886-+ ar_param.loadFromARFile(PARAM_FILE);
2887-+ ar_param.changeSize(320,240);
2888-+ nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);
2889-+ ar_code.loadFromARFile(CARCODE_FILE);
2890-+ //キャプチャイメージ用のラスタを準備
2891-+ raster=new JmfNyARRaster_RGB(320,240);
2892-+ }
2893-+
2894-+
2895-+
2896-+ public void onUpdateBuffer(Buffer i_buffer)
2897-+ {
2898-+ try{
2899-+ //キャプチャしたバッファをラスタにセット
2900-+ raster.setBuffer(i_buffer);
2901-+
2902-+ //キャプチャしたイメージを表示用に加工
2903-+ BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
2904-+ Image img=b2i.createImage(i_buffer);
2905-+
2906-+ Graphics g = getGraphics();
2907-+ double[][] atm=null;
2908-+
2909-+ //マーカー検出
2910-+ boolean is_marker_exist=nya.detectMarkerLite(raster,100);
2911-+ if(is_marker_exist){
2912-+ //変換行列を取得
2913-+ atm=nya.getTransmationMatrix().getArray();
2914-+ }
2915-+ //情報を画面に書く
2916-+ g.drawImage(img, 32, 32,this);
2917-+ if(is_marker_exist){
2918-+ g.drawString("マーカー検出:"+nya.getConfidence(),32,50);
2919-+ for(int i=0;i<3;i++){
2920-+ for(int i2=0;i2<4;i2++){
2921-+ g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);
2922-+ }
2923-+
2924-+ }
2925-+ }else{
2926-+ g.drawString("マーカー未検出:",32,100);
2927-+ }
2928-+ }catch(Exception e){
2929-+ e.printStackTrace();
2930-+ }
2931-+
2932-+
2933-+
2934-+
2935-+ }
2936-+ private void startCapture()
2937-+ {
2938-+ try{
2939-+ capture.start();
2940-+ }catch(Exception e){
2941-+ e.printStackTrace();
2942-+ }
2943-+ }
2944-+ public static void main(String[] args) {
2945-+ try{
2946-+ NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();
2947-+ mainwin.setVisible(true);
2948-+ mainwin.startCapture();
2949-+ }catch(Exception e){
2950-+ e.printStackTrace();
2951-+ }
2952-+
2953-+ }
2954-+
2955-+}
2956--2008.03.29 R.Iizuka nyatla.jp
2957-+2008.03.29 R.Iizuka A虎@nyatla.jp
2958-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARCode.java
2959-===================================================================
2960---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARCode.java (revision 174)
2961-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARCode.java (revision 178)
2962-@@ -33,6 +33,7 @@
2963- package jp.nyatla.nyartoolkit.core;
2964-
2965- import java.io.FileInputStream;
2966-+import java.io.InputStream;
2967- import java.io.InputStreamReader;
2968- import java.io.StreamTokenizer;
2969-
2970-@@ -84,19 +85,32 @@
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];
2972- patBW=new short[4][height][width];//static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
2973- }
2974--
2975--
2976- /**
2977- * int arLoadPatt( const char *filename );
2978- * ARToolKitのパターンファイルをロードする。
2979-+ * ファイル形式はBGR形式で記録されたパターンファイルであること。
2980- * @param filename
2981- * @return
2982- * @throws Exception
2983- */
2984- public void loadFromARFile(String filename) throws NyARException
2985- {
2986-+ try {
2987-+ loadFromARFile(new FileInputStream(filename));
2988-+
2989-+ } catch (Exception e) {
2990-+ throw new NyARException(e);
2991-+ }
2992-+ }
2993-+ /**
2994-+ *
2995-+ * @param i_stream
2996-+ * @throws NyARException
2997-+ */
2998-+ public void loadFromARFile(InputStream i_stream) throws NyARException
2999-+ {
3000- try{
3001-- StreamTokenizer st=new StreamTokenizer(new InputStreamReader(new FileInputStream(filename)));
3002-+ StreamTokenizer st=new StreamTokenizer(new InputStreamReader(i_stream));
3003- //パターンデータはGBRAで並んでる。
3004- for(int h=0; h<4; h++ ) {
3005- int l = 0;
3006-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARParam.java
3007-===================================================================
3008---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARParam.java (revision 174)
3009-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/NyARParam.java (revision 178)
3010-@@ -72,18 +72,25 @@
3011- */
3012- public void loadFromARFile(String i_filename) throws NyARException
3013- {
3014-- try{
3015-- FileInputStream fs=new FileInputStream(i_filename);
3016-- NyARParam new_inst[]=arParamLoad(fs,1);
3017-- fs.close();
3018-- xsize =new_inst[0].xsize;
3019-- ysize =new_inst[0].ysize;
3020-- mat =new_inst[0].mat;
3021-- dist_factor=new_inst[0].dist_factor;
3022-- }catch(Exception e){
3023-- throw new NyARException(e);
3024-- }
3025-+ try {
3026-+ loadFromARFile(new FileInputStream(i_filename));
3027-+ } catch (Exception e) {
3028-+ throw new NyARException(e);
3029-+ }
3030- }
3031-+ public void loadFromARFile(InputStream i_stream) throws NyARException
3032-+ {
3033-+ try {
3034-+ NyARParam new_inst[] = arParamLoad(i_stream, 1);
3035-+ i_stream.close();
3036-+ xsize = new_inst[0].xsize;
3037-+ ysize = new_inst[0].ysize;
3038-+ mat = new_inst[0].mat;
3039-+ dist_factor = new_inst[0].dist_factor;
3040-+ } catch (Exception e) {
3041-+ throw new NyARException(e);
3042-+ }
3043-+ }
3044- /*static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )*/
3045- private static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )
3046- {
3047-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt.java
3048-===================================================================
3049---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt.java (revision 174)
3050-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt.java (revision 178)
3051-@@ -49,7 +49,7 @@
3052- public double getConfidence();
3053- public int getDirection();
3054- public void evaluate(NyARCode i_code);
3055-- public void setPatt(NyARColorPatt i_target_patt) throws NyARException;
3056-+ public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException;
3057- }
3058-
3059-
3060-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java
3061-===================================================================
3062---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java (revision 174)
3063-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java (revision 178)
3064-@@ -54,7 +54,7 @@
3065- public int getDirection(){
3066- return dir;
3067- }
3068-- public void setPatt(NyARColorPatt i_target_patt) throws NyARException
3069-+ public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException
3070- {
3071- width=i_target_patt.getWidth();
3072- height=i_target_patt.getHeight();
3073-@@ -81,11 +81,12 @@
3074- }
3075- datapow = Math.sqrt( (double)sum );
3076- if(datapow == 0.0){
3077-- throw new NyARException();
3078-+ return false;// throw new NyARException();
3079- // dir.set(0);//*dir = 0;
3080- // cf.set(-1.0);//*cf = -1.0;
3081- // return -1;
3082-- }
3083-+ }
3084-+ return true;
3085- }
3086- /**
3087- * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer cf)
3088-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java
3089-===================================================================
3090---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java (revision 174)
3091-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java (revision 178)
3092-@@ -59,7 +59,7 @@
3093- public int getDirection(){
3094- return dir;
3095- }
3096-- public void setPatt(NyARColorPatt i_target_patt) throws NyARException
3097-+ public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException
3098- {
3099- width=i_target_patt.getWidth();
3100- height=i_target_patt.getHeight();
3101-@@ -87,11 +87,12 @@
3102- }
3103- datapow = Math.sqrt( (double)sum );
3104- if(datapow == 0.0){
3105-- throw new NyARException();
3106-+ return false;//throw new NyARException();
3107- // dir.set(0);//*dir = 0;
3108- // cf.set(-1.0);//*cf = -1.0;
3109- // return -1;
3110-- }
3111-+ }
3112-+ return true;
3113- }
3114- /**
3115- * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer cf)
3116-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java
3117-===================================================================
3118---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java (revision 174)
3119-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java (revision 178)
3120-@@ -47,7 +47,7 @@
3121- private int dir=0;
3122- private int ave;
3123- private int[][][] input=new int[height][width][3];
3124-- public void setPatt(NyARColorPatt i_target_patt) throws NyARException
3125-+ public boolean setPatt(NyARColorPatt i_target_patt) throws NyARException
3126- {
3127- width=i_target_patt.getWidth();
3128- height=i_target_patt.getHeight();
3129-@@ -71,11 +71,12 @@
3130-
3131- datapow = Math.sqrt( (double)sum );
3132- if( datapow == 0.0 ){
3133-- throw new NyARException();
3134-+ return false;// throw new NyARException();
3135- // dir.set(0);//*dir = 0;
3136- // cf.set(-1.0);//*cf = -1.0;
3137- // return -1;
3138- }
3139-+ return true;
3140- }
3141- public double getConfidence()
3142- {
3143-Index: D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java
3144-===================================================================
3145---- D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (revision 174)
3146-+++ D:/project.files/java.Lab/NyARToolKit/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (revision 178)
3147-@@ -91,7 +91,10 @@
3148- //パターンの評価オブジェクトを作る。
3149- NyARMatchPatt_Color_WITHOUT_PCA eva=new NyARMatchPatt_Color_WITHOUT_PCA();
3150- //パターンを評価器にセット
3151-- eva.setPatt(patt);
3152-+ if(!eva.setPatt(patt)){
3153-+ //計算に失敗した。
3154-+ return false;
3155-+ }
3156- //コードと比較する
3157- eva.evaluate(code);
3158- int square_index=0;
--- a/trunk/readme.ja.txt
+++ b/trunk/readme.ja.txt
@@ -1,7 +1,7 @@
11 ARToolkit Java class library NyARToolkit.
22 Copyright (C)2008 R.Iizuka
33
4-version Alpha 0.8.20080412.0
4+version 1.0.0.20080428.0
55
66 http://nyatla.jp/
77 airmail(at)ebony.plala.or.jp
@@ -112,7 +112,9 @@ sampleディレクトリ以下にあるソースはAPIは仕様が固まって
112112 クラスは関数機能毎にまとめた作りになっていますので、オリジナルの
113113 コード読んだことがあれば、なんとなく判ると思います。
114114
115-
115+演算性能は、Windows環境下でVCリリース版の約85%です。
116+マーカー認識部分はネイティブ版よりも低速ですが、変換行列計算部分
117+はネイティブ版よりも高速に動作します。
116118
117119
118120 ・足りない機能等
@@ -140,4 +142,4 @@ NyARToolkitを使って面白いものが出来たら、是非教えてくださ
140142
141143 ではでは、楽しく遊んでくださいネ。
142144
143-2008.03.29 R.Iizuka A虎@nyatla.jp
145+2008.04.28 R.Iizuka A虎@nyatla.jp
--- a/trunk/sample/java3d/.classpath
+++ b/trunk/sample/java3d/.classpath
@@ -2,10 +2,10 @@
22 <classpath>
33 <classpathentry path="src" kind="src"/>
44 <classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
5- <classpathentry path="C:/Program Files/Java/Java3D/1.4.0_01/lib/ext/j3dcore.jar" kind="lib"/>
6- <classpathentry path="C:/Program Files/Java/Java3D/1.4.0_01/lib/ext/j3dutils.jar" kind="lib"/>
7- <classpathentry path="C:/Program Files/Java/Java3D/1.4.0_01/lib/ext/vecmath.jar" kind="lib"/>
85 <classpathentry path="C:/Program Files/JMF2.1.1e/lib/jmf.jar" kind="lib"/>
6+ <classpathentry path="C:/Program Files/Java/Java3D/1.5.1/lib/ext/j3dcore.jar" kind="lib"/>
7+ <classpathentry path="C:/Program Files/Java/Java3D/1.5.1/lib/ext/j3dutils.jar" kind="lib"/>
8+ <classpathentry path="C:/Program Files/Java/Java3D/1.5.1/lib/ext/vecmath.jar" kind="lib"/>
99 <classpathentry path="/NyARJMF" combineaccessrules="false" kind="src"/>
1010 <classpathentry path="/NyARToolkit" combineaccessrules="false" kind="src"/>
1111 <classpathentry path="bin" kind="output"/>
--- a/trunk/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java
+++ b/trunk/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/J3dNyARRaster_RGB.java
@@ -18,47 +18,59 @@ import jp.nyatla.nyartoolkit.NyARException;
1818 import jp.nyatla.nyartoolkit.core.NyARParam;
1919 import jp.nyatla.nyartoolkit.jmf.utils.*;
2020
21-
21+/**
22+ *
23+ * @author A虎@
24+ * このクラスは、Java3Dと互換性のあるNyARToolkitのラスタイメージを保持します。
25+ *
26+ */
2227 public class J3dNyARRaster_RGB extends JmfNyARRaster_RGB
2328 {
24-// public ImageUpdater updater;
2529 private ImageComponent2D imc2d;
2630 private byte[] i2d_buf;
31+ private BufferedImage bufferd_image;
2732
33+ /**
34+ * JMFのキャプチャ画像をこのクラスのBufferedImageにコピーします。
35+ * @param i_buffer
36+ * 画像の格納されたバッファを指定して下さい。
37+ * 画像サイズはコンストラクタで与えたパラメタと同じサイズである必要があります。
38+ */
2839 public void setBuffer(javax.media.Buffer i_buffer) throws NyARException
2940 {
3041 super.setBuffer(i_buffer);
3142 //メモ:この時点では、ref_dataにはi_bufferの参照値が入ってる。
32- synchronized(imc2d){
43+ synchronized(this){
3344 //キャプチャデータをi2dのバッファにコピーする。(これ省略したいなあ…。)
34- System.arraycopy(ref_buf,0,i2d_buf,0,this.i2d_buf.length);
45+ System.arraycopy(this.ref_buf,0,this.i2d_buf,0,this.i2d_buf.length);
3546 }
3647 //ここでref_bufの参照値をref_bufへ移動
37- ref_buf=i2d_buf;
48+ this.ref_buf=this.i2d_buf;
3849 }
3950 public J3dNyARRaster_RGB(NyARParam i_cparam)
4051 {
4152 super(i_cparam.getX(),i_cparam.getY());
4253
4354 //RGBのラスタを作る。
44-// ColorSpace cs=ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
45-// ComponentColorModel cm;
46-// cm=new ComponentColorModel(cs,new int[]{8,8,8},false,false,ComponentColorModel.OPAQUE,DataBuffer.TYPE_BYTE);
47-// java.awt.image.WritableRaster raster=cm.createCompatibleWritableRaster(width,height);
48-// i2d_buf=((DataBufferByte)raster.getDataBuffer()).getData();
49-// BufferedImage background_image = new BufferedImage(cm,raster, false, null);
50- BufferedImage background_image = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
51- i2d_buf=((DataBufferByte)background_image.getRaster().getDataBuffer()).getData();
52- //
53- imc2d= new ImageComponent2D(ImageComponent2D.FORMAT_RGB, background_image, true, true);
54- imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);
55+ this.bufferd_image = new BufferedImage(this.width,this.height,BufferedImage.TYPE_3BYTE_BGR);
56+ i2d_buf=((DataBufferByte)bufferd_image.getRaster().getDataBuffer()).getData();
57+ this.imc2d= new ImageComponent2D(ImageComponent2D.FORMAT_RGB, this.bufferd_image, true, true);
58+ imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);
5559 }
5660 /**
57- * このオブジェクトと連動するImageComponent2Dオブジェクトの参照値を得る。
58- * @return
61+ * 自身の格納しているImageComponent2Dオブジェクトを作り直します。
62+ * Java3D1.5がDirectXで動いた(らしいとき)に、ImageComponent2Dのインスタンス
63+ * IDが異ならないと、Behavior内でイメージの更新を通知できない事象に対応するために実装してあります。
64+ * Behavior内でgetImageComponent2()関数を実行する直前に呼び出すことで、この事象を回避することができます。
65+ *
5966 */
67+ public void renewImageComponent2D()
68+ {
69+ this.imc2d= new ImageComponent2D(ImageComponent2D.FORMAT_RGB, this.bufferd_image, true, true);
70+ this.imc2d.setCapability(ImageComponent.ALLOW_IMAGE_WRITE);
71+ }
6072 public ImageComponent2D getImageComponent2D()
6173 {
62- return imc2d;
74+ return this.imc2d;
6375 }
6476 }
--- a/trunk/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java
+++ b/trunk/sample/java3d/src/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java
@@ -147,7 +147,6 @@ class NyARBehavior extends Behavior
147147 listener=i_listener;
148148 }
149149 }
150-
151150 /**
152151 * いわゆるイベントハンドラ
153152 */
@@ -158,7 +157,8 @@ class NyARBehavior extends Behavior
158157 Transform3D t3d=null;
159158 boolean is_marker_exist=false;
160159 if(back_ground!=null){
161- back_ground.setImage(raster.getImageComponent2D());
160+ raster.renewImageComponent2D();/*DirectXモードのときの対策*/
161+ back_ground.setImage(raster.getImageComponent2D());
162162 }
163163 if(raster.hasData()){
164164 is_marker_exist=related_nya.detectMarkerLite(raster, 100);
--- a/trunk/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java
+++ b/trunk/sample/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java
@@ -81,8 +81,18 @@ public class JmfNyARRaster_RGB implements NyARRaster
8181 public int getPixelTotal(int i_x,int i_y)
8282 {
8383 int bp=(i_x+i_y*width)*3;
84- return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);
84+ byte[] ref=this.ref_buf;
85+ return (ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);
8586 }
87+ public void getPixelTotalRowLine(int i_row,int[] o_line)
88+ {
89+ final byte[] ref=this.ref_buf;
90+ int bp=(i_row+1)*this.width*3-3;
91+ for(int i=this.width-1;i>=0;i--){
92+ o_line[i]=(ref[bp] & 0xff)+(ref[bp+1] & 0xff)+(ref[bp+2] & 0xff);
93+ bp-=3;
94+ }
95+ }
8696 public int getWidth()
8797 {
8898 return width;
@@ -91,12 +101,13 @@ public class JmfNyARRaster_RGB implements NyARRaster
91101 {
92102 return height;
93103 }
94- public void pickRgbArray(int i_x,int i_y,int[] i_rgb)
104+ public void getPixel(int i_x,int i_y,int[] i_rgb)
95105 {
96- int bp=(i_x+i_y*width)*3;
97- i_rgb[0]=(ref_buf[bp+red_idx] & 0xff);//R
98- i_rgb[1]=(ref_buf[bp+green_idx] & 0xff);//G
99- i_rgb[2]=(ref_buf[bp+blue_idx] & 0xff);//B
106+ int bp=(i_x+i_y*this.width)*3;
107+ byte[] ref=this.ref_buf;
108+ i_rgb[0]=(ref[bp+this.red_idx] & 0xff);//R
109+ i_rgb[1]=(ref[bp+this.green_idx] & 0xff);//G
110+ i_rgb[2]=(ref[bp+this.blue_idx] & 0xff);//B
100111 }
101112 /**
102113 * ピクセルの順序タイプを返します。
@@ -115,5 +126,20 @@ public class JmfNyARRaster_RGB implements NyARRaster
115126 {
116127 return ref_buf!=null;
117128 }
118-
129+ public void getPixelSet(int[] i_x,int i_y[],int i_num,int[] o_rgb)
130+ {
131+ int ri=this.red_idx;
132+ int bi=this.green_idx;
133+ int gi=this.blue_idx;
134+ int width=this.width;
135+ byte[] ref=this.ref_buf;
136+ int bp;
137+ for(int i=i_num-1;i>=0;i--){
138+ bp=(i_x[i]+i_y[i]*width)*3;
139+ o_rgb[i*3+0]=(ref[bp+ri] & 0xff);//R
140+ o_rgb[i*3+1]=(ref[bp+gi] & 0xff);//G
141+ o_rgb[i*3+2]=(ref[bp+bi] & 0xff);//B
142+ }
143+ return;
144+ }
119145 }
--- a/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java
+++ b/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java
@@ -15,7 +15,7 @@ import jp.nyatla.nyartoolkit.detector.*;
1515 public class GLNyARSingleDetectMarker extends NyARSingleDetectMarker
1616 {
1717 private double view_scale_factor=0.025;//#define VIEW_SCALEFACTOR 0.025 // 1.0 ARToolKit unit becomes 0.025 of my OpenGL units.
18- public GLNyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width)
18+ public GLNyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width) throws NyARException
1919 {
2020 super(i_param,i_code,i_marker_width);
2121 }
--- a/trunk/src/jp/nyatla/nyartoolkit/base/Param.java
+++ b/trunk/src/jp/nyatla/nyartoolkit/base/Param.java
@@ -126,12 +126,12 @@ public class Param {
126126 NyARMat.matrixTrans(mat_at, mat_a );//if( arMatrixTrans( mat_at, mat_a ) < 0 ){
127127
128128 NyARException.trap("未チェックのパス");
129- NyARMat.matrixMul( mat_wm1, mat_at, mat_a );//if( arMatrixMul( mat_wm1, mat_at, mat_a ) < 0 ) {
129+ mat_wm1.matrixMul(mat_at, mat_a );//if( arMatrixMul( mat_wm1, mat_at, mat_a ) < 0 ) {
130130 NyARException.trap("未チェックのパス");
131131 mat_wm1.matrixSelfInv();//if( arMatrixSelfInv( mat_wm1 ) < 0 ) {
132132
133133 NyARException.trap("未チェックのパス");
134- NyARMat.matrixMul( mat_wm2, mat_wm1, mat_at );//if( arMatrixMul( mat_wm2, mat_wm1, mat_at ) < 0 ) {
134+ mat_wm2.matrixMul(mat_wm1, mat_at );//if( arMatrixMul( mat_wm2, mat_wm1, mat_at ) < 0 ) {
135135
136136 //mat_cpara.row = AR_PARAM_CDMIN-1;//mat_cpara.row = AR_PARAM_CDMIN-1;
137137 //mat_cpara.clm = 1;
@@ -140,7 +140,7 @@ public class Param {
140140 NyARMat mat_cpara=new NyARMat(arParamGet_AR_PARAM_CDMIN-1,1);
141141 double[][] mat_cpara_array=mat_cpara.getArray();
142142 NyARException.trap("未チェックのパス");
143- NyARMat.matrixMul(mat_cpara, mat_wm2, mat_r );//if( arMatrixMul( &mat_cpara, mat_wm2, mat_r ) < 0 ) {
143+ mat_cpara.matrixMul(mat_wm2, mat_r );//if( arMatrixMul( &mat_cpara, mat_wm2, mat_r ) < 0 ) {
144144
145145 for(int i2=0;i<3;i++){
146146 for(int i3=0;i3<4;i3++){
--- a/trunk/src/jp/nyatla/nyartoolkit/core/NyARColorPatt.java
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARColorPatt.java
@@ -34,194 +34,13 @@ package jp.nyatla.nyartoolkit.core;
3434 import jp.nyatla.nyartoolkit.NyARException;
3535 import jp.nyatla.nyartoolkit.core.raster.*;
3636
37-/**
38- * 24ビットカラーのマーカーを保持するために使うクラスです。
39- * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。
40- *
41- */
42-public class NyARColorPatt
37+public interface NyARColorPatt
4338 {
44- public static final int AR_PATT_SAMPLE_NUM=64;//#define AR_PATT_SAMPLE_NUM 64
45- private short extpat[][][];
46- private int width;
47- private int height;
48- public NyARColorPatt(int i_width,int i_height)
49- {
50- width=i_width;
51- height=i_height;
52- extpat=new short[i_height][i_width][3];
53- }
54- public short[][][] getPatArray()
55- {
56- return extpat;
57- }
58- public int getWidth()
59- {
60- return width;
61- }
62- public int getHeight()
63- {
64- return height;
65- }
66- private static void get_cpara( double world[][], double vertex[][],double para[][] ) throws NyARException
67- {
68- NyARMat a = new NyARMat( 8, 8 );
69- double[][] a_array=a.getArray();
70- NyARMat b = new NyARMat( 8, 1 );
71- double[][] b_array=b.getArray();
72- NyARMat c = new NyARMat( 8, 1 );
73- double[][] c_array=c.getArray();
74-
75- for(int i = 0; i < 4; i++ ) {
76- a_array[i*2][0]=world[i][0];//a->m[i*16+0] = world[i][0];
77- a_array[i*2][1]=world[i][1];//a->m[i*16+1] = world[i][1];
78- a_array[i*2][2]=1.0;//a->m[i*16+2] = 1.0;
79- a_array[i*2][3]=0.0;//a->m[i*16+3] = 0.0;
80- a_array[i*2][4]=0.0;//a->m[i*16+4] = 0.0;
81- a_array[i*2][5]=0.0;//a->m[i*16+5] = 0.0;
82- a_array[i*2][6]=-world[i][0] * vertex[i][0];//a->m[i*16+6] = -world[i][0] * vertex[i][0];
83- a_array[i*2][7]=-world[i][1] * vertex[i][0];//a->m[i*16+7] = -world[i][1] * vertex[i][0];
84- a_array[i*2+1][0]=0.0;//a->m[i*16+8] = 0.0;
85- a_array[i*2+1][1]=0.0;//a->m[i*16+9] = 0.0;
86- a_array[i*2+1][2]=0.0;//a->m[i*16+10] = 0.0;
87- a_array[i*2+1][3]=world[i][0];//a->m[i*16+11] = world[i][0];
88- a_array[i*2+1][4]=world[i][1];//a->m[i*16+12] = world[i][1];
89- a_array[i*2+1][5]=1.0;//a->m[i*16+13] = 1.0;
90- a_array[i*2+1][6]=-world[i][0] * vertex[i][1];//a->m[i*16+14] = -world[i][0] * vertex[i][1];
91- a_array[i*2+1][7]=-world[i][1] * vertex[i][1];//a->m[i*16+15] = -world[i][1] * vertex[i][1];
92- b_array[i*2+0][0]=vertex[i][0];//b->m[i*2+0] = vertex[i][0];
93- b_array[i*2+1][0]=vertex[i][1];//b->m[i*2+1] = vertex[i][1];
94- }
95-// JartkException.trap("未チェックのパス");
96- a.matrixSelfInv();
97-
98-// JartkException.trap("未チェックのパス");
99- NyARMat.matrixMul( c, a, b );
100- for(int i = 0; i < 2; i++ ) {
101- para[i][0] = c_array[i*3+0][0];//para[i][0] = c->m[i*3+0];
102- para[i][1] = c_array[i*3+1][0];//para[i][1] = c->m[i*3+1];
103- para[i][2] = c_array[i*3+2][0];//para[i][2] = c->m[i*3+2];
104- }
105- para[2][0] = c_array[2*3+0][0];//para[2][0] = c->m[2*3+0];
106- para[2][1] = c_array[2*3+1][0];//para[2][1] = c->m[2*3+1];
107- para[2][2] = 1.0;//para[2][2] = 1.0;
108- }
109- /**
110- * imageから、i_markerの位置にあるパターンを切り出して、保持します。
111- * @param image
112- * @param i_marker
113- * @throws Exception
114- */
115- public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException
116- {
117- int[] x_coord=i_marker.x_coord;
118- int[] y_coord=i_marker.y_coord;
119- int[] vertex=i_marker.vertex;
120- int[][][] ext_pat2=new int[height][width][3];//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];
121- double[][] world=new double[4][2];//double world[4][2];
122- double[][] local=new double[4][2];//double local[4][2];
123- double[][] para=new double[3][3]; //double para[3][3];
124- double d, xw, yw;
125- int xc, yc;
126- int xdiv, ydiv;
127- int xdiv2, ydiv2;
128- int lx1, lx2, ly1, ly2;
129- int img_x,img_y;
130-
131- img_x=image.getWidth();
132- img_y=image.getHeight();
133-
134- double xdiv2_reciprocal; // [tp]
135- double ydiv2_reciprocal; // [tp]
136- int ext_pat2_x_index;
137- int ext_pat2_y_index;
138-
139- world[0][0] = 100.0;
140- world[0][1] = 100.0;
141- world[1][0] = 100.0 + 10.0;
142- world[1][1] = 100.0;
143- world[2][0] = 100.0 + 10.0;
144- world[2][1] = 100.0 + 10.0;
145- world[3][0] = 100.0;
146- world[3][1] = 100.0 + 10.0;
147- for(int i = 0; i < 4; i++ ) {
148- local[i][0] = x_coord[vertex[i]];
149- local[i][1] = y_coord[vertex[i]];
150- }
151- get_cpara( world, local, para );
152-
153- lx1 = (int)((local[0][0] - local[1][0])*(local[0][0] - local[1][0])+ (local[0][1] - local[1][1])*(local[0][1] - local[1][1]));
154- lx2 = (int)((local[2][0] - local[3][0])*(local[2][0] - local[3][0])+ (local[2][1] - local[3][1])*(local[2][1] - local[3][1]));
155- ly1 = (int)((local[1][0] - local[2][0])*(local[1][0] - local[2][0])+ (local[1][1] - local[2][1])*(local[1][1] - local[2][1]));
156- ly2 = (int)((local[3][0] - local[0][0])*(local[3][0] - local[0][0])+ (local[3][1] - local[0][1])*(local[3][1] - local[0][1]));
157- if( lx2 > lx1 ){
158- lx1 = lx2;
159- }
160- if( ly2 > ly1 ){
161- ly1 = ly2;
162- }
163- xdiv2 =width;
164- ydiv2 =height;
165-
166- while( xdiv2*xdiv2 < lx1/4 ){
167- xdiv2*=2;
168- }
169- while( ydiv2*ydiv2 < ly1/4 ){
170- ydiv2*=2;
171- }
172-
173- if( xdiv2 > AR_PATT_SAMPLE_NUM)
174- {
175- xdiv2 =AR_PATT_SAMPLE_NUM;
176- }
177- if( ydiv2 >AR_PATT_SAMPLE_NUM)
178- {
179- ydiv2 = AR_PATT_SAMPLE_NUM;
180- }
181-
182- xdiv = xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;
183- ydiv = ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;
184-/*
185-printf("%3d(%f), %3d(%f)\n", xdiv2, sqrt(lx1), ydiv2, sqrt(ly1));
186-*/
187-
188- xdiv2_reciprocal = 1.0 / xdiv2;
189- ydiv2_reciprocal = 1.0 / ydiv2;
190- int[] rgb_tmp=new int[3];
191- // arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );
192- for(int j = 0; j < ydiv2; j++ ) {
193- yw = 102.5 + 5.0 * (j+0.5) * ydiv2_reciprocal;
194- for(int i = 0; i < xdiv2; i++ ) {
195- xw = 102.5 + 5.0 * (i+0.5) * xdiv2_reciprocal;
196- d = para[2][0]*xw + para[2][1]*yw + para[2][2];
197- if( d == 0 ){
198- throw new NyARException();
199- }
200- xc = (int)((para[0][0]*xw + para[0][1]*yw + para[0][2])/d);
201- yc = (int)((para[1][0]*xw + para[1][1]*yw + para[1][2])/d);
202-
39+ public int getWidth();
40+ public int getHeight();
41+ public int[][][] getPatArray();
42+ public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException;
43+}
20344
204- if( xc >= 0 && xc < img_x && yc >= 0 && yc < img_y ) {
205- ext_pat2_y_index = j/ydiv;
206- ext_pat2_x_index = i/xdiv;
207-// image_index = (yc*arUtil_c.arImXsize+xc)*Config.AR_PIX_SIZE_DEFAULT;
208- image.pickRgbArray(xc, yc, rgb_tmp);
20945
210- ext_pat2[ext_pat2_y_index][ext_pat2_x_index][0] += rgb_tmp[0];//R
211- ext_pat2[ext_pat2_y_index][ext_pat2_x_index][1] += rgb_tmp[1];//G
212- ext_pat2[ext_pat2_y_index][ext_pat2_x_index][2] += rgb_tmp[2];//B
213-// System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]);
214- }
215- }
216- }
217-// short[][][] ext_pat=new short[Config.AR_PATT_SIZE_Y][Config.AR_PATT_SIZE_X][3];//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];
21846
219- for(int j = 0; j < height; j++ ) {
220- for(int i = 0; i < width; i++ ) { // PRL 2006-06-08.
221- extpat[j][i][0]=(short)(ext_pat2[j][i][0] / (xdiv*ydiv));//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));
222- extpat[j][i][1]=(short)(ext_pat2[j][i][1] / (xdiv*ydiv));//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));
223- extpat[j][i][2]=(short)(ext_pat2[j][i][2] / (xdiv*ydiv));//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));
224- }
225- }
226- }
227-}
\ No newline at end of file
--- /dev/null
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O1.java
@@ -0,0 +1,268 @@
1+package jp.nyatla.nyartoolkit.core;
2+
3+import jp.nyatla.nyartoolkit.NyARException;
4+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;
5+
6+/**
7+ * 24ビットカラーのマーカーを保持するために使うクラスです。
8+ * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。
9+ * 演算順序以外の最適化をしたもの
10+ *
11+ */
12+public class NyARColorPatt_O1 implements NyARColorPatt
13+{
14+ private static final int AR_PATT_SAMPLE_NUM=64;//#define AR_PATT_SAMPLE_NUM 64
15+ private int extpat[][][];
16+ private int width;
17+ private int height;
18+ public NyARColorPatt_O1(int i_width,int i_height)
19+ {
20+ this.width=i_width;
21+ this.height=i_height;
22+ this.extpat=new int[i_height][i_width][3];
23+ this.wk_pickFromRaster_ext_pat2=new int[i_height][i_width][3];
24+ }
25+ public int[][][] getPatArray()
26+ {
27+ return extpat;
28+ }
29+ public int getWidth()
30+ {
31+ return width;
32+ }
33+ public int getHeight()
34+ {
35+ return height;
36+ }
37+ private final NyARMat wk_get_cpara_a=new NyARMat(8,8);
38+ private final NyARMat wk_get_cpara_b=new NyARMat(8,1);
39+ private final NyARMat wk_get_cpara_c=new NyARMat(8,1);
40+ /**
41+ *
42+ * @param world
43+ * @param vertex
44+ * @param para
45+ * [3x3]
46+ * @throws NyARException
47+ */
48+ private void get_cpara( double world[][], double vertex[][],double[] para) throws NyARException
49+ {
50+ NyARMat a =wk_get_cpara_a;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 8 );
51+ double[][] a_array=a.getArray();
52+ NyARMat b =wk_get_cpara_b;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 1 );
53+ double[][] b_array=b.getArray();
54+ double[] a_pt0,a_pt1,world_pti;
55+
56+ for(int i = 0; i < 4; i++ ) {
57+ a_pt0=a_array[i*2];
58+ a_pt1=a_array[i*2+1];
59+ world_pti=world[i];
60+
61+ a_pt0[0]=world_pti[0];//a->m[i*16+0] = world[i][0];
62+ a_pt0[1]=world_pti[1];//a->m[i*16+1] = world[i][1];
63+ a_pt0[2]=1.0;//a->m[i*16+2] = 1.0;
64+ a_pt0[3]=0.0;//a->m[i*16+3] = 0.0;
65+ a_pt0[4]=0.0;//a->m[i*16+4] = 0.0;
66+ a_pt0[5]=0.0;//a->m[i*16+5] = 0.0;
67+ a_pt0[6]=-world_pti[0] * vertex[i][0];//a->m[i*16+6] = -world[i][0] * vertex[i][0];
68+ a_pt0[7]=-world_pti[1] * vertex[i][0];//a->m[i*16+7] = -world[i][1] * vertex[i][0];
69+ a_pt1[0]=0.0;//a->m[i*16+8] = 0.0;
70+ a_pt1[1]=0.0;//a->m[i*16+9] = 0.0;
71+ a_pt1[2]=0.0;//a->m[i*16+10] = 0.0;
72+ a_pt1[3]=world_pti[0];//a->m[i*16+11] = world[i][0];
73+ a_pt1[4]=world_pti[1];//a->m[i*16+12] = world[i][1];
74+ a_pt1[5]=1.0;//a->m[i*16+13] = 1.0;
75+ a_pt1[6]=-world_pti[0] * vertex[i][1];//a->m[i*16+14] = -world[i][0] * vertex[i][1];
76+ a_pt1[7]=-world_pti[1] * vertex[i][1];//a->m[i*16+15] = -world[i][1] * vertex[i][1];
77+ b_array[i*2+0][0]=vertex[i][0];//b->m[i*2+0] = vertex[i][0];
78+ b_array[i*2+1][0]=vertex[i][1];//b->m[i*2+1] = vertex[i][1];
79+ }
80+// JartkException.trap("未チェックのパス");
81+ a.matrixSelfInv();
82+
83+// JartkException.trap("未チェックのパス");
84+ NyARMat c = wk_get_cpara_c;//次処理で結果を受け取るので、初期化不要//new NyARMat( 8, 1 );
85+ double[][] c_array=c.getArray();
86+
87+ c.matrixMul(a, b);
88+ for(int i = 0; i < 2; i++ ) {
89+ para[i*3+0] = c_array[i*3+0][0];//para[i][0] = c->m[i*3+0];
90+ para[i*3+1] = c_array[i*3+1][0];//para[i][1] = c->m[i*3+1];
91+ para[i*3+2] = c_array[i*3+2][0];//para[i][2] = c->m[i*3+2];
92+ }
93+ para[2*3+0] = c_array[2*3+0][0];//para[2][0] = c->m[2*3+0];
94+ para[2*3+1] = c_array[2*3+1][0];//para[2][1] = c->m[2*3+1];
95+ para[2*3+2] = 1.0;//para[2][2] = 1.0;
96+ }
97+
98+ private final double[][] wk_pickFromRaster_local=new double[4][2];
99+ private final double[] wk_pickFromRaster_para=new double[9];//[3][3];
100+ private int[][][] wk_pickFromRaster_ext_pat2=null;//コンストラクタでint[height][width][3]を作る
101+ private final double[][] wk_pickFromRaster_world={//double world[4][2];
102+ {100.0, 100.0},
103+ {100.0+10.0,100.0},
104+ {100.0+10.0,100.0 + 10.0},
105+ {100.0, 100.0 + 10.0}
106+ };
107+ /**
108+ * pickFromRaster関数から使う変数です。
109+ *
110+ */
111+ private static void initValue_wk_pickFromRaster_ext_pat2(int[][][] i_ext_pat2,int i_width,int i_height)
112+ {
113+ int i,i2;
114+ int[][] pt2;
115+ int[] pt1;
116+ for(i=i_height-1;i>=0;i--){
117+ pt2=i_ext_pat2[i];
118+ for(i2=i_width-1;i2>=0;i2--){
119+ pt1=pt2[i2];
120+ pt1[0]=0;
121+ pt1[1]=0;
122+ pt1[2]=0;
123+ }
124+ }
125+ }
126+ private final int[] wk_pickFromRaster_rgb_tmp=new int[3];
127+ /**
128+ * imageから、i_markerの位置にあるパターンを切り出して、保持します。
129+ * Optimize:STEP[769->]
130+ * @param image
131+ * @param i_marker
132+ * @throws Exception
133+ */
134+ public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException
135+ {
136+ double d, xw, yw;
137+ int xc, yc;
138+ int xdiv, ydiv;
139+ int xdiv2, ydiv2;
140+ int lx1, lx2, ly1, ly2;
141+
142+ int img_x=image.getWidth();
143+ int img_y=image.getHeight();
144+
145+ double xdiv2_reciprocal; // [tp]
146+ double ydiv2_reciprocal; // [tp]
147+
148+
149+ int[] x_coord=i_marker.x_coord;
150+ int[] y_coord=i_marker.y_coord;
151+ double[][] local=wk_pickFromRaster_local;//double local[4][2];
152+ int[] vertex=i_marker.mkvertex;
153+ for(int i = 0; i < 4; i++ ) {
154+ local[i][0] = x_coord[vertex[i]];
155+ local[i][1] = y_coord[vertex[i]];
156+ }
157+ double[][] world=wk_pickFromRaster_world;
158+/* world[0][0] = 100.0;
159+ world[0][1] = 100.0;
160+ world[1][0] = 100.0 + 10.0;
161+ world[1][1] = 100.0;
162+ world[2][0] = 100.0 + 10.0;
163+ world[2][1] = 100.0 + 10.0;
164+ world[3][0] = 100.0;
165+ world[3][1] = 100.0 + 10.0;*/
166+ double[] para =wk_pickFromRaster_para; //double para[3][3];
167+ get_cpara( world, local, para );
168+ lx1 = (int)((local[0][0] - local[1][0])*(local[0][0] - local[1][0])+ (local[0][1] - local[1][1])*(local[0][1] - local[1][1]));
169+ lx2 = (int)((local[2][0] - local[3][0])*(local[2][0] - local[3][0])+ (local[2][1] - local[3][1])*(local[2][1] - local[3][1]));
170+ ly1 = (int)((local[1][0] - local[2][0])*(local[1][0] - local[2][0])+ (local[1][1] - local[2][1])*(local[1][1] - local[2][1]));
171+ ly2 = (int)((local[3][0] - local[0][0])*(local[3][0] - local[0][0])+ (local[3][1] - local[0][1])*(local[3][1] - local[0][1]));
172+ if( lx2 > lx1 ){
173+ lx1 = lx2;
174+ }
175+ if( ly2 > ly1 ){
176+ ly1 = ly2;
177+ }
178+ xdiv2 =this.width;
179+ ydiv2 =this.height;
180+
181+ while( xdiv2*xdiv2 < lx1/4 ){
182+ xdiv2*=2;
183+ }
184+ while( ydiv2*ydiv2 < ly1/4 ){
185+ ydiv2*=2;
186+ }
187+
188+ if( xdiv2 > AR_PATT_SAMPLE_NUM)
189+ {
190+ xdiv2 =AR_PATT_SAMPLE_NUM;
191+ }
192+ if( ydiv2 >AR_PATT_SAMPLE_NUM)
193+ {
194+ ydiv2 = AR_PATT_SAMPLE_NUM;
195+ }
196+
197+ xdiv = xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;
198+ ydiv = ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;
199+
200+ /*wk_pickFromRaster_ext_pat2ワーク変数を初期化する。*/
201+ int[][][] ext_pat2=wk_pickFromRaster_ext_pat2;//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];
202+ int extpat_j[][],extpat_j_i[];
203+ int ext_pat2_j[][],ext_pat2_j_i[];
204+
205+ initValue_wk_pickFromRaster_ext_pat2(ext_pat2,this.width,this.height);
206+
207+ xdiv2_reciprocal = 1.0 / xdiv2;
208+ ydiv2_reciprocal = 1.0 / ydiv2;
209+ int i,j;
210+ int[] rgb_tmp=wk_pickFromRaster_rgb_tmp;
211+ // arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );
212+ for(j = 0; j < ydiv2; j++ ) {
213+ yw = 102.5 + 5.0 * (j+0.5) * ydiv2_reciprocal;
214+ for(i = 0; i < xdiv2; i++ ) {
215+ xw = 102.5 + 5.0 * (i+0.5) * xdiv2_reciprocal;
216+ d = para[2*3+0]*xw + para[2*3+1]*yw + para[2*3+2];
217+ if( d == 0 ){
218+ throw new NyARException();
219+ }
220+ xc = (int)((para[0*3+0]*xw + para[0*3+1]*yw + para[0*3+2])/d);
221+ yc = (int)((para[1*3+0]*xw + para[1*3+1]*yw + para[1*3+2])/d);
222+
223+
224+ if( xc >= 0 && xc < img_x && yc >= 0 && yc < img_y ) {
225+ image.getPixel(xc, yc, rgb_tmp);
226+ ext_pat2_j_i=ext_pat2[j/ydiv][i/xdiv];
227+
228+ ext_pat2_j_i[0] += rgb_tmp[0];//R
229+ ext_pat2_j_i[1] += rgb_tmp[1];//G
230+ ext_pat2_j_i[2] += rgb_tmp[2];//B
231+// System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]);
232+ }
233+ }
234+ }
235+// short[][][] ext_pat=new short[Config.AR_PATT_SIZE_Y][Config.AR_PATT_SIZE_X][3];//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];
236+ /*<Optimize>*/
237+ int xdiv_x_ydiv=xdiv*ydiv;
238+ for(j = this.height-1; j>=0; j--){
239+ extpat_j=extpat[j];
240+ ext_pat2_j=ext_pat2[j];
241+ for(i = this.width-1; i>=0; i--){ // PRL 2006-06-08.
242+ ext_pat2_j_i=ext_pat2_j[i];
243+ extpat_j_i=extpat_j[i];
244+ extpat_j_i[0]=(ext_pat2_j_i[0] / xdiv_x_ydiv);//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));
245+ extpat_j_i[1]=(ext_pat2_j_i[1] / xdiv_x_ydiv);//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));
246+ extpat_j_i[2]=(ext_pat2_j_i[2] / xdiv_x_ydiv);//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));
247+ }
248+ }/*
249+ int xdiv_mul_ydiv=xdiv*ydiv;
250+ short [][] extpat_pt_2;
251+ short[] extpat_pt_1;
252+ int[][] ext_pat2_pt_2;
253+ int[] ext_pat2_pt_1;
254+ for(int j=this.height-1; j>=0; j--){//for(int j = 0; j < this.height; j++ ){
255+ extpat_pt_2=extpat[j];
256+ ext_pat2_pt_2=ext_pat2[j];
257+ for(int i = this.width-1; i>=0; i--){//for(int i = 0; i < this.width; i++ ){ // PRL 2006-06-08.
258+ extpat_pt_1=extpat_pt_2[i];
259+ ext_pat2_pt_1=ext_pat2_pt_2[i];
260+ extpat_pt_1[0]=(short)(ext_pat2_pt_1[0] / xdiv_mul_ydiv);//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));
261+ extpat_pt_1[1]=(short)(ext_pat2_pt_1[1] / xdiv_mul_ydiv);//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));
262+ extpat_pt_1[2]=(short)(ext_pat2_pt_1[2] / xdiv_mul_ydiv);//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));
263+ }
264+ }
265+ /*</Optimize>*/
266+ return;
267+ }
268+}
\ No newline at end of file
--- /dev/null
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O2.java
@@ -0,0 +1,281 @@
1+package jp.nyatla.nyartoolkit.core;
2+
3+import jp.nyatla.nyartoolkit.NyARException;
4+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;
5+
6+/**
7+ * 24ビットカラーのマーカーを保持するために使うクラスです。
8+ * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。
9+ * 演算順序を含む最適化をしたもの
10+ *
11+ */
12+public class NyARColorPatt_O2 implements NyARColorPatt
13+{
14+ private static final int AR_PATT_SAMPLE_NUM=64;//#define AR_PATT_SAMPLE_NUM 64
15+ private int extpat[][][];
16+ private int width;
17+ private int height;
18+ public NyARColorPatt_O2(int i_width,int i_height)
19+ {
20+ this.width=i_width;
21+ this.height=i_height;
22+ this.extpat=new int[i_height][i_width][3];
23+ this.wk_pickFromRaster_ext_pat2=new int[i_height][i_width][3];
24+ }
25+ public int[][][] getPatArray()
26+ {
27+ return extpat;
28+ }
29+ public int getWidth()
30+ {
31+ return width;
32+ }
33+ public int getHeight()
34+ {
35+ return height;
36+ }
37+ private final NyARMat wk_get_cpara_a=new NyARMat(8,8);
38+ private final NyARMat wk_get_cpara_b=new NyARMat(8,1);
39+// private final NyARMat wk_get_cpara_c=new NyARMat(8,1);
40+ /**
41+ *
42+ * @param world
43+ * @param vertex
44+ * @param para
45+ * [3x3]
46+ * @throws NyARException
47+ */
48+ /**
49+ * @param world
50+ * @param vertex
51+ * @param o_para
52+ * @throws NyARException
53+ */
54+ private void get_cpara(double vertex_0[], double vertex_1[],NyARMat o_para) throws NyARException
55+ {
56+ double world[][]=this.wk_pickFromRaster_world;
57+ NyARMat a =wk_get_cpara_a;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 8 );
58+ double[][] a_array=a.getArray();
59+ NyARMat b =wk_get_cpara_b;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 1 );
60+ double[][] b_array=b.getArray();
61+ double[] a_pt0,a_pt1,world_pti;
62+
63+ for(int i = 0; i < 4; i++ ) {
64+ a_pt0=a_array[i*2];
65+ a_pt1=a_array[i*2+1];
66+ world_pti=world[i];
67+
68+ a_pt0[0]=world_pti[0];//a->m[i*16+0] = world[i][0];
69+ a_pt0[1]=world_pti[1];//a->m[i*16+1] = world[i][1];
70+ a_pt0[2]=1.0;//a->m[i*16+2] = 1.0;
71+ a_pt0[3]=0.0;//a->m[i*16+3] = 0.0;
72+ a_pt0[4]=0.0;//a->m[i*16+4] = 0.0;
73+ a_pt0[5]=0.0;//a->m[i*16+5] = 0.0;
74+ a_pt0[6]=-world_pti[0] * vertex_0[i];//a->m[i*16+6] = -world[i][0] * vertex[i][0];
75+ a_pt0[7]=-world_pti[1] * vertex_0[i];//a->m[i*16+7] = -world[i][1] * vertex[i][0];
76+ a_pt1[0]=0.0;//a->m[i*16+8] = 0.0;
77+ a_pt1[1]=0.0;//a->m[i*16+9] = 0.0;
78+ a_pt1[2]=0.0;//a->m[i*16+10] = 0.0;
79+ a_pt1[3]=world_pti[0];//a->m[i*16+11] = world[i][0];
80+ a_pt1[4]=world_pti[1];//a->m[i*16+12] = world[i][1];
81+ a_pt1[5]=1.0;//a->m[i*16+13] = 1.0;
82+ a_pt1[6]=-world_pti[0] * vertex_1[i];//a->m[i*16+14] = -world[i][0] * vertex[i][1];
83+ a_pt1[7]=-world_pti[1] * vertex_1[i];//a->m[i*16+15] = -world[i][1] * vertex[i][1];
84+ b_array[i*2+0][0]=vertex_0[i];//b->m[i*2+0] = vertex[i][0];
85+ b_array[i*2+1][0]=vertex_1[i];//b->m[i*2+1] = vertex[i][1];
86+ }
87+// JartkException.trap("未チェックのパス");
88+ a.matrixSelfInv();
89+
90+// JartkException.trap("未チェックのパス");
91+// NyARMat c = wk_get_cpara_c;//次処理で結果を受け取るので、初期化不要//new NyARMat( 8, 1 );
92+// double[][] c_array=c.getArray();
93+
94+ o_para.matrixMul(a, b);
95+// para[0*3+0] = c_array[0*3+0][0];//para[i][0] = c->m[i*3+0];
96+// para[0*3+1] = c_array[0*3+1][0];//para[i][1] = c->m[i*3+1];
97+// para[0*3+2] = c_array[0*3+2][0];//para[i][2] = c->m[i*3+2];
98+// para[1*3+0] = c_array[1*3+0][0];//para[i][0] = c->m[i*3+0];
99+// para[1*3+1] = c_array[1*3+1][0];//para[i][1] = c->m[i*3+1];
100+// para[i*3+2] = c_array[1*3+2][0];//para[i][2] = c->m[i*3+2];
101+// para[2*3+0] = c_array[2*3+0][0];//para[2][0] = c->m[2*3+0];
102+// para[2*3+1] = c_array[2*3+1][0];//para[2][1] = c->m[2*3+1];
103+// para[2*3+2] = 1.0;//para[2][2] = 1.0;
104+
105+
106+ }
107+
108+ // private final double[] wk_pickFromRaster_para=new double[9];//[3][3];
109+ private int[][][] wk_pickFromRaster_ext_pat2=null;//コンストラクタでint[height][width][3]を作る
110+ private final double[][] wk_pickFromRaster_world={//double world[4][2];
111+ {100.0, 100.0},
112+ {100.0+10.0,100.0},
113+ {100.0+10.0,100.0 + 10.0},
114+ {100.0, 100.0 + 10.0}
115+ };
116+ /**
117+ * pickFromRaster関数から使う変数です。
118+ *
119+ */
120+ private static void initValue_wk_pickFromRaster_ext_pat2(int[][][] i_ext_pat2,int i_width,int i_height)
121+ {
122+ int i,i2;
123+ int[][] pt2;
124+ int[] pt1;
125+ for(i=i_height-1;i>=0;i--){
126+ pt2=i_ext_pat2[i];
127+ for(i2=i_width-1;i2>=0;i2--){
128+ pt1=pt2[i2];
129+ pt1[0]=0;
130+ pt1[1]=0;
131+ pt1[2]=0;
132+ }
133+ }
134+ }
135+ private final double[][] wk_pickFromRaster_local=new double[2][4];
136+ private final int[] wk_pickFromRaster_rgb_tmp=new int[3];
137+ private final NyARMat wk_pickFromRaster_cpara=new NyARMat(8,1);
138+ /**
139+ * imageから、i_markerの位置にあるパターンを切り出して、保持します。
140+ * Optimize:STEP[769->750]
141+ * @param image
142+ * @param i_marker
143+ * @throws Exception
144+ */
145+ public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException
146+ {
147+ NyARMat cpara=this.wk_pickFromRaster_cpara;
148+ //localの計算
149+ int[] x_coord=i_marker.x_coord;
150+ int[] y_coord=i_marker.y_coord;
151+ int[] vertex=i_marker.mkvertex;
152+ double[] local_0=wk_pickFromRaster_local[0];//double local[4][2];
153+ double[] local_1=wk_pickFromRaster_local[1];//double local[4][2];
154+ for(int i = 0; i < 4; i++ ) {
155+ local_0[i] = x_coord[vertex[i]];
156+ local_1[i] = y_coord[vertex[i]];
157+ }
158+ //xdiv2,ydiv2の計算
159+ int xdiv2, ydiv2;
160+ int l1,l2;
161+ double w1,w2;
162+
163+ //x計算
164+ w1=local_0[0] - local_0[1];
165+ w2=local_1[0] - local_1[1];
166+ l1 = (int)(w1*w1+w2*w2);
167+ w1=local_0[2] - local_0[3];
168+ w2=local_1[2] - local_1[3];
169+ l2 = (int)(w1*w1+w2*w2);
170+ if( l2 > l1 ){
171+ l1 = l2;
172+ }
173+ l1=l1/4;
174+ xdiv2 =this.width;
175+ while( xdiv2*xdiv2 < l1 ){
176+ xdiv2*=2;
177+ }
178+ if( xdiv2 > AR_PATT_SAMPLE_NUM)
179+ {
180+ xdiv2 =AR_PATT_SAMPLE_NUM;
181+ }
182+
183+ //y計算
184+ w1=local_0[1] - local_0[2];
185+ w2=local_1[1] - local_1[2];
186+ l1 = (int)(w1*w1+ w2*w2);
187+ w1=local_0[3] - local_0[0];
188+ w2=local_1[3] - local_1[0];
189+ l2 = (int)(w1*w1+ w2*w2);
190+ if( l2 > l1 ){
191+ l1 = l2;
192+ }
193+ ydiv2 =this.height;
194+ l1=l1/4;
195+ while( ydiv2*ydiv2 < l1 ){
196+ ydiv2*=2;
197+ }
198+ if( ydiv2 >AR_PATT_SAMPLE_NUM)
199+ {
200+ ydiv2 = AR_PATT_SAMPLE_NUM;
201+ }
202+
203+ //cparaの計算
204+ get_cpara(local_0,local_1,cpara);
205+
206+ int img_x=image.getWidth();
207+ int img_y=image.getHeight();
208+
209+ /*wk_pickFromRaster_ext_pat2ワーク変数を初期化する。*/
210+ int[][][] ext_pat2=wk_pickFromRaster_ext_pat2;//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];
211+ int extpat_j[][],extpat_j_i[];
212+ int ext_pat2_j[][],ext_pat2_j_i[];
213+
214+ initValue_wk_pickFromRaster_ext_pat2(ext_pat2,this.width,this.height);
215+
216+ double[][] cpara_array=cpara.getArray();
217+ double para21_x_yw,para01_x_yw,para11_x_yw;
218+ double para00,para01,para02,para10,para11,para12,para20,para21;
219+ para00 = cpara_array[0*3+0][0];//para[i][0] = c->m[i*3+0];
220+ para01 = cpara_array[0*3+1][0];//para[i][1] = c->m[i*3+1];
221+ para02 = cpara_array[0*3+2][0];//para[i][2] = c->m[i*3+2];
222+ para10 = cpara_array[1*3+0][0];//para[i][0] = c->m[i*3+0];
223+ para11 = cpara_array[1*3+1][0];//para[i][1] = c->m[i*3+1];
224+ para12 = cpara_array[1*3+2][0];//para[i][2] = c->m[i*3+2];
225+ para20 = cpara_array[2*3+0][0];//para[2][0] = c->m[2*3+0];
226+ para21 = cpara_array[2*3+1][0];//para[2][1] = c->m[2*3+1];
227+ //para22 = 1.0;//para[2][2] = 1.0;
228+
229+
230+ double d, xw, yw;
231+ int xc, yc;
232+ int i,j;
233+ int[] rgb_tmp=wk_pickFromRaster_rgb_tmp;
234+ // arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );
235+ int xdiv = xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;
236+ int ydiv = ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;
237+ double xdiv2_reciprocal = 1.0 / xdiv2;
238+ double ydiv2_reciprocal = 1.0 / ydiv2;
239+
240+ for(j = 0; j < ydiv2; j++ ) {
241+ yw = 102.5 + 5.0 * ((double)j+0.5) * ydiv2_reciprocal;
242+ para21_x_yw=para21*yw+1.0;
243+ para11_x_yw=para11*yw+para12;
244+ para01_x_yw=para01*yw+para02;
245+ ext_pat2_j=ext_pat2[j/ydiv];
246+ for(i = 0; i < xdiv2; i++ ) {
247+ xw = 102.5 + 5.0 * ((double)i+0.5) * xdiv2_reciprocal;
248+ d = para20*xw + para21_x_yw;
249+ if( d == 0 ){
250+ throw new NyARException();
251+ }
252+ xc = (int)((para00*xw + para01_x_yw)/d);
253+ yc = (int)((para10*xw + para11_x_yw)/d);
254+
255+
256+ if( xc >= 0 && xc < img_x && yc >= 0 && yc < img_y ) {
257+ image.getPixel(xc, yc, rgb_tmp);
258+ ext_pat2_j_i=ext_pat2_j[i/xdiv];
259+
260+ ext_pat2_j_i[0] += rgb_tmp[0];//R
261+ ext_pat2_j_i[1] += rgb_tmp[1];//G
262+ ext_pat2_j_i[2] += rgb_tmp[2];//B
263+ }
264+ }
265+ }
266+ /*<Optimize>*/
267+ int xdiv_x_ydiv=xdiv*ydiv;
268+ for(j =this.height-1; j>=0; j--){
269+ extpat_j=extpat[j];
270+ ext_pat2_j=ext_pat2[j];
271+ for(i = this.width-1; i>=0; i--){ // PRL 2006-06-08.
272+ ext_pat2_j_i=ext_pat2_j[i];
273+ extpat_j_i=extpat_j[i];
274+ extpat_j_i[0]=(ext_pat2_j_i[0] / xdiv_x_ydiv);//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));
275+ extpat_j_i[1]=(ext_pat2_j_i[1] / xdiv_x_ydiv);//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));
276+ extpat_j_i[2]=(ext_pat2_j_i[2] / xdiv_x_ydiv);//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));
277+ }
278+ }
279+ return;
280+ }
281+}
\ No newline at end of file
--- /dev/null
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARColorPatt_O3.java
@@ -0,0 +1,340 @@
1+package jp.nyatla.nyartoolkit.core;
2+
3+
4+
5+import jp.nyatla.nyartoolkit.NyARException;
6+import jp.nyatla.nyartoolkit.core.raster.NyARRaster;
7+
8+/**
9+ * 24ビットカラーのマーカーを保持するために使うクラスです。
10+ * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。
11+ * 演算順序を含む最適化をしたもの
12+ *
13+ */
14+public class NyARColorPatt_O3 implements NyARColorPatt
15+{
16+ private static final int AR_PATT_SAMPLE_NUM=64;//#define AR_PATT_SAMPLE_NUM 64
17+ private int extpat[][][];
18+ private int width;
19+ private int height;
20+ public NyARColorPatt_O3(int i_width,int i_height)
21+ {
22+ this.width=i_width;
23+ this.height=i_height;
24+ this.extpat=new int[i_height][i_width][3];
25+ }
26+ public int[][][] getPatArray()
27+ {
28+ return extpat;
29+ }
30+ public int getWidth()
31+ {
32+ return width;
33+ }
34+ public int getHeight()
35+ {
36+ return height;
37+ }
38+ private final NyARMat wk_get_cpara_a=new NyARMat(8,8);
39+ private final NyARMat wk_get_cpara_b=new NyARMat(8,1);
40+
41+ /**
42+ *
43+ * @param world
44+ * @param vertex
45+ * @param para
46+ * [3x3]
47+ * @throws NyARException
48+ */
49+ /**
50+ * @param world
51+ * @param vertex
52+ * @param o_para
53+ * @throws NyARException
54+ */
55+ private void get_cpara(double vertex_0[], double vertex_1[],NyARMat o_para) throws NyARException
56+ {
57+ double world[][]=this.wk_pickFromRaster_world;
58+ NyARMat a =wk_get_cpara_a;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 8 );
59+ double[][] a_array=a.getArray();
60+ NyARMat b =wk_get_cpara_b;//次処理で値を設定するので、初期化不要// new NyARMat( 8, 1 );
61+ double[][] b_array=b.getArray();
62+ double[] a_pt0,a_pt1,world_pti;
63+
64+ for(int i = 0; i < 4; i++ ) {
65+ a_pt0=a_array[i*2];
66+ a_pt1=a_array[i*2+1];
67+ world_pti=world[i];
68+
69+ a_pt0[0]=world_pti[0];//a->m[i*16+0] = world[i][0];
70+ a_pt0[1]=world_pti[1];//a->m[i*16+1] = world[i][1];
71+ a_pt0[2]=1.0;//a->m[i*16+2] = 1.0;
72+ a_pt0[3]=0.0;//a->m[i*16+3] = 0.0;
73+ a_pt0[4]=0.0;//a->m[i*16+4] = 0.0;
74+ a_pt0[5]=0.0;//a->m[i*16+5] = 0.0;
75+ a_pt0[6]=-world_pti[0] * vertex_0[i];//a->m[i*16+6] = -world[i][0] * vertex[i][0];
76+ a_pt0[7]=-world_pti[1] * vertex_0[i];//a->m[i*16+7] = -world[i][1] * vertex[i][0];
77+ a_pt1[0]=0.0;//a->m[i*16+8] = 0.0;
78+ a_pt1[1]=0.0;//a->m[i*16+9] = 0.0;
79+ a_pt1[2]=0.0;//a->m[i*16+10] = 0.0;
80+ a_pt1[3]=world_pti[0];//a->m[i*16+11] = world[i][0];
81+ a_pt1[4]=world_pti[1];//a->m[i*16+12] = world[i][1];
82+ a_pt1[5]=1.0;//a->m[i*16+13] = 1.0;
83+ a_pt1[6]=-world_pti[0] * vertex_1[i];//a->m[i*16+14] = -world[i][0] * vertex[i][1];
84+ a_pt1[7]=-world_pti[1] * vertex_1[i];//a->m[i*16+15] = -world[i][1] * vertex[i][1];
85+ b_array[i*2+0][0]=vertex_0[i];//b->m[i*2+0] = vertex[i][0];
86+ b_array[i*2+1][0]=vertex_1[i];//b->m[i*2+1] = vertex[i][1];
87+ }
88+ a.matrixSelfInv();
89+
90+
91+ o_para.matrixMul(a, b);
92+
93+
94+
95+ }
96+
97+ // private final double[] wk_pickFromRaster_para=new double[9];//[3][3];
98+ private final double[][] wk_pickFromRaster_world={//double world[4][2];
99+ {100.0, 100.0},
100+ {100.0+10.0,100.0},
101+ {100.0+10.0,100.0 + 10.0},
102+ {100.0, 100.0 + 10.0}
103+ };
104+ /**
105+ * pickFromRaster関数から使う変数です。
106+ *
107+ */
108+ private static void initValue_wk_pickFromRaster_ext_pat2(int[][][] i_ext_pat2,int i_width,int i_height)
109+ {
110+ int i,i2;
111+ int[][] pt2;
112+ int[] pt1;
113+ for(i=i_height-1;i>=0;i--){
114+ pt2=i_ext_pat2[i];
115+ for(i2=i_width-1;i2>=0;i2--){
116+ pt1=pt2[i2];
117+ pt1[0]=0;
118+ pt1[1]=0;
119+ pt1[2]=0;
120+ }
121+ }
122+ }
123+ private final double[][] wk_pickFromRaster_local=new double[2][4];
124+ private final NyARMat wk_pickFromRaster_cpara=new NyARMat(8,1);
125+ /**
126+ * imageから、i_markerの位置にあるパターンを切り出して、保持します。
127+ * Optimize:STEP[769->750]
128+ * @param image
129+ * @param i_marker
130+ * @throws Exception
131+ */
132+ public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException
133+ {
134+ NyARMat cpara=this.wk_pickFromRaster_cpara;
135+ //localの計算
136+ int[] x_coord=i_marker.x_coord;
137+ int[] y_coord=i_marker.y_coord;
138+ int[] vertex=i_marker.mkvertex;
139+ double[] local_0=wk_pickFromRaster_local[0];//double local[4][2];
140+ double[] local_1=wk_pickFromRaster_local[1];//double local[4][2];
141+ for(int i = 0; i < 4; i++ ) {
142+ local_0[i] = x_coord[vertex[i]];
143+ local_1[i] = y_coord[vertex[i]];
144+ }
145+ //xdiv2,ydiv2の計算
146+ int xdiv2, ydiv2;
147+ int l1,l2;
148+ double w1,w2;
149+
150+ //x計算
151+ w1=local_0[0] - local_0[1];
152+ w2=local_1[0] - local_1[1];
153+ l1 = (int)(w1*w1+w2*w2);
154+ w1=local_0[2] - local_0[3];
155+ w2=local_1[2] - local_1[3];
156+ l2 = (int)(w1*w1+w2*w2);
157+ if( l2 > l1 ){
158+ l1 = l2;
159+ }
160+ l1=l1/4;
161+ xdiv2 =this.width;
162+ while( xdiv2*xdiv2 < l1 ){
163+ xdiv2*=2;
164+ }
165+ if( xdiv2 > AR_PATT_SAMPLE_NUM)
166+ {
167+ xdiv2 =AR_PATT_SAMPLE_NUM;
168+ }
169+
170+ //y計算
171+ w1=local_0[1] - local_0[2];
172+ w2=local_1[1] - local_1[2];
173+ l1 = (int)(w1*w1+ w2*w2);
174+ w1=local_0[3] - local_0[0];
175+ w2=local_1[3] - local_1[0];
176+ l2 = (int)(w1*w1+ w2*w2);
177+ if( l2 > l1 ){
178+ l1 = l2;
179+ }
180+ ydiv2 =this.height;
181+ l1=l1/4;
182+ while( ydiv2*ydiv2 < l1 ){
183+ ydiv2*=2;
184+ }
185+ if( ydiv2 >AR_PATT_SAMPLE_NUM)
186+ {
187+ ydiv2 = AR_PATT_SAMPLE_NUM;
188+ }
189+
190+ //cparaの計算
191+ get_cpara(local_0,local_1,cpara);
192+ updateExtpat(image,cpara,xdiv2,ydiv2);
193+
194+ return;
195+ }
196+ //かなり大きいワークバッファを取るな…。
197+ private double[] wk_updateExtpat_para00_xw;
198+ private double[] wk_updateExtpat_para10_xw;
199+ private double[] wk_updateExtpat_para20_xw;
200+ private int[] wk_updateExtpat_rgb_buf;
201+ private int[] wk_updateExtpat_x_rgb_index;
202+ private int[] wk_updateExtpat_y_rgb_index;
203+ private int[] wk_updateExtpat_i_rgb_index;
204+
205+ /**
206+ * ワークバッファを予約する
207+ * @param i_xdiv2
208+ */
209+ private void reservWorkBuffers(int i_xdiv2)
210+ {
211+ int[] buf=this.wk_updateExtpat_rgb_buf;
212+ if(this.wk_updateExtpat_rgb_buf==null){
213+ wk_updateExtpat_para00_xw=new double[i_xdiv2];
214+ wk_updateExtpat_para10_xw=new double[i_xdiv2];
215+ wk_updateExtpat_para20_xw=new double[i_xdiv2];
216+ wk_updateExtpat_rgb_buf=new int[i_xdiv2*3];
217+ wk_updateExtpat_x_rgb_index=new int[i_xdiv2];
218+ wk_updateExtpat_y_rgb_index=new int[i_xdiv2];
219+ wk_updateExtpat_i_rgb_index=new int[i_xdiv2];
220+ }else{
221+ if(buf.length<i_xdiv2){
222+ wk_updateExtpat_para00_xw=new double[i_xdiv2];
223+ wk_updateExtpat_para10_xw=new double[i_xdiv2];
224+ wk_updateExtpat_para20_xw=new double[i_xdiv2];
225+ wk_updateExtpat_rgb_buf=new int[i_xdiv2*3];
226+ wk_updateExtpat_x_rgb_index=new int[i_xdiv2];
227+ wk_updateExtpat_y_rgb_index=new int[i_xdiv2];
228+ wk_updateExtpat_i_rgb_index=new int[i_xdiv2];
229+ }
230+ //十分なら何もしない。
231+ }
232+ return;
233+ }
234+
235+ private void updateExtpat(NyARRaster image,NyARMat i_cpara,int i_xdiv2,int i_ydiv2) throws NyARException
236+ {
237+ int img_x=image.getWidth();
238+ int img_y=image.getHeight();
239+
240+ /*wk_pickFromRaster_ext_pat2ワーク変数を初期化する。*/
241+ //int[][][] ext_pat2=wk_pickFromRaster_ext_pat2;//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];
242+ int extpat_j[][],extpat_j_i[];
243+ //int ext_pat2_j[][],ext_pat2_j_i[];
244+
245+ initValue_wk_pickFromRaster_ext_pat2(extpat,this.width,this.height);
246+
247+ double[][] cpara_array=i_cpara.getArray();
248+ double para21_x_yw,para01_x_yw,para11_x_yw;
249+ double para00,para01,para02,para10,para11,para12,para20,para21;
250+ para00 = cpara_array[0*3+0][0];//para[i][0] = c->m[i*3+0];
251+ para01 = cpara_array[0*3+1][0];//para[i][1] = c->m[i*3+1];
252+ para02 = cpara_array[0*3+2][0];//para[i][2] = c->m[i*3+2];
253+ para10 = cpara_array[1*3+0][0];//para[i][0] = c->m[i*3+0];
254+ para11 = cpara_array[1*3+1][0];//para[i][1] = c->m[i*3+1];
255+ para12 = cpara_array[1*3+2][0];//para[i][2] = c->m[i*3+2];
256+ para20 = cpara_array[2*3+0][0];//para[2][0] = c->m[2*3+0];
257+ para21 = cpara_array[2*3+1][0];//para[2][1] = c->m[2*3+1];
258+
259+
260+ double d,yw;
261+ int xc, yc;
262+ int i,j;
263+ // arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );
264+ int xdiv = i_xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;
265+ int ydiv = i_ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;
266+
267+ //計算バッファを予約する
268+ this.reservWorkBuffers(i_xdiv2);
269+ double[] para00_xw=this.wk_updateExtpat_para00_xw;
270+ double[] para10_xw=this.wk_updateExtpat_para10_xw;
271+ double[] para20_xw=this.wk_updateExtpat_para20_xw;
272+ int[] x_rgb_index=this.wk_updateExtpat_x_rgb_index;
273+ int[] y_rgb_index=this.wk_updateExtpat_y_rgb_index;
274+ int[] i_rgb_index=this.wk_updateExtpat_i_rgb_index;
275+ int[] rgb_buf=this.wk_updateExtpat_rgb_buf;
276+ double xw;
277+ for(i=0;i<i_xdiv2;i++){
278+ xw= 102.5 + 5.0 * ((double)i+0.5) /i_xdiv2;
279+ para20_xw[i]=para20*xw;
280+ para00_xw[i]=para00*xw;
281+ para10_xw[i]=para10*xw;
282+ }
283+
284+ int index_num;
285+
286+ for(j = 0; j < i_ydiv2; j++ ) {
287+ yw = 102.5 + 5.0 * ((double)j+0.5) /i_ydiv2;
288+ para21_x_yw=para21*yw+1.0;
289+ para11_x_yw=para11*yw+para12;
290+ para01_x_yw=para01*yw+para02;
291+ extpat_j=extpat[j/ydiv];
292+ index_num=0;
293+ //ステップ1.RGB取得用のマップを作成
294+ for(i = 0; i < i_xdiv2; i++ ) {
295+ d = para20_xw[i] + para21_x_yw;
296+ if( d == 0 ){
297+ throw new NyARException();
298+ }
299+ xc = (int)((para00_xw[i] + para01_x_yw)/d);
300+ yc = (int)((para10_xw[i] + para11_x_yw)/d);
301+ //範囲外は無視
302+ if(xc<0 || xc >=img_x || yc<0 || yc >=img_y){
303+ continue;
304+ }
305+// ピクセル値の計算
306+// image.getPixel(xc,yc,rgb_buf);
307+// ext_pat2_j_i=ext_pat2_j[i/xdiv];
308+// ext_pat2_j_i[0] += rgb_buf[0];//R
309+// ext_pat2_j_i[1] += rgb_buf[1];//G
310+// ext_pat2_j_i[2] += rgb_buf[2];//B
311+
312+ x_rgb_index[index_num]=xc;
313+ y_rgb_index[index_num]=yc;
314+ i_rgb_index[index_num]=i/xdiv;
315+ index_num++;
316+ }
317+// //ステップ2.ピクセル配列を取得
318+ image.getPixelSet(x_rgb_index,y_rgb_index,index_num,rgb_buf);
319+// //ピクセル値の計算
320+ for(i=index_num-1;i>=0;i--){
321+ extpat_j_i=extpat_j[i_rgb_index[i]];
322+ extpat_j_i[0] += rgb_buf[i*3+0];//R
323+ extpat_j_i[1] += rgb_buf[i*3+1];//G
324+ extpat_j_i[2] += rgb_buf[i*3+2];//B
325+ }
326+ }
327+ /*<Optimize>*/
328+ int xdiv_x_ydiv=xdiv*ydiv;
329+ for(j =this.height-1; j>=0; j--){
330+ extpat_j=extpat[j];
331+ for(i = this.width-1; i>=0; i--){ // PRL 2006-06-08.
332+ extpat_j_i=extpat_j[i];
333+ extpat_j_i[0]/=(xdiv_x_ydiv);//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));
334+ extpat_j_i[1]/=(xdiv_x_ydiv);//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));
335+ extpat_j_i[2]/=(xdiv_x_ydiv);//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));
336+ }
337+ }
338+ return;
339+ }
340+}
\ No newline at end of file
--- a/trunk/src/jp/nyatla/nyartoolkit/core/NyARDetectMarker.java
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARDetectMarker.java
@@ -35,7 +35,10 @@ package jp.nyatla.nyartoolkit.core;
3535
3636
3737 import jp.nyatla.nyartoolkit.NyARException;
38-import jp.nyatla.util.IntValue;
38+
39+
40+
41+
3942 /**
4043 * イメージからマーカー情報を検出するクラス。
4144 * このクラスは、arDetectMarker2.cとの置き換えになります。
@@ -46,375 +49,254 @@ public class NyARDetectMarker {
4649 private static final int AR_AREA_MAX=100000;//#define AR_AREA_MAX 100000
4750 private static final int AR_AREA_MIN=70;//#define AR_AREA_MIN 70
4851
49- private int area_max=AR_AREA_MAX;
50- private int area_min=AR_AREA_MIN;
51- private NyARMarker[] marker_holder; //マーカーデータの保持配列
52- private NyARMarker[] marker_info2_array; //マーカーデータのインデックス配列
53- private int marker_num;
52+// private final NyARMarker[] marker_holder; //マーカーデータの保持配列
53+// private final NyARMarker[] marker_info2_array;//マーカーデータのインデックス配列
54+// private int marker_num;
5455 private int width,height;
5556 /**
5657 * 最大i_squre_max個のマーカーを検出するクラスを作成する。
5758 * @param i_width
5859 * @param i_height
59- * @param i_squre_max
6060 */
61- public NyARDetectMarker(int i_width,int i_height,int i_squre_max)
62- {
63- width =i_width;
64- height=i_height;
65- marker_holder=new NyARMarker[i_squre_max];
66- marker_info2_array=new NyARMarker[i_squre_max];
67- }
68- public int getMarkerNum()
61+ public NyARDetectMarker(int i_width,int i_height)
6962 {
70- return marker_num;
71- }
72- public NyARMarker getMarker(int idx) throws NyARException
73- {
74- if(idx>=marker_num){
75- throw new NyARException();
76- }
77- return marker_info2_array[idx];
63+ this.width =i_width;
64+ this.height=i_height;
65+
66+// this.marker_holder=new NyARMarker[i_squre_max];
67+// this.marker_info2_array=new NyARMarker[i_squre_max];
68+// //先にマーカーホルダにオブジェクトを作っておく
69+// for(int i=0;i<i_squre_max;i++){
70+// this.marker_holder[i]=new NyARMarker();
71+// }
7872 }
73+ private static final int AR_CHAIN_MAX=10000;
74+ private final int[] wk_arGetContour_xdir={0, 1, 1, 1, 0,-1,-1,-1};
75+ private final int[] wk_arGetContour_ydir={-1,-1, 0, 1, 1, 1, 0,-1};
76+ private final int[] wk_arGetContour_xcoord=new int[AR_CHAIN_MAX];
77+ private final int[] wk_arGetContour_ycoord=new int[AR_CHAIN_MAX];
7978 /**
80- * static int get_vertex( int x_coord[], int y_coord[], int st, int ed,double thresh, int vertex[], int *vnum)
81- * 関数の代替関数
82- * @param x_coord
83- * @param y_coord
84- * @param st
85- * @param ed
86- * @param thresh
87- * @param vertex
88- * @param vnum
89- * @return
79+ * int arGetContour( ARInt16 *limage, int *label_ref,int label, int clip[4], ARMarkerInfo2 *marker_info2 )
80+ * 関数の代替品
81+ * detectMarker関数から使う関数です。o_markerにlabelとclipで示される1個のマーカーを格納します。
82+ * marker_holder[i_holder_num]にオブジェクトが無ければまず新規に作成し、もし
83+ * 既に存在すればそこにマーカー情報を上書きして記録します。
84+ * Optimize:STEP[591->543]
85+ * @param o_marker
86+ * @param limage
87+ * @param label_ref
88+ * @param label
89+ * @param clip
90+ * @throws NyARException
9091 */
91- private static boolean get_vertex( int[] x_coord, int[] y_coord, int st, int ed,double thresh, int vertex[],IntValue vnum)
92+ private final void arGetContour(NyARMarker o_marker,int[][] limage, int[] label_ref,int i_labelnum, NyARLabel i_label) throws NyARException
9293 {
93- double d, dmax;
94- double a, b, c;
95- int i, v1=0;
96-
97- a = y_coord[ed] - y_coord[st];
98- b = x_coord[st] - x_coord[ed];
99- c = x_coord[ed]*y_coord[st] - y_coord[ed]*x_coord[st];
100- dmax = 0;
101- for(i=st+1;i<ed;i++) {
102- d = a*x_coord[i] + b*y_coord[i] + c;
103- if( d*d > dmax ) {
104- dmax = d*d;
105- v1 = i;
106- }
107- }
108- if( dmax/(a*a+b*b) > thresh ) {
109- if(!get_vertex(x_coord, y_coord, st, v1, thresh, vertex, vnum)){
110- return false;
111- }
112- if( vnum.get() > 5 ){
113- return false;
114- }
115- vertex[vnum.get()] = v1;//vertex[(*vnum)] = v1;
116- vnum.inc();//(*vnum)++;
117-
118- if(!get_vertex(x_coord, y_coord, v1, ed, thresh, vertex, vnum)){
119- return false;
120- }
121- }
122- return true;
123- }
124- /**
125- * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor )
126- * 関数の代替関数
127- * @param area
128- * @param i_marker_info2
129- * @param factor
130- * @return
131- */
132- private static boolean check_square( int area, NyARMarker i_marker_info2, double factor )
133- {
134- int sx, sy;
135- int dmax, d, v1;
136- int[] vertex=new int[10];//int vertex[10]
137- int[] wv1=new int[10],wv2=new int[10];//int wv1[10],wv2[10];
138- int v2;// int wvnum1,wvnum2,v2;
139- double thresh;
140- int i;
141- IntValue wvnum1=new IntValue(),wvnum2=new IntValue();
142-
94+ final int[] xcoord=wk_arGetContour_xcoord;
95+ final int[] ycoord=wk_arGetContour_ycoord;
96+ final int[] xdir=wk_arGetContour_xdir; //static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
97+ final int[] ydir=wk_arGetContour_ydir;//static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};
98+ //ShortPointer p1;//ARInt16 *p1;
99+ int coord_num;
100+ int sx=0, sy=0, dir;
101+ int dmax, d, v1=0;
102+ int i, j,w;
143103
144- dmax = 0;
145- v1 = 0;
146- sx = i_marker_info2.x_coord[0];//sx = marker_info2->x_coord[0];
147- sy = i_marker_info2.y_coord[0];//sy = marker_info2->y_coord[0];
148- for(i=1;i<i_marker_info2.coord_num-1;i++){//for(i=1;i<marker_info2->coord_num-1;i++) {
149- d = (i_marker_info2.x_coord[i]-sx)*(i_marker_info2.x_coord[i]-sx)+ (i_marker_info2.y_coord[i]-sy)*(i_marker_info2.y_coord[i]-sy);
150- if( d > dmax ) {
151- dmax = d;
152- v1 = i;
153- }
104+ int[] limage_j;
105+ j = i_label.clip2;
106+ limage_j=limage[j];
107+ final int clip1=i_label.clip1;
108+ //p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 = &(limage[j*xsize+clip[0]]);
109+ for( i = i_label.clip0; i <= clip1; i++){//for( i = clip[0]; i <= clip[1]; i++, p1++ ) {
110+ w=limage_j[i];
111+ if(w > 0 && label_ref[w-1] == i_labelnum ) {//if( *p1 > 0 && label_ref[(*p1)-1] == label ) {
112+ sx = i;
113+ sy = j;
114+ break;
154115 }
116+ }
117+ if(i>clip1){//if( i > clip[1] ) {
118+ System.out.println("??? 1");//printf();
119+ throw new NyARException();//return(-1);
120+ }
155121
156- thresh = (area/0.75) * 0.01 * factor;
157-// vnum = 1;
158- vertex[0] = 0;
159- wvnum1.set(0);// wvnum1 = 0;
160- wvnum2.set(0);// wvnum2 = 0;
122+// //マーカーホルダが既に確保済みかを調べる
123+// if(marker_holder[i_holder_num]==null){
124+// //確保していなければ確保
125+// marker_holder[i_holder_num]=new NyARMarker();
126+// }
161127
162- if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord, 0, v1,thresh, wv1, wvnum1)){ //if( get_vertex(marker_info2->x_coord, marker_info2->y_coord, 0, v1,thresh, wv1, &wvnum1) < 0 ) {
163- return false;
128+
129+ coord_num=1;//marker_info2->coord_num = 1;
130+ xcoord[0]=sx;//marker_info2->x_coord[0] = sx;
131+ ycoord[0]=sy;//marker_info2->y_coord[0] = sy;
132+ dir = 5;
133+
134+ int r,c;
135+
136+ for(;;){
137+ r=ycoord[coord_num-1];
138+ c=xcoord[coord_num-1];
139+ //p1 = &(limage[marker_info2->y_coord[marker_info2->coord_num-1] * xsize+ marker_info2->x_coord[marker_info2->coord_num-1]]);
140+ dir = (dir+5)%8;
141+ for(i=0;i<8;i++) {
142+ if(limage[r+ydir[dir]][c+xdir[dir]]>0){//if( p1[ydir[dir]*xsize+xdir[dir]] > 0 ){
143+ break;
144+ }
145+ dir = (dir+1)%8;
164146 }
165- if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v1, i_marker_info2.coord_num-1, thresh, wv2, wvnum2)) {//if(get_vertex(marker_info2->x_coord, marker_info2->y_coord,v1, marker_info2->coord_num-1, thresh, wv2, &wvnum2) < 0 ) {
166- return false;
147+ if( i == 8 ){
148+ System.out.println("??? 2");//printf("??? 2\n");
149+ throw new NyARException();//return(-1);
167150 }
168-
169- if( wvnum1.get() == 1 && wvnum2.get() == 1 ) {//if( wvnum1 == 1 && wvnum2 == 1 ) {
170- vertex[1] = wv1[0];
171- vertex[2] = v1;
172- vertex[3] = wv2[0];
173- }else if( wvnum1.get() > 1 && wvnum2.get() == 0 ) {//}else if( wvnum1 > 1 && wvnum2 == 0 ) {
174- v2 = v1 / 2;
175- wvnum1.set(0);wvnum2.set(0);//wvnum1 = wvnum2 = 0;
176- if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,0, v2, thresh, wv1, wvnum1)) {
177- return false;
178- }
179- if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v2, v1, thresh, wv2, wvnum2)) {
180- return false;
181- }
182- if( wvnum1.get() == 1 && wvnum2.get() == 1 ) {
183- vertex[1] = wv1[0];
184- vertex[2] = wv2[0];
185- vertex[3] = v1;
186- }else{
187- return false;
188- }
189- }else if( wvnum1.get() == 0 && wvnum2.get() > 1 ) {
190- v2 = (v1 + i_marker_info2.coord_num-1) / 2;
191-
192- wvnum1.set(0);wvnum2.set(0);//wvnum1 = wvnum2 = 0;
193- if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v1, v2, thresh, wv1,wvnum1)) {
194- return false;
195- }
196- if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v2, i_marker_info2.coord_num-1, thresh, wv2, wvnum2)) {
197- return false;
198- }
199- if( wvnum1.get() == 1 && wvnum2.get() == 1 ) {
200- vertex[1] = v1;
201- vertex[2] = wv1[0];
202- vertex[3] = wv2[0];
203- }
204- else {
205- return false;
206- }
151+ xcoord[coord_num]= xcoord[coord_num-1] + xdir[dir];//marker_info2->x_coord[marker_info2->coord_num]= marker_info2->x_coord[marker_info2->coord_num-1] + xdir[dir];
152+ ycoord[coord_num]= ycoord[coord_num-1] + ydir[dir];//marker_info2->y_coord[marker_info2->coord_num]= marker_info2->y_coord[marker_info2->coord_num-1] + ydir[dir];
153+ if(xcoord[coord_num] == sx && ycoord[coord_num] == sy ){
154+ break;
207155 }
208- else {
209- return false;
156+ coord_num++;
157+ if(coord_num == xcoord.length-1){//if( marker_info2.coord_num == Config.AR_CHAIN_MAX-1 ){
158+ System.out.println("??? 3");//printf("??? 3\n");
159+ throw new NyARException();//return(-1);
210160 }
161+ }
211162
212- i_marker_info2.vertex[0] = vertex[0];
213- i_marker_info2.vertex[1] = vertex[1];
214- i_marker_info2.vertex[2] = vertex[2];
215- i_marker_info2.vertex[3] = vertex[3];
216- i_marker_info2.vertex[4] = i_marker_info2.coord_num-1;
217-
218- return true;
163+ dmax = 0;
164+ for(i=1;i<coord_num;i++) {// for(i=1;i<marker_info2->coord_num;i++) {
165+ d = (xcoord[i]-sx)*(xcoord[i]-sx)+ (ycoord[i]-sy)*(ycoord[i]-sy);// d = (marker_info2->x_coord[i]-sx)*(marker_info2->x_coord[i]-sx)+ (marker_info2->y_coord[i]-sy)*(marker_info2->y_coord[i]-sy);
166+ if( d > dmax ) {
167+ dmax = d;
168+ v1 = i;
169+ }
219170 }
171+ //NyARMarkerへcoord情報をセット
172+ //coordの並び替えと保存はNyARMarkerへ移動
173+ o_marker.setCoordXY(v1,coord_num,xcoord,ycoord);
174+
175+// int[] wx=new int[v1];//new int[Config.AR_CHAIN_MAX];
176+// int[] wy=new int[v1]; //new int[Config.AR_CHAIN_MAX];
177+// for(i=0;i<v1;i++) {
178+// wx[i] = marker_ref.x_coord[i];//wx[i] = marker_info2->x_coord[i];
179+// wy[i] = marker_ref.y_coord[i];//wy[i] = marker_info2->y_coord[i];
180+// }
181+// for(i=0;i<marker_ref.coord_num-v1;i++) {//for(i=v1;i<marker_info2->coord_num;i++) {
182+// marker_ref.x_coord[i] = marker_ref.x_coord[i+v1];//marker_info2->x_coord[i-v1] = marker_info2->x_coord[i];
183+// marker_ref.y_coord[i] = marker_ref.y_coord[i+v1];//marker_info2->y_coord[i-v1] = marker_info2->y_coord[i];
184+// }
185+// for(i=0;i<v1;i++) {
186+// marker_ref.x_coord[i-v1+marker_ref.coord_num] = wx[i];//marker_info2->x_coord[i-v1+marker_info2->coord_num] = wx[i];
187+// marker_ref.y_coord[i-v1+marker_ref.coord_num] = wy[i];//marker_info2->y_coord[i-v1+marker_info2->coord_num] = wy[i];
188+// }
189+// marker_ref.x_coord[marker_ref.coord_num] = marker_ref.x_coord[0];//marker_info2->x_coord[marker_info2->coord_num] = marker_info2->x_coord[0];
190+// marker_ref.y_coord[marker_ref.coord_num] = marker_ref.y_coord[0];//marker_info2->y_coord[marker_info2->coord_num] = marker_info2->y_coord[0];
191+// marker_ref.coord_num++;//marker_info2->coord_num++;
192+ return;
193+ }
194+
220195 /**
221- * int arGetContour( ARInt16 *limage, int *label_ref,int label, int clip[4], ARMarkerInfo2 *marker_info2 )
196+ * ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double factor, int *marker_num )
222197 * 関数の代替品
223- * detectMarker関数から使う関数です。marker_holder[i_holder_num]にオブジェクトが無ければまず新規に作成し、もし
224- * 既に存在すればそこにマーカー情報を上書きして記録します。
225- * @param limage
226- * @param label_ref
227- * @param label
228- * @param clip
229- * @return
230- * 検出したマーカーからマーカーオブジェクトを生成して返す。
198+ * ラベリング情報からマーカー一覧を作成してo_marker_listを更新します。
199+ * 関数はo_marker_listに重なりを除外したマーカーリストを作成します。
200+ *
201+ * @param i_labeling
202+ * ラベリング済みの情報を持つラベリングオブジェクト
203+ * @param i_factor
204+ * 何かの閾値?
205+ * @param o_marker_list
206+ * 抽出したマーカーを格納するリスト
231207 * @throws NyARException
232208 */
233- private NyARMarker arGetContour(int i_holder_num,short[][] limage, int[] label_ref,int label, int[] clip) throws NyARException
209+ public final void detectMarker(NyARLabeling i_labeling,double i_factor,NyARMarkerList o_marker_list) throws NyARException
234210 {
235- final int[] xdir={0, 1, 1, 1, 0,-1,-1,-1}; //static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
236- final int[] ydir={-1,-1, 0, 1, 1, 1, 0,-1};//static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};
237- //ShortPointer p1;//ARInt16 *p1;
238- int sx=0, sy=0, dir;
239- int dmax, d, v1=0;
240- int i, j;
241-
242- j = clip[2];
243- //p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 = &(limage[j*xsize+clip[0]]);
244- for( i = clip[0]; i <= clip[1]; i++){//for( i = clip[0]; i <= clip[1]; i++, p1++ ) {
245- if(limage[j][i] > 0 && label_ref[(limage[j][i])-1] == label ) {//if( *p1 > 0 && label_ref[(*p1)-1] == label ) {
246- sx = i; sy = j;
247- break;
248- }
249- }
250- if(i> clip[1]){//if( i > clip[1] ) {
251- System.out.println("??? 1");//printf();
252- throw new NyARException();//return(-1);
253- }
254-
255- //マーカーホルダが既に確保済みかを調べる
256- if(marker_holder[i_holder_num]==null){
257- //確保していなければ確保
258- marker_holder[i_holder_num]=new NyARMarker();
259- }
260- NyARMarker marker_ref=marker_holder[i_holder_num];
211+ int i;
212+ int xsize, ysize;
213+ NyARLabel[] labels=i_labeling.getLabel();
214+// int[] warea =i_labeling.getArea();
215+ int label_num =i_labeling.getLabelNum();
216+// int[][] wclip =i_labeling.getClip();
217+// double[] wpos =i_labeling.getPos();
218+ int[][] limage=i_labeling.getLabelImg();
219+ int[] label_ref =i_labeling.getLabelRef();
261220
262-
263- marker_ref.coord_num=1;//marker_info2->coord_num = 1;
264- marker_ref.x_coord[0]=sx;//marker_info2->x_coord[0] = sx;
265- marker_ref.y_coord[0]=sy;//marker_info2->y_coord[0] = sy;
266- dir = 5;
267-
268- for(;;){
269- int r=marker_ref.y_coord[marker_ref.coord_num-1];
270- int c=marker_ref.x_coord[marker_ref.coord_num-1];
271- //p1 = &(limage[marker_info2->y_coord[marker_info2->coord_num-1] * xsize+ marker_info2->x_coord[marker_info2->coord_num-1]]);
272- dir = (dir+5)%8;
273- for(i=0;i<8;i++) {
274- if(limage[r+ydir[dir]][c+xdir[dir]]>0){//if( p1[ydir[dir]*xsize+xdir[dir]] > 0 ){
275- break;
276- }
277- dir = (dir+1)%8;
278- }
279- if( i == 8 ){
280- System.out.println("??? 2");//printf("??? 2\n");
281- throw new NyARException();//return(-1);
282- }
283- marker_ref.x_coord[marker_ref.coord_num]= marker_ref.x_coord[marker_ref.coord_num-1] + xdir[dir];//marker_info2->x_coord[marker_info2->coord_num]= marker_info2->x_coord[marker_info2->coord_num-1] + xdir[dir];
284- marker_ref.y_coord[marker_ref.coord_num]= marker_ref.y_coord[marker_ref.coord_num-1] + ydir[dir];//marker_info2->y_coord[marker_info2->coord_num]= marker_info2->y_coord[marker_info2->coord_num-1] + ydir[dir];
285- if( marker_ref.x_coord[marker_ref.coord_num] == sx && marker_ref.y_coord[marker_ref.coord_num] == sy ){
286- break;
287- }
288- marker_ref.coord_num++;
289- if( marker_ref.coord_num == marker_ref.x_coord.length-1){//if( marker_info2.coord_num == Config.AR_CHAIN_MAX-1 ){
290- System.out.println("??? 3");//printf("??? 3\n");
291- throw new NyARException();//return(-1);
292- }
293- }
294-
295- dmax = 0;
296- for(i=1;i<marker_ref.coord_num;i++) {// for(i=1;i<marker_info2->coord_num;i++) {
297- d = (marker_ref.x_coord[i]-sx)*(marker_ref.x_coord[i]-sx)+ (marker_ref.y_coord[i]-sy)*(marker_ref.y_coord[i]-sy);// d = (marker_info2->x_coord[i]-sx)*(marker_info2->x_coord[i]-sx)+ (marker_info2->y_coord[i]-sy)*(marker_info2->y_coord[i]-sy);
298- if( d > dmax ) {
299- dmax = d;
300- v1 = i;
301- }
302- }
221+ //マーカーホルダをリセット
222+ o_marker_list.reset();
223+// marker_num=0;
224+ xsize =width;
225+ ysize =height;
226+// マーカーをmarker_holderに蓄積する。
227+ NyARMarker current_marker=o_marker_list.getCurrentHolder();
228+ NyARLabel label_pt;
229+ for(i=0; i<label_num; i++ ){
230+ label_pt=labels[i];
231+ if( label_pt.area < AR_AREA_MIN || label_pt.area > AR_AREA_MAX ){
232+ continue;
233+ }
234+ if( label_pt.clip0 == 1 || label_pt.clip1 == xsize-2 ){//if( wclip[i*4+0] == 1 || wclip[i*4+1] == xsize-2 ){
235+ continue;
236+ }
237+ if( label_pt.clip2 == 1 || label_pt.clip3 == ysize-2 ){//if( wclip[i*4+2] == 1 || wclip[i*4+3] == ysize-2 ){
238+ continue;
239+ }
240+ //ret = arGetContour( limage, label_ref, i+1,&(wclip[i*4]), &(marker_info2[marker_num2]));
241+ arGetContour(current_marker,limage, label_ref, i+1,label_pt);
303242
304- int[] wx=new int[v1];//new int[Config.AR_CHAIN_MAX];
305- int[] wy=new int[v1]; //new int[Config.AR_CHAIN_MAX];
306- for(i=0;i<v1;i++) {
307- wx[i] = marker_ref.x_coord[i];//wx[i] = marker_info2->x_coord[i];
308- wy[i] = marker_ref.y_coord[i];//wy[i] = marker_info2->y_coord[i];
309- }
310- for(i=v1;i<marker_ref.coord_num;i++) {//for(i=v1;i<marker_info2->coord_num;i++) {
311- marker_ref.x_coord[i-v1] = marker_ref.x_coord[i];//marker_info2->x_coord[i-v1] = marker_info2->x_coord[i];
312- marker_ref.y_coord[i-v1] = marker_ref.y_coord[i];//marker_info2->y_coord[i-v1] = marker_info2->y_coord[i];
313- }
314- for(i=0;i<v1;i++) {
315- marker_ref.x_coord[i-v1+marker_ref.coord_num] = wx[i];//marker_info2->x_coord[i-v1+marker_info2->coord_num] = wx[i];
316- marker_ref.y_coord[i-v1+marker_ref.coord_num] = wy[i];//marker_info2->y_coord[i-v1+marker_info2->coord_num] = wy[i];
317- }
318- marker_ref.x_coord[marker_ref.coord_num] = marker_ref.x_coord[0];//marker_info2->x_coord[marker_info2->coord_num] = marker_info2->x_coord[0];
319- marker_ref.y_coord[marker_ref.coord_num] = marker_ref.y_coord[0];//marker_info2->y_coord[marker_info2->coord_num] = marker_info2->y_coord[0];
320- marker_ref.coord_num++;//marker_info2->coord_num++;
321-
322- return marker_ref;
323- }
324- /**
325- * ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double factor, int *marker_num )
326- * 関数の代替品
327- * ラベリング情報からマーカー一覧を作成して保持します。
328- * この関数を実行すると、前回のdetectMarker関数で計算した保持値は破壊されます。
329- * @param i_labeling
330- * ラベリング済みの情報を持つラベリングオブジェクト
331- * @param factor
332- * 何かの閾値?
333- * @return
334- * @throws NyARException
335- */
336-// public void detectMarker(short[][] limage,int label_num,int[] label_ref,int[] warea,double[] wpos,int[] wclip,int area_max, int area_min, double factor) throws JartkException
337- public void detectMarker(NyARLabeling i_labeling,double factor) throws NyARException
338- {
339- int xsize, ysize;
340- int marker_num2;
341- double d;
342- int[] warea =i_labeling.getArea();
343- int label_num =i_labeling.getLabelNum();
344- int[][] wclip =i_labeling.getClip();
345- double[] wpos =i_labeling.getPos();
346- short[][] limage =i_labeling.getLabelImg();
347- int[] label_ref =i_labeling.getLabelRef();
348-
349- marker_num=0;
350- xsize =width;
351- ysize =height;
352-
353- marker_num2 = 0;
354- for(int i=0; i<label_num; i++ ) {
355- if( warea[i] < area_min || warea[i] > area_max ){
356- continue;
357- }
358- if( wclip[i][0] == 1 || wclip[i][1] == xsize-2 ){//if( wclip[i*4+0] == 1 || wclip[i*4+1] == xsize-2 ){
359- continue;
360- }
361- if( wclip[i][2] == 1 || wclip[i][3] == ysize-2 ){//if( wclip[i*4+2] == 1 || wclip[i*4+3] == ysize-2 ){
362- continue;
363- }
364- //ret = arGetContour( limage, label_ref, i+1,&(wclip[i*4]), &(marker_info2[marker_num2]));
365- arGetContour(marker_num2,limage, label_ref, i+1,wclip[i]);
366-
367- boolean ret = check_square( warea[i], marker_holder[marker_num2], factor );//ret = check_square( warea[i], &(marker_info2[marker_num2]), factor );
368- if(!ret){
369- //後半で整理するからここはいらない。// marker_holder[marker_num2]=null;
370- continue;
371- }
372- marker_holder[marker_num2].area = warea[i];
373- marker_holder[marker_num2].pos[0] = wpos[i*2+0];
374- marker_holder[marker_num2].pos[1] = wpos[i*2+1];
375- marker_num2++;
376- //マーカーリストが上限に達した
377- if( marker_num2 == marker_holder.length){
378- break;
379- }
380- }
381- for(int i=0; i < marker_num2; i++ ) {
382- for(int j=i+1; j < marker_num2; j++ ) {
383- d = (marker_holder[i].pos[0] - marker_holder[j].pos[0])*
384- (marker_holder[i].pos[0] - marker_holder[j].pos[0])+
385- (marker_holder[i].pos[1] - marker_holder[j].pos[1])*
386- (marker_holder[i].pos[1] - marker_holder[j].pos[1]);
387- if(marker_holder[i].area >marker_holder[j].area ) {
388- if( d <marker_holder[i].area / 4 ) {
389- marker_holder[j].area = 0;
390- }
391- }else{
392- if( d < marker_holder[j].area / 4 ) {
393- marker_holder[i].area = 0;
394- }
395- }
396- }
397- }
398- //みつかったマーカーを整理する。
399- //エリアが0のマーカーを外した配列を作って、その数もついでに計算
400- for(int i=0;i<marker_num2;i++){
401- if(marker_holder[i].area==0.0){
402- continue;
403- }
404- marker_info2_array[marker_num]=marker_holder[i];
405- marker_num++;
406- }
407-// for( i=0; i < marker_num2; i++ ) {
408-// if( marker_info2_array[i].area == 0.0 ) {
409-// for( j=i+1; j < marker_num2; j++ ){
410-// marker_info2_array[j-1] = marker_info2_array[j];
411-// }
412-// marker_num2--;
413-// }
414-// }
415- //発見したマーカー数をセット
416-// marker_num=marker_num2;//*marker_num = marker_num2;
417- //return( &(marker_info2[0]) );
243+ if(!current_marker.checkSquare(label_pt.area,i_factor,label_pt.pos_x,label_pt.pos_y)){
244+ //後半で整理するからここはいらない。// marker_holder[marker_num2]=null;
245+ continue;
246+ }
247+// この3行はcheckSquareの最終段に含める。
248+// marker_holder[marker_num2].area = warea[i];
249+// marker_holder[marker_num2].pos[0] = wpos[i*2+0];
250+// marker_holder[marker_num2].pos[1] = wpos[i*2+1];
251+ //マーカー検出→次のホルダを取得
252+ current_marker=o_marker_list.getNextHolder();
253+ //マーカーリストが上限に達したか確認
254+ if(current_marker==null){
255+ break;
256+ }
257+ }
258+ //マーカーリストを整理(重なり処理とかはマーカーリストに責務押し付け)
259+ o_marker_list.updateMarkerArray();
260+// 重なり処理かな?
261+// double[] pos_j,pos_i;
262+// for(i=0; i < marker_num2; i++ ){
263+// pos_i=marker_holder[i].pos;
264+// for(j=i+1; j < marker_num2; j++ ) {
265+// pos_j=marker_holder[j].pos;
266+// d = (pos_i[0] - pos_j[0])*(pos_i[0] - pos_j[0])+
267+// (pos_i[1] - pos_j[1])*(pos_i[1] - pos_j[1]);
268+// if(marker_holder[i].area >marker_holder[j].area ) {
269+// if( d <marker_holder[i].area / 4 ) {
270+// marker_holder[j].area = 0;
271+// }
272+// }else{
273+// if( d < marker_holder[j].area / 4 ) {
274+// marker_holder[i].area = 0;
275+// }
276+// }
277+// }
278+// }
279+// みつかったマーカーを整理する。
280+// エリアが0のマーカーを外した配列を作って、その数もついでに計算
281+// for(i=0;i<marker_num2;i++){
282+// if(marker_holder[i].area==0.0){
283+// continue;
284+// }
285+// marker_info2_array[marker_num]=marker_holder[i];
286+// marker_num++;
287+// }
288+// for( i=0; i < marker_num2; i++ ) {
289+// if( marker_info2_array[i].area == 0.0 ) {
290+// for( j=i+1; j < marker_num2; j++ ){
291+// marker_info2_array[j-1] = marker_info2_array[j];
292+// }
293+// marker_num2--;
294+// }
295+// }
296+// 発見したマーカー数をセット
297+// marker_num=marker_num2;//*marker_num = marker_num2;
298+// return( &(marker_info2[0]) );
299+ return;
418300 }
419301
420302 }
--- a/trunk/src/jp/nyatla/nyartoolkit/core/NyARDetectSquare.java
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARDetectSquare.java
@@ -31,146 +31,73 @@
3131 */
3232 package jp.nyatla.nyartoolkit.core;
3333
34-import jp.nyatla.util.DoubleValue;
3534 import jp.nyatla.nyartoolkit.NyARException;
3635 import jp.nyatla.nyartoolkit.core.raster.*;
3736
3837
39-public class NyARDetectSquare{
40- private NyARLabeling labeling;
41- private NyARDetectMarker detect;
4238
43- private NyARSquare[] marker_info;
44- private int number_of_square;
39+public class NyARDetectSquare
40+{
41+ private final NyARLabeling labeling;
42+ private final NyARDetectMarker detect;
4543 private NyARParam param;
4644
4745 /**
48- * 最大i_sqaure_max個のマーカー情報を抽出できるインスタンスを作る。
49- * @param i_sqaure_max
46+ * マーカー抽出インスタンスを作ります。
47+ * @param i_param
5048 */
51- public NyARDetectSquare(int i_sqaure_max,NyARParam i_param)
49+ public NyARDetectSquare(NyARParam i_param)
5250 {
5351 param=i_param;
54- marker_info=new NyARSquare[i_sqaure_max];//static ARMarkerInfo marker_infoL[AR_SQUARE_MAX];
5552 //解析オブジェクトを作る
5653 int width=i_param.getX();
5754 int height=i_param.getY();
5855
59- labeling=new NyARLabeling(width,height);
60- detect=new NyARDetectMarker(width,height,i_sqaure_max);
61- }
62- public NyARSquare[] getSquareArray()
63- {
64- return marker_info;
65- }
66- public int getSquareCount()
67- {
68- return number_of_square;
56+ labeling=new NyARLabeling_O2(width,height);
57+ detect=new NyARDetectMarker(width,height);
6958 }
7059 /**
71- * 矩形を検出する。
60+ * ラスタイメージから矩形を検出して、結果o_square_holderへ格納します。
7261 * @param i_marker
7362 * @param i_number_of_marker
63+ * @param i_square_holder
7464 * @throws NyARException
7565 */
76- public void detectSquare(NyARRaster i_image,int i_thresh) throws NyARException
66+ public void detectSquare(NyARRaster i_image,int i_thresh,NyARSquareList o_square_holder) throws NyARException
7767 {
78- number_of_square=0;
68+// number_of_square=0;
7969 labeling.labeling(i_image, i_thresh);
8070 if(labeling.getLabelNum()<1){
8171 return;
8272 }
83- detect.detectMarker(labeling,1.0);
84- int number_of_marker=detect.getMarkerNum();
85-
86-
73+ //ここでマーカー配列を作成する。
74+ detect.detectMarker(labeling,1.0,o_square_holder);
8775
88- int j=0;
89- for (int i = 0; i <number_of_marker; i++){
90- double[][] line =new double[4][3];
91- double[][] vertex =new double[4][2];
92- NyARMarker marker=detect.getMarker(i);
93-
94- //・・・線の検出??
95- if (!getLine(marker.x_coord, marker.y_coord,marker.coord_num, marker.vertex,line,vertex))
96- {
97- continue;
98- }
99- //markerは参照渡し。実体はdetect内のバッファを共有してるので注意
100- marker_info[j]=new NyARSquare(marker,line,vertex);
76+ //マーカー情報をフィルタして、スクエア配列を更新する。
77+ o_square_holder.updateSquareArray(param);
10178
102-
103-//ここで計算するのは良くないと思うんだ
104-// marker_infoL[j].id = id.get();
105-// marker_infoL[j].dir = dir.get();
106-// marker_infoL[j].cf = cf.get();
107- j++;
108- //配列数こえたらドゴォォォンしないようにループを抜ける
109- if(j>=marker_info.length){
110- break;
111- }
112- }
113- number_of_square=j;
114- }
115- /**
116- * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2])
117- * arGetLine2(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2], double *dist_factor)
118- * の2関数の合成品です。
119- * @param x_coord
120- * @param y_coord
121- * @param coord_num
122- * @param vertex
123- * @param line
124- * @param v
125- * @return
126- * @throws NyARException
127- */
128- private boolean getLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[][], double v[][]) throws NyARException
129- {
130- NyARMat input,evec;
131- NyARVec ev,mean;
132- double w1;
133- int st, ed, n;
134- int i, j;
135- DoubleValue dv1=new DoubleValue();
136- DoubleValue dv2=new DoubleValue();
137-
138- ev = new NyARVec(2);
139- mean = new NyARVec(2);
140- evec = new NyARMat(2,2);
141- double[] mean_array=mean.getArray();
142- double[][] evec_array=evec.getArray();
143- for( i = 0; i < 4; i++ ) {
144- w1 = (double)(vertex[i+1]-vertex[i]+1) * 0.05 + 0.5;
145- st = (int)(vertex[i] + w1);
146- ed = (int)(vertex[i+1] - w1);
147- n = ed - st + 1;
148- if(n<2){//nが2以下でmatrix.PCAを計算することはできないので、エラーにしておく。
149- //System.err.println("NyARDetectSquare::getLine 稀に出るエラーです。このエラーが出ても例外が起こらなければ平気だと思いますが、出たらnyatlaまで連絡してください。");
150- return false;//throw new NyARException();
151- }
152- input = new NyARMat( n, 2 );
153- double [][] in_array=input.getArray();
154- for( j = 0; j < n; j++ ) {
155- param.observ2Ideal(x_coord[st+j], y_coord[st+j],dv1,dv2);//arParamObserv2Ideal( dist_factor, x_coord[st+j], y_coord[st+j],&(input->m[j*2+0]), &(input->m[j*2+1]) );
156- in_array[j][0]=dv1.value;
157- in_array[j][1]=dv2.value;
158- }
159- NyARMat.matrixPCA(input, evec, ev, mean);
160-
161- line[i][0] = evec_array[0][1];//line[i][0] = evec->m[1];
162- line[i][1] = -evec_array[0][0];//line[i][1] = -evec->m[0];
163- line[i][2] = -(line[i][0]*mean_array[0] + line[i][1]*mean_array[1]);//line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);
164- }
165-
166- for( i = 0; i < 4; i++ ) {
167- w1 = line[(i+3)%4][0] * line[i][1] - line[i][0] * line[(i+3)%4][1];
168- if( w1 == 0.0 ){
169- return false;
170- }
171- v[i][0] = ( line[(i+3)%4][1] * line[i][2]- line[i][1] * line[(i+3)%4][2] ) / w1;
172- v[i][1] = ( line[i][0] * line[(i+3)%4][2]- line[(i+3)%4][0] * line[i][2] ) / w1;
173- }
174- return true;
79+// NyARSquare square;
80+// int j=0;
81+// for (int i = 0; i <number_of_marker; i++){
82+// double[][] line =new double[4][3];
83+// double[][] vertex =new double[4][2];
84+// //NyARMarker marker=detect.getMarker(i);
85+// square=square_holder.getSquare(i);
86+// //・・・線の検出??
87+// if (!square.getLine(param))
88+// {
89+// continue;
90+// }
91+// ここで計算するのは良くないと思うんだ
92+// marker_infoL[j].id = id.get();
93+// marker_infoL[j].dir = dir.get();
94+// marker_infoL[j].cf = cf.get();
95+// j++;
96+// //配列数こえたらドゴォォォンしないようにループを抜ける
97+// if(j>=marker_info.length){
98+// break;
99+// }
100+// }
101+// number_of_square=j;
175102 }
176103 }
--- a/trunk/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java
@@ -35,20 +35,186 @@ import jp.nyatla.nyartoolkit.NyARException;
3535 import jp.nyatla.nyartoolkit.core.raster.*;
3636
3737
38+interface NyARLabeling{
39+ /**
40+ * 検出したラベルの数を返す
41+ * @return
42+ */
43+ public int getLabelNum();
44+ /**
45+ *
46+ * @return
47+ * @throws NyARException
48+ */
49+ public int[] getLabelRef() throws NyARException;
50+ /**
51+ * 検出したラベル配列
52+ * @return
53+ * @throws NyARException
54+ */
55+ public NyARLabel[] getLabel() throws NyARException;
56+ /**
57+ * ラベリング済みイメージを返す
58+ * @return
59+ * @throws NyARException
60+ */
61+ public int[][] getLabelImg() throws NyARException;
62+ /**
63+ * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR )
64+ * 関数の代替品
65+ * ラスタimageをラベリングして、結果を保存します。
66+ * Optimize:STEP[1514->1493]
67+ * @param image
68+ * @param thresh
69+ * @throws NyARException
70+ */
71+ public void labeling(NyARRaster image,int thresh) throws NyARException;
72+}
73+
74+
75+
76+
77+/**
78+ * NyARLabeling_O2のworkとwork2を可変長にするためのクラス
79+ *
80+ *
81+ */
82+class NyARWorkHolder
83+{
84+ private final static int ARRAY_APPEND_STEP=256;
85+ public final int[] work;
86+ public final int[][] work2;
87+ private int allocate_size;
88+ /**
89+ * 最大i_holder_size個の動的割り当てバッファを準備する。
90+ * @param i_holder_size
91+ */
92+ public NyARWorkHolder(int i_holder_size)
93+ {
94+ //ポインタだけははじめに確保しておく
95+ this.work=new int[i_holder_size];
96+ this.work2=new int[i_holder_size][];
97+ this.allocate_size=0;
98+ }
99+ /**
100+ * i_indexで指定した番号までのバッファを準備する。
101+ * @param i_index
102+ */
103+ public final void reserv(int i_index) throws NyARException
104+ {
105+ //アロケート済みなら即リターン
106+ if(this.allocate_size>i_index){
107+ return;
108+ }
109+ //要求されたインデクスは範囲外
110+ if(i_index>=this.work.length){
111+ throw new NyARException();
112+ }
113+ //追加アロケート範囲を計算
114+ int range=i_index+ARRAY_APPEND_STEP;
115+ if(range>=this.work.length){
116+ range=this.work.length;
117+ }
118+ //アロケート
119+ for(int i=this.allocate_size;i<range;i++)
120+ {
121+ this.work2[i]=new int[7];
122+ }
123+ this.allocate_size=range;
124+ }
125+}
126+
127+class NyARLabel
128+{
129+ public int area;
130+ public int clip0;
131+ public int clip1;
132+ public int clip2;
133+ public int clip3;
134+ public double pos_x;
135+ public double pos_y;
136+}
137+
138+
139+class NyARLabelHolder
140+{
141+ private final static int ARRAY_APPEND_STEP=128;
142+ public final NyARLabel[] labels;
143+ private int allocate_size;
144+ /**
145+ * 最大i_holder_size個の動的割り当てバッファを準備する。
146+ * @param i_holder_size
147+ */
148+ public NyARLabelHolder(int i_holder_size)
149+ {
150+ //ポインタだけははじめに確保しておく
151+ this.labels=new NyARLabel[i_holder_size];
152+ this.allocate_size=0;
153+ }
154+ /**
155+ * i_indexで指定した番号までのバッファを準備する。
156+ * @param i_index
157+ */
158+ private final void reserv(int i_index) throws NyARException
159+ {
160+ //アロケート済みなら即リターン
161+ if(this.allocate_size>i_index){
162+ return;
163+ }
164+ //要求されたインデクスは範囲外
165+ if(i_index>=this.labels.length){
166+ throw new NyARException();
167+ }
168+ //追加アロケート範囲を計算
169+ int range=i_index+ARRAY_APPEND_STEP;
170+ if(range>=this.labels.length){
171+ range=this.labels.length;
172+ }
173+ //アロケート
174+ for(int i=this.allocate_size;i<range;i++)
175+ {
176+ this.labels[i]=new NyARLabel();
177+ }
178+ this.allocate_size=range;
179+ }
180+ /**
181+ * i_reserv_sizeまでのバッファを、初期条件i_lxsizeとi_lysizeで初期化する。
182+ * @param i_reserv_size
183+ * @param i_lxsize
184+ * @param i_lysize
185+ * @throws NyARException
186+ */
187+ public final void init(int i_reserv_size,int i_lxsize,int i_lysize) throws NyARException
188+ {
189+ reserv(i_reserv_size);
190+ NyARLabel l;
191+ for(int i=0;i<i_reserv_size;i++){
192+ l=this.labels[i];
193+ l.area=0;
194+ l.pos_x=0;
195+ l.pos_y=0;
196+ l.clip0= i_lxsize;//wclip[i*4+0] = lxsize;
197+ l.clip1= 0;//wclip[i*4+0] = lxsize;
198+ l.clip2= i_lysize;//wclip[i*4+2] = lysize;
199+ l.clip3= 0;//wclip[i*4+3] = 0;
200+ }
201+ }
202+}
38203
39204
40205 /**
41206 * ラベリングクラス。NyARRasterをラベリングして、結果値を保持します。
207+ * 構造を維持して最適化をしたバージョン
42208 *
43209 */
44-public class NyARLabeling{
45- private final int WORK_SIZE=1024*32;//#define WORK_SIZE 1024*32
46- private short[][] label_img;//static ARInt16 l_imageL[HARDCODED_BUFFER_WIDTH*HARDCODED_BUFFER_HEIGHT];
47- private int[] work=new int[WORK_SIZE];//static int workL[WORK_SIZE];
48- private int[] work2=new int[WORK_SIZE*7];//static int work2L[WORK_SIZE*7];
49- private int[] area=new int[WORK_SIZE];//static int wareaL[WORK_SIZE];
50- private int[][] clip=new int[WORK_SIZE][4];//static int wclipL[WORK_SIZE*4];
51- private double[] pos=new double[WORK_SIZE*2];//static double wposL[WORK_SIZE*2];
210+class NyARLabeling_O2 implements NyARLabeling
211+{
212+ private static final int WORK_SIZE=1024*32;//#define WORK_SIZE 1024*32
213+ private final int[][] glabel_img;//static ARInt16 l_imageL[HARDCODED_BUFFER_WIDTH*HARDCODED_BUFFER_HEIGHT];
214+
215+ private final NyARWorkHolder work_holder=new NyARWorkHolder(WORK_SIZE);
216+ private final NyARLabelHolder label_holder=new NyARLabelHolder(WORK_SIZE);
217+
52218 private int label_num;
53219 //
54220 private int width;
@@ -59,11 +225,11 @@ public class NyARLabeling{
59225 * @param i_height
60226 * ラベリング画像の高さ。解析するラスタの高さより大きいこと。
61227 */
62- public NyARLabeling(int i_width,int i_height)
228+ public NyARLabeling_O2(int i_width,int i_height)
63229 {
64230 width =i_width;
65231 height=i_height;
66- label_img=new short[height][width];
232+ glabel_img=new int[height][width];
67233 label_num=0;
68234 }
69235 /**
@@ -75,268 +241,245 @@ public class NyARLabeling{
75241 return label_num;
76242 }
77243 /**
78- *
79- * @return
80- * @throws NyARException
81- */
82- public int[] getLabelRef() throws NyARException
83- {
84- if(label_num<1){
85- throw new NyARException();
86- }
87- return work;
88- }
89- /**
90244 * 検出したエリア配列?
91245 * @return
92246 * @throws NyARException
93247 */
94- public int[] getArea() throws NyARException
248+ public NyARLabel[] getLabel() throws NyARException
95249 {
96250 if(label_num<1){
97251 throw new NyARException();
98252 }
99- return area;
100- }
253+ return this.label_holder.labels;
254+ }
101255 /**
102- * 検出したクリップ配列?
256+ *
103257 * @return
104258 * @throws NyARException
105259 */
106- public int[][] getClip() throws NyARException
260+ public int[] getLabelRef() throws NyARException
107261 {
108262 if(label_num<1){
109263 throw new NyARException();
110264 }
111- return clip;
265+ return work_holder.work;
112266 }
113267 /**
114- * 検出した位置配列?
268+ * ラベリング済みイメージを返す
115269 * @return
116270 * @throws NyARException
117271 */
118- public double[] getPos() throws NyARException
272+ public int[][] getLabelImg() throws NyARException
119273 {
120- if(label_num<1){
121- throw new NyARException();
122- }
123- return pos;
274+ return glabel_img;
124275 }
276+
277+ private int[] wk_reservLineBuffer_buf=null;
125278 /**
126- * ラベリング済みイメージを返す
279+ * ラベリング関数から使うラインスキャン用メモリの予約関数です。
280+ * i_widthピクセル分のラインスキャン用バッファを保障します。
281+ * @param i_width
127282 * @return
128- * @throws NyARException
129283 */
130- public short[][] getLabelImg() throws NyARException
284+ private int[] reservWorkLineBuffer(int i_width)
131285 {
132- if(label_num<1){
133- throw new NyARException();
286+ int[] buf=this.wk_reservLineBuffer_buf;
287+ if(buf==null){
288+ buf=new int[i_width];
289+ this.wk_reservLineBuffer_buf=buf;
290+ }else{
291+ if(buf.length<i_width){
292+ buf=new int[i_width];
293+ this.wk_reservLineBuffer_buf=buf;
294+ }
295+ //十分なら何もしない。
134296 }
135- return label_img;
136- }
137- /**
138- * 配列の先頭からsize個をゼロクリアする
139- * @param array
140- * @param size
141- */
142- private void putZero(int[] array,int size)
143- {
144- for(int i=0;i<size;i++){
145- array[i]=0;
146- }
147- }
148- /**
149- * 配列の先頭からsize個をゼロクリアする
150- * @param array
151- * @param size
152- */
153- private void putZero(double[] array,int size)
154- {
155- for(int i=0;i<size;i++){
156- array[i]=0;
157- }
297+ return buf;
158298 }
159299 /**
160300 * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR )
161301 * 関数の代替品
162302 * ラスタimageをラベリングして、結果を保存します。
303+ * Optimize:STEP[1514->1493]
163304 * @param image
164305 * @param thresh
165306 * @throws NyARException
166307 */
167308 public void labeling(NyARRaster image,int thresh) throws NyARException
168309 {
169- int wk_max; /* work */
170- int m,n; /* work */
171- int lxsize, lysize;
172- int[] warea;//int *warea;
173- int[][] wclip;//int *wclip;
174- double[] wpos;//double *wpos;
175- int thresht3 = thresh * 3;
176-
177- //ラベル数を0に初期化
178- label_num=0;
179-
180- warea=area;//warea = &wareaL[0];
181- wclip=clip;//wclip = &wclipL[0];
182- wpos=pos;//wpos = &wposL[0];
183-
184- lxsize=image.getWidth();//lxsize = arUtil_c.arImXsize;
185- lysize=image.getHeight();//lysize = arUtil_c.arImYsize;
186-
187- for(int i = 0; i < lxsize; i++){
188- label_img[0][i]=0;
189- label_img[lysize-1][i]=0;
190- }
191- for(int i = 0; i < lysize; i++) {
192- label_img[i][0]=0;
193- label_img[i][lxsize-1]=0;
194- }
195- int nya_pnt_start_x_start,nya_pnt_start_y_start;
196- int nya_poff_step;//スキャンステップ
197-
198- wk_max = 0;
199- nya_pnt_start_y_start=1;
200- nya_pnt_start_x_start=1;
201- nya_poff_step=1;//スキャンステップ
202- int nya_pnt_start_y=nya_pnt_start_y_start;
203- for (int j = 1; j < lysize - 1; j++, nya_pnt_start_y++) {//for (int j = 1; j < lysize - 1; j++, pnt += poff*2, pnt2 += 2) {
204- int nya_pnt_start_x=nya_pnt_start_x_start;
205- int p1=j-1;
206- int p2=j;
207- for(int i = 1; i < lxsize-1; i++, nya_pnt_start_x+=nya_poff_step) {//for(int i = 1; i < lxsize-1; i++, pnt+=poff, pnt2++) {
310+ int wk_max; /* work */
311+ int m,n; /* work */
312+ int lxsize, lysize;
313+ int thresht3 = thresh * 3;
314+ int i,j,k;
315+
316+ //ラベル数を0に初期化
317+ this.label_num=0;
318+// int[][] work2=this.wk_labeling_work2;
319+// int[] work=this.gwork;
320+
321+ int[][] label_img=this.glabel_img;
322+
323+ lxsize=image.getWidth();//lxsize = arUtil_c.arImXsize;
324+ lysize=image.getHeight();//lysize = arUtil_c.arImYsize;
325+
326+ int[] label_img_pt0,label_img_pt1;
327+
328+ //<Optimize>label_img_pt0,label_img_pt1
329+ label_img_pt0=label_img[0];
330+ label_img_pt1=label_img[lysize-1];
331+ for(i = 0; i < lxsize; i++){
332+ label_img_pt0[i]=0;
333+ label_img_pt1[i]=0;
334+ }
335+ //</Optimize>
336+ for(i = 0; i < lysize; i++) {
337+ label_img[i][0]=0;
338+ label_img[i][lxsize-1]=0;
339+ }
340+
341+ int[] work2_pt;
342+ wk_max = 0;
343+
344+ int label_pixel;
345+
346+ int[] work=this.work_holder.work;
347+ int[][] work2=this.work_holder.work2;
348+ //1ライン分のメモリを予約
349+ int[] line_bufferr=reservWorkLineBuffer(lxsize);
350+
351+ for(j = 1; j < lysize - 1; j++) {//for (int j = 1; j < lysize - 1; j++, pnt += poff*2, pnt2 += 2) {
352+ label_img_pt0=label_img[j];
353+ label_img_pt1=label_img[j-1];
354+ image.getPixelTotalRowLine(j,line_bufferr);
355+
356+ for(i = 1; i < lxsize-1; i++) {//for(int i = 1; i < lxsize-1; i++, pnt+=poff, pnt2++) {
208357 //RGBの合計値が閾値より大きいかな?
209- if(image.getPixelTotal(nya_pnt_start_x,nya_pnt_start_y)<=thresht3){
358+ if(line_bufferr[i]<=thresht3){
210359 //pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 = &(pnt2[-lxsize]);
211- if(label_img[p1][i]>0){//if( *pnt1 > 0 ) {
212- label_img[p2][i]=label_img[p1][i];//*pnt2 = *pnt1;
213-
214-
215- int p2_index=(label_img[p2][i]-1)*7;
216- work2[p2_index+0]++;//work2[((*pnt2)-1)*7+0] ++;
217- work2[p2_index+1]+=i;//work2[((*pnt2)-1)*7+1] += i;
218- work2[p2_index+2]+=j;//work2[((*pnt2)-1)*7+2] += j;
219- work2[p2_index+6]=j;//work2[((*pnt2)-1)*7+6] = j;
220- }else if(label_img[p1][i+1]> 0 ) {//}else if( *(pnt1+1) > 0 ) {
221- if(label_img[p1][i-1] > 0 ) {//if( *(pnt1-1) > 0 ) {
222- m = work[label_img[p1][i+1]-1];//m = work[*(pnt1+1)-1];
223- n = work[label_img[p1][i-1]-1];//n = work[*(pnt1-1)-1];
360+ if(label_img_pt1[i]>0){//if( *pnt1 > 0 ) {
361+ label_pixel=label_img_pt1[i];//*pnt2 = *pnt1;
362+
363+
364+ work2_pt=work2[label_pixel-1];
365+ work2_pt[0]++;//work2[((*pnt2)-1)*7+0] ++;
366+ work2_pt[1]+=i;//work2[((*pnt2)-1)*7+1] += i;
367+ work2_pt[2]+=j;//work2[((*pnt2)-1)*7+2] += j;
368+ work2_pt[6]=j;//work2[((*pnt2)-1)*7+6] = j;
369+ }else if(label_img_pt1[i+1]> 0 ) {//}else if( *(pnt1+1) > 0 ) {
370+ if(label_img_pt1[i-1] > 0 ) {//if( *(pnt1-1) > 0 ) {
371+ m = work[label_img_pt1[i+1]-1];//m = work[*(pnt1+1)-1];
372+ n = work[label_img_pt1[i-1]-1];//n = work[*(pnt1-1)-1];
224373 if( m > n ){
225- //JartkException.trap("未チェックのパス");
226- label_img[p2][i]=(short)n;//*pnt2 = n;
374+ label_pixel=n;//*pnt2 = n;
227375 //wk=IntPointer.wrap(work, 0);//wk = &(work[0]);
228- for(int k = 0; k < wk_max; k++) {
229- //JartkException.trap("未チェックのパス");
376+ for(k = 0; k < wk_max; k++) {
230377 if(work[k] == m ){//if( *wk == m )
231- //JartkException.trap("未チェックのパス");
232378 work[k]=n;//*wk = n;
233379 }
234380 }
235381 }else if( m < n ) {
236- //JartkException.trap("未チェックのパス");
237- label_img[p2][i]=(short)m;//*pnt2 = m;
382+ label_pixel=m;//*pnt2 = m;
238383 //wk=IntPointer.wrap(work,0);//wk = &(work[0]);
239- for(int k = 0; k < wk_max; k++){
240- //JartkException.trap("未チェックのパス");
384+ for(k = 0; k < wk_max; k++){
241385 if(work[k]==n){//if( *wk == n ){
242- //JartkException.trap("未チェックのパス");
243386 work[k]=m;//*wk = m;
244387 }
245388 }
246389 }else{
247- label_img[p2][i]=(short)m;//*pnt2 = m;
390+ label_pixel=m;//*pnt2 = m;
248391 }
249-
250- int p2_index=(label_img[p2][i]-1)*7;
251- work2[p2_index+0] ++;
252- work2[p2_index+1] += i;
253- work2[p2_index+2] += j;
254- work2[p2_index+6] = j;
255- }else if( (label_img[p2][i-1]) > 0 ) {//}else if( *(pnt2-1) > 0 ) {
256- m = work[(label_img[p1][i+1])-1];//m = work[*(pnt1+1)-1];
257- n = work[(label_img[p2][i-1])-1];//n = work[*(pnt2-1)-1];
392+ work2_pt=work2[label_pixel-1];
393+ work2_pt[0] ++;
394+ work2_pt[1] += i;
395+ work2_pt[2] += j;
396+ work2_pt[6] = j;
397+ }else if( (label_img_pt0[i-1]) > 0 ) {//}else if( *(pnt2-1) > 0 ) {
398+ m = work[(label_img_pt1[i+1])-1];//m = work[*(pnt1+1)-1];
399+ n = work[label_img_pt0[i-1]-1];//n = work[*(pnt2-1)-1];
258400 if( m > n ) {
259401
260- label_img[p2][i]=(short)n;//*pnt2 = n;
261- for(int k = 0; k < wk_max; k++) {
402+ label_pixel=n;//*pnt2 = n;
403+ for(k = 0; k < wk_max; k++) {
262404 if(work[k]==m){//if( *wk == m ){
263405 work[k]=n;//*wk = n;
264406 }
265407 }
266408 }else if( m < n ) {
267- label_img[p2][i]=(short)m;//*pnt2 = m;
268- for(int k = 0; k < wk_max; k++) {
409+ label_pixel=m;//*pnt2 = m;
410+ for(k = 0; k < wk_max; k++) {
269411 if(work[k]==n){//if( *wk == n ){
270412 work[k]=m;//*wk = m;
271413 }
272414 }
273415 }else{
274- label_img[p2][i]=(short)m;//*pnt2 = m;
416+ label_pixel=m;//*pnt2 = m;
275417 }
276-
277-
278- int p2_index=((label_img[p2][i])-1)*7;
279- work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;
280- work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;
281- work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;
418+ work2_pt=work2[label_pixel-1];
419+ work2_pt[0] ++;//work2[((*pnt2)-1)*7+0] ++;
420+ work2_pt[1] += i;//work2[((*pnt2)-1)*7+1] += i;
421+ work2_pt[2] += j;//work2[((*pnt2)-1)*7+2] += j;
282422 }else{
283423
284- label_img[p2][i]=label_img[p1][i+1];//*pnt2 = *(pnt1+1);
285-
286- int p2_index=((label_img[p2][i])-1)*7;
287- work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;
288- work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;
289- work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;
290- if( work2[p2_index+3] > i ){//if( work2[((*pnt2)-1)*7+3] > i ){
291- work2[p2_index+3] = i;// work2[((*pnt2)-1)*7+3] = i;
424+ label_pixel=label_img_pt1[i+1];//*pnt2 = *(pnt1+1);
425+
426+ work2_pt=work2[label_pixel-1];
427+ work2_pt[0] ++;//work2[((*pnt2)-1)*7+0] ++;
428+ work2_pt[1] += i;//work2[((*pnt2)-1)*7+1] += i;
429+ work2_pt[2] += j;//work2[((*pnt2)-1)*7+2] += j;
430+ if( work2_pt[3] > i ){//if( work2[((*pnt2)-1)*7+3] > i ){
431+ work2_pt[3] = i;// work2[((*pnt2)-1)*7+3] = i;
292432 }
293- work2[p2_index+6] = j;//work2[((*pnt2)-1)*7+6] = j;
433+ work2_pt[6] = j;//work2[((*pnt2)-1)*7+6] = j;
294434 }
295- }else if( (label_img[p1][i-1]) > 0 ) {//}else if( *(pnt1-1) > 0 ) {
296- label_img[p2][i]=label_img[p1][i-1];//*pnt2 = *(pnt1-1);
297-
298- int p2_index=((label_img[p2][i])-1)*7;
299- work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;
300- work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;
301- work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;
302- if( work2[p2_index+4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){
303- work2[p2_index+4] = i;// work2[((*pnt2)-1)*7+4] = i;
435+ }else if( (label_img_pt1[i-1]) > 0 ) {//}else if( *(pnt1-1) > 0 ) {
436+ label_pixel=label_img_pt1[i-1];//*pnt2 = *(pnt1-1);
437+
438+ work2_pt=work2[label_pixel-1];
439+ work2_pt[0] ++;//work2[((*pnt2)-1)*7+0] ++;
440+ work2_pt[1] += i;//work2[((*pnt2)-1)*7+1] += i;
441+ work2_pt[2] += j;//work2[((*pnt2)-1)*7+2] += j;
442+ if( work2_pt[4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){
443+ work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
304444 }
305- work2[p2_index+6] = j;//work2[((*pnt2)-1)*7+6] = j;
306- }else if(label_img[p2][i-1] > 0) {//}else if( *(pnt2-1) > 0) {
307- label_img[p2][i]=label_img[p2][i-1];//*pnt2 = *(pnt2-1);
308-
309- int p2_index=((label_img[p2][i])-1)*7;
310- work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;
311- work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;
312- work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;
313- if( work2[p2_index+4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){
314- work2[p2_index+4] = i;// work2[((*pnt2)-1)*7+4] = i;
445+ work2_pt[6] = j;//work2[((*pnt2)-1)*7+6] = j;
446+ }else if(label_img_pt0[i-1] > 0) {//}else if( *(pnt2-1) > 0) {
447+ label_pixel=label_img_pt0[i-1];//*pnt2 = *(pnt2-1);
448+
449+ work2_pt=work2[label_pixel-1];
450+ work2_pt[0] ++;//work2[((*pnt2)-1)*7+0] ++;
451+ work2_pt[1] += i;//work2[((*pnt2)-1)*7+1] += i;
452+ work2_pt[2] += j;//work2[((*pnt2)-1)*7+2] += j;
453+ if(work2_pt[4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){
454+ work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;
315455 }
316456 }else{
457+ //現在地までの領域を予約
458+ this.work_holder.reserv(wk_max);
317459 wk_max++;
318- if( wk_max > WORK_SIZE ) {
319- throw new NyARException();//return (0);
320- }
321- work[wk_max-1] = wk_max;label_img[p2][i]=(short)wk_max;//work[wk_max-1] = *pnt2 = wk_max;
322- work2[(wk_max-1)*7+0] = 1;
323- work2[(wk_max-1)*7+1] = i;
324- work2[(wk_max-1)*7+2] = j;
325- work2[(wk_max-1)*7+3] = i;
326- work2[(wk_max-1)*7+4] = i;
327- work2[(wk_max-1)*7+5] = j;
328- work2[(wk_max-1)*7+6] = j;
460+ work[wk_max-1] = wk_max;
461+ label_pixel=wk_max;//work[wk_max-1] = *pnt2 = wk_max;
462+ work2_pt=work2[wk_max-1];
463+ work2_pt[0] = 1;
464+ work2_pt[1] = i;
465+ work2_pt[2] = j;
466+ work2_pt[3] = i;
467+ work2_pt[4] = i;
468+ work2_pt[5] = j;
469+ work2_pt[6] = j;
329470 }
471+ label_img_pt0[i]=label_pixel;
330472 }else {
331- label_img[p2][i]=0;//*pnt2 = 0;
473+ label_img_pt0[i]=0;//*pnt2 = 0;
332474 }
475+
333476 }
334477 }
335- int j = 1;
336- for(int i = 0; i < wk_max; i++){//for(int i = 1; i <= wk_max; i++, wk++) {
478+ j = 1;
479+ for(i = 0; i < wk_max; i++){//for(int i = 1; i <= wk_max; i++, wk++) {
337480 work[i]=(work[i]==i+1)? j++: work[work[i]-1];//*wk = (*wk==i)? j++: work[(*wk)-1];
338481 }
339-
482+
340483 int wlabel_num=j - 1;//*label_num = *wlabel_num = j - 1;
341484
342485 if(wlabel_num==0){//if( *label_num == 0 ) {
@@ -344,38 +487,67 @@ public class NyARLabeling{
344487 return;
345488 }
346489
347- putZero(warea,wlabel_num);//put_zero( (ARUint8 *)warea, *label_num * sizeof(int) );
348- putZero(wpos,wlabel_num*2);//put_zero( (ARUint8 *)wpos, *label_num * 2 * sizeof(double) );
349- for(int i = 0; i < wlabel_num; i++) {//for(i = 0; i < *label_num; i++) {
350- wclip[i][0] = lxsize;//wclip[i*4+0] = lxsize;
351- wclip[i][1] = 0;//wclip[i*4+1] = 0;
352- wclip[i][2] = lysize;//wclip[i*4+2] = lysize;
353- wclip[i][3] = 0;//wclip[i*4+3] = 0;
354- }
355- for(int i = 0; i < wk_max; i++) {
356- j = work[i] - 1;
357- warea[j] += work2[i*7+0];
358- wpos[j*2+0] += work2[i*7+1];
359- wpos[j*2+1] += work2[i*7+2];
360- if( wclip[j][0] > work2[i*7+3] ){
361- wclip[j][0] = work2[i*7+3];
490+
491+
492+ //ラベルバッファを予約&初期化
493+ this.label_holder.init(wlabel_num, lxsize, lysize);
494+//
495+// putZero(warea,wlabel_num);//put_zero( (ARUint8 *)warea, *label_num * sizeof(int) );
496+// for(i=0;i<wlabel_num;i++){
497+// wpos[i*2+0]=0;
498+// wpos[i*2+1]=0;
499+// }
500+// for(i = 0; i < wlabel_num; i++) {//for(i = 0; i < *label_num; i++) {
501+// wclip[i][0] = lxsize;//wclip[i*4+0] = lxsize;
502+// wclip[i][1] = 0;//wclip[i*4+1] = 0;
503+// wclip[i][2] = lysize;//wclip[i*4+2] = lysize;
504+// wclip[i][3] = 0;//wclip[i*4+3] = 0;
505+// }
506+ NyARLabel label_pt;
507+ NyARLabel[] labels=this.label_holder.labels;
508+
509+ for(i = 0; i < wk_max; i++){
510+ label_pt=labels[work[i] - 1];
511+ work2_pt=work2[i];
512+ label_pt.area += work2_pt[0];
513+ label_pt.pos_x += work2_pt[1];
514+ label_pt.pos_y += work2_pt[2];
515+ if( label_pt.clip0 > work2_pt[3] ){
516+ label_pt.clip0 = work2_pt[3];
362517 }
363- if( wclip[j][1] < work2[i*7+4] ){
364- wclip[j][1] = work2[i*7+4];
518+ if( label_pt.clip1 < work2_pt[4] ){
519+ label_pt.clip1 = work2_pt[4];
365520 }
366- if( wclip[j][2] > work2[i*7+5] ){
367- wclip[j][2] = work2[i*7+5];
521+ if(label_pt.clip2 > work2_pt[5] ){
522+ label_pt.clip2 = work2_pt[5];
368523 }
369- if( wclip[j][3] < work2[i*7+6] ){
370- wclip[j][3] = work2[i*7+6];
524+ if( label_pt.clip3 < work2_pt[6] ){
525+ label_pt.clip3 = work2_pt[6];
371526 }
527+
528+// warea[j] += work2_pt[0];
529+// wpos[j*2+0] += work2_pt[1];
530+// wpos[j*2+1] += work2_pt[2];
531+// if( wclip[j][0] > work2_pt[3] ){
532+// wclip[j][0] = work2_pt[3];
533+// }
534+// if( wclip[j][1] < work2_pt[4] ){
535+// wclip[j][1] = work2_pt[4];
536+// }
537+// if( wclip[j][2] > work2_pt[5] ){
538+// wclip[j][2] = work2_pt[5];
539+// }
540+// if( wclip[j][3] < work2_pt[6] ){
541+// wclip[j][3] = work2_pt[6];
542+// }
372543 }
373544
374- for(int i = 0; i < wlabel_num; i++ ) {//for(int i = 0; i < *label_num; i++ ) {
375- wpos[i*2+0] /= warea[i];
376- wpos[i*2+1] /= warea[i];
545+ for(i = 0; i < wlabel_num; i++ ) {//for(int i = 0; i < *label_num; i++ ) {
546+ label_pt=labels[i];
547+ label_pt.pos_x /= label_pt.area;
548+ label_pt.pos_y /= label_pt.area;
377549 }
378-
550+
379551 label_num=wlabel_num;
380552 return;
381553 }
--- a/trunk/src/jp/nyatla/nyartoolkit/core/NyARMarker.java
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARMarker.java
@@ -35,6 +35,8 @@ package jp.nyatla.nyartoolkit.core;
3535
3636
3737
38+
39+
3840 /**
3941 * typedef struct {
4042 * int area;
@@ -48,13 +50,228 @@ package jp.nyatla.nyartoolkit.core;
4850 */
4951 class NyARMarker
5052 {
51- private static final int AR_CHAIN_MAX=10000;
52- int area;
53- double[] pos=new double[2];
53+ /**
54+ * メモリブロックのサイズ(32*4=128kb)
55+ */
56+ private static final int ALLOCATE_PAGE_SIZE=256;
57+ /**
58+ * メモリブロックの初期サイズ
59+ */
60+ private static final int INITIAL_SIZE=1;
61+ int[] x_coord=new int[INITIAL_SIZE];
62+ int[] y_coord=new int[INITIAL_SIZE];
5463 int coord_num;
55- int[] x_coord=new int[AR_CHAIN_MAX];
56- int[] y_coord=new int[AR_CHAIN_MAX];
57- int[] vertex=new int[5];
64+ int area;
65+ final double[] pos=new double[2];
66+ final int[] mkvertex=new int[5];
67+ /**
68+ * coordバッファをi_chain_num以上のサイズに再アロケートする。
69+ * 内容の引継ぎは行われない。
70+ * @param i_chain_num
71+ */
72+ private void reallocCoordArray(int i_chain_num)
73+ {
74+ if(x_coord.length<i_chain_num){
75+ //ALLOCATE_PAGE_SIZE単位で確保する。
76+ int new_size=((i_chain_num+ALLOCATE_PAGE_SIZE-1)/ALLOCATE_PAGE_SIZE)*ALLOCATE_PAGE_SIZE;
77+ x_coord=new int[new_size];
78+ y_coord=new int[new_size];
79+ coord_num=0;
80+ }
81+ }
82+ public void setCoordXY(int i_v1,int i_coord_num,int[] i_xcoord,int[] i_ycoord)
83+ {
84+ //メモリの割り当て保障
85+ reallocCoordArray(i_coord_num+1);
86+ //[A B C]を[B C A]に並べなおす。
87+ System.arraycopy(i_xcoord,i_v1,x_coord,0,i_coord_num-i_v1);
88+ System.arraycopy(i_xcoord,0,x_coord,i_coord_num-i_v1, i_v1);
89+ x_coord[i_coord_num]=x_coord[0];
90+ System.arraycopy(i_ycoord,i_v1,y_coord,0,i_coord_num-i_v1);
91+ System.arraycopy(i_ycoord,0,y_coord,i_coord_num-i_v1, i_v1);
92+ y_coord[i_coord_num]=y_coord[0];
93+ coord_num=i_coord_num+1;
94+ return;
95+//arGetContour関数から取り外した部分
96+// int[] wx=new int[v1];//new int[Config.AR_CHAIN_MAX];
97+// int[] wy=new int[v1]; //new int[Config.AR_CHAIN_MAX];
98+// for(i=0;i<v1;i++) {
99+// wx[i] = marker_ref.x_coord[i];//wx[i] = marker_info2->x_coord[i];
100+// wy[i] = marker_ref.y_coord[i];//wy[i] = marker_info2->y_coord[i];
101+// }
102+// for(i=0;i<marker_ref.coord_num-v1;i++) {//for(i=v1;i<marker_info2->coord_num;i++) {
103+// marker_ref.x_coord[i] = marker_ref.x_coord[i+v1];//marker_info2->x_coord[i-v1] = marker_info2->x_coord[i];
104+// marker_ref.y_coord[i] = marker_ref.y_coord[i+v1];//marker_info2->y_coord[i-v1] = marker_info2->y_coord[i];
105+// }
106+// for(i=0;i<v1;i++) {
107+// marker_ref.x_coord[i-v1+marker_ref.coord_num] = wx[i];//marker_info2->x_coord[i-v1+marker_info2->coord_num] = wx[i];
108+// marker_ref.y_coord[i-v1+marker_ref.coord_num] = wy[i];//marker_info2->y_coord[i-v1+marker_info2->coord_num] = wy[i];
109+// }
110+// marker_ref.x_coord[marker_ref.coord_num] = marker_ref.x_coord[0];//marker_info2->x_coord[marker_info2->coord_num] = marker_info2->x_coord[0];
111+// marker_ref.y_coord[marker_ref.coord_num] = marker_ref.y_coord[0];//marker_info2->y_coord[marker_info2->coord_num] = marker_info2->y_coord[0];
112+// marker_ref.coord_num++;//marker_info2->coord_num++;
113+ }
114+ private final NyARVertexCounter wk_checkSquare_wv1=new NyARVertexCounter();
115+ private final NyARVertexCounter wk_checkSquare_wv2=new NyARVertexCounter();
116+ /**
117+ * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor )
118+ * 関数の代替関数
119+ * OPTIMIZED STEP [450->397]
120+ * @param i_area
121+ * @param i_factor
122+ * @return
123+ */
124+ public boolean checkSquare(int i_area,double i_factor,double i_pos_x,double i_pos_y)
125+ {
126+ final int[] l_vertex=mkvertex;
127+ final int[] l_x_coord=x_coord;
128+ final int[] l_y_coord=y_coord;
129+ final NyARVertexCounter wv1=wk_checkSquare_wv1;
130+ final NyARVertexCounter wv2=wk_checkSquare_wv2;
131+ int sx, sy;
132+ int dmax, d, v1;
133+
134+ int v2;// int wvnum1,wvnum2,v2;
135+ double thresh;
136+ int i;
137+
138+ dmax = 0;
139+ v1 = 0;
140+ sx = l_x_coord[0];//sx = marker_info2->x_coord[0];
141+ sy = l_y_coord[0];//sy = marker_info2->y_coord[0];
142+ for(i=1;i<this.coord_num-1;i++){//for(i=1;i<marker_info2->coord_num-1;i++) {
143+ d = (l_x_coord[i]-sx)*(l_x_coord[i]-sx)+ (l_y_coord[i]-sy)*(l_y_coord[i]-sy);
144+ if( d > dmax ) {
145+ dmax = d;
146+ v1 = i;
147+ }
148+ }
149+
150+ thresh = (i_area/0.75) * 0.01 * i_factor;
151+
152+ l_vertex[0] = 0;
153+
154+ if(!wv1.getVertex(l_x_coord,l_y_coord, 0, v1,thresh)){ //if( get_vertex(marker_info2->x_coord, marker_info2->y_coord, 0, v1,thresh, wv1, &wvnum1) < 0 ) {
155+ return false;
156+ }
157+ if(!wv2.getVertex(l_x_coord,l_y_coord,v1, this.coord_num-1, thresh)) {//if(get_vertex(marker_info2->x_coord, marker_info2->y_coord,v1, marker_info2->coord_num-1, thresh, wv2, &wvnum2) < 0 ) {
158+ return false;
159+ }
160+
161+ if(wv1.number_of_vertex==1 && wv2.number_of_vertex==1) {//if( wvnum1 == 1 && wvnum2 == 1 ) {
162+ l_vertex[1] = wv1.vertex[0];
163+ l_vertex[2] = v1;
164+ l_vertex[3] = wv2.vertex[0];
165+ }else if( wv1.number_of_vertex>1 && wv2.number_of_vertex==0 ) {//}else if( wvnum1 > 1 && wvnum2 == 0 ) {
166+ v2 = v1 / 2;
167+ if(!wv1.getVertex(l_x_coord,l_y_coord,0, v2, thresh)) {
168+ return false;
169+ }
170+ if(!wv2.getVertex(l_x_coord,l_y_coord,v2, v1, thresh)) {
171+ return false;
172+ }
173+ if(wv1.number_of_vertex==1 && wv2.number_of_vertex==1 ) {
174+ l_vertex[1] = wv1.vertex[0];
175+ l_vertex[2] = wv2.vertex[0];
176+ l_vertex[3] = v1;
177+ }else{
178+ return false;
179+ }
180+ }else if(wv1.number_of_vertex==0 && wv2.number_of_vertex> 1 ) {
181+ v2 = (v1 + this.coord_num-1) / 2;
182+
183+ if(!wv1.getVertex(l_x_coord,l_y_coord,v1, v2, thresh)) {
184+ return false;
185+ }
186+ if(!wv2.getVertex(l_x_coord,l_y_coord,v2, this.coord_num-1, thresh)) {
187+ return false;
188+ }
189+ if( wv1.number_of_vertex==1 && wv2.number_of_vertex==1 ) {
190+ l_vertex[1] = v1;
191+ l_vertex[2] = wv1.vertex[0];
192+ l_vertex[3] = wv2.vertex[0];
193+ }
194+ else {
195+ return false;
196+ }
197+ }
198+ else {
199+ return false;
200+ }
201+ l_vertex[4] = this.coord_num-1;//この値使ってるの?
202+ //
203+ area = i_area;
204+ pos[0] = i_pos_x;
205+ pos[1] = i_pos_y;
206+// marker_holder[marker_num2].pos[1] = wpos[i*2+1];
207+ return true;
208+ }
58209 }
59210
60211
212+/**
213+ * get_vertex関数を切り離すためのクラス
214+ *
215+ */
216+final class NyARVertexCounter
217+{
218+ public final int[] vertex=new int[10];//5まで削れる
219+ public int number_of_vertex;
220+ private double thresh;
221+ private int[] x_coord;
222+ private int[] y_coord;
223+
224+ public boolean getVertex(int[] i_x_coord, int[] i_y_coord, int st, int ed,double i_thresh)
225+ {
226+ this.number_of_vertex=0;
227+ this.thresh=i_thresh;
228+ this.x_coord=i_x_coord;
229+ this.y_coord=i_y_coord;
230+ return get_vertex(st,ed);
231+ }
232+ /**
233+ * static int get_vertex( int x_coord[], int y_coord[], int st, int ed,double thresh, int vertex[], int *vnum)
234+ * 関数の代替関数
235+ * @param x_coord
236+ * @param y_coord
237+ * @param st
238+ * @param ed
239+ * @param thresh
240+ * @return
241+ */
242+ private boolean get_vertex(int st, int ed)
243+ {
244+ double d, dmax;
245+ double a, b, c;
246+ int i, v1=0;
247+ final int[] lx_coord=this.x_coord;
248+ final int[] ly_coord=this.y_coord;
249+ a = ly_coord[ed] - ly_coord[st];
250+ b = lx_coord[st] - lx_coord[ed];
251+ c = lx_coord[ed]*ly_coord[st] - ly_coord[ed]*lx_coord[st];
252+ dmax = 0;
253+ for(i=st+1;i<ed;i++) {
254+ d = a*lx_coord[i] + b*ly_coord[i] + c;
255+ if( d*d > dmax ) {
256+ dmax = d*d;
257+ v1 = i;
258+ }
259+ }
260+ if( dmax/(a*a+b*b) > thresh ) {
261+ if(!get_vertex(st, v1)){
262+ return false;
263+ }
264+ if(number_of_vertex > 5 ){
265+ return false;
266+ }
267+ vertex[number_of_vertex] = v1;//vertex[(*vnum)] = v1;
268+ number_of_vertex++;//(*vnum)++;
269+
270+ if(!get_vertex(v1, ed)){
271+ return false;
272+ }
273+ }
274+ return true;
275+ }
276+}
277+
--- /dev/null
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARMarkerList.java
@@ -0,0 +1,148 @@
1+package jp.nyatla.nyartoolkit.core;
2+
3+import jp.nyatla.nyartoolkit.NyARException;
4+
5+/**
6+ * このクラスは、detectMarkerがマーカーオブジェクトの蓄積に使うクラスです。
7+ * 実体を伴うマーカーホルダと、これを参照するマーカーアレイを持ちます。
8+ *
9+ * マーカーアレイはマーカーホルダに存在するマーカーリストを特定の条件でフィルタした
10+ * 結果を格納します。
11+ *
12+ * 一度作られたマーカーホルダは繰り返し使用されます。
13+ *
14+ *
15+ */
16+public class NyARMarkerList
17+{
18+ private int marker_holder_num;//marker_holderの使用中の数
19+ protected int marker_array_num;//marker_arrayの有効な数
20+ protected final NyARMarker[] marker_holder;//マーカーデータの保持配列
21+ protected final NyARMarker[] marker_array; //マーカーデータのインデックス配列
22+ /**
23+ * 派生データ型をラップするときに使う
24+ * @param i_holder
25+ * 値の保持配列。全要素に実体を割り当てる必要がある。
26+ */
27+ protected NyARMarkerList(NyARMarker[] i_holder)
28+ {
29+ this.marker_holder=i_holder;
30+ this.marker_array =new NyARMarker[i_holder.length];
31+ this.marker_array_num =0;
32+ this.marker_holder_num =0;
33+ }
34+ public NyARMarkerList(int i_number_of_holder)
35+ {
36+ this.marker_holder=new NyARMarker[i_number_of_holder];
37+ //先にマーカーホルダにオブジェクトを作っておく
38+ for(int i=0;i<i_number_of_holder;i++){
39+ this.marker_holder[i]=new NyARMarker();
40+ }
41+ this.marker_array =new NyARMarker[this.marker_holder.length];
42+ this.marker_array_num =0;
43+ this.marker_holder_num =0;
44+ }
45+ /**
46+ * 現在位置のマーカーホルダを返す。
47+ * 現在位置が終端の場合関数は失敗する。
48+ * @return
49+ */
50+ public final NyARMarker getCurrentHolder() throws NyARException
51+ {
52+ if(this.marker_holder_num>=this.marker_holder.length){
53+ throw new NyARException();
54+ }
55+ return this.marker_holder[this.marker_holder_num];
56+ }
57+ /**
58+ * マーカーホルダの現在位置を1つ進めて、そのホルダを返す。
59+ * この関数を実行すると、使用中のマーカーホルダの数が1個増える。
60+ * @return
61+ * 空いているマーカーホルダが無ければnullを返します。
62+ *
63+ */
64+ public final NyARMarker getNextHolder()
65+ {
66+ //現在位置が終端位置ならnullを返す。
67+ if(this.marker_holder_num+1>=this.marker_holder.length){
68+ this.marker_holder_num=this.marker_holder.length;
69+ return null;
70+ }
71+ this.marker_holder_num++;
72+ return this.marker_holder[this.marker_holder_num];
73+ }
74+ /**
75+ * マーカーアレイのi_indexの要素を返す。
76+ * @param i_index
77+ * @return
78+ * @throws NyARException
79+ */
80+ public final NyARMarker getMarker(int i_index) throws NyARException
81+ {
82+ if(i_index>=marker_array_num){
83+ throw new NyARException();
84+ }
85+ return this.marker_array[i_index];
86+ }
87+ /**
88+ * マーカーアレイの要素数を返す。
89+ * @return
90+ */
91+ public final int getMarkerNum()
92+ {
93+ return marker_array_num;
94+ }
95+ /**
96+ * マーカーアレイの要素数と、マーカーホルダの現在位置をリセットする。
97+ * @return
98+ */
99+ public final void reset()
100+ {
101+ this.marker_array_num=0;
102+ this.marker_holder_num=0;
103+ }
104+ /**
105+ * マーカーホルダに格納済みのマーカーから重なっているのものを除外して、
106+ * マーカーアレイにフィルタ結果を格納します。
107+ * [[この関数はマーカー検出処理と密接に関係する関数です。
108+ * NyARDetectMarkerクラス以外から呼び出さないで下さい。]]
109+ * メモ:この関数はmarker_holderの内容を変化させまするので注意。
110+ */
111+ public final void updateMarkerArray()
112+ {
113+ //重なり処理かな?
114+ int i;
115+ double d;
116+ double[] pos_j,pos_i;
117+// NyARMarker[] marker_holder;
118+ for(i=0; i < this.marker_holder_num; i++ ){
119+ pos_i=marker_holder[i].pos;
120+ for(int j=i+1; j < this.marker_holder_num; j++ ) {
121+ pos_j=marker_holder[j].pos;
122+ d = (pos_i[0] - pos_j[0])*(pos_i[0] - pos_j[0])+
123+ (pos_i[1] - pos_j[1])*(pos_i[1] - pos_j[1]);
124+ if(marker_holder[i].area >marker_holder[j].area ) {
125+ if( d <marker_holder[i].area / 4 ) {
126+ marker_holder[j].area = 0;
127+ }
128+ }else{
129+ if( d < marker_holder[j].area / 4 ) {
130+ marker_holder[i].area = 0;
131+ }
132+ }
133+ }
134+ }
135+ //みつかったマーカーを整理する。
136+ int l_array_num=0;
137+ //エリアが0のマーカーを外した配列を作って、その数もついでに計算
138+ for(i=0;i<marker_holder_num;i++){
139+ if(marker_holder[i].area==0.0){
140+ continue;
141+ }
142+ marker_array[l_array_num]=marker_holder[i];
143+ l_array_num++;
144+ }
145+ //マーカー個数を更新
146+ this.marker_array_num=l_array_num;
147+ }
148+}
\ No newline at end of file
--- a/trunk/src/jp/nyatla/nyartoolkit/core/NyARMat.java
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARMat.java
@@ -45,6 +45,11 @@ import jp.nyatla.nyartoolkit.NyARException;
4545 *
4646 */
4747 public class NyARMat{
48+ /**
49+ * 配列サイズと行列サイズは必ずしも一致しないことに注意
50+ * 返された配列のサイズを行列の大きさとして使わないこと!
51+ *
52+ */
4853 private double[][] m;
4954 private int clm,row;
5055 public NyARMat(int i_row,int i_clm)
@@ -53,6 +58,24 @@ public class NyARMat{
5358 clm=i_clm;
5459 row=i_row;
5560 }
61+ /**
62+ * i_row x i_clmサイズの行列を格納できるように行列サイズを変更します。
63+ * 実行後、行列の各値は不定になります。
64+ * @param i_row
65+ * @param i_clm
66+ */
67+ public void realloc(int i_row,int i_clm)
68+ {
69+ if(i_row<=this.m.length && i_clm<=this.m[0].length)
70+ {
71+ //十分な配列があれば何もしない。
72+ }else{
73+ //不十分なら取り直す。
74+ m=new double[i_row][i_clm];
75+ }
76+ this.clm=i_clm;
77+ this.row=i_row;
78+ }
5679 public int getClm()
5780 {
5881 return clm;
@@ -66,63 +89,69 @@ public class NyARMat{
6689 */
6790 public void zeroClear()
6891 {
69- for(int i=0;i<row;i++){
70- for(int i2=0;i2<clm;i2++){
92+ int i,i2;
93+ //For順変更OK
94+ for(i=row-1;i>=0;i--){
95+ for(i2=clm-1;i2>=0;i2--){
7196 m[i][i2]=0.0;
7297 }
7398 }
7499 }
75- public double[] getRowArray(int i_row)
76- {
77- return m[i_row];
78- }
100+
79101 public double[][] getArray()
80102 {
81103 return m;
82104 }
83- public NyARVec getRowVec(int i_row)
84- {
85- return NyARVec.wrap(m[i_row]);
86- }
105+// public void getRowVec(int i_row,NyARVec o_vec)
106+// {
107+// o_vec.set(this.m[i_row],this.clm);
108+// }
87109 /**
88- * aとbの積をdestに出力する。arMatrixMul()の代替品
89- * @param dest
110+ * aとbの積を自分自身に格納する。arMatrixMul()の代替品
90111 * @param a
91112 * @param b
92113 * @throws NyARException
93114 */
94- public static void matrixMul(NyARMat dest, NyARMat a, NyARMat b) throws NyARException
115+ public void matrixMul(NyARMat a, NyARMat b) throws NyARException
95116 {
96- if(a.clm != b.row || dest.row != a.row || dest.clm != b.clm){
117+ if(a.clm != b.row || this.row != a.row || this.clm != b.clm){
97118 throw new NyARException();
98119 }
99- for(int r = 0; r < dest.row; r++){
100- for(int c = 0; c < dest.getClm(); c++){
101- dest.m[r][c]=0.0;//dest.setARELEM0(r, c,0.0);
102- for(int i = 0; i < a.getClm(); i++){
103- dest.m[r][c]+=a.m[r][i]*b.m[i][c];//ARELEM0(dest, r, c) += ARELEM0(a, r, i) * ARELEM0(b, i, c);
120+ double w;
121+ int r,c,i;
122+ double[][] am=a.m,bm=b.m,dm=this.m;
123+ //For順変更禁止
124+ for(r = 0; r < this.row; r++){
125+ for(c = 0; c < this.clm; c++){
126+ w=0.0;//dest.setARELEM0(r, c,0.0);
127+ for(i = 0; i < a.clm; i++){
128+ w+=am[r][i]*bm[i][c];//ARELEM0(dest, r, c) += ARELEM0(a, r, i) * ARELEM0(b, i, c);
104129 }
130+ dm[r][c]=w;
105131 }
106132 }
107133 }
108134 private int[] wk_nos_matrixSelfInv=new int[50];
135+ private final static double matrixSelfInv_epsl=1.0e-10;
109136 /**
110137 * i_targetを逆行列に変換する。arMatrixSelfInv()と、arMatrixSelfInv_minv()関数を合成してあります。
138+ * OPTIMIZE STEP[485->422]
111139 * @param i_target
112140 * 逆行列にする行列
113141 * @throws NyARException
114142 */
115143 public void matrixSelfInv() throws NyARException
116144 {
117- double[][] ap=m;
118- int dimen=ap.length;
119- double[] wcp,wap,wbp;
145+ double[][] ap=this.m;
146+ int dimen=this.row;
147+ int dimen_1=dimen-1;
148+ double[] ap_n,ap_ip,ap_i;//wap;
120149 int j,ip,nwork;
121150 int[] nos=wk_nos_matrixSelfInv;//この関数で初期化される。
122- double epsl;
151+ //double epsl;
123152 double p,pbuf,work;
124153
125- epsl = 1.0e-10; /* Threshold value */
154+// epsl = 1.0e-10; /* Threshold value */
126155 /* check size */
127156 switch(dimen){
128157 case 0:
@@ -141,20 +170,21 @@ public class NyARMat{
141170 * ループ内で0初期化していいかが判らない。
142171 */
143172 ip=0;
144- int wap_ptr,wbp_ptr;
173+// int wap_ptr,wbp_ptr;
174+ //For順変更禁止
145175 for(int n=0; n<dimen;n++)
146176 {
147- wcp =ap[n];//wcp = ap + n * rowa;
177+ ap_n =ap[n];//wcp = ap + n * rowa;
148178 p=0.0;
149- wap_ptr=0;//wap = DoublePointer.wrap(wcp);
179+// wap_ptr=0;//wap = DoublePointer.wrap(wcp);
150180 for(int i = n; i<dimen ; i++){//for(i = n, wap = wcp, p = 0.0; i < dimen ; i++, wap += rowa)
151- wap=ap[i];
152- if( p < ( pbuf = Math.abs(wap[0]))) {
181+// wap=ap[i];
182+ if( p < ( pbuf = Math.abs(ap[i][0]))) {
153183 p = pbuf;
154184 ip = i;
155185 }
156186 }
157- if (p <= epsl){
187+ if (p <= matrixSelfInv_epsl){
158188 return;
159189 }
160190
@@ -162,38 +192,40 @@ public class NyARMat{
162192 nos[ip]= nos[n];
163193 nos[n] = nwork;
164194
165- wap=ap[ip];
166- wbp=wcp;
167- wap_ptr=0;
168- wbp_ptr=0;
195+ ap_ip=ap[ip];
196+// wbp=ap_n;
197+// wap_ptr=0;
198+// wbp_ptr=0;
169199 for(j=0; j< dimen ; j++){//for(j = 0, wap = ap + ip * rowa, wbp = wcp; j < dimen ; j++) {
170- work = wap[wap_ptr]; //work = *wap;
171- wap[wap_ptr]=wbp[wbp_ptr];wap_ptr++;//*wap++ = *wbp;
172- wbp[wbp_ptr]=work;wbp_ptr++; //*wbp++ = work;
200+ work = ap_ip[j]; //work = *wap;
201+ ap_ip[j]=ap_n[j];
202+// wap_ptr++;//*wap++ = *wbp;
203+ ap_n[j]=work;
204+// wbp_ptr++; //*wbp++ = work;
173205 }
174206
175- wap=wcp;
176- wap_ptr=0;
177- work=wcp[0];
178- for(j = 1; j < dimen ; j++){//for(j = 1, wap = wcp, work = *wcp; j < dimen ; j++, wap++)
179- wap[wap_ptr]=wap[wap_ptr+1]/work;//*wap = *(wap + 1) / work;
180- wap_ptr++;
207+// wap=ap_n;
208+// wap_ptr=0;
209+ work=ap_n[0];
210+ for(j = 0; j < dimen_1 ; j++){//for(j = 1, wap = wcp, work = *wcp; j < dimen ; j++, wap++)
211+ ap_n[j]=ap_n[j+1]/work;//*wap = *(wap + 1) / work;
212+// wap_ptr++;
181213 }
182- wap[wap_ptr]=1.0/work;//*wap = 1.0 / work;
183-
214+ ap_n[j]=1.0/work;//*wap = 1.0 / work;
215+// wbp=ap_n;
184216 for(int i = 0; i < dimen ; i++) {
185217 if(i != n) {
186- wap =ap[i];//wap = ap + i * rowa;
187- wbp =wcp;
188- wap_ptr=0;
189- wbp_ptr=0;
190- work=wap[0];
191- for(j = 1;j < dimen ; j++){//for(j = 1, wbp = wcp, work = *wap;j < dimen ; j++, wap++, wbp++)
192- wap[wap_ptr]=wap[wap_ptr+1]-work*wbp[wbp_ptr];//wap = *(wap + 1) - work * (*wbp);
193- wap_ptr++;
194- wbp_ptr++;
218+ ap_i =ap[i];//wap = ap + i * rowa;
219+
220+// wap_ptr=0;
221+// wbp_ptr=0;
222+ work=ap_i[0];
223+ for(j = 0;j < dimen_1 ; j++){//for(j = 1, wbp = wcp, work = *wap;j < dimen ; j++, wap++, wbp++)
224+ ap_i[j]=ap_i[j+1]-work*ap_n[j];//wap = *(wap + 1) - work * (*wbp);
225+// wap_ptr++;
226+// wbp_ptr++;
195227 }
196- wap[wap_ptr]=-work*wbp[wbp_ptr];//*wap = -work * (*wbp);
228+ ap_i[j]=-work*ap_n[j];//*wap = -work * (*wbp);
197229 }
198230 }
199231 }
@@ -206,11 +238,11 @@ public class NyARMat{
206238 }
207239 nos[j] = nos[n];
208240 for(int i = 0; i < dimen ;i++){//for(i = 0, wap = ap + j, wbp = ap + n; i < dimen ;i++, wap += rowa, wbp += rowa) {
209- wap=ap[i];
210- wbp=ap[i];
211- work =wap[j];//work = *wap;
212- wap[j]=wbp[n];//*wap = *wbp;
213- wbp[n]=work;//*wbp = work;
241+ ap_i=ap[i];
242+// wbp=ap[i];
243+ work =ap_i[j];//work = *wap;
244+ ap_i[j]=ap_i[n];//*wap = *wbp;
245+ ap_i[n]=work;//*wbp = work;
214246 }
215247 }
216248 return;
@@ -227,6 +259,7 @@ public class NyARMat{
227259 throw new NyARException();
228260 }
229261 NyARException.trap("未チェックのパス");
262+ //For順変更禁止
230263 for(int r=0;r< dest.row;r++){
231264 for(int c=0;c<dest.clm;c++){
232265 dest.m[r][c]=source.m[c][r];
@@ -243,6 +276,7 @@ public class NyARMat{
243276 throw new NyARException();
244277 }
245278 NyARException.trap("未チェックのパス");
279+ //For順変更禁止
246280 for(int r = 0; r < unit.getRow(); r++) {
247281 for(int c = 0; c < unit.getClm(); c++) {
248282 if(r == c) {
@@ -254,29 +288,43 @@ public class NyARMat{
254288 }
255289 }
256290 /**
257- * sourceの内容を自身にコピーする。
258- * @param dest
259- * @param source
291+ * sourceの内容を自身に複製する。
292+ * Optimized 2008.04.19
293+ * @param i_source
260294 * @return
261295 */
262- public void matrixDup(NyARMat source) throws NyARException
296+ public void matrixDup(NyARMat i_source) throws NyARException
263297 {
264- if(row != source.row || clm != source.clm)
265- {
266- throw new NyARException();
267- }
268-
269- for(int r = 0; r < row; r++){
270- for(int c = 0; c < clm; c++)
298+ //自身の配列サイズを相手のそれより大きいことを保障する。
299+ this.realloc(i_source.row,i_source.clm);
300+ //内容を転写
301+ int r,c;
302+ double[][] src_m,dest_m;
303+ src_m=i_source.m;
304+ dest_m=this.m;
305+ //コピーはFor順を変えてもOK
306+ for(r = this.row-1; r>=0; r--){
307+ for(c =this.clm-1;c>=0; c--)
271308 {
272- m[r][c]=source.m[r][c];
309+ dest_m[r][c]=src_m[r][c];
273310 }
274311 }
275312 }
276313 public NyARMat matrixAllocDup() throws NyARException
277314 {
278- NyARMat result=new NyARMat(row,clm);
279- result.matrixDup(this);
315+ NyARMat result=new NyARMat(this.row,this.clm);
316+ //コピー
317+ int r,c;
318+ double[][] dest_m,src_m;
319+ dest_m=result.m;
320+ src_m =this.m;
321+ //コピーはFor順を変えてもOK
322+ for(r = this.row-1; r>=0; r--){
323+ for(c =this.clm-1;c>=0; c--)
324+ {
325+ dest_m[r][c]=src_m[r][c];
326+ }
327+ }
280328 return result;
281329 }
282330 /**
@@ -341,41 +389,39 @@ public class NyARMat{
341389 private final static double PCA_VZERO=1e-16; //#define VZERO 1e-16
342390 /**
343391 * static int EX( ARMat *input, ARVec *mean )の代替関数
392+ * Optimize:STEP:[144->110]
344393 * @param input
345394 * @param mean
346395 * @return
347396 * @throws NyARException
348397 */
349- private static void PCA_EX(NyARMat input, NyARVec mean) throws NyARException
398+ private void PCA_EX(NyARVec mean) throws NyARException
350399 {
351- double[] v;
352-
353- int row, clm;
354-
355- row = input.row;
356- clm = input.clm;
357- if(row <= 0 || clm <= 0){
400+ int lrow,lclm;
401+ int i,i2;
402+ lrow = this.row;
403+ lclm = this.clm;
404+ double lm[][]=this.m;
405+
406+ if(lrow <= 0 || lclm <= 0){
358407 throw new NyARException();
359- }
360- if( mean.getClm() != clm ){
408+ }
409+ if( mean.getClm() != lclm ){
361410 throw new NyARException();
362- }
363- double[] mean_array=mean.getArray();
364- for(int i = 0; i < clm; i++ ){
365- mean_array[i]=0.0;//mean->v[i] = 0.0;
366- }
367-
368- v=mean.getArray();
369- for(int i = 0; i < row; i++ ) {
370- for(int j = 0; j < clm; j++ ){
371- //*(v++) += *(m++);
372- v[j]+=input.m[i][j];
373- }
374- }
375-
376- for(int i = 0; i < clm; i++ ){
377- mean_array[i]/=row;//mean->v[i] /= row;
378- }
411+ }
412+// double[] mean_array=mean.getArray();
413+// mean.zeroClear();
414+ final double[] mean_array=mean.getArray();
415+ double w;
416+ //For順変更禁止
417+ for(i2=0;i2<lclm;i2++){
418+ w=0.0;
419+ for(i=0;i<lrow;i++){
420+ //*(v++) += *(m++);
421+ w+=lm[i][i2];
422+ }
423+ mean_array[i2]=w/lrow;//mean->v[i] /= row;
424+ }
379425 }
380426 /**
381427 * static int CENTER( ARMat *inout, ARVec *mean )の代替関数
@@ -427,12 +473,12 @@ public class NyARMat{
427473 for(int i = 0; i < row; i++ ) {
428474 for(int j = 0; j < row; j++ ) {
429475 if( j < i ) {
430- NyARException.trap("未チェックのパス");{
476+ NyARException.trap("未チェックのパス");
431477 output.m[i][j]=output.m[j][i];//*out = output->m[j*row+i];
432- }
433478 }else{
434- in1=input.getRowArray(i);//in1 = &(input->m[clm*i]);
435- in2=input.getRowArray(j);//in2 = &(input->m[clm*j]);
479+ NyARException.trap("未チェックのパス");
480+ in1=input.m[i];//input.getRowArray(i);//in1 = &(input->m[clm*i]);
481+ in2=input.m[j];//input.getRowArray(j);//in2 = &(input->m[clm*j]);
436482 output.m[i][j]=0;//*out = 0.0;
437483 for(int k = 0; k < clm; k++ ){
438484 output.m[i][j]+=(in1[k]*in2[k]);//*out += *(in1++) * *(in2++);
@@ -444,148 +490,165 @@ public class NyARMat{
444490 }
445491 /**
446492 * static int xt_by_x( ARMat *input, ARMat *output )の代替関数
493+ * Optimize:2008.04.19
447494 * @param input
448- * @param output
495+ * @param i_output
449496 * @throws NyARException
450497 */
451- private static void PCA_xt_by_x(NyARMat input, NyARMat output) throws NyARException
498+ private static void PCA_xt_by_x(NyARMat input, NyARMat i_output) throws NyARException
452499 {
453500 double[] in;
454501 int row, clm;
455502
456503 row = input.row;
457504 clm = input.clm;
458- if(output.row!= clm || output.clm != clm ){
505+ if(i_output.row!= clm || i_output.clm != clm ){
459506 throw new NyARException();
460507 }
461-
508+
509+ int k,j;
510+ double[][] out_m=i_output.m;
511+ double w;
462512 for(int i = 0; i < clm; i++ ) {
463- for(int j = 0; j < clm; j++ ) {
513+ for(j = 0; j < clm; j++ ) {
464514 if( j < i ) {
465- output.m[i][j]=output.m[j][i];//*out = output->m[j*clm+i];
515+ out_m[i][j]=out_m[j][i];//*out = output->m[j*clm+i];
466516 }else{
467- output.m[i][j]=0.0;//*out = 0.0;
468- for(int k = 0; k < row; k++ ){
469- in=input.getRowArray(k);
470- output.m[i][j]+=(in[i]*in[j]);//*out += *in1 * *in2;
517+ w=0.0;//*out = 0.0;
518+ for(k = 0; k < row; k++ ){
519+ in=input.m[k];//in=input.getRowArray(k);
520+ w+=(in[i]*in[j]);//*out += *in1 * *in2;
471521 }
522+ out_m[i][j]=w;
472523 }
473524 }
474525 }
475526 }
527+ private final NyARVec wk_PCA_QRM_ev=new NyARVec(1);
476528 /**
477529 * static int QRM( ARMat *a, ARVec *dv )の代替関数
478530 * @param a
479531 * @param dv
480532 * @throws NyARException
481533 */
482- private static void PCA_QRM(NyARMat a, NyARVec dv) throws NyARException
534+ private void PCA_QRM(NyARVec dv) throws NyARException
483535 {
484- double w, t, s, x, y, c;
485- int dim, iter;
486- double[] dv_array=dv.getArray();
487-
488- dim = a.row;
489- if( dim != a.clm || dim < 2 ){
536+ double w, t, s, x, y, c;
537+ int dim, iter;
538+ double[] dv_array=dv.getArray();
539+
540+ dim = this.row;
541+ if( dim != this.clm || dim < 2 ){
490542 throw new NyARException();
491- }
492- if( dv.getClm() != dim ){
543+ }
544+ if( dv.getClm() != dim ){
493545 throw new NyARException();
494- }
495-
496- NyARVec ev = new NyARVec( dim );
497- double[] ev_array=ev.getArray();
498- if( ev == null ){
546+ }
547+
548+ NyARVec ev = this.wk_PCA_QRM_ev;
549+ ev.realloc(dim);
550+ double[] ev_array=ev.getArray();
551+ if( ev == null ){
499552 throw new NyARException();
500- }
553+ }
501554
502- NyARVec.vecTridiagonalize(a,dv,ev,1);
503-
504- ev_array[0]=0.0;//ev->v[0] = 0.0;
505- for(int h = dim-1; h > 0; h-- ) {
506- int j = h;
507- while(j>0 && Math.abs(ev_array[j]) > PCA_EPS*(Math.abs(dv_array[j-1])+Math.abs(dv_array[j]))){// while(j>0 && fabs(ev->v[j]) > EPS*(fabs(dv->v[j-1])+fabs(dv->v[j]))) j--;
508- j--;
509- }
510- if( j == h ){
511- continue;
512- }
513- iter = 0;
514- do{
515- iter++;
516- if( iter > PCA_MAX_ITER ){
517- break;
518- }
519- w = (dv_array[h-1] - dv_array[h]) / 2;//w = (dv->v[h-1] - dv->v[h]) / 2;//ここ?
520- t = ev_array[h] * ev_array[h];//t = ev->v[h] * ev->v[h];
521- s = Math.sqrt(w*w+t);
522- if( w < 0 ){
523- s = -s;
524- }
525- x=dv_array[j] - dv_array[h] + t/(w+s);//x = dv->v[j] - dv->v[h] + t/(w+s);
526- y=ev_array[j+1];//y = ev->v[j+1];
527- for(int k = j; k < h; k++ ){
528- if( Math.abs(x) >= Math.abs(y)){
529- if( Math.abs(x) > PCA_VZERO ) {
530- t = -y / x;
531- c = 1 / Math.sqrt(t*t+1);
532- s = t * c;
533- }else{
534- c = 1.0;
535- s = 0.0;
536- }
537- }else{
538- t = -x / y;
539- s = 1.0 / Math.sqrt(t*t+1);
540- c = t * s;
541- }
542- w = dv_array[k] - dv_array[k+1];//w = dv->v[k] - dv->v[k+1];
543- t = (w * s + 2 * c * ev_array[k+1]) * s;//t = (w * s + 2 * c * ev->v[k+1]) * s;
544- dv_array[k]-=t;//dv->v[k] -= t;
545- dv_array[k+1]+=t;//dv->v[k+1] += t;
546- if( k > j){
547- NyARException.trap("未チェックパス");{
548- ev_array[k]=c * ev_array[k] - s * y;//ev->v[k] = c * ev->v[k] - s * y;
549- }
550- }
551- ev_array[k+1]+=s * (c * w - 2 * s * ev_array[k+1]);//ev->v[k+1] += s * (c * w - 2 * s * ev->v[k+1]);
552-
553- for(int i = 0; i < dim; i++ ){
554- x = a.m[k][i];//x = a->m[k*dim+i];
555- y = a.m[k+1][i];//y = a->m[(k+1)*dim+i];
556- a.m[k][i]=c * x - s * y;//a->m[k*dim+i] = c * x - s * y;
557- a.m[k+1][i]=s * x + c * y;//a->m[(k+1)*dim+i] = s * x + c * y;
558- }
559- if( k < h-1 ) {
560- NyARException.trap("未チェックパス");{
561- x = ev_array[k+1];//x = ev->v[k+1];
562- y =-s*ev_array[k+2];//y = -s * ev->v[k+2];
563- ev_array[k+2]*=c;//ev->v[k+2] *= c;
564- }
565- }
566- }
567- }while(Math.abs(ev_array[h]) > PCA_EPS*(Math.abs(dv_array[h-1])+Math.abs(dv_array[h])));
568- }
569- double[] v1,v2;
570- for(int k = 0; k < dim-1; k++ ) {
571- int h = k;
572- t=dv_array[h];//t = dv->v[h];
573- for(int i = k+1; i < dim; i++ ){
574- if(dv_array[i] > t ){//if( dv->v[i] > t ) {
575- h = i;
576- t=dv_array[h];//t = dv->v[h];
577- }
578- }
579- dv_array[h]=dv_array[k];//dv->v[h] = dv->v[k];
580- dv_array[k]=t;//dv->v[k] = t;
581- v1=a.getRowArray(h);//v1 = &(a->m[h*dim]);
582- v2=a.getRowArray(k);//v2 = &(a->m[k*dim]);
583- for(int i = 0; i < dim; i++ ) {
584- w=v1[i];//w = *v1;
585- v1[i]=v2[i];//*v1 = *v2;
586- v2[i]=w;//*v2 = w;
587- }
588- }
555+ this.vecTridiagonalize(dv,ev,1);
556+
557+ ev_array[0]=0.0;//ev->v[0] = 0.0;
558+ for(int h = dim-1; h > 0; h-- ) {
559+ int j = h;
560+ while(j>0 && Math.abs(ev_array[j]) > PCA_EPS*(Math.abs(dv_array[j-1])+Math.abs(dv_array[j]))){// while(j>0 && fabs(ev->v[j]) > EPS*(fabs(dv->v[j-1])+fabs(dv->v[j]))) j--;
561+ j--;
562+ }
563+ if( j == h ){
564+ continue;
565+ }
566+ iter = 0;
567+ do{
568+ iter++;
569+ if( iter > PCA_MAX_ITER ){
570+ break;
571+ }
572+ w = (dv_array[h-1] - dv_array[h]) / 2;//w = (dv->v[h-1] - dv->v[h]) / 2;//ここ?
573+ t = ev_array[h] * ev_array[h];//t = ev->v[h] * ev->v[h];
574+ s = Math.sqrt(w*w+t);
575+ if( w < 0 ){
576+ s = -s;
577+ }
578+ x=dv_array[j] - dv_array[h] + t/(w+s);//x = dv->v[j] - dv->v[h] + t/(w+s);
579+ y=ev_array[j+1];//y = ev->v[j+1];
580+ for(int k = j; k < h; k++ ){
581+ if( Math.abs(x) >= Math.abs(y)){
582+ if( Math.abs(x) > PCA_VZERO ) {
583+ t = -y / x;
584+ c = 1 / Math.sqrt(t*t+1);
585+ s = t * c;
586+ }else{
587+ c = 1.0;
588+ s = 0.0;
589+ }
590+ }else{
591+ t = -x / y;
592+ s = 1.0 / Math.sqrt(t*t+1);
593+ c = t * s;
594+ }
595+ w = dv_array[k] - dv_array[k+1];//w = dv->v[k] - dv->v[k+1];
596+ t = (w * s + 2 * c * ev_array[k+1]) * s;//t = (w * s + 2 * c * ev->v[k+1]) * s;
597+ dv_array[k]-=t;//dv->v[k] -= t;
598+ dv_array[k+1]+=t;//dv->v[k+1] += t;
599+ if( k > j){
600+ NyARException.trap("未チェックパス");{
601+ ev_array[k]=c * ev_array[k] - s * y;//ev->v[k] = c * ev->v[k] - s * y;
602+ }
603+ }
604+ ev_array[k+1]+=s * (c * w - 2 * s * ev_array[k+1]);//ev->v[k+1] += s * (c * w - 2 * s * ev->v[k+1]);
605+
606+ for(int i = 0; i < dim; i++ ){
607+ x = this.m[k][i];//x = a->m[k*dim+i];
608+ y = this.m[k+1][i];//y = a->m[(k+1)*dim+i];
609+ this.m[k][i]=c * x - s * y;//a->m[k*dim+i] = c * x - s * y;
610+ this.m[k+1][i]=s * x + c * y;//a->m[(k+1)*dim+i] = s * x + c * y;
611+ }
612+ if( k < h-1 ) {
613+ NyARException.trap("未チェックパス");{
614+ x = ev_array[k+1];//x = ev->v[k+1];
615+ y =-s*ev_array[k+2];//y = -s * ev->v[k+2];
616+ ev_array[k+2]*=c;//ev->v[k+2] *= c;
617+ }
618+ }
619+ }
620+ }while(Math.abs(ev_array[h]) > PCA_EPS*(Math.abs(dv_array[h-1])+Math.abs(dv_array[h])));
621+ }
622+ for(int k = 0; k < dim-1; k++ ) {
623+ int h = k;
624+ t=dv_array[h];//t = dv->v[h];
625+ for(int i = k+1; i < dim; i++ ){
626+ if(dv_array[i] > t ){//if( dv->v[i] > t ) {
627+ h = i;
628+ t=dv_array[h];//t = dv->v[h];
629+ }
630+ }
631+ dv_array[h]=dv_array[k];//dv->v[h] = dv->v[k];
632+ dv_array[k]=t;//dv->v[k] = t;
633+ this.flipRow(h,k);
634+ }
635+ }
636+ /**
637+ * i_row_1番目の行と、i_row_2番目の行を入れ替える。
638+ * @param i_row_1
639+ * @param i_row_2
640+ */
641+ private void flipRow(int i_row_1,int i_row_2)
642+ {
643+ int i;
644+ double w;
645+ double[] r1=this.m[i_row_1],r2=this.m[i_row_2];
646+ //For順変更OK
647+ for(i=clm-1;i>=0;i--){
648+ w=r1[i];
649+ r1[i]=r2[i];
650+ r2[i]=w;
651+ }
589652 }
590653 /**
591654 * static int EV_create( ARMat *input, ARMat *u, ARMat *output, ARVec *ev )の代替関数
@@ -617,8 +680,9 @@ public class NyARMat{
617680 double[] m1,ev_array;
618681 double sum, work;
619682
620- m =output.getArray();//m = output->m;
621- in=input.getArray();
683+ NyARException.trap("未チェックのパス");
684+ m =output.m;//m = output->m;
685+ in=input.m;
622686 int i;
623687 ev_array=ev.getArray();
624688 for(i = 0; i < row; i++ ) {
@@ -630,7 +694,7 @@ public class NyARMat{
630694 work = 1 / Math.sqrt(Math.abs(ev_array[i]));//work = 1 / sqrt(fabs(ev->v[i]));
631695 for(int j = 0; j < clm; j++ ) {
632696 sum = 0.0;
633- m1=u.getRowArray(i);//m1 = &(u->m[i*row]);
697+ m1=u.m[i];//m1 = &(u->m[i*row]);
634698 // m2=input.getPointer(j);//m2 = &(input->m[j]);
635699 for(int k = 0; k < row; k++ ) {
636700 sum+=m1[k]+in[k][j];//sum += *m1 * *m2;
@@ -653,46 +717,61 @@ public class NyARMat{
653717 }
654718 }
655719 }
656- /*static int PCA( ARMat *input, ARMat *output, ARVec *ev )*/
657- private static void PCA_PCA(NyARMat input, NyARMat output, NyARVec ev) throws NyARException
720+ private NyARMat wk_PCA_PCA_u=null;
721+ /**
722+ * static int PCA( ARMat *input, ARMat *output, ARVec *ev )
723+ *
724+ * @param output
725+ * @param o_ev
726+ * @throws NyARException
727+ */
728+ private void PCA_PCA(NyARMat o_output, NyARVec o_ev) throws NyARException
658729 {
659- NyARMat u;
660- int row, clm, min;
661- double[] ev_array=ev.getArray();
730+
731+ int l_row, l_clm, min;
732+ double[] ev_array=o_ev.getArray();
662733
663- row =input.row;//row = input->row;
664- clm =input.clm;//clm = input->clm;
665- min =(clm < row)? clm: row;
666- if( row < 2 || clm < 2 ){
734+ l_row =this.row;//row = input->row;
735+ l_clm =this.clm;//clm = input->clm;
736+ min =(l_clm < l_row)? l_clm: l_row;
737+ if( l_row < 2 || l_clm < 2 ){
667738 throw new NyARException();
668739 }
669- if( output.clm != input.clm){//if( output->clm != input->clm ){
740+ if( o_output.clm != this.clm){//if( output->clm != input->clm ){
670741 throw new NyARException();
671742 }
672- if( output.row!= min ){//if( output->row != min ){
743+ if( o_output.row!= min ){//if( output->row != min ){
673744 throw new NyARException();
674745 }
675- if( ev.getClm() != min ){//if( ev->clm != min ){
746+ if( o_ev.getClm() != min ){//if( ev->clm != min ){
676747 throw new NyARException();
677748 }
678- u =new NyARMat( min, min );
749+
750+ NyARMat u;// u =new NyARMat( min, min );
751+ if(this.wk_PCA_PCA_u==null){
752+ u=new NyARMat( min, min );
753+ this.wk_PCA_PCA_u=u;
754+ }else{
755+ u=this.wk_PCA_PCA_u;
756+ u.realloc(min,min);
757+ }
758+
679759
680- if( row < clm ){
760+ if( l_row < l_clm ){
681761 NyARException.trap("未チェックのパス");
682- PCA_x_by_xt( input, u );//if(x_by_xt( input, u ) < 0 ) {
762+ PCA_x_by_xt( this, u );//if(x_by_xt( input, u ) < 0 ) {
683763 }else{
684- PCA_xt_by_x( input, u );//if(xt_by_x( input, u ) < 0 ) {
764+ PCA_xt_by_x( this, u );//if(xt_by_x( input, u ) < 0 ) {
685765 }
686- PCA_QRM( u, ev );
766+ u.PCA_QRM(o_ev);
687767
688768 double[][] m1,m2;
689- if( row < clm ) {
690- NyARException.trap("未チェックのパス");{
691- PCA_EV_create( input, u, output, ev );
692- }
769+ if( l_row < l_clm ) {
770+ NyARException.trap("未チェックのパス");
771+ PCA_EV_create( this, u, o_output, o_ev );
693772 }else{
694773 m1=u.m;//m1 = u->m;
695- m2=output.m;//m2 = output->m;
774+ m2=o_output.m;//m2 = output->m;
696775 int i;
697776 for(i = 0; i < min; i++){
698777 if( ev_array[i] < PCA_VZERO){//if( ev->v[i] < VZERO ){
@@ -711,53 +790,76 @@ public class NyARMat{
711790 }
712791 }
713792 }
714-
715- /*int arMatrixPCA( ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean );*/
716- public static void matrixPCA(NyARMat input, NyARMat evec, NyARVec ev, NyARVec mean) throws NyARException
793+ private NyARMat wk_work_matrixPCA=null;
794+ /**
795+ * int arMatrixPCA( ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean );
796+ * 関数の置き換え。input引数がthisになる。
797+ * Optimize:2008.04.19
798+ * @param o_evec
799+ * @param o_ev
800+ *
801+ * @param mean
802+ * @throws NyARException
803+ */
804+ public void matrixPCA(NyARMat o_evec, NyARVec o_ev, NyARVec mean) throws NyARException
717805 {
718- NyARMat work;
719806 double srow, sum;
720- int row, clm;
807+ int l_row, l_clm;
721808 int check;
722-
723- row=input.row;//row = input->row;
724- clm=input.clm;//clm = input->clm;
725- check = (row < clm)? row: clm;
726- if( row < 2 || clm < 2 ){
809+
810+
811+ l_row=this.row;//row = input->row;
812+ l_clm=this.clm;//clm = input->clm;
813+ check = (l_row < l_clm)? l_row: l_clm;
814+ if( l_row < 2 || l_clm < 2 ){
727815 throw new NyARException();
728816 }
729- if( evec.clm != input.clm || evec.row != check ){//if( evec->clm != input->clm || evec->row != check ){
817+ if( o_evec.clm != l_clm || o_evec.row != check ){//if( evec->clm != input->clm || evec->row != check ){
730818 throw new NyARException();
731819 }
732- if( ev.getClm() != check ){//if( ev->clm != check ){
820+ if( o_ev.getClm() != check ){//if( ev->clm != check ){
733821 throw new NyARException();
734822 }
735- if( mean.getClm() != input.clm){//if( mean->clm != input->clm ){
823+ if( mean.getClm() != l_clm){//if( mean->clm != input->clm ){
736824 throw new NyARException();
737825 }
826+
827+ //自分の内容をワークにコピー(高速化の為に、1度作ったインスタンスは使いまわす)
828+ NyARMat work;
829+ if(this.wk_work_matrixPCA==null){
830+ work=this.matrixAllocDup();
831+ this.wk_work_matrixPCA=work;
832+ }else{
833+ work=this.wk_work_matrixPCA;
834+ work.matrixDup(this);//arMatrixAllocDup( input );work = arMatrixAllocDup( input );
835+ }
836+
738837
739- work =input.matrixAllocDup();//arMatrixAllocDup( input );work = arMatrixAllocDup( input );
740-
741- srow = Math.sqrt((double)row);
742- PCA_EX( work, mean );
838+ srow = Math.sqrt((double)l_row);
839+ work.PCA_EX(mean );
743840
744841 PCA_CENTER(work,mean);
745842
746843
747- for(int i=0; i<row; i++){
748- for(int j=0;j<clm;j++){
844+ int i,j;
845+ //For順変更OK
846+ for(i=0; i<l_row; i++){
847+ for(j=0;j<l_clm;j++){
749848 work.m[i][j]/=srow;//work->m[i] /= srow;
750849 }
751850 }
752851
753- PCA_PCA( work, evec, ev );
852+ work.PCA_PCA(o_evec, o_ev);
754853
755854 sum = 0.0;
756- double[] ev_array=ev.getArray();
757- for(int i = 0; i < ev.getClm(); i++ ){//for(int i = 0; i < ev->clm; i++ ){
855+ double[] ev_array=o_ev.getArray();
856+ int ev_clm=o_ev.getClm();
857+ //For順変更禁止
858+ for(i=0;i<ev_clm;i++){//for(int i = 0; i < ev->clm; i++ ){
758859 sum+=ev_array[i];//sum += ev->v[i];
759860 }
760- for(int i = 0; i < ev.getClm(); i++ ){//for(int i = 0; i < ev->clm; i++ ){
861+ //For順変更禁止
862+ for(i=0;i<ev_clm;i++){//for(int i = 0; i < ev->clm; i++ ){
761863 ev_array[i]/=sum;//ev->v[i] /= sum;
762864 }
763865 }
@@ -789,7 +891,7 @@ public class NyARMat{
789891 work =input.matrixAllocDup();
790892
791893 NyARException.trap("未チェックパス");
792- PCA_PCA( work, evec, ev );//rval = PCA( work, evec, ev );
894+ work.PCA_PCA(evec, ev );//rval = PCA( work, evec, ev );
793895 sum = 0.0;
794896 double[] ev_array=ev.getArray();
795897 for(int i = 0; i < ev.getClm(); i++ ){//for( i = 0; i < ev->clm; i++ ){
@@ -807,7 +909,7 @@ public class NyARMat{
807909 NyARException.trap("未チェックのパス");
808910 NyARMat dest=new NyARMat(a.row, b.clm);
809911 NyARException.trap("未チェックのパス");
810- matrixMul(dest, a, b);
912+ dest.matrixMul(a, b);
811913 return dest;
812914 }
813915 /*static double mdet(double *ap, int dimen, int rowa)*/
@@ -860,4 +962,122 @@ public class NyARMat{
860962 }
861963 return Det_mdet(m.getArray(), m.row, m.clm);//return mdet(m->m, m->row, m->row);
862964 }
965+ private final NyARVec wk_vecTridiagonalize_vec=new NyARVec(0);
966+ private final NyARVec wk_vecTridiagonalize_vec2=new NyARVec(0);
967+ /**
968+ * arVecTridiagonalize関数の代替品
969+ * a,d,e間で演算をしてる。何をどうしているかはさっぱりさっぱり
970+ * @param a
971+ * @param d
972+ * @param e
973+ * @param i_e_start
974+ * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)
975+ * @return
976+ * @throws NyARException
977+ */
978+ private void vecTridiagonalize(NyARVec d, NyARVec e,int i_e_start) throws NyARException
979+ {
980+ NyARVec vec=wk_vecTridiagonalize_vec;
981+ //double[][] a_array=a.getArray();
982+ double s, t, p, q;
983+ int dim;
984+
985+ if(this.clm!=this.row){//if(a.getClm()!=a.getRow()){
986+ throw new NyARException();
987+ }
988+ if(this.clm != d.getClm()){//if(a.getClm() != d.clm){
989+ throw new NyARException();
990+ }
991+ if(this.clm != e.getClm()){//if(a.getClm() != e.clm){
992+ throw new NyARException();
993+ }
994+ dim = this.getClm();
995+
996+ double[] d_vec,e_vec;
997+ d_vec=d.getArray();
998+ e_vec=e.getArray();
999+ double[] a_vec_k;
1000+
1001+ for(int k = 0; k < dim-2; k++ ){
1002+
1003+ a_vec_k=this.m[k];
1004+ vec.setNewArray(a_vec_k,clm);//vec=this.getRowVec(k);//double[] vec_array=vec.getArray();
1005+ NyARException.trap("未チェックパス");
1006+ d_vec[k]=a_vec_k[k];//d.v[k]=vec.v[k];//d.set(k,v.get(k)); //d->v[k] = v[k];
1007+
1008+ //wv1.clm = dim-k-1;
1009+ //wv1.v = &(v[k+1]);
1010+ NyARException.trap("未チェックパス");
1011+ e_vec[k+i_e_start]=vec.vecHousehold(k+1);//e.v[k+i_e_start]=vec.vecHousehold(k+1);//e->v[k] = arVecHousehold(&wv1);
1012+ if(e_vec[k+i_e_start]== 0.0 ){//if(e.v[k+i_e_start]== 0.0 ){//if(e.v[k+i_e_start]== 0.0 ){
1013+ continue;
1014+ }
1015+
1016+ for(int i = k+1; i < dim; i++ ){
1017+ s = 0.0;
1018+ for(int j = k+1; j < i; j++ ) {
1019+ NyARException.trap("未チェックのパス");
1020+ s += this.m[j][i] * a_vec_k[j];//s += a_array[j][i] * vec.v[j];//s += a.get(j*dim+i) * v.get(j);//s += a->m[j*dim+i] * v[j];
1021+ }
1022+ for(int j = i; j < dim; j++ ) {
1023+ NyARException.trap("未チェックのパス");
1024+ s += this.m[i][j] * a_vec_k[j];//s += a_array[i][j] * vec.v[j];//s += a.get(i*dim+j) * v.get(j);//s += a->m[i*dim+j] * v[j];
1025+ }
1026+ NyARException.trap("未チェックのパス");
1027+ d_vec[i]=s;//d.v[i]=s;//d->v[i] = s;
1028+ }
1029+
1030+
1031+ //wv1.clm = wv2.clm = dim-k-1;
1032+ //wv1.v = &(v[k+1]);
1033+ //wv2.v = &(d->v[k+1]);
1034+ a_vec_k=this.m[k];
1035+ vec.setNewArray(a_vec_k,clm);//vec=this.getRowVec(k);
1036+// vec_array=vec.getArray();
1037+ NyARException.trap("未チェックパス");
1038+ t = vec.vecInnerproduct(d,k+1)/ 2;
1039+ for(int i = dim-1; i > k; i-- ) {
1040+ NyARException.trap("未チェックパス");
1041+ p = a_vec_k[i];//p = v.get(i);//p = v[i];
1042+ d_vec[i]-=t*p;q=d_vec[i];//d.v[i]-=t*p;q=d.v[i];//q = d->v[i] -= t*p;
1043+ for(int j = i; j < dim; j++ ){
1044+ NyARException.trap("未チェックパス");
1045+ this.m[i][j]-=p*(d_vec[j] + q*a_vec_k[j]);//a.m[i][j]-=p*(d.v[j] + q*vec.v[j]);//a->m[i*dim+j] -= p*(d->v[j]) + q*v[j];
1046+ }
1047+ }
1048+ }
1049+
1050+ if( dim >= 2) {
1051+ d_vec[dim-2]=this.m[dim-2][dim-2];//d.v[dim-2]=a.m[dim-2][dim-2];//d->v[dim-2] = a->m[(dim-2)*dim+(dim-2)];
1052+ e_vec[dim-2+i_e_start]=this.m[dim-2][dim-1];//e.v[dim-2+i_e_start]=a.m[dim-2][dim-1];//e->v[dim-2] = a->m[(dim-2)*dim+(dim-1)];
1053+ }
1054+
1055+ if( dim >= 1 ){
1056+ d_vec[dim-1]=this.m[dim-1][dim-1];//d.v[dim-1]=a_array[dim-1][dim-1];//d->v[dim-1] = a->m[(dim-1)*dim+(dim-1)];
1057+ }
1058+ NyARVec vec2=this.wk_vecTridiagonalize_vec2;
1059+ for(int k = dim-1; k >= 0; k--) {
1060+ a_vec_k=this.m[k];
1061+ vec.setNewArray(a_vec_k,clm);//vec=this.getRowVec(k);//v = a.getPointer(k*dim);//v = &(a->m[k*dim]);
1062+ if( k < dim-2 ) {
1063+ for(int i = k+1; i < dim; i++ ){
1064+ //wv1.clm = wv2.clm = dim-k-1;
1065+ //wv1.v = &(v[k+1]);
1066+ //wv2.v = &(a->m[i*dim+k+1]);
1067+ vec2.setNewArray(this.m[i],clm);//vec2=this.getRowVec(i);
1068+
1069+ t = vec.vecInnerproduct(vec2,k+1);
1070+ for(int j = k+1; j < dim; j++ ){
1071+ NyARException.trap("未チェックパス");
1072+ this.m[i][j]-=t*a_vec_k[j];//a_array[i][j]-=t*vec.v[j];//a.subValue(i*dim+j,t*v.get(j));//a->m[i*dim+j] -= t * v[j];
1073+ }
1074+ }
1075+ }
1076+ for(int i = 0; i < dim; i++ ){
1077+ a_vec_k[i]=0.0;//v.set(i,0.0);//v[i] = 0.0;
1078+ }
1079+ a_vec_k[k]=1;//v.set(k,1);//v[k] = 1;
1080+ }
1081+ return;
1082+ }
8631083 }
\ No newline at end of file
--- a/trunk/src/jp/nyatla/nyartoolkit/core/NyARParam.java
+++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARParam.java
@@ -47,8 +47,8 @@ public class NyARParam{
4747 private static final int SIZE_OF_PARAM_SET=4+4+(3*4*8)+(4*8);
4848 private static final int PD_LOOP = 3;
4949 protected int xsize, ysize;
50- private double[][] mat=new double[3][4];//Double2dArray mat=new Double2dArray(3,4);
51- private double[] dist_factor=new double[4];
50+ private double[] array34=new double[3*4];//Double2dArray mat=new Double2dArray(3,4);
51+ private double[] dist_factor=new double[4];
5252 public int getX()
5353 {
5454 return xsize;
@@ -61,9 +61,13 @@ public class NyARParam{
6161 {
6262 return dist_factor;
6363 }
64- public double[][] getMat()
64+ /**
65+ * パラメタを格納した[4x3]配列を返します。
66+ * @return
67+ */
68+ public final double[] get34Array()
6569 {
66- return mat;
70+ return array34;
6771 }
6872 /**
6973 * ARToolKit標準ファイルから1個目の設定をロードする。
@@ -85,25 +89,26 @@ public class NyARParam{
8589 i_stream.close();
8690 xsize = new_inst[0].xsize;
8791 ysize = new_inst[0].ysize;
88- mat = new_inst[0].mat;
92+ array34 = new_inst[0].array34;
8993 dist_factor = new_inst[0].dist_factor;
9094 } catch (Exception e) {
9195 throw new NyARException(e);
9296 }
9397 }
9498 /*static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )*/
95- private static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )
99+ private final static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )
96100 {
97101 return( a1 * b1 + a2 * b2 + a3 * b3 );
98102 }
99103 /* static double norm( double a, double b, double c )*/
100- private static double norm( double a, double b, double c )
104+ private final static double norm( double a, double b, double c )
101105 {
102106 return Math.sqrt( a*a + b*b + c*c );
103107 }
104108 /**
105109 * int arParamDecompMat( double source[3][4], double cpara[3][4], double trans[3][4] );
106110 * 関数の置き換え
111+ * Optimize STEP[754->665]
107112 * @param o_cpara
108113 * 戻り引数。3x4のマトリクスを指定すること。
109114 * @param o_trans
@@ -112,22 +117,32 @@ public class NyARParam{
112117 */
113118 public void decompMat(NyARMat o_cpara, NyARMat o_trans)
114119 {
115- double[][] source=mat;
116- double[][] Cpara=new double[3][4];//double Cpara[3][4];
120+ double[] source=array34;
121+ double[] Cpara=new double[3*4];//double Cpara[3][4];
117122 double rem1, rem2, rem3;
118-
119- if(source[2][3]>= 0 ){//if( source[2][3] >= 0 ) {
120- for(int r = 0; r < 3; r++ ){
121- for(int c = 0; c < 4; c++ ){
122- Cpara[r][c]=source[r][c];//Cpara[r][c] = source[r][c];
123- }
123+ int i;
124+ if(source[2*4+3]>= 0 ){//if( source[2][3] >= 0 ) {
125+ //<Optimize>
126+ //for(int r = 0; r < 3; r++ ){
127+ // for(int c = 0; c < 4; c++ ){
128+ // Cpara[r][c]=source[r][c];//Cpara[r][c] = source[r][c];
129+ // }
130+ //}
131+ for(i=0;i<12;i++){
132+ Cpara[i]=source[i];//Cpara[r][c] = source[r][c];
124133 }
134+ //</Optimize>
125135 }else {
126- for(int r = 0; r < 3; r++ ){
127- for(int c = 0; c < 4; c++ ){
128- Cpara[r][c]=-source[r][c];//Cpara[r][c] = -(source[r][c]);
129- }
136