• R/O
  • SSH
  • HTTPS

matereal: 提交


Commit MetaInfo

修订版192 (tree)
时间2010-11-12 09:44:32
作者arc

Log Message

removed unused source files of NyARToolkit.

更改概述

  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/processor/SingleNyIdMarkerProcesser.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/processor
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample/NyIdTest.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample/SingleARMarkerTest.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/TransformedBitmapPickup.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/j2se/LabelingBufferdImage.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/j2se/NyARRasterImageIO.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/j2se
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPickup.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPattern.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerParam.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerData_RawBit.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerDataEncoder_RawBit.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerData.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerDataEncoder.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit_O2.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotVector.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver_ARToolKit.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver/INyARTransportVectorSolver.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat_ARToolKit.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/INyARTransMat.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARRectOffset.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARPartialDifferentiationOptimize.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/INyARRotMatrixOptimize.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_Base.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_O2.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java
  • delete: napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat

差异

--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java (nonexistent)
@@ -1,367 +0,0 @@
1-/*
2- * Capture Test NyARToolkitCSサンプルプログラム
3- * --------------------------------------------------------------------------------
4- * The NyARToolkit is Java edition ARToolKit class library.
5- * Copyright (C)2008-2009 Ryo Iizuka
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- *
20- * For further information please contact.
21- * http://nyatla.jp/nyatoolkit/
22- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
23- *
24- */
25-package jp.nyatla.nyartoolkit.processor;
26-
27-import jp.nyatla.nyartoolkit.NyARException;
28-import jp.nyatla.nyartoolkit.core.*;
29-import jp.nyatla.nyartoolkit.core.analyzer.raster.threshold.*;
30-import jp.nyatla.nyartoolkit.core.match.*;
31-import jp.nyatla.nyartoolkit.core.param.*;
32-import jp.nyatla.nyartoolkit.core.pickup.*;
33-import jp.nyatla.nyartoolkit.core.raster.*;
34-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
35-import jp.nyatla.nyartoolkit.core.transmat.*;
36-import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;
37-import jp.nyatla.nyartoolkit.core.types.*;
38-import jp.nyatla.nyartoolkit.core.squaredetect.*;
39-
40-/**
41- * このクラスは、同時に1個のマーカを処理することのできる、アプリケーションプロセッサです。
42- * マーカの出現・移動・消滅を、イベントで通知することができます。
43- * クラスには複数のマーカを登録できます。一つのマーカが見つかると、プロセッサは継続して同じマーカを
44- * 1つだけ認識し続け、見失うまでの間は他のマーカを認識しません。
45- *
46- * イベントは、 OnEnter→OnUpdate[n]→OnLeaveの順で発生します。
47- * マーカが見つかるとまずOnEnterが1度発生して、何番のマーカが発見されたかがわかります。
48- * 次にOnUpdateにより、現在の変換行列が連続して渡されます。最後にマーカを見失うと、OnLeave
49- * イベントが発生します。
50- *
51- */
52-public abstract class SingleARMarkerProcesser
53-{
54- /**
55- * detectMarkerのコールバック関数
56- */
57- private class DetectSquareCB implements NyARSquareContourDetector.IDetectMarkerCallback
58- {
59- //公開プロパティ
60- public final NyARSquare square=new NyARSquare();
61- public double confidence=0.0;
62- public int code_index=-1;
63- public double cf_threshold_new = 0.50;
64- public double cf_threshold_exist = 0.30;
65-
66- //参照
67- private INyARRgbRaster _ref_raster;
68- //所有インスタンス
69- private INyARColorPatt _inst_patt;
70- private NyARMatchPattDeviationColorData _deviation_data;
71- private NyARMatchPatt_Color_WITHOUT_PCA[] _match_patt;
72- private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult();
73- private NyARCoord2Linear _coordline;
74-
75- public DetectSquareCB(NyARParam i_param)
76- {
77- this._match_patt=null;
78- this._coordline=new NyARCoord2Linear(i_param.getScreenSize(),i_param.getDistortionFactor());
79- return;
80- }
81- public void setNyARCodeTable(NyARCode[] i_ref_code,int i_code_resolution)
82- {
83- /*unmanagedで実装するときは、ここでリソース解放をすること。*/
84- this._deviation_data=new NyARMatchPattDeviationColorData(i_code_resolution,i_code_resolution);
85- this._inst_patt=new NyARColorPatt_Perspective_O2(i_code_resolution,i_code_resolution,4,25);
86- this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA[i_ref_code.length];
87- for(int i=0;i<i_ref_code.length;i++){
88- this._match_patt[i]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[i]);
89- }
90- }
91- private NyARIntPoint2d[] __tmp_vertex=NyARIntPoint2d.createArray(4);
92- private int _target_id;
93- /**
94- * Initialize call back handler.
95- */
96- public void init(INyARRgbRaster i_raster,int i_target_id)
97- {
98- this._ref_raster=i_raster;
99- this._target_id=i_target_id;
100- this.code_index=-1;
101- this.confidence=Double.MIN_NORMAL;
102- }
103-
104- /**
105- * 矩形が見付かるたびに呼び出されます。
106- * 発見した矩形のパターンを検査して、方位を考慮した頂点データを確保します。
107- */
108- public void onSquareDetect(NyARSquareContourDetector i_sender,int[] i_coordx,int[] i_coordy,int i_coor_num,int[] i_vertex_index) throws NyARException
109- {
110- if (this._match_patt==null) {
111- return;
112- }
113- //輪郭座標から頂点リストに変換
114- NyARIntPoint2d[] vertex=this.__tmp_vertex;
115- vertex[0].x=i_coordx[i_vertex_index[0]];
116- vertex[0].y=i_coordy[i_vertex_index[0]];
117- vertex[1].x=i_coordx[i_vertex_index[1]];
118- vertex[1].y=i_coordy[i_vertex_index[1]];
119- vertex[2].x=i_coordx[i_vertex_index[2]];
120- vertex[2].y=i_coordy[i_vertex_index[2]];
121- vertex[3].x=i_coordx[i_vertex_index[3]];
122- vertex[3].y=i_coordy[i_vertex_index[3]];
123-
124- //画像を取得
125- if (!this._inst_patt.pickFromRaster(this._ref_raster,vertex)){
126- return;//取得失敗
127- }
128- //取得パターンをカラー差分データに変換して評価する。
129- this._deviation_data.setRaster(this._inst_patt);
130-
131-
132- //code_index,dir,c1にデータを得る。
133- final NyARMatchPattResult mr=this.__detectMarkerLite_mr;
134- int lcode_index = 0;
135- int dir = 0;
136- double c1 = 0;
137- for (int i = 0; i < this._match_patt.length; i++) {
138- this._match_patt[i].evaluate(this._deviation_data,mr);
139- double c2 = mr.confidence;
140- if (c1 < c2) {
141- lcode_index = i;
142- c1 = c2;
143- dir = mr.direction;
144- }
145- }
146-
147- //認識処理
148- if (this._target_id == -1) { // マーカ未認識
149- //現在は未認識
150- if (c1 < this.cf_threshold_new) {
151- return;
152- }
153- if (this.confidence > c1) {
154- // 一致度が低い。
155- return;
156- }
157- //認識しているマーカIDを保存
158- this.code_index=lcode_index;
159- }else{
160- //現在はマーカ認識中
161- // 現在のマーカを認識したか?
162- if (lcode_index != this._target_id) {
163- // 認識中のマーカではないので無視
164- return;
165- }
166- //認識中の閾値より大きいか?
167- if (c1 < this.cf_threshold_exist) {
168- return;
169- }
170- //現在の候補よりも一致度は大きいか?
171- if (this.confidence>c1) {
172- return;
173- }
174- this.code_index=this._target_id;
175- }
176- //新しく認識、または継続認識中に更新があったときだけ、Square情報を更新する。
177- //ココから先はこの条件でしか実行されない。
178-
179- //一致率の高い矩形があれば、方位を考慮して頂点情報を作成
180- this.confidence=c1;
181- NyARSquare sq=this.square;
182- //directionを考慮して、squareを更新する。
183- for(int i=0;i<4;i++){
184- int idx=(i+4 - dir) % 4;
185- this._coordline.coord2Line(i_vertex_index[idx],i_vertex_index[(idx+1)%4],i_coordx,i_coordy,i_coor_num,sq.line[i]);
186- }
187- for (int i = 0; i < 4; i++) {
188- //直線同士の交点計算
189- if(!NyARLinear.crossPos(sq.line[i],sq.line[(i + 3) % 4],sq.sqvertex[i])){
190- throw new NyARException();//ここのエラー復帰するならダブルバッファにすればOK
191- }
192- }
193- }
194- }
195- /**オーナーが自由に使えるタグ変数です。
196- */
197- public Object tag;
198-
199- private int _lost_delay_count = 0;
200-
201- private int _lost_delay = 5;
202-
203- private NyARSquareContourDetector _square_detect;
204-
205- protected INyARTransMat _transmat;
206-
207- private NyARRectOffset _offset;
208- private int _threshold = 110;
209- // [AR]検出結果の保存用
210- private NyARBinRaster _bin_raster;
211-
212- private NyARRasterFilter_ARToolkitThreshold _tobin_filter;
213-
214- protected int _current_arcode_index = -1;
215-
216- private NyARRasterThresholdAnalyzer_SlidePTile _threshold_detect;
217-
218- protected SingleARMarkerProcesser()
219- {
220- return;
221- }
222-
223- private boolean _initialized=false;
224-
225- protected void initInstance(NyARParam i_param,int i_raster_type) throws NyARException
226- {
227- //初期化済?
228- assert(this._initialized==false);
229-
230- NyARIntSize scr_size = i_param.getScreenSize();
231- // 解析オブジェクトを作る
232- this._square_detect = new NyARSquareContourDetector_Rle(scr_size);
233- this._transmat = new NyARTransMat(i_param);
234- this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(110,i_raster_type);
235-
236- // 2値画像バッファを作る
237- this._bin_raster = new NyARBinRaster(scr_size.w, scr_size.h);
238- this._threshold_detect=new NyARRasterThresholdAnalyzer_SlidePTile(15,i_raster_type,4);
239- this._initialized=true;
240- //コールバックハンドラ
241- this._detectmarker_cb=new DetectSquareCB(i_param);
242- this._offset=new NyARRectOffset();
243- return;
244- }
245-
246- /*自動・手動の設定が出来ないので、コメントアウト
247- public void setThreshold(int i_threshold)
248- {
249- this._threshold = i_threshold;
250- return;
251- }*/
252-
253- /**検出するマーカコードの配列を指定します。 検出状態でこの関数を実行すると、
254- * オブジェクト状態に強制リセットがかかります。
255- */
256- public void setARCodeTable(NyARCode[] i_ref_code_table, int i_code_resolution, double i_marker_width)
257- {
258- if (this._current_arcode_index != -1) {
259- // 強制リセット
260- reset(true);
261- }
262- //検出するマーカセット、情報、検出器を作り直す。(1ピクセル4ポイントサンプリング,マーカのパターン領域は50%)
263- this._detectmarker_cb.setNyARCodeTable(i_ref_code_table,i_code_resolution);
264- this._offset.setSquare(i_marker_width);
265- return;
266- }
267-
268- public void reset(boolean i_is_force)
269- {
270- if (this._current_arcode_index != -1 && i_is_force == false) {
271- // 強制書き換えでなければイベントコール
272- this.onLeaveHandler();
273- }
274- // カレントマーカをリセット
275- this._current_arcode_index = -1;
276- return;
277- }
278- private DetectSquareCB _detectmarker_cb;
279- public void detectMarker(INyARRgbRaster i_raster) throws NyARException
280- {
281- // サイズチェック
282- assert(this._bin_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h));
283-
284- //BINイメージへの変換
285- this._tobin_filter.setThreshold(this._threshold);
286- this._tobin_filter.doFilter(i_raster, this._bin_raster);
287-
288- // スクエアコードを探す
289- this._detectmarker_cb.init(i_raster,this._current_arcode_index);
290- this._square_detect.detectMarkerCB(this._bin_raster,this._detectmarker_cb);
291-
292- // 認識状態を更新
293- final boolean is_id_found=this.updateStatus(this._detectmarker_cb.square,this._detectmarker_cb.code_index);
294- //閾値フィードバック(detectExistMarkerにもあるよ)
295- if(!is_id_found){
296- //マーカがなければ、探索+DualPTailで基準輝度検索
297- int th=this._threshold_detect.analyzeRaster(i_raster);
298- this._threshold=(this._threshold+th)/2;
299- }
300-
301-
302- return;
303- }
304- /**
305- *
306- * @param i_new_detect_cf
307- * @param i_exist_detect_cf
308- */
309- public void setConfidenceThreshold(double i_new_cf,double i_exist_cf)
310- {
311- this._detectmarker_cb.cf_threshold_exist=i_exist_cf;
312- this._detectmarker_cb.cf_threshold_new=i_new_cf;
313- }
314-
315- private NyARTransMatResult __NyARSquare_result = new NyARTransMatResult();
316-
317- /** オブジェクトのステータスを更新し、必要に応じてハンドル関数を駆動します。
318- * 戻り値は、「実際にマーカを発見する事ができたか」です。クラスの状態とは異なります。
319- */
320- private boolean updateStatus(NyARSquare i_square, int i_code_index) throws NyARException
321- {
322- NyARTransMatResult result = this.__NyARSquare_result;
323- if (this._current_arcode_index < 0) {// 未認識中
324- if (i_code_index < 0) {// 未認識から未認識の遷移
325- // なにもしないよーん。
326- return false;
327- } else {// 未認識から認識の遷移
328- this._current_arcode_index = i_code_index;
329- // イベント生成
330- // OnEnter
331- this.onEnterHandler(i_code_index);
332- // 変換行列を作成
333- this._transmat.transMat(i_square, this._offset, result);
334- // OnUpdate
335- this.onUpdateHandler(i_square, result);
336- this._lost_delay_count = 0;
337- return true;
338- }
339- } else {// 認識中
340- if (i_code_index < 0) {// 認識から未認識の遷移
341- this._lost_delay_count++;
342- if (this._lost_delay < this._lost_delay_count) {
343- // OnLeave
344- this._current_arcode_index = -1;
345- this.onLeaveHandler();
346- }
347- return false;
348- } else if (i_code_index == this._current_arcode_index) {// 同じARCodeの再認識
349- // イベント生成
350- // 変換行列を作成
351- this._transmat.transMatContinue(i_square, this._offset, result);
352- // OnUpdate
353- this.onUpdateHandler(i_square, result);
354- this._lost_delay_count = 0;
355- return true;
356- } else {// 異なるコードの認識→今はサポートしない。
357- throw new NyARException();
358- }
359- }
360- }
361-
362- protected abstract void onEnterHandler(int i_code);
363-
364- protected abstract void onLeaveHandler();
365-
366- protected abstract void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result);
367-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/processor/SingleNyIdMarkerProcesser.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/processor/SingleNyIdMarkerProcesser.java (nonexistent)
@@ -1,297 +0,0 @@
1-/*
2- * Capture Test NyARToolkitサンプルプログラム
3- * --------------------------------------------------------------------------------
4- * The NyARToolkit is Java edition ARToolKit class library.
5- * Copyright (C)2008-2009 Ryo Iizuka
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- *
20- * For further information please contact.
21- * http://nyatla.jp/nyatoolkit/
22- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
23- *
24- */
25-package jp.nyatla.nyartoolkit.processor;
26-
27-import jp.nyatla.nyartoolkit.NyARException;
28-import jp.nyatla.nyartoolkit.core.analyzer.raster.threshold.*;
29-import jp.nyatla.nyartoolkit.core.param.*;
30-import jp.nyatla.nyartoolkit.core.raster.*;
31-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
32-import jp.nyatla.nyartoolkit.core.transmat.*;
33-import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;
34-import jp.nyatla.nyartoolkit.core.types.*;
35-import jp.nyatla.nyartoolkit.nyidmarker.*;
36-import jp.nyatla.nyartoolkit.nyidmarker.data.*;
37-import jp.nyatla.nyartoolkit.core.squaredetect.*;
38-
39-public abstract class SingleNyIdMarkerProcesser
40-{
41- /**
42- * detectMarkerのコールバック関数
43- */
44- private class DetectSquareCB implements NyARSquareContourDetector.IDetectMarkerCallback
45- {
46- //公開プロパティ
47- public final NyARSquare square=new NyARSquare();
48- public INyIdMarkerData marker_data;
49- public int threshold;
50-
51-
52- //参照
53- private INyARRgbRaster _ref_raster;
54- //所有インスタンス
55- private INyIdMarkerData _current_data;
56- private final NyIdMarkerPickup _id_pickup = new NyIdMarkerPickup();
57- private NyARCoord2Linear _coordline;
58- private INyIdMarkerDataEncoder _encoder;
59-
60-
61- private INyIdMarkerData _data_temp;
62- private INyIdMarkerData _prev_data;
63-
64- public DetectSquareCB(NyARParam i_param,INyIdMarkerDataEncoder i_encoder)
65- {
66- this._coordline=new NyARCoord2Linear(i_param.getScreenSize(),i_param.getDistortionFactor());
67- this._data_temp=i_encoder.createDataInstance();
68- this._current_data=i_encoder.createDataInstance();
69- this._encoder=i_encoder;
70- return;
71- }
72- private NyARIntPoint2d[] __tmp_vertex=NyARIntPoint2d.createArray(4);
73- /**
74- * Initialize call back handler.
75- */
76- public void init(INyARRgbRaster i_raster,INyIdMarkerData i_prev_data)
77- {
78- this.marker_data=null;
79- this._prev_data=i_prev_data;
80- this._ref_raster=i_raster;
81- }
82- private final NyIdMarkerParam _marker_param=new NyIdMarkerParam();
83- private final NyIdMarkerPattern _marker_data=new NyIdMarkerPattern();
84-
85- /**
86- * 矩形が見付かるたびに呼び出されます。
87- * 発見した矩形のパターンを検査して、方位を考慮した頂点データを確保します。
88- */
89- public void onSquareDetect(NyARSquareContourDetector i_sender,int[] i_coordx,int[] i_coordy,int i_coor_num,int[] i_vertex_index) throws NyARException
90- {
91- //既に発見済なら終了
92- if(this.marker_data!=null){
93- return;
94- }
95- //輪郭座標から頂点リストに変換
96- NyARIntPoint2d[] vertex=this.__tmp_vertex;
97- vertex[0].x=i_coordx[i_vertex_index[0]];
98- vertex[0].y=i_coordy[i_vertex_index[0]];
99- vertex[1].x=i_coordx[i_vertex_index[1]];
100- vertex[1].y=i_coordy[i_vertex_index[1]];
101- vertex[2].x=i_coordx[i_vertex_index[2]];
102- vertex[2].y=i_coordy[i_vertex_index[2]];
103- vertex[3].x=i_coordx[i_vertex_index[3]];
104- vertex[3].y=i_coordy[i_vertex_index[3]];
105-
106- NyIdMarkerParam param=this._marker_param;
107- NyIdMarkerPattern patt_data =this._marker_data;
108- // 評価基準になるパターンをイメージから切り出す
109- if (!this._id_pickup.pickFromRaster(this._ref_raster,vertex, patt_data, param)){
110- return;
111- }
112- //エンコード
113- if(!this._encoder.encode(patt_data,this._data_temp)){
114- return;
115- }
116-
117- //継続認識要求されている?
118- if (this._prev_data==null){
119- //継続認識要求なし
120- this._current_data.copyFrom(this._data_temp);
121- }else{
122- //継続認識要求あり
123- if(!this._prev_data.isEqual((this._data_temp))){
124- return;//認識請求のあったIDと違う。
125- }
126- }
127- //新しく認識、または継続認識中に更新があったときだけ、Square情報を更新する。
128- //ココから先はこの条件でしか実行されない。
129- NyARSquare sq=this.square;
130- //directionを考慮して、squareを更新する。
131- for(int i=0;i<4;i++){
132- int idx=(i+4 - param.direction) % 4;
133- this._coordline.coord2Line(i_vertex_index[idx],i_vertex_index[(idx+1)%4],i_coordx,i_coordy,i_coor_num,sq.line[i]);
134- }
135- for (int i = 0; i < 4; i++) {
136- //直線同士の交点計算
137- if(!NyARLinear.crossPos(sq.line[i],sq.line[(i + 3) % 4],sq.sqvertex[i])){
138- throw new NyARException();//ここのエラー復帰するならダブルバッファにすればOK
139- }
140- }
141- this.threshold=param.threshold;
142- this.marker_data=this._current_data;//みつかった。
143- }
144- }
145- /**
146- * オーナーが自由に使えるタグ変数です。
147- */
148- public Object tag;
149-
150- /**
151- * ロスト遅延の管理
152- */
153- private int _lost_delay_count = 0;
154- private int _lost_delay = 5;
155-
156- private NyARSquareContourDetector_Rle _square_detect;
157- protected INyARTransMat _transmat;
158- private NyARRectOffset _offset;
159- private boolean _is_active;
160- private int _current_threshold=110;
161- // [AR]検出結果の保存用
162- private NyARBinRaster _bin_raster;
163- private NyARRasterFilter_ARToolkitThreshold _tobin_filter;
164- private DetectSquareCB _callback;
165- private INyIdMarkerData _data_current;
166-
167-
168- protected SingleNyIdMarkerProcesser()
169- {
170- return;
171- }
172- private boolean _initialized=false;
173- protected void initInstance(NyARParam i_param,INyIdMarkerDataEncoder i_encoder,double i_marker_width,int i_raster_format) throws NyARException
174- {
175- //初期化済?
176- assert(this._initialized==false);
177-
178- NyARIntSize scr_size = i_param.getScreenSize();
179- // 解析オブジェクトを作る
180- this._square_detect = new NyARSquareContourDetector_Rle(scr_size);
181- this._transmat = new NyARTransMat(i_param);
182- this._callback=new DetectSquareCB(i_param,i_encoder);
183-
184- // 2値画像バッファを作る
185- this._bin_raster = new NyARBinRaster(scr_size.w, scr_size.h);
186- //ワーク用のデータオブジェクトを2個作る
187- this._data_current=i_encoder.createDataInstance();
188- this._tobin_filter =new NyARRasterFilter_ARToolkitThreshold(110,i_raster_format);
189- this._threshold_detect=new NyARRasterThresholdAnalyzer_SlidePTile(15,i_raster_format,4);
190- this._initialized=true;
191- this._is_active=false;
192- this._offset=new NyARRectOffset();
193- this._offset.setSquare(i_marker_width);
194- return;
195-
196- }
197-
198- public void setMarkerWidth(int i_width)
199- {
200- this._offset.setSquare(i_width);
201- return;
202- }
203-
204- public void reset(boolean i_is_force)
205- {
206- if (i_is_force == false && this._is_active){
207- // 強制書き換えでなければイベントコール
208- this.onLeaveHandler();
209- }
210- //マーカ無効
211- this._is_active=false;
212- return;
213- }
214-
215- public void detectMarker(INyARRgbRaster i_raster) throws NyARException
216- {
217- // サイズチェック
218- if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h)) {
219- throw new NyARException();
220- }
221- // ラスタを2値イメージに変換する.
222- this._tobin_filter.setThreshold(this._current_threshold);
223- this._tobin_filter.doFilter(i_raster, this._bin_raster);
224-
225- // スクエアコードを探す(第二引数に指定したマーカ、もしくは新しいマーカを探す。)
226- this._callback.init(i_raster,this._is_active?this._data_current:null);
227- this._square_detect.detectMarkerCB(this._bin_raster, this._callback);
228-
229- // 認識状態を更新(マーカを発見したなら、current_dataを渡すかんじ)
230- final boolean is_id_found=updateStatus(this._callback.square,this._callback.marker_data);
231-
232- //閾値フィードバック(detectExistMarkerにもあるよ)
233- if(is_id_found){
234- //マーカがあれば、マーカの周辺閾値を反映
235- this._current_threshold=(this._current_threshold+this._callback.threshold)/2;
236- }else{
237- //マーカがなければ、探索+DualPTailで基準輝度検索
238- int th=this._threshold_detect.analyzeRaster(i_raster);
239- this._current_threshold=(this._current_threshold+th)/2;
240- }
241- return;
242- }
243-
244-
245- private NyARRasterThresholdAnalyzer_SlidePTile _threshold_detect;
246- private NyARTransMatResult __NyARSquare_result = new NyARTransMatResult();
247-
248- /**オブジェクトのステータスを更新し、必要に応じてハンドル関数を駆動します。
249- */
250- private boolean updateStatus(NyARSquare i_square, INyIdMarkerData i_marker_data) throws NyARException
251- {
252- boolean is_id_found=false;
253- NyARTransMatResult result = this.__NyARSquare_result;
254- if (!this._is_active) {// 未認識中
255- if (i_marker_data==null) {// 未認識から未認識の遷移
256- // なにもしないよーん。
257- this._is_active=false;
258- } else {// 未認識から認識の遷移
259- this._data_current.copyFrom(i_marker_data);
260- // イベント生成
261- // OnEnter
262- this.onEnterHandler(this._data_current);
263- // 変換行列を作成
264- this._transmat.transMat(i_square, this._offset, result);
265- // OnUpdate
266- this.onUpdateHandler(i_square, result);
267- this._lost_delay_count = 0;
268- this._is_active=true;
269- is_id_found=true;
270- }
271- } else {// 認識中
272- if (i_marker_data==null) {
273- // 認識から未認識の遷移
274- this._lost_delay_count++;
275- if (this._lost_delay < this._lost_delay_count) {
276- // OnLeave
277- this.onLeaveHandler();
278- this._is_active=false;
279- }
280- } else if(this._data_current.isEqual(i_marker_data)) {
281- //同じidの再認識
282- this._transmat.transMatContinue(i_square, this._offset, result);
283- // OnUpdate
284- this.onUpdateHandler(i_square, result);
285- this._lost_delay_count = 0;
286- is_id_found=true;
287- } else {// 異なるコードの認識→今はサポートしない。
288- throw new NyARException();
289- }
290- }
291- return is_id_found;
292- }
293- //通知ハンドラ
294- protected abstract void onEnterHandler(INyIdMarkerData i_code);
295- protected abstract void onLeaveHandler();
296- protected abstract void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result);
297-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java (nonexistent)
@@ -1,266 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.detector;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.*;
35-import jp.nyatla.nyartoolkit.core.match.*;
36-import jp.nyatla.nyartoolkit.core.param.NyARParam;
37-import jp.nyatla.nyartoolkit.core.pickup.*;
38-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
39-import jp.nyatla.nyartoolkit.core.raster.*;
40-import jp.nyatla.nyartoolkit.core.transmat.*;
41-import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
42-import jp.nyatla.nyartoolkit.core.types.NyARLinear;
43-import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
44-import jp.nyatla.nyartoolkit.core.types.*;
45-import jp.nyatla.nyartoolkit.core.squaredetect.*;
46-
47-/**
48- * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。
49- * 変換行列を求めるには、detectMarkerLite関数にラスタイメージを入力して、計算対象の矩形を特定します。
50- * detectMarkerLiteが成功すると、getTransmationMatrix等の関数が使用可能な状態になり、変換行列を求めることができます。
51- *
52- *
53- */
54-public class NyARCustomSingleDetectMarker
55-{
56- /**
57- * detectMarkerのコールバック関数
58- */
59- private class DetectSquareCB implements NyARSquareContourDetector.IDetectMarkerCallback
60- {
61- //公開プロパティ
62- public double confidence;
63- public NyARSquare square=new NyARSquare();
64-
65- //参照インスタンス
66- private INyARRgbRaster _ref_raster;
67- //所有インスタンス
68- private INyARColorPatt _inst_patt;
69- private NyARMatchPattDeviationColorData _deviation_data;
70- private NyARMatchPatt_Color_WITHOUT_PCA _match_patt;
71- private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult();
72- private NyARCoord2Linear _coordline;
73-
74- public DetectSquareCB(INyARColorPatt i_inst_patt,NyARCode i_ref_code,NyARParam i_param)
75- {
76- this._inst_patt=i_inst_patt;
77- this._deviation_data=new NyARMatchPattDeviationColorData(i_ref_code.getWidth(),i_ref_code.getHeight());
78- this._coordline=new NyARCoord2Linear(i_param.getScreenSize(),i_param.getDistortionFactor());
79- this._match_patt=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code);
80- return;
81- }
82- private NyARIntPoint2d[] __tmp_vertex=NyARIntPoint2d.createArray(4);
83- /**
84- * 矩形が見付かるたびに呼び出されます。
85- * 発見した矩形のパターンを検査して、方位を考慮した頂点データを確保します。
86- */
87- public void onSquareDetect(NyARSquareContourDetector i_sender,int[] i_coordx,int[] i_coordy,int i_coor_num,int[] i_vertex_index) throws NyARException
88- {
89- NyARMatchPattResult mr=this.__detectMarkerLite_mr;
90- //輪郭座標から頂点リストに変換
91- NyARIntPoint2d[] vertex=this.__tmp_vertex;
92- vertex[0].x=i_coordx[i_vertex_index[0]];
93- vertex[0].y=i_coordy[i_vertex_index[0]];
94- vertex[1].x=i_coordx[i_vertex_index[1]];
95- vertex[1].y=i_coordy[i_vertex_index[1]];
96- vertex[2].x=i_coordx[i_vertex_index[2]];
97- vertex[2].y=i_coordy[i_vertex_index[2]];
98- vertex[3].x=i_coordx[i_vertex_index[3]];
99- vertex[3].y=i_coordy[i_vertex_index[3]];
100-
101- //画像を取得
102- if (!this._inst_patt.pickFromRaster(this._ref_raster,vertex)){
103- return;
104- }
105- //取得パターンをカラー差分データに変換して評価する。
106- this._deviation_data.setRaster(this._inst_patt);
107- if(!this._match_patt.evaluate(this._deviation_data,mr)){
108- return;
109- }
110- //現在の一致率より低ければ終了
111- if (this.confidence > mr.confidence){
112- return;
113- }
114- //一致率の高い矩形があれば、方位を考慮して頂点情報を作成
115- NyARSquare sq=this.square;
116- this.confidence = mr.confidence;
117- //directionを考慮して、squareを更新する。
118- for(int i=0;i<4;i++){
119- int idx=(i+4 - mr.direction) % 4;
120- this._coordline.coord2Line(i_vertex_index[idx],i_vertex_index[(idx+1)%4],i_coordx,i_coordy,i_coor_num,sq.line[i]);
121- }
122- for (int i = 0; i < 4; i++) {
123- //直線同士の交点計算
124- if(!NyARLinear.crossPos(sq.line[i],sq.line[(i + 3) % 4],sq.sqvertex[i])){
125- throw new NyARException();//ここのエラー復帰するならダブルバッファにすればOK
126- }
127- }
128- }
129- public final void init(INyARRgbRaster i_raster)
130- {
131- this.confidence=0;
132- this._ref_raster=i_raster;
133-
134- }
135- }
136-
137- private boolean _is_continue = false;
138- private NyARSquareContourDetector _square_detect;
139- protected INyARTransMat _transmat;
140- //画処理用
141- private NyARBinRaster _bin_raster;
142- protected INyARRasterFilter_Rgb2Bin _tobin_filter;
143- private DetectSquareCB _detect_cb;
144- private NyARRectOffset _offset;
145-
146-
147- protected NyARCustomSingleDetectMarker()
148- {
149- return;
150- }
151- protected void initInstance(
152- INyARColorPatt i_patt_inst,
153- NyARSquareContourDetector i_sqdetect_inst,
154- INyARTransMat i_transmat_inst,
155- INyARRasterFilter_Rgb2Bin i_filter,
156- NyARParam i_ref_param,
157- NyARCode i_ref_code,
158- double i_marker_width) throws NyARException
159- {
160- final NyARIntSize scr_size=i_ref_param.getScreenSize();
161- // 解析オブジェクトを作る
162- this._square_detect = i_sqdetect_inst;
163- this._transmat = i_transmat_inst;
164- this._tobin_filter=i_filter;
165- //2値画像バッファを作る
166- this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
167- //_detect_cb
168- this._detect_cb=new DetectSquareCB(i_patt_inst,i_ref_code,i_ref_param);
169- //オフセットを作成
170- this._offset=new NyARRectOffset();
171- this._offset.setSquare(i_marker_width);
172- return;
173-
174- }
175-
176-
177-
178-
179- /**
180- * i_imageにマーカー検出処理を実行し、結果を記録します。
181- *
182- * @param i_raster
183- * マーカーを検出するイメージを指定します。イメージサイズは、カメラパラメータ
184- * と一致していなければなりません。
185- * @return マーカーが検出できたかを真偽値で返します。
186- * @throws NyARException
187- */
188- public boolean detectMarkerLite(INyARRgbRaster i_raster) throws NyARException
189- {
190- //サイズチェック
191- if(!this._bin_raster.getSize().isEqualSize(i_raster.getSize())){
192- throw new NyARException();
193- }
194-
195- //ラスタを2値イメージに変換する.
196- this._tobin_filter.doFilter(i_raster,this._bin_raster);
197-
198- //コールバックハンドラの準備
199- this._detect_cb.init(i_raster);
200- //矩形を探す(戻り値はコールバック関数で受け取る。)
201- this._square_detect.detectMarkerCB(this._bin_raster,_detect_cb);
202- if(this._detect_cb.confidence==0){
203- return false;
204- }
205- return true;
206- }
207- /**
208- * 検出したマーカーの変換行列を計算して、o_resultへ値を返します。
209- * 直前に実行したdetectMarkerLiteが成功していないと使えません。
210- *
211- * @param o_result
212- * 変換行列を受け取るオブジェクトを指定します。
213- * @throws NyARException
214- */
215- public void getTransmationMatrix(NyARTransMatResult o_result) throws NyARException
216- {
217- // 一番一致したマーカーの位置とかその辺を計算
218- if (this._is_continue) {
219- this._transmat.transMatContinue(this._detect_cb.square,this._offset, o_result);
220- } else {
221- this._transmat.transMat(this._detect_cb.square,this._offset, o_result);
222- }
223- return;
224- }
225- /**
226- * 現在の矩形を返します。
227- * @return
228- */
229- public NyARSquare refSquare()
230- {
231- return this._detect_cb.square;
232- }
233- /**
234- * 検出したマーカーの一致度を返します。
235- *
236- * @return マーカーの一致度を返します。0~1までの値をとります。 一致度が低い場合には、誤認識の可能性が高くなります。
237- * @throws NyARException
238- */
239- public double getConfidence()
240- {
241- return this._detect_cb.confidence;
242- }
243- /**
244- * getTransmationMatrixの計算モードを設定します。 初期値はTRUEです。
245- *
246- * @param i_is_continue
247- * TRUEなら、transMatCont互換の計算をします。 FALSEなら、transMat互換の計算をします。
248- */
249- public void setContinueMode(boolean i_is_continue)
250- {
251- this._is_continue = i_is_continue;
252- }
253- /**
254- * プローブ関数
255- * @return
256- */
257- public Object[] _getProbe()
258- {
259- Object[] r=new Object[1];
260- r[0]=this._detect_cb._inst_patt;
261- return r;
262- }
263-
264-
265-
266-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java (nonexistent)
@@ -1,337 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.detector;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.*;
35-import jp.nyatla.nyartoolkit.core.match.*;
36-import jp.nyatla.nyartoolkit.core.param.NyARParam;
37-import jp.nyatla.nyartoolkit.core.pickup.*;
38-import jp.nyatla.nyartoolkit.core.raster.*;
39-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
40-import jp.nyatla.nyartoolkit.core.transmat.*;
41-import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
42-import jp.nyatla.nyartoolkit.core.squaredetect.NyARCoord2Linear;
43-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareContourDetector;
44-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
45-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareContourDetector_Rle;
46-import jp.nyatla.nyartoolkit.core.types.*;
47-import jp.nyatla.nyartoolkit.core.types.stack.NyARObjectStack;
48-
49-class NyARDetectMarkerResult
50-{
51- public int arcode_id;
52- public double confidence;
53-
54- public NyARSquare square=new NyARSquare();
55-}
56-
57-
58-class NyARDetectMarkerResultStack extends NyARObjectStack<NyARDetectMarkerResult>
59-{
60- public NyARDetectMarkerResultStack(int i_length) throws NyARException
61- {
62- super(i_length,NyARDetectMarkerResult.class);
63- return;
64- }
65- protected NyARDetectMarkerResult createElement()
66- {
67- return new NyARDetectMarkerResult();
68- }
69-}
70-
71-
72-/**
73- * 複数のマーカーを検出し、それぞれに最も一致するARコードを、コンストラクタで登録したARコードから 探すクラスです。最大300個を認識しますが、ゴミラベルを認識したりするので100個程度が限界です。
74- *
75- */
76-public class NyARDetectMarker
77-{
78- /**
79- * detectMarkerのコールバック関数
80- */
81- private class DetectSquareCB implements NyARSquareContourDetector.IDetectMarkerCallback
82- {
83- //公開プロパティ
84- public NyARDetectMarkerResultStack result_stack=new NyARDetectMarkerResultStack(NyARDetectMarker.AR_SQUARE_MAX);
85- //参照インスタンス
86- public INyARRgbRaster _ref_raster;
87- //所有インスタンス
88- private INyARColorPatt _inst_patt;
89- private NyARMatchPattDeviationColorData _deviation_data;
90- private NyARMatchPatt_Color_WITHOUT_PCA[] _match_patt;
91- private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult();
92- private NyARCoord2Linear _coordline;
93-
94- public DetectSquareCB(INyARColorPatt i_inst_patt,NyARCode[] i_ref_code,int i_num_of_code,NyARParam i_param) throws NyARException
95- {
96- final int cw = i_ref_code[0].getWidth();
97- final int ch = i_ref_code[0].getHeight();
98-
99- this._inst_patt=i_inst_patt;
100- this._coordline=new NyARCoord2Linear(i_param.getScreenSize(),i_param.getDistortionFactor());
101- this._deviation_data=new NyARMatchPattDeviationColorData(cw,ch);
102-
103- //NyARMatchPatt_Color_WITHOUT_PCA[]の作成
104- this._match_patt=new NyARMatchPatt_Color_WITHOUT_PCA[i_num_of_code];
105- this._match_patt[0]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[0]);
106- for (int i = 1; i < i_num_of_code; i++){
107- //解像度チェック
108- if (cw != i_ref_code[i].getWidth() || ch != i_ref_code[i].getHeight()) {
109- throw new NyARException();
110- }
111- this._match_patt[i]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[i]);
112- }
113- return;
114- }
115- private NyARIntPoint2d[] __tmp_vertex=NyARIntPoint2d.createArray(4);
116- /**
117- * 矩形が見付かるたびに呼び出されます。
118- * 発見した矩形のパターンを検査して、方位を考慮した頂点データを確保します。
119- */
120- public void onSquareDetect(NyARSquareContourDetector i_sender,int[] i_coordx,int[] i_coordy,int i_coor_num,int[] i_vertex_index) throws NyARException
121- {
122- NyARMatchPattResult mr=this.__detectMarkerLite_mr;
123- //輪郭座標から頂点リストに変換
124- NyARIntPoint2d[] vertex=this.__tmp_vertex;
125- vertex[0].x=i_coordx[i_vertex_index[0]];
126- vertex[0].y=i_coordy[i_vertex_index[0]];
127- vertex[1].x=i_coordx[i_vertex_index[1]];
128- vertex[1].y=i_coordy[i_vertex_index[1]];
129- vertex[2].x=i_coordx[i_vertex_index[2]];
130- vertex[2].y=i_coordy[i_vertex_index[2]];
131- vertex[3].x=i_coordx[i_vertex_index[3]];
132- vertex[3].y=i_coordy[i_vertex_index[3]];
133-
134- //画像を取得
135- if (!this._inst_patt.pickFromRaster(this._ref_raster,vertex)){
136- return;
137- }
138- //取得パターンをカラー差分データに変換して評価する。
139- this._deviation_data.setRaster(this._inst_patt);
140-
141- //最も一致するパターンを割り当てる。
142- int square_index,direction;
143- double confidence;
144- this._match_patt[0].evaluate(this._deviation_data,mr);
145- square_index=0;
146- direction=mr.direction;
147- confidence=mr.confidence;
148- //2番目以降
149- for(int i=1;i<this._match_patt.length;i++){
150- this._match_patt[i].evaluate(this._deviation_data,mr);
151- if (confidence > mr.confidence) {
152- continue;
153- }
154- // もっと一致するマーカーがあったぽい
155- square_index = i;
156- direction = mr.direction;
157- confidence = mr.confidence;
158- }
159- //最も一致したマーカ情報を、この矩形の情報として記録する。
160- final NyARDetectMarkerResult result = this.result_stack.prePush();
161- result.arcode_id = square_index;
162- result.confidence = confidence;
163-
164- final NyARSquare sq=result.square;
165- //directionを考慮して、squareを更新する。
166- for(int i=0;i<4;i++){
167- int idx=(i+4 - direction) % 4;
168- this._coordline.coord2Line(i_vertex_index[idx],i_vertex_index[(idx+1)%4],i_coordx,i_coordy,i_coor_num,sq.line[i]);
169- }
170- for (int i = 0; i < 4; i++) {
171- //直線同士の交点計算
172- if(!NyARLinear.crossPos(sq.line[i],sq.line[(i + 3) % 4],sq.sqvertex[i])){
173- throw new NyARException();//ここのエラー復帰するならダブルバッファにすればOK
174- }
175- }
176- }
177- public void init(INyARRgbRaster i_raster)
178- {
179- this._ref_raster=i_raster;
180- this.result_stack.clear();
181-
182- }
183- }
184- private DetectSquareCB _detect_cb;
185-
186-
187- private static final int AR_SQUARE_MAX = 300;
188- private boolean _is_continue = false;
189- private NyARSquareContourDetector _square_detect;
190- protected INyARTransMat _transmat;
191- private NyARRectOffset[] _offset;
192-
193-
194- /**
195- * 複数のマーカーを検出し、最も一致するARCodeをi_codeから検索するオブジェクトを作ります。
196- *
197- * @param i_param
198- * カメラパラメータを指定します。
199- * @param i_code
200- * 検出するマーカーのARCode配列を指定します。
201- * 配列要素のインデックス番号が、そのままgetARCodeIndex関数で得られるARCodeインデックスになります。
202- * 例えば、要素[1]のARCodeに一致したマーカーである場合は、getARCodeIndexは1を返します。
203- * @param i_marker_width
204- * i_codeのマーカーサイズをミリメートルで指定した配列を指定します。 先頭からi_number_of_code個の要素には、有効な値を指定する必要があります。
205- * @param i_number_of_code
206- * i_codeに含まれる、ARCodeの数を指定します。
207- * @param i_input_raster_type
208- * 入力ラスタのピクセルタイプを指定します。この値は、INyARBufferReaderインタフェイスのgetBufferTypeの戻り値を指定します。
209- * @throws NyARException
210- */
211- public NyARDetectMarker(NyARParam i_param,NyARCode[] i_code,double[] i_marker_width, int i_number_of_code,int i_input_raster_type) throws NyARException
212- {
213- initInstance(i_param,i_code,i_marker_width,i_number_of_code,i_input_raster_type);
214- return;
215- }
216- protected void initInstance(
217- NyARParam i_ref_param,
218- NyARCode[] i_ref_code,
219- double[] i_marker_width,
220- int i_number_of_code,
221- int i_input_raster_type) throws NyARException
222- {
223-
224- final NyARIntSize scr_size=i_ref_param.getScreenSize();
225- // 解析オブジェクトを作る
226- final int cw = i_ref_code[0].getWidth();
227- final int ch = i_ref_code[0].getHeight();
228-
229- //detectMarkerのコールバック関数
230- this._detect_cb=new DetectSquareCB(
231- new NyARColorPatt_Perspective_O2(cw, ch,4,25),
232- i_ref_code,i_number_of_code,i_ref_param);
233- this._transmat = new NyARTransMat(i_ref_param);
234- //NyARToolkitプロファイル
235- this._square_detect =new NyARSquareContourDetector_Rle(i_ref_param.getScreenSize());
236- this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100,i_input_raster_type);
237-
238- //実サイズ保存
239- this._offset = NyARRectOffset.createArray(i_number_of_code);
240- for(int i=0;i<i_number_of_code;i++){
241- this._offset[i].setSquare(i_marker_width[i]);
242- }
243- //2値画像バッファを作る
244- this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
245- return;
246- }
247-
248- private NyARBinRaster _bin_raster;
249-
250- private INyARRasterFilter_Rgb2Bin _tobin_filter;
251-
252- /**
253- * i_imageにマーカー検出処理を実行し、結果を記録します。
254- *
255- * @param i_raster
256- * マーカーを検出するイメージを指定します。
257- * @param i_thresh
258- * 検出閾値を指定します。0~255の範囲で指定してください。 通常は100~130くらいを指定します。
259- * @return 見つかったマーカーの数を返します。 マーカーが見つからない場合は0を返します。
260- * @throws NyARException
261- */
262- public int detectMarkerLite(INyARRgbRaster i_raster, int i_threshold) throws NyARException
263- {
264- // サイズチェック
265- if (!this._bin_raster.getSize().isEqualSize(i_raster.getSize())) {
266- throw new NyARException();
267- }
268-
269- // ラスタを2値イメージに変換する.
270- ((NyARRasterFilter_ARToolkitThreshold)this._tobin_filter).setThreshold(i_threshold);
271- this._tobin_filter.doFilter(i_raster, this._bin_raster);
272-
273- //detect
274- this._detect_cb.init(i_raster);
275- this._square_detect.detectMarkerCB(this._bin_raster,this._detect_cb);
276-
277- //見付かった数を返す。
278- return this._detect_cb.result_stack.getLength();
279- }
280-
281- /**
282- * i_indexのマーカーに対する変換行列を計算し、結果値をo_resultへ格納します。 直前に実行したdetectMarkerLiteが成功していないと使えません。
283- *
284- * @param i_index
285- * マーカーのインデックス番号を指定します。 直前に実行したdetectMarkerLiteの戻り値未満かつ0以上である必要があります。
286- * @param o_result
287- * 結果値を受け取るオブジェクトを指定してください。
288- * @throws NyARException
289- */
290- public void getTransmationMatrix(int i_index, NyARTransMatResult o_result) throws NyARException
291- {
292- final NyARDetectMarkerResult result = this._detect_cb.result_stack.getItem(i_index);
293- // 一番一致したマーカーの位置とかその辺を計算
294- if (_is_continue) {
295- _transmat.transMatContinue(result.square, this._offset[result.arcode_id], o_result);
296- } else {
297- _transmat.transMat(result.square, this._offset[result.arcode_id], o_result);
298- }
299- return;
300- }
301-
302- /**
303- * i_indexのマーカーの一致度を返します。
304- *
305- * @param i_index
306- * マーカーのインデックス番号を指定します。 直前に実行したdetectMarkerLiteの戻り値未満かつ0以上である必要があります。
307- * @return マーカーの一致度を返します。0~1までの値をとります。 一致度が低い場合には、誤認識の可能性が高くなります。
308- * @throws NyARException
309- */
310- public double getConfidence(int i_index)
311- {
312- return this._detect_cb.result_stack.getItem(i_index).confidence;
313- }
314- /**
315- * i_indexのマーカーのARCodeインデックスを返します。
316- *
317- * @param i_index
318- * マーカーのインデックス番号を指定します。 直前に実行したdetectMarkerLiteの戻り値未満かつ0以上である必要があります。
319- * @return
320- */
321- public int getARCodeIndex(int i_index)
322- {
323- return this._detect_cb.result_stack.getItem(i_index).arcode_id;
324- }
325-
326- /**
327- * getTransmationMatrixの計算モードを設定します。
328- *
329- * @param i_is_continue
330- * TRUEなら、transMatContinueを使用します。 FALSEなら、transMatを使用します。
331- */
332- public void setContinueMode(boolean i_is_continue)
333- {
334- this._is_continue = i_is_continue;
335- }
336-
337-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java (nonexistent)
@@ -1,137 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.detector;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.*;
35-import jp.nyatla.nyartoolkit.core.param.NyARParam;
36-import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt;
37-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
38-
39-import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;
40-import jp.nyatla.nyartoolkit.core.squaredetect.*;
41-import jp.nyatla.nyartoolkit.core.pickup.*;
42-import jp.nyatla.nyartoolkit.core.transmat.*;
43-/**
44- * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。
45- *
46- */
47-public class NyARSingleDetectMarker extends NyARCustomSingleDetectMarker
48-{
49- public final static int PF_ARTOOLKIT_COMPATIBLE=1;
50- public final static int PF_NYARTOOLKIT=2;
51- public final static int PF_NYARTOOLKIT_ARTOOLKIT_FITTING=100;
52- public final static int PF_TEST2=201;
53-
54- /**
55- * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。
56- *
57- * @param i_param
58- * カメラパラメータを指定します。
59- * @param i_code
60- * 検出するARCodeを指定します。
61- * @param i_marker_width
62- * ARコードの物理サイズを、ミリメートルで指定します。
63- * @param i_input_raster_type
64- * 入力ラスタのピクセルタイプを指定します。この値は、INyARBufferReaderインタフェイスのgetBufferTypeの戻り値を指定します。
65- * @throws NyARException
66- */
67- public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type,int i_profile_id) throws NyARException
68- {
69- super();
70- initialize(i_param,i_code,i_marker_width,i_input_raster_type,i_profile_id);
71- return;
72- }
73- public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type) throws NyARException
74- {
75- super();
76- initialize(i_param,i_code,i_marker_width,i_input_raster_type,PF_NYARTOOLKIT);
77- return;
78- }
79- /**
80- * コンストラクタから呼び出す関数です。
81- * @param i_ref_param
82- * @param i_ref_code
83- * @param i_marker_width
84- * @param i_input_raster_type
85- * @param i_profile_id
86- * @throws NyARException
87- */
88- private void initialize(
89- NyARParam i_ref_param,
90- NyARCode i_ref_code,
91- double i_marker_width,
92- int i_input_raster_type,
93- int i_profile_id) throws NyARException
94- {
95- final NyARRasterFilter_ARToolkitThreshold th=new NyARRasterFilter_ARToolkitThreshold(100,i_input_raster_type);
96- INyARColorPatt patt_inst;
97- NyARSquareContourDetector sqdetect_inst;
98- INyARTransMat transmat_inst;
99-
100- switch(i_profile_id){
101- case PF_ARTOOLKIT_COMPATIBLE:
102- patt_inst=new NyARColorPatt_O3(i_ref_code.getWidth(), i_ref_code.getHeight());
103- sqdetect_inst=new NyARSquareContourDetector_ARToolKit(i_ref_param.getScreenSize());
104- transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);
105- break;
106- case PF_NYARTOOLKIT_ARTOOLKIT_FITTING:
107- patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);
108- sqdetect_inst=new NyARSquareContourDetector_Rle(i_ref_param.getScreenSize());
109- transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);
110- break;
111- case PF_NYARTOOLKIT://default
112- patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);
113- sqdetect_inst=new NyARSquareContourDetector_Rle(i_ref_param.getScreenSize());
114- transmat_inst=new NyARTransMat(i_ref_param);
115- break;
116- default:
117- throw new NyARException();
118- }
119- super.initInstance(patt_inst,sqdetect_inst,transmat_inst,th,i_ref_param,i_ref_code,i_marker_width);
120-
121- }
122-
123- /**
124- * i_imageにマーカー検出処理を実行し、結果を記録します。
125- *
126- * @param i_raster
127- * マーカーを検出するイメージを指定します。イメージサイズは、コンストラクタで指定i_paramの
128- * スクリーンサイズと一致し、かつi_input_raster_typeに指定した形式でなければいけません。
129- * @return マーカーが検出できたかを真偽値で返します。
130- * @throws NyARException
131- */
132- public boolean detectMarkerLite(INyARRgbRaster i_raster,int i_threshold) throws NyARException
133- {
134- ((NyARRasterFilter_ARToolkitThreshold)this._tobin_filter).setThreshold(i_threshold);
135- return super.detectMarkerLite(i_raster);
136- }
137-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample/NyIdTest.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample/NyIdTest.java (nonexistent)
@@ -1,147 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.sample;
32-
33-import java.io.*;
34-
35-
36-import jp.nyatla.nyartoolkit.core.param.NyARParam;
37-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
38-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
39-import jp.nyatla.nyartoolkit.core.transmat.*;
40-import jp.nyatla.nyartoolkit.nyidmarker.data.*;
41-import jp.nyatla.nyartoolkit.processor.*;
42-
43-/**
44- * 320x240のBGRA32で記録されたIdmarkerを撮影したRAWイメージから、
45- * Idマーカを認識します。
46- *
47- */
48-public class NyIdTest
49-{
50- public class MarkerProcessor extends SingleNyIdMarkerProcesser
51- {
52- private Object _sync_object = new Object();
53- public NyARTransMatResult transmat = null;
54- public int current_id = -1;
55-
56- public MarkerProcessor(NyARParam i_cparam, int i_raster_format) throws Exception
57- {
58- super();//
59- initInstance(i_cparam, new NyIdMarkerDataEncoder_RawBit(),100, i_raster_format);
60- //アプリケーションフレームワークの初期化
61- return;
62- }
63- /**
64- * アプリケーションフレームワークのハンドラ(マーカ出現)
65- */
66- protected void onEnterHandler(INyIdMarkerData i_code)
67- {
68- synchronized (this._sync_object)
69- {
70- NyIdMarkerData_RawBit code = (NyIdMarkerData_RawBit)i_code;
71- if (code.length > 4)
72- {
73- //4バイト以上の時はint変換しない。
74- this.current_id = -1;//undefined_id
75- }
76- else
77- {
78- this.current_id = 0;
79- //最大4バイト繋げて1個のint値に変換
80- for (int i = 0; i < code.length; i++)
81- {
82- this.current_id = (this.current_id << 8) | code.packet[i];
83- }
84- }
85- this.transmat = null;
86- }
87- }
88- /**
89- * アプリケーションフレームワークのハンドラ(マーカ消滅)
90- */
91- protected void onLeaveHandler()
92- {
93- synchronized (this._sync_object)
94- {
95- this.current_id = -1;
96- this.transmat = null;
97- }
98- return;
99- }
100- /**
101- * アプリケーションフレームワークのハンドラ(マーカ更新)
102- */
103- protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)
104- {
105- synchronized (this._sync_object)
106- {
107- this.transmat = result;
108- }
109- }
110- }
111- private final String data_file = "../Data/320x240NyId.raw";
112- private final String camera_file = "../Data/camera_para.dat";
113- public NyIdTest()
114- {
115- }
116- public void Test() throws Exception
117- {
118- //AR用カメラパラメタファイルをロード
119- NyARParam ap = new NyARParam();
120- ap.loadARParamFromFile(camera_file);
121- ap.changeScreenSize(320, 240);
122-
123- // 試験イメージの読み出し(320x240 BGRAのRAWデータ)
124- File f = new File(data_file);
125- FileInputStream fs = new FileInputStream(data_file);
126- byte[] buf = new byte[(int) f.length()];
127- fs.read(buf);
128-
129- NyARRgbRaster_RGB ra = new NyARRgbRaster_RGB(320, 240,false);
130- ra.wrapBuffer(buf);
131-
132- MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferType());
133- pr.detectMarker(ra);
134- return;
135- }
136- public static void main(String[] args)
137- {
138-
139- try {
140- NyIdTest t = new NyIdTest();
141- // t.Test_arGetVersion();
142- t.Test();
143- } catch (Exception e) {
144- e.printStackTrace();
145- }
146- }
147-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample/SingleARMarkerTest.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample/SingleARMarkerTest.java (nonexistent)
@@ -1,123 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.sample;
32-
33-import java.io.*;
34-
35-
36-import jp.nyatla.nyartoolkit.NyARException;
37-import jp.nyatla.nyartoolkit.core.param.NyARParam;
38-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
39-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
40-import jp.nyatla.nyartoolkit.core.transmat.*;
41-import jp.nyatla.nyartoolkit.core.*;
42-import jp.nyatla.nyartoolkit.processor.*;
43-
44-public class SingleARMarkerTest
45-{
46- class MarkerProcessor extends SingleARMarkerProcesser
47- {
48- private Object _sync_object=new Object();
49- public NyARTransMatResult transmat=null;
50- public int current_code=-1;
51-
52- public MarkerProcessor(NyARParam i_cparam,int i_raster_format) throws NyARException
53- {
54- //アプリケーションフレームワークの初期化
55- super();
56- initInstance(i_cparam,i_raster_format);
57- return;
58- }
59- protected void onEnterHandler(int i_code)
60- {
61- synchronized(this._sync_object){
62- current_code=i_code;
63- }
64- }
65- protected void onLeaveHandler()
66- {
67- synchronized(this._sync_object){
68- current_code=-1;
69- this.transmat=null;
70- }
71- return;
72- }
73-
74- protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)
75- {
76- synchronized(this._sync_object){
77- this.transmat=result;
78- }
79- }
80- }
81- private final static String CARCODE_FILE = "../Data/patt.hiro";
82- private final static String PARAM_FILE = "../Data/camera_para.dat";
83- private final String data_file = "../Data/320x240ABGR.raw";
84-
85- public SingleARMarkerTest()
86- {
87- }
88- public void Test() throws Exception
89- {
90- //AR用カメラパラメタファイルをロード
91- NyARParam ap = new NyARParam();
92- ap.loadARParamFromFile(PARAM_FILE);
93- ap.changeScreenSize(320, 240);
94-
95- // 試験イメージの読み出し(320x240 BGRAのRAWデータ)
96- File f = new File(data_file);
97- FileInputStream fs = new FileInputStream(data_file);
98- byte[] buf = new byte[(int) f.length()];
99- fs.read(buf);
100-
101- NyARRgbRaster_BGRA ra = new NyARRgbRaster_BGRA(320, 240,false);
102- ra.wrapBuffer(buf);
103-
104- MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferType());
105- NyARCode[] codes=new NyARCode[1];
106- codes[0]=new NyARCode(16,16);
107- codes[0].loadARPattFromFile(CARCODE_FILE);
108- pr.setARCodeTable(codes,16,80.0);
109- pr.detectMarker(ra);
110- return;
111- }
112- public static void main(String[] args)
113- {
114-
115- try {
116- SingleARMarkerTest t = new SingleARMarkerTest();
117- // t.Test_arGetVersion();
118- t.Test();
119- } catch (Exception e) {
120- e.printStackTrace();
121- }
122- }
123-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java (nonexistent)
@@ -1,114 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.sample;
32-
33-import java.io.*;
34-import java.util.*;
35-
36-import jp.nyatla.nyartoolkit.core.*;
37-import jp.nyatla.nyartoolkit.core.param.NyARParam;
38-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
39-import jp.nyatla.nyartoolkit.core.transmat.*;
40-import jp.nyatla.nyartoolkit.detector.NyARSingleDetectMarker;
41-import jp.nyatla.nyartoolkit.core.types.*;
42-
43-/**
44- * 320x240のBGRA32で記録されたRAWイメージから、1種類のパターンを認識し、
45- * その変換行列を1000回求め、それにかかったミリ秒時間を表示します。
46- *
47- */
48-public class RawFileTest
49-{
50- private final String code_file = "../Data/patt.hiro";
51-
52- private final String data_file = "../Data/320x240ABGR.raw";
53-
54- private final String camera_file = "../Data/camera_para.dat";
55-
56- public RawFileTest()
57- {
58- }
59-
60-
61- public void Test_arDetectMarkerLite() throws Exception
62- {
63- // AR用カメラパラメタファイルをロード
64- NyARParam ap = new NyARParam();
65- ap.loadARParamFromFile(camera_file);
66- ap.changeScreenSize(320, 240);
67-
68- // AR用のパターンコードを読み出し
69- NyARCode code = new NyARCode(16, 16);
70- code.loadARPattFromFile(code_file);
71-
72- // 試験イメージの読み出し(320x240 BGRAのRAWデータ)
73- File f = new File(data_file);
74- FileInputStream fs = new FileInputStream(data_file);
75- byte[] buf = new byte[(int) f.length()];
76- fs.read(buf);
77- INyARRgbRaster ra = new NyARRgbRaster_BGRA(320, 240,false);
78- ra.wrapBuffer(buf);
79- // Blank_Raster ra=new Blank_Raster(320, 240);
80-
81- // 1パターンのみを追跡するクラスを作成
82- NyARSingleDetectMarker ar = new NyARSingleDetectMarker(
83- ap, code, 80.0,ra.getBufferType(),NyARSingleDetectMarker.PF_NYARTOOLKIT);
84- NyARTransMatResult result_mat = new NyARTransMatResult();
85- ar.setContinueMode(false);
86- ar.detectMarkerLite(ra, 100);
87- ar.getTransmationMatrix(result_mat);
88-
89- // マーカーを検出
90- Date d2 = new Date();
91- for (int i = 0; i < 1000; i++) {
92- // 変換行列を取得
93- ar.detectMarkerLite(ra, 100);
94- ar.getTransmationMatrix(result_mat);
95- }
96- Date d = new Date();
97- NyARDoublePoint3d ang=new NyARDoublePoint3d();
98- result_mat.getZXYAngle(ang);
99- System.out.println(d.getTime() - d2.getTime());
100- }
101-
102- public static void main(String[] args)
103- {
104-
105- try {
106- RawFileTest t = new RawFileTest();
107- // t.Test_arGetVersion();
108- t.Test_arDetectMarkerLite();
109- } catch (Exception e) {
110- e.printStackTrace();
111- }
112- }
113-
114-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/j2se/NyARRasterImageIO.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/j2se/NyARRasterImageIO.java (nonexistent)
@@ -1,179 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.utils.j2se;
32-
33-
34-import java.awt.image.*;
35-import java.awt.*;
36-import jp.nyatla.nyartoolkit.*;
37-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
38-import jp.nyatla.nyartoolkit.core.raster.*;
39-import jp.nyatla.nyartoolkit.core.rasterreader.*;
40-import jp.nyatla.nyartoolkit.core.types.*;
41-
42-/**
43- * BufferdImageとRasterイメージ間で、ビットマップをコピーします。
44- */
45-public class NyARRasterImageIO
46-{
47- /**
48- * i_inの内容を、このイメージにコピーします。
49- * @param i_in
50- * @throws NyARException
51- */
52- public static void copy(INyARRgbRaster i_in,BufferedImage o_out) throws NyARException
53- {
54- assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight());
55-
56- //thisへ転写
57- INyARRgbPixelReader reader=i_in.getRgbPixelReader();
58- int[] rgb=new int[3];
59-
60- for(int y=o_out.getHeight()-1;y>=0;y--){
61- for(int x=o_out.getWidth()-1;x>=0;x--){
62- reader.getPixel(x,y,rgb);
63- o_out.setRGB(x,y,(rgb[0]<<16)|(rgb[1]<<8)|rgb[2]);
64- }
65- }
66- return;
67- }
68- /**
69- * GrayScale用
70- * @param i_in
71- * @throws NyARException
72- */
73- public static void copy(NyARGrayscaleRaster i_in,BufferedImage o_out) throws NyARException
74- {
75- assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight());
76- if(i_in.isEqualBufferType(NyARBufferType.INT1D_GRAY_8))
77- {
78- final int[] buf=(int[])i_in.getBuffer();
79- final int w=o_out.getWidth();
80- final int h=o_out.getHeight();
81- for(int y=h-1;y>=0;y--){
82- for(int x=w-1;x>=0;x--){
83- int v=buf[x+y*w];
84- o_out.setRGB(x, y,v*(1+0x100+0x10000));
85- }
86- }
87- }
88- return;
89- }
90- /**
91- * BIN_8用
92- * @param i_in
93- * @throws NyARException
94- */
95- public static void copy(INyARRaster i_in,BufferedImage o_out) throws NyARException
96- {
97- assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight());
98- if(i_in.isEqualBufferType(NyARBufferType.INT1D_BIN_8))
99- {
100- final int[] buf=(int[])i_in.getBuffer();
101- final int w=o_out.getWidth();
102- final int h=o_out.getHeight();
103- for(int y=h-1;y>=0;y--){
104- for(int x=w-1;x>=0;x--){
105- o_out.setRGB(x, y,buf[x+y*w]==0?0:0xffffff);
106- }
107- }
108- }
109- return;
110- }
111- /**
112- * ヒストグラムを書き出します。
113- * @param i_in
114- * @param o_out
115- * @throws NyARException
116- */
117- public static void copy(NyARHistogram i_in,int i_l,int i_t,int i_h,Graphics i_g) throws NyARException
118- {
119- //正規化のための定数を出す。
120- int max=0;
121- for(int i=0;i<i_in.length;i++){
122- max=max<i_in.data[i]?i_in.data[i]:max;
123- }
124- if(max==0){
125- return;
126- }
127- //ヒストグラムを書く
128- for(int i=0;i<i_in.length;i++){
129- i_g.drawLine(i_l+i,i_t,i_l+i,i_h-i_h*i_in.data[i]/max);
130- }
131- return;
132- }
133- /**
134- * i_outへこのイメージを出力します。
135- *
136- * @param i_out
137- * @throws NyARException
138- */
139- public static void copy(BufferedImage i_in,INyARRgbRaster o_out) throws NyARException
140- {
141- assert o_out.getSize().isEqualSize(i_in.getWidth(), i_in.getHeight());
142-
143- //thisへ転写
144- INyARRgbPixelReader reader=o_out.getRgbPixelReader();
145- int[] rgb=new int[3];
146- for(int y=i_in.getHeight()-1;y>=0;y--){
147- for(int x=i_in.getWidth()-1;x>=0;x--){
148- int pix=i_in.getRGB(x, y);
149- rgb[0]=(pix>>16)&0xff;
150- rgb[1]=(pix>>8)&0xff;
151- rgb[2]=(pix)&0xff;
152- reader.setPixel(x,y,rgb);
153- }
154- }
155- return;
156- }
157- /**
158- * BIN_8用
159- * @param i_in
160- * @throws NyARException
161- */
162- public static void copy(BufferedImage i_in,INyARRaster o_out) throws NyARException
163- {
164- assert o_out.getSize().isEqualSize(i_in.getWidth(), i_in.getHeight());
165- if(o_out.isEqualBufferType(NyARBufferType.INT1D_BIN_8))
166- {
167- final int[] buf=(int[])o_out.getBuffer();
168- final int w=i_in.getWidth();
169- final int h=i_in.getHeight();
170- for(int y=h-1;y>=0;y--){
171- for(int x=w-1;x>=0;x--){
172- buf[x+y*w]=(i_in.getRGB(x, y)&0xffffff)>0?1:0;
173- }
174- }
175- }
176- return;
177- }
178-
179-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/j2se/LabelingBufferdImage.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/j2se/LabelingBufferdImage.java (nonexistent)
@@ -1,249 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.utils.j2se;
32-
33-import java.awt.Graphics;
34-import java.awt.image.*;
35-import java.awt.color.*;
36-import java.awt.*;
37-
38-
39-import jp.nyatla.nyartoolkit.NyARException;
40-import jp.nyatla.nyartoolkit.core.types.*;
41-import jp.nyatla.nyartoolkit.core.raster.*;
42-import jp.nyatla.nyartoolkit.core.types.stack.*;
43-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;
44-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;
45-
46-/**
47- * bitmapとして利用可能なラベリングイメージです。
48- *
49- *
50- */
51-public class LabelingBufferdImage extends BufferedImage
52-{
53- public final static int COLOR_125_COLOR = 0;// 125色ラベルモード
54-
55- public final static int COLOR_256_MONO = 1;// 64階調モノクロモード
56-
57- public final static int COLOR_64_MONO = 2;// 64階調モノクロモード
58-
59- public final static int COLOR_32_MONO = 3;// 32階調モノクロモード
60-
61- public final static int COLOR_16_MONO = 4;// 16階調モノクロモード
62-
63- public final static int COLOR_8_MONO = 5;// 16階調モノクロモード
64-
65- private int[] _rgb_table_125;
66-
67-
68- /**
69- * i_width x i_heightの大きさのイメージを作成します。
70- *
71- * @param i_width
72- * @param i_height
73- */
74- public LabelingBufferdImage(int i_width, int i_height)
75- {
76- super(i_width, i_height, ColorSpace.TYPE_RGB);
77- // RGBテーブルを作成
78- this._rgb_table_125 = new int[125];
79- for (int i = 0; i < 5; i++) {
80- for (int i2 = 0; i2 < 5; i2++) {
81- for (int i3 = 0; i3 < 5; i3++) {
82- this._rgb_table_125[((i * 5) + i2) * 5 + i3] = ((((i * 63) << 8) | (i2 * 63)) << 8) | (i3 * 63);
83- }
84- }
85- }
86-/* case COLOR_256_MONO:
87- this._rgb_table = new int[256];
88- this._number_of_color = 256;
89- for (int i = 0; i < 256; i++) {
90- this._rgb_table[i] = (i << 16) | (i << 8) | i;
91- }
92- break;
93- case COLOR_64_MONO:
94- this._rgb_table = new int[64];
95- this._number_of_color = 64;
96- for (int i = 0; i < 64; i++) {
97- int m = (i * 4);
98- this._rgb_table[i] = (m << 16) | (m << 8) | m;
99- }
100- break;
101- case COLOR_32_MONO:
102- this._rgb_table = new int[32];
103- this._number_of_color = 32;
104- for (int i = 0; i < 32; i++) {
105- int m = (i * 8);
106- this._rgb_table[i] = (m << 16) | (m << 8) | m;
107- }
108- break;
109- case COLOR_16_MONO:
110- this._rgb_table = new int[32];
111- this._number_of_color = 16;
112- for (int i = 0; i < 16; i++) {
113- int m = (i * 8);
114- this._rgb_table[i] = (m << 16) | (m << 8) | m;
115- }
116- break;
117- }*/
118- }
119-
120-
121-
122- public void drawImage(NyARGrayscaleRaster i_raster) throws NyARException
123- {
124- assert (i_raster.getBufferType() == NyARBufferType.INT1D_GRAY_8);
125-
126- int w = this.getWidth();
127- int h = this.getHeight();
128- // サイズをチェック
129- NyARIntSize size = i_raster.getSize();
130- if (size.h > h || size.w > w) {
131- throw new NyARException();
132- }
133-
134- int[] limg;
135- // イメージの描画
136- limg = (int[]) i_raster.getBuffer();
137- for (int i = 0; i < h; i++) {
138- for (int i2 = 0; i2 < w; i2++) {
139- this.setRGB(i2, i,limg[i*w+i2]);
140- }
141- }
142- return;
143- }
144- /**
145- * バイナリラスタ
146- * @param i_raster
147- * @throws NyARException
148- */
149- public void drawImage(NyARBinRaster i_raster) throws NyARException
150- {
151- assert (i_raster.getBufferType() == NyARBufferType.INT1D_BIN_8);
152-
153- int w = this.getWidth();
154- int h = this.getHeight();
155- // サイズをチェック
156- NyARIntSize size = i_raster.getSize();
157- if (size.h > h || size.w > w) {
158- throw new NyARException();
159- }
160-
161- int[] limg;
162- // イメージの描画
163- limg = (int[]) i_raster.getBuffer();
164- for (int i = 0; i < h; i++) {
165- for (int i2 = 0; i2 < w; i2++) {
166- this.setRGB(i2, i, limg[i*w+i2] > 0 ? 255 : 0);
167- }
168- }
169- return;
170- }
171-
172- /**
173- * ラベリングイメージを書く
174- * @param i_raster
175- * @throws NyARException
176- */
177- public void drawLabel(NyARLabelingImage i_image) throws NyARException
178- {
179- int w = this.getWidth();
180- int h = this.getHeight();
181- // サイズをチェック
182- NyARIntSize size = i_image.getSize();
183- if (size.h > h || size.w > w) {
184- throw new NyARException();
185- }
186- int[] index_array=i_image.getIndexArray();
187-
188- int[] limg;
189- // イメージの描画
190- limg = (int[]) i_image.getBuffer();
191- for (int i = 0; i < h; i++) {
192- for (int i2 = 0; i2 < w; i2++) {
193- int t=limg[i*w+i2]-1;
194- if(t<0){
195- t=0;
196- }else{
197- t=index_array[t];
198- }
199- this.setRGB(i2, i,_rgb_table_125[t% _rgb_table_125.length]);
200- }
201- }
202- return;
203- }
204- /**
205- *
206- * @param i_stack
207- */
208-
209- public void overlayData(NyARLabelingLabel i_label)
210- {
211- Graphics g = this.getGraphics();
212- g.setColor(Color.red);
213- g.drawRect(i_label.clip_l,i_label.clip_t,i_label.clip_r-i_label.clip_l,i_label.clip_b-i_label.clip_t);
214- return;
215- }
216- /**
217- *
218- * @param i_stack
219- */
220-
221- public void overlayData(NyARIntPointStack i_stack)
222- {
223- int count = i_stack.getLength();
224- NyARIntPoint2d[] items = i_stack.getArray();
225- Graphics g = this.getGraphics();
226- for (int i = 0; i < count; i++) {
227- int x = items[i].x;
228- int y = items[i].y;
229- g.setColor(Color.red);
230- g.drawLine(x - 5, y, x + 5, y);
231- g.drawLine(x, y + 5, x, y - 5);
232- }
233- return;
234- }
235- public void overlayData(NyARIntRectStack i_stack)
236- {
237- Color[] c=new Color[]{Color.cyan,Color.red,Color.green};
238- int count = i_stack.getLength();
239- NyARIntRect[] items = i_stack.getArray();
240- Graphics g = this.getGraphics();
241- for (int i = 0; i < count; i++) {
242- int x = items[i].x;
243- int y = items[i].y;
244- g.setColor(c[i%1]);
245- g.drawRect(x,y,items[i].w,items[i].h);
246- }
247- return;
248- }
249-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/TransformedBitmapPickup.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/utils/TransformedBitmapPickup.java (nonexistent)
@@ -1,114 +0,0 @@
1-package jp.nyatla.nyartoolkit.utils;
2-
3-import jp.nyatla.nyartoolkit.NyARException;
4-import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;
5-import jp.nyatla.nyartoolkit.core.pickup.NyARColorPatt_Perspective_O2;
6-import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;
7-import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;
8-import jp.nyatla.nyartoolkit.core.types.NyARIntPoint2d;
9-
10-/**
11- * マーカの周辺領域からビットマップを取得する方法を提供します。
12- * 比較的負荷が大きいので、連続してパターンを取得し続ける用途には向いていません。
13- *
14- */
15-class TransformedBitmapPickup extends NyARColorPatt_Perspective_O2
16-{
17- private NyARIntPoint2d[] _work_points = NyARIntPoint2d.createArray(4);
18-
19- private NyARPerspectiveProjectionMatrix _ref_perspective;
20-
21- /**
22- *
23- * @param i_width
24- * 取得するビットマップの幅
25- * @param i_height
26- * 取得するビットマップの解像度
27- * @param i_resolution
28- * resolution of reading pixel per point. ---- 取得時の解像度。高解像度のときは1を指定してください。低解像度のときは2以上を指定します。
29- */
30- public TransformedBitmapPickup(NyARPerspectiveProjectionMatrix i_ref_cparam, int i_width, int i_height, int i_resolution)
31- {
32- super(i_width, i_height, i_resolution, 0);
33- this._ref_perspective = i_ref_cparam;
34- }
35-
36- /**
37- * This function retrieves bitmap from the area defined by RECT(i_l,i_t,i_r,i_b) above transform matrix i_base_mat.
38- * ----
39- * この関数は、basementで示される平面のAで定義される領域から、ビットマップを読み出します。
40- * 例えば、8cmマーカでRECT(i_l,i_t,i_r,i_b)に-40,0,0,-40.0を指定すると、マーカの左下部分の画像を抽出します。
41- *
42- * マーカから離れた場所になるほど、また、マーカの鉛直方向から外れるほど誤差が大きくなります。
43- * @param i_src_imege
44- * 詠み出し元の画像を指定します。
45- * @param i_l
46- * 基準点からの左上の相対座標(x)を指定します。
47- * @param i_t
48- * 基準点からの左上の相対座標(y)を指定します。
49- * @param i_r
50- * 基準点からの右下の相対座標(x)を指定します。
51- * @param i_b
52- * 基準点からの右下の相対座標(y)を指定します。
53- * @param i_base_mat
54- * @return 画像の取得の成否を返す。
55- */
56- public boolean pickupImage2d(INyARRgbRaster i_src_imege, double i_l, double i_t, double i_r, double i_b, NyARTransMatResult i_base_mat) throws NyARException
57- {
58- double cp00, cp01, cp02, cp11, cp12;
59- cp00 = this._ref_perspective.m00;
60- cp01 = this._ref_perspective.m01;
61- cp02 = this._ref_perspective.m02;
62- cp11 = this._ref_perspective.m11;
63- cp12 = this._ref_perspective.m12;
64- //マーカと同一平面上にある矩形の4個の頂点を座標変換して、射影変換して画面上の
65- //頂点を計算する。
66- //[hX,hY,h]=[P][RT][x,y,z]
67-
68- //出力先
69- NyARIntPoint2d[] poinsts = this._work_points;
70-
71- double yt0,yt1,yt2;
72- double x3, y3, z3;
73-
74- double m00=i_base_mat.m00;
75- double m10=i_base_mat.m10;
76- double m20=i_base_mat.m20;
77-
78- //yとtの要素を先に計算
79- yt0=i_base_mat.m01 * i_t+i_base_mat.m03;
80- yt1=i_base_mat.m11 * i_t+i_base_mat.m13;
81- yt2=i_base_mat.m21 * i_t+i_base_mat.m23;
82- // l,t
83- x3 = m00 * i_l + yt0;
84- y3 = m10 * i_l + yt1;
85- z3 = m20 * i_l + yt2;
86- poinsts[0].x = (int) ((x3 * cp00 + y3 * cp01 + z3 * cp02) / z3);
87- poinsts[0].y = (int) ((y3 * cp11 + z3 * cp12) / z3);
88- // r,t
89- x3 = m00 * i_r + yt0;
90- y3 = m10 * i_r + yt1;
91- z3 = m20 * i_r + yt2;
92- poinsts[1].x = (int) ((x3 * cp00 + y3 * cp01 + z3 * cp02) / z3);
93- poinsts[1].y = (int) ((y3 * cp11 + z3 * cp12) / z3);
94-
95- //yとtの要素を先に計算
96- yt0=i_base_mat.m01 * i_b+i_base_mat.m03;
97- yt1=i_base_mat.m11 * i_b+i_base_mat.m13;
98- yt2=i_base_mat.m21 * i_b+i_base_mat.m23;
99-
100- // r,b
101- x3 = m00 * i_r + yt0;
102- y3 = m10 * i_r + yt1;
103- z3 = m20 * i_r + yt2;
104- poinsts[2].x = (int) ((x3 * cp00 + y3 * cp01 + z3 * cp02) / z3);
105- poinsts[2].y = (int) ((y3 * cp11 + z3 * cp12) / z3);
106- // l,b
107- x3 = m00 * i_l + yt0;
108- y3 = m10 * i_l + yt1;
109- z3 = m20 * i_l + yt2;
110- poinsts[3].x = (int) ((x3 * cp00 + y3 * cp01 + z3 * cp02) / z3);
111- poinsts[3].y = (int) ((y3 * cp11 + z3 * cp12) / z3);
112- return this.pickFromRaster(i_src_imege, poinsts);
113- }
114-}
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerParam.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerParam.java (nonexistent)
@@ -1,43 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit(Extension)
3- * --------------------------------------------------------------------------------
4- * The NyARToolkit is Java edition ARToolKit class library.
5- * Copyright (C)2008-2009 Ryo Iizuka
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- *
20- * For further information please contact.
21- * http://nyatla.jp/nyatoolkit/
22- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
23- *
24- */
25-package jp.nyatla.nyartoolkit.nyidmarker;
26-
27-/**
28- * [[Strage class]]
29- * マーカを抽出した時のパラメータを格納するクラスです。
30- *
31- */
32-public class NyIdMarkerParam
33-{
34- /**
35- * マーカの方位値です。
36- */
37- public int direction;
38- /**
39- * マーカ周辺のパターン閾値です。
40- */
41- public int threshold;
42-
43-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerData_RawBit.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerData_RawBit.java (nonexistent)
@@ -1,55 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit(Extension)
3- * --------------------------------------------------------------------------------
4- * The NyARToolkit is Java edition ARToolKit class library.
5- * Copyright (C)2008-2009 Ryo Iizuka
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- *
20- * For further information please contact.
21- * http://nyatla.jp/nyatoolkit/
22- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
23- *
24- */
25-package jp.nyatla.nyartoolkit.nyidmarker.data;
26-
27-/**
28- * [[Strage class]]
29- *
30- */
31-public class NyIdMarkerData_RawBit implements INyIdMarkerData
32-{
33- public final int[] packet=new int[22];
34- public int length;
35- public boolean isEqual(INyIdMarkerData i_target)
36- {
37- NyIdMarkerData_RawBit s=(NyIdMarkerData_RawBit)i_target;
38- if(s.length!=this.length){
39- return false;
40- }
41- for(int i=s.length-1;i>=0;i--){
42- if(s.packet[i]!=this.packet[i]){
43- return false;
44- }
45- }
46- return true;
47- }
48- public void copyFrom(INyIdMarkerData i_source)
49- {
50- final NyIdMarkerData_RawBit s=(NyIdMarkerData_RawBit)i_source;
51- System.arraycopy(s.packet,0,this.packet,0,s.length);
52- this.length=s.length;
53- return;
54- }
55-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerDataEncoder_RawBit.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerDataEncoder_RawBit.java (nonexistent)
@@ -1,61 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit(Extension)
3- * --------------------------------------------------------------------------------
4- * The NyARToolkit is Java edition ARToolKit class library.
5- * Copyright (C)2008-2009 Ryo Iizuka
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- *
20- * For further information please contact.
21- * http://nyatla.jp/nyatoolkit/
22- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
23- *
24- */
25-package jp.nyatla.nyartoolkit.nyidmarker.data;
26-
27-import jp.nyatla.nyartoolkit.nyidmarker.*;
28-
29-
30-public class NyIdMarkerDataEncoder_RawBit implements INyIdMarkerDataEncoder
31-{
32- private final static int _DOMAIN_ID=0;
33- private final static int[] _mod_data={7,31,127,511,2047,4095};
34- public boolean encode(NyIdMarkerPattern i_data,INyIdMarkerData o_dest)
35- {
36- final NyIdMarkerData_RawBit dest=(NyIdMarkerData_RawBit)o_dest;
37- if(i_data.ctrl_domain!=_DOMAIN_ID){
38- return false;
39- }
40- //パケット数計算
41- final int resolution_len=(i_data.model+1);
42- final int packet_length=(resolution_len*resolution_len)/8+1;
43- int sum=0;
44- for(int i=0;i<packet_length;i++){
45- dest.packet[i]=i_data.data[i];
46- sum+=i_data.data[i];
47- }
48- //チェックドット値計算
49- sum=sum%_mod_data[i_data.model-2];
50- //チェックドット比較
51- if(i_data.check!=sum){
52- return false;
53- }
54- dest.length=packet_length;
55- return true;
56- }
57- public INyIdMarkerData createDataInstance()
58- {
59- return new NyIdMarkerData_RawBit();
60- }
61-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerData.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerData.java (nonexistent)
@@ -1,47 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit(Extension)
3- * --------------------------------------------------------------------------------
4- * The NyARToolkit is Java edition ARToolKit class library.
5- * Copyright (C)2008-2009 Ryo Iizuka
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- *
20- * For further information please contact.
21- * http://nyatla.jp/nyatoolkit/
22- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
23- *
24- */
25-package jp.nyatla.nyartoolkit.nyidmarker.data;
26-
27-/**
28- *
29- * [[Strage class]]
30- *
31- */
32-public interface INyIdMarkerData
33-{
34- /**
35- * i_targetのマーカデータと自身のデータが等しいかを返します。
36- * @param i_target
37- * 比較するマーカオブジェクト
38- * @return
39- * 等しいかの真偽値
40- */
41- public boolean isEqual(INyIdMarkerData i_target);
42- /**
43- * i_sourceからマーカデータをコピーします。
44- * @param i_source
45- */
46- public void copyFrom(INyIdMarkerData i_source);
47-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerDataEncoder.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerDataEncoder.java (nonexistent)
@@ -1,34 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit(Extension)
3- * --------------------------------------------------------------------------------
4- * The NyARToolkit is Java edition ARToolKit class library.
5- * Copyright (C)2008-2009 Ryo Iizuka
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- *
20- * For further information please contact.
21- * http://nyatla.jp/nyatoolkit/
22- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
23- *
24- */
25-package jp.nyatla.nyartoolkit.nyidmarker.data;
26-
27-import jp.nyatla.nyartoolkit.nyidmarker.NyIdMarkerPattern;
28-
29-
30-public interface INyIdMarkerDataEncoder
31-{
32- public boolean encode(NyIdMarkerPattern i_data,INyIdMarkerData o_dest);
33- public INyIdMarkerData createDataInstance();
34-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPickup.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPickup.java (nonexistent)
@@ -1,1076 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit(Extension)
3- * --------------------------------------------------------------------------------
4- * The NyARToolkit is Java edition ARToolKit class library.
5- * Copyright (C)2008-2009 Ryo Iizuka
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- *
20- * For further information please contact.
21- * http://nyatla.jp/nyatoolkit/
22- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
23- *
24- */
25-package jp.nyatla.nyartoolkit.nyidmarker;
26-
27-import jp.nyatla.nyartoolkit.NyARException;
28-import jp.nyatla.nyartoolkit.core.raster.rgb.*;
29-import jp.nyatla.nyartoolkit.core.rasterreader.*;
30-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
31-import jp.nyatla.nyartoolkit.core.types.*;
32-import jp.nyatla.nyartoolkit.core.utils.*;
33-
34-
35-
36-
37-
38-
39-
40-/**
41- * NyARColorPatt_NyIdMarkerがラスタからPerspective変換して読みだすためのクラス
42- *
43- */
44-class PerspectivePixelReader
45-{
46- private NyARPerspectiveParamGenerator _param_gen=new NyARPerspectiveParamGenerator_O1(1,1,100,100);
47- private double[] _cparam=new double[8];
48-
49-
50- public PerspectivePixelReader()
51- {
52- return;
53- }
54-
55- public boolean setSourceSquare(NyARIntPoint2d[] i_vertex)throws NyARException
56- {
57- return this._param_gen.getParam(i_vertex, this._cparam);
58- }
59-
60- /**
61- * 矩形からピクセルを切り出します
62- * @param i_lt_x
63- * @param i_lt_y
64- * @param i_step_x
65- * @param i_step_y
66- * @param i_width
67- * @param i_height
68- * @param i_out_st
69- * o_pixelへの格納場所の先頭インデクス
70- * @param o_pixel
71- * @throws NyARException
72- */
73- private boolean rectPixels(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,int i_lt_x,int i_lt_y,int i_step_x,int i_step_y,int i_width,int i_height,int i_out_st,int[] o_pixel)throws NyARException
74- {
75- final double[] cpara=this._cparam;
76- final int[] ref_x=this._ref_x;
77- final int[] ref_y=this._ref_y;
78- final int[] pixcel_temp=this._pixcel_temp;
79- final int raster_width=i_raster_size.w;
80- final int raster_height=i_raster_size.h;
81-
82- int out_index=i_out_st;
83- final double cpara_6=cpara[6];
84- final double cpara_0=cpara[0];
85- final double cpara_3=cpara[3];
86-
87- for(int i=0;i<i_height;i++){
88- //1列分のピクセルのインデックス値を計算する。
89- int cy0=1+i*i_step_y+i_lt_y;
90- double cpy0_12=cpara[1]*cy0+cpara[2];
91- double cpy0_45=cpara[4]*cy0+cpara[5];
92- double cpy0_7=cpara[7]*cy0+1.0;
93- int pt=0;
94- for(int i2=0;i2<i_width;i2++)
95- {
96- final int cx0=1+i2*i_step_x+i_lt_x;
97- final double d=cpara_6*cx0+cpy0_7;
98- final int x=(int)((cpara_0*cx0+cpy0_12)/d);
99- final int y=(int)((cpara_3*cx0+cpy0_45)/d);
100- if(x<0||y<0||x>=raster_width||y>=raster_height)
101- {
102- return false;
103- }
104- ref_x[pt]=x;
105- ref_y[pt]=y;
106- pt++;
107- }
108- //1行分のピクセルを取得(場合によっては専用アクセサを書いた方がいい)
109- i_reader.getPixelSet(ref_x,ref_y,i_width,pixcel_temp);
110- //グレースケールにしながら、line→mapへの転写
111- for(int i2=0;i2<i_width;i2++){
112- int index=i2*3;
113- o_pixel[out_index]=(pixcel_temp[index+0]+pixcel_temp[index+1]+pixcel_temp[index+2])/3;
114- out_index++;
115- }
116- }
117- return true;
118- }
119- /**
120- * i_freqにあるゼロクロス点の周期が、等間隔か調べます。
121- * 次段半周期が、前段の80%より大きく、120%未満であるものを、等間隔周期であるとみなします。
122- * @param i_freq
123- * @param i_width
124- */
125- private static boolean checkFreqWidth(int[] i_freq,int i_width)
126- {
127- int c=i_freq[1]-i_freq[0];
128- final int count=i_width*2-1;
129- for(int i=1;i<count;i++){
130- final int n=i_freq[i+1]-i_freq[i];
131- final int v=n*100/c;
132- if(v>150 || v<50){
133- return false;
134- }
135- c=n;
136- }
137- return true;
138- }
139- /**
140- * i_freq_count_tableとi_freq_tableの内容を調査し、最も大きな周波数成分を返します。
141- * @param i_freq_count_table
142- * @param i_freq_table
143- * @param o_freq_table
144- * @return
145- * 見つかれば0以上、密辛ければ0未満
146- */
147- private static int getMaxFreq(int[] i_freq_count_table,int[] i_freq_table,int[] o_freq_table)
148- {
149- //一番成分の大きいものを得る
150- int index=-1;
151- int max=0;
152- for(int i=0;i<MAX_FREQ;i++){
153- if(max<i_freq_count_table[i]){
154- index=i;
155- max=i_freq_count_table[i];
156- }
157- }
158- if(index==-1){
159- return -1;
160- }
161- /*周波数インデクスを計算*/
162- final int st=(index-1)*index;
163- for(int i=0;i<index*2;i++)
164- {
165- o_freq_table[i]=i_freq_table[st+i]*FRQ_STEP/max;
166- }
167- return index;
168- }
169-
170-
171- //タイミングパターン用のパラメタ(FRQ_POINTS*FRQ_STEPが100を超えないようにすること)
172- private static final int FRQ_EDGE=5;
173- private static final int FRQ_STEP=2;
174- private static final int FRQ_POINTS=(100-(FRQ_EDGE*2))/FRQ_STEP;
175-
176-
177- private static final int MIN_FREQ=3;
178- private static final int MAX_FREQ=10;
179- private static final int FREQ_SAMPLE_NUM=4;
180- private static final int MAX_DATA_BITS=MAX_FREQ+MAX_FREQ-1;
181-
182- private final int[] _ref_x=new int[108];
183- private final int[] _ref_y=new int[108];
184- //(model+1)*4*3とTHRESHOLD_PIXEL*3のどちらか大きい方
185- private int[] _pixcel_temp=new int[108*3];
186-
187- private final int[] _freq_count_table=new int[MAX_FREQ];
188- private final int[] _freq_table=new int[(MAX_FREQ*2-1)*MAX_FREQ*2/2];
189-
190- /**
191- * i_y1行目とi_y2行目を平均して、タイミングパターンの周波数を得ます。
192- * LHLを1周期として、たとえばLHLHLの場合は2を返します。LHLHやHLHL等の始端と終端のレベルが異なるパターンを
193- * 検出した場合、関数は失敗します。
194- *
195- * @param i_y1
196- * @param i_y2
197- * @param i_th_h
198- * @param i_th_l
199- * @param o_edge_index
200- * 検出したエッジ位置(H->L,L->H)のインデクスを受け取る配列です。
201- * [FRQ_POINTS]以上の配列を指定してください。
202- * @return
203- * @throws NyARException
204- */
205- public int getRowFrequency(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,int i_y1,int i_th_h,int i_th_l,int[] o_edge_index)throws NyARException
206- {
207- //3,4,5,6,7,8,9,10
208- final int[] freq_count_table=this._freq_count_table;
209- //0,2,4,6,8,10,12,14,16,18,20の要素を持つ配列
210- final int freq_table[]=this._freq_table;
211- //初期化
212- final double[] cpara=this._cparam;
213-// final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
214- final int[] ref_x=this._ref_x;
215- final int[] ref_y=this._ref_y;
216- final int[] pixcel_temp=this._pixcel_temp;
217- for(int i=0;i<10;i++){
218- freq_count_table[i]=0;
219- }
220- for(int i=0;i<110;i++){
221- freq_table[i]=0;
222- }
223- final int raster_width=i_raster_size.w;
224- final int raster_height=i_raster_size.h;
225-
226- final double cpara_0=cpara[0];
227- final double cpara_3=cpara[3];
228- final double cpara_6=cpara[6];
229-
230- //10-20ピクセル目からタイミングパターンを検出
231- for(int i=0;i<FREQ_SAMPLE_NUM;i++){
232- //2行分のピクセルインデックスを計算
233- final double cy0=1+i_y1+i;
234- final double cpy0_12=cpara[1]*cy0+cpara[2];
235- final double cpy0_45=cpara[4]*cy0+cpara[5];
236- final double cpy0_7=cpara[7]*cy0+1.0;
237-
238- int pt=0;
239- for(int i2=0;i2<FRQ_POINTS;i2++)
240- {
241- final double cx0=1+i2*FRQ_STEP+FRQ_EDGE;
242- final double d=(cpara_6*cx0)+cpy0_7;
243- final int x=(int)((cpara_0*cx0+cpy0_12)/d);
244- final int y=(int)((cpara_3*cx0+cpy0_45)/d);
245- if(x<0||y<0||x>=raster_width||y>=raster_height)
246- {
247- return -1;
248- }
249- ref_x[pt]=x;
250- ref_y[pt]=y;
251- pt++;
252- }
253-
254- //ピクセルを取得(入力画像を多様化するならここから先を調整すること)
255- i_reader.getPixelSet(ref_x,ref_y,FRQ_POINTS,pixcel_temp);
256-
257- //o_edge_indexを一時的に破壊して調査する
258- final int freq_t=getFreqInfo(pixcel_temp,i_th_h,i_th_l,o_edge_index);
259-
260- //周期は3-10であること
261- if(freq_t<MIN_FREQ || freq_t>MAX_FREQ){
262- continue;
263- }
264- //周期は等間隔であること
265- if(!checkFreqWidth(o_edge_index,freq_t)){
266- continue;
267- }
268- //検出カウンタを追加
269- freq_count_table[freq_t]++;
270- final int table_st=(freq_t-1)*freq_t;
271- for(int i2=0;i2<freq_t*2;i2++){
272- freq_table[table_st+i2]+=o_edge_index[i2];
273- }
274- }
275- return getMaxFreq(freq_count_table,freq_table,o_edge_index);
276- }
277-
278- public int getColFrequency(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,int i_x1,int i_th_h,int i_th_l,int[] o_edge_index)throws NyARException
279- {
280- final double[] cpara=this._cparam;
281-// final INyARRgbPixelReader reader=this._raster.getRgbPixelReader();
282- final int[] ref_x=this._ref_x;
283- final int[] ref_y=this._ref_y;
284- final int[] pixcel_temp=this._pixcel_temp;
285- //0,2,4,6,8,10,12,14,16,18,20=(11*20)/2=110
286- //初期化
287- final int[] freq_count_table=this._freq_count_table;
288- for(int i=0;i<10;i++){
289- freq_count_table[i]=0;
290- }
291- final int[] freq_table=this._freq_table;
292- for(int i=0;i<110;i++){
293- freq_table[i]=0;
294- }
295- final int raster_width=i_raster_size.w;
296- final int raster_height=i_raster_size.h;
297-
298-
299- final double cpara7=cpara[7];
300- final double cpara4=cpara[4];
301- final double cpara1=cpara[1];
302- //基準点から4ピクセルを参照パターンとして抽出
303- for(int i=0;i<FREQ_SAMPLE_NUM;i++){
304-
305- int cx0=1+i+i_x1;
306- final double cp6_0=cpara[6]*cx0;
307- final double cpx0_0=cpara[0]*cx0+cpara[2];
308- final double cpx3_0=cpara[3]*cx0+cpara[5];
309-
310- int pt=0;
311- for(int i2=0;i2<FRQ_POINTS;i2++)
312- {
313- int cy=1+i2*FRQ_STEP+FRQ_EDGE;
314-
315- final double d=cp6_0+cpara7*cy+1.0;
316- final int x=(int)((cpx0_0+cpara1*cy)/d);
317- final int y=(int)((cpx3_0+cpara4*cy)/d);
318- if(x<0||y<0||x>=raster_width||y>=raster_height)
319- {
320- return -1;
321- }
322- ref_x[pt]=x;
323- ref_y[pt]=y;
324- pt++;
325- }
326-
327- //ピクセルを取得(入力画像を多様化するならここを調整すること)
328- i_reader.getPixelSet(ref_x,ref_y,FRQ_POINTS,pixcel_temp);
329-
330- final int freq_t=getFreqInfo(pixcel_temp,i_th_h,i_th_l,o_edge_index);
331- //周期は3-10であること
332- if(freq_t<MIN_FREQ || freq_t>MAX_FREQ){
333- continue;
334- }
335- //周期は等間隔であること
336- if(!checkFreqWidth(o_edge_index,freq_t)){
337- continue;
338- }
339- //検出カウンタを追加
340- freq_count_table[freq_t]++;
341- final int table_st=(freq_t-1)*freq_t;
342- for(int i2=0;i2<freq_t*2;i2++){
343- freq_table[table_st+i2]+=o_edge_index[i2];
344- }
345- }
346- return getMaxFreq(freq_count_table,freq_table,o_edge_index);
347- }
348-
349- /**
350- * デバックすんだらstaticにしておk
351- * @param i_pixcels
352- * @param i_th_h
353- * @param i_th_l
354- * @param o_edge_index
355- * @return
356- */
357- private static int getFreqInfo(int[] i_pixcels,int i_th_h,int i_th_l,int[] o_edge_index)
358- {
359- //トークンを解析して、周波数を計算
360- int i=0;
361- int frq_l2h=0;
362- int frq_h2l=0;
363- while(i<FRQ_POINTS){
364- //L->Hトークンを検出する
365- while(i<FRQ_POINTS){
366- final int index=i*3;
367- final int pix=(i_pixcels[index+0]+i_pixcels[index+1]+i_pixcels[index+2])/3;
368- if(pix>i_th_h){
369- //トークン発見
370- o_edge_index[frq_l2h+frq_h2l]=i;
371- frq_l2h++;
372- break;
373- }
374- i++;
375- }
376- i++;
377- //L->Hトークンを検出する
378- while(i<FRQ_POINTS){
379- final int index=i*3;
380- final int pix=(i_pixcels[index+0]+i_pixcels[index+1]+i_pixcels[index+2])/3;
381- if(pix<=i_th_l){
382- //トークン発見
383- o_edge_index[frq_l2h+frq_h2l]=i;
384- frq_h2l++;
385- break;
386- }
387- i++;
388- }
389- i++;
390- }
391- return frq_l2h==frq_h2l?frq_l2h:-1;
392- }
393-
394- private final static int THRESHOLD_EDGE=10;
395- private final static int THRESHOLD_STEP=2;
396- private final static int THRESHOLD_WIDTH=10;
397- private final static int THRESHOLD_PIXEL=THRESHOLD_WIDTH/THRESHOLD_STEP;
398- private final static int THRESHOLD_SAMPLE=THRESHOLD_PIXEL*THRESHOLD_PIXEL;
399- private final static int THRESHOLD_SAMPLE_LT=THRESHOLD_EDGE;
400- private final static int THRESHOLD_SAMPLE_RB=100-THRESHOLD_WIDTH-THRESHOLD_EDGE;
401-
402- public static class TThreshold{
403- public int th_h;
404- public int th_l;
405- public int th;
406- public int lt_x;
407- public int lt_y;
408- public int rb_x;
409- public int rb_y;
410- }
411-
412- class THighAndLow{
413- public int h;
414- public int l;
415- }
416- /**
417- * ピクセル配列の上位、下位の4ピクセルのピクセル値平均を求めます。
418- * この関数は、(4/i_pixcel.length)の領域を占有するPtail法で双方向の閾値を求めることになります。
419- * @param i_pixcel
420- * @param i_initial
421- * @param i_out
422- */
423- private void getPtailHighAndLow(int[] i_pixcel,THighAndLow i_out)
424- {
425- int h3,h2,h1,h0,l3,l2,l1,l0;
426- h3=h2=h1=h0=l3=l2=l1=l0=i_pixcel[0];
427-
428- for(int i=i_pixcel.length-1;i>=1;i--){
429- final int pix=i_pixcel[i];
430- if(h0<pix){
431- if(h1<pix){
432- if(h2<pix){
433- if(h3<pix){
434- h0=h1;
435- h1=h2;
436- h2=h3;
437- h3=pix;
438- }else{
439- h0=h1;
440- h1=h2;
441- h2=pix;
442- }
443- }else{
444- h0=h1;
445- h1=pix;
446- }
447- }else{
448- h0=pix;
449- }
450- }
451- if(l0>pix){
452- if(l1>pix){
453- if(l2>pix){
454- if(l3>pix){
455- l0=l1;
456- l1=l2;
457- l2=l3;
458- l3=pix;
459- }else{
460- l0=l1;
461- l1=l2;
462- l2=pix;
463- }
464- }else{
465- l0=l1;
466- l1=pix;
467- }
468- }else{
469- l0=pix;
470- }
471- }
472- }
473- i_out.l=(l0+l1+l2+l3)/4;
474- i_out.h=(h0+h1+h2+h3)/4;
475- return;
476- }
477- private THighAndLow __detectThresholdValue_hl=new THighAndLow();
478- private NyARIntPoint2d __detectThresholdValue_tpt=new NyARIntPoint2d();
479- private int[] _th_pixels=new int[THRESHOLD_SAMPLE*4];
480- /**
481- * 指定した場所のピクセル値を調査して、閾値を計算して返します。
482- * @param i_reader
483- * @param i_x
484- * @param i_y
485- * @return
486- * @throws NyARException
487- */
488- public void detectThresholdValue(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,TThreshold o_threshold)throws NyARException
489- {
490- final int[] th_pixels=this._th_pixels;
491-
492- //左上のピックアップ領域からピクセルを得る(00-24)
493- rectPixels(i_reader,i_raster_size,THRESHOLD_SAMPLE_LT,THRESHOLD_SAMPLE_LT,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,0,th_pixels);
494-
495- //左下のピックアップ領域からピクセルを得る(25-49)
496- rectPixels(i_reader,i_raster_size,THRESHOLD_SAMPLE_LT,THRESHOLD_SAMPLE_RB,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,THRESHOLD_SAMPLE,th_pixels);
497-
498- //右上のピックアップ領域からピクセルを得る(50-74)
499- rectPixels(i_reader,i_raster_size,THRESHOLD_SAMPLE_RB,THRESHOLD_SAMPLE_LT,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,THRESHOLD_SAMPLE*2,th_pixels);
500-
501- //右下のピックアップ領域からピクセルを得る(75-99)
502- rectPixels(i_reader,i_raster_size,THRESHOLD_SAMPLE_RB,THRESHOLD_SAMPLE_RB,THRESHOLD_STEP,THRESHOLD_STEP,THRESHOLD_PIXEL,THRESHOLD_PIXEL,THRESHOLD_SAMPLE*3,th_pixels);
503-
504- final THighAndLow hl=this.__detectThresholdValue_hl;
505- //Ptailで求めたピクセル平均
506- getPtailHighAndLow(th_pixels,hl);
507-
508-
509-
510- //閾値中心
511- int th=(hl.h+hl.l)/2;
512- //ヒステリシス(差分の20%)
513- int th_sub=(hl.h-hl.l)/5;
514-
515- o_threshold.th=th;
516- o_threshold.th_h=th+th_sub;//ヒステリシス付き閾値
517- o_threshold.th_l=th-th_sub;//ヒステリシス付き閾値
518-
519- //エッジを計算(明点重心)
520- int lt_x,lt_y,lb_x,lb_y,rt_x,rt_y,rb_x,rb_y;
521- final NyARIntPoint2d tpt=this.__detectThresholdValue_tpt;
522- //LT
523- if(getHighPixelCenter(0,th_pixels,THRESHOLD_PIXEL,THRESHOLD_PIXEL,th,tpt)){
524- lt_x=tpt.x*THRESHOLD_STEP;
525- lt_y=tpt.y*THRESHOLD_STEP;
526- }else{
527- lt_x=11;
528- lt_y=11;
529- }
530- //LB
531- if(getHighPixelCenter(THRESHOLD_SAMPLE*1,th_pixels,THRESHOLD_PIXEL,THRESHOLD_PIXEL,th,tpt)){
532- lb_x=tpt.x*THRESHOLD_STEP;
533- lb_y=tpt.y*THRESHOLD_STEP;
534- }else{
535- lb_x=11;
536- lb_y=-1;
537- }
538- //RT
539- if(getHighPixelCenter(THRESHOLD_SAMPLE*2,th_pixels,THRESHOLD_PIXEL,THRESHOLD_PIXEL,th,tpt)){
540- rt_x=tpt.x*THRESHOLD_STEP;
541- rt_y=tpt.y*THRESHOLD_STEP;
542- }else{
543- rt_x=-1;
544- rt_y=11;
545- }
546- //RB
547- if(getHighPixelCenter(THRESHOLD_SAMPLE*3,th_pixels,THRESHOLD_PIXEL,THRESHOLD_PIXEL,th,tpt)){
548- rb_x=tpt.x*THRESHOLD_STEP;
549- rb_y=tpt.y*THRESHOLD_STEP;
550- }else{
551- rb_x=-1;
552- rb_y=-1;
553- }
554- //トラッキング開始位置の決定
555- o_threshold.lt_x=(lt_x+lb_x)/2+THRESHOLD_SAMPLE_LT-1;
556- o_threshold.rb_x=(rt_x+rb_x)/2+THRESHOLD_SAMPLE_RB+1;
557- o_threshold.lt_y=(lt_y+rt_y)/2+THRESHOLD_SAMPLE_LT-1;
558- o_threshold.rb_y=(lb_y+rb_y)/2+THRESHOLD_SAMPLE_RB+1;
559- return;
560- }
561-
562- private boolean getHighPixelCenter(int i_st,final int[] i_pixels,int i_width,int i_height,int i_th,NyARIntPoint2d o_point)
563- {
564- int rp=i_st;
565- int pos_x=0;
566- int pos_y=0;
567- int number_of_pos=0;
568- for(int i=0;i<i_height;i++){
569- for(int i2=0;i2<i_width;i2++){
570- if(i_pixels[rp++]>i_th){
571- pos_x+=i2;
572- pos_y+=i;
573- number_of_pos++;
574- }
575- }
576- }
577- if(number_of_pos>0){
578- pos_x/=number_of_pos;
579- pos_y/=number_of_pos;
580- }else{
581- return false;
582- }
583- o_point.x=pos_x;
584- o_point.y=pos_y;
585- return true;
586- }
587- private int[] __detectDataBitsIndex_freq_index1=new int[FRQ_POINTS];
588- private int[] __detectDataBitsIndex_freq_index2=new int[FRQ_POINTS];
589- private int detectDataBitsIndex(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,PerspectivePixelReader.TThreshold i_th,double[] o_index_row,double[] o_index_col) throws NyARException
590- {
591- //周波数を測定
592- final int[] freq_index1=this.__detectDataBitsIndex_freq_index1;
593- final int[] freq_index2=this.__detectDataBitsIndex_freq_index2;
594-
595- int frq_t=getRowFrequency(i_reader,i_raster_size,i_th.lt_y,i_th.th_h,i_th.th_l,freq_index1);
596- int frq_b=getRowFrequency(i_reader,i_raster_size,i_th.rb_y,i_th.th_h,i_th.th_l,freq_index2);
597- //周波数はまとも?
598- if((frq_t<0 && frq_b<0) || frq_t==frq_b){
599- return -1;
600- }
601- //タイミングパターンからインデクスを作成
602- int freq_h,freq_v;
603- int[] index;
604- if(frq_t>frq_b){
605- freq_h=frq_t;
606- index=freq_index1;
607- }else{
608- freq_h=frq_b;
609- index=freq_index2;
610- }
611- for(int i=0;i<freq_h+freq_h-1;i++){
612- o_index_row[i*2]=((index[i+1]-index[i])*2/5+index[i])+FRQ_EDGE;
613- o_index_row[i*2+1]=((index[i+1]-index[i])*3/5+index[i])+FRQ_EDGE;
614- }
615-
616-
617- final int frq_l=getColFrequency(i_reader,i_raster_size,i_th.lt_x,i_th.th_h,i_th.th_l,freq_index1);
618- final int frq_r=getColFrequency(i_reader,i_raster_size,i_th.rb_x,i_th.th_h,i_th.th_l,freq_index2);
619- //周波数はまとも?
620- if((frq_l<0 && frq_r<0) || frq_l==frq_r){
621- return -1;
622- }
623- //タイミングパターンからインデクスを作成
624- if(frq_l>frq_r){
625- freq_v=frq_l;
626- index=freq_index1;
627- }else{
628- freq_v=frq_r;
629- index=freq_index2;
630- }
631- //同じ周期?
632- if(freq_v!=freq_h){
633- return -1;
634- }
635-
636- for(int i=0;i<freq_v+freq_v-1;i++){
637- final int w=index[i];
638- final int w2=index[i+1]-w;
639- o_index_col[i*2]=((w2)*2/5+w)+FRQ_EDGE;
640- o_index_col[i*2+1]=((w2)*3/5+w)+FRQ_EDGE;
641- }
642- //Lv4以上は無理
643- if(freq_v>MAX_FREQ){
644- return -1;
645- }
646- return freq_v;
647-
648- }
649- private double[] __readDataBits_index_bit_x=new double[MAX_DATA_BITS*2];
650- private double[] __readDataBits_index_bit_y=new double[MAX_DATA_BITS*2];
651-
652- public boolean readDataBits(INyARRgbPixelReader i_reader,NyARIntSize i_raster_size,PerspectivePixelReader.TThreshold i_th,MarkerPattEncoder o_bitbuffer)throws NyARException
653- {
654- final double[] index_x=this.__readDataBits_index_bit_x;
655- final double[] index_y=this.__readDataBits_index_bit_y;
656-
657-
658- //読み出し位置を取得
659- final int size=detectDataBitsIndex(i_reader,i_raster_size,i_th,index_x,index_y);
660- final int resolution=size+size-1;
661- if(size<0){
662- return false;
663- }
664- if(!o_bitbuffer.initEncoder(size-1)){
665- return false;
666- }
667-
668- final double[] cpara=this._cparam;
669- final int[] ref_x=this._ref_x;
670- final int[] ref_y=this._ref_y;
671- final int[] pixcel_temp=this._pixcel_temp;
672-
673- final double cpara_0=cpara[0];
674- final double cpara_1=cpara[1];
675- final double cpara_3=cpara[3];
676- final double cpara_6=cpara[6];
677-
678-
679- final int th=i_th.th;
680- int p=0;
681- for(int i=0;i<resolution;i++){
682- //1列分のピクセルのインデックス値を計算する。
683- double cy0=1+index_y[i*2+0];
684- double cy1=1+index_y[i*2+1];
685- double cpy0_12=cpara_1*cy0+cpara[2];
686- double cpy0_45=cpara[4]*cy0+cpara[5];
687- double cpy0_7=cpara[7]*cy0+1.0;
688- double cpy1_12=cpara_1*cy1+cpara[2];
689- double cpy1_45=cpara[4]*cy1+cpara[5];
690- double cpy1_7=cpara[7]*cy1+1.0;
691-
692- int pt=0;
693- for(int i2=0;i2<resolution;i2++)
694- {
695-
696- double d;
697- double cx0=1+index_x[i2*2+0];
698- double cx1=1+index_x[i2*2+1];
699-
700- double cp6_0=cpara_6*cx0;
701- double cpx0_0=cpara_0*cx0;
702- double cpx3_0=cpara_3*cx0;
703-
704- double cp6_1=cpara_6*cx1;
705- double cpx0_1=cpara_0*cx1;
706- double cpx3_1=cpara_3*cx1;
707-
708- d=cp6_0+cpy0_7;
709- ref_x[pt]=(int)((cpx0_0+cpy0_12)/d);
710- ref_y[pt]=(int)((cpx3_0+cpy0_45)/d);
711- pt++;
712-
713- d=cp6_0+cpy1_7;
714- ref_x[pt]=(int)((cpx0_0+cpy1_12)/d);
715- ref_y[pt]=(int)((cpx3_0+cpy1_45)/d);
716- pt++;
717-
718- d=cp6_1+cpy0_7;
719- ref_x[pt]=(int)((cpx0_1+cpy0_12)/d);
720- ref_y[pt]=(int)((cpx3_1+cpy0_45)/d);
721- pt++;
722-
723- d=cp6_1+cpy1_7;
724- ref_x[pt]=(int)((cpx0_1+cpy1_12)/d);
725- ref_y[pt]=(int)((cpx3_1+cpy1_45)/d);
726- pt++;
727- }
728- //1行分のピクセルを取得(場合によっては専用アクセサを書いた方がいい)
729- i_reader.getPixelSet(ref_x,ref_y,resolution*4,pixcel_temp);
730- //グレースケールにしながら、line→mapへの転写
731- for(int i2=0;i2<resolution;i2++){
732- int index=i2*3*4;
733- int pixel=( pixcel_temp[index+0]+pixcel_temp[index+1]+pixcel_temp[index+2]+
734- pixcel_temp[index+3]+pixcel_temp[index+4]+pixcel_temp[index+5]+
735- pixcel_temp[index+6]+pixcel_temp[index+7]+pixcel_temp[index+8]+
736- pixcel_temp[index+9]+pixcel_temp[index+10]+pixcel_temp[index+11])/(4*3);
737- //暗点を1、明点を0で表現します。
738- o_bitbuffer.setBitByBitIndex(p,pixel>th?0:1);
739- p++;
740- }
741- }
742-/*
743- for(int i=0;i<225*4;i++){
744- this.vertex_x[i]=0;
745- this.vertex_y[i]=0;
746- }
747- for(int i=0;i<(resolution)*2;i++){
748- for(int i2=0;i2<(resolution)*2;i2++){
749- this.vertex_x[i*(resolution)*2+i2]=(int)index_x[i2];
750- this.vertex_y[i*(resolution)*2+i2]=(int)index_y[i];
751-
752- }
753- }
754-*/ return true;
755- }
756- public boolean setSquare(NyARIntPoint2d[] i_vertex) throws NyARException
757- {
758- if (!this._param_gen.getParam(i_vertex,this._cparam)) {
759- return false;
760- }
761- return true;
762- }
763-
764-}
765-class MarkerPattDecoder
766-{
767- public void decode(int model,int domain,int mask)
768- {
769-
770- }
771-}
772-/**
773- * マーカパターンのエンコーダです。
774- *
775- */
776-class MarkerPattEncoder
777-{
778- private final static int[] _bit_table_3={
779- 25, 26, 27, 28, 29, 30, 31,
780- 48, 9, 10, 11, 12, 13, 32,
781- 47, 24, 1, 2, 3, 14, 33,
782- 46, 23, 8, 0, 4, 15, 34,
783- 45, 22, 7, 6, 5, 16, 35,
784- 44, 21, 20, 19, 18, 17, 36,
785- 43, 42, 41, 40, 39, 38, 37
786- };
787- private final static int[] _bit_table_2={
788- 9, 10, 11, 12, 13,
789- 24, 1, 2, 3, 14,
790- 23, 8, 0, 4, 15,
791- 22, 7, 6, 5, 16,
792- 21, 20, 19, 18, 17};
793- private final static int[][] _bit_tables={
794- _bit_table_2,_bit_table_3,null,null,null,null,null,
795- };
796- /**
797- * RECT(0):[0]=(0)
798- * RECT(1):[1]=(1-8)
799- * RECT(2):[2]=(9-16),[3]=(17-24)
800- * RECT(3):[4]=(25-32),[5]=(33-40),[6]=(41-48)
801- */
802- private int[] _bit_table;
803- private int[] _bits=new int[16];
804- private int[] _work=new int[16];
805- private int _model;
806- public void setBitByBitIndex(int i_index_no,int i_value)
807- {
808- assert i_value==0 || i_value==1;
809- final int bit_no=this._bit_table[i_index_no];
810- if(bit_no==0){
811- this._bits[0]=i_value;
812- }else{
813- int bidx=(bit_no-1)/8+1;
814- int sidx=(bit_no-1)%8;
815- this._bits[bidx]=(this._bits[bidx]&(~(0x01<<sidx)))|(i_value<<sidx);
816- }
817- return;
818- }
819-
820- public void setBit(int i_bit_no,int i_value)
821- {
822- assert i_value==0 || i_value==1;
823- if(i_bit_no==0){
824- this._bits[0]=i_value;
825- }else{
826- int bidx=(i_bit_no-1)/8+1;
827- int sidx=(i_bit_no-1)%8;
828- this._bits[bidx]=(this._bits[bidx]&(~(0x01<<sidx)))|(i_value<<sidx);
829- }
830- return;
831- }
832- public int getBit(int i_bit_no)
833- {
834- if(i_bit_no==0){
835- return this._bits[0];
836- }else{
837- int bidx=(i_bit_no-1)/8+1;
838- int sidx=(i_bit_no-1)%8;
839- return (this._bits[bidx]>>(sidx))&(0x01);
840- }
841- }
842- public int getModel()
843- {
844- return this._model;
845- }
846- private static int getControlValue(int i_model,int[] i_data)
847- {
848- int v;
849- switch(i_model){
850- case 2:
851- v=(i_data[2] & 0x0e)>>1;
852- return v>=5?v-1:v;
853- case 3:
854- v=(i_data[4] & 0x3e)>>1;
855- return v>=21?v-1:v;
856- case 4:
857- case 5:
858- case 6:
859- case 7:
860- default:
861- break;
862- }
863- return -1;
864- }
865- public static int getCheckValue(int i_model,int[] i_data)
866- {
867- int v;
868- switch(i_model){
869- case 2:
870- v=(i_data[2] & 0xe0)>>5;
871- return v>5?v-1:v;
872- case 3:
873- v=((i_data[4] & 0x80)>>7) |((i_data[5] & 0x0f)<<1);
874- return v>21?v-1:v;
875- case 4:
876- case 5:
877- case 6:
878- case 7:
879- default:
880- break;
881- }
882- return -1;
883- }
884- public boolean initEncoder(int i_model)
885- {
886- if(i_model>3 || i_model<2){
887- //Lv4以降に対応する時は、この制限を変える。
888- return false;
889- }
890- this._bit_table=_bit_tables[i_model-2];
891- this._model=i_model;
892- return true;
893- }
894- private int getDirection()
895- {
896- int l,t,r,b;
897- int timing_pat;
898- switch(this._model){
899- case 2:
900- //トラッキングセルを得る
901- t=this._bits[2] & 0x1f;
902- r=((this._bits[2] & 0xf0)>>4)|((this._bits[3]&0x01)<<4);
903- b=this._bits[3] & 0x1f;
904- l=((this._bits[3] & 0xf0)>>4)|((this._bits[2]&0x01)<<4);
905- timing_pat=0x0a;
906- break;
907- case 3:
908- t=this._bits[4] & 0x7f;
909- r=((this._bits[4] & 0xc0)>>6)|((this._bits[5] & 0x1f)<<2);
910- b=((this._bits[5] & 0xf0)>>4)|((this._bits[6] & 0x07)<<4);
911- l=((this._bits[6] & 0xfc)>>2)|((this._bits[4] & 0x01)<<6);
912- timing_pat=0x2a;
913- break;
914- default:
915- return -3;
916- }
917- //タイミングパターンの比較
918- if(t==timing_pat){
919- if(r==timing_pat){
920- return (b!=timing_pat && l!=timing_pat)?2:-2;
921- }else if(l==timing_pat){
922- return (b!=timing_pat && r!=timing_pat)?3:-2;
923- }
924- }else if(b==timing_pat){
925- if(r==timing_pat){
926- return (t!=timing_pat && l!=timing_pat)?1:-2;
927- }else if(l==timing_pat){
928- return (t!=timing_pat && r!=timing_pat)?0:-2;
929- }
930- }
931- return -1;
932- }
933- /**
934- * 格納しているマーカパターンをエンコードして、マーカデータを返します。
935- * @param o_out
936- * @return
937- * 成功すればマーカの方位を返却します。失敗すると-1を返します。
938- */
939-
940- public int encode(NyIdMarkerPattern o_out)
941- {
942- final int d=getDirection();
943- if(d<0){
944- return -1;
945- }
946- //回転ビットの取得
947- getRotatedBits(d,o_out.data);
948- final int model=this._model;
949- //周辺ビットの取得
950- o_out.model=model;
951- int control_bits=getControlValue(model,o_out.data);
952- o_out.check=getCheckValue(model,o_out.data);
953- o_out.ctrl_mask=control_bits%5;
954- o_out.ctrl_domain=control_bits/5;
955- if(o_out.ctrl_domain!=0 || o_out.ctrl_mask!=0){
956- return -1;
957- }
958- //マスク解除処理を実装すること
959- return d;
960- }
961- private void getRotatedBits(int i_direction,int[] o_out)
962- {
963- int sl=i_direction*2;
964- int sr=8-sl;
965-
966- int w1;
967- o_out[0]=this._bits[0];
968- //RECT1
969- w1=this._bits[1];
970- o_out[1]=((w1<<sl)|(w1>>sr))& 0xff;
971-
972- //RECT2
973- sl=i_direction*4;
974- sr=16-sl;
975- w1=this._bits[2]|(this._bits[3]<<8);
976- w1=(w1<<sl)|(w1>>sr);
977- o_out[2]=w1 & 0xff;
978- o_out[3]=(w1>>8) & 0xff;
979-
980- if(this._model<2){
981- return;
982- }
983-
984- //RECT3
985- sl=i_direction*6;
986- sr=24-sl;
987- w1=this._bits[4]|(this._bits[5]<<8)|(this._bits[6]<<16);
988- w1=(w1<<sl)|(w1>>sr);
989- o_out[4]=w1 & 0xff;
990- o_out[5]=(w1>>8) & 0xff;
991- o_out[6]=(w1>>16) & 0xff;
992-
993- if(this._model<3){
994- return;
995- }
996- //RECT4(Lv4以降はここの制限を変える)
997-// shiftLeft(this._bits,7,3,i_direction*8);
998-// if(this._model<4){
999-// return;
1000-// }
1001- return;
1002- }
1003- public void shiftLeft(int[] i_pack,int i_start,int i_length,int i_ls)
1004- {
1005- int[] work=this._work;
1006- //端数シフト
1007- final int mod_shift=i_ls%8;
1008- for(int i=i_length-1;i>=1;i--){
1009- work[i]=(i_pack[i+i_start]<<mod_shift)|(0xff&(i_pack[i+i_start-1]>>(8-mod_shift)));
1010- }
1011- work[0]=(i_pack[i_start]<<mod_shift)|(0xff&(i_pack[i_start+i_length-1]>>(8-mod_shift)));
1012- //バイトシフト
1013- final int byte_shift=(i_ls/8)%i_length;
1014- for(int i=i_length-1;i>=0;i--){
1015- i_pack[(byte_shift+i)%i_length+i_start]=0xff & work[i];
1016- }
1017- return;
1018- }
1019-}
1020-/**
1021- * ラスタ画像の任意矩形から、NyARIdMarkerDataを抽出します。
1022- *
1023- */
1024-public class NyIdMarkerPickup
1025-{
1026- private PerspectivePixelReader _perspective_reader;
1027- private final PerspectivePixelReader.TThreshold __pickFromRaster_th=new PerspectivePixelReader.TThreshold();
1028- private final MarkerPattEncoder __pickFromRaster_encoder=new MarkerPattEncoder();
1029-
1030-
1031- public NyIdMarkerPickup()
1032- {
1033- this._perspective_reader=new PerspectivePixelReader();
1034- return;
1035- }
1036- /**
1037- * i_imageから、idマーカを読みだします。
1038- * o_dataにはマーカデータ、o_paramにはまーかのパラメータを返却します。
1039- * @param image
1040- * @param i_square
1041- * @param o_data
1042- * @param o_param
1043- * @return
1044- * @throws NyARException
1045- */
1046- public boolean pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertex,NyIdMarkerPattern o_data,NyIdMarkerParam o_param)throws NyARException
1047- {
1048-
1049- //遠近法のパラメータを計算
1050- if(!this._perspective_reader.setSourceSquare(i_vertex)){
1051- return false;
1052- };
1053-
1054- INyARRgbPixelReader reader=image.getRgbPixelReader();
1055- NyARIntSize raster_size=image.getSize();
1056-
1057-
1058-
1059- final PerspectivePixelReader.TThreshold th=this.__pickFromRaster_th;
1060- final MarkerPattEncoder encoder=this.__pickFromRaster_encoder;
1061- //マーカパラメータを取得
1062- this._perspective_reader.detectThresholdValue(reader,raster_size,th);
1063-
1064- if(!this._perspective_reader.readDataBits(reader,raster_size,th, encoder)){
1065- return false;
1066- }
1067- final int d=encoder.encode(o_data);
1068- if(d<0){
1069- return false;
1070- }
1071- o_param.direction=d;
1072- o_param.threshold=th.th;
1073-
1074- return true;
1075- }
1076-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPattern.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPattern.java (nonexistent)
@@ -1,39 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit(Extension)
3- * --------------------------------------------------------------------------------
4- * The NyARToolkit is Java edition ARToolKit class library.
5- * Copyright (C)2008-2009 Ryo Iizuka
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- *
20- * For further information please contact.
21- * http://nyatla.jp/nyatoolkit/
22- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
23- *
24- */
25-package jp.nyatla.nyartoolkit.nyidmarker;
26-/**
27- * [[Strage class]]
28- * IDマーカパターン値を格納するクラスです。
29- * クラスは、未整形のマーカデータを格納しています。
30- *
31- */
32-public class NyIdMarkerPattern
33-{
34- public int model;
35- public int ctrl_domain;
36- public int ctrl_mask;
37- public int check;
38- public final int[] data=new int[32];
39-}
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARRectOffset.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARRectOffset.java (nonexistent)
@@ -1,78 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat;
32-
33-import jp.nyatla.nyartoolkit.core.types.*;
34-
35-/**
36- * 矩形の頂点情報を格納します。
37- */
38-final public class NyARRectOffset
39-{
40- public final NyARDoublePoint3d[] vertex=NyARDoublePoint3d.createArray(4);
41- public static NyARRectOffset[] createArray(int i_number)
42- {
43- NyARRectOffset[] ret=new NyARRectOffset[i_number];
44- for(int i=0;i<i_number;i++)
45- {
46- ret[i]=new NyARRectOffset();
47- }
48- return ret;
49- }
50- /**
51- * 中心位置と辺長から、オフセット情報を作成して設定する。
52- * @param i_width
53- */
54- public void setSquare(double i_width)
55- {
56- final double w_2 = i_width / 2.0;
57-
58- NyARDoublePoint3d vertex3d_ptr;
59- vertex3d_ptr= this.vertex[0];
60- vertex3d_ptr.x = -w_2;
61- vertex3d_ptr.y = w_2;
62- vertex3d_ptr.z = 0.0;
63- vertex3d_ptr= this.vertex[1];
64- vertex3d_ptr.x = w_2;
65- vertex3d_ptr.y = w_2;
66- vertex3d_ptr.z = 0.0;
67- vertex3d_ptr= this.vertex[2];
68- vertex3d_ptr.x = w_2;
69- vertex3d_ptr.y = -w_2;
70- vertex3d_ptr.z = 0.0;
71- vertex3d_ptr= this.vertex[3];
72- vertex3d_ptr.x = -w_2;
73- vertex3d_ptr.y = -w_2;
74- vertex3d_ptr.z = 0.0;
75-
76- return;
77- }
78-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize.java (nonexistent)
@@ -1,286 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;
32-
33-
34-import jp.nyatla.nyartoolkit.NyARException;
35-import jp.nyatla.nyartoolkit.core.param.*;
36-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
37-import jp.nyatla.nyartoolkit.core.transmat.solver.INyARTransportVectorSolver;
38-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
39-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
40-/**
41- * 基本姿勢と実画像を一致するように、角度を微調整→平行移動量を再計算
42- * を繰り返して、変換行列を最適化する。
43- *
44- */
45-public class NyARRotMatrixOptimize implements INyARRotMatrixOptimize
46-{
47- private final static int AR_GET_TRANS_MAT_MAX_LOOP_COUNT = 5;// #define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5
48- private final static double AR_GET_TRANS_MAT_MAX_FIT_ERROR = 1.0;// #define AR_GET_TRANS_MAT_MAX_FIT_ERROR 1.0
49- private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
50- public NyARRotMatrixOptimize(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
51- {
52- this._projection_mat_ref=i_projection_mat_ref;
53- return;
54- }
55- final public double optimize(NyARRotMatrix_ARToolKit io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException
56- {
57- double err = -1;
58- /*ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。*/
59- for (int i = 0;; i++) {
60- // <arGetTransMat3>
61- err = modifyMatrix(io_rotmat,io_transvec,i_offset_3d,i_2d_vertex);
62- i_solver.solveTransportVector(i_offset_3d, io_transvec);
63- err = modifyMatrix(io_rotmat,io_transvec,i_offset_3d,i_2d_vertex);
64- // //</arGetTransMat3>
65- if (err < AR_GET_TRANS_MAT_MAX_FIT_ERROR || i == AR_GET_TRANS_MAT_MAX_LOOP_COUNT-1) {
66- break;
67- }
68- i_solver.solveTransportVector(i_offset_3d, io_transvec);
69- }
70- return err;
71- }
72-
73- private final double[][] __modifyMatrix_double1D = new double[8][3];
74- /**
75- * arGetRot計算を階層化したModifyMatrix 896
76- *
77- * @param nyrot
78- * @param trans
79- * @param i_vertex3d
80- * [m][3]
81- * @param i_vertex2d
82- * [n][2]
83- * @return
84- * @throws NyARException
85- */
86- public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException
87- {
88- double factor;
89- double a2, b2, c2;
90- double ma = 0.0, mb = 0.0, mc = 0.0;
91- double h, x, y;
92- double err, minerr = 0;
93- int t1, t2, t3;
94- int s1 = 0, s2 = 0, s3 = 0;
95-
96- factor = 10.0 * Math.PI / 180.0;
97- double rot0, rot1, rot3, rot4, rot6, rot7;
98- double combo00, combo01, combo02, combo03, combo10, combo11, combo12, combo13, combo20, combo21, combo22, combo23;
99- double combo02_2, combo02_5, combo02_8, combo02_11;
100- double combo22_2, combo22_5, combo22_8, combo22_11;
101- double combo12_2, combo12_5, combo12_8, combo12_11;
102- // vertex展開
103- final double VX00, VX01, VX02, VX10, VX11, VX12, VX20, VX21, VX22, VX30, VX31, VX32;
104- NyARDoublePoint3d d_pt;
105- d_pt = i_vertex3d[0];
106- VX00 = d_pt.x;
107- VX01 = d_pt.y;
108- VX02 = d_pt.z;
109- d_pt = i_vertex3d[1];
110- VX10 = d_pt.x;
111- VX11 = d_pt.y;
112- VX12 = d_pt.z;
113- d_pt = i_vertex3d[2];
114- VX20 = d_pt.x;
115- VX21 = d_pt.y;
116- VX22 = d_pt.z;
117- d_pt = i_vertex3d[3];
118- VX30 = d_pt.x;
119- VX31 = d_pt.y;
120- VX32 = d_pt.z;
121- final double P2D00, P2D01, P2D10, P2D11, P2D20, P2D21, P2D30, P2D31;
122- NyARDoublePoint2d d_pt2;
123- d_pt2 = i_vertex2d[0];
124- P2D00 = d_pt2.x;
125- P2D01 = d_pt2.y;
126- d_pt2 = i_vertex2d[1];
127- P2D10 = d_pt2.x;
128- P2D11 = d_pt2.y;
129- d_pt2 = i_vertex2d[2];
130- P2D20 = d_pt2.x;
131- P2D21 = d_pt2.y;
132- d_pt2 = i_vertex2d[3];
133- P2D30 = d_pt2.x;
134- P2D31 = d_pt2.y;
135- final NyARPerspectiveProjectionMatrix prjmat = this._projection_mat_ref;
136- final double CP0, CP1, CP2, CP4, CP5, CP6, CP8, CP9, CP10;
137- CP0 = prjmat.m00;
138- CP1 = prjmat.m01;
139- CP2 = prjmat.m02;
140- CP4 = prjmat.m10;
141- CP5 = prjmat.m11;
142- CP6 = prjmat.m12;
143- CP8 = prjmat.m20;
144- CP9 = prjmat.m21;
145- CP10 = prjmat.m22;
146- combo03 = CP0 * trans.x + CP1 * trans.y + CP2 * trans.z + prjmat.m03;
147- combo13 = CP4 * trans.x + CP5 * trans.y + CP6 * trans.z + prjmat.m13;
148- combo23 = CP8 * trans.x + CP9 * trans.y + CP10 * trans.z + prjmat.m23;
149- double CACA, SASA, SACA, CA, SA;
150- double CACACB, SACACB, SASACB, CASB, SASB;
151- double SACASC, SACACBSC, SACACBCC, SACACC;
152- final double[][] double1D = this.__modifyMatrix_double1D;
153-
154-
155- final double[] a_factor = double1D[1];
156- final double[] sinb = double1D[2];
157- final double[] cosb = double1D[3];
158- final double[] b_factor = double1D[4];
159- final double[] sinc = double1D[5];
160- final double[] cosc = double1D[6];
161- final double[] c_factor = double1D[7];
162- double w, w2;
163- double wsin, wcos;
164-
165- //現在の角度を確保
166- final NyARDoublePoint3d angle = io_rot.refAngle();
167- a2 = angle.x;
168- b2 = angle.y;
169- c2 = angle.z;
170-
171- // comboの3行目を先に計算
172- for (int i = 0; i < 10; i++) {
173- minerr = 1000000000.0;
174- // sin-cosテーブルを計算(これが外に出せるとは…。)
175- for (int j = 0; j < 3; j++) {
176- w2 = factor * (j - 1);
177- w = a2 + w2;
178- a_factor[j] = w;
179- w = b2 + w2;
180- b_factor[j] = w;
181- sinb[j] = Math.sin(w);
182- cosb[j] = Math.cos(w);
183- w = c2 + w2;
184- c_factor[j] = w;
185- sinc[j] = Math.sin(w);
186- cosc[j] = Math.cos(w);
187- }
188- //
189- for (t1 = 0; t1 < 3; t1++) {
190- SA = Math.sin(a_factor[t1]);
191- CA = Math.cos(a_factor[t1]);
192- // Optimize
193- CACA = CA * CA;
194- SASA = SA * SA;
195- SACA = SA * CA;
196- for (t2 = 0; t2 < 3; t2++) {
197- wsin = sinb[t2];
198- wcos = cosb[t2];
199- CACACB = CACA * wcos;
200- SACACB = SACA * wcos;
201- SASACB = SASA * wcos;
202- CASB = CA * wsin;
203- SASB = SA * wsin;
204- // comboの計算1
205- combo02 = CP0 * CASB + CP1 * SASB + CP2 * wcos;
206- combo12 = CP4 * CASB + CP5 * SASB + CP6 * wcos;
207- combo22 = CP8 * CASB + CP9 * SASB + CP10 * wcos;
208-
209- combo02_2 = combo02 * VX02 + combo03;
210- combo02_5 = combo02 * VX12 + combo03;
211- combo02_8 = combo02 * VX22 + combo03;
212- combo02_11 = combo02 * VX32 + combo03;
213- combo12_2 = combo12 * VX02 + combo13;
214- combo12_5 = combo12 * VX12 + combo13;
215- combo12_8 = combo12 * VX22 + combo13;
216- combo12_11 = combo12 * VX32 + combo13;
217- combo22_2 = combo22 * VX02 + combo23;
218- combo22_5 = combo22 * VX12 + combo23;
219- combo22_8 = combo22 * VX22 + combo23;
220- combo22_11 = combo22 * VX32 + combo23;
221- for (t3 = 0; t3 < 3; t3++) {
222- wsin = sinc[t3];
223- wcos = cosc[t3];
224- SACASC = SACA * wsin;
225- SACACC = SACA * wcos;
226- SACACBSC = SACACB * wsin;
227- SACACBCC = SACACB * wcos;
228-
229- rot0 = CACACB * wcos + SASA * wcos + SACACBSC - SACASC;
230- rot3 = SACACBCC - SACACC + SASACB * wsin + CACA * wsin;
231- rot6 = -CASB * wcos - SASB * wsin;
232-
233- combo00 = CP0 * rot0 + CP1 * rot3 + CP2 * rot6;
234- combo10 = CP4 * rot0 + CP5 * rot3 + CP6 * rot6;
235- combo20 = CP8 * rot0 + CP9 * rot3 + CP10 * rot6;
236-
237- rot1 = -CACACB * wsin - SASA * wsin + SACACBCC - SACACC;
238- rot4 = -SACACBSC + SACASC + SASACB * wcos + CACA * wcos;
239- rot7 = CASB * wsin - SASB * wcos;
240- combo01 = CP0 * rot1 + CP1 * rot4 + CP2 * rot7;
241- combo11 = CP4 * rot1 + CP5 * rot4 + CP6 * rot7;
242- combo21 = CP8 * rot1 + CP9 * rot4 + CP10 * rot7;
243- //
244- err = 0.0;
245- h = combo20 * VX00 + combo21 * VX01 + combo22_2;
246- x = P2D00 - (combo00 * VX00 + combo01 * VX01 + combo02_2) / h;
247- y = P2D01 - (combo10 * VX00 + combo11 * VX01 + combo12_2) / h;
248- err += x * x + y * y;
249- h = combo20 * VX10 + combo21 * VX11 + combo22_5;
250- x = P2D10 - (combo00 * VX10 + combo01 * VX11 + combo02_5) / h;
251- y = P2D11 - (combo10 * VX10 + combo11 * VX11 + combo12_5) / h;
252- err += x * x + y * y;
253- h = combo20 * VX20 + combo21 * VX21 + combo22_8;
254- x = P2D20 - (combo00 * VX20 + combo01 * VX21 + combo02_8) / h;
255- y = P2D21 - (combo10 * VX20 + combo11 * VX21 + combo12_8) / h;
256- err += x * x + y * y;
257- h = combo20 * VX30 + combo21 * VX31 + combo22_11;
258- x = P2D30 - (combo00 * VX30 + combo01 * VX31 + combo02_11) / h;
259- y = P2D31 - (combo10 * VX30 + combo11 * VX31 + combo12_11) / h;
260- err += x * x + y * y;
261- if (err < minerr) {
262- minerr = err;
263- ma = a_factor[t1];
264- mb = b_factor[t2];
265- mc = c_factor[t3];
266- s1 = t1 - 1;
267- s2 = t2 - 1;
268- s3 = t3 - 1;
269- }
270- }
271- }
272- }
273- if (s1 == 0 && s2 == 0 && s3 == 0) {
274- factor *= 0.5;
275- }
276- a2 = ma;
277- b2 = mb;
278- c2 = mc;
279- }
280- io_rot.setAngle(ma, mb, mc);
281- /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
282- return minerr / 4;
283- }
284-
285-
286-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_O2.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_O2.java (nonexistent)
@@ -1,236 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;
32-
33-
34-import jp.nyatla.nyartoolkit.NyARException;
35-import jp.nyatla.nyartoolkit.core.param.*;
36-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
37-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
38-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
39-/**
40- * 基本姿勢と実画像を一致するように、角度を微調整→平行移動量を再計算
41- * を繰り返して、変換行列を最適化する。
42- *
43- */
44-public class NyARRotMatrixOptimize_O2 implements INyARRotMatrixOptimize
45-{
46- private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
47- public NyARRotMatrixOptimize_O2(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
48- {
49- this._projection_mat_ref=i_projection_mat_ref;
50- return;
51- }
52- private final double[][] __modifyMatrix_double1D = new double[8][3];
53- /**
54- * arGetRot計算を階層化したModifyMatrix 896
55- *
56- * @param trans
57- * @param i_vertex3d
58- * [m][3]
59- * @param i_vertex2d
60- * [n][2]
61- * @return
62- * @throws NyARException
63- */
64- public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot,NyARDoublePoint3d trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException
65- {
66- double factor;
67- double a2, b2, c2;
68- double h, x, y;
69- double err, minerr = 0;
70- int t1, t2, t3;
71- int best_idx=0;
72-
73- factor = 10.0 * Math.PI / 180.0;
74- double rot0, rot1, rot2;
75- double combo00, combo01, combo02, combo03, combo10, combo11, combo12, combo13, combo20, combo21, combo22, combo23;
76- double combo02_2, combo02_5, combo02_8, combo02_11;
77- double combo22_2, combo22_5, combo22_8, combo22_11;
78- double combo12_2, combo12_5, combo12_8, combo12_11;
79- // vertex展開
80- final double VX00, VX01, VX02, VX10, VX11, VX12, VX20, VX21, VX22, VX30, VX31, VX32;
81- VX00 = i_vertex3d[0].x;
82- VX01 = i_vertex3d[0].y;
83- VX02 = i_vertex3d[0].z;
84- VX10 = i_vertex3d[1].x;
85- VX11 = i_vertex3d[1].y;
86- VX12 = i_vertex3d[1].z;
87- VX20 = i_vertex3d[2].x;
88- VX21 = i_vertex3d[2].y;
89- VX22 = i_vertex3d[2].z;
90- VX30 = i_vertex3d[3].x;
91- VX31 = i_vertex3d[3].y;
92- VX32 = i_vertex3d[3].z;
93- final double P2D00, P2D01, P2D10, P2D11, P2D20, P2D21, P2D30, P2D31;
94- P2D00 = i_vertex2d[0].x;
95- P2D01 = i_vertex2d[0].y;
96- P2D10 = i_vertex2d[1].x;
97- P2D11 = i_vertex2d[1].y;
98- P2D20 = i_vertex2d[2].x;
99- P2D21 = i_vertex2d[2].y;
100- P2D30 = i_vertex2d[3].x;
101- P2D31 = i_vertex2d[3].y;
102- final NyARPerspectiveProjectionMatrix prjmat = this._projection_mat_ref;
103- final double CP0 = prjmat.m00,CP1 = prjmat.m01,CP2 = prjmat.m02,CP4 = prjmat.m10,CP5 = prjmat.m11,CP6 = prjmat.m12,CP8 = prjmat.m20,CP9 = prjmat.m21,CP10 = prjmat.m22;
104- combo03 = CP0 * trans.x + CP1 * trans.y + CP2 * trans.z + prjmat.m03;
105- combo13 = CP4 * trans.x + CP5 * trans.y + CP6 * trans.z + prjmat.m13;
106- combo23 = CP8 * trans.x + CP9 * trans.y + CP10 * trans.z + prjmat.m23;
107- double CACA, SASA, SACA, CA, SA;
108- double CACACB, SACACB, SASACB, CASB, SASB;
109- double SACASC, SACACBSC, SACACBCC, SACACC;
110- final double[][] double1D = this.__modifyMatrix_double1D;
111-
112- final double[] a_factor = double1D[1];
113- final double[] sinb = double1D[2];
114- final double[] cosb = double1D[3];
115- final double[] b_factor = double1D[4];
116- final double[] sinc = double1D[5];
117- final double[] cosc = double1D[6];
118- final double[] c_factor = double1D[7];
119- double w, w2;
120- double wsin, wcos;
121-
122- final NyARDoublePoint3d angle = io_rot.refAngle();
123- a2 = angle.x;
124- b2 = angle.y;
125- c2 = angle.z;
126-
127- // comboの3行目を先に計算
128- for (int i = 0; i < 10; i++) {
129- minerr = 1000000000.0;
130- // sin-cosテーブルを計算(これが外に出せるとは…。)
131- for (int j = 0; j < 3; j++) {
132- w2 = factor * (j - 1);
133- w = a2 + w2;
134- a_factor[j] = w;
135- w = b2 + w2;
136- b_factor[j] = w;
137- sinb[j] = Math.sin(w);
138- cosb[j] = Math.cos(w);
139- w = c2 + w2;
140- c_factor[j] = w;
141- sinc[j] = Math.sin(w);
142- cosc[j] = Math.cos(w);
143- }
144- //
145- for (t1 = 0; t1 < 3; t1++) {
146- SA = Math.sin(a_factor[t1]);
147- CA = Math.cos(a_factor[t1]);
148- // Optimize
149- CACA = CA * CA;
150- SASA = SA * SA;
151- SACA = SA * CA;
152- for (t2 = 0; t2 < 3; t2++) {
153- wsin = sinb[t2];
154- wcos = cosb[t2];
155- CACACB = CACA * wcos;
156- SACACB = SACA * wcos;
157- SASACB = SASA * wcos;
158- CASB = CA * wsin;
159- SASB = SA * wsin;
160- // comboの計算1
161- combo02 = CP0 * CASB + CP1 * SASB + CP2 * wcos;
162- combo12 = CP4 * CASB + CP5 * SASB + CP6 * wcos;
163- combo22 = CP8 * CASB + CP9 * SASB + CP10 * wcos;
164-
165- combo02_2 = combo02 * VX02 + combo03;
166- combo02_5 = combo02 * VX12 + combo03;
167- combo02_8 = combo02 * VX22 + combo03;
168- combo02_11 = combo02 * VX32 + combo03;
169- combo12_2 = combo12 * VX02 + combo13;
170- combo12_5 = combo12 * VX12 + combo13;
171- combo12_8 = combo12 * VX22 + combo13;
172- combo12_11 = combo12 * VX32 + combo13;
173- combo22_2 = combo22 * VX02 + combo23;
174- combo22_5 = combo22 * VX12 + combo23;
175- combo22_8 = combo22 * VX22 + combo23;
176- combo22_11 = combo22 * VX32 + combo23;
177- for (t3 = 0; t3 < 3; t3++) {
178- wsin = sinc[t3];
179- wcos = cosc[t3];
180- SACASC = SACA * wsin;
181- SACACC = SACA * wcos;
182- SACACBSC = SACACB * wsin;
183- SACACBCC = SACACB * wcos;
184-
185- rot0 = CACACB * wcos + SASA * wcos + SACACBSC - SACASC;
186- rot1 = SACACBCC - SACACC + SASACB * wsin + CACA * wsin;
187- rot2 = -CASB * wcos - SASB * wsin;
188- combo00 = CP0 * rot0 + CP1 * rot1 + CP2 * rot2;
189- combo10 = CP4 * rot0 + CP5 * rot1 + CP6 * rot2;
190- combo20 = CP8 * rot0 + CP9 * rot1 + CP10 * rot2;
191-
192- rot0 = -CACACB * wsin - SASA * wsin + SACACBCC - SACACC;
193- rot1 = -SACACBSC + SACASC + SASACB * wcos + CACA * wcos;
194- rot2 = CASB * wsin - SASB * wcos;
195- combo01 = CP0 * rot0 + CP1 * rot1 + CP2 * rot2;
196- combo11 = CP4 * rot0 + CP5 * rot1 + CP6 * rot2;
197- combo21 = CP8 * rot0 + CP9 * rot1 + CP10 * rot2;
198- //
199- err = 0.0;
200- h = combo20 * VX00 + combo21 * VX01 + combo22_2;
201- x = P2D00 - (combo00 * VX00 + combo01 * VX01 + combo02_2) / h;
202- y = P2D01 - (combo10 * VX00 + combo11 * VX01 + combo12_2) / h;
203- err += x * x + y * y;
204- h = combo20 * VX10 + combo21 * VX11 + combo22_5;
205- x = P2D10 - (combo00 * VX10 + combo01 * VX11 + combo02_5) / h;
206- y = P2D11 - (combo10 * VX10 + combo11 * VX11 + combo12_5) / h;
207- err += x * x + y * y;
208- h = combo20 * VX20 + combo21 * VX21 + combo22_8;
209- x = P2D20 - (combo00 * VX20 + combo01 * VX21 + combo02_8) / h;
210- y = P2D21 - (combo10 * VX20 + combo11 * VX21 + combo12_8) / h;
211- err += x * x + y * y;
212- h = combo20 * VX30 + combo21 * VX31 + combo22_11;
213- x = P2D30 - (combo00 * VX30 + combo01 * VX31 + combo02_11) / h;
214- y = P2D31 - (combo10 * VX30 + combo11 * VX31 + combo12_11) / h;
215- err += x * x + y * y;
216- if (err < minerr) {
217- minerr = err;
218- a2 = a_factor[t1];
219- b2 = b_factor[t2];
220- c2 = c_factor[t3];
221- best_idx=t1+t2*3+t3*9;
222- }
223- }
224- }
225- }
226- if (best_idx==(1+3+9)) {
227- factor *= 0.5;
228- }
229- }
230- io_rot.setAngle(a2, b2, c2);
231- /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
232- return minerr /4;
233- }
234-
235-
236-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/INyARRotMatrixOptimize.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/INyARRotMatrixOptimize.java (nonexistent)
@@ -1,55 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
35-import jp.nyatla.nyartoolkit.core.types.*;
36-
37-public interface INyARRotMatrixOptimize
38-{
39- /**
40- * @param io_rot
41- * 初期回転行列
42- * @param i_trans
43- * 初期並進ベクトル
44- * @param i_vertex3d
45- * 初期3次元座標
46- * @param i_vertex2d
47- * 画面上の頂点群
48- * @return
49- * エラーレート
50- * @throws NyARException
51- */
52-// public double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException;
53- public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException;
54-
55-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_Base.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/artoolkit/NyARRotMatrixOptimize_Base.java (nonexistent)
@@ -1,194 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.param.*;
35-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
36-import jp.nyatla.nyartoolkit.core.types.matrix.*;
37-import jp.nyatla.nyartoolkit.core.types.*;
38-
39-/**
40- * 処理構造がわかる程度に展開したNyARRotTransOptimize
41- *
42- */
43-public class NyARRotMatrixOptimize_Base implements INyARRotMatrixOptimize
44-{
45- private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
46-
47- public NyARRotMatrixOptimize_Base(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
48- {
49- this._projection_mat_ref = i_projection_mat_ref;
50- return;
51- }
52- private double[] __createRotationMap_b_map=new double[6];
53- private double[] __createRotationMap_c_map=new double[6];
54- private double[] __createRotationMap_f=new double[3];
55- private void createRotationMap(NyARDoublePoint3d i_angle,double i_factor,NyARDoubleMatrix33[] i_rot_matrix)
56- {
57- double sina,cosa,sinb,cosb,sinc,cosc;
58- double CACA,SASA,SACA,SASB,CASB,SACACB,CACACB,SASACB;
59-
60-
61- final double[] f=this.__createRotationMap_f;
62- final double[] b_map=this.__createRotationMap_b_map;
63- final double[] c_map=this.__createRotationMap_c_map;
64- f[0]=-i_factor;
65- f[1]=0;
66- f[2]=i_factor;
67- double ang1,ang2;
68- //BとCのsinマップを先に作成
69- for(int i=0;i<3;i++)
70- {
71- ang1=i_angle.y + f[i];
72- b_map[i] =Math.sin(ang1);
73- b_map[i+3]=Math.cos(ang1);
74- ang2=i_angle.z + f[i];
75- c_map[i] =Math.sin(ang2);
76- c_map[i+3]=Math.cos(ang2);
77- }
78- int idx=0;
79- int t1,t2,t3;
80- for (t1 = 0; t1 < 3; t1++){
81- ang1=i_angle.x + f[t1];
82- sina = Math.sin(ang1);
83- cosa = Math.cos(ang1);
84- CACA = cosa * cosa;
85- SASA = sina * sina;
86- SACA = sina * cosa;
87-
88- for (t2=0;t2<3;t2++){
89- sinb = b_map[t2];
90- cosb = b_map[t2+3];
91- SASB = sina * sinb;
92- CASB = cosa * sinb;
93- SACACB = SACA * cosb;
94- CACACB = CACA * cosb;
95- SASACB = SASA * cosb;
96- for (t3=0;t3<3;t3++) {
97- sinc = c_map[t3];
98- cosc = c_map[t3+3];
99- final NyARDoubleMatrix33 mat_ptr=i_rot_matrix[idx];
100- mat_ptr.m00 = CACACB * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
101- mat_ptr.m01 = -CACACB * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
102- mat_ptr.m02 = CASB;
103- mat_ptr.m10 = SACACB * cosc - SACA * cosc + SASACB * sinc + CACA * sinc;
104- mat_ptr.m11 = -SACACB * sinc + SACA * sinc + SASACB * cosc + CACA * cosc;
105- mat_ptr.m12 = SASB;
106- mat_ptr.m20 = -CASB * cosc - SASB * sinc;
107- mat_ptr.m21 = CASB * sinc - SASB * cosc;
108- mat_ptr.m22 = cosb;
109- idx++;
110- }
111- }
112- }
113- return;
114- }
115- private final void getNewMatrix(NyARDoubleMatrix33 i_rot, NyARDoublePoint3d i_trans, NyARDoubleMatrix34 o_combo)
116- {
117- double cp0,cp1,cp2,cp3;
118- NyARPerspectiveProjectionMatrix cp=this._projection_mat_ref;
119-
120- cp3=cp.m03;
121- cp0=cp.m00;cp1=cp.m01;cp2=cp.m02;
122- o_combo.m00=cp0 * i_rot.m00 + cp1 * i_rot.m10 + cp2 * i_rot.m20;
123- o_combo.m01=cp0 * i_rot.m01 + cp1 * i_rot.m11 + cp2 * i_rot.m21;
124- o_combo.m02=cp0 * i_rot.m02 + cp1 * i_rot.m12 + cp2 * i_rot.m22;
125- o_combo.m03=cp0 * i_trans.x + cp1 * i_trans.y + cp2 * i_trans.z +cp3;
126-
127- cp0=cp.m10;cp1=cp.m11;cp2=cp.m12;
128- o_combo.m10=cp0 * i_rot.m00 + cp1 * i_rot.m10 + cp2 * i_rot.m20;
129- o_combo.m11=cp0 * i_rot.m01 + cp1 * i_rot.m11 + cp2 * i_rot.m21;
130- o_combo.m12=cp0 * i_rot.m02 + cp1 * i_rot.m12 + cp2 * i_rot.m22;
131- o_combo.m13=cp0 * i_trans.x + cp1 * i_trans.y + cp2 * i_trans.z +cp3;
132-
133- cp0=cp.m20;cp1=cp.m21;cp2=cp.m22;
134- o_combo.m20=cp0 * i_rot.m00 + cp1 * i_rot.m10 + cp2 * i_rot.m20;
135- o_combo.m21=cp0 * i_rot.m01 + cp1 * i_rot.m11 + cp2 * i_rot.m21;
136- o_combo.m22=cp0 * i_rot.m02 + cp1 * i_rot.m12 + cp2 * i_rot.m22;
137- o_combo.m23=cp0 * i_trans.x + cp1 * i_trans.y + cp2 * i_trans.z +cp3;
138- return;
139- }
140- private final NyARDoublePoint3d __modifyMatrix_angle = new NyARDoublePoint3d();
141- private final NyARDoubleMatrix34 __modifyMatrix_combo=new NyARDoubleMatrix34();
142- private final NyARDoubleMatrix33[] __modifyMatrix_next_rot_matrix=NyARDoubleMatrix33.createArray(27);
143- public double modifyMatrix(NyARRotMatrix_ARToolKit io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d) throws NyARException
144- {
145- final NyARDoublePoint3d angle = this.__modifyMatrix_angle;
146- final NyARDoubleMatrix34 combo=this.__modifyMatrix_combo;
147- final NyARDoubleMatrix33[] next_rot_matrix=this.__modifyMatrix_next_rot_matrix;
148- double factor;
149- double hx, hy, h, x, y;
150- double err, minerr = 0;
151- int i,i2;
152- int best_idx=0;
153- angle.setValue(io_rot.refAngle());// arGetAngle( rot, &a, &b, &c );
154- factor = 10.0 * Math.PI / 180.0;
155- for (int j = 0; j < 10; j++){
156- minerr = 1000000000.0;
157- //評価用の角度マップ作成
158- createRotationMap(angle,factor,next_rot_matrix);
159- //評価して一番宜しいIDを保存
160- best_idx=(1+1*3+1*9);
161- for(i2=0;i2<27;i2++){
162- this.getNewMatrix(next_rot_matrix[i2],i_trans,combo);
163- err = 0.0;
164- for (i = 0; i < 4; i++) {
165- hx = combo.m00 * i_vertex3d[i].x + combo.m01 * i_vertex3d[i].y + combo.m02 * i_vertex3d[i].z + combo.m03;
166- hy = combo.m10 * i_vertex3d[i].x + combo.m11 *i_vertex3d[i].y + combo.m12 * i_vertex3d[i].z + combo.m13;
167- h = combo.m20 * i_vertex3d[i].x + combo.m21 * i_vertex3d[i].y + combo.m22 * i_vertex3d[i].z + combo.m23;
168- x = i_vertex2d[i].x-(hx / h);
169- y = i_vertex2d[i].y-(hy / h);
170- err += x*x+y*y;
171- }
172- if (err < minerr){
173- minerr = err;
174- best_idx=i2;
175- }
176-
177- }
178- if (best_idx==(1+1*3+1*9)){
179- factor *= 0.5;
180- }else{
181- angle.z+=factor*(best_idx%3-1);
182- angle.y+=factor*((best_idx/3)%3-1);
183- angle.x+=factor*((best_idx/9)%3-1);
184- }
185- }
186- io_rot.setAngle(angle.x,angle.y,angle.z);
187- /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */
188- return minerr / 4;
189- }
190-
191-
192-
193-
194-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARPartialDifferentiationOptimize.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/optimize/NyARPartialDifferentiationOptimize.java (nonexistent)
@@ -1,388 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit (Extension)
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.optimize;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.param.*;
35-
36-import jp.nyatla.nyartoolkit.core.types.*;
37-import jp.nyatla.nyartoolkit.core.types.matrix.*;
38-import jp.nyatla.nyartoolkit.core.utils.*;
39-
40-class TSinCosValue{
41- public double cos_val;
42- public double sin_val;
43- public static TSinCosValue[] createArray(int i_size)
44- {
45- TSinCosValue[] result=new TSinCosValue[i_size];
46- for(int i=0;i<i_size;i++){
47- result[i]=new TSinCosValue();
48- }
49- return result;
50- }
51-}
52-
53-/**
54- * 基本姿勢と実画像を一致するように、角度を微調整→平行移動量を再計算 を繰り返して、変換行列を最適化する。
55- *
56- */
57-public class NyARPartialDifferentiationOptimize
58-{
59- private final NyARPerspectiveProjectionMatrix _projection_mat_ref;
60-
61- public NyARPartialDifferentiationOptimize(NyARPerspectiveProjectionMatrix i_projection_mat_ref)
62- {
63- this._projection_mat_ref = i_projection_mat_ref;
64- return;
65- }
66-
67- public final void sincos2Rotation_ZXY(TSinCosValue[] i_sincos, NyARDoubleMatrix33 i_rot_matrix)
68- {
69- final double sina = i_sincos[0].sin_val;
70- final double cosa = i_sincos[0].cos_val;
71- final double sinb = i_sincos[1].sin_val;
72- final double cosb = i_sincos[1].cos_val;
73- final double sinc = i_sincos[2].sin_val;
74- final double cosc = i_sincos[2].cos_val;
75- i_rot_matrix.m00 = cosc * cosb - sinc * sina * sinb;
76- i_rot_matrix.m01 = -sinc * cosa;
77- i_rot_matrix.m02 = cosc * sinb + sinc * sina * cosb;
78- i_rot_matrix.m10 = sinc * cosb + cosc * sina * sinb;
79- i_rot_matrix.m11 = cosc * cosa;
80- i_rot_matrix.m12 = sinc * sinb - cosc * sina * cosb;
81- i_rot_matrix.m20 = -cosa * sinb;
82- i_rot_matrix.m21 = sina;
83- i_rot_matrix.m22 = cosb * cosa;
84- }
85-
86- private final void rotation2Sincos_ZXY(NyARDoubleMatrix33 i_rot_matrix, TSinCosValue[] o_out,NyARDoublePoint3d o_ang)
87- {
88- double x, y, z;
89- double sina = i_rot_matrix.m21;
90- if (sina >= 1.0) {
91- x = Math.PI / 2;
92- y = 0;
93- z = Math.atan2(-i_rot_matrix.m10, i_rot_matrix.m00);
94- } else if (sina <= -1.0) {
95- x = -Math.PI / 2;
96- y = 0;
97- z = Math.atan2(-i_rot_matrix.m10, i_rot_matrix.m00);
98- } else {
99- x = Math.asin(sina);
100- y = Math.atan2(-i_rot_matrix.m20, i_rot_matrix.m22);
101- z = Math.atan2(-i_rot_matrix.m01, i_rot_matrix.m11);
102- }
103- o_ang.x=x;
104- o_ang.y=y;
105- o_ang.z=z;
106- o_out[0].sin_val = Math.sin(x);
107- o_out[0].cos_val = Math.cos(x);
108- o_out[1].sin_val = Math.sin(y);
109- o_out[1].cos_val = Math.cos(y);
110- o_out[2].sin_val = Math.sin(z);
111- o_out[2].cos_val = Math.cos(z);
112- return;
113- }
114-
115- /*
116- * 射影変換式 基本式 ox=(cosc * cosb - sinc * sina * sinb)*ix+(-sinc * cosa)*iy+(cosc * sinb + sinc * sina * cosb)*iz+i_trans.x; oy=(sinc * cosb + cosc * sina *
117- * sinb)*ix+(cosc * cosa)*iy+(sinc * sinb - cosc * sina * cosb)*iz+i_trans.y; oz=(-cosa * sinb)*ix+(sina)*iy+(cosb * cosa)*iz+i_trans.z;
118- *
119- * double ox=(cosc * cosb)*ix+(-sinc * sina * sinb)*ix+(-sinc * cosa)*iy+(cosc * sinb)*iz + (sinc * sina * cosb)*iz+i_trans.x; double oy=(sinc * cosb)*ix
120- * +(cosc * sina * sinb)*ix+(cosc * cosa)*iy+(sinc * sinb)*iz+(- cosc * sina * cosb)*iz+i_trans.y; double oz=(-cosa * sinb)*ix+(sina)*iy+(cosb *
121- * cosa)*iz+i_trans.z;
122- *
123- * sina,cosaについて解く cx=(cp00*(-sinc*sinb*ix+sinc*cosb*iz)+cp01*(cosc*sinb*ix-cosc*cosb*iz)+cp02*(iy))*sina
124- * +(cp00*(-sinc*iy)+cp01*((cosc*iy))+cp02*(-sinb*ix+cosb*iz))*cosa
125- * +(cp00*(i_trans.x+cosc*cosb*ix+cosc*sinb*iz)+cp01*((i_trans.y+sinc*cosb*ix+sinc*sinb*iz))+cp02*(i_trans.z));
126- * cy=(cp11*(cosc*sinb*ix-cosc*cosb*iz)+cp12*(iy))*sina +(cp11*((cosc*iy))+cp12*(-sinb*ix+cosb*iz))*cosa
127- * +(cp11*((i_trans.y+sinc*cosb*ix+sinc*sinb*iz))+cp12*(i_trans.z)); ch=(iy)*sina +(-sinb*ix+cosb*iz)*cosa +i_trans.z; sinb,cosb hx=(cp00*(-sinc *
128- * sina*ix+cosc*iz)+cp01*(cosc * sina*ix+sinc*iz)+cp02*(-cosa*ix))*sinb +(cp01*(sinc*ix-cosc * sina*iz)+cp00*(cosc*ix+sinc * sina*iz)+cp02*(cosa*iz))*cosb
129- * +(cp00*(i_trans.x+(-sinc*cosa)*iy)+cp01*(i_trans.y+(cosc * cosa)*iy)+cp02*(i_trans.z+(sina)*iy)); double hy=(cp11*(cosc *
130- * sina*ix+sinc*iz)+cp12*(-cosa*ix))*sinb +(cp11*(sinc*ix-cosc * sina*iz)+cp12*(cosa*iz))*cosb +(cp11*(i_trans.y+(cosc *
131- * cosa)*iy)+cp12*(i_trans.z+(sina)*iy)); double h =((-cosa*ix)*sinb +(cosa*iz)*cosb +i_trans.z+(sina)*iy); パラメータ返還式 L=2*Σ(d[n]*e[n]+a[n]*b[n])
132- * J=2*Σ(d[n]*f[n]+a[n]*c[n])/L K=2*Σ(-e[n]*f[n]+b[n]*c[n])/L M=Σ(-e[n]^2+d[n]^2-b[n]^2+a[n]^2)/L 偏微分式 +J*cos(x) +K*sin(x) -sin(x)^2 +cos(x)^2
133- * +2*M*cos(x)*sin(x)
134- */
135- private double optimizeParamX(TSinCosValue i_angle_y, TSinCosValue i_angle_z, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d, int i_number_of_vertex, double i_hint_angle) throws NyARException
136- {
137- NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;
138- final double sinb = i_angle_y.sin_val;
139- final double cosb = i_angle_y.cos_val;
140- final double sinc = i_angle_z.sin_val;
141- final double cosc = i_angle_z.cos_val;
142- double L, J, K, M, N, O;
143- L = J = K = M = N = O = 0;
144- for (int i = 0; i < i_number_of_vertex; i++) {
145- double ix, iy, iz;
146- ix = i_vertex3d[i].x;
147- iy = i_vertex3d[i].y;
148- iz = i_vertex3d[i].z;
149-
150- final double cp00 = cp.m00;
151- final double cp01 = cp.m01;
152- final double cp02 = cp.m02;
153- final double cp11 = cp.m11;
154- final double cp12 = cp.m12;
155-
156- double X0 = (cp00 * (-sinc * sinb * ix + sinc * cosb * iz) + cp01 * (cosc * sinb * ix - cosc * cosb * iz) + cp02 * (iy));
157- double X1 = (cp00 * (-sinc * iy) + cp01 * ((cosc * iy)) + cp02 * (-sinb * ix + cosb * iz));
158- double X2 = (cp00 * (i_trans.x + cosc * cosb * ix + cosc * sinb * iz) + cp01 * ((i_trans.y + sinc * cosb * ix + sinc * sinb * iz)) + cp02 * (i_trans.z));
159- double Y0 = (cp11 * (cosc * sinb * ix - cosc * cosb * iz) + cp12 * (iy));
160- double Y1 = (cp11 * ((cosc * iy)) + cp12 * (-sinb * ix + cosb * iz));
161- double Y2 = (cp11 * ((i_trans.y + sinc * cosb * ix + sinc * sinb * iz)) + cp12 * (i_trans.z));
162- double H0 = (iy);
163- double H1 = (-sinb * ix + cosb * iz);
164- double H2 = i_trans.z;
165-
166- double VX = i_vertex2d[i].x;
167- double VY = i_vertex2d[i].y;
168-
169- double a, b, c, d, e, f;
170- a = (VX * H0 - X0);
171- b = (VX * H1 - X1);
172- c = (VX * H2 - X2);
173- d = (VY * H0 - Y0);
174- e = (VY * H1 - Y1);
175- f = (VY * H2 - Y2);
176-
177- L += d * e + a * b;
178- N += d * d + a * a;
179- J += d * f + a * c;
180- M += e * e + b * b;
181- K += e * f + b * c;
182- O += f * f + c * c;
183-
184- }
185- L *=2;
186- J *=2;
187- K *=2;
188-
189- return getMinimumErrorAngleFromParam(L,J, K, M, N, O, i_hint_angle);
190-
191-
192- }
193-
194- private double optimizeParamY(TSinCosValue i_angle_x, TSinCosValue i_angle_z, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d, int i_number_of_vertex, double i_hint_angle) throws NyARException
195- {
196- NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;
197- final double sina = i_angle_x.sin_val;
198- final double cosa = i_angle_x.cos_val;
199- final double sinc = i_angle_z.sin_val;
200- final double cosc = i_angle_z.cos_val;
201- double L, J, K, M, N, O;
202- L = J = K = M = N = O = 0;
203- for (int i = 0; i < i_number_of_vertex; i++) {
204- double ix, iy, iz;
205- ix = i_vertex3d[i].x;
206- iy = i_vertex3d[i].y;
207- iz = i_vertex3d[i].z;
208-
209- final double cp00 = cp.m00;
210- final double cp01 = cp.m01;
211- final double cp02 = cp.m02;
212- final double cp11 = cp.m11;
213- final double cp12 = cp.m12;
214-
215- double X0 = (cp00 * (-sinc * sina * ix + cosc * iz) + cp01 * (cosc * sina * ix + sinc * iz) + cp02 * (-cosa * ix));
216- double X1 = (cp01 * (sinc * ix - cosc * sina * iz) + cp00 * (cosc * ix + sinc * sina * iz) + cp02 * (cosa * iz));
217- double X2 = (cp00 * (i_trans.x + (-sinc * cosa) * iy) + cp01 * (i_trans.y + (cosc * cosa) * iy) + cp02 * (i_trans.z + (sina) * iy));
218- double Y0 = (cp11 * (cosc * sina * ix + sinc * iz) + cp12 * (-cosa * ix));
219- double Y1 = (cp11 * (sinc * ix - cosc * sina * iz) + cp12 * (cosa * iz));
220- double Y2 = (cp11 * (i_trans.y + (cosc * cosa) * iy) + cp12 * (i_trans.z + (sina) * iy));
221- double H0 = (-cosa * ix);
222- double H1 = (cosa * iz);
223- double H2 = i_trans.z + (sina) * iy;
224-
225- double VX = i_vertex2d[i].x;
226- double VY = i_vertex2d[i].y;
227-
228- double a, b, c, d, e, f;
229- a = (VX * H0 - X0);
230- b = (VX * H1 - X1);
231- c = (VX * H2 - X2);
232- d = (VY * H0 - Y0);
233- e = (VY * H1 - Y1);
234- f = (VY * H2 - Y2);
235-
236- L += d * e + a * b;
237- N += d * d + a * a;
238- J += d * f + a * c;
239- M += e * e + b * b;
240- K += e * f + b * c;
241- O += f * f + c * c;
242-
243- }
244- L *= 2;
245- J *= 2;
246- K *= 2;
247- return getMinimumErrorAngleFromParam(L,J, K, M, N, O, i_hint_angle);
248-
249- }
250-
251- private double optimizeParamZ(TSinCosValue i_angle_x, TSinCosValue i_angle_y, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d, int i_number_of_vertex, double i_hint_angle) throws NyARException
252- {
253- NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;
254- final double sina = i_angle_x.sin_val;
255- final double cosa = i_angle_x.cos_val;
256- final double sinb = i_angle_y.sin_val;
257- final double cosb = i_angle_y.cos_val;
258- double L, J, K, M, N, O;
259- L = J = K = M = N = O = 0;
260- for (int i = 0; i < i_number_of_vertex; i++) {
261- double ix, iy, iz;
262- ix = i_vertex3d[i].x;
263- iy = i_vertex3d[i].y;
264- iz = i_vertex3d[i].z;
265-
266- final double cp00 = cp.m00;
267- final double cp01 = cp.m01;
268- final double cp02 = cp.m02;
269- final double cp11 = cp.m11;
270- final double cp12 = cp.m12;
271-
272- double X0 = (cp00 * (-sina * sinb * ix - cosa * iy + sina * cosb * iz) + cp01 * (ix * cosb + sinb * iz));
273- double X1 = (cp01 * (sina * ix * sinb + cosa * iy - sina * iz * cosb) + cp00 * (cosb * ix + sinb * iz));
274- double X2 = cp00 * i_trans.x + cp01 * (i_trans.y) + cp02 * (-cosa * sinb) * ix + cp02 * (sina) * iy + cp02 * ((cosb * cosa) * iz + i_trans.z);
275- double Y0 = cp11 * (ix * cosb + sinb * iz);
276- double Y1 = cp11 * (sina * ix * sinb + cosa * iy - sina * iz * cosb);
277- double Y2 = (cp11 * i_trans.y + cp12 * (-cosa * sinb) * ix + cp12 * ((sina) * iy + (cosb * cosa) * iz + i_trans.z));
278- double H0 = 0;
279- double H1 = 0;
280- double H2 = ((-cosa * sinb) * ix + (sina) * iy + (cosb * cosa) * iz + i_trans.z);
281-
282- double VX = i_vertex2d[i].x;
283- double VY = i_vertex2d[i].y;
284-
285- double a, b, c, d, e, f;
286- a = (VX * H0 - X0);
287- b = (VX * H1 - X1);
288- c = (VX * H2 - X2);
289- d = (VY * H0 - Y0);
290- e = (VY * H1 - Y1);
291- f = (VY * H2 - Y2);
292-
293- L += d * e + a * b;
294- N += d * d + a * a;
295- J += d * f + a * c;
296- M += e * e + b * b;
297- K += e * f + b * c;
298- O += f * f + c * c;
299-
300- }
301- L *=2;
302- J *=2;
303- K *=2;
304-
305- return getMinimumErrorAngleFromParam(L,J, K, M, N, O, i_hint_angle);
306- }
307- private TSinCosValue[] __angles_in=TSinCosValue.createArray(3);
308- private NyARDoublePoint3d __ang=new NyARDoublePoint3d();
309- public void modifyMatrix(NyARDoubleMatrix33 io_rot, NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d, int i_number_of_vertex) throws NyARException
310- {
311- TSinCosValue[] angles_in = this.__angles_in;// x,y,z
312- NyARDoublePoint3d ang = this.__ang;
313-
314- // ZXY系のsin/cos値を抽出
315- rotation2Sincos_ZXY(io_rot, angles_in,ang);
316- ang.x += optimizeParamX(angles_in[1], angles_in[2], i_trans, i_vertex3d, i_vertex2d, i_number_of_vertex, ang.x);
317- ang.y += optimizeParamY(angles_in[0], angles_in[2], i_trans, i_vertex3d, i_vertex2d, i_number_of_vertex, ang.y);
318- ang.z += optimizeParamZ(angles_in[0], angles_in[1], i_trans, i_vertex3d, i_vertex2d, i_number_of_vertex, ang.z);
319- io_rot.setZXYAngle(ang.x, ang.y, ang.z);
320- return;
321- }
322- private double[] __sin_table= new double[4];
323- /**
324- * エラーレートが最小になる点を得る。
325- */
326- private double getMinimumErrorAngleFromParam(double iL,double iJ, double iK, double iM, double iN, double iO, double i_hint_angle) throws NyARException
327- {
328- double[] sin_table = this.__sin_table;
329-
330- double M = (iN - iM)/iL;
331- double J = iJ/iL;
332- double K = -iK/iL;
333-
334- // パラメータからsinテーブルを作成
335- // (- 4*M^2-4)*x^4 + (4*K- 4*J*M)*x^3 + (4*M^2 -(K^2- 4)- J^2)*x^2 +(4*J*M- 2*K)*x + J^2-1 = 0
336- int number_of_sin = NyAREquationSolver.solve4Equation(-4 * M * M - 4, 4 * K - 4 * J * M, 4 * M * M - (K * K - 4) - J * J, 4 * J * M - 2 * K, J * J - 1, sin_table);
337-
338-
339- // 最小値2個を得ておく。
340- double min_ang_0 = Double.MAX_VALUE;
341- double min_ang_1 = Double.MAX_VALUE;
342- double min_err_0 = Double.MAX_VALUE;
343- double min_err_1 = Double.MAX_VALUE;
344- for (int i = 0; i < number_of_sin; i++) {
345- // +-cos_v[i]が頂点候補
346- double sin_rt = sin_table[i];
347- double cos_rt = Math.sqrt(1 - (sin_rt * sin_rt));
348- // cosを修復。微分式で0に近い方が正解
349- // 0 = 2*cos(x)*sin(x)*M - sin(x)^2 + cos(x)^2 + sin(x)*K + cos(x)*J
350- double a1 = 2 * cos_rt * sin_rt * M + sin_rt * (K - sin_rt) + cos_rt * (cos_rt + J);
351- double a2 = 2 * (-cos_rt) * sin_rt * M + sin_rt * (K - sin_rt) + (-cos_rt) * ((-cos_rt) + J);
352- // 絶対値になおして、真のcos値を得ておく。
353- a1 = a1 < 0 ? -a1 : a1;
354- a2 = a2 < 0 ? -a2 : a2;
355- cos_rt = (a1 < a2) ? cos_rt : -cos_rt;
356- double ang = Math.atan2(sin_rt, cos_rt);
357- // エラー値を計算
358- double err = iN * sin_rt * sin_rt + (iL*cos_rt + iJ) * sin_rt + iM * cos_rt * cos_rt + iK * cos_rt + iO;
359- // 最小の2個を獲得する。
360- if (min_err_0 > err) {
361- min_err_1 = min_err_0;
362- min_ang_1 = min_ang_0;
363- min_err_0 = err;
364- min_ang_0 = ang;
365- } else if (min_err_1 > err) {
366- min_err_1 = err;
367- min_ang_1 = ang;
368- }
369- }
370- // [0]をテスト
371- double gap_0;
372- gap_0 = min_ang_0 - i_hint_angle;
373- if (gap_0 > Math.PI) {
374- gap_0 = (min_ang_0 - Math.PI * 2) - i_hint_angle;
375- } else if (gap_0 < -Math.PI) {
376- gap_0 = (min_ang_0 + Math.PI * 2) - i_hint_angle;
377- }
378- // [1]をテスト
379- double gap_1;
380- gap_1 = min_ang_1 - i_hint_angle;
381- if (gap_1 > Math.PI) {
382- gap_1 = (min_ang_1 - Math.PI * 2) - i_hint_angle;
383- } else if (gap_1 < -Math.PI) {
384- gap_1 = (min_ang_1 + Math.PI * 2) - i_hint_angle;
385- }
386- return Math.abs(gap_1) < Math.abs(gap_0) ? gap_1 : gap_0;
387- }
388-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMatResult.java (nonexistent)
@@ -1,80 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat;
32-
33-
34-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
35-import jp.nyatla.nyartoolkit.core.types.matrix.*;
36-
37-/**
38- * NyARTransMat戻り値専用のNyARMat
39- *
40- */
41-public class NyARTransMatResult extends NyARDoubleMatrix34
42-{
43- /**
44- * エラーレート。この値はINyARTransMatの派生クラスが使います。
45- */
46- public double error;
47- public boolean has_value = false;
48- /**
49- * この関数は、0-PIの間で値を返します。
50- * @param o_out
51- */
52- public final void getZXYAngle(NyARDoublePoint3d o_out)
53- {
54- double sina = this.m21;
55- if (sina >= 1.0) {
56- o_out.x = Math.PI / 2;
57- o_out.y = 0;
58- o_out.z = Math.atan2(-this.m10, this.m00);
59- } else if (sina <= -1.0) {
60- o_out.x = -Math.PI / 2;
61- o_out.y = 0;
62- o_out.z = Math.atan2(-this.m10, this.m00);
63- } else {
64- o_out.x = Math.asin(sina);
65- o_out.z = Math.atan2(-this.m01, this.m11);
66- o_out.y = Math.atan2(-this.m20, this.m22);
67- }
68- }
69- public final void transformVertex(double i_x,double i_y,double i_z,NyARDoublePoint3d o_out)
70- {
71- o_out.x=this.m00*i_x+this.m01*i_y+this.m02*i_z+this.m03;
72- o_out.y=this.m10*i_x+this.m11*i_y+this.m12*i_z+this.m13;
73- o_out.z=this.m20*i_x+this.m21*i_y+this.m22*i_z+this.m23;
74- return;
75- }
76- public final void transformVertex(NyARDoublePoint3d i_in,NyARDoublePoint3d o_out)
77- {
78- transformVertex(i_in.x,i_in.y,i_in.z,o_out);
79- }
80-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat.java (nonexistent)
@@ -1,293 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit (Extension)
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.param.*;
35-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
36-import jp.nyatla.nyartoolkit.core.transmat.solver.*;
37-import jp.nyatla.nyartoolkit.core.transmat.optimize.*;
38-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
39-import jp.nyatla.nyartoolkit.core.types.*;
40-import jp.nyatla.nyartoolkit.core.types.matrix.*;
41-
42-/**
43- * This class calculates ARMatrix from square information and holds it. --
44- * 変換行列を計算して、結果を保持するクラス。
45- *
46- */
47-public class NyARTransMat implements INyARTransMat
48-{
49- private NyARPerspectiveProjectionMatrix _projection_mat_ref;
50- protected NyARRotMatrix _rotmatrix;
51- protected INyARTransportVectorSolver _transsolver;
52- protected NyARPartialDifferentiationOptimize _mat_optimize;
53-
54-
55- private NyARCameraDistortionFactor _ref_dist_factor;
56-
57- /**
58- * 派生クラスで自分でメンバオブジェクトを指定したい場合はこちらを使う。
59- *
60- */
61- protected NyARTransMat()
62- {
63- //_calculator,_rotmatrix,_mat_optimizeをコンストラクタの終了後に
64- //作成して割り当ててください。
65- return;
66- }
67- public NyARTransMat(NyARParam i_param) throws NyARException
68- {
69- final NyARCameraDistortionFactor dist=i_param.getDistortionFactor();
70- final NyARPerspectiveProjectionMatrix pmat=i_param.getPerspectiveProjectionMatrix();
71- this._transsolver=new NyARTransportVectorSolver(pmat,4);
72- //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。
73- //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。
74- this._rotmatrix = new NyARRotMatrix(pmat);
75- this._mat_optimize=new NyARPartialDifferentiationOptimize(pmat);
76- this._ref_dist_factor=dist;
77- this._projection_mat_ref=pmat;
78- }
79-
80- private final NyARDoublePoint2d[] __transMat_vertex_2d = NyARDoublePoint2d.createArray(4);
81- private final NyARDoublePoint3d[] __transMat_vertex_3d = NyARDoublePoint3d.createArray(4);
82- private final NyARDoublePoint3d __transMat_trans=new NyARDoublePoint3d();
83-
84- /**
85- * 頂点情報を元に、エラー閾値を計算します。
86- * @param i_vertex
87- */
88- private double makeErrThreshold(NyARDoublePoint2d[] i_vertex)
89- {
90- double a,b,l1,l2;
91- a=i_vertex[0].x-i_vertex[2].x;
92- b=i_vertex[0].y-i_vertex[2].y;
93- l1=a*a+b*b;
94- a=i_vertex[1].x-i_vertex[3].x;
95- b=i_vertex[1].y-i_vertex[3].y;
96- l2=a*a+b*b;
97- return (Math.sqrt(l1>l2?l1:l2))/200;
98- }
99-
100- /**
101- * double arGetTransMat( ARMarkerInfo *marker_info,double center[2], double width, double conv[3][4] )
102- *
103- * @param i_square
104- * 計算対象のNyARSquareオブジェクト
105- * @param i_direction
106- * @param i_width
107- * @return
108- * @throws NyARException
109- */
110- public void transMat(final NyARSquare i_square,NyARRectOffset i_offset, NyARTransMatResult o_result_conv) throws NyARException
111- {
112- final NyARDoublePoint3d trans=this.__transMat_trans;
113-
114- double err_threshold=makeErrThreshold(i_square.sqvertex);
115-
116- //平行移動量計算機に、2D座標系をセット
117- NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;
118- NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
119- this._ref_dist_factor.ideal2ObservBatch(i_square.sqvertex, vertex_2d,4);
120- this._transsolver.set2dVertex(vertex_2d,4);
121-
122- //回転行列を計算
123- this._rotmatrix.initRotBySquare(i_square.line,i_square.sqvertex);
124-
125- //回転後の3D座標系から、平行移動量を計算
126- this._rotmatrix.getPoint3dBatch(i_offset.vertex,vertex_3d,4);
127- this._transsolver.solveTransportVector(vertex_3d,trans);
128-
129- //計算結果の最適化(平行移動量と回転行列の最適化)
130- o_result_conv.error=this.optimize(this._rotmatrix, trans, this._transsolver,i_offset.vertex, vertex_2d,err_threshold);
131-
132- // マトリクスの保存
133- this.updateMatrixValue(this._rotmatrix, trans,o_result_conv);
134- return;
135- }
136-
137- /*
138- * (non-Javadoc)
139- * @see jp.nyatla.nyartoolkit.core.transmat.INyARTransMat#transMatContinue(jp.nyatla.nyartoolkit.core.NyARSquare, int, double, jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult)
140- */
141- public void transMatContinue(NyARSquare i_square,NyARRectOffset i_offset, NyARTransMatResult o_result_conv) throws NyARException
142- {
143- final NyARDoublePoint3d trans=this.__transMat_trans;
144-
145- // io_result_convが初期値なら、transMatで計算する。
146- if (!o_result_conv.has_value) {
147- this.transMat(i_square,i_offset, o_result_conv);
148- return;
149- }
150-
151- //最適化計算の閾値を決定
152- double err_threshold=makeErrThreshold(i_square.sqvertex);
153-
154-
155- //平行移動量計算機に、2D座標系をセット
156- NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;
157- NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
158- this._ref_dist_factor.ideal2ObservBatch(i_square.sqvertex, vertex_2d,4);
159- this._transsolver.set2dVertex(vertex_2d,4);
160-
161- //回転行列を計算
162- this._rotmatrix.initRotByPrevResult(o_result_conv);
163-
164- //回転後の3D座標系から、平行移動量を計算
165- this._rotmatrix.getPoint3dBatch(i_offset.vertex,vertex_3d,4);
166- this._transsolver.solveTransportVector(vertex_3d,trans);
167-
168- //現在のエラーレートを計算しておく
169- double min_err=errRate(this._rotmatrix,trans,i_offset.vertex, vertex_2d,4,vertex_3d);
170- NyARDoubleMatrix33 rot=this.__rot;
171- //エラーレートが前回のエラー値より閾値分大きかったらアゲイン
172- if(min_err<o_result_conv.error+err_threshold){
173- rot.setValue(this._rotmatrix);
174- //最適化してみる。
175- for (int i = 0;i<5; i++) {
176- //変換行列の最適化
177- this._mat_optimize.modifyMatrix(rot, trans, i_offset.vertex, vertex_2d, 4);
178- double err=errRate(rot,trans,i_offset.vertex, vertex_2d,4,vertex_3d);
179- //System.out.println("E:"+err);
180- if(min_err-err<err_threshold/2){
181- //System.out.println("BREAK");
182- break;
183- }
184- this._transsolver.solveTransportVector(vertex_3d, trans);
185- this._rotmatrix.setValue(rot);
186- min_err=err;
187- }
188- this.updateMatrixValue(this._rotmatrix, trans,o_result_conv);
189- }else{
190- //回転行列を計算
191- this._rotmatrix.initRotBySquare(i_square.line,i_square.sqvertex);
192-
193- //回転後の3D座標系から、平行移動量を計算
194- this._rotmatrix.getPoint3dBatch(i_offset.vertex,vertex_3d,4);
195- this._transsolver.solveTransportVector(vertex_3d,trans);
196-
197- //計算結果の最適化(平行移動量と回転行列の最適化)
198- min_err=this.optimize(this._rotmatrix, trans, this._transsolver,i_offset.vertex, vertex_2d,err_threshold);
199- this.updateMatrixValue(this._rotmatrix, trans,o_result_conv);
200- }
201- o_result_conv.error=min_err;
202- return;
203- }
204- private NyARDoubleMatrix33 __rot=new NyARDoubleMatrix33();
205- private double optimize(NyARRotMatrix io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex,double i_err_threshold) throws NyARException
206- {
207- //System.out.println("START");
208- NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
209- //初期のエラー値を計算
210- double min_err=errRate(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex,4,vertex_3d);
211- NyARDoubleMatrix33 rot=this.__rot;
212- rot.setValue(io_rotmat);
213- for (int i = 0;i<5; i++) {
214- //変換行列の最適化
215- this._mat_optimize.modifyMatrix(rot, io_transvec, i_offset_3d, i_2d_vertex, 4);
216- double err=errRate(rot,io_transvec, i_offset_3d, i_2d_vertex,4,vertex_3d);
217- //System.out.println("E:"+err);
218- if(min_err-err<i_err_threshold){
219- //System.out.println("BREAK");
220- break;
221- }
222- i_solver.solveTransportVector(vertex_3d, io_transvec);
223- io_rotmat.setValue(rot);
224- min_err=err;
225- }
226- //System.out.println("END");
227- return min_err;
228- }
229-
230- //エラーレート計算機
231- public double errRate(NyARDoubleMatrix33 io_rot,NyARDoublePoint3d i_trans, NyARDoublePoint3d[] i_vertex3d, NyARDoublePoint2d[] i_vertex2d,int i_number_of_vertex,NyARDoublePoint3d[] o_rot_vertex) throws NyARException
232- {
233- NyARPerspectiveProjectionMatrix cp = this._projection_mat_ref;
234- final double cp00=cp.m00;
235- final double cp01=cp.m01;
236- final double cp02=cp.m02;
237- final double cp11=cp.m11;
238- final double cp12=cp.m12;
239-
240- double err=0;
241- for(int i=0;i<i_number_of_vertex;i++){
242- double x3d,y3d,z3d;
243- o_rot_vertex[i].x=x3d=io_rot.m00*i_vertex3d[i].x+io_rot.m01*i_vertex3d[i].y+io_rot.m02*i_vertex3d[i].z;
244- o_rot_vertex[i].y=y3d=io_rot.m10*i_vertex3d[i].x+io_rot.m11*i_vertex3d[i].y+io_rot.m12*i_vertex3d[i].z;
245- o_rot_vertex[i].z=z3d=io_rot.m20*i_vertex3d[i].x+io_rot.m21*i_vertex3d[i].y+io_rot.m22*i_vertex3d[i].z;
246- x3d+=i_trans.x;
247- y3d+=i_trans.y;
248- z3d+=i_trans.z;
249-
250- //射影変換
251- double x2d=x3d*cp00+y3d*cp01+z3d*cp02;
252- double y2d=y3d*cp11+z3d*cp12;
253- double h2d=z3d;
254-
255- //エラーレート計算
256- double t1=i_vertex2d[i].x-x2d/h2d;
257- double t2=i_vertex2d[i].y-y2d/h2d;
258- err+=t1*t1+t2*t2;
259-
260- }
261- return err/i_number_of_vertex;
262- }
263-
264-
265-
266- /**
267- * パラメータで変換行列を更新します。
268- *
269- * @param i_rot
270- * @param i_off
271- * @param i_trans
272- */
273- public void updateMatrixValue(NyARRotMatrix i_rot, NyARDoublePoint3d i_trans,NyARTransMatResult o_result)
274- {
275- o_result.m00=i_rot.m00;
276- o_result.m01=i_rot.m01;
277- o_result.m02=i_rot.m02;
278- o_result.m03=i_trans.x;
279-
280- o_result.m10 =i_rot.m10;
281- o_result.m11 =i_rot.m11;
282- o_result.m12 =i_rot.m12;
283- o_result.m13 =i_trans.y;
284-
285- o_result.m20 = i_rot.m20;
286- o_result.m21 = i_rot.m21;
287- o_result.m22 = i_rot.m22;
288- o_result.m23 = i_trans.z;
289-
290- o_result.has_value = true;
291- return;
292- }
293-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotVector.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotVector.java (nonexistent)
@@ -1,380 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.NyARMat;
35-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
36-import jp.nyatla.nyartoolkit.core.types.NyARLinear;
37-import jp.nyatla.nyartoolkit.core.param.*;
38-
39-public class NyARRotVector
40-{
41-
42- //publicメンバ達
43- public double v1;
44-
45- public double v2;
46-
47- public double v3;
48-
49- //privateメンバ達
50-
51- private NyARPerspectiveProjectionMatrix _projection_mat_ref;
52-
53- private double[][] _inv_cpara_array_ref;
54-
55- public NyARRotVector(NyARPerspectiveProjectionMatrix i_cmat) throws NyARException
56- {
57- NyARMat mat_a = new NyARMat(3, 3);
58- double[][] a_array = mat_a.getArray();
59-
60- a_array[0][0] =i_cmat.m00;
61- a_array[0][1] =i_cmat.m01;
62- a_array[0][2] =i_cmat.m02;
63- a_array[1][0] =i_cmat.m10;
64- a_array[1][1] =i_cmat.m11;
65- a_array[1][2] =i_cmat.m12;
66- a_array[2][0] =i_cmat.m20;
67- a_array[2][1] =i_cmat.m21;
68- a_array[2][2] =i_cmat.m22;
69-
70- mat_a.matrixSelfInv();
71- this._projection_mat_ref = i_cmat;
72- this._inv_cpara_array_ref = mat_a.getArray();
73- //GCない言語のときは、ここで配列の所有権委譲してね!
74- }
75-
76- /**
77- * 2直線に直交するベクトルを計算する・・・だと思う。
78- * @param i_linear1
79- * @param i_linear2
80- */
81- public void exteriorProductFromLinear(NyARLinear i_linear1, NyARLinear i_linear2)
82- {
83- //1行目
84- final NyARPerspectiveProjectionMatrix cmat= this._projection_mat_ref;
85- final double w1 = i_linear1.dy * i_linear2.dx - i_linear2.dy * i_linear1.dx;
86- final double w2 = i_linear1.dx * i_linear2.c - i_linear2.dx * i_linear1.c;
87- final double w3 = i_linear1.c * i_linear2.dy - i_linear2.c * i_linear1.dy;
88-
89- final double m0 = w1 * (cmat.m01 * cmat.m12 - cmat.m02 * cmat.m11) + w2 * cmat.m11 - w3 * cmat.m01;//w1 * (cpara[0 * 4 + 1] * cpara[1 * 4 + 2] - cpara[0 * 4 + 2] * cpara[1 * 4 + 1]) + w2 * cpara[1 * 4 + 1] - w3 * cpara[0 * 4 + 1];
90- final double m1 = -w1 * cmat.m00 * cmat.m12 + w3 * cmat.m00;//-w1 * cpara[0 * 4 + 0] * cpara[1 * 4 + 2] + w3 * cpara[0 * 4 + 0];
91- final double m2 = w1 * cmat.m00 * cmat.m11;//w1 * cpara[0 * 4 + 0] * cpara[1 * 4 + 1];
92- final double w = Math.sqrt(m0 * m0 + m1 * m1 + m2 * m2);
93- this.v1 = m0 / w;
94- this.v2 = m1 / w;
95- this.v3 = m2 / w;
96- return;
97- }
98-
99- /**
100- * static int check_dir( double dir[3], double st[2], double ed[2],double cpara[3][4] ) Optimize:STEP[526->468]
101- * ベクトルの開始/終了座標を指定して、ベクトルの方向を調整する。
102- * @param i_start_vertex
103- * @param i_end_vertex
104- * @param cpara
105- */
106- public void checkVectorByVertex(final NyARDoublePoint2d i_start_vertex, final NyARDoublePoint2d i_end_vertex) throws NyARException
107- {
108- double h;
109- final double[][] inv_cpara = this._inv_cpara_array_ref;
110- //final double[] world = __checkVectorByVertex_world;// [2][3];
111- final double world0 = inv_cpara[0][0] * i_start_vertex.x * 10.0 + inv_cpara[0][1] * i_start_vertex.y * 10.0 + inv_cpara[0][2] * 10.0;// mat_a->m[0]*st[0]*10.0+
112- final double world1 = inv_cpara[1][0] * i_start_vertex.x * 10.0 + inv_cpara[1][1] * i_start_vertex.y * 10.0 + inv_cpara[1][2] * 10.0;// mat_a->m[3]*st[0]*10.0+
113- final double world2 = inv_cpara[2][0] * i_start_vertex.x * 10.0 + inv_cpara[2][1] * i_start_vertex.y * 10.0 + inv_cpara[2][2] * 10.0;// mat_a->m[6]*st[0]*10.0+
114- final double world3 = world0 + this.v1;
115- final double world4 = world1 + this.v2;
116- final double world5 = world2 + this.v3;
117- // </Optimize>
118-
119- //final double[] camera = __checkVectorByVertex_camera;// [2][2];
120- final NyARPerspectiveProjectionMatrix cmat= this._projection_mat_ref;
121- //h = cpara[2 * 4 + 0] * world0 + cpara[2 * 4 + 1] * world1 + cpara[2 * 4 + 2] * world2;
122- h = cmat.m20 * world0 + cmat.m21 * world1 + cmat.m22 * world2;
123- if (h == 0.0) {
124- throw new NyARException();
125- }
126- //final double camera0 = (cpara[0 * 4 + 0] * world0 + cpara[0 * 4 + 1] * world1 + cpara[0 * 4 + 2] * world2) / h;
127- //final double camera1 = (cpara[1 * 4 + 0] * world0 + cpara[1 * 4 + 1] * world1 + cpara[1 * 4 + 2] * world2) / h;
128- final double camera0 = (cmat.m00 * world0 + cmat.m01 * world1 + cmat.m02 * world2) / h;
129- final double camera1 = (cmat.m10 * world0 + cmat.m11 * world1 + cmat.m12 * world2) / h;
130-
131- //h = cpara[2 * 4 + 0] * world3 + cpara[2 * 4 + 1] * world4 + cpara[2 * 4 + 2] * world5;
132- h = cmat.m20 * world3 + cmat.m21 * world4 + cmat.m22 * world5;
133- if (h == 0.0) {
134- throw new NyARException();
135- }
136- //final double camera2 = (cpara[0 * 4 + 0] * world3 + cpara[0 * 4 + 1] * world4 + cpara[0 * 4 + 2] * world5) / h;
137- //final double camera3 = (cpara[1 * 4 + 0] * world3 + cpara[1 * 4 + 1] * world4 + cpara[1 * 4 + 2] * world5) / h;
138- final double camera2 = (cmat.m00 * world3 + cmat.m01 * world4 + cmat.m02 * world5) / h;
139- final double camera3 = (cmat.m10 * world3 + cmat.m11 * world4 + cmat.m12 * world5) / h;
140-
141- final double v = (i_end_vertex.x - i_start_vertex.x) * (camera2 - camera0) + (i_end_vertex.y - i_start_vertex.y) * (camera3 - camera1);
142- if (v < 0) {
143- this.v1 = -this.v1;
144- this.v2 = -this.v2;
145- this.v3 = -this.v3;
146- }
147- }
148- /**
149- * int check_rotation( double rot[2][3] )
150- * 2つのベクトル引数の調整をする?
151- * @param i_r
152- * @throws NyARException
153- */
154-
155- public final static void checkRotation(NyARRotVector io_vec1, NyARRotVector io_vec2) throws NyARException
156- {
157- double w;
158- int f;
159-
160- double vec10 = io_vec1.v1;
161- double vec11 = io_vec1.v2;
162- double vec12 = io_vec1.v3;
163- double vec20 = io_vec2.v1;
164- double vec21 = io_vec2.v2;
165- double vec22 = io_vec2.v3;
166-
167- double vec30 = vec11 * vec22 - vec12 * vec21;
168- double vec31 = vec12 * vec20 - vec10 * vec22;
169- double vec32 = vec10 * vec21 - vec11 * vec20;
170- w = Math.sqrt(vec30 * vec30 + vec31 * vec31 + vec32 * vec32);
171- if (w == 0.0) {
172- throw new NyARException();
173- }
174- vec30 /= w;
175- vec31 /= w;
176- vec32 /= w;
177-
178- double cb = vec10 * vec20 + vec11 * vec21 + vec12 * vec22;
179- if (cb < 0){
180- cb=-cb;//cb *= -1.0;
181- }
182- final double ca = (Math.sqrt(cb + 1.0) + Math.sqrt(1.0 - cb)) * 0.5;
183-
184- if (vec31 * vec10 - vec11 * vec30 != 0.0) {
185- f = 0;
186- } else {
187- if (vec32 * vec10 - vec12 * vec30 != 0.0) {
188- w = vec11;vec11 = vec12;vec12 = w;
189- w = vec31;vec31 = vec32;vec32 = w;
190- f = 1;
191- } else {
192- w = vec10;vec10 = vec12;vec12 = w;
193- w = vec30;vec30 = vec32;vec32 = w;
194- f = 2;
195- }
196- }
197- if (vec31 * vec10 - vec11 * vec30 == 0.0) {
198- throw new NyARException();
199- }
200-
201- double k1,k2,k3,k4;
202- double a, b, c, d;
203- double p1, q1, r1;
204- double p2, q2, r2;
205- double p3, q3, r3;
206- double p4, q4, r4;
207-
208-
209- k1 = (vec11 * vec32 - vec31 * vec12) / (vec31 * vec10 - vec11 * vec30);
210- k2 = (vec31 * ca) / (vec31 * vec10 - vec11 * vec30);
211- k3 = (vec10 * vec32 - vec30 * vec12) / (vec30 * vec11 - vec10 * vec31);
212- k4 = (vec30 * ca) / (vec30 * vec11 - vec10 * vec31);
213-
214- a = k1 * k1 + k3 * k3 + 1;
215- b = k1 * k2 + k3 * k4;
216- c = k2 * k2 + k4 * k4 - 1;
217-
218- d = b * b - a * c;
219- if (d < 0) {
220- throw new NyARException();
221- }
222- r1 = (-b + Math.sqrt(d)) / a;
223- p1 = k1 * r1 + k2;
224- q1 = k3 * r1 + k4;
225- r2 = (-b - Math.sqrt(d)) / a;
226- p2 = k1 * r2 + k2;
227- q2 = k3 * r2 + k4;
228- if (f == 1) {
229- w = q1;q1 = r1;r1 = w;
230- w = q2;q2 = r2;r2 = w;
231- w = vec11;vec11 = vec12;vec12 = w;
232- w = vec31;vec31 = vec32;vec32 = w;
233- f = 0;
234- }
235- if (f == 2) {
236- w = p1;p1 = r1;r1 = w;
237- w = p2;p2 = r2;r2 = w;
238- w = vec10;vec10 = vec12;vec12 = w;
239- w = vec30;vec30 = vec32;vec32 = w;
240- f = 0;
241- }
242-
243- if (vec31 * vec20 - vec21 * vec30 != 0.0) {
244- f = 0;
245- } else {
246- if (vec32 * vec20 - vec22 * vec30 != 0.0) {
247- w = vec21;vec21 = vec22;vec22 = w;
248- w = vec31;vec31 = vec32;vec32 = w;
249- f = 1;
250- } else {
251- w = vec20;vec20 = vec22;vec22 = w;
252- w = vec30;vec30 = vec32;vec32 = w;
253- f = 2;
254- }
255- }
256- if (vec31 * vec20 - vec21 * vec30 == 0.0) {
257- throw new NyARException();
258- }
259- k1 = (vec21 * vec32 - vec31 * vec22) / (vec31 * vec20 - vec21 * vec30);
260- k2 = (vec31 * ca) / (vec31 * vec20 - vec21 * vec30);
261- k3 = (vec20 * vec32 - vec30 * vec22) / (vec30 * vec21 - vec20 * vec31);
262- k4 = (vec30 * ca) / (vec30 * vec21 - vec20 * vec31);
263-
264- a = k1 * k1 + k3 * k3 + 1;
265- b = k1 * k2 + k3 * k4;
266- c = k2 * k2 + k4 * k4 - 1;
267-
268- d = b * b - a * c;
269- if (d < 0) {
270- throw new NyARException();
271- }
272- r3 = (-b + Math.sqrt(d)) / a;
273- p3 = k1 * r3 + k2;
274- q3 = k3 * r3 + k4;
275- r4 = (-b - Math.sqrt(d)) / a;
276- p4 = k1 * r4 + k2;
277- q4 = k3 * r4 + k4;
278- if (f == 1) {
279- w = q3;q3 = r3;r3 = w;
280- w = q4;q4 = r4;r4 = w;
281- w = vec21;vec21 = vec22;vec22 = w;
282- w = vec31;vec31 = vec32;vec32 = w;
283- f = 0;
284- }
285- if (f == 2) {
286- w = p3;p3 = r3;r3 = w;
287- w = p4;p4 = r4;r4 = w;
288- w = vec20;vec20 = vec22;vec22 = w;
289- w = vec30;vec30 = vec32;vec32 = w;
290- f = 0;
291- }
292-
293- double e1 = p1 * p3 + q1 * q3 + r1 * r3;
294- if (e1 < 0) {
295- e1 = -e1;
296- }
297- double e2 = p1 * p4 + q1 * q4 + r1 * r4;
298- if (e2 < 0) {
299- e2 = -e2;
300- }
301- double e3 = p2 * p3 + q2 * q3 + r2 * r3;
302- if (e3 < 0) {
303- e3 = -e3;
304- }
305- double e4 = p2 * p4 + q2 * q4 + r2 * r4;
306- if (e4 < 0) {
307- e4 = -e4;
308- }
309- if (e1 < e2) {
310- if (e1 < e3) {
311- if (e1 < e4) {
312- io_vec1.v1 = p1;
313- io_vec1.v2 = q1;
314- io_vec1.v3 = r1;
315- io_vec2.v1 = p3;
316- io_vec2.v2 = q3;
317- io_vec2.v3 = r3;
318- } else {
319- io_vec1.v1 = p2;
320- io_vec1.v2 = q2;
321- io_vec1.v3 = r2;
322- io_vec2.v1 = p4;
323- io_vec2.v2 = q4;
324- io_vec2.v3 = r4;
325- }
326- } else {
327- if (e3 < e4) {
328- io_vec1.v1 = p2;
329- io_vec1.v2 = q2;
330- io_vec1.v3 = r2;
331- io_vec2.v1 = p3;
332- io_vec2.v2 = q3;
333- io_vec2.v3 = r3;
334- } else {
335- io_vec1.v1 = p2;
336- io_vec1.v2 = q2;
337- io_vec1.v3 = r2;
338- io_vec2.v1 = p4;
339- io_vec2.v2 = q4;
340- io_vec2.v3 = r4;
341- }
342- }
343- } else {
344- if (e2 < e3) {
345- if (e2 < e4) {
346- io_vec1.v1 = p1;
347- io_vec1.v2 = q1;
348- io_vec1.v3 = r1;
349- io_vec2.v1 = p4;
350- io_vec2.v2 = q4;
351- io_vec2.v3 = r4;
352- } else {
353- io_vec1.v1 = p2;
354- io_vec1.v2 = q2;
355- io_vec1.v3 = r2;
356- io_vec2.v1 = p4;
357- io_vec2.v2 = q4;
358- io_vec2.v3 = r4;
359- }
360- } else {
361- if (e3 < e4) {
362- io_vec1.v1 = p2;
363- io_vec1.v2 = q2;
364- io_vec1.v3 = r2;
365- io_vec2.v1 = p3;
366- io_vec2.v2 = q3;
367- io_vec2.v3 = r3;
368- } else {
369- io_vec1.v1 = p2;
370- io_vec1.v2 = q2;
371- io_vec1.v3 = r2;
372- io_vec2.v1 = p4;
373- io_vec2.v2 = q4;
374- io_vec2.v3 = r4;
375- }
376- }
377- }
378- return;
379- }
380-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix.java (nonexistent)
@@ -1,153 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;
35-import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;
36-import jp.nyatla.nyartoolkit.core.types.*;
37-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix33;
38-/**
39- * 回転行列計算用の、3x3行列
40- *
41- */
42-public class NyARRotMatrix extends NyARDoubleMatrix33
43-{
44- /**
45- * インスタンスを準備します。
46- *
47- * @param i_param
48- */
49- public NyARRotMatrix(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException
50- {
51- this.__initRot_vec1=new NyARRotVector(i_matrix);
52- this.__initRot_vec2=new NyARRotVector(i_matrix);
53- return;
54- }
55- final private NyARRotVector __initRot_vec1;
56- final private NyARRotVector __initRot_vec2;
57- /**
58- * NyARTransMatResultの内容からNyARRotMatrixを復元します。
59- * @param i_prev_result
60- */
61- public final void initRotByPrevResult(NyARTransMatResult i_prev_result)
62- {
63-
64- this.m00=i_prev_result.m00;
65- this.m01=i_prev_result.m01;
66- this.m02=i_prev_result.m02;
67-
68- this.m10=i_prev_result.m10;
69- this.m11=i_prev_result.m11;
70- this.m12=i_prev_result.m12;
71-
72- this.m20=i_prev_result.m20;
73- this.m21=i_prev_result.m21;
74- this.m22=i_prev_result.m22;
75- return;
76- }
77- /**
78- *
79- * @param i_linear
80- * @param i_sqvertex
81- * @throws NyARException
82- */
83- public void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException
84- {
85- final NyARRotVector vec1=this.__initRot_vec1;
86- final NyARRotVector vec2=this.__initRot_vec2;
87-
88- //向かい合った辺から、2本のベクトルを計算
89-
90- //軸1
91- vec1.exteriorProductFromLinear(i_linear[0], i_linear[2]);
92- vec1.checkVectorByVertex(i_sqvertex[0], i_sqvertex[1]);
93-
94- //軸2
95- vec2.exteriorProductFromLinear(i_linear[1], i_linear[3]);
96- vec2.checkVectorByVertex(i_sqvertex[3], i_sqvertex[0]);
97-
98- //回転の最適化?
99- NyARRotVector.checkRotation(vec1,vec2);
100-
101- this.m00 =vec1.v1;
102- this.m10 =vec1.v2;
103- this.m20 =vec1.v3;
104- this.m01 =vec2.v1;
105- this.m11 =vec2.v2;
106- this.m21 =vec2.v3;
107-
108- //最後の軸を計算
109- final double w02 = vec1.v2 * vec2.v3 - vec1.v3 * vec2.v2;
110- final double w12 = vec1.v3 * vec2.v1 - vec1.v1 * vec2.v3;
111- final double w22 = vec1.v1 * vec2.v2 - vec1.v2 * vec2.v1;
112- final double w = Math.sqrt(w02 * w02 + w12 * w12 + w22 * w22);
113- this.m02 = w02/w;
114- this.m12 = w12/w;
115- this.m22 = w22/w;
116- return;
117- }
118- /**
119- * i_in_pointを変換行列で座標変換する。
120- * @param i_in_point
121- * @param i_out_point
122- */
123- public final void getPoint3d(final NyARDoublePoint3d i_in_point,final NyARDoublePoint3d i_out_point)
124- {
125- final double x=i_in_point.x;
126- final double y=i_in_point.y;
127- final double z=i_in_point.z;
128- i_out_point.x=this.m00 * x + this.m01 * y + this.m02 * z;
129- i_out_point.y=this.m10 * x + this.m11 * y + this.m12 * z;
130- i_out_point.z=this.m20 * x + this.m21 * y + this.m22 * z;
131- return;
132- }
133- /**
134- * 複数の頂点を一括して変換する
135- * @param i_in_point
136- * @param i_out_point
137- * @param i_number_of_vertex
138- */
139- public final void getPoint3dBatch(final NyARDoublePoint3d[] i_in_point,NyARDoublePoint3d[] i_out_point,int i_number_of_vertex)
140- {
141- for(int i=i_number_of_vertex-1;i>=0;i--){
142- final NyARDoublePoint3d out_ptr=i_out_point[i];
143- final NyARDoublePoint3d in_ptr=i_in_point[i];
144- final double x=in_ptr.x;
145- final double y=in_ptr.y;
146- final double z=in_ptr.z;
147- out_ptr.x=this.m00 * x + this.m01 * y + this.m02 * z;
148- out_ptr.y=this.m10 * x + this.m11 * y + this.m12 * z;
149- out_ptr.z=this.m20 * x + this.m21 * y + this.m22 * z;
150- }
151- return;
152- }
153-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java (nonexistent)
@@ -1,202 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.types.*;
35-import jp.nyatla.nyartoolkit.core.param.*;
36-/**
37- * 回転行列計算用の、3x3行列
38- *
39- */
40-public class NyARRotMatrix_ARToolKit extends NyARRotMatrix
41-{
42- /**
43- * インスタンスを準備します。
44- *
45- * @param i_param
46- */
47- public NyARRotMatrix_ARToolKit(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException
48- {
49- super(i_matrix);
50- this._angle=new NyARDoublePoint3d();
51- return;
52- }
53- final protected NyARDoublePoint3d _angle;
54-
55-
56-
57- public final void initRotBySquare(final NyARLinear[] i_linear,final NyARDoublePoint2d[] i_sqvertex) throws NyARException
58- {
59- super.initRotBySquare(i_linear,i_sqvertex);
60- //Matrixからangleをロード
61- this.updateAngleFromMatrix();
62- return;
63- }
64- public final NyARDoublePoint3d refAngle()
65- {
66- return this._angle;
67- }
68- /**
69- * 回転角から回転行列を計算してセットします。
70- * @param i_x
71- * @param i_y
72- * @param i_z
73- */
74- public void setAngle(final double i_x, final double i_y, final double i_z)
75- {
76- final double sina = Math.sin(i_x);
77- final double cosa = Math.cos(i_x);
78- final double sinb = Math.sin(i_y);
79- final double cosb = Math.cos(i_y);
80- final double sinc = Math.sin(i_z);
81- final double cosc = Math.cos(i_z);
82- // Optimize
83- final double CACA = cosa * cosa;
84- final double SASA = sina * sina;
85- final double SACA = sina * cosa;
86- final double SASB = sina * sinb;
87- final double CASB = cosa * sinb;
88- final double SACACB = SACA * cosb;
89-
90- this.m00 = CACA * cosb * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
91- this.m01 = -CACA * cosb * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
92- this.m02 = CASB;
93- this.m10 = SACACB * cosc - SACA * cosc + SASA * cosb * sinc + CACA * sinc;
94- this.m11 = -SACACB * sinc + SACA * sinc + SASA * cosb * cosc + CACA * cosc;
95- this.m12 = SASB;
96- this.m20 = -CASB * cosc - SASB * sinc;
97- this.m21 = CASB * sinc - SASB * cosc;
98- this.m22 = cosb;
99- updateAngleFromMatrix();
100- return;
101- }
102- /**
103- * 現在のMatrixからangkeを復元する。
104- * @param o_angle
105- */
106- private final void updateAngleFromMatrix()
107- {
108- double a,b,c;
109- double sina, cosa, sinb,cosb,sinc, cosc;
110-
111- if (this.m22 > 1.0) {// <Optimize/>if( rot[2][2] > 1.0 ) {
112- cosb = 1.0;// <Optimize/>rot[2][2] = 1.0;
113- } else if (this.m22 < -1.0) {// <Optimize/>}else if( rot[2][2] < -1.0 ) {
114- cosb = -1.0;// <Optimize/>rot[2][2] = -1.0;
115- }else{
116- cosb =this.m22;// <Optimize/>cosb = rot[2][2];
117- }
118- b = Math.acos(cosb);
119- sinb =Math.sin(b);
120- final double rot02=this.m02;
121- final double rot12=this.m12;
122- if (b >= 0.000001 || b <= -0.000001) {
123- cosa = rot02 / sinb;// <Optimize/>cosa = rot[0][2] / sinb;
124- sina = rot12 / sinb;// <Optimize/>sina = rot[1][2] / sinb;
125- if (cosa > 1.0) {
126- cosa = 1.0;
127- sina = 0.0;
128- }
129- if (cosa < -1.0) {
130- cosa = -1.0;
131- sina = 0.0;
132- }
133- if (sina > 1.0) {
134- sina = 1.0;
135- cosa = 0.0;
136- }
137- if (sina < -1.0) {
138- sina = -1.0;
139- cosa = 0.0;
140- }
141- a = Math.acos(cosa);
142- if (sina < 0) {
143- a = -a;
144- }
145- final double tmp = (rot02 * rot02 + rot12 * rot12);
146- sinc = (this.m21 * rot02 - this.m20 * rot12) / tmp;
147- cosc = -(rot02 * this.m20 + rot12 * this.m21) / tmp;
148-
149- if (cosc > 1.0) {
150- cosc = 1.0;
151- sinc = 0.0;
152- }
153- if (cosc < -1.0) {
154- cosc = -1.0;
155- sinc = 0.0;
156- }
157- if (sinc > 1.0) {
158- sinc = 1.0;
159- cosc = 0.0;
160- }
161- if (sinc < -1.0) {
162- sinc = -1.0;
163- cosc = 0.0;
164- }
165- c = Math.acos(cosc);
166- if (sinc < 0) {
167- c = -c;
168- }
169- } else {
170- a = b = 0.0;
171- cosa = cosb = 1.0;
172- sina = sinb = 0.0;
173- cosc=this.m00;//cosc = rot[0];// <Optimize/>cosc = rot[0][0];
174- sinc=this.m01;//sinc = rot[1];// <Optimize/>sinc = rot[1][0];
175- if (cosc > 1.0) {
176- cosc = 1.0;
177- sinc = 0.0;
178- }
179- if (cosc < -1.0) {
180- cosc = -1.0;
181- sinc = 0.0;
182- }
183- if (sinc > 1.0) {
184- sinc = 1.0;
185- cosc = 0.0;
186- }
187- if (sinc < -1.0) {
188- sinc = -1.0;
189- cosc = 0.0;
190- }
191- c = Math.acos(cosc);
192- if (sinc < 0) {
193- c = -c;
194- }
195- }
196- //angleの更新
197- this._angle.x = a;// wa.value=a;//*wa = a;
198- this._angle.y = b;// wb.value=b;//*wb = b;
199- this._angle.z = c;// wc.value=c;//*wc = c;
200- return;
201- }
202-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit_O2.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit_O2.java (nonexistent)
@@ -1,85 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.rotmatrix;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.param.*;
35-/**
36- * 回転行列計算用の、3x3行列
37- * 計算方法はARToolKitと同じだが、ARToolKitにある不要な行列から角度を逆算する
38- * 処理を省略しているため、下位12桁目の計算値が異なる。
39- *
40- */
41-public class NyARRotMatrix_ARToolKit_O2 extends NyARRotMatrix_ARToolKit
42-{
43- /**
44- * インスタンスを準備します。
45- *
46- * @param i_param
47- */
48- public NyARRotMatrix_ARToolKit_O2(NyARPerspectiveProjectionMatrix i_matrix) throws NyARException
49- {
50- super(i_matrix);
51- return;
52- }
53- public final void setAngle(final double i_x, final double i_y, final double i_z)
54- {
55- final double sina = Math.sin(i_x);
56- final double cosa = Math.cos(i_x);
57- final double sinb = Math.sin(i_y);
58- final double cosb = Math.cos(i_y);
59- final double sinc = Math.sin(i_z);
60- final double cosc = Math.cos(i_z);
61- // Optimize
62- final double CACA = cosa * cosa;
63- final double SASA = sina * sina;
64- final double SACA = sina * cosa;
65- final double SASB = sina * sinb;
66- final double CASB = cosa * sinb;
67- final double SACACB = SACA * cosb;
68-
69- this.m00 = CACA * cosb * cosc + SASA * cosc + SACACB * sinc - SACA * sinc;
70- this.m01 = -CACA * cosb * sinc - SASA * sinc + SACACB * cosc - SACA * cosc;
71- this.m02 = CASB;
72- this.m10 = SACACB * cosc - SACA * cosc + SASA * cosb * sinc + CACA * sinc;
73- this.m11 = -SACACB * sinc + SACA * sinc + SASA * cosb * cosc + CACA * cosc;
74- this.m12 = SASB;
75- this.m20 = -CASB * cosc - SASB * sinc;
76- this.m21 = CASB * sinc - SASB * cosc;
77- this.m22 = cosb;
78- //angleを逆計算せずに直接代入
79- this._angle.x=i_x;
80- this._angle.y=i_y;
81- this._angle.z=i_z;
82- return;
83- }
84-
85-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver_ARToolKit.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver_ARToolKit.java (nonexistent)
@@ -1,133 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.solver;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.NyARMat;
35-import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;
36-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
37-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
38-
39-/**
40- * 並進ベクトル[T]を3次元座標[b]と基点の回転済行列[M]から計算します。
41- * ARToolKit互換の数値を計算します。
42- *
43- */
44-public class NyARTransportVectorSolver_ARToolKit implements INyARTransportVectorSolver
45-{
46- private final NyARMat _mat_at = new NyARMat(3,8);//3,NUMBER_OF_VERTEX*2
47- private final NyARMat _mat_a = new NyARMat(8,3);//NUMBER_OF_VERTEX,3
48- private final NyARMat _mat_t = new NyARMat(3,3);//NUMBER_OF_VERTEX,3
49- private final NyARMat _mat_c = new NyARMat(8,1);//NUMBER_OF_VERTEX * 2, 1
50- private final NyARMat _mat_e = new NyARMat(3,1);
51- private final NyARMat _mat_f = new NyARMat(3,1);
52- private double[] _cx=new double[4];
53- private double[] _cy=new double[4];
54-
55- private final NyARPerspectiveProjectionMatrix _projection_mat;
56- public NyARTransportVectorSolver_ARToolKit(final NyARPerspectiveProjectionMatrix i_projection_mat_ref)
57- {
58- this._projection_mat=i_projection_mat_ref;
59- //aとb(aの転置行列)の固定部分を設定。
60- final double[][] mata = this._mat_a.getArray();
61- final double[][] matat = this._mat_at.getArray();
62-
63- //変換用行列のcpara部分を先に作成
64- for (int i = 0; i < 4; i++) {
65- final int x2 = i * 2;
66- mata[x2][0] = matat[0][x2] = i_projection_mat_ref.m00;// mat_a->m[j*6+0]=mat_b->m[num*0+j*2] =cpara[0][0];
67- mata[x2][1] = matat[1][x2] = i_projection_mat_ref.m01;// mat_a->m[j*6+1]=mat_b->m[num*2+j*2]=cpara[0][1];
68- mata[x2 + 1][0] = matat[0][x2 + 1] = 0.0;// mat_a->m[j*6+3] =mat_b->m[num*0+j*2+1]= 0.0;
69- mata[x2 + 1][1] = matat[1][x2 + 1] = i_projection_mat_ref.m11;// mat_a->m[j*6+4] =mat_b->m[num*2+j*2+1]= cpara[1][1];
70- }
71- return;
72- }
73- public void set2dVertex(NyARDoublePoint2d[] i_ref_vertex_2d,int i_number_of_vertex) throws NyARException
74- {
75- assert(i_number_of_vertex==4);
76- final double[] cx=this._cx;
77- final double[] cy=this._cy;
78- final double cpara02=this._projection_mat.m02;
79- final double cpara12=this._projection_mat.m12;
80- final NyARMat mat_t=this._mat_t;
81- final double[][] mata = this._mat_a.getArray();
82- final double[][] matat= this._mat_at.getArray();
83- for (int i = 0; i < 4; i++){
84- cx[i]=i_ref_vertex_2d[i].x;
85- cy[i]=i_ref_vertex_2d[i].y;
86- final int x2 = i * 2;
87- mata[x2][2] = matat[2][x2] = cpara02 - i_ref_vertex_2d[i].x;// mat_a->m[j*6+2]=mat_b->m[num*4+j*2]=cpara[0][2]-pos2d[j][0];
88- mata[x2 + 1][2] = matat[2][x2 + 1] = cpara12 - i_ref_vertex_2d[i].y;// mat_a->m[j*6+5]=mat_b->m[num*4+j*2+1]=cpara[1][2]-pos2d[j][1];
89- }
90- //T(3x3行列)の作成
91- mat_t.matrixMul(this._mat_at, this._mat_a);
92- mat_t.matrixSelfInv();
93- return;
94- }
95- /**
96- * 画面座標群と3次元座標群から、平行移動量を計算します。
97- * 2d座標系は、直前に実行したset2dVertexのものを使用します。
98- * @param i_vertex_2d
99- * 直前のset2dVertexコールで指定したものと同じものを指定してください。
100- * @param i_vertex3d
101- * 3次元空間の座標群を設定します。頂点の順番は、画面座標群と同じ順序で格納してください。
102- * @param o_transfer
103- * @throws NyARException
104- */
105- public void solveTransportVector(NyARDoublePoint3d[] i_vertex3d,NyARDoublePoint3d o_transfer) throws NyARException
106- {
107- final double[][] matc = this._mat_c.getArray();
108- final double cpara00=this._projection_mat.m00;
109- final double cpara01=this._projection_mat.m01;
110- final double cpara02=this._projection_mat.m02;
111- final double cpara11=this._projection_mat.m11;
112- final double cpara12=this._projection_mat.m12;
113- final double[] cx=this._cx;
114- final double[] cy=this._cy;
115-
116- //(3D座標?)を一括請求
117- for (int i = 0; i < 4; i++) {
118- final int x2 = i+i;
119- final NyARDoublePoint3d point3d_ptr=i_vertex3d[i];
120- //透視変換?
121- matc[x2][0] = point3d_ptr.z * cx[i] - cpara00 * point3d_ptr.x - cpara01 * point3d_ptr.y - cpara02 * point3d_ptr.z;// mat_c->m[j*2+0] = wz*pos2d[j][0]-cpara[0][0]*wx-cpara[0][1]*wy-cpara[0][2]*wz;
122- matc[x2 + 1][0] = point3d_ptr.z * cy[i] - cpara11 * point3d_ptr.y - cpara12 * point3d_ptr.z;// mat_c->m[j*2+1]= wz*pos2d[j][1]-cpara[1][1]*wy-cpara[1][2]*wz;
123- }
124- this._mat_e.matrixMul(this._mat_at,this._mat_c);
125- this._mat_f.matrixMul(this._mat_t, this._mat_e);
126-
127- final double[][] matf = this._mat_f.getArray();
128- o_transfer.x= matf[0][0];// trans[0] = mat_f->m[0];
129- o_transfer.y= matf[1][0];
130- o_transfer.z= matf[2][0];// trans[2] = mat_f->m[2];
131- return;
132- }
133-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver/INyARTransportVectorSolver.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver/INyARTransportVectorSolver.java (nonexistent)
@@ -1,56 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat.solver;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;
35-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint3d;
36-
37-/**
38- * 並進ベクトル[T]を3次元座標[b]と基点の回転済行列[M]から計算するインタフェイスです。
39- * [M][T]=[b]
40- *
41- */
42-public interface INyARTransportVectorSolver
43-{
44- public void set2dVertex(NyARDoublePoint2d[] i_ref_vertex_2d,int i_number_of_vertex) throws NyARException;
45- /**
46- * 画面座標群と3次元座標群から、平行移動量を計算します。
47- * 2d座標系は、直前に実行したset2dVertexのものを使用します。
48- * @param i_vertex_2d
49- * 直前のset2dVertexコールで指定したものと同じものを指定してください。
50- * @param i_vertex3d
51- * 3次元空間の座標群を設定します。頂点の順番は、画面座標群と同じ順序で格納してください。
52- * @param o_transfer
53- * @throws NyARException
54- */
55- public void solveTransportVector(NyARDoublePoint3d[] i_vertex3d,NyARDoublePoint3d o_transfer) throws NyARException;
56-}
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/solver/NyARTransportVectorSolver.java (nonexistent)
@@ -1,161 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit(Extension)
3- * --------------------------------------------------------------------------------
4- *
5- * The NyARToolkit is Java edition ARToolKit class library.
6- * Copyright (C)2008-2009 Ryo Iizuka
7- *
8- * This program is free software: you can redistribute it and/or modify
9- * it under the terms of the GNU General Public License as published by
10- * the Free Software Foundation, either version 3 of the License, or
11- * (at your option) any later version.
12- *
13- * This program is distributed in the hope that it will be useful,
14- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16- * GNU General Public License for more details.
17- *
18- * You should have received a copy of the GNU General Public License
19- * along with this program. If not, see <http://www.gnu.org/licenses/>.
20- *
21- * For further information please contact.
22- * http://nyatla.jp/nyatoolkit/
23- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
24- *
25- */
26-package jp.nyatla.nyartoolkit.core.transmat.solver;
27-
28-import jp.nyatla.nyartoolkit.NyARException;
29-import jp.nyatla.nyartoolkit.core.param.NyARPerspectiveProjectionMatrix;
30-import jp.nyatla.nyartoolkit.core.types.*;
31-
32-/**
33- * 並進ベクトル[T]を3次元座標[b]と基点の回転済行列[M]から計算します。
34- *
35- * アルゴリズムは、ARToolKit 拡張現実プログラミング入門 の、P207のものです。
36- *
37- * 計算手順
38- * [A]*[T]=bを、[A]T*[A]*[T]=[A]T*[b]にする。
39- * set2dVertexで[A]T*[A]=[M]を計算して、Aの3列目の情報だけ保存しておく。
40- * getTransportVectorで[M]*[T]=[A]T*[b]を連立方程式で解いて、[T]を得る。
41- */
42-public class NyARTransportVectorSolver implements INyARTransportVectorSolver
43-{
44- private double[] _cx;
45- private double[] _cy;
46- private final NyARPerspectiveProjectionMatrix _projection_mat;
47- private int _nmber_of_vertex;
48- public NyARTransportVectorSolver(final NyARPerspectiveProjectionMatrix i_projection_mat_ref,int i_max_vertex)
49- {
50- this._projection_mat=i_projection_mat_ref;
51- this._cx=new double[i_max_vertex];
52- this._cy=new double[i_max_vertex];
53- return;
54- }
55- private double _a00,_a01_10,_a02_20,_a11,_a12_21,_a22;
56- /**
57- * 画面上の座標群を指定します。
58- * @param i_ref_vertex_2d
59- * 歪み矯正済の画面上の頂点座標群への参照値を指定します。
60- * @throws NyARException
61- *
62- */
63- public void set2dVertex(NyARDoublePoint2d[] i_ref_vertex_2d,int i_number_of_vertex) throws NyARException
64- {
65- //3x2nと2n*3の行列から、最小二乗法計算するために3x3マトリクスを作る。
66- //行列[A]の3列目のキャッシュ
67- final double[] cx=this._cx;
68- final double[] cy=this._cy;
69-
70- double m22;
71- double p00=this._projection_mat.m00;
72- double p01=this._projection_mat.m01;
73- double p11=this._projection_mat.m11;
74- double p12=this._projection_mat.m12;
75- double p02=this._projection_mat.m02;
76- double w1,w2,w3,w4;
77-
78- this._a00=i_number_of_vertex*p00*p00;
79- this._a01_10=i_number_of_vertex*p00*p01;
80- this._a11=i_number_of_vertex*(p01*p01+p11*p11);
81-
82- //[A]T*[A]の計算
83- m22=0;
84- w1=w2=0;
85- for(int i=0;i<i_number_of_vertex;i++){
86- //座標を保存しておく。
87- w3=p02-(cx[i]=i_ref_vertex_2d[i].x);
88- w4=p12-(cy[i]=i_ref_vertex_2d[i].y);
89- w1+=w3;
90- w2+=w4;
91- m22+=w3*w3+w4*w4;
92- }
93- this._a02_20=w1*p00;
94- this._a12_21=p01*w1+p11*w2;
95- this._a22=m22;
96-
97- this._nmber_of_vertex=i_number_of_vertex;
98- return;
99- }
100-
101- /**
102- * 画面座標群と3次元座標群から、平行移動量を計算します。
103- * 2d座標系は、直前に実行したset2dVertexのものを使用します。
104- * @param i_vertex_2d
105- * 直前のset2dVertexコールで指定したものと同じものを指定してください。
106- * @param i_vertex3d
107- * 3次元空間の座標群を設定します。頂点の順番は、画面座標群と同じ順序で格納してください。
108- * @param o_transfer
109- * @throws NyARException
110- */
111- public void solveTransportVector(NyARDoublePoint3d[] i_vertex3d,NyARDoublePoint3d o_transfer) throws NyARException
112- {
113- final int number_of_vertex=this._nmber_of_vertex;
114- final double p00=this._projection_mat.m00;
115- final double p01=this._projection_mat.m01;
116- final double p02=this._projection_mat.m02;
117- final double p11=this._projection_mat.m11;
118- final double p12=this._projection_mat.m12;
119- //行列[A]の3列目のキャッシュ
120- final double[] cx=this._cx;
121- final double[] cy=this._cy;
122-
123- //回転行列を元座標の頂点群に適応
124- //[A]T*[b]を計算
125- double b1=0,b2=0,b3=0;
126- for(int i=0;i<number_of_vertex;i++)
127- {
128- double w1=i_vertex3d[i].z*cx[i]-p00*i_vertex3d[i].x-p01*i_vertex3d[i].y-p02*i_vertex3d[i].z;
129- double w2=i_vertex3d[i].z*cy[i]-p11*i_vertex3d[i].y-p12*i_vertex3d[i].z;
130- b1+=w1;
131- b2+=w2;
132- b3+=cx[i]*w1+cy[i]*w2;
133- }
134- //[A]T*[b]を計算
135- b3=p02*b1+p12*b2-b3;//順番変えたらダメよ
136- b2=p01*b1+p11*b2;
137- b1=p00*b1;
138- //([A]T*[A])*[T]=[A]T*[b]を方程式で解く。
139- //a01とa10を0と仮定しても良いんじゃないかな?
140- double a00=this._a00;
141- double a01=this._a01_10;
142- double a02=this._a02_20;
143- double a11=this._a11;
144- double a12=this._a12_21;
145- double a22=this._a22;
146-
147- double t1=a22*b2-a12*b3;
148- double t2=a12*b2-a11*b3;
149- double t3=a01*b3-a02*b2;
150- double t4=a12*a12-a11*a22;
151- double t5=a02*a12-a01*a22;
152- double t6=a02*a11-a01*a12;
153- double det=a00*t4-a01*t5 + a02*t6;
154- o_transfer.x= (a01*t1 - a02*t2 +b1*t4)/det;
155- o_transfer.y=-(a00*t1 + a02*t3 +b1*t5)/det;
156- o_transfer.z= (a00*t2 + a01*t3 +b1*t6)/det;
157-
158-
159- return;
160- }
161-}
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat_ARToolKit.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/NyARTransMat_ARToolKit.java (nonexistent)
@@ -1,222 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.param.*;
35-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
36-import jp.nyatla.nyartoolkit.core.transmat.solver.*;
37-import jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit.INyARRotMatrixOptimize;
38-import jp.nyatla.nyartoolkit.core.transmat.optimize.artoolkit.NyARRotMatrixOptimize_O2;
39-import jp.nyatla.nyartoolkit.core.transmat.rotmatrix.*;
40-import jp.nyatla.nyartoolkit.core.types.*;
41-
42-
43-/**
44- * This class calculates ARMatrix from square information and holds it. --
45- * 変換行列を計算して、結果を保持するクラス。
46- *
47- */
48-public class NyARTransMat_ARToolKit implements INyARTransMat
49-{
50- private final static int AR_GET_TRANS_MAT_MAX_LOOP_COUNT = 5;// #define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5
51- private final static double AR_GET_TRANS_MAT_MAX_FIT_ERROR = 1.0;// #define AR_GET_TRANS_MAT_MAX_FIT_ERROR 1.0
52- private final static double AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR = 1.0;
53-
54- protected NyARRotMatrix_ARToolKit _rotmatrix;
55- protected INyARTransportVectorSolver _transsolver;
56- protected INyARRotMatrixOptimize _mat_optimize;
57- private NyARCameraDistortionFactor _ref_dist_factor;
58-
59- /**
60- * 派生クラスで自分でメンバオブジェクトを指定したい場合はこちらを使う。
61- *
62- */
63- protected NyARTransMat_ARToolKit()
64- {
65- //_calculator,_rotmatrix,_mat_optimizeをコンストラクタの終了後に
66- //作成して割り当ててください。
67- return;
68- }
69- public NyARTransMat_ARToolKit(NyARParam i_param) throws NyARException
70- {
71- final NyARCameraDistortionFactor dist=i_param.getDistortionFactor();
72- final NyARPerspectiveProjectionMatrix pmat=i_param.getPerspectiveProjectionMatrix();
73- this._transsolver=new NyARTransportVectorSolver_ARToolKit(pmat);
74- //互換性が重要な時は、NyARRotMatrix_ARToolKitを使うこと。
75- //理屈はNyARRotMatrix_NyARToolKitもNyARRotMatrix_ARToolKitも同じだけど、少しだけ値がずれる。
76- this._rotmatrix = new NyARRotMatrix_ARToolKit_O2(pmat);
77- this._mat_optimize=new NyARRotMatrixOptimize_O2(pmat);
78- this._ref_dist_factor=dist;
79- }
80-
81- private final NyARDoublePoint2d[] __transMat_vertex_2d = NyARDoublePoint2d.createArray(4);
82- private final NyARDoublePoint3d[] __transMat_vertex_3d = NyARDoublePoint3d.createArray(4);
83- private final NyARDoublePoint3d __transMat_trans=new NyARDoublePoint3d();
84- /**
85- * double arGetTransMat( ARMarkerInfo *marker_info,double center[2], double width, double conv[3][4] )
86- *
87- * @param i_square
88- * 計算対象のNyARSquareオブジェクト
89- * @param i_width
90- * @return
91- * @throws NyARException
92- */
93- public void transMat(final NyARSquare i_square,NyARRectOffset i_offset, NyARTransMatResult o_result_conv) throws NyARException
94- {
95- final NyARDoublePoint3d trans=this.__transMat_trans;
96-
97- //平行移動量計算機に、2D座標系をセット
98- NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;
99- NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
100- this._ref_dist_factor.ideal2ObservBatch(i_square.sqvertex, vertex_2d,4);
101- this._transsolver.set2dVertex(vertex_2d,4);
102-
103- //回転行列を計算
104- this._rotmatrix.initRotBySquare(i_square.line,i_square.sqvertex);
105-
106- //回転後の3D座標系から、平行移動量を計算
107- this._rotmatrix.getPoint3dBatch(i_offset.vertex,vertex_3d,4);
108- this._transsolver.solveTransportVector(vertex_3d,trans);
109-
110- //計算結果の最適化(平行移動量と回転行列の最適化)
111- o_result_conv.error=this.optimize(this._rotmatrix, trans, this._transsolver,i_offset.vertex, vertex_2d);
112-
113- // マトリクスの保存
114- this.updateMatrixValue(this._rotmatrix, trans,o_result_conv);
115- return;
116- }
117-
118- /*
119- * (non-Javadoc)
120- * @see jp.nyatla.nyartoolkit.core.transmat.INyARTransMat#transMatContinue(jp.nyatla.nyartoolkit.core.NyARSquare, int, double, jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult)
121- */
122- public void transMatContinue(NyARSquare i_square,NyARRectOffset i_offset, NyARTransMatResult o_result_conv) throws NyARException
123- {
124- final NyARDoublePoint3d trans=this.__transMat_trans;
125-
126- // io_result_convが初期値なら、transMatで計算する。
127- if (!o_result_conv.has_value) {
128- this.transMat(i_square, i_offset, o_result_conv);
129- return;
130- }
131-
132- //平行移動量計算機に、2D座標系をセット
133- NyARDoublePoint2d[] vertex_2d=this.__transMat_vertex_2d;
134- NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
135- this._ref_dist_factor.ideal2ObservBatch(i_square.sqvertex, vertex_2d,4);
136- this._transsolver.set2dVertex(vertex_2d,4);
137-
138- //回転行列を計算
139- this._rotmatrix.initRotByPrevResult(o_result_conv);
140-
141- //回転後の3D座標系から、平行移動量を計算
142- this._rotmatrix.getPoint3dBatch(i_offset.vertex,vertex_3d,4);
143- this._transsolver.solveTransportVector(vertex_3d,trans);
144-
145- //計算結果の最適化(平行移動量と回転行列の最適化)
146- double err=this.optimize(this._rotmatrix, trans, this._transsolver,i_offset.vertex, vertex_2d);
147-
148- // マトリクスの保存
149- this.updateMatrixValue(this._rotmatrix, trans,o_result_conv);
150-
151- // エラー値が許容範囲でなければTransMatをやり直し
152- if (err > AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR) {
153- // rotationを矩形情報で初期化
154- this._rotmatrix.initRotBySquare(i_square.line,i_square.sqvertex);
155- //回転行列の平行移動量の計算
156- this._rotmatrix.getPoint3dBatch(i_offset.vertex,vertex_3d,4);
157- this._transsolver.solveTransportVector(vertex_3d,trans);
158- //計算結果の最適化(this._rotmatrix,trans)
159- final double err2=this.optimize(this._rotmatrix, trans, this._transsolver,i_offset.vertex, vertex_2d);
160- //エラー値が低かったら値を差換え
161- if (err2 < err) {
162- // 良い値が取れたら、差換え
163- this.updateMatrixValue(this._rotmatrix, trans,o_result_conv);
164- }
165- err=err2;
166- }
167- //エラー値保存
168- o_result_conv.error=err;
169- return;
170- }
171- private double optimize(NyARRotMatrix_ARToolKit io_rotmat,NyARDoublePoint3d io_transvec,INyARTransportVectorSolver i_solver,NyARDoublePoint3d[] i_offset_3d,NyARDoublePoint2d[] i_2d_vertex) throws NyARException
172- {
173- NyARDoublePoint3d[] vertex_3d=this.__transMat_vertex_3d;
174- double err = -1;
175- //System.out.println("START");
176- // ループを抜けるタイミングをARToolKitと合わせるために変なことしてます。
177- for (int i = 0;; i++) {
178- // <arGetTransMat3>
179- err = this._mat_optimize.modifyMatrix(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex);
180- io_rotmat.getPoint3dBatch(i_offset_3d,vertex_3d,4);
181- i_solver.solveTransportVector(vertex_3d, io_transvec);
182-
183- err = this._mat_optimize.modifyMatrix(io_rotmat, io_transvec, i_offset_3d, i_2d_vertex);
184- //System.out.println("E:"+err*4);
185- // //</arGetTransMat3>
186- if (err < AR_GET_TRANS_MAT_MAX_FIT_ERROR || i == AR_GET_TRANS_MAT_MAX_LOOP_COUNT - 1) {
187- break;
188- }
189- io_rotmat.getPoint3dBatch(i_offset_3d,vertex_3d,4);
190- i_solver.solveTransportVector(vertex_3d, io_transvec);
191- }
192- //System.out.println("END");
193- return err;
194- }
195- /**
196- * パラメータで変換行列を更新します。
197- *
198- * @param i_rot
199- * @param i_off
200- * @param i_trans
201- */
202- public void updateMatrixValue(NyARRotMatrix i_rot,NyARDoublePoint3d i_trans,NyARTransMatResult o_result)
203- {
204- o_result.m00=i_rot.m00;
205- o_result.m01=i_rot.m01;
206- o_result.m02=i_rot.m02;
207- o_result.m03=i_trans.x;
208-
209- o_result.m10 = i_rot.m10;
210- o_result.m11 = i_rot.m11;
211- o_result.m12 = i_rot.m12;
212- o_result.m13 = i_trans.y;
213-
214- o_result.m20 = i_rot.m20;
215- o_result.m21 = i_rot.m21;
216- o_result.m22 = i_rot.m22;
217- o_result.m23 = i_trans.z;
218-
219- o_result.has_value = true;
220- return;
221- }
222-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/INyARTransMat.java (revision 191)
+++ napkit/tags/napkit-m22/lib/NyARToolkit-2.5.2/src/jp/nyatla/nyartoolkit/core/transmat/INyARTransMat.java (nonexistent)
@@ -1,45 +0,0 @@
1-/*
2- * PROJECT: NyARToolkit
3- * --------------------------------------------------------------------------------
4- * This work is based on the original ARToolKit developed by
5- * Hirokazu Kato
6- * Mark Billinghurst
7- * HITLab, University of Washington, Seattle
8- * http://www.hitl.washington.edu/artoolkit/
9- *
10- * The NyARToolkit is Java edition ARToolKit class library.
11- * Copyright (C)2008-2009 Ryo Iizuka
12- *
13- * This program is free software: you can redistribute it and/or modify
14- * it under the terms of the GNU General Public License as published by
15- * the Free Software Foundation, either version 3 of the License, or
16- * (at your option) any later version.
17- *
18- * This program is distributed in the hope that it will be useful,
19- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21- * GNU General Public License for more details.
22- *
23- * You should have received a copy of the GNU General Public License
24- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25- *
26- * For further information please contact.
27- * http://nyatla.jp/nyatoolkit/
28- * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
29- *
30- */
31-package jp.nyatla.nyartoolkit.core.transmat;
32-
33-import jp.nyatla.nyartoolkit.NyARException;
34-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
35-
36-
37-/**
38- * This class calculates ARMatrix from square information. -- 変換行列を計算するクラス。
39- *
40- */
41-public interface INyARTransMat
42-{
43- public void transMat(NyARSquare i_square,NyARRectOffset i_offset, NyARTransMatResult o_result) throws NyARException;
44- public void transMatContinue(NyARSquare i_square,NyARRectOffset i_offset, NyARTransMatResult io_result_conv) throws NyARException;
45-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
Show on old repository browser