Ejemplo n.º 1
0
        /**
         * ストリームから読み出したデータでインスタンスを初期化します。
         * @param i_stream
         * @throws NyARRuntimeException
         */
        public ParamLoader(Stream i_stream, int i_screen_width, int i_screen_height)
        {
            //読み出し
            byte[] data = jp.nyatla.nyartoolkit.cs.cs4.BinaryReader.toArray(i_stream);
            jp.nyatla.nyartoolkit.cs.cs4.BinaryReader bis = new jp.nyatla.nyartoolkit.cs.cs4.BinaryReader(data, jp.nyatla.nyartoolkit.cs.cs4.BinaryReader.ENDIAN_BIG);
            //読み出したサイズでバージョンを決定
            int[] version_table = { 136, 144, 152, 176 };
            int   version       = -1;

            for (int i = 0; i < version_table.Length; i++)
            {
                if (data.Length % version_table[i] == 0)
                {
                    version = i + 1;
                    break;
                }
            }
            //一致しなければ無し
            if (version == -1)
            {
                throw new NyARRuntimeException();
            }
            int camera_width  = bis.getInt();
            int camera_height = bis.getInt();

            //size
            this.size = new NyARIntSize(i_screen_width, i_screen_height);
            double x_scale = (double)i_screen_width / (double)(camera_width);   // scale = (double)xsize / (double)(source->xsize);
            double y_scale = (double)i_screen_height / (double)(camera_height); // scale = (double)ysize / (double)(source->ysize);

            //projection matrix
            this.pmat = new NyARPerspectiveProjectionMatrix();
            double[] pjv = bis.getDoubleArray(new double[16], 12);
            pjv[12] = pjv[13] = pjv[14] = 0; pjv[15] = 1;
            this.pmat.setValue(pjv);
            this.pmat.changeScale(x_scale, y_scale);

            //dist factor
            switch (version)
            {
            case 1:    //Version1
                this.dist_factor = new NyARCameraDistortionFactorV2(bis.getDoubleArray(new double[NyARCameraDistortionFactorV2.NUM_OF_FACTOR]), x_scale, y_scale);
                break;

            case 4:    //Version4
                this.dist_factor = new NyARCameraDistortionFactorV4(bis.getDoubleArray(new double[NyARCameraDistortionFactorV4.NUM_OF_FACTOR]), x_scale, y_scale);
                break;

            default:
                throw new NyARRuntimeException();
            }
        }
        /**
         * @param i_src
         * isetファイルイメージを格納したbyte配列
         */
        public IsetFileDataParserV5Raw(byte[] i_src)
        {
            BinaryReader br = new jp.nyatla.nyartoolkit.cs.cs4.BinaryReader(i_src, jp.nyatla.nyartoolkit.cs.cs4.BinaryReader.ENDIAN_LITTLE);

            this.image_width  = br.getInt();
            this.image_height = br.getInt();
            this.image        = br.getByteArray(this.image_width * this.image_height);
            this.dpis         = new float[br.getInt()];
            for (int i = 0; i < this.dpis.Length; i++)
            {
                this.dpis[i] = br.getFloat();
            }
            return;
        }
        public static NyARNftFreakFsetFile loadFromfset3File(byte[] i_source)
        {
            jp.nyatla.nyartoolkit.cs.cs4.BinaryReader br = new jp.nyatla.nyartoolkit.cs.cs4.BinaryReader(i_source, jp.nyatla.nyartoolkit.cs.cs4.BinaryReader.ENDIAN_LITTLE);
            int num = br.getInt();

            RefDataSet[] rds = new RefDataSet[num];

            for (int i = 0; i < num; i++)
            {
                RefDataSet rd = new RefDataSet();
                rd.coord2D.x = br.getFloat();
                rd.coord2D.y = br.getFloat();
                rd.coord3D.x = br.getFloat();
                rd.coord3D.y = br.getFloat();
                br.getByteArray(rd.featureVec.v);
                rd.featureVec.angle  = br.getFloat();
                rd.featureVec.scale  = br.getFloat();
                rd.featureVec.maxima = br.getInt();
                rd.pageNo            = br.getInt();
                rd.refImageNo        = br.getInt();
                rds[i] = rd;
            }

            int page_num = br.getInt();

            PageInfo[] kpi = new PageInfo[page_num];
            for (int i = 0; i < page_num; i++)
            {
                int         page_no = br.getInt();
                int         img_num = br.getInt();
                ImageInfo[] kii     = new ImageInfo[img_num];
                for (int i2 = 0; i2 < img_num; i2++)
                {
                    kii[i2] = new ImageInfo(br.getInt(), br.getInt(), br.getInt());
                }
                kpi[i] = new PageInfo(page_no, kii);
            }
            return(new NyARNftFreakFsetFile(rds, kpi));
        }
        public static NyARNftDataSetFile loadFromNftFilePack(byte[] i_byte)
        {
            jp.nyatla.nyartoolkit.cs.cs4.BinaryReader br = new jp.nyatla.nyartoolkit.cs.cs4.BinaryReader(i_byte, jp.nyatla.nyartoolkit.cs.cs4.BinaryReader.ENDIAN_LITTLE);
            //タイプチェック
            String header = byteArray2NullTerminateStr(br.getByteArray(32));

            if (header.CompareTo(HS_NFTPACK_V1) != 0)
            {
                throw new NyARRuntimeException("Invalid header");
            }

            //Entryの取得
            int num_of_entry = br.getInt();

            if (num_of_entry != 3)
            {
                throw new NyARRuntimeException("Invalid entry size");
            }
            int[] entry_info = br.getIntArray(num_of_entry * 2);
            return(new NyARNftDataSetFile(
                       NyARNftIsetFile.loadFromIsetFile(br.getByteArray(entry_info[2 * 0 + 1]), NyARNftIsetFile.FILE_FORMAT_ARTK_V5RAW),
                       NyARNftFsetFile.loadFromFsetFile(br.getByteArray(entry_info[2 * 1 + 1])),
                       NyARNftFreakFsetFile.loadFromfset3File(br.getByteArray(entry_info[2 * 2 + 1]))));
        }