`normalize` C++ Examples

60 C++ code examples are found related to "normalize". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: yacclab_tensor.cc    From YACCLAB with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
void YacclabTensorOutput2D::NormalizeLabels() {
    std::map<int, int> map_new_labels;
    int i_max_new_label = 0;

    for (int r = 0; r < mat_.rows; ++r) {
        unsigned * const mat_row = mat_.ptr<unsigned>(r);
        for (int c = 0; c < mat_.cols; ++c) {
            int iCurLabel = mat_row[c];
            if (iCurLabel > 0) {
                if (map_new_labels.find(iCurLabel) == map_new_labels.end()) {
                    map_new_labels[iCurLabel] = ++i_max_new_label;
                }
                mat_row[c] = map_new_labels.at(iCurLabel);
            }
        }
    }
} 
Example 2
Source File: debug_render_impl.cc    From lullaby with Apache License 2.0 7 votes vote down vote up
static NormalizedCoordinates NormalizeScreenCoordinates(
    const mathfu::vec2& pixel_pos0, const mathfu::vec2& pixel_pos1,
    const mathfu::vec2i& dimensions) {
  // Flip Y axis from Y-down to Y-up, preserving quad winding.
  const float sx = 2.0f / dimensions.x;
  const float sy = 2.0f / dimensions.y;
  const float x0 = sx * pixel_pos0.x - 1.0f;
  const float y0 = 1.0f - sy * pixel_pos0.y;
  const float x1 = sx * pixel_pos1.x - 1.0f;
  const float y1 = 1.0f - sy * pixel_pos1.y;
  const float z = -1.0f;
  const NormalizedCoordinates coords = {
    mathfu::vec3(x0, y1, z),
    mathfu::vec3(x1, y0, z)
  };
  return coords;
} 
Example 3
Source File: Q3BSPFileImporter.cpp    From VulkanDemos with MIT License 7 votes vote down vote up
static void normalizePathName( const std::string &rPath, std::string &normalizedPath ) {
    normalizedPath = "";
    if (rPath.empty()) {
        return;
    }

#ifdef _WIN32
    std::string sep = "\\";
#else
    std::string sep = "/";
#endif

    static const unsigned int numDelimiters = 2;
    const char delimiters[ numDelimiters ] = { '/', '\\' };
    normalizedPath = rPath;
    for (const char delimiter : delimiters) {
        for ( size_t j=0; j<normalizedPath.size(); ++j ) {
            if ( normalizedPath[j] == delimiter ) {
                normalizedPath[ j ] = sep[ 0 ];
            }
        }
    }
} 
Example 4
Source File: Unicode.cpp    From apfs-fuse with GNU General Public License v2.0 7 votes vote down vote up
int normalizeOptFoldU32Char(char32_t ch, bool case_fold, char32_t *nfd, uint8_t *ccc)
{
	char32_t ch_idx;
	uint16_t hi_res;
	uint16_t mi_res;
	uint16_t lo_res;
	const uint16_t *seq_u16 = 0;
	const uint32_t *seq_u32 = 0;
	uint32_t seq_len = 0;
	uint32_t cnt;
	char32_t c;

	ccc[0] = 0;
	if (ch >= 0xF0000)
	{
		if ((ch & 0xFFFE) == 0xFFFE)
			return -1;
		else
		{
			nfd[0] = ch;
			return 1;
		}
	} 
Example 5
Source File: matrix.c    From btrf with BSD 2-Clause "Simplified" License 7 votes vote down vote up
void normalizeMatrix(Matrix *mat) {
	cellValueT lowest = minMatrix(mat, NULL, NULL);
	cellValueT highest = maxMatrix(mat, NULL, NULL);
	cellValueT *ptr = mat->cellValues;
	cellValueT val;
	double interval;
	matrixSizeT i = matSize(mat);

	interval = highest - lowest;

	// normalize
	ptr = mat->cellValues;
	i = matSize(mat);
	while (i--) {
		val = abs(*ptr);
		*(ptr++) = (cellValueT)(((double)(val - lowest) / interval) * 255.0);
	}
} 
Example 6
Source File: WorldGenerator.cpp    From programming-abstractions with MIT License 7 votes vote down vote up
static void normalizeTerrain(Grid<double>& heights) {
  /* Compute the maximum and minimum heights. */
  double maxHeight = -numeric_limits<double>::infinity();
  double minHeight = numeric_limits<double>::infinity();
  for (int row = 0; row < heights.numRows(); row++) {
    for (int col = 0; col < heights.numCols(); col++) {
      maxHeight = max(maxHeight, heights[row][col]);
      minHeight = min(minHeight, heights[row][col]);
    }
  }
  
  /* Remap everything from the range [minHeight, maxHeight] to [0, 1]. */
  double range = maxHeight - minHeight;
  for (int row = 0; row < heights.numRows(); row++) {
    for (int col = 0; col < heights.numCols(); col++) {
      heights[row][col] -= minHeight;
      heights[row][col] /= range;
    }
  }
} 
Example 7
Source File: SDL_x11xinput2.c    From awtk with GNU Lesser General Public License v2.1 7 votes vote down vote up
static void
xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
    double in_x, double in_y, float *out_x, float *out_y)
{
    int i;
    for (i = 0; i < videodata->numwindows; i++) {
        SDL_WindowData *d = videodata->windowlist[i];
        if (d->xwindow == window) {
            if (d->window->w == 1) {
                *out_x = 0.5f;
            } else {
                *out_x = in_x / (d->window->w - 1);
            }
            if (d->window->h == 1) {
                *out_y = 0.5f;
            } else {
                *out_y = in_y / (d->window->h - 1);
            }
            return;
        } 
Example 8
Source File: MixBiNormal.cc    From zerospeech2017 with GNU General Public License v3.0 7 votes vote down vote up
void
MixBiNormal::normalizeAlphasWithNoise()
{
  // Normalize alphas.
  int l;
  double tmp = 0.0;
  for (l=0;l<NumMixComps;l++) {
    tmp += cur_alphas[l];
  }  

  // added to each one.
  double noise = tmp/NumMixComps;
  tmp += tmp;

  const double inv_tmp = 1.0/tmp;
  for (l=0;l<NumMixComps;l++) {
    cur_alphas[l] += noise;
    cur_alphas[l] *= inv_tmp;
  }
} 
Example 9
Source File: mesh.cc    From cvkit with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
void Mesh::normalizeNormals()
{
  for (int i=3*(getVertexCount()-1); i>=0; i-=3)
  {
    float len=(float) sqrt(normal[i]*normal[i]+
                           normal[i+1]*normal[i+1]+
                           normal[i+2]*normal[i+2]);

    if (len > 0)
    {
      normal[i]/=len;
      normal[i+1]/=len;
      normal[i+2]/=len;
    }
  }
} 
Example 10
Source File: lz_encoder_mf.c    From rom-properties with GNU General Public License v2.0 7 votes vote down vote up
static void
normalize(lzma_mf *mf)
{
	assert(mf->read_pos + mf->offset == MUST_NORMALIZE_POS);
	uint32_t i = 0;
	// In future we may not want to touch the lowest bits, because there
	// may be match finders that use larger resolution than one byte.
	const uint32_t subvalue
			= (MUST_NORMALIZE_POS - mf->cyclic_size);
				// & (~(UINT32_C(1) << 10) - 1);

	for (i = 0; i < mf->hash_count; ++i) {
		// If the distance is greater than the dictionary size,
		// we can simply mark the hash element as empty.
		if (mf->hash[i] <= subvalue)
			mf->hash[i] = EMPTY_HASH_VALUE;
		else
			mf->hash[i] -= subvalue;
	} 
Example 11
Source File: duration.cpp    From ros_lecture with MIT License 7 votes vote down vote up
void normalizeSecNSecSigned(int32_t &sec, int32_t &nsec)
{
  int32_t nsec_part = nsec;
  int32_t sec_part = sec;

  while (nsec_part > 1000000000L)
  {
    nsec_part -= 1000000000L;
    ++sec_part;
  }
  while (nsec_part < 0)
  {
    nsec_part += 1000000000L;
    --sec_part;
  }
  sec = sec_part;
  nsec = nsec_part;
} 
Example 12
Source File: unicode.cc    From sling with Apache License 2.0 7 votes vote down vote up
int Unicode::Normalize(int c, int flags) {
  if (c & unicode_tab_mask) return c;
  if (flags & NORMALIZE_CASE) {
    c = unicode_lower_tab[c];
  }
  if (flags & NORMALIZE_LETTERS) {
    c = unicode_normalize_tab[c];
  }
  if (flags & NORMALIZE_DIGITS) {
    if (IsDigit(c)) c = '9';
  }
  if (flags & NORMALIZE_PUNCTUATION) {
    if (IsPunctuation(c)) c = 0;
  }
  if (flags & NORMALIZE_NAME) {
    if (IsNamePunctuation(c)) c = 0;
  }
  if (flags & NORMALIZE_WHITESPACE) {
    if (IsWhitespace(c)) c = 0;
  }
  return c;
} 
Example 13
Source File: GLVector.cpp    From OrionUO with MIT License 7 votes vote down vote up
void CVector::Normalize()
{
    WISPFUN_DEBUG("c38_f1");
    if (!X && !Y && !Z)
        return;

    double result = X * X + Y * Y + Z * Z;

    //if (result)
    {
        result = sqrtl(result);

        X /= result;
        Y /= result;
        Z /= result;
    }
} 
Example 14
Source File: monoembedding.cpp    From electron-edge-js with Apache License 2.0 7 votes vote down vote up
void MonoEmbedding::NormalizeException(MonoException** e) 
{
    static MonoMethod* method;

    if (!method)
    {
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "NormalizeException", -1);
    }

    void *params[] = { *e };
    MonoException *exc = NULL;
    MonoException *en = (MonoException*)mono_runtime_invoke(method, NULL, params, (MonoObject**)exc);
    if (NULL == exc)
    {
        *e = en;
    }
} 
Example 15
Source File: SkMatrix.cpp    From ZUI with MIT License 7 votes vote down vote up
static void normalize_perspective(SkScalar mat[9]) {
    // If it was interesting to never store the last element, we could divide all 8 other
    // elements here by the 9th, making it 1.0...
    //
    // When SkScalar was SkFixed, we would sometimes rescale the entire matrix to keep its
    // component values from getting too large. This is not a concern when using floats/doubles,
    // so we do nothing now.

    // Disable this for now, but it could be enabled.
#if 0
    if (0 == mat[SkMatrix::kMPersp0] && 0 == mat[SkMatrix::kMPersp1]) {
        SkScalar p2 = mat[SkMatrix::kMPersp2];
        if (p2 != 0 && p2 != 1) {
            double inv = 1.0 / p2;
            for (int i = 0; i < 6; ++i) {
                mat[i] = SkDoubleToScalar(mat[i] * inv);
            }
            mat[SkMatrix::kMPersp2] = 1;
        }
    }
#endif
} 
Example 16
Source File: mixing.cpp    From Marlin_2.0.X_Beta_Alfawise_Ux0 with GNU General Public License v3.0 7 votes vote down vote up
void Mixer::normalize(const uint8_t tool_index) {
  float cmax = 0;
  #ifdef MIXER_NORMALIZER_DEBUG
    float csum = 0;
  #endif
  MIXER_STEPPER_LOOP(i) {
    const float v = collector[i];
    NOLESS(cmax, v);
    #ifdef MIXER_NORMALIZER_DEBUG
      csum += v;
    #endif
  }
  #ifdef MIXER_NORMALIZER_DEBUG
    SERIAL_ECHOPGM("Mixer: Old relation : [ ");
    MIXER_STEPPER_LOOP(i) {
      SERIAL_ECHO_F(collector[i] / csum, 3);
      SERIAL_CHAR(' ');
    } 
Example 17
Source File: math.cpp    From SLib with MIT License 7 votes vote down vote up
SLIB_INLINE static T normalizeDegree(T v) noexcept
			{
				if (Math::isNaN(v)) {
					return 0;
				}
				sl_int32 n = (sl_int32)v;
				T f = v - n;
				if (f < 0) {
					f = 1 + f;
					n--;
				}
				n = n % 360;
				if (n < 0) {
					n += 360;
				}
				v = (T)(n) + f;
				return v;
			} 
Example 18
Source File: rational.cpp    From deepin-calculator with GNU General Public License v3.0 7 votes vote down vote up
void Rational::normalize()
{
    if (m_denom == 0) {
        m_valid = false;
        return;
    }
    if (m_num == 0) {
        m_denom = 1;
        return;
    }
    int g = gcd(abs(m_num), abs(m_denom));
    m_num /= g;
    m_denom /= g;
    if (m_denom < 0) {
        m_num = -m_num;
        m_denom = -m_denom;
    }
} 
Example 19
Source File: channel_args.cc    From grpc-nebula-c with Apache License 2.0 7 votes vote down vote up
grpc_channel_args* grpc_channel_args_normalize(const grpc_channel_args* a) {
  grpc_arg** args =
      static_cast<grpc_arg**>(gpr_malloc(sizeof(grpc_arg*) * a->num_args));
  for (size_t i = 0; i < a->num_args; i++) {
    args[i] = &a->args[i];
  }
  if (a->num_args > 1)
    qsort(args, a->num_args, sizeof(grpc_arg*), cmp_key_stable);

  grpc_channel_args* b =
      static_cast<grpc_channel_args*>(gpr_malloc(sizeof(grpc_channel_args)));
  b->num_args = a->num_args;
  b->args = static_cast<grpc_arg*>(gpr_malloc(sizeof(grpc_arg) * b->num_args));
  for (size_t i = 0; i < a->num_args; i++) {
    b->args[i] = copy_arg(args[i]);
  }

  gpr_free(args);
  return b;
} 
Example 20
Source File: eigennormalize.cpp    From inviwo with BSD 2-Clause "Simplified" License 7 votes vote down vote up
void EigenNormalize::process() {
    auto m = in_.getData();
    switch (method_.get()) {
        case Method::MaxElement: {
            auto maxV = m->maxCoeff();
            out_.setData(std::make_shared<Eigen::MatrixXf>((*m) / maxV));
            break;
        }
        case Method::MinMaxElement: {
            auto minV = m->minCoeff();
            auto maxV = m->maxCoeff();
            auto m2 = std::make_shared<Eigen::MatrixXf>(*m);
            m2->array() -= minV;
            m2->array() /= maxV - minV;
            out_.setData(m2);
            break;
        }
        case Method::Normalize:
            out_.setData(std::make_shared<Eigen::MatrixXf>(m->normalized()));
            break;
    }
} 
Example 21
Source File: Channel.cpp    From Rustla2 with MIT License 7 votes vote down vote up
Status Channel::NormalizeAdvancedChannel(std::string *channel) {
  try {
    auto channel_uri = folly::Uri(*channel);

    if (channel_uri.scheme() != "http" && channel_uri.scheme() != "https") {
      return Status(StatusCode::VALIDATION_ERROR,
                    "invalid advanced url schema. must be http or https");
    }

    *channel = channel_uri.str();
  } catch (const std::invalid_argument &e) {
    return Status(StatusCode::VALIDATION_ERROR, "invalid advanced url");
  }

  return Status::OK;
} 
Example 22
Source File: Sentence.cpp    From EventEntityExtractor with GNU Lesser General Public License v3.0 7 votes vote down vote up
void Sentence::NormalizeWords() {
	for (int s = 0; s < words.size(); ++s) {
		string word = words[s];

		// normalize digits
		bool is_number = true;
		for (int i = 0; i < word.size(); ++i) {
			if (!(word[i] >= '0' && word[i] <= '9')) {
				is_number = false;
				break;
			}
		}
		if (is_number) {
			lemmas[s] = "NUMNUM";
		} else if (word.find('@') != string::npos && word.find(".com") != string::npos) {
			lemmas[s] = "@EMAIL";
		} else { 
Example 23
Source File: yacclab_tensor.cc    From YACCLAB with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void YacclabTensorOutput3D::NormalizeLabels() {
    std::map<int, int> map_new_labels;
    int i_max_new_label = 0;

    if (mat_.dims == 3) {
        for (int z = 0; z < mat_.size[0]; z++) {
            for (int y = 0; y < mat_.size[1]; y++) {
                unsigned int * img_labels_row = reinterpret_cast<unsigned int *>(mat_.data + z * mat_.step[0] + y * mat_.step[1]);
                for (int x = 0; x < mat_.size[2]; x++) {
                    int iCurLabel = img_labels_row[x];
                    if (iCurLabel > 0) {
                        if (map_new_labels.find(iCurLabel) == map_new_labels.end()) {
                            map_new_labels[iCurLabel] = ++i_max_new_label;
                        }
                        img_labels_row[x] = map_new_labels.at(iCurLabel);
                    }
                }
            }
        }
    }
} 
Example 24
Source File: JMD_Math_Common.cpp    From ChromaTag with MIT License 6 votes vote down vote up
void JMD::JMD_Utils_Math::Vector_Normalize(vector<double> *vector_param) 
{
	//get length
	float length = Vector_Length(vector_param);
	
	//normalize elements
	for(vector<double>::iterator iter=vector_param->begin(); iter != vector_param->end(); ++iter)
	{
		*iter /= length;
	}
} 
Example 25
Source File: Normalize.cpp    From NiuTensor with Apache License 2.0 6 votes vote down vote up
void _Normalize(const XTensor * input, XTensor * output, int dim, 
                const XTensor * mean, const XTensor * var, 
                const XTensor * a, const XTensor * b, DTYPE epsilon)
{
    CheckNTErrors((_IsSameShaped(input, output)), "Unmatched input tensors!");
    CheckNTErrors((_IsSameShaped(a, b)), "Unmatched input tensors");
    CheckNTErrors((_IsSameShaped(mean, var)), "Unmatched input tensors");
    CheckNTErrors((input && output && mean && var && a && b), "Empty input tensors!");
    CheckNTErrors((dim >= 0 && dim < input->order), "Incorrect reduction dimension!");
    CheckNTErrors((input->order == mean->order + 1), "Incorrect reduction dimension!");

    int stride = 1;
    int strideNum = input->dimSize[dim];
    int blockSize = 1;
    int blockNum = 1;
    for (int i = 0; i < input->order; i++) {
        if (i < dim) {
            CheckNTErrors((input->dimSize[i] == mean->dimSize[i]), "Wrong size!");
            blockNum *= input->dimSize[i];
        }
        else if (i > dim) {
            CheckNTErrors((input->dimSize[i] == mean->dimSize[i - 1]), "Wrong size!");
            stride *= input->dimSize[i];
        }
    } 
Example 26
Source File: JMD_Math_Common.cpp    From ChromaTag with MIT License 6 votes vote down vote up
void JMD::JMD_Utils_Math::Vector_Normalize(float *vector_param, unsigned int size_param) 
{
	//get length
	float length = Vector_Length(vector_param, size_param);
	
	//normalize elements
	for( int i=0; i < size_param; i++ ) { vector_param[i] /= length; }
} 
Example 27
Source File: ApiRouter.cpp    From xmrig-amd with GNU General Public License v3.0 6 votes vote down vote up
static inline rapidjson::Value normalize(double d)
{
    using namespace rapidjson;

    if (!isnormal(d)) {
        return Value(kNullType);
    }

    return Value(floor(d * 100.0) / 100.0);
} 
Example 28
Source File: maximal_inputs.cpp    From echo with MIT License 6 votes vote down vote up
void NormalizeColByMax(const arma::mat &input,
                       arma::mat &output)
{
  output.set_size(input.n_rows, input.n_cols);
  for (arma::uword i = 0; i != input.n_cols; ++i)
  {
    const double max = arma::max(arma::abs(input.col(i)));
    if (max != 0.0)
    {
      output.col(i) = input.col(i) / max;
    }
    else
    {
      output.col(i) = input.col(i);
    }
  } 
Example 29
Source File: SkGaussFilter.cpp    From ZUI with MIT License 6 votes vote down vote up
static void normalize(int n, double* gauss) {
    // Carefully add from smallest to largest to calculate the normalizing sum.
    double sum = 0;
    for (int i = n-1; i >= 1; i--) {
        sum += 2 * gauss[i];
    }
    sum += gauss[0];

    // Normalize gauss.
    for (int i = 0; i < n; i++) {
        gauss[i] /= sum;
    }

    // The factors should sum to 1. Take any remaining slop, and add it to gauss[0]. Add the
    // values in such a way to maintain the most accuracy.
    sum = 0;
    for (int i = n - 1; i >= 1; i--) {
        sum += 2 * gauss[i];
    }

    gauss[0] = 1 - sum;
} 
Example 30
Source File: civil_time.cc    From zetasql with Apache License 2.0 6 votes vote down vote up
void NormalizeDatetime(int64_t* y, int32_t* mo, int32_t* d, int32_t* h, int32_t* m,
                       int32_t* s, int64_t* ns) {
  int64_t carry_seconds = zetasql_base::MathUtil::FloorOfRatio(*ns, kNanosPerSecond);
  absl::CivilSecond cs(*y, *mo, *d, *h, *m, *s);
  cs += carry_seconds;
  *y = cs.year();
  *mo = cs.month();
  *d = cs.day();
  *h = cs.hour();
  *m = cs.minute();
  *s = cs.second();
  *ns -= (carry_seconds * kNanosPerSecond);
  // The CivilTime constructor should have coerced all the time values to the
  // appropriate range.
  DCHECK(IsValidTimeFields(*h, *m, *s, *ns));
} 
Example 31
Source File: IntDistribution.cc    From w2rap-contigger with MIT License 6 votes vote down vote up
void IntDistribution::_normalize()
{
  const int x0 = _prob.x_min();
  const int x1 = _prob.x_max();
    
  ForceAssertGe(_prob[x0], 0.0);
  _prob_le[x0] = _prob[x0];
  for (int x = x0 + 1; x <= x1; x++) {
    const real_t p = _prob[x];
    ForceAssertGe(p, 0.0);
    _prob_le[x] = _prob_le[x - 1] + p;
  }
  
  const real_t sum = _prob_le[x1];
  if (sum == 0.0) {
    _prob = IntFunction<real_t>(); // this signals an invalid distribution
  }
  else { 
Example 32
Source File: domset.cc    From EGSfM with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void Domset::deNormalizePointCloud()
{
  const size_t numPoints( points.size() );
// denormalizing points
#if OPENMVG_USE_OPENMP
#pragma omp parallel for
#endif
  for_parallel( i, numPoints )
  {
    points[ i ].pos = ( points[ i ].pos / normScale ) + pcCentre.pos;
  }

  const size_t numOldPoints( origPoints.size() );
#if OPENMVG_USE_OPENMP
#pragma omp parallel for
#endif
  for_parallel( i, numOldPoints )
  {
    origPoints[ i ].pos = ( origPoints[ i ].pos / normScale ) + pcCentre.pos;
  }

  // denormalizing camera centers
  const size_t numViews( views.size() );
#if OPENMVG_USE_OPENMP
#pragma omp parallel for
#endif
  for_parallel( i, numViews )
  {
    views[ i ].trans = ( views[ i ].trans / normScale ) + pcCentre.pos;
  }
} 
Example 33
Source File: SparseDataset.cpp    From cirrus with Apache License 2.0 6 votes vote down vote up
void SparseDataset::normalize(uint64_t hash_size) {
  std::vector<FEATURE_TYPE> max_val_feature(hash_size);
  std::vector<FEATURE_TYPE> min_val_feature(hash_size,
      std::numeric_limits<FEATURE_TYPE>::max());

  for (const auto& w : data_) {
    for (const auto& v : w) {
      uint64_t index = v.first;
      FEATURE_TYPE value = v.second;

#ifdef DEBUG
      if (index >= hash_size)
        throw std::runtime_error("Index bigger than capacity");
#endif

      max_val_feature[index] = std::max(value, max_val_feature[index]);
      min_val_feature[index] = std::min(value, min_val_feature[index]);
    }
  }
  for (auto& w : data_) {
    for (auto& v : w) {
      int index = v.first;

      // only normalize if there are different values
      // in the same column
      if (max_val_feature[index] != min_val_feature[index]) {
        v.second = (v.second - min_val_feature[index]) /
                   (max_val_feature[index] - min_val_feature[index]);
      }
    }
  }
} 
Example 34
Source File: conditioning.cpp    From EGSfM with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void NormalizePoints(const Mat &points,
                      Mat *normalized_points,
                      Mat3 *T,
                      int width,
                      int height) {
  PreconditionerFromPoints(width, height, T);
  ApplyTransformationToPoints(points, *T, normalized_points);
} 
Example 35
Source File: Json.cpp    From XLArig with GNU General Public License v3.0 5 votes vote down vote up
rapidjson::Value xmrig::Json::normalize(double value, bool zero)
{
    using namespace rapidjson;

    if (!std::isnormal(value)) {
        return zero ? Value(0.0) : Value(kNullType);
    }

    return Value(floor(value * 100.0) / 100.0);
} 
Example 36
Source File: template_matching_based_tracker.cc    From ros-vrep-slam with MIT License 5 votes vote down vote up
bool template_matching_based_tracker::normalize(CvMat * V)
{
  float sum = 0.0, sum2 = 0.0;
  float * v = V->data.fl;

  for(int i = 0; i < V->rows; i++) {
    sum += v[i];
    sum2 += v[i] * v[i];
  }

  // Not enough contrast,  better not put this sample into the training set:
  if (sum < (V->rows * 10))
    return false;

  float mean = sum / V->rows;
  float inv_sigma = 1.0 / sqrt(sum2 / V->rows - mean * mean);

  // Not enough contrast,  better not put this sample into the training set:
  if (!finite(inv_sigma))
    return false;

  for(int i = 0; i < V->rows; i++)
    v[i] = inv_sigma * (v[i] - mean);

  return true;
} 
Example 37
Source File: buffer.cpp    From beam with Apache License 2.0 5 votes vote down vote up
SharedBuffer normalize(const SerializedMsg& msg, bool makeUnique) {
    size_t n = msg.size();
    if (n==0) return SharedBuffer();

    if (n==1) {
        if (makeUnique) {
            // copies
            return SharedBuffer(msg[0].data, msg[0].size);
        } else {
            return msg[0];
        }
    } 
Example 38
Source File: line3d.cpp    From StructSLAM with MIT License 5 votes vote down vote up
Vector6d normalizeCartesianLine(const Vector6d& line) {
      Vector3d p0 = line.head<3>();
      Vector3d d0 = line.tail<3>();
      d0.normalize();
      p0 -= d0*(d0.dot(p0));
      Vector6d nl;
      nl.head<3>() = p0;
      nl.tail<3>() = d0;
      return nl;
    } 
Example 39
Source File: ApiRouter.cpp    From xmrig-proxy with GNU General Public License v3.0 5 votes vote down vote up
static inline double normalize(double d)
{
    if (!std::isnormal(d)) {
        return 0.0;
    }

    return std::floor(d * 100.0) / 100.0;
} 
Example 40
Source File: math.cpp    From DEADCELL-CSGO with MIT License 5 votes vote down vote up
bool math::normalize_angles( vec3_t &angles ) {
	if( std::isfinite( angles.x ) && std::isfinite( angles.y ) && std::isfinite( angles.z ) ) {
		angles.x = std::remainder( angles.x, 360.f );
		angles.y = std::remainder( angles.y, 360.f );
		return true;
	}

	return false;
} 
Example 41
Source File: mp_vector.cpp    From OpenLSTO with Apache License 2.0 5 votes vote down vote up
mpVector& mpVector::Normalize()
{
  float length = sqrt(x*x + y*y + z*z);
  if(!length) return *this;
  x /= length;
  y /= length;
  z /= length;
  return *this;
} 
Example 42
Source File: tess_algebra.cpp    From indi-3rdparty with GNU Lesser General Public License v2.1 5 votes vote down vote up
void vector_normalize(vector *a)
{
    float mag = sqrt(vector_dot(a, a));
    if (mag != 0)
    {
        a->x /= mag;
        a->y /= mag;
        a->z /= mag;
    }
    else
    { 
Example 43
Source File: Rect.cpp    From Cpp-Windows-Programming with MIT License 5 votes vote down vote up
void Rect::Normalize() {
    int minX = min(left, right), minY = min(top, bottom),
        maxX = max(left, right), maxY = max(top, bottom);

    left = minX;
    top = minY;
    right = maxX;
    bottom = maxY;
  } 
Example 44
Source File: MatrixTreeNormalization.cpp    From Coda with Apache License 2.0 5 votes vote down vote up
void MatrixTreeNormalization::normalizeRootWeights(
    vector<double>* rootLogWeights)
{
    double sum = 0;
    for (size_t nodeIndex = 0; nodeIndex < rootLogWeights->size(); ++nodeIndex)
    {
        (*rootLogWeights)[nodeIndex] = std::exp((*rootLogWeights)[nodeIndex]);
        sum += (*rootLogWeights)[nodeIndex];
    }
    for (size_t nodeIndex = 0; nodeIndex < rootLogWeights->size(); ++nodeIndex)
    {
        (*rootLogWeights)[nodeIndex] /= sum;
    }
} 
Example 45
Source File: algebra.cpp    From AltitudeEstimation with MIT License 5 votes vote down vote up
void normalizeVector(float a[3])
{
   float len;
   vectorLength(& len,a);
   if (len != 0.0) {
      len = 1.0 / len;
      a[0] *= len;
      a[1] *= len;
      a[2] *= len;
   }
} 
Example 46
Source File: Quaternion.cpp    From bcflight with GNU General Public License v3.0 5 votes vote down vote up
void Quaternion::normalize()
{
	float l = sqrt( x * x + y * y + z * z + w * w );
	if ( l == 0.0f ) {
		x = 0.0f;
		y = 0.0f;
		z = 0.0f;
		w = 1.0f;
	} else { 
Example 47
Source File: Dialog.cpp    From OpenPapyrus with GNU Affero General Public License v3.0 5 votes vote down vote up
void CDialog::NormalizeSize(bool fullNormalize)
{
	RECT workRect;
	GetWorkAreaRect(&workRect);
	int xSize = RECT_SIZE_X(workRect);
	int ySize = RECT_SIZE_Y(workRect);
	RECT rect;
	GetWindowRect(&rect);
	int xSize2 = RECT_SIZE_X(rect);
	int ySize2 = RECT_SIZE_Y(rect);
	bool needMove = (xSize2 > xSize || ySize2 > ySize);
	if(xSize2 > xSize || (needMove && fullNormalize)) {
		rect.left = workRect.left;
		rect.right = workRect.right;
		xSize2 = xSize;
	}
	if(ySize2 > ySize || (needMove && fullNormalize)) {
		rect.top = workRect.top;
		rect.bottom = workRect.bottom;
		ySize2 = ySize;
	}
	if(needMove) {
		if(fullNormalize)
			Show(SW_SHOWMAXIMIZED);
		else
			Move(rect.left, rect.top, xSize2, ySize2, true);
	} 
Example 48
Source File: densecrf.cpp    From dss_crf with MIT License 5 votes vote down vote up
void expAndNormalize ( MatrixXf & out, const MatrixXf & in ) {
	out.resize( in.rows(), in.cols() );
	for( int i=0; i<out.cols(); i++ ){
		VectorXf b = in.col(i);
		b.array() -= b.maxCoeff();
		b = b.array().exp();
		out.col(i) = b / b.array().sum();
	}
} 
Example 49
Source File: meta_state_service_simple.cpp    From rdsn with MIT License 5 votes vote down vote up
std::string meta_state_service_simple::normalize_path(const std::string &s)
{
    if (s.empty() || s[0] != '/')
        return "";
    if (s.length() > 1 && *s.rbegin() == '/')
        return s.substr(0, s.length() - 1);
    return s;
} 
Example 50
Source File: MixBiNormal.cc    From zerospeech2017 with GNU General Public License v3.0 5 votes vote down vote up
void
MixBiNormal::normalizeAlphas()
{
  // Normalize alphas.
  int l;
  double tmp = 0.0;
  for (l=0;l<NumMixComps;l++) {
    tmp += cur_alphas[l];
  }  
  const double inv_tmp = 1.0/tmp;
  for (l=0;l<NumMixComps;l++) {
    cur_alphas[l] *= inv_tmp;
  }
} 
Example 51
Source File: prewhiten.cc    From face-recognizer-android with Apache License 2.0 5 votes vote down vote up
void NormalizeNeon(const float* const input, const float mean,
        const float std_adj, const int num_vals, float* const output) {
    const float32x4_t mean_vec = vdupq_n_f32(-mean);
    const float32x4_t std_vec = vdupq_n_f32(1/std_adj);

    float32x4_t result;

    int offset = 0;
    for (; offset <= num_vals - 4; offset += 4) {
        const float32x4_t deltas =
                vaddq_f32(mean_vec, vld1q_f32(&input[offset]));

        result = vmulq_f32(deltas, std_vec);
        vst1q_f32(&output[offset], result);
    }

    // Get the remaining 1 to 3 values.
    for (; offset < num_vals; ++offset) {
        output[offset] = (input[offset] - mean) / std_adj;
    }
} 
Example 52
Source File: 7z-ppmd.cpp    From OpenPapyrus with GNU Affero General Public License v3.0 5 votes vote down vote up
void CEncProps::Normalize(int level)
		{
			if(level < 0) 
				level = 5;
			if(level > 9) 
				level = 9;
			if(MemSize == (uint32)(int32)-1)
				MemSize = (level >= 9) ? ((uint32)192 << 20) : ((uint32)1 << (level + 19));
			const uint kMult = 16;
			if(MemSize / kMult > ReduceSize) {
				for(uint i = 16; i <= 31; i++) {
					uint32 m = (uint32)1 << i;
					if(ReduceSize <= m / kMult) {
						SETMIN(MemSize, m);
						break;
					}
				}
			}
			if(Order == -1) Order = kOrders[(uint)level];
		} 
Example 53
Source File: LzxDecoder.cpp    From OpenPapyrus with GNU Affero General Public License v3.0 5 votes vote down vote up
void CBitDecoder::NormalizeSmall()
		{
			if(_bitPos <= 16) {
				uint32 val;
				if(_buf >= _bufLim) {
					val = 0xFFFF;
					_extraSize += 2;
				}
				else {
					val = GetUi16(_buf);
					_buf += 2;
				}
				_value = (_value << 16) | val;
				_bitPos += 16;
			} 
Example 54
Source File: agg_arc.cpp    From swiftplot with Apache License 2.0 5 votes vote down vote up
void arc::normalize(double a1, double a2, bool ccw)
    {
        double ra = (std::fabs(m_rx) + std::fabs(m_ry)) / 2;
        m_da = std::acos(ra / (ra + 0.125 / m_scale)) * 2;
        if(ccw)
        {
            while(a2 < a1) a2 += pi * 2.0;
        }
        else
        {
            while 
Example 55
Source File: agg_slider_ctrl.cpp    From swiftplot with Apache License 2.0 5 votes vote down vote up
bool slider_ctrl_impl::normalize_value(bool preview_value_flag)
    {
        bool ret = true;
        if(m_num_steps)
        {
            int step = int(m_preview_value * m_num_steps + 0.5);
            ret = m_value != step / double(m_num_steps);
            m_value = step / double(m_num_steps);
        }
        else
        { 
Example 56
Source File: epsnormalize.cc    From DeepSpeech with Mozilla Public License 2.0 5 votes vote down vote up
void EpsNormalize(const FstClass &ifst, MutableFstClass *ofst,
                  EpsNormalizeType norm_type) {
  if (!internal::ArcTypesMatch(ifst, *ofst, "EpsNormalize")) {
    ofst->SetProperties(kError, kError);
    return;
  }
  EpsNormalizeArgs args(ifst, ofst, norm_type);
  Apply<Operation<EpsNormalizeArgs>>("EpsNormalize", ifst.ArcType(), &args);
} 
Example 57
Source File: hull.cpp    From ShapePFCN with GNU General Public License v3.0 5 votes vote down vote up
Quaternion normalize( Quaternion a )
{
	float m = sqrtf(sqr(a.w)+sqr(a.x)+sqr(a.y)+sqr(a.z));
	if(m<0.000000001) 
		{    
		a.w=1;
		a.x=a.y=a.z=0;
		return a;
	}
	return a * (1/m);
}