ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr,
                             const int keyboardWidth, const int keyboardHeight, const int gridWidth,
                             const int gridHeight, const int mostCommonKeyWidth, const int mostCommonKeyHeight,
                             const jintArray proximityChars, const int keyCount, const jintArray keyXCoordinates,
                             const jintArray keyYCoordinates, const jintArray keyWidths, const jintArray keyHeights,
                             const jintArray keyCharCodes, const jfloatArray sweetSpotCenterXs,
                             const jfloatArray sweetSpotCenterYs, const jfloatArray sweetSpotRadii)
    : GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight), MOST_COMMON_KEY_WIDTH(mostCommonKeyWidth),
      MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidth * mostCommonKeyWidth),
      MOST_COMMON_KEY_HEIGHT(mostCommonKeyHeight),
      NORMALIZED_SQUARED_MOST_COMMON_KEY_HYPOTENUSE(1.0f +
              SQUARE_FLOAT(static_cast<float>(mostCommonKeyHeight) /
                           static_cast<float>(mostCommonKeyWidth))),
      CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth),
      CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight),
      KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)),
      KEYBOARD_WIDTH(keyboardWidth), KEYBOARD_HEIGHT(keyboardHeight),
      KEYBOARD_HYPOTENUSE(hypotf(KEYBOARD_WIDTH, KEYBOARD_HEIGHT)),
      HAS_TOUCH_POSITION_CORRECTION_DATA(keyCount > 0 && keyXCoordinates && keyYCoordinates
                                         && keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs
                                         && sweetSpotCenterYs && sweetSpotRadii),
      mProximityCharsArray(new int[GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE
                                   /* proximityCharsLength */]),
      mCodeToKeyMap() {
    /* Let's check the input array length here to make sure */
    const jsize proximityCharsLength = env->GetArrayLength(proximityChars);
    if (proximityCharsLength != GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE) {
        AKLOGE("Invalid proximityCharsLength: %d", proximityCharsLength);
        ASSERT(false);
        return;
    }
    if (DEBUG_PROXIMITY_INFO) {
        AKLOGI("Create proximity info array %d", proximityCharsLength);
    }
    const jsize localeCStrUtf8Length = env->GetStringUTFLength(localeJStr);
    if (localeCStrUtf8Length >= MAX_LOCALE_STRING_LENGTH) {
        AKLOGI("Locale string length too long: length=%d", localeCStrUtf8Length);
        ASSERT(false);
    }
    memset(mLocaleStr, 0, sizeof(mLocaleStr));
    env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), mLocaleStr);
    safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityCharsLength,
                                    mProximityCharsArray);
    safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates);
    safeGetOrFillZeroIntArrayRegion(env, keyYCoordinates, KEY_COUNT, mKeyYCoordinates);
    safeGetOrFillZeroIntArrayRegion(env, keyWidths, KEY_COUNT, mKeyWidths);
    safeGetOrFillZeroIntArrayRegion(env, keyHeights, KEY_COUNT, mKeyHeights);
    safeGetOrFillZeroIntArrayRegion(env, keyCharCodes, KEY_COUNT, mKeyCodePoints);
    safeGetOrFillZeroFloatArrayRegion(env, sweetSpotCenterXs, KEY_COUNT, mSweetSpotCenterXs);
    safeGetOrFillZeroFloatArrayRegion(env, sweetSpotCenterYs, KEY_COUNT, mSweetSpotCenterYs);
    safeGetOrFillZeroFloatArrayRegion(env, sweetSpotRadii, KEY_COUNT, mSweetSpotRadii);
    initializeG();
}
Beispiel #2
0
/*!
 * Constructor
 */
ActiveContourSeed::ActiveContourSeed(Protobuf *seedData, int protobuf_index,
		bool useCellSpecificParameters,
		ActiveContourParameters *default_parameters,
		Image3D<float> *fullSegmentation, Image3D<float> *g_full,
		CallbackFunctions *callback) {
	// set up callback
	cb = callback;

	// set active contour parameters
	p_ = new ActiveContourParameters;
	p_->hsz = default_parameters->hsz;
	p_->tMax = default_parameters->tMax;
	p_->dt = default_parameters->dt;
	p_->sussmanInterval = default_parameters->sussmanInterval;
	p_->c = default_parameters->c;
	p_->d = default_parameters->d;
	p_->epsilon = default_parameters->epsilon;
	p_->r = default_parameters->r;
	p_->narrowBandThreshold = default_parameters->narrowBandThreshold;
	p_->res_x = default_parameters->res_x;
	p_->res_y = default_parameters->res_y;
	p_->res_z = default_parameters->res_z;

	// future work: option to use cell specific parameters
	useCellSpecificParameters = 0;
	if (useCellSpecificParameters) {
		log(cb,0,"Functionality to use cell specific parameters is not implemented, using default parameters");
	}

	// set up miscellaneous parameters
	_tElapse = 0;
	float xC, yC, zC;
	seedData->getSeedCenter(protobuf_index, xC, yC, zC);
	_xC = (int) xC;
	_yC = (int) yC;
	_zC = (int) zC;
	_seedIdx = seedData->getSeedIdx(protobuf_index);
	if (_seedIdx == 0.0f) {
		BOOST_THROW_EXCEPTION(Exception("Error: cannot set an active contour seed index to 0; this is reserved for background voxels"));
	}
	_hszX = (int) (p_->hsz / p_->res_x);
	_hszY = (int) (p_->hsz / p_->res_y);
	_hszZ = (int) (p_->hsz / p_->res_z);
	_dimx_Rel = 2 * _hszX + 1;
	_dimy_Rel = 2 * _hszY + 1;
	_dimz_Rel = 2 * _hszZ + 1;
	fullSegmentation->getDimensions(_dimx_Abs, _dimy_Abs, _dimz_Abs);

	// set up narrow band storage
	narrowBand_x = new Array1D<int> (cb);
	narrowBand_y = new Array1D<int> (cb);
	narrowBand_z = new Array1D<int> (cb);
	narrowBand_DphiDt = new Array1D<float> (cb);
	narrowBand_x->resize(_dimx_Rel * _dimy_Rel * _dimz_Rel);
	narrowBand_y->resize(_dimx_Rel * _dimy_Rel * _dimz_Rel);
	narrowBand_z->resize(_dimx_Rel * _dimy_Rel * _dimz_Rel);
	narrowBand_DphiDt->resize(_dimx_Rel * _dimy_Rel * _dimz_Rel);

	// set up fullSeg
	fullSeg = fullSegmentation;

	// set up phi
	phi_ = new Image3D<float> (cb);

	initializePhi(protobuf_index, seedData);

	// set up g
	g = new Image3D<float> (cb);
	g_x = new Image3D<float> (cb);
	g_y = new Image3D<float> (cb);
	g_z = new Image3D<float> (cb);
	initializeG(g_full);
}